HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
shallowwater2d.h
Go to the documentation of this file.
1 
36 #include <basic.h>
37 #include <math.h>
38 #include <matops.h>
39 
43 #define _SHALLOW_WATER_2D_ "shallow-water-2d"
44 
45 /* define ndims and nvars for this model */
46 #undef _MODEL_NDIMS_
47 #undef _MODEL_NVARS_
48 
49 #define _MODEL_NDIMS_ 2
50 
51 #define _MODEL_NVARS_ 3
52 
53 /* choices for upwinding schemes */
55 #define _ROE_ "roe"
56 
57 #define _LLF_ "llf-char"
58 
59 /* grid direction */
60 #undef _XDIR_
61 #undef _YDIR_
62 
63 #define _XDIR_ 0
64 #define _YDIR_ 1
65 
73 #define _ShallowWater2DGetFlowVar_(u,h,uvel,vvel) \
74  { \
75  h = u[0]; \
76  uvel = u[1] / h; \
77  vvel = u[2] / h; \
78  }
79 
91 #define _ShallowWater2DSetFlux_(f,h,uvel,vvel,g,dir) \
92  { \
93  if (dir == _XDIR_) { \
94  f[0] = (h) * (uvel); \
95  f[1] = (h) * (uvel) * (uvel) + 0.5 * (g) * (h) * (h); \
96  f[2] = (h) * (uvel) * (vvel); \
97  } else if (dir == _YDIR_) { \
98  f[0] = (h) * (vvel); \
99  f[1] = (h) * (uvel) * (vvel); \
100  f[2] = (h) * (vvel) * (vvel) + 0.5 * (g) * (h) * (h); \
101  } \
102  }
103 
108 #define _ShallowWater2DRoeAverage_(uavg,uL,uR,p) \
109  { \
110  double h , uvel , vvel ; \
111  double hL, uvelL, vvelL; \
112  double hR, uvelR, vvelR; \
113  _ShallowWater2DGetFlowVar_(uL,hL,uvelL,vvelL); \
114  _ShallowWater2DGetFlowVar_(uR,hR,uvelR,vvelR); \
115  h = 0.5 * (hL + hR ); \
116  uvel = (sqrt(hL)*uvelL + sqrt(hR)*uvelR) / (sqrt(hL) + sqrt(hR)); \
117  vvel = (sqrt(hL)*vvelL + sqrt(hR)*vvelR) / (sqrt(hL) + sqrt(hR)); \
118  uavg[0] = h; \
119  uavg[1] = h*uvel; \
120  uavg[2] = h*vvel; \
121  }
122 
129 #define _ShallowWater2DEigenvalues_(u,D,p,dir) \
130  { \
131  double h,uvel,vvel,c; \
132  _ShallowWater2DGetFlowVar_(u,h,uvel,vvel); \
133  c = sqrt(p->g*h); \
134  if (dir == _XDIR_) { \
135  D[0*_MODEL_NVARS_+0] = uvel-c; D[0*_MODEL_NVARS_+1] = 0; D[0*_MODEL_NVARS_+2] = 0; \
136  D[1*_MODEL_NVARS_+0] = 0; D[1*_MODEL_NVARS_+1] = uvel; D[1*_MODEL_NVARS_+2] = 0; \
137  D[2*_MODEL_NVARS_+0] = 0; D[2*_MODEL_NVARS_+1] = 0; D[2*_MODEL_NVARS_+2] = uvel+c; \
138  } else if (dir == _YDIR_) { \
139  D[0*_MODEL_NVARS_+0] = vvel-c; D[0*_MODEL_NVARS_+1] = 0; D[0*_MODEL_NVARS_+2] = 0; \
140  D[1*_MODEL_NVARS_+0] = 0; D[1*_MODEL_NVARS_+1] = vvel; D[1*_MODEL_NVARS_+2] = 0; \
141  D[2*_MODEL_NVARS_+0] = 0; D[2*_MODEL_NVARS_+1] = 0; D[2*_MODEL_NVARS_+2] = vvel+c; \
142  } \
143  }
144 
154 #define _ShallowWater2DLeftEigenvectors_(u,L,p,dir) \
155  { \
156  double h,uvel,vvel,c; \
157  _ShallowWater2DGetFlowVar_(u,h,uvel,vvel); \
158  c = sqrt(p->g*h); \
159  \
160  if (dir == _XDIR_) { \
161  L[0*_MODEL_NVARS_+0] = 0.5 + uvel/(2*c); \
162  L[0*_MODEL_NVARS_+1] = -1.0/(2*c); \
163  L[0*_MODEL_NVARS_+2] = 0.0; \
164  \
165  L[1*_MODEL_NVARS_+0] = vvel; \
166  L[1*_MODEL_NVARS_+1] = 0.0; \
167  L[1*_MODEL_NVARS_+2] = -1.0; \
168  \
169  L[2*_MODEL_NVARS_+0] = 0.5 - uvel/(2*c); \
170  L[2*_MODEL_NVARS_+1] = 1.0/(2*c); \
171  L[2*_MODEL_NVARS_+2] = 0.0; \
172  \
173  } else if (dir == _YDIR_) { \
174  L[0*_MODEL_NVARS_+0] = 0.5 + vvel/(2*c); \
175  L[0*_MODEL_NVARS_+1] = 0.0; \
176  L[0*_MODEL_NVARS_+2] = -1.0/(2*c); \
177  \
178  L[1*_MODEL_NVARS_+0] = -uvel; \
179  L[1*_MODEL_NVARS_+1] = 1.0; \
180  L[1*_MODEL_NVARS_+2] = 0.0; \
181  \
182  L[2*_MODEL_NVARS_+0] = 0.5 - vvel/(2*c); \
183  L[2*_MODEL_NVARS_+1] = 0.0; \
184  L[2*_MODEL_NVARS_+2] = 1.0/(2*c); \
185  } \
186  }
187 
197 #define _ShallowWater2DRightEigenvectors_(u,R,p,dir) \
198  { \
199  double h,uvel,vvel,c; \
200  _ShallowWater2DGetFlowVar_(u,h,uvel,vvel); \
201  c = sqrt(p->g*h); \
202  \
203  if (dir == _XDIR_) { \
204  R[0*_MODEL_NVARS_+0] = 1.0; \
205  R[1*_MODEL_NVARS_+0] = uvel-c; \
206  R[2*_MODEL_NVARS_+0] = vvel; \
207  \
208  R[0*_MODEL_NVARS_+1] = 0.0; \
209  R[1*_MODEL_NVARS_+1] = 0.0; \
210  R[2*_MODEL_NVARS_+1] = -1.0;\
211  \
212  R[0*_MODEL_NVARS_+2] = 1.0; \
213  R[1*_MODEL_NVARS_+2] = uvel+c; \
214  R[2*_MODEL_NVARS_+2] = vvel; \
215  \
216  } else if (dir == _YDIR_) { \
217  R[0*_MODEL_NVARS_+0] = 1.0; \
218  R[1*_MODEL_NVARS_+0] = uvel; \
219  R[2*_MODEL_NVARS_+0] = vvel-c; \
220  \
221  R[0*_MODEL_NVARS_+1] = 0.0; \
222  R[1*_MODEL_NVARS_+1] = 1.0; \
223  R[2*_MODEL_NVARS_+1] = 0.0;\
224  \
225  R[0*_MODEL_NVARS_+2] = 1.0; \
226  R[1*_MODEL_NVARS_+2] = uvel; \
227  R[2*_MODEL_NVARS_+2] = vvel+c; \
228  } \
229  }
230 
240 typedef struct shallowwater2d_parameters {
241  int bt_type,
242  topo_flag;
243  double g,
244  *b,
245  fhat,
246  beta,
247  D;
248  char upw_choice[_MAX_STRING_SIZE_];
256  int (*SourceUpwind)(double*,double*,double*,double*,int,void*,double);
258 
260 int ShallowWater2DInitialize (void*,void*);
262 int ShallowWater2DCleanup (void*);
263 
#define _MAX_STRING_SIZE_
Definition: basic.h:14
int ShallowWater2DCleanup(void *)
Contains macros and function definitions for common matrix operations.
int ShallowWater2DInitialize(void *, void *)
Some basic definitions and macros.
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.