16 double scrh0, scrh1, scrh2, scrh3, scrh4;
17 double rho, u,
v, w,
vel2, bx, by, bz, pr;
19 double a2,
a, ca2, cf2, cs2;
20 double cs,
ca, cf, b2, A2, At2;
22 double alpha_f, alpha_s, beta_y, beta_z;
23 double dw[
NVAR], *vL, *vR, *uL, *uR;
28 double delta, delta_inv, gmm1_inv;
30 static double *a2L, *a2R, *pR, *pL;
31 static double **fL, **fR, **Rp, **Rc;
32 static double **VL, **VR, **UL, **UR;
38 delta_inv = 1.0 / delta;
39 gmm1_inv = 1.0 / gmm1;
62 #if BACKGROUND_FIELD == YES
67 GLM_Solve (state, VL, VR, beg, end, grid);
71 VL = state->
vL; UL = state->
uL;
72 VR = state->
vR; UR = state->
uR;
78 Flux (UL, VL, a2L, bgf, fL, pL, beg, end);
79 Flux (UR, VR, a2R, bgf, fR, pR, beg, end);
81 SL = state->
SL; SR = state->
SR;
86 for (k =
NFLX; k--; ) {
87 for (j =
NFLX; j--; ) {
88 Rp[
k][
j] = Rc[
k][
j] = 0.0;
92 for (i = beg; i <= end; i++) {
94 vL = VL[
i]; vR = VR[
i];
95 uL = UL[
i]; uR = UR[
i];
97 #if SHOCK_FLATTENING == MULTID
102 HLL_SPEED (VL, VR, NULL, SL, SR, i, i);
104 scrh0 =
MAX(fabs(SL[i]), fabs(SR[i]));
108 for (nv =
NFLX; nv--; ) state->
flux[i][nv] = fL[i][nv];
109 state->
press[i] = pL[i];
110 }
else if (SR[i] < 0.0) {
111 for (nv =
NFLX; nv--; ) state->
flux[i][nv] = fR[i][nv];
112 state->
press[i] = pR[i];
114 scrh0 = 1.0/(SR[
i] - SL[
i]);
115 for (nv =
NFLX; nv--; ){
116 state->
flux[
i][nv] = SR[
i]*SL[
i]*(uR[nv] - uL[nv])
117 + SR[i]*fL[i][nv] - SL[i]*fR[i][nv];
118 state->
flux[
i][nv] *= scrh0;
120 state->
press[
i] = (SR[
i]*pL[
i] - SL[
i]*pR[
i])*scrh0;
126 rho = 0.5*(vL[
RHO] + vR[
RHO]);
127 EXPAND (u = 0.5*(vL[
VXn] + vR[
VXn]); ,
128 v = 0.5*(vL[
VXt] + vR[
VXt]); ,
129 w = 0.5*(vL[
VXb] + vR[
VXb]); )
130 EXPAND (bx = b1x = 0.5*(vL[
BXn] + vR[
BXn]); ,
131 by = b1y = 0.5*(vL[
BXt] + vR[
BXt]); ,
132 bz = b1z = 0.5*(vL[
BXb] + vR[
BXb]);)
135 EXPAND (bx += bgf[i][
BXn]; ,
140 pr = 0.5*(vL[PRS] + vR[PRS]);
142 for (nv = 0; nv <
NFLX; nv++) dw[nv] = vR[nv] - vL[nv];
145 sqrt_rho = sqrt(rho);
147 vel2 = EXPAND(u*u, +v*v, +w*w);
151 scrh3 = SELECT(0.0, by*by, by*by + bz*bz);
159 scrh0 = sqrt(scrh1*scrh1 + 4.0*a2*At2);
163 cf2 = 0.5*(a2 + A2 + scrh0);
172 alpha_f = (a2 - cs2)*scrh0;
173 alpha_s = (cf2 - a2)*scrh0;
175 alpha_f =
MAX(0.0, alpha_f);
176 alpha_s =
MAX(0.0, alpha_s);
178 alpha_f = sqrt(alpha_f);
179 alpha_s = sqrt(alpha_s);
184 SELECT (, beta_y =
DSIGN(by); ,
185 beta_y = by / scrh0; beta_z = bz / scrh0;)
187 SELECT (, beta_y = 1.0; ,
191 S = (bx >= 0.0 ? 1.0 : -1.0);
206 scrh0 = alpha_s*cs*S;
207 scrh1 = alpha_s*sqrt_rho*
a;
212 Rp[
RHO][
k] = rho*alpha_f;
213 EXPAND(Rp[VXn][k] = -cf*alpha_f; ,
214 Rp[
VXt][
k] = scrh0*beta_y; ,
215 Rp[
VXb][
k] = scrh0*beta_z;)
217 Rp[
BXt][k] = scrh1*beta_y; ,
218 Rp[
BXb][
k] = scrh1*beta_z;)
221 eta[
k] = (EXPAND( Rp[VXn][k]*dw[VXn],
223 + Rp[
VXb][k]*dw[
VXb]))*scrh2;
224 eta[
k] += (EXPAND( 0.0 ,
227 + alpha_f*dw[PRS])*scrh3;
234 Rp[
RHO][
k] = rho*alpha_f;
235 EXPAND(Rp[VXn][k] = cf*alpha_f; ,
236 Rp[
VXt][
k] = -scrh0*beta_y; ,
237 Rp[
VXb][
k] = -scrh0*beta_z;)
238 EXPAND(, Rp[
BXt][k] = scrh1*beta_y; ,
239 Rp[
BXb][
k] = scrh1*beta_z;)
242 eta[
k] = (EXPAND( Rp[VXn][k]*dw[VXn],
244 + Rp[
VXb][k]*dw[
VXb]))*scrh2;
245 eta[
k] += (EXPAND( 0.0,
248 + alpha_f*dw[PRS])*scrh3;
257 eta[
k] = dw[
RHO] - dw[PRS]/a2;
268 #if DIVB_CONTROL == EIGHT_WAVES
272 Rc[
BXn][
k] = eta[
k] = 0.0;
280 scrh0 = alpha_f*cf*S;
281 scrh1 = alpha_f*sqrt_rho*
a;
284 Rp[
RHO][
k] = rho*alpha_s;
285 EXPAND(Rp[VXn][k] = -cs*alpha_s; ,
286 Rp[
VXt][
k] = -scrh0*beta_y; ,
287 Rp[
VXb][
k] = -scrh0*beta_z;)
288 EXPAND(, Rp[
BXt][k] = -scrh1*beta_y; ,
289 Rp[
BXb][
k] = -scrh1*beta_z;)
292 eta[
k] = (EXPAND( Rp[VXn][k]*dw[VXn],
294 + Rp[
VXb][k]*dw[
VXb]))*scrh2;
295 eta[
k] +=(EXPAND( 0.0 ,
298 +alpha_s*dw[PRS])*scrh3;
305 Rp[
RHO][
k] = rho*alpha_s;
306 EXPAND(Rp[VXn][k] = cs*alpha_s; ,
307 Rp[
VXt][
k] = scrh0*beta_y; ,
308 Rp[
VXb][
k] = scrh0*beta_z;)
310 EXPAND ( , Rp[
BXt][k] = -scrh1*beta_y; ,
311 Rp[
BXb][
k] = -scrh1*beta_z;)
314 eta[
k] = (EXPAND( Rp[VXn][k]*dw[VXn],
316 + Rp[
VXb][k]*dw[
VXb]))*scrh2;
317 eta[
k] +=(EXPAND( 0.0 ,
320 +alpha_s*dw[PRS])*scrh3;
334 Rp[
BXt][
k] = -scrh3*sqrt_rho*S;
335 Rp[
BXb][
k] = scrh2*sqrt_rho*S;
346 Rp[
BXt][
k] = scrh3*sqrt_rho*S;
347 Rp[
BXb][
k] = -scrh2*sqrt_rho*S;
367 for (k = 0; k <
NFLX; k++) {
369 EXPAND (Rc[
MXn][k] = u*Rp[
RHO][k] + rho*Rp[VXn][k]; ,
372 EXPAND (Rc[
BXn][k] = Rp[
BXn][k]; ,
376 scrh0 = EXPAND(u*Rp[VXn][k], + v*Rp[
VXt][k], + w*Rp[
VXb][k]);
377 scrh1 = EXPAND(b1x*Rp[
BXn][k], + b1y*Rp[
BXt][k], + b1z*Rp[
BXb][k]);
378 Rc[ENG][
k] = 0.5*vel2*Rp[
RHO][
k] + rho*scrh0
379 + scrh1 + Rp[PRS][
k]*gmm1_inv;
384 cmax[
i] = fabs (u) + cf;
392 for (nv = 0; nv <
NFLX; nv++) {
394 for (k = 0; k <
NFLX; k++) {
395 scrh1 = fabs(lambda[k]);
396 if ((k ==
KFASTM || k ==
KFASTP || k == KSLOWM || k == KSLOWP)
397 && scrh1 < 0.5*delta){
398 scrh1 = scrh1*scrh1/delta + 0.25*delta;
400 scrh0 += scrh1*eta[
k]*Rc[nv][
k];
402 state->
flux[
i][nv] = 0.5*(fL[
i][nv] + fR[
i][nv] - scrh0);
404 state->
press[
i] = 0.5*(pL[
i] + pR[
i]);
407 #if DIVB_CONTROL == EIGHT_WAVES
408 ROE_DivBSource (state, grid, beg, end);
void GLM_Solve(const State_1D *state, double **VL, double **VR, int beg, int end, Grid *grid)
double ** flux
upwind flux computed with the Riemann solver
void Flux(double **u, double **w, double *a2, double **fx, double *p, int beg, int end)
double * SR
Rightmost velocity in the Riemann fan at i+1/2.
double ** vR
Primitive variables to the right of the interface, .
double ** GetBackgroundField(int beg, int end, int where, Grid *grid)
void SoundSpeed2(double **v, double *cs2, double *h, int beg, int end, int pos, Grid *grid)
double g_maxMach
The maximum Mach number computed during integration.
double * SL
Leftmost velocity in the Riemann fan at i+1/2.
double ** uR
same as vR, in conservative vars
#define ARRAY_1D(nx, type)
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
void PrimToCons(double **uprim, double **ucons, int ibeg, int iend)
void BACKGROUND_FIELD(real x1, real x2, real x3, real *B0)
double ** vL
Primitive variables to the left of the interface, .
double * press
Upwind pressure term computed with the Riemann solver.
#define FLAG_HLL
Use HLL Riemann solver.
#define ARRAY_2D(nx, ny, type)
double glm_ch
The propagation speed of divergence error.
double ** uL
same as vL, in conservative vars