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

Functions

void restrict_face_field (const MultiFab &fine, MultiFab &crse, int dir, const IntVect &rr, const Geometry &cgeom)
 

Function Documentation

◆ restrict_face_field()

void erf_detail_StructureCoarseSource::restrict_face_field ( const MultiFab &  fine,
MultiFab &  crse,
int  dir,
const IntVect &  rr,
const Geometry &  cgeom 
)

Restrict a face field from a level onto the faces normal to dir of the next coarser level: coarse face I takes the fine faces r I + m, |m| < r, along dir with the weights (r - |m|) / r^2, averaged over the fine faces across it. Applied to the source times J_f, this is the force-space restriction of restrict_face_sources divided by the coarse control volume (dx dy dz of the coarse level is r_dir r_t1 r_t2 times the fine one). On a non-periodic domain face, where the boundary condition sets the momentum and a source does nothing, a fine face inside the domain gives its whole force to the first coarse face inside instead of sharing it with the domain face (weight r / r^2 there); the fine domain face's own force stays on the coarse domain face. fine must have r - 1 ghost faces along dir, filled where another box of its level holds them and zero outside the level.

29 {
30  AMREX_ASSERT(fine.boxArray().coarsenable(rr));
31  BoxArray cba = fine.boxArray();
32  cba.coarsen(rr);
33  MultiFab crse_on_fine(cba, fine.DistributionMap(), 1, 0);
34 
35  const int rn = rr[dir];
36  const int t1 = (dir + 1) % AMREX_SPACEDIM;
37  const int t2 = (dir + 2) % AMREX_SPACEDIM;
38  const int r1 = rr[t1];
39  const int r2 = rr[t2];
40  const Real inv_w = Real(1.0) / Real(rn * rn * r1 * r2);
41 
42  // The coarse domain faces normal to dir, where the boundary condition sets the momentum
43  const bool walls = !cgeom.isPeriodic(dir);
44  const int clo = cgeom.Domain().smallEnd(dir);
45  const int chi = cgeom.Domain().bigEnd(dir) + 1;
46  AMREX_ALWAYS_ASSERT(!walls || chi - clo >= 2);
47 
48  for (MFIter mfi(crse_on_fine, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
49  const Box& bx = mfi.tilebox();
50  const auto f = fine.const_array(mfi);
51  const auto c = crse_on_fine.array(mfi);
52  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
53  const IntVect I(AMREX_D_DECL(i, j, k));
54  const IntVect base = I * rr;
55  const int Id = I[dir];
56  Real s = Real(0.0);
57  for (int m = 1 - rn; m < rn; ++m) {
58  Real w = Real(rn - amrex::Math::abs(m));
59  if (walls && m != 0) {
60  if ((Id == clo && m > 0) || (Id == chi && m < 0)) {
61  continue; // given to the face inside
62  }
63  if ((Id == clo + 1 && m < 0) || (Id == chi - 1 && m > 0)) {
64  w = Real(rn); // the whole force, the domain face's share too
65  }
66  }
67  for (int a = 0; a < r1; ++a) {
68  for (int b = 0; b < r2; ++b) {
69  IntVect iv = base;
70  iv[dir] += m;
71  iv[t1] += a;
72  iv[t2] += b;
73  s += w * f(iv);
74  }
75  }
76  }
77  c(i, j, k) = s * inv_w;
78  });
79  }
80 
81  crse.setVal(Real(0.0));
82  crse.ParallelCopy(crse_on_fine, 0, 0, 1, IntVect(0), IntVect(0), cgeom.periodicity());
83 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
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);})
real(c_double), private rr
Definition: ERF_module_mp_morr_two_moment.F90:224

Referenced by erf_structure::restrict_face_sources().

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