PLUTO
startup.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Loop on the computational cells to assign initial conditions.
5 
6  This function is called anyway, even if restart from file is enabled.
7  This is useful to initialized a number of global variables and/or
8  user-defined parameters by calling Init().
9 
10  \author A. Mignone (mignone@ph.unito.it)
11  \date Aug 16, 2012
12 */
13 /* ///////////////////////////////////////////////////////////////////// */
14 #include "pluto.h"
15 
16 /* ********************************************************************* */
17 void Startup (Data *d, Grid *G)
18 /*!
19  *
20  *
21  *
22  *
23  *********************************************************************** */
24 {
25  int i, j, k;
26  int isub, jsub, ksub, nsub = 5;
27  int nv, l_convert;
28  static double **ucons, **uprim;
29  double x1, x2, x3;
30  double x1p, x2p, x3p;
31  double x1s, x2s, x3s;
32  double dx1, dx2, dx3;
33  double us[256], u_av[256], b[3];
34  double scrh;
35  struct GRID *GX, *GY, *GZ;
36 
37  GX = G;
38  GY = G + 1;
39  GZ = G + 2;
40 
41  if (uprim == NULL){
42  uprim = ARRAY_2D(NMAX_POINT, NVAR, double);
43  ucons = ARRAY_2D(NMAX_POINT, NVAR, double);
44  }
45 
46 /* ---- set labels ---- */
47 
48  EXPAND(MXn = VXn = VX1; ,
49  MXt = VXt = VX2; ,
50  MXb = VXb = VX3;)
51 
52  #if PHYSICS == MHD || PHYSICS == RMHD
53  EXPAND(BXn = BX1; ,
54  BXt = BX2; ,
55  BXb = BX3;)
56  #endif
57 
58 /* ----------------------------------------------------------
59  If the -input-data-file command line argument is given,
60  try to read initial conditions from external files.
61  ---------------------------------------------------------- */
62 
63  print1 ("> Assigning initial conditions (Startup) ...\n");
64 
65 /* --------------------------------------------------------------
66  Assign initial conditions
67  -------------------------------------------------------------- */
68 
69  KTOT_LOOP(k) {
70  JTOT_LOOP(j) {
71  ITOT_LOOP(i) {
72 
73  #if GEOMETRY == CYLINDRICAL
74  x1 = GX->xgc[i]; x1p = GX->xr[i]; dx1 = GX->dx[i];
75  x2 = GY->xgc[j]; x2p = GY->xr[j]; dx2 = GY->dx[j];
76  x3 = GZ->xgc[k]; x3p = GZ->xr[k]; dx3 = GZ->dx[k];
77  #else
78  x1 = GX->x[i]; x1p = GX->xr[i]; dx1 = GX->dx[i];
79  x2 = GY->x[j]; x2p = GY->xr[j]; dx2 = GY->dx[j];
80  x3 = GZ->x[k]; x3p = GZ->xr[k]; dx3 = GZ->dx[k];
81  #endif
82 
83  for (nv = NVAR; nv--; ) d->Vc[nv][k][j][i] = u_av[nv] = 0.0;
84 
85 /* ----------------------------------------------------------------
86  Compute volume averages
87  ---------------------------------------------------------------- */
88 
89  #ifdef PSI_GLM
90  u_av[PSI_GLM] = us[PSI_GLM] = 0.0;
91  #endif
92 
93  #if INITIAL_SMOOTHING == YES
94 
95  for (ksub = 0; ksub < nsub; ksub++){
96  for (jsub = 0; jsub < nsub; jsub++){
97  for (isub = 0; isub < nsub; isub++){
98 
99  x1s = x1 + (double)(1.0 - nsub + 2.0*isub)/(double)(2.0*nsub)*dx1;
100  x2s = x2 + (double)(1.0 - nsub + 2.0*jsub)/(double)(2.0*nsub)*dx2;
101  x3s = x3 + (double)(1.0 - nsub + 2.0*ksub)/(double)(2.0*nsub)*dx3;
102 
103  Init (us, x1s, x2s, x3s);
104  for (nv = 0; nv < NVAR; nv++) {
105  u_av[nv] += us[nv]/(double)(nsub*nsub*nsub);
106  }
107  }}}
108 
109  #else
110 
111  Init (u_av, x1, x2, x3);
112 
113  #endif
114 
115  for (nv = NVAR; nv--; ) d->Vc[nv][k][j][i] = u_av[nv];
116 
117 /* -----------------------------------------------------
118  Initialize cell-centered vector potential
119  (only for output purposes)
120  ----------------------------------------------------- */
121 
122  #if PHYSICS == MHD || PHYSICS == RMHD
124  D_EXPAND( ,
125  d->Ax3[k][j][i] = u_av[AX3]; ,
126  d->Ax1[k][j][i] = u_av[AX1];
127  d->Ax2[k][j][i] = u_av[AX2];)
128  #endif
129  #endif
130 
131  /* -------------------------------------------------------------
132  Assign staggered components;
133  If a vector potential is used (ASSIGN_VECTOR_POTENTIAL == YES),
134  use the STAGGERED_INIT routine;
135  otherwise assign staggered components directly from
136  the init.c and ignore the vector potential.
137 
138  NOTE: in N dimensions only N components are assigned
139  through this call.
140  ------------------------------------------------------------- */
141 
142  #if PHYSICS == MHD || PHYSICS == RMHD
143  #if ASSIGN_VECTOR_POTENTIAL == YES
144  VectorPotentialDiff(b, i, j, k, G);
145 
146  #ifdef STAGGERED_MHD
147  for (nv = 0; nv < DIMENSIONS; nv++) {
148  d->Vs[nv][k][j][i] = b[nv];
149  }
150  #else
151  for (nv = 0; nv < DIMENSIONS; nv++) {
152  d->Vc[BX1+nv][k][j][i] = b[nv];
153  }
154  #endif
155 
156  #else
157 
158  #ifdef STAGGERED_MHD
159  D_EXPAND(
160  Init (u_av, x1p, x2, x3);
161  d->Vs[BX1s][k][j][i] = u_av[BX1]; ,
162 
163  Init (u_av, x1, x2p, x3);
164  d->Vs[BX2s][k][j][i] = u_av[BX2]; ,
165 
166  Init (u_av, x1, x2, x3p);
167  d->Vs[BX3s][k][j][i] = u_av[BX3];
168  )
169  #endif
170  #endif /* ASSIGN_VECTOR_POTENTIAL */
171  #endif /* PHYSICS == MHD || PHYSICS == RMHD */
172 
173  }}}
174 
175  #ifdef STAGGERED_MHD
176 
177  /* ---------------------------------------------------
178  Compute cell-centered magnetic field
179  by simple arithmetic averaging. This
180  is useful only for saving the first
181  output, since the average will be
182  re-computed at the beginning of the computation.
183  --------------------------------------------------- */
184 
185  DOM_LOOP(k,j,i){
186  D_EXPAND(
187  d->Vc[BX1][k][j][i] = 0.5*(d->Vs[BX1s][k][j][i] + d->Vs[BX1s][k][j][i-1]); ,
188  d->Vc[BX2][k][j][i] = 0.5*(d->Vs[BX2s][k][j][i] + d->Vs[BX2s][k][j-1][i]); ,
189  d->Vc[BX3][k][j][i] = 0.5*(d->Vs[BX3s][k][j][i] + d->Vs[BX3s][k-1][j][i]);
190  )
191  }
192 
193  #endif
194 
195 /* --------------------------------------------------------------------
196  Check if values have physical meaning...
197  -------------------------------------------------------------------- */
198 
199 #if PHYSICS != ADVECTION
200  KDOM_LOOP(k){ x3 = GZ->x[k];
201  JDOM_LOOP(j){ x2 = GY->x[j];
202  IDOM_LOOP(i){ x1 = GX->x[i];
203 
204  for (nv = NVAR; nv--; ) us[nv] = d->Vc[nv][k][j][i];
205 
206  if (us[RHO] <= 0.0) {
207  print ("! Startup(): negative density, zone [%f, %f, %f]\n", x1,x2,x3);
208  QUIT_PLUTO(1);
209  }
210  #if HAVE_ENERGY
211  if (us[PRS] <= 0.0) {
212  print ("! Startup(): negative pressure, zone [%f, %f, %f]\n",x1,x2,x3);
213  QUIT_PLUTO(1);
214  }
215  #endif
216 
217  #if (PHYSICS == RHD || PHYSICS == RMHD)
218  scrh = EXPAND(us[VX1]*us[VX1], + us[VX2]*us[VX2], + us[VX3]*us[VX3]);
219  if (scrh >= 1.0){
220  print ("! Startup(): total velocity exceeds 1\n");
221  QUIT_PLUTO(1);
222  }
223  #endif
224  }}}
225 #endif
226 
227 /* --------------------------------------------------------------------
228  Convert primitive variables to conservative ones
229  -------------------------------------------------------------------- */
230 
231  Boundary (d, -1, G);
232 
233 /* --------------------------------------------------------------------
234  Convert to conservative
235  -------------------------------------------------------------------- */
236 /*
237  KDOM_LOOP(k) {
238  JDOM_LOOP(j){
239  IDOM_LOOP(i) {
240  for (nv = NVAR; nv--; ) {
241  uprim[i][nv] = d->Vc[nv][k][j][i];
242  }}
243  PrimToCons(uprim, d->Uc[k][j], IBEG, IEND);
244  }}
245 */
246 }
247 
void Boundary(const Data *d, int idim, Grid *grid)
Definition: boundary.c:36
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
#define KDOM_LOOP(k)
Definition: macros.h:36
DOM_LOOP(k, j, i)
Definition: analysis.c:22
#define VX2
Definition: mod_defs.h:29
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
double * xr
Definition: structs.h:81
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
#define YES
Definition: pluto.h:25
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
#define KTOT_LOOP(k)
Definition: macros.h:40
double *** Ax3
Vector potential component in the direction.
Definition: structs.h:53
#define PSI_GLM
Definition: mod_defs.h:34
#define AX2
Definition: mod_defs.h:86
#define BX3s
Definition: ct.h:29
double * dx
Definition: structs.h:83
#define VX1
Definition: mod_defs.h:28
int VXb
Definition: globals.h:73
#define JDOM_LOOP(j)
Definition: macros.h:35
int BXn
Definition: globals.h:75
#define STAGGERED_MHD
Definition: ct.h:15
int MXt
Definition: globals.h:74
Definition: structs.h:78
#define AX3
Definition: mod_defs.h:87
#define UPDATE_VECTOR_POTENTIAL
Definition: pluto.h:381
#define PHYSICS
Definition: definitions_01.h:1
int j
Definition: analysis.c:2
if(divB==NULL)
Definition: analysis.c:10
int VXt
Definition: globals.h:73
int k
Definition: analysis.c:2
#define BX1s
Definition: ct.h:27
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int MXn
Definition: globals.h:74
double * x
Definition: structs.h:80
double * xgc
Cell volumetric centroid (!= x when geometry != CARTESIAN).
Definition: structs.h:84
#define INITIAL_SMOOTHING
int VXn
Definition: globals.h:73
#define MHD
Definition: pluto.h:111
#define BX3
Definition: mod_defs.h:27
PLUTO main header file.
void Init(double *, double, double, double)
Definition: init.c:17
#define ITOT_LOOP(i)
Definition: macros.h:38
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
Definition: structs.h:30
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
#define JTOT_LOOP(j)
Definition: macros.h:39
int i
Definition: analysis.c:2
void Startup(Data *d, Grid *G)
Definition: startup.c:17
#define AX1
Definition: mod_defs.h:85
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
void VectorPotentialDiff(double *, int, int, int, Grid *)
#define BX2s
Definition: ct.h:28
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define BX2
Definition: mod_defs.h:26
int BXt
Definition: globals.h:75
double *** Ax1
Vector potential component in the direction.
Definition: structs.h:51
#define NVAR
Definition: pluto.h:609
int BXb
Definition: globals.h:75
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
double *** Ax2
Vector potential component in the direction.
Definition: structs.h:52
#define RMHD
Definition: pluto.h:112
#define IDOM_LOOP(i)
Definition: macros.h:34
#define DIMENSIONS
Definition: definitions_01.h:2
int MXb
Definition: globals.h:74