PLUTO
flatten.c
Go to the documentation of this file.
1 #include"pluto.h"
2 
3 /* ********************************************************************** */
4 void Flatten (const State_1D *state, int beg, int end, Grid *grid)
5 /*
6  *
7  * Flatten distribution using
8  *
9  * - multidimensional flattening (revert to minmod limiter)
10  * - oned flattening (decrease slopes as in the original
11  * PPM algorithm)
12  *
13  *
14  *
15  ************************************************************************ */
16 #if SHOCK_FLATTENING == ONED
17 
18 /* -----------------------------------------
19  One dimensional shock flattening:
20  Requires 7 point stencil:
21 
22  |---|---|---|---|---|---|---|
23  i
24  f_t o o o
25  x x x x x x x
26 
27  It is kept mostly for backward
28  compatibility reasons.
29  ----------------------------------------- */
30 
31  /* ---- PPM PARAMETERS ---- */
32 
33 #if PHYSICS == HD
34 
35  #define EPS2 0.33
36  #define OME1 0.75
37  #define OME2 10.0
38 
39 #endif
40 
41 #if PHYSICS == MHD
42 
43  #define EPS2 0.33
44  #define OME1 0.75
45  #define OME2 10.0
46 
47 #endif
48 
49 #if PHYSICS == RHD || PHYSICS == RMHD
50 
51  #define EPS2 1.0
52  #define OME1 0.52
53  #define OME2 10.0
54 
55 #endif
56 
57 {
58  int i, nv, sj;
59  double scrh, dp, d2p, min_p, vf, fj;
60  real **v, **vp, **vm;
61  static real *f_t;
62 
63  #if EOS == ISOTHERMAL
64  int PRS = RHO;
65  #endif
66 
67  if (f_t == NULL){
68  f_t = ARRAY_1D(NMAX_POINT, double);
69  }
70 
71  v = state->v;
72  vp = state->vp;
73  vm = state->vm;
74 
75 /* ---------------------------------------------------------
76  the following constraints is necessary for
77  a particular combinations of algorithms:
78 
79  - CTU + CT + MHD + userdef boundary
80  - shock flattening.
81 
82  This is necessary when user defined boundary conditions
83  are used in the fully corner coupled unsplit schemes
84  (HANCOCK and CHARACTERISTIC_TRACING), since the
85  grid is expanded by one point in the userdef boundary
86  to get the correct electric field
87  (see the EXPAND_CTU_GRID in unsplit_ctu.c).
88  -------------------------------------------------------- */
89 
90  beg = MAX(beg, 3);
91  end = MIN(end, grid[g_dir].np_tot - 4);
92 
93  for (i = beg - 1; i <= end + 1; i++) {
94  dp = v[i + 1][PRS] - v[i - 1][PRS];
95  min_p = MIN(v[i + 1][PRS], v[i - 1][PRS]);
96  d2p = v[i + 2][PRS] - v[i - 2][PRS];
97  scrh = fabs(dp)/min_p;
98  if (scrh < EPS2 || (v[i + 1][VXn] > v[i - 1][VXn])){
99  f_t[i] = 0.0;
100  }else{
101  scrh = OME2*(fabs(dp/d2p) - OME1);
102  scrh = MIN(1.0, scrh);
103  f_t[i] = MAX(0.0, scrh);
104  }
105  }
106 
107  for (i = beg; i <= end; i++) {
108  sj = (v[i + 1][PRS] < v[i - 1][PRS] ? 1 : -1);
109  fj = MAX(f_t[i], f_t[i + sj]);
110  for (nv = 0; nv < NVAR; nv++){
111  vf = v[i][nv]*fj;
112  scrh = 1.0 - fj;
113  vm[i][nv] = vf + vm[i][nv]*scrh;
114  vp[i][nv] = vf + vp[i][nv]*scrh;
115  }
116  }
117 
118 /*
119  int beg, end, i, nv, sj;
120  real scrh1, scrh2, scrh3;
121  real **a, **ap, **am;
122  static real *f_t, *fj, *dp, *d2p, *min_p;
123 
124  #if EOS == ISOTHERMAL
125  int PR = DN;
126  #endif
127 
128  if (dp == NULL){
129  f_t = ARRAY_1D(NMAX_POINT, double);
130  fj = ARRAY_1D(NMAX_POINT, double);
131  dp = ARRAY_1D(NMAX_POINT, double);
132  d2p = ARRAY_1D(NMAX_POINT, double);
133  min_p = ARRAY_1D(NMAX_POINT, double);
134  }
135 
136  a = state->v;
137  ap = state->vp;
138  am = state->vm;
139 
140  beg = grid[g_dir].lbeg - 1;
141  end = grid[g_dir].lend + 1;
142 
143  beg = MAX(beg, 3);
144  end = MIN(end, grid[g_dir].np_tot - 3);
145 
146  for (i = beg - 2; i <= end + 2; i++) {
147  dp[i] = a[i + 1][PRS] - a[i - 1][PRS];
148  min_p[i] = MIN(a[i + 1][PRS], a[i - 1][PRS]);
149  }
150  for (i = beg - 1; i <= end + 1; i++) {
151  d2p[i] = a[i + 2][PRS] - a[i - 2][PRS];
152  }
153 
154  for (i = beg - 1; i <= end + 1; i++) {
155  scrh1 = fabs(dp[i]) / min_p[i];
156  scrh2 = a[i + 1][VXn] - a[i - 1][VXn];
157  if (scrh1 < EPS2 || scrh2 > 0.0){
158  f_t[i] = 0.0;
159  }else{
160  scrh3 = OME2*(fabs(dp[i]/d2p[i]) - OME1);
161  scrh3 = MIN(1.0, scrh3);
162  f_t[i] = MAX(0.0, scrh3);
163  }
164  }
165 
166  for (i = beg; i <= end; i++) {
167  sj = (dp[i] < 0.0 ? 1 : -1);
168  fj[i] = MAX(f_t[i], f_t[i + sj]);
169  }
170 
171  for (i = beg; i <= end; i++) {
172  for (nv = 0; nv < NVAR; nv++){
173  scrh1 = a[i][nv]*fj[i];
174  scrh2 = 1.0 - fj[i];
175  am[i][nv] = scrh1 + am[i][nv]*scrh2;
176  ap[i][nv] = scrh1 + ap[i][nv]*scrh2;
177  }}
178 */
179 
180 }
181 #undef EPS2
182 #undef OME1
183 #undef OME2
184 #else
185 {
186 
187 }
188 #endif
189 
#define MAX(a, b)
Definition: macros.h:101
double ** v
Cell-centered primitive varables at the base time level, v[i] = .
Definition: structs.h:134
int end
Global end index for the local array.
Definition: structs.h:116
double real
Definition: pluto.h:488
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
#define OME1
#define EPS2
#define OME2
double ** vp
prim vars at i+1/2 edge, vp[i] = vL(i+1/2)
Definition: structs.h:142
#define MIN(a, b)
Definition: macros.h:104
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int beg
Global start index for the local array.
Definition: structs.h:115
Definition: structs.h:78
void Flatten(const State_1D *state, int beg, int end, Grid *grid)
Definition: flatten.c:4
int VXn
Definition: globals.h:73
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
Definition: structs.h:141
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
int i
Definition: analysis.c:2
int np_tot
Total number of points in the local domain (boundaries included).
Definition: structs.h:100
#define NVAR
Definition: pluto.h:609