REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include <iostream>
2
3#include <AMReX.H>
4#include <AMReX_BLProfiler.H>
5#include <AMReX_ParallelDescriptor.H>
6
7#include <REMORA.H>
8
9std::string inputs_name = "";
10
11using namespace amrex;
12
13// Set the refine_grid_layout flags to (NGROW-1,NGROW-1,0) by default
14// since the REMORA default is different from the amrex default (NGROW-1,NGROW-1,NGROW-1)
15// Also set max_grid_size to very large since the only reason for
16// chopping grids is if Nprocs > Ngrids
17void add_par () {
18 ParmParse pp("amr");
19 ParmParse pp_remora("remora");
20
21 // Set the refine_grid_layout flags to (NGROW-1,NGROW-1,0) by default
22 pp.add("refine_grid_layout_x",1);
23 pp.add("refine_grid_layout_y",1);
24 pp.add("refine_grid_layout_z",0);
25
26 // n_proper is the minimum number of coarse cells between coarse-fine boundaries
27 // between levels (ell and ell+1) and levels (ell-1 and ell). We want this to be
28 // greater than or equal to the stencil width (a function of spatial order) divided by
29 // ref_ratio (which can be 2,3 or 4). This ensures that fillpatch at level (ell)
30 // does not need to reach beyond level (ell-1). Here to be conservative we set this to 2
31 // (rather than the amrex default of 1).
32 pp.add("n_proper",2);
33
34 int max_grid_size = 2048;
35 pp.queryAdd("max_grid_size",max_grid_size);
36
37 // This will set the default value of blocking_factor to be 1, but will allow
38 // the user to override it in the inputs file or on command line
39 int blocking_factor = 1;
40 pp.queryAdd("blocking_factor",blocking_factor);
41
42 // Default error buf of 0, user can override. Note that the whole column will be tagged
43 // if any one cell is tagged, even if n_error_buf_z = 0
44 int n_error_buf = 0;
45 pp.queryAdd("n_error_buf",n_error_buf);
46
47 // Inject variables into ParmParse database with the prefixes AMReX expects
48 // This allows a REMORA user to use the remora. prefix for some AMReX-specific options
49 amrex::Vector<int> n_cell;
50 pp_remora.queryarr("n_cell",n_cell);
51 pp.queryAdd("n_cell",n_cell);
52
53 int max_level = 0;
54 // Default max_level to 0 if not in file
55 if (!pp.query("max_level",max_level)) {
56 pp.queryAdd("max_level",max_level);
57 }
58
59 // If amr.v is not specified, set it equal to remora.v
60 int amr_verbosity = 0;
61 bool defined_amr_verbosity = pp.query("v",amr_verbosity);
62 if (!defined_amr_verbosity) {
63 int rem_verbosity = 0;
64 pp_remora.query("v",rem_verbosity);
65 pp.queryAdd("v",rem_verbosity);
66 }
67
68 ParmParse pp_geometry("geometry");
69 amrex::Vector<amrex::Real> prob_lo;
70 amrex::Vector<amrex::Real> prob_hi;
71 amrex::Vector<int> is_periodic;
72 pp_remora.queryarr("prob_lo",prob_lo);
73 pp_remora.queryarr("prob_hi",prob_hi);
74 pp_remora.queryarr("is_periodic",is_periodic);
75 pp_geometry.queryAdd("prob_lo",prob_lo);
76 pp_geometry.queryAdd("prob_hi",prob_hi);
77 pp_geometry.queryAdd("is_periodic",is_periodic);
78
79 ParmParse pp_fabarray("fabarray");
80#if defined(REMORA_USE_GPU)
81 amrex::Vector<int> omp_tile_size = {1024000,1024000,1024000};
82#else
83 amrex::Vector<int> omp_tile_size = {8, 8, 1024000};
84#endif
85 pp_remora.queryarr("omp_tile_size",omp_tile_size,0,3);
86 pp_fabarray.queryAdd("mfiter_tile_size",omp_tile_size);
87}
88
89int main(int argc, char* argv[])
90{
91{
92#ifdef AMREX_USE_MPI
93 MPI_Init(&argc, &argv);
94#endif
95
96 if (argc < 2) {
97 // Print usage and exit with error code if no input file was provided.
98 REMORA::print_usage(MPI_COMM_WORLD, std::cout);
100 MPI_COMM_WORLD, "No input file provided. Exiting!!");
101 return 1;
102 }
103
104 // Look for "-h" or "--help" flag and print usage
105 for (auto i = 1; i < argc; i++) {
106 const std::string param(argv[i]);
107 if ((param == "--help") || (param == "-h") || (param == "--usage")) {
108 REMORA::print_banner(MPI_COMM_WORLD, std::cout);
109 REMORA::print_usage(MPI_COMM_WORLD, std::cout);
110 return 0;
111 }
112 }
113
114 if (!amrex::FileSystem::Exists(std::string(argv[1]))) {
115 // Print usage and exit with error code if we cannot find the input file
116 REMORA::print_usage(MPI_COMM_WORLD, std::cout);
118 MPI_COMM_WORLD, "Input file does not exist = " +
119 std::string(argv[1]) + ". Exiting!!");
120 return 1;
121 }
122
123 // print_banner(MPI_COMM_WORLD, std::cout);
124 // Check to see if the command line contains --describe
125 if (argc >= 2) {
126 for (auto i = 1; i < argc; i++) {
127 if (std::string(argv[i]) == "--describe") {
128 REMORA::writeBuildInfo(std::cout);
129 return 0;
130 }
131 }
132 } else if(argc < 2) {
133 amrex::Print() << "REMORA is currently under development as a next-generation version of the Regional Ocean Modeling System (ROMS). See Docs for more information.\n"
134 <<" usage:\n"
135 <<" ./REMORA3d.xxx.yyy.ex inputs" <<std::endl;
136// std::cerr << "inputs should follow executable on command line" << std::endl;
137 return -1;
138 }
139
140 amrex::Initialize(argc,argv,true,MPI_COMM_WORLD,add_par);
141
142 // Save the inputs file name for later.
143 if (!strchr(argv[1], '=')) {
144 inputs_name = argv[1];
145 }
146
147 // timer for profiling
148 BL_PROFILE_VAR("main()", pmain);
149
150 // wallclock time
151 const Real strt_total = Real(amrex::second());
152
153 {
154 BL_PROFILE_VAR("REMORA::InitData()", pinit);
155 // constructor - reads in parameters from inputs file
156 // - sizes multilevel arrays and data structures
157 REMORA remora;
158
159 // initialize AMR data
160 remora.InitData();
161
162 BL_PROFILE_VAR_STOP(pinit);
163
164 // advance solution to final time
165 remora.Evolve();
166
167 // wallclock time
168 Real end_total = Real(amrex::second()) - strt_total;
169
170 // print wallclock time
171 ParallelDescriptor::ReduceRealMax(end_total ,ParallelDescriptor::IOProcessorNumber());
172 if (remora.Verbose()) {
173 amrex::Print() << "\nTotal Time: " << end_total << '\n';
174 }
175 }
176
177 // destroy timer for profiling
178 BL_PROFILE_VAR_STOP(pmain);
179 amrex::Finalize();
180#ifdef AMREX_USE_MPI
181 MPI_Finalize();
182#endif
183}
184}
Class that stores all relevant simulation state data with methods for time stepping.
Definition REMORA.H:91
static void print_error(MPI_Comm, const std::string &msg)
void Evolve()
Advance solution to final time.
Definition REMORA.cpp:259
static void writeBuildInfo(std::ostream &os)
Write build info to os.
void InitData()
Initialize multilevel data.
Definition REMORA.cpp:388
static void print_usage(MPI_Comm, std::ostream &)
static void print_banner(MPI_Comm, std::ostream &)
int main(int argc, char *argv[])
Definition main.cpp:89
void add_par()
Definition main.cpp:17
std::string inputs_name
Definition main.cpp:9