ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
PlaneSampler Struct Reference

#include <ERF_SampleData.H>

Collaboration diagram for PlaneSampler:

Public Member Functions

 PlaneSampler ()
 
amrex::Box getIndexBox (const amrex::RealBox &real_box, const amrex::Geometry &geom)
 
void get_plane_mfs (amrex::Vector< amrex::Geometry > &geom, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_new)
 
void write_plane_mfs (amrex::Vector< amrex::Real > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
 

Public Attributes

amrex::Vector< int > m_dir
 
amrex::Vector< int > m_lev
 
amrex::Vector< amrex::RealBox > m_bnd_rbx
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ps_mf
 

Constructor & Destructor Documentation

◆ PlaneSampler()

PlaneSampler::PlaneSampler ( )
inline
189  {
190  amrex::ParmParse pp("erf");
191 
192  // Count number of lo and hi points define the plane
193  int n_plane_lo = pp.countval("sample_plane_lo") / AMREX_SPACEDIM;
194  int n_plane_hi = pp.countval("sample_plane_hi") / AMREX_SPACEDIM;
195  int n_plane_dir = pp.countval("sample_plane_dir");
196  AMREX_ALWAYS_ASSERT( (n_plane_lo==n_plane_hi ) &&
197  (n_plane_lo==n_plane_dir) );
198 
199  // Parse the data
200  if (n_plane_lo > 0) {
201  // Parse lo
202  amrex::Vector<amrex::Real> r_lo; r_lo.resize(n_plane_lo*AMREX_SPACEDIM);
203  amrex::Vector<amrex::Vector<amrex::Real>> rv_lo;
204  pp.queryarr("sample_plane_lo",r_lo,0,n_plane_lo*AMREX_SPACEDIM);
205  for (int i(0); i < n_plane_lo; i++) {
206  amrex::Vector<amrex::Real> rv = {r_lo[AMREX_SPACEDIM*i+0],
207  r_lo[AMREX_SPACEDIM*i+1],
208  r_lo[AMREX_SPACEDIM*i+2]};
209  rv_lo.push_back(rv);
210  }
211 
212  // Parse hi
213  amrex::Vector<amrex::Real> r_hi; r_hi.resize(n_plane_hi*AMREX_SPACEDIM);
214  amrex::Vector<amrex::Vector<amrex::Real>> rv_hi;
215  pp.queryarr("sample_plane_hi",r_hi,0,n_plane_hi*AMREX_SPACEDIM);
216  for (int i(0); i < n_plane_hi; i++) {
217  amrex::Vector<amrex::Real> rv = {r_hi[AMREX_SPACEDIM*i+0],
218  r_hi[AMREX_SPACEDIM*i+1],
219  r_hi[AMREX_SPACEDIM*i+2]};
220  rv_hi.push_back(rv);
221  }
222 
223  // Construct vector of bounding real boxes
224  m_bnd_rbx.resize(n_plane_lo);
225  for (int i(0); i < n_plane_hi; i++){
226  amrex::RealBox rbx(rv_lo[i].data(),rv_hi[i].data());
227  m_bnd_rbx[i] = rbx;
228  }
229 
230  // Parse directionality
231  m_dir.resize(n_plane_dir);
232  pp.queryarr("sample_plane_dir",m_dir,0,n_plane_dir);
233 
234  // Allocate space for level indicator
235  m_lev.resize(n_plane_dir,0);
236 
237  // Allocate space for MF pointers
238  m_ps_mf.resize(n_plane_lo);
239  }
240  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:219
amrex::Vector< int > m_dir
Definition: ERF_SampleData.H:369
amrex::Vector< int > m_lev
Definition: ERF_SampleData.H:370
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ps_mf
Definition: ERF_SampleData.H:372
amrex::Vector< amrex::RealBox > m_bnd_rbx
Definition: ERF_SampleData.H:371
Here is the call graph for this function:

Member Function Documentation

◆ get_plane_mfs()

void PlaneSampler::get_plane_mfs ( amrex::Vector< amrex::Geometry > &  geom,
amrex::Vector< amrex::Vector< amrex::MultiFab >> &  vars_new 
)
inline
262  {
263  int nlev = vars_new.size();
264  int nplane = m_bnd_rbx.size();
265  int ncomp = 2;
266  bool interpolate = true;
267 
268  // Loop over each plane
269  for (int iplane(0); iplane<nplane; ++iplane) {
270  int dir = m_dir[iplane];
271  amrex::RealBox bnd_rbx = m_bnd_rbx[iplane];
272  amrex::Real point = bnd_rbx.lo(dir);
273 
274  // Search each level to get the finest data possible
275  for (int ilev(nlev-1); ilev>=0; --ilev) {
276 
277  // Construct CC velocities
278  amrex::MultiFab mf_cc_vel;
279  auto ba = vars_new[ilev][Vars::cons].boxArray();
280  auto dm = vars_new[ilev][Vars::cons].DistributionMap();
281  mf_cc_vel.define(ba, dm, AMREX_SPACEDIM, amrex::IntVect(1,1,1));
282  average_face_to_cellcenter(mf_cc_vel,0,
283  amrex::Array<const amrex::MultiFab*,3>{&vars_new[ilev][Vars::xvel],
284  &vars_new[ilev][Vars::yvel],
285  &vars_new[ilev][Vars::zvel]});
286 
287  // Construct vector of MFs holding T and WSP
288  amrex::MultiFab mf_cc_data;
289  mf_cc_data.define(ba, dm, ncomp, 1);
290 #ifdef _OPENMP
291 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
292 #endif
293  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
294  const amrex::Box& tbx = mfi.tilebox();
295  auto const& dfab = mf_cc_data.array(mfi);
296  auto const& tfab = vars_new[ilev][Vars::cons].array(mfi);
297  auto const& wfab = mf_cc_vel.array(mfi);
298  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
299  {
300  dfab(i,j,k,0) = tfab(i,j,k,1)/tfab(i,j,k,0);
301  dfab(i,j,k,1) = std::sqrt(wfab(i,j,k,0)*wfab(i,j,k,0)
302  + wfab(i,j,k,1)*wfab(i,j,k,1)
303  + wfab(i,j,k,2)*wfab(i,j,k,2)) ;
304  });
305 
306  }
307 
308  m_lev[iplane] = ilev;
309  m_ps_mf[iplane] = get_slice_data(dir, point, mf_cc_data, geom[ilev],
310  0, ncomp, interpolate, bnd_rbx);
311 
312  // We can stop if we got the entire plane
313  auto min_bnd_bx = m_ps_mf[iplane]->boxArray().minimalBox();
314  amrex::Box bnd_bx = getIndexBox(bnd_rbx, geom[ilev]);
315  if (bnd_bx == min_bnd_bx) { continue; }
316 
317  } // ilev
318  }// iplane
319  }
@ xvel
Definition: ERF_IndexDefines.H:130
@ cons
Definition: ERF_IndexDefines.H:129
@ zvel
Definition: ERF_IndexDefines.H:132
@ yvel
Definition: ERF_IndexDefines.H:131
amrex::Box getIndexBox(const amrex::RealBox &real_box, const amrex::Geometry &geom)
Definition: ERF_SampleData.H:244
Here is the call graph for this function:

