ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_detail_CoarseFineFaces Namespace Reference

Functions

std::map< int, Vector< Box > > make_cf_zface_patches (const BoxArray &fba, const Box &fdom)
 
void clamp_outside_domain (MultiFab &mf, const Box &cdom, bool per_x, bool per_y)
 
void copy_slabs_into (MultiFab &dst, const MultiFab &slabs, const Vector< int > &slab_box)
 
void scale_by_column_mapfac (MultiFab &f, const MultiFab &mx, const MultiFab &my, const Periodicity &per, bool divide)
 
MultiFab weighted_mass_flux (const MultiFab &m, const MultiFab &area, const MultiFab &mf)
 
MultiFab weighted_zflux (const MultiFab &w, const MultiFab &mx, const MultiFab &my)
 
void fill_cf_momentum (ERFFillPatcher &patcher, MultiFab &mom, const MultiFab &area, const MultiFab &mapfac, bool mass_flux, double time_d, const Vector< BCRec > &bcs)
 

Detailed Description

The mass flux a (rho u) / m of a horizontal momentum component, on the faces of its valid region and the ghost faces that the momentum, the area and the map factor all hold.

Parameters
mFace momenta, (rho u) or (rho v)
areaFace areas, ax or ay
mfMap factor on those faces, m_uy or m_vx

Fill the coarse/fine faces of one horizontal momentum component. Where cf_interp_mass_flux holds, the fill gives the mass flux, which is multiplied by the fine map factor and divided by the fine area on the faces it set; all other faces keep their values exactly.

Function Documentation

◆ clamp_outside_domain()

void erf_detail_CoarseFineFaces::clamp_outside_domain ( MultiFab &  mf,
const Box &  cdom,
bool  per_x,
bool  per_y 
)

Outside a non-periodic side of the domain, repeat the nearest value inside it. The coarse planes extend past the domain as valid cells, so the coarse patch the interpolation copies from them sees finite, one-sided data there.

71 {
72  if (per_x && per_y) { return; }
73  const IndexType ixt = mf.ixType();
74  const int xlo = cdom.smallEnd(0);
75  const int ylo = cdom.smallEnd(1);
76  const int xhi = cdom.bigEnd(0) + (ixt.nodeCentered(0) ? 1 : 0);
77  const int yhi = cdom.bigEnd(1) + (ixt.nodeCentered(1) ? 1 : 0);
78  for (MFIter mfi(mf); mfi.isValid(); ++mfi) {
79  const Array4<Real> a = mf.array(mfi);
80  const Box bx = mfi.validbox();
81  const int ilo = bx.smallEnd(0), ihi = bx.bigEnd(0);
82  const int jlo = bx.smallEnd(1), jhi = bx.bigEnd(1);
83  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
84  {
85  int ii = per_x ? i : amrex::min(amrex::max(i, xlo), xhi);
86  int jj = per_y ? j : amrex::min(amrex::max(j, ylo), yhi);
87  ii = amrex::min(amrex::max(ii, ilo), ihi);
88  jj = amrex::min(amrex::max(jj, jlo), jhi);
89  if (ii != i || jj != j) { a(i,j,k) = a(ii,jj,k); }
90  });
91  }
92 }
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})

Referenced by ERF::cf_zface_coarse_at(), and ERF::cf_zface_coarse_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_slabs_into()

void erf_detail_CoarseFineFaces::copy_slabs_into ( MultiFab &  dst,
const MultiFab &  slabs,
const Vector< int > &  slab_box 
)

