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
16REMORA::set3DPlotVariables (const std::string& pp_plot_var_names_3d)
17{
18 ParmParse pp(pp_prefix);
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 // Get state variables in the same order as we define them,
48 // since they may be in any order in the input list
49 Vector<std::string> tmp_plot_names;
50
51 for (int i = 0; i < ncons; ++i) {
53 tmp_plot_names.push_back(cons_names[i]);
54 }
55 }
56 // Check for velocity since it's not in cons_names
57 // If we are asked for any velocity component, we will need them all
58 if (containerHasElement(plot_var_names_3d, "x_velocity") ||
61 tmp_plot_names.push_back("x_velocity");
62 tmp_plot_names.push_back("y_velocity");
63 tmp_plot_names.push_back("z_velocity");
64 }
65
66 // If we are asked for any location component, we will provide them all
70 tmp_plot_names.push_back("x_cc");
71 tmp_plot_names.push_back("y_cc");
72 tmp_plot_names.push_back("z_cc");
73 }
74
75 for (int i = 0; i < derived_names.size(); ++i) {
77 tmp_plot_names.push_back(derived_names[i]);
78 } // if
79 } // i
80
81#ifdef REMORA_USE_PARTICLES
82 const auto& particles_namelist( particleData.getNamesUnalloc() );
83 for (auto it = particles_namelist.cbegin(); it != particles_namelist.cend(); ++it) {
84 std::string tmp( (*it)+"_count" );
86 tmp_plot_names.push_back(tmp);
87 }
88 }
89#endif
90
91 // Check to see if we found all the requested variables
92 for (auto plot_name : plot_var_names_3d) {
93 if (!containerHasElement(tmp_plot_names, plot_name)) {
94 Warning("\nWARNING: Requested to plot variable '" + plot_name + "' in 3D list but it is not available");
95 }
96 }
97 plot_var_names_3d = tmp_plot_names;
98}
99
100/**
101 * @param pp_plot_var_names_2d list of variable names to plot read in from parameter file
102 */
103void
104REMORA::set2DPlotVariables (const std::string& pp_plot_var_names_2d)
105{
106 ParmParse pp(pp_prefix);
107
108 if (pp.contains(pp_plot_var_names_2d.c_str()))
109 {
110 std::string nm;
111
112 int nPltVars = pp.countval(pp_plot_var_names_2d.c_str());
113
114 for (int i = 0; i < nPltVars; i++)
115 {
116 pp.get(pp_plot_var_names_2d.c_str(), nm, i);
117
118 // Add the named variable to our list of plot variables
119 // if it is not already in the list
121 plot_var_names_2d.push_back(nm);
122 }
123 }
124 } else {
125 //
126 // The default is to add none of the variables to the list
127 //
128 plot_var_names_2d.clear();
129 }
130
131 // If horizontal mixing is scaled_to_grid, automatically output the spatially
132 // varying coefficients used by the run as 2D fields.
134 if (!containerHasElement(plot_var_names_2d, "visc2")) {
135 plot_var_names_2d.push_back("visc2");
136 }
137 for (int n = 0; n < ncons; ++n) {
138 const std::string nm = std::string("diff2_") + cons_names[n];
140 plot_var_names_2d.push_back(nm);
141 }
142 }
143 }
144
145 Vector<std::string> tmp_plot_names;
146
147 if (containerHasElement(plot_var_names_2d, "zeta")) tmp_plot_names.push_back("zeta");
148 if (containerHasElement(plot_var_names_2d, "h")) tmp_plot_names.push_back("h");
149 if (containerHasElement(plot_var_names_2d, "f")) tmp_plot_names.push_back("f");
150 if (containerHasElement(plot_var_names_2d, "ubar")) tmp_plot_names.push_back("ubar");
151 if (containerHasElement(plot_var_names_2d, "vbar")) tmp_plot_names.push_back("vbar");
152 if (containerHasElement(plot_var_names_2d, "sustr")) tmp_plot_names.push_back("sustr");
153 if (containerHasElement(plot_var_names_2d, "bustr")) tmp_plot_names.push_back("bustr");
154 if (containerHasElement(plot_var_names_2d, "svstr")) tmp_plot_names.push_back("svstr");
155 if (containerHasElement(plot_var_names_2d, "bvstr")) tmp_plot_names.push_back("bvstr");
156
157 for (int i = 0; i < derived_names.size(); ++i) {
159 tmp_plot_names.push_back(derived_names[i]);
160 } // if
161 } // i
162
163 // Horizontal mixing coefficients (2D rho points)
165 tmp_plot_names.push_back("visc2");
166 }
167 for (int n = 0; n < ncons; ++n) {
168 const std::string nm = std::string("diff2_") + cons_names[n];
170 tmp_plot_names.push_back(nm);
171 }
172 }
173
174 // Check to see if we found all the requested variables
175 for (auto plot_name : plot_var_names_2d) {
176 if (!containerHasElement(tmp_plot_names, plot_name)) {
177 Warning("\nWARNING: Requested to plot variable '" + plot_name + "' in 2D list but it is not available");
178 }
179 }
180 plot_var_names_2d = tmp_plot_names;
181}
182
183/**
184 * @param pp_plot_var_names variables to add to plot list
185 */
186void
187REMORA::append3DPlotVariables (const std::string& pp_plot_var_names_3d)
188{
189 ParmParse pp(pp_prefix);
190
191 if (pp.contains("plot_vars")) {
192 amrex::Abort("You must use plot_vars_3d rather than plot_vars");
193 }
194
195 if (pp.contains(pp_plot_var_names_3d.c_str())) {
196 std::string nm;
197 int nPltVars = pp.countval(pp_plot_var_names_3d.c_str());
198 for (int i = 0; i < nPltVars; i++) {
199 pp.get(pp_plot_var_names_3d.c_str(), nm, i);
200 // Add the named variable to our list of plot variables
201 // if it is not already in the list
203 plot_var_names_3d.push_back(nm);
204 }
205 }
206 }
207
208 Vector<std::string> tmp_plot_names(0);
209#ifdef REMORA_USE_PARTICLES
210 Vector<std::string> particle_mesh_plot_names;
211 particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
212 for (int i = 0; i < particle_mesh_plot_names.size(); i++) {
213 std::string tmp(particle_mesh_plot_names[i]);
215 tmp_plot_names.push_back(tmp);
216 }
217 }
218#endif
219
220 for (int i = 0; i < tmp_plot_names.size(); i++) {
221 plot_var_names_3d.push_back( tmp_plot_names[i] );
222 }
223}
224
225/**
226 * @param pp_plot_var_names_2d variables to add to plot list
227 */
228void
229REMORA::append2DPlotVariables (const std::string& pp_plot_var_names_2d)
230{
231 ParmParse pp(pp_prefix);
232
233 if (pp.contains(pp_plot_var_names_2d.c_str())) {
234 std::string nm;
235 int nPltVars = pp.countval(pp_plot_var_names_2d.c_str());
236 for (int i = 0; i < nPltVars; i++) {
237 pp.get(pp_plot_var_names_2d.c_str(), nm, i);
238 // Add the named variable to our list of plot variables
239 // if it is not already in the list
241 plot_var_names_2d.push_back(nm);
242 }
243 }
244 }
245
246 Vector<std::string> tmp_plot_names(0);
247#ifdef REMORA_USE_PARTICLES
248 Vector<std::string> particle_mesh_plot_names;
249 particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
250 for (int i = 0; i < particle_mesh_plot_names.size(); i++) {
251 std::string tmp(particle_mesh_plot_names[i]);
253 tmp_plot_names.push_back(tmp);
254 }
255 }
256#endif
257
258 for (int i = 0; i < tmp_plot_names.size(); i++) {
259 plot_var_names_2d.push_back( tmp_plot_names[i] );
260 }
261}
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)
Definition REMORA.H:1346
amrex::Vector< std::string > cons_names
Names of scalars for plotfile output.
Definition REMORA.H:1397
void set2DPlotVariables(const std::string &pp_plot_var_names_2d)
void set3DPlotVariables(const std::string &pp_plot_var_names_3d)
std::string pp_prefix
default prefix for input file parameters
Definition REMORA.H:230
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:1403
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:1393
amrex::Vector< std::string > plot_var_names_2d
Names of 2D variables to output to AMReX plotfile.
Definition REMORA.H:1395
const amrex::Vector< std::string > derived_names
Names of derived fields for plotfiles.
Definition REMORA.H:1400
void append2DPlotVariables(const std::string &pp_plot_var_names_2d)
HorizMixingType horiz_mixing_type