REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_SetPlotVars.cpp
Go to the documentation of this file.
1#include <REMORA.H>
2#include "AMReX_Interp_3D_C.H"
3#include "AMReX_PlotFileUtil.H"
4
5using namespace amrex;
6
7template<typename V, typename T>
8bool containerHasElement(const V& iterable, const T& query) {
9 return std::find(iterable.begin(), iterable.end(), query) != iterable.end();
10}
11
12/**
13 * @param pp_plot_var_names_3d list of variable names to plot read in from parameter file
14 */
15void
17{
19
20 if (pp.contains("plot_vars")) {
21 amrex::Abort("You must use plot_vars_3d rather than plot_vars");
22 }
23
24 if (pp.contains(pp_plot_var_names_3d.c_str()))
25 {
26 std::string nm;
27
28 int nPltVars = pp.countval(pp_plot_var_names_3d.c_str());
29
30 for (int i = 0; i < nPltVars; i++)
31 {
32 pp.get(pp_plot_var_names_3d.c_str(), nm, i);
33
34 // Add the named variable to our list of plot variables
35 // if it is not already in the list
37 plot_var_names_3d.push_back(nm);
38 }
39 }
40 } else {
41 //
42 // The default is to add none of the variables to the list
43 //
44 plot_var_names_3d.clear();
45 }
46
47 const bool expand_fennel = containerHasElement(plot_var_names_3d, "fennel") &&
49 if (expand_fennel) {
50 // "fennel" means the biology tracers only, not any passive scalars ahead of them
51 for (int icomp = Bio_comp; icomp < ncons; ++icomp) {
54 }
55 }
56 }
57
58 // Get state variables in the same order as we define them,
59 // since they may be in any order in the input list
60 Vector<std::string> tmp_plot_names;
61
62 for (int i = 0; i < ncons; ++i) {
64 tmp_plot_names.push_back(cons_names[i]);
65 }
66 }
67 // Check for velocity since it's not in cons_names
68 // If we are asked for any velocity component, we will need them all
69 if (containerHasElement(plot_var_names_3d, "x_velocity") ||
72 tmp_plot_names.push_back("x_velocity");
73 tmp_plot_names.push_back("y_velocity");
74 tmp_plot_names.push_back("z_velocity");
75 }
76
77 // If we are asked for any location component, we will provide them all
81 tmp_plot_names.push_back("x_cc");
82 tmp_plot_names.push_back("y_cc");
83 tmp_plot_names.push_back("z_cc");
84 }
85
86 for (int i = 0; i < derived_names_3d.size(); ++i) {
89 } // if
90 } // i
91
92#ifdef REMORA_USE_PARTICLES
93 const auto& particles_namelist( particleData.getNamesUnalloc() );
94 for (auto it = particles_namelist.cbegin(); it != particles_namelist.cend(); ++it) {
95 std::string tmp( (*it)+"_count" );
97 tmp_plot_names.push_back(tmp);
98 }
99 }
100#endif
101
102 // Check to see if we found all the requested variables
103 for (auto plot_name : plot_var_names_3d) {
104 if (plot_name == "fennel" && expand_fennel) {
105 continue;
106 }
107 if (!containerHasElement(tmp_plot_names, plot_name) && ParallelDescriptor::IOProcessor()) {
108 Warning("\nWARNING: Requested to plot variable '" + plot_name + "' in 3D list but it is not available");
109 }
110 }
112}
113
114/**
115 * @param pp_plot_var_names_2d list of variable names to plot read in from parameter file
116 */
117void
119{
121
122 if (pp.contains(pp_plot_var_names_2d.c_str()))
123 {
124 std::string nm;
125
126 int nPltVars = pp.countval(pp_plot_var_names_2d.c_str());
127
128 for (int i = 0; i < nPltVars; i++)
129 {
130 pp.get(pp_plot_var_names_2d.c_str(), nm, i);
131
132 // Add the named variable to our list of plot variables
133 // if it is not already in the list
135 plot_var_names_2d.push_back(nm);
136 }
137 }
138 } else {
139 //
140 // The default is to add none of the variables to the list
141 //
142 plot_var_names_2d.clear();
143 }
144
145 // If horizontal mixing is scaled_to_grid, automatically output the spatially
146 // varying coefficients used by the run as 2D fields.
148 if (!containerHasElement(plot_var_names_2d, "visc2")) {
149 plot_var_names_2d.push_back("visc2");
150 }
151 for (int n = 0; n < ncons; ++n) {
152 const std::string nm = std::string("diff2_") + cons_names[n];
154 plot_var_names_2d.push_back(nm);
155 }
156 }
157 }
158
159 Vector<std::string> tmp_plot_names;
160
161 if (containerHasElement(plot_var_names_2d, "zeta")) tmp_plot_names.push_back("zeta");
162 if (containerHasElement(plot_var_names_2d, "h")) tmp_plot_names.push_back("h");
163 if (containerHasElement(plot_var_names_2d, "f")) tmp_plot_names.push_back("f");
164 if (containerHasElement(plot_var_names_2d, "ubar")) tmp_plot_names.push_back("ubar");
165 if (containerHasElement(plot_var_names_2d, "vbar")) tmp_plot_names.push_back("vbar");
166 if (containerHasElement(plot_var_names_2d, "sustr")) tmp_plot_names.push_back("sustr");
167 if (containerHasElement(plot_var_names_2d, "bustr")) tmp_plot_names.push_back("bustr");
168 if (containerHasElement(plot_var_names_2d, "svstr")) tmp_plot_names.push_back("svstr");
169 if (containerHasElement(plot_var_names_2d, "bvstr")) tmp_plot_names.push_back("bvstr");
170
171 for (int i = 0; i < derived_names_2d.size(); ++i) {
174 } // if
175 } // i
176
177 // Horizontal mixing coefficients (2D rho points)
179 tmp_plot_names.push_back("visc2");
180 }
181 for (int n = 0; n < ncons; ++n) {
182 const std::string nm = std::string("diff2_") + cons_names[n];
184 tmp_plot_names.push_back(nm);
185 }
186 }
187 for (int n = 0; n < ncons; ++n) {
188 const std::string nm = std::string("stflux_") + cons_names[n];
190 tmp_plot_names.push_back(nm);
191 }
192 }
193
194 if (containerHasElement(plot_var_names_2d, "lrflux")) tmp_plot_names.push_back("lrflux");
195 if (containerHasElement(plot_var_names_2d, "lhflux")) tmp_plot_names.push_back("lhflux");
196 if (containerHasElement(plot_var_names_2d, "srflux")) tmp_plot_names.push_back("srflux");
197 if (containerHasElement(plot_var_names_2d, "shflux")) tmp_plot_names.push_back("shflux");
198
199 if (containerHasElement(plot_var_names_2d, "mask_rho")) tmp_plot_names.push_back("mask_rho");
200 if (containerHasElement(plot_var_names_2d, "mask_u")) tmp_plot_names.push_back("mask_u");
201 if (containerHasElement(plot_var_names_2d, "mask_v")) tmp_plot_names.push_back("mask_v");
202
203 // Check to see if we found all the requested variables
204 for (auto plot_name : plot_var_names_2d) {
205 if (!containerHasElement(tmp_plot_names, plot_name) && ParallelDescriptor::IOProcessor()) {
206 Warning("\nWARNING: Requested to plot variable '" + plot_name + "' in 2D list but it is not available");
207 }
208 }
210}
211
212/**
213 * @param pp_plot_var_names variables to add to plot list
214 */
215void
217{
219
220 if (pp.contains("plot_vars")) {
221 amrex::Abort("You must use plot_vars_3d rather than plot_vars");
222 }
223
224 // This runs after the particle containers are set up, so the only thing it may add is
225 // a particle mesh variable, which set3DPlotVariables could not know about yet. Adding
226 // anything else back would resurrect a name set3DPlotVariables deliberately dropped as
227 // unavailable, and nothing downstream would ever fill it: the plotfile would carry the
228 // uninitialized sentinel from WritePlotFile under a real-looking variable name. The
229 // "fennel" keyword needs no handling here, since set3DPlotVariables already expanded it.
230#ifdef REMORA_USE_PARTICLES
231 Vector<std::string> particle_mesh_plot_names;
232 particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
233
234 if (pp.contains(pp_plot_var_names_3d.c_str())) {
235 std::string nm;
236 int nPltVars = pp.countval(pp_plot_var_names_3d.c_str());
237 for (int i = 0; i < nPltVars; i++) {
238 pp.get(pp_plot_var_names_3d.c_str(), nm, i);
241 plot_var_names_3d.push_back(nm);
242 }
243 }
244 }
245#else
246 amrex::ignore_unused(pp_plot_var_names_3d);
247#endif
248}
249
250/**
251 * @param pp_plot_var_names_2d variables to add to plot list
252 */
253void
255{
256 // Same rule as append3DPlotVariables: only a particle mesh variable may be added back.
257#ifdef REMORA_USE_PARTICLES
259
260 Vector<std::string> particle_mesh_plot_names;
261 particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
262
263 if (pp.contains(pp_plot_var_names_2d.c_str())) {
264 std::string nm;
265 int nPltVars = pp.countval(pp_plot_var_names_2d.c_str());
266 for (int i = 0; i < nPltVars; i++) {
267 pp.get(pp_plot_var_names_2d.c_str(), nm, i);
270 plot_var_names_2d.push_back(nm);
271 }
272 }
273 }
274#else
275 amrex::ignore_unused(pp_plot_var_names_2d);
276#endif
277}
mf_h setVal(geomdata.ProbHi(2))
pp_prob query("traditional", traditional)
bool containerHasElement(const V &iterable, const T &query)
bool containerHasElement(const V &iterable, const T &query)
int ncons
Number of conserved scalars in the state (temperature + salt + passive scalars + biology tracers)
Definition REMORA.H:1644
amrex::Vector< std::string > cons_names
Names of scalars for plotfile output.
Definition REMORA.H:1709
void set2DPlotVariables(const std::string &pp_plot_var_names_2d)
REMORABiology::BiologyModel biology_model
Active biology package.
Definition REMORA.H:1646
const amrex::Vector< std::string > derived_names_3d
Names of derived fields for 3d plotfile fields.
Definition REMORA.H:1712
int Bio_comp
First cons component of the biology block, i.e. Tracer_comp + nscalar. The state is laid out as temp,...
Definition REMORA.H:1641
void set3DPlotVariables(const std::string &pp_plot_var_names_3d)
std::string pp_prefix
default prefix for input file parameters
Definition REMORA.H:374
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:1717
void append3DPlotVariables(const std::string &pp_plot_var_names_3d)
amrex::Vector< std::string > plot_var_names_3d
Names of 3D variables to output to AMReX plotfile.
Definition REMORA.H:1705
amrex::Vector< std::string > plot_var_names_2d
Names of 2D variables to output to AMReX plotfile.
Definition REMORA.H:1707
void append2DPlotVariables(const std::string &pp_plot_var_names_2d)
const amrex::Vector< std::string > derived_names_2d
Names of derived fields for 2d plotfile fields.
Definition REMORA.H:1714
bool has_biology(BiologyModel model) noexcept
HorizMixingType horiz_mixing_type