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 pp.add("n_error_buf",0);
43
44 // Inject variables into ParmParse database with the prefixes AMReX expects
45 // This allows a REMORA user to use the remora. prefix for some AMReX-specific options
46 amrex::Vector<int> n_cell;
47 pp_remora.queryarr("n_cell",n_cell);
48 pp.queryAdd("n_cell",n_cell);
49
50 int max_level = 0;
51 // Default max_level to 0 if not in file
52 if (!pp.query("max_level",max_level)) {
53 pp.queryAdd("max_level",max_level);
54 }
55
56 // If amr.v is not specified, set it equal to remora.v
57 int amr_verbosity = 0;
58 bool defined_amr_verbosity = pp.query("v",amr_verbosity);
59 if (!defined_amr_verbosity) {
60 int rem_verbosity = 0;
61 pp_remora.query("v",rem_verbosity);
62 pp.queryAdd("v",rem_verbosity);
63 }
64
65 ParmParse pp_geometry("geometry");
66 amrex::Vector<amrex::Real> prob_lo;
67 amrex::Vector<amrex::Real> prob_hi;
68 amrex::Vector<int> is_periodic;
69 pp_remora.queryarr("prob_lo",prob_lo);
70 pp_remora.queryarr("prob_hi",prob_hi);
71 pp_remora.queryarr("is_periodic",is_periodic);
72 pp_geometry.queryAdd("prob_lo",prob_lo);
73 pp_geometry.queryAdd("prob_hi",prob_hi);
74 pp_geometry.queryAdd("is_periodic",is_periodic);
75
76 ParmParse pp_fabarray("fabarray");
77#if defined(REMORA_USE_GPU)
78 amrex::Vector<int> omp_tile_size = {1024000,1024000,1024000};
79#else
80 amrex::Vector<int> omp_tile_size = {8, 8, 1024000};
81#endif
82 pp_remora.queryarr("omp_tile_size",omp_tile_size,0,3);
83 pp_fabarray.queryAdd("mfiter_tile_size",omp_tile_size);
84}
85
86int main(int argc, char* argv[])
87{
88{
89#ifdef AMREX_USE_MPI
90 MPI_Init(&argc, &argv);
91#endif
92
93 if (argc < 2) {
94 // Print usage and exit with error code if no input file was provided.
95 REMORA::print_usage(MPI_COMM_WORLD, std::cout);
97 MPI_COMM_WORLD, "No input file provided. Exiting!!");
98 return 1;
99 }
100
101 // Look for "-h" or "--help" flag and print usage
102 for (auto i = 1; i < argc; i++) {
103 const std::string param(argv[i]);
104 if ((param == "--help") || (param == "-h") || (param == "--usage")) {
105 REMORA::print_banner(MPI_COMM_WORLD, std::cout);
106 REMORA::print_usage(MPI_COMM_WORLD, std::cout);
107 return 0;
108 }
109 }
110
111 if (!amrex::FileSystem::Exists(std::string(argv[1]))) {
112 // Print usage and exit with error code if we cannot find the input file
113 REMORA::print_usage(MPI_COMM_WORLD, std::cout);
115 MPI_COMM_WORLD, "Input file does not exist = " +
116 std::string(argv[1]) + ". Exiting!!");
117 return 1;
118 }
119
120 // print_banner(MPI_COMM_WORLD, std::cout);
121 // Check to see if the command line contains --describe
122 if (argc >= 2) {
123 for (auto i = 1; i < argc; i++) {
124 if (std::string(argv[i]) == "--describe") {
125 REMORA::writeBuildInfo(std::cout);
126 return 0;
127 }
128 }
129 } else if(argc < 2) {
130 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"
131 <<" usage:\n"
132 <<" ./REMORA3d.xxx.yyy.ex inputs" <<std::endl;
133// std::cerr << "inputs should follow executable on command line" << std::endl;
134 return -1;
135 }
136
137 amrex::Initialize(argc,argv,true,MPI_COMM_WORLD,add_par);
138
139 // Save the inputs file name for later.
140 if (!strchr(argv[1], '=')) {
141 inputs_name = argv[1];
142 }
143
144 // timer for profiling
145 BL_PROFILE_VAR("main()", pmain);
146
147 // wallclock time
148 const Real strt_total = Real(amrex::second());
149
150 {
151 BL_PROFILE_VAR("REMORA::InitData()", pinit);
152 // constructor - reads in parameters from inputs file
153 // - sizes multilevel arrays and data structures
154 REMORA remora;
155
156 // initialize AMR data
157 remora.InitData();
158
159 BL_PROFILE_VAR_STOP(pinit);
160
161 // advance solution to final time
162 remora.Evolve();
163
164 // wallclock time
165 Real end_total = Real(amrex::second()) - strt_total;
166
167 // print wallclock time
168 ParallelDescriptor::ReduceRealMax(end_total ,ParallelDescriptor::IOProcessorNumber());
169 if (remora.Verbose()) {
170 amrex::Print() << "\nTotal Time: " << end_total << '\n';
171 }
172 }
173
174 // destroy timer for profiling
175 BL_PROFILE_VAR_STOP(pmain);
176 amrex::Finalize();
177#ifdef AMREX_USE_MPI
178 MPI_Finalize();
179#endif
180}
181}
Class that stores all relevant simulation state data with methods for time stepping.
Definition REMORA.H:88
static void print_error(MPI_Comm, const std::string &msg)
void Evolve()
Advance solution to final time.
Definition REMORA.cpp:140
static void writeBuildInfo(std::ostream &os)
Write build info to os.
void InitData()
Initialize multilevel data.
Definition REMORA.cpp:258
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:86
void add_par()
Definition main.cpp:17
std::string inputs_name
Definition main.cpp:9