Copy fine slabs (one per coarse/fine face of a box, with the boxes' distribution) into the level's face array: slab s goes into box slab_box[s].

100 {
101  for (MFIter mfi(slabs); mfi.isValid(); ++mfi) {
102  const Array4<Real > d_a = dst.array(slab_box[mfi.index()]);
103  const Array4<Real const> s_a = slabs.const_array(mfi);
104  ParallelFor(mfi.validbox(), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
105  { d_a(i,j,k) = s_a(i,j,k); });
106  }
107 }

Referenced by ERF::set_cf_zghost_projection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill_cf_momentum()

void erf_detail_CoarseFineFaces::fill_cf_momentum ( ERFFillPatcher &  patcher,
MultiFab &  mom,
const MultiFab &  area,
const MultiFab &  mapfac,
bool  mass_flux,
double  time_d,
const Vector< BCRec > &  bcs 
)
1096 {
1097  PhysBCFunctNoOp null_bc;
1098  if (!mass_flux) {
1099  patcher.FillSet(mom, time_d, null_bc, bcs);
1100  return;
1101  }
1102  constexpr Real not_set = std::numeric_limits<Real>::max();
1103  MultiFab flux(mom.boxArray(), mom.DistributionMap(), 1, 0);
1104  flux.setVal(not_set);
1105  patcher.FillSet(flux, time_d, null_bc, bcs);
1106  for (MFIter mfi(flux, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1107  const Box bx = mfi.tilebox();
1108  const auto f = flux.const_array(mfi);
1109  const auto a = area.const_array(mfi);
1110  const auto mf = mapfac.const_array(mfi);
1111  const auto m = mom.array(mfi);
1112  const Real flag = not_set;
1113  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1114  {
1115  if (f(i,j,k) != flag) { m(i,j,k) = f(i,j,k) * mf(i,j,0) / a(i,j,k); }
1116  });
1117  }
1118 }
void FillSet(amrex::MultiFab &mf, double time, BC &cbc, amrex::Vector< amrex::BCRec > const &bcs)
Definition: ERF_FillPatcher.H:204

Referenced by ERF::FillSetHorizontalMomentaCF().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_cf_zface_patches()

std::map<int, Vector<Box> > erf_detail_CoarseFineFaces::make_cf_zface_patches ( const BoxArray &  fba,
const Box &  fdom 
)

The coarse/fine w-faces of every box of a level: its bottom (top) face where the cells just below (above) it are inside the domain and not in another box of the level.

44 {
45  std::map<int, Vector<Box>> out;
46  for (int n = 0; n < fba.size(); ++n) {
47  const Box& b = fba[n];
48  for (int side = 0; side < 2; ++side) {
49  const int kc = (side == 0) ? b.smallEnd(2) - 1 : b.bigEnd(2) + 1;
50  const int kf = (side == 0) ? b.smallEnd(2) : b.bigEnd(2) + 1;
51  if (kc < fdom.smallEnd(2) || kc > fdom.bigEnd(2)) { continue; }
52  Box outside(b); outside.setRange(2, kc);
53  BoxList uncovered = fba.complementIn(outside);
54  for (Box u : uncovered) {
55  u.surroundingNodes(2);
56  u.setRange(2, kf);
57  out[n].push_back(u);
58  }
59  }
60  }
61  return out;
62 }

Referenced by ERF::cf_zface_layout().

Here is the caller graph for this function:

◆ scale_by_column_mapfac()

void erf_detail_CoarseFineFaces::scale_by_column_mapfac ( MultiFab &  f,
const MultiFab &  mx,
const MultiFab &  my,
const Periodicity &  per,
bool  divide 
)

Multiply (or divide, with divide = true) the w-face data f, one plane of faces per box, by m_x m_y of the column each face caps (the cell map factors at its (i,j)). The vertical flux the advection and the projection balance is az Omega / (m_x m_y), so this converts between Omega and that flux. mx and my are the level's map factors, their ghost cells included.

118 {
119  BoxList bl;
120  for (int n = 0; n < f.boxArray().size(); ++n) {
121  const Box& b = f.boxArray()[n];
122  bl.push_back(Box(IntVect(b.smallEnd(0), b.smallEnd(1), 0), IntVect(b.bigEnd(0), b.bigEnd(1), 0)));
123  }
124  const BoxArray ba2d(std::move(bl));
125  MultiFab pmx(ba2d, f.DistributionMap(), 1, 0);
126  MultiFab pmy(ba2d, f.DistributionMap(), 1, 0);
127  pmx.setVal(1.0);
128  pmy.setVal(1.0);
129  pmx.ParallelCopy(mx, 0, 0, 1, mx.nGrowVect(), IntVect(0), per);
130  pmy.ParallelCopy(my, 0, 0, 1, my.nGrowVect(), IntVect(0), per);
131  for (MFIter mfi(f); mfi.isValid(); ++mfi) {
132  const Array4<Real > f_a = f.array(mfi);
133  const Array4<Real const> x_a = pmx.const_array(mfi);
134  const Array4<Real const> y_a = pmy.const_array(mfi);
135  ParallelFor(mfi.validbox(), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
136  {
137  const Real m2 = x_a(i,j,0) * y_a(i,j,0);
138  f_a(i,j,k) = divide ? f_a(i,j,k) / m2 : f_a(i,j,k) * m2;
139  });
140  }
141 }
GpuArray< int, AMREX_SPACEDIM > per
Definition: ERF_ActuatorSpreading.cpp:132

Referenced by ERF::cf_zface_coarse_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ weighted_mass_flux()

MultiFab erf_detail_CoarseFineFaces::weighted_mass_flux ( const MultiFab &  m,
const MultiFab &  area,
const MultiFab &  mf 
)
571 {
572  IntVect ng = amrex::min(m.nGrowVect(), area.nGrowVect());
573  ng[0] = amrex::min(ng[0], mf.nGrowVect()[0]);
574  ng[1] = amrex::min(ng[1], mf.nGrowVect()[1]);
575  MultiFab w(m.boxArray(), m.DistributionMap(), 1, ng);
576  for (MFIter mfi(w, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
577  const Box bx = mfi.growntilebox(ng);
578  const auto w_arr = w.array(mfi);
579  const auto m_arr = m.const_array(mfi);
580  const auto a_arr = area.const_array(mfi);
581  const auto f_arr = mf.const_array(mfi);
582  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
583  {
584  w_arr(i,j,k) = m_arr(i,j,k) * a_arr(i,j,k) / f_arr(i,j,0);
585  });
586  }
587  return w;
588 }
@ ng
Definition: ERF_Morrison.H:51

Referenced by ERF::average_down_mass_flux(), ERF::cf_anelastic_stage_registration(), and ERF::RegisterCoarseMomentumCF().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ weighted_zflux()

MultiFab erf_detail_CoarseFineFaces::weighted_zflux ( const MultiFab &  w,
const MultiFab &  mx,
const MultiFab &  my 
)

The vertical mass flux (rho w) / (m_x m_y) of a flat mesh, on the faces of its valid region and the ghost faces that the momentum and the map factors all hold.

Parameters
ww-face momenta, (rho w)
mxMap factor m_x
myMap factor m_y
600 {
601  IntVect ng = w.nGrowVect();
602  for (int d = 0; d < 2; ++d) {
603  ng[d] = amrex::min(ng[d], mx.nGrowVect()[d], my.nGrowVect()[d]);
604  }
605  MultiFab f(w.boxArray(), w.DistributionMap(), 1, ng);
606  for (MFIter mfi(f, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
607  const Box bx = mfi.growntilebox(ng);
608  const auto f_arr = f.array(mfi);
609  const auto w_arr = w.const_array(mfi);
610  const auto x_arr = mx.const_array(mfi);
611  const auto y_arr = my.const_array(mfi);
612  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
613  {
614  f_arr(i,j,k) = w_arr(i,j,k) / (x_arr(i,j,0) * y_arr(i,j,0));
615  });
616  }
617  return f;
618 }

Referenced by ERF::average_down_mass_flux(), and ERF::RegisterCoarseZMomentumCF().

Here is the call graph for this function:
Here is the caller graph for this function: