PLUTO
amrPluto.cpp File Reference
#include <iostream>
#include "FABView.H"
#include "ParmParse.H"
#include "CH_HDF5.H"
#include "parstream.H"
#include "CH_Timer.H"
#include "memusage.H"
#include "AMR.H"
#include "AMRLevelPlutoFactory.H"
#include "UsingNamespace.H"
#include "globals.h"
Include dependency graph for amrPluto.cpp:

Go to the source code of this file.

Macros

#define NOPT   32
 

Functions

void amrPluto (int, char *av[], char *, Cmd_Line *)
 
int main (int a_argc, char *a_argv[])
 
void print (const char *fmt,...)
 
void print1 (const char *fmt,...)
 

Macro Definition Documentation

#define NOPT   32

Definition at line 53 of file amrPluto.cpp.

Function Documentation

void amrPluto ( int  argc,
char *  av[],
char *  ini_file,
Cmd_Line cmd_line 
)

Definition at line 112 of file amrPluto.cpp.

121 {
122  Real residentSetSize=0.0;
123  Real size=0.0;
124 
125  Runtime runtime;
126  Grid grid[3];
127  RuntimeSetup (&runtime, cmd_line, ini_file);
128  RuntimeSet (&runtime);
129 
130  std::string base_name = "pout";
131  base_name = runtime.output_dir+string("/")+base_name;
132  setPoutBaseName(base_name);
133 
134  ShowConfig(argc, argv, ini_file);
135 
136  pout() << endl << "> Generating grid..." << endl << endl;
137  int nghost = GetNghost();
138  for (int idim = 0; idim < DIMENSIONS; idim++) {
139  grid[idim].nghost = nghost;
140  grid[idim].np_int = grid[idim].np_int_glob = runtime.npoint[idim];
141  grid[idim].np_tot = grid[idim].np_tot_glob = runtime.npoint[idim] + 2*nghost;
142  grid[idim].beg = grid[idim].gbeg = grid[idim].lbeg = nghost;
143  grid[idim].end = grid[idim].gend = grid[idim].lend
144  = (grid[idim].lbeg - 1) + grid[idim].np_int;
145  grid[idim].lbound = runtime.left_bound[idim];
146  grid[idim].rbound = runtime.right_bound[idim];
147  }
148  SetGrid (&runtime, grid);
149 
150  // VERBOSITY
151 
152  // This determines the amount of diagnositic output generated
153  int verbosity = 1; /* -- change through cmd line args ?? -- */
154  CH_assert(verbosity >= 0);
155 
156  // [Grid]
157 
158  // Set the physical size of the dimensions of the domain
159 
160  Real domainLength = 0.0, xbeg[3], xend[3];
161  g_x2stretch = 1.;
162  g_x3stretch = 1.;
163 
164  for (int dir = 0; dir < DIMENSIONS; dir++){
165  xbeg[dir] = runtime.patch_left_node[dir][1];
166  xend[dir] = runtime.patch_left_node[dir][2];
167  domainLength = MAX(domainLength, xend[dir] - xbeg[dir]);
168  }
169  domainLength = xend[IDIR] - xbeg[IDIR];
170 
171 #if (CHOMBO_LOGR == YES)
172  domainLength = log(xend[IDIR]/xbeg[IDIR]);
173 #endif
174 
175 #if CH_SPACEDIM > 1
176  g_x2stretch = (xend[JDIR] - xbeg[JDIR])/domainLength*(double)runtime.npoint[IDIR]/(double)runtime.npoint[JDIR];
177 #endif
178 #if CH_SPACEDIM == 3
179  g_x3stretch = (xend[KDIR] - xbeg[KDIR])/domainLength*(double)runtime.npoint[IDIR]/(double)runtime.npoint[KDIR];
180 #endif
181 
182 #if GEOMETRY == CARTESIAN
183  g_stretch_fact = g_x2stretch*g_x3stretch;
184 #endif
185 
186  // Set the resolution of the coarsest level
187  vector<int> numCells(SpaceDim);
188 
189  D_EXPAND(numCells[0] = runtime.patch_npoint[IDIR][1]; ,
190  numCells[1] = runtime.patch_npoint[JDIR][1]; ,
191  numCells[2] = runtime.patch_npoint[KDIR][1];)
192 
193  CH_assert(D_TERM( (numCells[0] > 0),
194  && (numCells[1] > 0),
195  && (numCells[2] > 0)));
196  CH_assert(D_TERM( (numCells[0] % 2 == 0),
197  && (numCells[1] % 2 == 0),
198  && (numCells[2] % 2 == 0)));
199 
200  // REFINEMENT
201  ParamFileRead (ini_file);
202 
203  //Maximum AMR level limit
204  int maxLevel = 0;
205  maxLevel = atoi(ParamFileGet("Levels",1));
206  int numReadLevels = MAX(maxLevel, 1);
207 
208  // Refinement ratios between levels
209  // Note: this requires a refRatio to be defined for the finest level
210  // (even though it will never be used)
211  std::vector<int> refRatios(numReadLevels + 1);
212  int totLevels = 1;
213  for (int nlev = 0; nlev <= numReadLevels; nlev++){
214  refRatios[nlev] = atoi(ParamFileGet("Ref_ratio",nlev+1));
215  if (nlev < maxLevel) totLevels *= refRatios[nlev];
216  }
217 
218  int nprocs = 1; // number of processors
219 #ifdef CH_MPI
220  MPI_Comm_size(Chombo_MPI::comm, &nprocs);
221 #endif
222 
223  pout() << endl << endl;
224  pout() << "> AMR: " << endl << endl;
225  pout() << " Number of levels: " << maxLevel << endl;
226  pout() << " Equivalent Resolution: " << grid[IDIR].np_int*totLevels;
227  D_EXPAND( ,
228  pout() << " x " << grid[JDIR].np_int*totLevels; ,
229  pout() << " x " << grid[KDIR].np_int*totLevels;)
230  pout() << endl;
231  pout() << " Number of procs: " << nprocs << endl << endl;
232 
233  // Number of coarse time steps from one regridding to the next
234  std::vector<int> regridIntervals(numReadLevels);
235  for (int nlev = 0; nlev < numReadLevels; nlev++)
236  regridIntervals[nlev] = atoi(ParamFileGet("Regrid_interval",nlev+1));
237 
238  // Threshold that triggers refinement
239  Real refineThresh = atof(ParamFileGet("Refine_thresh",1));
240 
241  // How far to extend refinement from cells newly tagged for refinement
242  int tagBufferSize = atoi (ParamFileGet("Tag_buffer_size",1));
243 
244  // Minimum dimension of a grid
245  int blockFactor = atoi(ParamFileGet("Block_factor",1));
246 
247  // Maximum dimension of a grid
248  int maxGridSize = atoi(ParamFileGet("Max_grid_size",1));
249 
250  NMAX_POINT = maxGridSize + 8;
251 // NMAX_POINT = 2*maxGridSize;
252 
253  Real fillRatio = atof (ParamFileGet("Fill_ratio",1));
254 
255  // [Time]
256 // Real cfl = runtime.cfl; // CFL multiplier
257 // Real maxDtGrowth = runtime.cfl_max_var; // Limit the time step growth
258 // Real stopTime = runtime.tstop; // Stop when the simulation time get here
259  Real initialDT = runtime.first_dt; // Initial time step
260 
261  Real dtToleranceFactor = 1.1; // Let the time step grow by this factor
262  // above the "maximum" before reducing it
263 
264  int nstop = 999999; // Stop after this number of steps
265  if (cmd_line->maxsteps > 0) nstop = cmd_line->maxsteps;
266 
267  // [Solver]
268 
269  Riemann_Solver *Solver; // SOLVER
270  std::string riem = runtime.solv_type;
271  Solver = SetSolver(riem.c_str());
272 
273  Real fixedDt = -1; // Determine if a fixed or variable time step will be used
274 
275  // [Boundary]
276  vector<int> isPeriodica(SpaceDim,0);
277 
278  for (int dir = 0; dir < DIMENSIONS; dir++){
279  if (runtime.left_bound[dir] == PERIODIC || runtime.right_bound[dir] == PERIODIC){
280  isPeriodica[dir] = 1;
281  } else {
282  isPeriodica[dir] = 0;
283  }
284  }
285 
286  bool isPeriodic[SpaceDim];
287  // convert periodic from int->bool
288  for (int dim = 0; dim < SpaceDim; dim++)
289  {
290  isPeriodic[dim] = (isPeriodica[dim] == 1);
291  if (isPeriodic[dim] && verbosity >= 2 && procID() == 0)
292  pout() << "Using Periodic BCs in direction: " << dim << endl;
293  }
294 
295  // [Output]
296 
297  // Set up checkpointing
298  Output output;
299  GetOutputFrequency (&output, "Checkpoint_interval");
300 
301  Real checkpointPeriod = output.dt;
302  Real checkpointClock = output.dclock;
303  int checkpointInterval = output.dn;
304 
305  // Set up plot file writing
306  GetOutputFrequency (&output, "Plot_interval");
307 
308  Real plotPeriod = output.dt;
309  Real plotClock = output.dclock;
310  int plotInterval = output.dn;
311 
312  if (cmd_line->write == NO) {
313  plotPeriod = checkpointPeriod = -1.0;
314  plotClock = checkpointClock = -1.0;
315  plotInterval = checkpointInterval = -1;
316  }
317 
318  // [Parameters]
319 
320  for (int i = 0; i < USER_DEF_PARAMETERS; ++i) g_inputParam[i] = runtime.aux[i];
321 
322  // Initialize PVTE_LAW EOS Table before calling Init()
323 
324 #if EOS == PVTE_LAW && NIONS == 0
325  #if TV_ENERGY_TABLE == YES
327  #else
329  #endif
331 #endif
332 
333  // Call Init once so all processors share global variables
334  // assigniments such as g_gamma, g_unitDensity, and so on.
335  // This is necessary since not all processors call Init
336  // from Startup.
337 
338  double u[256];
339  Init (u, g_domBeg[0], g_domBeg[1], g_domBeg[2]);
340 
341  // Print the parameters
342  if ( verbosity >= 2 ) {
343  pout() << "maximum step = " << nstop << endl;
344  pout() << "maximum time = " << runtime.tstop << endl;
345 
346  pout() << "number of cells = " << D_TERM(numCells[0] << " " <<,
347  numCells[1] << " " <<,
348  numCells[2] << ) endl;
349 
350  pout() << "maximum level = " << maxLevel << endl;
351 
352  pout() << "refinement ratio = ";
353  for (int i = 0; i < refRatios.size(); ++i) pout() << refRatios[i] << " ";
354  pout() << endl;
355 
356  pout() << "regrid interval = ";
357  for (int i = 0; i < regridIntervals.size(); ++i) pout() << regridIntervals[i] << " ";
358  pout() << endl;
359 
360  pout() << "refinement threshold = " << refineThresh << endl;
361 
362  pout() << "blocking factor = " << blockFactor << endl;
363  pout() << "max grid size = " << maxGridSize << endl;
364  pout() << "fill ratio = " << fillRatio << endl;
365 
366  pout() << "checkpoint interval = " << checkpointInterval << endl;
367  pout() << "plot interval = " << plotInterval << endl;
368  pout() << "CFL = " << runtime.cfl << endl;
369  pout() << "initial dt = " << initialDT << endl;
370  if (fixedDt > 0) pout() << "fixed dt = " << fixedDt << endl;
371  pout() << "maximum dt growth = " << runtime.cfl_max_var << endl;
372  pout() << "dt tolerance factor = " << dtToleranceFactor << endl;
373  }
374 
375  ShowUnits();
376 
377  ProblemDomain probDomain (IntVect::Zero,
378  IntVect(D_DECL(numCells[0]-1,
379  numCells[1]-1,
380  numCells[2]-1)),
381  isPeriodic);
382 
383  initialDT = initialDT*(probDomain.domainBox().bigEnd(0)-probDomain.domainBox().smallEnd(0)+1);
384 
385  PatchPluto* patchPluto = static_cast<PatchPluto*>(new PatchPluto());
386 
387  // Set up the patch integrator
388  patchPluto->setBoundary(runtime.left_bound, runtime.right_bound);
389  patchPluto->setRiemann(Solver);
390 
391  // Set up the AMRLevel... factory
392  AMRLevelPlutoFactory amrGodFact;
393 
394  amrGodFact.define(runtime.cfl,
395  domainLength,
396  verbosity,
397  refineThresh,
398  tagBufferSize,
399  initialDT,
400  patchPluto);
401 
402  AMR amr;
403 
404  // Set up the AMR object
405  amr.define(maxLevel,refRatios,probDomain,&amrGodFact);
406 
407  if (fixedDt > 0) amr.fixedDt(fixedDt);
408 
409  // Set grid generation parameters
410  amr.maxGridSize(maxGridSize);
411  amr.blockFactor(blockFactor);
412  amr.fillRatio(fillRatio);
413 
414  // The hyperbolic codes use a grid buffer of 1
415  amr.gridBufferSize(1);
416 
417  // Set output parameters
418  amr.checkpointPeriod(checkpointPeriod);
419  amr.checkpointClock (checkpointClock);
420  amr.checkpointInterval(checkpointInterval);
421  amr.plotPeriod (plotPeriod);
422  amr.plotClock (plotClock);
423  amr.plotInterval(plotInterval);
424  amr.regridIntervals(regridIntervals);
425  amr.maxDtGrow(runtime.cfl_max_var);
426  amr.dtToleranceFactor(dtToleranceFactor);
427 
428  // Setup output files
429  std::string prefix = "data.";
430  prefix = runtime.output_dir+string("/")+prefix;
431  amr.plotPrefix(prefix);
432 
433  // Setup checkpoint files
434  prefix = "chk.";
435  prefix = runtime.output_dir+string("/")+prefix;
436  amr.checkpointPrefix(prefix);
437 
438  amr.verbosity(verbosity);
439 
440  // Setup input files
441  if (cmd_line->restart == NO && cmd_line->h5restart == NO){
442  if (!ParamExist("fixed_hierarchy")) {
443 
444  // initialize from scratch for AMR run
445  // initialize hierarchy of levels
446  amr.setupForNewAMRRun();
447  } else {
448  MayDay::Error("Fixed_hierarchy option still disabled");
449  }
450  } else {
451  char restartNumber[32];
452  sprintf (restartNumber, "%04d.hdf5", cmd_line->nrestart);
453  prefix += restartNumber;
454 
455  pout() << endl << "> Restarting from file " << prefix << endl;
456 
457 #ifdef CH_USE_HDF5
458  HDF5Handle handle(prefix,HDF5Handle::OPEN_RDONLY);
459  // read from checkpoint file
460  amr.setupForRestart(handle);
461  handle.close();
462  // Create dummies to be passed to startup
463  // startup should be called at restart too
464 /*
465  Box dummyBox (IntVect::Zero,
466  IntVect(D_DECL(NMAX_POINT-1,
467  NMAX_POINT-1,
468  NMAX_POINT-1)));
469  FArrayBox dummyData(dummyBox,NVAR);
470  dummyData.setVal(0.0);
471  patchPluto->startup(dummyData);
472 */
473 #else
474  MayDay::Error("amrPluto restart only defined with hdf5");
475 #endif
476  }
477 
478  time_t tbeg, tend;
479  double exec_time;
480 
481  // Run the computation
482  pout() << "> Starting Computation" << endl;
483  time (&tbeg);
484 
485  amr.run(runtime.tstop,nstop);
486 
487  time (&tend);
488  exec_time = difftime (tend, tbeg);
489  pout() << "> Elapsed time: " << exec_time << " s" << endl;
490  pout() << "> Done\n";
491 
492  // Output the last plot file and statistics
493  amr.conclude();
494 }
#define EOS
Definition: pluto.h:341
#define MAX(a, b)
Definition: macros.h:101
int write
Definition: structs.h:16
int lbound
When different from zero, it specifies the boundary condition to be applied at leftmost grid side whe...
Definition: structs.h:105
void GetOutputFrequency(Output *, const char *)
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
#define USER_DEF_PARAMETERS
int ParamExist(const char *label)
Definition: parse_file.c:159
Riemann_Solver * SetSolver(const char *solver)
Definition: set_solver.c:4
int npoint[3]
Global number of zones in the interior domain.
Definition: structs.h:256
int nrestart
Definition: structs.h:14
void Riemann_Solver(const State_1D *, int, int, double *, Grid *)
Definition: pluto.h:489
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
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
#define PVTE_LAW
Definition: pluto.h:46
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 gend
Global end index for the global array.
Definition: structs.h:114
int np_tot_glob
Total number of points in the global domain (boundaries included).
Definition: structs.h:96
#define KDIR
Definition: pluto.h:195
int right_bound[3]
Array of right boundary types.
Definition: structs.h:258
double dt
time increment between outputs - one per output
Definition: structs.h:245
double patch_left_node[5][16]
Definition: structs.h:273
#define IDIR
Definition: pluto.h:193
int beg
Global start index for the local array.
Definition: structs.h:115
#define NIONS
Definition: cooling.h:28
Definition: structs.h:78
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
if(divB==NULL)
Definition: analysis.c:10
int nghost
Number of ghost zones.
Definition: structs.h:104
int RuntimeSetup(Runtime *, Cmd_Line *, char *)
Definition: runtime_setup.c:22
char solv_type[64]
The Riemann solver (Solver)
Definition: structs.h:267
double g_domBeg[3]
Lower limits of the computational domain.
Definition: globals.h:125
double aux[32]
Definition: structs.h:284
void MakeEV_TemperatureTable()
int ParamFileRead(char *fname)
Definition: parse_file.c:53
int maxsteps
Definition: structs.h:17
double tstop
The final integration time (tstop)
Definition: structs.h:280
void Init(double *, double, double, double)
Definition: init.c:17
D_EXPAND(tot/[n]=(double) grid[IDIR].np_int_glob;, tot/[n]=(double) grid[JDIR].np_int_glob;, tot/[n]=(double) grid[KDIR].np_int_glob;)
Definition: analysis.c:27
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
int i
Definition: analysis.c:2
int patch_npoint[5][16]
Definition: structs.h:261
#define TV_ENERGY_TABLE
Definition: eos.h:120
void MakeInternalEnergyTable()
void ShowUnits()
Definition: show_config.c:260
void MakePV_TemperatureTable()
Definition: thermal_eos.c:63
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
char * ParamFileGet(const char *label, int pos)
Definition: parse_file.c:86
#define JDIR
Definition: pluto.h:194
void SetGrid(Runtime *, Grid *)
Definition: set_grid.c:21
double max
Definition: analysis.c:5
void RuntimeSet(Runtime *runtime)
#define DIMENSIONS
Definition: definitions_01.h:2
#define NO
Definition: pluto.h:26
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
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:

