ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_LandSurface.H
Go to the documentation of this file.
1 #ifndef ERF_LANDSURFACE_H
2 #define ERF_LANDSURFACE_H
3 
4 #include <AMReX_PlotFileUtil.H>
5 
6 #include <ERF_NullSurf.H>
7 #include <ERF_SLM.H>
8 #include <ERF_MM5.H>
9 
10 #if ERF_USE_NOAH
11 #include <ERF_NOAH.H>
12 #endif
13 
14 class LandSurface {
15 
16 public:
17 
18  LandSurface () { }
19 
20  ~LandSurface () = default;
21 
22  void
23  ReSize (const int& nlev) { m_lsm_model.resize(nlev); }
24 
25  template<class NewSurfModel>
26  void
28  {
29  for (int lev(0); lev<m_lsm_model.size(); ++lev) {
30  m_lsm_model[lev] = std::make_unique<NewSurfModel>();
31  }
32  }
33 
34  void
35  Define (const int& lev,
36  SolverChoice& sc)
37  {
38  m_lsm_model[lev]->Define(sc);
39  }
40 
41  void
42  Init (const int& lev,
43  const amrex::MultiFab& cons_in,
44  const amrex::Geometry& geom,
45  const amrex::Real& dt_advance)
46  {
47  m_lsm_model[lev]->Init(cons_in, geom, dt_advance);
48  }
49 
50  void
51  Advance (const int& lev, const amrex::Real& dt_advance)
52  {
53  m_lsm_model[lev]->Advance(dt_advance);
54  }
55 
56  void
57  Update_Micro_Vars_Lev (const int& lev, amrex::MultiFab& cons_in)
58  {
59  m_lsm_model[lev]->Update_Micro_Vars(cons_in);
60  }
61 
62  void
63  Update_State_Vars_Lev (const int& lev, amrex::MultiFab& cons_in)
64  {
65  m_lsm_model[lev]->Update_State_Vars(cons_in);
66  }
67 
68  amrex::MultiFab*
69  Get_Data_Ptr (const int& lev, const int& varIdx) { return m_lsm_model[lev]->Lsm_Data_Ptr(varIdx); }
70 
71  amrex::MultiFab*
72  Get_Flux_Ptr (const int& lev, const int& varIdx) { return m_lsm_model[lev]->Lsm_Flux_Ptr(varIdx); }
73 
74  amrex::Geometry
75  Get_Lsm_Geom (const int& lev ) { return m_lsm_model[lev]->Lsm_Geom(); }
76 
77  int
78  Get_Data_Size () { return m_lsm_model[0]->Lsm_Data_Size(); }
79 
80  std::string
81  Get_VarName (const int& varIdx) { return m_lsm_model[0]->Lsm_VarName(varIdx); }
82 
83  void
84  Plot_Lsm_Data (amrex::Real time,
85  const amrex::Vector<int> &level_steps,
86  const amrex::Vector<amrex::IntVect> &ref_ratio)
87  {
88  int nlev = m_lsm_model.size();
89  int nvar = this->Get_Data_Size();
90  amrex::Vector<std::string> varnames;
91 
92  // Only write if we have valid pointers
93  if (this->Get_Data_Ptr(0,0)) {
94  varnames.resize(nvar);
95  m_lsm_geom_lev.resize(nlev);
96  m_lsm_data_lev.resize(nlev);
97  std::string plotfilename = amrex::Concatenate(plot_file_lsm, level_steps[0], 5);
98  for (int lev(0); lev<nlev; ++lev) {
99  m_lsm_geom_lev[lev] = this->Get_Lsm_Geom(lev);
100 
101  amrex::MultiFab* mf_lsm = this->Get_Data_Ptr(lev,0);
102  amrex::IntVect ng(0,0,0);
103  amrex::BoxArray ba = mf_lsm->boxArray();
104  amrex::DistributionMapping dm = mf_lsm->DistributionMap();
105  m_lsm_data_lev[lev].define(ba, dm, nvar, ng);
106  for (int n(0); n<nvar; ++n) {
107  mf_lsm = this->Get_Data_Ptr(lev,n);
108  amrex::MultiFab::Copy(m_lsm_data_lev[lev],*(mf_lsm),0,n,1,0);
109  if (lev==0) varnames[n] = this->Get_VarName(n);
110  }
111  }
112  WriteMultiLevelPlotfile (plotfilename, nlev, GetVecOfConstPtrs(m_lsm_data_lev),
113  varnames, m_lsm_geom_lev, time, level_steps, ref_ratio);
114  m_lsm_geom_lev.clear();
115  m_lsm_data_lev.clear();
116  }
117  }
118 
119 private:
120  // lsm model at each level
121  amrex::Vector<std::unique_ptr<NullSurf>> m_lsm_model;
122 
123  // plotfile prefix
124  std::string plot_file_lsm {"plt_lsm_"};
125 
126  // Vector of geometry
127  amrex::Vector<amrex::Geometry> m_lsm_geom_lev;
128 
129  // Vector of data pointers
130  amrex::Vector<amrex::MultiFab> m_lsm_data_lev;
131 };
132 #endif
Definition: ERF_LandSurface.H:14
amrex::Vector< amrex::Geometry > m_lsm_geom_lev
Definition: ERF_LandSurface.H:127
std::string Get_VarName(const int &varIdx)
Definition: ERF_LandSurface.H:81
void Advance(const int &lev, const amrex::Real &dt_advance)
Definition: ERF_LandSurface.H:51
int Get_Data_Size()
Definition: ERF_LandSurface.H:78
amrex::Geometry Get_Lsm_Geom(const int &lev)
Definition: ERF_LandSurface.H:75
~LandSurface()=default
void ReSize(const int &nlev)
Definition: ERF_LandSurface.H:23
amrex::Vector< amrex::MultiFab > m_lsm_data_lev
Definition: ERF_LandSurface.H:130
void Plot_Lsm_Data(amrex::Real time, const amrex::Vector< int > &level_steps, const amrex::Vector< amrex::IntVect > &ref_ratio)
Definition: ERF_LandSurface.H:84
amrex::Vector< std::unique_ptr< NullSurf > > m_lsm_model
Definition: ERF_LandSurface.H:121
void SetModel()
Definition: ERF_LandSurface.H:27
amrex::MultiFab * Get_Flux_Ptr(const int &lev, const int &varIdx)
Definition: ERF_LandSurface.H:72
void Init(const int &lev, const amrex::MultiFab &cons_in, const amrex::Geometry &geom, const amrex::Real &dt_advance)
Definition: ERF_LandSurface.H:42
LandSurface()
Definition: ERF_LandSurface.H:18
void Update_State_Vars_Lev(const int &lev, amrex::MultiFab &cons_in)
Definition: ERF_LandSurface.H:63
void Define(const int &lev, SolverChoice &sc)
Definition: ERF_LandSurface.H:35
amrex::MultiFab * Get_Data_Ptr(const int &lev, const int &varIdx)
Definition: ERF_LandSurface.H:69
std::string plot_file_lsm
Definition: ERF_LandSurface.H:124
void Update_Micro_Vars_Lev(const int &lev, amrex::MultiFab &cons_in)
Definition: ERF_LandSurface.H:57
Definition: ERF_DataStruct.H:78