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
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 // The NetCDF writer puts omega and z_velocity on the s_w points ROMS writes them at,
103 // the latter under the ROMS name w; AMReX plotfiles average both to cell centers
106
107 // Check to see if we found all the requested variables
108 for (auto plot_name : plot_var_names_3d) {
109 if (plot_name == "fennel" && expand_fennel) {
110 continue;
111 }
112 if (!containerHasElement(tmp_plot_names, plot_name) && ParallelDescriptor::IOProcessor()) {
113 Warning("\nWARNING: Requested to plot variable '" + plot_name + "' in 3D list but it is not available");
114 }
115 }
117}
118
119/**
120 * @param pp_plot_var_names_2d list of variable names to plot read in from parameter file
121 */
122void
124{
126
127 if (pp.contains(pp_plot_var_names_2d.c_str()))
128 {
129 std::string nm;
130
131 int nPltVars = pp.countval(pp_plot_var_names_2d.c_str());
132
133 for (int i = 0; i < nPltVars; i++)
134 {
135 pp.get(pp_plot_var_names_2d.c_str(), nm, i);
136
137 // Add the named variable to our list of plot variables
138 // if it is not already in the list
140 plot_var_names_2d.push_back(nm);
141 }
142 }
143 } else {
144 //
145 // The default is to add none of the variables to the list
146 //
147 plot_var_names_2d.clear();
148 }
149
150 // If horizontal mixing is scaled_to_grid, automatically output the spatially
151 // varying coefficients used by the run as 2D fields.
153 if (!containerHasElement(plot_var_names_2d, "visc2")) {
154 plot_var_names_2d.push_back("visc2");
155 }
156 for (int n = 0; n < ncons; ++n) {
157 const std::string nm = std::string("diff2_") + cons_names[n];
159 plot_var_names_2d.push_back(nm);
160 }
161 }
162 }
163
164 Vector<std::string> tmp_plot_names;
165
166 if (containerHasElement(plot_var_names_2d, "zeta")) tmp_plot_names.push_back("zeta");
167 if (containerHasElement(plot_var_names_2d, "h")) tmp_plot_names.push_back("h");
168 if (containerHasElement(plot_var_names_2d, "f")) tmp_plot_names.push_back("f");
169 if (containerHasElement(plot_var_names_2d, "ubar")) tmp_plot_names.push_back("ubar");
170 if (containerHasElement(plot_var_names_2d, "vbar")) tmp_plot_names.push_back("vbar");
171 if (containerHasElement(plot_var_names_2d, "sustr")) tmp_plot_names.push_back("sustr");
172 if (containerHasElement(plot_var_names_2d, "bustr")) tmp_plot_names.push_back("bustr");
173 if (containerHasElement(plot_var_names_2d, "svstr")) tmp_plot_names.push_back("svstr");
174 if (containerHasElement(plot_var_names_2d, "bvstr")) tmp_plot_names.push_back("bvstr");
175
176 for (int i = 0; i < derived_names_2d.size(); ++i) {
179 } // if
180 } // i
181
182 // Horizontal mixing coefficients (2D rho points)
184 tmp_plot_names.push_back("visc2");
185 }
186 for (int n = 0; n < ncons; ++n) {
187 const std::string nm = std::string("diff2_") + cons_names[n];
189 tmp_plot_names.push_back(nm);
190 }
191 }
192 for (int n = 0; n < ncons; ++n) {
193 const std::string nm = std::string("stflux_") + cons_names[n];
195 tmp_plot_names.push_back(nm);
196 }
197 }
198
199 if (containerHasElement(plot_var_names_2d, "lrflux")) tmp_plot_names.push_back("lrflux");
200 if (containerHasElement(plot_var_names_2d, "lhflux")) tmp_plot_names.push_back("lhflux");
201 if (containerHasElement(plot_var_names_2d, "srflux")) tmp_plot_names.push_back("srflux");
202 if (containerHasElement(plot_var_names_2d, "shflux")) tmp_plot_names.push_back("shflux");
203
204 if (containerHasElement(plot_var_names_2d, "mask_rho")) tmp_plot_names.push_back("mask_rho");
205 if (containerHasElement(plot_var_names_2d, "mask_u")) tmp_plot_names.push_back("mask_u");
206 if (containerHasElement(plot_var_names_2d, "mask_v")) tmp_plot_names.push_back("mask_v");
207
208 // Check to see if we found all the requested variables
209 for (auto plot_name : plot_var_names_2d) {
210 if (!containerHasElement(tmp_plot_names, plot_name) && ParallelDescriptor::IOProcessor()) {
211 Warning("\nWARNING: Requested to plot variable '" + plot_name + "' in 2D list but it is not available");
212 }
213 }
215}
216
217/**
218 * @param pp_plot_var_names variables to add to plot list
219 */
220void
222{
224
225 if (pp.contains("plot_vars")) {
226 amrex::Abort("You must use plot_vars_3d rather than plot_vars");
227 }
228
229 // This runs after the particle containers are set up, so the only thing it may add is
230 // a particle mesh variable, which set3DPlotVariables could not know about yet. Adding
231 // anything else back would resurrect a name set3DPlotVariables deliberately dropped as
232 // unavailable, and nothing downstream would ever fill it: the plotfile would carry the
233 // uninitialized sentinel from WritePlotFile under a real-looking variable name. The
234 // "fennel" keyword needs no handling here, since set3DPlotVariables already expanded it.
235#ifdef REMORA_USE_PARTICLES
236 Vector<std::string> particle_mesh_plot_names;
238
239 if (pp.contains(pp_plot_var_names_3d.c_str())) {
240 std::string nm;
241 int nPltVars = pp.countval(pp_plot_var_names_3d.c_str());
242 for (int i = 0; i < nPltVars; i++) {
243 pp.get(pp_plot_var_names_3d.c_str(), nm, i);
246 plot_var_names_3d.push_back(nm);
247 }
248 }
249 }
250#else
251 amrex::ignore_unused(pp_plot_var_names_3d);
252#endif
253}
254
255/**
256 * @param pp_plot_var_names_2d variables to add to plot list
257 */
258void
260{
261 // Same rule as append3DPlotVariables: only a particle mesh variable may be added back.
262#ifdef REMORA_USE_PARTICLES
264
265 Vector<std::string> particle_mesh_plot_names;
267
268 if (pp.contains(pp_plot_var_names_2d.c_str())) {
269 std::string nm;
270 int nPltVars = pp.countval(pp_plot_var_names_2d.c_str());
271 for (int i = 0; i < nPltVars; i++) {
272 pp.get(pp_plot_var_names_2d.c_str(), nm, i);
275 plot_var_names_2d.push_back(nm);
276 }
277 }
278 }
279#else
280 amrex::ignore_unused(pp_plot_var_names_2d);
281#endif
282}
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)
ParticlesNamesList & getNamesUnalloc()
void GetMeshPlotVarNames(amrex::Vector< std::string > &a_names) const
int ncons
Number of conserved scalars in the state (temperature + salt + passive scalars + biology tracers)
Definition REMORA.H:1839
amrex::Vector< std::string > cons_names
Names of scalars for plotfile output.
Definition REMORA.H:2009
void set2DPlotVariables(const std::string &pp_plot_var_names_2d)
REMORABiology::BiologyModel biology_model
Active biology package.
Definition REMORA.H:1841
bool plot_omega
Whether to write omega, the S-coordinate vertical velocity, to NetCDF output.
Definition REMORA.H:2005
bool plot_wvel
Whether to write z_velocity, the true vertical velocity, to NetCDF output as w.
Definition REMORA.H:2007
const amrex::Vector< std::string > derived_names_3d
Names of derived fields for 3d plotfile fields.
Definition REMORA.H:2012
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:1836
void set3DPlotVariables(const std::string &pp_plot_var_names_3d)
std::string pp_prefix
default prefix for input file parameters
Definition REMORA.H:381
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:2017
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:2001
ParticleData particleData
Particle container with all particle species.
Definition REMORA.H:2030
amrex::Vector< std::string > plot_var_names_2d
Names of 2D variables to output to AMReX plotfile.
Definition REMORA.H:2003
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:2014
bool has_biology(BiologyModel model) noexcept
HorizMixingType horiz_mixing_type