◆ getIndexBox()

amrex::Box PlaneSampler::getIndexBox ( const amrex::RealBox &  real_box,
const amrex::Geometry &  geom 
)
inline
245  {
246  amrex::IntVect slice_lo, slice_hi;
247 
248  AMREX_D_TERM(slice_lo[0]=static_cast<int>(std::floor((real_box.lo(0) - geom.ProbLo(0))/geom.CellSize(0)));,
249  slice_lo[1]=static_cast<int>(std::floor((real_box.lo(1) - geom.ProbLo(1))/geom.CellSize(1)));,
250  slice_lo[2]=static_cast<int>(std::floor((real_box.lo(2) - geom.ProbLo(2))/geom.CellSize(2))););
251 
252  AMREX_D_TERM(slice_hi[0]=static_cast<int>(std::floor((real_box.hi(0) - geom.ProbLo(0))/geom.CellSize(0)));,
253  slice_hi[1]=static_cast<int>(std::floor((real_box.hi(1) - geom.ProbLo(1))/geom.CellSize(1)));,
254  slice_hi[2]=static_cast<int>(std::floor((real_box.hi(2) - geom.ProbLo(2))/geom.CellSize(2))););
255 
256  return amrex::Box(slice_lo, slice_hi) & geom.Domain();
257  }

