PLUTO
rusanov-dw.c
Go to the documentation of this file.
1 #include "pluto.h"
2 
3 /* ********************************************************************* */
4 void RusanovDW_Solver (const State_1D *state, int beg, int end,
5  double *cmax, Grid *grid)
6 /*!
7  * Solve the Riemann problem for the relativistic MHD equations
8  * using the dominant-wave Riemann solver.
9  *
10  * LAST_MODIFIED
11  *
12  * Feb 04/2013 by Andrea Mignone (mignone@ph.unito.it)
13  *
14  **************************************************************************** */
15 {
16  int nv, i;
17  double *uL, *uR, *flux, cL, cR, lambda;
18  static double **fL, *pL, *a2L, *hL, *cmin_L, *cmax_L;
19  static double **fR, *pR, *a2R, *hR, *cmin_R, *cmax_R;
20  static double **VL, **VR, **UL, **UR;
21 double num, den, dU, dF, vn;
22 
23  if (fR == NULL){
24  fR = ARRAY_2D(NMAX_POINT, NFLX, double);
25  fL = ARRAY_2D(NMAX_POINT, NFLX, double);
26  pR = ARRAY_1D(NMAX_POINT, double);
27  pL = ARRAY_1D(NMAX_POINT, double);
28  cmin_R = ARRAY_1D(NMAX_POINT, double);
29  cmin_L = ARRAY_1D(NMAX_POINT, double);
30  cmax_R = ARRAY_1D(NMAX_POINT, double);
31  cmax_L = ARRAY_1D(NMAX_POINT, double);
32  #ifdef GLM_MHD
33  VL = ARRAY_2D(NMAX_POINT, NVAR, double);
34  VR = ARRAY_2D(NMAX_POINT, NVAR, double);
35  UL = ARRAY_2D(NMAX_POINT, NVAR, double);
36  UR = ARRAY_2D(NMAX_POINT, NVAR, double);
37  #endif
38 
39  a2R = ARRAY_1D(NMAX_POINT, double);
40  a2L = ARRAY_1D(NMAX_POINT, double);
41  hR = ARRAY_1D(NMAX_POINT, double);
42  hL = ARRAY_1D(NMAX_POINT, double);
43  }
44 
45 /* ----------------------------------------------------
46  redefine states if GLM_MHD is used
47  ---------------------------------------------------- */
48 
49  #ifdef GLM_MHD
50  GLM_Solve (state, VL, VR, beg, end, grid);
51  PrimToCons (VL, UL, beg, end);
52  PrimToCons (VR, UR, beg, end);
53  #else
54  VL = state->vL; UL = state->uL;
55  VR = state->vR; UR = state->uR;
56  #endif
57 
58 /* ----------------------------------------------------
59  compute sound speed & fluxes at zone interfaces
60  ---------------------------------------------------- */
61 
62  SoundSpeed2 (VL, a2L, hL, beg, end, FACE_CENTER, grid);
63  SoundSpeed2 (VR, a2R, hR, beg, end, FACE_CENTER, grid);
64 
65  Flux (UL, VL, hL, fL, pL, beg, end);
66  Flux (UR, VR, hR, fR, pR, beg, end);
67 
68 /* -------------------------------------------------------------------
69  compute Max and min eigenvalues for the left and right states
70  ------------------------------------------------------------------- */
71 
72  MaxSignalSpeed (VL, a2L, hL, cmin_L, cmax_L, beg, end);
73  MaxSignalSpeed (VR, a2R, hR, cmin_R, cmax_R, beg, end);
74 
75  for (i = beg; i <= end; i++) {
76 
77  uL = UL[i];
78  uR = UR[i];
79  flux = state->flux[i];
80 
81  /* -- compute local max eigenvalue -- */
82 
83  cL = MAX(fabs(cmax_L[i]), fabs(cmin_L[i]));
84  cR = MAX(fabs(cmax_R[i]), fabs(cmin_R[i]));
85  cmax[i] = MAX(cL, cR);
86  state->SL[i] = -cmax[i];
87  state->SR[i] = cmax[i];
88 
89 num = den = 0.0;
90 lambda = 1.0;
91 for (nv = 0; nv < NFLX; nv++) {
92  dU = uR[nv] - uL[nv];
93  dF = fR[i][nv] - fL[i][nv] + (nv == MXn ? (pR[i] - pL[i]):0.0);
94 
95  num += dU*dF;
96  den += dU*dU;
97 }
98 lambda = fabs(num)/(fabs(den) + 1.e-12);
99 
100 if (lambda > cmax[i]) lambda = cmax[i];
101 
102 vn = 0.5*( fabs(state->vR[i][VXn]) + fabs(state->vL[i][VXn]) );
103 vn = MAX( fabs(state->vR[i][VXn]), fabs(state->vL[i][VXn]) );
104 if (lambda < vn) lambda = vn;
105 
106 /*
107 cL = MIN(fabs(cmax_L[i]), fabs(cmin_L[i]));
108 cR = MIN(fabs(cmax_R[i]), fabs(cmin_R[i]));
109 */
110 
111  /* -- compute Rusanov flux -- */
112 
113  for (nv = NFLX; nv--; ) {
114  flux[nv] = 0.5*(fL[i][nv] + fR[i][nv] - lambda*(uR[nv] - uL[nv]));
115  }
116  state->press[i] = 0.5*(pL[i] + pR[i]);
117  }
118 
119 /* --------------------------------------------------------
120  initialize source term
121  -------------------------------------------------------- */
122 
123  #if DIVB_CONTROL == EIGHT_WAVES
124  POWELL_DIVB_SOURCE (state, beg, end, grid);
125  #endif
126 }
#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
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
void Flux(double **u, double **w, double *a2, double **fx, double *p, int beg, int end)
Definition: fluxes.c:23
double * SR
Rightmost velocity in the Riemann fan at i+1/2.
Definition: structs.h:167
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
void SoundSpeed2(double **v, double *cs2, double *h, int beg, int end, int pos, Grid *grid)
Definition: eos.c:16
#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
void RusanovDW_Solver(const State_1D *state, int beg, int end, double *cmax, Grid *grid)
Definition: rusanov-dw.c:4
int MXn
Definition: globals.h:74
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
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
void MaxSignalSpeed(double **v, double *cs2, double *cmin, double *cmax, int beg, int end)
Definition: eigenv.c:34
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
void POWELL_DIVB_SOURCE(const State_1D *, int, int, Grid *)
Definition: source.c:5
#define NVAR
Definition: pluto.h:609
double ** uL
same as vL, in conservative vars
Definition: structs.h:144