HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
NavierStokes2DSource.c
Go to the documentation of this file.
1 
5 #include <stdlib.h>
6 #include <basic.h>
7 #include <arrayfunctions.h>
8 #include <arrayfunctions_gpu.h>
10 #include <mpivars.h>
11 #include <hypar.h>
12 
13 static int NavierStokes2DSourceFunction (double*,double*,double*,void*,void*,double,int);
14 static int NavierStokes2DSourceUpwind (double*,double*,double*,double*,int,void*,double);
15 
38  double *source,
39  double *u,
40  void *s,
41  void *m,
42  double t
43  )
44 {
45  HyPar *solver = (HyPar* ) s;
46  MPIVariables *mpi = (MPIVariables*) m;
47  NavierStokes2D *param = (NavierStokes2D*) solver->physics;
48 
49  if ((param->grav_x == 0.0) && (param->grav_y == 0.0))
50  return(0); /* no gravitational forces */
51 
52  int v, done, p, p1, p2;
53  double *SourceI = solver->fluxI; /* interace source term */
54  double *SourceC = solver->fluxC; /* cell-centered source term */
55  double *SourceL = solver->fL;
56  double *SourceR = solver->fR;
57 
58  int ndims = solver->ndims;
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  int index[ndims],index1[ndims],index2[ndims],dim_interface[ndims];
65 
66  /* Along X-direction */
67  if (param->grav_x != 0.0) {
68  /* set interface dimensions */
69  _ArrayCopy1D_(dim,dim_interface,ndims); dim_interface[_XDIR_]++;
70  /* calculate the split source function exp(-phi/RT) */
71  IERR NavierStokes2DSourceFunction(SourceC,u,x,solver,mpi,t,_XDIR_); CHECKERR(ierr);
72  /* calculate the left and right interface source terms */
73  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
74  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
75  /* calculate the final interface source term */
76  IERR NavierStokes2DSourceUpwind(SourceI,SourceL,SourceR,u,_XDIR_,solver,t);
77  /* calculate the final cell-centered source term */
78  done = 0; _ArraySetValue_(index,ndims,0);
79  while (!done) {
80  _ArrayCopy1D_(index,index1,ndims);
81  _ArrayCopy1D_(index,index2,ndims); index2[_XDIR_]++;
82  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
83  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
84  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
85 
86  double dx_inverse; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,dxinv,dx_inverse);
87  double rho, uvel, vvel, e, P;
88  _NavierStokes2DGetFlowVar_((u+_MODEL_NVARS_*p),rho,uvel,vvel,e,P,param->gamma);
89  double term[_MODEL_NVARS_] = {0.0, rho*RT, 0.0, rho*RT*uvel};
90  for (v=0; v<_MODEL_NVARS_; v++) {
91  source[_MODEL_NVARS_*p+v] += ( (term[v]*param->grav_field_f[p])
92  * (SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dx_inverse );
93  }
94  uvel = P; /* useless statement to avoid compiler warnings */
95  _ArrayIncrementIndex_(ndims,dim,index,done);
96  }
97  }
98 
99  /* Along Y-direction */
100  if (param->grav_y != 0.0) {
101  /* set interface dimensions */
102  _ArrayCopy1D_(dim,dim_interface,ndims); dim_interface[_YDIR_]++;
103  /* calculate the split source function exp(-phi/RT) */
104  IERR NavierStokes2DSourceFunction(SourceC,u,x,solver,mpi,t,_YDIR_); CHECKERR(ierr);
105  /* calculate the left and right interface source terms */
106  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_YDIR_,solver,mpi,0); CHECKERR(ierr);
107  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_YDIR_,solver,mpi,0); CHECKERR(ierr);
108  /* calculate the final interface source term */
109  IERR NavierStokes2DSourceUpwind(SourceI,SourceL,SourceR,u,_YDIR_,solver,t);
110 
111  /* calculate the final cell-centered source term */
112  done = 0; _ArraySetValue_(index,ndims,0);
113  while (!done) {
114  _ArrayCopy1D_(index,index1,ndims);
115  _ArrayCopy1D_(index,index2,ndims); index2[_YDIR_]++;
116  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
117  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
118  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
119 
120  double dy_inverse; _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,dxinv,dy_inverse);
121  double rho, uvel, vvel, e, P;
122  _NavierStokes2DGetFlowVar_((u+_MODEL_NVARS_*p),rho,uvel,vvel,e,P,param->gamma);
123  double term[_MODEL_NVARS_] = {0.0, 0.0, rho*RT, rho*RT*vvel};
124  for (v=0; v<_MODEL_NVARS_; v++) {
125  source[_MODEL_NVARS_*p+v] += ( (term[v]*param->grav_field_f[p])
126  * (SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dy_inverse );
127  }
128  uvel = P; /* useless statement to avoid compiler warnings */
129  _ArrayIncrementIndex_(ndims,dim,index,done);
130  }
131  }
132 
133  return(0);
134 }
152  double *f,
153  double *u,
154  double *x,
155  void *s,
156  void *m,
157  double t,
158  int dir
159  )
160 {
161  HyPar *solver = (HyPar* ) s;
162  NavierStokes2D *param = (NavierStokes2D*) solver->physics;
163 
164  int ghosts = solver->ghosts;
165  int *dim = solver->dim_local;
166  int ndims = solver->ndims;
167  int index[ndims], bounds[ndims], offset[ndims];
168 
169  /* set bounds for array index to include ghost points */
170  _ArrayCopy1D_(dim,bounds,ndims);
171  int i; for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
172 
173  /* set offset such that index is compatible with ghost point arrangement */
174  _ArraySetValue_(offset,ndims,-ghosts);
175 
176  int done = 0; _ArraySetValue_(index,ndims,0);
177  while (!done) {
178  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
179  (f+_MODEL_NVARS_*p)[0] = 0.0;
180  (f+_MODEL_NVARS_*p)[1] = param->grav_field_g[p] * (dir == _XDIR_);
181  (f+_MODEL_NVARS_*p)[2] = param->grav_field_g[p] * (dir == _YDIR_);
182  (f+_MODEL_NVARS_*p)[3] = param->grav_field_g[p];
183  _ArrayIncrementIndex_(ndims,bounds,index,done);
184  }
185 
186  return(0);
187 }
201  double *fI,
202  double *fL,
203  double *fR,
204  double *u,
205  int dir,
206  void *s,
207  double t
208  )
209 {
210  HyPar *solver = (HyPar*) s;
211  int done,k;
213 
214  int ndims = solver->ndims;
215  int *dim = solver->dim_local;
216 
217  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
218  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
219  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
220 
221  done = 0; _ArraySetValue_(index_outer,ndims,0);
222  while (!done) {
223  _ArrayCopy1D_(index_outer,index_inter,ndims);
224  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
225  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0,p);
226  for (k = 0; k < _MODEL_NVARS_; k++)
227  (fI+_MODEL_NVARS_*p)[k] = 0.5 * ((fL+_MODEL_NVARS_*p)[k] + (fR+_MODEL_NVARS_*p)[k]);
228  }
229  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
230  }
231 
232  return(0);
233 }
#define IERR
Definition: basic.h:16
MPI related function definitions.
Contains function definitions for common array operations on GPU.
#define CHECKERR(ierr)
Definition: basic.h:18
#define _NavierStokes2DGetFlowVar_(u, rho, vx, vy, e, P, gamma)
Some basic definitions and macros.
static int NavierStokes2DSourceFunction(double *, double *, double *, void *, void *, double, int)
double * x
Definition: hypar.h:107
double * fluxI
Definition: hypar.h:136
int ndims
Definition: hypar.h:26
double * grav_field_g
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _YDIR_
Definition: euler2d.h:41
Contains structure definition for hypar.
2D Navier Stokes equations (compressible flows)
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)
Structure containing variables and parameters specific to the 2D Navier Stokes equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D Navier-Stokes equations.
double * grav_field_f
int NavierStokes2DSource(double *source, double *u, void *s, void *m, double t)
#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
static int NavierStokes2DSourceUpwind(double *, double *, double *, double *, int, void *, double)
double * fR
Definition: hypar.h:139
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 _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
double * dxinv
Definition: hypar.h:110