ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
PlaneAverage Class Reference

#include <ERF_PlaneAverage.H>

Collaboration diagram for PlaneAverage:

Public Member Functions

AMREX_FORCE_INLINE PlaneAverage (const amrex::MultiFab *field_in, amrex::Geometry geom_in, int axis_in, bool inc_ghost=false)
 
 PlaneAverage ()=delete
 
 ~PlaneAverage ()=default
 
AMREX_FORCE_INLINE void operator() ()
 
AMREX_FORCE_INLINE amrex::Real line_average_interpolated (amrex::Real x, int comp) const
 
void set_precision (int p)
 
amrex::Real dx () const
 
amrex::Real xlo () const
 
int axis () const
 
int level () const
 
int ncomp () const
 
int ncell_plane () const
 
int ncell_line () const
 
const amrex::Vector< amrex::Real > & line_average () const
 
AMREX_FORCE_INLINE void line_average (int comp, amrex::Gpu::HostVector< amrex::Real > &l_vec)
 
const amrex::Vector< amrex::Real > & line_centroids () const
 
const amrex::MultiFab & field () const
 
template<typename IndexSelector >
AMREX_FORCE_INLINE void compute_averages (const IndexSelector &idxOp, const amrex::MultiFab &mfab)
 
template<typename IndexSelector >
void compute_averages (const IndexSelector &idxOp, const amrex::MultiFab &mfab)
 

Protected Attributes

int m_ncomp
 
amrex::Vector< amrex::Real > m_line_average
 
amrex::Vector< amrex::Real > m_line_xcentroid
 
amrex::Real m_dx
 
amrex::Real m_xlo
 
int m_ncell_plane
 
int m_ncell_line
 
int m_precision = 4
 
const int m_level = 0
 
const amrex::MultiFab * m_field
 
amrex::Geometry m_geom
 
const int m_axis
 
bool m_inc_ghost = false
 
amrex::IntVect m_ixtype
 
amrex::IntVect m_ng = amrex::IntVect(0)
 

Detailed Description

Basic averaging and interpolation operations

Constructor & Destructor Documentation

◆ PlaneAverage() [1/2]

PlaneAverage::PlaneAverage ( const amrex::MultiFab *  field_in,
amrex::Geometry  geom_in,
int  axis_in,
bool  inc_ghost = false 
)
explicit
94  : m_field(field_in), m_geom(geom_in), m_axis(axis_in), m_inc_ghost(inc_ghost)
95 {
96  AMREX_ALWAYS_ASSERT(m_axis >= 0 && m_axis < AMREX_SPACEDIM);
97 
98  m_xlo = m_geom.ProbLo(m_axis);
99  m_dx = m_geom.CellSize(m_axis);
100  m_ncomp = m_field->nComp();
101  m_ixtype = m_field->boxArray().ixType().toIntVect();
102 
103  amrex::Box domain = m_geom.Domain();
104  if (inc_ghost) {
105  m_ng = field_in->nGrowVect();
106  domain.grow(axis_in, m_ng[axis_in]);
107  }
108  amrex::IntVect dom_lo(domain.loVect());
109  amrex::IntVect dom_hi(domain.hiVect());
110 
111  m_ncell_line = dom_hi[m_axis] - dom_lo[m_axis] + 1 + m_ixtype[m_axis];
112 
113  m_ncell_plane = 1;
114  auto period = m_geom.periodicity();
115  for (int i = 0; i < AMREX_SPACEDIM; ++i) {
116  int p_fac = (!period.isPeriodic(i)) ? 1 : 0;
117  if (i != m_axis) m_ncell_plane *= (dom_hi[i] - dom_lo[i] + 1 + p_fac*m_ixtype[i]);
118  }
119 
120  m_line_average.resize(static_cast<size_t>(m_ncell_line) * m_ncomp, 0.0);
122 
123  for (int i = 0; i < m_ncell_line; ++i) {
124  m_line_xcentroid[i] = m_xlo + (i + 0.5) * m_dx;
125  }
126 }
int m_ncell_line
Definition: ERF_PlaneAverage.H:70
amrex::Real m_xlo
Definition: ERF_PlaneAverage.H:67
amrex::IntVect m_ixtype
Definition: ERF_PlaneAverage.H:79
amrex::IntVect m_ng
Definition: ERF_PlaneAverage.H:80
amrex::Vector< amrex::Real > m_line_xcentroid
Definition: ERF_PlaneAverage.H:64
const amrex::MultiFab * m_field
Definition: ERF_PlaneAverage.H:75
int m_ncell_plane
Definition: ERF_PlaneAverage.H:69
amrex::Vector< amrex::Real > m_line_average
Definition: ERF_PlaneAverage.H:62
const int m_axis
Definition: ERF_PlaneAverage.H:77
bool m_inc_ghost
Definition: ERF_PlaneAverage.H:78
amrex::Real m_dx
Definition: ERF_PlaneAverage.H:66
amrex::Geometry m_geom
Definition: ERF_PlaneAverage.H:76
int m_ncomp
Definition: ERF_PlaneAverage.H:59

