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 (m_eddyDiffs_lev.size() < lev+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{1,1,0};
387 
388  // Z0 heights FAB
389  //--------------------------------------------------------
390  z_0[lev].define(ba2d, dm, ncomp, ng);
391  z_0[lev].setVal(z0_const);
392  if (read_z0) {
393  read_custom_roughness(lev, fname);
394  }
395 
396  // 2D MFs for U*, T*, T_surf
397  //--------------------------------------------------------
398  u_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
399  u_star[lev]->setVal(1.E34);
400 
401  w_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
402  w_star[lev]->setVal(1.E34);
403 
404  t_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
405  t_star[lev]->setVal(0.0); // default to neutral
406 
407  q_star[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
408  q_star[lev]->setVal(0.0); // default to dry
409 
410  olen[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
411  olen[lev]->setVal(1.E34);
412 
413  pblh[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
414  pblh[lev]->setVal(1.E34);
415 
416  t_surf[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
417  t_surf[lev]->setVal(default_land_surf_temp);
418 
419  q_surf[lev] = std::make_unique<amrex::MultiFab>(ba2d, dm, ncomp, ng);
420  q_surf[lev]->setVal(default_land_surf_moist);
421 
422  // TODO: Do we want an enum struct for indexing?
423 
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  // NOTE: SST from the LOW file populates TSK in update_sst_tsk.
435  // So if we have TSK, it contains everything and has been
436  // sanity checked for valid SST values.
437  if (use_tsk) { m_ignore_sst = true; }
438  if (use_tsk) {
439  amrex::Print() << "(land: TSK, ";
440  } else {
441  amrex::Print() << "(land: T0, ";
442  }
443  if (use_tsk && !use_sst) {
444  amrex::Print() << "sea: TSK)" << std::endl;
445  } else {
446  amrex::Print() << "sea: SST)" << std::endl;
447  AMREX_ALWAYS_ASSERT(m_sst_lev[lev][0]);
448  }
449  }
450  }
451 
452  void
453  update_fluxes (const int& lev,
454  const amrex::Real& time,
455  const amrex::MultiFab& cons_in,
456  const std::unique_ptr<amrex::MultiFab>& z_phys_nd,
457  int max_iters = 100);
458 
459  template <typename FluxIter>
460  void compute_fluxes (const int& lev,
461  const int& max_iters,
462  const FluxIter& most_flux,
463  bool is_land);
464 
465  void init_tke_from_ustar (const int& lev,
466  amrex::MultiFab& cons,
467  const std::unique_ptr<amrex::MultiFab>& z_phys_nd,
468  const amrex::Real tkefac = 1.0,
469  const amrex::Real zscale = 700.0);
470 
471  void impose_SurfaceLayer_bcs (const int& lev,
472  amrex::Vector<const amrex::MultiFab*> mfs,
473  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_lev,
474  amrex::MultiFab* xheat_flux,
475  amrex::MultiFab* yheat_flux,
476  amrex::MultiFab* zheat_flux,
477  amrex::MultiFab* xqv_flux,
478  amrex::MultiFab* yqv_flux,
479  amrex::MultiFab* zqv_flux,
480  const amrex::MultiFab* z_phys);
481 
482  template <typename FluxCalc>
483  void compute_SurfaceLayer_bcs (const int& lev,
484  amrex::Vector<const amrex::MultiFab*> mfs,
485  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_lev,
486  amrex::MultiFab* xheat_flux,
487  amrex::MultiFab* yheat_flux,
488  amrex::MultiFab* zheat_flux,
489  amrex::MultiFab* xqv_flux,
490  amrex::MultiFab* yqv_flux,
491  amrex::MultiFab* zqv_flux,
492  const amrex::MultiFab* z_phys,
493  const FluxCalc& flux_comp);
494 
495  void fill_tsurf_with_sst_and_tsk (const int& lev,
496  const amrex::Real& time);
497 
498  void fill_qsurf_with_qsat (const int& lev,
499  const amrex::MultiFab& cons_in,
500  const std::unique_ptr<amrex::MultiFab>& z_phys_nd);
501 
502  void get_lsm_tsurf (const int& lev);
503 
504  /* wrapper around compute_pblh */
505  void update_pblh (const int& lev,
506  amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars,
507  amrex::MultiFab* z_phys_cc,
508  const MoistureComponentIndices& moisture_indices);
509 
510  template <typename PBLHeightEstimator>
511  void compute_pblh (const int& lev,
512  amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars,
513  amrex::MultiFab* z_phys_cc,
514  const PBLHeightEstimator& est,
515  const MoistureComponentIndices& moisture_indice);
516 
517  void read_custom_roughness (const int& lev,
518  const std::string& fname);
519 
520  void update_surf_temp (const amrex::Real& time)
521  {
522  if (surf_heating_rate != 0) {
523  int nlevs = static_cast<int>(m_geom.size());
524  for (int lev = 0; lev < nlevs; lev++) {
525  t_surf[lev]->setVal(surf_temp + surf_heating_rate * time);
526  amrex::Print() << "Surface temp at t=" << time << ": "
527  << surf_temp + surf_heating_rate * time << std::endl;
528  }
529  }
530  }
531 
532  void update_mac_ptrs (const int& lev,
533  amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars_old,
534  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Theta_prim,
535  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Qv_prim,
536  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Qr_prim)
537  {
538  m_ma.update_field_ptrs(lev, vars_old, Theta_prim, Qv_prim, Qr_prim);
539  }
540 
541  amrex::MultiFab* get_u_star (const int& lev) { return u_star[lev].get(); }
542 
543  amrex::MultiFab* get_w_star (const int& lev) { return w_star[lev].get(); }
544 
545  amrex::MultiFab* get_t_star (const int& lev) { return t_star[lev].get(); }
546 
547  amrex::MultiFab* get_q_star (const int& lev) { return q_star[lev].get(); }
548 
549  amrex::MultiFab* get_olen (const int& lev) { return olen[lev].get(); }
550 
551  amrex::MultiFab* get_pblh (const int& lev) { return pblh[lev].get(); }
552 
553  const amrex::MultiFab* get_mac_avg (const int& lev, int comp)
554  {
555  return m_ma.get_average(lev, comp);
556  }
557 
558  amrex::MultiFab* get_t_surf (const int& lev) { return t_surf[lev].get(); }
559  void set_t_surf(const int& lev, const amrex::Real tsurf) { t_surf[lev]->setVal(tsurf); }
560 
561  amrex::MultiFab* get_q_surf (const int& lev) { return q_surf[lev].get(); }
562  void set_q_surf(const int& lev, const amrex::Real qsurf) { q_surf[lev]->setVal(qsurf); }
563 
564  amrex::Real get_zref (const int& lev) { return (m_ma.get_zref(lev))->min(0); }
565 
566  amrex::MultiFab* get_z0 (const int& lev) { return &z_0[lev]; }
567 
569 
570  amrex::iMultiFab* get_lmask (const int& lev) { return m_lmask_lev[lev][0]; }
571 
572  int lmask_min_reduce (amrex::iMultiFab& lmask,
573  const int& nghost)
574  {
575  int lmask_min = amrex::ReduceMin(lmask, nghost, [=] AMREX_GPU_HOST_DEVICE(
576  amrex::Box const& bx, amrex::Array4<int const> const& lm_arr) -> int
577  {
578  int locmin = std::numeric_limits<int>::max();
579  const auto lo = lbound(bx);
580  const auto hi = ubound(bx);
581  for (int j = lo.y; j <= hi.y; ++j) {
582  for (int i = lo.x; i <= hi.x; ++i) {
583  locmin = std::min(locmin, lm_arr(i, j, 0));
584  }
585  }
586  return locmin;
587  });
588 
589  return lmask_min;
590  }
591 
592  void update_sst_ptr(const int lev, const int itime, amrex::MultiFab* sst_ptr) {
593  m_sst_lev[lev][itime] = sst_ptr;
594  }
595 
596  void update_tsk_ptr(const int lev, const int itime, amrex::MultiFab* tsk_ptr) {
597  m_tsk_lev[lev][itime] = tsk_ptr;
598  }
599 
600  enum struct FluxCalcType {
601  MOENG = 0, ///< Moeng functional form
602  DONELAN, ///< Donelan functional form
603  CUSTOM, ///< Custom constant flux functional form
604  BULK_COEFF, ///< Bulk transfer coefficient functional form
605  ROTATE ///< Terrain rotation flux functional form
606  };
607 
608  enum struct ThetaCalcType {
609  ADIABATIC = 0,
610  HEAT_FLUX, ///< Heat-flux specified
611  SURFACE_TEMPERATURE ///< Surface temperature specified
612  };
613 
614  enum struct MoistCalcType {
615  ADIABATIC = 0,
616  MOISTURE_FLUX, ///< Qv-flux specified
617  SURFACE_MOISTURE ///< Surface Qv specified
618  };
619 
620  enum struct RoughCalcType {
621  CONSTANT = 0, ///< Constant z0
622  CHARNOCK,
624  DONELAN,
626  };
627 
628  enum struct PBLHeightCalcType { None, MYNN25, YSU, MRF };
629 
636 
637 private:
638  // Set in constructor
639  amrex::Vector<amrex::Geometry> m_geom;
640  bool m_rotate = false;
644 
645  bool m_include_wstar = false;
657  amrex::Real custom_rhosurf{0}; // use specified value instead of rho from first cell
658  bool specified_rho_surf{false};
660  bool cnk_visc{false};
662  amrex::Vector<amrex::MultiFab> z_0;
663  bool m_var_z0{false};
664 
666  bool m_has_lsm_tsurf = false;
668 
672 
673  bool m_ignore_sst = false;
674 
676  amrex::Vector<std::unique_ptr<amrex::MultiFab>> u_star;
677  amrex::Vector<std::unique_ptr<amrex::MultiFab>> w_star;
678  amrex::Vector<std::unique_ptr<amrex::MultiFab>> t_star;
679  amrex::Vector<std::unique_ptr<amrex::MultiFab>> q_star;
680  amrex::Vector<std::unique_ptr<amrex::MultiFab>> olen;
681  amrex::Vector<std::unique_ptr<amrex::MultiFab>> pblh;
682  amrex::Vector<std::unique_ptr<amrex::MultiFab>> t_surf;
683  amrex::Vector<std::unique_ptr<amrex::MultiFab>> q_surf;
684 
685  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_sst_lev;
686  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_tsk_lev;
687  amrex::Vector<amrex::Vector<amrex::iMultiFab*>> m_lmask_lev;
688  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_lsm_data_lev;
689  amrex::Vector<amrex::Vector<amrex::MultiFab*>> m_lsm_flux_lev;
690  amrex::Vector<std::string> m_lsm_data_name;
691  amrex::Vector<std::string> m_lsm_flux_name;
692  amrex::Vector<amrex::MultiFab*> m_Hwave_lev;
693  amrex::Vector<amrex::MultiFab*> m_Lwave_lev;
694  amrex::Vector<amrex::MultiFab*> m_eddyDiffs_lev;
695 };
696 
697 #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::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:631
int lmask_min_reduce(amrex::iMultiFab &lmask, const int &nghost)
Definition: ERF_SurfaceLayer.H:572
amrex::Vector< std::string > m_lsm_data_name
Definition: ERF_SurfaceLayer.H:690
bool m_include_wstar
Definition: ERF_SurfaceLayer.H:645
bool specified_rho_surf
Definition: ERF_SurfaceLayer.H:658
void set_q_surf(const int &lev, const amrex::Real qsurf)
Definition: ERF_SurfaceLayer.H:562
bool m_rotate
Definition: ERF_SurfaceLayer.H:640
PBLHeightCalcType pblh_type
Definition: ERF_SurfaceLayer.H:635
amrex::Vector< amrex::Vector< amrex::iMultiFab * > > m_lmask_lev
Definition: ERF_SurfaceLayer.H:687
amrex::iMultiFab * get_lmask(const int &lev)
Definition: ERF_SurfaceLayer.H:570
bool use_moisture
Definition: ERF_SurfaceLayer.H:665
amrex::MultiFab * get_q_surf(const int &lev)
Definition: ERF_SurfaceLayer.H:561
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:716
bool m_has_lsm_tsurf
Definition: ERF_SurfaceLayer.H:666
amrex::MultiFab * get_w_star(const int &lev)
Definition: ERF_SurfaceLayer.H:543
void update_surf_temp(const amrex::Real &time)
Definition: ERF_SurfaceLayer.H:520
amrex::Real m_Cq
Definition: ERF_SurfaceLayer.H:671
RoughCalcType rough_type_land
Definition: ERF_SurfaceLayer.H:633
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:689
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_surf
Definition: ERF_SurfaceLayer.H:682
amrex::Real z0_const
Definition: ERF_SurfaceLayer.H:646
amrex::Real cnk_a
Definition: ERF_SurfaceLayer.H:659
amrex::Real m_Ch
Definition: ERF_SurfaceLayer.H:670
amrex::Real surf_temp
Definition: ERF_SurfaceLayer.H:648
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:532
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:679
int m_lsm_tsurf_indx
Definition: ERF_SurfaceLayer.H:667
amrex::Vector< amrex::MultiFab * > m_Lwave_lev
Definition: ERF_SurfaceLayer.H:693
void get_lsm_tsurf(const int &lev)
Definition: ERF_SurfaceLayer.cpp:657
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:617
amrex::Real get_zref(const int &lev)
Definition: ERF_SurfaceLayer.H:564
amrex::MultiFab * get_olen(const int &lev)
Definition: ERF_SurfaceLayer.H:549
amrex::Vector< amrex::MultiFab > z_0
Definition: ERF_SurfaceLayer.H:662
amrex::Real surf_moist_flux
Definition: ERF_SurfaceLayer.H:653
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:634
amrex::Real surf_moist
Definition: ERF_SurfaceLayer.H:652
amrex::Vector< std::unique_ptr< amrex::MultiFab > > w_star
Definition: ERF_SurfaceLayer.H:677
bool m_ignore_sst
Definition: ERF_SurfaceLayer.H:673
amrex::MultiFab * get_u_star(const int &lev)
Definition: ERF_SurfaceLayer.H:541
amrex::Real m_bdy_time_interval
Definition: ERF_SurfaceLayer.H:643
amrex::Real m_stop_time
Definition: ERF_SurfaceLayer.H:642
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_data_lev
Definition: ERF_SurfaceLayer.H:688
void set_t_surf(const int &lev, const amrex::Real tsurf)
Definition: ERF_SurfaceLayer.H:559
amrex::Real custom_qstar
Definition: ERF_SurfaceLayer.H:656
amrex::Vector< std::unique_ptr< amrex::MultiFab > > u_star
Definition: ERF_SurfaceLayer.H:676
void update_tsk_ptr(const int lev, const int itime, amrex::MultiFab *tsk_ptr)
Definition: ERF_SurfaceLayer.H:596
amrex::Real custom_rhosurf
Definition: ERF_SurfaceLayer.H:657
amrex::Real m_start_time
Definition: ERF_SurfaceLayer.H:641
amrex::Vector< std::unique_ptr< amrex::MultiFab > > q_surf
Definition: ERF_SurfaceLayer.H:683
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_sst_lev
Definition: ERF_SurfaceLayer.H:685
FluxCalcType
Definition: ERF_SurfaceLayer.H:600
@ 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:614
@ SURFACE_MOISTURE
Surface Qv specified.
@ MOISTURE_FLUX
Qv-flux specified.
amrex::Real depth
Definition: ERF_SurfaceLayer.H:661
amrex::Vector< amrex::MultiFab * > m_Hwave_lev
Definition: ERF_SurfaceLayer.H:692
amrex::Real default_land_surf_moist
Definition: ERF_SurfaceLayer.H:651
bool m_var_z0
Definition: ERF_SurfaceLayer.H:663
amrex::MultiFab * get_t_star(const int &lev)
Definition: ERF_SurfaceLayer.H:545
bool have_variable_sea_roughness()
Definition: ERF_SurfaceLayer.H:568
void compute_fluxes(const int &lev, const int &max_iters, const FluxIter &most_flux, bool is_land)
Definition: ERF_SurfaceLayer.cpp:182
amrex::MultiFab * get_q_star(const int &lev)
Definition: ERF_SurfaceLayer.H:547
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_lsm_flux_lev
Definition: ERF_SurfaceLayer.H:689
PBLHeightCalcType
Definition: ERF_SurfaceLayer.H:628
amrex::MultiFab * get_pblh(const int &lev)
Definition: ERF_SurfaceLayer.H:551
void fill_tsurf_with_sst_and_tsk(const int &lev, const amrex::Real &time)
Definition: ERF_SurfaceLayer.cpp:536
amrex::Real surf_temp_flux
Definition: ERF_SurfaceLayer.H:650
amrex::Vector< amrex::Geometry > m_geom
Definition: ERF_SurfaceLayer.H:639
amrex::Vector< std::unique_ptr< amrex::MultiFab > > t_star
Definition: ERF_SurfaceLayer.H:678
amrex::MultiFab * get_z0(const int &lev)
Definition: ERF_SurfaceLayer.H:566
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_tsk_lev
Definition: ERF_SurfaceLayer.H:686
amrex::Real custom_tstar
Definition: ERF_SurfaceLayer.H:655
bool cnk_visc
Definition: ERF_SurfaceLayer.H:660
amrex::Real surf_heating_rate
Definition: ERF_SurfaceLayer.H:649
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:620
FluxCalcType flux_type
Definition: ERF_SurfaceLayer.H:630
MoistCalcType moist_type
Definition: ERF_SurfaceLayer.H:632
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:255
amrex::Vector< amrex::MultiFab * > m_eddyDiffs_lev
Definition: ERF_SurfaceLayer.H:694
const amrex::MultiFab * get_mac_avg(const int &lev, int comp)
Definition: ERF_SurfaceLayer.H:553
void update_sst_ptr(const int lev, const int itime, amrex::MultiFab *sst_ptr)
Definition: ERF_SurfaceLayer.H:592
amrex::Real custom_ustar
Definition: ERF_SurfaceLayer.H:654
amrex::Vector< std::unique_ptr< amrex::MultiFab > > olen
Definition: ERF_SurfaceLayer.H:680
amrex::MultiFab * get_t_surf(const int &lev)
Definition: ERF_SurfaceLayer.H:558
amrex::Real m_Cd
Definition: ERF_SurfaceLayer.H:669
amrex::Vector< std::unique_ptr< amrex::MultiFab > > pblh
Definition: ERF_SurfaceLayer.H:681
amrex::Real default_land_surf_temp
Definition: ERF_SurfaceLayer.H:647
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:608
@ 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:753
amrex::Vector< std::string > m_lsm_flux_name
Definition: ERF_SurfaceLayer.H:691
MOSTAverage m_ma
Definition: ERF_SurfaceLayer.H:675
@ 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:105