PLUTO
prototypes.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ARRAY_1D(nx, type)    (type *)Array1D(nx,sizeof(type))
 
#define ARRAY_2D(nx, ny, type)    (type **)Array2D(nx,ny,sizeof(type))
 
#define ARRAY_3D(nx, ny, nz, type)    (type ***)Array3D(nx,ny,nz,sizeof(type))
 
#define ARRAY_4D(nx, ny, nz, nv, type)   (type ****)Array4D(nx,ny,nz,nv,sizeof(type))
 

Functions

int AdvanceStep (const Data *, Riemann_Solver *, Time_Step *, Grid *)
 
void AdvectFlux (const State_1D *, int, int, Grid *)
 
void Analysis (const Data *, Grid *)
 
void Boundary (const Data *, int, Grid *)
 
char * Array1D (int, size_t)
 
char ** Array2D (int, int, size_t)
 
char *** Array3D (int, int, int, size_t)
 
char **** Array4D (int, int, int, int, size_t)
 
double *** ArrayBox (long int, long int, long int, long int, long int, long int)
 
double *** ArrayBoxMap (int, int, int, int, int, int, double *)
 
double *** ArrayMap (int, int, int, double *)
 
unsigned char *** ArrayCharMap (int, int, int, unsigned char *)
 
void BodyForceVectorGet (double **v, double **g, double *, double *, double *, int beg, int end, Grid *grid)
 
void BodyForcePotentialGet (double **v, double **gphi, double *phi_p, double *phi_c, int beg, int end, Grid *grid)
 
double BodyForcePotential (double, double, double)
 
void BodyForceVector (double *, double *, double, double, double)
 
void ChangeDumpVar ()
 
void CharTracingStep (const State_1D *, int, int, Grid *)
 
void CheckPrimStates (double **, double **, double **, int, int)
 
int CheckNaN (double **, int, int, int)
 
int CloseBinaryFile (FILE *, int)
 
void ComputeUserVar (const Data *, Grid *)
 
float *** Convert_dbl2flt (double ***, double, int)
 
void ConsToPrim3D (Data_Arr, Data_Arr, unsigned char ***, RBox *)
 
void CreateImage (char *)
 
void ComputeEntropy (const Data *, Grid *)
 
void EntropySwitch (const Data *, Grid *)
 
void EntropyOhmicHeating (const Data *, Data_Arr, double, Grid *)
 
void FreeArray1D (void *)
 
void FreeArray2D (void **)
 
void FreeArray3D (void ***)
 
void FreeArray4D (void ****)
 
void FreeArrayBox (double ***, long, long, long)
 
void FreeArrayBoxMap (double ***, int, int, int, int, int, int)
 
void FreeArrayMap (double ***)
 
void FreeArrayCharMap (unsigned char ***)
 
void FindShock (const Data *, Grid *)
 
void FlagShock (const Data *, Grid *)
 
void Flatten (const State_1D *, int, int, Grid *)
 
void FreeGrid (Grid *)
 
void GetAreaFlux (const State_1D *, double **, double **, int, int, Grid *)
 
void GetCGSUnits (double *u)
 
ImageGetImage (char *)
 
double * GetInverse_dl (const Grid *)
 
int GetNghost (void)
 
void GetOutputFrequency (Output *, const char *)
 
RBoxGetRBox (int, int)
 
double *** GetUserVar (char *)
 
void HancockStep (const State_1D *, int, int, Grid *)
 
int LocateIndex (double *, int, int, double)
 
void Init (double *, double, double, double)
 
void Initialize (int argc, char *argv[], Data *, Runtime *, Grid *, Cmd_Line *)
 
void InternalBoundaryReset (const State_1D *, Time_Step *, int, int, Grid *)
 
void InputDataFree (void)
 
void InputDataInterpolate (double *, double, double, double)
 
void InputDataRead (char *, char *)
 
void InputDataSet (char *, int *)
 
int IsLittleEndian (void)
 
void MakeState (State_1D *)
 
void MakeGeometry (Grid *)
 
double MeanMolecularWeight (double *)
 
double Median (double a, double b, double c)
 
FILE * OpenBinaryFile (char *, int, char *)
 
void ParabolicFlux (Data_Arr, Data_Arr J, double ***, const State_1D *, double **, int, int, Grid *)
 
double ParabolicRHS (const Data *, Data_Arr, double, Grid *)
 
void ParseCmdLineArgs (int, char *argv[], char *, Cmd_Line *)
 
int ParamFileRead (char *)
 
char * ParamFileGet (const char *, int)
 
int ParamExist (const char *)
 
int ParamFileHasBoth (const char *, const char *)
 
void PrimToChar (double **, double *, double *)
 
void PrimToCons3D (Data_Arr, Data_Arr, RBox *)
 
void ReadBinaryArray (void *, size_t, int, FILE *, int, int)
 
void ReadHDF5 (Output *output, Grid *grid)
 
void ResetState (const Data *, State_1D *, Grid *)
 
void RestartFromFile (Runtime *, int, int, Grid *)
 
void RestartDump (Runtime *)
 
void RestartGet (Runtime *, int, int, int)
 
void RightHandSide (const State_1D *, Time_Step *, int, int, double, Grid *)
 
void RightHandSideSource (const State_1D *, Time_Step *, int, int, double, double *, Grid *)
 
void RKC (const Data *d, Time_Step *, Grid *)
 
RuntimeRuntimeGet (void)
 
int RuntimeSetup (Runtime *, Cmd_Line *, char *)
 
void RuntimeSet (Runtime *runtime)
 
void SetColorMap (unsigned char *, unsigned char *, unsigned char *, char *)
 
void SetDefaultVarNames (Output *)
 
int SetDumpVar (char *, int, int)
 
void SetIndexes (Index *indx, Grid *grid)
 
int SetLogFile (char *, Cmd_Line *)
 
void SetOutput (Data *d, Runtime *input)
 
void SetRBox (void)
 
Riemann_SolverSetSolver (const char *)
 
void SetGrid (Runtime *, Grid *)
 
void SetJetDomain (const Data *, int, int, Grid *)
 
void Show (double **, int)
 
void ShowMatrix (double **, int n, double)
 
void ShowVector (double *, int n)
 
void ShowConfig (int, char *a[], char *)
 
void ShowDomainDecomposition (int, Grid *)
 
void ShowUnits ()
 
void SplitSource (const Data *, double, Time_Step *, Grid *)
 
void STS (const Data *d, Time_Step *, Grid *)
 
void Startup (Data *, Grid *)
 
void States (const State_1D *, int, int, Grid *)
 
void SwapEndian (void *, const int)
 
void UnsetJetDomain (const Data *, int, Grid *)
 
void UpdateStage (const Data *, Data_Arr, double **, Riemann_Solver *, double, Time_Step *, Grid *)
 
void UserDefBoundary (const Data *, RBox *, int, Grid *)
 
void VectorPotentialDiff (double *, int, int, int, Grid *)
 
void Where (int, Grid *)
 
void WriteData (const Data *, Output *, Grid *)
 
void WriteBinaryArray (void *, size_t, int, FILE *, int)
 
void WriteHDF5 (Output *output, Grid *grid)
 
void WriteVTK_Header (FILE *, Grid *)
 
void WriteVTK_Vector (FILE *, Data_Arr, double, char *, Grid *)
 
void WriteVTK_Scalar (FILE *, double ***, double, char *, Grid *)
 
void WriteTabArray (Output *, char *, Grid *)
 
void WritePPM (double ***, char *, char *, Grid *)
 
void WritePNG (double ***, char *, char *, Grid *)
 
void print (const char *fmt,...)
 
void print1 (const char *fmt,...)
 
void Trace (double)
 
void FlipSign (int, int, int *)
 
void OutflowBound (double ***, int, int, Grid *)
 
void PeriodicBound (double ***, int, int)
 
void ReflectiveBound (double ***, int, int, int)
 
void PlutoError (int, char *)
 
double Length_1 (int i, int j, int k, Grid *)
 
double Length_2 (int i, int j, int k, Grid *)
 
double Length_3 (int i, int j, int k, Grid *)
 
void VectorPotentialUpdate (const Data *d, const void *vp, const State_1D *state, const Grid *grid)
 
void Enthalpy (double **, double *, int, int)
 
void Entropy (double **, double *, int, int)
 
void SoundSpeed2 (double **, double *, double *, int, int, int, Grid *)
 
double GetEntropy (double x)
 
void WriteAsciiFile (char *fname, double *q, int nvar)
 

Macro Definition Documentation

#define ARRAY_1D (   nx,
  type 
)    (type *)Array1D(nx,sizeof(type))

Definition at line 170 of file prototypes.h.

#define ARRAY_2D (   nx,
  ny,
  type 
)    (type **)Array2D(nx,ny,sizeof(type))

Definition at line 171 of file prototypes.h.

#define ARRAY_3D (   nx,
  ny,
  nz,
  type 
)    (type ***)Array3D(nx,ny,nz,sizeof(type))

Definition at line 172 of file prototypes.h.

#define ARRAY_4D (   nx,
  ny,
  nz,
  nv,
  type 
)    (type ****)Array4D(nx,ny,nz,nv,sizeof(type))

Definition at line 173 of file prototypes.h.

Function Documentation

int AdvanceStep ( const Data d,
Riemann_Solver Riemann,
Time_Step Dts,
Grid grid 
)

Advance equations using the corner transport upwind method (CTU)

Parameters
[in,out]dpointer to Data structure
[in]Riemannpointer to a Riemann solver function
[in,out]Dtspointer to time step structure
[in]gridpointer to array of Grid structures

Advance the equations by a single time step using unsplit integrators based on the method of lines.

Parameters
[in,out]dpointer to Data structure
[in]Riemannpointer to a Riemann solver function
[in,out]Dtspointer to time step structure
[in]gridpointer to array of Grid structures

Definition at line 88 of file ctu_step.c.

100 {
101  int i, j,k, nv, *in;
102  int errp, errm;
103  double dt2, inv_dtp, *inv_dl;
104  Index indx;
105  static unsigned char *flagm, *flagp;
106  static Data_Arr UM[DIMENSIONS], UP[DIMENSIONS];
107 
108  static Data_Arr dU, UH, Bs0;
109  static State_1D state;
110  static double **dtdV, **dcoeff, ***T;
111  double *dtdV2, **rhs;
112  RBox *box = GetRBox(DOM, CENTER);
113 
114 /* -----------------------------------------------------------------
115  Check algorithm compatibilities
116  ----------------------------------------------------------------- */
117 
118  #if !(GEOMETRY == CARTESIAN || GEOMETRY == CYLINDRICAL)
119  print1 ("! AdvanceStep(): ");
120  print1 ("CTU only works in Cartesian or cylindrical coordinates\n");
121  QUIT_PLUTO(1);
122  #endif
123 
124 /* --------------------------------------------------------
125  Allocate static memory areas
126  --------------------------------------------------------- */
127 
128  if (dU == NULL){
129 
130  dtdV = ARRAY_2D(DIMENSIONS,NMAX_POINT, double);
131 
132  MakeState (&state);
133 
134  flagp = ARRAY_1D(NMAX_POINT, unsigned char);
135  flagm = ARRAY_1D(NMAX_POINT, unsigned char);
136 
137  UH = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
138  dU = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
139  #ifdef STAGGERED_MHD
140  Bs0 = ARRAY_4D(DIMENSIONS, NX3_TOT, NX2_TOT, NX1_TOT, double);
141  #endif
142 
143  /* ---------------------------------------------------------
144  corner-coupled multidimensional arrays are stored into
145  memory following the same conventions adopted when
146  sweeping along the coordinate directions, i.e.,
147 
148  (z,y,x)->(z,x,y)->(y,x,z).
149 
150  This allows 1-D arrays to conveniently point at the
151  fastest running indexes of the respective multi-D ones.
152  --------------------------------------------------------- */
153 
154  UM[IDIR] = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
155  UP[IDIR] = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
156 
157  UM[JDIR] = ARRAY_4D(NX3_TOT, NX1_TOT, NX2_TOT, NVAR, double);
158  UP[JDIR] = ARRAY_4D(NX3_TOT, NX1_TOT, NX2_TOT, NVAR, double);
159 
160  #if DIMENSIONS == 3
161  UM[KDIR] = ARRAY_4D(NX2_TOT, NX1_TOT, NX3_TOT, NVAR, double);
162  UP[KDIR] = ARRAY_4D(NX2_TOT, NX1_TOT, NX3_TOT, NVAR, double);
163  #endif
164 
165  #if (PARABOLIC_FLUX & EXPLICIT)
166  dcoeff = ARRAY_2D(NMAX_POINT, NVAR, double);
167  #endif
168  #if THERMAL_CONDUCTION == EXPLICIT
169  T = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
170  #endif
171  }
172 
173 /* -- save pointers -- */
174 
175  rhs = state.rhs;
176 /* memset (dU[0][0][0], 0.0, NX3_TOT*NX2_TOT*NX1_TOT*NVAR*sizeof(double)); */
177 
178  #ifdef FARGO
179  FARGO_SubtractVelocity (d,grid);
180  #endif
181 
182 /* -------------------------------------------------------
183  Set boundary conditions and flag shocked regions for
184  shock flattening or energy/entropy selective update.
185  ------------------------------------------------------- */
186 
187  g_intStage = 1;
188  Boundary (d, ALL_DIR, grid);
189  #if (SHOCK_FLATTENING == MULTID) || (ENTROPY_SWITCH)
190  FlagShock (d, grid);
191  #endif
192 
193  dt2 = 0.5*g_dt;
194  D_EXPAND(
195  ITOT_LOOP(i) dtdV[IDIR][i] = dt2/grid[IDIR].dV[i]; ,
196  JTOT_LOOP(j) dtdV[JDIR][j] = dt2/grid[JDIR].dV[j]; ,
197  KTOT_LOOP(k) dtdV[KDIR][k] = dt2/grid[KDIR].dV[k];
198  )
199 
200  #if THERMAL_CONDUCTION == EXPLICIT
201  TOT_LOOP(k,j,i) T[k][j][i] = d->Vc[PRS][k][j][i]/d->Vc[RHO][k][j][i];
202  #endif
203 
204 /* ------------------------------------------------
205  Compute current arrays
206  ------------------------------------------------ */
207 
208  #if (RESISTIVITY == EXPLICIT) && (defined STAGGERED_MHD)
209  GetCurrent (d, -1, grid);
210  #endif
211 
212 /* ----------------------------------------------------
213  Convert primitive to conservative and reset arrays
214  ---------------------------------------------------- */
215 
216  KTOT_LOOP(k) JTOT_LOOP(j){
217  ITOT_LOOP(i){
218  VAR_LOOP(nv) state.v[i][nv] = d->Vc[nv][k][j][i];
219  }
220  PrimToCons(state.v, d->Uc[k][j], 0, NX1_TOT-1);
221  }
222 
223  #ifdef STAGGERED_MHD
224  nv = NX1_TOT*sizeof(double);
225  KTOT_LOOP(k) JTOT_LOOP(j){
226  D_EXPAND(memcpy(Bs0[BX1s][k][j], d->Vs[BX1s][k][j], nv); ,
227  memcpy(Bs0[BX2s][k][j], d->Vs[BX2s][k][j], nv); ,
228  memcpy(Bs0[BX3s][k][j], d->Vs[BX3s][k][j], nv);)
229  }
230  #endif
231 
232 /* ----------------------------------------------------
233  1. Compute Normal predictors and
234  solve normal Riemann problems.
235  Store computations in UP, UM, RHS (X,Y,Z)
236  ---------------------------------------------------- */
237 
238  for (g_dir = 0; g_dir < DIMENSIONS; g_dir++){
239 
240  SetIndexes (&indx, grid);
241  ResetState (d, &state, grid);
242  #if (RESISTIVITY == EXPLICIT) && !(defined STAGGERED_MHD)
243  GetCurrent(d, g_dir, grid);
244  #endif
245  TRANSVERSE_LOOP(indx,in,i,j,k){
246 
247  g_i = i; g_j = j; g_k = k;
248 
249  /* ---------------------------------------------
250  save computational time by having state.up
251  and state.um pointing at the fastest
252  running indexes of UP and UM.
253  Also, during the x-sweep we initialize Uc
254  and dU by changing the memory address of
255  state.u and state.rhs.
256  --------------------------------------------- */
257 
258  state.up = UP[g_dir][*(indx.pt2)][*(indx.pt1)]; state.uL = state.up;
259  state.um = UM[g_dir][*(indx.pt2)][*(indx.pt1)]; state.uR = state.um + 1;
260 
261  /* ---- get a 1-D array of primitive quantities ---- */
262 
263  for (*in = 0; (*in) < indx.ntot; (*in)++) {
264  VAR_LOOP(nv) state.v[*in][nv] = d->Vc[nv][k][j][i];
265  state.flag[*in] = d->flag[k][j][i];
266  #ifdef STAGGERED_MHD
267  state.bn[*in] = d->Vs[g_dir][k][j][i];
268  #endif
269  }
270 
271  CheckNaN (state.v, 0, indx.ntot - 1, 0);
272 
273 #if !(PARABOLIC_FLUX & EXPLICIT) /* adopt this formulation when there're no
274  explicit diffusion flux terms */
275  States (&state, indx.beg - 1, indx.end + 1, grid);
276  Riemann (&state, indx.beg - 1, indx.end, Dts->cmax, grid);
277  #ifdef STAGGERED_MHD
278  CT_StoreEMF (&state, indx.beg - 1, indx.end, grid);
279  #endif
280  RightHandSide (&state, Dts, indx.beg, indx.end, dt2, grid);
281 
282  #if CTU_MHD_SOURCE == YES
283  CTU_CT_Source (state.v, state.up, state.um,
284  dtdV[g_dir], indx.beg - 1, indx.end + 1, grid);
285  #endif
286 
287  /* ------------------------------------------------------------------
288  At this point we have at disposal the normal predictors U^_\pm.
289  To save memory, we compute corner coupled states by first
290  subtracting the normal contribution and then by adding the total
291  time increment. For example, in the x-direction, we do
292 
293  U^{n+1/2}_\pm = U^_\pm - RX + (RX + RY + RZ)
294 
295  where the first subtraction is done here while dU = (RX + RY + RZ) is
296  the total time increment which will be added later (step 2 below).
297  In a 2-D domain dU contains the following (X,Y,Z) contributions:
298 
299  0 X 0 0 X 0
300  +--------+ +--------+
301  | | | |
302  0| X |0 --> Y| XY |Y
303  | | | |
304  +--------+ +--------+
305  0 X 0 0 X 0
306 
307  (X sweep) (Y sweep)
308 
309  Also, evolve cell center values by dt/2.
310  For staggered mhd, this step should be carried also in one rows of
311  boundary zones in order to provide the cell and time centered
312  e.m.f.
313  ------------------------------------------------------------------ */
314 
315  if (g_dir == IDIR){
316 
317  for (nv = NVAR; nv--; ) {
318  state.rhs[indx.beg - 1][nv] = 0.0;
319  state.rhs[indx.end + 1][nv] = 0.0;
320  }
321 
322  for ((*in) = indx.beg-1; (*in) <= indx.end+1; (*in)++) {
323  for (nv = NVAR; nv--; ){
324  dU[k][j][i][nv] = state.rhs[*in][nv];
325  UH[k][j][i][nv] = d->Uc[k][j][i][nv] + state.rhs[*in][nv];
326  state.up[*in][nv] -= state.rhs[*in][nv];
327  state.um[*in][nv] -= state.rhs[*in][nv];
328  }}
329  }else{
330  for ((*in) = indx.beg; (*in) <= indx.end; (*in)++) {
331  for (nv = NVAR; nv--; ){
332  dU[k][j][i][nv] += state.rhs[*in][nv];
333  UH[k][j][i][nv] += state.rhs[*in][nv];
334  state.up[*in][nv] -= state.rhs[*in][nv];
335  state.um[*in][nv] -= state.rhs[*in][nv];
336  }}
337  }
338 
339 #else
340 
341  /* -------------------------------------------------------------
342  When parabolic terms have to be included explicitly, we use
343  a slightly different formulation where the transverse
344  predictors are computed using 1st order states.
345  This still yields a second-order accurate scheme but allow
346  to compute the solution at the half time step in one rows
347  of ghost zones, which is essential to update the parabolic
348  terms using midpoint rule:
349 
350  U^{n+1} = U^n - RHS(hyp, n+1/2) - RHS(par, n+1/2)
351 
352 
353  Since RHS(par) has a stencil 3-point wide.
354  Corner coupled states are modified to account for parabolic
355  terms in the following way:
356 
357  U^{n+1/2}_\pm = U^_\pm - RX,h + (RX,h + RY,h + RZ,h)
358  + (RX,p + RY,p + RZ,p)
359  -------------------------------------------------------------- */
360 
361  for ((*in) = 0; (*in) < indx.ntot; (*in)++) {
362  for (nv = NVAR; nv--; ) {
363  state.vp[*in][nv] = state.vm[*in][nv] = state.vh[*in][nv] = state.v[*in][nv];
364  }}
365  #ifdef STAGGERED_MHD
366  for (*in = 0; (*in) < indx.ntot-1; (*in)++) {
367  state.vR[*in][BXn] = state.vL[*in][BXn] = state.bn[*in];
368  }
369  #endif
370  PrimToCons(state.vm, state.um, 0, indx.ntot-1);
371  PrimToCons(state.vp, state.up, 0, indx.ntot-1);
372 
373  Riemann (&state, indx.beg-1, indx.end, Dts->cmax, grid);
374  #ifdef STAGGERED_MHD
375  CT_StoreEMF (&state, indx.beg-1, indx.end, grid);
376  #endif
377 
378  /* -----------------------------------------------------------
379  compute rhs using the hyperbolic fluxes only
380  ----------------------------------------------------------- */
381 
382  #if (VISCOSITY == EXPLICIT)
383  for ((*in) = 0; (*in) < indx.ntot; (*in)++) for (nv = NVAR; nv--; )
384  state.par_src[*in][nv] = 0.0;
385  #endif
386  RightHandSide (&state, Dts, indx.beg, indx.end, dt2, grid);
387  ParabolicFlux (d->Vc, d->J, T, &state, dcoeff, indx.beg-1, indx.end, grid);
388 
389  /* ----------------------------------------------------------------
390  compute LR states and subtract normal (hyperbolic)
391  rhs contribution.
392  NOTE: states are computed from IBEG - 1 (= indx.beg) up to
393  IEND + 1 (= indx.end) since EMF has already been evaluated
394  and stored using 1st order states above.
395  NOTE: States should be called after ParabolicFlux since some
396  terms (e.g. thermal conduction) may depend on left and
397  right normal states.
398  ---------------------------------------------------------------- */
399 
400  States (&state, indx.beg, indx.end, grid);
401  #if CTU_MHD_SOURCE == YES
402  CTU_CT_Source (state.v, state.up, state.um,
403  dtdV[g_dir], indx.beg, indx.end, grid);
404  #endif
405 
406  for ((*in) = indx.beg; (*in) <= indx.end; (*in)++) {
407  for (nv = NVAR; nv--; ){
408  state.up[*in][nv] -= state.rhs[*in][nv];
409  state.um[*in][nv] -= state.rhs[*in][nv];
410  }}
411 
412  /* -----------------------------------------------------------
413  re-compute the full rhs using the total (hyp+par) rhs
414  ----------------------------------------------------------- */
415 
416  RightHandSide (&state, Dts, indx.beg, indx.end, dt2, grid);
417 
418  if (g_dir == IDIR){
419  for ((*in) = indx.beg; (*in) <= indx.end; (*in)++) {
420  for (nv = NVAR; nv--; ){
421  dU[k][j][i][nv] = state.rhs[*in][nv];
422  UH[k][j][i][nv] = d->Uc[k][j][i][nv] + state.rhs[*in][nv];
423  }}
424  }else{
425  for ((*in) = indx.beg; (*in) <= indx.end; (*in)++) {
426  for (nv = NVAR; nv--; ){
427  dU[k][j][i][nv] += state.rhs[*in][nv];
428  UH[k][j][i][nv] += state.rhs[*in][nv];
429  }}
430  }
431 #endif
432  } /* -- end loop on transverse directions -- */
433 
434  } /* -- end loop on dimensions -- */
435 
436 /* -------------------------------------------------------
437  2a. Advance staggered magnetic fields by dt/2
438  ------------------------------------------------------- */
439 
440  #ifdef STAGGERED_MHD
441  CT_Update (d, d->Vs, 0.5*g_dt, grid);
442  CT_AverageMagneticField (d->Vs, UH, grid);
443  #endif
444 
445 /* ----------------------------------------------------------
446  2b. Convert cell and time centered values to primitive.
447  UH is transformed from conservative to primitive
448  variables for efficiency purposes.
449  ---------------------------------------------------------- */
450 
451  g_dir = IDIR;
452  SetIndexes (&indx, grid);
453  TRANSVERSE_LOOP(indx,in,i,j,k){
454  g_i = i; g_j = j; g_k = k;
455  errp = ConsToPrim(UH[k][j], state.v, indx.beg, indx.end, d->flag[k][j]);
456  for ((*in) = indx.beg; (*in) <= indx.end; (*in)++) {
457  VAR_LOOP(nv) d->Vc[nv][k][j][i] = state.v[*in][nv];
458  }
459  #if THERMAL_CONDUCTION == EXPLICIT
460  for ((*in) = indx.beg; (*in) <= indx.end; (*in)++){
461  T[k][j][i] = d->Vc[PRS][k][j][i]/d->Vc[RHO][k][j][i];
462  }
463  #endif
464  }
465  #if (RESISTIVITY == EXPLICIT) && (defined STAGGERED_MHD)
466  GetCurrent (d, -1, grid);
467  #endif
468 
469 /* ----------------------------------------------------
470  3. Final conservative update
471  ---------------------------------------------------- */
472 
473  g_intStage = 2;
474  for (g_dir = 0; g_dir < DIMENSIONS; g_dir++){
475 
476  SetIndexes (&indx, grid);
477  ResetState (d, &state, grid);
478  #if (RESISTIVITY == EXPLICIT) && !(defined STAGGERED_MHD)
479  GetCurrent(d, g_dir, grid);
480  #endif
481  TRANSVERSE_LOOP(indx,in,i,j,k){
482 
483  g_i = i; g_j = j; g_k = k;
484 
485  /* ---------------------------------------------------------
486  Convert conservative corner-coupled states to primitive
487  --------------------------------------------------------- */
488 
489  state.up = UP[g_dir][*(indx.pt2)][*(indx.pt1)]; state.uL = state.up;
490  state.um = UM[g_dir][*(indx.pt2)][*(indx.pt1)]; state.uR = state.um + 1;
491 
492  for ((*in) = indx.beg-1; (*in) <= indx.end+1; (*in)++){
493  for (nv = NVAR; nv--; ){
494  state.up[*in][nv] += dU[k][j][i][nv];
495  state.um[*in][nv] += dU[k][j][i][nv];
496  }
497  flagp[*in] = flagm[*in] = d->flag[k][j][i];
498  }
499 
500  /* -------------------------------------------------------
501  compute time centered, cell centered state.
502  Useful for source terms like gravity,
503  curvilinear terms and Powell's 8wave
504  ------------------------------------------------------- */
505 
506  for ((*in) = indx.beg-1; (*in) <= indx.end+1; (*in)++) {
507  NVAR_LOOP(nv) state.vh[*in][nv] = d->Vc[nv][k][j][i];
508  state.flag[*in] = d->flag[k][j][i];
509  }
510 
511  #ifdef STAGGERED_MHD
512  for ((*in) = indx.beg - 2; (*in) <= indx.end + 1; (*in)++){
513  state.uL[*in][BXn] = state.uR[*in][BXn] = d->Vs[BXs + g_dir][k][j][i];
514  state.bn[*in] = state.uL[*in][BXn];
515  }
516  #endif
517 
518  errm = ConsToPrim (state.um, state.vm, indx.beg - 1, indx.end + 1, flagm);
519  errp = ConsToPrim (state.up, state.vp, indx.beg - 1, indx.end + 1, flagp);
520 /*
521  if (errm || errp){
522  WARNING(print ("! Corner coupled states not physical: reverting to 1st order\n");)
523  for (in = indx.beg - 1; in <= indx.end + 1; in++){
524  if ( (flagm[*in] & FLAG_CONS2PRIM_FAIL)
525  || (flagm[in] & FLAG_CONS2PRIM_FAIL) ) {
526  for (nv = 0; nv < NVAR; nv++) {
527  state.v[in][nv] = d->Vc[nv][*k][*j][*i];
528  }
529  PrimToCons(state.v, state.u, in, in);
530  for (nv = 0; nv < NVAR; nv++) {
531  state.vm[in][nv] = state.vp[in][nv] = state.vh[in][nv] = state.v[in][nv];
532  state.um[in][nv] = state.up[in][nv] = state.uh[in][nv] = state.u[in][nv];
533  }
534  }
535  }
536  }
537 */
538 
539  /* ------------------------------------------
540  compute flux & righ-hand-side
541  ------------------------------------------ */
542 
543  Riemann (&state, indx.beg - 1, indx.end, Dts->cmax, grid);
544  #ifdef STAGGERED_MHD
545  CT_StoreEMF (&state, indx.beg - 1, indx.end, grid);
546  #endif
547  #if (PARABOLIC_FLUX & EXPLICIT)
548 
549  /* --------------------------------------------------------
550  since integration in the transverse directions extends
551  one point below and one point above the computational
552  box (when using CT), we avoid computing parabolic
553  operators in one row of boundary zones below and above
554  since the 3-point wide stencil may not be available.
555  -------------------------------------------------------- */
556 
557  errp = 1;
558  #ifdef STAGGERED_MHD
559  D_EXPAND( ,
560  errp = (*(indx.pt1) < indx.t1_end) && (*(indx.pt1) > indx.t1_beg); ,
561  errp = errp && (*(indx.pt2) < indx.t2_end) && (*(indx.pt2) > indx.t2_beg);)
562  #endif
563  if (errp) {
564  ParabolicFlux (d->Vc, d->J, T, &state, dcoeff, indx.beg - 1, indx.end, grid);
565  inv_dl = GetInverse_dl(grid);
566  for ((*in) = indx.beg; (*in) <= indx.end; (*in)++) {
567  inv_dtp = 0.0;
568  #if VISCOSITY == EXPLICIT
569  inv_dtp = MAX(inv_dtp, dcoeff[*in][MX1]);
570  #endif
571  #if RESISTIVITY == EXPLICIT
572  EXPAND(inv_dtp = MAX(inv_dtp, dcoeff[*in][BX1]); ,
573  inv_dtp = MAX(inv_dtp, dcoeff[*in][BX2]); ,
574  inv_dtp = MAX(inv_dtp, dcoeff[*in][BX3]);)
575  #endif
577  inv_dtp = MAX(inv_dtp, dcoeff[*in][ENG]);
578  #endif
579  inv_dtp *= inv_dl[*in]*inv_dl[*in];
580 
581  Dts->inv_dtp = MAX(Dts->inv_dtp, inv_dtp);
582  }
583  }
584  #endif
585  #if UPDATE_VECTOR_POTENTIAL == YES
586  VectorPotentialUpdate (d, NULL, &state, grid);
587  #endif
588  #ifdef SHEARINGBOX
589  SB_SaveFluxes(&state, grid);
590  #endif
591 
592  RightHandSide (&state, Dts, indx.beg, indx.end, g_dt, grid);
593 
594  for ((*in) = indx.beg; (*in) <= indx.end; (*in)++) {
595  NVAR_LOOP(nv) d->Uc[k][j][i][nv] += state.rhs[*in][nv];
596  }
597  }
598  }
599 
600  #ifdef SHEARINGBOX
601  SB_CorrectFluxes(d->Uc, g_time+0.5*g_dt, g_dt, grid);
602  #endif
603 
604  #ifdef STAGGERED_MHD
605  CT_Update (d, Bs0, g_dt, grid);
606  CT_AverageMagneticField (d->Vs, d->Uc, grid);
607  #endif
608 
609 /* ----------------------------------------------
610  convert to primitive
611  ---------------------------------------------- */
612 
613  #ifdef FARGO
614  FARGO_ShiftSolution (d->Uc, d->Vs, grid);
615  #endif
616 
617  ConsToPrim3D(d->Uc, d->Vc, d->flag, box);
618 
619  #ifdef FARGO
620  FARGO_AddVelocity (d,grid);
621  #endif
622 
623  return(0); /* -- step has been achieved, return success -- */
624 }
void Boundary(const Data *d, int idim, Grid *grid)
Definition: boundary.c:36
#define MAX(a, b)
Definition: macros.h:101
tuple T
Definition: Sph_disk.py:33
void CT_StoreEMF(const State_1D *state, int beg, int end, Grid *grid)
Definition: ct_emf.c:35
double ** v
Cell-centered primitive varables at the base time level, v[i] = .
Definition: structs.h:134
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
void ResetState(const Data *, State_1D *, Grid *)
Definition: set_indexes.c:163
#define MX1
Definition: mod_defs.h:20
double ** vh
Primitive state at n+1/2 (only for one step method)
Definition: structs.h:162
double **** Data_Arr
Definition: pluto.h:492
double **** J
Electric current defined as curl(B).
Definition: structs.h:54
void GetCurrent(const Data *d, int dir, Grid *grid)
Definition: res_functions.c:97
RBox * GetRBox(int, int)
Definition: rbox.c:232
int ntot
Definition: structs.h:318
#define CENTER
Definition: pluto.h:200
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
double ** rhs
Conservative right hand side.
Definition: structs.h:163
int t2_end
Definition: structs.h:320
void States(const State_1D *, int, int, Grid *)
Definition: plm_states.c:430
#define RHO
Definition: mod_defs.h:19
int t1_end
Definition: structs.h:319
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
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
static void CTU_CT_Source(double **, double **, double **, double *, int, int, Grid *)
Definition: ctu_step.c:628
double g_dt
The current integration time step.
Definition: globals.h:118
double * GetInverse_dl(const Grid *)
Definition: set_geometry.c:205
void SB_CorrectFluxes(Data_Arr U, double t, double dt, Grid *grid)
Definition: sb_flux.c:105
#define DOM
Computational domain (interior)
Definition: pluto.h:152
#define BX3s
Definition: ct.h:29
void CT_Update(const Data *d, Data_Arr Bs, double dt, Grid *grid)
Definition: ct.c:29
void FARGO_ShiftSolution(Data_Arr U, Data_Arr Us, Grid *grid)
Definition: fargo.c:42
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
double * cmax
Maximum signal velocity for hyperbolic eqns.
Definition: structs.h:214
void FARGO_AddVelocity(const Data *, Grid *)
#define KDIR
Definition: pluto.h:195
unsigned char *** flag
Pointer to a 3D array setting useful integration flags that are retrieved during integration.
Definition: structs.h:55
int t2_beg
Definition: structs.h:320
void ConsToPrim3D(Data_Arr U, Data_Arr V, unsigned char ***flag, RBox *box)
Definition: mappers3D.c:16
void MakeState(State_1D *)
Definition: tools.c:51
double inv_dtp
Inverse of diffusion (parabolic) time step .
Definition: structs.h:217
int BXn
Definition: globals.h:75
double ** vp
prim vars at i+1/2 edge, vp[i] = vL(i+1/2)
Definition: structs.h:142
int t1_beg
Definition: structs.h:319
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
Definition: globals.h:82
int CheckNaN(double **, int, int, int)
Definition: tools.c:19
void FARGO_SubtractVelocity(const Data *, Grid *)
#define THERMAL_CONDUCTION
Definition: pluto.h:365
#define VAR_LOOP(n)
Definition: macros.h:226
#define TOT_LOOP(k, j, i)
Definition: macros.h:44
int * pt1
Definition: structs.h:319
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
#define NVAR_LOOP(n)
Definition: pluto.h:618
int ConsToPrim(double **ucons, double **uprim, int ibeg, int iend, unsigned char *flag)
Definition: mappers.c:89
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
#define BXs
Definition: ct.h:33
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int * pt2
Definition: structs.h:320
int j
Definition: analysis.c:2
#define ARRAY_4D(nx, ny, nz, nv, type)
Definition: prototypes.h:173
int k
Definition: analysis.c:2
#define BX1s
Definition: ct.h:27
void SetIndexes(Index *indx, Grid *grid)
Definition: set_indexes.c:49
void RightHandSide(const State_1D *state, Time_Step *Dts, int beg, int end, double dt, Grid *grid)
Definition: rhs.c:88
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
Definition: structs.h:141
double ** uR
same as vR, in conservative vars
Definition: structs.h:145
int beg
Definition: structs.h:318
#define BX3
Definition: mod_defs.h:27
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
#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
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
void PrimToCons(double **uprim, double **ucons, int ibeg, int iend)
Definition: mappers.c:26
int i
Definition: analysis.c:2
double g_time
The current integration time.
Definition: globals.h:117
double * bn
Face magentic field, bn = bx(i+1/2)
Definition: structs.h:165
Definition: structs.h:317
double **** Uc
The main four-index data array used for cell-centered conservative variables.
Definition: structs.h:37
void SB_SaveFluxes(State_1D *state, Grid *grid)
Definition: sb_flux.c:57
#define BX1
Definition: mod_defs.h:25
double ** um
same as vm, in conservative vars
Definition: structs.h:146
void ParabolicFlux(Data_Arr V, Data_Arr J, double ***T, const State_1D *state, double **dcoeff, int beg, int end, Grid *grid)
double ** vL
Primitive variables to the left of the interface, .
Definition: structs.h:136
#define BX2s
Definition: ct.h:28
double ** up
same as vp, in conservative vars
Definition: structs.h:147
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define BX2
Definition: mod_defs.h:26
void FlagShock(const Data *, Grid *)
void VectorPotentialUpdate(const Data *d, const void *vp, const State_1D *state, const Grid *grid)
#define JDIR
Definition: pluto.h:194
int end
Definition: structs.h:318
#define NVAR
Definition: pluto.h:609
Definition: structs.h:346
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define EXPLICIT
Definition: pluto.h:67
#define TRANSVERSE_LOOP(indx, ip, i, j, k)
Definition: macros.h:54
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 ** uL
same as vL, in conservative vars
Definition: structs.h:144
void CT_AverageMagneticField(double ****bf, double ****UU, Grid *grid)
#define ALL_DIR
Definition: pluto.h:196

Here is the call graph for this function:

Here is the caller graph for this function:

void AdvectFlux ( const State_1D state,
int  beg,
int  end,
Grid grid 
)
Parameters
[in,out]state
[in]beginitial index of computation
[in]endfinal index of computation
Returns
This function has no return value.

Definition at line 47 of file adv_flux.c.

56 {
57  int i, nv;
58  double *ts, *flux, *vL, *vR;
59  double s, rho;
60  double phi;
61  static double *sigma, **vi;
62 
63 /* -- compute scalar's fluxes -- */
64 
65  for (i = beg; i <= end; i++){
66 
67  flux = state->flux[i];
68  vL = state->vL[i];
69  vR = state->vR[i];
70 
71  ts = flux[RHO] > 0.0 ? vL:vR;
72 
73  NSCL_LOOP(nv) flux[nv] = flux[RHO]*ts[nv];
74 
75  #if COOLING == MINEq
76 
77  /* ----- He ----- */
78 
79  phi = ts[X_HeI] + ts[X_HeII];
80  for (nv = X_HeI; nv <= X_HeII; nv++) flux[nv] /= phi;
81 
82  /* ----- C ----- */
83 
84  phi = 0.0;
85  for (nv = X_CI; nv < X_CI + C_IONS; nv++) phi += ts[nv];
86  for (nv = X_CI; nv < X_CI + C_IONS; nv++) flux[nv] /= phi;
87 
88  /* ----- N ----- */
89 
90  phi = 0.0;
91  for (nv = X_NI; nv < X_NI+N_IONS; nv++) phi += ts[nv];
92  for (nv = X_NI; nv < X_NI+N_IONS; nv++) flux[nv] /= phi;
93 
94  /* ----- O ----- */
95 
96  phi = 0.0;
97  for (nv = X_OI; nv < X_OI+O_IONS; nv++) phi += ts[nv];
98  for (nv = X_OI; nv < X_OI+O_IONS; nv++) flux[nv] /= phi;
99 
100  /* ----- Ne ----- */
101 
102  phi = 0.0;
103  for (nv = X_NeI; nv < X_NeI+Ne_IONS; nv++) phi += ts[nv];
104  for (nv = X_NeI; nv < X_NeI+Ne_IONS; nv++) flux[nv] /= phi;
105 
106  /* ----- S ----- */
107 
108  phi = 0.0;
109  for (nv = X_SI; nv < X_SI+S_IONS; nv++) phi += ts[nv];
110  for (nv = X_SI; nv < X_SI+S_IONS; nv++) flux[nv] /= phi;
111 
112  #endif
113 
114  #if COOLING == H2_COOL
115  phi = ts[X_HI] + 2.0*ts[X_H2] + ts[X_HII];
116  for (nv = X_HI; nv < X_HI + NIONS; nv++) flux[nv] /= phi;
117  #endif
118 
119  #if USE_CMA == YES /* -- only for tracers -- */
120  phi = 0.0;
121  NTRACER_LOOP(nv) phi += ts[nv];
122  NTRACER_LOOP(nv) flux[nv] /= phi;
123  #endif
124 
125  #if ENTROPY_SWITCH
126  if (flux[RHO] >= 0.0) flux[ENTR] = state->vL[i][ENTR]*flux[RHO];
127  else flux[ENTR] = state->vR[i][ENTR]*flux[RHO];
128  #endif
129  }
130 }
#define S_IONS
Definition: cooling.h:17
#define NSCL_LOOP(n)
Definition: pluto.h:616
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
#define RHO
Definition: mod_defs.h:19
#define C_IONS
Definition: cooling.h:13
#define NTRACER_LOOP(n)
Definition: pluto.h:615
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
#define O_IONS
Definition: cooling.h:15
Definition: cooling.h:110
#define X_HII
Definition: cooling.h:31
#define NIONS
Definition: cooling.h:28
Definition: cooling.h:110
#define s
#define Ne_IONS
Definition: cooling.h:16
int i
Definition: analysis.c:2
#define X_H2
Definition: cooling.h:30
double ** vL
Primitive variables to the left of the interface, .
Definition: structs.h:136
#define N_IONS
Definition: cooling.h:14

Here is the caller graph for this function:

void Analysis ( const Data d,
Grid grid 
)

Perform runtime data analysis.

Parameters
[in]dthe PLUTO Data structure
[in]gridpointer to array of Grid structures

Compute volume-integrated magnetic pressure, Maxwell and Reynolds stresses. Save them to "averages.dat"

Definition at line 66 of file init.c.

74 {
75 
76 }

Here is the call graph for this function:

Here is the caller graph for this function:

char* Array1D ( int  nx,
size_t  dsize 
)

Allocate memory for a 1-D array of any basic data type starting at 0.

Parameters
[in]nxnumber of elements to be allocated
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char *) to the allocated memory area.

Definition at line 80 of file arrays.c.

90 {
91  char *v;
92  v = (char *) malloc (nx*dsize);
93  PlutoError (!v, "Allocation failure in Array1D");
94  g_usedMemory += nx*dsize;
95 
96  #if NONZERO_INITIALIZE == YES
97  if (dsize==sizeof(double)){
98  int i;
99  double *q;
100  q = (double *) v;
101  for (i = nx; i--; ) q[i] = i*1.e18 - 1.e16;
102  }
103  #endif
104  return v;
105 }
void PlutoError(int, char *)
Definition: tools.c:115
int i
Definition: analysis.c:2
static Runtime q
long int g_usedMemory
Amount of used memory in bytes.
Definition: globals.h:96

Here is the call graph for this function:

char** Array2D ( int  nx,
int  ny,
size_t  dsize 
)

Allocate memory for a 2-D array of any basic data type.

Parameters
[in]nxnumber of elements in the 2nd dimension
[in]nynumber of elements in the 1st dimension
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char **) to the allocated memory area with index range [0...nx-1][0...ny-1]

Definition at line 108 of file arrays.c.

120 {
121  int i;
122  char **m;
123 
124  m = (char **)malloc ((size_t) nx*sizeof(char *));
125  PlutoError (!m, "Allocation failure in Array2D (1)");
126  m[0] = (char *) malloc ((size_t) nx*ny*dsize);
127  PlutoError (!m[0],"Allocation failure in Array2D (2)");
128 
129  for (i = 1; i < nx; i++) m[i] = m[(i - 1)] + ny*dsize;
130 
131  g_usedMemory += nx*ny*dsize;
132 
133  #if NONZERO_INITIALIZE == YES
134  if (dsize==sizeof(double)){
135  int j;
136  double **q;
137  q = (double **)m;
138  for (i = nx; i--; ){
139  for (j = ny; j--; ){
140  q[i][j] = i*j*1.e18 + 1.e16*j;
141  }}
142  }
143  #endif
144 
145  return m;
146 }
int j
Definition: analysis.c:2
void PlutoError(int, char *)
Definition: tools.c:115
int i
Definition: analysis.c:2
static Runtime q
long int g_usedMemory
Amount of used memory in bytes.
Definition: globals.h:96

Here is the call graph for this function:

char*** Array3D ( int  nx,
int  ny,
int  nz,
size_t  dsize 
)

Allocate memory for a 3-D array of any basic data type.

Parameters
[in]nxnumber of elements in the 3rd dimension
[in]nynumber of elements in the 2nd dimension
[in]nznumber of elements in the 1st dimension
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char ***) to the allocated memory area with index range [0...nx-1][0...ny-1][0...nz-1]

Definition at line 149 of file arrays.c.

162 {
163  int i, j;
164  char ***m;
165 
166  m = (char ***) malloc ((size_t) nx*sizeof (char **));
167  PlutoError (!m, "Allocation failure in Array3D (1)");
168 
169  m[0] = (char **) malloc ((size_t) nx*ny*sizeof(char *));
170  PlutoError (!m[0],"Allocation failure in Array3D (2)");
171 
172  m[0][0] = (char *) malloc ((size_t) nx*ny*nz*dsize);
173  PlutoError (!m[0][0],"Allocation failure in Array3D (3)");
174 
175 /* ---------------------------
176  single subscript: i
177  --------------------------- */
178 
179  for (i = 1; i < nx; i++) m[i] = m[i - 1] + ny;
180 
181 /* ---------------------------
182  double subscript:
183 
184  (i,0) (0,j)
185  (i,j)
186  --------------------------- */
187 
188  for (j = 1; j < ny; j++) m[0][j] = m[0][j - 1] + nz*dsize;
189  for (i = 1; i < nx; i++) m[i][0] = m[i - 1][0] + ny*nz*dsize;
190 
191  for (i = 1; i < nx; i++) {
192  for (j = 1; j < ny; j++) {
193  m[i][j] = m[i][j - 1] + nz*dsize;
194  }}
195 
196  for (j = 0; j < ny; j++){
197  for (i = 0; i < nx; i++){
198  if (m[i][j] == NULL){
199  print ("! Allocation failure in Array3D\n");
200  QUIT_PLUTO(1);
201  }
202  }}
203 
204  g_usedMemory += nx*ny*nz*dsize;
205 
206  #if NONZERO_INITIALIZE == YES
207  if (dsize==sizeof(double)){
208  double ***q;
209  int k;
210  q = (double ***)m;
211  for (i = nx; i--; ){
212  for (j = ny; j--; ){
213  for (k = nz; k--; ){
214  q[i][j][k] = 1.e18*i + 1.e17*j + 1.e16*k + 1.e15;
215  }}}
216  }
217  #endif
218 
219  return m;
220 }
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
void PlutoError(int, char *)
Definition: tools.c:115
int i
Definition: analysis.c:2
static Runtime q
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
long int g_usedMemory
Amount of used memory in bytes.
Definition: globals.h:96

Here is the call graph for this function:

char**** Array4D ( int  nx,
int  ny,
int  nz,
int  nv,
size_t  dsize 
)

Allocate memory for a 4-D array of any basic data type.

Parameters
[in]nxnumber of elements in the 4th dimension
[in]nynumber of elements in the 3rd dimension
[in]nznumber of elements in the 2nd dimension
[in]nvnumber of elements in the 1st dimension
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char ****) to the allocated memory area with index range [0...nx-1][0...ny-1][0...nz-1][0...nv-1]

Definition at line 222 of file arrays.c.

236 {
237  int i, j, k;
238  char ****m;
239 
240  m = (char ****) malloc ((size_t) nx*sizeof (char ***));
241  PlutoError (!m, "Allocation failure in Array4D (1)");
242 
243  m[0] = (char ***) malloc ((size_t) nx*ny*sizeof (char **));
244  PlutoError (!m[0], "Allocation failure in Array4D (2)");
245 
246  m[0][0] = (char **) malloc ((size_t) nx*ny*nz*sizeof (char *));
247  PlutoError (!m[0][0], "Allocation failure in Array4D (3)");
248 
249  m[0][0][0] = (char *) malloc ((size_t) nx*ny*nz*nv*dsize);
250  PlutoError (!m[0][0][0], "Allocation failure in Array4D (4)");
251 
252 /* ---------------------------
253  single subscript: i
254  --------------------------- */
255 
256  for (i = 1; i < nx; i++) m[i] = m[i - 1] + ny;
257 
258 /* ---------------------------
259  double subscript:
260 
261  (i,0) (0,j)
262  (i,j)
263  --------------------------- */
264 
265  for (i = 1; i < nx; i++) {
266  m[i][0] = m[i - 1][0] + ny*nz;
267  }
268  for (j = 1; j < ny; j++) {
269  m[0][j] = m[0][j - 1] + nz;
270  }
271 
272  for (i = 1; i < nx; i++) {
273  for (j = 1; j < ny; j++) {
274  m[i][j] = m[i][j - 1] + nz;
275  }}
276 
277 /* ---------------------------
278  triple subscript:
279 
280  (i,0,0) (0,j,0) (0,0,k)
281  (i,j,0) (i,0,k) (0,j,k)
282  (i,j,k)
283  --------------------------- */
284 
285  for (i = 1; i < nx; i++) {
286  m[i][0][0] = m[i - 1][0][0] + ny*nz*nv*dsize;
287  }
288  for (j = 1; j < ny; j++) {
289  m[0][j][0] = m[0][j - 1][0] + nz*nv*dsize;
290  }
291 
292  for (k = 1; k < nz; k++) {
293  m[0][0][k] = m[0][0][k - 1] + nv*dsize;
294  }
295 
296 
297  for (i = 1; i < nx; i++) {
298  for (j = 1; j < ny; j++) {
299  m[i][j][0] = m[i][j - 1][0] + nz*nv*dsize;
300  }}
301 
302  for (i = 1; i < nx; i++) {
303  for (k = 1; k < nz; k++) {
304  m[i][0][k] = m[i][0][k - 1] + nv*dsize;
305  }}
306 
307  for (j = 1; j < ny; j++) {
308  for (k = 1; k < nz; k++) {
309  m[0][j][k] = m[0][j][k - 1] + nv*dsize;
310  }}
311 
312  for (i = 1; i < nx; i++) {
313  for (j = 1; j < ny; j++) {
314  for (k = 1; k < nz; k++) {
315  m[i][j][k] = m[i][j][k - 1] + nv*dsize;
316  }
317  }
318  }
319 
320  g_usedMemory += nx*ny*nz*nv*dsize;
321 
322  #if NONZERO_INITIALIZE == YES
323  if (dsize==sizeof(double)){
324  int l;
325  double ****q;
326  q = (double ****)m;
327  for (i = nx; i--; ){
328  for (j = ny; j--; ){
329  for (k = nz; k--; ){
330  for (l = nv; l--; ){
331  q[i][j][k][l] = l*1.e18*i + 1.e17*i*j - 1.e16*k*j + 1.e17;
332  }}}}
333  }
334  #endif
335 
336  return m;
337 }
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
void PlutoError(int, char *)
Definition: tools.c:115
int i
Definition: analysis.c:2
static Runtime q
long int g_usedMemory
Amount of used memory in bytes.
Definition: globals.h:96

Here is the call graph for this function:

double*** ArrayBox ( long int  nrl,
long int  nrh,
long int  ncl,
long int  nch,
long int  ndl,
long int  ndh 
)

Allocate memory for a 3-D array in double precision with given subscript range [low...high] for each direction. Useful for staggered arrays which do not start at [0].

Parameters
[in]nrllower bound index for the 3rd dimension
[in]nrhupper bound index for the 3rd dimension
[in]ncllower bound index for the 2nd dimension
[in]nchupper bound index for the 2nd dimension
[in]ndllower bound index for the 1st dimension
[in]ndhupper bound index for the 1st dimension
Returns
A pointer of type (double ***) to the allocated memory area with index range [nrl...nhl][ncl...nch][ndl...ndh].

Definition at line 341 of file arrays.c.

360 {
361  long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
362  double ***t;
363 
364 /* allocate pointers to pointers to rows */
365 
366  t=(double ***) malloc((unsigned int)(nrow*sizeof(double**)));
367  if (!t) {
368  print ("! ArrayBox: allocation failure (1)\n");
369  QUIT_PLUTO(1);
370  }
371  t -= nrl;
372 
373 /* allocate pointers to rows and set pointers to them */
374 
375  t[nrl]=(double **) malloc((unsigned int)(nrow*ncol*sizeof(double*)));
376  if (!t[nrl]) {
377  print ("! ArrayBox: allocation failure (2)\n");
378  QUIT_PLUTO(1);
379  }
380  t[nrl] -= ncl;
381 
382 /* allocate rows and set pointers to them */
383 
384  t[nrl][ncl]=(double *) malloc((unsigned int)(nrow*ncol*ndep*sizeof(double)));
385  if (!t[nrl][ncl]) {
386  print ("! ArrayBox: allocation failure (3)\n");
387  QUIT_PLUTO(1);
388  }
389  t[nrl][ncl] -= ndl;
390 
391  for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
392  for(i=nrl+1;i<=nrh;i++) {
393  t[i]=t[i-1]+ncol;
394  t[i][ncl]=t[i-1][ncl]+ncol*ndep;
395  for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
396  }
397 
398 /* return pointer to array of pointers to rows */
399 
400  return t;
401 }
int j
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int i
Definition: analysis.c:2
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

Here is the caller graph for this function:

double*** ArrayBoxMap ( int  nrl,
int  nrh,
int  ncl,
int  nch,
int  ndl,
int  ndh,
double *  uptr 
)

Convert a one-dimensional array into a 3D array with given subscript range [low...high] for each direction.

Definition at line 537 of file arrays.c.

546 {
547  int i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
548  double ***t;
549 
550 /* -- allocate pointers to pointers to rows -- */
551 
552  t = (double ***) malloc((size_t)((nrow)*sizeof(double**)));
553  if (!t) {
554  print ("! ArrayBoxMap: allocation failure (1) \n");
555  QUIT_PLUTO (1);
556  }
557  t -= nrl;
558 
559 /* -- allocate pointers to rows and set pointers to them -- */
560 
561  t[nrl] = (double **) malloc((size_t)((nrow*ncol)*sizeof(double*)));
562  if (!t[nrl]) {
563  print ("! ArrayBoxMap: allocation failure (2) \n");
564  QUIT_PLUTO (1);
565  }
566  t[nrl] -= ncl;
567 
568  t[nrl][ncl] = uptr;
569  if (!t[nrl][ncl]) {
570  print ("! ArrayBoxMap: allocation failure (3) \n");
571  QUIT_PLUTO (1);
572  }
573  t[nrl][ncl] -= ndl;
574 
575  for(j = ncl+1; j <= nch; j++) t[nrl][j] = t[nrl][j-1] + ndep;
576  for(i = nrl+1; i <= nrh; i++) {
577  t[i] = t[i-1] + ncol;
578  t[i][ncl] = t[i-1][ncl] + ncol*ndep;
579  for(j = ncl+1; j <= nch; j++) t[i][j] = t[i][j-1] + ndep;
580  }
581 
582  return t;
583 }
int j
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int i
Definition: analysis.c:2
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

unsigned char*** ArrayCharMap ( int  ,
int  ,
int  ,
unsigned char *   
)

Definition at line 476 of file arrays.c.

478 {
479  int i,j;
480  unsigned char ***t;
481 
482 /* -- allocate pointers to pointers to rows -- */
483 
484  t = (unsigned char ***) malloc((size_t)((nx)*sizeof(unsigned char**)));
485  if (!t) {
486  print ("! ArrayCharMap: allocation failure (1) \n");
487  QUIT_PLUTO (1);
488  }
489 
490 /* -- allocate pointers to rows and set pointers to them -- */
491 
492  t[0] = (unsigned char **) malloc((size_t)((nx*ny)*sizeof(unsigned char*)));
493  if (!t[0]) {
494  print ("! ArrayCharMap: allocation failure (2) \n");
495  QUIT_PLUTO(1);
496  }
497 
498 /* -- make the 3D array point to uptr -- */
499 
500  t[0][0] = uptr;
501  if (!t[0][0]) {
502  print ("! ArrayCharMap: allocation failure (3) \n");
503  QUIT_PLUTO (1);
504  }
505 
506  for(j = 1; j < ny; j++) t[0][j]=t[0][j-1] + nz;
507 
508  for(i = 1; i < nx; i++) {
509  t[i] = t[i-1] + ny;
510  t[i][0] = t[i-1][0] + ny*nz;
511  for(j = 1; j < ny; j++) t[i][j] = t[i][j-1] + nz;
512  }
513 
514  return t;
515 }
int j
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int i
Definition: analysis.c:2
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

double*** ArrayMap ( int  nx,
int  ny,
int  nz,
double *  uptr 
)

Convert a one dimensional array with (nx*ny*nz) elements into a 3D array with index range [0..nx-1][0..ny-1][0..nz-1]. This function is similar, conceptually, to Array3D() except that the memory area is already allocated.

Parameters
[in]uptrpointer to 1D array
[in]nxnumber of elements in the 3rd dimension
[in]nynumber of elements in the 2nd dimensions
[in]nznumber of elements in the 1st dimensions
Returns
A pointer to the 3D array.

Definition at line 421 of file arrays.c.

436 {
437  int i,j;
438  double ***t;
439 
440 /* -- allocate pointers to pointers to rows -- */
441 
442  t = (double ***) malloc((size_t)((nx)*sizeof(double**)));
443  if (!t) {
444  print ("! ArrayMap: allocation failure (1) \n");
445  QUIT_PLUTO (1);
446  }
447 
448 /* -- allocate pointers to rows and set pointers to them -- */
449 
450  t[0] = (double **) malloc((size_t)((nx*ny)*sizeof(double*)));
451  if (!t[0]) {
452  print ("! ArrayMap: allocation failure (2) \n");
453  QUIT_PLUTO(1);
454  }
455 
456 /* -- make the 3D array point to uptr -- */
457 
458  t[0][0] = uptr;
459  if (!t[0][0]) {
460  print ("! ArrayMap: allocation failure (3) \n");
461  QUIT_PLUTO (1);
462  }
463 
464  for(j = 1; j < ny; j++) t[0][j]=t[0][j-1] + nz;
465 
466  for(i = 1; i < nx; i++) {
467  t[i] = t[i-1] + ny;
468  t[i][0] = t[i-1][0] + ny*nz;
469  for(j = 1; j < ny; j++) t[i][j] = t[i][j-1] + nz;
470  }
471 
472  return t;
473 }
int j
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int i
Definition: analysis.c:2
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

double BodyForcePotential ( double  ,
double  ,
double   
)

Definition at line 479 of file init.c.

484 {
485  double om2 = SB_OMEGA*SB_OMEGA;
486  double zb = g_domBeg[KDIR], ze = g_domEnd[KDIR];
487  double psi;
488 
489 #if STRATIFICATION == YES
490  psi = om2*(0.5*z*z - SB_Q*x*x);
491  #ifdef CTU /* see note in BodyForceVector() */
492  if (z > ze) psi -= 2.0*om2*ze*(z - ze);
493  if (z < zb) psi -= 2.0*om2*zb*(z - zb);
494  #endif
495  return psi;
496 #else
497  return -om2*SB_Q*x*x;
498 #endif
499 }
#define KDIR
Definition: pluto.h:195
#define SB_OMEGA
Disk local orbital frequency .
Definition: shearingbox.h:81
double g_domBeg[3]
Lower limits of the computational domain.
Definition: globals.h:125
#define SB_Q
The shear parameter, .
Definition: shearingbox.h:76
double g_domEnd[3]
Upper limits of the computational domain.
Definition: globals.h:126

Here is the caller graph for this function:

void BodyForcePotentialGet ( double **  v,
double **  gphi,
double *  phi_p,
double *  phi_c,
int  beg,
int  end,
Grid grid 
)
void BodyForceVector ( double *  v,
double *  g,
double  x,
double  y,
double  z 
)

Include gravitational force in the shearing box module. Coriolis terms are included elsewhere.

Note: with FARGO, gravity in the x-direction must not be included.

Definition at line 441 of file init.c.

449 {
450  double om2 = SB_OMEGA*SB_OMEGA;
451  double zb = g_domBeg[KDIR], ze = g_domEnd[KDIR];
452 
453 #ifdef FARGO
454  g[IDIR] = 0.0;
455 #else
456  g[IDIR] = om2*2.0*SB_Q*x;
457 #endif
458  g[JDIR] = 0.0;
459 
460 #if STRATIFICATION == YES
461  g[KDIR] = -om2*z;
462 
463 /* -----------------------------------------------------------
464  With CTU and a reflective vertical boundary, gravity must
465  be symmetrized since the predictor step of CTU does not
466  not preserve the symmetry.
467  ----------------------------------------------------------- */
468 
469  #ifdef CTU
470  if (z > ze) g[KDIR] += 2.0*om2*ze;
471  else if (z < zb) g[KDIR] += 2.0*om2*zb;
472  #endif
473 
474 #else
475  g[KDIR] = 0.0;
476 #endif
477 }
#define KDIR
Definition: pluto.h:195
#define IDIR
Definition: pluto.h:193
#define SB_OMEGA
Disk local orbital frequency .
Definition: shearingbox.h:81
double g_domBeg[3]
Lower limits of the computational domain.
Definition: globals.h:125
#define SB_Q
The shear parameter, .
Definition: shearingbox.h:76
double g_domEnd[3]
Upper limits of the computational domain.
Definition: globals.h:126
#define JDIR
Definition: pluto.h:194

Here is the caller graph for this function:

void BodyForceVectorGet ( double **  v,
double **  g,
double *  ,
double *  ,
double *  ,
int  beg,
int  end,
Grid grid 
)
void Boundary ( const Data d,
int  idim,
Grid grid 
)

Set boundary conditions on one or more sides of the computational domain.

Parameters
[in,out]dpointer to PLUTO Data structure containing the solution array (including centered and staggered fields)
[in]idimspecifies on which side(s) of the computational domain boundary conditions must be set. Possible values are
  • idim = IDIR first dimension (x1)
  • idim = JDIR second dimenson (x2)
  • idim = KDIR third dimension (x3)
  • idim = ALL_DIR all dimensions
[in]gridpointer to an array of grid structures.

Definition at line 36 of file boundary.c.

54 {
55  int is, nv, fargo_velocity_has_changed;
56  int side[6] = {X1_BEG, X1_END, X2_BEG, X2_END, X3_BEG, X3_END};
57  int type[6], sbeg, send, vsign[NVAR];
58  int par_dim[3] = {0, 0, 0};
59  double ***q;
60 
61 /* ---------------------------------------------------
62  Check the number of processors in each direction
63  --------------------------------------------------- */
64 
65  D_EXPAND(par_dim[0] = grid[IDIR].nproc > 1; ,
66  par_dim[1] = grid[JDIR].nproc > 1; ,
67  par_dim[2] = grid[KDIR].nproc > 1;)
68 
69 /* -------------------------------------------------
70  With FARGO, boundary conditions must be set on
71  total velocity.
72  We temporarily add the background motion if
73  the input array contains the deviation only.
74  ------------------------------------------------- */
75 
76  #ifdef FARGO
77  fargo_velocity_has_changed = NO;
78  if (FARGO_HasTotalVelocity() == NO) {
79  FARGO_AddVelocity (d,grid);
80  fargo_velocity_has_changed = YES;
81  }
82  #endif
83 
84 /* -------------------------------------------------
85  Call userdef internal boundary with side == 0
86  ------------------------------------------------- */
87 
88  #if INTERNAL_BOUNDARY == YES
89  UserDefBoundary (d, NULL, 0, grid);
90  #endif
91 
92 /* -------------------------------------
93  Exchange data between processors
94  ------------------------------------- */
95 
96  #ifdef PARALLEL
97  MPI_Barrier (MPI_COMM_WORLD);
98  for (nv = 0; nv < NVAR; nv++) {
99  AL_Exchange_dim ((char *)d->Vc[nv][0][0], par_dim, SZ);
100  }
101  #ifdef STAGGERED_MHD
102  D_EXPAND(
103  AL_Exchange_dim ((char *)(d->Vs[BX1s][0][0] - 1), par_dim, SZ_stagx); ,
104  AL_Exchange_dim ((char *)d->Vs[BX2s][0][-1] , par_dim, SZ_stagy); ,
105  AL_Exchange_dim ((char *)d->Vs[BX3s][-1][0] , par_dim, SZ_stagz);)
106  #endif
107  MPI_Barrier (MPI_COMM_WORLD);
108  #endif
109 
110 /* ----------------------------------------------------------------
111  When idim == ALL_DIR boundaries are imposed on ALL sides:
112  a loop from sbeg = 0 to send = 2*DIMENSIONS - 1 is performed.
113  When idim = n, boundaries are imposed at the beginning and
114  the end of the i-th direction.
115  ---------------------------------------------------------------- */
116 
117  if (idim == ALL_DIR) {
118  sbeg = 0;
119  send = 2*DIMENSIONS - 1;
120  } else {
121  sbeg = 2*idim;
122  send = 2*idim + 1;
123  }
124 
125 /* --------------------------------------------------------
126  Main loop on computational domain sides
127  -------------------------------------------------------- */
128 
129  type[0] = grid[IDIR].lbound; type[1] = grid[IDIR].rbound;
130  type[2] = grid[JDIR].lbound; type[3] = grid[JDIR].rbound;
131  type[4] = grid[KDIR].lbound; type[5] = grid[KDIR].rbound;
132 
133  for (is = sbeg; is <= send; is++){
134 
135  if (type[is] == 0) continue; /* no physical boundary: skip */
136 
137  if (type[is] == OUTFLOW) {
138 
139  /* -------------------------------
140  OUTFLOW boundary condition
141  ------------------------------- */
142 
143  for (nv = 0; nv < NVAR; nv++){
144  OutflowBound (d->Vc[nv], side[is], CENTER, grid + (is/2));
145  }
146  #ifdef STAGGERED_MHD
147  D_EXPAND(OutflowBound (d->Vs[BX1s], side[is], X1FACE, grid+(is/2)); ,
148  OutflowBound (d->Vs[BX2s], side[is], X2FACE, grid+(is/2)); ,
149  OutflowBound (d->Vs[BX3s], side[is], X3FACE, grid+(is/2));)
150 
151  /* ---------------------------------------------------------
152  average normal field only since transverse components
153  are assigned consistently with cell-centered quantities.
154  --------------------------------------------------------- */
155 
156  CT_AverageNormalMagField (d, side[is], grid);
157  #endif
158 
159  }else if ( (type[is] == REFLECTIVE)
160  || (type[is] == AXISYMMETRIC)
161  || (type[is] == EQTSYMMETRIC)){
162 
163  /* -------------------------------------
164  REFLECTIVE-type boundary conditions
165  ------------------------------------- */
166 
167  FlipSign (side[is], type[is], vsign);
168  for (nv = 0; nv < NVAR; nv++){
169  ReflectiveBound (d->Vc[nv], vsign[nv], side[is], CENTER);
170  }
171  #ifdef STAGGERED_MHD
172  D_EXPAND(ReflectiveBound(d->Vs[BX1s], vsign[BX1], side[is], X1FACE); ,
173  ReflectiveBound(d->Vs[BX2s], vsign[BX2], side[is], X2FACE); ,
174  ReflectiveBound(d->Vs[BX3s], vsign[BX3], side[is], X3FACE);)
175  #endif
176 
177  }else if (type[is] == PERIODIC) {
178 
179  /* ----------------------------------------
180  PERIODIC boundary condition (only for
181  one processor in the direction)
182  ---------------------------------------- */
183 
184  if (!par_dim[is/2]) {
185  for (nv = 0; nv < NVAR; nv++){
186  PeriodicBound (d->Vc[nv], side[is], CENTER);
187  }
188  #ifdef STAGGERED_MHD
189  D_EXPAND(PeriodicBound (d->Vs[BX1s], side[is], X1FACE); ,
190  PeriodicBound (d->Vs[BX2s], side[is], X2FACE); ,
191  PeriodicBound (d->Vs[BX3s], side[is], X3FACE);)
192  #endif
193 
194  }
195 
196  }else if (type[is] == SHEARING) { /* -- shearingbox boundary -- */
197 
198  /* ---------------------------------------------------------
199  SHEARING-BOX boundary condition is implemented as
200 
201  1) apply periodic boundary conditions for all variables
202  (except staggered BX)
203  2) Perform spatial shift in the y-direction
204  --------------------------------------------------------- */
205 
206  #ifdef SHEARINGBOX
207  if (side[is] != X1_BEG && side[is] != X1_END){
208  print1 ("! BOUNDARY: shearingbox can only be assigned at an X1 boundary\n");
209  QUIT_PLUTO(1);
210  }
211  if (grid[IDIR].nproc == 1){
212  for (nv = 0; nv < NVAR; nv++) {
213  PeriodicBound (d->Vc[nv], side[is], CENTER);
214  }
215  #ifdef STAGGERED_MHD
216  D_EXPAND( ; ,
217  PeriodicBound (d->Vs[BX2s], side[is], X2FACE); ,
218  PeriodicBound (d->Vs[BX3s], side[is], X3FACE);)
219  #endif
220  }
221  SB_Boundary (d, side[is], grid);
222 
223  /* -- assign normal component of staggered B
224  using the div.B = 0 condition -- */
225 
226  #ifdef STAGGERED_MHD
227  FillMagneticField (d, side[is], grid);
228  CT_AverageNormalMagField (d, side[is], grid);
229  CT_AverageTransverseMagField (d, side[is], grid);
230  #endif
231  #endif /* def SHEARINGBOX */
232 
233  }else if (type[is] == USERDEF) {
234 
235  /* --------------------------------------------------------------
236  USER-DEFINED boundary condition
237  -------------------------------------------------------------- */
238 
239  #ifdef GLM_MHD
240  {int i,j,k;
241  switch(side[is]){
242  case X1_BEG: X1_BEG_LOOP(k,j,i) d->Vc[PSI_GLM][k][j][i] = 0.0; break;
243  case X1_END: X1_END_LOOP(k,j,i) d->Vc[PSI_GLM][k][j][i] = 0.0; break;
244  case X2_BEG: X2_BEG_LOOP(k,j,i) d->Vc[PSI_GLM][k][j][i] = 0.0; break;
245  case X2_END: X2_END_LOOP(k,j,i) d->Vc[PSI_GLM][k][j][i] = 0.0; break;
246  case X3_BEG: X3_BEG_LOOP(k,j,i) d->Vc[PSI_GLM][k][j][i] = 0.0; break;
247  case X3_END: X3_END_LOOP(k,j,i) d->Vc[PSI_GLM][k][j][i] = 0.0; break;
248  }
249  }
250  #endif
251 
252  RBox *box = GetRBox(side[is], CENTER);
253  UserDefBoundary (d, box, side[is], grid);
254  #ifdef STAGGERED_MHD
255  D_EXPAND(box = GetRBox(side[is], X1FACE);
256  UserDefBoundary (d, box, side[is], grid); ,
257  box = GetRBox(side[is], X2FACE);
258  UserDefBoundary (d, box, side[is], grid); ,
259  box = GetRBox(side[is], X3FACE);
260  UserDefBoundary (d, box, side[is], grid);)
261 
262  /* -- assign normal component of staggered B
263  using the div.B = 0 condition -- */
264 
265  FillMagneticField (d, side[is], grid);
266  CT_AverageNormalMagField (d, side[is], grid);
267  CT_AverageTransverseMagField (d, side[is], grid);
268  #endif
269  }
270  }
271 
272 /* --------------------------------------------------
273  With FARGO, restore velocity deviation if the
274  original input array to Boundary() did not
275  contain the background velocity.
276  -------------------------------------------------- */
277 
278  #ifdef FARGO
279  if (fargo_velocity_has_changed){
281  }
282  #endif
283 
284 /* -------------------------------------------------------
285  Compute entropy for the next time level
286  ------------------------------------------------------- */
287 
288  #if ENTROPY_SWITCH
289  ComputeEntropy (d, grid);
290  #endif
291 
292 }
#define X3_BEG
Boundary region at X3 beg.
Definition: pluto.h:150
#define SHEARING
Definition: pluto.h:138
int AL_Exchange_dim(char *buf, int *dims, int sz_ptr)
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
int lbound
When different from zero, it specifies the boundary condition to be applied at leftmost grid side whe...
Definition: structs.h:105
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
RBox * GetRBox(int, int)
Definition: rbox.c:232
void OutflowBound(double ***q, int side, int vpos, Grid *grid)
Definition: boundary.c:295
#define CENTER
Definition: pluto.h:200
void FillMagneticField(const Data *d, int side, Grid *grid)
Assign the normal component of the staggered magnetic field in the ghost zone-faces.
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
#define X3FACE
Definition: pluto.h:203
void SB_Boundary(const Data *d, int side, Grid *grid)
Definition: sb_boundary.c:27
#define YES
Definition: pluto.h:25
int rbound
Same as lbound, but for the right edge of the grid.
Definition: structs.h:112
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
void FlipSign(int side, int type, int *vsign)
Definition: boundary.c:408
void PeriodicBound(double ***q, int side, int vpos)
Definition: boundary.c:568
#define PSI_GLM
Definition: mod_defs.h:34
#define X3_END_LOOP(k, j, i)
Definition: macros.h:52
#define BX3s
Definition: ct.h:29
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
void FARGO_AddVelocity(const Data *, Grid *)
#define X2_BEG_LOOP(k, j, i)
Definition: macros.h:47
#define KDIR
Definition: pluto.h:195
int FARGO_HasTotalVelocity()
int SZ_stagx
Definition: globals.h:24
void ComputeEntropy(const Data *, Grid *)
int SZ_stagy
Definition: globals.h:25
#define X1FACE
Definition: pluto.h:201
void FARGO_SubtractVelocity(const Data *, Grid *)
#define X2_END_LOOP(k, j, i)
Definition: macros.h:51
#define IDIR
Definition: pluto.h:193
#define USERDEF
Definition: pluto.h:139
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
int j
Definition: analysis.c:2
int SZ_stagz
Definition: globals.h:26
int k
Definition: analysis.c:2
void CT_AverageNormalMagField(const Data *d, int side, Grid *grid)
Compute the normal component of the volume-average magnetic field from the staggered components in th...
#define BX1s
Definition: ct.h:27
#define X1_END_LOOP(k, j, i)
Definition: macros.h:50
void CT_AverageTransverseMagField(const Data *d, int side, Grid *grid)
Compute the transverse component of the volume-average magnetic field from the staggered components i...
#define BX3
Definition: mod_defs.h:27
#define X3_END
Boundary region at X3 end.
Definition: pluto.h:151
#define OUTFLOW
Definition: pluto.h:133
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
#define X1_BEG_LOOP(k, j, i)
Definition: macros.h:46
#define REFLECTIVE
Definition: pluto.h:134
int i
Definition: analysis.c:2
#define BX1
Definition: mod_defs.h:25
void ReflectiveBound(double ***q, int s, int side, int vpos)
Definition: boundary.c:501
#define BX2s
Definition: ct.h:28
#define X2_BEG
Boundary region at X2 beg.
Definition: pluto.h:148
#define AXISYMMETRIC
Definition: pluto.h:135
#define BX2
Definition: mod_defs.h:26
#define PERIODIC
Definition: pluto.h:137
Definition: al_hidden.h:38
#define EQTSYMMETRIC
Definition: pluto.h:136
#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
#define X2FACE
Definition: pluto.h:202
void UserDefBoundary(const Data *, RBox *, int, Grid *)
Definition: init.c:98
#define X3_BEG_LOOP(k, j, i)
Definition: macros.h:48
int nproc
number of processors for this grid.
Definition: structs.h:120
#define DIMENSIONS
Definition: definitions_01.h:2
#define NO
Definition: pluto.h:26
#define ALL_DIR
Definition: pluto.h:196

Here is the call graph for this function:

Here is the caller graph for this function:

void ChangeDumpVar ( )

Definition at line 21 of file userdef_output.c.

26 {
27  Image *image;
28 
29 }
Definition: structs.h:300
static Image image[MAX_IMAGE_NUMBER]
Definition: set_image.c:4

Here is the call graph for this function:

Here is the caller graph for this function:

void CharTracingStep ( const State_1D state,
int  beg,
int  end,
Grid grid 
)

Compute interface states using characteristic tracing step.

Parameters
[in]statepointer to a State_1D structure
[in]beginitial index of computation
[in]endfinal index of computation
[in]gridpointer to an array of Grid structures
Returns
This function has no return value.

Tasks are numbered below.

1) Compute eigenvectors and eigenvalues if not yet defined.

2) Obtain characteristic variable increments dwp and dwm.

3) Initialize vp and vm to the reference state. Since this is somewhat arbitrary we use the value of CHTR_REF_STATE to select one of the following cases:

  • CHTR_REF_STATE==1: use cell-center value;
  • CHTR_REF_STATE==2: interpolated value at base time level
  • CHTR_REF_STATE==3: traditional PPM reference state (fastest wave), minimize the size of the term subject to characteristic limiting.

Passive scalars use always CHTR_REF_STATE == 2.

4) Compute left and right states in primitive variables. This step also depends on the value of CHTR_REF_STATE and include:

  • evolve characteristic variable increments by dt/2;
  • discard contributions from waves not reaching the interface;
  • project characteristic differences dwp and dwm onto right eigenvectors

5) Add source term to L/R states

6) Repeat construction for passive scalars

Definition at line 198 of file char_tracing.c.

219 {
220  int i, j, k, nv;
221  double dx, dtdx, scrh;
222  double dv[NVAR], dw[NVAR];
223  double nu_max=1.0, nu_min=-1.0, nu[NVAR];
224  double *vc, *vp, *vm, **L, **R, *lambda;
225  double *dfR, *dfL;
226  #if GEOMETRY != CARTESIAN
227  double betaL[NVAR], betaR[NVAR];
228  #endif
229  static double **src;
230 
231 /* --------------------------------------------
232  allocate memory and set pointer shortcuts
233  -------------------------------------------- */
234 
235  if (src == NULL){
236  src = ARRAY_2D(NMAX_POINT, NVAR, double);
237  }
238 
239  #if GEOMETRY != CARTESIAN
240  dfL = grid[g_dir].dfL;
241  dfR = grid[g_dir].dfR;
242  #endif
243 
244 /* ---------------------------------------------
245  define some useful quantities, compute
246  source term and undivided differences
247  --------------------------------------------- */
248 
249  #if CHAR_LIMITING == NO
250  SoundSpeed2 (state->v, state->a2, state->h, beg, end, CELL_CENTER, grid);
251  #endif
252 
253  PrimSource (state, beg, end, state->a2, state->h, src, grid);
254  for (i = beg; i <= end; i++){
255 
256  dx = grid[g_dir].dx[i];
257  dtdx = g_dt/dx;
258 
259  vc = state->v[i];
260  vp = state->vp[i];
261  vm = state->vm[i];
262  L = state->Lp[i];
263  R = state->Rp[i];
264  lambda = state->lambda[i];
265 
266  /* --------------------------------------------------------------
267  1. Compute eigenvectors and eigenvalues if not yet defined
268  -------------------------------------------------------------- */
269 
270  #if CHAR_LIMITING == NO
271  PrimEigenvectors (vc, state->a2[i], state->h[i], lambda, L, R);
272  #if NVAR != NFLX
273  for (k = NFLX; k < NVAR; k++) lambda[k] = vc[V1];
274  #endif
275  #endif
276  for (k = 0; k < NVAR; k++) nu[k] = dtdx*lambda[k];
277  nu_max = MAX(nu[1], 0.0); nu_min = MIN(nu[0], 0.0);
278 
279  /* ------------------------------------------------------------
280  1a. Geometry
281  ------------------------------------------------------------ */
282 
283 
284  #if GEOMETRY == CYLINDRICAL || GEOMETRY == POLAR
285  if (g_dir == IDIR) {
286  double *xR = grid[IDIR].xr;
287  for (k = NVAR; k--; ){
288 betaR[k] = betaL[k] = 0.0;
289 /*
290  scrh = nu[k]*dx;
291  betaR[k] = (nu[k] > 1.e-12 ? scrh/(6.0*xR[i] - 3.0*scrh):0.0);
292  betaL[k] = (nu[k] < -1.e-12 ? -scrh/(6.0*xR[i-1] - 3.0*scrh):0.0);
293 */
294  }
295  nu_max *= (1.0 - betaR[1]);
296  nu_min *= (1.0 + betaL[0]);
297  }else{
298  for (k = NVAR; k--; ) betaR[k] = betaL[k] = 0.0;
299  }
300  #endif
301 
302 
303  /* --------------------------------------------------------------
304  2. Obtain characteristic variable increment dw
305  -------------------------------------------------------------- */
306 
307  for (nv = NVAR; nv--; ) dv[nv] = vp[nv] - vm[nv];
308  PrimToChar(L, dv, dw);
309 
310  /* ----------------------------------------------------------------
311  3. Initialize vp and vm to the reference state.
312  Since this is somewhat arbitrary we set it using REF_STATE:
313 
314  REF_STATE==1: use cell-center value;
315  REF_STATE==2: interpolated value at base time level
316  REF_STATE==3: traditional PPM reference state (fastest
317  wave), minimize the size of the term
318  subject to characteristic limiting.
319 
320  Passive scalars use always REF_STATE == 2.
321  ---------------------------------------------------------------- */
322 
323  #if REF_STATE == 1
324  for (nv = NFLX; nv--; ) vp[nv] = vm[nv] = vc[nv];
325  #elif REF_STATE == 3
326  for (nv = NFLX; nv--; ) {
327  #if GEOMETRY == CARTESIAN
328  vp[nv] = vc[nv] + 0.5*dv[nv]*(1.0 - nu_max);
329  vm[nv] = vc[nv] - 0.5*dv[nv]*(1.0 + nu_min);
330  #else
331  vp[nv] = vc[nv] + dv[nv]*(dfR[i] - 0.5*nu_max);
332  vm[nv] = vc[nv] + dv[nv]*(dfL[i] - 0.5*nu_min);
333  #endif
334  }
335  #endif
336 
337  /* --------------------------------------------------------------------
338  4. Compute L/R states in primitive variables:
339 
340  Evolve interface states for dt/2 using characteristic tracing.
341  Depending on the choice of the reference state (i.e.
342  REF_STATE = 1,2,3) we compute, e.g. Vp(t+dt/2), as
343 
344  Vp(t+dt/2) = \sum [w + dw*dfR - nu*dw*(1-beta)]*R =
345 
346  = V + \sum [dfR - nu*(1-beta)]*dw*R (REF_STATE = 1)
347  = Vp + \sum [ - nu*(1-beta)]*dw*R (REF_STATE = 2)
348  = Vmax + \sum [nu_max*(1-beta_max) - nu*(1-beta)]*dw*R (REF_STATE = 3)
349 
350  where Vmax = Vp - nu_max*(1-beta_max) is the reference state
351  of the original PPM algorithm.
352  -------------------------------------------------------------------- */
353 
354  #ifdef GLM_MHD /* -- hot fix for backward test compatibility
355  must review this at some point !! -- */
356  nu_max = nu[1]; nu_min = nu[0];
357  #endif
358 
359  for (k = 0; k < NFLX; k++){
360  if (nu[k] >= 0.0) {
361  #if GEOMETRY != CARTESIAN
362  nu[k] *= (1.0 - betaR[k]);
363  #endif
364  #if REF_STATE == 1
365  dw[k] *= 0.5*(1.0 - nu[k]);
366  #elif REF_STATE == 2
367  dw[k] *= -0.5*nu[k];
368  #elif REF_STATE == 3
369  dw[k] *= 0.5*(nu_max - nu[k]);
370  #endif
371  for (nv = 0; nv < NFLX; nv++) vp[nv] += dw[k]*R[nv][k];
372  }else{
373  #if GEOMETRY != CARTESIAN
374  nu[k] *= (1.0 + betaL[k]);
375  #endif
376  #if REF_STATE == 1
377  dw[k] *= -0.5*(1.0 + nu[k]);
378  #elif REF_STATE == 2
379  dw[k] *= -0.5*nu[k];
380  #elif REF_STATE == 3
381  dw[k] *= 0.5*(nu_min - nu[k]);
382  #endif
383  for (nv = 0; nv < NFLX; nv++) vm[nv] += dw[k]*R[nv][k];
384  }
385  }
386 
387  /* -------------------------------------------------------
388  5. Add source term to L/R states
389  ------------------------------------------------------- */
390 
391  for (nv = NFLX; nv--; ) {
392  vp[nv] += 0.5*g_dt*src[i][nv];
393  vm[nv] += 0.5*g_dt*src[i][nv];
394  }
395 
396  /* -------------------------------------------------------
397  6. Repeat construction for passive scalars
398  ------------------------------------------------------- */
399 
400  #if NVAR != NFLX
401  for (nv = NFLX; nv < NVAR; nv++) {
402  #if GEOMETRY == CARTESIAN
403  vp[nv] = vc[nv] + 0.5*dv[nv];
404  vm[nv] = vc[nv] - 0.5*dv[nv];
405  #else
406  vp[nv] = vc[nv] + dv[nv]*dfR[i];
407  vm[nv] = vc[nv] + dv[nv]*dfL[i];
408  #endif
409  }
410  if (nu[NFLX] >= 0.0){ /* -- scalars all move at the flow speed -- */
411  scrh = -0.5*nu[NFLX];
412  #if GEOMETRY != CARTESIAN
413  scrh *= (1.0 - betaR[k]);
414  #endif
415  for (k = NFLX; k < NVAR; k++) vp[k] += dw[k]*scrh;
416  }else {
417  scrh = -0.5*nu[NFLX];
418  #if GEOMETRY != CARTESIAN
419  scrh *= (1.0 + betaL[k]);
420  #endif
421  for (k = NFLX; k < NVAR; k++) vm[k] += dw[k]*scrh;
422  }
423  #endif
424 
425  } /* -- end main loop on grid points -- */
426 
427 /* -------------------------------------------
428  Shock flattening (only 1D)
429  ------------------------------------------- */
430 
431  #if SHOCK_FLATTENING == ONED
432  Flatten (state, beg, end, grid);
433  #endif
434 
435 /* -------------------------------------------
436  Assign face-centered magnetic field
437  ------------------------------------------- */
438 
439  #ifdef STAGGERED_MHD
440  for (i = beg-1; i <= end; i++) {
441  state->vR[i][BXn] = state->vL[i][BXn] = state->bn[i];
442  }
443  #endif
444 
445 /* --------------------------------------------------------
446  evolve cell-center values by dt/2
447  -------------------------------------------------------- */
448 
449  CheckPrimStates (state->vm, state->vp, state->v, beg, end);
450 
451  for (i = beg; i <= end; i++){
452  vp = state->vp[i];
453  vm = state->vm[i];
454  for (nv = NVAR; nv--; ) {
455  state->vh[i][nv] = 0.5*(vp[nv] + vm[nv]);
456  }
457  }
458 
459 }
#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
double ** vh
Primitive state at n+1/2 (only for one step method)
Definition: structs.h:162
void Flatten(const State_1D *, int, int, Grid *)
Definition: flatten.c:4
double *** Lp
Definition: structs.h:155
void PrimEigenvectors(double *q, double cs2, double h, double *lambda, double **LL, double **RR)
Definition: eigenv.c:91
double * xr
Definition: structs.h:81
tuple scrh
Definition: configure.py:200
void CheckPrimStates(double **vM, double **vP, double **v0, int beg, int end)
Definition: check_states.c:4
double g_dt
The current integration time step.
Definition: globals.h:118
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
double * dx
Definition: structs.h:83
double * h
Enthalpy.
Definition: structs.h:159
void SoundSpeed2(double **v, double *cs2, double *h, int beg, int end, int pos, Grid *grid)
Definition: eos.c:16
int BXn
Definition: globals.h:75
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
#define CELL_CENTER
Definition: pluto.h:205
#define NFLX
Definition: mod_defs.h:32
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int j
Definition: analysis.c:2
double ** lambda
Characteristic speed associated to Lp and Rp.
Definition: structs.h:156
int k
Definition: analysis.c:2
void PrimSource(const State_1D *, int, int, double *, double *, double **, Grid *)
Definition: prim_eqn.c:71
void PrimToChar(double **L, double *v, double *w)
Definition: eigenv.c:593
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
Definition: structs.h:141
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
int i
Definition: analysis.c:2
double * bn
Face magentic field, bn = bx(i+1/2)
Definition: structs.h:165
double ** vL
Primitive variables to the left of the interface, .
Definition: structs.h:136
double * a2
Sound speed squared.
Definition: structs.h:158
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
double *** Rp
Left and right primitive eigenvectors.
Definition: structs.h:155
#define NVAR
Definition: pluto.h:609

Here is the call graph for this function:

Here is the caller graph for this function:

int CheckNaN ( double **  u,
int  is,
int  ie,
int  id 
)

Cheeck whether the array u contains Not-a-Number (NaN)

Definition at line 19 of file tools.c.

25 {
26  int ii, nv, i, j;
27 
28  for (ii = is; ii <= ie; ii++) {
29  for (nv = 0; nv < NVAR; nv++) {
30  if (u[ii][nv] != u[ii][nv]) {
31  print (" > NaN found (%d), |", id);
32  Show (u, ii);
33  QUIT_PLUTO(1);
34  }
35  }}
36  return (0);
37 }
void Show(double **a, int ip)
Definition: tools.c:132
int j
Definition: analysis.c:2
int i
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: tools.c:367
#define NVAR
Definition: pluto.h:609
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

Here is the caller graph for this function:

void CheckPrimStates ( double **  ,
double **  ,
double **  ,
int  ,
int   
)

Definition at line 4 of file check_states.c.

15 {
16 #if PHYSICS != ADVECTION
17  int i, nv, switch_to_1st;
18  double scrhm, scrhp;
19  double *ac, *ap, *am;
20 
21  for (i = beg; i <= end; i++){
22 
23  switch_to_1st = 0;
24 
25  ac = v0[i];
26  am = vM[i];
27  ap = vP[i];
28 
29  /* ---- Prevent unphysical states by revertin to first
30  order in time and space, i.e. set dw = 0 ---- */
31 
32  #if HAVE_ENERGY
33  switch_to_1st = (ap[PRS] < 0.0) || (am[PRS] < 0.0) ;
34  #endif
35  switch_to_1st = switch_to_1st ||
36  (ap[RHO] < 0.0) || (am[RHO] < 0.0) ;
37 
38  /* ---- Check for superluminal velocities ---- */
39 
40 #if (PHYSICS == RHD) || (PHYSICS == RMHD)
41  #if RECONSTRUCT_4VEL == NO
42  scrhm = EXPAND(am[VX1]*am[VX1], + am[VX2]*am[VX2], + am[VX3]*am[VX3]);
43  scrhp = EXPAND(ap[VX1]*ap[VX1], + ap[VX2]*ap[VX2], + ap[VX3]*ap[VX3]);
44  switch_to_1st = switch_to_1st || (scrhm >= 1.0);
45  switch_to_1st = switch_to_1st || (scrhp >= 1.0);
46  #endif
47 #endif
48 
49  if (switch_to_1st){
50 /*
51  WARNING (
52  print (" ! CheckPrimStates: Unphysical state, ");
53  Where (i,NULL);
54  )
55 */
56  #ifdef STAGGERED_MHD
57  scrhp = ap[BXn];
58  scrhm = am[BXn];
59  #endif
60 
61  for (nv = 0; nv < NVAR; nv++){
62  am[nv] = ap[nv] = ac[nv];
63  }
64 
65  #ifdef STAGGERED_MHD
66  ap[BXn] = scrhp;
67  am[BXn] = scrhm;
68  #endif
69 
70  }
71  }
72 #endif
73 }
#define VX2
Definition: mod_defs.h:29
#define RHO
Definition: mod_defs.h:19
#define VX1
Definition: mod_defs.h:28
int BXn
Definition: globals.h:75
int i
Definition: analysis.c:2
#define VX3
Definition: mod_defs.h:30
#define NVAR
Definition: pluto.h:609

Here is the caller graph for this function:

int CloseBinaryFile ( FILE *  fbin,
int  sz 
)

Close file.

Parameters
[in]fbinpointer to the FILE that needs to be closed (serial mode only)
[in]szthe distributed array descriptor for parallel mode
Returns
Returns 0 on success

Definition at line 78 of file bin_io.c.

88 {
89  #ifdef PARALLEL
90  AL_File_close(sz);
91  #else
92  fclose (fbin);
93  #endif
94  return(0);
95 }
int AL_File_close(int sz_ptr)
Definition: al_io.c:83

Here is the call graph for this function:

Here is the caller graph for this function:

void ComputeEntropy ( const Data ,
Grid  
)

Here is the caller graph for this function:

void ComputeUserVar ( const Data ,
Grid  
)

Definition at line 4 of file userdef_output.c.

14 {
15  int i, j, k;
16 
17  DOM_LOOP(k,j,i){
18  }
19 }
DOM_LOOP(k, j, i)
Definition: analysis.c:22
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
int i
Definition: analysis.c:2

Here is the call graph for this function:

Here is the caller graph for this function:

void ConsToPrim3D ( Data_Arr  U,
Data_Arr  V,
unsigned char ***  flag,
RBox box 
)

Convert a 3D array of conservative variables U to an array of primitive variables V. Note that [nv] is the fastest running index for U while it is the slowest running index for V.

Parameters
[in]Upointer to 3D array of conserved variables, with array indexing [k][j][i][nv]
[out]Vpointer to 3D array of primitive variables, with array indexing [nv][k][j][i]
[in,out]flagpointer to 3D array of flags.
[in]boxpointer to RBox structure containing the domain portion over which conversion must be performed.

Definition at line 16 of file mappers3D.c.

32 {
33  int i, j, k, nv, err;
34  int ibeg, iend, jbeg, jend, kbeg, kend;
35  int current_dir;
36  static double **v, **u;
37 
38  if (v == NULL){
39  v = ARRAY_2D(NMAX_POINT, NVAR, double);
40  u = ARRAY_2D(NMAX_POINT, NVAR, double);
41  }
42 
43 /* ----------------------------------------------
44  Save current sweep direction and by default,
45  perform the conversion along X1 stripes
46  ---------------------------------------------- */
47 
48  current_dir = g_dir;
49  g_dir = IDIR;
50 
51 /* -----------------------------------------------
52  Set (beg,end) indices in ascending order for
53  proper call to ConsToPrim()
54  ----------------------------------------------- */
55 
56  ibeg = (box->ib <= box->ie) ? (iend=box->ie, box->ib):(iend=box->ib, box->ie);
57  jbeg = (box->jb <= box->je) ? (jend=box->je, box->jb):(jend=box->jb, box->je);
58  kbeg = (box->kb <= box->ke) ? (kend=box->ke, box->kb):(kend=box->kb, box->ke);
59 
60  for (k = kbeg; k <= kend; k++){ g_k = k;
61  for (j = jbeg; j <= jend; j++){ g_j = j;
62 
63 #ifdef CHOMBO
64  for (i = ibeg; i <= iend; i++) NVAR_LOOP(nv) u[i][nv] = U[nv][k][j][i];
65  #if COOLING == MINEq || COOLING == H2_COOL
66  if (g_intStage == 1) for (i = ibeg; i <= iend; i++) NormalizeIons(u[i]);
67  #endif
68  err = ConsToPrim (u, v, ibeg, iend, flag[k][j]);
69 
70  /* -------------------------------------------------------------
71  Ensure any change to 1D conservative arrays is not lost.
72  Note: Conversion must be done even when err = 0 in case
73  ENTROPY_SWITCH is employed.
74  ------------------------------------------------------------- */
75 
76  for (i = ibeg; i <= iend; i++) NVAR_LOOP(nv) U[nv][k][j][i] = u[i][nv];
77 #else
78  err = ConsToPrim (U[k][j], v, ibeg, iend, flag[k][j]);
79 #endif
80  for (i = ibeg; i <= iend; i++) NVAR_LOOP(nv) V[nv][k][j][i] = v[i][nv];
81  }}
82  g_dir = current_dir;
83 
84 }
int jb
Lower corner index in the x2 direction.
Definition: structs.h:349
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
int kb
Lower corner index in the x3 direction.
Definition: structs.h:351
void NormalizeIons(double *)
int ib
Lower corner index in the x1 direction.
Definition: structs.h:347
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
#define NVAR_LOOP(n)
Definition: pluto.h:618
int ConsToPrim(double **ucons, double **uprim, int ibeg, int iend, unsigned char *flag)
Definition: mappers.c:89
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
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 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 ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define NVAR
Definition: pluto.h:609

Here is the call graph for this function:

Here is the caller graph for this function:

float*** Convert_dbl2flt ( double ***  Vdbl,
double  unit,
int  swap_endian 
)

Convert the a double-precision 3D array into single precision. Swap endianity if swap_endian == 1.

Parameters
[in]Vdblpointer to a 3D double precision aray
[in]unita multiplicative constant typically used to write in c.g.s units.
[in]swap_endianwhen set to 1, swap endianity during the conversion.
Returns
a pointer to a 3D array in single precision.

Definition at line 216 of file bin_io.c.

228 {
229  int i, j, k;
230  float flt;
231  static float ***Vflt;
232 
233  if (Vflt == NULL) Vflt = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, float);
234 
235  if (!swap_endian){
236  DOM_LOOP(k,j,i){
237  Vflt[k][j][i] = (float)(Vdbl[k][j][i]*unit);
238  }
239  }else{
240  DOM_LOOP(k,j,i){
241  flt = (float)(Vdbl[k][j][i]*unit);
242  SWAP_VAR(flt);
243  Vflt[k][j][i] = flt;
244  }
245  }
246 
247  return (Vflt);
248 }
DOM_LOOP(k, j, i)
Definition: analysis.c:22
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
#define SWAP_VAR(x)
Definition: macros.h:115
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
int i
Definition: analysis.c:2
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55

Here is the call graph for this function:

Here is the caller graph for this function:

void CreateImage ( char *  )

Definition at line 8 of file set_image.c.

19 {
20  static int icount = 0;
21 
22  sprintf (image[icount].basename,"%s",var_name);
23 
24  image[icount].slice_plane = X12_PLANE;
25  image[icount].slice_coord = 0.0;
26 
27  image[icount].max = image[icount].min = 0.0;
28  image[icount].logscale = 0;
29  image[icount].colormap = "br";
30 
31  icount++;
32 }
#define X12_PLANE
Definition: pluto.h:158
double max
Definition: structs.h:308
char * colormap
Definition: structs.h:304
double slice_coord
Definition: structs.h:310
double min
Definition: structs.h:309
int logscale
Definition: structs.h:303
int slice_plane
Definition: structs.h:302
static Image image[MAX_IMAGE_NUMBER]
Definition: set_image.c:4

Here is the caller graph for this function:

void Enthalpy ( double **  v,
real h,
int  beg,
int  end 
)

Compute the enthalpy.

Parameters
[in]v1D array of primitive quantities
[in]h1D array of enthalpy values
[in]beginitial index of computation
[in]endfinal index of computation
Returns
This function has no return value.

Definition at line 48 of file eos.c.

59 {
60  int i;
61  double gmmr, theta;
62 
63  gmmr = g_gamma/(g_gamma - 1.0);
64 
65 /* ---------------------------------------------------------------
66  Classical equations of state
67  --------------------------------------------------------------- */
68 
69  #if PHYSICS == HD || PHYSICS == MHD
70  for (i = beg; i <= end; i++) h[i] = gmmr*v[i][PRS]/v[i][RHO];
71  #elif PHYSICS == RHD || PHYSICS == RMHD
72  for (i = beg; i <= end; i++) {
73  theta = v[i][PRS]/v[i][RHO];
74  h[i] = 1.0 + gmmr*theta;
75  }
76  #endif
77 }
double g_gamma
Definition: globals.h:112
#define RHO
Definition: mod_defs.h:19
static double gmmr
Definition: two_shock.c:42
int i
Definition: analysis.c:2

Here is the call graph for this function:

Here is the caller graph for this function:

void Entropy ( double **  v,
double *  s,
int  beg,
int  end 
)

Compute the entropy.

Parameters
[in]v1D array of primitive quantities
[in]s1D array of entropy values
[in]isinitial index of computation
[in]iefinal index of computation
Returns
This function has no return value.

Definition at line 80 of file eos.c.

91 {
92  int i;
93  double rho, th;
94 
95  #if PHYSICS == HD || PHYSICS == MHD
96  for (i = beg; i <= end; i++){
97  rho = v[i][RHO];
98  s[i] = v[i][PRS]/pow(rho,g_gamma);
99  }
100  #elif PHYSICS == RHD || PHYSICS == RMHD
101  for (i = beg; i <= end; i++) {
102  rho = v[i][RHO];
103  s[i] = v[i][PRS]/pow(rho,g_gamma);
104  }
105  #endif
106 }
double g_gamma
Definition: globals.h:112
#define RHO
Definition: mod_defs.h:19
#define s
int i
Definition: analysis.c:2

Here is the call graph for this function:

void EntropyOhmicHeating ( const Data ,
Data_Arr  ,
double  ,
Grid  
)

Here is the caller graph for this function:

void EntropySwitch ( const Data ,
Grid  
)
void FindShock ( const Data ,
Grid  
)

Here is the caller graph for this function:

void FlagShock ( const Data ,
Grid  
)

Here is the caller graph for this function:

void Flatten ( const State_1D ,
int  ,
int  ,
Grid  
)

Definition at line 4 of file flatten.c.

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 }
#define MAX(a, b)
Definition: macros.h:101
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
#define MIN(a, b)
Definition: macros.h:104
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int VXn
Definition: globals.h:73
#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
#define NVAR
Definition: pluto.h:609

Here is the caller graph for this function:

void FlipSign ( int  side,
int  type,
int *  vsign 
)

Reverse the sign of vector components with respect to axis side. Depending on type, one needs to symmetrize or anti-symmetrize:

  • REFLECTIVE:
    o Vn -> -Vn, Bn -> -Bn
    o Vp -> Vp, Bp -> Bp
    o Vt -> Vt, Bt -> Bt
  • AXISYMMETRIC:
    o Vn -> -Vn, Bn -> -Bn
    o Vp -> Vp, Bp -> Bp
    o Vt -> -Vt, Bt -> -Bt
  • EQTSYMMETRIC:
    o Vn -> -Vn, Bn -> Bn
    o Vp -> Vp, Bp -> -Bp
    o Vt -> Vt, Bt -> -Bt

where (n) is the normal components, (p) and (t) are the transverse (or poloidal and toroidal for cylindrical and spherical coordinates) components.

Parameters
[in]sideboundary side
[in]typeboundary condition type
[out]vsignan array of values (+1 or -1) giving the sign

Definition at line 408 of file boundary.c.

436 {
437  int nv;
438  int Vn, Vp, Vt;
439  int Bn, Bp, Bt;
440 
441  #if PHYSICS == ADVECTION
442  for (nv = 0; nv < NVAR; nv++) vsign[nv] = 1.0;
443  return;
444  #endif
445 
446 /* ----------------------------------------------------------
447  get normal (n), poloidal (p) and toroidal (t) vector
448  components. The ordering is the same as in SetIndexes()
449  ---------------------------------------------------------- */
450 
451  if (side == X1_BEG || side == X1_END){
452  Vn = VX1; Vp = VX2; Vt = VX3;
453  #if PHYSICS == MHD || PHYSICS == RMHD
454  Bn = BX1; Bp = BX2; Bt = BX3;
455  #endif
456  }else if (side == X2_BEG || side == X2_END){
457  Vn = VX2; Vp = VX1; Vt = VX3;
458  #if PHYSICS == MHD || PHYSICS == RMHD
459  Bn = BX2; Bp = BX1; Bt = BX3;
460  #endif
461  }else if (side == X3_BEG || side == X3_END){
462  Vn = VX3; Vp = VX1; Vt = VX2;
463  #if PHYSICS == MHD || PHYSICS == RMHD
464  Bn = BX3; Bp = BX1; Bt = BX2;
465  #endif
466  }
467 
468 /* ---------------------------------------
469  decide which variable flips sign
470  --------------------------------------- */
471 
472  for (nv = 0; nv < NVAR; nv++) vsign[nv] = 1.0;
473 
474  vsign[Vn] = -1.0;
475  #if PHYSICS == MHD || PHYSICS == RMHD
476  vsign[Bn] = -1.0;
477  #endif
478 
479  #if COMPONENTS == 3
480  if (type == AXISYMMETRIC){
481  vsign[Vt] = -1.0;
482  #if PHYSICS == MHD || PHYSICS == RMHD
483  vsign[Bt] = -1.0;
484  #endif
485  }
486  #endif
487 
488  #if PHYSICS == MHD || PHYSICS == RMHD
489  if (type == EQTSYMMETRIC){
490  EXPAND(vsign[Bn] = 1.0; ,
491  vsign[Bp] = -1.0; ,
492  vsign[Bt] = -1.0;)
493  #ifdef GLM_MHD
494  vsign[PSI_GLM] = -1.0;
495  #endif
496  }
497  #endif
498 }
#define X3_BEG
Boundary region at X3 beg.
Definition: pluto.h:150
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
#define VX2
Definition: mod_defs.h:29
#define PSI_GLM
Definition: mod_defs.h:34
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
#define VX1
Definition: mod_defs.h:28
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
#define BX3
Definition: mod_defs.h:27
#define X3_END
Boundary region at X3 end.
Definition: pluto.h:151
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#define X2_BEG
Boundary region at X2 beg.
Definition: pluto.h:148
#define AXISYMMETRIC
Definition: pluto.h:135
#define BX2
Definition: mod_defs.h:26
#define EQTSYMMETRIC
Definition: pluto.h:136
#define NVAR
Definition: pluto.h:609
#define GLM_MHD
Definition: glm.h:25

Here is the caller graph for this function:

void FreeArray1D ( void *  v)

Free memory allocated by the pointer *v.

Definition at line 37 of file arrays.c.

42 {
43  free ((char *)v);
44 }

Here is the caller graph for this function:

void FreeArray2D ( void **  m)

Free memory allocated by the double pointer **v.

Definition at line 46 of file arrays.c.

51 {
52  free ((char *) m[0]);
53  free ((char *) m);
54 }
void FreeArray3D ( void ***  m)

Free memory allocated by the pointer ***v.

Definition at line 56 of file arrays.c.

61 {
62  free ((char *) m[0][0]);
63  free ((char *) m[0]);
64  free ((char *) m);
65 }
void FreeArray4D ( void ****  m)

Free memory allocated by the pointer ****v.

Definition at line 67 of file arrays.c.

72 {
73  free ((char *) m[0][0][0]);
74  free ((char *) m[0][0]);
75  free ((char *) m[0]);
76  free ((char *) m);
77 }

Here is the caller graph for this function:

void FreeArrayBox ( double ***  t,
long  nrl,
long  ncl,
long  ndl 
)

Free memory allocated by the ArrayBox function.

Parameters
[in]tpointer to an allocated memory area
[in]nrlstarting index of the array for the 3rd dimension
[in]nclstarting index of the array for the 2nd dimension
[in]ndlstarting index of the array for the 1st dimension

Definition at line 403 of file arrays.c.

413 {
414  free((char *) (t[nrl][ncl]+ndl));
415  free((char *) (t[nrl]+ncl));
416  free((char *) (t+nrl));
417 }

Here is the caller graph for this function:

void FreeArrayBoxMap ( double ***  t,
int  nrl,
int  nrh,
int  ncl,
int  nch,
int  ndl,
int  ndh 
)

Free memory allocated with the ArrayBoxMap () function

Definition at line 586 of file arrays.c.

593 {
594  free((char*) (t[nrl]+ncl));
595  free((char*) (t+nrl));
596 }
void FreeArrayCharMap ( unsigned char ***  )

Definition at line 530 of file arrays.c.

531 {
532  free((char*) t[0]);
533  free((char*) t);
534 }
void FreeArrayMap ( double ***  t)

Free memory allocate with ArrayMap()

Definition at line 518 of file arrays.c.

524 {
525  free((char*) t[0]);
526  free((char*) t);
527 }
void FreeGrid ( Grid grid)

Free array memory allocated previously.

Definition at line 191 of file set_grid.c.

196 {
197  int dir;
198 
199  for (dir = 0; dir < 3; dir++){
200  FreeArray1D(grid[dir].x);
201  FreeArray1D(grid[dir].xl);
202  FreeArray1D(grid[dir].xr);
203  FreeArray1D(grid[dir].dx);
204  FreeArray1D(grid[dir].xgc);
205  FreeArray1D(grid[dir].dV);
206  FreeArray1D(grid[dir].A-1);
207  FreeArray1D(grid[dir].r_1);
208  FreeArray1D(grid[dir].ct);
209  FreeArray1D(grid[dir].inv_dx);
210  FreeArray1D(grid[dir].inv_dxi);
211  }
212 }
void FreeArray1D(void *v)
Definition: arrays.c:37

Here is the call graph for this function:

void GetAreaFlux ( const State_1D ,
double **  ,
double **  ,
int  ,
int  ,
Grid  
)

Definition at line 4 of file get_area_flux.c.

9 {
10  int i,j,k, nv;
11  double A, rp, rp2, rp3, s, s2;
12  double **flux = state->flux;
13 #if ENTROPY_SWITCH
14  double **visc_flux = state->visc_flux;
15  double **visc_src = state->visc_src;
16  double **tc_flux = state->tc_flux;
17  double **res_flux = state->res_flux;
18 #endif
19 
20  if (g_dir == IDIR) {
21 
22  for (i = beg - 1; i <= end; i++){
23  A = grid[IDIR].A[i];
24  rp = grid[IDIR].xr[i];
25 #if GEOMETRY == CYLINDRICAL
26  NVAR_LOOP(nv) fA[i][nv] = flux[i][nv]*A;
27  #if COMPONENTS == 3
28  fA[i][MX3] = flux[i][MX3]*A*A;
29  IF_DUST(fA[i][MX3_D] = flux[i][MX3_D]*A*A;)
30  #endif
31 #elif GEOMETRY == POLAR
32  NVAR_LOOP(nv) fA[i][nv] = flux[i][nv]*A;
33  #if COMPONENTS >= 2
34  fA[i][MX2] *= A;
35  IF_DUST(fA[i][MX2_D] *= A;)
36  #endif
37 #elif GEOMETRY == SPHERICAL
38  rp2 = rp*rp;
39  NVAR_LOOP(nv) fA[i][nv] = flux[i][nv]*rp2;
40  #if COMPONENTS == 3
41  rp3 = rp2*rp;
42  fA[i][MX3] = flux[i][MX3]*rp3;
43  IF_DUST(fA[i][MX3_D] = flux[i][MX3_D]*rp3;)
44  #endif
45  #if PHYSICS == MHD
46  EXPAND( ; ,
47  fA[i][BX2] = flux[i][BX2]*rp; ,
48  fA[i][BX3] = flux[i][BX3]*rp;)
49  #endif
50 #endif
51 
52  #if (ENTROPY_SWITCH) && (VISCOSITY == EXPLICIT)
53  EXPAND(fvA[i][MX1] = visc_flux[i][MX1]*A; ,
54  fvA[i][MX2] = visc_flux[i][MX2]*A; ,
55  fvA[i][MX3] = visc_flux[i][MX3]*A;)
56  #if GEOMETRY == CYLINDRICAL && COMPONENTS == 3
57  fvA[i][MX3] *= rp;
58  #elif GEOMETRY == POLAR && COMPONENTS >= 2
59  fvA[i][MX2] *= rp;
60  #elif GEOMETRY == SPHERICAL && COMPONENTS == 3
61  fvA[i][MX3] *= rp;
62  #endif
63  #if HAVE_ENERGY
64  fvA[i][ENG] = visc_flux[i][ENG]*A;
65  #endif
66  #endif
67  }
68 
69  }else if (g_dir == JDIR){
70 
71  for (j = beg - 1; j <= end; j++){
72 
73 #if GEOMETRY == SPHERICAL
74  s = grid[JDIR].A[j];
75  s2 = s*s;
76 
77  NVAR_LOOP(nv) fA[j][nv] = flux[j][nv]*s;
78  #if COMPONENTS == 3
79  fA[j][MX3] = flux[j][MX3]*s2;
80  IF_DUST(fA[j][MX3_D] = flux[j][MX3_D]*s2;)
81  #endif
82 
83  #if (ENTROPY_SWITCH) && (VISCOSITY == EXPLICIT)
84  EXPAND(fvA[j][iMR] = visc_flux[j][iMR]*s; ,
85  fvA[j][iMTH] = visc_flux[j][iMTH]*s; ,
86  fvA[j][iMPHI] = visc_flux[j][iMPHI]*s2;)
87  #if HAVE_ENERGY
88  fvA[j][ENG] = visc_flux[j][ENG]*s;
89  #endif
90  #endif
91 #endif
92 
93  }
94 
95  }else if (g_dir == KDIR){
96 
97  print1 ("! GetAreaFlux(): should not be called during x3 sweep\n");
98  QUIT_PLUTO(1);
99 
100  }
101 
102 }
#define MX3
Definition: mod_defs.h:22
#define iMPHI
Definition: mod_defs.h:71
#define MX1
Definition: mod_defs.h:20
#define iMTH
Definition: mod_defs.h:70
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
#define VISCOSITY
Definition: pluto.h:385
#define SPHERICAL
Definition: pluto.h:36
#define KDIR
Definition: pluto.h:195
#define POLAR
Definition: pluto.h:35
#define iMR
Definition: mod_defs.h:69
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
#define NVAR_LOOP(n)
Definition: pluto.h:618
#define PHYSICS
Definition: definitions_01.h:1
int j
Definition: analysis.c:2
#define MX2
Definition: mod_defs.h:21
int k
Definition: analysis.c:2
#define GEOMETRY
Definition: definitions_01.h:4
#define CYLINDRICAL
Definition: pluto.h:34
#define MHD
Definition: pluto.h:111
#define s
#define BX3
Definition: mod_defs.h:27
#define COMPONENTS
Definition: definitions_01.h:3
#define ENTROPY_SWITCH
Definition: pluto.h:337
int i
Definition: analysis.c:2
#define BX2
Definition: mod_defs.h:26
#define JDIR
Definition: pluto.h:194
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define EXPLICIT
Definition: pluto.h:67
#define IF_DUST(a)
Definition: pluto.h:625
#define HAVE_ENERGY
Definition: pluto.h:395

Here is the call graph for this function:

Here is the caller graph for this function:

void GetCGSUnits ( double *  u)

Compute an array of c.g.s units

Parameters
[in]uan array containing the c.g.s units of the primitive variables, e.g., u[RHO] will be in gr/cm^3, u[VX1] will be in cm/s, etc...

Definition at line 557 of file write_data.c.

566 {
567  int nv;
568  double unit_velocity = UNIT_VELOCITY;
569  double unit_pressure = UNIT_DENSITY*UNIT_VELOCITY*UNIT_VELOCITY;
570  double unit_mag = UNIT_VELOCITY*sqrt(4.0*CONST_PI*UNIT_DENSITY);
571 
572  #if PHYSICS == RHD || PHYSICS == RMHD
573  unit_velocity = CONST_c;
574  #endif
575 
576  u[RHO] = UNIT_DENSITY;
577  EXPAND(u[VX1] = unit_velocity; ,
578  u[VX2] = unit_velocity; ,
579  u[VX3] = unit_velocity;)
580  #if PHYSICS == MHD || PHYSICS == RMHD
581  EXPAND(u[BX1] = unit_mag; ,
582  u[BX2] = unit_mag; ,
583  u[BX3] = unit_mag;)
584  #endif
585  #if HAVE_ENERGY
586  u[PRS] = unit_pressure;
587  #endif
588 }
#define UNIT_DENSITY
Unit density in gr/cm^3.
Definition: pluto.h:369
#define VX2
Definition: mod_defs.h:29
#define RHO
Definition: mod_defs.h:19
#define CONST_c
Speed of Light.
Definition: pluto.h:255
#define VX1
Definition: mod_defs.h:28
#define UNIT_VELOCITY
Unit velocity in cm/sec.
Definition: pluto.h:377
#define PHYSICS
Definition: definitions_01.h:1
#define MHD
Definition: pluto.h:111
#define BX3
Definition: mod_defs.h:27
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#define CONST_PI
.
Definition: pluto.h:269
#define BX2
Definition: mod_defs.h:26
#define RMHD
Definition: pluto.h:112
#define HAVE_ENERGY
Definition: pluto.h:395

Here is the caller graph for this function:

double GetEntropy ( double  x)
Image* GetImage ( char *  )

Definition at line 35 of file set_image.c.

45 {
46  int indx = -1;
47 
48  while (strcmp(image[++indx].basename, var_name)) {
49  if (image[indx].colormap == NULL) { /* if colormap is NULL, image does not exist! */
50  print1 ("! Error: var '%s' is not associated with a valid image\n");
51  QUIT_PLUTO(1);
52  }
53  }
54 
55  return (image + indx);
56 }
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
static Image image[MAX_IMAGE_NUMBER]
Definition: set_image.c:4

Here is the call graph for this function:

Here is the caller graph for this function:

double* GetInverse_dl ( const Grid )

Definition at line 205 of file set_geometry.c.

218 {
219 #if GEOMETRY == CARTESIAN || GEOMETRY == CYLINDRICAL
220 
221  return grid[g_dir].inv_dx;
222 
223 #elif GEOMETRY == POLAR
224 
225  if (g_dir != JDIR){
226  return grid[g_dir].inv_dx;
227  }else{
228  int j;
229  double r_1;
230  static double *inv_dl;
231 
232  if (inv_dl == NULL) {
233  #ifdef CHOMBO
234  inv_dl = ARRAY_1D(NX2_MAX, double);
235  #else
236  inv_dl = ARRAY_1D(NX2_TOT, double);
237  #endif
238  }
239  r_1 = grid[IDIR].r_1[g_i];
240  JTOT_LOOP(j) inv_dl[j] = grid[JDIR].inv_dx[j]*r_1;
241  return inv_dl;
242  }
243 
244 #elif GEOMETRY == SPHERICAL
245 
246  int j, k;
247  double r_1, s;
248  static double *inv_dl2, *inv_dl3;
249 
250  if (inv_dl2 == NULL) {
251  #ifdef CHOMBO
252  inv_dl2 = ARRAY_1D(NX2_MAX, double);
253  inv_dl3 = ARRAY_1D(NX3_MAX, double);
254  #else
255  inv_dl2 = ARRAY_1D(NX2_TOT, double);
256  inv_dl3 = ARRAY_1D(NX3_TOT, double);
257  #endif
258  }
259 
260  if (g_dir == IDIR){
261  return grid[IDIR].inv_dx;
262  }else if (g_dir == JDIR) {
263  r_1 = grid[IDIR].r_1[g_i];
264  JTOT_LOOP(j) inv_dl2[j] = grid[JDIR].inv_dx[j]*r_1;
265  return inv_dl2;
266  }else if (g_dir == KDIR){
267  r_1 = grid[IDIR].r_1[g_i];
268  s = grid[JDIR].x[g_j];
269  s = sin(s);
270  KTOT_LOOP(k) inv_dl3[k] = grid[KDIR].inv_dx[k]*r_1/s;
271  return inv_dl3;
272  }
273 
274 #endif
275 
276  return NULL;
277 }
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
#define KTOT_LOOP(k)
Definition: macros.h:40
#define KDIR
Definition: pluto.h:195
#define NX3_MAX
Definition: pluto.h:743
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
Definition: globals.h:82
#define NX2_MAX
Definition: pluto.h:742
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int j
Definition: analysis.c:2
if(divB==NULL)
Definition: analysis.c:10
int k
Definition: analysis.c:2
#define s
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
#define JTOT_LOOP(j)
Definition: macros.h:39
#define JDIR
Definition: pluto.h:194

Here is the caller graph for this function:

int GetNghost ( void  )

Compute the number of ghost zones, depending on the selected scheme.

Definition at line 18 of file get_nghost.c.

24 {
25  int nv, nghost ;
26  Limiter *limiter[NVAR];
27 
28  #if RECONSTRUCTION == FLAT
29 
30  nghost = 2;
31 
32  #elif RECONSTRUCTION == LINEAR || RECONSTRUCTION == LimO3\
33  || RECONSTRUCTION == WENO3
34  #if LIMITER == FOURTH_ORDER_LIM
35  nghost = 3;
36  #else
37  nghost = 2;
38  #endif
39 
40  #elif RECONSTRUCTION == LINEAR_MULTID
41 
42  nghost = 2;
43 
44  #elif RECONSTRUCTION == PARABOLIC
45 
46  #if PHYSICS == HD || PHYSICS == RHD
47  nghost = 4; /* -- since HD makes use of contact steepener -- */
48  #else
49  nghost = 3;
50  #endif
51 
52  #elif RECONSTRUCTION == WENO3_FD || RECONSTRUCTION == LIMO3_FD
53 
54  nghost = 2;
55 
56  #elif RECONSTRUCTION == WENOZ_FD || \
57  RECONSTRUCTION == MP5_FD
58 
59  nghost = 3;
60 
61  #endif
62 
63  #if SHOCK_FLATTENING == ONED
64 
65  nghost = MAX(4, nghost);
66 
67  #elif SHOCK_FLATTENING == MULTID
68 
69 /* ------------------------------------------------------
70  The MULTID shock flattening only need 2 ghost zones.
71  However for axisymmetric simulations with CTU
72  3 zones will ensure that flag[][][] will remain
73  symmetric around the axis.
74  ------------------------------------------------------ */
75 
76  nghost = MAX(3, nghost);
77  #endif
78 
79 /* ----------------------------------------------------
80  The following should operate on the static grid
81  version of the code. Add an extra row of boundary
82  zones if CTU+CT is selected.
83  At least 3 ghost zones.
84  ---------------------------------------------------- */
85 
86  #ifdef CTU
87  #ifdef STAGGERED_MHD
88  nghost++;
89  #endif
90  #endif
91 
92 /* ----------------------------------------
93  FARGO PPM needs at least 3 ghost zones
94  ---------------------------------------- */
95 
96  #ifdef FARGO
97  #if FARGO_ORDER == 3
98  nghost = MAX(3,nghost);
99  #endif
100  #endif
101 
102  #if (defined CH_SPACEDIM) && (TIME_STEPPING == RK_MIDPOINT)
103  nghost++; /* AMR + RK_MIDPOINT */
104  #endif
105 
106  return (nghost);
107 }
#define MAX(a, b)
Definition: macros.h:101
void Limiter(double *, double *, double *, int, int, Grid *)
Definition: pluto.h:490
#define NVAR
Definition: pluto.h:609

Here is the caller graph for this function:

void GetOutputFrequency ( Output output,
const char *  output_format 
)

Set the intervals between output files. This can be done in three different ways:

  • dt: time interval in code units
  • dn: step interval
  • dclock: actual clock time (in hours)

However, dn and dclock are mutually exclusive.

Definition at line 433 of file runtime_setup.c.

445 {
446  char *str;
447  int len, nhrs, nmin, nsec;
448 
449 /* -- time interval in code units (dt) -- */
450 
451  output->dt = atof(ParamFileGet(output_format, 1));
452 
453 /* -- check the 2nd field and decide to set "dn" or "dclock" -- */
454 
455  str = ParamFileGet(output_format,2);
456  len = strlen(str);
457  if (str[len-1] == 'h'){
458  output->dclock = atof(str); /* clock interval in hours */
459  nhrs = (int)output->dclock; /* integer part */
460  nmin = (int)((output->dclock - nhrs)*100.0); /* remainder in minutes */
461  if (nmin >= 60){
462  printf ("! OutputFrequency: number of minutes exceeds 60 in %s output\n",
463  output_format);
464  QUIT_PLUTO(1);
465  }
466  output->dclock = nhrs*3600.0 + nmin*60; /* convert to seconds */
467  output->dn = -1;
468  }else if (str[len-1] == 'm'){
469  output->dclock = atof(str); /* clock interval in minutes */
470  nmin = (int)output->dclock; /* integer part */
471  nsec = (int)((output->dclock - nmin)*100.0); /* remainder in seconds */
472  if (nsec >= 60){
473  printf ("! OutputFrequency: number of seconds exceeds 60 in %s output\n",
474  output_format);
475  QUIT_PLUTO(1);
476  }
477  output->dclock = nmin*60.0 + nsec;
478  output->dn = -1;
479  }else if (str[len-1] == 's'){
480  output->dclock = atof(str); /* clock interval in seconds */
481  output->dn = -1;
482  }else{
483  output->dclock = -1.0;
484  output->dn = atoi(ParamFileGet(output_format, 2));
485  }
486 
487 }
double dt
time increment between outputs - one per output
Definition: structs.h:245
char * ParamFileGet(const char *label, int pos)
Definition: parse_file.c:86
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
double dclock
time increment in clock hours - one per output
Definition: structs.h:246
int dn
step increment between outputs - one per output
Definition: structs.h:238

Here is the call graph for this function:

Here is the caller graph for this function:

RBox* GetRBox ( int  side,
int  vpos 
)

Returns a pointer to a local static RBox

Parameters
[in]sidethe region of the computational domain where the box is required. There 8 possible values: X1_BEG, ... , X3_END, DOM, TOT.
[in]vposthe variable position inside the cell: CENTER, X1FACE, X2FACE or X3FACE.

Definition at line 232 of file rbox.c.

243 {
244  if (vpos == CENTER) return &(rbox_center[side-X1_BEG]);
245  else if (vpos == X1FACE) return &(rbox_x1face[side-X1_BEG]);
246  else if (vpos == X2FACE) return &(rbox_x2face[side-X1_BEG]);
247  else if (vpos == X3FACE) return &(rbox_x3face[side-X1_BEG]);
248 }
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
#define CENTER
Definition: pluto.h:200
#define X3FACE
Definition: pluto.h:203
#define X1FACE
Definition: pluto.h:201
static RBox rbox_x1face[8]
Definition: rbox.c:30
static RBox rbox_x3face[8]
Definition: rbox.c:30
static RBox rbox_center[8]
Definition: rbox.c:30
static RBox rbox_x2face[8]
Definition: rbox.c:30
#define X2FACE
Definition: pluto.h:202

Here is the caller graph for this function:

double*** GetUserVar ( char *  var_name)

return a pointer to the 3D array associated with the variable named 'var_name'.

Definition at line 251 of file set_output.c.

257 {
258  int indx = -1;
259 
260  while (strcmp(all_outputs->var_name[++indx], var_name)){
261  if (all_outputs->V[indx] == NULL){
262  print1 ("! Error: uservar '%s' is not allocated\n");
263  QUIT_PLUTO(1);
264  }
265  }
266  return (all_outputs->V[indx]);
267 }
double *** V[64]
pointer to arrays being written - same for all
Definition: structs.h:247
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
static Output * all_outputs
Definition: set_output.c:35
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
char ** var_name
variable names - same for all
Definition: structs.h:242

Here is the call graph for this function:

Here is the caller graph for this function:

void HancockStep ( const State_1D ,
int  ,
int  ,
Grid  
)

Definition at line 136 of file hancock.c.

141  {
142  int nv, i, ifail;
143  double dBx, dpsi, dtdx, dt, dtdV;
144  double *A, *dx, *dV, r;
145  double *vp, *vm, *vc, dvp[NVAR], dvm[NVAR];
146  double P0, P1, P2;
147  double **rhs;
148  static double **fp, **fm, **uh, **u;
149  static double *pp, *pm, *hp, *hm;
150  static double *lambda_max, *lambda_min;
151 
152 #if GEOMETRY != CARTESIAN && GEOMETRY != CYLINDRICAL
153  print1 ("! Hancock does not work in this geometry \n");
154  QUIT_PLUTO(1);
155 #endif
156 #if BODY_FORCE != NO
157  print ("! Conservative Hancock scheme does not support gravity\n");
158  QUIT_PLUTO(1);
159 #endif
160 #if RECONSTRUCTION != LINEAR
161  print1 ("! The MUSCL-Hancock scheme works with Linear reconstruction only\n");
162  QUIT_PLUTO(1);
163 #endif
164 #if (PARABOLIC_FLUX & EXPLICIT)
165  print1 ("! Conservative MUSCL-Hancock incompatible with Explicit Diffusion\n");
166  QUIT_PLUTO(1);
167 #endif
168 
169  if (fp == NULL){
170  fp = ARRAY_2D(NMAX_POINT, NVAR, double);
171  fm = ARRAY_2D(NMAX_POINT, NVAR, double);
172  pp = ARRAY_1D(NMAX_POINT, double);
173  pm = ARRAY_1D(NMAX_POINT, double);
174  u = ARRAY_2D(NMAX_POINT, NVAR, double);
175  uh = ARRAY_2D(NMAX_POINT, NVAR, double);
176 
177  hp = ARRAY_1D(NMAX_POINT, double);
178  hm = ARRAY_1D(NMAX_POINT, double);
179  lambda_max = ARRAY_1D(NMAX_POINT, double);
180  lambda_min = ARRAY_1D(NMAX_POINT, double);
181  }
182  rhs = state->rhs;
183 
184 #if RECONSTRUCT_4VEL
185  ConvertTo3vel (state->v, beg-1, end+1);
186  ConvertTo3vel (state->vp, beg, end);
187  ConvertTo3vel (state->vm, beg, end);
188 #endif
189 
190 /* --------------------------------
191  make fluxes
192  -------------------------------- */
193 
194  PrimToCons (state->v, u, beg, end);
195  PrimToCons (state->vp, state->up, beg, end);
196  PrimToCons (state->vm, state->um, beg, end);
197 
198  Enthalpy (state->vp, hp, beg, end);
199  Enthalpy (state->vm, hm, beg, end);
200 
201  Flux(state->up, state->vp, hp, fp, pp, beg, end);
202  Flux(state->um, state->vm, hm, fm, pm, beg, end);
203 
204  dx = grid[g_dir].dx; A = grid[g_dir].A; dV = grid[g_dir].dV;
205 
206 /* ---------------------------------------------------
207  Compute passive scalar fluxes
208  --------------------------------------------------- */
209 
210  #if NFLX != NVAR
211  for (i = beg; i <= end; i++){
212  vp = state->vp[i]; vm = state->vm[i];
213  #if NSCL > 0
214  for (nv = NFLX; nv < (NFLX + NSCL); nv++){
215  fp[i][nv] = fp[i][RHO]*vp[nv];
216  fm[i][nv] = fm[i][RHO]*vm[nv];
217  }
218  #endif
219  }
220  #endif
221 
222  #if CHAR_UPWIND == YES
223  MAX_CH_SPEED (state->v, lambda_min, lambda_max, beg, end);
224  #endif
225 
226 /* ------------------------------------------------------
227  Initialize right-hand-side with flux difference
228  ------------------------------------------------------ */
229 
230  dt = 0.5*g_dt;
231  for (i = beg; i <= end; i++) {
232 
233  dtdx = dt/dx[i];
234  vp = state->vp[i];
235  vm = state->vm[i];
236  #if GEOMETRY == CARTESIAN
237  for (nv = NVAR; nv--; ) rhs[i][nv] = -dtdx*(fp[i][nv] - fm[i][nv]);
238  #elif GEOMETRY == CYLINDRICAL
239  dtdV = dt/dV[i];
240  for (nv = NVAR; nv--; ) {
241  rhs[i][nv] = -dtdV*(A[i]*fp[i][nv] - A[i-1]*fm[i][nv]);
242  }
243  #ifdef GLM_MHD
244  rhs[i][BXn] = -dtdx*(vp[PSI_GLM] - vm[PSI_GLM]);
245  #endif
246  #endif
247  rhs[i][MXn] -= dtdx*(pp[i] - pm[i]);
248 
249  /* ---- add Powell source term ---- */
250 
251  #if (PHYSICS == MHD || PHYSICS == RMHD) && (DIVB_CONTROL == EIGHT_WAVES)
252  dBx = (vp[BXn]*A[i] - vm[BXn]*A[i-1])/dV[i];
253  EXPAND(rhs[i][BX1] -= dt*state->v[i][VX1]*dBx; ,
254  rhs[i][BX2] -= dt*state->v[i][VX2]*dBx; ,
255  rhs[i][BX3] -= dt*state->v[i][VX3]*dBx;)
256  #endif
257 
258  /* ---- Extended GLM source term ---- */
259 
260  #ifdef GLM_MHD
261  #if GLM_EXTENDED == YES
262  dBx = (vp[BXn]*A[i] - vm[BXn]*A[i-1])/dV[i];
263  EXPAND(rhs[i][MX1] -= dt*state->v[i][BX1]*dBx; ,
264  rhs[i][MX2] -= dt*state->v[i][BX2]*dBx; ,
265  rhs[i][MX3] -= dt*state->v[i][BX3]*dBx;)
266  #if HAVE_ENERGY
267  dpsi = (vp[PSI_GLM] - vm[PSI_GLM])/dx[i];
268  rhs[i][ENG] -= dt*state->v[i][BXn]*dpsi;
269  #endif
270  #endif
271  #endif
272  }
273 
274 /* ------------------------------------------------
275  Source terms: geometry
276  ------------------------------------------------ */
277 
278  #if GEOMETRY == CYLINDRICAL && COMPONENTS == 3
279  if (g_dir == IDIR) {
280  double vB, vel2, g_2, r_1, *uc;
281 
282  for (i = beg; i <= end; i++){
283  r_1 = grid[IDIR].r_1[i];
284  vc = state->v[i];
285  uc = u[i];
286 
287  vB = EXPAND(vc[VX1]*vc[BX1], + vc[VX2]*vc[BX2], + vc[VX3]*vc[BX3]);
288  vel2 = EXPAND(vc[VX1]*vc[VX1], + vc[VX2]*vc[VX2], + vc[VX3]*vc[VX3]);
289  g_2 = 1.0 - vel2;
290 
291  rhs[i][iMR] += dt*((uc[MX3]*vc[VX3] - (vc[BX3]*g_2 + vB*vc[VX3])*vc[BX3]))*r_1;
292 
293  rhs[i][iMPHI] = -dtdV*(A[i]*A[i]*fp[i][iMPHI] - A[i-1]*A[i-1]*fm[i][iMPHI]);
294  rhs[i][iMPHI] *= r_1;
295 
296  rhs[i][iBPHI] -= dt*(vc[VX3]*uc[BX1] - uc[BX3]*vc[VX1])*r_1;
297  }
298  }
299  #endif
300 
301 /* ------------------------------------------------
302  Update solution vector to get u(n+1/2)
303  ------------------------------------------------ */
304 
305  for (i = beg; i <= end; i++) {
306  for (nv = NVAR; nv--; ) uh[i][nv] = u[i][nv] + rhs[i][nv];
307  }
308 
309 /* -------------------------------------------------
310  check if U(x_i, n+1/2) has physical meaning.
311  Revert to 1st order otherwise.
312  ------------------------------------------------- */
313 
314  if (ConsToPrim (uh, state->vh, beg, end, state->flag) != 0){
315  for (i = beg; i <= end; i++){
316  if (state->flag[i] != 0){
317  for (nv = NVAR; nv--; ){
318  uh[i][nv] = u[i][nv];
319  state->vh[i][nv] = state->v[i][nv];
320  state->vp[i][nv] = state->vm[i][nv] = state->v[i][nv];
321  }
322  #ifdef STAGGERED_MHD
323  state->vp[i][BXn] = state->bn[i];
324  state->vm[i][BXn] = state->bn[i-1];
325  #endif
326  }
327  }
328  }
329 
330 /* ----------------------------------------------------
331  evolve interface values accordingly
332  ---------------------------------------------------- */
333 
334  for (i = beg; i <= end; i++) {
335  vp = state->vp[i];
336  vm = state->vm[i];
337  vc = state->v[i];
338 
339  for (nv = NVAR; nv--; ){
340 /*
341  dvp[nv] = dvm[nv] = state->vh[i][nv] - state->v[i][nv];
342 
343  P0 = 1.5*vc[nv] - 0.25*(vp[nv] + vm[nv]);
344  P1 = vp[nv] - vm[nv];
345  P2 = 3.0*(vp[nv] - 2.0*vc[nv] + vm[nv]);
346 
347  dvp[nv] += P0 + 0.5*P1 + 0.25*P2 - vc[nv];
348  dvm[nv] += P0 - 0.5*P1 + 0.25*P2 - vc[nv];
349 */
350  P1 = vp[nv] - vm[nv];
351  dvp[nv] = dvm[nv] = state->vh[i][nv] - state->v[i][nv];
352  dvp[nv] += 0.5*P1;
353  dvm[nv] -= 0.5*P1;
354  }
355 
356  #if CHAR_UPWIND == YES
357 
358  if (lambda_min[i] > 0.0)
359  for (nv = NVAR; nv--; ) dvm[nv] = 0.0;
360  else if (lambda_max[i] < 0.0)
361  for (nv = NVAR; nv--; ) dvp[nv] = 0.0;
362 
363  #endif
364 
365  for (nv = NVAR; nv--; ){
366  vp[nv] = vc[nv] + dvp[nv];
367  vm[nv] = vc[nv] + dvm[nv];
368  }
369  }
370  #ifdef STAGGERED_MHD
371  for (i = beg-1; i <= end; i++){
372  state->vp[i][BXn] = state->vm[i+1][BXn] = state->bn[i];
373  }
374  #endif
375 
376  CheckPrimStates (state->vm, state->vp, state->v, beg, end);
377 }
#define MX3
Definition: mod_defs.h:22
#define iMPHI
Definition: mod_defs.h:71
#define MX1
Definition: mod_defs.h:20
#define VX2
Definition: mod_defs.h:29
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
void Flux(double **u, double **w, double *a2, double **fx, double *p, int beg, int end)
Definition: fluxes.c:23
#define RHO
Definition: mod_defs.h:19
void CheckPrimStates(double **vM, double **vP, double **v0, int beg, int end)
Definition: check_states.c:4
void Enthalpy(double **v, real *h, int beg, int end)
Definition: eos.c:48
double g_dt
The current integration time step.
Definition: globals.h:118
#define PSI_GLM
Definition: mod_defs.h:34
#define VX1
Definition: mod_defs.h:28
int BXn
Definition: globals.h:75
#define iMR
Definition: mod_defs.h:69
#define NFLX
Definition: mod_defs.h:32
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int ConsToPrim(double **ucons, double **uprim, int ibeg, int iend, unsigned char *flag)
Definition: mappers.c:89
#define NSCL
Definition: pluto.h:572
#define MX2
Definition: mod_defs.h:21
list vel2
Definition: Sph_disk.py:39
#define iBPHI
Definition: mod_defs.h:152
void ConvertTo3vel(double **, int, int)
Definition: four_vel.c:25
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int MXn
Definition: globals.h:74
#define BX3
Definition: mod_defs.h:27
#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
void PrimToCons(double **uprim, double **ucons, int ibeg, int iend)
Definition: mappers.c:26
int i
Definition: analysis.c:2
FILE * fp
Definition: analysis.c:7
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define BX2
Definition: mod_defs.h:26
#define NVAR
Definition: pluto.h:609
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

Here is the caller graph for this function:

void Init ( double *  v,
double  x1,
double  x2,
double  x3 
)

The Init() function can be used to assign initial conditions as as a function of spatial position.

Parameters
[out]va pointer to a vector of primitive variables
[in]x1coordinate point in the 1st dimension
[in]x2coordinate point in the 2nd dimension
[in]x3coordinate point in the 3rdt dimension

The meaning of x1, x2 and x3 depends on the geometry:

\[ \begin{array}{cccl} x_1 & x_2 & x_3 & \mathrm{Geometry} \\ \noalign{\medskip} \hline x & y & z & \mathrm{Cartesian} \\ \noalign{\medskip} R & z & - & \mathrm{cylindrical} \\ \noalign{\medskip} R & \phi & z & \mathrm{polar} \\ \noalign{\medskip} r & \theta & \phi & \mathrm{spherical} \end{array} \]

Variable names are accessed by means of an index v[nv], where nv = RHO is density, nv = PRS is pressure, nv = (VX1, VX2, VX3) are the three components of velocity, and so forth.

Definition at line 17 of file init.c.

43 {
44  v[RHO] = 1.0;
45  v[VX1] = 0.0;
46  v[VX2] = 0.0;
47  v[VX3] = 0.0;
48  #if HAVE_ENERGY
49  v[PRS] = 1.0;
50  #endif
51  v[TRC] = 0.0;
52 
53  #if PHYSICS == MHD || PHYSICS == RMHD
54 
55  v[BX1] = 0.0;
56  v[BX2] = 0.0;
57  v[BX3] = 0.0;
58 
59  v[AX1] = 0.0;
60  v[AX2] = 0.0;
61  v[AX3] = 0.0;
62 
63  #endif
64 }
#define VX2
Definition: mod_defs.h:29
#define RHO
Definition: mod_defs.h:19
#define AX2
Definition: mod_defs.h:86
#define TRC
Definition: pluto.h:581
#define VX1
Definition: mod_defs.h:28
#define AX3
Definition: mod_defs.h:87
#define BX3
Definition: mod_defs.h:27
#define AX1
Definition: mod_defs.h:85
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#define BX2
Definition: mod_defs.h:26

Here is the call graph for this function:

Here is the caller graph for this function:

void Initialize ( int  argc,
char *  argv[],
Data data,
Runtime runtime,
Grid grid,
Cmd_Line cmd_line 
)

Initialize computational grid, domain decomposition and memory allocation. Also, set initial conditions and output attributes.

Parameters
[in]argcthe number of command-line argument passed to the code
[in]argvthe argument value as a 1D array of char
[in,out]dataa pointer to the main PLUTO data structure
[in,out]runtimea pointer to the Runtime structure
[in]gridpointer to an array of Grid structures
[in]cmd_linepointer to the Cmd_Line structure
Returns
This function has no return value.

Definition at line 37 of file initialize.c.

53 {
54  int nprocs, decomp_mode;
55  int i, j, k, idim, nv;
56  int nx, ny, nz, nghost, status;
57  int gsize[DIMENSIONS], lsize[DIMENSIONS];
58  int beg[DIMENSIONS], end[DIMENSIONS];
59  int gbeg[DIMENSIONS], gend[DIMENSIONS];
60  int lbeg[DIMENSIONS], lend[DIMENSIONS];
61  int is_gbeg[DIMENSIONS], is_gend[DIMENSIONS];
62  int ghosts[DIMENSIONS];
63  int periods[DIMENSIONS];
64  int pardim[DIMENSIONS], stagdim[DIMENSIONS];
65  int procs[DIMENSIONS];
66  char ini_file[128];
67  double scrh, dxmin[3], dxming[3];
68  Output *output;
69  #ifdef PARALLEL
70  MPI_Datatype rgb_type;
71  MPI_Datatype Float_Vect_type;
72  #endif
73 
74 /* -- set default input file name -- */
75 
76  sprintf (ini_file,"pluto.ini");
77 
78 /* -- parse command line options -- */
79 
80  ParseCmdLineArgs (argc, argv, ini_file, cmd_line);
81 
82  #ifdef PARALLEL
83 
84 /* -- get number of processors -- */
85 
86  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
87 
88 /* -- read initialization file -- */
89 
90  if (prank == 0) RuntimeSetup (runtime, cmd_line, ini_file);
91  MPI_Bcast (runtime, sizeof (struct RUNTIME) , MPI_BYTE, 0, MPI_COMM_WORLD);
92 
93 /* -- get number of ghost zones and set periodic boundaries -- */
94 
95  nghost = GetNghost();
96  MPI_Allreduce (&nghost, &idim, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
97  nghost = idim;
98 
99  for (idim = 0; idim < DIMENSIONS; idim++) {
100  gsize[idim] = runtime->npoint[idim];
101  ghosts[idim] = nghost;
102  periods[idim] = (runtime->left_bound[idim] == PERIODIC ? 1:0)
103  || (runtime->left_bound[idim] == SHEARING ? 1:0);
104  pardim[idim] = cmd_line->parallel_dim[idim];
105  }
106 
107 /* -- find parallel decomposition mode and number of processors -- */
108 
109  decomp_mode = GetDecompMode(cmd_line, procs);
110 
111 /* ---- double distributed array descriptor ---- */
112 
113 /* SetDistributedArray (SZ, type, gsize, periods, stagdim);
114  return args: beg, end, lsize, lbeg, lend, gbeg, gend, is_gbeg, is_gend
115 */
116 
117  AL_Sz_init (MPI_COMM_WORLD, &SZ);
118  AL_Set_type (MPI_DOUBLE, 1, SZ);
119  AL_Set_dimensions (DIMENSIONS, SZ);
120  AL_Set_global_dim (gsize, SZ);
121  AL_Set_ghosts (ghosts, SZ);
122  AL_Set_periodic_dim (periods, SZ);
123  AL_Set_parallel_dim (pardim, SZ);
124 
125  AL_Decompose (SZ, procs, decomp_mode);
126  AL_Get_local_dim (SZ, lsize);
127  AL_Get_bounds (SZ, beg, end, ghosts, AL_C_INDEXES);
128  AL_Get_lbounds (SZ, lbeg, lend, ghosts, AL_C_INDEXES);
129  AL_Get_gbounds (SZ, gbeg, gend, ghosts, AL_C_INDEXES);
130  AL_Is_boundary (SZ, is_gbeg, is_gend);
131 
132 /* ---- float distributed array descriptor ---- */
133 
134  AL_Sz_init (MPI_COMM_WORLD, &SZ_float);
135  AL_Set_type (MPI_FLOAT, 1, SZ_float);
136  AL_Set_dimensions (DIMENSIONS, SZ_float);
137  AL_Set_global_dim (gsize, SZ_float);
138  AL_Set_ghosts (ghosts, SZ_float);
139  AL_Set_periodic_dim (periods, SZ_float);
140  AL_Set_parallel_dim (pardim, SZ_float);
141 
142  AL_Decompose (SZ_float, procs, decomp_mode);
143  AL_Get_local_dim (SZ_float, lsize);
144  AL_Get_bounds (SZ_float, beg, end, ghosts, AL_C_INDEXES);
145  AL_Get_lbounds (SZ_float, lbeg, lend, ghosts, AL_C_INDEXES);
146  AL_Get_gbounds (SZ_float, gbeg, gend, ghosts, AL_C_INDEXES);
147  AL_Is_boundary (SZ_float, is_gbeg, is_gend);
148 
149 /* ---- char distributed array descriptor ---- */
150 
151  AL_Sz_init (MPI_COMM_WORLD, &SZ_char);
152  AL_Set_type (MPI_CHAR, 1, SZ_char);
153  AL_Set_dimensions (DIMENSIONS, SZ_char);
154  AL_Set_global_dim (gsize, SZ_char);
155  AL_Set_ghosts (ghosts, SZ_char);
156  AL_Set_periodic_dim (periods, SZ_char);
157  AL_Set_parallel_dim (pardim, SZ_char);
158 
159  AL_Decompose (SZ_char, procs, decomp_mode);
160  AL_Get_local_dim (SZ_char, lsize);
161  AL_Get_bounds (SZ_char, beg, end, ghosts, AL_C_INDEXES);
162  AL_Get_lbounds (SZ_char, lbeg, lend, ghosts, AL_C_INDEXES);
163  AL_Get_gbounds (SZ_char, gbeg, gend, ghosts, AL_C_INDEXES);
164  AL_Is_boundary (SZ_char, is_gbeg, is_gend);
165 
166 /* ---- Float_Vec distributed array descriptor ---- */
167 
168  MPI_Type_contiguous (3, MPI_FLOAT, &Float_Vect_type);
169  MPI_Type_commit (&Float_Vect_type);
170 
171  AL_Sz_init (MPI_COMM_WORLD, &SZ_Float_Vect);
172  AL_Set_type (MPI_FLOAT, 3, SZ_Float_Vect);
173  AL_Set_dimensions (DIMENSIONS, SZ_Float_Vect);
175  AL_Set_ghosts (ghosts, SZ_Float_Vect);
178 
179  AL_Decompose (SZ_Float_Vect, procs, decomp_mode);
181  AL_Get_bounds (SZ_Float_Vect, beg, end, ghosts, AL_C_INDEXES);
182  AL_Get_lbounds (SZ_Float_Vect, lbeg, lend, ghosts, AL_C_INDEXES);
183  AL_Get_gbounds (SZ_Float_Vect, gbeg, gend, ghosts, AL_C_INDEXES);
184  AL_Is_boundary (SZ_Float_Vect, is_gbeg, is_gend);
185 
186  for (idim = 0; idim < DIMENSIONS; idim++) {
187  grid[idim].nghost = nghost;
188  grid[idim].np_tot = lsize[idim] + 2*ghosts[idim];
189  grid[idim].np_int = lsize[idim];
190  grid[idim].np_tot_glob = runtime->npoint[idim] + 2*ghosts[idim];
191  grid[idim].np_int_glob = runtime->npoint[idim];
192  grid[idim].beg = beg[idim];
193  grid[idim].end = end[idim];
194  grid[idim].gbeg = gbeg[idim];
195  grid[idim].gend = gend[idim];
196  grid[idim].lbeg = lbeg[idim];
197  grid[idim].lend = lend[idim];
198  grid[idim].lbound = runtime->left_bound[idim]*is_gbeg[idim];
199  grid[idim].rbound = runtime->right_bound[idim]*is_gend[idim];
200  grid[idim].nproc = procs[idim];
201  }
202 
203 /* -- Find total number of processors & decomposition mode -- */
204 
205 /* AL_Get_size(SZ, &nprocs); Replaced by MPI_Comm_size above */
206 
207  #ifdef STAGGERED_MHD
208 
209 /* ---- x-staggered array descriptor (double) ---- */
210 
211  #if DIMENSIONS >= 1
212  D_EXPAND(stagdim[IDIR] = AL_TRUE; ,
213  stagdim[JDIR] = AL_FALSE; ,
214  stagdim[KDIR] = AL_FALSE;)
215 
216  DIM_LOOP(idim) gsize[idim] = runtime->npoint[idim];
217  gsize[IDIR] += 1;
218 
219  #ifdef SHEARINGBOX
220  periods[IDIR] = 0;
221  #endif
222 
223  AL_Sz_init (MPI_COMM_WORLD, &SZ_stagx);
224  AL_Set_type (MPI_DOUBLE, 1, SZ_stagx);
225  AL_Set_dimensions (DIMENSIONS, SZ_stagx);
226  AL_Set_global_dim (gsize, SZ_stagx);
227  AL_Set_ghosts (ghosts, SZ_stagx);
228  AL_Set_staggered_dim(stagdim, SZ_stagx);
229  AL_Set_periodic_dim (periods, SZ_stagx);
230  AL_Set_parallel_dim (pardim, SZ_stagx);
231 
232  AL_Decompose (SZ_stagx, procs, decomp_mode);
233  AL_Get_local_dim (SZ_stagx, lsize);
234  AL_Get_bounds (SZ_stagx, beg, end, ghosts, AL_C_INDEXES);
235  AL_Get_lbounds (SZ_stagx, lbeg, lend, ghosts, AL_C_INDEXES);
236  AL_Get_gbounds (SZ_stagx, gbeg, gend, ghosts, AL_C_INDEXES);
237  AL_Is_boundary (SZ_stagx, is_gbeg, is_gend);
238 
239  #ifdef SHEARINGBOX
240  periods[IDIR] = 1;
241  #endif
242  #endif
243 
244  #if DIMENSIONS >= 2
245  D_EXPAND(stagdim[IDIR] = AL_FALSE; ,
246  stagdim[JDIR] = AL_TRUE; ,
247  stagdim[KDIR] = AL_FALSE;)
248 
249  DIM_LOOP(idim) gsize[idim] = runtime->npoint[idim];
250  gsize[JDIR] += 1;
251 
252  AL_Sz_init (MPI_COMM_WORLD, &SZ_stagy);
253  AL_Set_type (MPI_DOUBLE, 1, SZ_stagy);
254  AL_Set_dimensions (DIMENSIONS, SZ_stagy);
255  AL_Set_global_dim (gsize, SZ_stagy);
256  AL_Set_ghosts (ghosts, SZ_stagy);
257  AL_Set_staggered_dim(stagdim, SZ_stagy);
258  AL_Set_periodic_dim (periods, SZ_stagy);
259  AL_Set_parallel_dim (pardim, SZ_stagy);
260 
261  AL_Decompose (SZ_stagy, procs, decomp_mode);
262  AL_Get_local_dim (SZ_stagy, lsize);
263  AL_Get_bounds (SZ_stagy, beg, end, ghosts, AL_C_INDEXES);
264  AL_Get_lbounds (SZ_stagy, lbeg, lend, ghosts, AL_C_INDEXES);
265  AL_Get_gbounds (SZ_stagy, gbeg, gend, ghosts, AL_C_INDEXES);
266  AL_Is_boundary (SZ_stagy, is_gbeg, is_gend);
267  #endif
268 
269  #if DIMENSIONS == 3
270  D_EXPAND(stagdim[IDIR] = AL_FALSE; ,
271  stagdim[JDIR] = AL_FALSE; ,
272  stagdim[KDIR] = AL_TRUE;)
273 
274  DIM_LOOP(idim) gsize[idim] = runtime->npoint[idim];
275  gsize[KDIR] += 1;
276 
277  AL_Sz_init (MPI_COMM_WORLD, &SZ_stagz);
278  AL_Set_type (MPI_DOUBLE, 1, SZ_stagz);
279  AL_Set_dimensions (DIMENSIONS, SZ_stagz);
280  AL_Set_global_dim (gsize, SZ_stagz);
281  AL_Set_ghosts (ghosts, SZ_stagz);
282  AL_Set_staggered_dim(stagdim, SZ_stagz);
283  AL_Set_periodic_dim (periods, SZ_stagz);
284  AL_Set_parallel_dim (pardim, SZ_stagz);
285 
286  AL_Decompose (SZ_stagz, procs, decomp_mode);
287  AL_Get_local_dim (SZ_stagz, lsize);
288  AL_Get_bounds (SZ_stagz, beg, end, ghosts, AL_C_INDEXES);
289  AL_Get_lbounds (SZ_stagz, lbeg, lend, ghosts, AL_C_INDEXES);
290  AL_Get_gbounds (SZ_stagz, gbeg, gend, ghosts, AL_C_INDEXES);
291  AL_Is_boundary (SZ_stagz, is_gbeg, is_gend);
292  #endif
293 
294  #endif /* STAGGERED_MHD */
295 
296  /* -- find processors coordinates in a Cartesian topology -- */
297 
298  {
299  int coords[3] = {0,0,0};
300  int rank;
301  MPI_Comm cartcomm;
302  AL_Get_cart_comm(SZ, &cartcomm);
303  MPI_Cart_get(cartcomm, DIMENSIONS, procs, periods, coords);
304  MPI_Cart_rank(cartcomm, coords, &rank);
305  if (rank != prank) {
306  printf ("! Initialize: rank and prank are different\n");
307  QUIT_PLUTO(1);
308  }
309  for (idim = 0; idim < DIMENSIONS; idim++) {
310  grid[idim].rank_coord = coords[idim];
311  }
312  }
313 
314  #else /* if NOT PARALLEL */
315 
316 /* -----------------------------------------------------
317  Serial Initialization
318  ----------------------------------------------------- */
319 
320  RuntimeSetup (runtime, cmd_line, ini_file);
321  nghost = GetNghost();
322 
323  for (idim = 0; idim < DIMENSIONS; idim++) {
324  grid[idim].nghost = nghost;
325  grid[idim].np_int = grid[idim].np_int_glob = runtime->npoint[idim];
326  grid[idim].np_tot = grid[idim].np_tot_glob = runtime->npoint[idim] + 2*nghost;
327  grid[idim].beg = grid[idim].gbeg = grid[idim].lbeg = nghost;
328  grid[idim].end = grid[idim].gend = grid[idim].lend
329  = (grid[idim].lbeg - 1) + grid[idim].np_int;
330  grid[idim].lbound = runtime->left_bound[idim];
331  grid[idim].rbound = runtime->right_bound[idim];
332  grid[idim].nproc = 1;
333  }
334  nprocs = 1;
335 
336  #endif
337 
338  RuntimeSet (runtime);
339 
340 /* ----------------------------------------------------
341  Set output directory and log file
342  ---------------------------------------------------- */
343 
344  SetLogFile (runtime->output_dir, cmd_line);
345  ShowConfig (argc, argv, ini_file);
346 
347 /* ---------------------------------------------------
348  Grid Generation
349  --------------------------------------------------- */
350 
351  print1 ("\n> Generating grid...\n\n");
352  SetGrid (runtime, grid);
353  Where (-1, grid); /* -- store grid inside the "Where"
354  function for subsequent calls -- */
355  if (cmd_line->makegrid == YES) {
356  print1 ("\n> Done < \n");
357  QUIT_PLUTO(0);
358  }
359 
360 /* ------------------------------------------------
361  Initialize global variables
362  ------------------------------------------------ */
363 
364  g_dt = runtime->first_dt;
365  g_time = 0.0;
366  g_maxMach = 0.0;
367  g_maxRiemannIter = 0;
368  g_usedMemory = 0;
369 
370  IBEG = grid[IDIR].lbeg; IEND = grid[IDIR].lend;
371  JBEG = grid[JDIR].lbeg; JEND = grid[JDIR].lend;
372  KBEG = grid[KDIR].lbeg; KEND = grid[KDIR].lend;
373 
374  NX1 = grid[IDIR].np_int;
375  NX2 = grid[JDIR].np_int;
376  NX3 = grid[KDIR].np_int;
377 
378  NX1_TOT = grid[IDIR].np_tot;
379  NX2_TOT = grid[JDIR].np_tot;
380  NX3_TOT = grid[KDIR].np_tot;
381 
382 /* ---------------------------------------
383  Get the maximum number of points
384  among all directions
385  --------------------------------------- */
386 
389 
390 /* ---------------------------------------------
391  Define the RBox structures.
392  --------------------------------------------- */
393 
394  SetRBox();
395 
396 /* --------------------------------------------------------------------
397  Find the minimum physical cell length for each direction
398  -------------------------------------------------------------------- */
399 
400  for (idim = 0; idim < DIMENSIONS; idim++) dxmin[idim] = 1.e30;
401 
402  for (i = IBEG; i <= IEND; i++) {
403  for (j = JBEG; j <= JEND; j++) {
404  for (k = KBEG; k <= KEND; k++) {
405 
406  scrh = Length_1(i, j, k, grid);
407  dxmin[IDIR] = MIN (dxmin[IDIR], scrh);
408 
409  scrh = Length_2(i, j, k, grid);
410  dxmin[JDIR] = MIN (dxmin[JDIR], scrh);
411 
412  scrh = Length_3(i, j, k, grid);
413  dxmin[KDIR] = MIN (dxmin[KDIR], scrh);
414 
415  }}}
416 
417  #ifdef PARALLEL
418  MPI_Allreduce (dxmin, dxming, 3, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD);
419  dxmin[IDIR] = dxming[IDIR];
420  dxmin[JDIR] = dxming[JDIR];
421  dxmin[KDIR] = dxming[KDIR];
422  #endif
423 
424  grid[IDIR].dl_min = dxmin[IDIR];
425  grid[JDIR].dl_min = dxmin[JDIR];
426  grid[KDIR].dl_min = dxmin[KDIR];
427 
428 /* --------------------------------------------------------------
429  Define geometrical coefficients for linear interpolation
430  -------------------------------------------------------------- */
431 
432  PLM_CoefficientsSet (grid); /* -- these may be needed by
433  shock flattening algorithms */
434  #if RECONSTRUCTION == PARABOLIC
435  PPM_CoefficientsSet (grid);
436  #endif
437 
438 /* --------------------------------------------------------------
439  Copy user defined parameters into global array g_inputParam
440  -------------------------------------------------------------- */
441 
442  for (nv = 0; nv < USER_DEF_PARAMETERS; nv++) g_inputParam[nv] = runtime->aux[nv];
443 
444 /* ------------------------------------------------------------
445  Allocate memory for 3D data arrays
446  ------------------------------------------------------------ */
447 
448  print1 ("\n> Memory allocation\n");
449  data->Vc = ARRAY_4D(NVAR, NX3_TOT, NX2_TOT, NX1_TOT, double);
450  data->Uc = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
451 
452  #ifdef STAGGERED_MHD
453  data->Vs = ARRAY_1D(DIMENSIONS, double ***);
454  D_EXPAND(
455  data->Vs[BX1s] = ArrayBox( 0, NX3_TOT-1, 0, NX2_TOT-1,-1, NX1_TOT-1); ,
456  data->Vs[BX2s] = ArrayBox( 0, NX3_TOT-1,-1, NX2_TOT-1, 0, NX1_TOT-1); ,
457  data->Vs[BX3s] = ArrayBox(-1, NX3_TOT-1, 0, NX2_TOT-1, 0, NX1_TOT-1);)
458  #endif
459 
461  D_EXPAND( ,
462  data->Ax3 = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double); ,
463  data->Ax1 = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
464  data->Ax2 = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
465  )
466  #endif
467 
468  #if RESISTIVITY != NO
469  data->J = ARRAY_4D(3,NX3_TOT, NX2_TOT, NX1_TOT, double);
470  #endif
471 
472  data->flag = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, unsigned char);
473 
474 /* ------------------------------------------------------------
475  Initialize tables needed for EOS
476  ------------------------------------------------------------ */
477 
478  #if EOS == PVTE_LAW && NIONS == 0
479  #if TV_ENERGY_TABLE == YES
481  #else
483  #endif
485  #endif
486 
487 /* ------------------------------------------------------------
488  Assign initial conditions
489  ------------------------------------------------------------ */
490 
491  Startup (data, grid);
492 
493 /* ------------------------------------------------------------
494  Set output attributes (names, images, number of outputs...)
495  ------------------------------------------------------------ */
496 
497  SetOutput (data, runtime);
498 
499 /* -----------------------------------
500  print normalization units
501  ----------------------------------- */
502 
503  ShowUnits();
504 
505  print1 ("> Number of processors: %d\n",nprocs);
506  D_EXPAND(print1 ("> Typical proc size: %d",grid[IDIR].np_int); ,
507  print1 (" X %d", grid[JDIR].np_int); ,
508  print1 (" X %d", grid[KDIR].np_int);)
509  print1 ("\n");
510  #ifdef PARALLEL
511  print1 ("> Parallel Directions: ");
512  D_EXPAND(if (pardim[IDIR]) print1 (" X1"); ,
513  if (pardim[JDIR]) print1 ("/X2"); ,
514  if (pardim[KDIR]) print1 ("/X3");)
515  print1 ("\n");
516  #endif
517  if (cmd_line->show_dec) ShowDomainDecomposition (nprocs, grid);
518 }
int AL_Is_boundary(int sz_ptr, int *is_gbeg, int *is_gend)
Definition: al_boundary.c:28
double Length_2(int i, int j, int k, Grid *)
Definition: set_geometry.c:169
#define SHEARING
Definition: pluto.h:138
#define MAX(a, b)
Definition: macros.h:101
int lbound
When different from zero, it specifies the boundary condition to be applied at leftmost grid side whe...
Definition: structs.h:105
void ShowDomainDecomposition(int, Grid *)
Definition: show_config.c:295
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
void PPM_CoefficientsSet(Grid *grid)
Definition: ppm_coeffs.c:58
int GetNghost(void)
Definition: get_nghost.c:18
int end
Global end index for the local array.
Definition: structs.h:116
void ShowConfig(int, char *a[], char *)
Definition: show_config.c:16
double **** J
Electric current defined as curl(B).
Definition: structs.h:54
int parallel_dim[3]
Definition: structs.h:19
#define USER_DEF_PARAMETERS
#define DIM_LOOP(d)
Definition: macros.h:227
int SetLogFile(char *, Cmd_Line *)
Definition: tools.c:321
int npoint[3]
Global number of zones in the interior domain.
Definition: structs.h:256
long int NX1
Number of interior zones in the X1 directions (boundaries excluded) for the local processor...
Definition: globals.h:48
int AL_Get_gbounds(int, int *, int *, int *, int)
Definition: al_sz_get.c:746
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
char output_dir[256]
The name of the output directory (output_dir for static PLUTO, Output_dir for PLUTO-Chombo) ...
Definition: structs.h:269
int np_int_glob
Total number of points in the global domain (boundaries excluded).
Definition: structs.h:98
tuple scrh
Definition: configure.py:200
int SZ_float
Definition: globals.h:27
int left_bound[3]
Array of left boundary types.
Definition: structs.h:257
#define YES
Definition: pluto.h:25
int rbound
Same as lbound, but for the right edge of the grid.
Definition: structs.h:112
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
int g_maxRiemannIter
Maximum number of iterations for iterative Riemann Solver.
Definition: globals.h:93
double g_dt
The current integration time step.
Definition: globals.h:118
#define AL_TRUE
Definition: al_codes.h:28
double *** Ax3
Vector potential component in the direction.
Definition: structs.h:53
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
int AL_Get_local_dim(int, int *)
Definition: al_sz_get.c:309
double *** ArrayBox(long int nrl, long int nrh, long int ncl, long int nch, long int ndl, long int ndh)
Definition: arrays.c:341
#define BX3s
Definition: ct.h:29
int gend
Global end index for the global array.
Definition: structs.h:114
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
int AL_Set_global_dim(int *, int)
Definition: al_sz_set.c:141
int prank
Processor rank.
Definition: globals.h:33
int AL_Set_staggered_dim(int *, int)
Definition: al_sz_set.c:293
int np_tot_glob
Total number of points in the global domain (boundaries included).
Definition: structs.h:96
#define KDIR
Definition: pluto.h:195
unsigned char *** flag
Pointer to a 3D array setting useful integration flags that are retrieved during integration.
Definition: structs.h:55
int AL_Decompose(int sz_ptr, int *procs, int mode)
Definition: al_decompose.c:39
int SZ_stagx
Definition: globals.h:24
int right_bound[3]
Array of right boundary types.
Definition: structs.h:258
int SZ_stagy
Definition: globals.h:25
int SZ_Float_Vect
Definition: globals.h:29
#define AL_C_INDEXES
Definition: al_codes.h:36
#define MIN(a, b)
Definition: macros.h:104
int AL_Get_cart_comm(int, MPI_Comm *)
Definition: al_sz_get.c:117
double g_maxMach
The maximum Mach number computed during integration.
Definition: globals.h:119
void Startup(Data *, Grid *)
Definition: startup.c:17
long int NX2
Number of interior zones in the X2 directions (boundaries excluded) for the local processor...
Definition: globals.h:50
#define IDIR
Definition: pluto.h:193
double Length_1(int i, int j, int k, Grid *)
Definition: set_geometry.c:156
int beg
Global start index for the local array.
Definition: structs.h:115
void PLM_CoefficientsSet(Grid *grid)
Definition: plm_coeffs.c:30
int AL_Sz_init(MPI_Comm, int *)
Definition: al_sz_init.c:22
double g_inputParam[32]
Array containing the user-defined parameters.
Definition: globals.h:131
int gbeg
Global start index for the global array.
Definition: structs.h:113
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
#define UPDATE_VECTOR_POTENTIAL
Definition: pluto.h:381
int show_dec
Definition: structs.h:21
int j
Definition: analysis.c:2
#define ARRAY_4D(nx, ny, nz, nv, type)
Definition: prototypes.h:173
int nghost
Number of ghost zones.
Definition: structs.h:104
int SZ_stagz
Definition: globals.h:26
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int RuntimeSetup(Runtime *, Cmd_Line *, char *)
Definition: runtime_setup.c:22
void Where(int, Grid *)
Definition: tools.c:235
int k
Definition: analysis.c:2
double dl_min
minimum cell length (e.g.
Definition: structs.h:94
#define BX1s
Definition: ct.h:27
static int GetDecompMode(Cmd_Line *cmd_line, int procs[])
double aux[32]
Definition: structs.h:284
int SZ_char
Definition: globals.h:28
void MakeEV_TemperatureTable()
int rank_coord
Parallel coordinate in a Cartesian topology.
Definition: structs.h:121
void SetRBox(void)
Definition: rbox.c:33
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
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
void ParseCmdLineArgs(int argc, char *argv[], char *ini_file, Cmd_Line *cmd)
Definition: cmd_line_opt.c:18
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
#define RESISTIVITY
Definition: pluto.h:357
int i
Definition: analysis.c:2
double g_time
The current integration time.
Definition: globals.h:117
int makegrid
Definition: structs.h:15
void MakeInternalEnergyTable()
double **** Uc
The main four-index data array used for cell-centered conservative variables.
Definition: structs.h:37
int AL_Set_parallel_dim(int *, int)
Definition: al_sz_set.c:216
double Length_3(int i, int j, int k, Grid *)
Definition: set_geometry.c:186
#define AL_FALSE
Definition: al_codes.h:29
int AL_Set_periodic_dim(int *, int)
Definition: al_sz_set.c:253
void ShowUnits()
Definition: show_config.c:260
void MakePV_TemperatureTable()
Definition: thermal_eos.c:63
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
#define BX2s
Definition: ct.h:28
double first_dt
The initial time step (first_dt)
Definition: structs.h:281
#define PERIODIC
Definition: pluto.h:137
int np_tot
Total number of points in the local domain (boundaries included).
Definition: structs.h:100
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
int AL_Set_dimensions(int, int)
Definition: al_sz_set.c:69
Definition: al_hidden.h:38
#define JDIR
Definition: pluto.h:194
double *** Ax1
Vector potential component in the direction.
Definition: structs.h:51
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
void SetGrid(Runtime *, Grid *)
Definition: set_grid.c:21
int AL_Set_type(AL_Datatype, int, int)
Definition: al_sz_set.c:101
#define NVAR
Definition: pluto.h:609
double *** Ax2
Vector potential component in the direction.
Definition: structs.h:52
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
int AL_Get_lbounds(int, int *, int *, int *, int)
Definition: al_sz_get.c:668
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int g_usedMemory
Amount of used memory in bytes.
Definition: globals.h:96
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
int nproc
number of processors for this grid.
Definition: structs.h:120
long int NX3
Number of interior zones in the X3 directions (boundaries excluded) for the local processor...
Definition: globals.h:52
void RuntimeSet(Runtime *runtime)
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
int AL_Set_ghosts(int *, int)
Definition: al_sz_set.c:333
#define DIMENSIONS
Definition: definitions_01.h:2
#define NO
Definition: pluto.h:26
int AL_Get_bounds(int, int *, int *, int *, int)
Definition: al_sz_get.c:707
void SetOutput(Data *d, Runtime *input)
Definition: set_output.c:37
int np_int
Total number of points in the local domain (boundaries excluded).
Definition: structs.h:102

Here is the call graph for this function:

Here is the caller graph for this function:

void InputDataFree ( void  )

Free memory stored by user-supplied data.

Definition at line 484 of file input_data.c.

489 {
490  int nv;
491  for (nv = 0; nv < id_nvar; nv++){
492  free ((char *) Vin[nv][0][0]);
493  free ((char *) Vin[nv][0]);
494  free ((char *) Vin[nv]);
495  }
496 }
static double *** Vin[ID_MAX_NVAR]
An array of 3D data values containing the initial data file variables.
Definition: input_data.c:50
static int id_nvar
Number of variables to be read on input.
Definition: input_data.c:38
void InputDataInterpolate ( double *  vs,
double  x1,
double  x2,
double  x3 
)

Perform bi- or tri-linear interpolation on external dataset to compute vs[] at the given point {x1,x2,x3}.

Parameters
[in]vsinterpolated value
[in]x1coordinate point at which at interpolates are desired
[in]x2coordinate point at which at interpolates are desired
[in]x3coordinate point at which at interpolates are desired
Returns
This function has no return value.

The function performs the following tasks.

  • Convert PLUTO coordinates to input grid geometry if necessary.
  • Make sure point (x1,x2,x3) does not fall outside input grid range. Limit to input grid edge otherwise.
  • Use table lookup by binary search to find the indices il, jl and kl such that grid points of PLUTO fall between [il, il+1], [jl, jl+1], [kl, kl+1].
  • Define normalized coordinates between [0,1]:
    • x[il+1] < x1[i] < x[il+1] ==> 0 < xx < 1
    • y[jl+1] < x2[j] < y[jl+1] ==> 0 < yy < 1
    • z[kl+1] < x3[k] < z[kl+1] ==> 0 < zz < 1
  • Perform bi- or tri-linear interpolation.

Definition at line 287 of file input_data.c.

300 {
301  int il = 0, jl = 0, kl = 0;
302  int ih, jh, kh;
303  int im, jm, km;
304  int i, j, k, nv, inv;
305  double xx, yy, zz;
306  double ***V;
307 
308 /* --------------------------------------------------------------------- */
309 /*! - Convert PLUTO coordinates to input grid geometry if necessary. */
310 /* --------------------------------------------------------------------- */
311 
312  #if GEOMETRY == CARTESIAN
313  if (id_geom == GEOMETRY) {
314 
315  /* same coordinate system: nothing to do */
316 
317  }else if (id_geom == CYLINDRICAL) {
318  double R, z, phi;
319  R = sqrt(x1*x1 + x2*x2);
320  phi = atan2(x2,x1);
321  if (phi < 0.0) phi += 2.0*CONST_PI;
322  z = x3;
323 
324  x1 = R; x2 = z; x3 = phi;
325  }else if (id_geom == POLAR) {
326  double R, phi, z;
327  R = sqrt(x1*x1 + x2*x2);
328  phi = atan2(x2,x1);
329  if (phi < 0.0) phi += 2.0*CONST_PI;
330  z = x3;
331 
332  x1 = R; x2 = phi; x3 = z;
333  }else if (id_geom == SPHERICAL){
334  double r, theta, phi;
335  r = D_EXPAND(x1*x1, + x2*x2, + x3*x3);
336  r = sqrt(r);
337  theta = acos(x3/r);
338  phi = atan2(x2,x1);
339  if (phi < 0.0) phi += 2.0*CONST_PI;
340  if (theta < 0.0) theta += 2.0*CONST_PI;
341 
342  x1 = r; x2 = theta; x3 = phi;
343  }else{
344  print1 ("! InputDataInterpolate: invalid or unsupported coordinate transformation.\n");
345  QUIT_PLUTO(1);
346  }
347  #elif GEOMETRY == CYLINDRICAL
348  if (id_geom == GEOMETRY) {
349 
350  /* same coordinate system: nothing to do */
351 
352  }else if (id_geom == SPHERICAL) {
353  double r, theta, phi;
354  r = D_EXPAND(x1*x1, + x2*x2, + 0.0);
355  r = sqrt(r);
356  theta = acos(x2/r);
357  phi = 0.0;
358  if (theta < 0.0) theta += 2.0*CONST_PI;
359 
360  x1 = r; x2 = theta; x3 = phi;
361  }else{
362  print1 ("! InputDataInterpolate: invalid or unsupported coordinate transformation.\n");
363  QUIT_PLUTO(1);
364  }
365  #elif GEOMETRY == POLAR
366  if (id_geom == GEOMETRY) {
367 
368  /* same coordinate system: nothing to do */
369 
370  }else if (id_geom == CARTESIAN) {
371  double x, y, z;
372  x = x1*cos(x2);
373  y = x1*sin(x2);
374  z = x3;
375 
376  x1 = x; x2 = y; x3 = z;
377  }else{
378  print1 ("! InputDataInterpolate: invalid or unsupported coordinate transformation.\n");
379  QUIT_PLUTO(1);
380  }
381  #elif GEOMETRY == SPHERICAL
382  if (id_geom == GEOMETRY) {
383 
384  /* same coordinate system: nothing to do */
385 
386 
387  }else if (id_geom == CARTESIAN) {
388  double x, y, z;
389  x = x1*sin(x2)*cos(x3);
390  y = x1*sin(x2)*sin(x3);
391  z = x1*cos(x2);
392 
393  x1 = x; x2 = y; x3 = z;
394  }else{
395  print1 ("! InputDataInterpolate: invalid or unsupported coordinate transformation.\n");
396  QUIT_PLUTO(1);
397  }
398  #endif
399 
400 /* --------------------------------------------------------------------- */
401 /*! - Make sure point (x1,x2,x3) does not fall outside input grid range.
402  Limit to input grid edge otherwise. */
403 /* --------------------------------------------------------------------- */
404 
405  D_EXPAND(if (x1 < id_x1[0]) x1 = id_x1[0];
406  else if (x1 > id_x1[id_nx1-1]) x1 = id_x1[id_nx1-1]; ,
407 
408  if (x2 < id_x2[0]) x2 = id_x2[0];
409  else if (x2 > id_x2[id_nx2-1]) x2 = id_x2[id_nx2-1]; ,
410 
411  if (x3 < id_x3[0]) x3 = id_x3[0];
412  else if (x3 > id_x3[id_nx3-1]) x3 = id_x3[id_nx3-1]; )
413 
414 /* --------------------------------------------------------------------- */
415 /*! - Use table lookup by binary search to find the indices
416  il, jl and kl such that grid points of PLUTO fall between
417  [il, il+1], [jl, jl+1], [kl, kl+1]. */
418 /* --------------------------------------------------------------------- */
419 
420  il = 0;
421  ih = id_nx1 - 1;
422  while (il != (ih-1)){
423  im = (il+ih)/2;
424  if (x1 <= id_x1[im]) ih = im;
425  else il = im;
426  }
427 
428  if (id_nx2 > 1){
429  jl = 0;
430  jh = id_nx2 - 1;
431  while (jl != (jh-1)){
432  jm = (jl+jh)/2;
433  if (x2 <= id_x2[jm]) jh = jm;
434  else jl = jm;
435  }
436  }
437 
438  if (id_nx3 > 1){
439  kl = 0;
440  kh = id_nx3 - 1;
441  while (kl != (kh - 1)){
442  km = (kl+kh)/2;
443  if (x3 <= id_x3[km]) kh = km;
444  else kl = km;
445  }
446  }
447 
448 /* --------------------------------------------------------------------- */
449 /*! - Define normalized coordinates between [0,1]:
450  - x[il+1] < x1[i] < x[il+1] ==> 0 < xx < 1
451  - y[jl+1] < x2[j] < y[jl+1] ==> 0 < yy < 1
452  - z[kl+1] < x3[k] < z[kl+1] ==> 0 < zz < 1 */
453 /* --------------------------------------------------------------------- */
454 
455  xx = yy = zz = 0.0; /* initialize normalized coordinates */
456 
457  if (id_nx1 > 1) xx = (x1 - id_x1[il])/(id_x1[il+1] - id_x1[il]);
458  if (id_nx2 > 1) yy = (x2 - id_x2[jl])/(id_x2[jl+1] - id_x2[jl]);
459  if (id_nx3 > 1) zz = (x3 - id_x3[kl])/(id_x3[kl+1] - id_x3[kl]);
460 
461 /* --------------------------------------------------------------------- */
462 /*! - Perform bi- or tri-linear interpolation. */
463 /* --------------------------------------------------------------------- */
464 
465  for (nv = 0; nv < id_nvar; nv++) {
466  inv = id_var_indx[nv];
467  V = Vin[nv];
468  vs[inv] = V[kl][jl][il]*(1.0 - xx)*(1.0 - yy)*(1.0 - zz)
469  + V[kl][jl][il+1]*xx*(1.0 - yy)*(1.0 - zz);
470  if (id_nx2 > 1){
471  vs[inv] += V[kl][jl+1][il]*(1.0 - xx)*yy*(1.0 - zz)
472  + V[kl][jl+1][il+1]*xx*yy*(1.0 - zz);
473  }
474  if (id_nx3 > 1){
475  vs[inv] += V[kl+1][jl][il]*(1.0 - xx)*(1.0 - yy)*zz
476  + V[kl+1][jl][il+1]*xx*(1.0 - yy)*zz
477  + V[kl+1][jl+1][il]*(1.0 - xx)*yy*zz
478  + V[kl+1][jl+1][il+1]*xx*yy*zz;
479  }
480  }
481 }
static double * id_x2
Array of point coordinates of the x2 input grid.
Definition: input_data.c:47
static int id_var_indx[ID_MAX_NVAR]
The variable index.
Definition: input_data.c:39
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
static int id_nx3
Size of input grid in the x3 direction.
Definition: input_data.c:42
static double *** Vin[ID_MAX_NVAR]
An array of 3D data values containing the initial data file variables.
Definition: input_data.c:50
#define SPHERICAL
Definition: pluto.h:36
static int id_nx1
Size of input grid in the x1 direction.
Definition: input_data.c:40
#define POLAR
Definition: pluto.h:35
static double * id_x1
Array of point coordinates of the x1 input grid.
Definition: input_data.c:46
static int id_nx2
Size of input grid in the x2 direction.
Definition: input_data.c:41
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
#define GEOMETRY
Definition: definitions_01.h:4
#define CARTESIAN
Definition: pluto.h:33
#define CYLINDRICAL
Definition: pluto.h:34
static int id_geom
Geometry of the input grid.
Definition: input_data.c:44
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
#define CONST_PI
.
Definition: pluto.h:269
static int id_nvar
Number of variables to be read on input.
Definition: input_data.c:38
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
static double * id_x3
Array of point coordinates of the x3 input grid.
Definition: input_data.c:48

Here is the call graph for this function:

Here is the caller graph for this function:

void InputDataRead ( char *  data_fname,
char *  endianity 
)

Read input data file and store the contents into the local storage array Vin. Memory allocation is also done here. The grid size and number of variables must have previously set by calling InputDataSet().

Parameters
[in]data_fnamethe data file name
[in]endianityan input string ("little" or "big") giving the byte-order of how the input data file was originally written. If an empty string is supplied, no change is made.
Returns
This function has no return value.

Definition at line 191 of file input_data.c.

206 {
207  int i, j, k, nv, swap_endian=NO;
208  size_t dsize, dcount;
209  double udbl;
210  float uflt;
211  char ext[] = " ";
212  FILE *fp;
213 
214 /* ----------------------------------------------------
215  Check endianity
216  ---------------------------------------------------- */
217 
218  if ( (!strcmp(endianity,"big") && IsLittleEndian()) ||
219  (!strcmp(endianity,"little") && !IsLittleEndian())) {
220  swap_endian = YES;
221  }
222 
223  print1 (" Input data file: %s (endianity: %s) \n",
224  data_fname, endianity);
225 
226 /* ------------------------------------------------------
227  Get data type from file extensions (dbl or flt).
228  ------------------------------------------------------ */
229 
230  dcount = strlen(data_fname);
231  for (i = 0; i < 3; i++) ext[i] = data_fname[dcount-3+i];
232 
233  if (!strcmp(ext,"dbl")){
234  print1 (" Precision: (double)\n");
235  dsize = sizeof(double);
236  } else if (!strcmp(ext,"flt")) {
237  print1 (" Precision:\t\t (single)\n");
238  dsize = sizeof(float);
239  } else {
240  print1 ("! InputDataRead: unsupported data type '%s'\n",ext);
241  QUIT_PLUTO(1);
242  }
243 
244 /* -------------------------------------------------------
245  Read and store data values
246  ------------------------------------------------------- */
247 
248  fp = fopen(data_fname, "rb");
249  if (fp == NULL){
250  print1 ("! InputDataRead: file %s does not exist\n");
251  QUIT_PLUTO(1);
252  }
253  for (nv = 0; nv < id_nvar; nv++){
254  if (Vin[nv] == NULL) Vin[nv] = ARRAY_3D(id_nx3, id_nx2, id_nx1, double);
255 
256  dcount = 1;
257 
258  if (dsize == sizeof(double)){
259  for (k = 0; k < id_nx3; k++){
260  for (j = 0; j < id_nx2; j++){
261  for (i = 0; i < id_nx1; i++){
262  if (fread (&udbl, dsize, dcount, fp) != dcount){
263  print1 ("! InputDataRead: error reading data %d.\n",nv);
264  break;
265  }
266  if (swap_endian) SWAP_VAR(udbl);
267  Vin[nv][k][j][i] = udbl;
268  }}}
269  }else{
270  for (k = 0; k < id_nx3; k++){
271  for (j = 0; j < id_nx2; j++){
272  for (i = 0; i < id_nx1; i++){
273  if (fread (&uflt, dsize, dcount, fp) != dcount){
274  print1 ("! InputDataRead: error reading data %d.\n",nv);
275  break;
276  }
277  if (swap_endian) SWAP_VAR(uflt);
278  Vin[nv][k][j][i] = uflt;
279  }}}
280  }
281  }
282  fclose(fp);
283  print1 ("\n");
284 }
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
static int id_nx3
Size of input grid in the x3 direction.
Definition: input_data.c:42
static double *** Vin[ID_MAX_NVAR]
An array of 3D data values containing the initial data file variables.
Definition: input_data.c:50
#define YES
Definition: pluto.h:25
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
static int id_nx1
Size of input grid in the x1 direction.
Definition: input_data.c:40
#define SWAP_VAR(x)
Definition: macros.h:115
static int id_nx2
Size of input grid in the x2 direction.
Definition: input_data.c:41
int j
Definition: analysis.c:2
int IsLittleEndian(void)
Definition: tools.c:40
int k
Definition: analysis.c:2
int i
Definition: analysis.c:2
FILE * fp
Definition: analysis.c:7
static int id_nvar
Number of variables to be read on input.
Definition: input_data.c:38
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define NO
Definition: pluto.h:26

Here is the call graph for this function:

Here is the caller graph for this function:

void InputDataSet ( char *  grid_fname,
int *  get_var 
)

Initialize access to input data file by assigning values to grid-related information (geometry, number of points, etc...). This function should be called just once for input-data initialization.

Parameters
[in]gnamethe grid file name
[in]get_varan array of integers specifying which variables have to be read from the input data.
Returns
Thi function has no return value.

The following tasks are performed.

  • Scan grid data file and try to determine the grid geometry (id_geom). Search for tag "GEOMETRY:" and read the word that follows.
  • Move file pointer until the first line that does not begin with a "#".
  • Start reading number of points and grid coordinates. For the input x1 direction these are stored inside the module variables id_nx1 and id_x1.
  • Find out how many and which variables we have to read (:id_nvar and id_var_indx). Stop counting variables as soon as the first occurrence of "-1" in get_var is encountered

Definition at line 54 of file input_data.c.

67 {
68  int i, ip, nv, success;
69  size_t dsize, dcount;
70  char *sub_str, sline[256];
71  const char delimiters[] = " \t\r\f\n";
72  double xl, xr;
73  fpos_t file_pos;
74  FILE *fp;
75 
76  print1 ("> Input data:\n\n");
77 
78 /* --------------------------------------------------------------------- */
79 /*! - Scan grid data file and try to determine the grid geometry
80  (::id_geom). Search for tag "GEOMETRY:" and read the word that
81  follows. */
82 /* --------------------------------------------------------------------- */
83 
84  fp = fopen(grid_fname,"r");
85  if (fp == NULL){
86  print1 ("! InputDataSet: grid file %s not found\n",grid_fname);
87  QUIT_PLUTO(1);
88  }
89  success = 0;
90  while(!success){
91  fgets(sline,512,fp);
92  sub_str = strtok(sline, delimiters);
93  while (sub_str != NULL){
94  if (!strcmp(sub_str,"GEOMETRY:")) {
95  sub_str = strtok(NULL, delimiters);
96  success = 1;
97  break;
98  }
99  sub_str = strtok(NULL, delimiters);
100  }
101  }
102 
103  if (!strcmp(sub_str,"CARTESIAN")) id_geom = CARTESIAN;
104  else if (!strcmp(sub_str,"CYLINDRICAL")) id_geom = CYLINDRICAL;
105  else if (!strcmp(sub_str,"POLAR")) id_geom = POLAR;
106  else if (!strcmp(sub_str,"SPHERICAL")) id_geom = SPHERICAL;
107  else{
108  print1 ("! InputDataSet: unknown geometry\n");
109  QUIT_PLUTO(1);
110  }
111 
112  print1 (" Input grid file: %s\n", grid_fname);
113  print1 (" Input grid geometry: %s\n", sub_str);
114 
115 /* --------------------------------------------------------------------- */
116 /*! - Move file pointer until the first line that does not
117  begin with a "#". */
118 /* --------------------------------------------------------------------- */
119 
120  success = 0;
121  while(!success){
122  fgetpos(fp, &file_pos);
123  fgets(sline,512,fp);
124  if (sline[0] != '#') success = 1;
125  }
126 
127  fsetpos(fp, &file_pos);
128 
129 /* --------------------------------------------------------------------- */
130 /*! - Start reading number of points and grid coordinates. For the
131  input x1 direction these are stored inside the module variables
132  ::id_nx1 and ::id_x1. */
133 /* --------------------------------------------------------------------- */
134 
135  fscanf (fp,"%d \n",&id_nx1);
136  id_x1 = ARRAY_1D(id_nx1, double);
137  for (i = 0; i < id_nx1; i++){
138  fscanf(fp,"%d %lf %lf\n", &ip, &xl, &xr);
139  id_x1[i] = 0.5*(xl + xr);
140  }
141 
142  fscanf (fp,"%d \n",&id_nx2);
143  id_x2 = ARRAY_1D(id_nx2, double);
144  for (i = 0; i < id_nx2; i++){
145  fscanf(fp,"%d %lf %lf\n", &ip, &xl, &xr);
146  id_x2[i] = 0.5*(xl + xr);
147  }
148 
149  fscanf (fp,"%d \n",&id_nx3);
150  id_x3 = ARRAY_1D(id_nx3, double);
151  for (i = 0; i < id_nx3; i++){
152  fscanf(fp,"%d %lf %lf\n", &ip, &xl, &xr);
153  id_x3[i] = 0.5*(xl + xr);
154  }
155  fclose(fp);
156 
157 /* -- reset grid with 1 point -- */
158 
159  if (id_nx1 == 1) id_x1[0] = 0.0;
160  if (id_nx2 == 1) id_x2[0] = 0.0;
161  if (id_nx3 == 1) id_x3[0] = 0.0;
162 
163  print1 (" Input grid extension: x1 = [%12.3e, %12.3e] (%d points)\n",
164  id_x1[0], id_x1[id_nx1-1], id_nx1);
165  print1 ("\t\t\t x2 = [%12.3e, %12.3e] (%d points)\n",
166  id_x2[0], id_x2[id_nx2-1], id_nx2);
167  print1 ("\t\t\t x3 = [%12.3e, %12.3e] (%d points)\n",
168  id_x3[0], id_x3[id_nx3-1], id_nx3);
169 
170 
171 /* --------------------------------------------------------------------- */
172 /*! - Find out how many and which variables we have to read (:id_nvar
173  and ::id_var_indx).
174  Stop counting variables as soon as the first occurrence of "-1"
175  in get_var is encountered */
176 /* --------------------------------------------------------------------- */
177 
178  id_nvar = 0;
179  for (nv = 0; nv < ID_MAX_NVAR; nv++){
180  if (get_var[nv] != -1) {
181  id_nvar++;
182  id_var_indx[nv] = get_var[nv];
183  }else{
184  break;
185  }
186  }
187  print1 (" Number of variables: %d\n",id_nvar);
188 }
static double * id_x2
Array of point coordinates of the x2 input grid.
Definition: input_data.c:47
static int id_var_indx[ID_MAX_NVAR]
The variable index.
Definition: input_data.c:39
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
static int id_nx3
Size of input grid in the x3 direction.
Definition: input_data.c:42
#define SPHERICAL
Definition: pluto.h:36
static int id_nx1
Size of input grid in the x1 direction.
Definition: input_data.c:40
#define POLAR
Definition: pluto.h:35
static double * id_x1
Array of point coordinates of the x1 input grid.
Definition: input_data.c:46
static int id_nx2
Size of input grid in the x2 direction.
Definition: input_data.c:41
#define CARTESIAN
Definition: pluto.h:33
#define CYLINDRICAL
Definition: pluto.h:34
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
static int id_geom
Geometry of the input grid.
Definition: input_data.c:44
int i
Definition: analysis.c:2
FILE * fp
Definition: analysis.c:7
#define ID_MAX_NVAR
Definition: input_data.c:36
static int id_nvar
Number of variables to be read on input.
Definition: input_data.c:38
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
static double * id_x3
Array of point coordinates of the x3 input grid.
Definition: input_data.c:48

Here is the call graph for this function:

Here is the caller graph for this function:

void InternalBoundaryReset ( const State_1D ,
Time_Step ,
int  ,
int  ,
Grid  
)

Here is the caller graph for this function:

int IsLittleEndian ( void  )

Return 1 if the current architecture has little endian order

Definition at line 40 of file tools.c.

45 {
46  int TestEndian = 1;
47  return *(char*)&TestEndian;
48 }

Here is the caller graph for this function:

double Length_1 ( int  i,
int  j,
int  k,
Grid  
)

Definition at line 156 of file set_geometry.c.

164 {
165  return (grid[0].dx[i]);
166 }
int i
Definition: analysis.c:2

Here is the caller graph for this function:

double Length_2 ( int  i,
int  j,
int  k,
Grid  
)

Definition at line 169 of file set_geometry.c.

177 {
178  #if GEOMETRY == CARTESIAN || GEOMETRY == CYLINDRICAL
179  return (grid[1].dx[j]);
180  #elif GEOMETRY == POLAR || GEOMETRY == SPHERICAL
181  return (fabs(grid[0].xgc[i])*grid[1].dx[j]);
182  #endif
183 }
int j
Definition: analysis.c:2
int i
Definition: analysis.c:2

Here is the caller graph for this function:

double Length_3 ( int  i,
int  j,
int  k,
Grid  
)

Definition at line 186 of file set_geometry.c.

194 {
195  #if GEOMETRY == CARTESIAN || GEOMETRY == POLAR
196  return (grid[2].dx[k]);
197  #elif GEOMETRY == CYLINDRICAL
198  return (fabs(grid[0].xgc[i])*grid[2].dx[k]);
199  #elif GEOMETRY == SPHERICAL
200  return (fabs(grid[0].xgc[i]*sin(grid[1].xgc[j]))*grid[2].dx[k]);
201  #endif
202 }
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
int i
Definition: analysis.c:2

Here is the caller graph for this function:

int LocateIndex ( double *  yarr,
int  beg,
int  end,
double  y 
)

Given an array yarr[beg..end] and a given value y, returns the array index i such that yarr[i] < y < yarr[i+1] (for increasing arrays) or yarr[i+1] < y < yarr[i] (for decreasing arrays). yarr must be monotonically increasing or monotonically decreasing.

Parameters
[in]yarrthe 1D array
[in]beginitial index of the array
[in]endfinal index of the array
[in]ythe value to be searched for
Returns
On success return the index of the array. Otherwise returns -1.

Reference

  • "Numerical Recipes in C", Sect. 3.4 "How to Search an Ordered Table"

Definition at line 144 of file math_table2D.c.

165 {
166  int iu,im,il, ascnd;
167 
168  ascnd = (yarr[end] >= yarr[beg]); /* ascnd = 1 if table is increasing */
169 
170 /* --------------------------------------------
171  Check if y is bounded between max and min
172  -------------------------------------------- */
173 
174  if ( (ascnd && (y < yarr[beg] || y > yarr[end])) ||
175  (!ascnd && (y > yarr[beg] || y < yarr[end]))){
176 /* print ("! LocatIndex: element outside range ");
177  print ("(%12.6e not in [%12.6e, %12.6e]\n",y,yarr[beg],yarr[end]);*/
178  return -1;
179  }
180 
181  il = beg; /* Initialize lower */
182  iu = end; /* and upper limits. */
183 
184  while ( (iu - il) > 1) {
185  im = (iu + il) >> 1; /* Compute midpoint */
186  if ((y >= yarr[im]) == ascnd) il = im; /* Replace lower limit */
187  else iu = im; /* or upper limit */
188  }
189  if (y == yarr[beg]) return beg;
190  else if (y == yarr[end]) return end;
191  else return il;
192 }

Here is the caller graph for this function:

void MakeGeometry ( Grid GXYZ)
Parameters
[in,out]GXYZPointer to an array of Grid structures;

Definition at line 16 of file set_geometry.c.

22 {
23  int i, j, k, idim, ngh, ileft;
24  int iright;
25  int iend, jend, kend;
26  double xiL, xiR, dxi, dvol;
27  double x, dx, xr, xl;
28  double y, dy, yr, yl;
29  struct GRID *GG;
30 
31  iend = GXYZ[0].lend + GXYZ[0].nghost;
32  jend = GXYZ[1].lend + GXYZ[1].nghost;
33  kend = GXYZ[2].lend + GXYZ[2].nghost;
34 
35 /* --------------------------------------------------------------
36  Memory allocation. All values are defined at the cell center
37  with the exception of the area element which is defined on a
38  staggered mesh and therefore starts at [-1].
39  ----------------------------------------------------------- */
40 
41  for (idim = 0; idim < 3; idim++) {
42  (GXYZ + idim)->A = ARRAY_1D (GXYZ[idim].np_tot+1, double)+1;
43  (GXYZ + idim)->xgc = ARRAY_1D (GXYZ[idim].np_tot, double);
44  (GXYZ + idim)->dV = ARRAY_1D (GXYZ[idim].np_tot, double);
45  (GXYZ + idim)->r_1 = ARRAY_1D (GXYZ[idim].np_tot, double);
46  (GXYZ + idim)->ct = ARRAY_1D (GXYZ[idim].np_tot, double);
47  (GXYZ + idim)->inv_dx = ARRAY_1D (GXYZ[idim].np_tot, double);
48  (GXYZ + idim)->inv_dxi = ARRAY_1D (GXYZ[idim].np_tot, double);
49  }
50 
51 /* ------------------------------------------------------------
52  Define area (A), volume element (dV) and cell geometrical
53  centers for each direction.
54 
55  Conventions:
56  - G->dx: spacing (always > 0)
57  - G->x: cell-center. Can be > 0 or < 0
58  - G->xgc: geometrical cell center.
59  ----------------------------------------------------------- */
60 
61 /* ------------------------------------------------------------
62  X1 (IDIR) Direction
63  ------------------------------------------------------------ */
64 
65  GG = GXYZ;
66  for (i = 0; i <= iend; i++) {
67 
68  dx = GG->dx[i];
69  x = GG->x[i];
70  xr = x + 0.5*dx;
71  xl = x - 0.5*dx;
72 
73  #if GEOMETRY == CARTESIAN
74  GG->A[i] = 1.0;
75  if (i == 0) GG->A[-1] = 1.0;
76  GG->dV[i] = dx;
77  GG->xgc[i] = x;
78  #elif GEOMETRY == CYLINDRICAL || GEOMETRY == POLAR
79  GG->A[i] = fabs(xr);
80  if (i == 0) GG->A[-1] = fabs(xl);
81  GG->dV[i] = fabs(x)*dx;
82  GG->xgc[i] = x + dx*dx/(12.0*x);
83  GG->r_1[i] = 1.0/x;
84  #elif GEOMETRY == SPHERICAL
85  GG->A[i] = xr*xr;
86  if (i == 0) GG->A[-1] = xl*xl;
87 
88  GG->dV[i] = fabs(xr*xr*xr - xl*xl*xl)/3.0;
89  GG->xgc[i] = x + 2.0*x*dx*dx/(12.0*x*x + dx*dx);
90  GG->r_1[i] = 1.0/x;
91  #endif
92  }
93 
94 /* ------------------------------------------------------------
95  X2 (JDIR) Direction
96  ------------------------------------------------------------ */
97 
98  GG = GXYZ + 1;
99  for (j = 0; j <= jend; j++) {
100 
101  dx = GG->dx[j];
102  x = GG->x[j];
103  xr = x + 0.5*dx;
104  xl = x - 0.5*dx;
105  #if GEOMETRY != SPHERICAL
106  GG->A[j] = 1.0;
107  if (j == 0) GG->A[-1] = 1.0;
108  GG->dV[j] = dx;
109  GG->xgc[j] = x;
110 
111  #else
112  GG->A[j] = fabs(sin(xr));
113  if (j == 0) GG->A[-1] = fabs(sin(xl));
114  GG->dV[j] = fabs(cos(xl) - cos(xr));
115 
116  GG->xgc[j] = (sin(xr) - sin(xl) + xl*cos(xl) - xr*cos(xr));
117  GG->xgc[j] /= cos(xl) - cos(xr);
118  GG->ct[j] = 1.0/tan(x); /* (sin(xr) - sin(xl))/(cos(xl) - cos(xr)); */
119  #endif
120  }
121 
122 /* ------------------------------------------------------------
123  X3 (KDIR) Direction
124  ------------------------------------------------------------ */
125 
126  GG = GXYZ + 2;
127  for (k = 0; k <= kend; k++) {
128  dx = GG->dx[k];
129  x = GG->x[k];
130  xr = x + 0.5*dx;
131  xl = x - 0.5*dx;
132 
133  GG->A[k] = 1.0;
134  if (k == 0) GG->A[-1] = 1.0;
135  GG->dV[k] = dx;
136  GG->xgc[k] = x;
137  }
138 
139 /* ---------------------------------------------------------
140  compute and store the reciprocal of cell spacing
141  between interfaces (inv_dx) and cell centers (inv_dxi)
142  --------------------------------------------------------- */
143 
144  for (idim = 0; idim < DIMENSIONS; idim++){
145  for (i = 0; i < GXYZ[idim].np_tot; i++) {
146  GXYZ[idim].inv_dx[i] = 1.0/(GXYZ[idim].dx[i]);
147  }
148 
149  for (i = 0; i < GXYZ[idim].np_tot-1; i++) {
150  GXYZ[idim].inv_dxi[i] = 2.0/(GXYZ[idim].dx[i] + GXYZ[idim].dx[i+1]);
151  }
152  }
153 }
double * xr
Definition: structs.h:81
int lend
Local end index for the local array.
Definition: structs.h:118
double * dV
Cell volume.
Definition: structs.h:86
double * dx
Definition: structs.h:83
double * inv_dx
Definition: structs.h:90
double * xl
Definition: structs.h:82
Definition: structs.h:78
int j
Definition: analysis.c:2
int nghost
Number of ghost zones.
Definition: structs.h:104
int k
Definition: analysis.c:2
double * x
Definition: structs.h:80
double * xgc
Cell volumetric centroid (!= x when geometry != CARTESIAN).
Definition: structs.h:84
double * r_1
Geometrical factor 1/r.
Definition: structs.h:88
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
int i
Definition: analysis.c:2
double * ct
Geometrical factor cot(theta).
Definition: structs.h:89
int np_tot
Total number of points in the local domain (boundaries included).
Definition: structs.h:100
double * inv_dxi
inverse of the distance between the center of two cells, inv_dxi = .
Definition: structs.h:91
double * A
Right interface area, A[i] = .
Definition: structs.h:87
#define DIMENSIONS
Definition: definitions_01.h:2

Here is the caller graph for this function:

void MakeState ( State_1D state)

Allocate memory areas for arrays inside the state structure.

Definition at line 51 of file tools.c.

59 {
60  state->v = ARRAY_2D(NMAX_POINT, NVAR, double);
61  state->vp = ARRAY_2D(NMAX_POINT, NVAR, double);
62  state->vm = ARRAY_2D(NMAX_POINT, NVAR, double);
63  state->up = ARRAY_2D(NMAX_POINT, NVAR, double);
64  state->um = ARRAY_2D(NMAX_POINT, NVAR, double);
65  state->flux = ARRAY_2D(NMAX_POINT, NVAR, double);
66 
67  state->src = ARRAY_2D(NMAX_POINT, NVAR, double);
68 
69  state->visc_flux = ARRAY_2D(NMAX_POINT, NVAR, double);
70  state->visc_src = ARRAY_2D(NMAX_POINT, NVAR, double);
71  state->tc_flux = ARRAY_2D(NMAX_POINT, NVAR, double);
72  state->res_flux = ARRAY_2D(NMAX_POINT, NVAR, double);
73 
74  state->rhs = ARRAY_2D(NMAX_POINT, NVAR, double);
75  state->press = ARRAY_1D(NMAX_POINT, double);
76  state->bn = ARRAY_1D(NMAX_POINT, double);
77  state->SL = ARRAY_1D(NMAX_POINT, double);
78  state->SR = ARRAY_1D(NMAX_POINT, double);
79 
80 /* -- eigenvectors -- */
81 
82  state->Lp = ARRAY_3D(NMAX_POINT, NFLX, NFLX, double);
83  state->Rp = ARRAY_3D(NMAX_POINT, NFLX, NFLX, double);
84  state->lambda = ARRAY_2D(NMAX_POINT, NFLX, double);
85  state->lmax = ARRAY_1D(NVAR, double);
86 
87  state->a2 = ARRAY_1D(NMAX_POINT, double);
88  state->h = ARRAY_1D(NMAX_POINT, double);
89 
90 /* state->dwlim = ARRAY_2D(NMAX_POINT, NVAR, double);*/
91 
92  state->flag = ARRAY_1D(NMAX_POINT, unsigned char);
93 
94 /* --------------------------------------
95  define shortcut pointers for
96  left and right values with respect
97  to the cell center
98  -------------------------------------- */
99 
100  state->vL = state->vp;
101  state->vR = state->vm + 1;
102 
103  state->uL = state->up;
104  state->uR = state->um + 1;
105 
106  #if (TIME_STEPPING == HANCOCK) || (TIME_STEPPING == CHARACTERISTIC_TRACING)
107  state->vh = ARRAY_2D(NMAX_POINT, NVAR, double);
108  #else
109  state->vh = state->v;
110  #endif
111 
112 }
double ** v
Cell-centered primitive varables at the base time level, v[i] = .
Definition: structs.h:134
double * lmax
Define the maximum k-characteristic speed over the domain.
Definition: structs.h:157
double ** vh
Primitive state at n+1/2 (only for one step method)
Definition: structs.h:162
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
double ** visc_src
Viscosity source term.
Definition: structs.h:151
double *** Lp
Definition: structs.h:155
double ** rhs
Conservative right hand side.
Definition: structs.h:163
double * SR
Rightmost velocity in the Riemann fan at i+1/2.
Definition: structs.h:167
double ** res_flux
Resistive flux (current)
Definition: structs.h:153
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
double ** visc_flux
Viscosity flux.
Definition: structs.h:150
double * h
Enthalpy.
Definition: structs.h:159
double ** vp
prim vars at i+1/2 edge, vp[i] = vL(i+1/2)
Definition: structs.h:142
double ** src
Definition: structs.h:160
#define NFLX
Definition: mod_defs.h:32
double * SL
Leftmost velocity in the Riemann fan at i+1/2.
Definition: structs.h:166
double ** lambda
Characteristic speed associated to Lp and Rp.
Definition: structs.h:156
unsigned char * flag
Definition: structs.h:168
double ** tc_flux
Thermal conduction flux.
Definition: structs.h:152
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
Definition: structs.h:141
double ** uR
same as vR, in conservative vars
Definition: structs.h:145
#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
double * bn
Face magentic field, bn = bx(i+1/2)
Definition: structs.h:165
double ** um
same as vm, in conservative vars
Definition: structs.h:146
double ** vL
Primitive variables to the left of the interface, .
Definition: structs.h:136
double * a2
Sound speed squared.
Definition: structs.h:158
double * press
Upwind pressure term computed with the Riemann solver.
Definition: structs.h:164
double ** up
same as vp, in conservative vars
Definition: structs.h:147
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
double *** Rp
Left and right primitive eigenvectors.
Definition: structs.h:155
#define NVAR
Definition: pluto.h:609
double ** uL
same as vL, in conservative vars
Definition: structs.h:144

Here is the caller graph for this function:

double MeanMolecularWeight ( double *  v)

Return the mean molecular weight.

Parameters
[in]varray of primitive variables (including ions)

Definition at line 178 of file radiat.modified_by_Bhargav.c.

222 {
223  int nv;
224 
225  for (nv = NFLX;nv <(NFLX+NIONS);nv++){
226  if (V[nv] < 0.0) V[nv] = 0.0;
227  if (V[nv] > 1.0) V[nv] = 1.0;
228  }
229 
230  double N_H = V[RHO]*(UNIT_DENSITY/CONST_amu)*(X/A_H); /* n(H) */
231  double N_He = V[RHO]*(UNIT_DENSITY/CONST_amu)*(Y/A_He); /* n(He) */
232  double N_Z = V[RHO]*(UNIT_DENSITY/CONST_amu)*((1.0-X-Y)/A_Z); /*/ n(metals) */
233 
234  double fracHe = N_He/N_H;
235  double fracZ = N_Z/N_H;
236 
237  double fn = V[X_HI];
238 
239  double munum = 1.0 + A_He*(fracHe) + A_Z*(fracZ);
240  double muden = 2 - fn + fracHe + fracZ + 0.5*A_Z*(fracZ);
241 
242  return munum/muden;
243 
244 
245  /*
246  return ( (A_H + frac_He*A_He + frac_Z*A_Z) /
247  (2.0 + frac_He + 2.0*frac_Z - V[X_HI]));
248  */
249 }
#define UNIT_DENSITY
Unit density in gr/cm^3.
Definition: pluto.h:369
#define RHO
Definition: mod_defs.h:19
#define CONST_amu
Atomic mass unit.
Definition: pluto.h:253
#define Y
#define A_H
#define X
#define NFLX
Definition: mod_defs.h:32
#define NIONS
Definition: cooling.h:28
#define A_He
Definition: cooling.h:110
#define A_Z

Here is the call graph for this function:

Here is the caller graph for this function:

double Median ( double  a,
double  b,
double  c 
)

Definition at line 264 of file fd_reconstruct.c.

270 {
271  return (a + MINMOD(b-a,c-a));
272 }
static double a
Definition: init.c:135
#define MINMOD(a, b)
Definition: macros.h:112
tuple c
Definition: menu.py:375

Here is the caller graph for this function:

FILE* OpenBinaryFile ( char *  filename,
int  sz,
char *  mode 
)

Open a file for write/reading in binary mode.

Parameters
[in]filenamea valid file name
[in]szthe distributed array descriptor. This parameter replaces dsize in parallel mode
[in]modea string giving the opening mode (only "w" or "r" are allowed)
Returns
The pointer to the file.

Definition at line 31 of file bin_io.c.

43 {
44  FILE *fp;
45 
46 /* ----------------------------------------------
47  when reading, check if file exists
48  ---------------------------------------------- */
49 
50  if (strcmp(mode,"r") == 0 && prank == 0){
51  fp = fopen(filename, "rb");
52  if (fp == NULL){
53  print1 ("! OpenBinaryFile: file %s does not exists\n", filename);
54  QUIT_PLUTO(1);
55  }
56  fclose(fp);
57  }
58 
59 /* ------------------------------------------------
60  file exists, keep going
61  ------------------------------------------------ */
62 
63  #ifdef PARALLEL
64  AL_File_open(filename, sz);
65  return NULL;
66  #else
67  if (strcmp(mode,"w") == 0) fp = fopen(filename, "wb");
68  else if (strcmp(mode,"r") == 0) fp = fopen(filename, "rb");
69  if (fp == NULL){
70  print1 ("! Cannot find file %s\n",filename);
71  QUIT_PLUTO(1);
72  }
73  return (fp);
74  #endif
75 }
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
int AL_File_open(char *filename, int sz_ptr)
Definition: al_io.c:27
int prank
Processor rank.
Definition: globals.h:33
FILE * fp
Definition: analysis.c:7
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

Here is the caller graph for this function:

void OutflowBound ( double ***  q,
int  side,
int  vpos,
Grid grid 
)

Impose zero-gradient boundary conditions on 'q' on the boundary side specified by box->side. The staggered component of magnetic field is assigned using the div.B = 0 condition in a different loop.

Parameters
[in,out]qa 3D array representing a flow variable
[in]boxpointer to a RBox structure defining the extent of the boundary region and the variable position inside the cell
[in]gridpointer to an array of Grid structures

Definition at line 295 of file boundary.c.

308 {
309  int i, j, k;
310  double dB, *A, *dV;
311  RBox *box = GetRBox (side, vpos);
312 
313  A = grid->A;
314  dV = grid->dV;
315 
316  if (side == X1_BEG) {
317  if (box->vpos != X1FACE){
318  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k][j][IBEG];
319  }else{
320  BOX_LOOP(box,k,j,i){
321  #if GEOMETRY == CARTESIAN
322  q[k][j][i] = 2.0*q[k][j][i+1] - q[k][j][i+2];
323  #else
324  dB = (A[i+2]*q[k][j][i+2] - A[i+1]*q[k][j][i+1])/dV[i+2];
325  q[k][j][i] = (q[k][j][i+1]*A[i+1] - dV[i+1]*dB)/A[i];
326  #endif
327  }
328  }
329 
330  }else if (side == X1_END){
331 
332  if (box->vpos != X1FACE){
333  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k][j][IEND];
334  }else{
335  BOX_LOOP(box,k,j,i){
336  #if GEOMETRY == CARTESIAN
337  q[k][j][i] = 2.0*q[k][j][i-1] - q[k][j][i-2];
338  #else
339  dB = (A[i-1]*q[k][j][i-1] - A[i-2]*q[k][j][i-2])/dV[i-1];
340  q[k][j][i] = (q[k][j][i-1]*A[i-1] + dV[i]*dB)/A[i];
341  #endif
342  }
343  }
344 
345  }else if (side == X2_BEG){
346 
347  if (box->vpos != X2FACE) {
348  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k][JBEG][i];
349  }else{
350  BOX_LOOP(box,k,j,i) {
351  #if GEOMETRY == CARTESIAN
352  q[k][j][i] = 2.0*q[k][j+1][i] - q[k][j+2][i];
353  #else
354  dB = (A[j+2]*q[k][j+2][i] - A[j+1]*q[k][j+1][i])/dV[j+2];
355  q[k][j][i] = (q[k][j+1][i]*A[j+1] - dV[j+1]*dB)/A[j];
356  #endif
357  }
358  }
359 
360  }else if (side == X2_END){
361 
362  if (box->vpos != X2FACE) {
363  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k][JEND][i];
364  }else{
365  BOX_LOOP(box,k,j,i){
366  #if GEOMETRY == CARTESIAN
367  q[k][j][i] = 2.0*q[k][j-1][i] - q[k][j-2][i];
368  #else
369  dB = (A[j-1]*q[k][j-1][i] - A[j-2]*q[k][j-2][i])/dV[j-1];
370  q[k][j][i] = (q[k][j-1][i]*A[j-1] + dV[j]*dB)/A[j];
371  #endif
372  }
373  }
374 
375  }else if (side == X3_BEG){
376 
377  if (box->vpos != X3FACE) {
378  BOX_LOOP(box,k,j,i) q[k][j][i] = q[KBEG][j][i];
379  }else{
380  BOX_LOOP(box,k,j,i) {
381  #if GEOMETRY == CARTESIAN
382  q[k][j][i] = 2.0*q[k+1][j][i] - q[k+2][j][i];
383  #else
384  dB = (A[k+2]*q[k+2][j][i] - A[k+1]*q[k+1][j][i])/dV[k+2];
385  q[k][j][i] = (q[k+1][j][i]*A[k+1] - dV[k+1]*dB)/A[k];
386  #endif
387  }
388  }
389 
390  }else if (side == X3_END){
391 
392  if (box->vpos != X3FACE) {
393  BOX_LOOP(box,k,j,i) q[k][j][i] = q[KEND][j][i];
394  }else{
395  BOX_LOOP(box,k,j,i) {
396  #if GEOMETRY == CARTESIAN
397  q[k][j][i] = 2.0*q[k-1][j][i] - q[k-2][j][i];
398  #else
399  dB = (A[k-1]*q[k-1][j][i] - A[k-2]*q[k-2][j][i])/dV[k-1];
400  q[k][j][i] = (q[k-1][j][i]*A[k-1] + dV[k]*dB)/A[k];
401  #endif
402  }
403  }
404  }
405 }
#define X3_BEG
Boundary region at X3 beg.
Definition: pluto.h:150
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
RBox * GetRBox(int, int)
Definition: rbox.c:232
int vpos
Location of the variable inside the cell.
Definition: structs.h:359
double dB
Definition: analysis.c:4
#define X3FACE
Definition: pluto.h:203
#define BOX_LOOP(B, k, j, i)
Definition: macros.h:70
double * dV
Cell volume.
Definition: structs.h:86
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
#define X1FACE
Definition: pluto.h:201
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
int j
Definition: analysis.c:2
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
#define X3_END
Boundary region at X3 end.
Definition: pluto.h:151
int i
Definition: analysis.c:2
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
#define X2_BEG
Boundary region at X2 beg.
Definition: pluto.h:148
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
Definition: structs.h:346
static Runtime q
#define X2FACE
Definition: pluto.h:202
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
double * A
Right interface area, A[i] = .
Definition: structs.h:87

Here is the call graph for this function:

Here is the caller graph for this function:

void ParabolicFlux ( Data_Arr  V,
Data_Arr  J,
double ***  T,
const State_1D state,
double **  dcoeff,
int  beg,
int  end,
Grid grid 
)

Add the diffusion fluxes to the upwind fluxes for explicit time integration.

Parameters
[in]Vpointer to the 3D array of cell-centered primitive variables
[in,out]statepointer to a State_1D structure
[out]dcoeffthe diffusion coefficients 1D array
[in]beginitial index of computation
[in]endfinal index of computation
[in]gridpointer to an array of Grid structures

Definition at line 34 of file parabolic_flux.c.

50 {
51  int i, j, k, nv;
52 
53 /* -------------------------------------------------
54  1. Viscosity
55  ------------------------------------------------- */
56 
57  #if VISCOSITY == EXPLICIT
58  #ifdef FARGO
59  print ("! ParabolicFlux: FARGO incompatible with explicit viscosity.\n");
60  print (" Try STS or RKC instead\n");
61  QUIT_PLUTO(1);
62  #endif
63  ViscousFlux (V, state->visc_flux, state->visc_src, dcoeff, beg, end, grid);
64  for (i = beg; i <= end; i++){
65  EXPAND(state->flux[i][MX1] -= state->visc_flux[i][MX1]; ,
66  state->flux[i][MX2] -= state->visc_flux[i][MX2]; ,
67  state->flux[i][MX3] -= state->visc_flux[i][MX3]; )
68  #if HAVE_ENERGY
69  state->flux[i][ENG] -= state->visc_flux[i][ENG];
70  #endif
71 
72  }
73  #endif
74 
75 /* -------------------------------------------------
76  2. Thermal conduction
77  ------------------------------------------------- */
78 
79  #if THERMAL_CONDUCTION == EXPLICIT
80  TC_Flux (T, state, dcoeff, beg, end, grid);
81  for (i = beg; i <= end; i++) state->flux[i][ENG] -= state->tc_flux[i][ENG];
82  /* !!!! tc_flux can be redefined as a 1D array since only the energy
83  component is required !!! */
84  #endif
85 
86 /* ----------------------------------------------------------------
87  3. Resistivity.
88  Note for the entropy flux: differently from viscosity and
89  thermal conduction, the contribution to the entropy due to
90  currents is given by J^2 and cannot be expressed as a simple
91  two-point flux difference.
92  This is done in a separate step (...)
93  ---------------------------------------------------------------- */
94 
95  #if (RESISTIVITY == EXPLICIT)
96  ResistiveFlux (V, J, state->res_flux, dcoeff, beg, end, grid);
97  for (i = beg; i <= end; i++){
98 
99  /* ------------------------------------------
100  normal component of magnetic field does
101  not evolve during the current sweep.
102  ------------------------------------------ */
103 
104  state->res_flux[i][BXn] = 0.0;
105 
106  /* ---------------------------------------------------
107  add the parabolic part of the EMF, only for
108  cell-centered MHD. CT is handled in a truly
109  multidimensional way.
110  --------------------------------------------- */
111 
112  EXPAND(state->flux[i][BX1] += state->res_flux[i][BX1]; ,
113  state->flux[i][BX2] += state->res_flux[i][BX2]; ,
114  state->flux[i][BX3] += state->res_flux[i][BX3]; )
115  #if HAVE_ENERGY
116  state->flux[i][ENG] += state->res_flux[i][ENG];
117  #endif
118  }
119  #endif
120 
121 }
#define MX3
Definition: mod_defs.h:22
tuple T
Definition: Sph_disk.py:33
void ViscousFlux(Data_Arr, double **, double **, double **, int, int, Grid *)
Definition: viscous_flux.c:14
int end
Global end index for the local array.
Definition: structs.h:116
#define MX1
Definition: mod_defs.h:20
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
void TC_Flux(double ***, const State_1D *, double **, int, int, Grid *)
Definition: tc_flux.c:57
double ** visc_src
Viscosity source term.
Definition: structs.h:151
double ** res_flux
Resistive flux (current)
Definition: structs.h:153
double ** visc_flux
Viscosity flux.
Definition: structs.h:150
int BXn
Definition: globals.h:75
int beg
Global start index for the local array.
Definition: structs.h:115
int j
Definition: analysis.c:2
#define MX2
Definition: mod_defs.h:21
if(divB==NULL)
Definition: analysis.c:10
int k
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
double ** tc_flux
Thermal conduction flux.
Definition: structs.h:152
#define BX3
Definition: mod_defs.h:27
#define RESISTIVITY
Definition: pluto.h:357
int i
Definition: analysis.c:2
#define BX1
Definition: mod_defs.h:25
#define BX2
Definition: mod_defs.h:26
void ResistiveFlux(Data_Arr V, Data_Arr curlB, double **res_flux, double **dcoeff, int beg, int end, Grid *grid)
Definition: res_flux.c:52
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define EXPLICIT
Definition: pluto.h:67

Here is the call graph for this function:

Here is the caller graph for this function:

double ParabolicRHS ( const Data d,
Data_Arr  dU,
double  dt,
Grid grid 
)
Parameters
[in]V3D array containing primitive variables
[out]dU3D array containing the conservative right hand sides
[in]dtthe time step
[in]grida pointer to an array of Grid structure
Returns
On output it returns the maximum diffusion coefficients among all dissipative term over the local processor grid.

Definition at line 50 of file parabolic_rhs.c.

60 {
61  int i, j, k, nv;
62  double r, th, r_1, s_1;
63  double dtdl, dtdV, dt_rdr;
64  double *inv_dl, inv_dl2;
65  double *rp, *A, *du, **vh, *C, **tc_flx;
66  double dvp[NVAR], dvm[NVAR], dvl;
67  double ****V;
68  static double **res_flx;
69  static double **dcoeff, ***T;
70  static double **ViF, **ViS;
71 
72  static Data_Arr C_dtp;
73  static State_1D state;
74  double max_inv_dtp[3],inv_dtp;
75 
76  i = j = k = 0;
77 
78  if (C_dtp == NULL) {
79  C_dtp = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
80  #if ADD_TC
81  MakeState (&state);
82  #ifdef CH_SPACEDIM
83  i = j = k = 1;
84  D_EXPAND(i = NMAX_POINT;, j = NMAX_POINT;, k = NMAX_POINT;)
85  T = ARRAY_3D(k, j, i, double);
86  #else
87  T = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
88  #endif
89  #endif
90 
91  ViF = ARRAY_2D(NMAX_POINT, NVAR, double);
92  ViS = ARRAY_2D(NMAX_POINT, NVAR, double);
93  res_flx = ARRAY_2D(NMAX_POINT, NVAR, double);
94  dcoeff = ARRAY_2D(NMAX_POINT, NVAR, double);
95  }
96 
97  V = d->Vc; /* -- set a pointer to the primitive vars array -- */
98 
99  #if ADD_RESISTIVITY && (defined STAGGERED_MHD)
100  GetCurrent (d, -1, grid);
101  #endif
102 
103 /* ------------------------------------------------
104  compute the temperature array if TC is needed
105  ------------------------------------------------ */
106 
107  #if ADD_TC
108  TOT_LOOP(k,j,i) T[k][j][i] = V[PRS][k][j][i]/V[RHO][k][j][i];
109  vh = state.vh;
110  tc_flx = state.tc_flux;
111  #endif
112 
113 max_inv_dtp[0] = max_inv_dtp[1] = max_inv_dtp[2] = 0.0;
114 
115 /* ----------------------------------------------------------------------
116  L O O P O N X1 D I R E C T I O N ( I D I R )
117  ---------------------------------------------------------------------- */
118 
119  g_dir = IDIR;
120  A = grid[g_dir].A;
121  rp = grid[g_dir].xr;
122  #if ADD_RESISTIVITY && !(defined STAGGERED_MHD)
123  GetCurrent(d, g_dir, grid);
124  #endif
125  KDOM_LOOP (k){
126  JDOM_LOOP (j){
127 
128  g_j = j; g_k = k;
129 
130  /* -------------------------------------------------------------------
131  Compute viscous, resistive and thermal cond. fluxes in the x1 dir
132  ------------------------------------------------------------------- */
133 
134  #if ADD_VISCOSITY
135  ViscousFlux (V, ViF, ViS, dcoeff, IBEG-1, IEND, grid);
136  #endif
137 
138  #if ADD_RESISTIVITY
139  ResistiveFlux (V, d->J, res_flx, dcoeff, IBEG - 1, IEND, grid);
140  #endif
141 
142  #if ADD_TC
143  ITOT_LOOP (i) for (nv = NVAR; nv--; ) vh[i][nv] = V[nv][k][j][i];
144 
145  for (nv = NVAR; nv--; ) dvm[nv] = vh[1][nv] - vh[0][nv];
146  for(i=1; i<NX1_TOT-1; i++){
147  for (nv = NVAR; nv--; ) {
148  dvp[nv] = vh[i+1][nv] - vh[i][nv];
149  dvl = VAN_LEER(dvp[nv], dvm[nv]);
150  state.vp[i][nv] = vh[i][nv] + 0.5*dvl;
151  state.vm[i][nv] = vh[i][nv] - 0.5*dvl;
152  dvm[nv] = dvp[nv];
153  }}
154  TC_Flux (T, &state, dcoeff, IBEG - 1, IEND, grid);
155  #endif
156 
157  /* ---------------------------
158  compute inverse time-step
159  --------------------------- */
160 
161  if (g_intStage == 1){
162  inv_dl = GetInverse_dl(grid);
163  IDOM_LOOP(i){
164  C = C_dtp[k][j][i];
165  inv_dl2 = 0.5*inv_dl[i]*inv_dl[i];
166  #if ADD_VISCOSITY
167  C[MX1] = (dcoeff[i-1][MX1] + dcoeff[i][MX1])*inv_dl2;
168  #endif
169  #if ADD_RESISTIVITY
170  EXPAND(C[BX1] = (dcoeff[i-1][BX1] + dcoeff[i][BX1])*inv_dl2; ,
171  C[BX2] = (dcoeff[i-1][BX2] + dcoeff[i][BX2])*inv_dl2; ,
172  C[BX3] = (dcoeff[i-1][BX3] + dcoeff[i][BX3])*inv_dl2;)
173  #endif
174  #if ADD_TC
175  C[ENG] = (dcoeff[i-1][ENG] + dcoeff[i][ENG])*inv_dl2;
176  inv_dtp = dcoeff[i][ENG]*inv_dl[i]*inv_dl[i];
177  max_inv_dtp[g_dir] = MAX(max_inv_dtp[g_dir], inv_dtp);
178  #endif
179  }
180  }
181 
182  /* ---------------------------
183  Main X1-sweep
184  --------------------------- */
185 
186  IDOM_LOOP (i){
187 
188  du = dU[k][j][i];
189  r = grid[IDIR].x[i];
190  dtdV = dt/grid[IDIR].dV[i];
191  dtdl = dt/grid[IDIR].dx[i];
192 
193  #if HAVE_ENERGY
194  du[ENG] = 0.0; /* energy contribution may come from any of the
195  dissipative terms. It's better to initialize it
196  to zero and then add contribution separately. */
197  #endif
198 
199  /* -------------------------------------------
200  VISCOSITY: build rhs in the x1 direction
201  ------------------------------------------- */
202 
203  #if ADD_VISCOSITY
204  r_1 = 1.0/grid[IDIR].x[i];
205  #if GEOMETRY == CARTESIAN
206  EXPAND(du[MX1] = (ViF[i][MX1] - ViF[i-1][MX1])*dtdl + dt*ViS[i][MX1];,
207  du[MX2] = (ViF[i][MX2] - ViF[i-1][MX2])*dtdl + dt*ViS[i][MX2];,
208  du[MX3] = (ViF[i][MX3] - ViF[i-1][MX3])*dtdl + dt*ViS[i][MX3];)
209  #if HAVE_ENERGY
210  du[ENG] += (ViF[i][ENG] - ViF[i - 1][ENG])*dtdl;
211  #endif
212  #elif GEOMETRY == CYLINDRICAL
213  EXPAND(du[MX1] = (A[i]*ViF[i][MX1] - A[i-1]*ViF[i-1][MX1])*dtdV
214  + dt*ViS[i][MX1]; ,
215  du[MX2] = (A[i]*ViF[i][MX2] - A[i-1]*ViF[i-1][MX2])*dtdV
216  + dt*ViS[i][MX2]; ,
217  du[MX3] = (A[i]*A[i]*ViF[i][MX3] - A[i-1]*A[i-1]*ViF[i-1][MX3])*r_1*dtdV;)
218  #if HAVE_ENERGY
219  du[ENG] += (A[i]*ViF[i][ENG] - A[i-1]*ViF[i-1][ENG])*dtdV;
220  #endif
221  #elif GEOMETRY == POLAR
222  EXPAND(du[MX1] = (A[i]*ViF[i][MX1] - A[i-1]*ViF[i-1][MX1])*dtdV
223  + dt*ViS[i][MX1]; ,
224  du[MX2] = (A[i]*A[i]*ViF[i][MX2] - A[i-1]*A[i-1]*ViF[i-1][MX2])*r_1*dtdV; ,
225  du[MX3] = (A[i]*ViF[i][MX3] - A[i-1]*ViF[i-1][MX3])*dtdV
226  + dt*ViS[i][MX3];)
227  #if HAVE_ENERGY
228  du[ENG] += (A[i]*ViF[i][ENG] - A[i-1]*ViF[i-1][ENG])*dtdV;
229  #endif
230  #elif GEOMETRY == SPHERICAL
231  EXPAND(du[MX1] = (A[i]*ViF[i][MX1] - A[i-1]*ViF[i-1][MX1])*dtdV
232  + dt*ViS[i][MX1];,
233  du[MX2] = (A[i]*ViF[i][MX2] - A[i-1]*ViF[i-1][MX2])*dtdV
234  + dt*ViS[i][MX2];,
235  du[MX3] = (rp[i]*A[i]*ViF[i][MX3] - rp[i-1]*A[i-1]*ViF[i-1][MX3])*r_1*dtdV;)
236  #if HAVE_ENERGY
237  du[ENG] += (A[i]*ViF[i][ENG] - A[i-1]*ViF[i-1][ENG])*dtdV;
238  #endif
239  #endif
240  #endif /* -- VISCOSITY -- */
241 
242  /* ----------------------------------------------
243  RESISTIVITY: build rhs in the x1 direction
244  ---------------------------------------------- */
245 
246  #if ADD_RESISTIVITY
247  #if GEOMETRY == CARTESIAN /* -- x coordinate -- */
248  EXPAND(
249  du[BX1] = 0.0; ,
250  du[BX2] = -(res_flx[i][BX2] - res_flx[i-1][BX2])*dtdl; ,
251  du[BX3] = -(res_flx[i][BX3] - res_flx[i-1][BX3])*dtdl; )
252  #if EOS != ISOTHERMAL
253  du[ENG] += -(res_flx[i][ENG] - res_flx[i-1][ENG])*dtdl;
254  #endif
255 
256  #elif GEOMETRY == CYLINDRICAL /* -- r coordinate -- */
257  EXPAND(
258  du[BX1] = 0.0; ,
259  du[BX2] = -(A[i]*res_flx[i][BX2] - A[i-1]*res_flx[i-1][BX2])*dtdV; ,
260  du[BX3] = -(res_flx[i][BX3] - res_flx[i-1][BX3])*dtdl;)
261  #if EOS != ISOTHERMAL
262  du[ENG] += -(A[i]*res_flx[i][ENG] - A[i-1]*res_flx[i-1][ENG])*dtdV;
263  #endif
264 
265  #elif GEOMETRY == POLAR /* -- r coordinate -- */
266  EXPAND(
267  du[BX1] = 0.0; ,
268  du[BX2] = -(res_flx[i][BX2] - res_flx[i-1][BX2])*dtdl; ,
269  du[BX3] = -(A[i]*res_flx[i][BX3] - A[i-1]*res_flx[i-1][BX3])*dtdV; )
270  #if EOS != ISOTHERMAL
271  du[ENG] += -(A[i]*res_flx[i][ENG] - A[i-1]*res_flx[i-1][ENG])*dtdV;
272  #endif
273 
274  #elif GEOMETRY == SPHERICAL /* -- r coordinate -- */
275  dt_rdr = dtdl/r;
276  EXPAND(
277  du[BX1] = 0.0; ,
278  du[BX2] = -(rp[i]*res_flx[i][BX2] - rp[i-1]*res_flx[i-1][BX2])*dt_rdr; ,
279  du[BX3] = -(rp[i]*res_flx[i][BX3] - rp[i-1]*res_flx[i-1][BX3])*dt_rdr; )
280  #if EOS != ISOTHERMAL
281  du[ENG] += -(A[i]*res_flx[i][ENG] - A[i-1]*res_flx[i-1][ENG])*dtdV;
282  #endif
283  #endif
284  #endif /* -- RESISTIVITY -- */
285 
286  /* ---------------------------------------------------
287  THERMAL_CONDUCTION: build rhs in the x1 direction
288  --------------------------------------------------- */
289 
290  #if ADD_TC
291  #if GEOMETRY == CARTESIAN
292  du[ENG] += (tc_flx[i][ENG] - tc_flx[i-1][ENG])*dtdl;
293  #else
294  du[ENG] += (A[i]*tc_flx[i][ENG] - A[i-1]*tc_flx[i-1][ENG])*dtdV;
295  #endif
296  #endif
297  }
298  }}
299 
300 /* ----------------------------------------------------------------------
301  L O O P O N X2 D I R E C T I O N ( J D I R )
302  ---------------------------------------------------------------------- */
303 
304 #if DIMENSIONS > 1
305  g_dir = JDIR;
306  A = grid[g_dir].A;
307  #if ADD_RESISTIVITY && !(defined STAGGERED_MHD)
308  GetCurrent(d, g_dir, grid);
309  #endif
310  KDOM_LOOP (k){
311  IDOM_LOOP (i){
312 
313  g_i = i; g_k = k;
314 
315  /* -------------------------------------------------------------------
316  Compute viscous, resistive and thermal cond. fluxes in the x2 dir
317  ------------------------------------------------------------------- */
318 
319  #if ADD_VISCOSITY
320  ViscousFlux (V, ViF, ViS, dcoeff, JBEG-1, JEND, grid);
321  #endif
322  #if ADD_RESISTIVITY
323  ResistiveFlux (V, d->J, res_flx, dcoeff, JBEG - 1, JEND, grid);
324  #endif
325 
326  #if ADD_TC
327  JTOT_LOOP (j) for (nv = NVAR; nv--; ) vh[j][nv] = V[nv][k][j][i];
328 
329  for (nv = NVAR; nv--; ) dvm[nv] = vh[1][nv] - vh[0][nv];
330  for(j = 1; j < NX2_TOT-1; j++){
331  for (nv = NVAR; nv--; ) {
332  dvp[nv] = vh[j+1][nv] - vh[j][nv];
333  dvl = VAN_LEER(dvp[nv], dvm[nv]);
334  state.vp[j][nv] = vh[j][nv] + 0.5*dvl;
335  state.vm[j][nv] = vh[j][nv] - 0.5*dvl;
336  dvm[nv] = dvp[nv];
337  }}
338  TC_Flux (T, &state, dcoeff, JBEG - 1, JEND, grid);
339  #endif
340 
341  /* ---------------------------
342  compute inverse time-step
343  --------------------------- */
344 
345  if (g_intStage == 1){
346  inv_dl = GetInverse_dl(grid);
347  JDOM_LOOP(j){
348  C = C_dtp[k][j][i];
349  inv_dl2 = 0.5*inv_dl[j]*inv_dl[j];
350  #if ADD_VISCOSITY
351  C[MX1] += (dcoeff[j-1][MX1] + dcoeff[j][MX1])*inv_dl2;
352  #endif
353  #if ADD_RESISTIVITY
354  EXPAND(C[BX1] += (dcoeff[j-1][BX1] + dcoeff[j][BX1])*inv_dl2; ,
355  C[BX2] += (dcoeff[j-1][BX2] + dcoeff[j][BX2])*inv_dl2; ,
356  C[BX3] += (dcoeff[j-1][BX3] + dcoeff[j][BX3])*inv_dl2;)
357  #endif
358  #if ADD_TC
359  C[ENG] += (dcoeff[j-1][ENG] + dcoeff[j][ENG])*inv_dl2;
360 
361  inv_dtp = dcoeff[j][ENG]*inv_dl[j]*inv_dl[j];
362  max_inv_dtp[g_dir] = MAX(max_inv_dtp[g_dir], inv_dtp);
363  #endif
364  }
365  }
366 
367  /* ---------------------------
368  Main X2-sweep
369  --------------------------- */
370 
371  r = grid[IDIR].x[i];
372  JDOM_LOOP (j){
373 
374  du = dU[k][j][i];
375  dtdV = dt/grid[JDIR].dV[j];
376  dtdl = dt/grid[JDIR].dx[j];
377 
378  #if GEOMETRY == POLAR || GEOMETRY == SPHERICAL
379  dtdl /= r;
380  dtdV /= r;
381  #endif
382 
383  /* ------------------------------------------
384  VISCOSITY: build rhs in the x2 direction
385  ------------------------------------------ */
386 
387  #if ADD_VISCOSITY
388  s_1 = 1.0/sin(grid[JDIR].x[j]);
389  #if GEOMETRY != SPHERICAL
390  EXPAND(du[MX1] += (ViF[j][MX1] - ViF[j-1][MX1])*dtdl + dt*ViS[j][MX1];,
391  du[MX2] += (ViF[j][MX2] - ViF[j-1][MX2])*dtdl + dt*ViS[j][MX2];,
392  du[MX3] += (ViF[j][MX3] - ViF[j-1][MX3])*dtdl + dt*ViS[j][MX3];)
393  #if HAVE_ENERGY
394  du[ENG] += (ViF[j][ENG] - ViF[j-1][ENG])*dtdl;
395  #endif
396  #elif GEOMETRY == SPHERICAL
397  EXPAND(du[MX1] += (A[j]*ViF[j][MX1] - A[j-1]*ViF[j-1][MX1])*dtdV
398  + dt*ViS[j][MX1];,
399  du[MX2] += (A[j]*ViF[j][MX2] - A[j-1]*ViF[j-1][MX2])*dtdV
400  + dt*ViS[j][MX2];,
401  du[MX3] += (A[j]*A[j]*ViF[j][MX3] - A[j-1]*A[j-1]*ViF[j-1][MX3])*s_1*dtdV;)
402  #if HAVE_ENERGY
403  du[ENG] += (A[j]*ViF[j][ENG] - A[j-1]*ViF[j-1][ENG])*dtdV;
404  #endif
405  #endif
406  #endif/* -- VISCOSITY -- */
407 
408  /* ----------------------------------------------
409  RESISTIVITY: build rhs in the x2 direction
410  ---------------------------------------------- */
411 
412  #if ADD_RESISTIVITY
413  #if GEOMETRY != SPHERICAL /* -- y coordinate -- */
414  EXPAND(
415  du[BX1] -= (res_flx[j][BX1] - res_flx[j-1][BX1])*dtdl; ,
416  ,
417  du[BX3] -= (res_flx[j][BX3] - res_flx[j-1][BX3])*dtdl; )
418  #if HAVE_ENERGY
419  du[ENG] -= (res_flx[j][ENG] - res_flx[j-1][ENG])*dtdl;
420  #endif
421  #elif GEOMETRY == SPHERICAL /* -- theta coordinate -- */
422  EXPAND(
423  du[BX1] -= (A[j]*res_flx[j][BX1] - A[j-1]*res_flx[j-1][BX1])*dtdV; ,
424  ,
425  du[BX3] -= (res_flx[j][BX3] - res_flx[j-1][BX3])*dtdl;)
426  #if HAVE_ENERGY
427  du[ENG] -= (A[j]*res_flx[j][ENG] - A[j-1]*res_flx[j-1][ENG])*dtdV;
428  #endif
429  #endif
430  #endif /* -- RESISTIVE MHD -- */
431 
432  /* ---------------------------------------------------
433  THERMAL_CONDUCTION: build rhs in the x2 direction
434  --------------------------------------------------- */
435 
436  #if ADD_TC
437  #if GEOMETRY != SPHERICAL
438  du[ENG] += (tc_flx[j][ENG] - tc_flx[j-1][ENG])*dtdl;
439  #else
440  du[ENG] += (A[j]*tc_flx[j][ENG] - A[j-1]*tc_flx[j-1][ENG])*dtdV;
441  #endif
442  #endif
443  }
444 
445  }}
446 #endif
447 
448 /* ----------------------------------------------------------------------
449  L O O P O N X3 D I R E C T I O N ( K D I R )
450  ---------------------------------------------------------------------- */
451 
452 #if DIMENSIONS == 3
453  g_dir = KDIR;
454  A = grid[g_dir].A;
455  #if ADD_RESISTIVITY && !(defined STAGGERED_MHD)
456  GetCurrent(d, g_dir, grid);
457  #endif
458  JDOM_LOOP (j){
459  IDOM_LOOP (i){
460 
461  g_i = i; g_j = j;
462 
463  /* -------------------------------------------------------------------
464  Compute viscous, resistive and thermal cond. fluxes in the x3 dir
465  ------------------------------------------------------------------- */
466 
467  #if ADD_VISCOSITY
468  ViscousFlux (V, ViF, ViS, dcoeff, KBEG-1, KEND, grid);
469  #endif
470  #if ADD_RESISTIVITY
471  ResistiveFlux (V, d->J, res_flx, dcoeff, KBEG - 1, KEND, grid);
472  #endif
473 
474  #if ADD_TC
475  KTOT_LOOP (k) for (nv = NVAR; nv--; ) vh[k][nv] = V[nv][k][j][i];
476 
477  for (nv = NVAR; nv--; ) dvm[nv] = vh[1][nv] - vh[0][nv];
478  for(k=1; k<NX3_TOT-1; k++){
479  for (nv = NVAR; nv--; ) {
480  dvp[nv] = vh[k+1][nv]- vh[k][nv];
481  dvl = VAN_LEER(dvp[nv], dvm[nv]);
482  state.vp[k][nv] = vh[k][nv] + 0.5*dvl;
483  state.vm[k][nv] = vh[k][nv] - 0.5*dvl;
484  dvm[nv] = dvp[nv];
485  }}
486  TC_Flux (T, &state, dcoeff, KBEG - 1, KEND, grid);
487  #endif
488 
489  /* ---------------------------
490  compute inverse time-step
491  --------------------------- */
492 
493  if (g_intStage == 1){
494  inv_dl = GetInverse_dl(grid);
495  KDOM_LOOP(k){
496  C = C_dtp[k][j][i];
497  inv_dl2 = 0.5*inv_dl[k]*inv_dl[k];
498  #if ADD_VISCOSITY
499  C[MX1] += (dcoeff[k-1][MX1] + dcoeff[k][MX1])*inv_dl2;
500  #endif
501  #if ADD_RESISTIVITY
502  EXPAND(C[BX1] += (dcoeff[k-1][BX1] + dcoeff[k][BX1])*inv_dl2; ,
503  C[BX2] += (dcoeff[k-1][BX2] + dcoeff[k][BX2])*inv_dl2; ,
504  C[BX3] += (dcoeff[k-1][BX3] + dcoeff[k][BX3])*inv_dl2;)
505  #endif
506  #if ADD_TC
507  C[ENG] += (dcoeff[k-1][ENG] + dcoeff[k][ENG])*inv_dl2;
508 
509  inv_dtp = dcoeff[k][ENG]*inv_dl[k]*inv_dl[k];
510  max_inv_dtp[g_dir] = MAX(max_inv_dtp[g_dir], inv_dtp);
511 
512  #endif
513  }
514  }
515 
516  /* ---------------------------
517  Main X3-sweep
518  --------------------------- */
519 
520  r = grid[IDIR].x[i];
521  th = grid[JDIR].x[j];
522  KDOM_LOOP (k){
523 
524  du = dU[k][j][i];
525  dtdV = dt/grid[KDIR].dV[k];
526  dtdl = dt/grid[KDIR].dx[k];
527  #if GEOMETRY == SPHERICAL
528  dtdl /= r*sin(th);
529  #endif
530 
531  /* ------------------------------------------
532  VISCOSITY: build rhs in the x3 direction
533  ------------------------------------------ */
534 
535  #if ADD_VISCOSITY
536  du[MX1] += (ViF[k][MX1] - ViF[k-1][MX1])*dtdl + dt*ViS[k][MX1];
537  du[MX2] += (ViF[k][MX2] - ViF[k-1][MX2])*dtdl + dt*ViS[k][MX2];
538  du[MX3] += (ViF[k][MX3] - ViF[k-1][MX3])*dtdl + dt*ViS[k][MX3];
539  #if HAVE_ENERGY
540  du[ENG] += (ViF[k][ENG] - ViF[k-1][ENG])*dtdl;
541  #endif
542  #endif/* -- VISCOSITY -- */
543 
544  /* ----------------------------------------------
545  RESISTIVITY: build rhs in the x3 direction
546  ---------------------------------------------- */
547 
548  #if ADD_RESISTIVITY
549  du[BX1] -= (res_flx[k][BX1] - res_flx[k-1][BX1])*dtdl;
550  du[BX2] -= (res_flx[k][BX2] - res_flx[k-1][BX2])*dtdl;
551  #if HAVE_ENERGY
552  du[ENG] -= (res_flx[k][ENG] - res_flx[k-1][ENG])*dtdl;
553  #endif
554  #endif /* -- RESISTIVITY -- */
555 
556  /* ---------------------------------------------------
557  THERMAL_CONDUCTION: build rhs in the x3 direction
558  --------------------------------------------------- */
559 
560  #if ADD_TC
561  du[ENG] += (tc_flx[k][ENG] - tc_flx[k-1][ENG])*dtdl;
562  #endif
563  }
564  }}
565 #endif
566 
567 /* OLD VERSION
568 D_EXPAND(th = max_inv_dtp[IDIR]; ,
569  th = MAX(th, max_inv_dtp[JDIR]); ,
570  th = MAX(th, max_inv_dtp[KDIR]);)
571 return th;
572 */
573 
574 /* --------------------------------------------------------------
575  take the maximum of inverse dt over domain and zero
576  right hand side in the internal boundary zones.
577  -------------------------------------------------------------- */
578 
579  th = 0.0;
580  DOM_LOOP(k,j,i){
581  #if ADD_VISCOSITY
582  th = MAX(th, C_dtp[k][j][i][MX1]);
583  #endif
584  #if ADD_RESISTIVITY
585  EXPAND(th = MAX(th, C_dtp[k][j][i][BX1]); ,
586  th = MAX(th, C_dtp[k][j][i][BX2]); ,
587  th = MAX(th, C_dtp[k][j][i][BX3]);)
588  #endif
589  #if ADD_TC
590  th = MAX(th, C_dtp[k][j][i][ENG]);
591  #endif
592  #if INTERNAL_BOUNDARY == YES
593  if (d->flag[k][j][i] & FLAG_INTERNAL_BOUNDARY) {
594  for (nv = NVAR; nv--; ) dU[k][j][i][nv] = 0.0;
595  }
596  #endif
597  }
598  return th;
599 }
#define FLAG_INTERNAL_BOUNDARY
Zone belongs to an internal boundary region and should be excluded from being updated in time...
Definition: pluto.h:184
#define MX3
Definition: mod_defs.h:22
#define EOS
Definition: pluto.h:341
#define MAX(a, b)
Definition: macros.h:101
tuple T
Definition: Sph_disk.py:33
#define KDOM_LOOP(k)
Definition: macros.h:36
void ViscousFlux(Data_Arr, double **, double **, double **, int, int, Grid *)
Definition: viscous_flux.c:14
#define MX1
Definition: mod_defs.h:20
double **** Data_Arr
Definition: pluto.h:492
DOM_LOOP(k, j, i)
Definition: analysis.c:22
double **** J
Electric current defined as curl(B).
Definition: structs.h:54
void GetCurrent(const Data *d, int dir, Grid *grid)
Definition: res_functions.c:97
void TC_Flux(double ***, const State_1D *, double **, int, int, Grid *)
Definition: tc_flux.c:57
double * xr
Definition: structs.h:81
#define RHO
Definition: mod_defs.h:19
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
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 * GetInverse_dl(const Grid *)
Definition: set_geometry.c:205
double * dV
Cell volume.
Definition: structs.h:86
#define VAN_LEER(a, b)
Definition: macros.h:113
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
double * dx
Definition: structs.h:83
#define KDIR
Definition: pluto.h:195
unsigned char *** flag
Pointer to a 3D array setting useful integration flags that are retrieved during integration.
Definition: structs.h:55
void MakeState(State_1D *)
Definition: tools.c:51
#define JDOM_LOOP(j)
Definition: macros.h:35
double ** vp
prim vars at i+1/2 edge, vp[i] = vL(i+1/2)
Definition: structs.h:142
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
Definition: globals.h:82
#define TOT_LOOP(k, j, i)
Definition: macros.h:44
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int j
Definition: analysis.c:2
#define MX2
Definition: mod_defs.h:21
#define ARRAY_4D(nx, ny, nz, nv, type)
Definition: prototypes.h:173
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
double * x
Definition: structs.h:80
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
#define ISOTHERMAL
Definition: pluto.h:49
double * r_1
Geometrical factor 1/r.
Definition: structs.h:88
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
Definition: structs.h:141
#define BX3
Definition: mod_defs.h:27
#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
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
#define BX1
Definition: mod_defs.h:25
#define ADD_TC
Definition: parabolic_rhs.c:46
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define BX2
Definition: mod_defs.h:26
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
#define JDIR
Definition: pluto.h:194
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
void ResistiveFlux(Data_Arr V, Data_Arr curlB, double **res_flux, double **dcoeff, int beg, int end, Grid *grid)
Definition: res_flux.c:52
#define NVAR
Definition: pluto.h:609
#define IDOM_LOOP(i)
Definition: macros.h:34
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
double * A
Right interface area, A[i] = .
Definition: structs.h:87
#define HAVE_ENERGY
Definition: pluto.h:395

Here is the call graph for this function:

Here is the caller graph for this function:

int ParamExist ( const char *  label)

Check whether *label exists in any of the lines (**fline).

Parameters
[in]label
Returns
0 on success, 1 if label cannot be found.

Definition at line 159 of file parse_file.c.

166 {
167  int k;
168  char sline[512], *str;
169  const char delimiters[] = " \t\r\f";
170 
171 /* ---------------------------------------
172  search if label exists
173  --------------------------------------- */
174 
175  for (k = 0; k < nlines; k++) {
176  sprintf (sline,"%s",fline[k]);
177  str = strtok(sline,delimiters);
178  if (strcmp(str,label) == 0) return(1);
179  }
180 
181  return (0);
182 }
static char ** fline
All of the lines (including empty ones) in the file.
Definition: parse_file.c:49
static int nlines
The total number of lines (including empty ones) contained in the file.
Definition: parse_file.c:47
int k
Definition: analysis.c:2

Here is the caller graph for this function:

char* ParamFileGet ( const char *  label,
int  pos 
)

Search for *label in all the lines pointed to by **fline. If label exists, return a pointer to the string located pos words after label. Issue an error if this string cannot be located.

Parameters
[in]labelthe first word of a line to be searched
[in]posan integer giving the position of the word
Returns
the n-th word contained in the same line

Definition at line 86 of file parse_file.c.

97 {
98  int k, nwords, nw;
99  static char **words;
100 
101 /* -------------------------------------------------------------
102  Allocate memory and initialize words[][] string array with
103  to avoid unpleasant situations occurring when there're
104  empty words.
105  ------------------------------------------------------------- */
106 
107  if (words == NULL) words = ARRAY_2D(128,128,char);
108  for (k = 0; k < 127; k++) sprintf (words[k],"\0");
109 
110  for (k = 0; k < nlines; k++) { /* Loop over lines */
111  nwords = ParamFileGetWords(fline[k],words); /* get words for k-th line */
112 
113  if (nwords > 0 && strcmp(words[0],label) == 0){ /* check if 1st word */
114  if (pos <= nwords) return words[pos]; /* matches label */
115  else {
116  printf ("! ParamFileGet: field # %d does not exist\n",pos);
117  QUIT_PLUTO(1);
118  }
119  }
120  }
121 
122  printf ("! ParamFileGet: label '%s' was not found\n",label);
123  QUIT_PLUTO(1);
124 
125  return NULL;
126 }
static int ParamFileGetWords(char *line, char **)
Definition: parse_file.c:185
static char ** fline
All of the lines (including empty ones) in the file.
Definition: parse_file.c:49
static int nlines
The total number of lines (including empty ones) contained in the file.
Definition: parse_file.c:47
int k
Definition: analysis.c:2
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

Here is the caller graph for this function:

int ParamFileHasBoth ( const char *  label1,
const char *  label2 
)

Locate the line beginning with label1 and return 1 if label2 can be found on the same line. Return 0 otherwise.

Parameters
[in]label1The first word of the line to be searched
[in]label2A word containined in the same line beginning with label1
Returns
1 If label2 and label1 are in the same line. 0 otherwise.

Definition at line 129 of file parse_file.c.

139 {
140  int k, nwords, nw;
141  static char **words;
142 
143  if (words == NULL) words = ARRAY_2D(128,128,char);
144 
145  for (k = 0; k < nlines; k++) { /* Loop over lines */
146  nwords = ParamFileGetWords(fline[k],words); /* get words for k-th line */
147  if (strcmp(words[0],label1) == 0){
148  for (nw = 1; nw < nwords; nw++){
149  if (words[nw][0] == '#') break; /* comment detected:
150  no need to read any further */
151  if (strcmp(words[nw], label2) == 0) return 1;
152  }
153  }
154  }
155  return 0;
156 }
static int ParamFileGetWords(char *line, char **)
Definition: parse_file.c:185
static char ** fline
All of the lines (including empty ones) in the file.
Definition: parse_file.c:49
static int nlines
The total number of lines (including empty ones) contained in the file.
Definition: parse_file.c:47
int k
Definition: analysis.c:2
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171

Here is the call graph for this function:

Here is the caller graph for this function:

int ParamFileRead ( char *  fname)

Parse file *fname and store its content line by line in *fline. Blank lines are excluded.

Parameters
[in]fnamethe name of the file to be read
Returns
the number of liens successfully read.

Definition at line 53 of file parse_file.c.

61 {
62  char sline[512];
63  FILE *fp;
64 
65  if (fline == NULL) fline = ARRAY_2D(128,128,char);
66 
67  fp = fopen(fname,"r");
68  if (fp == NULL) {
69  printf ("! ParamFileRead: file %s not found\n", fname);
70  QUIT_PLUTO(1);
71  }
72  nlines = 0;
73 
74  while ( fgets(sline, 512, fp) != NULL ) {
75  if (strlen(sline) > 0) {
76  strcpy (fline[nlines],sline);
77  nlines++;
78  }
79  }
80  fclose(fp);
81 
82  return(nlines);
83 }
static char ** fline
All of the lines (including empty ones) in the file.
Definition: parse_file.c:49
static int nlines
The total number of lines (including empty ones) contained in the file.
Definition: parse_file.c:47
FILE * fp
Definition: analysis.c:7
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the caller graph for this function:

void ParseCmdLineArgs ( int  argc,
char *  argv[],
char *  ini_file,
Cmd_Line cmd 
)

Parse command line options. Error messages will be output to stdout.

Parameters
[in]argcargument count
[in]argvargument vector
[in]ini_filea pointer to a string containing the name of the initialization file (default: "pluto.ini")
[out]cmdthe command-line structure.

Definition at line 18 of file cmd_line_opt.c.

32 {
33  int i,j;
34 
35 /* -----------------------------------------------
36  Set default values first
37  ----------------------------------------------- */
38 
39  cmd->restart = NO;
40  cmd->h5restart = NO;
41  cmd->maxsteps = 0 ;
42  cmd->write = YES;
43  cmd->makegrid = NO;
44  cmd->jet = -1; /* -- means no direction -- */
45  cmd->show_dec = NO;
46  cmd->xres = -1; /* -- means no grid resizing -- */
47 
48  cmd->nproc[IDIR] = -1; /* means autodecomp will be used */
49  cmd->nproc[JDIR] = -1;
50  cmd->nproc[KDIR] = -1;
51 
52  #ifdef PARALLEL
53  cmd->parallel_dim[IDIR] = YES; /* by default, we parallelize */
54  cmd->parallel_dim[JDIR] = YES; /* all directions */
55  cmd->parallel_dim[KDIR] = YES;
56  #endif
57 
58 /* --------------------------------------------------------------------
59  Parse Command Line Options.
60 
61  Note: Since at this time the output directory is now known and
62  "pluto.log" has not been opened yet, we use printf to issue
63  error messages.
64  -------------------------------------------------------------------- */
65 
66  for (i = 1; i < argc ; i++){
67 
68  if (!strcmp(argv[i],"-dec")) {
69 
70  /* -- start reading integers at i+1 -- */
71 
72  for (g_dir = 0; g_dir < DIMENSIONS; g_dir++){
73 
74  if ((++i) >= argc){
75  if (prank == 0){
76  D_SELECT(printf ("! You must specify -dec n1\n"); ,
77  printf ("! You must specify -dec n1 n2\n"); ,
78  printf ("! You must specify -dec n1 n2 n3\n");)
79  }
80  QUIT_PLUTO(1);
81  }
82  cmd->nproc[g_dir] = atoi(argv[i]);
83  if (cmd->nproc[g_dir] == 0){
84  if (prank == 0) {
85  printf ("! Incorrect number of processor for g_dir = %d \n", g_dir);
86  }
87  QUIT_PLUTO(0);
88  }
89  }
90 
91  }else if (!strcmp(argv[i],"-i")) {
92 
93  sprintf (ini_file,"%s",argv[++i]);
94 
95  } else if (!strcmp(argv[i],"-makegrid")) {
96 
97  cmd->makegrid = YES;
98 
99  }else if (!strcmp(argv[i],"-maxsteps")){
100 
101  if ((++i) >= argc){
102  if (prank == 0) printf ("! You must specify -maxsteps nn\n");
103  QUIT_PLUTO(1);
104  }else{
105  cmd->maxsteps = atoi(argv[i]);
106  if (cmd->maxsteps == 0) {
107  if (prank == 0)
108  printf ("! You must specify -maxsteps nn, with nn > 0 \n");
109  QUIT_PLUTO(0);
110  }
111  }
112 
113  }else if (!strcmp(argv[i],"-no-write")) {
114 
115  cmd->write = NO;
116 
117  }else if (!strcmp(argv[i],"-no-x1par")) {
118 
119  cmd->parallel_dim[IDIR] = NO;
120 
121  }else if (!strcmp(argv[i],"-no-x2par")) {
122 
123  cmd->parallel_dim[JDIR] = NO;
124 
125  }else if (!strcmp(argv[i],"-no-x3par")) {
126 
127  cmd->parallel_dim[KDIR] = NO;
128 
129  } else if (!strcmp(argv[i],"-show-dec")) {
130 
131  cmd->show_dec = YES;
132 
133  } else if (!strcmp(argv[i],"-x1jet")) {
134 
135  cmd->jet = IDIR;
136 
137  } else if (!strcmp(argv[i],"-x2jet")) {
138 
139  cmd->jet = JDIR;
140 
141  } else if (!strcmp(argv[i],"-x3jet")) {
142 
143  cmd->jet = KDIR;
144 
145  }else if (!strcmp(argv[i],"-xres")){
146 
147  if ((++i) >= argc){
148  if (prank == 0) printf ("! You must specify -xres nn\n");
149  QUIT_PLUTO(1);
150  }else{
151  cmd->xres = atoi(argv[i]);
152  if (cmd->xres <= 1) {
153  if (prank == 0) printf ("! You must specify -xres nn, with nn > 1 \n");
154  QUIT_PLUTO(0)
155  }
156  }
157 
158  }else if (!strcmp(argv[i],"-restart") || !strcmp(argv[i],"-h5restart")) {
159 
160  /* ---------------------------------------------
161  default restart is last written file (-1)
162  --------------------------------------------- */
163 
164  if (!strcmp(argv[i], "-restart")) cmd->restart = YES; /* can only take YES/NO values */
165  else cmd->h5restart = YES;
166  cmd->nrestart = -1; /* the file number to restart from */
167 
168  if ((++i) < argc){
169  char *endptr;
170 /* cmd->restart = atoi(argv[i]); */
171  cmd->nrestart = (int)strtol(argv[i], &endptr, 10);
172 
173  /* ----------------------------------------------
174  if a non-numerical character is encountered,
175  cmd->nrestart should reset to -1
176  ---------------------------------------------- */
177 
178  if (endptr == argv[i]){
179  i--;
180  cmd->nrestart = -1;
181  }
182  }
183 
184  }else if (!strcmp(argv[i],"--help")){
185 
186  PrintUsage();
187  QUIT_PLUTO(1);
188 
189  }else{
190  if (prank == 0) printf ("! Unknown option '%s'\n",argv[i]);
191  QUIT_PLUTO(1);
192  }
193  }
194 
195 /* -- disable domain decomposition in the
196  direction specified by -xnjet -- */
197 
198  if (cmd->jet == IDIR) cmd->parallel_dim[IDIR] = NO;
199  else if (cmd->jet == JDIR) cmd->parallel_dim[JDIR] = NO;
200  else if (cmd->jet == KDIR) cmd->parallel_dim[KDIR] = NO;
201 
202 }
int write
Definition: structs.h:16
int parallel_dim[3]
Definition: structs.h:19
int nrestart
Definition: structs.h:14
static void PrintUsage()
Definition: cmd_line_opt.c:204
#define YES
Definition: pluto.h:25
int xres
Definition: structs.h:22
int nproc[3]
Definition: structs.h:20
int h5restart
Definition: structs.h:13
int prank
Processor rank.
Definition: globals.h:33
#define KDIR
Definition: pluto.h:195
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int show_dec
Definition: structs.h:21
int j
Definition: analysis.c:2
int jet
Definition: structs.h:18
int maxsteps
Definition: structs.h:17
int i
Definition: analysis.c:2
int makegrid
Definition: structs.h:15
#define JDIR
Definition: pluto.h:194
int restart
Definition: structs.h:12
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define DIMENSIONS
Definition: definitions_01.h:2
#define NO
Definition: pluto.h:26

Here is the call graph for this function:

Here is the caller graph for this function:

void PeriodicBound ( double ***  q,
int  side,
int  vpos 
)

Implements periodic boundary conditions in serial mode.

Definition at line 568 of file boundary.c.

573 {
574  int i, j, k;
575  RBox *box = GetRBox(side, vpos);
576 
577  if (side == X1_BEG){
578 
579  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k][j][i + NX1];
580 
581  }else if (side == X1_END){
582 
583  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k][j][i - NX1];
584 
585  }else if (side == X2_BEG){
586 
587  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k][j + NX2][i];
588 
589  }else if (side == X2_END){
590 
591  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k][j - NX2][i];
592 
593  }else if (side == X3_BEG){
594 
595  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k + NX3][j][i];
596 
597  }else if (side == X3_END){
598 
599  BOX_LOOP(box,k,j,i) q[k][j][i] = q[k - NX3][j][i];
600 
601  }
602 }
#define X3_BEG
Boundary region at X3 beg.
Definition: pluto.h:150
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
RBox * GetRBox(int, int)
Definition: rbox.c:232
long int NX1
Number of interior zones in the X1 directions (boundaries excluded) for the local processor...
Definition: globals.h:48
#define BOX_LOOP(B, k, j, i)
Definition: macros.h:70
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
long int NX2
Number of interior zones in the X2 directions (boundaries excluded) for the local processor...
Definition: globals.h:50
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
int j
Definition: analysis.c:2
if(divB==NULL)
Definition: analysis.c:10
int k
Definition: analysis.c:2
#define X3_END
Boundary region at X3 end.
Definition: pluto.h:151
int i
Definition: analysis.c:2
#define X2_BEG
Boundary region at X2 beg.
Definition: pluto.h:148
Definition: structs.h:346
static Runtime q
long int NX3
Number of interior zones in the X3 directions (boundaries excluded) for the local processor...
Definition: globals.h:52

Here is the call graph for this function:

Here is the caller graph for this function:

void PlutoError ( int  condition,
char *  str 
)

If condition is true, issue an error and quit the code.

Definition at line 115 of file tools.c.

120 {
121  char *str_err="! Error: ";
122 
123  if (condition) {
124  print (str_err);
125  print (str);
126  print ("\n");
127  QUIT_PLUTO(1);
128  }
129 }
void print(const char *fmt,...)
Definition: tools.c:367
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

Here is the caller graph for this function:

void PrimToChar ( double **  Lp,
double *  v,
double *  w 
)

Compute the matrix-vector multiplcation between the the L matrix (containing primitive left eigenvectors) and the vector v. The result containing the characteristic variables is stored in the vector w = L.v

For efficiency purpose, multiplication is done explicitly, so that only nonzero entries of the left primitive eigenvectors are considered.

Parameters
[in]LLeft eigenvectors
[in]v(difference of) primitive variables
[out]w(difference of) characteristic variables

Compute the matrix-vector multiplcation between the the L matrix (containing primitive left eigenvectors) and the vector v. The result containing the characteristic variables is stored in the vector w = L.v

For efficiency purpose, multiplication is done explicitly, so that only nonzero entries of the left primitive eigenvectors are considered.

Parameters
[in]LpLeft eigenvectors
[in]v(difference of) primitive variables
[out]w(difference of) characteristic variables

Definition at line 593 of file eigenv.c.

609 {
610  int nv;
611 
612  #if HAVE_ENERGY
613  w[0] = L[0][VXn]*v[VXn] + L[0][PRS]*v[PRS];
614  w[1] = L[1][VXn]*v[VXn] + L[1][PRS]*v[PRS];
615  EXPAND( w[2] = v[RHO] + L[2][PRS]*v[PRS]; ,
616  w[3] = v[VXt]; ,
617  w[4] = v[VXb];)
618  #elif EOS == ISOTHERMAL
619  w[0] = L[0][RHO]*v[RHO] + L[0][VXn]*v[VXn];
620  w[1] = L[1][RHO]*v[RHO] + L[1][VXn]*v[VXn];
621  EXPAND( ,
622  w[2] = v[VXt]; ,
623  w[3] = v[VXb];)
624  #endif
625 
626 /* -----------------------------------------------
627  For passive scalars, the characteristic
628  variable is equal to the primitive one,
629  since l = r = (0,..., 1 , 0 ,....)
630  ----------------------------------------------- */
631 
632 #if NSCL > 0
633  NSCL_LOOP(nv) w[nv] = v[nv];
634 #endif
635 }
#define EOS
Definition: pluto.h:341
#define NSCL_LOOP(n)
Definition: pluto.h:616
#define RHO
Definition: mod_defs.h:19
int VXb
Definition: globals.h:73
#define NSCL
Definition: pluto.h:572
int VXt
Definition: globals.h:73
int VXn
Definition: globals.h:73
#define ISOTHERMAL
Definition: pluto.h:49

Here is the caller graph for this function:

void PrimToCons3D ( Data_Arr  V,
Data_Arr  U,
RBox box 
)

Convert a 3D array of primitive variables V to an array of conservative variables U. Note that [nv] is the fastest running index for U while it is the slowest running index for V.

Parameters
[in]Vpointer to 3D array of primitive variables, with array indexing [nv][k][j][i]
[out]Upointer to 3D array of conserved variables, with array indexing [k][j][i][nv]
[in]boxpointer to RBox structure containing the domain portion over which conversion must be performed.

Definition at line 86 of file mappers3D.c.

101 {
102  int i, j, k, nv;
103  int ibeg, iend, jbeg, jend, kbeg, kend;
104  int current_dir;
105  static double **v, **u;
106 
107  if (v == NULL) {
108  v = ARRAY_2D(NMAX_POINT, NVAR, double);
109  u = ARRAY_2D(NMAX_POINT, NVAR, double);
110  }
111 
112  current_dir = g_dir; /* save current direction */
113  g_dir = IDIR;
114 
115 /* -----------------------------------------------
116  Set (beg,end) indices in ascending order for
117  proper call to ConsToPrim()
118  ----------------------------------------------- */
119 
120  ibeg = (box->ib <= box->ie) ? (iend=box->ie, box->ib):(iend=box->ib, box->ie);
121  jbeg = (box->jb <= box->je) ? (jend=box->je, box->jb):(jend=box->jb, box->je);
122  kbeg = (box->kb <= box->ke) ? (kend=box->ke, box->kb):(kend=box->kb, box->ke);
123 
124  for (k = kbeg; k <= kend; k++){ g_k = k;
125  for (j = jbeg; j <= jend; j++){ g_j = j;
126  for (i = ibeg; i <= iend; i++) VAR_LOOP(nv) v[i][nv] = V[nv][k][j][i];
127 #ifdef CHOMBO
128  PrimToCons(v, u, ibeg, iend);
129  for (i = ibeg; i <= iend; i++) VAR_LOOP(nv) U[nv][k][j][i] = u[i][nv];
130 #else
131  PrimToCons (v, U[k][j], ibeg, iend);
132 #endif
133  }}
134  g_dir = current_dir; /* restore current direction */
135 
136 }
int jb
Lower corner index in the x2 direction.
Definition: structs.h:349
int kb
Lower corner index in the x3 direction.
Definition: structs.h:351
int ib
Lower corner index in the x1 direction.
Definition: structs.h:347
#define VAR_LOOP(n)
Definition: macros.h:226
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
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 ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define NVAR
Definition: pluto.h:609

Here is the call graph for this function:

Here is the caller graph for this function:

void print ( const char *  fmt,
  ... 
)

Define print function for the static grid version of PLUTO. The Chombo version is defined in Chombo/amrPLUTO.cpp

Definition at line 497 of file amrPluto.cpp.

504 {
505  char buffer[256];
506  va_list args;
507  va_start (args, fmt);
508  vsprintf (buffer,fmt, args);
509  pout() << buffer;
510 }
void print1 ( const char *  fmt,
  ... 
)

Define print1 function

Definition at line 511 of file amrPluto.cpp.

512 {
513  char buffer[256];
514 
515  if (prank != 0) return;
516  va_list args;
517  va_start (args, fmt);
518  vsprintf (buffer,fmt, args);
519  pout() << buffer;
520 }
int prank
Processor rank.
Definition: globals.h:33
void ReadBinaryArray ( void *  V,
size_t  dsize,
int  sz,
FILE *  fl,
int  istag,
int  swap_endian 
)

Read a double-precision array from binary file.

Parameters
[in]Vpointer to a 3D array, V[k][j][i] –> V[i + NX1*j + NX1*NX2*k]. Must start with index 0
[in]dsizethe size of the each buffer element (sizeof(double) or sizeof(float)). This parameter is used only in serial mode.
[in]szthe distributed array descriptor. This parameter replaces dsize in parallel mode
[in]fla valid FILE pointer
[in]istaga flag to identify cell-centered (istag = -1) or staggered field data (istag = 0,1 or 2 for staggering in the x1, x2 or x3 directions)
[in]swap_endiana flag for swapping endianity
Returns
This function has no return value.
Remarks
The data array V is assumed to start always with index 0 for both cell-centered and staggered arrays.

Definition at line 143 of file bin_io.c.

167 {
168  int i, j, k;
169  int ioff, joff, koff;
170  char *Vc;
171 
172 /* ---------------------------------------
173  parallel reading handled by ArrayLib
174  --------------------------------------- */
175 
176  #ifdef PARALLEL
177  AL_Read_array (V, sz, istag);
178  #else
179 
180 /* ---------------------------------------
181  serial reading
182  --------------------------------------- */
183 
184  Vc = (char *) V;
185  ioff = (istag == 0);
186  joff = (istag == 1);
187  koff = (istag == 2);
188 
189  for (k = KBEG; k <= KEND + koff; k++) {
190  for (j = JBEG; j <= JEND + joff; j++) {
191  i = IBEG + (NX1_TOT + ioff)*(j + (NX2_TOT + joff)*k);
192  fread (Vc + i*dsize, dsize, NX1 + ioff, fl);
193  }}
194  #endif
195 
196 /* -----------------------------------
197  now swap endian if necessary
198  ----------------------------------- */
199 
200  if (swap_endian){
201  double *Vd;
202  Vd = (double *) V;
203  ioff = (istag == 0);
204  joff = (istag == 1);
205  koff = (istag == 2);
206 
207  for (k = KBEG-koff; k <= KEND + koff; k++) {
208  for (j = JBEG-joff; j <= JEND + joff; j++) {
209  for (i = IBEG-ioff; i <= IEND + ioff; i++) {
210  SWAP_VAR(Vd[i + (NX1_TOT + ioff)*(j + (NX2_TOT + joff)*k)]);
211  }}}
212  }
213 }
long int NX1
Number of interior zones in the X1 directions (boundaries excluded) for the local processor...
Definition: globals.h:48
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
#define SWAP_VAR(x)
Definition: macros.h:115
int j
Definition: analysis.c:2
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
int i
Definition: analysis.c:2
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
int AL_Read_array(void *va, int sz_ptr, int istag)
Definition: al_io.c:209

Here is the call graph for this function:

Here is the caller graph for this function:

void ReadHDF5 ( Output output,
Grid grid 
)

Read data from disk using hdf5 format (double precision).

Parameters
[in]outputthe output structure associated with HDF5 format
[in]grida pointer to an array of Grid structures
Returns
This function has no return value.

Definition at line 582 of file hdf5_io.c.

591 {
592  hid_t dataspace, memspace, dataset;
593  hid_t file_identifier, group, timestep;
594  hid_t file_access = 0;
595 #if MPI_POSIX == NO
596  hid_t plist_id_mpiio = 0; /* for collective MPI I/O */
597 #endif
598  hid_t err;
599 
600  hsize_t dimens[DIMENSIONS];
601  hsize_t start[DIMENSIONS];
602  hsize_t stride[DIMENSIONS];
603  hsize_t count[DIMENSIONS];
604 
605  char filename[128], tstepname[32];
606  int ierr, rank, nd, nv, ns;
607  Grid *wgrid[3];
608 
609 /* --------------------------------------------------------------
610  Since data is read in reverse order (Z-Y-X) it is
611  convenient to define pointers to grid in reverse order
612  -------------------------------------------------------------- */
613 
614  for (nd = 0; nd < DIMENSIONS; nd++) wgrid[nd] = grid + DIMENSIONS - nd - 1;
615 
616  print1 ("> restarting from file #%d (dbl.h5)\n",output->nfile);
617  sprintf (filename, "%s/data.%04d.dbl.h5", output->dir, output->nfile);
618 
619  rank = DIMENSIONS;
620 
621  #ifdef PARALLEL
622  file_access = H5Pcreate (H5P_FILE_ACCESS);
623  #if MPI_POSIX == YES
624  H5Pset_fapl_mpiposix(file_access, MPI_COMM_WORLD, 1);
625  #else
626  H5Pset_fapl_mpio(file_access, MPI_COMM_WORLD, MPI_INFO_NULL);
627  #endif
628  file_identifier = H5Fopen(filename, H5F_ACC_RDONLY, file_access);
629  H5Pclose(file_access);
630  #else
631  file_identifier = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
632  #endif
633 
634  if (file_identifier < 0){
635  print1 ("! HDF5_READ: file %s does not exist\n");
636  QUIT_PLUTO(1);
637  }
638 
639  sprintf (tstepname, "Timestep_%d", output->nfile);
640  timestep = H5Gopen(file_identifier, tstepname);
641  group = H5Gopen(timestep, "vars");
642 
643  #if MPI_POSIX == NO
644  plist_id_mpiio = H5Pcreate(H5P_DATASET_XFER);
645  H5Pset_dxpl_mpio(plist_id_mpiio,H5FD_MPIO_COLLECTIVE);
646  #endif
647 
648  for (nv = 0; nv < output->nvar; nv++) {
649 
650  /* -- skip variable if excluded from output or if it is staggered -- */
651 
652  if (!output->dump_var[nv] || output->stag_var[nv] != -1) continue;
653 
654  dataset = H5Dopen(group, output->var_name[nv]);
655  dataspace = H5Dget_space(dataset);
656 
657  #ifdef PARALLEL
658  for (nd = 0; nd < DIMENSIONS; nd++) {
659  start[nd] = wgrid[nd]->beg - wgrid[nd]->nghost;
660  stride[nd] = 1;
661  count[nd] = wgrid[nd]->np_int;
662  }
663  err = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, start, stride, count, NULL);
664  #endif
665 
666  for (nd = 0; nd < DIMENSIONS; nd++) dimens[nd] = wgrid[nd]->np_tot;
667 
668  memspace = H5Screate_simple(rank,dimens,NULL);
669 
670  for (nd = 0; nd < DIMENSIONS; nd++){
671  start[nd] = wgrid[nd]->nghost;
672  stride[nd] = 1;
673  count[nd] = wgrid[nd]->np_int;
674  }
675 
676  err = H5Sselect_hyperslab(memspace,H5S_SELECT_SET, start, stride, count, NULL);
677 
678  #if MPI_POSIX == NO
679  err = H5Dread(dataset, H5T_NATIVE_DOUBLE, memspace, dataspace,
680  plist_id_mpiio, output->V[nv][0][0]);
681  #else
682  err = H5Dread(dataset, H5T_NATIVE_DOUBLE, memspace, dataspace,
683  H5P_DEFAULT, output->V[nv][0][0]);
684  #endif
685 
686  H5Dclose(dataset);
687  H5Sclose(memspace);
688  H5Sclose(dataspace);
689  }
690 
691  #if MPI_POSIX == NO
692  H5Pclose(plist_id_mpiio);
693  #endif
694  H5Gclose(group);
695 
696  #ifdef STAGGERED_MHD
697  group = H5Gopen(timestep, "stag_vars");
698 
699  #if MPI_POSIX == NO
700  plist_id_mpiio = H5Pcreate(H5P_DATASET_XFER);
701  H5Pset_dxpl_mpio(plist_id_mpiio,H5FD_MPIO_COLLECTIVE);
702  #endif
703 
704  for (ns = 0; ns < DIMENSIONS; ns++) {
705  dataset = H5Dopen(group, output->var_name[NVAR+ns]);
706  dataspace = H5Dget_space(dataset);
707 
708  #ifdef PARALLEL
709  for (nd = 0; nd < DIMENSIONS; nd++) {
710  start[nd] = wgrid[nd]->beg - wgrid[nd]->nghost;
711  stride[nd] = 1;
712  count[nd] = wgrid[nd]->np_int;
713  if (ns == DIMENSIONS-1-nd){
714  if (grid[ns].lbound != 0) count[nd] += 1;
715  else start[nd] += 1;
716  }
717  }
718  err = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET,
719  start, stride, count, NULL);
720  #endif
721 
722  for (nd = 0; nd < DIMENSIONS; nd++)
723  dimens[nd] = wgrid[nd]->np_tot + (ns == (DIMENSIONS-1-nd));
724 
725  memspace = H5Screate_simple(rank,dimens,NULL);
726 
727  for (nd = 0; nd < DIMENSIONS; nd++){
728  start[nd] = wgrid[nd]->nghost;
729  stride[nd] = 1;
730  count[nd] = wgrid[nd]->np_int;
731  if (ns == DIMENSIONS-1-nd && grid[ns].lbound != 0) {
732  start[nd] -= 1;
733  count[nd] += 1;
734  }
735  }
736 
737  err = H5Sselect_hyperslab(memspace,H5S_SELECT_SET,
738  start, stride, count, NULL);
739  #if MPI_POSIX == NO
740  err = H5Dread(dataset, H5T_NATIVE_DOUBLE, memspace,
741  dataspace, plist_id_mpiio, output->V[NVAR+ns][0][0]);
742  #else
743  err = H5Dread(dataset, H5T_NATIVE_DOUBLE, memspace,
744  dataspace, H5P_DEFAULT, output->V[NVAR+ns][0][0]);
745  #endif
746  H5Dclose(dataset);
747  H5Sclose(memspace);
748  H5Sclose(dataspace);
749  }
750 
751  #if MPI_POSIX == NO
752  H5Pclose(plist_id_mpiio);
753  #endif
754  H5Gclose(group);
755  #endif
756 
757  H5Gclose(timestep);
758  H5Fclose(file_identifier);
759 }
int lbound
When different from zero, it specifies the boundary condition to be applied at leftmost grid side whe...
Definition: structs.h:105
double *** V[64]
pointer to arrays being written - same for all
Definition: structs.h:247
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
int nfile
current number being saved - one per output
Definition: structs.h:237
char dir[256]
output directory name
Definition: structs.h:244
int beg
Global start index for the local array.
Definition: structs.h:115
Definition: structs.h:78
int nghost
Number of ghost zones.
Definition: structs.h:104
int nvar
tot.
Definition: structs.h:234
int * dump_var
select vars being written - one per output
Definition: structs.h:240
int * stag_var
centered or staggered variable - same for all
Definition: structs.h:239
int np_tot
Total number of points in the local domain (boundaries included).
Definition: structs.h:100
#define NVAR
Definition: pluto.h:609
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
char ** var_name
variable names - same for all
Definition: structs.h:242
#define DIMENSIONS
Definition: definitions_01.h:2
int np_int
Total number of points in the local domain (boundaries excluded).
Definition: structs.h:102

Here is the call graph for this function:

Here is the caller graph for this function:

void ReflectiveBound ( double ***  q,
int  s,
int  side,
int  vpos 
)

Make symmetric (s = 1) or anti-symmetric (s=-1) profiles with respect to the boundary plane specified by box->side. The sign is set by the FlipSign() function.

Parameters
[in,out]qa 3D flow quantity
[in]boxpointer to box structure
[in]san integer taking only the values +1 (symmetric profile) or -1 (antisymmetric profile)

Definition at line 501 of file boundary.c.

513 {
514  int i, j, k;
515  RBox *box = GetRBox(side, vpos);
516 
517  if (side == X1_BEG) {
518 
519  if (box->vpos != X1FACE){
520  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[k][j][2*IBEG-i-1];
521  }else{
522  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[k][j][2*IBEG-i-2];
523  }
524 
525  }else if (side == X1_END){
526 
527  if (box->vpos != X1FACE){
528  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[k][j][2*IEND-i+1];
529  }else{
530  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[k][j][2*IEND-i];
531  }
532 
533  }else if (side == X2_BEG){
534 
535  if (box->vpos != X2FACE){
536  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[k][2*JBEG-j-1][i];
537  }else{
538  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[k][2*JBEG-j-2][i];
539  }
540 
541  }else if (side == X2_END){
542 
543  if (box->vpos != X2FACE){
544  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[k][2*JEND-j+1][i];
545  }else{
546  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[k][2*JEND-j][i];
547  }
548  }else if (side == X3_BEG){
549 
550  if (box->vpos != X3FACE){
551  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[2*KBEG-k-1][j][i];
552  }else{
553  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[2*KBEG-k-2][j][i];
554  }
555 
556  }else if (side == X3_END){
557 
558  if (box->vpos != X3FACE){
559  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[2*KEND-k+1][j][i];
560  }else{
561  BOX_LOOP(box,k,j,i) q[k][j][i] = s*q[2*KEND-k][j][i];
562  }
563 
564  }
565 }
#define X3_BEG
Boundary region at X3 beg.
Definition: pluto.h:150
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
RBox * GetRBox(int, int)
Definition: rbox.c:232
int vpos
Location of the variable inside the cell.
Definition: structs.h:359
#define X3FACE
Definition: pluto.h:203
#define BOX_LOOP(B, k, j, i)
Definition: macros.h:70
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
#define X1FACE
Definition: pluto.h:201
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
int j
Definition: analysis.c:2
if(divB==NULL)
Definition: analysis.c:10
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
#define s
#define X3_END
Boundary region at X3 end.
Definition: pluto.h:151
int i
Definition: analysis.c:2
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
#define X2_BEG
Boundary region at X2 beg.
Definition: pluto.h:148
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
Definition: structs.h:346
static Runtime q
#define X2FACE
Definition: pluto.h:202
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35

Here is the call graph for this function:

Here is the caller graph for this function:

void ResetState ( const Data d,
State_1D state,
Grid grid 
)

Initialize some of the elements of the State_1D structure to zero in order to speed up computations. These includes:

  • source term
  • left and right eigenvectors
  • the maximum eigenvalue ???
Parameters
[in]dpointer to Data structure
[out]statepointer to a State_1D structure
[in]gridpointer to an array of Grid structures

Definition at line 163 of file set_indexes.c.

177 {
178  int i, j, k, nv;
179  double v[NVAR], lambda[NVAR];
180  double a;
181 
182  for (i = 0; i < NMAX_POINT; i++){
183  for (j = NVAR; j--; ) state->src[i][j] = 0.0;
184 
185  for (j = NFLX; j--; ){
186  for (k = NFLX; k--; ){
187  state->Lp[i][j][k] = state->Rp[i][j][k] = 0.0;
188  }}
189  }
190 
191 /* ---------------------------------------------------------
192  When using Finite Difference methods, we need to find,
193  for each characteristic k, its maximum over the
194  whole computational domain (LF global splitting).
195  --------------------------------------------------------- */
196 
197  #ifdef FINITE_DIFFERENCE
198  FD_GetMaxEigenvalues (d, state, grid);
199  #endif
200 }
static double a
Definition: init.c:135
void FD_GetMaxEigenvalues(const Data *d, State_1D *state, Grid *grid)
Definition: fd_flux.c:293
double *** Lp
Definition: structs.h:155
double ** src
Definition: structs.h:160
#define NFLX
Definition: mod_defs.h:32
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
int i
Definition: analysis.c:2
double *** Rp
Left and right primitive eigenvectors.
Definition: structs.h:155
#define NVAR
Definition: pluto.h:609

Here is the call graph for this function:

Here is the caller graph for this function:

void RestartDump ( Runtime ini)

Write restart information needed for later restarts.

Definition at line 251 of file restart.c.

256 {
257  int n;
258  char fout[512];
259  Restart restart;
260  FILE *fr;
261 
262 /* --------------------------------------------------
263  Define restart structure elements here
264  -------------------------------------------------- */
265 
266  restart.t = g_time;
267  restart.dt = g_dt;
268  restart.nstep = g_stepNumber;
269  for (n = 0; n < MAX_OUTPUT_TYPES; n++){
270  restart.nfile[n] = ini->output[n].nfile;
271  }
272 
273 /* --------------------------------------------------
274  Dump structure to disk
275  -------------------------------------------------- */
276 
277  counter++;
278  if (prank == 0) {
279  sprintf (fout,"%s/restart.out",ini->output_dir);
280  if (counter == 0) {
281  fr = fopen (fout, "wb");
282  }else {
283  fr = fopen (fout, "r+b");
284  fseek (fr, counter*sizeof(Restart), SEEK_SET);
285  }
286 
287  fwrite (&restart, sizeof(Restart), 1, fr);
288  fclose(fr);
289  }
290 }
double dt
Definition: structs.h:293
static int n
Definition: analysis.c:3
double t
Definition: structs.h:292
Output output[MAX_OUTPUT_TYPES]
Definition: structs.h:272
int nfile
current number being saved - one per output
Definition: structs.h:237
char output_dir[256]
The name of the output directory (output_dir for static PLUTO, Output_dir for PLUTO-Chombo) ...
Definition: structs.h:269
double g_dt
The current integration time step.
Definition: globals.h:118
int prank
Processor rank.
Definition: globals.h:33
long int g_stepNumber
Gives the current integration step number.
Definition: globals.h:97
int nstep
Definition: structs.h:290
static int counter
Definition: restart.c:174
#define MAX_OUTPUT_TYPES
Definition: pluto.h:95
double g_time
The current integration time.
Definition: globals.h:117
int nfile[MAX_OUTPUT_TYPES]
Definition: structs.h:291

Here is the caller graph for this function:

void RestartFromFile ( Runtime ini,
int  nrestart,
int  type,
Grid grid 
)

Read input binary / hdf5 data.

Parameters
[in]ini
[in]nrestart
[in]typespecifies the output data type (type should be either DBL_OUTPUT or DBL_H5_OUTPUT).
[in]gridpointer to an array of Grid structures

Definition at line 17 of file restart.c.

28 {
29  int nv, single_file, origin, nlines=0;
30  int swap_endian=0;
31  char fname[512], fout[512], str[512];
32  double dbl;
33  void *Vpt;
34  Output *output;
35  FILE *fbin;
36 
37 /* ----------------------------------------------------------
38  Get the pointer to the output format specified by "type"
39  ---------------------------------------------------------- */
40 
41  for (nv = 0; nv < MAX_OUTPUT_TYPES; nv++){
42  output = ini->output + nv;
43  if (output->type == type) break;
44  }
45 
46 /* -------------------------------------------------------
47  Compare the endianity of the restart file (by reading
48  the corresponding entry in dbl.out or dbl.h5.out)
49  with that of the current architecture.
50  Turn swap_endian to 1 if they're different.
51  ------------------------------------------------------- */
52 
53  if (prank == 0){
54  if (type == DBL_OUTPUT) {
55  sprintf (fout,"%s/dbl.out",ini->output_dir);
56  fbin = fopen (fout, "r");
57  } else if (type == DBL_H5_OUTPUT) {
58  sprintf (fout,"%s/dbl.h5.out",ini->output_dir);
59  fbin = fopen (fout, "r");
60  }
61  if (fbin == NULL){
62  print1 ("! Restart: cannot find dbl.out or dbl.h5.out\n");
63  QUIT_PLUTO(1);
64  }
65 
66  while (fgets(str, 512, fbin) != 0) nlines++; /* -- count lines in dbl.out -- */
67  rewind(fbin);
68  if (nrestart > nlines-1){
69  printf ("! Restart: position too large\n");
70  QUIT_PLUTO(1);
71  }
72  origin = (nrestart >= 0 ? nrestart:(nlines+nrestart));
73  for (nv = origin; nv--; ) while ( fgetc(fbin) != '\n'){}
74  fscanf(fbin, "%d %lf %lf %d %s %s\n",&nv, &dbl, &dbl, &nv, str, str);
75  if ( (!strcmp(str,"big") && IsLittleEndian()) ||
76  (!strcmp(str,"little") && !IsLittleEndian())) {
77  swap_endian = 1;
78  print1 ("> Restart: endianity is reversed\n");
79  }
80  fclose(fbin);
81  }
82  #ifdef PARALLEL
83  MPI_Bcast (&swap_endian, 1, MPI_INT, 0, MPI_COMM_WORLD);
84  #endif
85 
86 /* ---------------------------------------------
87  Read restart.out and get Restart structure
88  --------------------------------------------- */
89 
90  RestartGet (ini, nrestart, type, swap_endian);
91  if (type == DBL_H5_OUTPUT){
92  #ifdef USE_HDF5
93  ReadHDF5 (output, grid);
94  #endif
95  return;
96  }
97 
98  print1 ("> restarting from file #%d (dbl)\n",output->nfile);
99  single_file = strcmp(output->mode,"single_file") == 0;
100 
101 /* -----------------------------------------------------------------
102  For .dbl output, read data from disk
103  ----------------------------------------------------------------- */
104 
105  if (single_file){
106  int sz;
107  long long offset;
108 
109  sprintf (fname, "%s/data.%04d.dbl", output->dir, output->nfile);
110  offset = 0;
111  #ifndef PARALLEL
112  fbin = OpenBinaryFile (fname, 0, "r");
113  #endif
114  for (nv = 0; nv < output->nvar; nv++) {
115  if (!output->dump_var[nv]) continue;
116 
117  if (output->stag_var[nv] == -1) { /* -- cell-centered data -- */
118  sz = SZ;
119  Vpt = (void *)output->V[nv][0][0];
120  } else if (output->stag_var[nv] == 0) { /* -- x-staggered data -- */
121  sz = SZ_stagx;
122  Vpt = (void *)(output->V[nv][0][0]-1);
123  } else if (output->stag_var[nv] == 1) { /* -- y-staggered data -- */
124  sz = SZ_stagy;
125  Vpt = (void *)output->V[nv][0][-1];
126  } else if (output->stag_var[nv] == 2) { /* -- z-staggered data -- */
127  sz = SZ_stagz;
128  Vpt = (void *)output->V[nv][-1][0];
129  }
130  #ifdef PARALLEL
131  fbin = OpenBinaryFile (fname, sz, "r");
132  AL_Set_offset(sz, offset);
133  #endif
134  ReadBinaryArray (Vpt, sizeof(double), sz, fbin,
135  output->stag_var[nv], swap_endian);
136  #ifdef PARALLEL
137  offset = AL_Get_offset(sz);
138  CloseBinaryFile(fbin, sz);
139  #endif
140  }
141  #ifndef PARALLEL
142  CloseBinaryFile(fbin, sz);
143  #endif
144 
145  }else{
146 
147  int sz;
148  for (nv = 0; nv < output->nvar; nv++) {
149  if (!output->dump_var[nv]) continue;
150  sprintf (fname, "%s/%s.%04d.%s", output->dir, output->var_name[nv],
151  output->nfile, output->ext);
152 
153  if (output->stag_var[nv] == -1) { /* -- cell-centered data -- */
154  sz = SZ;
155  Vpt = (void *)output->V[nv][0][0];
156  } else if (output->stag_var[nv] == 0) { /* -- x-staggered data -- */
157  sz = SZ_stagx;
158  Vpt = (void *)(output->V[nv][0][0]-1);
159  } else if (output->stag_var[nv] == 1) { /* -- y-staggered data -- */
160  sz = SZ_stagy;
161  Vpt = (void *)output->V[nv][0][-1];
162  } else if (output->stag_var[nv] == 2) { /* -- z-staggered data -- */
163  sz = SZ_stagz;
164  Vpt = (void *)output->V[nv][-1][0];
165  }
166  fbin = OpenBinaryFile (fname, sz, "r");
167  ReadBinaryArray (Vpt, sizeof(double), sz, fbin,
168  output->stag_var[nv], swap_endian);
169  CloseBinaryFile (fbin, sz);
170  }
171  }
172 }
void RestartGet(Runtime *ini, int nrestart, int out_type, int swap_endian)
Definition: restart.c:177
void ReadHDF5(Output *output, Grid *grid)
Definition: hdf5_io.c:582
double *** V[64]
pointer to arrays being written - same for all
Definition: structs.h:247
long long AL_Get_offset(int sz_ptr)
Definition: al_io.c:327
Output output[MAX_OUTPUT_TYPES]
Definition: structs.h:272
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
FILE * OpenBinaryFile(char *filename, int sz, char *mode)
Definition: bin_io.c:31
int nfile
current number being saved - one per output
Definition: structs.h:237
char output_dir[256]
The name of the output directory (output_dir for static PLUTO, Output_dir for PLUTO-Chombo) ...
Definition: structs.h:269
int AL_Set_offset(int sz_ptr, long long offset)
Definition: al_io.c:342
char dir[256]
output directory name
Definition: structs.h:244
static int nlines
The total number of lines (including empty ones) contained in the file.
Definition: parse_file.c:47
int prank
Processor rank.
Definition: globals.h:33
int SZ_stagx
Definition: globals.h:24
int SZ_stagy
Definition: globals.h:25
char ext[8]
output extension
Definition: structs.h:243
void ReadBinaryArray(void *V, size_t dsize, int sz, FILE *fl, int istag, int swap_endian)
Definition: bin_io.c:143
struct szz SZ
#define DBL_H5_OUTPUT
Definition: pluto.h:82
int IsLittleEndian(void)
Definition: tools.c:40
int SZ_stagz
Definition: globals.h:26
int nvar
tot.
Definition: structs.h:234
#define MAX_OUTPUT_TYPES
Definition: pluto.h:95
int * dump_var
select vars being written - one per output
Definition: structs.h:240
#define DBL_OUTPUT
Definition: pluto.h:79
char mode[32]
single or multiple files - one per output
Definition: structs.h:241
int type
output format (DBL, FLT, ...) - one per output
Definition: structs.h:233
int * stag_var
centered or staggered variable - same for all
Definition: structs.h:239
int CloseBinaryFile(FILE *fbin, int sz)
Definition: bin_io.c:78
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
char ** var_name
variable names - same for all
Definition: structs.h:242

Here is the call graph for this function:

Here is the caller graph for this function:

void RestartGet ( Runtime ini,
int  nrestart,
int  out_type,
int  swap_endian 
)

Collect restart information needed for (potential) later restarts.

Definition at line 177 of file restart.c.

184 {
185  int origin, n, k;
186  char fout[512];
187  Restart restart;
188  FILE *fr;
189 
190  if (nrestart < 0){
191  printf ("! negative restart file temporarily disabled\n");
192  QUIT_PLUTO(1);
193  }
194 
195 /* -------------------------------------------------
196  Open "restart.out" and scan line by line until
197  the output type specified by "out_type" has
198  nfile = nrestart.
199  counter will contain the line number where this
200  occurs. Processor 0 does the actual reading.
201  ------------------------------------------------- */
202 
203  if (prank == 0) {
204  sprintf (fout,"%s/restart.out",ini->output_dir);
205  fr = fopen (fout, "rb");
206  if (fr == NULL){
207  print1 ("! RestartGet: cannot find restart.out\n");
208  QUIT_PLUTO(1);
209  }
210 
211  origin = (nrestart < 0 ? SEEK_END:SEEK_SET);
212  k = 0;
213  while (counter == -1){
214  if (feof(fr)){
215  print("! RestartGet: end of file encountered.\n");
216  QUIT_PLUTO(1);
217  }
218  fseek (fr, k*sizeof(Restart), origin);
219  fread (&restart, sizeof (Restart), 1, fr);
220  for (n = 0; n < MAX_OUTPUT_TYPES; n++){
221  if (swap_endian) SWAP_VAR(restart.nfile[n]);
222  if (ini->output[n].type == out_type && restart.nfile[n] == nrestart){
223  counter = k;
224  }
225  }
226  k++;
227  }
228  fclose(fr);
229  if (swap_endian){
230  SWAP_VAR(restart.t);
231  SWAP_VAR(restart.dt);
232  SWAP_VAR(restart.nstep);
233  }
234  }
235 
236 /* printf ("counter = %d\n",counter); */
237 
238  #ifdef PARALLEL
239  MPI_Bcast (&restart, sizeof (Restart), MPI_BYTE, 0, MPI_COMM_WORLD);
240  #endif
241 
242  g_time = restart.t;
243  g_dt = restart.dt;
244  g_stepNumber = restart.nstep;
245 
246  for (n = 0; n < MAX_OUTPUT_TYPES; n++){
247  ini->output[n].nfile = restart.nfile[n];
248  }
249 }
double dt
Definition: structs.h:293
static int n
Definition: analysis.c:3
double t
Definition: structs.h:292
Output output[MAX_OUTPUT_TYPES]
Definition: structs.h:272
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
int nfile
current number being saved - one per output
Definition: structs.h:237
char output_dir[256]
The name of the output directory (output_dir for static PLUTO, Output_dir for PLUTO-Chombo) ...
Definition: structs.h:269
double g_dt
The current integration time step.
Definition: globals.h:118
int prank
Processor rank.
Definition: globals.h:33
#define SWAP_VAR(x)
Definition: macros.h:115
long int g_stepNumber
Gives the current integration step number.
Definition: globals.h:97
int nstep
Definition: structs.h:290
static int counter
Definition: restart.c:174
int k
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
#define MAX_OUTPUT_TYPES
Definition: pluto.h:95
double g_time
The current integration time.
Definition: globals.h:117
int type
output format (DBL, FLT, ...) - one per output
Definition: structs.h:233
int nfile[MAX_OUTPUT_TYPES]
Definition: structs.h:291
#define QUIT_PLUTO(e_code)
Definition: macros.h:125

Here is the call graph for this function:

Here is the caller graph for this function:

void RightHandSide ( const State_1D state,
Time_Step Dts,
int  beg,
int  end,
double  dt,
Grid grid 
)
Parameters
[in,out]statepointer to State_1D structure
[in]Dtspointer to time step structure
[in]beginitial index of computation
[in]endfinal index of computation
[in]dttime increment
[in]gridpointer to Grid structure
Returns
This function has no return value.
Note
Todo:

Definition at line 88 of file rhs.c.

103 {
104  int i, j, k, nv;
105  double dtdx, dtdV, scrh, rhog;
106  double *x1 = grid[IDIR].x, *x2 = grid[JDIR].x, *x3 = grid[KDIR].x;
107  double *x1p = grid[IDIR].xr, *x2p = grid[JDIR].xr, *x3p = grid[KDIR].xr;
108  double *dx1 = grid[IDIR].dx, *dx2 = grid[JDIR].dx, *dx3 = grid[KDIR].dx;
109  double *dV1 = grid[IDIR].dV, *dV2 = grid[JDIR].dV, *dV3 = grid[KDIR].dV;
110  double **rhs = state->rhs;
111  double **flux = state->flux, *p = state->press;
112  double **vh = state->vh, **vp = state->vp, **vm = state->vm;
113  double *A = grid[g_dir].A, *dV = grid[g_dir].dV;
114 
115  double cl;
116  double w, wp, vphi, phi_c;
117  double g[3];
118  static double **fA, *phi_p;
119  static double **fvA;
120 #if ENTROPY_SWITCH
121  double rhs_entr;
122  double **visc_flux = state->visc_flux;
123  double **visc_src = state->visc_src;
124  double **tc_flux = state->tc_flux;
125  double **res_flux = state->res_flux;
126  if (fvA == NULL) fvA = ARRAY_2D(NMAX_POINT, NVAR, double);
127 #endif
128 
129  #if GEOMETRY != CARTESIAN
130  if (fA == NULL) fA = ARRAY_2D(NMAX_POINT, NVAR, double);
131  #endif
132  if (phi_p == NULL) phi_p = ARRAY_1D(NMAX_POINT, double);
133 
134 /* --------------------------------------------------
135  1. Compute fluxes for passive scalars and dust
136  -------------------------------------------------- */
137 
138 #if NSCL > 0
139  AdvectFlux (state, beg - 1, end, grid);
140 #endif
141 
142 #if DUST == YES
143  Dust_Solver(state, beg - 1, end, Dts->cmax, grid);
144 #endif
145 
146  i = g_i; /* will be redefined during x1-sweep */
147  j = g_j; /* will be redefined during x2-sweep */
148  k = g_k; /* will be redefined during x3-sweep */
149 
150 /* ------------------------------------------------
151  Add pressure to normal component of
152  momentum flux if necessary.
153  ------------------------------------------------ */
154 
155 #if USE_PR_GRADIENT == NO
156  for (i = beg - 1; i <= end; i++) flux[i][MXn] += p[i];
157 #endif
158 
159 /* -----------------------------------------------------
160  Compute gravitational potential at cell interfaces
161  ----------------------------------------------------- */
162 
163 #if (BODY_FORCE & POTENTIAL)
164  if (g_dir == IDIR) {
165  for (i = beg-1; i <= end; i++) {
166  phi_p[i] = BodyForcePotential(x1p[i], x2[j], x3[k]);
167  }
168  }else if (g_dir == JDIR){
169  for (j = beg-1; j <= end; j++) {
170  phi_p[j] = BodyForcePotential(x1[i], x2p[j], x3[k]);
171  }
172  }else if (g_dir == KDIR){
173  for (k = beg-1; k <= end; k++) {
174  phi_p[k] = BodyForcePotential(x1[i], x2[j], x3p[k]);
175  }
176  }
177 #endif
178 
179 /* -----------------------------------------------------
180  Compute total flux
181  ----------------------------------------------------- */
182 
183  #if (defined FARGO && !defined SHEARINGBOX) ||\
184  (ROTATING_FRAME == YES) || (BODY_FORCE & POTENTIAL)
185  TotalFlux(state, phi_p, beg-1, end, grid);
186  #endif
187 
188 #if GEOMETRY == CARTESIAN
189 
190  if (g_dir == IDIR){
191 
192  for (i = beg; i <= end; i++) {
193  dtdx = dt/dx1[i];
194 
195  /* -- I1. initialize rhs with flux difference -- */
196 
197  NVAR_LOOP(nv) rhs[i][nv] = -dtdx*(flux[i][nv] - flux[i-1][nv]);
198  #if USE_PR_GRADIENT == YES
199  rhs[i][MX1] -= dtdx*(p[i] - p[i-1]);
200  #endif
201 
202  /* -- I5. Add dissipative terms to entropy equation -- */
203 
204  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
205  rhog = vh[i][RHO];
206  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
207 
208  rhs_entr = 0.0;
209  #if VISCOSITY == EXPLICIT
210  rhs_entr += (visc_flux[i][ENG] - visc_flux[i-1][ENG]);
211  rhs_entr -= EXPAND( vh[i][VX1]*(visc_flux[i][MX1] - visc_flux[i-1][MX1]) ,
212  + vh[i][VX2]*(visc_flux[i][MX2] - visc_flux[i-1][MX2]) ,
213  + vh[i][VX3]*(visc_flux[i][MX3] - visc_flux[i-1][MX3]));
214  #endif
215 
216  #if THERMAL_CONDUCTION == EXPLICIT
217  rhs_entr += (tc_flux[i][ENG] - tc_flux[i-1][ENG]);
218  #endif
219  rhs[i][ENTR] += rhs_entr*dtdx*rhog;
220  #endif
221 
222  }
223  } else if (g_dir == JDIR){
224 
225  for (j = beg; j <= end; j++) {
226  dtdx = dt/dx2[j];
227 
228  /* -- J1. initialize rhs with flux difference -- */
229 
230  NVAR_LOOP(nv) rhs[j][nv] = -dtdx*(flux[j][nv] - flux[j-1][nv]);
231  #if USE_PR_GRADIENT == YES
232  rhs[j][MX2] -= dtdx*(p[j] - p[j-1]);
233  #endif
234 
235  /* -- J5. Add dissipative terms to entropy equation -- */
236 
237  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
238  rhog = vh[j][RHO];
239  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
240 
241  rhs_entr = 0.0;
242  #if VISCOSITY == EXPLICIT
243  rhs_entr += (visc_flux[j][ENG] - visc_flux[j-1][ENG]);
244  rhs_entr -= EXPAND( vh[j][VX1]*(visc_flux[j][MX1] - visc_flux[j-1][MX1]) ,
245  + vh[j][VX2]*(visc_flux[j][MX2] - visc_flux[j-1][MX2]) ,
246  + vh[j][VX3]*(visc_flux[j][MX3] - visc_flux[j-1][MX3]));
247  #endif
248 
249  #if THERMAL_CONDUCTION == EXPLICIT
250  rhs_entr += (tc_flux[j][ENG] - tc_flux[j-1][ENG]);
251  #endif
252  rhs[j][ENTR] += rhs_entr*dtdx*rhog;
253  #endif
254 
255  }
256 
257  }else if (g_dir == KDIR){
258 
259  for (k = beg; k <= end; k++) {
260  dtdx = dt/dx3[k];
261 
262  /* -- K1. initialize rhs with flux difference -- */
263 
264  NVAR_LOOP(nv) rhs[k][nv] = -dtdx*(flux[k][nv] - flux[k-1][nv]);
265  #if USE_PR_GRADIENT == YES
266  rhs[k][MX3] -= dtdx*(p[k] - p[k-1]);
267  #endif
268 
269  /* -- K5. Add dissipative terms to entropy equation -- */
270 
271  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
272  rhog = vh[k][RHO];
273  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
274  rhs_entr = 0.0;
275  #if VISCOSITY == EXPLICIT
276  rhs_entr += (visc_flux[k][ENG] - visc_flux[k-1][ENG]);
277  rhs_entr -= EXPAND( vh[k][VX1]*(visc_flux[k][MX1] - visc_flux[k-1][MX1]) ,
278  + vh[k][VX2]*(visc_flux[k][MX2] - visc_flux[k-1][MX2]) ,
279  + vh[k][VX3]*(visc_flux[k][MX3] - visc_flux[k-1][MX3]));
280  #endif
281 
282  #if THERMAL_CONDUCTION == EXPLICIT
283  rhs_entr += (tc_flux[k][ENG] - tc_flux[k-1][ENG]);
284  #endif
285  rhs[k][ENTR] += rhs_entr*dtdx*rhog;
286  #endif
287  }
288  }
289 
290 #elif GEOMETRY == CYLINDRICAL
291 
292 {
293  double R, z, phi, R_1;
294 
295 #if DUST == YES
296  #error "DUST not implemented in CYLINDRICAL coordinates"
297 #endif
298 
299  if (g_dir == IDIR) {
300  double vc[NVAR];
301 
302  GetAreaFlux (state, fA, fvA, beg, end, grid);
303  for (i = beg; i <= end; i++){
304  R = x1[i];
305  dtdV = dt/dV1[i];
306  dtdx = dt/dx1[i];
307  R_1 = 1.0/R;
308 
309  /* -- I1. initialize rhs with flux difference -- */
310 
311  rhs[i][RHO] = -dtdV*(fA[i][RHO] - fA[i-1][RHO]);
312  EXPAND(rhs[i][iMR] = - dtdV*(fA[i][iMR] - fA[i-1][iMR]); ,
313  rhs[i][iMZ] = - dtdV*(fA[i][iMZ] - fA[i-1][iMZ]); ,
314  rhs[i][iMPHI] = - dtdV*(fA[i][iMPHI] - fA[i-1][iMPHI])*fabs(R_1);)
315  #if USE_PR_GRADIENT == YES
316  rhs[i][iMR] -= dtdx*(p[i] - p[i-1]);
317  #endif
318  #if PHYSICS == MHD
319  EXPAND(rhs[i][iBR] = - dtdV*(fA[i][iBR] - fA[i-1][iBR]); ,
320  rhs[i][iBZ] = - dtdV*(fA[i][iBZ] - fA[i-1][iBZ]); ,
321  rhs[i][iBPHI] = - dtdx*(flux[i][iBPHI] - flux[i-1][iBPHI]);)
322  #ifdef GLM_MHD
323  rhs[i][iBR] = - dtdx*(flux[i][iBR] - flux[i-1][iBR]);
324  rhs[i][PSI_GLM] = - dtdV*(fA[i][PSI_GLM] - fA[i-1][PSI_GLM]);
325  #endif
326  #endif
327  IF_ENERGY(rhs[i][ENG] = -dtdV*(fA[i][ENG] - fA[i-1][ENG]);)
328  NSCL_LOOP(nv) rhs[i][nv] = -dtdV*(fA[i][nv] - fA[i-1][nv]);
329 
330  /* -- I5. Add dissipative terms to entropy equation -- */
331 
332  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
333  NVAR_LOOP(nv) vc[nv] = 0.5*(vp[i][nv] + vm[i][nv]);
334  rhog = vc[RHO];
335  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
336 
337  rhs_entr = 0.0;
338  #if VISCOSITY == EXPLICIT
339  rhs_entr += (fvA[i][ENG] - fvA[i-1][ENG]);
340  rhs_entr -= EXPAND( vc[VX1]*(fvA[i][MX1] - fvA[i-1][MX1]) ,
341  + vc[VX2]*(fvA[i][MX2] - fvA[i-1][MX2]) ,
342  + vc[VX3]*(fvA[i][MX3] - fvA[i-1][MX3])*fabs(R_1));
343 
344  rhs_entr -= EXPAND( vc[VX1]*visc_src[i][MX1],
345  + vc[VX2]*visc_src[i][MX2],
346  + vc[VX3]*visc_src[i][MX3]);
347  #endif
348 
349  #if THERMAL_CONDUCTION == EXPLICIT
350  rhs_entr += (A[i]*tc_flux[i][ENG] - A[i-1]*tc_flux[i-1][ENG]);
351  #endif
352  rhs[i][ENTR] += rhs_entr*dtdV*rhog;
353  #endif
354  }
355 
356  } else if (g_dir == JDIR) {
357 
358  for (j = beg; j <= end; j++){
359  dtdx = dt/dx2[j];
360 
361  /* -- J1. initialize rhs with flux difference -- */
362 
363  NVAR_LOOP(nv) rhs[j][nv] = -dtdx*(flux[j][nv] - flux[j-1][nv]);
364  #if USE_PR_GRADIENT == YES
365  rhs[j][iMZ] += - dtdx*(p[j] - p[j-1]);
366  #endif
367 
368  /* -- J5. Add dissipative terms to entropy equation -- */
369 
370  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
371  rhog = vh[j][RHO];
372  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
373 
374  rhs_entr = 0.0;
375  #if VISCOSITY == EXPLICIT
376  rhs_entr += (visc_flux[j][ENG] - visc_flux[j-1][ENG]);
377  rhs_entr -= EXPAND( vc[VX1]*(visc_flux[j][MX1] - visc_flux[j-1][MX1]) ,
378  + vc[VX2]*(visc_flux[j][MX2] - visc_flux[j-1][MX2]) ,
379  + vc[VX3]*(visc_flux[j][MX3] - visc_flux[j-1][MX3]));
380  #endif
381  #if THERMAL_CONDUCTION == EXPLICIT
382  rhs_entr += (tc_flux[j][ENG] - tc_flux[j-1][ENG]);
383  #endif
384  rhs[j][ENTR] += rhs_entr*dtdx*rhog;
385  #endif
386  }
387  }
388 }
389 
390 #elif GEOMETRY == POLAR
391 {
392  double R, phi, z;
393  double R_1;
394 
395  if (g_dir == IDIR) {
396  double vc[NVAR];
397 
398  GetAreaFlux (state, fA, fvA, beg, end, grid);
399  for (i = beg; i <= end; i++) {
400  R = x1[i];
401  dtdV = dt/dV1[i];
402  dtdx = dt/dx1[i];
403  R_1 = grid[IDIR].r_1[i];
404 
405  /* -- I1. initialize rhs with flux difference -- */
406 
407  rhs[i][RHO] = -dtdV*(fA[i][RHO] - fA[i-1][RHO]);
408  EXPAND(rhs[i][iMR] = - dtdV*(fA[i][iMR] - fA[i-1][iMR])
409  - dtdx*(p[i] - p[i-1]); ,
410  rhs[i][iMPHI] = - dtdV*(fA[i][iMPHI] - fA[i-1][iMPHI])*R_1; ,
411  rhs[i][iMZ] = - dtdV*(fA[i][iMZ] - fA[i-1][iMZ]);)
412  #if PHYSICS == MHD
413  EXPAND(rhs[i][iBR] = -dtdV*(fA[i][iBR] - fA[i-1][iBR]); ,
414  rhs[i][iBPHI] = -dtdx*(flux[i][iBPHI] - flux[i-1][iBPHI]); ,
415  rhs[i][iBZ] = -dtdV*(fA[i][iBZ] - fA[i-1][iBZ]);)
416  #ifdef GLM_MHD
417  rhs[i][iBR] = -dtdx*(flux[i][iBR] - flux[i-1][iBR]);
418  rhs[i][PSI_GLM] = -dtdV*(fA[i][PSI_GLM] - fA[i-1][PSI_GLM]);
419  #endif
420  #endif
421  IF_ENERGY(rhs[i][ENG] = -dtdV*(fA[i][ENG] - fA[i-1][ENG]);)
422 
423  NSCL_LOOP(nv) rhs[i][nv] = -dtdV*(fA[i][nv] - fA[i-1][nv]);
424 
425  IF_DUST(NDUST_LOOP(nv) rhs[i][nv] = -dtdV*(fA[i][nv] - fA[i-1][nv]);
426  rhs[i][MX2_D] *= R_1;)
427 
428  /* -- I5. Add dissipative terms to entropy equation -- */
429 
430  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
431  for (nv = NVAR; nv--; ) vc[nv] = 0.5*(vp[i][nv] + vm[i][nv]);
432  rhog = vc[RHO];
433  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
434 
435  rhs_entr = 0.0;
436  #if VISCOSITY == EXPLICIT
437  rhs_entr += (fvA[i][ENG] - fvA[i-1][ENG]);
438  rhs_entr -= EXPAND( vc[VX1]*(fvA[i][iMR] - fvA[i-1][iMR]) ,
439  + vc[VX2]*(fvA[i][iMPHI] - fvA[i-1][iMPHI])*R_1 ,
440  + vc[VX3]*(fvA[i][iMZ] - fvA[i-1][iMZ]));
441 
442  rhs_entr -= EXPAND( vc[VX1]*visc_src[i][MX1],
443  + vc[VX2]*visc_src[i][MX2],
444  + vc[VX3]*visc_src[i][MX3]);
445  #endif
446 
447  #if THERMAL_CONDUCTION == EXPLICIT
448  rhs_entr += (A[i]*tc_flux[i][ENG] - A[i-1]*tc_flux[i-1][ENG]);
449  #endif
450  rhs[i][ENTR] += rhs_entr*dtdV*rhog;
451  #endif
452 
453  }
454 
455  } else if (g_dir == JDIR) {
456 
457  scrh = dt/x1[i];
458  for (j = beg; j <= end; j++){
459  dtdx = scrh/dx2[j];
460 
461  /* -- J1. Compute equations rhs for phi-contributions -- */
462 
463  NVAR_LOOP(nv) rhs[j][nv] = -dtdx*(flux[j][nv] - flux[j-1][nv]);
464  rhs[j][iMPHI] -= dtdx*(p[j] - p[j-1]);
465 
466  /* -- J5. Add dissipative terms to entropy equation -- */
467 
468  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
469  rhog = vh[j][RHO];
470  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
471 
472  rhs_entr = 0.0;
473  #if VISCOSITY == EXPLICIT
474  rhs_entr += (visc_flux[j][ENG] - visc_flux[j-1][ENG]);
475  rhs_entr -= EXPAND( vh[j][VX1]*(visc_flux[j][MX1] - visc_flux[j-1][MX1]) ,
476  + vh[j][VX2]*(visc_flux[j][MX2] - visc_flux[j-1][MX2]) ,
477  + vh[j][VX3]*(visc_flux[j][MX3] - visc_flux[j-1][MX3]));
478 
479  rhs_entr -= EXPAND( vh[j][VX1]*visc_src[j][MX1],
480  + vh[j][VX2]*visc_src[j][MX2],
481  + vh[j][VX3]*visc_src[j][MX3]);
482  #endif
483  #if THERMAL_CONDUCTION == EXPLICIT
484  rhs_entr += (tc_flux[j][ENG] - tc_flux[j-1][ENG]);
485  #endif
486  rhs[j][ENTR] += rhs_entr*dtdx*rhog;
487  #endif
488 
489  }
490 
491  } else if (g_dir == KDIR) {
492 
493  for (k = beg; k <= end; k++){
494  dtdx = dt/dx3[k];
495 
496  /* -- K1. initialize rhs with flux difference -- */
497 
498  VAR_LOOP(nv) rhs[k][nv] = -dtdx*(flux[k][nv] - flux[k-1][nv]);
499  rhs[k][MX3] -= dtdx*(p[k] - p[k-1]);
500 
501  /* -- K5. Add dissipative terms to entropy equation -- */
502 
503  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
504  rhog = vh[k][RHO];
505  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
506 
507  rhs_entr = 0.0;
508  #if VISCOSITY == EXPLICIT
509  rhs_entr += (visc_flux[k][ENG] - visc_flux[k-1][ENG]);
510  rhs_entr -= EXPAND( vh[j][VX1]*(visc_flux[k][MX1] - visc_flux[k-1][MX1]) ,
511  + vh[j][VX2]*(visc_flux[k][MX2] - visc_flux[k-1][MX2]) ,
512  + vh[j][VX3]*(visc_flux[k][MX3] - visc_flux[k-1][MX3]));
513  #endif
514 
515  #if THERMAL_CONDUCTION == EXPLICIT
516  rhs_entr += (tc_flux[k][ENG] - tc_flux[k-1][ENG]);
517  #endif
518  rhs[k][ENTR] += rhs_entr*dtdx*rhog;
519  #endif
520 
521  }
522  }
523 }
524 #elif GEOMETRY == SPHERICAL
525 {
526  double r_1, th, s, s_1;
527 
528  if (g_dir == IDIR) {
529  double vc[NVAR], dVdx;
530 
531  GetAreaFlux (state, fA, fvA, beg, end, grid);
532  for (i = beg; i <= end; i++) {
533  dtdV = dt/dV1[i];
534  dtdx = dt/dx1[i];
535  r_1 = grid[IDIR].r_1[i];
536 
537  /* -- I1. initialize rhs with flux difference -- */
538 
539 /* Alternative sequence
540 dVdx = dV1[i]/dx1[i];
541 NVAR_LOOP(nv) rhs[i][nv] = -dtdV*(fA[i][nv] - fA[i-1][nv]);
542 rhs[i][MX1] -= dtdx*(p[i] - p[i-1]);
543 rhs[i][MX3] *= r_1;
544 #if PHYSICS == MHD
545  EXPAND(
546  ,
547  rhs[i][iBTH] *= dVrdx; ,
548  rhs[i][iBPHI] *= dVrdx;
549  )
550  #ifdef GLM_MHD
551  rhs[i][iBR] *= dVdx;
552  #endif
553 #endif
554 IF_DUST(rhs[i][MX3_D] *= r_1;)
555 */
556 
557  rhs[i][RHO] = -dtdV*(fA[i][RHO] - fA[i-1][RHO]);
558  EXPAND(
559  rhs[i][iMR] = - dtdV*(fA[i][iMR] - fA[i-1][iMR])
560  - dtdx*(p[i] - p[i-1]); ,
561  rhs[i][iMTH] = -dtdV*(fA[i][iMTH] - fA[i-1][iMTH]); ,
562  rhs[i][iMPHI] = -dtdV*(fA[i][iMPHI] - fA[i-1][iMPHI])*r_1;
563  )
564  #if PHYSICS == MHD
565  EXPAND(
566  rhs[i][iBR] = -dtdV*(fA[i][iBR] - fA[i-1][iBR]); ,
567  rhs[i][iBTH] = -dtdx*(fA[i][iBTH] - fA[i-1][iBTH])*r_1; ,
568  rhs[i][iBPHI] = -dtdx*(fA[i][iBPHI] - fA[i-1][iBPHI])*r_1;
569  )
570  #ifdef GLM_MHD
571  rhs[i][iBR] = -dtdx*(flux[i][iBR] - flux[i-1][iBR]);
572  rhs[i][PSI_GLM] = -dtdV*(fA[i][PSI_GLM] - fA[i-1][PSI_GLM]);
573  #endif
574  #endif
575  IF_ENERGY(rhs[i][ENG] = -dtdV*(fA[i][ENG] - fA[i-1][ENG]);)
576 
577  NSCL_LOOP(nv) rhs[i][nv] = -dtdV*(fA[i][nv] - fA[i-1][nv]);
578  IF_DUST(NDUST_LOOP(nv) rhs[i][nv] = -dtdV*(fA[i][nv] - fA[i-1][nv]);
579  rhs[i][MX3_D] *= r_1;)
580 
581  /* -- I5. Add dissipative terms to entropy equation -- */
582 
583  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
584  NVAR_LOOP(nv) vc[nv] = 0.5*(vp[i][nv] + vm[i][nv]);
585 
586  rhog = vc[RHO];
587  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
588 
589  rhs_entr = 0.0;
590  #if VISCOSITY == EXPLICIT
591  rhs_entr += (fvA[i][ENG] - fvA[i-1][ENG]);
592  rhs_entr -= EXPAND( vc[VX1]*(fvA[i][iMR] - fvA[i-1][iMR]) ,
593  + vc[VX2]*(fvA[i][iMTH] - fvA[i-1][iMTH]) ,
594  + vc[VX3]*(fvA[i][iMPHI] - fvA[i-1][iMPHI])*r_1);
595 
596  rhs_entr -= EXPAND( vc[VX1]*visc_src[i][MX1],
597  + vc[VX2]*visc_src[i][MX2],
598  + vc[VX3]*visc_src[i][MX3]);
599  #endif
600  #if THERMAL_CONDUCTION == EXPLICIT
601  rhs_entr += (A[i]*tc_flux[i][ENG] - A[i-1]*tc_flux[i-1][ENG]);
602  #endif
603  rhs[i][ENTR] += rhs_entr*dtdV*rhog;
604  #endif
605  }
606 
607  } else if (g_dir == JDIR) {
608 
609  GetAreaFlux (state, fA, fvA, beg, end, grid);
610  r_1 = 0.5*(x1p[i]*x1p[i] - x1p[i-1]*x1p[i-1])/dV1[i];
611  scrh = dt*r_1;
612  for (j = beg; j <= end; j++){
613  th = x2[j];
614  dtdV = scrh/dV2[j];
615  dtdx = scrh/dx2[j];
616  s = sin(th);
617  s_1 = 1.0/s;
618 
619  /* -- J1. initialize rhs with flux difference -- */
620 
621  rhs[j][RHO] = -dtdV*(fA[j][RHO] - fA[j-1][RHO]);
622  EXPAND(
623  rhs[j][iMR] = - dtdV*(fA[j][iMR] - fA[j-1][iMR]); ,
624  rhs[j][iMTH] = - dtdV*(fA[j][iMTH] - fA[j-1][iMTH])
625  - dtdx*(p[j] - p[j-1]); ,
626  rhs[j][iMPHI] = - dtdV*(fA[j][iMPHI] - fA[j-1][iMPHI])*fabs(s_1);
627  )
628  #if PHYSICS == MHD
629  EXPAND(
630  rhs[j][iBR] = -dtdV*(fA[j][iBR] - fA[j-1][iBR]); ,
631  rhs[j][iBTH] = -dtdV*(fA[j][iBTH] - fA[j-1][iBTH]); ,
632  rhs[j][iBPHI] = -dtdx*(flux[j][iBPHI] - flux[j-1][iBPHI]);
633  )
634  #ifdef GLM_MHD
635  rhs[j][iBTH] = -dtdx*(flux[j][iBTH] - flux[j-1][iBTH]);
636  rhs[j][PSI_GLM] = -dtdV*(fA[j][PSI_GLM] - fA[j-1][PSI_GLM]);
637  #endif
638  #endif
639  IF_ENERGY(rhs[j][ENG] = -dtdV*(fA[j][ENG] - fA[j-1][ENG]);)
640 
641  NSCL_LOOP(nv) rhs[j][nv] = -dtdV*(fA[j][nv] - fA[j-1][nv]);
642 
643  IF_DUST(NDUST_LOOP(nv) rhs[j][nv] = -dtdV*(fA[j][nv] - fA[j-1][nv]);
644  rhs[j][MX3_D] *= fabs(s_1);)
645 
646  /* -- J5. Add TC dissipative term to entropy equation -- */
647 
648  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
649  rhog = vh[j][RHO];
650  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
651 
652  rhs_entr = 0.0;
653  #if VISCOSITY == EXPLICIT
654  rhs_entr += (fvA[j][ENG] - fvA[j-1][ENG]);
655  rhs_entr -= EXPAND( vc[VX1]*(fvA[j][iMR] - fvA[j-1][iMR]) ,
656  + vc[VX2]*(fvA[j][iMTH] - fvA[j-1][iMTH]) ,
657  + vc[VX3]*(fvA[j][iMPHI] - fvA[j-1][iMPHI])*fabs(s_1));
658 
659  rhs_entr -= EXPAND( vc[VX1]*visc_src[j][MX1],
660  + vc[VX2]*visc_src[j][MX2],
661  + vc[VX3]*visc_src[j][MX3]);
662  #endif
663  #if THERMAL_CONDUCTION == EXPLICIT
664  rhs_entr += (A[j]*tc_flux[j][ENG] - A[j-1]*tc_flux[j-1][ENG]);
665  #endif
666  rhs[j][ENTR] += rhs_entr*dtdV*rhog;
667  #endif
668 
669  }
670 
671  } else if (g_dir == KDIR) {
672 
673  r_1 = 0.5*(x1p[i]*x1p[i] - x1p[i-1]*x1p[i-1])/dV1[i];
674  scrh = dt*r_1*dx2[j]/dV2[j];
675  for (k = beg; k <= end; k++) {
676  dtdx = scrh/dx3[k];
677 
678  /* -- K1. initialize rhs with flux difference -- */
679 
680  VAR_LOOP(nv) rhs[k][nv] = -dtdx*(flux[k][nv] - flux[k-1][nv]);
681  rhs[k][iMPHI] -= dtdx*(p[k] - p[k-1]);
682 
683  /* -- K5. Add dissipative terms to entropy equation -- */
684 
685  #if (ENTROPY_SWITCH) && (PARABOLIC_FLUX & EXPLICIT)
686  rhog = vh[k][RHO];
687  rhog = (g_gamma - 1.0)*pow(rhog,1.0-g_gamma);
688 
689  rhs_entr = 0.0;
690  #if VISCOSITY == EXPLICIT
691  rhs_entr += (visc_flux[k][ENG] - visc_flux[k-1][ENG]);
692  rhs_entr -= EXPAND( vc[VX1]*(visc_flux[k][MX1] - visc_flux[k-1][MX1]) ,
693  + vc[VX2]*(visc_flux[k][MX2] - visc_flux[k-1][MX2]) ,
694  + vc[VX3]*(visc_flux[k][MX3] - visc_flux[k-1][MX3]));
695  #endif
696  #if THERMAL_CONDUCTION == EXPLICIT
697  rhs_entr += (tc_flux[k][ENG] - tc_flux[k-1][ENG]);
698  #endif
699  rhs[k][ENTR] += rhs_entr*dtdx*rhog;
700  #endif
701  }
702  }
703 }
704 #endif /* GEOMETRY == SPHERICAL */
705 
706 /* --------------------------------------------------------------
707  Add source terms
708  -------------------------------------------------------------- */
709 
710  RightHandSideSource (state, Dts, beg, end, dt, phi_p, grid);
711 
712 /* --------------------------------------------------
713  Reset right hand side in internal boundary zones
714  -------------------------------------------------- */
715 
716  #if INTERNAL_BOUNDARY == YES
717  InternalBoundaryReset(state, Dts, beg, end, grid);
718  #endif
719 
720 /* --------------------------------------------------
721  Time step determination
722  -------------------------------------------------- */
723 
724 #if !GET_MAX_DT
725 return;
726 #endif
727 
728  cl = 0.0;
729  for (i = beg-1; i <= end; i++) {
730  scrh = Dts->cmax[i]*grid[g_dir].inv_dxi[i];
731  cl = MAX(cl, scrh);
732  }
733  #if GEOMETRY == POLAR || GEOMETRY == SPHERICAL
734  if (g_dir == JDIR) {
735  cl /= fabs(grid[IDIR].xgc[g_i]);
736  }
737  #if GEOMETRY == SPHERICAL
738  if (g_dir == KDIR){
739  cl /= fabs(grid[IDIR].xgc[g_i])*sin(grid[JDIR].xgc[g_j]);
740  }
741  #endif
742  #endif
743  Dts->inv_dta = MAX(cl, Dts->inv_dta);
744 }
#define MX3
Definition: mod_defs.h:22
#define MAX(a, b)
Definition: macros.h:101
#define NSCL_LOOP(n)
Definition: pluto.h:616
double g_gamma
Definition: globals.h:112
int end
Global end index for the local array.
Definition: structs.h:116
#define MX1
Definition: mod_defs.h:20
double ** vh
Primitive state at n+1/2 (only for one step method)
Definition: structs.h:162
#define VX2
Definition: mod_defs.h:29
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
#define IF_ENERGY(a)
Definition: pluto.h:631
double ** visc_src
Viscosity source term.
Definition: structs.h:151
#define iMTH
Definition: mod_defs.h:70
void RightHandSideSource(const State_1D *state, Time_Step *Dts, int beg, int end, double dt, double *phi_p, Grid *grid)
Definition: rhs_source.c:68
double ** rhs
Conservative right hand side.
Definition: structs.h:163
double * xr
Definition: structs.h:81
#define iBZ
Definition: mod_defs.h:138
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
#define YES
Definition: pluto.h:25
static void TotalFlux(const State_1D *, double *, int, int, Grid *)
Definition: rhs.c:747
#define PSI_GLM
Definition: mod_defs.h:34
double ** res_flux
Resistive flux (current)
Definition: structs.h:153
#define iMPHI
double * dV
Cell volume.
Definition: structs.h:86
void GetAreaFlux(const State_1D *state, double **fA, double **fvA, int beg, int end, Grid *grid)
Definition: get_area_flux.c:4
#define NDUST_LOOP(n)
Definition: pluto.h:617
double * dx
Definition: structs.h:83
double * cmax
Maximum signal velocity for hyperbolic eqns.
Definition: structs.h:214
#define iBR
Definition: mod_defs.h:150
double ** visc_flux
Viscosity flux.
Definition: structs.h:150
#define VX1
Definition: mod_defs.h:28
#define KDIR
Definition: pluto.h:195
#define iMZ
Definition: mod_defs.h:59
double ** vp
prim vars at i+1/2 edge, vp[i] = vL(i+1/2)
Definition: structs.h:142
#define iMR
Definition: mod_defs.h:69
double inv_dta
Inverse of advection (hyperbolic) time step, .
Definition: structs.h:215
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
Definition: globals.h:82
#define VAR_LOOP(n)
Definition: macros.h:226
#define IDIR
Definition: pluto.h:193
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
#define NVAR_LOOP(n)
Definition: pluto.h:618
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
#define PHYSICS
Definition: definitions_01.h:1
int j
Definition: analysis.c:2
#define MX2
Definition: mod_defs.h:21
#define iBPHI
Definition: mod_defs.h:152
int k
Definition: analysis.c:2
int MXn
Definition: globals.h:74
double * x
Definition: structs.h:80
double ** tc_flux
Thermal conduction flux.
Definition: structs.h:152
double * xgc
Cell volumetric centroid (!= x when geometry != CARTESIAN).
Definition: structs.h:84
double BodyForcePotential(double, double, double)
Definition: init.c:479
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
double * r_1
Geometrical factor 1/r.
Definition: structs.h:88
#define USE_PR_GRADIENT
Definition: rhs.c:83
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
Definition: structs.h:141
#define iBTH
Definition: mod_defs.h:151
#define MHD
Definition: pluto.h:111
#define s
#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
void InternalBoundaryReset(const State_1D *, Time_Step *, int, int, Grid *)
#define VX3
Definition: mod_defs.h:30
double * press
Upwind pressure term computed with the Riemann solver.
Definition: structs.h:164
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define JDIR
Definition: pluto.h:194
#define NVAR
Definition: pluto.h:609
double * inv_dxi
inverse of the distance between the center of two cells, inv_dxi = .
Definition: structs.h:91
void AdvectFlux(const State_1D *state, int beg, int end, Grid *grid)
Definition: adv_flux.c:47
#define GLM_MHD
Definition: glm.h:25
#define IF_DUST(a)
Definition: pluto.h:625
double * A
Right interface area, A[i] = .
Definition: structs.h:87

Here is the call graph for this function:

Here is the caller graph for this function:

void RightHandSideSource ( const State_1D state,
Time_Step Dts,
int  beg,
int  end,
double  dt,
double *  phi_p,
Grid grid 
)
Parameters
[in,out]statepointer to State_1D structure
[in]Dtspointer to time step structure
[in]beginitial index of computation
[in]endfinal index of computation
[in]dttime increment
[in]phi_pforce potential at interfaces
[in]gridpointer to Grid structure
Returns
This function has no return value.

Definition at line 68 of file rhs_source.c.

82 {
83  int i, j, k, nv;
84  double r_1, g[3];
85 
86  double dtdx, scrh, th, ct, s;
87  double Sm;
88  double *x1 = grid[IDIR].x, *x2 = grid[JDIR].x, *x3 = grid[KDIR].x;
89  double *x1p = grid[IDIR].xr, *x2p = grid[JDIR].xr, *x3p = grid[KDIR].xr;
90  double *dx1 = grid[IDIR].dx, *dx2 = grid[JDIR].dx, *dx3 = grid[KDIR].dx;
91  double *dV1 = grid[IDIR].dV, *dV2 = grid[JDIR].dV, *dV3 = grid[KDIR].dV;
92 
93  double **rhs = state->rhs;
94  double **flux = state->flux;
95  double **vh = state->vh;
96  double **vp = state->vp;
97  double **vm = state->vm;
98  double *p;
99  double *A, *dV;
100  double cl;
101  double **Bg0, **wA, w, wp, vphi, phi_c;
102  double vphi_d, Sm_d;
103  double vc[NVAR], *vg;
104 
105 #ifdef FARGO
106  wA = FARGO_GetVelocity();
107 #endif
108 
109 #if (PHYSICS == MHD) && (BACKGROUND_FIELD == YES)
110  Bg0 = GetBackgroundField (beg, end, CELL_CENTER, grid);
111 #endif
112 
113 /* --------------------------
114  pointer shortcuts
115  -------------------------- */
116 
117  p = state->press;
118  A = grid[g_dir].A;
119  dV = grid[g_dir].dV;
120 
121  i = g_i; /* will be redefined during x1-sweep */
122  j = g_j; /* will be redefined during x2-sweep */
123  k = g_k; /* will be redefined during x3-sweep */
124 
125  if (g_dir == IDIR){
126 
127 #if GEOMETRY == SPHERICAL
128  th = x2[j];
129  s = sin(th);
130 #endif
131 
132  for (i = beg; i <= end; i++) {
133  dtdx = dt/dx1[i];
134 
135  /* --------------------------------------------
136  I1. Add geometrical source term
137  -------------------------------------------- */
138 
139 #if GEOMETRY == CARTESIAN
140 
141  vg = state->vh[i];
142  #ifdef SHEARINGBOX /* Include Coriolis term for x-momentum */
143  rhs[i][MX1] += dt*2.0*vh[i][RHO]*vh[i][VX2]*SB_OMEGA;
144  #endif
145 
146  #if (defined FARGO && !defined SHEARINGBOX)
147  w = wA[k][i];
148  #endif
149 
150 #elif GEOMETRY == CYLINDRICAL
151 
152  r_1 = 1.0/x1[i];
153  vg = vc;
154  NFLX_LOOP(nv) vc[nv] = 0.5*(vp[i][nv] + vm[i][nv]);
155  #if COMPONENTS == 3
156  vphi = vc[iVPHI];
157  IF_ROTATING_FRAME(w = g_OmegaZ*x1[i];
158  vphi += w;)
159  rhs[i][MX1] += dt*(vc[RHO]*vphi*vphi - TotBB(vc, Bg0[i], iBPHI, iBPHI))*r_1;
160  #endif
161 
162 #elif GEOMETRY == POLAR
163 
164  r_1 = grid[IDIR].r_1[i];
165  vg = vc;
166  NFLX_LOOP(nv) vc[nv] = 0.5*(vp[i][nv] + vm[i][nv]);
167  vphi = vc[iVPHI];
168  #if (defined FARGO) || (ROTATING_FRAME == YES)
169  w = 0.0;
170  IF_FARGO (w += wA[k][i];)
171  IF_ROTATING_FRAME(w += g_OmegaZ*x1[i];)
172  vphi += w;
173  #endif
174  rhs[i][MX1] += dt*( vc[RHO]*vphi*vphi
175  - TotBB(vc, Bg0[i], iBPHI, iBPHI))*r_1;
176 
177  IF_DUST(vphi_d = SELECT(0.0, vc[VX3_D], 0.0);
178  #if (defined FARGO) || (ROTATING_FRAME == YES)
179  vphi_d += w;
180  #endif
181  rhs[i][MX1_D] += dt*vc[RHO_D]*vphi_d*vphi_d*r_1;)
182 
183 #elif GEOMETRY == SPHERICAL
184 
185  r_1 = 1.0/x1[i];
186  vg = vc;
187  NFLX_LOOP(nv) vc[nv] = 0.5*(vp[i][nv] + vm[i][nv]);
188  vphi = SELECT(0.0, 0.0, vc[iVPHI]);
189  #if (defined FARGO) || (ROTATING_FRAME == YES)
190  w = 0.0;
191  IF_FARGO (w += wA[j][i];)
192  IF_ROTATING_FRAME(w += g_OmegaZ*x1[i]*s;)
193  vphi += w;
194  #endif
195  Sm = vc[RHO]*(EXPAND( 0.0, + vc[VX2]*vc[VX2], + vphi*vphi));
196  Sm += EXPAND( 0.0, - TotBB(vc, Bg0[i], iBTH, iBTH),
197  - TotBB(vc, Bg0[i], iBPHI,iBPHI));
198  rhs[i][MX1] += dt*Sm*r_1;
199 
200  IF_DUST(vphi_d = SELECT(0.0, 0.0, vc[VX3_D]);
201  #if (defined FARGO) || (ROTATING_FRAME == YES)
202  vphi_d += w;
203  #endif
204  Sm_d = vc[RHO_D]*(EXPAND( 0.0, + vc[VX2_D]*vc[VX2_D], + vphi_d*vphi_d));
205  rhs[i][MX1_D] += dt*Sm_d*r_1;)
206 #endif
207 
208  /* ----------------------------------------------------
209  I2. Modify rhs to enforce conservation
210  ---------------------------------------------------- */
211 
212 #if ((defined FARGO && !defined SHEARINGBOX) || (ROTATING_FRAME == YES))
213  rhs[i][iMPHI] -= w*rhs[i][RHO];
214  IF_DUST (rhs[i][iMPHI_D] -= w*rhs[i][RHO_D];)
215  IF_ENERGY(rhs[i][ENG] -= w*(rhs[i][iMPHI] + 0.5*w*rhs[i][RHO]);)
216 #endif
217 
218  /* ----------------------------------------------------
219  I3. Include body forces
220  ---------------------------------------------------- */
221 
222 #if (BODY_FORCE & VECTOR)
223  BodyForceVector(vg, g, x1[i], x2[j], x3[k]);
224  rhs[i][MX1] += dt*vg[RHO]*g[IDIR];
225  IF_DUST (rhs[i][MX1_D] += dt*vg[RHO_D]*g[IDIR];)
226  IF_ENERGY(rhs[i][ENG] += dt*0.5*(flux[i][RHO] + flux[i-1][RHO])*g[IDIR];)
227 #endif
228 
229 #if (BODY_FORCE & POTENTIAL)
230  rhs[i][MX1] -= dtdx*vg[RHO]*(phi_p[i] - phi_p[i-1]);
231  IF_DUST (rhs[i][MX1_D] -= dtdx*vg[RHO_D]*(phi_p[i] - phi_p[i-1]);)
232  IF_ENERGY(phi_c = BodyForcePotential(x1[i], x2[j], x3[k]);
233  rhs[i][ENG] -= phi_c*rhs[i][RHO];)
234 #endif
235 
236 
237  }
238 
239  } else if (g_dir == JDIR){
240 
241  scrh = 1.0;
242 #if GEOMETRY == POLAR
243  scrh = 1.0/x1[i];
244 #elif GEOMETRY == SPHERICAL
245  scrh = r_1 = 0.5*(x1p[i]*x1p[i] - x1p[i-1]*x1p[i-1])/dV1[i];
246 #endif
247  for (j = beg; j <= end; j++) {
248  dtdx = dt/dx2[j]*scrh;
249 
250  /* --------------------------------------------
251  J1. Add geometrical source terms
252  -------------------------------------------- */
253 
254 #if GEOMETRY != SPHERICAL
255 
256  vg = state->vh[j];
257 
258 #ifdef SHEARINGBOX /* Include Coriolis term for y-momentum */
259  #ifdef FARGO
260  rhs[j][MX2] += dt*(SB_Q-2.0)*vh[j][RHO]*vh[j][VX1]*SB_OMEGA;
261  #else
262  rhs[j][MX2] -= dt*2.0*vh[j][RHO]*vh[j][VX1]*SB_OMEGA;
263  #endif
264 #endif
265 
266 
267 #elif GEOMETRY == SPHERICAL
268 
269  th = x2[j];
270  s = sin(th);
271  ct = grid[JDIR].ct[j];
272 
273  vg = vc;
274  NFLX_LOOP(nv) vc[nv] = state->vh[j][nv];
275  vphi = SELECT(0.0, 0.0, vc[iVPHI]);
276  #if (defined FARGO) || (ROTATING_FRAME == YES)
277  w = 0.0;
278  IF_FARGO (w += wA[j][i];)
279  IF_ROTATING_FRAME(w += g_OmegaZ*x1[i]*s;)
280  vphi += w;
281  #endif
282  Sm = vc[RHO]*(EXPAND( 0.0, - vc[iVTH]*vc[iVR], + ct*vphi*vphi));
283  Sm += EXPAND(0.0, + TotBB(vc, Bg0[j], iBTH, iBR),
284  - ct*TotBB(vc, Bg0[j], iBPHI, iBPHI));
285  rhs[j][MX2] += dt*Sm*r_1;
286 
287  IF_DUST(vphi_d = SELECT(0.0, 0.0, vc[VX3_D]);
288  #if (defined FARGO) || (ROTATING_FRAME == YES)
289  vphi_d += w;
290  #endif
291  Sm_d = vc[RHO_D]*(EXPAND( 0.0, - vc[VX2_D]*vc[VX1_D], + ct*vphi_d*vphi_d));
292  rhs[j][MX2_D] += dt*Sm_d*r_1;)
293 
294  /* ----------------------------------------------------
295  J2. Modify rhs to enforce conservation
296  ---------------------------------------------------- */
297 
298  #if (defined FARGO) || (ROTATING_FRAME == YES)
299  rhs[j][MX3] -= w*rhs[j][RHO];
300  IF_DUST (rhs[j][MX3_D] -= w*rhs[j][RHO_D];)
301  IF_ENERGY(rhs[j][ENG] -= w*(rhs[j][MX3] + 0.5*w*rhs[j][RHO]);)
302  #endif
303 
304 #endif /* GEOMETRY == SPHERICAL */
305 
306  /* ----------------------------------------------------
307  J3. Include Body force
308  ---------------------------------------------------- */
309 
310 #if (BODY_FORCE & VECTOR)
311  BodyForceVector(vg, g, x1[i], x2[j], x3[k]);
312  rhs[j][MX2] += dt*vg[RHO]*g[JDIR];
313  IF_DUST (rhs[j][MX2_D] += dt*vg[RHO_D]*g[JDIR];)
314  IF_ENERGY(rhs[j][ENG] += dt*0.5*(flux[j][RHO] + flux[j-1][RHO])*g[JDIR];)
315 #endif
316 
317 #if (BODY_FORCE & POTENTIAL)
318  rhs[j][MX2] -= dtdx*vg[RHO]*(phi_p[j] - phi_p[j-1]);
319  IF_DUST (rhs[j][MX2_D] -= dtdx*vg[RHO_D]*(phi_p[j] - phi_p[j-1]);)
320  IF_ENERGY(phi_c = BodyForcePotential(x1[i], x2[j], x3[k]);
321  rhs[j][ENG] -= phi_c*rhs[j][RHO];)
322 #endif
323  }
324 
325  }else if (g_dir == KDIR){
326 
327  scrh = dt;
328 #if GEOMETRY == SPHERICAL
329  r_1 = 0.5*(x1p[i]*x1p[i] - x1p[i-1]*x1p[i-1])/dV1[i];
330  scrh = dt*r_1*dx2[j]/dV2[j];
331 #endif
332 
333  for (k = beg; k <= end; k++) {
334  dtdx = scrh/dx3[k];
335  vg = state->vh[k];
336 
337 #if (GEOMETRY == CARTESIAN) || (GEOMETRY == POLAR)
338  /* ------------------------------------------------------
339  K2. modify rhs to enforce conservation (FARGO only)
340  (solid body rotations are not included the
341  velocity depends on the cylindrical radius only)
342  ------------------------------------------------------ */
343 
344  #if (defined FARGO && !defined SHEARINGBOX)
345  w = wA[k][i];
346  rhs[k][MX2] -= w*rhs[k][RHO];
347  IF_DUST (rhs[k][MX2_D] -= w*rhs[k][RHO_D];)
348  IF_ENERGY(rhs[k][ENG] -= w*(rhs[k][MX2] + 0.5*w*rhs[k][RHO]);)
349  #endif
350 #endif
351 
352  /* ----------------------------------------------------
353  K3. Include body forces
354  ---------------------------------------------------- */
355 
356 #if (BODY_FORCE & VECTOR)
357  BodyForceVector(vg, g, x1[i], x2[j], x3[k]);
358  rhs[k][MX3] += dt*vg[RHO]*g[KDIR];
359  IF_DUST(rhs[k][MX3_D] += dt*vg[RHO_D]*g[KDIR];)
360  IF_ENERGY(rhs[k][ENG] += dt*0.5*(flux[k][RHO] + flux[k-1][RHO])*g[KDIR];)
361 #endif
362 
363 #if (BODY_FORCE & POTENTIAL)
364  rhs[k][MX3] -= dtdx*vg[RHO]*(phi_p[k] - phi_p[k-1]);
365  IF_DUST (rhs[k][MX3_D] -= dtdx*vg[RHO_D]*(phi_p[k] - phi_p[k-1]);)
366  IF_ENERGY(phi_c = BodyForcePotential(x1[i], x2[j], x3[k]);
367  rhs[k][ENG] -= phi_c*rhs[k][RHO];)
368 #endif
369  }
370  }
371 
372 /* ---------------------------------------------------------------
373  Source terms coming from tensor discretazion of parabolic
374  terms in curvilinear coordinates (only for viscosity)
375  ---------------------------------------------------------------- */
376 
377 #if (VISCOSITY == EXPLICIT) && (GEOMETRY != CARTESIAN)
378  for (i = beg; i <= end; i++) {
379  EXPAND(rhs[i][MX1] += dt*state->visc_src[i][MX1]; ,
380  rhs[i][MX2] += dt*state->visc_src[i][MX2]; ,
381  rhs[i][MX3] += dt*state->visc_src[i][MX3];)
382  }
383 #endif
384 
385 /* --------------------------------------------------
386  Dust drag force term
387  -------------------------------------------------- */
388 
389 #if DUST == YES
390  Dust_DragForce(state, beg, end, dt, grid);
391 #endif
392 
393 /* --------------------------------------------------
394  Powell's source terms
395  -------------------------------------------------- */
396 
397 #if (PHYSICS == MHD) && (DIVB_CONTROL == EIGHT_WAVES)
398  for (i = beg; i <= end; i++) {
399  EXPAND(rhs[i][MX1] += dt*state->src[i][MX1]; ,
400  rhs[i][MX2] += dt*state->src[i][MX2]; ,
401  rhs[i][MX3] += dt*state->src[i][MX3];)
402 
403  EXPAND(rhs[i][BX1] += dt*state->src[i][BX1]; ,
404  rhs[i][BX2] += dt*state->src[i][BX2]; ,
405  rhs[i][BX3] += dt*state->src[i][BX3];)
406  #if HAVE_ENERGY
407  rhs[i][ENG] += dt*state->src[i][ENG];
408  #endif
409  }
410 #endif
411 
412 /* -------------------------------------------------
413  Extended GLM source terms
414  ------------------------------------------------- */
415 
416 #if (defined GLM_MHD) && (GLM_EXTENDED == YES)
417  GLM_ExtendedSource (state, dt, beg, end, grid);
418 #endif
419 
420 }
#define MX3
Definition: mod_defs.h:22
#define IF_ROTATING_FRAME(a)
Definition: pluto.h:643
#define iMPHI
Definition: rhs_source.c:64
int end
Global end index for the local array.
Definition: structs.h:116
#define MX1
Definition: mod_defs.h:20
double ** vh
Primitive state at n+1/2 (only for one step method)
Definition: structs.h:162
#define VX2
Definition: mod_defs.h:29
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
#define IF_ENERGY(a)
Definition: pluto.h:631
double ** visc_src
Viscosity source term.
Definition: structs.h:151
void GLM_ExtendedSource(const State_1D *state, double dt, int beg, int end, Grid *grid)
Definition: glm.c:168
double ** rhs
Conservative right hand side.
Definition: structs.h:163
double * xr
Definition: structs.h:81
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
#define BODY_FORCE
Definition: definitions_01.h:5
#define YES
Definition: pluto.h:25
static double ** wA
#define iVPHI
Definition: mod_defs.h:67
#define g_OmegaZ
Definition: init.c:64
#define VISCOSITY
Definition: pluto.h:385
#define SPHERICAL
Definition: pluto.h:36
double * dV
Cell volume.
Definition: structs.h:86
double * dx
Definition: structs.h:83
#define iBR
Definition: mod_defs.h:150
double ** GetBackgroundField(int beg, int end, int where, Grid *grid)
Definition: bckgrnd_field.c:5
#define VX1
Definition: mod_defs.h:28
#define POTENTIAL
Definition: pluto.h:129
#define KDIR
Definition: pluto.h:195
double ** vp
prim vars at i+1/2 edge, vp[i] = vL(i+1/2)
Definition: structs.h:142
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
Definition: globals.h:82
#define CELL_CENTER
Definition: pluto.h:205
double ** src
Definition: structs.h:160
#define IF_FARGO(a)
Definition: pluto.h:637
#define iVR
Definition: mod_defs.h:65
#define IDIR
Definition: pluto.h:193
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
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
#define SB_OMEGA
Disk local orbital frequency .
Definition: shearingbox.h:81
int j
Definition: analysis.c:2
#define iVTH
Definition: mod_defs.h:66
#define MX2
Definition: mod_defs.h:21
#define iBPHI
Definition: mod_defs.h:152
#define NFLX_LOOP(n)
Definition: pluto.h:613
int k
Definition: analysis.c:2
double * x
Definition: structs.h:80
double BodyForcePotential(double, double, double)
Definition: init.c:479
#define TotBB(v, b0, a, b)
Definition: rhs_source.c:55
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
#define GEOMETRY
Definition: definitions_01.h:4
#define SB_Q
The shear parameter, .
Definition: shearingbox.h:76
double * r_1
Geometrical factor 1/r.
Definition: structs.h:88
#define CARTESIAN
Definition: pluto.h:33
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
Definition: structs.h:141
#define iBTH
Definition: mod_defs.h:151
#define s
#define BX3
Definition: mod_defs.h:27
#define VECTOR
Definition: pluto.h:128
int i
Definition: analysis.c:2
double ** FARGO_GetVelocity(void)
void BodyForceVector(double *, double *, double, double, double)
Definition: init.c:441
#define BX1
Definition: mod_defs.h:25
double * ct
Geometrical factor cot(theta).
Definition: structs.h:89
double * press
Upwind pressure term computed with the Riemann solver.
Definition: structs.h:164
#define BX2
Definition: mod_defs.h:26
#define JDIR
Definition: pluto.h:194
#define NVAR
Definition: pluto.h:609
#define EXPLICIT
Definition: pluto.h:67
#define ROTATING_FRAME
Definition: pluto.h:361
#define IF_DUST(a)
Definition: pluto.h:625
double * A
Right interface area, A[i] = .
Definition: structs.h:87

Here is the call graph for this function:

Here is the caller graph for this function:

void RKC ( const Data d,
Time_Step Dts,
Grid grid 
)

Solve diffusion equation using Runge-Kutta-Chebyshev (RKC) method

Parameters
[in,out]dpointer to Data structure
[in,out]Dtspointer to Time_Step structure
[in]gridpointer to an array of Grid structures

Definition at line 58 of file rkc.c.

67 {
68  int i, j, k, nv, s, s_RKC = 0;
69  int nv_indx, var_list[NVAR], nvar_rkc;
70  double kappa_dl2, eta_dl2, nu_dl2;
71  double absh, sprad, Y;
72  double epsilon = 2./13.;
73  double w_0, w_1;
74  double scrh, scr1, scr2;
75  double mu_j, nu_j, mu_tilde,a_jm1;
76  double Tj, dTj, d2Tj, Tjm1, Tjm2, dTjm1, dTjm2, d2Tjm1, d2Tjm2;
77  double b_j, b_jm1, b_jm2, arg;
78  double dt_par;
79  static Data_Arr Y_jm1, Y_jm2, UU_0, F_0, F_jm1;
80  static double **v;
81  static unsigned char *flag;
82 
83  if (Y_jm1 == NULL) {
84  Y_jm1 = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
85  Y_jm2 = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
86  UU_0 = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
87  F_0 = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
88  F_jm1 = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
89  flag = ARRAY_1D(NMAX_POINT, unsigned char);
90  v = ARRAY_2D(NMAX_POINT, NVAR, double);
91  }
92 
93 /* -------------------------------------------------------
94  set the number of variables to be evolved with RKC
95  ------------------------------------------------------- */
96 
97  i = 0;
98  for (nv = 0; nv < NVAR; nv++) var_list[nv] = 0;
99  #if VISCOSITY == RK_CHEBYSHEV
100  EXPAND(var_list[i++] = MX1; ,
101  var_list[i++] = MX2; ,
102  var_list[i++] = MX3;)
103  #endif
104 
106  EXPAND(var_list[i++] = BX1; ,
107  var_list[i++] = BX2; ,
108  var_list[i++] = BX3;)
109  #endif
111  || (VISCOSITY == RK_CHEBYSHEV && EOS == IDEAL) \
112  || (RESISTIVITY == RK_CHEBYSHEV && EOS == IDEAL)
113 
114  var_list[i++] = ENG;
115  #endif
116  nvar_rkc = i;
117 
118 /* -------------------------------------------------
119  get conservative vector UU
120  ------------------------------------------------- */
121 
122  KDOM_LOOP(k){
123  JDOM_LOOP(j){
124  IDOM_LOOP(i){
125  for (nv = NVAR; nv--; ) {
126  v[i][nv] = d->Vc[nv][k][j][i];
127  }}
128  PrimToCons (v, UU_0[k][j], IBEG, IEND);
129  }}
130 
131 /* -------------------------------------------------
132  Compute the parabolic time step by calling
133  the RHS function once outside the main loop.
134  ------------------------------------------------- */
135 
136  g_intStage = 1;
137  Boundary(d, ALL_DIR, grid);
138  #if SHOCK_FLATTENING == MULTID
139  FindShock (d, grid);
140  #endif
141 
142  Dts->inv_dtp = ParabolicRHS(d, F_0, 1.0, grid);
143  Dts->inv_dtp /= (double) DIMENSIONS;
144  #ifdef PARALLEL
145  MPI_Allreduce (&Dts->inv_dtp, &scrh, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
146  Dts->inv_dtp = scrh;
147  #endif
148  dt_par = Dts->cfl_par/(2.0*Dts->inv_dtp); /* -- explicit parabolic time step -- */
149 
150 /* -----------------------------------------------------
151  Compute spectral radius (placeholder for now...)
152  -----------------------------------------------------*/
153 
154  D_EXPAND( sprad = 4.*Dts->inv_dtp;,
155  sprad = 8.*Dts->inv_dtp;,
156  sprad = 12.*Dts->inv_dtp;)
157 
158 D_EXPAND( sprad = 2./dt_par; ,
159  sprad = 4./dt_par; ,
160  sprad = 6./dt_par;)
161 
162 /* -----------------------------------------------------
163  Compute number of RKC steps from sprad
164  -----------------------------------------------------*/
165 
166  absh = g_dt;
167  s_RKC = 1 + (int)(sqrt(1.54*absh*sprad + 1));
168  Dts->Nrkc = s_RKC;
169 /* limit dt */
170  if(absh > 0.653*s_RKC*s_RKC/sprad){
171  print1 ("! RKC: outside parameter range\n");
172  QUIT_PLUTO(1);
173  }
174 
175 /* ------------------------------------------------------------------
176  RKC main stage loop
177  ------------------------------------------------------------------ */
178 
179 /* -- define coefficients -- */
180 
181  w_0 = 1. + epsilon/(1.*s_RKC)/(1.*s_RKC);
182  scr1 = w_0*w_0 - 1.;
183  scr2 = sqrt(scr1);
184  arg = s_RKC*log(w_0 + scr2);
185  w_1 = sinh(arg)*scr1/(cosh(arg)*s_RKC*scr2 - w_0*sinh(arg));
186  b_jm1 = 1./(2.*w_0)/(2.*w_0);
187  b_jm2 = b_jm1;
188  mu_tilde = w_1*b_jm1;
189 
190 /* -------------------------------------------------------------
191  First RKC stage here:
192  - take one step in conservative variables,
193  - convert to primitive
194  ------------------------------------------------------------- */
195 
196  DOM_LOOP (k,j,i){
197  for (nv = 0; nv < NVAR; nv++) {
198  Y_jm1[k][j][i][nv] = Y_jm2[k][j][i][nv] = UU_0[k][j][i][nv];
199  }
200  for (nv_indx = 0; nv_indx < nvar_rkc; nv_indx++){
201  nv = var_list[nv_indx];
202  Y_jm1[k][j][i][nv] = Y_jm2[k][j][i][nv] + mu_tilde*absh*F_0[k][j][i][nv];
203  }
204  }
205 
206  KDOM_LOOP(k){
207  JDOM_LOOP(j){
208  ConsToPrim (Y_jm1[k][j], v, IBEG, IEND, flag);
209  IDOM_LOOP(i){
210  for (nv = NVAR; nv--; ){
211  d->Vc[nv][k][j][i] = v[i][nv];
212  }}
213  }}
214 
215 /* -----------------------------------------------------------------
216  Loop over remaining RKC stages s = 2,..,s_RKC steps
217  ----------------------------------------------------------------- */
218 
219 /* -- Initialize Chebyshev polynomials (recursive) -- */
220 
221  Tjm1 = w_0; Tjm2 = 1.0; dTjm1 = 1.0;
222  dTjm2 = 0.0; d2Tjm1 = 0.0; d2Tjm2 = 0.0;
223 
224  for (s = 2; s <= s_RKC; s++){
225 
226  /* ---- compute coefficients ---- */
227 
228  Tj = 2.*w_0*Tjm1 - Tjm2;
229  dTj = 2.*w_0*dTjm1 - dTjm2 + 2.*Tjm1;
230  d2Tj = 2.*w_0*d2Tjm1 - d2Tjm2 + 4.*dTjm1;
231  b_j = d2Tj/dTj/dTj;
232  a_jm1 = 1. - Tjm1*b_jm1;
233  mu_j = 2.*w_0*b_j/b_jm1;
234  nu_j = - b_j/b_jm2;
235  mu_tilde = mu_j*w_1/w_0;
236 
237  /* -- call again boundary and take a new step -- */
238 
239  g_intStage = s;
240  Boundary(d, ALL_DIR, grid);
241  ParabolicRHS (d, F_jm1, 1.0, grid);
242  DOM_LOOP (k,j,i){
243  for (nv_indx = 0; nv_indx < nvar_rkc; nv_indx++){
244  nv = var_list[nv_indx];
245  Y = mu_j*Y_jm1[k][j][i][nv] + nu_j*Y_jm2[k][j][i][nv];
246  Y_jm2[k][j][i][nv] = Y_jm1[k][j][i][nv];
247  Y_jm1[k][j][i][nv] = Y + (1. - mu_j - nu_j)*UU_0[k][j][i][nv]
248  + absh*mu_tilde*(F_jm1[k][j][i][nv]
249  - a_jm1*F_0[k][j][i][nv]);
250  }
251  } /* END DOM_LOOP */
252 
253  /* -- Put parameters of s -> s-1 (outside of dom loop) -- */
254 
255  b_jm2 = b_jm1; b_jm1 = b_j; Tjm2 = Tjm1;
256  Tjm1 = Tj; dTjm2 = dTjm1; dTjm1 = dTj;
257  d2Tjm2 = d2Tjm1; d2Tjm1 = d2Tj;
258 
259  /* ----------------------------------------------------------
260  convert conservative variables to primitive for the next
261  s steps (or timestep if s == s_RKC)
262  ---------------------------------------------------------- */
263 
264  KDOM_LOOP(k){
265  JDOM_LOOP(j){
266  ConsToPrim (Y_jm1[k][j], v, IBEG, IEND, flag);
267  IDOM_LOOP(i){
268  for (nv = NVAR; nv--; ){
269  d->Vc[nv][k][j][i] = v[i][nv];
270  }}
271  }}
272  }/* s loop */
273 }/* func */
#define IDEAL
Definition: pluto.h:45
#define MX3
Definition: mod_defs.h:22
void Boundary(const Data *d, int idim, Grid *grid)
Definition: boundary.c:36
#define EOS
Definition: pluto.h:341
#define KDOM_LOOP(k)
Definition: macros.h:36
#define MX1
Definition: mod_defs.h:20
double **** Data_Arr
Definition: pluto.h:492
DOM_LOOP(k, j, i)
Definition: analysis.c:22
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
tuple scrh
Definition: configure.py:200
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
double g_dt
The current integration time step.
Definition: globals.h:118
double ParabolicRHS(const Data *d, Data_Arr dU, double dt, Grid *grid)
Definition: parabolic_rhs.c:50
#define VISCOSITY
Definition: pluto.h:385
#define Y
void FindShock(const Data *, Grid *)
double inv_dtp
Inverse of diffusion (parabolic) time step .
Definition: structs.h:217
#define JDOM_LOOP(j)
Definition: macros.h:35
#define THERMAL_CONDUCTION
Definition: pluto.h:365
double cfl_par
Courant number for diffusion (STS only).
Definition: structs.h:221
int ConsToPrim(double **ucons, double **uprim, int ibeg, int iend, unsigned char *flag)
Definition: mappers.c:89
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int j
Definition: analysis.c:2
#define MX2
Definition: mod_defs.h:21
if(divB==NULL)
Definition: analysis.c:10
#define ARRAY_4D(nx, ny, nz, nv, type)
Definition: prototypes.h:173
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
#define s
#define BX3
Definition: mod_defs.h:27
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
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
#define RESISTIVITY
Definition: pluto.h:357
int i
Definition: analysis.c:2
#define BX1
Definition: mod_defs.h:25
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define BX2
Definition: mod_defs.h:26
#define RK_CHEBYSHEV
Definition: pluto.h:69
#define NVAR
Definition: pluto.h:609
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define IDOM_LOOP(i)
Definition: macros.h:34
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
#define DIMENSIONS
Definition: definitions_01.h:2
#define ALL_DIR
Definition: pluto.h:196

Here is the call graph for this function:

Here is the caller graph for this function:

Runtime* RuntimeGet ( void  )

Definition at line 498 of file runtime_setup.c.

499 {
500  return &q;
501 }
static Runtime q

Here is the caller graph for this function:

void RuntimeSet ( Runtime runtime)

Store a static copy of the runtime structure for later access.

Definition at line 491 of file runtime_setup.c.

495 {
496  q = *runtime;
497 }
static Runtime q

Here is the caller graph for this function:

int RuntimeSetup ( Runtime runtime,
Cmd_Line cmd_line,
char *  ini_file 
)

Open and parse the runtime initialization file. Assign values to the runtime structure.

Parameters
[out]runtimepointer to a Runtime structure
[in]cmd_linepointer to a Cmd_Line structure (useful, e.g., to resize the domain using the -xres option)
[in]ini_filethe name of the initialization file (default is "pluto.ini") specified with the -i option.

Definition at line 22 of file runtime_setup.c.

34 {
35  int idim, ip, ipos, itype, nlines;
36  char *bound_opt[NOPT], str_var[512], *str;
37  char *glabel[] = {"X1-grid", "X2-grid","X3-grid"};
38  char *bbeg_label[] = {"X1-beg", "X2-beg","X3-beg"};
39  char *bend_label[] = {"X1-end", "X2-end","X3-end"};
40  double dbl_var, rx;
41  Output *output;
42  FILE *fp;
43 
44  for (itype = 0; itype < NOPT; itype++) {
45  bound_opt[itype] = "0000";
46  }
47 
48 /* ---------------------------------------------------
49  available options are given as two set of names;
50  This facilitates when updating the code and
51  people are too lazy to read the manual !
52  --------------------------------------------------- */
53 
54  bound_opt[OUTFLOW] = "outflow";
55  bound_opt[REFLECTIVE] = "reflective";
56  bound_opt[AXISYMMETRIC] = "axisymmetric";
57  bound_opt[EQTSYMMETRIC] = "eqtsymmetric";
58  bound_opt[PERIODIC] = "periodic";
59  bound_opt[SHEARING] = "shearingbox";
60  bound_opt[USERDEF] = "userdef";
61 
62  runtime->log_freq = 1; /* -- default -- */
63 
64  nlines = ParamFileRead(ini_file);
65 
66 /* ------------------------------------------------------------
67  [Grid] Section
68  ------------------------------------------------------------ */
69 
70  for (idim = 0; idim < 3; idim++){
71  runtime->npatch[idim] = atoi(ParamFileGet(glabel[idim], 1));
72  runtime->npoint[idim] = 0;
73 
74  ipos = 1;
75  for (ip = 1; ip <= runtime->npatch[idim]; ip++) {
76 
77  runtime->patch_left_node[idim][ip] = atof(ParamFileGet(glabel[idim], ++ipos));
78  runtime->patch_npoint[idim][ip] = atoi(ParamFileGet(glabel[idim], ++ipos));
79  runtime->npoint[idim] += runtime->patch_npoint[idim][ip];
80  runtime->grid_is_uniform[idim] = 0;
81 
82  strcpy (str_var, ParamFileGet(glabel[idim], ++ipos));
83 /*
84 printf ("%f %d %s\n",runtime->patch_left_node[idim][ip],runtime->patch_npoint[idim][ip],str_var);
85 */
86  if (strcmp(str_var,"u") == 0 || strcmp(str_var,"uniform") == 0) {
87  runtime->patch_type[idim][ip] = UNIFORM_GRID;
88  if (runtime->npatch[idim] == 1) runtime->grid_is_uniform[idim] = 1;
89  }else if (strcmp(str_var,"s") == 0 || strcmp(str_var,"strecthed") == 0) {
90  runtime->patch_type[idim][ip] = STRETCHED_GRID;
91  }else if (strcmp(str_var,"l+") == 0){
92  runtime->patch_type[idim][ip] = LOGARITHMIC_INC_GRID;
93  }else if (strcmp(str_var,"l-") == 0){
94  runtime->patch_type[idim][ip] = LOGARITHMIC_DEC_GRID;
95  }else{
96  printf ("\nSetup: You must specify either 'u', 's', 'l+' or 'l-' as grid-type in %s\n",
97  ini_file);
98  QUIT_PLUTO(1);
99  }
100  }
101 
102  runtime->patch_left_node[idim][ip] = atof(ParamFileGet(glabel[idim], ++ipos));
103 
104  if ( (ipos+1) != (runtime->npatch[idim]*3 + 3)) {
105  printf ("! Setup: domain #%d setup is not properly defined \n", idim);
106  QUIT_PLUTO(1);
107  }
108  if (idim >= DIMENSIONS && runtime->npoint[idim] != 1) {
109  printf ("! Setup: %d point(s) on dim. %d is NOT valid, resetting to 1\n",
110  runtime->npoint[idim],idim+1);
111  runtime->npoint[idim] = 1;
112  runtime->npatch[idim] = 1;
113  runtime->patch_npoint[idim][1] = 1;
114  }
115  }
116 
117 /* ------------------------------------------------------------
118  Change the resolution if cmd_line->xres has been given
119  ------------------------------------------------------------ */
120 
121  if (cmd_line->xres > 1) {
122  rx = (double)cmd_line->xres/(double)runtime->patch_npoint[IDIR][1];
123  for (idim = 0; idim < DIMENSIONS; idim++){
124  if (runtime->npatch[idim] > 1){
125  printf ("! Setup: -xres option works on uniform, single patch grid\n");
126  QUIT_PLUTO(1);
127  }
128 
129  dbl_var = (double)runtime->patch_npoint[idim][1];
130  runtime->patch_npoint[idim][1] = MAX( (int)(dbl_var*rx), 1);
131  dbl_var = (double)runtime->npoint[idim];
132  runtime->npoint[idim] = MAX( (int)(dbl_var*rx), 1);
133  }
134  }
135 
136 /* ------------------------------------------------------------
137  [Time] Section
138  ------------------------------------------------------------ */
139 
140  runtime->cfl = atof(ParamFileGet("CFL", 1));
141 
142  if (ParamExist ("CFL_par")) runtime->cfl_par = atof(ParamFileGet("CFL_par", 1));
143  else runtime->cfl_par = 0.8/(double)DIMENSIONS;
144 
145  if (ParamExist ("rmax_par")) runtime->rmax_par = atof(ParamFileGet("rmax_par", 1));
146  else runtime->rmax_par = 100.0;
147 
148  runtime->cfl_max_var = atof(ParamFileGet("CFL_max_var", 1));
149  runtime->tstop = atof(ParamFileGet("tstop", 1));
150  runtime->first_dt = atof(ParamFileGet("first_dt", 1));
151 
152 /* ------------------------------------------------------------
153  [Solver] Section
154  ------------------------------------------------------------ */
155 
156  sprintf (runtime->solv_type,"%s",ParamFileGet("Solver",1));
157 
158 /* ------------------------------------------------------------
159  [Boundary] Section
160  ------------------------------------------------------------ */
161 
162  for (idim = 0; idim < 3; idim++){
163 
164  str = ParamFileGet(bbeg_label[idim], 1);
165  COMPARE (str, bound_opt[itype], itype);
166  if (itype == NOPT) {
167  printf ("! Setup: don't know how to put left boundary '%s' \n", str);
168  QUIT_PLUTO(1);
169  }
170  runtime->left_bound[idim] = itype;
171  }
172 
173  for (idim = 0; idim < 3; idim++){
174 
175  str = ParamFileGet(bend_label[idim], 1);
176  COMPARE (str, bound_opt[itype], itype);
177  if (itype == NOPT) {
178  printf ("! Setup: don't know how to put left boundary '%s' \n", str);
179  QUIT_PLUTO(1);
180  }
181  runtime->right_bound[idim] = itype;
182  }
183 
184 /* ------------------------------------------------------------
185  [Static Grid Output] Section
186  ------------------------------------------------------------ */
187 
188 #ifndef CHOMBO
189  runtime->user_var = atoi(ParamFileGet("uservar", 1));
190  for (ip = 0; ip < runtime->user_var; ip++){
191  if ( (str = ParamFileGet("uservar", 2 + ip)) != NULL){
192  sprintf (runtime->user_var_name[ip], "%s", str);
193  }else{
194  printf ("! Setup: missing name after user var name '%s'\n",
195  runtime->user_var_name[ip-1]);
196  QUIT_PLUTO(1);
197  }
198  }
199 
200 /* ---- set output directory ---- */
201 
202  sprintf (runtime->output_dir, "%s","./"); /* default value is current directory */
203  if (ParamExist("output_dir")){
204  str = ParamFileGet("output_dir",1);
205  sprintf (runtime->output_dir, "%s",str);
206  }
207 
208 /* -- check if we have write access and if the directory exists -- */
209 
210  sprintf (str_var,"%s/tmp09123.txt",runtime->output_dir); /* -- test file -- */
211  fp = fopen(str_var,"w"); /* -- open test file for writing -- */
212  if (fp == NULL){
213  printf ("! Setup: cannot access directory '%s'.\n", runtime->output_dir);
214  printf ("! Please check that the directory exists\n");
215  printf ("! and you have write permission.\n");
216  QUIT_PLUTO(1);
217  }else{
218  fclose(fp);
219  remove(str_var); /* -- remove file -- */
220  }
221 
222 /* ---- dbl output ---- */
223 
224  ipos = 0;
225  output = runtime->output + (ipos++);
226  output->type = DBL_OUTPUT;
227  output->cgs = 0; /* cannot write .dbl using cgs units */
228  GetOutputFrequency(output, "dbl");
229 
230  sprintf (output->mode,"%s",ParamFileGet("dbl",3));
231  #ifdef USE_ASYNC_IO
232  if ( strcmp(output->mode,"single_file")
233  && strcmp(output->mode,"single_file_async")
234  && strcmp(output->mode,"multiple_files")){
235  printf ("! Setup: expecting 'single_file', 'single_file_async' ");
236  printf ("or 'multiple_files' in dbl output\n");
237  QUIT_PLUTO(1);
238  }
239  #else
240  if ( strcmp(output->mode,"single_file")
241  && strcmp(output->mode,"multiple_files")){
242  printf (
243  "! Setup: expecting 'single_file' or 'multiple_files' in dbl output\n");
244  QUIT_PLUTO(1);
245  }
246  #endif
247 
248  /* ---- flt output ---- */
249 
250  if (ParamExist("flt")){
251  output = runtime->output + (ipos++);
252  output->type = FLT_OUTPUT;
253  GetOutputFrequency(output, "flt");
254 
255  sprintf (output->mode,"%s",ParamFileGet("flt",3));
256  #ifdef USE_ASYNC_IO
257  if ( strcmp(output->mode,"single_file")
258  && strcmp(output->mode,"single_file_async")
259  && strcmp(output->mode,"multiple_files")){
260  printf ("! Setup: expecting 'single_file', 'single_file_async' ");
261  printf ("or 'multiple_files' in flt output\n");
262  QUIT_PLUTO(1);
263  }
264  #else
265  if ( strcmp(output->mode,"single_file")
266  && strcmp(output->mode,"multiple_files")){
267  printf (
268  "! Setup: expecting 'single_file' or 'multiple_files' in flt output\n");
269  QUIT_PLUTO(1);
270  }
271  #endif
272  if (ParamFileHasBoth ("flt","cgs")) output->cgs = 1;
273  else output->cgs = 0;
274  }
275 
276  /* -- hdf5 output -- */
277 
278  if (ParamExist("dbl.h5")){
279  output = runtime->output + (ipos++);
280  output->type = DBL_H5_OUTPUT;
281  output->cgs = 0; /* cannot write .h5 using cgs units */
282  GetOutputFrequency(output, "dbl.h5");
283  }
284  if (ParamExist("flt.h5")){
285  output = runtime->output + (ipos++);
286  output->type = FLT_H5_OUTPUT;
287  output->cgs = 0; /* cannot write .h5 using cgs units */
288  GetOutputFrequency(output, "flt.h5");
289  }
290 
291  /* -- vtk output -- */
292 
293  if (ParamExist ("vtk")){
294  output = runtime->output + (ipos++);
295  output->type = VTK_OUTPUT;
296  GetOutputFrequency(output, "vtk");
297 
298  if (ParamFileGet("vtk",3) == NULL){
299  printf ("! Setup: extra field missing in vtk output\n");
300  QUIT_PLUTO(1);
301  }
302  sprintf (output->mode,"%s",ParamFileGet("vtk",3));
303  if ( strcmp(output->mode,"single_file")
304  && strcmp(output->mode,"multiple_files")){
305  printf ("! Setup: expecting 'single_file' or 'multiple_files' in\n");
306  printf (" vtk output\n");
307  QUIT_PLUTO(1);
308  }
309  if (ParamFileHasBoth ("vtk","cgs")) output->cgs = 1;
310  else output->cgs = 0;
311  }
312 
313  /* -- tab output -- */
314 
315  if (ParamExist ("tab")){
316  output = runtime->output + (ipos++);
317  output->type = TAB_OUTPUT;
318  GetOutputFrequency(output, "tab");
319  if (ParamFileHasBoth ("tab","cgs")) output->cgs = 1;
320  else output->cgs = 0;
321  }
322 
323  /* -- ppm output -- */
324 
325  if (ParamExist ("ppm")){
326  output = runtime->output + (ipos++);
327  output->type = PPM_OUTPUT;
328  output->cgs = 0; /* Cannot write ppm in cgs units */
329  GetOutputFrequency(output, "ppm");
330  }
331 
332  /* -- png output -- */
333 
334  if (ParamExist ("png")){
335  output = runtime->output + (ipos++);
336  output->type = PNG_OUTPUT;
337  output->cgs = 0; /* Cannot write png in cgs units */
338  GetOutputFrequency(output, "png");
339  }
340 
341 
342  /* -- log frequency -- */
343 
344  runtime->log_freq = atoi(ParamFileGet("log", 1));
345  runtime->log_freq = MAX(runtime->log_freq, 1);
346 
347  /* -- set default for remaining output type -- */
348 
349  while (ipos < MAX_OUTPUT_TYPES){
350  output = runtime->output + ipos;
351  output->type = -1;
352  output->cgs = 0;
353  output->dt = -1.0;
354  output->dn = -1;
355  output->dclock = -1.0;
356  ipos++;
357  }
358 
359  /* -- analysis -- */
360 
361  if (ParamExist ("analysis")){
362  runtime->anl_dt = atof(ParamFileGet("analysis", 1));
363  runtime->anl_dn = atoi(ParamFileGet("analysis", 2));
364  }else{
365  runtime->anl_dt = -1.0; /* -- defaults -- */
366  runtime->anl_dn = -1;
367  }
368 #endif
369 
370 #ifdef CHOMBO
371 
372 /* ------------------------------------------------------------
373  [Chombo HDF5 output] section
374  ------------------------------------------------------------ */
375 
376 /* ---- set output directory ---- */
377 
378  sprintf (runtime->output_dir, "%s","./"); /* default value is current directory */
379  if (ParamExist("Output_dir")){
380  str = ParamFileGet("Output_dir",1);
381  sprintf (runtime->output_dir, "%s",str);
382  }
383 
384 /* -- check if we have write access and if the directory exists -- */
385 
386  sprintf (str_var,"%s/tmp09123.txt",runtime->output_dir); /* -- test file -- */
387  fp = fopen(str_var,"w"); /* -- open test file for writing -- */
388  if (fp == NULL){
389  printf ("! Setup: cannot access directory '%s'.\n", runtime->output_dir);
390  printf ("! Please check that the directory exists\n");
391  printf ("! and you have write permission.\n");
392  QUIT_PLUTO(1);
393  }else{
394  fclose(fp);
395  remove(str_var); /* -- remove file -- */
396  }
397 #endif
398 
399 /* ------------------------------------------------------------
400  [Parameters] Section
401  ------------------------------------------------------------ */
402 
403  fp = fopen(ini_file,"r");
404 
405 /* -- find position at "[Parameters" -- */
406 
407  for (ipos = 0; ipos <= nlines; ipos++){
408  fgets(str_var, 512, fp);
409 
410  if (strlen(str_var) > 0) {
411  str = strtok (str_var,"]");
412  if (strcmp(str,"[Parameters") == 0) break;
413  }
414  }
415 
416  fgets(str_var, 512, fp);
417 
418  for (ip = 0; ip < USER_DEF_PARAMETERS; ip++){
419  fscanf (fp,"%s \n", str_var);
420  dbl_var = atof(ParamFileGet(str_var,1));
421  runtime->aux[ip] = dbl_var;
422  fgets(str_var, sizeof(str_var), fp); /* use fgets to advance to next line */
423  }
424  fclose(fp);
425 
426  return(0);
427 }
#define SHEARING
Definition: pluto.h:138
#define MAX(a, b)
Definition: macros.h:101
int user_var
The number of additional user-variables being held in memory and written to disk. ...
Definition: structs.h:264
#define USER_DEF_PARAMETERS
int ParamExist(const char *label)
Definition: parse_file.c:159
int ParamFileHasBoth(const char *label1, const char *label2)
Definition: parse_file.c:129
#define FLT_H5_OUTPUT
Definition: pluto.h:83
#define PPM_OUTPUT
Definition: pluto.h:85
int npoint[3]
Global number of zones in the interior domain.
Definition: structs.h:256
Output output[MAX_OUTPUT_TYPES]
Definition: structs.h:272
char output_dir[256]
The name of the output directory (output_dir for static PLUTO, Output_dir for PLUTO-Chombo) ...
Definition: structs.h:269
#define LOGARITHMIC_INC_GRID
Definition: pluto.h:40
int left_bound[3]
Array of left boundary types.
Definition: structs.h:257
#define UNIFORM_GRID
Definition: pluto.h:38
int xres
Definition: structs.h:22
char user_var_name[128][128]
Definition: structs.h:268
static int nlines
The total number of lines (including empty ones) contained in the file.
Definition: parse_file.c:47
int grid_is_uniform[3]
Definition: structs.h:259
#define LOGARITHMIC_DEC_GRID
Definition: pluto.h:41
int cgs
when set to 1 saves data in c.g.s units
Definition: structs.h:236
int right_bound[3]
Array of right boundary types.
Definition: structs.h:258
int log_freq
The log frequency (log)
Definition: structs.h:263
void GetOutputFrequency(Output *output, const char *output_format)
double anl_dt
Time step increment for Analysis() ( analysis (double) )
Definition: structs.h:282
double rmax_par
(STS) max ratio between current time step and parabolic time step
Definition: structs.h:278
double dt
time increment between outputs - one per output
Definition: structs.h:245
double patch_left_node[5][16]
Definition: structs.h:273
#define COMPARE(s1, s2, ii)
Definition: runtime_setup.c:18
#define VTK_OUTPUT
Definition: pluto.h:81
#define IDIR
Definition: pluto.h:193
#define USERDEF
Definition: pluto.h:139
#define DBL_H5_OUTPUT
Definition: pluto.h:82
char solv_type[64]
The Riemann solver (Solver)
Definition: structs.h:267
double aux[32]
Definition: structs.h:284
#define STRETCHED_GRID
Definition: pluto.h:39
#define MAX_OUTPUT_TYPES
Definition: pluto.h:95
int ParamFileRead(char *fname)
Definition: parse_file.c:53
double tstop
The final integration time (tstop)
Definition: structs.h:280
#define TAB_OUTPUT
Definition: pluto.h:84
#define FLT_OUTPUT
Definition: pluto.h:80
#define NOPT
Definition: runtime_setup.c:15
#define OUTFLOW
Definition: pluto.h:133
#define REFLECTIVE
Definition: pluto.h:134
int patch_npoint[5][16]
Definition: structs.h:261
#define DBL_OUTPUT
Definition: pluto.h:79
FILE * fp
Definition: analysis.c:7
char mode[32]
single or multiple files - one per output
Definition: structs.h:241
int patch_type[5][16]
Definition: structs.h:262
int npatch[5]
The number of grid patches.
Definition: structs.h:260
int type
output format (DBL, FLT, ...) - one per output
Definition: structs.h:233
#define AXISYMMETRIC
Definition: pluto.h:135
double first_dt
The initial time step (first_dt)
Definition: structs.h:281
#define PERIODIC
Definition: pluto.h:137
double cfl_par
(STS) parabolic cfl number
Definition: structs.h:277
char * ParamFileGet(const char *label, int pos)
Definition: parse_file.c:86
#define EQTSYMMETRIC
Definition: pluto.h:136
double cfl_max_var
Maximum increment between consecutive time steps (CFL_max_var).
Definition: structs.h:275
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
int anl_dn
Definition: structs.h:266
#define PNG_OUTPUT
Definition: pluto.h:86
#define DIMENSIONS
Definition: definitions_01.h:2
double dclock
time increment in clock hours - one per output
Definition: structs.h:246
int dn
step increment between outputs - one per output
Definition: structs.h:238
double cfl
Hyperbolic cfl number (CFL)
Definition: structs.h:274

Here is the call graph for this function:

Here is the caller graph for this function:

void SetColorMap ( unsigned char *  ,
unsigned char *  ,
unsigned char *  ,
char *   
)

Definition at line 11 of file colortable.c.

19 {
20  int ii;
21 
22  if (!strcmp(map_name,"bw")) ct_bw(r,g,b);
23  else if (!strcmp(map_name,"red")) ct_red(r,g,b);
24  else if (!strcmp(map_name,"br")) ct_br(r,g,b);
25  else if (!strcmp(map_name,"blue")) ct_blue(r,g,b);
26  else if (!strcmp(map_name,"green")) ct_green(r,g,b);
27  else if (!strcmp(map_name,"jet")) ct_jet(r,g,b);
28  else {
29  printf (" ? Colormap is not defined, using B&W\n");
30  ct_bw(r,g,b);
31  }
32 
33 }
void ct_jet(unsigned char *r, unsigned char *g, unsigned char *b)
Definition: colortable.c:1359
void ct_br(unsigned char *, unsigned char *, unsigned char *)
Definition: colortable.c:564
void ct_red(unsigned char *, unsigned char *, unsigned char *)
Definition: colortable.c:300
void ct_green(unsigned char *, unsigned char *, unsigned char *)
Definition: colortable.c:1093
void ct_blue(unsigned char *, unsigned char *, unsigned char *)
Definition: colortable.c:829
void ct_bw(unsigned char *, unsigned char *, unsigned char *)
Definition: colortable.c:35

Here is the call graph for this function:

Here is the caller graph for this function:

void SetDefaultVarNames ( Output )

Definition at line 4 of file var_names.c.

13 {
14  int nv;
15 
16 /* ----------------------------------------------
17  Physics module file names;
18  these pertain to the physics module ONLY
19  ---------------------------------------------- */
20 
21  output->var_name[RHO] = "rho";
22  EXPAND(output->var_name[VX1] = "vx1"; ,
23  output->var_name[VX2] = "vx2"; ,
24  output->var_name[VX3] = "vx3";)
25 #if HAVE_ENERGY
26  output->var_name[PRS] = "prs";
27 #endif
28 
29 #if PHYSICS == MHD || PHYSICS == RMHD
30  EXPAND(output->var_name[BX1] = "bx1"; ,
31  output->var_name[BX2] = "bx2"; ,
32  output->var_name[BX3] = "bx3";)
33 #endif
34 
35  /* (staggered field names are set in SetOutput) */
36 
37 #ifdef GLM_MHD
38  output->var_name[PSI_GLM] = "psi_glm";
39 #endif
40 
41 /* ------------------------------------------------
42  Dust
43  ------------------------------------------------ */
44 
45 #if DUST == YES
46  output->var_name[RHO_D] = "rho_d";
47  EXPAND(output->var_name[VX1_D] = "vx1_d"; ,
48  output->var_name[VX2_D] = "vx2_d"; ,
49  output->var_name[VX3_D] = "vx3_d";)
50 #endif
51 
52 /* ------------------------------------------------
53  Tracers
54  ------------------------------------------------ */
55 
56  NTRACER_LOOP(nv) sprintf (output->var_name[nv],"tr%d",nv - TRC + 1);
57 
58  #if ENTROPY_SWITCH
59  sprintf (output->var_name[ENTR],"entropy");
60  #endif
61 
62 /* ------------------------------------------------
63  Cooling vars
64  ------------------------------------------------ */
65 
66 #if COOLING == MINEq
67  {
68  static char *ion_name[] = {"X_HI", "X_HeI", "X_HeII"
69  C_EXPAND("X_CI","X_CII", "X_CIII", "X_CIV", "X_CV")
70  N_EXPAND("X_NI","X_NII", "X_NIII", "X_NIV", "X_NV")
71  O_EXPAND("X_OI","X_OII", "X_OIII", "X_OIV", "X_OV")
72  Ne_EXPAND("X_NeI","X_NeII", "X_NeIII", "X_NeIV", "X_NeV")
73  S_EXPAND("X_SI","X_SI I", "X_SIII", "X_SIV", "X_SV")
74  Fe_EXPAND("X_FeI", "X_FeII", "X_FeIII")};
75 
76  NIONS_LOOP(nv) output->var_name[nv] = ion_name[nv-NFLX];
77  }
78 #elif COOLING == SNEq
79 
80  output->var_name[X_HI] = "X_HI";
81 
82 #elif COOLING == H2_COOL
83  {
84  static char *molnames[] = {"X_HI", "X_H2", "X_HII"};
85  NIONS_LOOP(nv) output->var_name[nv] = molnames[nv-NFLX];
86  }
87 
88 #endif
89 
90 }
#define NIONS_LOOP(n)
Definition: pluto.h:614
#define VX2
Definition: mod_defs.h:29
#define RHO
Definition: mod_defs.h:19
#define PSI_GLM
Definition: mod_defs.h:34
#define NTRACER_LOOP(n)
Definition: pluto.h:615
#define TRC
Definition: pluto.h:581
#define S_EXPAND(a, b, c, d, e)
Definition: cooling.h:83
#define VX1
Definition: mod_defs.h:28
#define N_EXPAND(a, b, c, d, e)
Definition: cooling.h:41
#define NFLX
Definition: mod_defs.h:32
#define C_EXPAND(a, b, c, d, e)
Definition: cooling.h:27
Definition: cooling.h:110
#define BX3
Definition: mod_defs.h:27
#define O_EXPAND(a, b, c, d, e)
Definition: cooling.h:55
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#define BX2
Definition: mod_defs.h:26
#define Fe_EXPAND(a, b, c)
Definition: cooling.h:91

Here is the caller graph for this function:

int SetDumpVar ( char *  var_name,
int  out_type,
int  flag 
)

Include ('flag == YES') or exclude ('flag == NO') the variable associated to 'var_name' in or from the output type 'out_type'. If 'out_type' corresponds to an image (ppm or png), create a correspdonding Image structure.

Parameters
[in]var_namethe name of the variable (e.g. "rho", "vx1",...)
[in]out_typeselect the output type (e.g., DBL_OUTPUT, VTK_OUTPUT, and so forth)
[in]flagan integer values (YES/NO).

Definition at line 211 of file set_output.c.

224 {
225  int k, nv;
226  Output *output;
227 
228  for (k = 0; k < MAX_OUTPUT_TYPES; k++){
229  output = all_outputs + k;
230  if (output->type == out_type) break;
231  }
232 
233  for (nv = output->nvar; nv--; ) {
234  if (strcmp(output->var_name[nv], var_name) == 0) {
235  output->dump_var[nv] = flag;
236  if (flag == YES){
237  if (out_type == PPM_OUTPUT || out_type == PNG_OUTPUT){
238  CreateImage (var_name);
239  }
240  }
241  return(0);
242  }
243  }
244 
245  print1 ("! var_name '%s' cannot be set/unset for writing\n",var_name);
246  return(1);
247 
248 }
#define PPM_OUTPUT
Definition: pluto.h:85
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
#define YES
Definition: pluto.h:25
int k
Definition: analysis.c:2
void CreateImage(char *)
Definition: set_image.c:8
int nvar
tot.
Definition: structs.h:234
static Output * all_outputs
Definition: set_output.c:35
#define MAX_OUTPUT_TYPES
Definition: pluto.h:95
int * dump_var
select vars being written - one per output
Definition: structs.h:240
int type
output format (DBL, FLT, ...) - one per output
Definition: structs.h:233
#define PNG_OUTPUT
Definition: pluto.h:86
char ** var_name
variable names - same for all
Definition: structs.h:242

Here is the call graph for this function:

Here is the caller graph for this function:

void SetGrid ( Runtime rtime,
Grid GXYZ 
)
Parameters
[in]rtimepointer to a Runtime structure
[out]GXYZpointer to array of Grid structures

Definition at line 21 of file set_grid.c.

28 {
29  int i, idim;
30  int iL, iR, ngh;
31  char fname[512];
32  double *dx, *xlft, *xrgt;
33  Grid *G;
34  FILE *fg;
35  double xpatch_lft, xpatch_rgt;
36 
37  InitializeGrid(rtime, GXYZ);
38 
39  i = MAX(rtime->npoint[0], MAX(rtime->npoint[1], rtime->npoint[2]));
40  dx = ARRAY_1D(i + 2, double);
41  xlft = ARRAY_1D(i + 2, double);
42  xrgt = ARRAY_1D(i + 2, double);
43 
44  for (idim = 0; idim < 3; idim++) {
45 
46  G = GXYZ + idim;
47  ngh = G->nghost;
48 
49  iL = ngh - 1;
50  MakeGrid (idim, rtime, xlft, xrgt, dx);
51 /*MakeGrid (idim, rtime, G->xl_glob + iL, G->xr_glob + iL, G->dx_glob + iL); */
52 
53  /* ---- Assign values to grid structure members ---- */
54 
55  for (i = 1; i <= rtime->npoint[idim]; i++) {
56  G->dx_glob[i + ngh - 1] = dx[i];
57  G->xl_glob[i + ngh - 1] = xlft[i];
58  G->xr_glob[i + ngh - 1] = xrgt[i];
59  }
60 
61  iL = ngh;
62  iR = rtime->npoint[idim] + ngh - 1;
63  if (idim < DIMENSIONS){
64  G->xr_glob[iL - 1] = G->xl_glob[iL];
65  G->xl_glob[iR + 1] = G->xr_glob[iR];
66  }
67 /* ---- fill boundary values by copying adjacent cells ---- */
68 
69  for (i = 0; i < ngh; i++) {
70 
71  /* ---- left boundary ---- */
72 
73  G->dx_glob[i] = G->dx_glob[iL];
74  G->xl_glob[i] = G->xl_glob[iL] - (ngh - i)*G->dx_glob[iL];
75  G->xr_glob[i] = G->xl_glob[i] + G->dx_glob[iL];
76 
77  /* ---- right boundary ---- */
78 
79  G->dx_glob[iR + i + 1] = G->dx_glob[iR];
80  G->xl_glob[iR + i + 1] = G->xl_glob[iR] + (i + 1.0)*G->dx_glob[iR];
81  G->xr_glob[iR + i + 1] = G->xl_glob[iR] + (i + 2.0)*G->dx_glob[iR];
82  }
83 
84 /* ---- define geometrical cell center ---- */
85 
86  for (i = 0; i <= iR + ngh; i++) {
87  G->x_glob[i] = 0.5*(G->xl_glob[i] + G->xr_glob[i]);
88  }
89 
90 /* ---- define leftmost and rightmost domain extrema ---- */
91 
92  G->xi = G->xl_glob[iL];
93  G->xf = G->xr_glob[iR];
94 
95  g_domBeg[idim] = G->xl_glob[iL];
96  g_domEnd[idim] = G->xr_glob[iR];
97  }
98 
99 /* ---- free memory ---- */
100 
101  FreeArray1D(dx);
102  FreeArray1D(xlft);
103  FreeArray1D(xrgt);
104 
105 /* ---------------------------------------------------------------------
106  Write grid file
107  --------------------------------------------------------------------- */
108 
109  sprintf (fname,"%s/grid.out", rtime->output_dir);
110 #ifdef PLUTO3_Grid
111  fg = fopen(fname,"w");
112  for (idim = 0; idim < 3; idim++) {
113  G = GXYZ + idim;
114  ngh = G->nghost;
115  iL = G->gbeg;
116  iR = G->gend;
117 
118  fprintf (fg, "%d \n", iR - iL + 1);
119  for (i = iL; i <= iR; i++) {
120  fprintf (fg, " %d %12.6e %12.6e %12.6e %12.6e\n",
121  i-ngh+1, G->xl_glob[i], G->x_glob[i], G->xr_glob[i], G->dx_glob[i]);
122  }
123  }
124  fclose(fg);
125 #else
126  if (prank == 0){
127  time_t time_now;
128  time(&time_now);
129 
130  fg = fopen(fname,"w");
131  fprintf (fg, "# ******************************************************\n");
132  #ifdef CHOMBO
133  fprintf (fg, "# PLUTO-Chombo %s (Base) Grid File\n",PLUTO_VERSION);
134  #else
135  fprintf (fg, "# PLUTO %s Grid File\n",PLUTO_VERSION);
136  #endif
137 
138  fprintf (fg, "# Generated on %s",asctime(localtime(&time_now)));
139 
140 /* fprintf (fg, "# %s\n", getenv("PWD")); */
141 
142  fprintf (fg, "# \n");
143  fprintf (fg,"# DIMENSIONS: %d\n",DIMENSIONS);
144  #if GEOMETRY == CARTESIAN
145  fprintf (fg, "# GEOMETRY: CARTESIAN\n");
146  #elif GEOMETRY == CYLINDRICAL
147  fprintf (fg, "# GEOMETRY: CYLINDRICAL\n");
148  #elif GEOMETRY == POLAR
149  fprintf (fg, "# GEOMETRY: POLAR\n");
150  #elif GEOMETRY == SPHERICAL
151  fprintf (fg, "# GEOMETRY: SPHERICAL\n");
152  #endif
153  for (idim = 0; idim < DIMENSIONS; idim++){
154  fprintf (fg, "# X%d: [% f, % f], %d point(s), %d ghosts\n", idim+1,
155  g_domBeg[idim], g_domEnd[idim],
156  GXYZ[idim].np_int_glob, GXYZ[idim].nghost);
157  }
158  fprintf (fg, "# ******************************************************\n");
159  for (idim = 0; idim < 3; idim++) {
160  G = GXYZ + idim;
161  ngh = G->nghost;
162  iL = G->gbeg;
163  iR = G->gend;
164 
165  fprintf (fg, "%d \n", iR - iL + 1);
166  for (i = iL; i <= iR; i++) {
167  fprintf (fg, " %d %18.12e %18.12e\n",
168  i-ngh+1, G->xl_glob[i], G->xr_glob[i]);
169  }
170  }
171  fclose(fg);
172  }
173 #endif
174 
175 /* ---- define geometry factors, vol, area, etc... ---- */
176 
177  MakeGeometry(GXYZ);
178 
179 /* ----------------------------------------
180  print domain specifications
181  ---------------------------------------- */
182 
183  for (idim = 0; idim < DIMENSIONS; idim++){
184  print1 (" X%d: [% f, % f], %d point(s), %d ghosts\n", idim+1,
185  g_domBeg[idim], g_domEnd[idim],
186  GXYZ[idim].np_int_glob, GXYZ[idim].nghost);
187  }
188 }
void FreeArray1D(void *v)
Definition: arrays.c:37
#define MAX(a, b)
Definition: macros.h:101
void MakeGeometry(Grid *)
Definition: set_geometry.c:16
int npoint[3]
Global number of zones in the interior domain.
Definition: structs.h:256
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
static void InitializeGrid(Runtime *, Grid *)
Definition: set_grid.c:215
char output_dir[256]
The name of the output directory (output_dir for static PLUTO, Output_dir for PLUTO-Chombo) ...
Definition: structs.h:269
int np_int_glob
Total number of points in the global domain (boundaries excluded).
Definition: structs.h:98
double * x_glob
Cell geometrical central points.
Definition: structs.h:80
double * dx_glob
Cell size.
Definition: structs.h:83
#define PLUTO_VERSION
Definition: pluto.h:16
double * xr_glob
Cell right interface.
Definition: structs.h:81
double xf
Leftmost and rightmost point in the local domain.
Definition: structs.h:79
int gend
Global end index for the global array.
Definition: structs.h:114
double * dx
Definition: structs.h:83
int prank
Processor rank.
Definition: globals.h:33
static void MakeGrid(int, Runtime *, double *, double *, double *)
Definition: set_grid.c:273
Definition: structs.h:78
int gbeg
Global start index for the global array.
Definition: structs.h:113
int nghost
Number of ghost zones.
Definition: structs.h:104
double * xl_glob
Cell left interface.
Definition: structs.h:82
double g_domBeg[3]
Lower limits of the computational domain.
Definition: globals.h:125
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
int i
Definition: analysis.c:2
double g_domEnd[3]
Upper limits of the computational domain.
Definition: globals.h:126
double xi
Definition: structs.h:79
#define DIMENSIONS
Definition: definitions_01.h:2

Here is the call graph for this function:

Here is the caller graph for this function:

void SetIndexes ( Index indx,
Grid grid 
)

Set vector indices and integration index range.

Parameters
[out]indxpointer to an Index structure
[in]gridpointer to an array of Grid structures

Definition at line 49 of file set_indexes.c.

57 {
58  IBEG = grid[IDIR].lbeg; IEND = grid[IDIR].lend;
59  JBEG = grid[JDIR].lbeg; JEND = grid[JDIR].lend;
60  KBEG = grid[KDIR].lbeg; KEND = grid[KDIR].lend;
61 
62  if (g_dir == IDIR) { /* -- Order: X-Y-Z {in,t1,t2 = i,j,k} -- */
63 
64  EXPAND(VXn = MXn = VX1; ,
65  VXt = MXt = VX2; ,
66  VXb = MXb = VX3;)
67 #if PHYSICS == MHD || PHYSICS == RMHD
68  EXPAND(BXn = BX1; ,
69  BXt = BX2; ,
70  BXb = BX3;)
71 #endif
72 #if DUST == YES
73  EXPAND(VXn_D = MXn_D = VX1_D; ,
74  VXt_D = MXt_D = VX2_D; ,
75  VXb_D = MXb_D = VX3_D;)
76 #endif
77 
78  indx->ntot = grid[IDIR].np_tot;
79  indx->beg = IBEG; indx->end = IEND;
80  indx->t1_beg = JBEG; indx->t1_end = JEND;
81  indx->t2_beg = KBEG; indx->t2_end = KEND;
82 
83  }else if (g_dir == JDIR){ /* -- Order: Y-X-Z {in,t1,t2 = j,i,k} -- */
84 
85  EXPAND(VXn = MXn = VX2; ,
86  VXt = MXt = VX1; ,
87  VXb = MXb = VX3;)
88 #if PHYSICS == MHD || PHYSICS == RMHD
89  EXPAND(BXn = BX2; ,
90  BXt = BX1; ,
91  BXb = BX3;)
92 #endif
93 #if DUST == YES
94  EXPAND(VXn_D = MXn_D = VX2_D; ,
95  VXt_D = MXt_D = VX1_D; ,
96  VXb_D = MXb_D = VX3_D;)
97 #endif
98 
99  indx->ntot = grid[JDIR].np_tot;
100  indx->beg = JBEG; indx->end = JEND;
101  indx->t1_beg = IBEG; indx->t1_end = IEND;
102  indx->t2_beg = KBEG; indx->t2_end = KEND;
103 
104  }else if (g_dir == KDIR){ /* -- Order: Z-X-Y {in,t1,t2 = k,i,j} -- */
105 
106  VXn = MXn = VX3;
107  VXt = MXt = VX1;
108  VXb = MXb = VX2;
109  #if PHYSICS == MHD || PHYSICS == RMHD
110  BXn = BX3;
111  BXt = BX1;
112  BXb = BX2;
113  #endif
114 #if DUST == YES
115  EXPAND(VXn_D = MXn_D = VX3_D; ,
116  VXt_D = MXt_D = VX1_D; ,
117  VXb_D = MXb_D = VX2_D;)
118 #endif
119 
120  indx->ntot = grid[KDIR].np_tot;
121  indx->beg = KBEG; indx->end = KEND;
122  indx->t1_beg = IBEG; indx->t1_end = IEND;
123  indx->t2_beg = JBEG; indx->t2_end = JEND;
124 
125  }
126 
127 /* -------------------------------------------------------
128  Expand grid one further zone to account for proper
129  flux computation. This is necessary to obtain the EMF
130  in the boundary zones and to get transverse rhs for
131  corner coupled states.
132  ------------------------------------------------------- */
133 
134  #ifdef STAGGERED_MHD
135  D_EXPAND( ; ,
136  indx->t1_beg--; indx->t1_end++; ,
137  indx->t2_beg--; indx->t2_end++;)
138  #ifdef CTU
139  if (g_intStage == 1){
140  indx->beg--;
141  indx->end++;
142  D_EXPAND( ; ,
143  indx->t1_beg--; indx->t1_end++; ,
144  indx->t2_beg--; indx->t2_end++;)
145  }
146  #endif
147  #else
148  #ifdef CTU
149  if (g_intStage == 1){
150  #if (PARABOLIC_FLUX & EXPLICIT)
151  indx->beg--;
152  indx->end++;
153  #endif
154  D_EXPAND( ,
155  indx->t1_beg--; indx->t1_end++; ,
156  indx->t2_beg--; indx->t2_end++;)
157  }
158  #endif
159  #endif
160 }
#define VX2
Definition: mod_defs.h:29
int MXn_D
Definition: globals.h:78
int ntot
Definition: structs.h:318
int VXn_D
Definition: globals.h:77
int t2_end
Definition: structs.h:320
#define YES
Definition: pluto.h:25
int t1_end
Definition: structs.h:319
int VXt_D
Definition: globals.h:77
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
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
#define VX1
Definition: mod_defs.h:28
#define KDIR
Definition: pluto.h:195
int VXb_D
Definition: globals.h:77
int t2_beg
Definition: structs.h:320
int VXb
Definition: globals.h:73
int BXn
Definition: globals.h:75
int t1_beg
Definition: structs.h:319
int MXt
Definition: globals.h:74
int MXb_D
Definition: globals.h:78
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
#define PHYSICS
Definition: definitions_01.h:1
int VXt
Definition: globals.h:73
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int MXn
Definition: globals.h:74
int VXn
Definition: globals.h:73
#define DUST
Definition: pluto.h:333
int beg
Definition: structs.h:318
#define MHD
Definition: pluto.h:111
#define BX3
Definition: mod_defs.h:27
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
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
int MXt_D
Definition: globals.h:78
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
#define BX2
Definition: mod_defs.h:26
int np_tot
Total number of points in the local domain (boundaries included).
Definition: structs.h:100
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
#define JDIR
Definition: pluto.h:194
int BXt
Definition: globals.h:75
int end
Definition: structs.h:318
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
int BXb
Definition: globals.h:75
#define RMHD
Definition: pluto.h:112
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
int MXb
Definition: globals.h:74

Here is the call graph for this function:

Here is the caller graph for this function:

void SetJetDomain ( const Data d,
int  dir,
int  log_freq,
Grid grid 
)

Adjust the size of computational domain by reducing the final computationa index in the direction of propagation.

Parameters
[in]dpointer to Data structure
[in]dirthe direction of propagation
[in]log_freqthe output log frequency
[in,out]gridpointer to array of Grid structures

Definition at line 29 of file jet_domain.c.

41 {
42  int i, j, k, ngh;
43  int n, n_glob;
44  static int first_call = 1;
45  double ***pr, ***dn, dp;
46 
47  dn = d->Vc[RHO];
48  #if HAVE_ENERGY
49  pr = d->Vc[PRS];
50  #else
51  pr = d->Vc[RHO];
52  #endif
53 
54  ngh = grid[dir].nghost;
55 
56 /* -- save original domain offsets
57  and return for the first time -- */
58 
59  if (first_call){
60  if (dir == IDIR) {
61  jd_nbeg = IBEG; jd_nend = IEND;
63  }else if (dir == JDIR){
64  jd_nbeg = JBEG; jd_nend = JEND;
66  }else if (dir == KDIR){
67  jd_nbeg = KBEG; jd_nend = KEND;
69  }
70 
71  rbound = grid[dir].rbound;
72  first_call = 0;
73  return;
74  }
75 
76 /* --------------------------------------
77  find where grad(p) is not zero and
78  add safety guard cells
79  -------------------------------------- */
80 
81  n = GetRightmostIndex(dir, pr) + 2*ngh;
82 
83  if (n < jd_nbeg + ngh) n = jd_nbeg + ngh;
84  if (n > jd_nend) n = jd_nend;
85 
86  #ifdef PARALLEL
87  MPI_Allreduce (&n, &n_glob, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
88  n = n_glob;
89  #endif
90 
91  if (g_stepNumber%log_freq==0){
92 /* print1 ("- SetJetDomain: index %d / %d\n",n,jd_nend); */
93  }
94 
95 /* ------------------------------------------------------------------
96  Change global integer variables giving the rightmost integration
97  indexes. Also, suppress the rightmost physics boundary (rbound)
98  if solution has not yet reached it.
99  ------------------------------------------------------------------ */
100 
101  if (dir == IDIR) {
102  IEND = grid[IDIR].lend = n;
103  NX1_TOT = IEND + ngh;
104  NX1 = IEND - ngh;
105 
106  grid[IDIR].rbound = rbound;
107  if (jd_nend != IEND) grid[IDIR].rbound = 0;
108 
109  } else if (dir == JDIR){
110 
111  JEND = grid[JDIR].lend = n;
112  NX2_TOT = JEND + ngh;
113  NX2 = JEND - ngh;
114  grid[JDIR].rbound = rbound;
115  if (jd_nend != JEND) grid[JDIR].rbound = 0;
116 
117  }else if (dir == KDIR){
118 
119  KEND = grid[KDIR].lend = n;
120  NX3_TOT = KEND + ngh;
121  NX3 = KEND - ngh;
122 
123  grid[KDIR].rbound = rbound;
124  if (jd_nend != KEND) grid[KDIR].rbound = 0;
125  }
126 
127 /* ------------------------------------------------------
128  Recompute RBox(es) after indices have been changed
129  ------------------------------------------------------ */
130 
131  SetRBox();
132 
133 /*
134  print1 ("Box = %d/%d\n", n, jd_nend);
135  {
136  double t0, t1, i0, i1;
137  FILE *fp;
138  t0 = g_time;
139  t1 = t0 + g_dt;
140  i0 = (int)(t0/0.5);
141  i1 = (int)(t1/0.5);
142 
143  if (i0 != i1){
144  fp = fopen("box.out","w");
145  fprintf (fp,"%f %f %f %f\n",0.0, grid[IDIR].x[IEND],
146  0.0, grid[JDIR].x[JEND]);
147  fclose(fp);
148  }
149  }
150 */
151 }
static int jd_ntot
Definition: jet_domain.c:25
static int jd_npt
Definition: jet_domain.c:25
static int n
Definition: analysis.c:3
static int rbound
Definition: jet_domain.c:25
long int NX1
Number of interior zones in the X1 directions (boundaries excluded) for the local processor...
Definition: globals.h:48
#define RHO
Definition: mod_defs.h:19
int rbound
Same as lbound, but for the right edge of the grid.
Definition: structs.h:112
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
int lend
Local end index for the local array.
Definition: structs.h:118
#define KDIR
Definition: pluto.h:195
long int g_stepNumber
Gives the current integration step number.
Definition: globals.h:97
long int NX2
Number of interior zones in the X2 directions (boundaries excluded) for the local processor...
Definition: globals.h:50
#define IDIR
Definition: pluto.h:193
static int GetRightmostIndex(int, double ***)
Definition: jet_domain.c:194
static int jd_nend
Definition: jet_domain.c:25
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int j
Definition: analysis.c:2
int nghost
Number of ghost zones.
Definition: structs.h:104
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
void SetRBox(void)
Definition: rbox.c:33
int i
Definition: analysis.c:2
static int jd_nbeg
Definition: jet_domain.c:25
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
#define JDIR
Definition: pluto.h:194
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int NX3
Number of interior zones in the X3 directions (boundaries excluded) for the local processor...
Definition: globals.h:52
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35

Here is the call graph for this function:

Here is the caller graph for this function:

int SetLogFile ( char *  output_dir,
Cmd_Line cmd 
)

Set the name of the log file and open in write or append mode depending on whether restart is enabled or not.

Parameters
[in]output_dirthe name of the output directory
[in]cmdpointer to cmd line option structure.

Definition at line 321 of file tools.c.

330 {
331 #if PRINT_TO_FILE == YES
332  FILE *fl;
333 
334 /* ------------------------------------------------
335  All processors set log file name
336  ------------------------------------------------ */
337 
338  sprintf (log_file_name, "%s/pluto.log",output_dir);
339 
340 /* ------------------------------------------------
341  Proc. #0 opens log file for writing if
342  -restart or -h5restart have not been given.
343  Otherwise, open in append mode.
344  ------------------------------------------------ */
345 
346  if (prank == 0){
347  if (cmd->restart == NO && cmd->h5restart == NO){
348  fl = fopen(log_file_name,"w");
349  }else{
350  fl = fopen(log_file_name,"aw");
351  }
352 
353  /* -- check that we have a valid directory name -- */
354 
355  if (fl == NULL){
356  printf ("! SetLogFile: pluto.log cannot be written.\n");
357  QUIT_PLUTO(1);
358  }
359  fprintf(fl,"\n");
360  fclose(fl);
361  }
362 #endif
363 }
static char log_file_name[512]
Definition: tools.c:318
int h5restart
Definition: structs.h:13
int prank
Processor rank.
Definition: globals.h:33
int restart
Definition: structs.h:12
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define NO
Definition: pluto.h:26

Here is the caller graph for this function:

void SetOutput ( Data d,
Runtime runtime 
)

Set default attributes (variable names, pointers to data structures, filename extensions, etc...) of the output structures.

Parameters
[in]dpointer to Data structure
[in]runtimepointer to Runtime structure

Definition at line 37 of file set_output.c.

46 {
47  int nv, i, k;
48  Output *output;
49 
50  if (runtime->user_var > 0)
51  d->Vuser = ARRAY_4D(runtime->user_var, NX3_TOT, NX2_TOT, NX1_TOT, double);
52  else
53  d->Vuser = NULL;
54 
55  all_outputs = runtime->output;
56 
57 /* ---------------------------------------------
58  Loop on output types
59  --------------------------------------------- */
60 
61  for (k = 0; k < MAX_OUTPUT_TYPES; k++){
62  output = runtime->output + k;
63  output->var_name = ARRAY_2D(64,128,char);
64  output->stag_var = ARRAY_1D(64, int);
65  output->dump_var = ARRAY_1D(64, int);
66  strcpy(output->dir, runtime->output_dir); /* output directory is the same */
67  /* for all outputs (easy to change) */
68  output->nfile = -1;
69 
70  /* -- set variables names -- */
71 
72  SetDefaultVarNames(output);
73 
74  /* -- Set array pointers -- */
75 
76  for (nv = 0; nv < NVAR; nv++){
77  output->V[nv] = d->Vc[nv];
78  output->stag_var[nv] = -1; /* -- means cell centered -- */
79  }
80  nv = NVAR;
81  #ifdef STAGGERED_MHD
82  D_EXPAND(
83  output->var_name[nv] = "bx1s";
84  output->V[nv] = d->Vs[BX1s];
85  output->stag_var[nv++] = 0; ,
86 
87  output->var_name[nv] = "bx2s";
88  output->V[nv] = d->Vs[BX2s];
89  output->stag_var[nv++] = 1; ,
90 
91  output->var_name[nv] = "bx3s";
92  output->V[nv] = d->Vs[BX3s];
93  output->stag_var[nv++] = 2;
94  )
95  #endif
96 
97  #if UPDATE_VECTOR_POTENTIAL == YES
98  #if DIMENSIONS == 3
99  output->var_name[nv] = "Ax1";
100  output->V[nv] = d->Ax1;
101  output->stag_var[nv++] = -1; /* -- vector potential is
102  computed at cell center -- */
103 
104  output->var_name[nv] = "Ax2";
105  output->V[nv] = d->Ax2;
106  output->stag_var[nv++] = -1;
107  #endif
108  output->var_name[nv] = "Ax3";
109  output->V[nv] = d->Ax3;
110  output->stag_var[nv++] = -1;
111  #endif
112  output->nvar = nv;
113 
114  /* -- repeat for user defined vars -- */
115 
116  for (i = 0; i < runtime->user_var; i++){
117  sprintf (output->var_name[i + nv], "%s", runtime->user_var_name[i]);
118  output->V[i + nv] = d->Vuser[i];
119  output->stag_var[i + nv] = -1; /* -- assume cell-centered -- */
120  }
121 
122  /* -- add user vars to total number of variables -- */
123 
124  output->nvar += runtime->user_var;
125 
126  /* -- select which variables are going to be dumped to disk -- */
127 
128  for (nv = output->nvar; nv--; ) output->dump_var[nv] = YES;
129  #if ENTROPY_SWITCH
130  output->dump_var[ENTR] = NO;
131  #endif
132 
133  switch (output->type){
134  case DBL_OUTPUT: /* -- dump ALL variables -- */
135  sprintf (output->ext,"dbl");
136  break;
137  case FLT_OUTPUT: /* -- do not dump staggered fields (below)-- */
138  sprintf (output->ext,"flt");
139  break;
140  case DBL_H5_OUTPUT: /* -- dump ALL variables -- */
141  sprintf (output->ext,"dbl.h5");
142  break;
143  case FLT_H5_OUTPUT: /* -- do not dump staggered fields (below)-- */
144  sprintf (output->ext,"flt.h5");
145  break;
146  case VTK_OUTPUT: /* -- do not dump staggered fields (below) -- */
147  sprintf (output->ext,"vtk");
148  #if VTK_VECTOR_DUMP == YES
149  D_EXPAND(output->dump_var[VX1] = VTK_VECTOR; ,
150  output->dump_var[VX2] = NO; ,
151  output->dump_var[VX3] = NO;)
152  #if PHYSICS == MHD || PHYSICS == RMHD
153  D_EXPAND(output->dump_var[BX1] = VTK_VECTOR; ,
154  output->dump_var[BX2] = NO; ,
155  output->dump_var[BX3] = NO;)
156  #endif
157  #endif
158  break;
159  case TAB_OUTPUT: /* -- do not dump staggered fields -- */
160  sprintf (output->ext,"tab");
161  break;
162  case PPM_OUTPUT: /* -- dump density only -- */
163  sprintf (output->ext,"ppm");
164  for (nv = output->nvar; nv--; ) output->dump_var[nv] = NO;
165  break;
166  case PNG_OUTPUT: /* -- dump density only -- */
167  sprintf (output->ext,"png");
168  for (nv = output->nvar; nv--; ) output->dump_var[nv] = NO;
169  break;
170  }
171 
172  /* ---------------------------------------------------------------
173  for divergence cleaning never dump the scalar psi unless
174  the output type can be potentially used for restart
175  --------------------------------------------------------------- */
176 
177  #ifdef GLM_MHD
178  if (output->type == DBL_OUTPUT || output->type == DBL_H5_OUTPUT)
179  output->dump_var[PSI_GLM] = YES;
180  else
181  output->dump_var[PSI_GLM] = NO;
182  #endif
183  }
184 
185 /* -- exclude stag components from all output except .dbl -- */
186 
187  #ifdef STAGGERED_MHD
188  D_EXPAND( SetDumpVar ("bx1s", VTK_OUTPUT, NO); ,
189  SetDumpVar ("bx2s", VTK_OUTPUT, NO); ,
190  SetDumpVar ("bx3s", VTK_OUTPUT, NO);)
191  D_EXPAND( SetDumpVar ("bx1s", FLT_OUTPUT, NO); ,
192  SetDumpVar ("bx2s", FLT_OUTPUT, NO); ,
193  SetDumpVar ("bx3s", FLT_OUTPUT, NO);)
194  D_EXPAND( SetDumpVar ("bx1s", FLT_H5_OUTPUT, NO); ,
195  SetDumpVar ("bx2s", FLT_H5_OUTPUT, NO); ,
196  SetDumpVar ("bx3s", FLT_H5_OUTPUT, NO);)
197  D_EXPAND( SetDumpVar ("bx1s", TAB_OUTPUT, NO); ,
198  SetDumpVar ("bx2s", TAB_OUTPUT, NO); ,
199  SetDumpVar ("bx3s", TAB_OUTPUT, NO);)
200  #endif
201 
202 /* -- defaults: dump density only in ppm and png formats -- */
203 
204  SetDumpVar ("rho", PPM_OUTPUT, YES);
205  SetDumpVar ("rho", PNG_OUTPUT, YES);
206 
207  ChangeDumpVar();
208 }
int user_var
The number of additional user-variables being held in memory and written to disk. ...
Definition: structs.h:264
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
#define VX2
Definition: mod_defs.h:29
#define FLT_H5_OUTPUT
Definition: pluto.h:83
#define PPM_OUTPUT
Definition: pluto.h:85
double *** V[64]
pointer to arrays being written - same for all
Definition: structs.h:247
#define VTK_VECTOR
Definition: pluto.h:88
Output output[MAX_OUTPUT_TYPES]
Definition: structs.h:272
int nfile
current number being saved - one per output
Definition: structs.h:237
char output_dir[256]
The name of the output directory (output_dir for static PLUTO, Output_dir for PLUTO-Chombo) ...
Definition: structs.h:269
#define YES
Definition: pluto.h:25
void SetDefaultVarNames(Output *)
Definition: var_names.c:4
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
char user_var_name[128][128]
Definition: structs.h:268
double *** Ax3
Vector potential component in the direction.
Definition: structs.h:53
#define PSI_GLM
Definition: mod_defs.h:34
char dir[256]
output directory name
Definition: structs.h:244
#define BX3s
Definition: ct.h:29
#define VX1
Definition: mod_defs.h:28
char ext[8]
output extension
Definition: structs.h:243
#define VTK_OUTPUT
Definition: pluto.h:81
#define DBL_H5_OUTPUT
Definition: pluto.h:82
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
#define ARRAY_4D(nx, ny, nz, nv, type)
Definition: prototypes.h:173
int k
Definition: analysis.c:2
int nvar
tot.
Definition: structs.h:234
static Output * all_outputs
Definition: set_output.c:35
#define BX1s
Definition: ct.h:27
#define MAX_OUTPUT_TYPES
Definition: pluto.h:95
int * dump_var
select vars being written - one per output
Definition: structs.h:240
#define TAB_OUTPUT
Definition: pluto.h:84
#define FLT_OUTPUT
Definition: pluto.h:80
#define BX3
Definition: mod_defs.h:27
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
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
#define DBL_OUTPUT
Definition: pluto.h:79
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
int type
output format (DBL, FLT, ...) - one per output
Definition: structs.h:233
int * stag_var
centered or staggered variable - same for all
Definition: structs.h:239
#define BX2s
Definition: ct.h:28
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define BX2
Definition: mod_defs.h:26
double *** Ax1
Vector potential component in the direction.
Definition: structs.h:51
double **** Vuser
Array storing user-defined supplementary variables written to disk.
Definition: structs.h:49
void ChangeDumpVar()
#define NVAR
Definition: pluto.h:609
double *** Ax2
Vector potential component in the direction.
Definition: structs.h:52
#define PNG_OUTPUT
Definition: pluto.h:86
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
char ** var_name
variable names - same for all
Definition: structs.h:242
#define NO
Definition: pluto.h:26
int SetDumpVar(char *var_name, int out_type, int flag)
Definition: set_output.c:211

Here is the call graph for this function:

Here is the caller graph for this function:

void SetRBox ( void  )

Definition at line 33 of file rbox.c.

38 {
39  int s;
40 
41 /* ---------------------------------------------------
42  0. Set X1_BEG grid index ranges
43  --------------------------------------------------- */
44 
45  s = X1_BEG; s -= X1_BEG;
46 
48 
49  rbox_center[s].ib = IBEG-1; rbox_center[s].ie = 0;
50  rbox_center[s].jb = 0; rbox_center[s].je = NX2_TOT-1;
51  rbox_center[s].kb = 0; rbox_center[s].ke = NX3_TOT-1;
52 
54 
55  #ifndef CHOMBO /* -- useless for AMR -- */
59 
60  D_EXPAND(rbox_x1face[s].ib--; rbox_x1face[s].ie--; ,
61  rbox_x2face[s].jb--; ,
62  rbox_x3face[s].kb--;)
63  #endif
64 
65 /* ---------------------------------------------------
66  1. set X1_END grid index ranges
67  --------------------------------------------------- */
68 
69  s = X1_END; s -= X1_BEG;
70 
72 
74  rbox_center[s].jb = 0; rbox_center[s].je = NX2_TOT-1;
75  rbox_center[s].kb = 0; rbox_center[s].ke = NX3_TOT-1;
76 
78 
79  #ifndef CHOMBO /* -- useless for AMR -- */
83 
84  D_EXPAND( ; ,
85  rbox_x2face[s].jb--; ,
86  rbox_x3face[s].kb--;)
87  #endif
88 
89 /* ---------------------------------------------------
90  2. set X2_BEG grid index ranges
91  --------------------------------------------------- */
92 
93  s = X2_BEG; s -= X1_BEG;
94 
96 
97  rbox_center[s].ib = 0; rbox_center[s].ie = NX1_TOT-1;
98  rbox_center[s].jb = JBEG-1; rbox_center[s].je = 0;
99  rbox_center[s].kb = 0; rbox_center[s].ke = NX3_TOT-1;
100 
102 
103  #ifndef CHOMBO /* -- useless for AMR -- */
107 
108  D_EXPAND(rbox_x1face[s].ib--; ,
109  rbox_x2face[s].jb--; rbox_x2face[s].je--; ,
110  rbox_x3face[s].kb--;)
111  #endif
112 
113 /* ---------------------------------------------------
114  3. set X2_END grid index ranges
115  --------------------------------------------------- */
116 
117  s = X2_END; s -= X1_BEG;
118 
120 
121  rbox_center[s].ib = 0; rbox_center[s].ie = NX1_TOT-1;
122  rbox_center[s].jb = JEND+1; rbox_center[s].je = NX2_TOT-1;
123  rbox_center[s].kb = 0; rbox_center[s].ke = NX3_TOT-1;
124 
126 
127  #ifndef CHOMBO /* -- useless for AMR -- */
131 
132  D_EXPAND(rbox_x1face[s].ib--; ,
133  ; ,
134  rbox_x3face[s].kb--;)
135  #endif
136 
137 /* ---------------------------------------------------
138  4. set X3_BEG grid index ranges
139  --------------------------------------------------- */
140 
141  s = X3_BEG; s -= X1_BEG;
142 
144 
145  rbox_center[s].ib = 0; rbox_center[s].ie = NX1_TOT-1;
146  rbox_center[s].jb = 0; rbox_center[s].je = NX2_TOT-1;
147  rbox_center[s].kb = KBEG-1; rbox_center[s].ke = 0;
148 
150 
151  #ifndef CHOMBO /* -- useless for AMR -- */
155 
156  D_EXPAND(rbox_x1face[s].ib--; ,
157  rbox_x2face[s].jb--; ,
158  rbox_x3face[s].kb--; rbox_x3face[s].ke--;)
159  #endif
160 
161 /* ---------------------------------------------------
162  5. set X3_END grid index ranges
163  --------------------------------------------------- */
164 
165  s = X3_END; s -= X1_BEG;
166 
168 
169  rbox_center[s].ib = 0; rbox_center[s].ie = NX1_TOT-1;
170  rbox_center[s].jb = 0; rbox_center[s].je = NX2_TOT-1;
171  rbox_center[s].kb = KEND+1; rbox_center[s].ke = NX3_TOT-1;
172 
174 
175  #ifndef CHOMBO /* -- useless for AMR -- */
179 
180  D_EXPAND(rbox_x1face[s].ib--; ,
181  rbox_x2face[s].jb--; ,
182  ;)
183  #endif
184 
185 /* ---------------------------------------------------
186  6. set DOM index ranges
187  --------------------------------------------------- */
188 
189  s = DOM; s -= X1_BEG;
190 
195 
197 
198  #ifndef CHOMBO /* -- useless for AMR -- */
202 
203  D_EXPAND(rbox_x1face[s].ib--; ,
204  rbox_x2face[s].jb--; ,
205  rbox_x3face[s].kb--;)
206  #endif
207 
208 /* ---------------------------------------------------
209  7. set TOT index ranges
210  --------------------------------------------------- */
211 
212  s = TOT; s -= X1_BEG;
213 
215  rbox_center[s].ib = 0; rbox_center[s].ie = NX1_TOT-1;
216  rbox_center[s].jb = 0; rbox_center[s].je = NX2_TOT-1;
217  rbox_center[s].kb = 0; rbox_center[s].ke = NX3_TOT-1;
218 
220 
221  #ifndef CHOMBO /* -- useless for AMR -- */
225 
226  D_EXPAND(rbox_x1face[s].ib--; ,
227  rbox_x2face[s].jb--; ,
228  rbox_x3face[s].kb--;)
229  #endif
230 }
#define X3_BEG
Boundary region at X3 beg.
Definition: pluto.h:150
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
int jb
Lower corner index in the x2 direction.
Definition: structs.h:349
#define CENTER
Definition: pluto.h:200
int vpos
Location of the variable inside the cell.
Definition: structs.h:359
#define X3FACE
Definition: pluto.h:203
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 DOM
Computational domain (interior)
Definition: pluto.h:152
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
#define TOT
Computational domain (total)
Definition: pluto.h:153
int ib
Lower corner index in the x1 direction.
Definition: structs.h:347
#define X1FACE
Definition: pluto.h:201
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
static RBox rbox_x1face[8]
Definition: rbox.c:30
static RBox rbox_x3face[8]
Definition: rbox.c:30
#define s
static RBox rbox_center[8]
Definition: rbox.c:30
#define X3_END
Boundary region at X3 end.
Definition: pluto.h:151
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 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
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
#define X2_BEG
Boundary region at X2 beg.
Definition: pluto.h:148
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
static RBox rbox_x2face[8]
Definition: rbox.c:30
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
#define X2FACE
Definition: pluto.h:202
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35

Here is the call graph for this function:

Here is the caller graph for this function:

Riemann_Solver* SetSolver ( const char *  solver)

PURPOSE

return a pointer to a riemann solver function

Depending on the choice of the Riemann solver specified in pluto.ini, return a pointer to the corresponding Riemann solver function

Definition at line 4 of file set_solver.c.

12 {
13 
14  #ifdef FINITE_DIFFERENCE
15  return (&FD_Flux);
16  #endif
17 
18 /* ------------------------------------------------------
19  Set Pointers for SOLVERS
20  ------------------------------------------------------ */
21 
22  #if EOS == IDEAL
23  if ( !strcmp(solver, "two_shock")) return (&TwoShock_Solver);
24  else if (!strcmp(solver, "tvdlf")) return (&LF_Solver);
25  else if (!strcmp(solver, "roe")) return (&Roe_Solver);
26  else if (!strcmp(solver, "ausm+")) return (&AUSMp_Solver);
27  else if (!strcmp(solver, "hlle") ||
28  !strcmp(solver, "hll")) return (&HLL_Solver);
29  else if (!strcmp(solver, "hllc")) return (&HLLC_Solver);
30 /*
31  else if (!strcmp(solver, "rusanov_dw")) return (&RusanovDW_Solver);
32 */
33  #elif EOS == PVTE_LAW
34  if (!strcmp(solver, "tvdlf")) return (&LF_Solver);
35  else if (!strcmp(solver, "hlle") ||
36  !strcmp(solver, "hll")) return (&HLL_Solver);
37  else if (!strcmp(solver, "hllc")) return (&HLLC_Solver);
38 /*
39  else if (!strcmp(solver, "rusanov_dw")) return (&RusanovDW_Solver);
40 */
41  #elif EOS == ISOTHERMAL
42  if (!strcmp(solver, "tvdlf")) return (&LF_Solver);
43  else if (!strcmp(solver, "roe")) return (&Roe_Solver);
44  else if (!strcmp(solver, "hlle") ||
45  !strcmp(solver, "hll")) return (&HLL_Solver);
46  else if (!strcmp(solver, "hllc")) return (&HLLC_Solver);
47 /*
48  else if (!strcmp(solver, "rusanov_dw")) return (&RusanovDW_Solver);
49 */
50  #endif
51 
52  print1 ("\n! SetSolver: '%s' not available with this configuration.\n",
53  solver);
54  QUIT_PLUTO(1);
55 }
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
Riemann_Solver AUSMp_Solver
Definition: mod_defs.h:108
Riemann_Solver HLLC_Solver
Definition: mod_defs.h:106
Riemann_Solver Roe_Solver
Definition: mod_defs.h:106
Riemann_Solver TwoShock_Solver
Definition: mod_defs.h:106
Riemann_Solver HLL_Solver
Definition: mod_defs.h:106
Riemann_Solver LF_Solver
Definition: mod_defs.h:106
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
void FD_Flux(const State_1D *state, int beg, int end, double *cmax, Grid *grid)
Definition: fd_flux.c:23

Here is the call graph for this function:

Here is the caller graph for this function:

void Show ( double **  a,
int  ip 
)

Print the component of the array a at grid index ip

Definition at line 132 of file tools.c.

137 {
138  int nv, ix, iy, iz;
139 
140  if (g_dir == IDIR) {
141  print ("X-sweep");
142  ix = ip;
143  iy = g_j;
144  iz = g_k;
145  } else if (g_dir == JDIR) {
146  print ("Y-sweep");
147  ix = g_i;
148  iy = ip;
149  iz = g_k;
150  } else if (g_dir == KDIR) {
151  print ("Z-sweep");
152  ix = g_i;
153  iy = g_j;
154  iz = ip;
155  }
156 
157  D_SELECT( print (" (%d)> ", ix); ,
158  print (" (%d,%d)> ", ix, iy); ,
159  print (" (%d,%d,%d)> ", ix, iy, iz); )
160 
161 
162  for (nv = 0; nv < NVAR; nv++) {
163  print ("%12.6e ", a[ip][nv]);
164  }
165  print ("\n");
166 }
static double a
Definition: init.c:135
#define KDIR
Definition: pluto.h:195
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
Definition: globals.h:82
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
void print(const char *fmt,...)
Definition: tools.c:367
#define JDIR
Definition: pluto.h:194
#define NVAR
Definition: pluto.h:609

Here is the call graph for this function:

Here is the caller graph for this function:

void ShowConfig ( int  argc,
char *  argv[],
char *  ini_file 
)

Write a summary of the selected options


/ _ \/ / / / / /_ __/ __ \ / ___/ /__/ /_/ / / / / /_/ /

/ / /____/____/ /_/ ____/

Definition at line 16 of file show_config.c.

31 {
32  int n;
33  FILE *fp;
34  time_t time_now;
35  char str1[128], str2[128], str3[128], sline[512];
36 
37  CheckConfig();
38 
39  print1 ("\n");
40  print1(" ___ __ __ ____________ \n");
41  print1(" / _ \\/ / / / / /_ __/ __ \\ \n");
42  print1(" / ___/ /__/ /_/ / / / / /_/ / \n");
43  print1("/_/ /____/\\____/ /_/ \\____/ \n");
44  print1("============================= v. %s \n", PLUTO_VERSION);
45 
46  print1 ("\n> System:\n\n");
47 
48  if ( (fp = fopen("sysconf.out","r")) != NULL){
49 
50  while (fscanf (fp, "%s %s %s\n", str1, str2, str3) != EOF) {
51  if (!strcmp(str1,"USER"))
52  print1 (" %s: %s\n",str1, str3);
53  else if (!strcmp(str1,"WORKING_g_dir"))
54  print1 (" %s: %s\n",str1, str3);
55  else if (!strcmp(str1,"SYSTEM_NAME"))
56  print1 (" %s: %s\n",str1, str3);
57  else if (!strcmp(str1,"NODE_NAME"))
58  print1 (" %s: %s\n",str1, str3);
59  else if (!strcmp(str1,"ARCH"))
60  print1 (" %s: %s\n",str1, str3);
61  else if (!strcmp(str1,"BYTE_ORDER"))
62  print1 (" %s: %s\n\n",str1, str3);
63  }
64  fclose(fp);
65 
66  }else{
67  print1 ("! sysconf.out file not found \n\n");
68  }
69 
70  time(&time_now);
71  print1("> Local time: %s\n",asctime(localtime(&time_now)));
72 
73  if (COMPONENTS < DIMENSIONS) {
74  print1 ("Sorry, but the number of vector components can\n");
75  print1 ("not be less than the dimension number.\n");
76  print1 ("Please edit definitions.h and fix this.\n");
77  QUIT_PLUTO(1);
78  }
79 
80 /* -- print command line arguments -- */
81 
82  print1 ("> Cmd line args: ");
83  for (n = 1; n < argc; n++) print1 ("%s ",argv[n]);
84  print1 ("\n\n");
85 
86 /* -- print problem configuration -- */
87 
88  print1 ("> Header configuration:\n\n");
89 
90  if (PHYSICS == ADVECTION) print1 (" PHYSICS: ADVECTION\n");
91  if (PHYSICS == HD) print1 (" PHYSICS: HD\n");
92  if (PHYSICS == RHD) print1 (" PHYSICS: RHD\n");
93  if (PHYSICS == MHD) print1 (" PHYSICS: MHD [div.B: ");
94  if (PHYSICS == RMHD) print1 (" PHYSICS: RMHD [div.B: ");
95 #if PHYSICS == MHD || PHYSICS == RMHD
96  #if DIVB_CONTROL == NO
97  print1 ("None]\n");
98  #elif DIVB_CONTROL == EIGHT_WAVES
99  print1 ("Powell's 8wave]\n");
100  #elif DIVB_CONTROL == DIV_CLEANING
101  #if GLM_EXTENDED == NO
102  print1 ("Divergence Cleaning (GLM)]\n");
103  #elif GLM_EXTENDED == YES
104  print1 ("Divergence Cleaning (Extended GLM)]\n");
105  #endif
106 
107  #elif DIVB_CONTROL == CONSTRAINED_TRANSPORT
108  print1 ("CT/");
109  #if CT_EMF_AVERAGE == ARITHMETIC
110  print1 ("Ar. average]\n");
111  #elif CT_EMF_AVERAGE == UCT_CONTACT
112  print1 ("UCT_CONTACT]\n");
113  #elif CT_EMF_AVERAGE == UCT0
114  print1 ("UCT0]\n");
115  #elif CT_EMF_AVERAGE == UCT_HLL
116  print1 ("UCT_HLL]\n");
117  #endif
118  #endif
119 #endif
120 
121  print1 (" DIMENSIONS: %d\n", DIMENSIONS);
122  print1 (" COMPONENTS: %d\n", COMPONENTS);
123 
124  print1 (" GEOMETRY: ");
125  if (GEOMETRY == CARTESIAN) print1 ("Cartesian\n");
126  if (GEOMETRY == CYLINDRICAL) print1 ("Cylindrical\n");
127  if (GEOMETRY == POLAR) print1 ("Polar\n");
128  if (GEOMETRY == SPHERICAL) print1 ("Spherical\n");
129 
130  print1 (" BODY_FORCE: ");
131  print1 (BODY_FORCE == NO ? "NO\n":"EXPLICIT\n");
132 
133  print1 (" RECONSTRUCTION: ");
134 #ifndef FINITE_DIFFERENCE
135  if (RECONSTRUCTION == FLAT) print1 ("Flat");
136  if (RECONSTRUCTION == LINEAR) print1 ("Linear TVD");
137  if (RECONSTRUCTION == LINEAR_MULTID) print1 ("Linear_Multid");
138  if (RECONSTRUCTION == LimO3) print1 ("LimO3");
139  if (RECONSTRUCTION == WENO3) print1 ("WENO 3rd order");
140  if (RECONSTRUCTION == PARABOLIC) print1 ("Parabolic");
141  #ifdef CHAR_LIMITING
142  if (CHAR_LIMITING == YES) print1 (" (Characteristic lim)\n");
143  else print1 (" (Primitive lim)\n");
144  #endif
145 #endif
146 
147 #ifdef FINITE_DIFFERENCE
148  if (RECONSTRUCTION == LIMO3_FD) print1 ("LimO3 (FD), 3rd order\n");
149  if (RECONSTRUCTION == WENO3_FD) print1 ("WENO3 (FD), 3rd order\n");
150  if (RECONSTRUCTION == WENOZ_FD) print1 ("WENOZ (FD) 5th order\n");
151  if (RECONSTRUCTION == MP5_FD) print1 ("MP5 (FD), 5th order\n");
152 #endif
153 
154  print1 (" TRACERS: %d\n", NTRACER);
155  print1 (" VARIABLES: %d\n", NVAR);
156  print1 (" ENTROPY_SWITCH: %s\n",(ENTROPY_SWITCH != NO ? "ENABLED":"NO"));
157 #if PHYSICS == MHD
158  print1 (" BACKGROUND_FIELD: %s\n",(BACKGROUND_FIELD == YES ? "YES":"NO"));
159 #endif
160 
161  print1 (" LOADED MODULES:\n");
162  #if PHYSICS == MHD
163  #ifdef SHEARINGBOX
164  print1 ("\n o [SHEARINGBOX]\n");
165  print1 (" - Order: %d\n", SB_ORDER);
166  print1 (" - Sym Hydro Flux: %s\n",
167  (SB_SYMMETRIZE_HYDRO == YES ? "YES":"NO"));
168  print1 (" - Sym Ey: %s\n",
169  (SB_SYMMETRIZE_EY == YES ? "YES":"NO"));
170  print1 (" - Sym Ez: %s\n",
171  (SB_SYMMETRIZE_EZ == YES ? "YES":"NO"));
172  print1 (" - Force EMF periods: %s\n",
173  (SB_FORCE_EMF_PERIODS == YES ? "YES":"NO"));
174  #endif
175  #endif
176  #ifdef FARGO
177  print1 ("\n o [FARGO]\n");
178  print1 (" - Order: %d\n", FARGO_ORDER);
179  print1 (" - Average Speed: %s\n",
180  (FARGO_AVERAGE_VELOCITY == YES ? "YES":"NO"));
181  print1 (" - Av. Frequency: %d\n", FARGO_NSTEP_AVERAGE);
182 
183  #endif
184  print1 ("\n");
185 
186  print1 (" ROTATION: ");
187  print1(ROTATING_FRAME == YES ? "YES\n":"NO\n");
188 
189  print1 (" EOS: ");
190  if (EOS == IDEAL) print1 ("Ideal\n");
191  else if (EOS == PVTE_LAW) print1 ("PVTE_LAW\n");
192  else if (EOS == BAROTROPIC) print1 ("Barotropic\n");
193  else if (EOS == ISOTHERMAL) print1 ("Isothermal\n");
194  else if (EOS == TAUB) print1 ("Taub - TM\n");
195  else print1 ("None\n");
196 
197  print1 (" TIME INTEGRATOR: ");
198  if (TIME_STEPPING == EULER) print1 ("Euler\n");
199  if (TIME_STEPPING == RK2) print1 ("Runga-Kutta II\n");
200  if (TIME_STEPPING == RK3) print1 ("Runga_Kutta III\n");
202  print1 ("Characteristic Tracing\n");
203  if (TIME_STEPPING == HANCOCK) print1 ("Hancock\n");
204 
205  print1 (" DIM. SPLITTING: ");
206  if (DIMENSIONAL_SPLITTING == YES) print1 ("Yes\n");
207  else print1 ("No\n");
208 
209 
210  #if PARABOLIC_FLUX != NO
211  print1 (" DIFFUSION TERMS:");
212  #if (RESISTIVITY == EXPLICIT)
213  print1 (" Resistivity [EXPLICIT]\n");
214  #elif (RESISTIVITY == SUPER_TIME_STEPPING)
215  print1 (" Resistivity [STS]\n");
216  #endif
217 
218  #if (THERMAL_CONDUCTION == EXPLICIT)
219  print1 (" Thermal Conduction [EXPLICIT]\n");
220  #elif (THERMAL_CONDUCTION == SUPER_TIME_STEPPING)
221  print1 (" Thermal Conduction [STS]\n");
222  #endif
223 
224  #if (VISCOSITY == EXPLICIT)
225  print1 (" Viscosity [EXPLICIT]\n");
226  #elif (VISCOSITY == SUPER_TIME_STEPPING)
227  print1 (" Viscosity [STS]\n");
228  #endif
229  #endif
230 
231  print1 ("\n");
232 
233 /* -----------------------------------------------------
234  Print runtime configuration info (definitions.h
235  and from pluto.ini)
236  ----------------------------------------------------- */
237 /*
238  print1 ("> Header file configuration (definitions.h):\n\n");
239  print1 (" +----------------------------------------------------------\n");
240  fp = fopen("definitions.h","r");
241  while ( fgets(sline, 512, fp) != NULL ) {
242  print1 (" | %s",sline);
243  }
244  fclose(fp);
245  print1 (" +---------------------------------------------------------\n\n");
246 */
247  print1 ("> Runtime configuration (%s):\n\n", ini_file);
248  print1 (" +----------------------------------------------------------\n");
249  fp = fopen(ini_file,"r");
250  while ( fgets(sline, 512, fp) != NULL ) {
251  print1 (" | %s",sline);
252  }
253  fclose(fp);
254  print1 (" +---------------------------------------------------------\n");
255 
256 
257 }
#define IDEAL
Definition: pluto.h:45
#define EOS
Definition: pluto.h:341
#define DIMENSIONAL_SPLITTING
Definition: definitions_01.h:9
#define LimO3
Definition: pluto.h:217
static int n
Definition: analysis.c:3
#define BAROTROPIC
Definition: pluto.h:48
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
#define BODY_FORCE
Definition: definitions_01.h:5
#define LINEAR_MULTID
Definition: pluto.h:215
#define YES
Definition: pluto.h:25
#define PVTE_LAW
Definition: pluto.h:46
#define PLUTO_VERSION
Definition: pluto.h:16
#define SB_ORDER
Definition: shearingbox.h:29
#define SPHERICAL
Definition: pluto.h:36
#define LINEAR
Definition: pluto.h:212
static void CheckConfig()
Definition: show_config.c:416
#define TAUB
Definition: pluto.h:47
#define EULER
Definition: pluto.h:59
#define PARABOLIC
Definition: pluto.h:214
#define HD
Definition: pluto.h:109
#define POLAR
Definition: pluto.h:35
#define WENO3
Definition: pluto.h:218
#define FARGO_NSTEP_AVERAGE
Definition: fargo.h:25
#define SB_FORCE_EMF_PERIODS
Force periodicity at y- and z- boundaries.
Definition: shearingbox.h:61
#define RK3
Definition: pluto.h:63
#define CHAR_LIMITING
Definition: pluto.h:293
#define FARGO_ORDER
Set the order of interpolation during the linear transport step.
Definition: fargo.h:17
#define PHYSICS
Definition: definitions_01.h:1
#define CHARACTERISTIC_TRACING
Definition: pluto.h:61
#define WENO3_FD
Definition: pluto.h:222
#define GEOMETRY
Definition: definitions_01.h:4
#define FARGO_AVERAGE_VELOCITY
Definition: fargo.h:33
#define HANCOCK
Definition: pluto.h:60
#define ISOTHERMAL
Definition: pluto.h:49
#define CARTESIAN
Definition: pluto.h:33
#define CYLINDRICAL
Definition: pluto.h:34
#define MHD
Definition: pluto.h:111
#define COMPONENTS
Definition: definitions_01.h:3
#define MP5_FD
Definition: pluto.h:226
#define ENTROPY_SWITCH
Definition: pluto.h:337
#define WENOZ_FD
Definition: pluto.h:224
#define SB_SYMMETRIZE_HYDRO
Symmetrize the hydrodynamical fluxes at the left and right x-boundaries in order to enforce conservat...
Definition: shearingbox.h:36
#define FLAT
Definition: pluto.h:211
#define ADVECTION
Definition: pluto.h:108
void BACKGROUND_FIELD(real x1, real x2, real x3, real *B0)
Definition: init.c:95
#define SB_SYMMETRIZE_EY
Symmetrize the y-component of the electric field at the left and right x-boundaries to enforce conser...
Definition: shearingbox.h:46
FILE * fp
Definition: analysis.c:7
#define NTRACER
#define RHD
Definition: pluto.h:110
#define TIME_STEPPING
Definition: definitions_01.h:8
#define LIMO3_FD
Definition: pluto.h:227
#define NVAR
Definition: pluto.h:609
#define RK2
Definition: pluto.h:62
#define SB_SYMMETRIZE_EZ
Symmetrize the z-component of electric field at the left and right x-boundaries to enforce conservati...
Definition: shearingbox.h:54
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define RMHD
Definition: pluto.h:112
#define ROTATING_FRAME
Definition: pluto.h:361
#define RECONSTRUCTION
Definition: definitions_01.h:7
#define DIMENSIONS
Definition: definitions_01.h:2
#define NO
Definition: pluto.h:26

Here is the call graph for this function:

Here is the caller graph for this function:

void ShowDomainDecomposition ( int  nprocs,
Grid GXYZ 
)

Show the parallel domain decomposition by having each processor print its own computational domain. This is activated with the -show-dec command line argument. It may be long for several thousand processors.

Parameters
[in]nprocsthe total number of processors
[in]GXYZa pointer to an array of grid structures

Definition at line 295 of file show_config.c.

305 {
306  int p;
307  int ib, ie, jb, je, kb, ke;
308  int nxp, nyp, nzp;
309  int nghx, nghy, nghz;
310 
311  static int *ib_proc, *ie_proc;
312  static int *jb_proc, *je_proc;
313  static int *kb_proc, *ke_proc;
314 
315  double xb, xe, yb, ye, zb, ze;
316 
317  double *xb_proc, *xe_proc;
318  double *yb_proc, *ye_proc;
319  double *zb_proc, *ze_proc;
320 
321  Grid *Gx, *Gy, *Gz;
322 
323  Gx = GXYZ;
324  Gy = GXYZ + 1;
325  Gz = GXYZ + 2;
326 
327 /* ---- Allocate memory ---- */
328 
329  ib_proc = ARRAY_1D(nprocs, int); ie_proc = ARRAY_1D(nprocs, int);
330  jb_proc = ARRAY_1D(nprocs, int); je_proc = ARRAY_1D(nprocs, int);
331  kb_proc = ARRAY_1D(nprocs, int); ke_proc = ARRAY_1D(nprocs, int);
332  xb_proc = ARRAY_1D(nprocs, double); xe_proc = ARRAY_1D(nprocs, double);
333  yb_proc = ARRAY_1D(nprocs, double); ye_proc = ARRAY_1D(nprocs, double);
334  zb_proc = ARRAY_1D(nprocs, double); ze_proc = ARRAY_1D(nprocs, double);
335 
336 #ifdef PARALLEL
337  nxp = Gx->np_tot;
338  nyp = Gy->np_tot;
339  nzp = Gz->np_tot;
340 
341 /* -- Local beg and end indices -- */
342 
343  ib = nghx = Gx->nghost; ie = ib + Gx->np_int - 1;
344  jb = nghy = Gy->nghost; je = jb + Gy->np_int - 1;
345  kb = nghz = Gz->nghost; ke = kb + Gz->np_int - 1;
346 
347 /* -- Leftmost and rightmost processor coordinates -- */
348 
349  xb = Gx->xl[ib]; xe = Gx->xr[ie];
350  yb = Gy->xl[jb]; ye = Gy->xr[je];
351  zb = Gz->xl[kb]; ze = Gz->xr[ke];
352 
353  D_EXPAND(
354  MPI_Gather (&xb, 1, MPI_DOUBLE, xb_proc, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
355  MPI_Gather (&xe, 1, MPI_DOUBLE, xe_proc, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); ,
356 
357  MPI_Gather (&yb, 1, MPI_DOUBLE, yb_proc, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
358  MPI_Gather (&ye, 1, MPI_DOUBLE, ye_proc, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); ,
359 
360  MPI_Gather (&zb, 1, MPI_DOUBLE, zb_proc, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
361  MPI_Gather (&ze, 1, MPI_DOUBLE, ze_proc, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
362  )
363 
364 /* -- Global beg and end indices -- */
365 
366  ib = Gx->beg; ie += Gx->beg - nghx;
367  jb = Gy->beg; je += Gy->beg - nghy;
368  kb = Gz->beg; ke += Gz->beg - nghz;
369 
370  D_EXPAND(
371  MPI_Gather (&ib, 1, MPI_INT, ib_proc, 1, MPI_INT, 0, MPI_COMM_WORLD);
372  MPI_Gather (&ie, 1, MPI_INT, ie_proc, 1, MPI_INT, 0, MPI_COMM_WORLD); ,
373 
374  MPI_Gather (&jb, 1, MPI_INT, jb_proc, 1, MPI_INT, 0, MPI_COMM_WORLD);
375  MPI_Gather (&je, 1, MPI_INT, je_proc, 1, MPI_INT, 0, MPI_COMM_WORLD); ,
376 
377  MPI_Gather (&kb, 1, MPI_INT, kb_proc, 1, MPI_INT, 0, MPI_COMM_WORLD);
378  MPI_Gather (&ke, 1, MPI_INT, ke_proc, 1, MPI_INT, 0, MPI_COMM_WORLD);
379  )
380 
381  print1 ("> Domain Decomposition (%d procs):\n\n", nprocs);
382 
383  for (p = 0; p < nprocs; p++){
384  D_EXPAND(
385  print1 (" - Proc # %d, X1: [%f, %f], i: [%d, %d], NX1: %d\n",
386  p, xb_proc[p], xe_proc[p],
387  ib_proc[p], ie_proc[p],
388  ie_proc[p]-ib_proc[p]+1); ,
389  print1 (" X2: [%f, %f], j: [%d, %d]; NX2: %d\n",
390  yb_proc[p], ye_proc[p],
391  jb_proc[p], je_proc[p],
392  je_proc[p]-jb_proc[p]+1); ,
393  print1 (" X3: [%f, %f], k: [%d, %d], NX3: %d\n\n",
394  zb_proc[p], ze_proc[p],
395  kb_proc[p], ke_proc[p],
396  ke_proc[p]-kb_proc[p]+1);
397  )
398  }
399 
400  MPI_Barrier (MPI_COMM_WORLD);
401 #endif
402 
403 /* ---- Free memory ---- */
404 
405  FreeArray1D((void *) ib_proc); FreeArray1D((void *) ie_proc);
406  FreeArray1D((void *) jb_proc); FreeArray1D((void *) je_proc);
407  FreeArray1D((void *) kb_proc); FreeArray1D((void *) ke_proc);
408  FreeArray1D((void *) xb_proc); FreeArray1D((void *) xe_proc);
409  FreeArray1D((void *) yb_proc); FreeArray1D((void *) ye_proc);
410  FreeArray1D((void *) zb_proc); FreeArray1D((void *) ze_proc);
411 
412  print1 ("\n");
413 }
void FreeArray1D(void *v)
Definition: arrays.c:37
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
double * xr
Definition: structs.h:81
double * xl
Definition: structs.h:82
int beg
Global start index for the local array.
Definition: structs.h:115
Definition: structs.h:78
int nghost
Number of ghost zones.
Definition: structs.h:104
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
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 np_tot
Total number of points in the local domain (boundaries included).
Definition: structs.h:100
int np_int
Total number of points in the local domain (boundaries excluded).
Definition: structs.h:102

Here is the call graph for this function:

Here is the caller graph for this function:

void ShowMatrix ( double **  A,
int  n,
double  eps 
)

Make a nice printing of a 2D matrix A[0..n-1][0..n-1] Entries with values below eps will display "0.0"

Definition at line 182 of file tools.c.

189 {
190  int k1,k2;
191 
192  print ("----------------------------------------------------------------\n");
193  for (k1 = 0; k1 < n; k1++){
194  for (k2 = 0; k2 < n; k2++){
195  print ("%12.3e ", fabs(A[k1][k2]) > eps ? A[k1][k2]:0.0);
196  }
197  printf ("\n");
198  }
199  print ("----------------------------------------------------------------\n");
200 }
static int n
Definition: analysis.c:3
#define eps
void print(const char *fmt,...)
Definition: tools.c:367
double * A
Right interface area, A[i] = .
Definition: structs.h:87

Here is the call graph for this function:

Here is the caller graph for this function:

void ShowUnits ( )

Show units when cooling is enabled.

Definition at line 260 of file show_config.c.

266 {
267 
268 #if COOLING != NO
269  print1 ("> Cooling Module: ");
270  if (COOLING == SNEq) print1 (" SNEq\n");
271  if (COOLING == MINEq) print1 (" MINEq\n");
272  if (COOLING == TABULATED) print1 (" TABULATED\n");
273  if (COOLING == H2_COOL) print1 (" H2_COOL \n");
274 #endif
275 
276  print1 ("> Normalization Units:\n\n");
277  print1 (" [Density]: %8.3e (gr/cm^3), %8.3e (1/cm^3)\n",
279  print1 (" [Pressure]: %8.3e (dyne/cm^2)\n",
281  print1 (" [Velocity]: %8.3e (cm/s)\n",UNIT_VELOCITY);
282  print1 (" [Length]: %8.3e (cm)\n",UNIT_LENGTH);
283  print1 (" [Temperature]: %8.3e X (p/rho*mu) (K)\n",KELVIN);
284  print1 (" [Time]: %8.3e (sec), %8.3e (yrs) \n",
286 #if PHYSICS == MHD || PHYSICS == RMHD
287  print1 (" [Mag Field]: %8.3e (Gauss)\n",
289 #endif
290 
291  print1 (" \n");
292 }
#define H2_COOL
Definition: pluto.h:104
#define UNIT_DENSITY
Unit density in gr/cm^3.
Definition: pluto.h:369
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
#define KELVIN
Definition: pluto.h:401
#define CONST_mp
Proton mass.
Definition: pluto.h:261
#define SNEq
Definition: pluto.h:102
#define UNIT_VELOCITY
Unit velocity in cm/sec.
Definition: pluto.h:377
#define UNIT_LENGTH
Unit Length in cm.
Definition: pluto.h:373
#define MINEq
Definition: pluto.h:101
#define TABULATED
Definition: pluto.h:103
#define COOLING
Definition: definitions_01.h:6
#define CONST_PI
.
Definition: pluto.h:269

Here is the call graph for this function:

Here is the caller graph for this function:

void ShowVector ( double *  v,
int  n 
)

Print the component of the array a at grid index ip

Definition at line 169 of file tools.c.

174 {
175  int k;
176 
177  for (k = 0; k < n; k++) print ("%12.6e ", v[k]);
178  print ("\n");
179 }
static int n
Definition: analysis.c:3
int k
Definition: analysis.c:2
void print(const char *fmt,...)
Definition: tools.c:367

Here is the call graph for this function:

void SoundSpeed2 ( double **  v,
double *  cs2,
double *  h,
int  beg,
int  end,
int  pos,
Grid grid 
)

Define the square of the sound speed.

Parameters
[in]v1D array of primitive quantities
[out]cs21D array containing the square of the sound speed
[in]h1D array of enthalpy values
[in]beginitial index of computation
[in]endfinal index of computation
[in]posan integer specifying the spatial position inside the cell (only for spatially-dependent EOS)
[in]gridpointer to an array of Grid structures
Returns
This function has no return value.

Definition at line 16 of file eos.c.

32 {
33  int i;
34 
35  #if PHYSICS == HD || PHYSICS == MHD
36  for (i = beg; i <= end; i++) cs2[i] = g_gamma*v[i][PRS]/v[i][RHO];
37  #elif PHYSICS == RHD || PHYSICS == RMHD
38  double theta;
39  Enthalpy(v, h, beg, end);
40  for (i = beg; i <= end; i++) {
41  theta = v[i][PRS]/v[i][RHO];
42  cs2[i] = g_gamma*theta/h[i];
43  }
44  #endif
45 }
double g_gamma
Definition: globals.h:112
int end
Global end index for the local array.
Definition: structs.h:116
#define RHO
Definition: mod_defs.h:19
void Enthalpy(double **v, real *h, int beg, int end)
Definition: eos.c:48
int beg
Global start index for the local array.
Definition: structs.h:115
int i
Definition: analysis.c:2

Here is the call graph for this function:

Here is the caller graph for this function:

void SplitSource ( const Data d,
double  dt,
Time_Step Dts,
Grid grid 
)

Take one step on operator-split source terms.

Parameters
[in,out]dpointer to PLUTO Data structure containing the solution array updated from the most recent call
[in]dtthe time step used to integrate the source terms
[in]Dtspointer to the time step structure
[in]gridpointer to an array of grid structures

Definition at line 25 of file split_source.c.

38 {
39 /* ---- GLM source term treated in main ---- */
40 /*
41  #ifdef GLM_MHD
42  GLM_SOURCE (d->Vc, dt, grid);
43  #endif
44 */
45 /* ---------------------------------------------
46  Cooling/Heating losses
47  --------------------------------------------- */
48 
49  #if COOLING != NO
50  #if COOLING == POWER_LAW /* -- solve exactly -- */
51  PowerLawCooling (d->Vc, dt, Dts, grid);
52  #else
53  CoolingSource (d, dt, Dts, grid);
54  #endif
55  #endif
56 
57 /* ----------------------------------------------
58  Parabolic terms using STS:
59 
60  - resistivity
61  - thermal conduction
62  - viscosity
63  ---------------------------------------------- */
64 
65  #if (PARABOLIC_FLUX & SUPER_TIME_STEPPING)
66  STS (d, Dts, grid);
67  #endif
68 
69  #if (PARABOLIC_FLUX & RK_CHEBYSHEV)
70  RKC (d, Dts, grid);
71  #endif
72 }
void RKC(const Data *d, Time_Step *, Grid *)
Definition: rkc.c:58
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
void CoolingSource(const Data *d, double dt, Time_Step *Dts, Grid *GXYZ)
void PowerLawCooling(Data_Arr VV, double dt, Time_Step *Dts, Grid *grid)
Definition: cooling.c:50
void STS(const Data *d, Time_Step *, Grid *)
Definition: sts.c:55

Here is the call graph for this function:

Here is the caller graph for this function:

void Startup ( Data ,
Grid  
)

Definition at line 17 of file startup.c.

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 }
void Boundary(const Data *d, int idim, Grid *grid)
Definition: boundary.c:36
#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
#define KTOT_LOOP(k)
Definition: macros.h:40
#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
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
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
#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
#define NVAR
Definition: pluto.h:609
int BXb
Definition: globals.h:75
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#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

Here is the call graph for this function:

Here is the caller graph for this function:

void States ( const State_1D state,
int  beg,
int  end,
Grid grid 
)

Compute 1D left and right interface states using piecewise linear reconstruction and the characteristic decomposition of the quasi-linear form of the equations.

This is done by first extrapolating the cell center value to the interface using piecewise limited linear reconstruction on the characteristic variables.

Left and right states are then evolved for the half time step using characteristic tracing if necessary.

Compute states using piecewise linear interpolation.

Parameters
[in]statepointer to a State_1D structure
[in]begstarting point where vp and vm must be computed
[in]endfinal point where vp and vm must be computed
[in]gridpointer to array of Grid structures
Returns
This function has no return value.

Compute 1D left and right interface states using piecewise linear reconstruction and the characteristic decomposition of the quasi-linear form of the equations.

This is done by first extrapolating the cell center value to the interface using piecewise limited linear reconstruction on the characteristic variables.

Left and right states are then evolved for the half time step using characteristic tracing if necessary.

Parameters
[in]statepointer to State_1D structure
[in]beginitial index of computation
[in]endfinal index of computation
[in]gridpointer to an array of Grid structures

Definition at line 430 of file plm_states.c.

444 {
445  int i, j, k, nv;
446  double dvp[NVAR], dvm[NVAR], dv_lim[NVAR], dvc[NVAR], d2v;
447  double dw_lim[NVAR], dwp[NVAR], dwm[NVAR];
448  double dp, dm, dc;
449  double **vp, **vm, **v;
450  double **L, **R, *lambda;
451  double cp, cm, wp, wm, cpk[NVAR], cmk[NVAR];
452  double kstp[NVAR];
453  PLM_Coeffs plm_coeffs;
454  static double **dv;
455 
456 /* ---------------------------------------------
457  0. Allocate memory and set pointer shortcuts
458  --------------------------------------------- */
459 
460  if (dv == NULL) {
461  dv = ARRAY_2D(NMAX_POINT, NVAR, double);
462  }
463 
464  v = state->v;
465  vp = state->vp;
466  vm = state->vm;
467 
468  #if UNIFORM_CARTESIAN_GRID == NO
469  PLM_CoefficientsGet(&plm_coeffs, g_dir);
470  #endif
471 
472 /* ---------------------------------------------
473  Compute sound speed and then convert
474  to 4-vel if necessary.
475  --------------------------------------------- */
476 
477  SoundSpeed2 (state->v, state->a2, state->h, beg, end, CELL_CENTER, grid);
478 
479 #if RECONSTRUCT_4VEL
480  ConvertTo4vel (state->v, beg-1, end+1); /* From now up to the end of the
481  * function, v contains the 4-vel */
482 #endif
483 
484  for (i = beg-1; i <= end; i++){
485  NVAR_LOOP(nv) dv[i][nv] = v[i+1][nv] - v[i][nv];
486  }
487 
488 /* --------------------------------------------------------------
489  Set the amount of steepening for each characteristic family.
490  Default is 2, but nonlinear fields may be safely set to 1
491  for strongly nonlinear problems.
492  -------------------------------------------------------------- */
493 
494  for (k = NVAR; k--; ) kstp[k] = 2.0;
495  #if PHYSICS == HD || PHYSICS == RHD
496  kstp[0] = kstp[1] = 1.0;
497  #elif PHYSICS == MHD
498  kstp[KFASTP] = kstp[KFASTM] = 1.0;
499  #if COMPONENTS > 1
500  kstp[KSLOWP] = kstp[KSLOWM] = 1.0;
501  #endif
502  #endif
503 
504 /* --------------------------------------------------------------
505  2. Start main spatial loop
506  -------------------------------------------------------------- */
507 
508  for (i = beg; i <= end; i++){
509 
510  L = state->Lp[i];
511  R = state->Rp[i];
512  lambda = state->lambda[i];
513 
514  PrimEigenvectors(v[i], state->a2[i], state->h[i], lambda, L, R);
515 
516  /* ---------------------------------------------------------------
517  2a. Project forward, backward (and centered) undivided
518  differences of primitive variables along characteristics,
519  dw(k) = L(k).dv
520  --------------------------------------------------------------- */
521 
522  #if UNIFORM_CARTESIAN_GRID == YES
523  cp = cm = 2.0;
524  wp = wm = 1.0;
525  dp = dm = 0.5;
526  NVAR_LOOP(nv) {
527  dvp[nv] = dv[i][nv];
528  dvm[nv] = dv[i-1][nv];
529 
530  k = nv;
531  cpk[k] = cmk[k] = kstp[k];
532  }
533  #else
534  cp = plm_coeffs.cp[i]; cm = plm_coeffs.cm[i];
535  wp = plm_coeffs.wp[i]; wm = plm_coeffs.wm[i];
536  dp = plm_coeffs.dp[i]; dm = plm_coeffs.dm[i];
537  NVAR_LOOP(nv) {
538  dvp[nv] = dv[i][nv]*wp;
539  dvm[nv] = dv[i-1][nv]*wm;
540 
541  /* -- Map 1 < kstp < 2 ==> 1 < ck < c -- */
542 
543  k = nv;
544  cpk[k] = (2.0 - cp) + (cp - 1.0)*kstp[k]; /* used only for general */
545  cmk[k] = (2.0 - cm) + (cm - 1.0)*kstp[k]; /* minmod limiter */
546  }
547  #endif
548 
549  PrimToChar(L, dvm, dwm);
550  PrimToChar(L, dvp, dwp);
551 
552  /* ----------------------------------------------------------
553  2b. Apply slope limiter to characteristic differences for
554  nv < NFLX, dw = Limiter(dwp, dwm).
555  ------------------------------------------------------- */
556 
557  #if SHOCK_FLATTENING == MULTID
558  if (state->flag[i] & FLAG_FLAT) {
559  for (k = NFLX; k--; ) dw_lim[k] = 0.0;
560  } else if (state->flag[i] & FLAG_MINMOD) {
561  for (k = NFLX; k--; ){
562  SET_MM_LIMITER(dw_lim[k], dwp[k], dwm[k], cp, cm);
563  }
564  } else
565  #endif
566  for (k = NFLX; k--; ){
567  #if LIMITER == DEFAULT
568  SET_GM_LIMITER(dw_lim[k], dwp[k], dwm[k], cpk[k], cmk[k]);
569  #else
570  SET_LIMITER(dw_lim[k], dwp[k], dwm[k], cp, cm);
571  #endif
572  }
573 
574  /* ------------------------------------------------------------------
575  2c. Project limited slopes in characteristic variables on right
576  eigenvectors to obtain primitive slopes: dv = \sum dw.R
577 
578  Also, enforce monotonicity in primitive variables as well.
579  ------------------------------------------------------------------ */
580 
581  for (nv = NFLX; nv--; ){
582  dc = 0.0;
583  for (k = 0; k < NFLX; k++) dc += dw_lim[k]*R[nv][k];
584 
585  if (dvp[nv]*dvm[nv] > 0.0){
586  d2v = ABS_MIN(cp*dvp[nv], cm*dvm[nv]);
587  dv_lim[nv] = MINMOD(d2v, dc);
588  }else dv_lim[nv] = 0.0;
589  }
590 
591  /* -----------------------------------------------------------------
592  2d. Repeat construction for passive scalars (tracers).
593  For a passive scalar, the primitive variable is the same as
594  the characteristic one. We use the MC limiter always.
595  ----------------------------------------------------------------- */
596 
597  #if NFLX != NVAR
598  for (nv = NFLX; nv < NVAR; nv++ ){
599  #if LIMITER == DEFAULT
600  SET_MC_LIMITER(dv_lim[nv], dvp[nv], dvm[nv], cp, cm);
601  #else
602  SET_LIMITER(dv_lim[nv], dvp[nv], dvm[nv], cp, cm);
603  #endif
604  }
605  #endif
606 
607  /* --------------------------------------------------------------------
608  2e. Build L/R states at time level t^n
609  -------------------------------------------------------------------- */
610 
611  for (nv = NVAR; nv--; ) {
612  vp[i][nv] = v[i][nv] + dv_lim[nv]*dp;
613  vm[i][nv] = v[i][nv] - dv_lim[nv]*dm;
614  }
615 
616  #if (PHYSICS == RHD || PHYSICS == RMHD)
617  VelocityLimiter (v[i], vp[i], vm[i]);
618  #endif
619 
620  } /* -- end main loop on grid points -- */
621 
622 /* ----------------------------------------------------
623  3a. Check monotonicity
624  ---------------------------------------------------- */
625 
626  #if CHECK_MONOTONICITY == YES
627  MonotonicityTest(state->v, state->vp, state->vm, beg, end);
628  #endif
629 
630 /* -------------------------------------------
631  3b. Shock flattening (only 1D)
632  ------------------------------------------- */
633 
634  #if SHOCK_FLATTENING == ONED
635  Flatten (state, beg, end, grid);
636  #endif
637 
638 /* -------------------------------------------
639  4. Assign face-centered magnetic field
640  ------------------------------------------- */
641 
642  #ifdef STAGGERED_MHD
643  for (i = beg-1; i <= end; i++) {
644  state->vR[i][BXn] = state->vL[i][BXn] = state->bn[i];
645  }
646  #endif
647 
648 /* --------------------------------------------------------
649  5. Evolve L/R states and center value by dt/2
650  -------------------------------------------------------- */
651 
652  #if TIME_STEPPING == CHARACTERISTIC_TRACING
653  CharTracingStep(state, beg, end, grid);
654  #elif TIME_STEPPING == HANCOCK
655  HancockStep(state, beg, end, grid);
656  #endif
657 
658 /* --------------------------------------------------------
659  6. Convert back to 3-velocity
660  -------------------------------------------------------- */
661 
662 #if RECONSTRUCT_4VEL
663  ConvertTo3vel (state->v, beg-1, end+1);
664  ConvertTo3vel (state->vp, beg, end);
665  ConvertTo3vel (state->vm, beg, end);
666 #endif
667 
668 /* ----------------------------------------------
669  7. Obtain L/R states in conservative variables
670  ---------------------------------------------- */
671 
672  PrimToCons (state->vp, state->up, beg, end);
673  PrimToCons (state->vm, state->um, beg, end);
674 }
double ** v
Cell-centered primitive varables at the base time level, v[i] = .
Definition: structs.h:134
void VelocityLimiter(double *, double *, double *)
Definition: vel_limiter.c:16
void ConvertTo4vel(double **, int, int)
Definition: four_vel.c:4
int end
Global end index for the local array.
Definition: structs.h:116
void Flatten(const State_1D *, int, int, Grid *)
Definition: flatten.c:4
#define FLAG_FLAT
Reconstruct using FLAT limiter.
Definition: pluto.h:180
#define ABS_MIN(a, b)
Definition: macros.h:107
double *** Lp
Definition: structs.h:155
void PrimEigenvectors(double *q, double cs2, double h, double *lambda, double **LL, double **RR)
Definition: eigenv.c:91
void CharTracingStep(const State_1D *, int, int, Grid *)
Definition: char_tracing.c:198
double * cm
Definition: plm_coeffs.h:40
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
double * h
Enthalpy.
Definition: structs.h:159
#define SET_GM_LIMITER(dv, dvp, dvm, cp, cm)
Definition: plm_coeffs.h:96
#define FLAG_MINMOD
Reconstruct using MINMOD limiter.
Definition: pluto.h:179
void SoundSpeed2(double **v, double *cs2, double *h, int beg, int end, int pos, Grid *grid)
Definition: eos.c:16
int BXn
Definition: globals.h:75
double ** vp
prim vars at i+1/2 edge, vp[i] = vL(i+1/2)
Definition: structs.h:142
#define CELL_CENTER
Definition: pluto.h:205
#define NFLX
Definition: mod_defs.h:32
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
#define NVAR_LOOP(n)
Definition: pluto.h:618
#define SET_MC_LIMITER(dv, dvp, dvm, cp, cm)
Definition: plm_coeffs.h:119
int j
Definition: analysis.c:2
double ** lambda
Characteristic speed associated to Lp and Rp.
Definition: structs.h:156
unsigned char * flag
Definition: structs.h:168
double * cp
Definition: plm_coeffs.h:39
int k
Definition: analysis.c:2
void ConvertTo3vel(double **, int, int)
Definition: four_vel.c:25
#define MINMOD(a, b)
Definition: macros.h:112
void PrimToChar(double **L, double *v, double *w)
Definition: eigenv.c:593
#define SET_MM_LIMITER(dv, dvp, dvm, cp, cm)
Definition: plm_coeffs.h:76
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
Definition: structs.h:141
void PLM_CoefficientsGet(PLM_Coeffs *plm_coeffs, int dir)
Definition: plm_coeffs.c:79
double * dm
Definition: plm_coeffs.h:44
double * dp
Definition: plm_coeffs.h:43
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
double * bn
Face magentic field, bn = bx(i+1/2)
Definition: structs.h:165
static void MonotonicityTest(double **, double **, double **, int, int)
Definition: plm_states.c:679
double ** um
same as vm, in conservative vars
Definition: structs.h:146
double * wm
Definition: plm_coeffs.h:42
double ** vL
Primitive variables to the left of the interface, .
Definition: structs.h:136
double * a2
Sound speed squared.
Definition: structs.h:158
double ** up
same as vp, in conservative vars
Definition: structs.h:147
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
double *** Rp
Left and right primitive eigenvectors.
Definition: structs.h:155
#define NVAR
Definition: pluto.h:609
double * wp
Definition: plm_coeffs.h:41
void HancockStep(const State_1D *, int, int, Grid *)
Definition: hancock.c:136

Here is the call graph for this function:

Here is the caller graph for this function:

void STS ( const Data d,
Time_Step Dts,
Grid grid 
)

Solve diffusion equation(s) using Super-Time-Stepping.

Parameters
[in,out]dpointer to Data structure
[in,out]Dtspointer to Time_Step structure
[in]gridpointer to an array of Grid structures

Definition at line 55 of file sts.c.

64 {
65  int i, j, k, nv, n, m;
66  double N, ts[STS_MAX_STEPS];
67  double dt_par, tau, tsave, inv_dtp;
68  static Data_Arr rhs;
69  RBox *box = GetRBox(DOM, CENTER);
70 
71  if (rhs == NULL) rhs = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
72 
73 /* -------------------------------------------------------------
74  Compute the conservative vector in order to start the cycle.
75  This step will be useless if the data structure
76  contains Vc as well as Uc (for future improvements).
77  ------------------------------------------------------------- */
78 
79  PrimToCons3D(d->Vc, d->Uc, box);
80  tsave = g_time;
81 
82 /* ------------------------------------------------------------
83  Main STS Loop starts here
84  ------------------------------------------------------------ */
85 
86  m = 0;
87  n = STS_MAX_STEPS;
88  while (m < n){
89 
90  g_intStage = m + 1;
91  Boundary(d, ALL_DIR, grid);
92  inv_dtp = ParabolicRHS(d, rhs, 1.0, grid);
93 
94  /* --------------------------------------------------------------
95  At the first step (m=0) compute (explicit) parabolic time
96  step. Restriction on explicit time step should be
97 
98  [2*eta_x/dx^2 + 2*eta_y/dy^2 + 2*eta_z/dz^2]*dt < 1
99 
100  which in PLUTO is normally written as
101 
102  [2/dtp_x + 2/dtp_y + 2/dtp_z]*dt/Ndim = 1/Ndim = cfl_par
103 
104  where Ndim is the number of spatial dimensions.
105  -------------------------------------------------------------- */
106 
107  if (m == 0){
108  Dts->inv_dtp = inv_dtp/(double)DIMENSIONS;
109  #ifdef PARALLEL
110  MPI_Allreduce (&Dts->inv_dtp, &tau, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
111  Dts->inv_dtp = tau;
112  #endif
113  Dts->inv_dtp = MAX(Dts->inv_dtp, 1.e-18);
114  dt_par = Dts->cfl_par/(2.0*Dts->inv_dtp); /* explicit parabolic
115  time step */
116  /* -------------------------------------------
117  Compute the number of steps needed to fit
118  the supertimestep with the advection one.
119  ------------------------------------------- */
120 
121  N = STS_FindRoot(1.0, dt_par, g_dt);
122  N = floor(N+1.0);
123  n = (int)N;
124 
125  Dts->Nsts = n;
126  if (n > STS_MAX_STEPS){
127  print1 ("! STS: the number of substeps (%d) is > %d\n",n, STS_MAX_STEPS);
128  QUIT_PLUTO(1);
129  }
130 
131  /* ------------------------------------------
132  Adjust explicit timestep to make Nsts an
133  integer number and compute the substeps.
134  ------------------------------------------ */
135 
136  if (Dts->Nsts > 1){
137  dt_par = STS_CorrectTimeStep(Dts->Nsts, g_dt);
138  STS_ComputeSubSteps(dt_par, ts, Dts->Nsts);
139  }
140 
141  if (Dts->Nsts == 1) ts[0] = g_dt;
142 
143  } /* end if m == 0 */
144 
145  tau = ts[n-m-1];
146 
147  /* -----------------------------------------------
148  Update cell-centered conservative variables
149  ----------------------------------------------- */
150 
151  DOM_LOOP (k,j,i){
152  #if VISCOSITY == SUPER_TIME_STEPPING
153  EXPAND(d->Uc[k][j][i][MX1] += tau*rhs[k][j][i][MX1]; ,
154  d->Uc[k][j][i][MX2] += tau*rhs[k][j][i][MX2]; ,
155  d->Uc[k][j][i][MX3] += tau*rhs[k][j][i][MX3];)
156  #endif
157  #if (RESISTIVITY == SUPER_TIME_STEPPING)
158  EXPAND(d->Uc[k][j][i][BX1] += tau*rhs[k][j][i][BX1]; ,
159  d->Uc[k][j][i][BX2] += tau*rhs[k][j][i][BX2]; ,
160  d->Uc[k][j][i][BX3] += tau*rhs[k][j][i][BX3];)
161  #endif
162  #if HAVE_ENERGY
163  #if (THERMAL_CONDUCTION == SUPER_TIME_STEPPING) || \
164  (RESISTIVITY == SUPER_TIME_STEPPING) || \
165  (VISCOSITY == SUPER_TIME_STEPPING)
166  d->Uc[k][j][i][ENG] += tau*rhs[k][j][i][ENG];
167  #endif
168  #endif
169  }
170  #if (defined STAGGERED_MHD) && (RESISTIVITY == SUPER_TIME_STEPPING)
171 
172  /* -----------------------------------------------
173  Update staggered magnetic field variables
174  ----------------------------------------------- */
175 
176 /* This piece of code should be used for simple Cartesian 2D
177  configurations with constant resistivity.
178  It shows that the stability limit of the resistive part of the
179  induction equation is larger if the right hand side is written
180  as Laplacian(B) rather than curl(J)
181 
182 double ***Bx, ***By, ***Bz, Jz, dx, dy, dt;
183 static double ***Ez, ***Rx, ***Ry;
184 if (Ez == NULL) {
185  Ez = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
186  Rx = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
187  Ry = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
188 }
189 Bx = d->Vs[BX1s];
190 By = d->Vs[BX2s];
191 dx = grid[IDIR].dx[IBEG];
192 dy = grid[JDIR].dx[JBEG];
193 
194 dt = tau;
195 k=0;
196 for (j = 1; j < NX2_TOT-1; j++) for (i = 1; i < NX1_TOT-1; i++){
197  Jz = (By[k][j][i+1] - By[k][j][i])/dx - (Bx[k][j+1][i] - Bx[k][j][i])/dy;
198  Ez[k][j][i] = Jz*g_inputParam[ETAZ];
199  Rx[k][j][i] = (Bx[k][j][i+1] - 2.0*Bx[k][j][i] + Bx[k][j][i-1])/(dx*dx)
200  + (Bx[k][j+1][i] - 2.0*Bx[k][j][i] + Bx[k][j-1][i])/(dy*dy);
201 
202  Ry[k][j][i] = (By[k][j][i+1] - 2.0*By[k][j][i] + By[k][j][i-1])/(dx*dx)
203  + (By[k][j+1][i] - 2.0*By[k][j][i] + By[k][j-1][i])/(dy*dy);
204 }
205 
206 JDOM_LOOP(j) for (i = IBEG-1; i <= IEND; i++){
207 // Bx[k][j][i] += - dt/dy*(Ez[k][j][i] - Ez[k][j-1][i]);
208  Bx[k][j][i] += dt*g_inputParam[ETAZ]*Rx[k][j][i];
209 }
210 
211 for (j = JBEG-1; j <= JEND; j++) IDOM_LOOP(i){
212 // By[k][j][i] += dt/dx*(Ez[k][j][i] - Ez[k][j][i-1]);
213  By[k][j][i] += dt*g_inputParam[ETAZ]*Ry[k][j][i];
214 }
215 */
216  CT_Update (d, d->Vs, tau, grid);
217  CT_AverageMagneticField (d->Vs, d->Uc, grid);
218  #endif
219 
220  /* --------------------------------------------------
221  Unflag zone tagged with the ENTROPY_SWITCH since
222  only total energy can be evolved using STS
223  -------------------------------------------------- */
224 
225  #if ENTROPY_SWITCH
226  TOT_LOOP(k,j,i) d->flag[k][j][i] &= ~FLAG_ENTROPY;
227  #endif
228 
229  /* ----------------------------------------------
230  convert conservative variables to primitive
231  for next iteration. Increment loop index.
232  ---------------------------------------------- */
233 
234  ConsToPrim3D(d->Uc, d->Vc, d->flag, box);
235  g_time += ts[n-m-1];
236  m++;
237  }
238  g_time = tsave; /* restore initial time step */
239 }
#define MX3
Definition: mod_defs.h:22
void Boundary(const Data *d, int idim, Grid *grid)
Definition: boundary.c:36
#define MAX(a, b)
Definition: macros.h:101
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
#define MX1
Definition: mod_defs.h:20
double **** Data_Arr
Definition: pluto.h:492
DOM_LOOP(k, j, i)
Definition: analysis.c:22
static int n
Definition: analysis.c:3
RBox * GetRBox(int, int)
Definition: rbox.c:232
#define CENTER
Definition: pluto.h:200
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
void PrimToCons3D(Data_Arr V, Data_Arr U, RBox *box)
Definition: mappers3D.c:86
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
double g_dt
The current integration time step.
Definition: globals.h:118
double ParabolicRHS(const Data *d, Data_Arr dU, double dt, Grid *grid)
Definition: parabolic_rhs.c:50
#define DOM
Computational domain (interior)
Definition: pluto.h:152
void CT_Update(const Data *d, Data_Arr Bs, double dt, Grid *grid)
Definition: ct.c:29
static void STS_ComputeSubSteps(double, double tau[], int)
Definition: sts.c:242
unsigned char *** flag
Pointer to a 3D array setting useful integration flags that are retrieved during integration.
Definition: structs.h:55
void ConsToPrim3D(Data_Arr U, Data_Arr V, unsigned char ***flag, RBox *box)
Definition: mappers3D.c:16
double inv_dtp
Inverse of diffusion (parabolic) time step .
Definition: structs.h:217
static double STS_CorrectTimeStep(int, double)
Definition: sts.c:289
#define TOT_LOOP(k, j, i)
Definition: macros.h:44
#define FLAG_ENTROPY
Update pressure using entropy equation.
Definition: pluto.h:182
double cfl_par
Courant number for diffusion (STS only).
Definition: structs.h:221
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int j
Definition: analysis.c:2
#define MX2
Definition: mod_defs.h:21
#define ARRAY_4D(nx, ny, nz, nv, type)
Definition: prototypes.h:173
int k
Definition: analysis.c:2
#define BX3
Definition: mod_defs.h:27
static double STS_FindRoot(double, double, double)
Definition: sts.c:258
#define STS_MAX_STEPS
Definition: sts.c:49
int i
Definition: analysis.c:2
double g_time
The current integration time.
Definition: globals.h:117
double **** Uc
The main four-index data array used for cell-centered conservative variables.
Definition: structs.h:37
#define BX1
Definition: mod_defs.h:25
int Nsts
Maximum number of substeps used in STS.
Definition: structs.h:223
#define BX2
Definition: mod_defs.h:26
#define NVAR
Definition: pluto.h:609
Definition: structs.h:346
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
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
void CT_AverageMagneticField(double ****bf, double ****UU, Grid *grid)
#define ALL_DIR
Definition: pluto.h:196

Here is the call graph for this function:

Here is the caller graph for this function:

void SwapEndian ( void *  x,
const int  nbytes 
)

Swap the byte order of x.

Parameters
[in]xpointer to the variable being swapped
[in]nbytesdata type size
Returns
This function has no return value.

Definition at line 203 of file tools.c.

211 {
212  int k;
213  static char Swapped[16];
214  char *c;
215 
216  c = (char *) x;
217 
218  for (k = nbytes; k--; ) Swapped[k] = *(c + nbytes - 1 - k);
219  for (k = nbytes; k--; ) c[k] = Swapped[k];
220 }
int k
Definition: analysis.c:2
double * x
Definition: structs.h:80
tuple c
Definition: menu.py:375
void Trace ( double  xx)

Print a number xx and the number of times it has been called.

Definition at line 223 of file tools.c.

228 {
229  static int ik;
230 
231  printf ("Trace ------> %f , %d\n", xx, ++ik);
232 }
void UnsetJetDomain ( const Data d,
int  dir,
Grid grid 
)

Restore original (full domain) indexes.

Definition at line 154 of file jet_domain.c.

159 {
160 
161  if (dir == IDIR){
162  IBEG = grid[IDIR].lbeg = jd_nbeg;
163  IEND = grid[IDIR].lend = jd_nend;
164  NX1_TOT = jd_ntot;
165  NX1 = jd_npt;
166  grid[IDIR].rbound = rbound;
167  }
168 
169  if (dir == JDIR){
170  JBEG = grid[JDIR].lbeg = jd_nbeg;
171  JEND = grid[JDIR].lend = jd_nend;
172  NX2_TOT = jd_ntot;
173  NX2 = jd_npt;
174  grid[JDIR].rbound = rbound;
175  }
176 
177  if (dir == KDIR){
178  KBEG = grid[KDIR].lbeg = jd_nbeg;
179  KEND = grid[KDIR].lend = jd_nend;
180  NX3_TOT = jd_ntot;
181  NX3 = jd_npt;
182  grid[KDIR].rbound = rbound;
183  }
184 
185 /* ------------------------------------------------------
186  Recompute RBox(es) after indices have been changed
187  ------------------------------------------------------ */
188 
189  SetRBox();
190 
191 }
static int jd_ntot
Definition: jet_domain.c:25
static int jd_npt
Definition: jet_domain.c:25
static int rbound
Definition: jet_domain.c:25
long int NX1
Number of interior zones in the X1 directions (boundaries excluded) for the local processor...
Definition: globals.h:48
int rbound
Same as lbound, but for the right edge of the grid.
Definition: structs.h:112
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
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
#define KDIR
Definition: pluto.h:195
long int NX2
Number of interior zones in the X2 directions (boundaries excluded) for the local processor...
Definition: globals.h:50
#define IDIR
Definition: pluto.h:193
static int jd_nend
Definition: jet_domain.c:25
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
void SetRBox(void)
Definition: rbox.c:33
static int jd_nbeg
Definition: jet_domain.c:25
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
#define JDIR
Definition: pluto.h:194
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int NX3
Number of interior zones in the X3 directions (boundaries excluded) for the local processor...
Definition: globals.h:52
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35

Here is the call graph for this function:

Here is the caller graph for this function:

void UpdateStage ( const Data d,
Data_Arr  UU,
double **  aflux,
Riemann_Solver Riemann,
double  dt,
Time_Step Dts,
Grid grid 
)
Parameters
[in,out]dpointer to PLUTO Data structure
[in,out]UUdata array containing conservative variables at the previous time step to be updated
[out]afluxinterface fluxes needed for refluxing operations (only with AMR)
[in]Riemannpointer to a Riemann solver function
[in]dtthe time step for the current update step
[in,out]Dtspointer to time step structure
[in]gridpointer to array of Grid structures

Definition at line 38 of file update_stage.c.

53 {
54  int i, j, k;
55  int nv, dir, beg_dir, end_dir;
56  int *ip;
57  double *inv_dl, dl2;
58  static double ***T, ***C_dt[NVAR], **dcoeff;
59  static State_1D state;
60  Index indx;
61  intList cdt_list;
62 
63  #if DIMENSIONAL_SPLITTING == YES
64  beg_dir = end_dir = g_dir;
65  #else
66  beg_dir = 0;
67  end_dir = DIMENSIONS-1;
68  #endif
69 
70  cdt_list = TimeStepIndexList();
71 
72 /* --------------------------------------------------------------
73  1. Allocate memory
74  -------------------------------------------------------------- */
75 
76  if (state.v == NULL){
77  MakeState (&state);
78  #if (PARABOLIC_FLUX & EXPLICIT)
79  dcoeff = ARRAY_2D(NMAX_POINT, NVAR, double);
80  #endif
81  }
82 
83 /* --------------------------------------------------------------
84  2. Reset arrays.
85  C_dt is an array used to store the inverse time step for
86  advection and diffusion.
87  We use C_dt[RHO] for advection,
88  C_dt[MX1] for viscosity,
89  C_dt[BX1...BX3] for resistivity and
90  C_dt[ENG] for thermal conduction.
91  --------------------------------------------------------------- */
92 
93  #if DIMENSIONAL_SPLITTING == NO
94  if (C_dt[RHO] == NULL){
95  FOR_EACH(nv, 0, (&cdt_list)) {
96  C_dt[nv] = ARRAY_3D(NX3_MAX, NX2_MAX, NX1_MAX, double);
97  }
98  }
99 
100  if (g_intStage == 1) KTOT_LOOP(k) JTOT_LOOP(j){
101  FOR_EACH(nv, 0, (&cdt_list)) {
102  memset ((void *)C_dt[nv][k][j],'\0', NX1_TOT*sizeof(double));
103  }
104  }
105  #endif
106 
107 /* ------------------------------------------------
108  2a. Compute current arrays
109  ------------------------------------------------ */
110 
111  #if (RESISTIVITY == EXPLICIT) && (defined STAGGERED_MHD)
112  GetCurrent (d, -1, grid);
113  #endif
114 
115 /* ------------------------------------------------
116  2b. Compute Temperature array
117  ------------------------------------------------ */
118 
119  #if THERMAL_CONDUCTION == EXPLICIT
120  if (T == NULL) T = ARRAY_3D(NX3_MAX, NX2_MAX, NX1_MAX, double);
121  TOT_LOOP(k,j,i) T[k][j][i] = d->Vc[PRS][k][j][i]/d->Vc[RHO][k][j][i];
122  #endif
123 
124 /* ----------------------------------------------------------------
125  3. Main loop on directions
126  ---------------------------------------------------------------- */
127 
128  for (dir = beg_dir; dir <= end_dir; dir++){
129 
130  g_dir = dir;
131  SetIndexes (&indx, grid); /* -- set normal and transverse indices -- */
132  ResetState (d, &state, grid);
133 
134  #if (RESISTIVITY == EXPLICIT) && !(defined STAGGERED_MHD)
135  GetCurrent(d, dir, grid);
136  #endif
137 
138  TRANSVERSE_LOOP(indx,ip,i,j,k){
139  g_i = i; g_j = j; g_k = k;
140  for ((*ip) = 0; (*ip) < indx.ntot; (*ip)++) {
141  VAR_LOOP(nv) state.v[(*ip)][nv] = d->Vc[nv][k][j][i];
142  state.flag[*ip] = d->flag[k][j][i];
143  #ifdef STAGGERED_MHD
144  state.bn[(*ip)] = d->Vs[g_dir][k][j][i];
145  #endif
146  }
147  CheckNaN (state.v, 0, indx.ntot-1,0);
148  States (&state, indx.beg - 1, indx.end + 1, grid);
149  Riemann (&state, indx.beg - 1, indx.end, Dts->cmax, grid);
150  #ifdef STAGGERED_MHD
151  CT_StoreEMF (&state, indx.beg - 1, indx.end, grid);
152  #endif
153  #if (PARABOLIC_FLUX & EXPLICIT)
154  ParabolicFlux(d->Vc, d->J, T, &state, dcoeff, indx.beg-1, indx.end, grid);
155  #endif
156  #if UPDATE_VECTOR_POTENTIAL == YES
157  VectorPotentialUpdate (d, NULL, &state, grid);
158  #endif
159  #ifdef SHEARINGBOX
160  SB_SaveFluxes (&state, grid);
161  #endif
162  RightHandSide (&state, Dts, indx.beg, indx.end, dt, grid);
163 
164  /* -- update: U = U + dt*R -- */
165 
166  #ifdef CHOMBO
167  for ((*ip) = indx.beg; (*ip) <= indx.end; (*ip)++) {
168  VAR_LOOP(nv) UU[nv][k][j][i] += state.rhs[*ip][nv];
169  }
170  SaveAMRFluxes (&state, aflux, indx.beg-1, indx.end, grid);
171  #else
172  for ((*ip) = indx.beg; (*ip) <= indx.end; (*ip)++) {
173  VAR_LOOP(nv) UU[k][j][i][nv] += state.rhs[*ip][nv];
174  }
175  #endif
176 
177  if (g_intStage > 1) continue;
178 
179  /* -- compute inverse dt coefficients when g_intStage = 1 -- */
180 
181  inv_dl = GetInverse_dl(grid);
182  for ((*ip) = indx.beg; (*ip) <= indx.end; (*ip)++) {
183  #if DIMENSIONAL_SPLITTING == NO
184 
185  #if !GET_MAX_DT
186  C_dt[0][k][j][i] += 0.5*( Dts->cmax[(*ip)-1]
187  + Dts->cmax[*ip])*inv_dl[*ip];
188  #endif
189  #if (PARABOLIC_FLUX & EXPLICIT)
190  dl2 = 0.5*inv_dl[*ip]*inv_dl[*ip];
191  FOR_EACH(nv, 1, (&cdt_list)) {
192  C_dt[nv][k][j][i] += (dcoeff[*ip][nv]+dcoeff[(*ip)-1][nv])*dl2;
193  }
194  #endif
195 
196  #elif DIMENSIONAL_SPLITTING == YES
197 
198  #if !GET_MAX_DT
199  Dts->inv_dta = MAX(Dts->inv_dta, Dts->cmax[*ip]*inv_dl[*ip]);
200  #endif
201  #if (PARABOLIC_FLUX & EXPLICIT)
202  dl2 = inv_dl[*ip]*inv_dl[*ip];
203  FOR_EACH(nv, 1, (&cdt_list)) {
204  Dts->inv_dtp = MAX(Dts->inv_dtp, dcoeff[*ip][nv]*dl2);
205  }
206  #endif
207  #endif
208  }
209  }
210  }
211 
212 /* -------------------------------------------------------------------
213  4. Additional terms here
214  ------------------------------------------------------------------- */
215 
216  #if (ENTROPY_SWITCH) && (RESISTIVITY == EXPLICIT)
217  EntropyOhmicHeating(d, UU, dt, grid);
218  #endif
219 
220  #ifdef SHEARINGBOX
221  SB_CorrectFluxes (UU, 0.0, dt, grid);
222  #endif
223 
224  #ifdef STAGGERED_MHD
225  CT_Update(d, d->Vs, dt, grid);
226  #endif
227 
228  #if DIMENSIONAL_SPLITTING == YES
229  return;
230  #endif
231 
232 /* -------------------------------------------------------------------
233  5. Reduce dt for dimensionally unsplit schemes.
234  ------------------------------------------------------------------- */
235 
236  if (g_intStage > 1) return;
237 
238  for (k = KBEG; k <= KEND; k++){ g_k = k;
239  for (j = JBEG; j <= JEND; j++){ g_j = j;
240  for (i = IBEG; i <= IEND; i++){
241  #if !GET_MAX_DT
242  Dts->inv_dta = MAX(Dts->inv_dta, C_dt[0][k][j][i]);
243  #endif
244  #if (PARABOLIC_FLUX & EXPLICIT)
245  FOR_EACH(nv, 1, (&cdt_list)) {
246  Dts->inv_dtp = MAX(Dts->inv_dtp, C_dt[nv][k][j][i]);
247  }
248  #endif
249  }
250  }}
251  #if !GET_MAX_DT
252  Dts->inv_dta /= (double)DIMENSIONS;
253  #endif
254  #if (PARABOLIC_FLUX & EXPLICIT)
255  Dts->inv_dtp /= (double)DIMENSIONS;
256  #endif
257 
258 }
static void SaveAMRFluxes(const State_1D *, double **, int, int, Grid *)
#define MAX(a, b)
Definition: macros.h:101
tuple T
Definition: Sph_disk.py:33
void CT_StoreEMF(const State_1D *state, int beg, int end, Grid *grid)
Definition: ct_emf.c:35
double ** v
Cell-centered primitive varables at the base time level, v[i] = .
Definition: structs.h:134
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
void ResetState(const Data *, State_1D *, Grid *)
Definition: set_indexes.c:163
int end
Global end index for the local array.
Definition: structs.h:116
void EntropyOhmicHeating(const Data *, Data_Arr, double, Grid *)
double **** J
Electric current defined as curl(B).
Definition: structs.h:54
void GetCurrent(const Data *d, int dir, Grid *grid)
Definition: res_functions.c:97
int ntot
Definition: structs.h:318
void States(const State_1D *, int, int, Grid *)
Definition: plm_states.c:430
#define RHO
Definition: mod_defs.h:19
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
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 * GetInverse_dl(const Grid *)
Definition: set_geometry.c:205
void SB_CorrectFluxes(Data_Arr U, double t, double dt, Grid *grid)
Definition: sb_flux.c:105
void CT_Update(const Data *d, Data_Arr Bs, double dt, Grid *grid)
Definition: ct.c:29
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
double * cmax
Maximum signal velocity for hyperbolic eqns.
Definition: structs.h:214
#define FOR_EACH(nv, beg, list)
Definition: macros.h:89
void MakeState(State_1D *)
Definition: tools.c:51
double inv_dtp
Inverse of diffusion (parabolic) time step .
Definition: structs.h:217
#define NX3_MAX
Definition: pluto.h:743
double inv_dta
Inverse of advection (hyperbolic) time step, .
Definition: structs.h:215
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
Definition: globals.h:82
int CheckNaN(double **, int, int, int)
Definition: tools.c:19
#define VAR_LOOP(n)
Definition: macros.h:226
#define NX2_MAX
Definition: pluto.h:742
#define TOT_LOOP(k, j, i)
Definition: macros.h:44
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
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
int j
Definition: analysis.c:2
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
void SetIndexes(Index *indx, Grid *grid)
Definition: set_indexes.c:49
void RightHandSide(const State_1D *state, Time_Step *Dts, int beg, int end, double dt, Grid *grid)
Definition: rhs.c:88
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
int beg
Definition: structs.h:318
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
double * bn
Face magentic field, bn = bx(i+1/2)
Definition: structs.h:165
Definition: structs.h:317
void SB_SaveFluxes(State_1D *state, Grid *grid)
Definition: sb_flux.c:57
void ParabolicFlux(Data_Arr V, Data_Arr J, double ***T, const State_1D *state, double **dcoeff, int beg, int end, Grid *grid)
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
static intList TimeStepIndexList()
Definition: update_stage.c:456
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
void VectorPotentialUpdate(const Data *d, const void *vp, const State_1D *state, const Grid *grid)
int end
Definition: structs.h:318
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
#define NVAR
Definition: pluto.h:609
#define NX1_MAX
Definition: pluto.h:741
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
#define TRANSVERSE_LOOP(indx, ip, i, j, k)
Definition: macros.h:54
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
#define DIMENSIONS
Definition: definitions_01.h:2

Here is the call graph for this function:

Here is the caller graph for this function:

void UserDefBoundary ( const Data d,
RBox box,
int  side,
Grid grid 
)

Assign user-defined boundary conditions.

Parameters
[in,out]dpointer to the PLUTO data structure containing cell-centered primitive quantities (d->Vc) and staggered magnetic fields (d->Vs, when used) to be filled.
[in]boxpointer to a RBox structure containing the lower and upper indices of the ghost zone-centers/nodes or edges at which data values should be assigned.
[in]sidespecifies the boundary side where ghost zones need to be filled. It can assume the following pre-definite values: X1_BEG, X1_END, X2_BEG, X2_END, X3_BEG, X3_END. The special value side == 0 is used to control a region inside the computational domain.
[in]gridpointer to an array of Grid structures.

Assign user-defined boundary conditions in the lower boundary ghost zones. The profile is top-hat:

\[ V_{ij} = \left\{\begin{array}{ll} V_{\rm jet} & \quad\mathrm{for}\quad r_i < 1 \\ \noalign{\medskip} \mathrm{Reflect}(V) & \quad\mathrm{otherwise} \end{array}\right. \]

where $ V_{\rm jet} = (\rho,v,p)_{\rm jet} = (1,M,1/\Gamma)$ and M is the flow Mach number (the unit velocity is the jet sound speed, so $ v = M$).

Assign user-defined boundary conditions:

  • left side (x beg): constant shocked values
  • bottom side (y beg): constant shocked values for x < 1/6 and reflective boundary otherwise.
  • top side (y end): time-dependent boundary: for $ x < x_s(t) = 10 t/\sin\alpha + 1/6 + 1.0/\tan\alpha $ we use fixed (post-shock) values. Unperturbed values otherwise.

Assign user-defined boundary conditions at inner and outer radial boundaries. Reflective conditions are applied except for the azimuthal velocity which is fixed.

Assign user-defined boundary conditions.

Parameters
[in/out]d pointer to the PLUTO data structure containing cell-centered primitive quantities (d->Vc) and staggered magnetic fields (d->Vs, when used) to be filled.
[in]boxpointer to a RBox structure containing the lower and upper indices of the ghost zone-centers/nodes or edges at which data values should be assigned.
[in]sidespecifies on which side boundary conditions need to be assigned. side can assume the following pre-definite values: X1_BEG, X1_END, X2_BEG, X2_END, X3_BEG, X3_END. The special value side == 0 is used to control a region inside the computational domain.
[in]gridpointer to an array of Grid structures.

Set the injection boundary condition at the lower z-boundary (X2-beg must be set to userdef in pluto.ini). For $ R \le 1 $ we set constant input values (given by the GetJetValues() function while for $ R > 1 $ the solution has equatorial symmetry with respect to the z=0 plane. To avoid numerical problems with a "top-hat" discontinuous jump, we smoothly merge the inlet and reflected value using a profile function Profile().

Provide inner radial boundary condition in polar geometry. Zero gradient is prescribed on density, pressure and magnetic field. For the velocity, zero gradient is imposed on v/r (v = vr, vphi).

The user-defined boundary is used to impose stress-free boundary and purely vertical magnetic field at the top and bottom boundaries, as done in Bodo et al. (2012). In addition, constant temperature and hydrostatic balance are imposed. For instance, at the bottom boundary, one has:

\[ \left\{\begin{array}{lcl} \DS \frac{dp}{dz} &=& \rho g_z \\ \noalign{\medskip} p &=& \rho c_s^2 \end{array}\right. \qquad\Longrightarrow\qquad \frac{p_{k+1}-p_k}{\Delta z} = \frac{p_{k} + p_{k+1}}{2c_s^2}g_z \]

where $g_z$ is the value of gravity at the lower boundary. Solving for $p_k$ at the bottom boundary where $k=k_b-1$ gives:

\[ \left\{\begin{array}{lcl} p_k &=& \DS p_{k+1} \frac{1-a}{1+a} \\ \noalign{\medskip} \rho_k &=& \DS \frac{p_k}{c_s^2} \end{array}\right. \qquad\mathrm{where}\qquad a = \frac{\Delta z g_z}{2c_s^2} > 0 \]

where, for simplicity, we keep constant temperature in the ghost zones rather than at the boundary interface (this seems to give a more stable behavior and avoids negative densities). A similar treatment holds at the top boundary.

Assign user-defined boundary conditions. At the inner boundary we use outflow conditions, except for velocity which we reset to zero when there's an inflow

Definition at line 98 of file init.c.

119 {
120  int i, j, k, nv;
121  double *x1, *x2, *x3;
122 
123  x1 = grid[IDIR].x;
124  x2 = grid[JDIR].x;
125  x3 = grid[KDIR].x;
126 
127  if (side == 0) { /* -- check solution inside domain -- */
128  DOM_LOOP(k,j,i){};
129  }
130 
131  if (side == X1_BEG){ /* -- X1_BEG boundary -- */
132  if (box->vpos == CENTER) {
133  BOX_LOOP(box,k,j,i){ }
134  }else if (box->vpos == X1FACE){
135  BOX_LOOP(box,k,j,i){ }
136  }else if (box->vpos == X2FACE){
137  BOX_LOOP(box,k,j,i){ }
138  }else if (box->vpos == X3FACE){
139  BOX_LOOP(box,k,j,i){ }
140  }
141  }
142 
143  if (side == X1_END){ /* -- X1_END boundary -- */
144  if (box->vpos == CENTER) {
145  BOX_LOOP(box,k,j,i){ }
146  }else if (box->vpos == X1FACE){
147  BOX_LOOP(box,k,j,i){ }
148  }else if (box->vpos == X2FACE){
149  BOX_LOOP(box,k,j,i){ }
150  }else if (box->vpos == X3FACE){
151  BOX_LOOP(box,k,j,i){ }
152  }
153  }
154 
155  if (side == X2_BEG){ /* -- X2_BEG boundary -- */
156  if (box->vpos == CENTER) {
157  BOX_LOOP(box,k,j,i){ }
158  }else if (box->vpos == X1FACE){
159  BOX_LOOP(box,k,j,i){ }
160  }else if (box->vpos == X2FACE){
161  BOX_LOOP(box,k,j,i){ }
162  }else if (box->vpos == X3FACE){
163  BOX_LOOP(box,k,j,i){ }
164  }
165  }
166 
167  if (side == X2_END){ /* -- X2_END boundary -- */
168  if (box->vpos == CENTER) {
169  BOX_LOOP(box,k,j,i){ }
170  }else if (box->vpos == X1FACE){
171  BOX_LOOP(box,k,j,i){ }
172  }else if (box->vpos == X2FACE){
173  BOX_LOOP(box,k,j,i){ }
174  }else if (box->vpos == X3FACE){
175  BOX_LOOP(box,k,j,i){ }
176  }
177  }
178 
179  if (side == X3_BEG){ /* -- X3_BEG boundary -- */
180  if (box->vpos == CENTER) {
181  BOX_LOOP(box,k,j,i){ }
182  }else if (box->vpos == X1FACE){
183  BOX_LOOP(box,k,j,i){ }
184  }else if (box->vpos == X2FACE){
185  BOX_LOOP(box,k,j,i){ }
186  }else if (box->vpos == X3FACE){
187  BOX_LOOP(box,k,j,i){ }
188  }
189  }
190 
191  if (side == X3_END){ /* -- X3_END boundary -- */
192  if (box->vpos == CENTER) {
193  BOX_LOOP(box,k,j,i){ }
194  }else if (box->vpos == X1FACE){
195  BOX_LOOP(box,k,j,i){ }
196  }else if (box->vpos == X2FACE){
197  BOX_LOOP(box,k,j,i){ }
198  }else if (box->vpos == X3FACE){
199  BOX_LOOP(box,k,j,i){ }
200  }
201  }
202 }
#define X3_BEG
Boundary region at X3 beg.
Definition: pluto.h:150
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
DOM_LOOP(k, j, i)
Definition: analysis.c:22
#define CENTER
Definition: pluto.h:200
int vpos
Location of the variable inside the cell.
Definition: structs.h:359
#define X3FACE
Definition: pluto.h:203
#define BOX_LOOP(B, k, j, i)
Definition: macros.h:70
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
#define KDIR
Definition: pluto.h:195
#define X1FACE
Definition: pluto.h:201
#define IDIR
Definition: pluto.h:193
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
double * x
Definition: structs.h:80
#define X3_END
Boundary region at X3 end.
Definition: pluto.h:151
int i
Definition: analysis.c:2
#define X2_BEG
Boundary region at X2 beg.
Definition: pluto.h:148
#define JDIR
Definition: pluto.h:194
#define X2FACE
Definition: pluto.h:202

Here is the call graph for this function:

Here is the caller graph for this function:

void VectorPotentialDiff ( double *  ,
int  ,
int  ,
int  ,
Grid  
)

Here is the caller graph for this function:

void VectorPotentialUpdate ( const Data d,
const void *  vp,
const State_1D state,
const Grid grid 
)

Here is the caller graph for this function:

void Where ( int  i,
Grid grid 
)

Print the location of a particular zone (i,j,k) in the computational domain.

Note
This function must be initialized before using it to store grid information. This is done by calling Where(i, grid) the very first time. Subsequent calls can be then done by simply using Where(i,NULL).

Definition at line 235 of file tools.c.

246 {
247  int ii=0, jj=0, kk=0;
248  double x1, x2, x3;
249  static Grid *grid1, *grid2, *grid3;
250 
251 /* --------------------------------------------------
252  Keep a local copy of grid for subsequent calls
253  -------------------------------------------------- */
254 
255  if (grid != NULL){
256  grid1 = grid + IDIR;
257  grid2 = grid + JDIR;
258  grid3 = grid + KDIR;
259  return;
260  }
261 
262  #ifdef CH_SPACEDIM
263  if (g_intStage < 0) return; /* HOT FIX used by CHOMBO
264  (g_intStage = -1) when writing HDF5 file */
265  #endif
266 
267 /* -- ok, proceed normally -- */
268 
269  if (g_dir == IDIR){
270  D_EXPAND(ii = i;, jj = g_j;, kk = g_k;)
271  }else if (g_dir == JDIR){
272  D_EXPAND(ii = g_i;, jj = i;, kk = g_k;)
273  }else if (g_dir == KDIR){
274  D_EXPAND(ii = g_i;, jj = g_j;, kk = i;)
275  }
276 
277  D_EXPAND(
278  x1 = grid1->x[ii]; ,
279  x2 = grid2->x[jj]; ,
280  x3 = grid3->x[kk];
281  )
282 
283  D_SELECT(
284  print ("zone [x1(%d) = %f]",
285  ii, grid1->x[ii]); ,
286 
287  print ("zone [x1(%d) = %f, x2(%d) = %f]",
288  ii, grid1->x[ii],
289  jj, grid2->x[jj]); ,
290 
291  print ("zone [x1(%d) = %f, x2(%d) = %f, x3(%d) = %f]",
292  ii, grid1->x[ii],
293  jj, grid2->x[jj],
294  kk, grid3->x[kk]);
295  )
296 
297  #ifdef CHOMBO
298  print (", Level = %d\n", grid1->level);
299  return;
300  #endif
301  #ifdef PARALLEL
302  print (", proc %d\n", prank);
303  return;
304  #else
305  print ("\n");
306  return;
307  #endif
308 }
int level
The current refinement level (chombo only).
Definition: structs.h:122
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
int prank
Processor rank.
Definition: globals.h:33
#define KDIR
Definition: pluto.h:195
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
Definition: globals.h:82
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
Definition: structs.h:78
double * x
Definition: structs.h:80
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
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
void print(const char *fmt,...)
Definition: tools.c:367
#define JDIR
Definition: pluto.h:194

Here is the call graph for this function:

Here is the caller graph for this function:

void WriteAsciiFile ( char *  fname,
double *  q,
int  nvar 
)

Write one row a multi-column ascii file

Definition at line 416 of file tools.c.

421 {
422  int n;
423  static char old_file[64] = "\0";
424  FILE *fp;
425 
426 /* --------------------------------------------------------
427  If the old file name matches the new one, then open
428  in append mode. Otherwise, open in write mode.
429  -------------------------------------------------------- */
430 
431  if (strcmp (fname,old_file) == 0){
432  fp = fopen(fname,"a");
433  }else{
434  fp = fopen(fname,"w");
435  sprintf (old_file,"%s",fname);
436  }
437 
438  for (n = 0; n < nvar; n++) fprintf (fp,"%12.6e ",q[n]);
439  fprintf (fp,"\n");
440  fclose(fp);
441 
442 }
static int n
Definition: analysis.c:3
FILE * fp
Definition: analysis.c:7
static Runtime q
void WriteBinaryArray ( void *  V,
size_t  dsize,
int  sz,
FILE *  fl,
int  istag 
)

Write an array to disk in binary format.

Parameters
[in]Vsingle pointer to a 3D array, V[k][j][i] –> V[i + NX1*j + NX1*NX2*k]. Must start with index 0
[in]dsizethe size of the each buffer element (sizeof(double) or sizeof(float)). This parameter is used only in serial mode.
[in]szthe distributed array descriptor. This parameter replaces dsize in parallel mode
[in]fla valid FILE pointer
[in]istaga flag to identify cell-centered (istag = -1) or staggered field data (istag = 0,1 or 2 for staggering in the x1, x2 or x3 directions)
Returns
This function has no return value.
Remarks
The data array is assumed to start always with index 0 for both cell-centered and staggered arrays.

Definition at line 98 of file bin_io.c.

120 {
121  int i, j, k;
122  int ioff, joff, koff;
123  char *Vc;
124 
125  #ifdef PARALLEL
126  MPI_Barrier (MPI_COMM_WORLD);
127  AL_Write_array (V, sz, istag);
128  return;
129  #else
130  Vc = (char *) V;
131  ioff = (istag == 0);
132  joff = (istag == 1);
133  koff = (istag == 2);
134 
135  for (k = KBEG; k <= KEND + koff; k++) {
136  for (j = JBEG; j <= JEND + joff; j++) {
137  i = IBEG + (NX1_TOT + ioff)*(j + (NX2_TOT + joff)*k);
138  fwrite (Vc + i*dsize, dsize, NX1 + ioff, fl);
139  }}
140  #endif
141 }
long int NX1
Number of interior zones in the X1 directions (boundaries excluded) for the local processor...
Definition: globals.h:48
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
int AL_Write_array(void *va, int sz_ptr, int istag)
Definition: al_io.c:115
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
int i
Definition: analysis.c:2
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35

Here is the call graph for this function:

Here is the caller graph for this function:

void WriteData ( const Data d,
Output output,
Grid grid 
)

Write data to disk using any of the available formats.

Parameters
[in]dpointer to PLUTO Data structre
[in]outputthe output structure corresponding to a given format
[in]gridpointer to an array of Grid structures
  • DBL output: Double-precision data files can be written using single or multiple file mode.
    • for single file, serial: we open the file just once before the main variable loop, dump variables and then close.
    • for single file, parallel the distributed array descriptor sz is different for cell-centered or staggered data type and we thus have to open and close the file after each variable has been dumped.
    • when writing multiple files we open, write to and close the file one each loop cycle.
      Note
      In all cases, the pointer to the data array that has to be written must be cast into (void *) and the starting index of the array must be zero.
  • VTK output: in order to enable parallel writing, files must be closed and opened again for scalars, since the distributed array descriptors used by ArrayLib (Float_Vect) and (float) are different. This is done using the AL_Get_offset() and AL_Set_offset() functions.

Definition at line 29 of file write_data.c.

38 {
39  int i, j, k, nv;
40  int single_file;
41  size_t dsize;
42  char filename[512], sline[512];
43  static int last_computed_var = -1;
44  double units[MAX_OUTPUT_VARS];
45  float ***Vpt3;
46  void *Vpt;
47  FILE *fout, *fbin;
48  time_t tbeg, tend;
49  long long offset;
50 
51 /* -----------------------------------------------------------
52  Increment the file number and initialize units
53  ----------------------------------------------------------- */
54 
55  output->nfile++;
56 
57  print1 ("> Writing file #%d (%s) to disk...", output->nfile, output->ext);
58 
59  #ifdef PARALLEL
60  MPI_Barrier (MPI_COMM_WORLD);
61  if (prank == 0) time(&tbeg);
62  #endif
63 
64  for (nv = 0; nv < MAX_OUTPUT_VARS; nv++) units[nv] = 1.0;
65  if (output->cgs) GetCGSUnits(units);
66 
67 /* --------------------------------------------------------
68  Get user var if necessary
69  -------------------------------------------------------- */
70 
71  if (last_computed_var != g_stepNumber && d->Vuser != NULL) {
72  ComputeUserVar (d, grid);
73  last_computed_var = g_stepNumber;
74  }
75 
76 /* --------------------------------------------------------
77  Select the output type
78  -------------------------------------------------------- */
79 
80  if (output->type == DBL_OUTPUT) {
81 
82  /* ------------------------------------------------------------------- */
83  /*! - \b DBL output:
84  Double-precision data files can be written using single or
85  multiple file mode.
86  - for single file, serial: we open the file just once before
87  the main variable loop, dump variables and then close.
88  - for single file, parallel the distributed array descriptor sz is
89  different for cell-centered or staggered data type and we
90  thus have to open and close the file after each variable
91  has been dumped.
92  - when writing multiple files we open, write to and close the
93  file one each loop cycle.
94  \note In all cases, the pointer to the data array that has to be
95  written must be cast into (void *) and the starting index of
96  the array must be zero.
97  */
98  /* ------------------------------------------------------------------- */
99 
100  int sz;
101  single_file = strcmp(output->mode,"single_file") == 0;
102  dsize = sizeof(double);
103 
104  if (single_file){ /* -- single output file -- */
105 
106  sprintf (filename, "%s/data.%04d.%s", output->dir,output->nfile,
107  output->ext);
108  offset = 0;
109  #ifndef PARALLEL
110  fbin = OpenBinaryFile (filename, 0, "w");
111  #endif
112  for (nv = 0; nv < output->nvar; nv++) {
113  if (!output->dump_var[nv]) continue;
114 
115  if (output->stag_var[nv] == -1) { /* -- cell-centered data -- */
116  sz = SZ;
117  Vpt = (void *)output->V[nv][0][0];
118  } else if (output->stag_var[nv] == 0) { /* -- x-staggered data -- */
119  sz = SZ_stagx;
120  Vpt = (void *)(output->V[nv][0][0]-1);
121  } else if (output->stag_var[nv] == 1) { /* -- y-staggered data -- */
122  sz = SZ_stagy;
123  Vpt = (void *)output->V[nv][0][-1];
124  } else if (output->stag_var[nv] == 2) { /* -- z-staggered data -- */
125  sz = SZ_stagz;
126  Vpt = (void *)output->V[nv][-1][0];
127  }
128  #ifdef PARALLEL
129  fbin = OpenBinaryFile (filename, sz, "w");
130  AL_Set_offset(sz, offset);
131  #endif
132  WriteBinaryArray (Vpt, dsize, sz, fbin, output->stag_var[nv]);
133  #ifdef PARALLEL
134  offset = AL_Get_offset(sz);
135  CloseBinaryFile(fbin, sz);
136  #endif
137  }
138  #ifndef PARALLEL
139  CloseBinaryFile(fbin, sz);
140  #endif
141 
142  }else{ /* -- multiple files -- */
143 
144  for (nv = 0; nv < output->nvar; nv++) {
145  if (!output->dump_var[nv]) continue;
146  sprintf (filename, "%s/%s.%04d.%s", output->dir, output->var_name[nv],
147  output->nfile, output->ext);
148 
149  if (output->stag_var[nv] == -1) { /* -- cell-centered data -- */
150  sz = SZ;
151  Vpt = (void *)output->V[nv][0][0];
152  } else if (output->stag_var[nv] == 0) { /* -- x-staggered data -- */
153  sz = SZ_stagx;
154  Vpt = (void *)(output->V[nv][0][0]-1);
155  } else if (output->stag_var[nv] == 1) { /* -- y-staggered data -- */
156  sz = SZ_stagy;
157  Vpt = (void *)output->V[nv][0][-1];
158  } else if (output->stag_var[nv] == 2) { /* -- z-staggered data -- */
159  sz = SZ_stagz;
160  Vpt = (void *)output->V[nv][-1][0];
161  }
162  fbin = OpenBinaryFile (filename, sz, "w");
163  WriteBinaryArray (Vpt, dsize, sz, fbin, output->stag_var[nv]);
164  CloseBinaryFile (fbin, sz);
165  }
166  }
167 
168  } else if (output->type == FLT_OUTPUT) {
169 
170  /* ----------------------------------------------------------
171  FLT output for cell-centered data
172  ---------------------------------------------------------- */
173 
174  single_file = strcmp(output->mode,"single_file") == 0;
175 
176  if (single_file){ /* -- single output file -- */
177  sprintf (filename, "%s/data.%04d.%s", output->dir, output->nfile,
178  output->ext);
179  fbin = OpenBinaryFile (filename, SZ_float, "w");
180  for (nv = 0; nv < output->nvar; nv++) {
181  if (!output->dump_var[nv]) continue;
182 /* Vpt = (void *)(Convert_dbl2flt(output->V[nv],0))[0][0]; */
183  Vpt3 = Convert_dbl2flt(output->V[nv], units[nv],0);
184  Vpt = (void *)Vpt3[0][0];
185  WriteBinaryArray (Vpt, sizeof(float), SZ_float, fbin,
186  output->stag_var[nv]);
187  }
188  CloseBinaryFile(fbin, SZ_float);
189 /*
190 BOV_Header(output, filename);
191 */
192  }else{ /* -- multiple files -- */
193 
194  for (nv = 0; nv < output->nvar; nv++) {
195  if (!output->dump_var[nv]) continue;
196  sprintf (filename, "%s/%s.%04d.%s", output->dir, output->var_name[nv],
197  output->nfile, output->ext);
198 
199  fbin = OpenBinaryFile (filename, SZ_float, "w");
200 /* Vpt = (void *)(Convert_dbl2flt(output->V[nv],0))[0][0]; */
201  Vpt3 = Convert_dbl2flt(output->V[nv], units[nv],0);
202  Vpt = (void *)Vpt3[0][0];
203  WriteBinaryArray (Vpt, sizeof(float), SZ_float, fbin,
204  output->stag_var[nv]);
205  CloseBinaryFile (fbin, SZ_float);
206  }
207  }
208 
209  }else if (output->type == DBL_H5_OUTPUT || output->type == FLT_H5_OUTPUT){
210 
211  /* ------------------------------------------------------
212  HDF5 (static grid) output (single/double precision)
213  ------------------------------------------------------ */
214 
215  #ifdef USE_HDF5
216  single_file = YES;
217  WriteHDF5 (output, grid);
218  #else
219  print1 ("! WriteData: HDF5 library not available\n");
220  return;
221  #endif
222 
223  }else if (output->type == VTK_OUTPUT) {
224 
225  /* ------------------------------------------------------------------- */
226  /*! - \b VTK output:
227  in order to enable parallel writing, files must be closed and
228  opened again for scalars, since the distributed array descriptors
229  used by ArrayLib (Float_Vect) and (float) are different. This is
230  done using the AL_Get_offset() and AL_Set_offset() functions. */
231  /* ------------------------------------------------------------------- */
232 
233  single_file = strcmp(output->mode,"single_file") == 0;
234  sprintf (filename, "%s/data.%04d.%s", output->dir, output->nfile,
235  output->ext);
236 
237  if (single_file){ /* -- single output file -- */
238 
239  fbin = OpenBinaryFile(filename, SZ_Float_Vect, "w");
240  WriteVTK_Header(fbin, grid);
241  for (nv = 0; nv < output->nvar; nv++) { /* -- write vectors -- */
242  if (output->dump_var[nv] != VTK_VECTOR) continue;
243  WriteVTK_Vector (fbin, output->V + nv, units[nv],
244  output->var_name[nv], grid);
245  }
246 
247  #ifdef PARALLEL
248  offset = AL_Get_offset(SZ_Float_Vect);
250  fbin = OpenBinaryFile(filename, SZ_float, "w");
251  AL_Set_offset(SZ_float, offset);
252  #endif
253 
254  for (nv = 0; nv < output->nvar; nv++) { /* -- write scalars -- */
255  if (output->dump_var[nv] != YES) continue;
256  WriteVTK_Scalar (fbin, output->V[nv], units[nv],
257  output->var_name[nv], grid);
258  }
259  CloseBinaryFile(fbin, SZ_float);
260 
261  }else{ /* -- multiple output files -- */
262 
263  for (nv = 0; nv < output->nvar; nv++) { /* -- write vectors -- */
264  if (output->dump_var[nv] != VTK_VECTOR) continue;
265  if (strcmp(output->var_name[nv],"vx1") == 0) {
266  sprintf (filename, "%s/vfield.%04d.%s", output->dir, output->nfile,
267  output->ext);
268  }else if (strcmp(output->var_name[nv],"bx1") == 0) {
269  sprintf (filename, "%s/bfield.%04d.%s", output->dir, output->nfile,
270  output->ext);
271  }else{
272  print1 ("! WriteData: unknown vector type in VTK output\n");
273  QUIT_PLUTO(1);
274  }
275 
276  fbin = OpenBinaryFile(filename, SZ_Float_Vect, "w");
277  WriteVTK_Header(fbin, grid);
278  WriteVTK_Vector(fbin, output->V + nv, units[nv],
279  output->var_name[nv], grid);
281  }
282 
283  for (nv = 0; nv < output->nvar; nv++) { /* -- write scalars -- */
284  if (output->dump_var[nv] != YES) continue;
285  sprintf (filename, "%s/%s.%04d.%s", output->dir, output->var_name[nv],
286  output->nfile, output->ext);
287  fbin = OpenBinaryFile(filename, SZ_Float_Vect, "w");
288  WriteVTK_Header(fbin, grid);
289  #ifdef PARALLEL
290  offset = AL_Get_offset(SZ_Float_Vect);
292  fbin = OpenBinaryFile(filename, SZ_float, "w");
293  AL_Set_offset(SZ_float, offset);
294  #endif
295  WriteVTK_Scalar(fbin, output->V[nv], units[nv],
296  output->var_name[nv], grid);
297  CloseBinaryFile (fbin, SZ_float);
298  }
299  }
300 
301  }else if (output->type == TAB_OUTPUT) {
302 
303  /* ------------------------------------------------------
304  Tabulated (ASCII) output
305  ------------------------------------------------------ */
306 
307  single_file = YES;
308  sprintf (filename,"%s/data.%04d.%s", output->dir, output->nfile,
309  output->ext);
310  WriteTabArray (output, filename, grid);
311 
312  }else if (output->type == PPM_OUTPUT) {
313 
314  /* ------------------------------------------------------
315  PPM output
316  ------------------------------------------------------ */
317 
318  single_file = NO;
319  for (nv = 0; nv < output->nvar; nv++) {
320  if (!output->dump_var[nv]) continue;
321  sprintf (filename, "%s/%s.%04d.%s", output->dir, output->var_name[nv],
322  output->nfile, output->ext);
323  WritePPM (output->V[nv], output->var_name[nv], filename, grid);
324  }
325 
326  }else if (output->type == PNG_OUTPUT) {
327 
328  /* ------------------------------------------------------
329  PNG output
330  ------------------------------------------------------ */
331 
332  #ifdef USE_PNG
333  single_file = NO;
334  for (nv = 0; nv < output->nvar; nv++) {
335  if (!output->dump_var[nv]) continue;
336  sprintf (filename, "%s/%s.%04d.%s", output->dir, output->var_name[nv],
337  output->nfile, output->ext);
338  WritePNG (output->V[nv], output->var_name[nv], filename, grid);
339  }
340  #else
341  print1 ("! PNG library not available\n");
342  return;
343  #endif
344 
345  }
346 
347 /* -------------------------------------------------------------
348  Update corresponding ".out" file
349  ------------------------------------------------------------- */
350 
351  sprintf (filename,"%s/%s.out",output->dir, output->ext);
352 
353  if (prank == 0) {
354  if (output->nfile == 0) {
355  fout = fopen (filename, "w");
356  }else {
357  fout = fopen (filename, "r+");
358  for (nv = 0; nv < output->nfile; nv++) fgets (sline, 512, fout);
359  fseek (fout, ftell(fout), SEEK_SET);
360  }
361 
362  /* -- write a multi-column file -- */
363 
364  fprintf (fout, "%d %12.6e %12.6e %ld ",
365  output->nfile, g_time, g_dt, g_stepNumber);
366 
367  if (single_file) fprintf (fout,"single_file ");
368  else fprintf (fout,"multiple_files ");
369 
370  if (IsLittleEndian()) fprintf (fout, "little ");
371  else fprintf (fout, "big ");
372 
373  for (nv = 0; nv < output->nvar; nv++) {
374  if (output->dump_var[nv]) fprintf (fout, "%s ", output->var_name[nv]);
375  }
376 
377  fprintf (fout,"\n");
378  fclose (fout);
379  }
380 
381  #ifdef PARALLEL
382  MPI_Barrier (MPI_COMM_WORLD);
383  if (prank == 0){
384  time(&tend);
385  print1 (" [%5.2f sec]",difftime(tend,tbeg));
386  }
387  #endif
388  print1 ("\n");
389 
390 }
void WritePNG(double ***, char *, char *, Grid *)
#define FLT_H5_OUTPUT
Definition: pluto.h:83
#define PPM_OUTPUT
Definition: pluto.h:85
double *** V[64]
pointer to arrays being written - same for all
Definition: structs.h:247
long long AL_Get_offset(int sz_ptr)
Definition: al_io.c:327
#define VTK_VECTOR
Definition: pluto.h:88
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
FILE * OpenBinaryFile(char *filename, int sz, char *mode)
Definition: bin_io.c:31
int nfile
current number being saved - one per output
Definition: structs.h:237
int SZ_float
Definition: globals.h:27
#define YES
Definition: pluto.h:25
void GetCGSUnits(double *u)
Definition: write_data.c:557
double g_dt
The current integration time step.
Definition: globals.h:118
int AL_Set_offset(int sz_ptr, long long offset)
Definition: al_io.c:342
void WriteVTK_Scalar(FILE *, double ***, double, char *, Grid *)
Definition: write_vtk.c:341
void WriteHDF5(Output *output, Grid *grid)
Definition: hdf5_io.c:45
char dir[256]
output directory name
Definition: structs.h:244
void WriteVTK_Vector(FILE *, Data_Arr, double, char *, Grid *)
Definition: write_vtk.c:259
int prank
Processor rank.
Definition: globals.h:33
void WriteVTK_Header(FILE *, Grid *)
Definition: write_vtk.c:91
float *** Convert_dbl2flt(double ***Vdbl, double unit, int swap_endian)
Definition: bin_io.c:216
int cgs
when set to 1 saves data in c.g.s units
Definition: structs.h:236
int SZ_stagx
Definition: globals.h:24
int SZ_stagy
Definition: globals.h:25
char ext[8]
output extension
Definition: structs.h:243
int SZ_Float_Vect
Definition: globals.h:29
void ComputeUserVar(const Data *, Grid *)
Definition: userdef_output.c:4
struct szz SZ
long int g_stepNumber
Gives the current integration step number.
Definition: globals.h:97
#define VTK_OUTPUT
Definition: pluto.h:81
#define DBL_H5_OUTPUT
Definition: pluto.h:82
void WritePPM(double ***, char *, char *, Grid *)
Definition: write_img.c:10
int j
Definition: analysis.c:2
int IsLittleEndian(void)
Definition: tools.c:40
int SZ_stagz
Definition: globals.h:26
int k
Definition: analysis.c:2
int nvar
tot.
Definition: structs.h:234
int * dump_var
select vars being written - one per output
Definition: structs.h:240
#define TAB_OUTPUT
Definition: pluto.h:84
#define FLT_OUTPUT
Definition: pluto.h:80
#define MAX_OUTPUT_VARS
Definition: pluto.h:96
int i
Definition: analysis.c:2
double g_time
The current integration time.
Definition: globals.h:117
#define DBL_OUTPUT
Definition: pluto.h:79
char mode[32]
single or multiple files - one per output
Definition: structs.h:241
int type
output format (DBL, FLT, ...) - one per output
Definition: structs.h:233
int * stag_var
centered or staggered variable - same for all
Definition: structs.h:239
void WriteTabArray(Output *, char *, Grid *)
Definition: write_tab.c:31
double **** Vuser
Array storing user-defined supplementary variables written to disk.
Definition: structs.h:49
int CloseBinaryFile(FILE *fbin, int sz)
Definition: bin_io.c:78
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
void WriteBinaryArray(void *V, size_t dsize, int sz, FILE *fl, int istag)
Definition: bin_io.c:98
#define PNG_OUTPUT
Definition: pluto.h:86
char ** var_name
variable names - same for all
Definition: structs.h:242
#define NO
Definition: pluto.h:26

Here is the call graph for this function:

Here is the caller graph for this function:

void WriteHDF5 ( Output output,
Grid grid 
)

Write data to disk using hdf5 format in single or double precision.

Parameters
[in]outputthe output structure associated with HDF5 format
[in]grida pointer to an array of Grid structures
Returns
This function has no return value.
Note
Writing of staggered magnetic fields: Here we follow the same convention used by ArrayLib, where internal points that lie on the grid boundary between processors are owned by the left processor. For this reason, only the leftmost processor writes one additional point in the direction of staggering while the other processors write the same amount of zones as for cell-centered data. Also, keep in mind that the data array Vs starts from -1 (instead of 0) in the staggered direction.
Writing of staggered magnetic fields: Here we follow the same convention used by ArrayLib, where internal points that lie on the grid boundary between processors are owned by the left processor. For this reason, only the leftmost processor writes one additional point in the direction of staggering while the other processors write the same amount of zones as for cell-centered data. Also, keep in mind that the data array Vs starts from -1 (instead of 0) in the staggered direction.

Definition at line 45 of file hdf5_io.c.

55 {
56  hid_t dataspace, memspace, dataset;
57  hid_t strspace, stratt, string_type;
58  hid_t tspace, tattr;
59  hid_t file_identifier, group, timestep;
60  hid_t file_access = 0;
61  #if MPI_POSIX == NO
62  hid_t plist_id_mpiio = 0; /* for collective MPI I/O */
63  #endif
64  hid_t err;
65 
66  hsize_t dimstr;
67  hsize_t dimens[DIMENSIONS];
68  hsize_t start[DIMENSIONS];
69  hsize_t stride[DIMENSIONS];
70  hsize_t count[DIMENSIONS];
71 
72  time_t tbeg, tend;
73  static float ****node_coords, ****cell_coords;
74  char filename[512], filenamexmf[512], tstepname[32];
75  char *coords = "/cell_coords/X /cell_coords/Y /cell_coords/Z ";
76  char *cname[] = {"X", "Y", "Z"};
77  char xmfext[8];
78  int rank, nd, nv, ns, nc, ngh, ii, jj, kk;
79  int n1p, n2p, n3p, nprec;
80  Grid *wgrid[3];
81  FILE *fxmf;
82 
83 /* ----------------------------------------------------------------
84  compute coordinates just once
85  ---------------------------------------------------------------- */
86 
87  if (node_coords == NULL) {
88  double x1, x2, x3;
89 
90  n1p = NX1 + (grid[IDIR].rbound != 0);
91  n2p = NX2 + (grid[JDIR].rbound != 0);
92  n3p = NX3 + (grid[KDIR].rbound != 0);
93 
94  node_coords = ARRAY_4D(3, n3p, n2p, n1p, float);
95  cell_coords = ARRAY_4D(3, NX3, NX2, NX1, float);
96 
97  for (kk = 0; kk < n3p; kk++) { x3 = grid[KDIR].xl[KBEG+kk];
98  for (jj = 0; jj < n2p; jj++) { x2 = grid[JDIR].xl[JBEG+jj];
99  for (ii = 0; ii < n1p; ii++) { x1 = grid[IDIR].xl[IBEG+ii];
100 
101  node_coords[JDIR][kk][jj][ii] = 0.0;
102  node_coords[KDIR][kk][jj][ii] = 0.0;
103 
104  #if GEOMETRY == CARTESIAN || GEOMETRY == CYLINDRICAL
105  D_EXPAND(node_coords[IDIR][kk][jj][ii] = (float)x1; ,
106  node_coords[JDIR][kk][jj][ii] = (float)x2; ,
107  node_coords[KDIR][kk][jj][ii] = (float)x3;)
108  #elif GEOMETRY == POLAR
109  D_EXPAND(node_coords[IDIR][kk][jj][ii] = (float)(x1*cos(x2)); ,
110  node_coords[JDIR][kk][jj][ii] = (float)(x1*sin(x2)); ,
111  node_coords[KDIR][kk][jj][ii] = (float)(x3);)
112  #elif GEOMETRY == SPHERICAL
113  #if DIMENSIONS <= 2
114  D_EXPAND(node_coords[IDIR][kk][jj][ii] = (float)(x1*sin(x2)); ,
115  node_coords[JDIR][kk][jj][ii] = (float)(x1*cos(x2)); ,
116  node_coords[KDIR][kk][jj][ii] = 0.0;)
117  #else
118  D_EXPAND(node_coords[IDIR][kk][jj][ii] = (float)(x1*sin(x2)*cos(x3)); ,
119  node_coords[JDIR][kk][jj][ii] = (float)(x1*sin(x2)*sin(x3)); ,
120  node_coords[KDIR][kk][jj][ii] = (float)(x1*cos(x2));)
121  #endif
122  #else
123  print1 ("! HDF5_IO: Unknown geometry\n");
124  QUIT_PLUTO(1);
125  #endif
126  }}}
127 
128  for (kk = 0; kk < NX3; kk++) { x3 = grid[KDIR].x[KBEG+kk];
129  for (jj = 0; jj < NX2; jj++) { x2 = grid[JDIR].x[JBEG+jj];
130  for (ii = 0; ii < NX1; ii++) { x1 = grid[IDIR].x[IBEG+ii];
131 
132  cell_coords[JDIR][kk][jj][ii] = 0.0;
133  cell_coords[KDIR][kk][jj][ii] = 0.0;
134 
135  #if GEOMETRY == CARTESIAN || GEOMETRY == CYLINDRICAL
136  D_EXPAND(cell_coords[IDIR][kk][jj][ii] = (float)x1; ,
137  cell_coords[JDIR][kk][jj][ii] = (float)x2; ,
138  cell_coords[KDIR][kk][jj][ii] = (float)x3;)
139  #elif GEOMETRY == POLAR
140  D_EXPAND(cell_coords[IDIR][kk][jj][ii] = (float)(x1*cos(x2)); ,
141  cell_coords[JDIR][kk][jj][ii] = (float)(x1*sin(x2)); ,
142  cell_coords[KDIR][kk][jj][ii] = (float)(x3);)
143  #elif GEOMETRY == SPHERICAL
144  #if DIMENSIONS <= 2
145  D_EXPAND(cell_coords[IDIR][kk][jj][ii] = (float)(x1*sin(x2)); ,
146  cell_coords[JDIR][kk][jj][ii] = (float)(x1*cos(x2)); ,
147  cell_coords[KDIR][kk][jj][ii] = 0.0;)
148  #else
149  D_EXPAND(cell_coords[IDIR][kk][jj][ii] = (float)(x1*sin(x2)*cos(x3)); ,
150  cell_coords[JDIR][kk][jj][ii] = (float)(x1*sin(x2)*sin(x3)); ,
151  cell_coords[KDIR][kk][jj][ii] = (float)(x1*cos(x2));)
152  #endif
153  #else
154  print1 ("! HDF5_IO: Unknown geometry\n");
155  QUIT_PLUTO(1);
156  #endif
157  }}}
158 
159  }
160 
161 /* --------------------------------------------------------------
162  Since data is written in reverse order (Z-Y-X) it is
163  convenient to define pointers to grid in reverse order
164  -------------------------------------------------------------- */
165 
166  for (nd = 0; nd < DIMENSIONS; nd++) wgrid[nd] = grid + DIMENSIONS - nd - 1;
167 
168  #ifdef PARALLEL
169  MPI_Barrier (MPI_COMM_WORLD);
170  if (prank == 0)time(&tbeg);
171  #endif
172 
173  sprintf (filename, "%s/data.%04d.%s", output->dir,output->nfile, output->ext);
174 
175  rank = DIMENSIONS;
176  dimstr = 3;
177 
178  #ifdef PARALLEL
179  file_access = H5Pcreate(H5P_FILE_ACCESS);
180  #if MPI_POSIX == YES
181  H5Pset_fapl_mpiposix(file_access, MPI_COMM_WORLD, 1);
182  #else
183  H5Pset_fapl_mpio(file_access, MPI_COMM_WORLD, MPI_INFO_NULL);
184  #endif
185  file_identifier = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, file_access);
186  H5Pclose(file_access);
187  #else
188  file_identifier = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
189  #endif
190 
191  sprintf (tstepname, "Timestep_%d", output->nfile);
192  timestep = H5Gcreate(file_identifier, tstepname, 0);
193 
194  tspace = H5Screate(H5S_SCALAR);
195  tattr = H5Acreate(timestep, "Time", H5T_NATIVE_DOUBLE, tspace, H5P_DEFAULT);
196  err = H5Awrite(tattr, H5T_NATIVE_DOUBLE, &g_time);
197  H5Aclose(tattr);
198  H5Sclose(tspace);
199 
200  group = H5Gcreate(timestep, "vars", 0); /* Create group "vars" (cell-centered vars) */
201 
202 /* Define "coords" attribute of group "vars" */
203 
204  strspace = H5Screate_simple(1, &dimstr, NULL);
205  string_type = H5Tcopy(H5T_C_S1);
206  H5Tset_size(string_type, strlen("/cell_coords/X "));
207  H5Tset_strpad(string_type,H5T_STR_SPACEPAD);
208  stratt = H5Acreate(group,"coords",string_type,strspace, H5P_DEFAULT);
209  err = H5Awrite(stratt, string_type, coords);
210  H5Aclose(stratt);
211  H5Sclose(strspace);
212 
213  for (nd = 0; nd < DIMENSIONS; nd++) dimens[nd] = wgrid[nd]->np_int_glob;
214 
215  dataspace = H5Screate_simple(rank, dimens, NULL);
216 
217  #ifdef PARALLEL
218  for (nd = 0; nd < DIMENSIONS; nd++) {
219  start[nd] = wgrid[nd]->beg - wgrid[nd]->nghost;
220  stride[nd] = 1;
221  count[nd] = wgrid[nd]->np_int;
222  }
223 
224  err = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, start, stride, count, NULL);
225  #endif
226 
227  for (nd = 0; nd < DIMENSIONS; nd++) dimens[nd] = wgrid[nd]->np_tot;
228 
229  memspace = H5Screate_simple(rank,dimens,NULL);
230 
231  for (nd = 0; nd < DIMENSIONS; nd++){
232  start[nd] = wgrid[nd]->nghost;
233  stride[nd] = 1;
234  count[nd] = wgrid[nd]->np_int;
235  }
236  err = H5Sselect_hyperslab(memspace,H5S_SELECT_SET, start, stride, count, NULL);
237 
238 /* ------------------------------------
239  write cell-centered data
240  ------------------------------------ */
241 
242  #if MPI_POSIX == NO
243  plist_id_mpiio = H5Pcreate(H5P_DATASET_XFER);
244  H5Pset_dxpl_mpio(plist_id_mpiio,H5FD_MPIO_COLLECTIVE);
245  #endif
246 
247  for (nv = 0; nv < output->nvar; nv++) {
248 
249  /* -- skip variable if excluded from output or if it is staggered -- */
250 
251  if (!output->dump_var[nv] || output->stag_var[nv] != -1) continue;
252 
253  if (output->type == DBL_H5_OUTPUT){
254  dataset = H5Dcreate(group, output->var_name[nv], H5T_NATIVE_DOUBLE,
255  dataspace, H5P_DEFAULT);
256  #if MPI_POSIX == NO
257  err = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, memspace, dataspace,
258  plist_id_mpiio, output->V[nv][0][0]);
259  #else
260  err = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, memspace, dataspace,
261  H5P_DEFAULT, output->V[nv][0][0]);
262  #endif
263  }else if (output->type == FLT_H5_OUTPUT){
264  void *Vpt;
265  Vpt = (void *)(Convert_dbl2flt(output->V[nv],1.0, 0))[0][0];
266 
267  dataset = H5Dcreate(group, output->var_name[nv], H5T_NATIVE_FLOAT,
268  dataspace, H5P_DEFAULT);
269 
270  #if MPI_POSIX == NO
271  err = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace,
272  dataspace, plist_id_mpiio, Vpt);
273  #else
274  err = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace,
275  dataspace, H5P_DEFAULT, Vpt);
276  #endif
277  }
278  H5Dclose(dataset);
279  }
280 
281  #if MPI_POSIX == NO
282  H5Pclose(plist_id_mpiio);
283  #endif
284  H5Sclose(memspace);
285  H5Sclose(dataspace);
286  H5Gclose(group); /* Close group "vars" */
287 
288 /* --------------------------------------------------------------------- */
289 /*! \note Writing of staggered magnetic fields:
290  Here we follow the same convention used by ArrayLib, where internal
291  points that lie on the grid boundary between processors are owned
292  by the \b left processor.
293  For this reason, only the leftmost processor writes one additional
294  point in the direction of staggering while the other processors
295  write the same amount of zones as for cell-centered data.
296  Also, keep in mind that the data array Vs starts from -1
297  (instead of 0) in the staggered direction. */
298 /* --------------------------------------------------------------------- */
299 
300  #ifdef STAGGERED_MHD
301  if (output->type == DBL_H5_OUTPUT){
302  group = H5Gcreate(timestep, "stag_vars", 0); /* Create group "stag_vars" (staggered vars) */
303 
304  #if MPI_POSIX == NO
305  plist_id_mpiio = H5Pcreate(H5P_DATASET_XFER);
306  H5Pset_dxpl_mpio(plist_id_mpiio,H5FD_MPIO_COLLECTIVE);
307  #endif
308 
309  for (ns = 0; ns < DIMENSIONS; ns++) {
310 
311  /* -- skip variable if excluded from output or if it is cell-centered -- */
312 
313  if (!output->dump_var[NVAR+ns] || output->stag_var[NVAR+ns] == -1) continue;
314  for (nd = 0; nd < DIMENSIONS; nd++) {
315  dimens[nd] = wgrid[nd]->np_int_glob + (ns == (DIMENSIONS-1-nd));
316  }
317  dataspace = H5Screate_simple(rank, dimens, NULL);
318 
319  #ifdef PARALLEL
320  for (nd = 0; nd < DIMENSIONS; nd++) {
321  start[nd] = wgrid[nd]->beg - wgrid[nd]->nghost;
322  stride[nd] = 1;
323  count[nd] = wgrid[nd]->np_int;
324  if (ns == DIMENSIONS-1-nd){
325  if (grid[ns].lbound != 0) count[nd] += 1;
326  else start[nd] += 1;
327  }
328  }
329  err = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET,
330  start, stride, count, NULL);
331  #endif
332 
333  for (nd = 0; nd < DIMENSIONS; nd++){
334  dimens[nd] = wgrid[nd]->np_tot + (ns==(DIMENSIONS-1-nd));
335  }
336  memspace = H5Screate_simple(rank,dimens,NULL);
337 
338  for (nd = 0; nd < DIMENSIONS; nd++){
339  start[nd] = wgrid[nd]->nghost;
340  stride[nd] = 1;
341  count[nd] = wgrid[nd]->np_int;
342  if (ns == (DIMENSIONS-1-nd) && grid[ns].lbound != 0) {
343  start[nd] -= 1;
344  count[nd] += 1;
345  }
346  }
347 
348  err = H5Sselect_hyperslab(memspace,H5S_SELECT_SET, start, stride, count, NULL);
349 
350  if (output->type == DBL_H5_OUTPUT){
351  dataset = H5Dcreate(group, output->var_name[NVAR+ns], H5T_NATIVE_DOUBLE,
352  dataspace, H5P_DEFAULT);
353  #if MPI_POSIX == NO
354  err = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, memspace, dataspace,
355  plist_id_mpiio, output->V[NVAR+ns][0][0]);
356  #else
357  err = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, memspace, dataspace,
358  H5P_DEFAULT, output->V[NVAR+ns][0][0]);
359  #endif
360  }else if (output->type == FLT_H5_OUTPUT){
361  void *Vpt;
362  Vpt = (void *)(Convert_dbl2flt(output->V[NVAR+ns],1.0, 0))[0][0];
363  dataset = H5Dcreate(group, output->var_name[NVAR+ns], H5T_NATIVE_FLOAT,
364  dataspace, H5P_DEFAULT);
365 
366  #if MPI_POSIX == NO
367  err = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace,
368  dataspace, plist_id_mpiio, Vpt);
369  #else
370  err = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace,
371  dataspace, H5P_DEFAULT, Vpt);
372  #endif
373  }
374 
375  H5Dclose(dataset);
376  H5Sclose(memspace);
377  H5Sclose(dataspace);
378  }
379 
380  #if MPI_POSIX == NO
381  H5Pclose(plist_id_mpiio);
382  #endif
383  H5Gclose(group);} /* Close group "stag_vars" */
384  #endif /* STAGGERED_MHD */
385 
386  H5Gclose(timestep);
387 
388  group = H5Gcreate(file_identifier, "cell_coords", 0); /* Create group "cell_coords" (centered mesh) */
389 
390  for (nd = 0; nd < DIMENSIONS; nd++) dimens[nd] = wgrid[nd]->np_int_glob;
391  dataspace = H5Screate_simple(rank, dimens, NULL);
392 
393  #ifdef PARALLEL
394  for (nd = 0; nd < DIMENSIONS; nd++) {
395  start[nd] = wgrid[nd]->beg - wgrid[nd]->nghost;
396  stride[nd] = 1;
397  count[nd] = wgrid[nd]->np_int;
398  }
399  err = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET,
400  start, stride, count, NULL);
401  #endif
402 
403  for (nd = 0; nd < DIMENSIONS; nd++) dimens[nd] = wgrid[nd]->np_int;
404  memspace = H5Screate_simple(rank,dimens,NULL);
405 
406 /* ------------------------------------
407  write cell centered mesh
408  ------------------------------------ */
409 
410  #if MPI_POSIX == NO
411  plist_id_mpiio = H5Pcreate(H5P_DATASET_XFER);
412  H5Pset_dxpl_mpio(plist_id_mpiio,H5FD_MPIO_COLLECTIVE);
413  #endif
414 
415  for (nc = 0; nc < 3; nc++) {
416  dataset = H5Dcreate(group, cname[nc], H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT);
417 
418  #if MPI_POSIX == NO
419  err = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace,
420  dataspace, plist_id_mpiio, cell_coords[nc][0][0]);
421  #else
422  err = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace,
423  dataspace, H5P_DEFAULT, cell_coords[nc][0][0]);
424  #endif
425 
426  H5Dclose(dataset);
427  }
428 
429  #if MPI_POSIX == NO
430  H5Pclose(plist_id_mpiio);
431  #endif
432  H5Sclose(memspace);
433  H5Sclose(dataspace);
434  H5Gclose(group); /* Close group "cell_coords" */
435 
436  group = H5Gcreate(file_identifier, "node_coords", 0); /* Create group "node_coords" (node mesh) */
437 
438  for (nd = 0; nd < DIMENSIONS; nd++) dimens[nd] = wgrid[nd]->np_int_glob+1;
439 
440  dataspace = H5Screate_simple(rank, dimens, NULL);
441 
442  #ifdef PARALLEL
443  for (nd = 0; nd < DIMENSIONS; nd++) {
444  start[nd] = wgrid[nd]->beg - wgrid[nd]->nghost;
445  stride[nd] = 1;
446  count[nd] = wgrid[nd]->np_int;
447  if (wgrid[nd]->rbound != 0) count[nd] += 1;
448  }
449 
450  err = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET,
451  start, stride, count, NULL);
452  #endif
453 
454  for (nd = 0; nd < DIMENSIONS; nd++) {
455  dimens[nd] = wgrid[nd]->np_int;
456  if (wgrid[nd]->rbound != 0) dimens[nd] += 1;
457  }
458  memspace = H5Screate_simple(rank,dimens,NULL);
459 
460 /* ------------------------------------
461  write node centered mesh
462  ------------------------------------ */
463 
464  #if MPI_POSIX == NO
465  plist_id_mpiio = H5Pcreate(H5P_DATASET_XFER);
466  H5Pset_dxpl_mpio(plist_id_mpiio,H5FD_MPIO_COLLECTIVE);
467  #endif
468 
469  for (nc = 0; nc < 3; nc++) {
470  dataset = H5Dcreate(group, cname[nc], H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT);
471 
472  #if MPI_POSIX == NO
473  err = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace,
474  dataspace, plist_id_mpiio, node_coords[nc][0][0]);
475  #else
476  err = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace,
477  dataspace, H5P_DEFAULT, node_coords[nc][0][0]);
478  #endif
479 
480  H5Dclose(dataset);
481  }
482 
483  #if MPI_POSIX == NO
484  H5Pclose(plist_id_mpiio);
485  #endif
486  H5Sclose(memspace);
487  H5Sclose(dataspace);
488  H5Gclose(group); /* Close group "node_coords" */
489 
490  H5Fclose(file_identifier);
491 
492 /* Create XDMF file to read HDF5 output (Visit or Paraview) */
493 
494  if (prank == 0) {
495 
496  if (output->type == DBL_H5_OUTPUT){
497  sprintf(xmfext,"dbl.xmf");
498  nprec = 8;
499  } else if (output->type == FLT_H5_OUTPUT){
500  sprintf(xmfext,"flt.xmf");
501  nprec = 4;
502  }
503 
504  sprintf (filenamexmf, "%s/data.%04d.%s", output->dir, output->nfile, xmfext);
505 
506  fxmf = fopen(filenamexmf, "w");
507  fprintf(fxmf, "<?xml version=\"1.0\" ?>\n");
508  fprintf(fxmf, "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" []>\n");
509  fprintf(fxmf, "<Xdmf Version=\"2.0\">\n");
510  fprintf(fxmf, " <Domain>\n");
511  fprintf(fxmf, " <Grid Name=\"node_mesh\" GridType=\"Uniform\">\n");
512  fprintf(fxmf, " <Time Value=\"%12.6e\"/>\n",g_time);
513  #if DIMENSIONS == 2
514  fprintf(fxmf," <Topology TopologyType=\"2DSMesh\" NumberOfElements=\"%d %d\"/>\n",
515  wgrid[0]->np_int_glob+1, wgrid[1]->np_int_glob+1);
516  fprintf(fxmf, " <Geometry GeometryType=\"X_Y\">\n");
517  for (nd = 0; nd < DIMENSIONS; nd++) {
518  fprintf(fxmf," <DataItem Dimensions=\"%d %d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n",
519  wgrid[0]->np_int_glob+1, wgrid[1]->np_int_glob+1 );
520  fprintf(fxmf, " %s:/node_coords/%s\n",filename,cname[nd]);
521  fprintf(fxmf, " </DataItem>\n");
522  }
523  #elif DIMENSIONS == 3
524  fprintf(fxmf, " <Topology TopologyType=\"3DSMesh\" NumberOfElements=\"%d %d %d\"/>\n",
525  wgrid[0]->np_int_glob+1, wgrid[1]->np_int_glob+1, wgrid[2]->np_int_glob+1);
526  fprintf(fxmf, " <Geometry GeometryType=\"X_Y_Z\">\n");
527  for (nd = 0; nd < DIMENSIONS; nd++) {
528  fprintf(fxmf, " <DataItem Dimensions=\"%d %d %d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n",
529  wgrid[0]->np_int_glob+1, wgrid[1]->np_int_glob+1, wgrid[2]->np_int_glob+1 );
530  fprintf(fxmf, " %s:/node_coords/%s\n",filename,cname[nd]);
531  fprintf(fxmf, " </DataItem>\n");
532  }
533  #endif
534  fprintf(fxmf, " </Geometry>\n");
535  for (nv = 0; nv < output->nvar; nv++) { /* Write cell-centered variables */
536  if (!output->dump_var[nv] || output->stag_var[nv] != -1) continue; /* -- skip variable if excluded from output or if it is staggered */
537  fprintf(fxmf, " <Attribute Name=\"%s\" AttributeType=\"Scalar\" Center=\"Cell\">\n",
538  output->var_name[nv]);
539  #if DIMENSIONS == 2
540  fprintf(fxmf, " <DataItem Dimensions=\"%d %d\" NumberType=\"Float\" Precision=\"%d\" Format=\"HDF\">\n",
541  wgrid[0]->np_int_glob, wgrid[1]->np_int_glob, nprec);
542  #elif DIMENSIONS == 3
543  fprintf(fxmf, " <DataItem Dimensions=\"%d %d %d\" NumberType=\"Float\" Precision=\"%d\" Format=\"HDF\">\n",
544  wgrid[0]->np_int_glob, wgrid[1]->np_int_glob, wgrid[2]->np_int_glob, nprec);
545  #endif
546  fprintf(fxmf, " %s:%s/vars/%s\n",filename,tstepname,output->var_name[nv]);
547  fprintf(fxmf, " </DataItem>\n");
548  fprintf(fxmf, " </Attribute>\n");
549  }
550  for (nd = 0; nd < DIMENSIONS; nd++) { /* Write cell center coordinates (as cell-centerd variables) */
551  fprintf(fxmf, " <Attribute Name=\"%s\" AttributeType=\"Scalar\" Center=\"Cell\">\n",
552  cname[nd]);
553  #if DIMENSIONS == 2
554  fprintf(fxmf, " <DataItem Dimensions=\"%d %d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n",
555  wgrid[0]->np_int_glob, wgrid[1]->np_int_glob);
556  #elif DIMENSIONS == 3
557  fprintf(fxmf, " <DataItem Dimensions=\"%d %d %d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n",
558  wgrid[0]->np_int_glob, wgrid[1]->np_int_glob, wgrid[2]->np_int_glob);
559  #endif
560  fprintf(fxmf, " %s:/cell_coords/%s\n",filename,cname[nd]);
561  fprintf(fxmf, " </DataItem>\n");
562  fprintf(fxmf, " </Attribute>\n");
563  }
564  fprintf(fxmf, " </Grid>\n");
565  fprintf(fxmf, " </Domain>\n");
566  fprintf(fxmf, "</Xdmf>\n");
567  fclose(fxmf);
568  } /* if (prank == 0) */
569 
570 /* XDMF file */
571 
572  #ifdef PARALLEL
573  MPI_Barrier (MPI_COMM_WORLD);
574  if (prank == 0){
575  time(&tend);
576  print1 (" [%5.2f sec]",difftime(tend,tbeg));
577  }
578  #endif
579 }
int lbound
When different from zero, it specifies the boundary condition to be applied at leftmost grid side whe...
Definition: structs.h:105
#define FLT_H5_OUTPUT
Definition: pluto.h:83
static int rbound
Definition: jet_domain.c:25
double *** V[64]
pointer to arrays being written - same for all
Definition: structs.h:247
long int NX1
Number of interior zones in the X1 directions (boundaries excluded) for the local processor...
Definition: globals.h:48
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
int nfile
current number being saved - one per output
Definition: structs.h:237
int np_int_glob
Total number of points in the global domain (boundaries excluded).
Definition: structs.h:98
int rbound
Same as lbound, but for the right edge of the grid.
Definition: structs.h:112
#define SPHERICAL
Definition: pluto.h:36
char dir[256]
output directory name
Definition: structs.h:244
int prank
Processor rank.
Definition: globals.h:33
float *** Convert_dbl2flt(double ***Vdbl, double unit, int swap_endian)
Definition: bin_io.c:216
#define KDIR
Definition: pluto.h:195
char ext[8]
output extension
Definition: structs.h:243
#define POLAR
Definition: pluto.h:35
double * xl
Definition: structs.h:82
long int NX2
Number of interior zones in the X2 directions (boundaries excluded) for the local processor...
Definition: globals.h:50
#define IDIR
Definition: pluto.h:193
int beg
Global start index for the local array.
Definition: structs.h:115
#define DBL_H5_OUTPUT
Definition: pluto.h:82
Definition: structs.h:78
#define ARRAY_4D(nx, ny, nz, nv, type)
Definition: prototypes.h:173
int nghost
Number of ghost zones.
Definition: structs.h:104
int nvar
tot.
Definition: structs.h:234
double * x
Definition: structs.h:80
#define GEOMETRY
Definition: definitions_01.h:4
int * dump_var
select vars being written - one per output
Definition: structs.h:240
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
double g_time
The current integration time.
Definition: globals.h:117
int type
output format (DBL, FLT, ...) - one per output
Definition: structs.h:233
int * stag_var
centered or staggered variable - same for all
Definition: structs.h:239
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
int np_tot
Total number of points in the local domain (boundaries included).
Definition: structs.h:100
#define JDIR
Definition: pluto.h:194
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
#define NVAR
Definition: pluto.h:609
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
long int NX3
Number of interior zones in the X3 directions (boundaries excluded) for the local processor...
Definition: globals.h:52
char ** var_name
variable names - same for all
Definition: structs.h:242
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
#define DIMENSIONS
Definition: definitions_01.h:2
int np_int
Total number of points in the local domain (boundaries excluded).
Definition: structs.h:102

Here is the call graph for this function:

Here is the caller graph for this function:

void WritePNG ( double ***  ,
char *  ,
char *  ,
Grid  
)

Here is the caller graph for this function:

void WritePPM ( double ***  ,
char *  ,
char *  ,
Grid  
)

Definition at line 10 of file write_img.c.

19 {
20  int ic, ir;
21  FILE *fl;
22  char header[512];
23  Image *ppm;
24 
25  ppm = GetImage (var_name);
26  SetColorMap (ppm->r, ppm->g, ppm->b, ppm->colormap);
27  GetSlice (Vdbl, ppm, grid);
28  if (prank != 0) return;
29 
30  sprintf (header,"P6\n%d %d\n255\n", ppm->ncol, ppm->nrow);
31  fl = fopen (filename,"w");
32  fprintf(fl,"%s",header);
33  for (ir = 0; ir < ppm->nrow; ir++){
34  fwrite (ppm->rgb[ir], sizeof(RGB), ppm->ncol, fl);
35  }
36  fclose(fl);
37 }
unsigned char b[256]
Definition: structs.h:306
void SetColorMap(unsigned char *r, unsigned char *g, unsigned char *b, char *map_name)
Definition: colortable.c:11
Definition: structs.h:296
int prank
Processor rank.
Definition: globals.h:33
int ncol
Definition: structs.h:301
unsigned char g[256]
Definition: structs.h:306
char * colormap
Definition: structs.h:304
RGB ** rgb
Definition: structs.h:307
Definition: structs.h:300
int nrow
Definition: structs.h:301
static void GetSlice(double ***, Image *, Grid *)
Definition: write_img.c:144
unsigned char r[256]
Definition: structs.h:306
Image * GetImage(char *)
Definition: set_image.c:35

Here is the call graph for this function:

Here is the caller graph for this function:

void WriteTabArray ( Output output,
char *  filename,
Grid grid 
)

Write tabulated array.

Parameters
[in]outputa pointer to the output structure corresponding to the tab format
[in]filenamethe output file name
[in]gridpointer to an array of Grid structures

Definition at line 31 of file write_tab.c.

40 {
41  int nv, i, j, k;
42  FILE *fout;
43 
44  #ifdef PARALLEL
45  print1 ("! WriteTabArray: tab output not supported in parallel\n");
46  return;
47  #endif
48 
49  #if DIMENSIONS == 3
50  print1 ("! WriteTabArray: tab output not supported in 3D\n");
51  return;
52  #endif
53 
54 /* ------------------------------------------
55  dump arrays in ascii format to disk
56  ------------------------------------------ */
57 
58  fout = fopen (filename, "w");
59  k = 0;
60  IDOM_LOOP (i){
61  JDOM_LOOP(j){
62  fprintf (fout, "%f %f ", grid[IDIR].x[i], grid[JDIR].x[j]);
63  for (nv = 0; nv < output->nvar; nv++) {
64  if (output->dump_var[nv])
65  fprintf (fout, "%12.6e ", output->V[nv][k][j][i]);
66  }
67  fprintf (fout, "\n"); /* newline */
68  }
69  #if DIMENSIONS > 1
70  fprintf (fout, "\n"); /* skip one more empty line in 2D */
71  #endif
72  }
73  fclose (fout);
74 }
double *** V[64]
pointer to arrays being written - same for all
Definition: structs.h:247
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
#define JDOM_LOOP(j)
Definition: macros.h:35
#define IDIR
Definition: pluto.h:193
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
int nvar
tot.
Definition: structs.h:234
double * x
Definition: structs.h:80
int * dump_var
select vars being written - one per output
Definition: structs.h:240
int i
Definition: analysis.c:2
#define JDIR
Definition: pluto.h:194
#define IDOM_LOOP(i)
Definition: macros.h:34

Here is the call graph for this function:

Here is the caller graph for this function:

void WriteVTK_Header ( FILE *  fvtk,
Grid grid 
)

Write VTK header in parallel or serial mode. In parallel mode only processor 0 does the actual writing (see al_io.c/AL_Write_header).

Parameters
[in]fvtkpointer to file
[in]gridpointer to an array of Grid structures
Todo:
Write the grid using several processors.

Definition at line 91 of file write_vtk.c.

103 {
104  int i, j, k;
105  int nx1, nx2, nx3;
106  char header[1024];
107  float x1, x2, x3;
108  static float ***node_coord, *xnode, *ynode, *znode;
109 
110 /* ------------------------------------------------
111  get global dimensions
112  ------------------------------------------------ */
113 
114  nx1 = grid[IDIR].gend + 1 - grid[IDIR].nghost;
115  nx2 = grid[JDIR].gend + 1 - grid[JDIR].nghost;
116  nx3 = grid[KDIR].gend + 1 - grid[KDIR].nghost;
117 
118 /* -------------------------------------------------------------
119  Allocate memory and define node coordinates only once.
120  ------------------------------------------------------------- */
121 
122  if (node_coord == NULL){
123  node_coord = ARRAY_3D(nx2 + JOFFSET, nx1 + IOFFSET, 3, float);
124 
125  #if VTK_FORMAT == RECTILINEAR_GRID
126  xnode = ARRAY_1D(nx1 + IOFFSET, float);
127  ynode = ARRAY_1D(nx2 + JOFFSET, float);
128  znode = ARRAY_1D(nx3 + KOFFSET, float);
129 
130  for (i = 0; i < nx1 + IOFFSET; i++){
131  x1 = (float)(grid[IDIR].xl_glob[i+IBEG]);
132  if (IsLittleEndian()) SWAP_VAR(x1);
133  xnode[i] = x1;
134  }
135  for (j = 0; j < nx2 + JOFFSET; j++){
136  x2 = (float)(grid[JDIR].xl_glob[j+JBEG]);
137  if (IsLittleEndian()) SWAP_VAR(x2);
138  ynode[j] = x2;
139  }
140  for (k = 0; k < nx3 + KOFFSET; k++){
141  x3 = (float)(grid[KDIR].xl_glob[k+KBEG]);
142  if (IsLittleEndian()) SWAP_VAR(x3);
143  #if DIMENSIONS == 2
144  znode[k] = 0.0;
145  #else
146  znode[k] = x3;
147  #endif
148  }
149  #endif
150  }
151 
152 /* ----------------------------------------------------------
153  Part I, II, III:
154  Write file header on string "header"
155  ---------------------------------------------------------- */
156 
157  sprintf(header,"# vtk DataFile Version 2.0\n");
158  sprintf(header+strlen(header),"PLUTO %s VTK Data\n",PLUTO_VERSION);
159  sprintf(header+strlen(header),"BINARY\n");
160  #if VTK_FORMAT == RECTILINEAR_GRID
161  sprintf(header+strlen(header),"DATASET %s\n","RECTILINEAR_GRID");
162  #elif VTK_FORMAT == STRUCTURED_GRID
163  sprintf(header+strlen(header),"DATASET %s\n","STRUCTURED_GRID");
164  #endif
165 
166  VTK_HEADER_WRITE_STRING(header);
167 
168  /* -- generate time info -- */
169 
170  #if VTK_TIME_INFO == YES
171  sprintf (header,"FIELD FieldData 1\n");
172  sprintf (header+strlen(header),"TIME 1 1 double\n");
173  double tt=g_time;
174  if (IsLittleEndian()) SWAP_VAR(tt);
175  VTK_HEADER_WRITE_STRING(header);
176  VTK_HEADER_WRITE_DBLARR(&tt, 1);
178 
179  #endif /* VTK_TIME_INFO */
180 
181  sprintf(header,"DIMENSIONS %d %d %d\n",
182  nx1 + IOFFSET, nx2 + JOFFSET, nx3 + KOFFSET);
183  VTK_HEADER_WRITE_STRING(header);
184 
185 #if VTK_FORMAT == RECTILINEAR_GRID
186 
187  /* -- reset header string and keep going -- */
188 
189  sprintf(header,"X_COORDINATES %d float\n", nx1 + IOFFSET);
190  VTK_HEADER_WRITE_STRING(header);
191  VTK_HEADER_WRITE_FLTARR(xnode, nx1 + IOFFSET);
192 
193  sprintf(header,"\nY_COORDINATES %d float\n", nx2 + JOFFSET);
194  VTK_HEADER_WRITE_STRING(header);
195  VTK_HEADER_WRITE_FLTARR(ynode, nx2 + JOFFSET);
196 
197  sprintf(header,"\nZ_COORDINATES %d float\n", nx3 + KOFFSET);
198  VTK_HEADER_WRITE_STRING(header);
199  VTK_HEADER_WRITE_FLTARR(znode, nx3 + KOFFSET);
200 
201  sprintf (header,"\nCELL_DATA %d\n", nx1*nx2*nx3);
202  VTK_HEADER_WRITE_STRING (header);
203 
204 #elif VTK_FORMAT == STRUCTURED_GRID
205 
206  sprintf(header,"POINTS %d float\n", (nx1+IOFFSET)*(nx2+JOFFSET)*(nx3+KOFFSET));
207  VTK_HEADER_WRITE_STRING(header);
208 
209 /* ---------------------------------------------------------------
210  Part IV: (structured) grid information
211  --------------------------------------------------------------- */
212 
213  x1 = x2 = x3 = 0.0;
214  for (k = 0; k < nx3 + KOFFSET; k++){
215  for (j = 0; j < nx2 + JOFFSET; j++){
216  for (i = 0; i < nx1 + IOFFSET; i++){
217  D_EXPAND(x1 = grid[IDIR].xl_glob[IBEG + i]; ,
218  x2 = grid[JDIR].xl_glob[JBEG + j]; ,
219  x3 = grid[KDIR].xl_glob[KBEG + k];)
220 
221  #if (GEOMETRY == CARTESIAN) || (GEOMETRY == CYLINDRICAL)
222  node_coord[j][i][0] = x1;
223  node_coord[j][i][1] = x2;
224  node_coord[j][i][2] = x3;
225  #elif GEOMETRY == POLAR
226  node_coord[j][i][0] = x1*cos(x2);
227  node_coord[j][i][1] = x1*sin(x2);
228  node_coord[j][i][2] = x3;
229  #elif GEOMETRY == SPHERICAL
230  #if DIMENSIONS == 2
231  node_coord[j][i][0] = x1*sin(x2);
232  node_coord[j][i][1] = x1*cos(x2);
233  node_coord[j][i][2] = 0.0;
234  #elif DIMENSIONS == 3
235  node_coord[j][i][0] = x1*sin(x2)*cos(x3);
236  node_coord[j][i][1] = x1*sin(x2)*sin(x3);
237  node_coord[j][i][2] = x1*cos(x2);
238  #endif
239  #endif
240 
241  if (IsLittleEndian()){
242  SWAP_VAR(node_coord[j][i][0]);
243  SWAP_VAR(node_coord[j][i][1]);
244  SWAP_VAR(node_coord[j][i][2]);
245  }
246  }}
247  VTK_HEADER_WRITE_FLTARR(node_coord[0][0],3*(nx1+IOFFSET)*(nx2+JOFFSET));
248  }
249 
250  sprintf (header,"\nCELL_DATA %d\n", nx1*nx2*nx3);
251  VTK_HEADER_WRITE_STRING(header);
252 
253 #endif
254 }
#define VTK_HEADER_WRITE_STRING(header)
Definition: write_vtk.c:82
#define VTK_HEADER_WRITE_FLTARR(arr, nelem)
Definition: write_vtk.c:84
#define PLUTO_VERSION
Definition: pluto.h:16
int gend
Global end index for the global array.
Definition: structs.h:114
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
#define KDIR
Definition: pluto.h:195
#define SWAP_VAR(x)
Definition: macros.h:115
#define IDIR
Definition: pluto.h:193
int j
Definition: analysis.c:2
int IsLittleEndian(void)
Definition: tools.c:40
#define VTK_HEADER_WRITE_DBLARR(arr, nelem)
Definition: write_vtk.c:86
int nghost
Number of ghost zones.
Definition: structs.h:104
int k
Definition: analysis.c:2
double * xl_glob
Cell left interface.
Definition: structs.h:82
#define GEOMETRY
Definition: definitions_01.h:4
#define CARTESIAN
Definition: pluto.h:33
#define CYLINDRICAL
Definition: pluto.h:34
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
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
double g_time
The current integration time.
Definition: globals.h:117
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
#define JDIR
Definition: pluto.h:194
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35

Here is the call graph for this function:

Here is the caller graph for this function:

void WriteVTK_Scalar ( FILE *  fvtk,
double ***  V,
double  unit,
char *  var_name,
Grid grid 
)

Write VTK scalar field.

Parameters
[in]fvtkpointer to file (handle)
[in]Vpointer to 3D data array
[in]unitthe corresponding cgs unit (if specified, 1 otherwise)
[in]var_namethe variable name appearing in the VTK file
[in]gridpointer to an array of Grid structures

Definition at line 341 of file write_vtk.c.

352 {
353  int i,j,k;
354  char header[512];
355  float ***Vflt;
356 
357  sprintf (header,"\nSCALARS %s float\n", var_name);
358  sprintf (header,"%sLOOKUP_TABLE default\n",header);
359 
360  #ifdef PARALLEL
361  MPI_Barrier (MPI_COMM_WORLD);
362  AL_Write_header (header, strlen(header), MPI_CHAR, SZ_float);
363  #else
364  fprintf (fvtk, "%s",header);
365  #endif
366 
367  Vflt = Convert_dbl2flt(V, unit, IsLittleEndian());
368  WriteBinaryArray (Vflt[0][0], sizeof(float), SZ_float, fvtk, -1);
369 }
int AL_Write_header(void *vbuffer, int nelem, AL_Datatype type, int sz_ptr)
Definition: al_io.c:285
int SZ_float
Definition: globals.h:27
float *** Convert_dbl2flt(double ***Vdbl, double unit, int swap_endian)
Definition: bin_io.c:216
int j
Definition: analysis.c:2
int IsLittleEndian(void)
Definition: tools.c:40
int k
Definition: analysis.c:2
int i
Definition: analysis.c:2
void WriteBinaryArray(void *V, size_t dsize, int sz, FILE *fl, int istag)
Definition: bin_io.c:98

Here is the call graph for this function:

Here is the caller graph for this function:

void WriteVTK_Vector ( FILE *  fvtk,
Data_Arr  V,
double  unit,
char *  var_name,
Grid grid 
)

Write VTK vector field data. This is enabled only when VTK_VECTOR_DUMP is set to YES. For generality purposes, vectors are written always with 3 components, even when there're only 2 being used.

The following Maple script has been used to find vector components from cyl/sph to cartesian:

1 restart;
2 with(linalg);
3 Acyl := matrix (3,3,[ cos(phi), sin(phi), 0,
4  -sin(phi), cos(phi), 0,
5  0 , 0 , 1]);
6 Asph := matrix (3,3,[ sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta),
7  cos(theta)*cos(phi), cos(theta)*sin(phi), -sin(theta),
8  -sin(phi) , cos(phi) , 0]);
9 Bcyl := simplify(inverse(Acyl));
10 Bsph := simplify(inverse(Asph));
Parameters
[in]fvtkpointer to file
[in]Va 4D array [nv][k][j][i] containing the vector components (nv) defined at cell centers (k,j,i). The index nv = 0 marks the vector first component.
[in]unitthe corresponding cgs unit (if specified, 1 otherwise)
[in]var_namethe variable name appearing in the VTK file
[in]gridpointer to an array of Grid structures

Definition at line 259 of file write_vtk.c.

291 {
292  int i,j,k;
293  int vel_field, mag_field;
294  char header[512];
295  static Float_Vect ***vect3D;
296  double v[3], x1, x2, x3;
297 
298  if (vect3D == NULL){
300  }
301 
302 /* --------------------------------------------------------
303  Write VTK vector fields
304  -------------------------------------------------------- */
305 
306  v[0] = v[1] = v[2] = 0.0;
307  x1 = x2 = x3 = 0.0;
308 
309  vel_field = (strcmp(var_name,"vx1") == 0);
310  mag_field = (strcmp(var_name,"bx1") == 0);
311  if (vel_field || mag_field) {
312  DOM_LOOP(k,j,i){
313  D_EXPAND(v[0] = V[0][k][j][i]; x1 = grid[IDIR].x[i]; ,
314  v[1] = V[1][k][j][i]; x2 = grid[JDIR].x[j]; ,
315  v[2] = V[2][k][j][i]; x3 = grid[KDIR].x[k];)
316 
317  VectorCartesianComponents(v, x1, x2, x3);
318  vect3D[k][j][i].v1 = (float)v[0]*unit;
319  vect3D[k][j][i].v2 = (float)v[1]*unit;
320  vect3D[k][j][i].v3 = (float)v[2]*unit;
321 
322  if (IsLittleEndian()){
323  SWAP_VAR(vect3D[k][j][i].v1);
324  SWAP_VAR(vect3D[k][j][i].v2);
325  SWAP_VAR(vect3D[k][j][i].v3);
326  }
327 
328  } /* endfor DOM_LOOP(k,j,i) */
329 
330  if (vel_field)
331  sprintf (header,"\nVECTORS %dD_Velocity_Field float\n", DIMENSIONS);
332  else
333  sprintf (header,"\nVECTORS %dD_Magnetic_Field float\n", DIMENSIONS);
334 
335  VTK_HEADER_WRITE_STRING(header);
336  WriteBinaryArray (vect3D[0][0], sizeof(Float_Vect), SZ_Float_Vect, fvtk, -1);
337  }
338 }
DOM_LOOP(k, j, i)
Definition: analysis.c:22
float v1
Definition: structs.h:314
float v2
Definition: structs.h:314
#define VTK_HEADER_WRITE_STRING(header)
Definition: write_vtk.c:82
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
float v3
Definition: structs.h:314
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
#define KDIR
Definition: pluto.h:195
int SZ_Float_Vect
Definition: globals.h:29
#define SWAP_VAR(x)
Definition: macros.h:115
#define IDIR
Definition: pluto.h:193
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int j
Definition: analysis.c:2
int IsLittleEndian(void)
Definition: tools.c:40
int k
Definition: analysis.c:2
double * x
Definition: structs.h:80
void VectorCartesianComponents(double *v, double x1, double x2, double x3)
Definition: math_misc.c:227
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
#define JDIR
Definition: pluto.h:194
void WriteBinaryArray(void *V, size_t dsize, int sz, FILE *fl, int istag)
Definition: bin_io.c:98
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

Here is the call graph for this function:

Here is the caller graph for this function: