PLUTO
riemann_full.c
Go to the documentation of this file.
1 #include "pluto.h"
2 
3 #define MAX_ITER 20
4 #define small_p 1.e-9
5 #define small_rho 1.e-9
6 
7 static void PFUN (real p, real *vL, real *vR, real *f, real *df);
8 static void FUN_LR (real p, real *v, real *fLR, real *dfLR);
9 
10 /* ***************************************************************************** */
11 void TWO_SHOCK (const State_1D *state, real *cmax, Grid *grid)
12 /*
13  *
14  * NAME
15  *
16  * RIEMANN
17  *
18  *
19  * PURPOSE
20  *
21  *
22  * LAST_MODIFIED
23  *
24  * April 4th 2006, by Andrea Mignone (mignone@to.astro.it)
25  *
26  *
27  ******************************************************************************* */
28 {
29  int nv, k, i, beg, end;
30  real pstar, ustar, dp, fp, dfp;
31  real th, q, scrh, gmmp, gp1, gm1;
32  real *vL, *vR;
33  real fL, dfL, SL, STL, csL;
34  real fR, dfR, SR, STR, csR;
35  static real *s, **vs, **us, *cmax_loc;
36  static int *shock;
37 
38  if (vs == NULL){
39  vs = array_2D(NMAX_POINT, NVAR);
40  us = array_2D(NMAX_POINT, NVAR);
41  s = array_1D(NMAX_POINT);
42  cmax_loc = array_1D(NMAX_POINT);
43  shock = int_array_1D(NMAX_POINT);
44  }
45 
46  beg = grid[g_dir].lbeg - 1;
47  end = grid[g_dir].lend;
48 
49  gm1 = g_gamma - 1.0;
50  gp1 = g_gamma + 1.0;
51  gmmp = gm1/gp1;
52 
53  for (i = beg; i <= end; i++){
54 
55  vL = state->vL[i];
56  vR = state->vR[i];
57  s[i] = 0.0;
58 
59  /* -- guess here -- */
60 
61  pstar = 0.5*(vL[PRS] + vR[PRS]);
62 
63  for (k = 0; k < MAX_ITER; k++){
64 
65  PFUN (pstar, vL, vR, &fp, &dfp);
66  dp = fp/dfp;
67  pstar -= dp;
68 
69  if (fabs(dp) < 1.e-7*pstar) break;
70  if (k == (MAX_ITER-5)){
71  print ("! Too many iterations in Rieman\n");
72  Show(state->vL,i);
73  Show(state->vR,i);
74 
75  QUIT_PLUTO(1);
76  }
77  }
78 
79  FUN_LR (pstar, vL, &fL, &dfL);
80  FUN_LR (pstar, vR, &fR, &dfR);
81 
82  ustar = 0.5*(vL[VXn] + vR[VXn] + fR - fL);
83 
84  /* -- sample solution -- */
85 
86  if (s[i] <= ustar){ /* -- left of CD -- */
87  q = pstar/vL[PRS];
88  csL = sqrt(g_gamma*vL[PRS]/vL[RHO]);
89 
90  if (q > 1.0) { /* -- left wave is a shock -- */
91 
92  scrh = gp1*q + gm1;
93  SL = vL[VXn] - csL*sqrt(0.5/g_gamma*scrh);
94  if (s[i] < SL){
95  for (nv = NVAR; nv--; ) vs[i][nv] = vL[nv];
96  }else {
97  vs[i][RHO] = vL[RHO]*(q + gmmp)/(gmmp*q + 1.0);
98  vs[i][VXn] = ustar;
99  vs[i][PRS] = pstar;
100  }
101 
102  }else{ /* -- left wave is a rarefaction -- */
103 
104  SL = vL[VXn] - csL;
105 
106  if (s[i] < SL) {
107  for (nv = NVAR; nv--; ) vs[i][nv] = vL[nv];
108  }else {
109  vs[i][RHO] = vL[RHO]*pow(q, 1.0/g_gamma);
110  vs[i][VXn] = ustar;
111  vs[i][PRS] = pstar;
112  STL = ustar - sqrt(g_gamma*pstar/vs[i][RHO]);
113  if (s[i] < STL){ /* -- sol inside rarefaction -- */
114  scrh = 2.0 + gm1/csL*(vL[VXn] - s[i]);
115  vs[i][RHO] = vL[RHO]*pow(scrh/gp1, 2.0/gm1);
116  vs[i][PRS] = vL[PRS]*pow(scrh/gp1, 2.0*g_gamma/gm1);
117  vs[i][VXn] = 2.0/gp1*(csL + 0.5*gm1*vL[VXn] + s[i]);
118  }
119  }
120  }
121 
122  }else{ /* -- right of CD -- */
123 
124  q = pstar/vR[PRS];
125  csR = sqrt(g_gamma*vR[PRS]/vR[RHO]);
126 
127  if (q > 1.0) { /* -- right wave is a shock -- */
128 
129  scrh = gp1*q + gm1;
130  SR = vR[VXn] + csR*sqrt(0.5/g_gamma*scrh);
131  if (s[i] > SR){
132  for (nv = NVAR; nv--; ) vs[i][nv] = vR[nv];
133  }else {
134  vs[i][RHO] = vR[RHO]*(q + gmmp)/(gmmp*q + 1.0);
135  vs[i][VXn] = ustar;
136  vs[i][PRS] = pstar;
137  }
138 
139  }else{ /* -- right wave is a rarefaction -- */
140 
141  SR = vR[VXn] + csR;
142 
143  if (s[i] > SR) {
144  for (nv = NVAR; nv--; ) vs[i][nv] = vR[nv];
145  }else {
146  vs[i][RHO] = vR[RHO]*pow(q, 1.0/g_gamma);
147  vs[i][VXn] = ustar;
148  vs[i][PRS] = pstar;
149  STR = ustar + sqrt(g_gamma*pstar/vs[i][RHO]);
150  if (s[i] > STR){ /* -- sol inside rarefaction -- */
151  scrh = 2.0 - gm1/csR*(vR[VXn] - s[i]);
152  vs[i][RHO] = vR[RHO]*pow(scrh/gp1, 2.0/gm1);
153  vs[i][PRS] = vR[PRS]*pow(scrh/gp1, 2.0*g_gamma/gm1);
154  vs[i][VXn] = 2.0/gp1*(-csR + 0.5*gm1*vR[VXn] + s[i]);
155  }
156  }
157  }
158  }
159 
160  if (ustar > 0.0) {
161  EXPAND( ,
162  vs[i][VXt] = vL[VXt]; ,
163  vs[i][VXb] = vL[VXb];)
164  }else{
165  EXPAND( ,
166  vs[i][VXt] = vR[VXt]; ,
167  vs[i][VXb] = vR[VXb];)
168  }
169 
170  }
171 
172 /* -- compute fluxes -- */
173 
174  MAX_CH_SPEED (vs, cmax_loc, grid, beg, end);
175  for (i = beg; i <= end; i++) {
176  *cmax = MAX(cmax_loc[i], *cmax);
177  }
178  FLUX(us, vs, state->flux, state->press, beg, end);
179 
180 }
181 
182 /* ************************************************ */
183 void PFUN (real p, real *vL, real *vR, real *f, real *df)
184 /*
185  *
186  *
187  *
188  *
189  ************************************************** */
190 {
191  real fL , fR;
192  real dfL, dfR;
193 
194  FUN_LR (p, vL, &fL, &dfL);
195  FUN_LR (p, vR, &fR, &dfR);
196 
197  *f = fL + fR + vR[VXn] - vL[VXn];
198  *df = dfL + dfR;
199 }
200 
201 /* ************************************************ */
202 void FUN_LR (real p, real *v, real *fLR, real *dfLR)
203 /*
204  *
205  *
206  *
207  *
208  ************************************************** */
209 {
210  real A, B, scrh, cs;
211  real q;
212 
213  if (p > v[PRS]) { /* -- (shock) -- */
214 
215  A = 2.0/(g_gamma + 1.0)/v[RHO];
216  B = (g_gamma - 1.0)/(g_gamma + 1.0)*v[PRS];
217  scrh = A/(p + B);
218  *fLR = (p - v[PRS])*sqrt(scrh);
219  *dfLR = sqrt(scrh)*(1.0 - 0.5*(p - v[PRS])/(B + p));
220 
221  }else{ /* -- (rarefaction) -- */
222 
223  cs = sqrt(g_gamma*v[PRS]/v[RHO]);
224  q = p/v[PRS];
225  scrh = pow(q, 0.5*(g_gamma - 1.0)/g_gamma) - 1.0;
226  *fLR = 2.0*cs/(g_gamma - 1.0)*scrh;
227  scrh = pow(q, -0.5*(g_gamma + 1.0)/g_gamma);
228  *dfLR = 1.0/(v[RHO]*cs)*scrh;
229  }
230 
231 }
232 
233 
#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
double real
Definition: pluto.h:488
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
int lend
Local end index for the local array.
Definition: structs.h:118
int lbeg
Local start index for the local array.
Definition: structs.h:117
static void FUN_LR(real p, real *v, real *fLR, real *dfLR)
Definition: riemann_full.c:202
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
int VXb
Definition: globals.h:73
#define MAX_ITER
Definition: riemann_full.c:3
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
void TWO_SHOCK(const State_1D *state, real *cmax, Grid *grid)
Definition: riemann_full.c:11
Definition: structs.h:78
int VXt
Definition: globals.h:73
int k
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int VXn
Definition: globals.h:73
#define s
double ** array_2D(int nx, int ny)
Definition: Turbulence.c:111
PLUTO main header file.
void Show(double **, int)
Definition: tools.c:132
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
int i
Definition: analysis.c:2
FILE * fp
Definition: analysis.c:7
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 NVAR
Definition: pluto.h:609
static Runtime q
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
static void PFUN(real p, real *vL, real *vR, real *f, real *df)
Definition: riemann_full.c:183