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
 
amrex::Vector< std::string > m_name
 

Constructor & Destructor Documentation

◆ PlaneSampler()

PlaneSampler::PlaneSampler ( )
inline
483  {
484  amrex::ParmParse pp("erf");
485 
486  // Count number of lo and hi points define the plane
487  int n_plane_lo = pp.countval("sample_plane_lo") / AMREX_SPACEDIM;
488  int n_plane_hi = pp.countval("sample_plane_hi") / AMREX_SPACEDIM;
489  int n_plane_dir = pp.countval("sample_plane_dir");
490  AMREX_ALWAYS_ASSERT( (n_plane_lo==n_plane_hi ) &&
491  (n_plane_lo==n_plane_dir) );
492 
493  // Parse the data
494  if (n_plane_lo > 0) {
495  // Parse lo
496  amrex::Vector<amrex::Real> r_lo; r_lo.resize(n_plane_lo*AMREX_SPACEDIM);
497  amrex::Vector<amrex::Vector<amrex::Real>> rv_lo;
498  pp.queryarr("sample_plane_lo",r_lo,0,n_plane_lo*AMREX_SPACEDIM);
499  for (int i(0); i < n_plane_lo; i++) {
500  amrex::Vector<amrex::Real> rv = {r_lo[AMREX_SPACEDIM*i+0],
501  r_lo[AMREX_SPACEDIM*i+1],
502  r_lo[AMREX_SPACEDIM*i+2]};
503  rv_lo.push_back(rv);
504  }
505 
506  // Parse hi
507  amrex::Vector<amrex::Real> r_hi; r_hi.resize(n_plane_hi*AMREX_SPACEDIM);
508  amrex::Vector<amrex::Vector<amrex::Real>> rv_hi;
509  pp.queryarr("sample_plane_hi",r_hi,0,n_plane_hi*AMREX_SPACEDIM);
510  for (int i(0); i < n_plane_hi; i++) {
511  amrex::Vector<amrex::Real> rv = {r_hi[AMREX_SPACEDIM*i+0],
512  r_hi[AMREX_SPACEDIM*i+1],
513  r_hi[AMREX_SPACEDIM*i+2]};
514  rv_hi.push_back(rv);
515  }
516 
517  // Construct vector of bounding real boxes
518  m_bnd_rbx.resize(n_plane_lo);
519  for (int i(0); i < n_plane_hi; i++){
520  amrex::RealBox rbx(rv_lo[i].data(),rv_hi[i].data());
521  m_bnd_rbx[i] = rbx;
522  }
523 
524  // Parse directionality
525  m_dir.resize(n_plane_dir);
526  pp.queryarr("sample_plane_dir",m_dir,0,n_plane_dir);
527 
528  // Parse names
529  std::string name_base = "plt_plane_";
530  m_name.resize(n_plane_lo);
531  int n_names = pp.countval("sample_plane_name");
532  if (n_names > 0) {
533  AMREX_ALWAYS_ASSERT( n_names==n_plane_lo );
534  pp.queryarr("sample_plane_name",m_name,0,n_names);
535  } else {
536  for (int iplane(0); iplane<n_plane_lo; ++iplane) {
537  m_name[iplane] = amrex::Concatenate(name_base, iplane , 5);
538  }
539  }
540 
541  // Allocate space for level indicator
542  m_lev.resize(n_plane_dir,0);
543 
544  // Allocate space for MF pointers
545  m_ps_mf.resize(n_plane_lo);
546  }
547  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:230
amrex::Vector< int > m_dir
Definition: ERF_SampleData.H:675
amrex::Vector< int > m_lev
Definition: ERF_SampleData.H:676
amrex::Vector< std::string > m_name
Definition: ERF_SampleData.H:679
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ps_mf
Definition: ERF_SampleData.H:678
amrex::Vector< amrex::RealBox > m_bnd_rbx
Definition: ERF_SampleData.H:677
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
569  {
570  int nlev = static_cast<int>(vars_new.size());
571  int nplane = static_cast<int>(m_bnd_rbx.size());
572  int ncomp = 2;
573  bool interpolate = true;
574 
575  // Loop over each plane
576  for (int iplane(0); iplane<nplane; ++iplane) {
577  int dir = m_dir[iplane];
578  amrex::RealBox bnd_rbx = m_bnd_rbx[iplane];
579  amrex::Real point = bnd_rbx.lo(dir);
580 
581  // Search each level to get the finest data possible
582  for (int ilev(nlev-1); ilev>=0; --ilev) {
583 
584  // Construct CC velocities
585  amrex::MultiFab mf_cc_vel;
586  auto ba = vars_new[ilev][Vars::cons].boxArray();
587  auto dm = vars_new[ilev][Vars::cons].DistributionMap();
588  mf_cc_vel.define(ba, dm, AMREX_SPACEDIM, amrex::IntVect(1,1,1));
589  average_face_to_cellcenter(mf_cc_vel,0,
590  amrex::Array<const amrex::MultiFab*,3>{&vars_new[ilev][Vars::xvel],
591  &vars_new[ilev][Vars::yvel],
592  &vars_new[ilev][Vars::zvel]});
593 
594  // Construct vector of MFs holding T and WSP
595  amrex::MultiFab mf_cc_data;
596  mf_cc_data.define(ba, dm, ncomp, 1);
597 #ifdef _OPENMP
598 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
599 #endif
600  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
601  const amrex::Box& tbx = mfi.tilebox();
602  auto const& dfab = mf_cc_data.array(mfi);
603  auto const& tfab = vars_new[ilev][Vars::cons].array(mfi);
604  auto const& wfab = mf_cc_vel.array(mfi);
605  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
606  {
607  dfab(i,j,k,0) = tfab(i,j,k,1)/tfab(i,j,k,0);
608  dfab(i,j,k,1) = std::sqrt(wfab(i,j,k,0)*wfab(i,j,k,0)
609  + wfab(i,j,k,1)*wfab(i,j,k,1)
610  + wfab(i,j,k,2)*wfab(i,j,k,2)) ;
611  });
612 
613  }
614 
615  m_lev[iplane] = ilev;
616  m_ps_mf[iplane] = get_slice_data(dir, point, mf_cc_data, geom[ilev],
617  0, ncomp, interpolate, bnd_rbx);
618 
619  // We can stop if we got the entire plane
620  auto min_bnd_bx = m_ps_mf[iplane]->boxArray().minimalBox();
621  amrex::Box bnd_bx = getIndexBox(bnd_rbx, geom[ilev]);
622  if (bnd_bx == min_bnd_bx) { break; }
623 
624  } // ilev
625  }// iplane
626  }
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ xvel
Definition: ERF_IndexDefines.H:141
@ cons
Definition: ERF_IndexDefines.H:140
@ zvel
Definition: ERF_IndexDefines.H:143
@ yvel
Definition: ERF_IndexDefines.H:142
amrex::Box getIndexBox(const amrex::RealBox &real_box, const amrex::Geometry &geom)
Definition: ERF_SampleData.H:551
Here is the call graph for this function:

