HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
Euler1DSource.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <basic.h>
8 #include <arrayfunctions.h>
10 #include <mpivars.h>
11 #include <hypar.h>
12 
13 static int Euler1DSourceFunction(double*,double*,double*,void*,void*,double);
14 
24  double *source,
25  double *u,
26  void *s,
27  void *m,
28  double t
29  )
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 }
80 
90  double *f,
91  double *u,
92  double *x,
93  void *s,
94  void *m,
95  double t
96  )
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 IERR
Definition: basic.h:16
MPI related function definitions.
#define CHECKERR(ierr)
Definition: basic.h:18
Structure containing variables and parameters specific to the 1D Euler equations. This structure cont...
Definition: euler1d.h:273
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
Definition: euler1d.h:300
int Euler1DSource(double *source, double *u, void *s, void *m, double t)
Definition: Euler1DSource.c:23
Some basic definitions and macros.
double * x
Definition: hypar.h:107
double * fluxI
Definition: hypar.h:136
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Contains structure definition for hypar.
int(* InterpolateInterfacesHyp)(double *, double *, double *, double *, int, int, void *, void *, int)
Definition: hypar.h:224
#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
double * fR
Definition: hypar.h:139
1D Euler Equations (inviscid, compressible flows)
double * fL
Definition: hypar.h:139
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _Euler1DGetFlowVar_(u, rho, v, e, P, p)
Definition: euler1d.h:81
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
double * grav_field
Definition: euler1d.h:288
double * fluxC
Definition: hypar.h:128
static int Euler1DSourceFunction(double *, double *, double *, void *, void *, double)
Definition: Euler1DSource.c:89
double * dxinv
Definition: hypar.h:110