Bring the ground heights and the composite source volume up to date with the grids: a no-op unless the BoxArray or DistributionMapping of a level, or the finest level, has changed since the last call. Aborts if no level has a cell center in the region. z_phys_nd and detJ must be allocated on every level. fill_ground(lev, slab) must fill a one-node-thick nodal slab at the bottom of the domain, on the footprint of every box of the level, with the ground heights (ERF::fill_surface_nodes, which interpolates them from coarser levels where the level does not reach the ground).
219 bool same = (finest_level + 1 ==
static_cast<int>(
m_lev.size()));
220 for (
int lev = 0; same && lev <= finest_level; ++lev) {
221 same = (
m_lev[lev].ba == grids[lev]) && (
m_lev[lev].dm == dmap[lev]);
223 if (same) {
return; }
226 m_lev.resize(finest_level + 1);
228 for (
int lev = 0; lev <= finest_level; ++lev) {
229 LevelGeometry& lg =
m_lev[lev];
236 const int kg = geom[lev].Domain().smallEnd(2);
238 amrex::BoxList bl = z_phys_nd[lev]->boxArray().boxList();
239 for (
auto& b : bl) { b.setRange(2, kg); }
240 lg.ground = std::make_unique<amrex::MultiFab>(amrex::BoxArray(std::move(bl)),
241 z_phys_nd[lev]->DistributionMap(), 1, 0);
242 fill_ground(lev, *lg.ground);
245 std::unique_ptr<amrex::iMultiFab> uncovered;
246 if (lev < finest_level) {
247 uncovered = std::make_unique<amrex::iMultiFab>(
248 amrex::makeFineMask(grids[lev], dmap[lev], grids[lev+1], ref_ratio[lev], 1, 0));
251 const auto dx = geom[lev].CellSizeArray();
252 const auto problo = geom[lev].ProbLoArray();
258 const amrex::Real dV0 = len[0] * len[1] * len[2];
260 amrex::ReduceOps<amrex::ReduceOpSum, amrex::ReduceOpSum> reduce_op;
261 amrex::ReduceData<amrex::Real, amrex::Real> reduce_data(reduce_op);
262 for (amrex::MFIter mfi(grids[lev], dmap[lev]); mfi.isValid(); ++mfi) {
263 const amrex::Box& bx = mfi.validbox();
264 auto z = z_phys_nd[lev]->const_array(mfi);
265 auto zg = lg.ground->const_array(mfi);
266 auto dj = detJ[lev]->const_array(mfi);
267 auto mx = mf_mx[lev]->const_array(mfi);
268 auto my = mf_my[lev]->const_array(mfi);
269 const bool has_mask = (uncovered !=
nullptr);
270 auto msk = has_mask ? uncovered->const_array(mfi) : amrex::Array4<int const>{};
271 reduce_op.eval(bx, reduce_data,
272 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) -> amrex::GpuTuple<amrex::Real, amrex::Real>
274 if (!
erf_mass_source::in_source(i,j,k,
z,zg,kg,
problo,
dx,
period,
x0,
y0,r2,hmax)) {
275 return {amrex::Real(0), amrex::Real(0)};
277 const amrex::Real dV = dV0 * dj(i,j,k) / (mx(i,j,0) * my(i,j,0));
278 const amrex::Real u = (!has_mask || msk(i,j,k) == 1) ? dV : amrex::Real(0);
282 auto hv = reduce_data.value(reduce_op);
283 amrex::Real v[2] = {amrex::get<0>(hv), amrex::get<1>(hv)};
284 amrex::ParallelDescriptor::ReduceRealSum(v, 2);
290 amrex::Abort(
"erf.mass_source: no cell centre lies inside the source region on any level; "
291 "make radius or height larger, or check that center is inside the domain");
293 amrex::Print() <<
"Mass source: region volume " <<
m_volume <<
" m^3 on the composite grid";
294 for (
int lev = 0; lev <= finest_level; ++lev) {
295 amrex::Print() << (lev == 0 ?
" (" :
", ") <<
"level " << lev <<
": " <<
m_lev[lev].volume <<
" m^3";
297 amrex::Print() <<
")" << std::endl;
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > LengthScaleCellSize(const amrex::Geometry &geom)
Definition: ERF_LengthScaleCellSize.H:28