ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
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()
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()
191  {
192  amrex::Print() << "Advection Choices: " << std::endl;
193  amrex::Print() << " dycore_horiz_adv_type : " << adv_type_convert_int_to_string(dycore_horiz_adv_type);
194  if (dycore_horiz_upw_frac < 1) amrex::Print() << " with " << 100*dycore_horiz_upw_frac << "% upwinding";
195  amrex::Print() << std::endl;
196  amrex::Print() << " dycore_vert_adv_type : " << adv_type_convert_int_to_string(dycore_vert_adv_type);
197  if (dycore_vert_upw_frac < 1) amrex::Print() << " with " << 100*dycore_vert_upw_frac << "% upwinding";
198  amrex::Print() << std::endl;
199  amrex::Print() << " dryscal_horiz_adv_type : " << adv_type_convert_int_to_string(dryscal_horiz_adv_type);
200  if (dryscal_horiz_upw_frac < 1) amrex::Print() << " with " << 100*dryscal_horiz_upw_frac << "% upwinding";
201  amrex::Print() << std::endl;
202  amrex::Print() << " dryscal_vert_adv_type : " << adv_type_convert_int_to_string(dryscal_vert_adv_type);
203  if (dryscal_vert_upw_frac < 1) amrex::Print() << " with " << 100*dryscal_vert_upw_frac << "% upwinding";
204  amrex::Print() << std::endl;
205  amrex::Print() << " moistscal_horiz_adv_type : " << adv_type_convert_int_to_string(moistscal_horiz_adv_type);
206  if (moistscal_horiz_upw_frac < 1) amrex::Print() << " with " << 100*moistscal_horiz_upw_frac << "% upwinding";
207  amrex::Print() << std::endl;
208  amrex::Print() << " moistscal_vert_adv_type : " << adv_type_convert_int_to_string(moistscal_vert_adv_type);
209  if (moistscal_vert_upw_frac < 1) amrex::Print() << " with " << 100*moistscal_vert_upw_frac << "% upwinding";
210  amrex::Print() << std::endl;
211  }
212 
213  std::string
215  {
216  if (adv_int == AdvType::Centered_2nd) {
217  return "Centered_2nd";
218  } else if (adv_int == AdvType::Upwind_3rd) {
219  return "Upwind_3rd";
220  } else if (adv_int == AdvType::Centered_4th) {
221  return "Centered_4th";
222  } else if (adv_int == AdvType::Upwind_5th) {
223  return "Upwind_5th";
224  } else if (adv_int == AdvType::Centered_6th) {
225  return "Centered_6th";
226  } else if (adv_int == AdvType::Weno_3) {
227  return "WENO3";
228  } else if (adv_int == AdvType::Weno_3Z) {
229  return "WENOZ3";
230  } else if (adv_int == AdvType::Weno_5) {
231  return "WENO5";
232  } else if (adv_int == AdvType::Weno_5Z) {
233  return "WENOZ5";
234  } else if (adv_int == AdvType::Weno_3MZQ) {
235  return "WENOMZQ3";
236  } else if (adv_int == AdvType::Weno_7) {
237  return "WENO7";
238  } else if (adv_int == AdvType::Weno_7Z) {
239  return "WENOZ7";
240  } else {
241  return "Unknown";
242  }
243  }
244 
246  {
247  if (adv_string == "Centered_2nd") {
248  return AdvType::Centered_2nd;
249  } else if ((adv_string == "Upwind_3rd") || (adv_string == "Blended_3rd4th")) {
250  return AdvType::Upwind_3rd;
251  } else if (adv_string == "Centered_4th") {
252  return AdvType::Centered_4th;
253  } else if (adv_string == "Upwind_5th" || (adv_string == "Blended_5th6th")) {
254  return AdvType::Upwind_5th;
255  } else if (adv_string == "Centered_6th") {
256  return AdvType::Centered_6th;
257  } else if (adv_string == "WENO3") {
258  return AdvType::Weno_3;
259  } else if (adv_string == "WENOZ3") {
260  return AdvType::Weno_3Z;
261  } else if (adv_string == "WENO5") {
262  return AdvType::Weno_5;
263  } else if (adv_string == "WENOZ5") {
264  return AdvType::Weno_5Z;
265  } else if (adv_string == "WENOMZQ3") {
266  return AdvType::Weno_3MZQ;
267  } else if (adv_string == "WENO7") {
268  return AdvType::Weno_7;
269  } else if (adv_string == "WENOZ7") {
270  return AdvType::Weno_7Z;
271  } else {
272  return AdvType::Unknown;
273  }
274  }
275 
276  // Default prefix
277  std::string pp_prefix {"erf"};
278 
279  // Order and type of spatial discretizations used in advection
280  // Defaults given below but these can be over-written at run-time
288 
289  // Blending between upwind and the next-highest order central scheme
290  // Note: This is used by both Upwind_* and Blended_* schemes -- the default
291  // is a pure upwind scheme
292  amrex::Real dycore_horiz_upw_frac = 1.0;
293  amrex::Real dycore_vert_upw_frac = 1.0;
294  amrex::Real dryscal_horiz_upw_frac = 1.0;
295  amrex::Real dryscal_vert_upw_frac = 1.0;
296  amrex::Real moistscal_horiz_upw_frac = 1.0;
297  amrex::Real moistscal_vert_upw_frac = 1.0;
298 
299  // Thin immersed bodies
300  amrex::Vector<amrex::IntVect> zero_xflux;
301  amrex::Vector<amrex::IntVect> zero_yflux;
302  amrex::Vector<amrex::IntVect> zero_zflux;
303  bool have_zero_flux_faces = false;
304 };
305 #endif
AdvType
Definition: ERF_IndexDefines.H:191
@ 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
amrex::Vector< amrex::IntVect > zero_yflux
Definition: ERF_AdvStruct.H:301
void display()
Definition: ERF_AdvStruct.H:190
AdvType adv_type_convert_string_to_advtype(std::string adv_string)
Definition: ERF_AdvStruct.H:245
amrex::Real dryscal_vert_upw_frac
Definition: ERF_AdvStruct.H:295
AdvType moistscal_horiz_adv_type
Definition: ERF_AdvStruct.H:286
AdvType dycore_vert_adv_type
Definition: ERF_AdvStruct.H:283
AdvType moistscal_vert_adv_type
Definition: ERF_AdvStruct.H:287
amrex::Real moistscal_vert_upw_frac
Definition: ERF_AdvStruct.H:297
amrex::Real dycore_vert_upw_frac
Definition: ERF_AdvStruct.H:293
bool use_efficient_advection
Definition: ERF_AdvStruct.H:281
void init_params()
Definition: ERF_AdvStruct.H:21
std::string pp_prefix
Definition: ERF_AdvStruct.H:277
amrex::Real moistscal_horiz_upw_frac
Definition: ERF_AdvStruct.H:296
AdvType dryscal_horiz_adv_type
Definition: ERF_AdvStruct.H:284
amrex::Vector< amrex::IntVect > zero_xflux
Definition: ERF_AdvStruct.H:300
amrex::Vector< amrex::IntVect > zero_zflux
Definition: ERF_AdvStruct.H:302
AdvType dycore_horiz_adv_type
Definition: ERF_AdvStruct.H:282
bool have_zero_flux_faces
Definition: ERF_AdvStruct.H:303
amrex::Real dycore_horiz_upw_frac
Definition: ERF_AdvStruct.H:292
std::string adv_type_convert_int_to_string(AdvType adv_int)
Definition: ERF_AdvStruct.H:214
AdvType dryscal_vert_adv_type
Definition: ERF_AdvStruct.H:285
amrex::Real dryscal_horiz_upw_frac
Definition: ERF_AdvStruct.H:294