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 File Reference

Compute the flux integral over the physical boundary. More...

#include <stdlib.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Functions

int BoundaryIntegral (void *s, void *m)
 

Detailed Description

Compute the flux integral over the physical boundary.

Author
Debojyoti Ghosh

Definition in file BoundaryIntegral.c.

Function Documentation

int BoundaryIntegral ( void *  s,
void *  m 
)

Computes the flux integral over the boundary. The local flux integral (on this processor) is computed for physical as well as MPI boundaries. The global boundary integral is computed by summing the local integrals over all the processors, since the contributions from the MPI boundaries cancel out.

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables

Definition at line 17 of file BoundaryIntegral.c.

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
int MPISum_double(double *, double *, int, void *)
Definition: MPISum.c:39
#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
double * dxinv
Definition: hypar.h:110
int ndims
Definition: hypar.h:26
#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