◆ getIndexBox()

amrex::Box PlaneSampler::getIndexBox ( const amrex::RealBox &  real_box,
const amrex::Geometry &  geom 
)
inline
552  {
553  amrex::IntVect slice_lo, slice_hi;
554 
555  AMREX_D_TERM(slice_lo[0]=static_cast<int>(std::floor((real_box.lo(0) - geom.ProbLo(0))/geom.CellSize(0)));,
556  slice_lo[1]=static_cast<int>(std::floor((real_box.lo(1) - geom.ProbLo(1))/geom.CellSize(1)));,
557  slice_lo[2]=static_cast<int>(std::floor((real_box.lo(2) - geom.ProbLo(2))/geom.CellSize(2))););
558 
559  AMREX_D_TERM(slice_hi[0]=static_cast<int>(std::floor((real_box.hi(0) - geom.ProbLo(0))/geom.CellSize(0)));,
560  slice_hi[1]=static_cast<int>(std::floor((real_box.hi(1) - geom.ProbLo(1))/geom.CellSize(1)));,
561  slice_hi[2]=static_cast<int>(std::floor((real_box.hi(2) - geom.ProbLo(2))/geom.CellSize(2))););
562 
563  return amrex::Box(slice_lo, slice_hi) & geom.Domain();
564  }

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
633  {
634  amrex::Vector<std::string> varnames = {"T", "Wsp"};
635 
636  int nplane = m_ps_mf.size();
637  for (int iplane(0); iplane<nplane; ++iplane) {
638  // Data members that can be used as-is
639  int dir = m_dir[iplane];
640  int lev = m_lev[iplane];
641  amrex::Real m_time = time[lev];
642  amrex::Vector<int> m_level_steps = {level_steps[lev]};
643  amrex::Vector<amrex::IntVect> m_ref_ratio = {ref_ratio[lev]};
644 
645  // Create modified geometry object corresponding to the plane
646  amrex::RealBox m_rb = m_bnd_rbx[iplane];
647  amrex::Box m_dom = getIndexBox(m_rb, geom[lev]);
648  amrex::Real point = m_rb.hi(dir);
649  amrex::Vector<int> is_per(AMREX_SPACEDIM,0);
650  for (int d(0); d<AMREX_SPACEDIM; ++d) {
651  if (d==dir) {
652  m_rb.setLo(d,point-0.5*geom[lev].CellSize(d));
653  m_rb.setHi(d,point+0.5*geom[lev].CellSize(d));
654  }
655  is_per[d] = geom[lev].isPeriodic(d);
656  }
657  amrex::Vector<amrex::Geometry> m_geom; m_geom.resize(1);
658  m_geom[0].define(m_dom, &m_rb, geom[lev].Coord(), is_per.data());
659 
660  // Create plotfile name
661  std::string name_plane = m_name[iplane];
662  name_plane += "_step_";
663  std::string plotfilename = amrex::Concatenate(name_plane, m_level_steps[0], 5);
664 
665  // Get the data
666  amrex::Vector<const amrex::MultiFab*> mf = {m_ps_mf[iplane].get()};
667 
668  // Write each plane
669  WriteMultiLevelPlotfile(plotfilename, 1, mf,
670  varnames, m_geom, m_time,
671  m_level_steps, m_ref_ratio);
672  } // iplane
673  }
Coord
Definition: ERF_DataStruct.H:85
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_name

amrex::Vector<std::string> PlaneSampler::m_name

Referenced by PlaneSampler(), and write_plane_mfs().

◆ 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: