PLUTO
PatchStartup.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <string>
3 using std::string;
4 
5 #include "PatchPluto.H"
6 
7 void PatchPluto::startup(FArrayBox& a_U)
8 {
9  int i, j, k;
10  int isub, jsub, ksub, nsub = 5;
11  int nxtot, nytot, nztot;
12  int nv, l_convert;
13  int ibg, ieg, jbg, jeg, kbg, keg;
14  static double **ucons, **uprim;
15  double x1, x2, x3;
16  double x1s, x2s, x3s;
17  double dx1, dx2, dx3;
18  double us[256], u_av[256], b[3];
19  double scrh, dx, cylr;
20 
21  double ***UU[NVAR];
22  Grid grid[3];
23  Box curBox = a_U.box();
24  RBox tbox;
25 
26  FArrayBox dV(curBox,CHOMBO_NDV);
27 
28  curBox.grow(-m_numGhost);
29 
30  setGrid(curBox,grid,dV); /* -- define grid -- */
31 
32  jbg = jeg = kbg = keg = 0;
33 
34  D_EXPAND(ibg = a_U.loVect()[0]; ieg = a_U.hiVect()[0]; ,
35  jbg = a_U.loVect()[1]; jeg = a_U.hiVect()[1]; ,
36  kbg = a_U.loVect()[2]; keg = a_U.hiVect()[2];)
37 
38  NX1_TOT = nxtot = ieg - ibg + 1;
39  NX2_TOT = nytot = jeg - jbg + 1;
40  NX3_TOT = nztot = keg - kbg + 1;
41 
42  if (uprim == NULL){
43  uprim = ARRAY_2D(NMAX_POINT, NVAR, double);
44  ucons = ARRAY_2D(NMAX_POINT, NVAR, double);
45  }
46 
47  for (nv=0 ; nv<NVAR ; nv ++)
48  UU[nv] = ArrayMap(nztot,nytot,nxtot,a_U.dataPtr(nv));
49 
50  /* ---- set labels ---- */
51 
52  EXPAND(MXn = VXn = VX1; ,
53  MXt = VXt = VX2; ,
54  MXb = VXb = VX3;)
55 
56  #if PHYSICS == MHD || PHYSICS == RMHD
57  EXPAND(BXn = BX1; ,
58  BXt = BX2; ,
59  BXb = BX3;)
60  #endif
61 
62  tbox.ib = 0; tbox.ie = nxtot-1;
63  tbox.jb = 0; tbox.je = nytot-1;
64  tbox.kb = 0; tbox.ke = nztot-1;
65 
66 /* --------------------------------------------------------------
67  Assign initial conditions
68  -------------------------------------------------------------- */
69 
70  BOX_LOOP(&tbox,k,j,i){
71  x3 = grid[KDIR].x[k];
72  x2 = grid[JDIR].x[j];
73  x1 = grid[IDIR].x[i];
74 
75  for (nv = 0; nv < NVAR; nv++) UU[nv][k][j][i] = u_av[nv] = 0.0;
76 
77 #ifdef GLM_MHD
78  u_av[PSI_GLM] = us[PSI_GLM] = 0.0;
79 #endif
80 
81 /* ----------------------------------------------------------------
82  Compute volume averages
83  ---------------------------------------------------------------- */
84 
85  #if INITIAL_SMOOTHING == YES
86 
87  for (ksub = 0; ksub < nsub; ksub++){
88  for (jsub = 0; jsub < nsub; jsub++){
89  for (isub = 0; isub < nsub; isub++){
90 
91  x1s = x1 + (double)(1.0 - nsub + 2.0*isub)/(double)(2.0*nsub)*dx1;
92  x2s = x2 + (double)(1.0 - nsub + 2.0*jsub)/(double)(2.0*nsub)*dx2;
93  x3s = x3 + (double)(1.0 - nsub + 2.0*ksub)/(double)(2.0*nsub)*dx3;
94 
95  Init (us, x1s, x2s, x3s);
96  for (nv = 0; nv < NVAR; nv++) {
97  u_av[nv] += us[nv]/(double)(nsub*nsub*nsub);
98  }
99  }}}
100 
101  #else
102 
103  Init (u_av, x1, x2, x3);
104 
105  #endif
106 
107  for (nv = 0; nv < NVAR; nv++) UU[nv][k][j][i] = u_av[nv];
108 
109  #if (PHYSICS == MHD || PHYSICS == RMHD)
110  #if ASSIGN_VECTOR_POTENTIAL == YES
111  VectorPotentialDiff(b, i, j, k, grid);
112  for (nv = 0; nv < DIMENSIONS; nv++) UU[BX1+nv][k][j][i] = b[nv];
113  #endif /* ASSIGN_VECTOR_POTENTIAL */
114  #endif /* PHYSICS == MHD || PHYSICS == RMHD */
115 
116  }
117 
118 /* --------------------------------------------------------------------
119  Convert primitive variables to conservative ones
120  -------------------------------------------------------------------- */
121 
122  for (k = 0; k < nztot ; k++) {
123  for (j = 0; j < nytot ; j++) {
124 
125  for (i = 0; i < nxtot; i++) {
126  for (nv = 0 ; nv < NVAR ; nv++) {
127  us[nv] = uprim[i][nv] = UU[nv][k][j][i];
128  }
129 
130  /* -- check if primitive values are physically ok -- */
131 
132  if (us[RHO] <= 0.0) {
133  print ("! startup: density is negative\n");
134  QUIT_PLUTO(1);
135  }
136  #if EOS != ISOTHERMAL
137  if (us[PRS] <= 0.0) {
138  print ("! startup: pressure is negative\n");
139  QUIT_PLUTO(1);
140  }
141  #endif
142  #if (PHYSICS == RHD) || (PHYSICS == RMHD)
143  scrh = EXPAND(us[VX1]*us[VX1], + us[VX2]*us[VX2], + us[VX3]*us[VX3]);
144  if (scrh >= 1.0){
145  print ("! startup: total velocity exceeds 1\n");
146  QUIT_PLUTO(1);
147  }
148  #endif
149  }
150 
151  PrimToCons (uprim, ucons, 0, nxtot-1);
152  for (i = 0; i < nxtot; i++) {
153  for (nv = 0; nv < NVAR; nv++) {
154  UU[nv][k][j][i] = ucons[i][nv];
155  }}
156 
157 #if ENTROPY_SWITCH
158  Entropy(uprim, UU[ENTR][k][j], 0, nxtot-1); /* -- primitive: s -- */
159  for (i = 0; i < nxtot; i++) {
160  UU[ENTR][k][j][i] *= UU[RHO][k][j][i]; /* -- conservative: s*D -- */
161  }
162 #endif
163 
164  }}
165 
166 /* --------------------------------------------------
167  Pass U*dV/m_dx^3 to the library
168  -------------------------------------------------- */
169 
170  #if GEOMETRY != CARTESIAN
171  #if CHOMBO_CONS_AM == YES
172  #if ROTATING_FRAME == YES
173  Box aBox = a_U.box();
174  for(BoxIterator bit(aBox); bit.ok(); ++bit) {
175  const IntVect& iv = bit();
176  a_U(iv,iMPHI) += a_U(iv,RHO)*dV(iv,1)*g_OmegaZ;
177  a_U(iv,iMPHI) *= dV(iv,1);
178  }
179  #else
180  a_U.mult(dV,1,iMPHI);
181  #endif
182  #endif
183  for (nv = 0; nv < a_U.nComp(); nv++) a_U.mult(dV,0,nv);
184  #else
185  if (g_stretch_fact != 1.) a_U *= g_stretch_fact;
186  #endif
187 
188  for (nv = 0; nv < NVAR; nv++) FreeArrayMap(UU[nv]);
189  FreeGrid(grid);
190 }
#define iMPHI
Definition: mod_defs.h:71
int jb
Lower corner index in the x2 direction.
Definition: structs.h:349
#define VX2
Definition: mod_defs.h:29
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
#define BOX_LOOP(B, k, j, i)
Definition: macros.h:70
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
int kb
Lower corner index in the x3 direction.
Definition: structs.h:351
#define PSI_GLM
Definition: mod_defs.h:34
#define g_OmegaZ
Definition: init.c:64
double * dV
Cell volume.
Definition: structs.h:86
double * dx
Definition: structs.h:83
#define VX1
Definition: mod_defs.h:28
void FreeArrayMap(double ***t)
Definition: arrays.c:518
#define KDIR
Definition: pluto.h:195
int VXb
Definition: globals.h:73
int ib
Lower corner index in the x1 direction.
Definition: structs.h:347
int BXn
Definition: globals.h:75
void Entropy(double **v, double *s, int beg, int end)
Definition: eos.c:80
int MXt
Definition: globals.h:74
void FreeGrid(Grid *)
Definition: set_grid.c:191
#define IDIR
Definition: pluto.h:193
Definition: structs.h:78
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
#define PHYSICS
Definition: definitions_01.h:1
int j
Definition: analysis.c:2
int VXt
Definition: globals.h:73
int k
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int MXn
Definition: globals.h:74
double * x
Definition: structs.h:80
int VXn
Definition: globals.h:73
#define MHD
Definition: pluto.h:111
#define BX3
Definition: mod_defs.h:27
void Init(double *, double, double, double)
Definition: init.c:17
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
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
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
#define VX3
Definition: mod_defs.h:30
void VectorPotentialDiff(double *, int, int, int, Grid *)
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define BX2
Definition: mod_defs.h:26
#define JDIR
Definition: pluto.h:194
int BXt
Definition: globals.h:75
#define NVAR
Definition: pluto.h:609
Definition: structs.h:346
int BXb
Definition: globals.h:75
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define RMHD
Definition: pluto.h:112
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
#define DIMENSIONS
Definition: definitions_01.h:2
double *** ArrayMap(int nx, int ny, int nz, double *uptr)
Definition: arrays.c:421
int MXb
Definition: globals.h:74