HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Euler1DSource.c File Reference

Contains the functions to compute the gravitation source terms for the 1D Euler equations. More...

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

Go to the source code of this file.

Functions

static int Euler1DSourceFunction (double *, double *, double *, void *, void *, double)
 
int Euler1DSource (double *source, double *u, void *s, void *m, double t)
 

Detailed Description

Contains the functions to compute the gravitation source terms for the 1D Euler equations.

Author
Debojyoti Ghosh

Definition in file Euler1DSource.c.

Function Documentation

int Euler1DSourceFunction ( double *  f,
double *  u,
double *  x,
void *  s,
void *  m,
double  t 
)
static

Compute the gravitational source function that is then "discretized" in a way similar to the hyperbolic flux function for the balanced formulation introduced in the reference below. The source term is reformulated and "discretized" in a similar fashion as the hyperbolic flux to ensure that the hydrostatic balance is maintained to machine precision.

Parameters
fComputed source function (array size and layout same as u)
uSolution (conserved variables)
xSpatial coordinates
sSolver object of type HyPar
mMPI object of type MPIVariables
tCurrent solution time

Definition at line 89 of file Euler1DSource.c.

97 {
98  HyPar *solver = (HyPar* ) s;
99  Euler1D *param = (Euler1D*) solver->physics;
100 
101  int ghosts = solver->ghosts;
102  int *dim = solver->dim_local;
103  int ndims = solver->ndims;
104  int index[ndims], bounds[ndims], offset[ndims];
105 
106  /* set bounds for array index to include ghost points */
107  _ArrayCopy1D_(dim,bounds,ndims);
108  int i; for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
109 
110  /* set offset such that index is compatible with ghost point arrangement */
111  _ArraySetValue_(offset,ndims,-ghosts);
112 
113  int done = 0; _ArraySetValue_(index,ndims,0);
114  while (!done) {
115  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
116  (f+_MODEL_NVARS_*p)[0] = 0.0;
117  (f+_MODEL_NVARS_*p)[1] = param->grav_field[p];
118  (f+_MODEL_NVARS_*p)[2] = param->grav_field[p];
119  _ArrayIncrementIndex_(ndims,bounds,index,done);
120  }
121 
122  return(0);
123 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArrayCopy1D_(x, y, size)
double * grav_field
Definition: euler1d.h:288
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Structure containing variables and parameters specific to the 1D Euler equations. This structure cont...
Definition: euler1d.h:273
int Euler1DSource ( double *  source,
double *  u,
void *  s,
void *  m,
double  t 
)

Compute the gravitational source terms for the 1D Euler equations. The source term is computed according to the balanced formulation introduced in the reference below. The source term is reformulated and "discretized" in a similar fashion as the hyperbolic flux to ensure that the hydrostatic balance is maintained to machine precision.

Parameters
sourceComputed source terms (array size & layout same as u)
uSolution (conserved variables)
sSolver object of type HyPar
mMPI object of type MPIVariables
tCurrent solution time

Definition at line 23 of file Euler1DSource.c.

30 {
31  HyPar *solver = (HyPar* ) s;
32  MPIVariables *mpi = (MPIVariables*) m;
33  Euler1D *param = (Euler1D*) solver->physics;
34 
35  if (param->grav == 0.0) return(0); /* no gravitational forces */
36 
37  int v, done, p, p1, p2;
38  double *SourceI = solver->fluxI; /* interace source term */
39  double *SourceC = solver->fluxC; /* cell-centered source term */
40  double *SourceL = solver->fL;
41  double *SourceR = solver->fR;
42 
43  int ndims = solver->ndims;
44  int ghosts = solver->ghosts;
45  int *dim = solver->dim_local;
46  double *x = solver->x;
47  double *dxinv = solver->dxinv;
48  int index[ndims],index1[ndims],index2[ndims],dim_interface[ndims];
49 
50  /* set interface dimensions */
51  _ArrayCopy1D_(dim,dim_interface,ndims); dim_interface[_XDIR_]++;
52  /* calculate the split source function exp(-phi/RT) */
53  IERR Euler1DSourceFunction(SourceC,u,x,solver,mpi,t); CHECKERR(ierr);
54  /* calculate the left and right interface source terms */
55  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
56  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
57  /* calculate the final interface source term */
58  IERR param->SourceUpwind(SourceI,SourceL,SourceR,u,_XDIR_,solver,t);
59  /* calculate the final cell-centered source term */
60  done = 0; _ArraySetValue_(index,ndims,0);
61  while (!done) {
62  _ArrayCopy1D_(index,index1,ndims);
63  _ArrayCopy1D_(index,index2,ndims); index2[_XDIR_]++;
64  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
65  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
66  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
67  double dx_inverse; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,dxinv,dx_inverse);
68  double rho, vel, e, P; _Euler1DGetFlowVar_((u+_MODEL_NVARS_*p),rho,vel,e,P,param);
69  double term[_MODEL_NVARS_] = {0.0, rho, rho*vel};
70  for (v=0; v<_MODEL_NVARS_; v++) {
71  source[_MODEL_NVARS_*p+v] += ( (term[v]*(1.0/param->grav_field[p]))
72  * (SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dx_inverse );
73  }
74  vel = P; /* useless statement to avoid compiler warning */
75  _ArrayIncrementIndex_(ndims,dim,index,done);
76  }
77 
78  return(0);
79 }
#define _ArraySetValue_(x, size, value)
#define _Euler1DGetFlowVar_(u, rho, v, e, P, p)
Definition: euler1d.h:81
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
double * fL
Definition: hypar.h:139
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
double * fluxI
Definition: hypar.h:136
static int Euler1DSourceFunction(double *, double *, double *, void *, void *, double)
Definition: Euler1DSource.c:89
#define _ArrayCopy1D_(x, y, size)
double * fluxC
Definition: hypar.h:128
int(* InterpolateInterfacesHyp)(double *, double *, double *, double *, int, int, void *, void *, int)
Definition: hypar.h:224
#define CHECKERR(ierr)
Definition: basic.h:18
double * grav_field
Definition: euler1d.h:288
double * dxinv
Definition: hypar.h:110
int ndims
Definition: hypar.h:26
#define IERR
Definition: basic.h:16
Structure of MPI-related variables.
double * x
Definition: hypar.h:107
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
Definition: euler1d.h:300
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Structure containing variables and parameters specific to the 1D Euler equations. This structure cont...
Definition: euler1d.h:273
double grav
Definition: euler1d.h:275
#define _XDIR_
Definition: euler1d.h:75
double * fR
Definition: hypar.h:139