HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
BoundaryIntegral.c
Go to the documentation of this file.
1 
5 #include <stdlib.h>
6 #include <basic.h>
7 #include <arrayfunctions.h>
8 #include <mpivars.h>
9 #include <hypar.h>
10 
18  void *s,
19  void *m
20  )
21 {
22  HyPar *solver = (HyPar*) s;
23  MPIVariables *mpi = (MPIVariables*) m;
24 
25  int ndims = solver->ndims;
26  int nvars = solver->nvars;
27  int *dim = solver->dim_local;
28  int ghosts = solver->ghosts;
29  int d,v,k;
30 
31  double *local_integral = (double*) calloc (nvars,sizeof(double));
32  double *global_integral = (double*) calloc (nvars,sizeof(double));
33 
34  /* calculate the local boundary integral on each process */
35  _ArraySetValue_(local_integral,nvars,0.0);
36  for (d=0; d<ndims; d++) {
37  for (v=0; v<nvars; v++) {
38  double dxinv[ndims], dS = 1.0;
39  for (k=0; k<ndims; k++) {
40  /* uniform grid assumed */
41  _GetCoordinate_(k,dim[k]/2,dim,ghosts,solver->dxinv,dxinv[k]);
42  }
43  for (k=0; k<ndims; k++) if (k!=d) dS *= (1.0/dxinv[k]);
44  local_integral[v] += (solver->StepBoundaryIntegral[(2*d+0)*nvars+v])*dS;
45  local_integral[v] += (solver->StepBoundaryIntegral[(2*d+1)*nvars+v])*dS;
46  }
47  }
48 
49  /* add across process to calculate global boundary integral
50  * (internal (MPI) boundaries must cancel out)
51  */
52  IERR MPISum_double(global_integral,local_integral,nvars,&mpi->world); CHECKERR(ierr);
53 
54  /* add to the total boundary integral */
55  _ArrayAXPY_(global_integral,1.0,solver->TotalBoundaryIntegral,nvars);
56 
57  free(local_integral);
58  free(global_integral);
59  return(0);
60 }
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
MPI related function definitions.
int MPISum_double(double *, double *, int, void *)
Definition: MPISum.c:39
int BoundaryIntegral(void *s, void *m)
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
int ghosts
Definition: hypar.h:52
MPI_Comm world
double * StepBoundaryIntegral
Definition: hypar.h:384
double * TotalBoundaryIntegral
Definition: hypar.h:386
int nvars
Definition: hypar.h:29
#define CHECKERR(ierr)
Definition: basic.h:18
Contains structure definition for hypar.
double * dxinv
Definition: hypar.h:110
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
#define IERR
Definition: basic.h:16
Structure of MPI-related variables.
#define _ArrayAXPY_(x, a, y, size)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23