Skip to content

Commit c333708

Browse files
authored
Bounded sampling (#4195)
The `get_line_data` and `get_slice_data` routines do not currently allow for a natural way to bound the returned MultiFab. In the former case, the line length is dictated by the bottom and top of the boxarray at that level. In the latter case, the plane is dictated by the problem domain at that level. This PR adds an optional `Box` argument to the `get_line_data` call and an optional `RealBox` argument to the `get_slice_data` call. These optional arguments bound the returned MuliFab. This feature has application in the ERF code in [PR 1897](erf-model/ERF#1897) where it is of great value to sample velocities in planes/lines just upstream of a wind turbine. Since the wind turbine is small in relation to the problem domain, the bounding feature ensures the returned data is actually what the user wants.
1 parent b00c828 commit c333708

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

Src/Base/AMReX_MultiFabUtil.H

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ namespace amrex
169169
std::unique_ptr<MultiFab> get_slice_data(int dir, Real coord,
170170
const MultiFab& cc,
171171
const Geometry& geom, int start_comp, int ncomp,
172-
bool interpolate=false);
172+
bool interpolate=false,
173+
RealBox const& bnd_rbx = RealBox());
173174

174175
/**
175176
* \brief Get data in a cell of MultiFab/FabArray
@@ -188,7 +189,7 @@ namespace amrex
188189
* specified by a direction and a cell.
189190
*/
190191
template <typename MF, std::enable_if_t<IsFabArray<MF>::value,int> FOO = 0>
191-
MF get_line_data (MF const& mf, int dir, IntVect const& cell);
192+
MF get_line_data (MF const& mf, int dir, IntVect const& cell, Box const& bnd_bx = Box());
192193

193194
//! Return an iMultiFab that has the same BoxArray and DistributionMapping
194195
//! as the coarse MultiFab cmf. Cells covered by the coarsened fine grids
@@ -996,26 +997,40 @@ Vector<typename MF::value_type> get_cell_data (MF const& mf, IntVect const& cell
996997
}
997998

998999
template <typename MF, std::enable_if_t<IsFabArray<MF>::value,int> FOO>
999-
MF get_line_data (MF const& mf, int dir, IntVect const& cell)
1000+
MF get_line_data (MF const& mf, int dir, IntVect const& cell, Box const& bnd_bx)
10001001
{
1002+
bool do_bnd = (!bnd_bx.isEmpty());
1003+
10011004
BoxArray const& ba = mf.boxArray();
10021005
DistributionMapping const& dm = mf.DistributionMap();
10031006
const auto nboxes = static_cast<int>(ba.size());
10041007

10051008
BoxList bl(ba.ixType());
10061009
Vector<int> procmap;
10071010
Vector<int> index_map;
1008-
for (int i = 0; i < nboxes; ++i) {
1009-
Box const& b = ba[i];
1010-
IntVect lo = cell;
1011-
lo[dir] = b.smallEnd(dir);
1012-
if (b.contains(lo)) {
1013-
IntVect hi = lo;
1014-
hi[dir] = b.bigEnd(dir);
1015-
Box b1d(lo,hi,b.ixType());
1016-
bl.push_back(b1d);
1017-
procmap.push_back(dm[i]);
1018-
index_map.push_back(i);
1011+
if (!do_bnd) {
1012+
for (int i = 0; i < nboxes; ++i) {
1013+
Box const& b = ba[i];
1014+
IntVect lo = cell;
1015+
lo[dir] = b.smallEnd(dir);
1016+
if (b.contains(lo)) {
1017+
IntVect hi = lo;
1018+
hi[dir] = b.bigEnd(dir);
1019+
Box b1d(lo,hi,b.ixType());
1020+
bl.push_back(b1d);
1021+
procmap.push_back(dm[i]);
1022+
index_map.push_back(i);
1023+
}
1024+
}
1025+
} else {
1026+
for (int i = 0; i < nboxes; ++i) {
1027+
Box const& b = ba[i];
1028+
Box const& b1d = bnd_bx & b;
1029+
if (b1d.ok()) {
1030+
bl.push_back(b1d);
1031+
procmap.push_back(dm[i]);
1032+
index_map.push_back(i);
1033+
}
10191034
}
10201035
}
10211036

Src/Base/AMReX_MultiFabUtil.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace {
99
using namespace amrex;
1010

1111
Box
12-
getIndexBox(const RealBox& real_box, const Geometry& geom) {
12+
getIndexBox (const RealBox& real_box, const Geometry& geom) {
1313
IntVect slice_lo, slice_hi;
1414

1515
AMREX_D_TERM(slice_lo[0]=static_cast<int>(std::floor((real_box.lo(0) - geom.ProbLo(0))/geom.CellSize(0)));,
@@ -24,12 +24,11 @@ namespace {
2424
}
2525

2626

27-
std::unique_ptr<MultiFab> allocateSlice(int dir, const MultiFab& cell_centered_data,
28-
int ncomp, const Geometry& geom, Real dir_coord,
29-
Vector<int>& slice_to_full_ba_map) {
27+
std::unique_ptr<MultiFab> allocateSlice (int dir, const MultiFab& cell_centered_data,
28+
int ncomp, const Geometry& geom, Real dir_coord,
29+
Vector<int>& slice_to_full_ba_map, RealBox real_slice) {
3030

3131
// Get our slice and convert to index space
32-
RealBox real_slice = geom.ProbDomain();
3332
real_slice.setLo(dir, dir_coord);
3433
real_slice.setHi(dir, dir_coord);
3534
Box slice_box = getIndexBox(real_slice, geom);
@@ -550,7 +549,7 @@ namespace amrex
550549
return amrex::cast<FabArray<BaseFab<Long> > > (imf);
551550
}
552551

553-
std::unique_ptr<MultiFab> get_slice_data(int dir, Real coord, const MultiFab& cc, const Geometry& geom, int start_comp, int ncomp, bool interpolate) {
552+
std::unique_ptr<MultiFab> get_slice_data(int dir, Real coord, const MultiFab& cc, const Geometry& geom, int start_comp, int ncomp, bool interpolate, RealBox const& bnd_rbx) {
554553

555554
BL_PROFILE("amrex::get_slice_data");
556555

@@ -559,9 +558,15 @@ namespace amrex
559558
}
560559

561560
const auto geomdata = geom.data();
561+
RealBox real_slice;
562+
if (bnd_rbx.ok()) {
563+
real_slice = bnd_rbx;
564+
} else {
565+
real_slice = geom.ProbDomain();
566+
}
562567

563568
Vector<int> slice_to_full_ba_map;
564-
std::unique_ptr<MultiFab> slice = allocateSlice(dir, cc, ncomp, geom, coord, slice_to_full_ba_map);
569+
std::unique_ptr<MultiFab> slice = allocateSlice(dir, cc, ncomp, geom, coord, slice_to_full_ba_map, real_slice);
565570

566571
if (!slice) {
567572
return nullptr;

0 commit comments

Comments
 (0)