PLUTO
two_shock.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Two-shock Riemann solver for the HD equations.
5 
6  Solve the Riemann problem for the Euler equations of gasdynamics
7  using the two-shock approximation.
8 
9  Reference:
10  - On input, it takes left and right primitive state
11  vectors state->vL and state->vR at zone edge i+1/2;
12  On output, return flux and pressure vectors at the
13  same interface.
14 
15  - Also, compute maximum wave propagation speed (cmax)
16  for explicit time step computation
17 
18 
19  LAST_MODIFIED
20 
21  April 4th 2006, by Andrea Mignone (mignone@to.astro.it)
22 
23 
24  \b Reference:
25  - "FLASH: an Adaptive Mesh Hydrodynamics Code for Modeling
26  Astrophysical Thermonuclear Flashes"
27  Fryxell et al, ApJS(2000) 131:273 (pages 292-294)
28 
29  \authors A. Mignone (mignone@ph.unito.it)
30  \date July 5, 2015
31 */
32 /* ///////////////////////////////////////////////////////////////////// */
33 #include "pluto.h"
34 
35 #define MAX_ITER 5
36 #define small_p 1.e-9
37 #define small_rho 1.e-9
38 
39 /* ***************************************************************************** */
40 void TwoShock_Solver (const State_1D *state, int beg, int end,
41  double *cmax, Grid *grid)
42 /*!
43  *
44  ******************************************************************************* */
45 {
46 #if EOS == IDEAL
47  int i, iter, nv;
48 
49  double vxl, taul, cl, *ql;
50  double vxr, taur, cr, *qr;
51  double zs, taus, cs, *qs;
52  double pstar, ustar, rho_star, cstar;
53  double sigma, lambda_s, lambda_star, zeta, dp;
54  double g1_g, scrh1, scrh2, scrh3, scrh4;
55  static double **ws, **us;
56  static double **fL, **fR, *pL, *pR, *a2L, *a2R;
57  double *uL, *uR;
58 
59  if (ws == NULL){
60  ws = ARRAY_2D(NMAX_POINT, NVAR, double);
61  us = ARRAY_2D(NMAX_POINT, NVAR, double);
62 
63  fL = ARRAY_2D(NMAX_POINT, NFLX, double);
64  fR = ARRAY_2D(NMAX_POINT, NFLX, double);
65  pL = ARRAY_1D(NMAX_POINT, double);
66  pR = ARRAY_1D(NMAX_POINT, double);
67 
68  a2L = ARRAY_1D(NMAX_POINT, double);
69  a2R = ARRAY_1D(NMAX_POINT, double);
70  }
71 
72 /* ---------------------------------------------------------------
73  SOLVE RIEMANN PROBLEM
74  --------------------------------------------------------------- */
75 
76  g1_g = 0.5*(g_gamma + 1.0)/g_gamma;
77  for (i = beg; i <= end; i++) {
78 
79  uL = state->uL[i];
80  uR = state->uR[i];
81 
82 #if SHOCK_FLATTENING == MULTID
83  if ((state->flag[i] & FLAG_HLL) || (state->flag[i+1] & FLAG_HLL)){
84  a2L[i] = g_gamma*state->vL[i][PRS]/state->vL[i][RHO];
85  a2R[i] = g_gamma*state->vR[i][PRS]/state->vR[i][RHO];
86  HLL_Speed (state->vL, state->vR, a2L, a2R, &cl - i, &cr - i, i, i);
87  Flux (state->uL, state->vL, a2L, fL, pL, i, i);
88  Flux (state->uR, state->vR, a2R, fR, pR, i, i);
89 
90  cs = MAX(fabs(cl), fabs(cr));
91  cmax[i] = cs;
92  cl = MIN(0.0, cl);
93  cr = MAX(0.0, cr);
94  scrh1 = 1.0/(cr - cl);
95  for (nv = NFLX; nv--; ){
96  state->flux[i][nv] = cl*cr*(uR[nv] - uL[nv])
97  + cr*fL[i][nv] - cl*fR[i][nv];
98  state->flux[i][nv] *= scrh1;
99  }
100  state->press[i] = (cr*pL[i] - cl*pR[i])*scrh1;
101  continue;
102  }
103 #endif
104 
105  qr = state->vR[i];
106  ql = state->vL[i];
107 
108  cl = sqrt(g_gamma*ql[PRS]*ql[RHO]);
109  cr = sqrt(g_gamma*qr[PRS]*qr[RHO]);
110 
111  taul = 1.0/ql[RHO];
112  taur = 1.0/qr[RHO];
113 
114  /* -- First guess -- */
115 
116  pstar = qr[PRS] - ql[PRS] - cr*(qr[VXn] - ql[VXn]);
117  pstar = ql[PRS] + pstar*cl/(cl + cr);
118  pstar = MAX(small_p , pstar);
119 
120  /* -- Begin to iterate -- */
121 
122  for (iter = 1; iter <= MAX_ITER; iter++) {
123  vxl = cl*sqrt(1.0 + g1_g*(pstar - ql[PRS])/ql[PRS]);
124  vxr = cr*sqrt(1.0 + g1_g*(pstar - qr[PRS])/qr[PRS]);
125 
126  scrh1 = vxl*vxl;
127  scrh1 = 2.0*scrh1*vxl/(scrh1 + cl*cl);
128 
129  scrh2 = vxr*vxr;
130  scrh2 = 2.0*scrh2*vxr/(scrh2 + cr*cr);
131 
132  scrh3 = ql[VXn] - (pstar - ql[PRS])/vxl;
133  scrh4 = qr[VXn] + (pstar - qr[PRS])/vxr;
134 
135  dp = scrh1*scrh2/(scrh1 + scrh2)*(scrh4 - scrh3);
136 
137  pstar -= dp;
138 /*
139  scrh1 = 4.0*taul*vxl*vxl;
140  scrh1 = -scrh1*vxl/(scrh1 - (g_gamma + 1.0)*(pstar - ql[PRS]));
141  scrh2 = 4.0*taur*vxr*vxr;
142  scrh2 = scrh2*vxr/(scrh2 - (g_gamma + 1.0)*(pstar - qr[PRS]));
143 
144  scrh3 = ql[VXn] - (pstar - ql[PRS])/vxl;
145  scrh4 = qr[VXn] + (pstar - qr[PRS])/vxr;
146  dp = (scrh4 - scrh3)*(scrh1*scrh2)/(scrh2 - scrh1);
147  pstar = pstar + dp;
148 */
149 
150  pstar = MAX (small_p, pstar);
152  if (fabs(dp/pstar) < 1.e-6) break;
153 /*
154  if (iter == MAX_ITER) {
155  print ("Rieman solver not converging ps %12.6e dp %12.6e %12.6e %12.6e %12.6e %12.6e \n",
156  pstar,dp, scrh1, scrh2, scrh3, scrh4);
157  }
158 */
159  }
160 
161 /* End iterating */
162 
163  scrh3 = ql[VXn] - (pstar - ql[PRS])/vxl;
164  scrh4 = qr[VXn] + (pstar - qr[PRS])/vxr;
165  ustar = 0.5*(scrh3 + scrh4);
166 
167  if (ustar > 0.0) {
168  sigma = 1.0;
169  taus = taul;
170  cs = cl*taul;
171  zs = vxl;
172  qs = ql;
173  }else{
174  sigma = -1.0;
175  taus = taur;
176  cs = cr*taur;
177  zs = vxr;
178  qs = qr;
179  }
180 
181  rho_star = taus - (pstar - qs[PRS])/(zs*zs);
182  rho_star = MAX(small_rho,1.0/rho_star);
183  cstar = sqrt(g_gamma*pstar/rho_star);
184  if (pstar < qs[PRS]){
185  lambda_s = cs - sigma*qs[VXn];
186  lambda_star = cstar - sigma*ustar;
187  }else{
188  lambda_s = lambda_star = zs*taus - sigma*qs[VXn];
189  }
190 
191  /* -- Now find solution -- */
192 
193  if (lambda_star > 0.0){
194 
195  ws[i][RHO] = rho_star;
196  ws[i][VXn] = ustar;
197  ws[i][PRS] = pstar;
198 
199  } else if (lambda_s < 0.0){
200 
201  ws[i][RHO] = qs[RHO];
202  ws[i][VXn] = qs[VXn];
203  ws[i][PRS] = qs[PRS];
204 
205  } else { /* linearly interpolate rarefaction fan */
206 
207  scrh1 = MAX(lambda_s - lambda_star, lambda_s + lambda_star);
208  zeta = 0.5*(1.0 + (lambda_s + lambda_star)/scrh1);
209 
210  ws[i][RHO] = zeta*rho_star + (1.0 - zeta)*qs[RHO];
211  ws[i][VXn] = zeta*ustar + (1.0 - zeta)*qs[VXn];
212  ws[i][PRS] = zeta*pstar + (1.0 - zeta)*qs[PRS];
213  }
214 
215  /* -- transverse velocities are advected -- */
216 
217  EXPAND( ,
218  ws[i][VXt] = qs[VXt]; ,
219  ws[i][VXb] = qs[VXb];)
220 
221  /* -- compute flux -- */
222 
223  PrimToCons (ws, us, i, i);
224  scrh2 = g_gamma*ws[i][PRS]/ws[i][RHO];
225  Flux (us, ws, &scrh2 - i, state->flux, state->press, i, i);
226  cstar = sqrt(scrh2);
227 
228  /* -- compute max speed -- */
229 
230  scrh1 = fabs(ws[i][VXn])/cstar;
231  g_maxMach = MAX(scrh1, g_maxMach);
232  scrh1 = fabs(ws[i][VXn]) + cstar;
233  cmax[i] = scrh1;
234 
235  /* -- Add artificial viscosity -- */
236 
237 #ifdef ARTIFICIAL_VISC
238  scrh1 = ARTIFICIAL_VISC*(MAX(0.0, ql[VXn] - qr[VXn]));
239  for (nv = 0; nv < NFLX; nv++) {
240  state->flux[i][nv] += scrh1*(uL[nv] - uR[nv]);
241  }
242 #endif
243 
244  }
245 
246 
247 #else
248  print1 ("! TwoShock_Solver: not defined for this EOS\n");
249  QUIT_PLUTO(1);
250 #endif /* EOS == IDEAL */
251 }
252 
253 #undef MAX_ITER
254 #undef small_p
255 #undef small_rho
#define MAX_ITER
Definition: two_shock.c:35
#define MAX(a, b)
Definition: macros.h:101
double g_gamma
Definition: globals.h:112
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
#define ARTIFICIAL_VISC
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
void Flux(double **u, double **w, double *a2, double **fx, double *p, int beg, int end)
Definition: fluxes.c:23
void TwoShock_Solver(const State_1D *state, int beg, int end, double *cmax, Grid *grid)
Definition: two_shock.c:40
#define RHO
Definition: mod_defs.h:19
#define small_rho
Definition: two_shock.c:37
int g_maxRiemannIter
Maximum number of iterations for iterative Riemann Solver.
Definition: globals.h:93
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
#define small_p
Definition: two_shock.c:36
int VXb
Definition: globals.h:73
#define MIN(a, b)
Definition: macros.h:104
double g_maxMach
The maximum Mach number computed during integration.
Definition: globals.h:119
#define NFLX
Definition: mod_defs.h:32
Definition: structs.h:78
int VXt
Definition: globals.h:73
unsigned char * flag
Definition: structs.h:168
int VXn
Definition: globals.h:73
double ** uR
same as vR, in conservative vars
Definition: structs.h:145
PLUTO main header file.
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
void PrimToCons(double **uprim, double **ucons, int ibeg, int iend)
Definition: mappers.c:26
int i
Definition: analysis.c:2
void HLL_Speed(double **vL, double **vR, double *a2L, double *a2R, double *SL, double *SR, int beg, int end)
Definition: hll_speed.c:24
double ** vL
Primitive variables to the left of the interface, .
Definition: structs.h:136
double * press
Upwind pressure term computed with the Riemann solver.
Definition: structs.h:164
#define FLAG_HLL
Use HLL Riemann solver.
Definition: pluto.h:181
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define NVAR
Definition: pluto.h:609
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
double ** uL
same as vL, in conservative vars
Definition: structs.h:144