PLUTO
hllc.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief HLLC Riemann solver for MHD.
5 
6  Solve the Riemann problem for the adiabatic MHD equations using
7  a modified version of the HLLC Riemann solver of Li (2005).
8  The isothermal version has not been implemented yet.
9 
10  Our formulation differs from Li's original solver in the way
11  transverse momenta are computed.
12 
13  On input, this function takes left and right primitive state vectors
14  \c state->vL and \c state->vR at zone edge \c i+1/2;
15  On output, return flux and pressure vectors at the same interface
16  \c i+1/2 (note that the \c i refers to \c i+1/2).
17 
18  Also during this step, compute maximum wave propagation speed (cmax)
19  for explicit time step computation.
20 
21  \b Reference:
22  - "An HLLC RIemann Solver for MHD", S. Li, JCP (200) 203, 344
23 
24  \authors A. Mignone (mignone@ph.unito.it)
25  \date Dec 10, 2013
26 */
27 /* ///////////////////////////////////////////////////////////////////// */
28 #include"pluto.h"
29 
30 #if HAVE_ENERGY
31 /* ********************************************************************* */
32 void HLLC_Solver (const State_1D *state, int beg, int end,
33  double *cmax, Grid *grid)
34 /*!
35  * Solve Riemann problem for the adiabatic MHD equations using a slightly
36  * modified version of the two-state HLLC Riemann solver of Li (2005).
37  *
38  * \param[in,out] state pointer to State_1D structure
39  * \param[in] beg initial grid index
40  * \param[out] end final grid index
41  * \param[out] cmax 1D array of maximum characteristic speeds
42  * \param[in] grid pointer to array of Grid structures.
43  *
44  *********************************************************************** */
45 {
46  int nv, i;
47  double scrh;
48  double pl, pr;
49  double vBl, usl[NFLX];
50  double vBr, usr[NFLX];
51 
52  double Bxs, Bys, Bzs, ps, vBs;
53  double vxl, vxr, vxs, vys, vzs;
54  double Fhll[NFLX], alpha_l, alpha_r;
55  double **bgf, *vL, *vR, *uL, *uR, *SL, *SR;
56  static double **fL, **fR, **Uhll;
57  static double **VL, **VR, **UL, **UR;
58  static double *pL, *pR, *a2L, *a2R;
59 
60  if (fL == NULL){
61  fL = ARRAY_2D(NMAX_POINT, NFLX, double);
62  fR = ARRAY_2D(NMAX_POINT, NFLX, double);
63  Uhll = ARRAY_2D(NMAX_POINT, NFLX, double);
64  pL = ARRAY_1D(NMAX_POINT, double);
65  pR = ARRAY_1D(NMAX_POINT, double);
66  a2L = ARRAY_1D(NMAX_POINT, double);
67  a2R = ARRAY_1D(NMAX_POINT, double);
68  #ifdef GLM_MHD
69  VL = ARRAY_2D(NMAX_POINT, NVAR, double);
70  VR = ARRAY_2D(NMAX_POINT, NVAR, double);
71  UL = ARRAY_2D(NMAX_POINT, NVAR, double);
72  UR = ARRAY_2D(NMAX_POINT, NVAR, double);
73  #endif
74  }
75 
76  #if BACKGROUND_FIELD == YES
77  print ("! Background field splitting not allowed with HLLC solver\n");
78  QUIT_PLUTO(1);
79  #endif
80 
81  #ifdef GLM_MHD
82  GLM_Solve (state, VL, VR, beg, end, grid);
83  PrimToCons (VL, UL, beg, end);
84  PrimToCons (VR, UR, beg, end);
85  #else
86  VL = state->vL; UL = state->uL;
87  VR = state->vR; UR = state->uR;
88  #endif
89 
90 /* ----------------------------------------------------
91  compute sound speed & fluxes at zone interfaces
92  ---------------------------------------------------- */
93 
94  SoundSpeed2 (VL, a2L, NULL, beg, end, FACE_CENTER, grid);
95  SoundSpeed2 (VR, a2R, NULL, beg, end, FACE_CENTER, grid);
96 
97  Flux (UL, VL, a2L, bgf, fL, pL, beg, end);
98  Flux (UR, VR, a2R, bgf, fR, pR, beg, end);
99 
100  /* ----------------------------------------
101  get max and min signal velocities
102  ---------------------------------------- */
103 
104  SL = state->SL; SR = state->SR;
105  HLL_Speed (VL, VR, a2L, a2R, bgf, SL, SR, beg, end);
106 
107  for (i = beg; i <= end; i++) {
108 
109  scrh = MAX(fabs(SL[i]), fabs(SR[i]));
110  cmax[i] = scrh;
111 
112 /* --------------------------------------------
113  compute fluxes
114  -------------------------------------------- */
115 
116  if (SL[i] >= 0.0){
117 
118  for (nv = 0; nv < NFLX; nv++) {
119  state->flux[i][nv] = fL[i][nv];
120  }
121  state->press[i] = pL[i];
122 
123  }else if (SR[i] <= 0.0){
124 
125  for (nv = 0; nv < NFLX; nv++) {
126  state->flux[i][nv] = fR[i][nv];
127  }
128  state->press[i] = pR[i];
129 
130  }else{
131 
132  vL = VL[i]; uL = UL[i];
133  vR = VR[i]; uR = UR[i];
134 
135  /* ---- define hll states ---- */
136 
137  scrh = 1.0/(SR[i] - SL[i]);
138  for (nv = 0; nv < NFLX; nv++){
139  Uhll[i][nv] = SR[i]*uR[nv] - SL[i]*uL[nv]
140  + fL[i][nv] - fR[i][nv];
141  Uhll[i][nv] *= scrh;
142 
143  Fhll[nv] = SL[i]*SR[i]*(uR[nv] - uL[nv])
144  + SR[i]*fL[i][nv] - SL[i]*fR[i][nv];
145  Fhll[nv] *= scrh;
146  }
147  Uhll[i][MXn] += (pL[i] - pR[i])*scrh;
148  Fhll[MXn] += (SR[i]*pL[i] - SL[i]*pR[i])*scrh;
149 
150 #if SHOCK_FLATTENING == MULTID
151  if ((state->flag[i] & FLAG_HLL) || (state->flag[i+1] & FLAG_HLL)){
152  for (nv = NFLX; nv--; ){
153  state->flux[i][nv] = SL[i]*SR[i]*(uR[nv] - uL[nv])
154  + SR[i]*fL[i][nv] - SL[i]*fR[i][nv];
155  state->flux[i][nv] *= scrh;
156  }
157  state->press[i] = (SR[i]*pL[i] - SL[i]*pR[i])*scrh;
158  continue;
159  }
160 #endif
161 
162  /* ---- define total pressure, vB in left and right states ---- */
163 
164  pl = EXPAND(vL[BX1]*vL[BX1], + vL[BX2]*vL[BX2], + vL[BX3]*vL[BX3]);
165  pr = EXPAND(vR[BX1]*vR[BX1], + vR[BX2]*vR[BX2], + vR[BX3]*vR[BX3]);
166 
167  pl = vL[PRS] + 0.5*pl;
168  pr = vR[PRS] + 0.5*pr;
169 
170  vBl = EXPAND(vL[VX1]*vL[BX1], + vL[VX2]*vL[BX2], + vL[VX3]*vL[BX3]);
171  vBr = EXPAND(vR[VX1]*vR[BX1], + vR[VX2]*vR[BX2], + vR[VX3]*vR[BX3]);
172 
173  vxl = vL[VXn];
174  vxr = vR[VXn];
175 
176  /* ---- magnetic field ---- */
177 
178  EXPAND(Bxs = Uhll[i][BXn]; ,
179  Bys = Uhll[i][BXt]; ,
180  Bzs = Uhll[i][BXb];)
181 
182  /* ---- normal velocity vx ---- */
183 
184  vxs = Uhll[i][MXn]/Uhll[i][RHO];
185  ps = Fhll[MXn] + Bxs*Bxs - Fhll[RHO]*vxs;
186 /*
187  ps = vL[RHO]*(SL[i] - vxl)*(vxs - vxl) + pl - vL[BXn]*vL[BXn] + Bxs*Bxs;
188 */
189  vBs = EXPAND(Uhll[i][BX1]*Uhll[i][MX1], +
190  Uhll[i][BX2]*Uhll[i][MX2], +
191  Uhll[i][BX3]*Uhll[i][MX3]);
192 
193  vBs /= Uhll[i][RHO];
194 
195  usl[RHO] = uL[RHO]*(SL[i] - vxl)/(SL[i] - vxs);
196  usr[RHO] = uR[RHO]*(SR[i] - vxr)/(SR[i] - vxs);
197 
198  usl[ENG] = (uL[ENG]*(SL[i] - vxl) +
199  ps*vxs - pl*vxl - Bxs*vBs + vL[BXn]*vBl)/(SL[i] - vxs);
200  usr[ENG] = (uR[ENG]*(SR[i] - vxr) +
201  ps*vxs - pr*vxr - Bxs*vBs + vR[BXn]*vBr)/(SR[i] - vxs);
202 
203  EXPAND(usl[MXn] = usl[RHO]*vxs;
204  usr[MXn] = usr[RHO]*vxs; ,
205 
206  usl[MXt] = (uL[MXt]*(SL[i] - vxl)
207  - (Bxs*Bys - vL[BXn]*vL[BXt]))/(SL[i] - vxs);
208  usr[MXt] = (uR[MXt]*(SR[i] - vxr)
209  - (Bxs*Bys - vR[BXn]*vR[BXt]))/(SR[i] - vxs); ,
210 
211  usl[MXb] = (uL[MXb]*(SL[i] - vxl)
212  - (Bxs*Bzs - vL[BXn]*vL[BXb]))/(SL[i] - vxs);
213  usr[MXb] = (uR[MXb]*(SR[i] - vxr)
214  - (Bxs*Bzs - vR[BXn]*vR[BXb]))/(SR[i] - vxs);)
215 
216  EXPAND(usl[BXn] = usr[BXn] = Bxs; ,
217  usl[BXt] = usr[BXt] = Bys; ,
218  usl[BXb] = usr[BXb] = Bzs;)
219 
220  #ifdef GLM_MHD
221  usl[PSI_GLM] = usr[PSI_GLM] = vL[PSI_GLM];
222  #endif
223 
224  if (vxs >= 0.0){
225  for (nv = 0; nv < NFLX; nv++) {
226  state->flux[i][nv] = fL[i][nv] + SL[i]*(usl[nv] - uL[nv]);
227  }
228  state->press[i] = pL[i];
229  } else {
230  for (nv = 0; nv < NFLX; nv++) {
231  state->flux[i][nv] = fR[i][nv] + SR[i]*(usr[nv] - uR[nv]);
232  }
233  state->press[i] = pR[i];
234  }
235  }
236  }
237 
238 /* -----------------------------------------------------
239  initialize source term
240  ----------------------------------------------------- */
241 
242  #if DIVB_CONTROL == EIGHT_WAVES
243  HLL_DivBSource (state, Uhll, beg + 1, end, grid);
244  #endif
245 }
246 
247 #elif EOS == ISOTHERMAL
248 
249 /* ******************************************************************** */
250 void HLLC_Solver (const State_1D *state, int beg, int end,
251  double *cmax, Grid *grid)
252 /*
253  *
254  *
255  *
256  *********************************************************************** */
257 {
258  print1 ("! HLLC solver not implemented for Isothermal EOS\n");
259  print1 ("! Use hll or hlld instead.\n");
260  QUIT_PLUTO(1);
261 }
262 
263 #endif /* end #if on EOS */
#define MX3
Definition: mod_defs.h:22
#define MAX(a, b)
Definition: macros.h:101
void GLM_Solve(const State_1D *state, double **VL, double **VR, int beg, int end, Grid *grid)
Definition: glm.c:24
#define MX1
Definition: mod_defs.h:20
#define VX2
Definition: mod_defs.h:29
void HLL_DivBSource(const State_1D *state, double **Uhll, int beg, int end, Grid *grid)
Definition: source.c:179
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
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
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
double * SR
Rightmost velocity in the Riemann fan at i+1/2.
Definition: structs.h:167
#define PSI_GLM
Definition: mod_defs.h:34
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
#define VX1
Definition: mod_defs.h:28
void HLLC_Solver(const State_1D *state, int beg, int end, real *cmax, Grid *grid)
Definition: hllc.c:28
void SoundSpeed2(double **v, double *cs2, double *h, int beg, int end, int pos, Grid *grid)
Definition: eos.c:16
int BXn
Definition: globals.h:75
int MXt
Definition: globals.h:74
#define NFLX
Definition: mod_defs.h:32
#define FACE_CENTER
Definition: pluto.h:206
Definition: structs.h:78
double * SL
Leftmost velocity in the Riemann fan at i+1/2.
Definition: structs.h:166
#define MX2
Definition: mod_defs.h:21
unsigned char * flag
Definition: structs.h:168
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int MXn
Definition: globals.h:74
int VXn
Definition: globals.h:73
double ** uR
same as vR, in conservative vars
Definition: structs.h:145
#define BX3
Definition: mod_defs.h:27
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
#define BX1
Definition: mod_defs.h:25
void HLL_Speed(double **vL, double **vR, double *a2L, double *a2R, double *SL, double *SR, int beg, int end)
Definition: hll_speed.c:24
#define VX3
Definition: mod_defs.h:30
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 BX2
Definition: mod_defs.h:26
int BXt
Definition: globals.h:75
#define NVAR
Definition: pluto.h:609
int BXb
Definition: globals.h:75
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define GLM_MHD
Definition: glm.h:25
int MXb
Definition: globals.h:74
double ** uL
same as vL, in conservative vars
Definition: structs.h:144