ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
main.cpp File Reference
#include <iostream>
#include <AMReX.H>
#include <AMReX_BLProfiler.H>
#include <AMReX_ParallelDescriptor.H>
#include "ERF.H"
Include dependency graph for main.cpp:

Functions

void add_par ()
 
int main (int argc, char *argv[])
 

Variables

std::string inputs_name
 

Function Documentation

◆ add_par()

void add_par ( )

Function to set the refine_grid_layout flags to (1,1,0) by default since the ERF default is different from the amrex default (1,1,1) Also set max_grid_size to very large since the only reason for chopping grids is if Nprocs > Ngrids

24  {
25  ParmParse pp("amr");
26 
27  // Set the refine_grid_layout flags to (1,1,0) by default
28  pp.add("refine_grid_layout_x",1);
29  pp.add("refine_grid_layout_y",1);
30  pp.add("refine_grid_layout_z",0);
31 
32  // n_proper is the minimum number of coarse cells between coarse-fine boundaries
33  // between levels (ell and ell+1) and levels (ell-1 and ell). We want this to be
34  // greater than or equal to the stencil width (a function of spatial order) divided by
35  // ref_ratio (which can be 2,3 or 4). This ensures that fillpatch at level (ell)
36  // does not need to reach beyond level (ell-1). Here to be conservative we set this to 2
37  // (rather than the amrex default of 1).
38  pp.add("n_proper",2);
39 
40  int max_grid_size = 2048;
41  pp.queryAdd("max_grid_size",max_grid_size);
42 
43  // This will set the default value of blocking_factor to be 1, but will allow
44  // the user to override it in the inputs file or on command line
45  int blocking_factor = 1;
46  pp.queryAdd("blocking_factor",blocking_factor);
47 
48  int n_error_buf = 0;
49  pp.queryAdd("n_error_buf",n_error_buf);
50 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: Microphysics_Utils.H:183

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main driver – creates the ERF object, calls ERF.InitData() and ERF.Evolve() Also includes the multiblock interface in the case where there is more than one ERF object

57 {
58 #ifdef AMREX_USE_MPI
59  MPI_Init(&argc, &argv);
60 #endif
61 
62  if (argc < 2) {
63  // Print usage and exit with error code if no input file was provided.
64  ERF::print_usage(MPI_COMM_WORLD, std::cout);
66  MPI_COMM_WORLD, "No input file provided. Exiting!!");
67  return 1;
68  }
69 
70  // Look for "-h" or "--help" flag and print usage
71  for (auto i = 1; i < argc; i++) {
72  const std::string param(argv[i]);
73  if ((param == "--help") || (param == "-h") || (param == "--usage")) {
74  ERF::print_banner(MPI_COMM_WORLD, std::cout);
75  ERF::print_usage(MPI_COMM_WORLD, std::cout);
76  return 0;
77  }
78  }
79 
80  if (!amrex::FileSystem::Exists(std::string(argv[1]))) {
81  // Print usage and exit with error code if we cannot find the input file
82  ERF::print_usage(MPI_COMM_WORLD, std::cout);
84  MPI_COMM_WORLD, "Input file does not exist = " +
85  std::string(argv[1]) + ". Exiting!!");
86  return 1;
87  }
88 
89  // print_banner(MPI_COMM_WORLD, std::cout);
90  // Check to see if the command line contains --describe
91  if (argc >= 2) {
92  for (auto i = 1; i < argc; i++) {
93  if (std::string(argv[i]) == "--describe") {
94  ERF::writeBuildInfo(std::cout);
95  return 0;
96  }
97  }
98  }
99  amrex::Initialize(argc,argv,true,MPI_COMM_WORLD,add_par);
100 
101  // Save the inputs file name for later.
102  if (!strchr(argv[1], '=')) {
103  inputs_name = argv[1];
104  }
105 
106  // timer for profiling
107  BL_PROFILE_VAR("main()", pmain);
108 
109  // wallclock time
110  const Real strt_total = amrex::second();
111 
112 #ifdef ERF_USE_MULTIBLOCK
113  {
114  // Vector of constructor parameters for MultiBlock
115  std::vector<RealBox> rb_v;
116  std::vector<int> max_level_v;
117  std::vector<int> coord_v;
118  std::vector<amrex::Vector<int>> n_cell_v;
119  std::vector<amrex::Array<int,AMREX_SPACEDIM>> is_per_v;
120  std::vector<amrex::Vector<amrex::IntVect>> ref_rat_v;
121  std::vector<std::string> prefix_v;
122  int max_step{1};
123 
124  // Local constructor parameters for vector
125  RealBox rb;
126  int max_level{0};
127  int coord{0};
128  amrex::Vector<int> n_cell = {1,1,1};
129  amrex::Array<int,AMREX_SPACEDIM> is_per = {1,1,1};
130  amrex::Vector<amrex::IntVect> ref_rat = {amrex::IntVect(1,1,1)};
131 
132  // Parse max steps for the block
133  {
134  ParmParse pp;
135  pp.query("max_step", max_step);
136  }
137 
138  // Parse data for erf1 constructor
139  {
140  ParmParse pp("erf1");
141  amrex::Vector<Real> lo = {0.,0.,0.};
142  amrex::Vector<Real> hi = {0.,0.,0.};
143  amrex::Vector<int> periodicity = {1,1,1};
144  pp.queryarr("prob_lo",lo);
145  pp.queryarr("prob_hi",hi);
146  rb.setLo(lo);
147  rb.setHi(hi);
148  pp.query("max_level",max_level);
149  pp.query("coord",coord);
150  pp.queryarr("n_cell",n_cell);
151  pp.queryarr("is_periodic",periodicity);
152  {
153  for( int i(0); i<AMREX_SPACEDIM; i++ ) is_per[i] = periodicity[i];
154  }
155  pp.queryarr("ref_ratio",ref_rat);
156 
157  rb_v.push_back(rb);
158  max_level_v.push_back(max_level);
159  coord_v.push_back(coord);
160  n_cell_v.push_back(n_cell);
161  is_per_v.push_back(is_per);
162  ref_rat_v.push_back(ref_rat);
163  prefix_v.push_back("erf1");
164  }
165 
166  // Parse data for erf2 constructor
167  {
168  ParmParse pp("erf2");
169  amrex::Vector<Real> lo = {0.,0.,0.};
170  amrex::Vector<Real> hi = {0.,0.,0.};
171  amrex::Vector<int> periodicity = {1,1,1};
172  pp.queryarr("prob_lo",lo);
173  pp.queryarr("prob_hi",hi);
174  rb.setLo(lo);
175  rb.setHi(hi);
176  pp.query("max_level",max_level);
177  pp.query("coord",coord);
178  pp.queryarr("n_cell",n_cell);
179  pp.queryarr("is_periodic",periodicity);
180  {
181  for( int i(0); i<AMREX_SPACEDIM; i++ ) is_per[i] = periodicity[i];
182  }
183  pp.queryarr("ref_ratio",ref_rat);
184 
185  rb_v.push_back(rb);
186  max_level_v.push_back(max_level);
187  coord_v.push_back(coord);
188  n_cell_v.push_back(n_cell);
189  is_per_v.push_back(is_per);
190  ref_rat_v.push_back(ref_rat);
191  prefix_v.push_back("erf2");
192 
193  }
194 
195  // Construct a MultiBlockContainer
196  MultiBlockContainer mbc(rb_v, max_level_v, n_cell_v,
197  coord_v, ref_rat_v, is_per_v,
198  prefix_v, max_step);
199 
200  // Initialize data
201  mbc.InitializeBlocks();
202 
203  // Advane blocks a timestep
204  mbc.AdvanceBlocks();
205  }
206 #else
207  {
208  // constructor - reads in parameters from inputs file
209  // - sizes multilevel arrays and data structures
210  ERF erf;
211 
212  // initialize AMR data
213  erf.InitData();
214 
215  // advance solution to final time
216  erf.Evolve();
217 
218  // wallclock time
219  Real end_total = amrex::second() - strt_total;
220 
221  // print wallclock time
222  ParallelDescriptor::ReduceRealMax(end_total ,ParallelDescriptor::IOProcessorNumber());
223  if (erf.Verbose()) {
224  amrex::Print() << "\nTotal Time: " << end_total << '\n';
225  }
226  }
227 #endif
228 
229  // destroy timer for profiling
230  BL_PROFILE_VAR_STOP(pmain);
231 
232  amrex::Finalize();
233 #ifdef AMREX_USE_MPI
234  MPI_Finalize();
235 #endif
236 }
Definition: ERF.H:87
void Evolve()
Definition: ERF.cpp:324
static void print_banner(MPI_Comm, std::ostream &)
Definition: console_io.cpp:60
void InitData()
Definition: ERF.cpp:535
static void print_error(MPI_Comm, const std::string &msg)
Definition: console_io.cpp:43
static void writeBuildInfo(std::ostream &os)
Definition: writeJobInfo.cpp:137
static void print_usage(MPI_Comm, std::ostream &)
Definition: console_io.cpp:26
Definition: MultiBlockContainer.H:8
void add_par()
Definition: main.cpp:24
std::string inputs_name
Definition: main.cpp:14
Here is the call graph for this function:

Variable Documentation

◆ inputs_name

std::string inputs_name

Referenced by main(), and ERF::writeJobInfo().