Referenced by get_plane_mfs(), and write_plane_mfs().

Here is the caller graph for this function:

◆ write_plane_mfs()

void PlaneSampler::write_plane_mfs ( amrex::Vector< amrex::Real > &  time,
amrex::Vector< int > &  level_steps,
amrex::Vector< amrex::IntVect > &  ref_ratio,
amrex::Vector< amrex::Geometry > &  geom 
)
inline
326  {
327  std::string name_base = "plt_plane_";
328  amrex::Vector<std::string> varnames = {"T", "Wsp"};
329 
330  int nplane = m_ps_mf.size();
331  for (int iplane(0); iplane<nplane; ++iplane) {
332  // Data members that can be used as-is
333  int dir = m_dir[iplane];
334  int lev = m_lev[iplane];
335  amrex::Real m_time = time[lev];
336  amrex::Vector<int> m_level_steps = {level_steps[lev]};
337  amrex::Vector<amrex::IntVect> m_ref_ratio = {ref_ratio[lev]};
338 
339  // Create modified geometry object corresponding to the plane
340  amrex::RealBox m_rb = m_bnd_rbx[iplane];
341  amrex::Box m_dom = getIndexBox(m_rb, geom[lev]);
342  amrex::Real point = m_rb.hi(dir);
343  amrex::Vector<int> is_per(AMREX_SPACEDIM,0);
344  for (int d(0); d<AMREX_SPACEDIM; ++d) {
345  if (d==dir) {
346  m_rb.setLo(d,point-0.5*geom[lev].CellSize(d));
347  m_rb.setHi(d,point+0.5*geom[lev].CellSize(d));
348  }
349  is_per[d] = geom[lev].isPeriodic(d);
350  }
351  amrex::Vector<amrex::Geometry> m_geom; m_geom.resize(1);
352  m_geom[0].define(m_dom, &m_rb, geom[lev].Coord(), is_per.data());
353 
354  // Create plotfile name
355  std::string name_plane = amrex::Concatenate(name_base, iplane , 5);
356  name_plane += "_step_";
357  std::string plotfilename = amrex::Concatenate(name_plane, m_level_steps[0], 5);
358 
359  // Get the data
360  amrex::Vector<const amrex::MultiFab*> mf = {m_ps_mf[iplane].get()};
361 
362  // Write each plane
363  WriteMultiLevelPlotfile(plotfilename, 1, mf,
364  varnames, m_geom, m_time,
365  m_level_steps, m_ref_ratio);
366  } // iplane
367  }
Coord
Definition: ERF_DataStruct.H:64
Here is the call graph for this function:

Member Data Documentation

◆ m_bnd_rbx

amrex::Vector<amrex::RealBox> PlaneSampler::m_bnd_rbx

◆ m_dir

amrex::Vector<int> PlaneSampler::m_dir

◆ m_lev

amrex::Vector<int> PlaneSampler::m_lev

◆ m_ps_mf

amrex::Vector<std::unique_ptr<amrex::MultiFab> > PlaneSampler::m_ps_mf

The documentation for this struct was generated from the following file: