HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
euler1d.h
Go to the documentation of this file.
1 
31 /*
32  d [ rho ] d [ rho*u ]\n
33  -- [ rho*u ] + -- [rho*u*u + p ] = 0\n
34  dt [ e ] dx [ (e+p)*u ]\n
35 
36  Equation of state:
37  p 1
38  e = ------- + - rho * u^2
39  gamma-1 2
40 
41 */
42 
43 #include <basic.h>
44 #include <math.h>
45 #include <matops.h>
46 
50 #define _EULER_1D_ "euler1d"
51 
52 /* define ndims and nvars for this model */
53 #undef _MODEL_NDIMS_
54 #undef _MODEL_NVARS_
55 
56 #define _MODEL_NDIMS_ 1
57 
58 #define _MODEL_NVARS_ 3
59 
60 /* choices for upwinding schemes */
62 #define _ROE_ "roe"
63 
64 #define _RF_ "rf-char"
65 
66 #define _LLF_ "llf-char"
67 
68 #define _SWFS_ "steger-warming"
69 
70 #define _RUSANOV_ "rusanov"
71 
72 /* grid direction */
73 #undef _XDIR_
74 
75 #define _XDIR_ 0
76 
81 #define _Euler1DGetFlowVar_(u,rho,v,e,P,p) \
82  { \
83  double gamma = p->gamma; \
84  rho = u[0]; \
85  v = u[1] / rho; \
86  e = u[2]; \
87  P = (e - 0.5*rho*v*v) * (gamma-1.0); \
88  }
89 
94 #define _Euler1DSetFlux_(f,rho,v,e,P) \
95  { \
96  f[0] = (rho) * (v); \
97  f[1] = (rho) * (v) * (v) + (P); \
98  f[2] = ((e) + (P)) * (v); \
99  }
100 
115 #define _Euler1DSetStiffFlux_(f,rho,v,e,P,gamma) \
116  { \
117  double gamma_inv = 1.0 / (gamma); \
118  f[0] = gamma_inv * (rho)*(v); \
119  f[1] = gamma_inv * (rho)*(v)*(v) + (P); \
120  f[2] = ((e)+(P)) * (v) - 0.5*gamma_inv*((gamma)-1)*(rho)*(v)*(v)*(v); \
121  }
122 
134 #define _Euler1DSetLinearizedStiffFlux_(f,u,J) \
135  { \
136  _MatVecMultiply_((J),(u),(f),(_MODEL_NVARS_)); \
137  }
138 
149 #define _Euler1DSetStiffJac_(J,rho,v,e,P,gamma) \
150  { \
151  double gm1 = (gamma)-1; \
152  double inv_gm = 1.0/(gamma); \
153  double gm1_inv_gm = gm1 * inv_gm; \
154  J[0] = 0.5*gm1_inv_gm*(rho)*(v)*(v)*(v)/(P) - (v); \
155  J[1] = 1.0 - gm1_inv_gm*(rho)*(v)*(v)/(P); \
156  J[2] = gm1_inv_gm*(rho)*(v)/(P); \
157  J[3] = 0.5*gm1_inv_gm*(rho)*(v)*(v)*(v)*(v)/(P) + 0.5*((gamma)-5.0)*(v)*(v); \
158  J[4] = (3.0-(gamma))*(v) - gm1_inv_gm*(rho)*(v)*(v)*(v)/(P); \
159  J[5] = gm1_inv_gm*(rho)*(v)*(v)/(P) + gm1; \
160  J[6] = 0.25*gm1_inv_gm*(rho)*(v)*(v)*(v)*(v)*(v)/(P) - (gamma)*(v)*(e)/(rho) + 0.5*(2.0*(gamma)-3.0)*(v)*(v)*(v); \
161  J[7] = (gamma)*(e)/(rho) - 1.5*gm1*(v)*(v) - 0.5*gm1_inv_gm*(rho)*(v)*(v)*(v)*(v)/(P); \
162  J[8] = 0.5*gm1_inv_gm*(rho)*(v)*(v)*(v)/(P) + (gamma)*(v); \
163  }
164 
169 #define _Euler1DRoeAverage_(uavg,uL,uR,p) \
170  { \
171  double rho ,v ,e ,P ,H ,csq; \
172  double rhoL,vL,eL,PL,HL,cLsq; \
173  double rhoR,vR,eR,PR,HR,cRsq; \
174  double gamma = p->gamma; \
175  rhoL = uL[0]; \
176  vL = uL[1] / rhoL; \
177  eL = uL[2]; \
178  PL = (eL - 0.5*rhoL*vL*vL) * (gamma-1.0); \
179  cLsq = gamma * PL/rhoL; \
180  HL = 0.5*vL*vL + cLsq / (gamma-1.0); \
181  rhoR = uR[0]; \
182  vR = uR[1] / rhoR; \
183  eR = uR[2]; \
184  PR = (eR - 0.5*rhoR*vR*vR) * (gamma-1.0); \
185  cRsq = gamma * PR/rhoR; \
186  HR = 0.5*vR*vR + cRsq / (gamma-1.0); \
187  double tL = sqrt(rhoL); \
188  double tR = sqrt(rhoR); \
189  rho = tL * tR; \
190  v = (tL*vL + tR*vR) / (tL + tR); \
191  H = (tL*HL + tR*HR) / (tL + tR); \
192  csq = (gamma-1.0) * (H-0.5*v*v); \
193  P = csq * rho / gamma; \
194  e = P/(gamma-1.0) + 0.5*rho*v*v; \
195  \
196  uavg[0] = rho; \
197  uavg[1] = rho*v; \
198  uavg[2] = e; \
199  }
200 
207 #define _Euler1DEigenvalues_(u,D,p,dir) \
208  { \
209  double gamma = p->gamma; \
210  double rho,v,e,P,c; \
211  rho = u[0]; \
212  v = u[1] / rho; \
213  e = u[2]; \
214  P = (e - 0.5*rho*v*v) * (gamma-1.0); \
215  c = sqrt(gamma*P/rho); \
216  D[0*_MODEL_NVARS_+0] = v; D[0*_MODEL_NVARS_+1] = 0; D[0*_MODEL_NVARS_+2] = 0; \
217  D[1*_MODEL_NVARS_+0] = 0; D[1*_MODEL_NVARS_+1] = (v-c); D[1*_MODEL_NVARS_+2] = 0; \
218  D[2*_MODEL_NVARS_+0] = 0; D[2*_MODEL_NVARS_+1] = 0; D[2*_MODEL_NVARS_+2] = (v+c); \
219  }
220 
225 #define _Euler1DLeftEigenvectors_(u,L,p,dir) \
226  { \
227  double gamma = p->gamma; \
228  double rho,v,e,P,c; \
229  rho = u[0]; \
230  v = u[1] / rho; \
231  e = u[2]; \
232  P = (e - 0.5*rho*v*v) * (gamma-1.0); \
233  c = sqrt(gamma*P/rho); \
234  L[1*_MODEL_NVARS_+0] = ((gamma - 1)/(rho*c)) * (-(v*v)/2 - c*v/(gamma-1)); \
235  L[1*_MODEL_NVARS_+1] = ((gamma - 1)/(rho*c)) * (v + c/(gamma-1)); \
236  L[1*_MODEL_NVARS_+2] = ((gamma - 1)/(rho*c)) * (-1); \
237  L[0*_MODEL_NVARS_+0] = ((gamma - 1)/(rho*c)) * (rho*(-(v*v)/2+c*c/(gamma-1))/c); \
238  L[0*_MODEL_NVARS_+1] = ((gamma - 1)/(rho*c)) * (rho*v/c); \
239  L[0*_MODEL_NVARS_+2] = ((gamma - 1)/(rho*c)) * (-rho/c); \
240  L[2*_MODEL_NVARS_+0] = ((gamma - 1)/(rho*c)) * ((v*v)/2 - c*v/(gamma-1)); \
241  L[2*_MODEL_NVARS_+1] = ((gamma - 1)/(rho*c)) * (-v + c/(gamma-1)); \
242  L[2*_MODEL_NVARS_+2] = ((gamma - 1)/(rho*c)) * (1); \
243  }
244 
249 #define _Euler1DRightEigenvectors_(u,R,p,dir) \
250  { \
251  double gamma = p->gamma; \
252  double rho,v,e,P,c; \
253  rho = u[0]; \
254  v = u[1] / rho; \
255  e = u[2]; \
256  P = (e - 0.5*rho*v*v) * (gamma-1.0); \
257  c = sqrt(gamma*P/rho); \
258  R[0*_MODEL_NVARS_+1] = - rho/(2*c); R[1*_MODEL_NVARS_+1] = -rho*(v-c)/(2*c); R[2*_MODEL_NVARS_+1] = -rho*((v*v)/2+(c*c)/(gamma-1)-c*v)/(2*c); \
259  R[0*_MODEL_NVARS_+0] = 1; R[1*_MODEL_NVARS_+0] = v; R[2*_MODEL_NVARS_+0] = v*v / 2; \
260  R[0*_MODEL_NVARS_+2] = rho/(2*c); R[1*_MODEL_NVARS_+2] = rho*(v+c)/(2*c); R[2*_MODEL_NVARS_+2] = rho*((v*v)/2+(c*c)/(gamma-1)+c*v)/(2*c); \
261  }
262 
273 typedef struct euler1d_parameters {
274  double gamma;
275  double grav;
286  int grav_type;
287 
288  double *grav_field;
289  double *fast_jac;
290  double *solution;
291  char upw_choice[_MAX_STRING_SIZE_];
300  int (*SourceUpwind)(double*,double*,double*,double*,int,void*,double);
301 
302 } Euler1D;
303 
305 int Euler1DInitialize (void*,void*);
307 int Euler1DCleanup (void*);
308 
#define _MAX_STRING_SIZE_
Definition: basic.h:14
int Euler1DCleanup(void *)
double * fast_jac
Definition: euler1d.h:289
Contains macros and function definitions for common matrix operations.
double * solution
Definition: euler1d.h:290
int grav_type
Definition: euler1d.h:286
double * grav_field
Definition: euler1d.h:288
Some basic definitions and macros.
int Euler1DInitialize(void *, void *)
Structure containing variables and parameters specific to the 1D Euler equations. This structure cont...
Definition: euler1d.h:273
double gamma
Definition: euler1d.h:274
double grav
Definition: euler1d.h:275