ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SurfaceLayer.H
Go to the documentation of this file.
1 #ifndef ERF_SURFACELAYER_H
2 #define ERF_SURFACELAYER_H
3 
4 #include "AMReX_Geometry.H"
5 #include "AMReX_ParmParse.H"
6 #include "AMReX_FArrayBox.H"
7 #include "AMReX_MultiFab.H"
8 #include "AMReX_iMultiFab.H"
9 #include "AMReX_MFInterpolater.H"
10 
11 #include "ERF_IndexDefines.H"
12 #include "ERF_Constants.H"
13 #include "ERF_MOSTAverage.H"
14 #include "ERF_MOSTStress.H"
15 #include "ERF_TerrainMetrics.H"
16 #include "ERF_PBLHeight.H"
17 #include "ERF_MicrophysicsUtils.H"
18 
19 /** Abstraction layer for different surface layer schemes (e.g. MOST, Cd)
20  *
21  * van der Laan, P., Kelly, M. C., & Sørensen, N. N. (2017). A new k-epsilon
22  * model consistent with Monin-Obukhov similarity theory. Wind Energy,
23  * 20(3), 479–489. https://doi.org/10.1002/we.2017
24  *
25  * Consistent with Dyer (1974) formulation from page 57, Chapter 2, Modeling
26  * the vertical ABL structure in Modelling of Atmospheric Flow Fields,
27  * Demetri P Lalas and Corrado F Ratto, January 1996,
28  * https://doi.org/10.1142/2975.
29  */
31 {
32 
33 public:
34  // Constructor
35  explicit SurfaceLayer (const amrex::Vector<amrex::Geometry>& geom,
36  bool& use_rot_surface_flux,
37  std::string a_pp_prefix,
38  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Qv_prim,
39  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& z_phys_nd,
40  const MeshType& a_mesh_type,
41  const TerrainType& a_terrain_type,
42  const TurbChoice& a_turb_choice,
43  amrex::Real start_low_time,
44  amrex::Real final_low_time,
45  amrex::Real low_time_interval = 0.0)
46  : m_geom(geom),
47  m_rotate(use_rot_surface_flux),
48  m_start_low_time(start_low_time),
49  m_final_low_time(final_low_time),
50  m_low_time_interval(low_time_interval),
51  m_ma(geom, (z_phys_nd[0] != nullptr), a_pp_prefix, a_mesh_type, a_terrain_type)
52  {
53  // We have a moisture model if Qv_prim is a valid pointer
54  use_moisture = (Qv_prim[0].get());
55 
56  // Get roughness
57  amrex::ParmParse pp("erf");
58  pp.query("most.z0", z0_const);
59 
60  // Specify how to compute the flux
61  if (use_rot_surface_flux) {
63  } else {
64  std::string flux_string_in;
65  std::string flux_string{"moeng"};
66  auto read_flux = pp.query("surface_layer.flux_type", flux_string_in);
67  if (read_flux) {
68  flux_string = amrex::toLower(flux_string_in);
69  }
70  if (flux_string == "donelan") {
72  } else if (flux_string == "moeng") {
74  } else if (flux_string == "rico") {
76  } else if (flux_string == "bulk_coeff") {
78  } else if (flux_string == "custom") {
80  } else {
81  amrex::Abort("Undefined MOST flux type!");
82  }
83  }
84 
85  // Include w* to handle free convection (Beljaars 1995, QJRMS)
86  pp.query("most.include_wstar", m_include_wstar);
87 
88  std::string pblh_string_in;
89  std::string pblh_string{"none"};
90  auto read_pblh = pp.query("most.pblh_calc", pblh_string_in);
91  if (read_pblh) {
92  pblh_string = amrex::toLower(pblh_string_in);
93  }
94  if (pblh_string == "none") {
96  } else if (pblh_string == "mynn25") {
98  } else if (pblh_string == "mynnedmf") {
100  } else if (pblh_string == "ysu") {
102  } else if (pblh_string == "mrf") {
104  } else {
105  amrex::Abort("Undefined PBLH calc type!");
106  }
107 
108  // Get surface temperature
109  auto erf_st = pp.query("most.surf_temp", surf_temp);
110  if (erf_st) { default_land_surf_temp = surf_temp; }
111 
112  // Get surface moisture
113  bool erf_sq = false;
114  if (use_moisture) { erf_sq = pp.query("most.surf_moist", surf_moist); }
115  if (erf_sq) { default_land_surf_moist = surf_moist; }
116 
117  // Custom type user must specify the fluxes
122  pp.get("most.ustar", custom_ustar);
123  pp.get("most.tstar", custom_tstar);
124  pp.get("most.qstar", custom_qstar);
125  pp.query("most.rhosurf", custom_rhosurf);
126  if (custom_qstar != 0) {
128  "Specified custom MOST qv flux without moisture model!");
129  }
130  amrex::Print() << "Using specified ustar, tstar, qstar for MOST = "
131  << custom_ustar << " " << custom_tstar << " "
132  << custom_qstar << std::endl;
133 
134  // Bulk transfer coefficient (must specify coeffs and surface values)
135  } else if (flux_type == FluxCalcType::BULK_COEFF) {
136  pp.get("most.Cd", m_Cd);
137  pp.get("most.Ch", m_Ch);
138  pp.get("most.Cq", m_Cq);
139  pp.get("most.surf_temp", default_land_surf_temp);
140  pp.get("most.surf_moist", default_land_surf_moist);
141  amrex::Print() << "Using specified Cd, Ch, Cq for MOST = "
142  << m_Cd << " " << m_Ch << " "
143  << m_Cq << std::endl;
144 
145  // Specify surface temperature/moisture or surface flux
146  } else {
147  if (erf_st) {
149  pp.query("most.surf_heating_rate", surf_heating_rate); // [K/h]
150  surf_heating_rate = surf_heating_rate / 3600.0; // [K/s]
151  if (pp.query("most.surf_temp_flux", surf_temp_flux)) {
152  amrex::Abort("Can only specify one of surf_temp_flux or surf_heating_rate");
153  }
154  } else {
155  pp.query("most.surf_temp_flux", surf_temp_flux);
156 
157  if (pp.query("most.surf_heating_rate", surf_heating_rate)) {
158  amrex::Abort("Can only specify one of surf_temp_flux or surf_heating_rate");
159  }
160  if (std::abs(surf_temp_flux) >
163  } else {
165  }
166  }
167 
168  if (erf_sq) {
170  } else {
171  pp.query("most.surf_moist_flux", surf_moist_flux);
172  if (std::abs(surf_moist_flux) >
175  } else {
177  }
178  }
179  }
180 
182  {
183  pp.query("most.rico.theta_z0", rico_theta_z0);
184  pp.query("most.rico.qsat_z0", rico_qsat_z0);
185  }
186 
187  // Make sure the inputs file doesn't try to use most.roughness_type
188  std::string bogus_input;
189  if (pp.query("most.roughness_type", bogus_input) > 0) {
190  amrex::Abort("most.roughness_type is deprecated; use "
191  "most.roughness_type_land and/or most.roughness_type_sea");
192  }
193 
194  // Specify how to compute the surface flux over land (if there is any)
195  std::string rough_land_string_in;
196  std::string rough_land_string{"constant"};
197  auto read_rough_land =
198  pp.query("most.roughness_type_land", rough_land_string_in);
199  if (read_rough_land) {
200  rough_land_string = amrex::toLower(rough_land_string_in);
201  }
202  if (rough_land_string == "constant") {
204  } else {
205  amrex::Abort("Undefined MOST roughness type for land!");
206  }
207 
208  // Specify how to compute the surface flux over sea (if there is any)
209  std::string rough_sea_string_in;
210  std::string rough_sea_string{"charnock"};
211  auto read_rough_sea = pp.query("most.roughness_type_sea", rough_sea_string_in);
212  if (read_rough_sea) {
213  rough_sea_string = amrex::toLower(rough_sea_string_in);
214  }
215  if (rough_sea_string == "charnock") {
217  pp.query("most.charnock_constant", cnk_a);
218  pp.query("most.charnock_viscosity", cnk_visc);
219  if (cnk_a > 0) {
220  amrex::Print() << "If there is water, Charnock relation with C_a="
221  << cnk_a << (cnk_visc ? " and viscosity" : "")
222  << " will be used" << std::endl;
223  } else {
224  amrex::Print() << "If there is water, Charnock relation with variable "
225  "Charnock parameter (COARE3.0)"
226  << (cnk_visc ? " and viscosity" : "") << " will be used"
227  << std::endl;
228  }
229  } else if (rough_sea_string == "coare3.0") {
231  amrex::Print() << "If there is water, Charnock relation with variable "
232  "Charnock parameter (COARE3.0)"
233  << (cnk_visc ? " and viscosity" : "") << " will be used"
234  << std::endl;
235  cnk_a = -1;
236  } else if (rough_sea_string == "donelan") {
238  } else if (rough_sea_string == "modified_charnock") {
240  pp.query("most.modified_charnock_depth", depth);
241  } else if (rough_sea_string == "wave_coupled") {
243  } else if (rough_sea_string == "constant") {
245  } else {
246  amrex::Abort("Undefined MOST roughness type for sea!");
247  }
248 
249  // use skin temperature instead of sea-surface temperature
250  // (wrfinput data may have lower resolution SST data)
251  pp.query("most.ignore_sst", m_ignore_sst);
252 
253  // If we're using the RANS k model, then we need to update the dirichlet
254  // BC based on the instantaneous u* and θ*; the turbulence modeling
255  // choices can vary per level but for now, assume that if specified then
256  // all levels are using the same RANS model.
257  m_update_k_rans = (a_turb_choice.rans_type == RANSType::kEqn &&
258  a_turb_choice.dirichlet_k == true);
259  if (m_update_k_rans) {
260  inv_Cmu2 = 1.0 / (a_turb_choice.Cmu0 * a_turb_choice.Cmu0);
261  theta_ref = a_turb_choice.theta_ref;
262  }
263 
264  } // constructor
265 
266  void make_SurfaceLayer_at_level (const int& lev,
267  int nlevs,
268  const amrex::Vector<amrex::MultiFab*>& mfv,
269  std::unique_ptr<amrex::MultiFab>& Theta_prim,
270  std::unique_ptr<amrex::MultiFab>& Qv_prim,
271  std::unique_ptr<amrex::MultiFab>& Qr_prim,
272  std::unique_ptr<amrex::MultiFab>& z_phys_nd,
273  amrex::MultiFab* Hwave,
274  amrex::MultiFab* Lwave,
275  amrex::MultiFab* eddyDiffs,
276  amrex::Vector<amrex::MultiFab*> lsm_data,
277  amrex::Vector<std::string> lsm_data_name,
278  amrex::Vector<amrex::MultiFab*> lsm_flux,
279  amrex::Vector<std::string> lsm_flux_name,
280  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& sst_lev,
281  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& tsk_lev,
282  amrex::Vector<std::unique_ptr<amrex::iMultiFab>>& lmask_lev)
283  {
284  // Update MOST Average
286  Theta_prim, Qv_prim, Qr_prim,
287  z_phys_nd);
288 
289  // Get CC vars
290  amrex::MultiFab& mf = *(mfv[0]);
291 
292  amrex::ParmParse pp("erf");
293 
294  // Do we have a time-varying surface roughness that needs to be saved?
295  if (lev == 0) {
296  const int nghost = 0; // ghost cells not included
297  int lmask_min = lmask_min_reduce(*lmask_lev[0].get(), nghost);
298  amrex::ParallelDescriptor::ReduceIntMin(lmask_min);
299 
300  m_var_z0 = (lmask_min < 1) & (rough_type_sea != RoughCalcType::CONSTANT);
301  if (m_var_z0) {
302  std::string rough_sea_string{"charnock"};
303  pp.query("most.roughness_type_sea", rough_sea_string);
304  amrex::Print() << "Variable sea roughness (type " << rough_sea_string
305  << ")" << std::endl;
306  }
307  }
308 
309  if (m_eddyDiffs_lev.size() < lev+1) {
310  m_Hwave_lev.resize(nlevs);
311  m_Lwave_lev.resize(nlevs);
312  m_eddyDiffs_lev.resize(nlevs);
313 
314  m_lsm_data_lev.resize(nlevs);
315  m_lsm_flux_lev.resize(nlevs);
316 
317  m_sst_lev.resize(nlevs);
318  m_tsk_lev.resize(nlevs);
319  m_lmask_lev.resize(nlevs);
320 
321  // Size the MOST params for all levels
322  z_0.resize(nlevs);
323  u_star.resize(nlevs);
324  w_star.resize(nlevs);
325  t_star.resize(nlevs);
326  q_star.resize(nlevs);
327  t_surf.resize(nlevs);
328  q_surf.resize(nlevs);
329  olen.resize(nlevs);
330  pblh.resize(nlevs);
331  }
332 
333  // Get pointers to SST,TSK and LANDMASK data
334  int nt_tot_sst = sst_lev.size();
335  m_sst_lev[lev].resize(nt_tot_sst);
336  for (int nt(0); nt < nt_tot_sst; ++nt) {
337  m_sst_lev[lev][nt] = sst_lev[nt].get();
338  }
339  int nt_tot_tsk = static_cast<int>(tsk_lev.size());
340  m_tsk_lev[lev].resize(nt_tot_tsk);
341  for (int nt(0); nt < nt_tot_tsk; ++nt) {
342  m_tsk_lev[lev][nt] = tsk_lev[nt].get();
343  }
344  int nt_tot_lmask = static_cast<int>(lmask_lev.size());
345  m_lmask_lev[lev].resize(nt_tot_lmask);
346  for (int nt(0); nt < nt_tot_lmask; ++nt) {
347  m_lmask_lev[lev][nt] = lmask_lev[nt].get();
348  }
349 
350  // Get pointers to wave data
351  m_Hwave_lev[lev] = Hwave;
352  m_Lwave_lev[lev] = Lwave;
353  m_eddyDiffs_lev[lev] = eddyDiffs;
354 
355  // Get pointers to LSM data and Fluxes
356  int ndata = static_cast<int>(lsm_data.size());
357  int nflux = static_cast<int>(lsm_flux.size());
358  m_lsm_data_name.resize(ndata);
359  m_lsm_data_lev[lev].resize(ndata);
360  m_lsm_flux_name.resize(nflux);
361  m_lsm_flux_lev[lev].resize(nflux);
362  for (int n(0); n < ndata; ++n) {
363  m_lsm_data_name[n] = lsm_data_name[n];
364  m_lsm_data_lev[lev][n] = lsm_data[n];
365  if (amrex::toLower(lsm_data_name[n]) == "theta") {
366  m_has_lsm_tsurf = true;
367  m_lsm_tsurf_indx = n;
368  }
369  }
370  for (int n(0); n < nflux; ++n) {
371  m_lsm_flux_name[n] = lsm_flux_name[n];
372  m_lsm_flux_lev[lev][n] = lsm_flux[n];
373  }
374 
375  // Check if there is a user-specified roughness file to be read
376  std::string fname;
377  bool read_z0 = false;
378  if ( (flux_type == FluxCalcType::MOENG) ||
380  int count = pp.countval("most.roughness_file_name");
381  if (count > 1) {
382  AMREX_ALWAYS_ASSERT(count >= lev+1);
383  pp.query("most.roughness_file_name", fname, lev);
384  read_z0 = true;
385  } else if (count == 1) {
386  if (lev == 0) {
387  pp.query("most.roughness_file_name", fname);
388  } else {
389  // we will interpolate from the coarsest level
390  fname = "";
391  }
392  read_z0 = true;
393  }
394  // else use z0_const
395  }
396 
397  // Attributes for MFs and FABs
398  //--------------------------------------------------------
399  // Create a 2D ba, dm, & ghost cells
400  amrex::BoxArray ba = mf.boxArray();
401  amrex::BoxList bl2d = ba.boxList();
402  for (auto& b : bl2d) { b.setRange(2,0); }
403  amrex::BoxArray ba2d(std::move(bl2d));
404  const amrex::DistributionMapping& dm = mf.DistributionMap();
405  const int ncomp = 1;
406  amrex::IntVect ng{1,1,0};
407 
408  // Z0 heights FAB
409  //--------------------------------------------------------
410  z_0[lev].define(ba2d, dm, ncomp, ng);
411  z_0[lev].setVal(z0_const);
412  if (read_z0) {
413  read_custom_roughness(lev, fname);
414  }
415 
416  // 2D MFs for U*, T*, T_surf
417  //--------------------------------------------------------
418  u_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
419  u_star[lev]->setVal(1.E34);
420 
421  w_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
422  w_star[lev]->setVal(1.E34);
423 
424  t_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
425  t_star[lev]->setVal(0.0); // default to neutral
426 
427  q_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
428  q_star[lev]->setVal(0.0); // default to dry
429 
430  olen[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
431  olen[lev]->setVal(1.E34);
432 
433  pblh[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
434  pblh[lev]->setVal(1.E34);
435 
436  t_surf[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
437  t_surf[lev]->setVal(default_land_surf_temp);
438 
439  q_surf[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
440  q_surf[lev]->setVal(default_land_surf_moist);
441 
442  // TODO: Do we want an enum struct for indexing?
443 
444  bool use_sst = (!m_sst_lev[lev].empty() && m_sst_lev[lev][0]);
445  bool use_tsk = (!m_tsk_lev[lev].empty() && m_tsk_lev[lev][0]);
446  if (use_sst || use_tsk || m_has_lsm_tsurf) {
447  // Valid SST, TSK or LSM data; t_surf set before computing fluxes (avoids
448  // extended lambda capture) Note that land temp will be set from m_tsk_lev
449  // while sea temp will be set from m_sst_lev
451 
452  // Pathways in fill_tsurf_with_sst_and_tsk
453  amrex::Print() << "Using MOST with specified surface temperature ";
454  // NOTE: SST from the LOW file populates TSK in update_sst_tsk.
455  // So if we have TSK, it contains everything and has been
456  // sanity checked for valid SST values.
457  if (use_tsk) { m_ignore_sst = true; }
458  if (use_tsk) {
459  amrex::Print() << "(land: TSK, ";
460  } else {
461  amrex::Print() << "(land: T0, ";
462  }
463  if (use_tsk && !use_sst) {
464  amrex::Print() << "sea: TSK)" << std::endl;
465  } else {
466  amrex::Print() << "sea: SST)" << std::endl;
468  }
469  }
470  }
471 
472  void
473  update_fluxes (const int& lev,
474  const amrex::Real& elapsed_time_since_start_low,
475  amrex::MultiFab& cons_in,
476  const std::unique_ptr<amrex::MultiFab>& z_phys_nd,
477  const std::unique_ptr<amrex::MultiFab>& walldist,
478  int max_iters = 100);
479 
480  template <typename FluxIter>
481  void compute_fluxes (const int& lev,
482  const int& max_iters,
483  amrex::MultiFab& cons_in,
484  const FluxIter& most_flux,
485  bool is_land);
486 
487  void init_tke_from_ustar (const int& lev,
488  amrex::MultiFab& cons,
489  const std::unique_ptr<amrex::MultiFab>& z_phys_nd,
490  const amrex::Real tkefac = 1.0,
491  const amrex::Real zscale = 700.0);
492 
493  void impose_SurfaceLayer_bcs (const int& lev,
494  amrex::Vector<const amrex::MultiFab*> mfs,
495  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_lev,
496  amrex::MultiFab* xheat_flux,
497  amrex::MultiFab* yheat_flux,
498  amrex::MultiFab* zheat_flux,
499  amrex::MultiFab* xqv_flux,
500  amrex::MultiFab* yqv_flux,
501  amrex::MultiFab* zqv_flux,
502  const amrex::MultiFab* z_phys);
503 
504  template <typename FluxCalc>
505  void compute_SurfaceLayer_bcs (const int& lev,
506  amrex::Vector<const amrex::MultiFab*> mfs,
507  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_lev,
508  amrex::MultiFab* xheat_flux,
509  amrex::MultiFab* yheat_flux,
510  amrex::MultiFab* zheat_flux,
511  amrex::MultiFab* xqv_flux,
512  amrex::MultiFab* yqv_flux,
513  amrex::MultiFab* zqv_flux,
514  const amrex::MultiFab* z_phys,
515  const FluxCalc& flux_comp);
516 
517  void fill_tsurf_with_sst_and_tsk (const int& lev,
518  const amrex::Real& time);
519 
520  void fill_qsurf_with_qsat (const int& lev,
521  const amrex::MultiFab& cons_in,
522  const std::unique_ptr<amrex::MultiFab>& z_phys_nd);
523 
524  void get_lsm_tsurf (const int& lev);
525 
526  /* wrapper around compute_pblh */
527  void update_pblh (const int& lev,
528  amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars,
529  amrex::MultiFab* z_phys_cc,
530  const MoistureComponentIndices& moisture_indices);
531 
532  template <typename PBLHeightEstimator>
533  void compute_pblh (const int& lev,
534  amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars,
535  amrex::MultiFab* z_phys_cc,
536  const PBLHeightEstimator& est,
537  const MoistureComponentIndices& moisture_indice);
538 
539  void read_custom_roughness (const int& lev,
540  const std::string& fname);
541 
542  void update_surf_temp (const amrex::Real& time)
543  {
544  if (surf_heating_rate != 0) {
545  int nlevs = static_cast<int>(m_geom.size());
546  for (int lev = 0; lev < nlevs; lev++) {
547  t_surf[lev]->setVal(surf_temp + surf_heating_rate * time);
548  amrex::Print() << "Surface temp at t=" << time << ": "
549  << surf_temp + surf_heating_rate * time << std::endl;
550  }
551  }
552  }
553 
554  void update_mac_ptrs (const int& lev,
555  amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars_old,
556  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Theta_prim,
557  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Qv_prim,
558  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Qr_prim)
559  {
560  m_ma.update_field_ptrs(lev, vars_old, Theta_prim, Qv_prim, Qr_prim);
561  }
562 
563  amrex::MultiFab* get_u_star (const int& lev) { return u_star[lev].get(); }
564 
565  amrex::MultiFab* get_w_star (const int& lev) { return w_star[lev].get(); }
566 
567  amrex::MultiFab* get_t_star (const int& lev) { return t_star[lev].get(); }
568 
569  amrex::MultiFab* get_q_star (const int& lev) { return q_star[lev].get(); }
570 
571  amrex::MultiFab* get_olen (const int& lev) { return olen[lev].get(); }
572 
573  amrex::MultiFab* get_pblh (const int& lev) { return pblh[lev].get(); }
574 
575  const amrex::MultiFab* get_mac_avg (const int& lev, int comp)
576  {
577  return m_ma.get_average(lev, comp);
578  }
579 
580  amrex::MultiFab* get_t_surf (const int& lev) { return t_surf[lev].get(); }
581  void set_t_surf(const int& lev, const amrex::Real tsurf) { t_surf[lev]->setVal(tsurf); }
582 
583  amrex::MultiFab* get_q_surf (const int& lev) { return q_surf[lev].get(); }
584  void set_q_surf(const int& lev, const amrex::Real qsurf) { q_surf[lev]->setVal(qsurf); }
585 
586  amrex::Real get_zref (const int& lev) { return (m_ma.get_zref(lev))->min(0); }
587 
588  amrex::MultiFab* get_z0 (const int& lev) { return &z_0[lev]; }
589 
591 
592  amrex::iMultiFab* get_lmask (const int& lev) { return m_lmask_lev[lev][0]; }
593 
594  int lmask_min_reduce (amrex::iMultiFab& lmask,
595  const int& nghost)
596  {
597  int lmask_min = amrex::ReduceMin(lmask, nghost, [=] AMREX_GPU_HOST_DEVICE(
598  amrex::Box const& bx, amrex::Array4<int const> const& lm_arr) -> int
599  {
600  int locmin = std::numeric_limits<int>::max();
601  const auto lo = lbound(bx);
602  const auto hi = ubound(bx);
603  for (int j = lo.y; j <= hi.y; ++j) {
604  for (int i = lo.x; i <= hi.x; ++i) {
605  locmin = std::min(locmin, lm_arr(i, j, 0));
606  }
607  }
608  return locmin;
609  });
610 
611  return lmask_min;
612  }
613 
614  void update_sst_ptr(const int lev, const int itime, amrex::MultiFab* sst_ptr) {
615  m_sst_lev[lev][itime] = sst_ptr;
616  }
617 
618  void update_tsk_ptr(const int lev, const int itime, amrex::MultiFab* tsk_ptr) {
619  m_tsk_lev[lev][itime] = tsk_ptr;
620  }
621 
622  enum struct FluxCalcType {
623  MOENG = 0, ///< Moeng functional form
624  DONELAN, ///< Donelan functional form
625  CUSTOM, ///< Custom constant flux functional form
626  BULK_COEFF, ///< Bulk transfer coefficient functional form
627  ROTATE, ///< Terrain rotation flux functional form
628  RICO
629  };
630 
631  enum struct ThetaCalcType {
632  ADIABATIC = 0,
633  HEAT_FLUX, ///< Heat-flux specified
634  SURFACE_TEMPERATURE ///< Surface temperature specified
635  };
636 
637  enum struct MoistCalcType {
638  ADIABATIC = 0,
639  MOISTURE_FLUX, ///< Qv-flux specified
640  SURFACE_MOISTURE ///< Surface Qv specified
641  };
642 
643  enum struct RoughCalcType {
644  CONSTANT = 0, ///< Constant z0
645  CHARNOCK,
647  DONELAN,
649  };
650 
651  enum struct PBLHeightCalcType { None, MYNN25, YSU, MRF };
652 
659 
660 private:
661  // Set in constructor
662  amrex::Vector<amrex::Geometry> m_geom;
663  bool m_rotate = false;
667 
668  bool m_include_wstar = false;
680  amrex::Real custom_rhosurf{0}; // use specified value instead of rho from first cell
681  bool specified_rho_surf{false};
683  bool cnk_visc{false};
685  amrex::Vector<amrex::MultiFab> z_0;
686  bool m_var_z0{false};
687 
690 
692  bool m_has_lsm_tsurf = false;
694 
698 
699  bool m_ignore_sst = false;
700 
702  amrex::Vector<std::unique_ptr<amrex::MultiFab>> u_star;
703  amrex::Vector<std::unique_ptr<amrex::MultiFab>> w_star;
704  amrex::Vector<std::unique_ptr<amrex::MultiFab>> t_star;
705  amrex::Vector<std::unique_ptr<amrex::MultiFab>> q_star;
706  amrex::Vector<std::unique_ptr<amrex::MultiFab>> olen;
707  amrex::Vector<std::unique_ptr<amrex::MultiFab>> pblh;
708  amrex::Vector<std::unique_ptr<amrex::MultiFab>> t_surf;
709  amrex::Vector<std::unique_ptr<amrex::MultiFab>> q_surf;
710 
711  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_sst_lev;
712  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_tsk_lev;
713  amrex::Vector<amrex::Vector<amrex::iMultiFab*>> m_lmask_lev;
714  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_lsm_data_lev;
715  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_lsm_flux_lev;
716  amrex::Vector<std::string> m_lsm_data_name;
717  amrex::Vector<std::string> m_lsm_flux_name;
718  amrex::Vector<amrex::MultiFab*> m_Hwave_lev;
719  amrex::Vector<amrex::MultiFab*> m_Lwave_lev;
720  amrex::Vector<amrex::MultiFab*> m_eddyDiffs_lev;
721 
722  bool m_update_k_rans = false;
725 };
726 
727 #endif /* SURFACELAYER_H */
ParmParse pp("prob")
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
pp get("wavelength", wavelength)
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_ASSERT_WITH_MESSAGE(wbar_cutoff_min > wbar_cutoff_max, "ERROR: wbar_cutoff_min < wbar_cutoff_max")
Definition: ERF_MOSTAverage.H:14
amrex::MultiFab * get_zref(const int &lev) const
Definition: ERF_MOSTAverage.H:105
const amrex::MultiFab * get_average(const int &lev, const int &comp) const
Definition: ERF_MOSTAverage.H:102
void update_field_ptrs(const int &lev, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_old, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Theta_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qv_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qr_prim)
Definition: ERF_MOSTAverage.cpp:265
void make_MOSTAverage_at_level(const int &lev, const amrex::Vector< amrex::MultiFab * > &vars_old, std::unique_ptr< amrex::MultiFab > &Theta_prim, std::unique_ptr< amrex::MultiFab > &Qv_prim, std::unique_ptr< amrex::MultiFab > &Qr_prim, std::unique_ptr< amrex::MultiFab > &z_phys_nd)
Definition: ERF_MOSTAverage.cpp:85
Definition: ERF_SurfaceLayer.H:31
ThetaCalcType theta_type
Definition: ERF_SurfaceLayer.H:654
int lmask_min_reduce(amrex::iMultiFab &lmask, const int &nghost)
Definition: ERF_SurfaceLayer.H:594
amrex::Vector< std::string > m_lsm_data_name
Definition: ERF_SurfaceLayer.H:716
bool m_include_wstar
Definition: ERF_SurfaceLayer.H:668
bool specified_rho_surf
Definition: ERF_SurfaceLayer.H:681
void set_q_surf(const int &lev, const amrex::Real qsurf)
Definition: ERF_SurfaceLayer.H:584
bool m_rotate
Definition: ERF_SurfaceLayer.H:663
PBLHeightCalcType pblh_type
Definition: ERF_SurfaceLayer.H:658
amrex::Vector< amrex::Vector< amrex::iMultiFab * > > m_lmask_lev
Definition: ERF_SurfaceLayer.H:713
amrex::iMultiFab * get_lmask(const int &lev)
Definition: ERF_SurfaceLayer.H:592
bool use_moisture
Definition: ERF_SurfaceLayer.H:691
amrex::MultiFab * get_q_surf(const int &lev)
Definition: ERF_SurfaceLayer.H:583
void init_tke_from_ustar(const int &lev, amrex::MultiFab &cons, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, const amrex::Real tkefac=1.0, const amrex::Real zscale=700.0)
Definition: ERF_SurfaceLayer.cpp:789
bool m_has_lsm_tsurf
Definition: ERF_SurfaceLayer.H:692
amrex::MultiFab * get_w_star(const int &lev)
Definition: ERF_SurfaceLayer.H:565
void update_surf_temp(const amrex::Real &time)
Definition: ERF_SurfaceLayer.H:542
amrex::Real m_Cq
Definition: ERF_SurfaceLayer.H:697
RoughCalcType rough_type_land
Definition: ERF_SurfaceLayer.H:656
void update_pblh(const int &lev, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars, amrex::MultiFab *z_phys_cc, const MoistureComponentIndices &moisture_indices)
Definition: ERF_SurfaceLayer.cpp:762
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_surf
Definition: ERF_SurfaceLayer.H:708
amrex::Real z0_const
Definition: ERF_SurfaceLayer.H:669
amrex::Real cnk_a
Definition: ERF_SurfaceLayer.H:682
amrex::Real m_Ch
Definition: ERF_SurfaceLayer.H:696
amrex::Real m_start_low_time
Definition: ERF_SurfaceLayer.H:664
amrex::Real surf_temp
Definition: ERF_SurfaceLayer.H:671
void update_mac_ptrs(const int &lev, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_old, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Theta_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qv_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qr_prim)
Definition: ERF_SurfaceLayer.H:554
void compute_pblh(const int &lev, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars, amrex::MultiFab *z_phys_cc, const PBLHeightEstimator &est, const MoistureComponentIndices &moisture_indice)
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_star
Definition: ERF_SurfaceLayer.H:705
int m_lsm_tsurf_indx
Definition: ERF_SurfaceLayer.H:693
amrex::Real rico_qsat_z0
Definition: ERF_SurfaceLayer.H:689
bool m_update_k_rans
Definition: ERF_SurfaceLayer.H:722
amrex::Vector< amrex::MultiFab * > m_Lwave_lev
Definition: ERF_SurfaceLayer.H:719
void get_lsm_tsurf(const int &lev)
Definition: ERF_SurfaceLayer.cpp:727
void fill_qsurf_with_qsat(const int &lev, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd)
Definition: ERF_SurfaceLayer.cpp:684
amrex::Real get_zref(const int &lev)
Definition: ERF_SurfaceLayer.H:586
amrex::MultiFab * get_olen(const int &lev)
Definition: ERF_SurfaceLayer.H:571
amrex::Vector< amrex::MultiFab > z_0
Definition: ERF_SurfaceLayer.H:685
amrex::Real surf_moist_flux
Definition: ERF_SurfaceLayer.H:676
void compute_SurfaceLayer_bcs(const int &lev, amrex::Vector< const amrex::MultiFab * > mfs, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_lev, amrex::MultiFab *xheat_flux, amrex::MultiFab *yheat_flux, amrex::MultiFab *zheat_flux, amrex::MultiFab *xqv_flux, amrex::MultiFab *yqv_flux, amrex::MultiFab *zqv_flux, const amrex::MultiFab *z_phys, const FluxCalc &flux_comp)
RoughCalcType rough_type_sea
Definition: ERF_SurfaceLayer.H:657
amrex::Real surf_moist
Definition: ERF_SurfaceLayer.H:675
amrex::Vector< std::unique_ptr< amrex::MultiFab > > w_star
Definition: ERF_SurfaceLayer.H:703
bool m_ignore_sst
Definition: ERF_SurfaceLayer.H:699
amrex::MultiFab * get_u_star(const int &lev)
Definition: ERF_SurfaceLayer.H:563
void compute_fluxes(const int &lev, const int &max_iters, amrex::MultiFab &cons_in, const FluxIter &most_flux, bool is_land)
void update_fluxes(const int &lev, const amrex::Real &elapsed_time_since_start_low, amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, const std::unique_ptr< amrex::MultiFab > &walldist, int max_iters=100)
Definition: ERF_SurfaceLayer.cpp:12
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_data_lev
Definition: ERF_SurfaceLayer.H:714
void set_t_surf(const int &lev, const amrex::Real tsurf)
Definition: ERF_SurfaceLayer.H:581
amrex::Real custom_qstar
Definition: ERF_SurfaceLayer.H:679
amrex::Vector< std::unique_ptr< amrex::MultiFab > > u_star
Definition: ERF_SurfaceLayer.H:702
void update_tsk_ptr(const int lev, const int itime, amrex::MultiFab *tsk_ptr)
Definition: ERF_SurfaceLayer.H:618
amrex::Real custom_rhosurf
Definition: ERF_SurfaceLayer.H:680
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_surf
Definition: ERF_SurfaceLayer.H:709
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_sst_lev
Definition: ERF_SurfaceLayer.H:711
FluxCalcType
Definition: ERF_SurfaceLayer.H:622
@ MOENG
Moeng functional form.
@ BULK_COEFF
Bulk transfer coefficient functional form.
@ CUSTOM
Custom constant flux functional form.
@ ROTATE
Terrain rotation flux functional form.
@ DONELAN
Donelan functional form.
MoistCalcType
Definition: ERF_SurfaceLayer.H:637
@ SURFACE_MOISTURE
Surface Qv specified.
@ MOISTURE_FLUX
Qv-flux specified.
amrex::Real depth
Definition: ERF_SurfaceLayer.H:684
amrex::Vector< amrex::MultiFab * > m_Hwave_lev
Definition: ERF_SurfaceLayer.H:718
amrex::Real default_land_surf_moist
Definition: ERF_SurfaceLayer.H:674
bool m_var_z0
Definition: ERF_SurfaceLayer.H:686
amrex::MultiFab * get_t_star(const int &lev)
Definition: ERF_SurfaceLayer.H:567
bool have_variable_sea_roughness()
Definition: ERF_SurfaceLayer.H:590
amrex::MultiFab * get_q_star(const int &lev)
Definition: ERF_SurfaceLayer.H:569
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_flux_lev
Definition: ERF_SurfaceLayer.H:715
PBLHeightCalcType
Definition: ERF_SurfaceLayer.H:651
amrex::MultiFab * get_pblh(const int &lev)
Definition: ERF_SurfaceLayer.H:573
amrex::Real rico_theta_z0
Definition: ERF_SurfaceLayer.H:688
void fill_tsurf_with_sst_and_tsk(const int &lev, const amrex::Real &time)
Definition: ERF_SurfaceLayer.cpp:597
amrex::Real surf_temp_flux
Definition: ERF_SurfaceLayer.H:673
amrex::Vector< amrex::Geometry > m_geom
Definition: ERF_SurfaceLayer.H:662
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_star
Definition: ERF_SurfaceLayer.H:704
amrex::Real theta_ref
Definition: ERF_SurfaceLayer.H:724
amrex::MultiFab * get_z0(const int &lev)
Definition: ERF_SurfaceLayer.H:588
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_tsk_lev
Definition: ERF_SurfaceLayer.H:712
SurfaceLayer(const amrex::Vector< amrex::Geometry > &geom, bool &use_rot_surface_flux, std::string a_pp_prefix, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Qv_prim, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &z_phys_nd, const MeshType &a_mesh_type, const TerrainType &a_terrain_type, const TurbChoice &a_turb_choice, amrex::Real start_low_time, amrex::Real final_low_time, amrex::Real low_time_interval=0.0)
Definition: ERF_SurfaceLayer.H:35
amrex::Real custom_tstar
Definition: ERF_SurfaceLayer.H:678
amrex::Real m_final_low_time
Definition: ERF_SurfaceLayer.H:665
bool cnk_visc
Definition: ERF_SurfaceLayer.H:683
amrex::Real surf_heating_rate
Definition: ERF_SurfaceLayer.H:672
void make_SurfaceLayer_at_level(const int &lev, int nlevs, const amrex::Vector< amrex::MultiFab * > &mfv, std::unique_ptr< amrex::MultiFab > &Theta_prim, std::unique_ptr< amrex::MultiFab > &Qv_prim, std::unique_ptr< amrex::MultiFab > &Qr_prim, std::unique_ptr< amrex::MultiFab > &z_phys_nd, amrex::MultiFab *Hwave, amrex::MultiFab *Lwave, amrex::MultiFab *eddyDiffs, amrex::Vector< amrex::MultiFab * > lsm_data, amrex::Vector< std::string > lsm_data_name, amrex::Vector< amrex::MultiFab * > lsm_flux, amrex::Vector< std::string > lsm_flux_name, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &sst_lev, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &tsk_lev, amrex::Vector< std::unique_ptr< amrex::iMultiFab >> &lmask_lev)
Definition: ERF_SurfaceLayer.H:266
RoughCalcType
Definition: ERF_SurfaceLayer.H:643
FluxCalcType flux_type
Definition: ERF_SurfaceLayer.H:653
MoistCalcType moist_type
Definition: ERF_SurfaceLayer.H:655
amrex::Real inv_Cmu2
Definition: ERF_SurfaceLayer.H:723
void impose_SurfaceLayer_bcs(const int &lev, amrex::Vector< const amrex::MultiFab * > mfs, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_lev, amrex::MultiFab *xheat_flux, amrex::MultiFab *yheat_flux, amrex::MultiFab *zheat_flux, amrex::MultiFab *xqv_flux, amrex::MultiFab *yqv_flux, amrex::MultiFab *zqv_flux, const amrex::MultiFab *z_phys)
Definition: ERF_SurfaceLayer.cpp:310
amrex::Vector< amrex::MultiFab * > m_eddyDiffs_lev
Definition: ERF_SurfaceLayer.H:720
const amrex::MultiFab * get_mac_avg(const int &lev, int comp)
Definition: ERF_SurfaceLayer.H:575
void update_sst_ptr(const int lev, const int itime, amrex::MultiFab *sst_ptr)
Definition: ERF_SurfaceLayer.H:614
amrex::Real custom_ustar
Definition: ERF_SurfaceLayer.H:677
amrex::Vector< std::unique_ptr< amrex::MultiFab > > olen
Definition: ERF_SurfaceLayer.H:706
amrex::MultiFab * get_t_surf(const int &lev)
Definition: ERF_SurfaceLayer.H:580
amrex::Real m_Cd
Definition: ERF_SurfaceLayer.H:695
amrex::Vector< std::unique_ptr< amrex::MultiFab > > pblh
Definition: ERF_SurfaceLayer.H:707
amrex::Real default_land_surf_temp
Definition: ERF_SurfaceLayer.H:670
ThetaCalcType
Definition: ERF_SurfaceLayer.H:631
@ SURFACE_TEMPERATURE
Surface temperature specified.
@ HEAT_FLUX
Heat-flux specified.
void read_custom_roughness(const int &lev, const std::string &fname)
Definition: ERF_SurfaceLayer.cpp:858
amrex::Vector< std::string > m_lsm_flux_name
Definition: ERF_SurfaceLayer.H:717
amrex::Real m_low_time_interval
Definition: ERF_SurfaceLayer.H:666
MOSTAverage m_ma
Definition: ERF_SurfaceLayer.H:701
@ ng
Definition: ERF_Morrison.H:48
@ cons
Definition: ERF_IndexDefines.H:156
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
Definition: ERF_DataStruct.H:106
Definition: ERF_TurbStruct.H:42
RANSType rans_type
Definition: ERF_TurbStruct.H:413
bool dirichlet_k
Definition: ERF_TurbStruct.H:415
amrex::Real Cmu0
Definition: ERF_TurbStruct.H:391
amrex::Real theta_ref
Definition: ERF_TurbStruct.H:402