HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
ShallowWater1DSource.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 ShallowWater1DSourceFunction1 (double*,double*,double*,void*,void*,double);
14 static int ShallowWater1DSourceFunction2 (double*,double*,double*,void*,void*,double);
15 
26  double *source,
27  double *u,
28  void *s,
29  void *m,
30  double t
31  )
32 {
33  HyPar *solver = (HyPar* ) s;
34  MPIVariables *mpi = (MPIVariables*) m;
35  ShallowWater1D *param = (ShallowWater1D*) solver->physics;
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 
53  /* calculate the first source function */
54  IERR ShallowWater1DSourceFunction1(SourceC,u,x,solver,mpi,t); CHECKERR(ierr);
55  /* calculate the left and right interface source terms */
56  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
57  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
58  /* calculate the final interface source term */
59  IERR param->SourceUpwind(SourceI,SourceL,SourceR,u,_XDIR_,solver,t);
60  /* calculate the final cell-centered source term */
61  done = 0; _ArraySetValue_(index,ndims,0);
62  while (!done) {
63  _ArrayCopy1D_(index,index1,ndims);
64  _ArrayCopy1D_(index,index2,ndims); index2[_XDIR_]++;
65  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
66  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
67  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
68  double dx_inverse; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,dxinv,dx_inverse);
69  for (v=0; v<_MODEL_NVARS_; v++)
70  source[_MODEL_NVARS_*p+v] += (SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dx_inverse;
71  _ArrayIncrementIndex_(ndims,dim,index,done);
72  }
73 
74  /* calculate the second source function */
75  IERR ShallowWater1DSourceFunction2(SourceC,u,x,solver,mpi,t); CHECKERR(ierr);
76  /* calculate the left and right interface source terms */
77  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
78  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
79  /* calculate the final interface source term */
80  IERR param->SourceUpwind(SourceI,SourceL,SourceR,u,_XDIR_,solver,t);
81  /* calculate the final cell-centered source term */
82  done = 0; _ArraySetValue_(index,ndims,0);
83  while (!done) {
84  _ArrayCopy1D_(index,index1,ndims);
85  _ArrayCopy1D_(index,index2,ndims); index2[_XDIR_]++;
86  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
87  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
88  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
89  double dx_inverse; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,dxinv,dx_inverse);
90  double h, vel; _ShallowWater1DGetFlowVar_((u+_MODEL_NVARS_*p),h,vel);
91  double term[_MODEL_NVARS_] = { 0.0, -param->g * (h + param->b[p]) };
92  for (v=0; v<_MODEL_NVARS_; v++) {
93  source[_MODEL_NVARS_*p+v] += term[v]*(SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dx_inverse;
94  }
95  vel = h; /* useless statement to avoid compiler warning */
96  _ArrayIncrementIndex_(ndims,dim,index,done);
97  }
98 
99  return(0);
100 }
101 
112  double *f,
113  double *u,
114  double *x,
115  void *s,
116  void *m,
117  double t
118  )
119 {
120  HyPar *solver = (HyPar* ) s;
121  ShallowWater1D *param = (ShallowWater1D*) solver->physics;
122 
123  int ghosts = solver->ghosts;
124  int *dim = solver->dim_local;
125  int ndims = solver->ndims;
126  int index[ndims], bounds[ndims], offset[ndims];
127 
128  /* set bounds for array index to include ghost points */
129  _ArrayCopy1D_(dim,bounds,ndims);
130  int i; for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
131 
132  /* set offset such that index is compatible with ghost point arrangement */
133  _ArraySetValue_(offset,ndims,-ghosts);
134 
135  int done = 0; _ArraySetValue_(index,ndims,0);
136  while (!done) {
137  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
138  (f+_MODEL_NVARS_*p)[0] = 0.0;
139  (f+_MODEL_NVARS_*p)[1] = 0.5 * param->g * param->b[p] * param->b[p];
140  _ArrayIncrementIndex_(ndims,bounds,index,done);
141  }
142 
143  return(0);
144 }
145 
156  double *f,
157  double *u,
158  double *x,
159  void *s,
160  void *m,
161  double t
162  )
163 {
164  HyPar *solver = (HyPar* ) s;
165  ShallowWater1D *param = (ShallowWater1D*) solver->physics;
166 
167  int ghosts = solver->ghosts;
168  int *dim = solver->dim_local;
169  int ndims = solver->ndims;
170  int index[ndims], bounds[ndims], offset[ndims];
171 
172  /* set bounds for array index to include ghost points */
173  _ArrayCopy1D_(dim,bounds,ndims);
174  int i; for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
175 
176  /* set offset such that index is compatible with ghost point arrangement */
177  _ArraySetValue_(offset,ndims,-ghosts);
178 
179  int done = 0; _ArraySetValue_(index,ndims,0);
180  while (!done) {
181  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
182  (f+_MODEL_NVARS_*p)[0] = 0.0;
183  (f+_MODEL_NVARS_*p)[1] = param->b[p];
184  _ArrayIncrementIndex_(ndims,bounds,index,done);
185  }
186 
187  return(0);
188 }
Structure containing variables and parameters specific to the 1D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 1D ShallowWater equations.
static int ShallowWater1DSourceFunction2(double *, double *, double *, void *, void *, double)
1D Shallow Water Equations
#define IERR
Definition: basic.h:16
MPI related function definitions.
#define CHECKERR(ierr)
Definition: basic.h:18
Some basic definitions and macros.
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
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
int ShallowWater1DSource(double *source, double *u, void *s, void *m, double t)
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)
#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 _ShallowWater1DGetFlowVar_(u, h, v)
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.
static int ShallowWater1DSourceFunction1(double *, double *, double *, void *, void *, double)
#define _MODEL_NVARS_
Definition: euler1d.h:58
#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