HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
Euler1DGravityField.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <math.h>
8 #include <arrayfunctions.h>
10 #include <hypar.h>
11 #include <mpivars.h>
12 
24  void *s,
25  void *m
26  )
27 {
28  HyPar *solver = (HyPar*) s;
29  MPIVariables *mpi = (MPIVariables*) m;
30  Euler1D *param = (Euler1D*) solver->physics;
31 
32  double *S = param->grav_field;
33  int *dim = solver->dim_local;
34  int ghosts = solver->ghosts;
35  int index[_MODEL_NDIMS_], bounds[_MODEL_NDIMS_],
36  offset[_MODEL_NDIMS_], d, done;
37 
38  /* set bounds for array index to include ghost points */
39  _ArrayCopy1D_(dim,bounds,_MODEL_NDIMS_);
40  for (d=0; d<_MODEL_NDIMS_; d++) bounds[d] += 2*ghosts;
41  /* set offset such that index is compatible with ghost point arrangement */
42  _ArraySetValue_(offset,_MODEL_NDIMS_,-ghosts);
43 
44  /* set the value of the gravity field */
45  done = 0; _ArraySetValue_(index,_MODEL_NDIMS_,0);
46  while (!done) {
47  int p; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,index,offset,ghosts,p);
48  double xcoord; _GetCoordinate_(_XDIR_,index[_XDIR_]-ghosts,dim,ghosts,solver->x,xcoord);
49  if (param->grav_type == 0) {
50  S[p] = exp(-param->grav*xcoord);
51  } else if (param->grav_type == 1) {
52  double pi = 4.0 * atan(1.0);
53  double phi = -sin(2*pi*xcoord)/(2*pi);
54  S[p] = exp(-phi);
55  }
56  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,index,done);
57  }
58 
59  if (param->grav_type != 1) {
60  /* a sensible simulation will not specify peridic boundary conditions
61  * along a direction in which gravity acts (unless the gravitational field
62  * itself is sinusoidal), so extrapolate the gravity field at the boundaries */
63  int indexb[_MODEL_NDIMS_], indexi[_MODEL_NDIMS_];
64  for (d = 0; d < _MODEL_NDIMS_; d++) {
65  /* left boundary */
66  if (!mpi->ip[d]) {
67  _ArrayCopy1D_(dim,bounds,_MODEL_NDIMS_); bounds[d] = ghosts;
68  _ArraySetValue_(offset,_MODEL_NDIMS_,0); offset[d] = -ghosts;
69  done = 0; _ArraySetValue_(indexb,_MODEL_NDIMS_,0);
70  while (!done) {
71  _ArrayCopy1D_(indexb,indexi,_MODEL_NDIMS_); indexi[d] = ghosts-1-indexb[d];
72  int p1; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,indexb,offset,ghosts,p1);
73  int p2; _ArrayIndex1D_ (_MODEL_NDIMS_,dim,indexi,ghosts,p2);
74  S[p1] = S[p2];
75  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,indexb,done);
76  }
77  }
78  /* right boundary */
79  if (mpi->ip[d] == mpi->iproc[d]-1) {
80  _ArrayCopy1D_(dim,bounds,_MODEL_NDIMS_); bounds[d] = ghosts;
81  _ArraySetValue_(offset,_MODEL_NDIMS_,0); offset[d] = dim[d];
82  done = 0; _ArraySetValue_(indexb,_MODEL_NDIMS_,0);
83  while (!done) {
84  _ArrayCopy1D_(indexb,indexi,_MODEL_NDIMS_); indexi[d] = dim[d]-1-indexb[d];
85  int p1; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,indexb,offset,ghosts,p1);
86  int p2; _ArrayIndex1D_ (_MODEL_NDIMS_,dim,indexi,ghosts,p2);
87  S[p1] = S[p2];
88  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,indexb,done);
89  }
90  }
91  }
92  }
93 
94  return(0);
95 }
MPI related function definitions.
Structure containing variables and parameters specific to the 1D Euler equations. This structure cont...
Definition: euler1d.h:273
double * x
Definition: hypar.h:107
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _MODEL_NDIMS_
Definition: euler1d.h:56
Contains structure definition for hypar.
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
double grav
Definition: euler1d.h:275
#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
void * physics
Definition: hypar.h:266
int Euler1DGravityField(void *s, void *m)
1D Euler Equations (inviscid, compressible flows)
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
int grav_type
Definition: euler1d.h:286
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
double * grav_field
Definition: euler1d.h:288