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