1 #ifndef ERF_MOSTAverage_H
2 #define ERF_MOSTAverage_H
5 #include <AMReX_FArrayBox.H>
6 #include <AMReX_MultiFab.H>
7 #include <AMReX_iMultiFab.H>
8 #include <AMReX_ParmParse.H>
15 amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars_old,
16 amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Theta_prim,
17 amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Qv_prim,
18 amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Qr_prim,
19 amrex::Vector<std::unique_ptr<amrex::MultiFab>>& z_phys_nd);
41 amrex::Vector<std::unique_ptr<
amrex::MultiFab>>& Theta_prim,
42 amrex::Vector<std::unique_ptr<
amrex::MultiFab>>& Qv_prim,
43 amrex::Vector<std::unique_ptr<
amrex::MultiFab>>& Qr_prim);
92 [[nodiscard]]
const amrex::MultiFab*
get_average (
int lev,
int comp)
const {
return m_averages[lev][comp].get(); }
109 AMREX_GPU_HOST_DEVICE AMREX_INLINE
111 const amrex::Real& yp,
112 const amrex::Real& zp,
113 amrex::Real* interp_vals,
114 amrex::Array4<amrex::Real const>
const& interp_array,
115 amrex::Array4<amrex::Real const>
const& z_arr,
116 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& plo,
117 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& dxi,
118 const int interp_comp)
122 amrex::Real zval= 0.0;
123 int kmax = ubound(z_arr).z;
124 int i_new = (int) (xp * dxi[0] - 0.5);
125 int j_new = (int) (yp * dxi[1] - 0.5);
126 amrex::Real z_target = zp;
127 for (
int lk(0); lk<kmax; ++lk) {
128 amrex::Real z_lo = 0.25 * ( z_arr(i_new,j_new ,lk ) + z_arr(i_new+1,j_new ,lk )
129 + z_arr(i_new,j_new+1,lk ) + z_arr(i_new+1,j_new+1,lk ) );
130 amrex::Real z_hi = 0.25 * ( z_arr(i_new,j_new ,lk+1) + z_arr(i_new+1,j_new ,lk+1)
131 + z_arr(i_new,j_new+1,lk+1) + z_arr(i_new+1,j_new+1,lk+1) );
132 if (z_target > z_lo && z_target < z_hi){
134 zval = (amrex::Real) lk + ((z_target - z_lo) / (z_hi - z_lo)) + 0.5;
139 amrex::ignore_unused(found);
140 AMREX_ASSERT_WITH_MESSAGE(found,
"MOSTAverage: Height above terrain not found, try increasing z_ref!");
142 const amrex::RealVect lx((xp - plo[0])*dxi[0] + 0.5,
143 (yp - plo[1])*dxi[1] + 0.5,
146 const amrex::IntVect ijk = lx.floor();
148 int i = ijk[0];
int j = ijk[1];
int k = ijk[2];
151 const amrex::RealVect sx_hi = lx - ijk;
152 const amrex::RealVect sx_lo = 1.0 - sx_hi;
154 for (
int n = 0; n < interp_comp; n++)
155 interp_vals[n] = sx_lo[0]*sx_lo[1]*sx_lo[2]*interp_array(i-1, j-1, k-1,n) +
156 sx_lo[0]*sx_lo[1]*sx_hi[2]*interp_array(i-1, j-1, k ,n) +
157 sx_lo[0]*sx_hi[1]*sx_lo[2]*interp_array(i-1, j , k-1,n) +
158 sx_lo[0]*sx_hi[1]*sx_hi[2]*interp_array(i-1, j , k ,n) +
159 sx_hi[0]*sx_lo[1]*sx_lo[2]*interp_array(i , j-1, k-1,n) +
160 sx_hi[0]*sx_lo[1]*sx_hi[2]*interp_array(i , j-1, k ,n) +
161 sx_hi[0]*sx_hi[1]*sx_lo[2]*interp_array(i , j , k-1,n) +
162 sx_hi[0]*sx_hi[1]*sx_hi[2]*interp_array(i , j , k ,n);
169 const amrex::Vector<amrex::Geometry>
m_geom;
170 amrex::Vector<amrex::Vector<amrex::MultiFab*>>
m_fields;
182 amrex::Vector<std::unique_ptr<amrex::MultiFab>>
m_x_pos;
183 amrex::Vector<std::unique_ptr<amrex::MultiFab>>
m_y_pos;
184 amrex::Vector<std::unique_ptr<amrex::MultiFab>>
m_z_pos;
185 amrex::Vector<std::unique_ptr<amrex::iMultiFab>>
m_i_indx;
186 amrex::Vector<std::unique_ptr<amrex::iMultiFab>>
m_j_indx;
187 amrex::Vector<std::unique_ptr<amrex::iMultiFab>>
m_k_indx;
188 amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab>>>
m_averages;
189 amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab>>>
m_rot_fields;
Definition: ERF_MOSTAverage.H:12
int m_navg
Definition: ERF_MOSTAverage.H:176
bool m_t_avg
Definition: ERF_MOSTAverage.H:209
int m_policy
Definition: ERF_MOSTAverage.H:178
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > m_averages
Definition: ERF_MOSTAverage.H:188
MOSTAverage(amrex::Vector< amrex::Geometry > geom, 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, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &z_phys_nd)
void set_k_indices_T()
Definition: ERF_MOSTAverage.cpp:410
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_y_pos
Definition: ERF_MOSTAverage.H:183
void update_field_ptrs(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:228
void set_region_normalization()
Definition: ERF_MOSTAverage.H:52
void write_xz_positions(int lev, int j)
Definition: ERF_MOSTAverage.cpp:1385
void set_norm_indices_T()
Definition: ERF_MOSTAverage.cpp:467
int m_radius
Definition: ERF_MOSTAverage.H:198
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > m_i_indx
Definition: ERF_MOSTAverage.H:185
void set_rotated_fields(int lev)
Definition: ERF_MOSTAverage.cpp:247
amrex::Vector< amrex::MultiFab * > m_z_phys_nd
Definition: ERF_MOSTAverage.H:171
amrex::Vector< int > m_t_init
Definition: ERF_MOSTAverage.H:210
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_x_pos
Definition: ERF_MOSTAverage.H:182
void set_plane_normalization()
Definition: ERF_MOSTAverage.cpp:306
amrex::Real get_zref() const
Definition: ERF_MOSTAverage.H:95
amrex::Vector< amrex::Real > m_Vsg
Definition: ERF_MOSTAverage.H:217
void write_k_indices(int lev)
Definition: ERF_MOSTAverage.cpp:1297
void set_norm_positions_T()
Definition: ERF_MOSTAverage.cpp:586
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > m_rot_fields
Definition: ERF_MOSTAverage.H:189
void compute_averages(int lev)
Definition: ERF_MOSTAverage.cpp:648
bool m_rotate
Definition: ERF_MOSTAverage.H:179
amrex::Vector< amrex::Vector< amrex::Real > > m_plane_average
Definition: ERF_MOSTAverage.H:194
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_z_pos
Definition: ERF_MOSTAverage.H:184
void set_k_indices_N()
Definition: ERF_MOSTAverage.cpp:351
amrex::Vector< amrex::Vector< int > > m_ncell_plane
Definition: ERF_MOSTAverage.H:193
std::string m_pp_prefix
Definition: ERF_MOSTAverage.H:181
bool m_norm_vec
Definition: ERF_MOSTAverage.H:205
int m_nvar
Definition: ERF_MOSTAverage.H:175
amrex::Real m_fact_new
Definition: ERF_MOSTAverage.H:212
void set_z_positions_T()
Definition: ERF_MOSTAverage.cpp:540
const amrex::MultiFab * get_average(int lev, int comp) const
Definition: ERF_MOSTAverage.H:92
void compute_region_averages(int lev)
Definition: ERF_MOSTAverage.cpp:959
int m_ncell_region
Definition: ERF_MOSTAverage.H:199
void compute_plane_averages(int lev)
Definition: ERF_MOSTAverage.cpp:674
void write_norm_indices(int lev)
Definition: ERF_MOSTAverage.cpp:1336
int m_maxlev
Definition: ERF_MOSTAverage.H:177
void write_averages(int lev)
Definition: ERF_MOSTAverage.cpp:1415
bool include_subgrid_vel
Definition: ERF_MOSTAverage.H:216
~MOSTAverage()
Definition: ERF_MOSTAverage.H:22
amrex::Real m_time_window
Definition: ERF_MOSTAverage.H:211
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > m_j_indx
Definition: ERF_MOSTAverage.H:186
MOSTAverage(MOSTAverage &&) noexcept=default
amrex::Vector< amrex::Vector< amrex::MultiFab * > > m_fields
Definition: ERF_MOSTAverage.H:170
amrex::Vector< int > m_k_in
Definition: ERF_MOSTAverage.H:200
amrex::Real m_fact_old
Definition: ERF_MOSTAverage.H:212
bool m_interp
Definition: ERF_MOSTAverage.H:204
const amrex::Vector< amrex::Geometry > m_geom
Definition: ERF_MOSTAverage.H:169
AMREX_GPU_HOST_DEVICE static AMREX_INLINE void trilinear_interp_T(const amrex::Real &xp, const amrex::Real &yp, const amrex::Real &zp, amrex::Real *interp_vals, amrex::Array4< amrex::Real const > const &interp_array, amrex::Array4< amrex::Real const > const &z_arr, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &plo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxi, const int interp_comp)
Definition: ERF_MOSTAverage.H:110
amrex::Real m_zref
Definition: ERF_MOSTAverage.H:180
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > m_k_indx
Definition: ERF_MOSTAverage.H:187
Definition: ERF_console_io.cpp:12