HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
Euler1DGravityField.c File Reference

Contains the function to compute the gravitational field. More...

#include <stdlib.h>
#include <math.h>
#include <arrayfunctions.h>
#include <physicalmodels/euler1d.h>
#include <hypar.h>
#include <mpivars.h>

Go to the source code of this file.

Functions

int Euler1DGravityField (void *s, void *m)
 

Detailed Description

Contains the function to compute the gravitational field.

Author
Debojyoti Ghosh

Definition in file Euler1DGravityField.c.

Function Documentation

◆ Euler1DGravityField()

int Euler1DGravityField ( void *  s,
void *  m 
)

Compute the gravitational field over the domain. See

  • Xing, Y., Shu, C.-W., "High Order Well-Balanced WENO Scheme for the Gas Dynamics Equations Under Gravitational Fields", Journal of Scientific Computing, 54, 2013, pp. 645-662. http://dx.doi.org/10.1007/s10915-012-9585-8
    for details on the treatment of the gravitational source term. This function computes the graviational potential function. If there is no gravity, the gravitational field is 1.0 all over the domain.
Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables

Definition at line 23 of file Euler1DGravityField.c.

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 }
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
#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
#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)
double * grav_field
Definition: euler1d.h:288