ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ERF_AdvStruct.H
Go to the documentation of this file.
1 #ifndef ERF_ADV_STRUCT_H_
2 #define ERF_ADV_STRUCT_H_
3 
4 #include <string>
5 #include <iostream>
6 
7 #include <AMReX_ParmParse.H>
8 #include <AMReX_Print.H>
9 #include <AMReX_Gpu.H>
10 #include <AMReX_Geometry.H>
11 
12 #include <ERF_Constants.H>
13 #include <ERF_IndexDefines.H>
14 
15 /**
16  * Container holding the advection-related choices
17  */
18 
19 struct AdvChoice {
20  public:
21  void init_params(std::string pp_prefix)
22  {
23  amrex::ParmParse pp(pp_prefix);
24 
25  // Order and type of spatial discretizations used in advection
26  pp.query("use_efficient_advection", use_efficient_advection);
27  std::string dycore_horiz_adv_string = "" ; std::string dycore_vert_adv_string = "";
28  std::string dryscal_horiz_adv_string = "" ; std::string dryscal_vert_adv_string = "";
29  pp.query("dycore_horiz_adv_type" , dycore_horiz_adv_string);
30  pp.query("dycore_vert_adv_type" , dycore_vert_adv_string);
31  pp.query("dryscal_horiz_adv_type" , dryscal_horiz_adv_string);
32  pp.query("dryscal_vert_adv_type" , dryscal_vert_adv_string);
33 
34  std::string moistscal_horiz_adv_string = ""; std::string moistscal_vert_adv_string = "";
35  pp.query("moistscal_horiz_adv_type", moistscal_horiz_adv_string);
36  pp.query("moistscal_vert_adv_type" , moistscal_vert_adv_string);
37 
39  amrex::Print() << "Using efficient advection scheme" << std::endl;
40  }
41 
42  if ( (dycore_horiz_adv_string == "Blended_3rd4th") ||
43  (dycore_horiz_adv_string == "Blended_5th6th") )
44  {
45  pp.query("dycore_horiz_upw_frac" , dycore_horiz_upw_frac);
46  AMREX_ASSERT_WITH_MESSAGE((dycore_horiz_upw_frac >= 0.) && (dycore_horiz_upw_frac <= 1.),
47  "The dycore horizontal upwinding fraction must be between 0 and 1");
48  }
49 
50  if ( (dycore_vert_adv_string == "Blended_3rd4th") ||
51  (dycore_vert_adv_string == "Blended_5th6th") )
52  {
53  pp.query("dycore_vert_upw_frac" , dycore_vert_upw_frac);
54  AMREX_ASSERT_WITH_MESSAGE((dycore_vert_upw_frac >= 0.) && (dycore_vert_upw_frac <= 1.),
55  "The dycore vertical upwinding fraction must be between 0 and 1");
56  }
57 
58  if ( (dryscal_horiz_adv_string == "Blended_3rd4th") ||
59  (dryscal_horiz_adv_string == "Blended_5th6th") )
60  {
61  pp.query("dryscal_horiz_upw_frac" , dryscal_horiz_upw_frac);
62  AMREX_ASSERT_WITH_MESSAGE((dryscal_horiz_upw_frac >= 0.) && (dryscal_horiz_upw_frac <= 1.),
63  "The dry scalar horizontal upwinding fraction must be between 0 and 1");
64  }
65 
66  if ( (dryscal_vert_adv_string == "Blended_3rd4th") ||
67  (dryscal_vert_adv_string == "Blended_5th6th") )
68  {
69  pp.query("dryscal_vert_upw_frac" , dryscal_vert_upw_frac);
70  AMREX_ASSERT_WITH_MESSAGE((dryscal_vert_upw_frac >= 0.) && (dryscal_vert_upw_frac <= 1.),
71  "The dry scalar vertical upwinding fraction must be between 0 and 1");
72  }
73 
74  if ( (moistscal_horiz_adv_string == "Blended_3rd4th") ||
75  (moistscal_horiz_adv_string == "Blended_5th6th") )
76  {
77  pp.query("moistscal_horiz_upw_frac" , moistscal_horiz_upw_frac);
78  AMREX_ASSERT_WITH_MESSAGE((moistscal_horiz_upw_frac >= 0.) && (moistscal_horiz_upw_frac <= 1.),
79  "The moist scalar horizontal upwinding fraction must be between 0 and 1");
80  }
81 
82  if ( (moistscal_vert_adv_string == "Blended_3rd4th") ||
83  (moistscal_vert_adv_string == "Blended_5th6th") )
84  {
85  pp.query("moistscal_vert_upw_frac" , moistscal_vert_upw_frac);
86  AMREX_ASSERT_WITH_MESSAGE((moistscal_vert_upw_frac >= 0.) && (moistscal_vert_upw_frac <= 1.),
87  "The moist scalar vertical upwinding fraction must be between 0 and 1");
88  }
89 
90  if ( (dycore_horiz_adv_string == "Centered_2nd") ||
91  (dycore_horiz_adv_string == "Upwind_3rd" ) ||
92  (dycore_horiz_adv_string == "Blended_3rd4th") ||
93  (dycore_horiz_adv_string == "Centered_4th") ||
94  (dycore_horiz_adv_string == "Upwind_5th" ) ||
95  (dycore_horiz_adv_string == "Blended_5th6th") ||
96  (dycore_horiz_adv_string == "Centered_6th") )
97  {
99  }
100 
101  if ( (dycore_vert_adv_string == "Centered_2nd") ||
102  (dycore_vert_adv_string == "Upwind_3rd" ) ||
103  (dycore_vert_adv_string == "Blended_3rd4th") ||
104  (dycore_vert_adv_string == "Centered_4th") ||
105  (dycore_vert_adv_string == "Upwind_5th" ) ||
106  (dycore_vert_adv_string == "Blended_5th6th") ||
107  (dycore_vert_adv_string == "Centered_6th") )
108  {
110  }
111 
112  if ( (dryscal_horiz_adv_string == "Centered_2nd") ||
113  (dryscal_horiz_adv_string == "Upwind_3rd" ) ||
114  (dryscal_horiz_adv_string == "Blended_3rd4th") ||
115  (dryscal_horiz_adv_string == "Centered_4th") ||
116  (dryscal_horiz_adv_string == "Upwind_5th" ) ||
117  (dryscal_horiz_adv_string == "Blended_5th6th") ||
118  (dryscal_horiz_adv_string == "Centered_6th") ||
119  (dryscal_horiz_adv_string == "WENO3" ) ||
120  (dryscal_horiz_adv_string == "WENOZ3" ) ||
121  (dryscal_horiz_adv_string == "WENOMZQ3" ) ||
122  (dryscal_horiz_adv_string == "WENO5" ) ||
123  (dryscal_horiz_adv_string == "WENOZ5" ) ||
124  (dryscal_horiz_adv_string == "WENO7" ) ||
125  (dryscal_horiz_adv_string == "WENOZ7" ) )
126  {
128  }
129 
130  if ( (dryscal_vert_adv_string == "Centered_2nd") ||
131  (dryscal_vert_adv_string == "Upwind_3rd" ) ||
132  (dryscal_vert_adv_string == "Blended_3rd4th") ||
133  (dryscal_vert_adv_string == "Centered_4th") ||
134  (dryscal_vert_adv_string == "Upwind_5th" ) ||
135  (dryscal_vert_adv_string == "Blended_5th6th") ||
136  (dryscal_vert_adv_string == "Centered_6th") ||
137  (dryscal_vert_adv_string == "WENO3" ) ||
138  (dryscal_vert_adv_string == "WENOZ3" ) ||
139  (dryscal_vert_adv_string == "WENOMZQ3" ) ||
140  (dryscal_vert_adv_string == "WENO5" ) ||
141  (dryscal_vert_adv_string == "WENOZ5" ) ||
142  (dryscal_vert_adv_string == "WENO7" ) ||
143  (dryscal_vert_adv_string == "WENOZ7" ))
144  {
146  }
147 
148  if ( (moistscal_horiz_adv_string == "Centered_2nd") ||
149  (moistscal_horiz_adv_string == "Upwind_3rd" ) ||
150  (moistscal_horiz_adv_string == "Blended_3rd4th") ||
151  (moistscal_horiz_adv_string == "Centered_4th") ||
152  (moistscal_horiz_adv_string == "Upwind_5th" ) ||
153  (moistscal_horiz_adv_string == "Blended_5th6th") ||
154  (moistscal_horiz_adv_string == "Centered_6th") ||
155  (moistscal_horiz_adv_string == "WENO3" ) ||
156  (moistscal_horiz_adv_string == "WENOZ3" ) ||
157  (moistscal_horiz_adv_string == "WENOMZQ3" ) ||
158  (moistscal_horiz_adv_string == "WENO5" ) ||
159  (moistscal_horiz_adv_string == "WENOZ5" ) ||
160  (moistscal_horiz_adv_string == "WENO7" ) ||
161  (moistscal_horiz_adv_string == "WENOZ7" ))
162  {
163  moistscal_horiz_adv_type = adv_type_convert_string_to_advtype(moistscal_horiz_adv_string);
164  }
165 
166  if ( (moistscal_vert_adv_string == "Centered_2nd") ||
167  (moistscal_vert_adv_string == "Upwind_3rd" ) ||
168  (moistscal_vert_adv_string == "Blended_3rd4th") ||
169  (moistscal_vert_adv_string == "Centered_4th") ||
170  (moistscal_vert_adv_string == "Upwind_5th" ) ||
171  (moistscal_vert_adv_string == "Blended_5th6th") ||
172  (moistscal_vert_adv_string == "Centered_6th") ||
173  (moistscal_vert_adv_string == "WENO3" ) ||
174  (moistscal_vert_adv_string == "WENOZ3" ) ||
175  (moistscal_vert_adv_string == "WENOMZQ3" ) ||
176  (moistscal_vert_adv_string == "WENO5" ) ||
177  (moistscal_vert_adv_string == "WENOZ5" ) ||
178  (moistscal_vert_adv_string == "WENO7" ) ||
179  (moistscal_vert_adv_string == "WENOZ7" ))
180  {
181  moistscal_vert_adv_type = adv_type_convert_string_to_advtype(moistscal_vert_adv_string);
182  }
183 
184  pp.queryarr("zero_xflux_faces", zero_xflux);
185  pp.queryarr("zero_yflux_faces", zero_yflux);
186  pp.queryarr("zero_zflux_faces", zero_zflux);
187  have_zero_flux_faces = ((zero_xflux.size() > 0) || (zero_yflux.size() > 0) || (zero_zflux.size() > 0));
188  }
189 
190  void display(std::string& pp_prefix)
191  {
192  amrex::Print() << "Advection Choices: " << std::endl;
193 
194  // We read these again here just as a convenience to avoid passing them
195  amrex::ParmParse pp(pp_prefix);
196  std::string dycore_horiz_adv_string = "" ; std::string dycore_vert_adv_string = "";
197  std::string dryscal_horiz_adv_string = "" ; std::string dryscal_vert_adv_string = "";
198  pp.query("dycore_horiz_adv_type" , dycore_horiz_adv_string);
199  pp.query("dycore_vert_adv_type" , dycore_vert_adv_string);
200  pp.query("dryscal_horiz_adv_type" , dryscal_horiz_adv_string);
201  pp.query("dryscal_vert_adv_type" , dryscal_vert_adv_string);
202  std::string moistscal_horiz_adv_string = ""; std::string moistscal_vert_adv_string = "";
203  pp.query("moistscal_horiz_adv_type", moistscal_horiz_adv_string);
204  pp.query("moistscal_vert_adv_type" , moistscal_vert_adv_string);
205 
206  if (dycore_horiz_adv_string != "") {
207  amrex::Print() << " dycore_horiz_adv_type : " << dycore_horiz_adv_string;
208  } else {
209  amrex::Print() << " dycore_horiz_adv_type : " << adv_type_convert_int_to_string(dycore_horiz_adv_type);
210  }
211  if ( (dycore_horiz_adv_string == "Blended_3rd4th") ||
212  (dycore_horiz_adv_string == "Blended_5th6th") ) {
213  amrex::Print() << " with " << 100*dycore_horiz_upw_frac << "% upwinding";
214  }
215  amrex::Print() << std::endl;
216 
217  if (dycore_vert_adv_string != "") {
218  amrex::Print() << " dycore_vert_adv_type : " << dycore_vert_adv_string;
219  } else {
220  amrex::Print() << " dycore_vert_adv_type : " << adv_type_convert_int_to_string(dycore_vert_adv_type);
221  }
222  if ( (dycore_vert_adv_string == "Blended_3rd4th") ||
223  (dycore_vert_adv_string == "Blended_5th6th") ) {
224  amrex::Print() << " with " << 100*dycore_vert_upw_frac << "% upwinding";
225  }
226  amrex::Print() << std::endl;
227 
228  if (dryscal_horiz_adv_string != "") {
229  amrex::Print() << " dryscal_horiz_adv_type : " << dryscal_horiz_adv_string;
230  } else {
231  amrex::Print() << " dryscal_horiz_adv_type : " << adv_type_convert_int_to_string(dryscal_horiz_adv_type);
232  }
233  if ( (dryscal_horiz_adv_string == "Blended_3rd4th") ||
234  (dryscal_horiz_adv_string == "Blended_5th6th") ) {
235  amrex::Print() << " with " << 100*dryscal_horiz_upw_frac << "% upwinding";
236  }
237  amrex::Print() << std::endl;
238 
239  if (dryscal_vert_adv_string != "") {
240  amrex::Print() << " dryscal_vert_adv_type : " << dryscal_vert_adv_string;
241  } else {
242  amrex::Print() << " dryscal_vert_adv_type : " << adv_type_convert_int_to_string(dryscal_vert_adv_type);
243  }
244  if ( (dryscal_vert_adv_string == "Blended_3rd4th") ||
245  (dryscal_vert_adv_string == "Blended_5th6th") ) {
246  amrex::Print() << " with " << 100*dryscal_vert_upw_frac << "% upwinding";
247  }
248  amrex::Print() << std::endl;
249 
250  if (moistscal_horiz_adv_string != "") {
251  amrex::Print() << " moistscal_horiz_adv_type : " << moistscal_horiz_adv_string;
252  } else {
253  amrex::Print() << " moistscal_horiz_adv_type : " << adv_type_convert_int_to_string(moistscal_horiz_adv_type);
254  }
255  if ( (moistscal_horiz_adv_string == "Blended_3rd4th") ||
256  (moistscal_horiz_adv_string == "Blended_5th6th") ) {
257  amrex::Print() << " with " << 100*moistscal_horiz_upw_frac << "% upwinding";
258  }
259  amrex::Print() << std::endl;
260 
261  if (moistscal_vert_adv_string != "") {
262  amrex::Print() << " moistscal_vert_adv_type : " << moistscal_vert_adv_string;
263  } else {
264  amrex::Print() << " moistscal_vert_adv_type : " << adv_type_convert_int_to_string(moistscal_vert_adv_type);
265  }
266  if ( (moistscal_vert_adv_string == "Blended_3rd4th") ||
267  (moistscal_vert_adv_string == "Blended_5th6th") ) {
268  amrex::Print() << " with " << 100*moistscal_vert_upw_frac << "% upwinding";
269  }
270  amrex::Print() << std::endl;
271  }
272 
273  std::string
275  {
276  if (adv_int == AdvType::Centered_2nd) {
277  return "Centered_2nd";
278  } else if (adv_int == AdvType::Upwind_3rd) {
279  return "Upwind_3rd";
280  } else if (adv_int == AdvType::Centered_4th) {
281  return "Centered_4th";
282  } else if (adv_int == AdvType::Upwind_5th) {
283  return "Upwind_5th";
284  } else if (adv_int == AdvType::Centered_6th) {
285  return "Centered_6th";
286  } else if (adv_int == AdvType::Weno_3) {
287  return "WENO3";
288  } else if (adv_int == AdvType::Weno_3Z) {
289  return "WENOZ3";
290  } else if (adv_int == AdvType::Weno_5) {
291  return "WENO5";
292  } else if (adv_int == AdvType::Weno_5Z) {
293  return "WENOZ5";
294  } else if (adv_int == AdvType::Weno_3MZQ) {
295  return "WENOMZQ3";
296  } else if (adv_int == AdvType::Weno_7) {
297  return "WENO7";
298  } else if (adv_int == AdvType::Weno_7Z) {
299  return "WENOZ7";
300  } else {
301  return "Unknown";
302  }
303  }
304 
306  {
307  if (adv_string == "Centered_2nd") {
308  return AdvType::Centered_2nd;
309  } else if ((adv_string == "Upwind_3rd") || (adv_string == "Blended_3rd4th")) {
310  return AdvType::Upwind_3rd;
311  } else if (adv_string == "Centered_4th") {
312  return AdvType::Centered_4th;
313  } else if (adv_string == "Upwind_5th" || (adv_string == "Blended_5th6th")) {
314  return AdvType::Upwind_5th;
315  } else if (adv_string == "Centered_6th") {
316  return AdvType::Centered_6th;
317  } else if (adv_string == "WENO3") {
318  return AdvType::Weno_3;
319  } else if (adv_string == "WENOZ3") {
320  return AdvType::Weno_3Z;
321  } else if (adv_string == "WENO5") {
322  return AdvType::Weno_5;
323  } else if (adv_string == "WENOZ5") {
324  return AdvType::Weno_5Z;
325  } else if (adv_string == "WENOMZQ3") {
326  return AdvType::Weno_3MZQ;
327  } else if (adv_string == "WENO7") {
328  return AdvType::Weno_7;
329  } else if (adv_string == "WENOZ7") {
330  return AdvType::Weno_7Z;
331  } else {
332  return AdvType::Unknown;
333  }
334  }
335 
336  // Order and type of spatial discretizations used in advection
337  // Defaults given below but these can be over-written at run-time
345 
346  // Blending between upwind and the next-highest order central scheme
347  // Note: This is used by both Upwind_* and Blended_* schemes -- the default
348  // is a pure upwind scheme
349  amrex::Real dycore_horiz_upw_frac = 1.0;
350  amrex::Real dycore_vert_upw_frac = 1.0;
351  amrex::Real dryscal_horiz_upw_frac = 1.0;
352  amrex::Real dryscal_vert_upw_frac = 1.0;
353  amrex::Real moistscal_horiz_upw_frac = 1.0;
354  amrex::Real moistscal_vert_upw_frac = 1.0;
355 
356  // Thin immersed bodies
357  amrex::Vector<amrex::IntVect> zero_xflux;
358  amrex::Vector<amrex::IntVect> zero_yflux;
359  amrex::Vector<amrex::IntVect> zero_zflux;
360  bool have_zero_flux_faces = false;
361 };
362 #endif
AdvType
Definition: ERF_IndexDefines.H:203
@ Centered_4th
@ Centered_6th
@ Centered_2nd
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:219
Definition: ERF_AdvStruct.H:19
void display(std::string &pp_prefix)
Definition: ERF_AdvStruct.H:190
void init_params(std::string pp_prefix)
Definition: ERF_AdvStruct.H:21
amrex::Vector< amrex::IntVect > zero_yflux
Definition: ERF_AdvStruct.H:358
AdvType adv_type_convert_string_to_advtype(std::string adv_string)
Definition: ERF_AdvStruct.H:305
amrex::Real dryscal_vert_upw_frac
Definition: ERF_AdvStruct.H:352
AdvType moistscal_horiz_adv_type
Definition: ERF_AdvStruct.H:343
AdvType dycore_vert_adv_type
Definition: ERF_AdvStruct.H:340
AdvType moistscal_vert_adv_type
Definition: ERF_AdvStruct.H:344
amrex::Real moistscal_vert_upw_frac
Definition: ERF_AdvStruct.H:354
amrex::Real dycore_vert_upw_frac
Definition: ERF_AdvStruct.H:350
bool use_efficient_advection
Definition: ERF_AdvStruct.H:338
amrex::Real moistscal_horiz_upw_frac
Definition: ERF_AdvStruct.H:353
AdvType dryscal_horiz_adv_type
Definition: ERF_AdvStruct.H:341
amrex::Vector< amrex::IntVect > zero_xflux
Definition: ERF_AdvStruct.H:357
amrex::Vector< amrex::IntVect > zero_zflux
Definition: ERF_AdvStruct.H:359
AdvType dycore_horiz_adv_type
Definition: ERF_AdvStruct.H:339
bool have_zero_flux_faces
Definition: ERF_AdvStruct.H:360
amrex::Real dycore_horiz_upw_frac
Definition: ERF_AdvStruct.H:349
std::string adv_type_convert_int_to_string(AdvType adv_int)
Definition: ERF_AdvStruct.H:274
AdvType dryscal_vert_adv_type
Definition: ERF_AdvStruct.H:342
amrex::Real dryscal_horiz_upw_frac
Definition: ERF_AdvStruct.H:351