HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
NavierStokes3DSource.c
Go to the documentation of this file.
1 
5 #include <stdlib.h>
6 #include <basic.h>
7 #include <arrayfunctions.h>
9 #include <mpivars.h>
10 #include <hypar.h>
11 
12 int NavierStokes3DSourceFunction (double*,double*,double*,void*,void*,double,int);
13 int NavierStokes3DSourceUpwind (double*,double*,double*,double*,int,void*,double);
14 
39  double *source,
40  double *u,
41  void *s,
42  void *m,
43  double t
44  )
45 {
46  HyPar *solver = (HyPar* ) s;
47  MPIVariables *mpi = (MPIVariables*) m;
48  NavierStokes3D *param = (NavierStokes3D*) solver->physics;
49 
50  if ((param->grav_x == 0.0) && (param->grav_y == 0.0) && (param->grav_z == 0.0))
51  return(0); /* no gravitational forces */
52 
53  int v, done, p, p1, p2, dir;
54  double *SourceI = solver->fluxI; /* interace source term */
55  double *SourceC = solver->fluxC; /* cell-centered source term */
56  double *SourceL = solver->fL;
57  double *SourceR = solver->fR;
58 
59  int ghosts = solver->ghosts;
60  int *dim = solver->dim_local;
61  double *x = solver->x;
62  double *dxinv = solver->dxinv;
63  double RT = param->p0 / param->rho0;
64  static int index[_MODEL_NDIMS_],index1[_MODEL_NDIMS_],index2[_MODEL_NDIMS_],dim_interface[_MODEL_NDIMS_];
65  static double grav[_MODEL_NDIMS_];
66 
67  grav[_XDIR_] = param->grav_x;
68  grav[_YDIR_] = param->grav_y;
69  grav[_ZDIR_] = param->grav_z;
70  for (dir = 0; dir < _MODEL_NDIMS_; dir++) {
71  if (grav[dir] != 0.0) {
72  /* set interface dimensions */
73  _ArrayCopy1D_(dim,dim_interface,_MODEL_NDIMS_); dim_interface[dir]++;
74  /* calculate the split source function exp(-phi/RT) */
75  IERR NavierStokes3DSourceFunction(SourceC,u,x,solver,mpi,t,dir); CHECKERR(ierr);
76  /* calculate the left and right interface source terms */
77  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,dir,solver,mpi,0); CHECKERR(ierr);
78  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,dir,solver,mpi,0); CHECKERR(ierr);
79  /* calculate the final interface source term */
80  IERR NavierStokes3DSourceUpwind(SourceI,SourceL,SourceR,u,dir,solver,t);
81  /* calculate the final cell-centered source term */
82  done = 0; _ArraySetValue_(index,_MODEL_NDIMS_,0);
83  while (!done) {
84  _ArrayCopy1D_(index,index1,_MODEL_NDIMS_);
85  _ArrayCopy1D_(index,index2,_MODEL_NDIMS_); index2[dir]++;
86  _ArrayIndex1D_(_MODEL_NDIMS_,dim ,index ,ghosts,p );
87  _ArrayIndex1D_(_MODEL_NDIMS_,dim_interface,index1,0 ,p1);
88  _ArrayIndex1D_(_MODEL_NDIMS_,dim_interface,index2,0 ,p2);
89 
90  double dx_inverse; _GetCoordinate_(dir,index[dir],dim,ghosts,dxinv,dx_inverse);
91  double rho, vel[_MODEL_NDIMS_], e, P;
92  _NavierStokes3DGetFlowVar_((u+_MODEL_NVARS_*p),_NavierStokes3D_stride_,rho,vel[0],vel[1],vel[2],e,P,param->gamma);
93  double term[_MODEL_NVARS_] = {0.0, rho*RT*(dir==_XDIR_), rho*RT*(dir==_YDIR_), rho*RT*(dir==_ZDIR_), rho*RT*vel[dir]};
94  for (v=0; v<_MODEL_NVARS_; v++) {
95  source[_MODEL_NVARS_*p+v] += ( (term[v]*param->grav_field_f[p])
96  * (SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dx_inverse );
97  }
98  vel[0] = P; /* useless statement to avoid compiler warnings */
99  _ArrayIncrementIndex_(_MODEL_NDIMS_,dim,index,done);
100  }
101  }
102  }
103 
104  return(0);
105 }
106 
125  double *f,
126  double *u,
127  double *x,
128  void *s,
129  void *m,
130  double t,
131  int dir
132  )
133 {
134  HyPar *solver = (HyPar* ) s;
135  NavierStokes3D *param = (NavierStokes3D*) solver->physics;
136 
137  int ghosts = solver->ghosts;
138  int *dim = solver->dim_local;
139  static int index[_MODEL_NDIMS_], bounds[_MODEL_NDIMS_], offset[_MODEL_NDIMS_];
140 
141  /* set bounds for array index to include ghost points */
142  _ArrayCopy1D_(dim,bounds,_MODEL_NDIMS_);
143  int i; for (i=0; i<_MODEL_NDIMS_; i++) bounds[i] += 2*ghosts;
144 
145  /* set offset such that index is compatible with ghost point arrangement */
146  _ArraySetValue_(offset,_MODEL_NDIMS_,-ghosts);
147 
148  int done = 0; _ArraySetValue_(index,_MODEL_NDIMS_,0);
149  while (!done) {
150  int p; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,index,offset,ghosts,p);
151  (f+_MODEL_NVARS_*p)[0] = 0.0;
152  (f+_MODEL_NVARS_*p)[1] = param->grav_field_g[p] * (dir == _XDIR_);
153  (f+_MODEL_NVARS_*p)[2] = param->grav_field_g[p] * (dir == _YDIR_);
154  (f+_MODEL_NVARS_*p)[3] = param->grav_field_g[p] * (dir == _ZDIR_);
155  (f+_MODEL_NVARS_*p)[4] = param->grav_field_g[p];
156  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,index,done);
157  }
158 
159  return(0);
160 }
161 
175  double *fI,
176  double *fL,
177  double *fR,
178  double *u,
179  int dir,
180  void *s,
181  double t
182  )
183 {
184  HyPar *solver = (HyPar*) s;
185  int done,k, *dim = solver->dim_local;
187 
188 
189  static int index_outer[_MODEL_NDIMS_], index_inter[_MODEL_NDIMS_],
190  bounds_outer[_MODEL_NDIMS_], bounds_inter[_MODEL_NDIMS_];
191  _ArrayCopy1D_(dim,bounds_outer,_MODEL_NDIMS_); bounds_outer[dir] = 1;
192  _ArrayCopy1D_(dim,bounds_inter,_MODEL_NDIMS_); bounds_inter[dir] += 1;
193 
194  done = 0; _ArraySetValue_(index_outer,_MODEL_NDIMS_,0);
195  while (!done) {
196  _ArrayCopy1D_(index_outer,index_inter,_MODEL_NDIMS_);
197  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
198  int p; _ArrayIndex1D_(_MODEL_NDIMS_,bounds_inter,index_inter,0,p);
199  for (k = 0; k < _MODEL_NVARS_; k++)
200  (fI+_MODEL_NVARS_*p)[k] = 0.5 * ((fL+_MODEL_NVARS_*p)[k] + (fR+_MODEL_NVARS_*p)[k]);
201  }
202  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds_outer,index_outer,done);
203  }
204 
205  return(0);
206 }
#define IERR
Definition: basic.h:16
MPI related function definitions.
#define CHECKERR(ierr)
Definition: basic.h:18
#define _ZDIR_
Structure containing variables and parameters specific to the 3D Navier Stokes equations. This structure contains the physical parameters, variables, and function pointers specific to the 3D Navier-Stokes equations.
Some basic definitions and macros.
double * grav_field_g
double * x
Definition: hypar.h:107
double * fluxI
Definition: hypar.h:136
3D Navier Stokes equations (compressible flows)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int NavierStokes3DSourceUpwind(double *, double *, double *, double *, int, void *, double)
#define _YDIR_
Definition: euler2d.h:41
#define _MODEL_NDIMS_
Definition: euler1d.h:56
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)
static const int _NavierStokes3D_stride_
#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
double * fL
Definition: hypar.h:139
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
int NavierStokes3DSourceFunction(double *, double *, double *, void *, void *, double, int)
Structure of MPI-related variables.
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _DECLARE_IERR_
Definition: basic.h:17
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
double * fluxC
Definition: hypar.h:128
int NavierStokes3DSource(double *source, double *u, void *s, void *m, double t)
double * grav_field_f
double * dxinv
Definition: hypar.h:110
#define _NavierStokes3DGetFlowVar_(u, stride, rho, vx, vy, vz, e, P, gamma)