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  amrex::Real start_time,
43  amrex::Real stop_time,
44  amrex::Real bdy_time_interval = 0.0)
45  : m_geom(geom),
46  m_rotate(use_rot_surface_flux),
47  m_start_time(start_time),
48  m_stop_time(stop_time),
49  m_bdy_time_interval(bdy_time_interval),
50  m_ma(geom, (z_phys_nd[0] != nullptr), a_pp_prefix, a_mesh_type, a_terrain_type)
51  {
52  // We have a moisture model if Qv_prim is a valid pointer
53  use_moisture = (Qv_prim[0].get());
54 
55  // Get roughness
56  amrex::ParmParse pp("erf");
57  pp.query("most.z0", z0_const);
58 
59  // Specify how to compute the flux
60  if (use_rot_surface_flux) {
62  } else {
63  std::string flux_string_in;
64  std::string flux_string{"moeng"};
65  auto read_flux = pp.query("surface_layer.flux_type", flux_string_in);
66  if (read_flux) {
67  flux_string = amrex::toLower(flux_string_in);
68  }
69  if (flux_string == "donelan") {
71  } else if (flux_string == "moeng") {
73  } else if (flux_string == "bulk_coeff") {
75  } else if (flux_string == "custom") {
77  } else {
78  amrex::Abort("Undefined MOST flux type!");
79  }
80  }
81 
82  // Include w* to handle free convection (Beljaars 1995, QJRMS)
83  pp.query("most.include_wstar", m_include_wstar);
84 
85  std::string pblh_string_in;
86  std::string pblh_string{"none"};
87  auto read_pblh = pp.query("most.pblh_calc", pblh_string_in);
88  if (read_pblh) {
89  pblh_string = amrex::toLower(pblh_string_in);
90  }
91  if (pblh_string == "none") {
93  } else if (pblh_string == "mynn25") {
95  } else if (pblh_string == "mynnedmf") {
97  } else if (pblh_string == "ysu") {
99  } else if (pblh_string == "mrf") {
101  } else {
102  amrex::Abort("Undefined PBLH calc type!");
103  }
104 
105  // Get surface temperature
106  auto erf_st = pp.query("most.surf_temp", surf_temp);
107  if (erf_st) { default_land_surf_temp = surf_temp; }
108 
109  // Get surface moisture
110  bool erf_sq = false;
111  if (use_moisture) { erf_sq = pp.query("most.surf_moist", surf_moist); }
112  if (erf_sq) { default_land_surf_moist = surf_moist; }
113 
114  // Custom type user must specify the fluxes
118  pp.get("most.ustar", custom_ustar);
119  pp.get("most.tstar", custom_tstar);
120  pp.get("most.qstar", custom_qstar);
121  pp.query("most.rhosurf", custom_rhosurf);
122  if (custom_qstar != 0) {
123  AMREX_ASSERT_WITH_MESSAGE(use_moisture,
124  "Specified custom MOST qv flux without moisture model!");
125  }
126  amrex::Print() << "Using specified ustar, tstar, qstar for MOST = "
127  << custom_ustar << " " << custom_tstar << " "
128  << custom_qstar << std::endl;
129 
130  // Bulk transfer coefficient (must specify coeffs and surface values)
131  } else if (flux_type == FluxCalcType::BULK_COEFF) {
132  pp.get("most.Cd", m_Cd);
133  pp.get("most.Ch", m_Ch);
134  pp.get("most.Cq", m_Cq);
135  pp.get("most.surf_temp", default_land_surf_temp);
136  pp.get("most.surf_moist", default_land_surf_moist);
137  amrex::Print() << "Using specified Cd, Ch, Cq for MOST = "
138  << m_Cd << " " << m_Ch << " "
139  << m_Cq << std::endl;
140 
141  // Specify surface temperature/moisture or surface flux
142  } else {
143  if (erf_st) {
145  pp.query("most.surf_heating_rate", surf_heating_rate); // [K/h]
146  surf_heating_rate = surf_heating_rate / 3600.0; // [K/s]
147  if (pp.query("most.surf_temp_flux", surf_temp_flux)) {
148  amrex::Abort("Can only specify one of surf_temp_flux or surf_heating_rate");
149  }
150  } else {
151  pp.query("most.surf_temp_flux", surf_temp_flux);
152 
153  if (pp.query("most.surf_heating_rate", surf_heating_rate)) {
154  amrex::Abort("Can only specify one of surf_temp_flux or surf_heating_rate");
155  }
156  if (std::abs(surf_temp_flux) >
159  } else {
161  }
162  }
163 
164  if (erf_sq) {
166  } else {
167  pp.query("most.surf_moist_flux", surf_moist_flux);
168  if (std::abs(surf_moist_flux) >
171  } else {
173  }
174  }
175  }
176 
177  // Make sure the inputs file doesn't try to use most.roughness_type
178  std::string bogus_input;
179  if (pp.query("most.roughness_type", bogus_input) > 0) {
180  amrex::Abort("most.roughness_type is deprecated; use "
181  "most.roughness_type_land and/or most.roughness_type_sea");
182  }
183 
184  // Specify how to compute the surface flux over land (if there is any)
185  std::string rough_land_string_in;
186  std::string rough_land_string{"constant"};
187  auto read_rough_land =
188  pp.query("most.roughness_type_land", rough_land_string_in);
189  if (read_rough_land) {
190  rough_land_string = amrex::toLower(rough_land_string_in);
191  }
192  if (rough_land_string == "constant") {
194  } else {
195  amrex::Abort("Undefined MOST roughness type for land!");
196  }
197 
198  // Specify how to compute the surface flux over sea (if there is any)
199  std::string rough_sea_string_in;
200  std::string rough_sea_string{"charnock"};
201  auto read_rough_sea = pp.query("most.roughness_type_sea", rough_sea_string_in);
202  if (read_rough_sea) {
203  rough_sea_string = amrex::toLower(rough_sea_string_in);
204  }
205  if (rough_sea_string == "charnock") {
207  pp.query("most.charnock_constant", cnk_a);
208  pp.query("most.charnock_viscosity", cnk_visc);
209  if (cnk_a > 0) {
210  amrex::Print() << "If there is water, Charnock relation with C_a="
211  << cnk_a << (cnk_visc ? " and viscosity" : "")
212  << " will be used" << std::endl;
213  } else {
214  amrex::Print() << "If there is water, Charnock relation with variable "
215  "Charnock parameter (COARE3.0)"
216  << (cnk_visc ? " and viscosity" : "") << " will be used"
217  << std::endl;
218  }
219  } else if (rough_sea_string == "coare3.0") {
221  amrex::Print() << "If there is water, Charnock relation with variable "
222  "Charnock parameter (COARE3.0)"
223  << (cnk_visc ? " and viscosity" : "") << " will be used"
224  << std::endl;
225  cnk_a = -1;
226  } else if (rough_sea_string == "donelan") {
228  } else if (rough_sea_string == "modified_charnock") {
230  pp.query("most.modified_charnock_depth", depth);
231  } else if (rough_sea_string == "wave_coupled") {
233  } else if (rough_sea_string == "constant") {
235  } else {
236  amrex::Abort("Undefined MOST roughness type for sea!");
237  }
238 
239  // use skin temperature instead of sea-surface temperature
240  // (wrfinput data may have lower resolution SST data)
241  pp.query("most.ignore_sst", m_ignore_sst);
242  } // constructor
243 
244  void make_SurfaceLayer_at_level (const int& lev,
245  int nlevs,
246  const amrex::Vector<amrex::MultiFab*>& mfv,
247  std::unique_ptr<amrex::MultiFab>& Theta_prim,
248  std::unique_ptr<amrex::MultiFab>& Qv_prim,
249  std::unique_ptr<amrex::MultiFab>& Qr_prim,
250  std::unique_ptr<amrex::MultiFab>& z_phys_nd,
251  amrex::MultiFab* Hwave,
252  amrex::MultiFab* Lwave,
253  amrex::MultiFab* eddyDiffs,
254  amrex::Vector<amrex::MultiFab*> lsm_data,
255  amrex::Vector<std::string> lsm_data_name,
256  amrex::Vector<amrex::MultiFab*> lsm_flux,
257  amrex::Vector<std::string> lsm_flux_name,
258  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& sst_lev,
259  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& tsk_lev,
260  amrex::Vector<std::unique_ptr<amrex::iMultiFab>>& lmask_lev)
261  {
262  // Update MOST Average
264  Theta_prim, Qv_prim, Qr_prim,
265  z_phys_nd);
266 
267  // Get CC vars
268  amrex::MultiFab& mf = *(mfv[0]);
269 
270  amrex::ParmParse pp("erf");
271 
272  // Do we have a time-varying surface roughness that needs to be saved?
273  if (lev == 0) {
274  const int nghost = 0; // ghost cells not included
275  int lmask_min = lmask_min_reduce(*lmask_lev[0].get(), nghost);
276  amrex::ParallelDescriptor::ReduceIntMin(lmask_min);
277 
278  m_var_z0 = (lmask_min < 1) & (rough_type_sea != RoughCalcType::CONSTANT);
279  if (m_var_z0) {
280  std::string rough_sea_string{"charnock"};
281  pp.query("most.roughness_type_sea", rough_sea_string);
282  amrex::Print() << "Variable sea roughness (type " << rough_sea_string
283  << ")" << std::endl;
284  }
285  }
286 
287  if ((lev == 0) || (lev > nlevs - 1)) {
288  m_Hwave_lev.resize(nlevs);
289  m_Lwave_lev.resize(nlevs);
290  m_eddyDiffs_lev.resize(nlevs);
291 
292  m_lsm_data_lev.resize(nlevs);
293  m_lsm_flux_lev.resize(nlevs);
294 
295  m_sst_lev.resize(nlevs);
296  m_tsk_lev.resize(nlevs);
297  m_lmask_lev.resize(nlevs);
298 
299  // Size the MOST params for all levels
300  z_0.resize(nlevs);
301  u_star.resize(nlevs);
302  w_star.resize(nlevs);
303  t_star.resize(nlevs);
304  q_star.resize(nlevs);
305  t_surf.resize(nlevs);
306  q_surf.resize(nlevs);
307  olen.resize(nlevs);
308  pblh.resize(nlevs);
309  }
310 
311  // Get pointers to SST,TSK and LANDMASK data
312  int nt_tot_sst = sst_lev.size();
313  m_sst_lev[lev].resize(nt_tot_sst);
314  for (int nt(0); nt < nt_tot_sst; ++nt) {
315  m_sst_lev[lev][nt] = sst_lev[nt].get();
316  }
317  int nt_tot_tsk = static_cast<int>(tsk_lev.size());
318  m_tsk_lev[lev].resize(nt_tot_tsk);
319  for (int nt(0); nt < nt_tot_tsk; ++nt) {
320  m_tsk_lev[lev][nt] = tsk_lev[nt].get();
321  }
322  int nt_tot_lmask = static_cast<int>(lmask_lev.size());
323  m_lmask_lev[lev].resize(nt_tot_lmask);
324  for (int nt(0); nt < nt_tot_lmask; ++nt) {
325  m_lmask_lev[lev][nt] = lmask_lev[nt].get();
326  }
327 
328  // Get pointers to wave data
329  m_Hwave_lev[lev] = Hwave;
330  m_Lwave_lev[lev] = Lwave;
331  m_eddyDiffs_lev[lev] = eddyDiffs;
332 
333  // Get pointers to LSM data and Fluxes
334  int ndata = static_cast<int>(lsm_data.size());
335  int nflux = static_cast<int>(lsm_flux.size());
336  m_lsm_data_name.resize(ndata);
337  m_lsm_data_lev[lev].resize(ndata);
338  m_lsm_flux_name.resize(nflux);
339  m_lsm_flux_lev[lev].resize(nflux);
340  for (int n(0); n < ndata; ++n) {
341  m_lsm_data_name[n] = lsm_data_name[n];
342  m_lsm_data_lev[lev][n] = lsm_data[n];
343  if (amrex::toLower(lsm_data_name[n]) == "theta") {
344  m_has_lsm_tsurf = true;
345  m_lsm_tsurf_indx = n;
346  }
347  }
348  for (int n(0); n < nflux; ++n) {
349  m_lsm_flux_name[n] = lsm_flux_name[n];
350  m_lsm_flux_lev[lev][n] = lsm_flux[n];
351  }
352 
353  // Check if there is a user-specified roughness file to be read
354  std::string fname;
355  bool read_z0 = false;
356  if ( (flux_type == FluxCalcType::MOENG) ||
358  int count = pp.countval("most.roughness_file_name");
359  if (count > 1) {
360  AMREX_ALWAYS_ASSERT(count >= lev+1);
361  pp.query("most.roughness_file_name", fname, lev);
362  read_z0 = true;
363  } else if (count == 1) {
364  if (lev == 0) {
365  pp.query("most.roughness_file_name", fname);
366  } else {
367  // we will interpolate from the coarsest level
368  fname = "";
369  }
370  read_z0 = true;
371  }
372  // else use z0_const
373  }
374 
375  // Attributes for MFs and FABs
376  //--------------------------------------------------------
377  // Create a 2D ba, dm, & ghost cells
378  amrex::BoxArray ba = mf.boxArray();
379  amrex::BoxList bl2d = ba.boxList();
380  for (auto& b : bl2d) {
381  b.setRange(2, 0);
382  }
383  amrex::BoxArray ba2d(std::move(bl2d));
384  const amrex::DistributionMapping& dm = mf.DistributionMap();
385  const int ncomp = 1;
386  amrex::IntVect ng = mf.nGrowVect();
387  ng[2] = 0;
388 
389  // Z0 heights FAB
390  //--------------------------------------------------------
391  z_0[lev].define(ba2d, dm, ncomp, ng);
392  z_0[lev].setVal(z0_const);
393  if (read_z0) {
394  read_custom_roughness(lev, fname);
395  }
396 
397  // 2D MFs for U*, T*, T_surf
398  //--------------------------------------------------------
399  u_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
400  u_star[lev]->setVal(1.E34);
401 
402  w_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
403  w_star[lev]->setVal(1.E34);
404 
405  t_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
406  t_star[lev]->setVal(0.0); // default to neutral
407 
408  q_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
409  q_star[lev]->setVal(0.0); // default to dry
410 
411  olen[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
412  olen[lev]->setVal(1.E34);
413 
414  pblh[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
415  pblh[lev]->setVal(1.E34);
416 
417  t_surf[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
418  t_surf[lev]->setVal(default_land_surf_temp);
419 
420  q_surf[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
421  q_surf[lev]->setVal(default_land_surf_moist);
422 
423  // TODO: Do we want an enum struct for indexing?
424  if (m_sst_lev[lev][0] || m_tsk_lev[lev][0] || m_has_lsm_tsurf) {
425  // Valid SST, TSK or LSM data; t_surf set before computing fluxes (avoids
426  // extended lambda capture) Note that land temp will be set from m_tsk_lev
427  // while sea temp will be set from m_sst_lev
429 
430  // Pathways in fill_tsurf_with_sst_and_tsk
431  bool use_tsk = (m_tsk_lev[lev][0]);
432  bool use_sst = (m_sst_lev[lev][0]);
433  amrex::Print() << "Using MOST with specified surface temperature ";
434  if (use_tsk && !use_sst) { m_ignore_sst = true; }
435  if (use_tsk) {
436  amrex::Print() << "(land: TSK, ";
437  } else {
438  amrex::Print() << "(land: T0, ";
439  }
440  if (use_tsk && m_ignore_sst) {
441  amrex::Print() << "sea: TSK)" << std::endl;
442  } else {
443  amrex::Print() << "sea: SST)" << std::endl;
444  AMREX_ALWAYS_ASSERT(m_sst_lev[lev][0]);
445  }
446  }
447  }
448 
449  void
450  update_fluxes (const int& lev,
451  const amrex::Real& time,
452  const amrex::MultiFab& cons_in,
453  const std::unique_ptr<amrex::MultiFab>& z_phys_nd,
454  int max_iters = 100);
455 
456  template <typename FluxIter>
457  void compute_fluxes (const int& lev,
458  const int& max_iters,
459  const FluxIter& most_flux,
460  bool is_land);
461 
462  void init_tke_from_ustar (const int& lev,
463  amrex::MultiFab& cons,
464  const std::unique_ptr<amrex::MultiFab>& z_phys_nd,
465  const amrex::Real tkefac = 1.0,
466  const amrex::Real zscale = 700.0);
467 
468  void impose_SurfaceLayer_bcs (const int& lev,
469  amrex::Vector<const amrex::MultiFab*> mfs,
470  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_lev,
471  amrex::MultiFab* xheat_flux,
472  amrex::MultiFab* yheat_flux,
473  amrex::MultiFab* zheat_flux,
474  amrex::MultiFab* xqv_flux,
475  amrex::MultiFab* yqv_flux,
476  amrex::MultiFab* zqv_flux,
477  const amrex::MultiFab* z_phys);
478 
479  template <typename FluxCalc>
480  void compute_SurfaceLayer_bcs (const int& lev,
481  amrex::Vector<const amrex::MultiFab*> mfs,
482  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_lev,
483  amrex::MultiFab* xheat_flux,
484  amrex::MultiFab* yheat_flux,
485  amrex::MultiFab* zheat_flux,
486  amrex::MultiFab* xqv_flux,
487  amrex::MultiFab* yqv_flux,
488  amrex::MultiFab* zqv_flux,
489  const amrex::MultiFab* z_phys,
490  const FluxCalc& flux_comp);
491 
492  void fill_tsurf_with_sst_and_tsk (const int& lev,
493  const amrex::Real& time);
494 
495  void fill_qsurf_with_qsat (const int& lev,
496  const amrex::MultiFab& cons_in,
497  const std::unique_ptr<amrex::MultiFab>& z_phys_nd);
498 
499  void get_lsm_tsurf (const int& lev);
500 
501  /* wrapper around compute_pblh */
502  void update_pblh (const int& lev,
503  amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars,
504  amrex::MultiFab* z_phys_cc,
505  const MoistureComponentIndices& moisture_indices);
506 
507  template <typename PBLHeightEstimator>
508  void compute_pblh (const int& lev,
509  amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars,
510  amrex::MultiFab* z_phys_cc,
511  const PBLHeightEstimator& est,
512  const MoistureComponentIndices& moisture_indice);
513 
514  void read_custom_roughness (const int& lev,
515  const std::string& fname);
516 
517  void update_surf_temp (const amrex::Real& time)
518  {
519  if (surf_heating_rate != 0) {
520  int nlevs = static_cast<int>(m_geom.size());
521  for (int lev = 0; lev < nlevs; lev++) {
522  t_surf[lev]->setVal(surf_temp + surf_heating_rate * time);
523  amrex::Print() << "Surface temp at t=" << time << ": "
524  << surf_temp + surf_heating_rate * time << std::endl;
525  }
526  }
527  }
528 
529  void update_mac_ptrs (const int& lev,
530  amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars_old,
531  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Theta_prim,
532  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Qv_prim,
533  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Qr_prim)
534  {
535  m_ma.update_field_ptrs(lev, vars_old, Theta_prim, Qv_prim, Qr_prim);
536  }
537 
538  amrex::MultiFab* get_u_star (const int& lev) { return u_star[lev].get(); }
539 
540  amrex::MultiFab* get_w_star (const int& lev) { return w_star[lev].get(); }
541 
542  amrex::MultiFab* get_t_star (const int& lev) { return t_star[lev].get(); }
543 
544  amrex::MultiFab* get_q_star (const int& lev) { return q_star[lev].get(); }
545 
546  amrex::MultiFab* get_olen (const int& lev) { return olen[lev].get(); }
547 
548  amrex::MultiFab* get_pblh (const int& lev) { return pblh[lev].get(); }
549 
550  const amrex::MultiFab* get_mac_avg (const int& lev, int comp)
551  {
552  return m_ma.get_average(lev, comp);
553  }
554 
555  amrex::MultiFab* get_t_surf (const int& lev) { return t_surf[lev].get(); }
556 
557  amrex::MultiFab* get_q_surf (const int& lev) { return q_surf[lev].get(); }
558 
560 
561  amrex::MultiFab* get_z0 (const int& lev) { return &z_0[lev]; }
562 
564 
565  amrex::iMultiFab* get_lmask (const int& lev) { return m_lmask_lev[lev][0]; }
566 
567  int lmask_min_reduce (amrex::iMultiFab& lmask,
568  const int& nghost)
569  {
570  int lmask_min = amrex::ReduceMin(lmask, nghost, [=] AMREX_GPU_HOST_DEVICE(
571  amrex::Box const& bx, amrex::Array4<int const> const& lm_arr) -> int
572  {
573  int locmin = std::numeric_limits<int>::max();
574  const auto lo = lbound(bx);
575  const auto hi = ubound(bx);
576  for (int j = lo.y; j <= hi.y; ++j) {
577  for (int i = lo.x; i <= hi.x; ++i) {
578  locmin = std::min(locmin, lm_arr(i, j, 0));
579  }
580  }
581  return locmin;
582  });
583 
584  return lmask_min;
585  }
586 
587  void update_sst_ptr(const int lev, const int itime, amrex::MultiFab* sst_ptr) {
588  m_sst_lev[lev][itime] = sst_ptr;
589  }
590 
591  void update_tsk_ptr(const int lev, const int itime, amrex::MultiFab* tsk_ptr) {
592  m_tsk_lev[lev][itime] = tsk_ptr;
593  }
594 
595  enum struct FluxCalcType {
596  MOENG = 0, ///< Moeng functional form
597  DONELAN, ///< Donelan functional form
598  CUSTOM, ///< Custom constant flux functional form
599  BULK_COEFF, ///< Bulk transfer coefficient functional form
600  ROTATE ///< Terrain rotation flux functional form
601  };
602 
603  enum struct ThetaCalcType {
604  ADIABATIC = 0,
605  HEAT_FLUX, ///< Heat-flux specified
606  SURFACE_TEMPERATURE ///< Surface temperature specified
607  };
608 
609  enum struct MoistCalcType {
610  ADIABATIC = 0,
611  MOISTURE_FLUX, ///< Qv-flux specified
612  SURFACE_MOISTURE ///< Surface Qv specified
613  };
614 
615  enum struct RoughCalcType {
616  CONSTANT = 0, ///< Constant z0
617  CHARNOCK,
619  DONELAN,
621  };
622 
623  enum struct PBLHeightCalcType { None, MYNN25, YSU, MRF };
624 
631 
632 private:
633  // Set in constructor
634  amrex::Vector<amrex::Geometry> m_geom;
635  bool m_rotate = false;
639 
640  bool m_include_wstar = false;
652  amrex::Real custom_rhosurf{0}; // use specified value instead of rho from first cell
653  bool specified_rho_surf{false};
655  bool cnk_visc{false};
657  amrex::Vector<amrex::MultiFab> z_0;
658  bool m_var_z0{false};
659 
661  bool m_has_lsm_tsurf = false;
663 
667 
668  bool m_ignore_sst = false;
669 
671  amrex::Vector<std::unique_ptr<amrex::MultiFab>> u_star;
672  amrex::Vector<std::unique_ptr<amrex::MultiFab>> w_star;
673  amrex::Vector<std::unique_ptr<amrex::MultiFab>> t_star;
674  amrex::Vector<std::unique_ptr<amrex::MultiFab>> q_star;
675  amrex::Vector<std::unique_ptr<amrex::MultiFab>> olen;
676  amrex::Vector<std::unique_ptr<amrex::MultiFab>> pblh;
677  amrex::Vector<std::unique_ptr<amrex::MultiFab>> t_surf;
678  amrex::Vector<std::unique_ptr<amrex::MultiFab>> q_surf;
679 
680  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_sst_lev;
681  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_tsk_lev;
682  amrex::Vector<amrex::Vector<amrex::iMultiFab*>> m_lmask_lev;
683  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_lsm_data_lev;
684  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_lsm_flux_lev;
685  amrex::Vector<std::string> m_lsm_data_name;
686  amrex::Vector<std::string> m_lsm_flux_name;
687  amrex::Vector<amrex::MultiFab*> m_Hwave_lev;
688  amrex::Vector<amrex::MultiFab*> m_Lwave_lev;
689  amrex::Vector<amrex::MultiFab*> m_eddyDiffs_lev;
690 };
691 
692 #endif /* SURFACELAYER_H */
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:233
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_MOSTAverage.H:14
amrex::Real get_zref() 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:260
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:84
Definition: ERF_SurfaceLayer.H:31
ThetaCalcType theta_type
Definition: ERF_SurfaceLayer.H:626
int lmask_min_reduce(amrex::iMultiFab &lmask, const int &nghost)
Definition: ERF_SurfaceLayer.H:567
amrex::Vector< std::string > m_lsm_data_name
Definition: ERF_SurfaceLayer.H:685
bool m_include_wstar
Definition: ERF_SurfaceLayer.H:640
bool specified_rho_surf
Definition: ERF_SurfaceLayer.H:653
bool m_rotate
Definition: ERF_SurfaceLayer.H:635
PBLHeightCalcType pblh_type
Definition: ERF_SurfaceLayer.H:630
amrex::Vector< amrex::Vector< amrex::iMultiFab * > > m_lmask_lev
Definition: ERF_SurfaceLayer.H:682
amrex::iMultiFab * get_lmask(const int &lev)
Definition: ERF_SurfaceLayer.H:565
bool use_moisture
Definition: ERF_SurfaceLayer.H:660
amrex::MultiFab * get_q_surf(const int &lev)
Definition: ERF_SurfaceLayer.H:557
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:699
bool m_has_lsm_tsurf
Definition: ERF_SurfaceLayer.H:661
amrex::MultiFab * get_w_star(const int &lev)
Definition: ERF_SurfaceLayer.H:540
void update_surf_temp(const amrex::Real &time)
Definition: ERF_SurfaceLayer.H:517
amrex::Real m_Cq
Definition: ERF_SurfaceLayer.H:666
RoughCalcType rough_type_land
Definition: ERF_SurfaceLayer.H:628
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:672
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_surf
Definition: ERF_SurfaceLayer.H:677
amrex::Real z0_const
Definition: ERF_SurfaceLayer.H:641
amrex::Real cnk_a
Definition: ERF_SurfaceLayer.H:654
amrex::Real m_Ch
Definition: ERF_SurfaceLayer.H:665
amrex::Real surf_temp
Definition: ERF_SurfaceLayer.H:643
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:529
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:674
int m_lsm_tsurf_indx
Definition: ERF_SurfaceLayer.H:662
amrex::Vector< amrex::MultiFab * > m_Lwave_lev
Definition: ERF_SurfaceLayer.H:688
void get_lsm_tsurf(const int &lev)
Definition: ERF_SurfaceLayer.cpp:640
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:600
amrex::MultiFab * get_olen(const int &lev)
Definition: ERF_SurfaceLayer.H:546
amrex::Vector< amrex::MultiFab > z_0
Definition: ERF_SurfaceLayer.H:657
amrex::Real surf_moist_flux
Definition: ERF_SurfaceLayer.H:648
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:629
amrex::Real surf_moist
Definition: ERF_SurfaceLayer.H:647
amrex::Vector< std::unique_ptr< amrex::MultiFab > > w_star
Definition: ERF_SurfaceLayer.H:672
bool m_ignore_sst
Definition: ERF_SurfaceLayer.H:668
amrex::MultiFab * get_u_star(const int &lev)
Definition: ERF_SurfaceLayer.H:538
amrex::Real m_bdy_time_interval
Definition: ERF_SurfaceLayer.H:638
amrex::Real m_stop_time
Definition: ERF_SurfaceLayer.H:637
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_data_lev
Definition: ERF_SurfaceLayer.H:683
amrex::Real custom_qstar
Definition: ERF_SurfaceLayer.H:651
amrex::Vector< std::unique_ptr< amrex::MultiFab > > u_star
Definition: ERF_SurfaceLayer.H:671
void update_tsk_ptr(const int lev, const int itime, amrex::MultiFab *tsk_ptr)
Definition: ERF_SurfaceLayer.H:591
amrex::Real custom_rhosurf
Definition: ERF_SurfaceLayer.H:652
amrex::Real m_start_time
Definition: ERF_SurfaceLayer.H:636
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_surf
Definition: ERF_SurfaceLayer.H:678
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_sst_lev
Definition: ERF_SurfaceLayer.H:680
FluxCalcType
Definition: ERF_SurfaceLayer.H:595
@ 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.
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, amrex::Real start_time, amrex::Real stop_time, amrex::Real bdy_time_interval=0.0)
Definition: ERF_SurfaceLayer.H:35
MoistCalcType
Definition: ERF_SurfaceLayer.H:609
@ SURFACE_MOISTURE
Surface Qv specified.
@ MOISTURE_FLUX
Qv-flux specified.
amrex::Real depth
Definition: ERF_SurfaceLayer.H:656
amrex::Vector< amrex::MultiFab * > m_Hwave_lev
Definition: ERF_SurfaceLayer.H:687
amrex::Real default_land_surf_moist
Definition: ERF_SurfaceLayer.H:646
bool m_var_z0
Definition: ERF_SurfaceLayer.H:658
amrex::MultiFab * get_t_star(const int &lev)
Definition: ERF_SurfaceLayer.H:542
bool have_variable_sea_roughness()
Definition: ERF_SurfaceLayer.H:563
void compute_fluxes(const int &lev, const int &max_iters, const FluxIter &most_flux, bool is_land)
Definition: ERF_SurfaceLayer.cpp:192
amrex::MultiFab * get_q_star(const int &lev)
Definition: ERF_SurfaceLayer.H:544
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_flux_lev
Definition: ERF_SurfaceLayer.H:684
PBLHeightCalcType
Definition: ERF_SurfaceLayer.H:623
amrex::MultiFab * get_pblh(const int &lev)
Definition: ERF_SurfaceLayer.H:548
void fill_tsurf_with_sst_and_tsk(const int &lev, const amrex::Real &time)
Definition: ERF_SurfaceLayer.cpp:519
amrex::Real surf_temp_flux
Definition: ERF_SurfaceLayer.H:645
amrex::Vector< amrex::Geometry > m_geom
Definition: ERF_SurfaceLayer.H:634
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_star
Definition: ERF_SurfaceLayer.H:673
amrex::MultiFab * get_z0(const int &lev)
Definition: ERF_SurfaceLayer.H:561
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_tsk_lev
Definition: ERF_SurfaceLayer.H:681
amrex::Real custom_tstar
Definition: ERF_SurfaceLayer.H:650
bool cnk_visc
Definition: ERF_SurfaceLayer.H:655
amrex::Real surf_heating_rate
Definition: ERF_SurfaceLayer.H:644
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:244
RoughCalcType
Definition: ERF_SurfaceLayer.H:615
FluxCalcType flux_type
Definition: ERF_SurfaceLayer.H:625
MoistCalcType moist_type
Definition: ERF_SurfaceLayer.H:627
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:262
amrex::Vector< amrex::MultiFab * > m_eddyDiffs_lev
Definition: ERF_SurfaceLayer.H:689
const amrex::MultiFab * get_mac_avg(const int &lev, int comp)
Definition: ERF_SurfaceLayer.H:550
void update_sst_ptr(const int lev, const int itime, amrex::MultiFab *sst_ptr)
Definition: ERF_SurfaceLayer.H:587
amrex::Real custom_ustar
Definition: ERF_SurfaceLayer.H:649
amrex::Vector< std::unique_ptr< amrex::MultiFab > > olen
Definition: ERF_SurfaceLayer.H:675
amrex::MultiFab * get_t_surf(const int &lev)
Definition: ERF_SurfaceLayer.H:555
amrex::Real m_Cd
Definition: ERF_SurfaceLayer.H:664
amrex::Vector< std::unique_ptr< amrex::MultiFab > > pblh
Definition: ERF_SurfaceLayer.H:676
amrex::Real default_land_surf_temp
Definition: ERF_SurfaceLayer.H:642
amrex::Real get_zref()
Definition: ERF_SurfaceLayer.H:559
void update_fluxes(const int &lev, const amrex::Real &time, const amrex::MultiFab &cons_in, const std::unique_ptr< amrex::MultiFab > &z_phys_nd, int max_iters=100)
Definition: ERF_SurfaceLayer.cpp:12
ThetaCalcType
Definition: ERF_SurfaceLayer.H:603
@ 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:736
amrex::Vector< std::string > m_lsm_flux_name
Definition: ERF_SurfaceLayer.H:686
MOSTAverage m_ma
Definition: ERF_SurfaceLayer.H:670
@ ng
Definition: ERF_Morrison.H:48
@ cons
Definition: ERF_IndexDefines.H:140
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
Definition: ERF_DataStruct.H:99