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

Functions

void scale_by_face_jacobian (MultiFab &mf, int dir, const MultiFab &detJ, const Geometry &geom, bool divide)
 
void restrict_face_sources (std::array< MultiFab, AMREX_SPACEDIM > &src, int L, int lev, const Vector< BoxArray > &grids, const Vector< DistributionMapping > &dmap, const Vector< Geometry > &geom, const Vector< IntVect > &ref_ratio, const Vector< const MultiFab * > &detJ)
 
std::array< Real, AMREX_SPACEDIM > face_source_force (const std::array< MultiFab, AMREX_SPACEDIM > &src, const Geometry &geom, const MultiFab *detJ)
 
void restrict_face_sources (std::array< amrex::MultiFab, AMREX_SPACEDIM > &src, int L, int lev, const amrex::Vector< amrex::BoxArray > &grids, const amrex::Vector< amrex::DistributionMapping > &dmap, const amrex::Vector< amrex::Geometry > &geom, const amrex::Vector< amrex::IntVect > &ref_ratio, const amrex::Vector< const amrex::MultiFab * > &detJ)
 Restrict face-centered momentum sources from level L down to level lev < L. More...
 
void scale_by_face_jacobian (amrex::MultiFab &mf, int dir, const amrex::MultiFab &detJ, const amrex::Geometry &geom, bool divide)
 Multiply (divide = false) or divide (divide = true) the valid faces normal to dir by the face Jacobian J_f described above. More...
 
std::array< amrex::Real, AMREX_SPACEDIM > face_source_force (const std::array< amrex::MultiFab, AMREX_SPACEDIM > &src, const amrex::Geometry &geom, const amrex::MultiFab *detJ)
 The force [N] a face source puts on the air, per direction: the sum over the faces of the source times J_f dx dy dz, each face counted once. More...
 

Function Documentation

◆ face_source_force() [1/2]

std::array<amrex::Real,AMREX_SPACEDIM> erf_structure::face_source_force ( const std::array< amrex::MultiFab, AMREX_SPACEDIM > &  src,
const amrex::Geometry &  geom,
const amrex::MultiFab *  detJ 
)

The force [N] a face source puts on the air, per direction: the sum over the faces of the source times J_f dx dy dz, each face counted once.

src[d] holds the source on the faces normal to d of detJ's boxes (no ghost faces needed); detJ is nullptr on a uniform-dz mesh (J_f = 1). Reduces over the ranks.

◆ face_source_force() [2/2]

std::array<Real,AMREX_SPACEDIM> erf_structure::face_source_force ( const std::array< MultiFab, AMREX_SPACEDIM > &  src,
const Geometry &  geom,
const MultiFab *  detJ 
)
166 {
167  std::array<Real,AMREX_SPACEDIM> force{};
168  const Real dV = AMREX_D_TERM(geom.CellSize(0), * geom.CellSize(1), * geom.CellSize(2));
169  for (int d = 0; d < AMREX_SPACEDIM; ++d) {
170  MultiFab f(src[d].boxArray(), src[d].DistributionMap(), 1, 0);
171  MultiFab::Copy(f, src[d], 0, 0, 1, 0);
172  if (detJ) { scale_by_face_jacobian(f, d, *detJ, geom, false); }
173  force[d] = f.sum_unique(0, false, geom.periodicity()) * dV;
174  }
175  return force;
176 }
void scale_by_face_jacobian(MultiFab &mf, int dir, const MultiFab &detJ, const Geometry &geom, bool divide)
Definition: ERF_StructureCoarseSource.cpp:91
Here is the call graph for this function:

◆ restrict_face_sources() [1/2]

void erf_structure::restrict_face_sources ( std::array< amrex::MultiFab, AMREX_SPACEDIM > &  src,
int  L,
int  lev,
const amrex::Vector< amrex::BoxArray > &  grids,
const amrex::Vector< amrex::DistributionMapping > &  dmap,
const amrex::Vector< amrex::Geometry > &  geom,
const amrex::Vector< amrex::IntVect > &  ref_ratio,
const amrex::Vector< const amrex::MultiFab * > &  detJ 
)

Restrict face-centered momentum sources from level L down to level lev < L.

src holds the source [N/m^3] on the faces of grids[L] (x, y, z faces; it may have ghost faces). On return it holds the source on the faces of grids[lev], without ghost faces, zero away from the region level L covers.

The force on a face is the source times the face's control volume, J_f dx dy dz, with J_f the mesh Jacobian on the face (the mean of detJ in the two cells beside it, the one cell inside the domain on a non-periodic domain face). The restriction goes down one level at a time: coarse face I takes the forces of the fine faces r I + m, |m| < r, along the face normal with the weights (r - |m|) / r, and of every fine face across it. Each fine force is shared out with weights that add up to 1, so the total force is kept exactly, also when the fine level is split into boxes or crosses a periodic boundary. On a non-periodic domain face, where the boundary condition sets the momentum, a fine face inside the domain gives its whole force to the first coarse face inside, so the force on the faces inside the domain is kept too. The coarse source is the coarse force divided by the coarse face's control volume.

