HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
VolumeIntegral.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <basic.h>
8 #include <arrayfunctions.h>
9 #include <mpivars.h>
10 #include <hypar.h>
11 
15  double *VolumeIntegral,
16  double *u,
17  void *s,
18  void *m
19  )
20 {
21  HyPar *solver = (HyPar*) s;
22  MPIVariables *mpi = (MPIVariables*) m;
23 
24  int ndims = solver->ndims;
25  int nvars = solver->nvars;
26  int *dim = solver->dim_local;
27  int ghosts = solver->ghosts;
28  int d,v;
29 
30  /* calculate local volume integral of the solution */
31  int index[ndims], done = 0;
32  double *local_integral = (double*) calloc (nvars,sizeof(double));
33  _ArraySetValue_(local_integral,nvars,0.0);
34  _ArraySetValue_(index,ndims,0);
35  while (!done) {
36  int p; _ArrayIndex1D_(ndims,dim,index,ghosts,p);
37  double dxinv[ndims];
38  for (d=0; d<ndims; d++) { _GetCoordinate_(d,index[d],dim,ghosts,solver->dxinv,dxinv[d]); }
39  double dV = 1.0; for (d=0; d<ndims; d++) dV *= (1.0/dxinv[d]);
40  for (v=0; v<nvars; v++) local_integral[v] += (u[p*nvars+v]*dV);
41  _ArrayIncrementIndex_(ndims,dim,index,done);
42  }
43  /* sum over all processors to get global integral of the solution */
44  IERR MPISum_double(VolumeIntegral,local_integral,nvars,&mpi->world); CHECKERR(ierr);
45  free(local_integral);
46 
47  return(0);
48 }
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
MPI related function definitions.
#define CHECKERR(ierr)
Definition: basic.h:18
int MPISum_double(double *, double *, int, void *)
Definition: MPISum.c:39
Some basic definitions and macros.
int VolumeIntegral(double *VolumeIntegral, double *u, void *s, void *m)
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Contains structure definition for hypar.
MPI_Comm world
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
Contains macros and function definitions for common array operations.
double * dxinv
Definition: hypar.h:110