ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_AverageDown.cpp File Reference
#include <ERF.H>
#include <ERF_Utils.H>
Include dependency graph for ERF_AverageDown.cpp:

Functions

void average_down_faces_mapfac (const MultiFab &fine, MultiFab &crse, const IntVect &rr, const Periodicity &cper, const MultiFab &mf_f, const MultiFab &mf_c, const MultiFab *mf2_f, const MultiFab *mf2_c, const MultiFab *area_f, const MultiFab *area_c)
 

Function Documentation

◆ average_down_faces_mapfac()

void average_down_faces_mapfac ( const MultiFab &  fine,
MultiFab &  crse,
const IntVect &  rr,
const Periodicity &  cper,
const MultiFab &  mf_f,
const MultiFab &  mf_c,
const MultiFab *  mf2_f,
const MultiFab *  mf2_c,
const MultiFab *  area_f,
const MultiFab *  area_c 
)
21 {
22  const bool has_mf2 = (mf2_f != nullptr);
23  const bool has_area = (area_f != nullptr);
24  MultiFab wf(fine.boxArray(), fine.DistributionMap(), 1, 0);
25  for (MFIter mfi(wf, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
26  const Box bx = mfi.tilebox();
27  const auto w_arr = wf.array(mfi);
28  const auto m_arr = fine.const_array(mfi);
29  const auto f_arr = mf_f.const_array(mfi);
30  const auto g_arr = (has_mf2) ? mf2_f->const_array(mfi) : Array4<const Real>{};
31  const auto a_arr = (has_area) ? area_f->const_array(mfi) : Array4<const Real>{};
32  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
33  {
34  const Real mf = (has_mf2) ? f_arr(i,j,0) * g_arr(i,j,0) : f_arr(i,j,0);
35  const Real a = (has_area) ? a_arr(i,j,k) : one;
36  w_arr(i,j,k) = m_arr(i,j,k) * a / mf;
37  });
38  }
39 
40  // The coarse faces under the fine level, on the fine level's distribution
41  const BoxArray cba = amrex::coarsen(fine.boxArray(), rr);
42  const DistributionMapping& dm = fine.DistributionMap();
43  MultiFab wc(cba, dm, 1, 0);
44  amrex::average_down_faces(wf, wc, rr);
45 
46  // The coarse map factors on those faces (cell-centered in z, with no extent in z)
47  // Convert the list, not its boxes, so that it carries the type too; convert before
48  // collapsing z, since a nodal box of one point in z would convert to an empty cell box
49  BoxList bl2d = cba.boxList();
50  bl2d.convert(IndexType(IntVect(cba.ixType()[0], cba.ixType()[1], 0)));
51  for (auto& b : bl2d) {
52  b.setRange(2, 0);
53  }
54  const BoxArray ba2d(std::move(bl2d));
55  MultiFab fc(ba2d, dm, 1, 0);
56  fc.ParallelCopy(mf_c, 0, 0, 1, IntVect(0), IntVect(0), cper);
57  MultiFab gc;
58  if (has_mf2) {
59  gc.define(ba2d, dm, 1, 0);
60  gc.ParallelCopy(*mf2_c, 0, 0, 1, IntVect(0), IntVect(0), cper);
61  }
62  MultiFab ac;
63  if (has_area) {
64  ac.define(cba, dm, 1, 0);
65  ac.ParallelCopy(*area_c, 0, 0, 1, IntVect(0), IntVect(0), cper);
66  }
67 
68  for (MFIter mfi(wc, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
69  const Box bx = mfi.tilebox();
70  const auto w_arr = wc.array(mfi);
71  const auto f_arr = fc.const_array(mfi);
72  const auto g_arr = (has_mf2) ? gc.const_array(mfi) : Array4<const Real>{};
73  const auto a_arr = (has_area) ? ac.const_array(mfi) : Array4<const Real>{};
74  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
75  {
76  const Real mf = (has_mf2) ? f_arr(i,j,0) * g_arr(i,j,0) : f_arr(i,j,0);
77  const Real a = (has_area) ? a_arr(i,j,k) : one;
78  w_arr(i,j,k) *= mf / a;
79  });
80  }
81  crse.ParallelCopy(wc, 0, 0, 1, IntVect(0), IntVect(0), cper);
82 }
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);})
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
@ fc
Definition: ERF_AdvanceMorrison.cpp:141
real(c_double), private rr
Definition: ERF_module_mp_morr_two_moment.F90:224
real(c_double), private ac
Definition: ERF_module_mp_morr_two_moment.F90:181

Referenced by ERF::AverageDownTo().

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