PLUTO
TagCells.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <string>
3 using std::string;
4 
5 #include "PatchPluto.H"
6 #include "LoHiSide.H"
7 
8 
9 #if (EOS != ISOTHERMAL) && (AMR_EN_SWITCH == NO)
10  #define REF_VAR ENG
11 #else
12  #define REF_VAR RHO
13 #endif
14 
15 
16 //#define REF_VAR -1 /* means user-defined */
17 
18 #define REF_CRIT 1 /* 1 == first derivative, 2 == second derivative */
19 
20 /* ************************************************************************* */
21 //void PatchPluto::computeRefGradient(FArrayBox& gFab, FArrayBox& UFab, const Box& b)
22 void PatchPluto::computeRefGradient(FArrayBox& gFab, FArrayBox& UFab,
23  const FArrayBox& a_dV, const Box& b)
24 
25 /*
26  *
27  * PURPOSE
28  *
29  * Tag cells for refinement by computing grad[k][j][i].
30  * By default a convex combination of the first and second
31  * derivative of the total energy density is used.
32  *
33  * REF_CRIT = 1 --> triggers refinement towards the 1st derivative
34  * REF_CRIT = 2 --> triggers refinement towards the 2nd derivative
35  *
36  *
37  *
38  *************************************************************************** */
39 {
40  CH_assert(m_isDefined);
41 
42  int nv, i, j, k;
43  int Uib, Uie, Ujb=0, Uje=0, Ukb=0, Uke=0;
44  int Gib, Gie, Gjb=0, Gje=0, Gkb=0, Gke=0;
45 
46  double rp, rm, r;
47  double x, dqx_p, dqx_m, dqx, d2qx, den_x;
48  double y, dqy_p, dqy_m, dqy, d2qy, den_y;
49  double z, dqz_p, dqz_m, dqz, d2qz, den_z;
50 
51  double qref, gr1, gr2;
52 
53  double eps = 0.1;
54  double ***UU[NVAR], ***grad;
55  RBox Ubox, Gbox;
56 
57  double us[NVAR], vs[NVAR];
58  double pm = 0.0, Kin;
59  double **rho, **Bx, **By, dx0,xi,chi_r;
60 
61 dx0 = 12.8*2/64.0;
62 
63  rp = rm = r = 1.0;
64 
65 /* -----------------------------------------------
66  The solution array U is defined on the box
67  [Uib, Uie] x [Ujb, Uje] x [Ukb, Uke], which
68  differs from that of gFab ([Gib,...Gke]),
69  typically one point larger in each direction.
70  ----------------------------------------------- */
71 
72  Ubox.jb = Ubox.je = Ubox.kb = Ubox.ke = 0;
73  Gbox.jb = Gbox.je = Gbox.kb = Gbox.ke = 0;
74 
75  D_EXPAND(Ubox.ib = UFab.loVect()[IDIR]; Ubox.ie = UFab.hiVect()[IDIR]; ,
76  Ubox.jb = UFab.loVect()[JDIR]; Ubox.je = UFab.hiVect()[JDIR]; ,
77  Ubox.kb = UFab.loVect()[KDIR]; Ubox.ke = UFab.hiVect()[KDIR]; );
78 
79  D_EXPAND(Gbox.ib = gFab.loVect()[IDIR]; Gbox.ie = gFab.hiVect()[IDIR]; ,
80  Gbox.jb = gFab.loVect()[JDIR]; Gbox.je = gFab.hiVect()[JDIR]; ,
81  Gbox.kb = gFab.loVect()[KDIR]; Gbox.ke = gFab.hiVect()[KDIR]; );
82 
83  for (nv = 0; nv < NVAR; nv++){
84  UU[nv] = ArrayBoxMap(Ubox.kb, Ubox.ke,
85  Ubox.jb, Ubox.je,
86  Ubox.ib, Ubox.ie, UFab.dataPtr(nv));
87  }
88  grad = ArrayBoxMap(Gbox.kb, Gbox.ke,
89  Gbox.jb, Gbox.je,
90  Gbox.ib, Gbox.ie, gFab.dataPtr(0));
91 
92 /* -- check ref criterion -- */
93 
94  #if REF_CRIT != 1 && REF_CRIT != 2
95  print ("! TagCells.cpp: Refinement criterion not valid\n");
96  QUIT_PLUTO(1);
97  #endif
98 
99 /* -----------------------------------------------
100  Main spatial loop for zone tagging based on
101  1st (REF_CRIT = 1) or 2nd (REF_CRIT = 2)
102  derivative error norm.
103  ----------------------------------------------- */
104 
105  Bx = UU[BX1][0];
106  By = UU[BX2][0];
107  rho = UU[RHO][0];
108  xi = fabs(dx0/m_dx - 1.0);
109  chi_r = (0.2 - 0.37)/(1.0 + xi*xi) + 0.37;
110 
111 /* ----------------------------------------------------------------
112  Main spatial loop for zone tagging based on 1st (REF_CRIT = 1)
113  or 2nd (REF_CRIT = 2) derivative error norm.
114  ---------------------------------------------------------------- */
115 
116  BOX_LOOP(&Gbox, k, j, i){
117  z = (k + 0.5)*m_dx + g_domBeg[KDIR];
118  y = (j + 0.5)*m_dx + g_domBeg[JDIR];
119  x = (i + 0.5)*m_dx + g_domBeg[IDIR];
120 
121  #if GEOMETRY == CYLINDRICAL
122  rp = (i+0.5)/(i+1.5);
123  rm = (i+0.5)/(i-0.5);
124  #endif
125 
126  dqx = 0.5*(UU[BY][k][j][i+1] - UU[BY][k][j][i-1]);
127  dqy = 0.5*(UU[BX][k][j+1][i] - UU[BX][k][j-1][i]);
128 
129  pm = rho[j][i];
130  gr1 = fabs(dqx - dqy)/(fabs(dqx) + fabs(dqy) + m_dx/dx0*sqrt(pm));
131  grad[k][j][i] = gr1/chi_r;
132  }
133 
134 /* --------------------------------------------------------------
135  Ok, grad[] has been computed. Now Free memory.
136  -------------------------------------------------------------- */
137 
138  FreeArrayBoxMap(grad, Gbox.kb, Gbox.ke, Gbox.jb, Gbox.je, Gbox.ib, Gbox.ie);
139  for (nv = 0; nv < NVAR; nv++){
140  FreeArrayBoxMap(UU[nv], Ubox.kb, Ubox.ke, Ubox.jb, Ubox.je, Ubox.ib, Ubox.ie);
141  }
142  #if CHOMBO_REFINEMENT_VAR == -1
143  FreeArrayBox(q, Ubox.kb, Ubox.jb, Ubox.ib);
144  #endif
145 }
146 #undef REF_VAR
147 #undef REF_CRIT
#define BY
Definition: mod_defs.h:109
int jb
Lower corner index in the x2 direction.
Definition: structs.h:349
#define RHO
Definition: mod_defs.h:19
#define BOX_LOOP(B, k, j, i)
Definition: macros.h:70
int kb
Lower corner index in the x3 direction.
Definition: structs.h:351
void FreeArrayBox(double ***t, long nrl, long ncl, long ndl)
Definition: arrays.c:403
#define KDIR
Definition: pluto.h:195
int ib
Lower corner index in the x1 direction.
Definition: structs.h:347
#define BX
Definition: mod_defs.h:108
#define eps
#define IDIR
Definition: pluto.h:193
static double Bx
Definition: hlld.c:62
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
double g_domBeg[3]
Lower limits of the computational domain.
Definition: globals.h:125
double * x
Definition: structs.h:80
D_EXPAND(tot/[n]=(double) grid[IDIR].np_int_glob;, tot/[n]=(double) grid[JDIR].np_int_glob;, tot/[n]=(double) grid[KDIR].np_int_glob;)
Definition: analysis.c:27
int i
Definition: analysis.c:2
int ie
Upper corner index in the x1 direction.
Definition: structs.h:348
int ke
Upper corner index in the x3 direction.
Definition: structs.h:352
int je
Upper corner index in the x2 direction.
Definition: structs.h:350
#define BX1
Definition: mod_defs.h:25
double *** ArrayBoxMap(int nrl, int nrh, int ncl, int nch, int ndl, int ndh, double *uptr)
Definition: arrays.c:537
void FreeArrayBoxMap(double ***t, int nrl, int nrh, int ncl, int nch, int ndl, int ndh)
Definition: arrays.c:586
#define BX2
Definition: mod_defs.h:26
#define JDIR
Definition: pluto.h:194
#define NVAR
Definition: pluto.h:609
Definition: structs.h:346
static Runtime q
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
double xi
Definition: structs.h:79