int main ( int  a_argc,
char *  a_argv[] 
)

Definition at line 60 of file amrPluto.cpp.

70 {
71  Real end_memory, size;
72 #ifdef CH_MPI
73  // Start MPI
74  MPI_Init(&a_argc,&a_argv);
75 #ifdef CH_AIX
76  H5dont_atexit();
77 #endif
78 // setChomboMPIErrorHandler();
79 #endif
80 
81  int rank;
82 
83 #ifdef CH_MPI
84  MPI_Comm_rank(Chombo_MPI::comm, &rank);
85  prank = rank;
86 #else
87  rank = 0;
88 #endif
89 
90  char ini_file[128];
91  Cmd_Line cmd_line;
92 
93  sprintf (ini_file,"pluto.ini"); // default
94  ParseCmdLineArgs(a_argc, a_argv, ini_file, &cmd_line);
95 
96 #ifdef TRAP_FPE
97  enableFpExceptions();
98 #endif
99 
100  // Run amrPluto, i.e., do the computation
101  amrPluto(a_argc, a_argv, ini_file, &cmd_line);
102 
103 #ifdef CH_MPI
104  // Exit MPI
105  dumpmemoryatexit();
106  MPI_Finalize();
107 #endif
108 
109 }
int prank
Processor rank.
Definition: globals.h:33
void amrPluto(int, char *av[], char *, Cmd_Line *)
Definition: amrPluto.cpp:112
void ParseCmdLineArgs(int argc, char *argv[], char *ini_file, Cmd_Line *cmd)
Definition: cmd_line_opt.c:18

Here is the call graph for this function:

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

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,
  ... 
)

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