ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ERF_DataStruct.H
Go to the documentation of this file.
1 #ifndef ERF_DATA_STRUCT_H_
2 #define ERF_DATA_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 #include <ERF_AdvStruct.H>
15 #include <ERF_DiffStruct.H>
16 #include <ERF_SpongeStruct.H>
17 #include <ERF_TurbStruct.H>
18 #include <ERF_TurbPertStruct.H>
19 
20 AMREX_ENUM(InitType,
21  None, Input_Sounding, NCFile, WRFInput, Metgrid, Uniform
22 );
23 
24 AMREX_ENUM(ABLDriverType,
25  None, PressureGradient, GeostrophicWind
26 );
27 
28 AMREX_ENUM(CouplingType,
29  OneWay, TwoWay
30 );
31 
32 AMREX_ENUM(SubsteppingType,
33  None, Explicit, Implicit
34 );
35 
36 AMREX_ENUM(MeshType,
37  ConstantDz, StretchedDz, VariableDz
38 );
39 
40 AMREX_ENUM(TerrainType,
41  None, StaticFittedMesh, MovingFittedMesh, EB, ImmersedForcing
42 );
43 
44 AMREX_ENUM(MoistureModelType,
45  Eulerian, Lagrangian, Undefined
46 );
47 
48 AMREX_ENUM(MoistureType,
49  SAM, SAM_NoIce, SAM_NoPrecip_NoIce, Kessler, Kessler_NoRain, SatAdj, Morrison, None
50 );
51 
52 AMREX_ENUM(WindFarmType,
53  Fitch, EWP, SimpleAD, GeneralAD, None
54 );
55 
56 AMREX_ENUM(WindFarmLocType,
57  lat_lon, x_y, None
58 );
59 
60 AMREX_ENUM(LandSurfaceType,
61  SLM, MM5, None, NOAH
62 );
63 
64 AMREX_ENUM(PerturbationType,
65  Source, Direct, None
66 );
67 
68 enum struct Coord {
69  x, y, z
70 };
71 
72 // These are used as integers so must be enum not enum struct
73 enum Rayleigh {
75 };
76 
77 // These are used as integers so must be enum not enum struct
78 enum Sponge {
80 };
81 
82 /**
83  * Container holding many of the algorithmic options and parameters
84  */
85 
86 struct SolverChoice {
87  public:
88  void init_params(int max_level, std::string pp_prefix)
89  {
90  amrex::ParmParse pp(pp_prefix);
91 
92  bool bogus;
93  if (pp.query("use_terrain",bogus) > 0) {
94  amrex::Abort("The input use_terrain is deprecated. Set terrain_type instead.");
95  }
96 
97  pp.query("grid_stretching_ratio", grid_stretching_ratio);
98  if (grid_stretching_ratio != 0) {
99  AMREX_ASSERT_WITH_MESSAGE((grid_stretching_ratio >= 1.),
100  "The grid stretching ratio must be greater than 1");
101  }
102  if (grid_stretching_ratio >= 1) {
103  if (mesh_type == MeshType::ConstantDz) {
104  mesh_type = MeshType::StretchedDz;
105  }
106  if (terrain_type != TerrainType::StaticFittedMesh) {
107  amrex::Print() << "Turning terrain on to enable grid stretching" << std::endl;
108  terrain_type = TerrainType::StaticFittedMesh;
109  }
110  pp.query("zsurface", zsurf);
111  if (zsurf != 0.0) {
112  amrex::Print() << "Nominal zsurface height != 0, may result in unexpected behavior"
113  << std::endl;
114  }
115  pp.get("initial_dz", dz0);
116  }
117 
118  // Do we set map scale factors to 0.5 instead of 1 for testing?
119  pp.query("test_mapfactor", test_mapfactor);
120 
121  // What type of moisture model to use?
122  moisture_type = MoistureType::None; // Default
123  if (pp.query("moisture_type",moisture_type) > 0) {
124  amrex::Abort("The input moisture_type is deprecated. Set moisture_model instead.");
125  }
126  pp.query_enum_case_insensitive("moisture_model",moisture_type);
127  if (moisture_type == MoistureType::SAM) {
131  } else if (moisture_type == MoistureType::SAM_NoIce) {
135  } else if (moisture_type == MoistureType::SAM_NoPrecip_NoIce) {
138  } else if (moisture_type == MoistureType::Morrison) {
142  } else if (moisture_type == MoistureType::Kessler) {
146  } else if (moisture_type == MoistureType::Kessler_NoRain) {
149  } else if (moisture_type == MoistureType::SatAdj) {
152  }
153 
154  // TODO: should we set default for dry??
155  // Set a different default for moist vs dry
156  if (moisture_type != MoistureType::None) {
157  if (moisture_type == MoistureType::Kessler_NoRain ||
158  moisture_type == MoistureType::SAM ||
159  moisture_type == MoistureType::SAM_NoIce ||
160  moisture_type == MoistureType::SAM_NoPrecip_NoIce ||
161  moisture_type == MoistureType::Morrison ||
162  moisture_type == MoistureType::SatAdj)
163  {
164  buoyancy_type = 1; // uses Rhoprime
165  } else {
166  buoyancy_type = 2; // uses Tprime
167  }
168  }
169 
170  // Which expression (1,2/3 or 4) to use for buoyancy
171  pp.query("buoyancy_type", buoyancy_type);
172 
173  // What type of land surface model to use
174  lsm_type = LandSurfaceType::None; // Default
175  pp.query_enum_case_insensitive("land_surface_model",lsm_type);
176 
177  // Is the terrain none, static or moving?
178  std::string terrain_type_temp = "";
179  pp.query("terrain_type", terrain_type_temp);
180  if (terrain_type_temp == "Moving") {
181  amrex::Warning("erf.terrain_type = Moving is deprecated; please replace Moving by MovingFittedMesh");
182  terrain_type = TerrainType::MovingFittedMesh;
183  } else if (terrain_type_temp == "Static") {
184  amrex::Warning("erf.terrain_type = Static is deprecated; please replace Static by StaticFittedMesh");
185  terrain_type = TerrainType::StaticFittedMesh;
186  } else {
187  pp.query_enum_case_insensitive("terrain_type",terrain_type);
188  }
189 
190  //
191  // Read the init_type here to make sure we correctly set the mesh and terrain types
192  //
193  std::string init_type_temp_string;
194  pp.query("init_type",init_type_temp_string);
195  if ( (init_type_temp_string == "Real") || (init_type_temp_string == "real") ) {
196  amrex::Warning("erf.init_type = Real is deprecated; please replace Real by WRFInput");
197  init_type = InitType::WRFInput;
198  use_real_bcs = true;
199  } else if ( (init_type_temp_string == "Ideal") || (init_type_temp_string == "ideal") ) {
200  amrex::Warning("erf.init_type = Ideal is deprecated; please replace Ideal by WRFInput");
201  init_type = InitType::WRFInput;
202  use_real_bcs = false;
203  } else {
204  pp.query_enum_case_insensitive("init_type",init_type);
205  use_real_bcs = ( (init_type == InitType::WRFInput) || (init_type == InitType::Metgrid) );
206  }
207 
208  if ( (init_type == InitType::WRFInput) || (init_type == InitType::Metgrid) ) {
209  if (terrain_type != TerrainType::StaticFittedMesh) {
210  amrex::Abort("Only terrain_type = StaticFittedMesh are allowed with init_type = WRFInput or Metgrid");
211  }
212  }
213 
214  if (init_type == InitType::WRFInput) {
215  if (moisture_type == MoistureType::None) {
216  amrex::Abort("Can't have moisture_type = None with init_type = WRFInput");
217  }
218 
219  // NetCDF wrfbdy lateral boundary file
220  std::string nc_bdy_file_temp_string;
221  bool has_bdy = pp.query("nc_bdy_file", nc_bdy_file_temp_string);
222  if (!has_bdy) use_real_bcs = false;
223 
224  bool use_real_bcs_temp = use_real_bcs;
225  pp.query("use_real_bcs", use_real_bcs_temp);
226  if (use_real_bcs && !use_real_bcs_temp) {
227  use_real_bcs = false;
228  }
229  }
230 
231  // Check for rebalancing with wrfinput
232  if (init_type == InitType::WRFInput) {
233  pp.query("rebalance_wrfinput",rebalance_wrfinput);
234  }
235 
236 
237  if (terrain_type == TerrainType::StaticFittedMesh ||
238  terrain_type == TerrainType::MovingFittedMesh) {
239  mesh_type = MeshType::VariableDz;
240  }
241 
242  int n_zlevels = pp.countval("terrain_z_levels");
243  if (n_zlevels > 0)
244  {
245  if (terrain_type == TerrainType::None) {
246  terrain_type = TerrainType::StaticFittedMesh;
247  }
248  if (mesh_type == MeshType::ConstantDz) {
249  mesh_type = MeshType::StretchedDz;
250  }
251  }
252 
253  // Use lagged_delta_rt in the fast integrator?
254  pp.query("use_lagged_delta_rt", use_lagged_delta_rt);
255 
256  // These default to true but are used for unit testing
257  pp.query("use_gravity", use_gravity);
259 
260  pp.query("c_p", c_p);
261  rdOcp = R_d / c_p;
262 
263  read_int_string(max_level, "anelastic", anelastic, 0);
264 
265  // *******************************************************************************
266  // Read substepping_type and allow for different values at each level
267  // *******************************************************************************
268  substepping_type.resize(max_level+1);
269 
270  for (int i = 0; i <= max_level; i++) {
271  substepping_type[i] = SubsteppingType::Implicit;
272  }
273 
274  int nvals = pp.countval("substepping_type");
275  AMREX_ALWAYS_ASSERT(nvals == 0 || nvals == 1 || nvals >= max_level+1);
276 
277  if (nvals == 1) {
278  pp.query_enum_case_insensitive("substepping_type",substepping_type[0]);
279  for (int i = 1; i <= max_level; i++) {
281  }
282  } else if (nvals > 1) { // in this case we have asserted nvals >= max_level+1
283  for (int i = 0; i <= max_level; i++) {
284  pp.query_enum_case_insensitive("substepping_type",substepping_type[i],i);
285  }
286  }
287 
288  // *******************************************************************************
289  // Error check on deprecated input
290  // *******************************************************************************
291  int nvals_old = pp.countval("no_substepping");
292  if (nvals_old > 0) {
293  amrex::Abort("The no_substepping flag is deprecated -- set substepping_type instead");
294  }
295  // *******************************************************************************
296 
297  bool any_anelastic = false;
298  for (int i = 0; i <= max_level; ++i) {
299  if (anelastic[i] == 1) any_anelastic = true;
300  }
301 
302  if (any_anelastic == 1) {
304  fixed_density = true; // We default to true but are allowed to override below
305  buoyancy_type = 3; // (This isn't actually used when anelastic is set)
306  } else {
307  pp.query("project_initial_velocity", project_initial_velocity);
308  }
309 
310  pp.query("fixed_density", fixed_density);
311 
312  // *******************************************************************************
313 
314  pp.query("ncorr", ncorr);
315  pp.query("poisson_abstol", poisson_abstol);
316  pp.query("poisson_reltol", poisson_reltol);
317 
318  for (int lev = 0; lev <= max_level; lev++) {
319  if (anelastic[lev] != 0)
320  {
321  substepping_type[lev] = SubsteppingType::None;
322  }
323  }
324 
325  pp.query("force_stage1_single_substep", force_stage1_single_substep);
326 
327  // Include Coriolis forcing?
328  pp.query("use_coriolis", use_coriolis);
329  pp.query("has_lat_lon", has_lat_lon);
330  if (has_lat_lon) { pp.query("variable_coriolis", variable_coriolis); }
331 
332  // Include Rayleigh damping (separate flags for each variable)
333  pp.query("rayleigh_damp_U", rayleigh_damp_U);
334  pp.query("rayleigh_damp_V", rayleigh_damp_V);
335  pp.query("rayleigh_damp_W", rayleigh_damp_W);
336  pp.query("rayleigh_damp_T", rayleigh_damp_T);
337  pp.query("rayleigh_dampcoef", rayleigh_dampcoef);
338  pp.query("rayleigh_zdamp", rayleigh_zdamp);
339 
340  // Flag to do explicit MOST formulation
341  pp.query("use_explicit_most",use_explicit_most);
342 
343  // Flag to do MOST rotations with terrain
344  pp.query("use_rotate_most",use_rotate_most);
345  if (use_rotate_most) {
346  AMREX_ASSERT_WITH_MESSAGE(terrain_type != TerrainType::None,"MOST stress rotations are only valid with terrain!");
347  AMREX_ASSERT_WITH_MESSAGE(use_explicit_most, "MOST Stress rotations are only valid with explicit MOST!");
348  }
349 
350  // Which external forcings?
351  abl_driver_type = ABLDriverType::None; // Default: no ABL driver for simulating classical fluid dynamics problems
352  pp.query_enum_case_insensitive("abl_driver_type",abl_driver_type);
353 
354  // Which type of inflow turbulent generation
355  pert_type = PerturbationType::None; // Default
356  pp.query_enum_case_insensitive("perturbation_type",pert_type);
357 
358  amrex::Vector<amrex::Real> abl_pressure_grad_in = {0.0, 0.0, 0.0};
359  pp.queryarr("abl_pressure_grad",abl_pressure_grad_in);
360  for(int i = 0; i < AMREX_SPACEDIM; ++i) abl_pressure_grad[i] = abl_pressure_grad_in[i];
361 
362  amrex::Vector<amrex::Real> abl_geo_forcing_in = {0.0, 0.0, 0.0};
363  if(pp.queryarr("abl_geo_forcing",abl_geo_forcing_in)) {
364  amrex::Print() << "Specified abl_geo_forcing: (";
365  for (int i = 0; i < AMREX_SPACEDIM; ++i) {
366  abl_geo_forcing[i] = abl_geo_forcing_in[i];
367  amrex::Print() << abl_geo_forcing[i] << " ";
368  }
369  amrex::Print() << ")" << std::endl;
370  }
371 
372  if (use_coriolis)
373  {
375  }
376 
377  pp.query("add_custom_rhotheta_forcing", custom_rhotheta_forcing);
378  pp.query("add_custom_moisture_forcing", custom_moisture_forcing);
379  pp.query("add_custom_w_subsidence", custom_w_subsidence);
380  pp.query("add_custom_geostrophic_profile", custom_geostrophic_profile);
381  pp.query("custom_forcing_uses_primitive_vars", custom_forcing_prim_vars);
382 
383  pp.query("nudging_from_input_sounding", nudging_from_input_sounding);
384 
386  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!(!abl_geo_wind_table.empty() && custom_geostrophic_profile),
387  "Should not have both abl_geo_wind_table and custom_geostrophic_profile set.");
388 
389  pp.query("Ave_Plane", ave_plane);
390 
391  pp.query("use_moist_background", use_moist_background);
392 
393  // Use numerical diffusion?
394  pp.query("num_diff_coeff",num_diff_coeff);
395  AMREX_ASSERT_WITH_MESSAGE(( (num_diff_coeff >= 0.) && (num_diff_coeff <= 1.) ),
396  "Numerical diffusion coefficient must be between 0 & 1.");
398  if (use_num_diff) {
399  amrex::Print() << "6th-order numerical diffusion turned on with coefficient = "
400  << num_diff_coeff << std::endl;
401  num_diff_coeff *= std::pow(2.0,-6);
402  }
403 
404  // Use monotonic advection?
405  pp.query("use_mono_adv",use_mono_adv);
406 
407  advChoice.init_params(pp_prefix);
408  diffChoice.init_params(pp_prefix);
409  spongeChoice.init_params(pp_prefix);
410 
411  turbChoice.resize(max_level+1);
412  for (int lev = 0; lev <= max_level; lev++) {
413  turbChoice[lev].init_params(lev,max_level,pp_prefix);
414  }
415 
416  // YSU PBL: use consistent coriolis frequency
417  for (int lev = 0; lev <= max_level; lev++) {
418  if (turbChoice[lev].pbl_ysu_use_consistent_coriolis) {
419  if (use_coriolis) {
420  turbChoice[lev].pbl_ysu_coriolis_freq = coriolis_factor * sinphi;
421  if (lev == 0) {
422  amrex::Print() << "YSU PBL using ERF coriolis frequency: " << turbChoice[lev].pbl_ysu_coriolis_freq << std::endl;
423  }
424  } else {
425  amrex::Abort("YSU cannot use ERF coriolis frequency if not using coriolis");
426  }
427  }
428  }
429 
430 
431  // Which type of multilevel coupling
432  coupling_type = CouplingType::TwoWay; // Default
433  pp.query_enum_case_insensitive("coupling_type",coupling_type);
434 
435  // Which type of windfarm model
436  windfarm_type = WindFarmType::None; // Default
437  pp.query_enum_case_insensitive("windfarm_type",windfarm_type);
438 
439  static std::string windfarm_loc_type_string = "None";
440  windfarm_loc_type = WindFarmLocType::None;
441  pp.query_enum_case_insensitive("windfarm_loc_type",windfarm_loc_type);
442 
443  pp.query("windfarm_loc_table", windfarm_loc_table);
444  pp.query("windfarm_spec_table", windfarm_spec_table);
445  pp.query("windfarm_blade_table", windfarm_blade_table);
446  pp.query("windfarm_airfoil_tables", windfarm_airfoil_tables);
447  pp.query("windfarm_spec_table_extra", windfarm_spec_table_extra);
448 
449  // Sampling distance upstream of the turbine to find the
450  // incoming free stream velocity as a factor of the diameter of the
451  // turbine. ie. the sampling distance will be this number multiplied
452  // by the diameter of the turbine
453  pp.query("sampling_distance_by_D", sampling_distance_by_D);
454  pp.query("turb_disk_angle_from_x", turb_disk_angle);
455 
456  pp.query("windfarm_x_shift",windfarm_x_shift);
457  pp.query("windfarm_y_shift",windfarm_y_shift);
458  // Test if time averaged data is to be output
459  pp.query("time_avg_vel",time_avg_vel);
460 
461  check_params(max_level);
462  }
463 
464  void check_params(int max_level)
465  {
466  // Warn for PBL models and moisture - these may not yet be compatible
467  for (int lev = 0; lev <= max_level; lev++) {
468  if ((moisture_type != MoistureType::None) && (turbChoice[lev].pbl_type != PBLType::None)) {
469  amrex::Warning("\n*** WARNING: Moisture may not yet be compatible with PBL models, \n proceed with caution ***");
470  }
471  }
472  //
473  // Buoyancy type check
474  //
475  if (buoyancy_type != 1 && buoyancy_type != 2 && buoyancy_type != 3 && buoyancy_type != 4) {
476  amrex::Abort("buoyancy_type must be 1, 2, 3 or 4");
477  }
478 
479  if (!use_lagged_delta_rt && !(terrain_type == TerrainType::MovingFittedMesh)) {
480  amrex::Error("Can't turn off lagged_delta_rt when terrain not moving");
481  }
482 
483  //
484  // Wind farm checks
485  //
486  if (windfarm_type==WindFarmType::SimpleAD and sampling_distance_by_D < 0.0) {
487  amrex::Abort("To use simplified actuator disks, you need to provide a variable"
488  " erf.sampling_distance_by_D in the inputs which specifies the upstream"
489  " distance as a factor of the turbine diameter at which the incoming free stream"
490  " velocity will be computed at.");
491  }
492  if ( (windfarm_type==WindFarmType::SimpleAD ||
493  windfarm_type==WindFarmType::GeneralAD ) && turb_disk_angle < 0.0) {
494  amrex::Abort("To use simplified actuator disks, you need to provide a variable"
495  " erf.turb_disk_angle_from_x in the inputs which is the angle of the face of the"
496  " turbine disk from the x-axis. A turbine facing an oncoming flow in the x-direction"
497  " will have turb_disk_angle value of 90 deg.");
498  }
499  if (windfarm_loc_type == WindFarmLocType::lat_lon and (windfarm_x_shift < 0.0 or windfarm_y_shift < 0.0)) {
500  amrex::Abort("You are using windfarms with latitude-logitude option to position the turbines."
501  " For this you should provide the inputs erf.windfarm_x_shift and"
502  " erf.windfarm_y_shift which are the values by which the bounding box of the"
503  " windfarm is shifted from the x and the y axes.");
504  }
505  }
506 
507  void display(int max_level, std::string pp_prefix)
508  {
509  amrex::Print() << "SOLVER CHOICE: " << std::endl;
510  amrex::Print() << "force_stage1_single_substep : " << force_stage1_single_substep << std::endl;
511  for (int lev = 0; lev <= max_level; lev++) {
512  amrex::Print() << "anelastic at level : " << lev << " is " << anelastic[lev] << std::endl;
513  if (substepping_type[lev] == SubsteppingType::None) {
514  amrex::Print() << "No substepping at level " << lev << std::endl;
515  } else if (substepping_type[lev] == SubsteppingType::Explicit) {
516  amrex::Print() << "Explicit substepping at level " << lev << std::endl;
517  } else if (substepping_type[lev] == SubsteppingType::Implicit) {
518  amrex::Print() << "Implicit substepping at level " << lev << std::endl;
519  }
520  }
521  amrex::Print() << "fixed_density : " << fixed_density << std::endl;
522  amrex::Print() << "use_coriolis : " << use_coriolis << std::endl;
523  amrex::Print() << "use_gravity : " << use_gravity << std::endl;
524 
525  if (moisture_type == MoistureType::SAM) {
526  amrex::Print() << "Moisture Model: SAM" << std::endl;
527  } else if (moisture_type == MoistureType::SAM_NoIce) {
528  amrex::Print() << "Moisture Model: SAM No Ice" << std::endl;
529  } else if (moisture_type == MoistureType::SAM_NoPrecip_NoIce) {
530  amrex::Print() << "Moisture Model: SAM No Precip No Ice" << std::endl;
531  } else if (moisture_type == MoistureType::Morrison) {
532  amrex::Print() << "Moisture Model: Morrison" << std::endl;
533  } else if (moisture_type == MoistureType::Kessler) {
534  amrex::Print() << "Moisture Model: Kessler" << std::endl;
535  } else if (moisture_type == MoistureType::Kessler_NoRain) {
536  amrex::Print() << "Moisture Model: Kessler No Rain" << std::endl;
537  } else {
538  amrex::Print() << "Moisture Model: None" << std::endl;
539  }
540 
541  if (terrain_type == TerrainType::StaticFittedMesh) {
542  amrex::Print() << "Terrain Type: StaticFittedMesh" << std::endl;
543  } else if (terrain_type == TerrainType::MovingFittedMesh) {
544  amrex::Print() << "Terrain Type: MovingFittedMesh" << std::endl;
545  } else if (terrain_type == TerrainType::EB) {
546  amrex::Print() << "Terrain Type: EB" << std::endl;
547  } else if (terrain_type == TerrainType::ImmersedForcing) {
548  amrex::Print() << "Terrain Type: ImmersedForcing" << std::endl;
549  } else {
550  amrex::Print() << "Terrain Type: None" << std::endl;
551  }
552 
553  if (mesh_type == MeshType::ConstantDz) {
554  amrex::Print() << " Mesh Type: ConstantDz" << std::endl;
555  } else if (mesh_type == MeshType::StretchedDz) {
556  amrex::Print() << " Mesh Type: StretchedDz" << std::endl;
557  } else if (mesh_type == MeshType::VariableDz) {
558  amrex::Print() << " Mesh Type: VariableDz" << std::endl;
559  } else {
560  amrex::Abort("No mesh_type set!");
561  }
562 
563  amrex::Print() << "ABL Driver Type: " << std::endl;
564  if (abl_driver_type == ABLDriverType::None) {
565  amrex::Print() << " None" << std::endl;
566  } else if (abl_driver_type == ABLDriverType::PressureGradient) {
567  amrex::Print() << " Pressure Gradient "
568  << amrex::RealVect(abl_pressure_grad[0],abl_pressure_grad[1],abl_pressure_grad[2])
569  << std::endl;
570  } else if (abl_driver_type == ABLDriverType::GeostrophicWind) {
571  amrex::Print() << " Geostrophic Wind "
572  << amrex::RealVect(abl_geo_forcing[0],abl_geo_forcing[1],abl_geo_forcing[2])
573  << std::endl;
574  }
575 
576  if (max_level > 0) {
577  amrex::Print() << "Coupling Type: " << std::endl;
578  if (coupling_type == CouplingType::TwoWay) {
579  amrex::Print() << " Two-way" << std::endl;
580  } else if (coupling_type == CouplingType::OneWay) {
581  amrex::Print() << " One-way" << std::endl;
582  }
583  }
584 
585  amrex::Print() << "Buoyancy_type : " << buoyancy_type << std::endl;
586 
587  advChoice.display(pp_prefix);
590 
591  for (int lev = 0; lev <= max_level; lev++) {
592  turbChoice[lev].display(lev);
593  }
594  }
595 
596  void build_coriolis_forcings_const_lat (std::string pp_prefix)
597  {
598  amrex::ParmParse pp(pp_prefix);
599 
600  // Read the rotational time period (in seconds)
601  amrex::Real rot_time_period = 86400.0;
602  pp.query("rotational_time_period", rot_time_period);
603 
604  coriolis_factor = 2.0 * 2.0 * PI / rot_time_period;
605 
606  amrex::Real latitude = 90.0;
607  pp.query("latitude", latitude);
608 
609  pp.query("coriolis_3d", coriolis_3d);
610 
611  // Convert to radians
612  latitude *= (PI/180.);
613  sinphi = std::sin(latitude);
614  if (coriolis_3d) {
615  cosphi = std::cos(latitude);
616  }
617 
618  amrex::Print() << "Coriolis frequency, f = " << coriolis_factor * sinphi << " 1/s" << std::endl;
619 
620  if (abl_driver_type == ABLDriverType::GeostrophicWind) {
621  // Read in the geostrophic wind -- we only use this to construct
622  // the forcing term so no need to keep it
623  amrex::Vector<amrex::Real> abl_geo_wind(3);
624  pp.queryarr("abl_geo_wind",abl_geo_wind);
625 
626  if(!pp.query("abl_geo_wind_table",abl_geo_wind_table)) {
627  abl_geo_forcing = {
628  -coriolis_factor * (abl_geo_wind[1]*sinphi - abl_geo_wind[2]*cosphi),
629  coriolis_factor * abl_geo_wind[0]*sinphi,
630  -coriolis_factor * abl_geo_wind[0]*cosphi
631  };
632  } else {
633  amrex::Print() << "NOTE: abl_geo_wind_table provided, ignoring input abl_geo_wind" << std::endl;
634  }
635  }
636  }
637 
638  void read_int_string (int max_level, const char* string_to_read,
639  amrex::Vector<int>& vec_to_fill, int default_int)
640  {
641  amrex::ParmParse pp("erf");
642  int nvals = pp.countval(string_to_read);
643  AMREX_ALWAYS_ASSERT(nvals == 0 || nvals == 1 || nvals >= max_level+1);
644  amrex::Vector<int> temp; temp.resize(nvals);
645  pp.queryarr(string_to_read,temp);
646  if (nvals == 0) {
647  for (int i = 0; i <= max_level; ++i) vec_to_fill.push_back(default_int);
648  } else if (nvals == 1) {
649  for (int i = 0; i <= max_level; ++i) vec_to_fill.push_back(temp[0]);
650  } else {
651  for (int i = 0; i <= max_level; ++i) vec_to_fill.push_back(temp[i]);
652  }
653  }
654 
655  inline static
656  InitType init_type = InitType::None;
657 
658  inline static
659  TerrainType terrain_type = TerrainType::None;
660 
661  inline static
662  bool use_real_bcs = false;
663 
664  inline static
665  MeshType mesh_type = MeshType::ConstantDz;
666 
667  static
668  void set_mesh_type (MeshType new_mesh_type)
669  {
670  mesh_type = new_mesh_type;
671  }
672 
676  amrex::Vector<TurbChoice> turbChoice;
677 
679 
680  amrex::Vector<SubsteppingType> substepping_type;
681  amrex::Vector<int> anelastic;
682 
683  bool fixed_density = false;
684  int ncorr = 1;
685  amrex::Real poisson_abstol = 1e-10;
686  amrex::Real poisson_reltol = 1e-10;
687 
688  bool test_mapfactor = false;
689 
690  int buoyancy_type = 1; // uses rhoprime directly
691 
692  // Specify what additional physics/forcing modules we use
693  bool use_gravity = false;
694  bool use_coriolis = false;
695  bool coriolis_3d = true;
696 
697  bool rayleigh_damp_U = false;
698  bool rayleigh_damp_V = false;
699  bool rayleigh_damp_W = false;
700  bool rayleigh_damp_T = false;
701  amrex::Real rayleigh_dampcoef = 0.2; // inverse time scale [1/s]
702  amrex::Real rayleigh_zdamp = 500.0; // damping layer depth [m]
703  amrex::Real rayleigh_ztop;
704 
705  // This defaults to true but can be set to false for moving terrain cases only
706  bool use_lagged_delta_rt = true;
707 
708  // Constants
709  amrex::Real gravity;
710  amrex::Real c_p = Cp_d; // specific heat at constant pressure for dry air [J/(kg-K)]
711  amrex::Real rdOcp;
712 
713  // Staggered z levels for vertical grid stretching
714  amrex::Real grid_stretching_ratio = 0;
715  amrex::Real zsurf = 0.0;
716  amrex::Real dz0;
717 
719 
720  // Coriolis forcing
721  amrex::Real coriolis_factor = 0.0;
722  amrex::Real cosphi = 0.0;
723  amrex::Real sinphi = 0.0;
724 
725  // User-specified forcings in problem definition
728  bool custom_w_subsidence = false;
731 
732  // Do we use source terms to nudge the solution towards
733  // the time-varying data provided in input sounding files?
735 
736  // User specified MOST BC type
737  bool use_explicit_most = false;
738 
739  // MOST stress rotations
740  bool use_rotate_most = false;
741 
742  // User wishes to output time averaged velocity fields
743  bool time_avg_vel = false;
744 
745  // Type of perturbation
746  PerturbationType pert_type;
747 
748  // Numerical diffusion
749  bool use_num_diff{false};
750  amrex::Real num_diff_coeff{0.};
751 
752  // Monotonic advection limiter
753  bool use_mono_adv{false};
754 
755  // Rebalance wrfinput
756  bool rebalance_wrfinput{false};
757 
758  CouplingType coupling_type;
759  MoistureType moisture_type;
760  WindFarmType windfarm_type;
761  WindFarmLocType windfarm_loc_type;
762  LandSurfaceType lsm_type;
763 
764  ABLDriverType abl_driver_type;
765  amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> abl_pressure_grad;
766  amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> abl_geo_forcing;
767  std::string abl_geo_wind_table;
768  bool have_geo_wind_profile {false};
769 
770  bool has_lat_lon{false};
771  bool variable_coriolis{false};
772 
773  int ave_plane {2};
774  // Microphysics params
775  bool use_moist_background {false};
776  int RhoQv_comp {-1};
777  int RhoQc_comp {-1};
778 
779  // This component will be model-dependent:
780  // if a model with no rain, this will stay -1
781  // if Kessler, then it will be set to RhoQ3
782  // if SAM, then it will be set to RhoQ4
783  int RhoQr_comp {-1};
784 
787  amrex::Real sampling_distance_by_D = -1.0;
788  amrex::Real turb_disk_angle = -1.0;
789  amrex::Real windfarm_x_shift = -1.0;
790  amrex::Real windfarm_y_shift = -1.0;
791 
792  // Use forest canopy model?
793  bool do_forest_drag {false};
794 };
795 #endif
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:12
constexpr amrex::Real PI
Definition: ERF_Constants.H:6
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:21
constexpr amrex::Real R_d
Definition: ERF_Constants.H:10
Rayleigh
Definition: ERF_DataStruct.H:73
@ ubar
Definition: ERF_DataStruct.H:74
@ wbar
Definition: ERF_DataStruct.H:74
@ nvars
Definition: ERF_DataStruct.H:74
@ vbar
Definition: ERF_DataStruct.H:74
@ thetabar
Definition: ERF_DataStruct.H:74
Sponge
Definition: ERF_DataStruct.H:78
@ nvars_sponge
Definition: ERF_DataStruct.H:79
@ vbar_sponge
Definition: ERF_DataStruct.H:79
@ ubar_sponge
Definition: ERF_DataStruct.H:79
Coord
Definition: ERF_DataStruct.H:68
AMREX_ENUM(InitType, None, Input_Sounding, NCFile, WRFInput, Metgrid, Uniform)
#define RhoQ4_comp
Definition: ERF_IndexDefines.H:45
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:43
#define RhoQ3_comp
Definition: ERF_IndexDefines.H:44
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:219
Definition: ERF_EWP.H:9
Definition: ERF_Fitch.H:9
Definition: ERF_GeneralAD.H:8
Definition: ERF_Kessler.H:38
Definition: ERF_MM5.H:26
Definition: ERF_Morrison.H:50
Definition: ERF_NOAH.H:30
Definition: ERF_SAM.H:53
Definition: ERF_SLM.H:26
Definition: ERF_SatAdj.H:41
Definition: ERF_SimpleAD.H:8
@ bogus
Definition: ERF_IndexDefines.H:186
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
Definition: ERF_DiffStruct.H:19
void init_params(std::string pp_prefix)
Definition: ERF_DiffStruct.H:21
void display()
Definition: ERF_DiffStruct.H:64
Definition: ERF_DataStruct.H:86
bool rayleigh_damp_T
Definition: ERF_DataStruct.H:700
amrex::Real dz0
Definition: ERF_DataStruct.H:716
bool use_lagged_delta_rt
Definition: ERF_DataStruct.H:706
amrex::Real coriolis_factor
Definition: ERF_DataStruct.H:721
bool use_explicit_most
Definition: ERF_DataStruct.H:737
static MeshType mesh_type
Definition: ERF_DataStruct.H:665
amrex::Real windfarm_x_shift
Definition: ERF_DataStruct.H:789
bool rayleigh_damp_V
Definition: ERF_DataStruct.H:698
int RhoQr_comp
Definition: ERF_DataStruct.H:783
void display(int max_level, std::string pp_prefix)
Definition: ERF_DataStruct.H:507
bool rebalance_wrfinput
Definition: ERF_DataStruct.H:756
amrex::Real poisson_reltol
Definition: ERF_DataStruct.H:686
void build_coriolis_forcings_const_lat(std::string pp_prefix)
Definition: ERF_DataStruct.H:596
amrex::Real rayleigh_zdamp
Definition: ERF_DataStruct.H:702
amrex::Real rdOcp
Definition: ERF_DataStruct.H:711
void read_int_string(int max_level, const char *string_to_read, amrex::Vector< int > &vec_to_fill, int default_int)
Definition: ERF_DataStruct.H:638
std::string windfarm_spec_table
Definition: ERF_DataStruct.H:785
bool use_mono_adv
Definition: ERF_DataStruct.H:753
DiffChoice diffChoice
Definition: ERF_DataStruct.H:674
bool use_gravity
Definition: ERF_DataStruct.H:693
int ncorr
Definition: ERF_DataStruct.H:684
int force_stage1_single_substep
Definition: ERF_DataStruct.H:678
std::string windfarm_spec_table_extra
Definition: ERF_DataStruct.H:785
amrex::Real cosphi
Definition: ERF_DataStruct.H:722
LandSurfaceType lsm_type
Definition: ERF_DataStruct.H:762
amrex::Real c_p
Definition: ERF_DataStruct.H:710
std::string windfarm_loc_table
Definition: ERF_DataStruct.H:785
amrex::Real gravity
Definition: ERF_DataStruct.H:709
void check_params(int max_level)
Definition: ERF_DataStruct.H:464
bool custom_rhotheta_forcing
Definition: ERF_DataStruct.H:726
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > abl_geo_forcing
Definition: ERF_DataStruct.H:766
WindFarmLocType windfarm_loc_type
Definition: ERF_DataStruct.H:761
bool custom_w_subsidence
Definition: ERF_DataStruct.H:728
bool nudging_from_input_sounding
Definition: ERF_DataStruct.H:734
bool rayleigh_damp_U
Definition: ERF_DataStruct.H:697
int RhoQc_comp
Definition: ERF_DataStruct.H:777
bool custom_geostrophic_profile
Definition: ERF_DataStruct.H:729
amrex::Real rayleigh_ztop
Definition: ERF_DataStruct.H:703
amrex::Real grid_stretching_ratio
Definition: ERF_DataStruct.H:714
amrex::Real sinphi
Definition: ERF_DataStruct.H:723
bool have_geo_wind_profile
Definition: ERF_DataStruct.H:768
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > abl_pressure_grad
Definition: ERF_DataStruct.H:765
void init_params(int max_level, std::string pp_prefix)
Definition: ERF_DataStruct.H:88
amrex::Vector< SubsteppingType > substepping_type
Definition: ERF_DataStruct.H:680
bool coriolis_3d
Definition: ERF_DataStruct.H:695
bool use_num_diff
Definition: ERF_DataStruct.H:749
amrex::Real sampling_distance_by_D
Definition: ERF_DataStruct.H:787
int RhoQv_comp
Definition: ERF_DataStruct.H:776
bool test_mapfactor
Definition: ERF_DataStruct.H:688
bool use_coriolis
Definition: ERF_DataStruct.H:694
bool custom_moisture_forcing
Definition: ERF_DataStruct.H:727
amrex::Real num_diff_coeff
Definition: ERF_DataStruct.H:750
std::string windfarm_blade_table
Definition: ERF_DataStruct.H:786
bool fixed_density
Definition: ERF_DataStruct.H:683
amrex::Real zsurf
Definition: ERF_DataStruct.H:715
amrex::Vector< TurbChoice > turbChoice
Definition: ERF_DataStruct.H:676
bool variable_coriolis
Definition: ERF_DataStruct.H:771
bool project_initial_velocity
Definition: ERF_DataStruct.H:718
amrex::Vector< int > anelastic
Definition: ERF_DataStruct.H:681
AdvChoice advChoice
Definition: ERF_DataStruct.H:673
bool use_moist_background
Definition: ERF_DataStruct.H:775
MoistureType moisture_type
Definition: ERF_DataStruct.H:759
bool custom_forcing_prim_vars
Definition: ERF_DataStruct.H:730
std::string abl_geo_wind_table
Definition: ERF_DataStruct.H:767
static TerrainType terrain_type
Definition: ERF_DataStruct.H:659
ABLDriverType abl_driver_type
Definition: ERF_DataStruct.H:764
bool rayleigh_damp_W
Definition: ERF_DataStruct.H:699
PerturbationType pert_type
Definition: ERF_DataStruct.H:746
SpongeChoice spongeChoice
Definition: ERF_DataStruct.H:675
WindFarmType windfarm_type
Definition: ERF_DataStruct.H:760
static InitType init_type
Definition: ERF_DataStruct.H:656
static bool use_real_bcs
Definition: ERF_DataStruct.H:662
int buoyancy_type
Definition: ERF_DataStruct.H:690
amrex::Real poisson_abstol
Definition: ERF_DataStruct.H:685
amrex::Real turb_disk_angle
Definition: ERF_DataStruct.H:788
amrex::Real windfarm_y_shift
Definition: ERF_DataStruct.H:790
bool has_lat_lon
Definition: ERF_DataStruct.H:770
bool do_forest_drag
Definition: ERF_DataStruct.H:793
bool time_avg_vel
Definition: ERF_DataStruct.H:743
bool use_rotate_most
Definition: ERF_DataStruct.H:740
amrex::Real rayleigh_dampcoef
Definition: ERF_DataStruct.H:701
CouplingType coupling_type
Definition: ERF_DataStruct.H:758
std::string windfarm_airfoil_tables
Definition: ERF_DataStruct.H:786
static void set_mesh_type(MeshType new_mesh_type)
Definition: ERF_DataStruct.H:668
int ave_plane
Definition: ERF_DataStruct.H:773
Definition: ERF_SpongeStruct.H:15
void display()
Definition: ERF_SpongeStruct.H:45
void init_params(std::string pp_prefix)
Definition: ERF_SpongeStruct.H:17