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 + "' 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 // Get state variables in the same order as we define them,
132 // since they may be in any order in the input list
133 Vector<std::string> tmp_plot_names;
134
135 for (int i = 0; i < NCONS; ++i) {
137 tmp_plot_names.push_back(cons_names[i]);
138 }
139 }
140 // Check for velocity since it's not in cons_names
141 // If we are asked for any velocity component, we will need them all
142 if (containerHasElement(plot_var_names_2d, "x_velocity") ||
143 containerHasElement(plot_var_names_2d, "y_velocity") ||
144 containerHasElement(plot_var_names_2d, "z_velocity")) {
145 tmp_plot_names.push_back("x_velocity");
146 tmp_plot_names.push_back("y_velocity");
147 tmp_plot_names.push_back("z_velocity");
148 }
149
150 // If we are asked for any location component, we will provide them all
154 tmp_plot_names.push_back("x_cc");
155 tmp_plot_names.push_back("y_cc");
156 tmp_plot_names.push_back("z_cc");
157 }
158
159 for (int i = 0; i < derived_names.size(); ++i) {
161 tmp_plot_names.push_back(derived_names[i]);
162 } // if
163 } // i
164
165#ifdef REMORA_USE_PARTICLES
166 const auto& particles_namelist( particleData.getNamesUnalloc() );
167 for (auto it = particles_namelist.cbegin(); it != particles_namelist.cend(); ++it) {
168 std::string tmp( (*it)+"_count" );
170 tmp_plot_names.push_back(tmp);
171 }
172 }
173#endif
174
175 // Check to see if we found all the requested variables
176 for (auto plot_name : plot_var_names_2d) {
177 if (!containerHasElement(tmp_plot_names, plot_name)) {
178 Warning("\nWARNING: Requested to plot variable '" + plot_name + "' but it is not available");
179 }
180 }
181 plot_var_names_2d = tmp_plot_names;
182}
183
184/**
185 * @param pp_plot_var_names variables to add to plot list
186 */
187void
188REMORA::append3DPlotVariables (const std::string& pp_plot_var_names_3d)
189{
190 ParmParse pp(pp_prefix);
191
192 if (pp.contains("plot_vars")) {
193 amrex::Abort("You must use plot_vars_3d rather than plot_vars");
194 }
195
196 if (pp.contains(pp_plot_var_names_3d.c_str())) {
197 std::string nm;
198 int nPltVars = pp.countval(pp_plot_var_names_3d.c_str());
199 for (int i = 0; i < nPltVars; i++) {
200 pp.get(pp_plot_var_names_3d.c_str(), nm, i);
201 // Add the named variable to our list of plot variables
202 // if it is not already in the list
204 plot_var_names_3d.push_back(nm);
205 }
206 }
207 }
208
209 Vector<std::string> tmp_plot_names(0);
210#ifdef REMORA_USE_PARTICLES
211 Vector<std::string> particle_mesh_plot_names;
212 particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
213 for (int i = 0; i < particle_mesh_plot_names.size(); i++) {
214 std::string tmp(particle_mesh_plot_names[i]);
216 tmp_plot_names.push_back(tmp);
217 }
218 }
219#endif
220
221 for (int i = 0; i < tmp_plot_names.size(); i++) {
222 plot_var_names_3d.push_back( tmp_plot_names[i] );
223 }
224}
225
226/**
227 * @param pp_plot_var_names_2d variables to add to plot list
228 */
229void
230REMORA::append2DPlotVariables (const std::string& pp_plot_var_names_2d)
231{
232 ParmParse pp(pp_prefix);
233
234 if (pp.contains(pp_plot_var_names_2d.c_str())) {
235 std::string nm;
236 int nPltVars = pp.countval(pp_plot_var_names_2d.c_str());
237 for (int i = 0; i < nPltVars; i++) {
238 pp.get(pp_plot_var_names_2d.c_str(), nm, i);
239 // Add the named variable to our list of plot variables
240 // if it is not already in the list
242 plot_var_names_2d.push_back(nm);
243 }
244 }
245 }
246
247 Vector<std::string> tmp_plot_names(0);
248#ifdef REMORA_USE_PARTICLES
249 Vector<std::string> particle_mesh_plot_names;
250 particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
251 for (int i = 0; i < particle_mesh_plot_names.size(); i++) {
252 std::string tmp(particle_mesh_plot_names[i]);
254 tmp_plot_names.push_back(tmp);
255 }
256 }
257#endif
258
259 for (int i = 0; i < tmp_plot_names.size(); i++) {
260 plot_var_names_2d.push_back( tmp_plot_names[i] );
261 }
262}
#define NCONS
bool containerHasElement(const V &iterable, const T &query)
bool containerHasElement(const V &iterable, const T &query)
const amrex::Vector< std::string > cons_names
Names of scalars for plotfile output.
Definition REMORA.H:1293
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:229
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:1289
amrex::Vector< std::string > plot_var_names_2d
Names of 2D variables to output to AMReX plotfile.
Definition REMORA.H:1291
const amrex::Vector< std::string > derived_names
Names of derived fields for plotfiles.
Definition REMORA.H:1296
void append2DPlotVariables(const std::string &pp_plot_var_names_2d)