detJ[l] is detJ_cc of level l, with one ghost cell filled, on a stretched or terrain-following mesh, and nullptr on a uniform-dz mesh (J_f = 1 there, and no Jacobian is applied).

◆ restrict_face_sources() [2/2]

void erf_structure::restrict_face_sources ( std::array< MultiFab, AMREX_SPACEDIM > &  src,
int  L,
int  lev,
const Vector< BoxArray > &  grids,
const Vector< DistributionMapping > &  dmap,
const Vector< Geometry > &  geom,
const Vector< IntVect > &  ref_ratio,
const Vector< const MultiFab * > &  detJ 
)
128 {
129  AMREX_ALWAYS_ASSERT(lev >= 0 && lev < L);
130 
131  // The source times J_f on level L: the force per nominal cell volume dx dy dz
132  if (detJ[L]) {
133  for (int d = 0; d < AMREX_SPACEDIM; ++d) {
134  scale_by_face_jacobian(src[d], d, *detJ[L], geom[L], false);
135  }
136  }
137 
138  // Down one level at a time to level lev, each with the ghost faces the next restriction reads
139  for (int l = L - 1; l >= lev; --l) {
140  for (int d = 0; d < AMREX_SPACEDIM; ++d) {
141  IntVect ng_fine(0);
142  ng_fine[d] = ref_ratio[l][d] - 1;
143  if (src[d].nGrowVect() != ng_fine) {
144  MultiFab grown(src[d].boxArray(), src[d].DistributionMap(), 1, ng_fine);
145  grown.setVal(Real(0.0));
146  MultiFab::Copy(grown, src[d], 0, 0, 1, 0);
147  src[d] = std::move(grown);
148  }
149  src[d].FillBoundary(geom[l+1].periodicity());
150  MultiFab crse(convert(grids[l], IntVect::TheDimensionVector(d)), dmap[l], 1, 0);
151  restrict_face_field(src[d], crse, d, ref_ratio[l], geom[l]);
152  src[d] = std::move(crse);
153  }
154  }
155 
156  // Back from force per nominal volume to the source on level lev
157  if (detJ[lev]) {
158  for (int d = 0; d < AMREX_SPACEDIM; ++d) {
159  scale_by_face_jacobian(src[d], d, *detJ[lev], geom[lev], true);
160  }
161  }
162 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
void restrict_face_field(const MultiFab &fine, MultiFab &crse, int dir, const IntVect &rr, const Geometry &cgeom)
Definition: ERF_StructureCoarseSource.cpp:28
Here is the call graph for this function:

◆ scale_by_face_jacobian() [1/2]

void erf_structure::scale_by_face_jacobian ( amrex::MultiFab &  mf,
int  dir,
const amrex::MultiFab &  detJ,
const amrex::Geometry &  geom,
bool  divide 
)

Multiply (divide = false) or divide (divide = true) the valid faces normal to dir by the face Jacobian J_f described above.

mf lives on the faces of detJ's boxes, with detJ's distribution.

◆ scale_by_face_jacobian() [2/2]

void erf_structure::scale_by_face_jacobian ( MultiFab &  mf,
int  dir,
const MultiFab &  detJ,
const Geometry &  geom,
bool  divide 
)
92 {
93  AMREX_ALWAYS_ASSERT(detJ.nGrow() >= 1);
94  // A face on a non-periodic domain face takes the Jacobian of its one cell inside the
95  // domain: detJ_cc is not set below the ground (make_J)
96  const bool periodic = geom.isPeriodic(dir);
97  const int dlo = geom.Domain().smallEnd(dir);
98  const int dhi = geom.Domain().bigEnd(dir) + 1;
99 
100  for (MFIter mfi(mf, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
101  const Box& bx = mfi.tilebox();
102  const auto a = mf.array(mfi);
103  const auto J = detJ.const_array(mfi);
104  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
105  const IntVect hi(AMREX_D_DECL(i, j, k)); // the cell on the high side of the face
106  IntVect lo = hi; // and the one on its low side
107  lo[dir] -= 1;
108  Real Jf;
109  if (!periodic && hi[dir] == dlo) {
110  Jf = J(hi);
111  } else if (!periodic && hi[dir] == dhi) {
112  Jf = J(lo);
113  } else {
114  Jf = Real(0.5) * (J(lo) + J(hi));
115  }
116  a(i, j, k) = divide ? a(i, j, k) / Jf : a(i, j, k) * Jf;
117  });
118  }
119 }
GpuArray< int, AMREX_SPACEDIM > dhi
Definition: ERF_ActuatorSpreading.cpp:132
GpuArray< int, AMREX_SPACEDIM > dlo
Definition: ERF_ActuatorSpreading.cpp:132
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 face_source_force(), and restrict_face_sources().

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