ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Urban.H
Go to the documentation of this file.
1 #ifndef ERF_URBAN_H
2 #define ERF_URBAN_H
3 
4 #include <memory>
5 #include <string>
6 
7 #include <ERF_NullUrban.H>
8 
9 /**
10  * @brief Wrapper class for managing urban models across AMR levels.
11  */
12 class Urban {
13 
14 public:
15 
16  Urban () = default;
17 
18  ~Urban () = default;
19 
20  /**
21  * @brief Resizes urban-model storage and records active AMR levels.
22  */
23  void ReSize (const int& nlev, const amrex::Vector<int>& active_levs)
24  {
25  AMREX_ALWAYS_ASSERT(active_levs.size() == nlev);
26  m_urban_model.resize(nlev);
27  m_active_levs = active_levs;
28  }
29 
30  /**
31  * @brief Instantiates an urban model on each active AMR level.
32  */
33  template<class NewUrbanModel>
34  void SetModel ()
35  {
36  m_first_active_lev = -1;
37  for (int lev = 0; lev < m_urban_model.size(); ++lev) {
38  if (m_active_levs[lev] == 1) {
39  m_urban_model[lev] = std::make_unique<NewUrbanModel>();
40  if (m_first_active_lev == -1) {
41  m_first_active_lev = lev;
42  }
43  }
44  }
45  }
46 
47  /**
48  * @brief Defines the urban model on an active level.
49  */
50  void Define (const int& lev, SolverChoice& sc)
51  {
52  if (m_active_levs[lev] == 1) {
53  m_urban_model[lev]->Define(sc);
54  }
55  }
56 
57  /**
58  * @brief Initializes the urban model on an active level.
59  */
60  void Init (const int& lev, const amrex::MultiFab& cons_in,
61  const amrex::MultiFab& u_in, const amrex::MultiFab& v_in,
62  const amrex::Geometry& geom, const amrex::Real& dt_advance,
63  const amrex::MultiFab& z_phys_nd, const amrex::iMultiFab& land_type,
64  const amrex::MultiFab& urb_frac)
65  {
66  if (m_active_levs[lev] == 1) {
67  m_urban_model[lev]->Init(cons_in, u_in, v_in, geom, dt_advance,
68  z_phys_nd, land_type, urb_frac);
69  }
70  }
71 
72  /**
73  * @brief Advances the urban model on an active level.
74  */
75  void Advance (const int& lev, const amrex::Real& dt_advance,
76  const amrex::Real& time, const amrex::Real& start_time,
77  const amrex::Geometry& geom, const amrex::MultiFab* z_phys_nd,
78  amrex::MultiFab& eddyDiffs_lev, const amrex::Real& calday)
79  {
80  if (m_active_levs[lev] == 1) {
81  m_urban_model[lev]->Advance(dt_advance, time, start_time, geom,
82  z_phys_nd, eddyDiffs_lev, calday);
83  }
84  }
85 
86  /**
87  * @brief Updates coupled urban fields on an active level.
88  */
89  void Update_Urban_Vars_Lev (const int& lev, amrex::MultiFab& cons_in,
90  amrex::MultiFab& u_in, amrex::MultiFab& v_in)
91  {
92  if (m_active_levs[lev] == 1) {
93  m_urban_model[lev]->Update_Urban_Vars(cons_in, u_in, v_in);
94  }
95  }
96 
97  /**
98  * @brief Updates atmospheric state fields on an active level.
99  */
100  void Update_State_Vars_Lev (const int& lev, amrex::MultiFab& cons_in)
101  {
102  if (m_active_levs[lev] == 1) {
103  m_urban_model[lev]->Update_State_Vars(cons_in);
104  }
105  }
106 
107  /**
108  * @brief Returns a model data field, or null for an inactive level.
109  */
110  amrex::MultiFab* Get_Data_Ptr (const int& lev, const int& varIdx)
111  {
112  return m_active_levs[lev] ? m_urban_model[lev]->Urban_Data_Ptr(varIdx) : nullptr;
113  }
114 
115  /**
116  * @brief Returns a model flux field, or null for an inactive level.
117  */
118  amrex::MultiFab* Get_Flux_Ptr (const int& lev, const int& varIdx)
119  {
120  return m_active_levs[lev] ? m_urban_model[lev]->Urban_Flux_Ptr(varIdx) : nullptr;
121  }
122 
123  /**
124  * @brief Returns the urban-model geometry for a level.
125  */
126  amrex::Geometry Get_Urban_Geom (const int& lev)
127  {
128  return m_active_levs[lev] ? m_urban_model[lev]->Urban_Geom() : amrex::Geometry();
129  }
130 
131  /**
132  * @brief Returns the number of model data fields.
133  */
135  {
136  return (m_first_active_lev != -1)
137  ? m_urban_model[m_first_active_lev]->Urban_Data_Size() : 0;
138  }
139 
140  /**
141  * @brief Returns a model data-field name.
142  */
143  std::string Get_DataName (const int& varIdx)
144  {
145  return (m_first_active_lev != -1)
146  ? m_urban_model[m_first_active_lev]->Urban_DataName(varIdx) : "";
147  }
148 
149  /**
150  * @brief Returns a model data-field index.
151  */
152  int Get_DataIdx (const int& lev, const std::string& varname)
153  {
154  return m_active_levs[lev] ? m_urban_model[lev]->Urban_DataIndex(varname) : -1;
155  }
156 
157  /**
158  * @brief Sets flux inputs on an active level.
159  */
160  void set_urban_flux_inputs (const int& lev, const amrex::Real& declin)
161  {
162  if (m_active_levs[lev] == 1) {
163  m_urban_model[lev]->set_flux_inputs(declin);
164  }
165  }
166 
167  /**
168  * @brief Sets terrain inputs on an active level.
169  */
171  const int& lev,
172  const amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab>>>& tsk_in,
173  const amrex::Vector<amrex::Vector<std::unique_ptr<amrex::iMultiFab>>>& lmask_in,
174  const amrex::Vector<amrex::Vector<std::unique_ptr<amrex::iMultiFab>>>& land_type_in,
175  const amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab>>>& urb_frac_in,
176  amrex::MultiFab* lat_in, amrex::MultiFab* lon_in)
177  {
178  if (m_active_levs[lev] == 1) {
179  m_urban_model[lev]->set_terrain_inputs(
180  tsk_in[lev], lmask_in[lev], land_type_in[lev], urb_frac_in[lev],
181  lat_in, lon_in);
182  }
183  }
184 
185 private:
186  amrex::Vector<std::unique_ptr<NullUrban>> m_urban_model;
187  amrex::Vector<int> m_active_levs;
189 };
190 
191 #endif
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Wrapper class for managing urban models across AMR levels.
Definition: ERF_Urban.H:12
void Define(const int &lev, SolverChoice &sc)
Defines the urban model on an active level.
Definition: ERF_Urban.H:50
void Update_Urban_Vars_Lev(const int &lev, amrex::MultiFab &cons_in, amrex::MultiFab &u_in, amrex::MultiFab &v_in)
Updates coupled urban fields on an active level.
Definition: ERF_Urban.H:89
Urban()=default
void ReSize(const int &nlev, const amrex::Vector< int > &active_levs)
Resizes urban-model storage and records active AMR levels.
Definition: ERF_Urban.H:23
int m_first_active_lev
Definition: ERF_Urban.H:188
int Get_DataIdx(const int &lev, const std::string &varname)
Returns a model data-field index.
Definition: ERF_Urban.H:152
amrex::Geometry Get_Urban_Geom(const int &lev)
Returns the urban-model geometry for a level.
Definition: ERF_Urban.H:126
amrex::Vector< int > m_active_levs
Definition: ERF_Urban.H:187
amrex::Vector< std::unique_ptr< NullUrban > > m_urban_model
Definition: ERF_Urban.H:186
void Init(const int &lev, const amrex::MultiFab &cons_in, const amrex::MultiFab &u_in, const amrex::MultiFab &v_in, const amrex::Geometry &geom, const amrex::Real &dt_advance, const amrex::MultiFab &z_phys_nd, const amrex::iMultiFab &land_type, const amrex::MultiFab &urb_frac)
Initializes the urban model on an active level.
Definition: ERF_Urban.H:60
~Urban()=default
void Advance(const int &lev, const amrex::Real &dt_advance, const amrex::Real &time, const amrex::Real &start_time, const amrex::Geometry &geom, const amrex::MultiFab *z_phys_nd, amrex::MultiFab &eddyDiffs_lev, const amrex::Real &calday)
Advances the urban model on an active level.
Definition: ERF_Urban.H:75
int Get_Data_Size()
Returns the number of model data fields.
Definition: ERF_Urban.H:134
void Update_State_Vars_Lev(const int &lev, amrex::MultiFab &cons_in)
Updates atmospheric state fields on an active level.
Definition: ERF_Urban.H:100
amrex::MultiFab * Get_Data_Ptr(const int &lev, const int &varIdx)
Returns a model data field, or null for an inactive level.
Definition: ERF_Urban.H:110
std::string Get_DataName(const int &varIdx)
Returns a model data-field name.
Definition: ERF_Urban.H:143
amrex::MultiFab * Get_Flux_Ptr(const int &lev, const int &varIdx)
Returns a model flux field, or null for an inactive level.
Definition: ERF_Urban.H:118
void SetModel()
Instantiates an urban model on each active AMR level.
Definition: ERF_Urban.H:34
void set_urban_flux_inputs(const int &lev, const amrex::Real &declin)
Sets flux inputs on an active level.
Definition: ERF_Urban.H:160
void set_urban_terrain_inputs(const int &lev, const amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab >>> &tsk_in, const amrex::Vector< amrex::Vector< std::unique_ptr< amrex::iMultiFab >>> &lmask_in, const amrex::Vector< amrex::Vector< std::unique_ptr< amrex::iMultiFab >>> &land_type_in, const amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab >>> &urb_frac_in, amrex::MultiFab *lat_in, amrex::MultiFab *lon_in)
Sets terrain inputs on an active level.
Definition: ERF_Urban.H:170
Definition: ERF_DataStruct.H:685