◆ PlaneAverage() [2/2]

PlaneAverage::PlaneAverage ( )
delete

◆ ~PlaneAverage()

PlaneAverage::~PlaneAverage ( )
default

Member Function Documentation

◆ axis()

int PlaneAverage::axis ( ) const
inline
37 { return m_axis; }

◆ compute_averages() [1/2]

template<typename IndexSelector >
AMREX_FORCE_INLINE void PlaneAverage::compute_averages ( const IndexSelector &  idxOp,
const amrex::MultiFab &  mfab 
)

fill line storage with averages

Referenced by SAM::Compute_Coefficients(), make_mom_sources(), make_sources(), and operator()().

Here is the caller graph for this function:

◆ compute_averages() [2/2]

template<typename IndexSelector >
void PlaneAverage::compute_averages ( const IndexSelector &  idxOp,
const amrex::MultiFab &  mfab 
)
185 {
186  const amrex::Real denom = 1.0 / (amrex::Real)m_ncell_plane;
187  amrex::AsyncArray<amrex::Real> lavg(m_line_average.data(), m_line_average.size());
188  amrex::Real* line_avg = lavg.data();
189  const int ncomp = m_ncomp;
190 
191  amrex::Box domain = amrex::convert(m_geom.Domain(),m_ixtype);
192 
193  amrex::IntVect ng = amrex::IntVect(0);
194  int offset = m_ng[m_axis];
195  if (m_inc_ghost) ng[m_axis] = offset;
196 
197  std::unique_ptr<amrex::iMultiFab> mask = OwnerMask(*m_field, m_geom.periodicity(), ng);
198 
199 #ifdef _OPENMP
200 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
201 #endif
202  for (amrex::MFIter mfi(mfab, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
203  amrex::Box tbx = mfi.tilebox();
204  if (tbx.smallEnd(m_axis) == domain.smallEnd(m_axis)) tbx.growLo(m_axis,offset);
205  if (tbx.bigEnd (m_axis) == domain.bigEnd (m_axis)) tbx.growHi(m_axis,offset);
206  amrex::Box pbx = PerpendicularBox<IndexSelector>(tbx, amrex::IntVect(0));
207 
208  const amrex::Array4<const amrex::Real>& fab_arr = mfab.const_array(mfi);
209  const amrex::Array4<const int >& mask_arr = mask->const_array(mfi);
210 
211  amrex::ParallelFor(amrex::Gpu::KernelInfo().setReduction(true), pbx, [=]
212  AMREX_GPU_DEVICE( int p_i, int p_j, int p_k,
213  amrex::Gpu::Handler const& handler) noexcept
214  {
215  // Loop over the direction perpendicular to the plane.
216  // This reduces the atomic pressure on the destination arrays.
217  amrex::Box lbx = ParallelBox<IndexSelector>(tbx, amrex::IntVect{p_i, p_j, p_k});
218 
219  for (int k = lbx.smallEnd(2); k <= lbx.bigEnd(2); ++k) {
220  for (int j = lbx.smallEnd(1); j <= lbx.bigEnd(1); ++j) {
221  for (int i = lbx.smallEnd(0); i <= lbx.bigEnd(0); ++i) {
222  int ind = idxOp.getIndx(i, j, k) + offset;
223  for (int n = 0; n < ncomp; ++n) {
224  // NOTE: This factor is to avoid an if statement that will break
225  // the devicereducesum since all threads won't participate.
226  // This more performant than Gpu::Atomic::Add.
227  amrex::Real fac = (mask_arr(i,j,k)) ? 1.0 : 0.0;
228  amrex::Gpu::deviceReduceSum(&line_avg[ncomp * ind + n],
229  fab_arr(i, j, k, n) * denom * fac, handler);
230  }
231  }
232  }
233  }
234  });
235  }
236 
237  lavg.copyToHost(m_line_average.data(), m_line_average.size());
238  amrex::ParallelDescriptor::ReduceRealSum(m_line_average.data(), m_line_average.size());
239 }
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:28
int ncomp() const
Definition: ERF_PlaneAverage.H:39
Here is the call graph for this function:

◆ dx()

amrex::Real PlaneAverage::dx ( ) const
inline
34 { return m_dx; }

◆ field()

const amrex::MultiFab& PlaneAverage::field ( ) const
inline
56 { return *m_field; }

Referenced by SAM::Compute_Coefficients(), make_mom_sources(), and make_sources().

Here is the caller graph for this function:

◆ level()

int PlaneAverage::level ( ) const
inline
38 { return m_level; }
const int m_level
Definition: ERF_PlaneAverage.H:73

◆ line_average() [1/2]

const amrex::Vector<amrex::Real>& PlaneAverage::line_average ( ) const
inline
44  {
45  return m_line_average;
46  }

Referenced by SAM::Compute_Coefficients(), make_mom_sources(), and make_sources().

Here is the caller graph for this function:

◆ line_average() [2/2]

void PlaneAverage::line_average ( int  comp,
amrex::Gpu::HostVector< amrex::Real > &  l_vec 
)
155 {
156  AMREX_ALWAYS_ASSERT(comp >= 0 && comp < m_ncomp);
157 
158  for (int i = 0; i < m_ncell_line; i++)
159  l_vec[i] = m_line_average[m_ncomp * i + comp];
160 }

◆ line_average_interpolated()

amrex::Real PlaneAverage::line_average_interpolated ( amrex::Real  x,
int  comp 
) const

evaluate line average at specific location for any average component

130 {
131  AMREX_ALWAYS_ASSERT(comp >= 0 && comp < m_ncomp);
132 
133  amrex::Real c = 0.0;
134  int ind = 0;
135 
136  if (x > m_xlo + 0.5 * m_dx) {
137  ind = static_cast<int>(floor((x - m_xlo) / m_dx - 0.5));
138  const amrex::Real x1 = m_xlo + (ind + 0.5) * m_dx;
139  c = (x - x1) / m_dx;
140  }
141 
142  if (ind + 1 >= m_ncell_line) {
143  ind = m_ncell_line - 2;
144  c = 1.0;
145  }
146 
147  AMREX_ALWAYS_ASSERT(ind >= 0 && ind + 1 < m_ncell_line);
148 
149  return m_line_average[m_ncomp * ind + comp] * (1.0 - c) +
150  m_line_average[m_ncomp * (ind + 1) + comp] * c;
151 }

◆ line_centroids()

const amrex::Vector<amrex::Real>& PlaneAverage::line_centroids ( ) const
inline
52  {
53  return m_line_xcentroid;
54  }

◆ ncell_line()

int PlaneAverage::ncell_line ( ) const
inline
41 { return m_ncell_line; }

Referenced by SAM::Compute_Coefficients(), make_mom_sources(), and make_sources().

Here is the caller graph for this function:

◆ ncell_plane()

int PlaneAverage::ncell_plane ( ) const
inline
40 { return m_ncell_plane; }

◆ ncomp()

int PlaneAverage::ncomp ( ) const
inline
39 { return m_ncomp; }

Referenced by compute_averages().

Here is the caller graph for this function:

◆ operator()()

void PlaneAverage::operator() ( )
164 {
165  std::fill(m_line_average.begin(), m_line_average.end(), 0.0);
166  switch (m_axis) {
167  case 0:
169  break;
170  case 1:
172  break;
173  case 2:
175  break;
176  default:
177  amrex::Abort("axis must be equal to 0, 1, or 2");
178  break;
179  }
180 }
DirectionSelector< 0 > XDir
Definition: ERF_DirectionSelector.H:36
DirectionSelector< 1 > YDir
Definition: ERF_DirectionSelector.H:37
DirectionSelector< 2 > ZDir
Definition: ERF_DirectionSelector.H:38
AMREX_FORCE_INLINE void compute_averages(const IndexSelector &idxOp, const amrex::MultiFab &mfab)
Here is the call graph for this function:

◆ set_precision()

void PlaneAverage::set_precision ( int  p)
inline

change precision of text file output

32 { m_precision = p; }
int m_precision
Definition: ERF_PlaneAverage.H:72

◆ xlo()

amrex::Real PlaneAverage::xlo ( ) const
inline
35 { return m_xlo; }

Member Data Documentation

◆ m_axis

const int PlaneAverage::m_axis
protected

◆ m_dx

amrex::Real PlaneAverage::m_dx
protected

line storage for centroids of each cell along a line

Referenced by dx(), line_average_interpolated(), and PlaneAverage().

◆ m_field

const amrex::MultiFab* PlaneAverage::m_field
protected

level for plane averaging for now fixed at level=0

Referenced by compute_averages(), field(), operator()(), and PlaneAverage().

◆ m_geom

amrex::Geometry PlaneAverage::m_geom
protected

Referenced by compute_averages(), and PlaneAverage().

◆ m_inc_ghost

bool PlaneAverage::m_inc_ghost = false
protected

Referenced by compute_averages().

◆ m_ixtype

amrex::IntVect PlaneAverage::m_ixtype
protected

Referenced by compute_averages(), and PlaneAverage().

◆ m_level

const int PlaneAverage::m_level = 0
protected

precision for line plot text file

Referenced by level().

◆ m_line_average

amrex::Vector<amrex::Real> PlaneAverage::m_line_average
protected

number of average components line storage for the average velocity and tracer variables

Referenced by compute_averages(), line_average(), line_average_interpolated(), operator()(), and PlaneAverage().

◆ m_line_xcentroid

amrex::Vector<amrex::Real> PlaneAverage::m_line_xcentroid
protected

Referenced by line_centroids(), and PlaneAverage().

◆ m_ncell_line

int PlaneAverage::m_ncell_line
protected

number of cells in plane

Referenced by line_average(), line_average_interpolated(), ncell_line(), and PlaneAverage().

◆ m_ncell_plane

int PlaneAverage::m_ncell_plane
protected

bottom of domain in axis direction

Referenced by compute_averages(), ncell_plane(), and PlaneAverage().

◆ m_ncomp

int PlaneAverage::m_ncomp
protected

◆ m_ng

amrex::IntVect PlaneAverage::m_ng = amrex::IntVect(0)
protected

Referenced by compute_averages(), and PlaneAverage().

◆ m_precision

int PlaneAverage::m_precision = 4
protected

number of cells along line

Referenced by set_precision().

◆ m_xlo

amrex::Real PlaneAverage::m_xlo
protected

mesh spacing in axis direction

Referenced by line_average_interpolated(), PlaneAverage(), and xlo().


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