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