1#ifndef AMREX_MultiFabUtil_H_
2#define AMREX_MultiFabUtil_H_
3#include <AMReX_Config.H>
12#include <AMReX_MultiFabUtil_C.H>
21 int ncomp,
int ngrow = 0);
24 int ncomp,
IntVect const& ng_vect);
53 template <FabArrayType CMF, FabArrayType FMF>
58 template <FabArrayType CMF, FabArrayType FMF>
83 bool use_harmonic_averaging =
false,
90 bool use_harmonic_averaging =
false,
97 bool use_harmonic_averaging,
101 template <FabArrayType MF>
107 template <FabArrayType MF>
113 template <FabArrayType MF>
119 template <FabArrayType MF>
130 template <BaseFabType FAB>
132 const IntVect& ratio,
int ngcrse=0);
135 template <FabArrayType MF>
140 template <BaseFabType FAB>
157 const IntVect& ratio,
int ngcrse=0);
160 template <BaseFabType FAB>
165 bool mfiter_is_definitely_safe=
false);
175 int scomp,
int ncomp,
const IntVect& ratio);
178 int scomp,
int ncomp,
int rr);
183 template <BaseFabType FAB>
185 int scomp,
int ncomp,
const IntVect& ratio);
186 template <BaseFabType FAB>
188 int scomp,
int ncomp,
int rr);
193 int scomp,
int ncomp,
203 void writeFabs (
const MultiFab& mf,
int comp,
int ncomp,
const std::string& name);
209 const Geometry& geom,
int start_comp,
int ncomp,
210 bool interpolate=
false,
220 template <FabArrayType MF>
229 template <FabArrayType MF>
235 template <BaseFabType FAB>
237 int crse_value = 0,
int fine_value = 1,
241 int crse_value = 0,
int fine_value = 1,
243 template <BaseFabType FAB>
245 Periodicity const& period,
int crse_value,
int fine_value,
249 Periodicity const& period,
int crse_value,
int fine_value,
251 template <BaseFabType FAB>
254 Periodicity const& period,
int crse_value,
int fine_value,
256 template <BaseFabType FAB>
259 Periodicity const& period,
int crse_value,
int fine_value,
287 template <
typename T,
typename U>
290 T mf_out(mf_in.boxArray(), mf_in.DistributionMap(), mf_in.nComp(), mf_in.nGrowVect());
293#pragma omp parallel if (Gpu::notInLaunchRegion())
297 const Long n = mfi.fabbox().numPts() * mf_in.nComp();
298 auto * pdst = mf_out[mfi].dataPtr();
299 auto const* psrc = mf_in [mfi].dataPtr();
302 pdst[i] =
static_cast<typename T::value_type
>(psrc[i]);
368 template <
typename Op,
typename T, BaseFabType FAB,
typename F>
369#ifndef AMREX_USE_CUDA
370 requires (IsCallableR<T,F,int,int,int,int>::value)
373 ReduceToPlane (
int direction,
Box const& domain, FabArray<FAB>
const& mf,
F const& f);
419 template <
typename Op, MultiFabLike FA,
typename F>
420#ifndef AMREX_USE_CUDA
421 requires (IsCallableR<
typename FA::value_type,
480 template <
typename Op, MultiFabLike FA,
typename F>
481#ifndef AMREX_USE_CUDA
482 requires (IsCallableR<
typename FA::value_type,
517 template <
typename Op, MultiFabLike FA,
typename F>
518#ifndef AMREX_USE_CUDA
519 requires (IsCallableR<
typename FA::value_type,
524 IntVect const& plane_max_grid_size,
F const& f);
544 Box const& domain,
int direction,
bool local =
false);
555 Vector<Geometry>
const& geom,
556 Vector<IntVect>
const& ratio,
586 void FillRandom (MultiFab& mf,
int scomp,
int ncomp);
612 [[nodiscard]] Vector<MultiFab>
convexify (Vector<MultiFab const*>
const& mf,
613 Vector<IntVect>
const& refinement_ratio);
618template <BaseFabType FAB>
621 int crse_value,
int fine_value,
MFInfo const& info)
623 return makeFineMask(cmf.boxArray(), cmf.DistributionMap(), cmf.nGrowVect(),
628template <BaseFabType FAB>
634 return makeFineMask(cmf.boxArray(), cmf.DistributionMap(), cmf.nGrowVect(),
635 fba, ratio, period, crse_value, fine_value, info);
638template <BaseFabType FAB>
640makeFineMask (
const FabArray<FAB>& cmf,
const FabArray<FAB>& fmf,
642 Periodicity const& period,
int crse_value,
int fine_value,
645 iMultiFab mask(cmf.boxArray(), cmf.DistributionMap(), 1, cnghost, info);
649 1, 0,
MFInfo().SetAlloc(
false));
651 mask.
setVal(fine_value, cpc, 0, 1);
656template <BaseFabType FAB>
658makeFineMask (
const FabArray<FAB>& cmf,
const FabArray<FAB>& fmf,
660 Periodicity const& period,
int crse_value,
int fine_value,
663 iMultiFab mask(cmf.boxArray(), cmf.DistributionMap(), 1, cnghost, info);
667 1, 0,
MFInfo().SetAlloc(
false));
669 mask.
setVal(fine_value, cpc, 0, 1);
678template <BaseFabType FAB>
680 const IntVect& ratio,
int ngcrse,
bool mfiter_is_definitely_safe)
686 int ncomp = crse.nComp();
687 using value_type =
typename FAB::value_type;
689 if (mfiter_is_definitely_safe ||
isMFIterSafe(fine, crse))
692#pragma omp parallel if (Gpu::notInLaunchRegion())
696 const Box& bx = mfi.growntilebox(ngcrse);
702 amrex_avgdown_nodes(tbx,crsearr,finearr,0,0,ncomp,ratio);
711 crse.ParallelCopy(ctmp,0,0,ncomp,ngcrse,ngcrse);
720template <BaseFabType FAB>
721void average_down (
const FabArray<FAB>& S_fine, FabArray<FAB>& S_crse,
int scomp,
int ncomp,
int rr)
726template <BaseFabType FAB>
727void average_down (
const FabArray<FAB>& S_fine, FabArray<FAB>& S_crse,
732 AMREX_ASSERT((S_crse.is_cell_centered() && S_fine.is_cell_centered()) ||
733 (S_crse.is_nodal() && S_fine.is_nodal()));
735 using value_type =
typename FAB::value_type;
737 bool is_cell_centered = S_crse.is_cell_centered();
742 BoxArray crse_S_fine_BA = S_fine.boxArray(); crse_S_fine_BA.
coarsen(ratio);
744 if (crse_S_fine_BA == S_crse.boxArray() && S_fine.DistributionMap() == S_crse.DistributionMap())
748 auto const& crsema = S_crse.arrays();
749 auto const& finema = S_fine.const_arrays();
750 if (is_cell_centered) {
754 amrex_avgdown(i,j,k,n,crsema[box_no],finema[box_no],scomp,scomp,ratio);
760 amrex_avgdown_nodes(i,j,k,n,crsema[box_no],finema[box_no],scomp,scomp,ratio);
770#pragma omp parallel if (Gpu::notInLaunchRegion())
775 const Box& bx = mfi.tilebox();
779 if (is_cell_centered) {
782 amrex_avgdown(i,j,k,n,crsearr,finearr,scomp,scomp,ratio);
787 amrex_avgdown_nodes(i,j,k,n,crsearr,finearr,scomp,scomp,ratio);
795 FabArray<FAB> crse_S_fine(crse_S_fine_BA, S_fine.DistributionMap(), ncomp, 0,
800 auto const& crsema = crse_S_fine.
arrays();
801 auto const& finema = S_fine.const_arrays();
802 if (is_cell_centered) {
806 amrex_avgdown(i,j,k,n,crsema[box_no],finema[box_no],0,scomp,ratio);
812 amrex_avgdown_nodes(i,j,k,n,crsema[box_no],finema[box_no],0,scomp,ratio);
822#pragma omp parallel if (Gpu::notInLaunchRegion())
827 const Box& bx = mfi.tilebox();
835 if (is_cell_centered) {
838 amrex_avgdown(i,j,k,n,crsearr,finearr,0,scomp,ratio);
843 amrex_avgdown_nodes(i,j,k,n,crsearr,finearr,0,scomp,ratio);
849 S_crse.ParallelCopy(crse_S_fine,0,scomp,ncomp);
869 int numcomp,
IntVect nghost,
bool local)
872 BL_ASSERT(
x.DistributionMap() ==
y.DistributionMap());
873 BL_ASSERT(
x.nGrowVect().allGE(nghost) &&
y.nGrowVect().allGE(nghost));
878 auto const& xma =
x.const_arrays();
879 auto const& yma =
y.const_arrays();
884 auto const& xfab = xma[box_no];
885 auto const& yfab = yma[box_no];
886 for (
int n = 0; n < numcomp; ++n) {
887 t += f(xfab(i,j,k,xcomp+n) , yfab(i,j,k,ycomp+n));
895#pragma omp parallel if (!system::regtest_reduction) reduction(+:sm)
899 Box const& bx = mfi.growntilebox(nghost);
904 sm += f(xfab(i,j,k,xcomp+n) , yfab(i,j,k,ycomp+n));
924template <
typename MMF,
typename Pred,
typename F>
931 int numcomp,
IntVect nghost,
bool local)
935 BL_ASSERT(
x.DistributionMap() ==
y.DistributionMap());
936 BL_ASSERT(
x.DistributionMap() == mask.DistributionMap());
937 BL_ASSERT(
x.nGrowVect().allGE(nghost) &&
y.nGrowVect().allGE(nghost));
938 BL_ASSERT(mask.nGrowVect().allGE(nghost));
943 auto const& xma =
x.const_arrays();
944 auto const& yma =
y.const_arrays();
945 auto const& mma = mask.const_arrays();
950 if (pf(mma[box_no](i,j,k))) {
951 auto const& xfab = xma[box_no];
952 auto const& yfab = yma[box_no];
953 for (
int n = 0; n < numcomp; ++n) {
954 t += f(xfab(i,j,k,xcomp+n) , yfab(i,j,k,ycomp+n));
963#pragma omp parallel if (!system::regtest_reduction) reduction(+:sm)
967 Box const& bx = mfi.growntilebox(nghost);
970 auto const& mfab = mask.const_array(mfi);
973 if (pf(mfab(i,j,k))) {
974 sm += f(xfab(i,j,k,xcomp+n) , yfab(i,j,k,ycomp+n));
987template <FabArrayType CMF, FabArrayType FMF>
996template <FabArrayType CMF, FabArrayType FMF>
1006 auto const& ccma = cc.arrays();
1007 AMREX_D_TERM(
auto const& fxma = fc[0]->const_arrays();,
1008 auto const& fyma = fc[1]->const_arrays();,
1009 auto const& fzma = fc[2]->const_arrays(););
1013#if (AMREX_SPACEDIM == 1)
1017 amrex_avg_fc_to_cc(i,j,k, ccma[box_no],
AMREX_D_DECL(fxma[box_no],
1021#
if (AMREX_SPACEDIM == 1)
1033#pragma omp parallel if (Gpu::notInLaunchRegion())
1037 const Box bx = mfi.growntilebox(ng_vect);
1038 auto const& ccarr = cc.array(mfi);
1039 AMREX_D_TERM(
auto const& fxarr = fc[0]->const_array(mfi);,
1040 auto const& fyarr = fc[1]->const_array(mfi);,
1041 auto const& fzarr = fc[2]->const_array(mfi););
1043#if (AMREX_SPACEDIM == 1)
1048 amrex_avg_fc_to_cc(i,j,k, ccarr, fxarr, dcomp, gd);
1053 amrex_avg_fc_to_cc(i,j,k, ccarr,
AMREX_D_DECL(fxarr,fyarr,fzarr), dcomp);
1060template <FabArrayType MF>
1063 const IntVect& ratio,
int ngcrse)
1065 AMREX_ASSERT(fine.size() == AMREX_SPACEDIM && crse.
size() == AMREX_SPACEDIM);
1073template <FabArrayType MF>
1080template <FabArrayType MF>
1083 int ratio,
int ngcrse)
1088template <FabArrayType MF>
1091 const IntVect& ratio,
int ngcrse)
1093 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1098template <BaseFabType FAB>
1106 const auto type = fine.ixType();
1108 for (dir = 0; dir < AMREX_SPACEDIM; ++dir) {
1109 if (type.nodeCentered(dir)) {
break; }
1111 auto tmptype = type;
1113 if (dir >= AMREX_SPACEDIM || !tmptype.cellCentered()) {
1114 amrex::Abort(
"average_down_faces: not face index type");
1116 const int ncomp = crse.nComp();
1121 auto const& crsema = crse.arrays();
1122 auto const& finema = fine.const_arrays();
1126 amrex_avgdown_faces(i,j,k,n, crsema[box_no], finema[box_no], 0, 0, ratio, dir);
1135#pragma omp parallel if (Gpu::notInLaunchRegion())
1139 const Box& bx = mfi.growntilebox(ngcrse);
1140 auto const& crsearr = crse.array(mfi);
1141 auto const& finearr = fine.const_array(mfi);
1144 amrex_avgdown_faces(i,j,k,n, crsearr, finearr, 0, 0, ratio, dir);
1154 crse.ParallelCopy(ctmp,0,0,ncomp,ngcrse,ngcrse);
1158template <FabArrayType MF>
1163 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1168template <BaseFabType FAB>
1178template <FabArrayType MF>
1181 using T =
typename MF::value_type;
1182 const int ncomp = mf.nComp();
1184 auto* dp = dv.
data();
1186 auto loc = cell.dim3();
1189 Box const& box = mfi.validbox();
1192 auto const& fab = mf.const_array(mfi);
1195 for (
int n = 0; n < ncomp; ++n) {
1196 dp[n] = fab(loc.x,loc.y,loc.z,n);
1209template <FabArrayType MF>
1212 bool do_bnd = (!bnd_bx.isEmpty());
1214 BoxArray const& ba = mf.boxArray();
1216 const auto nboxes =
static_cast<int>(ba.
size());
1222 for (
int i = 0; i < nboxes; ++i) {
1223 Box const& b = ba[i];
1231 procmap.push_back(dm[i]);
1232 index_map.push_back(i);
1236 for (
int i = 0; i < nboxes; ++i) {
1237 Box const& b = ba[i];
1238 Box const& b1d = bnd_bx & b;
1241 procmap.push_back(dm[i]);
1242 index_map.push_back(i);
1252 MF rmf(rba, rdm, mf.nComp(),
IntVect(0),
1253 MFInfo().SetArena(mf.arena()));
1255#pragma omp parallel if (Gpu::notInLaunchRegion())
1258 Box const& b = mfi.validbox();
1259 auto const& dfab = rmf.array(mfi);
1260 auto const& sfab = mf.const_array(index_map[mfi.index()]);
1264 dfab(i,j,k,n) = sfab(i,j,k,n);
1273template <
typename Op,
typename T,
typename F>
1274void reduce_to_plane (
Array4<T> const& ar,
int direction,
Box const& bx,
int box_no,
1277#if defined(AMREX_USE_GPU)
1282 constexpr int nthreads = 128;
1283 auto nblocks =
static_cast<int>(b2d.numPts());
1284#ifdef AMREX_USE_SYCL
1289 int bid = h.blockIdx();
1290 int tid = h.threadIdx();
1295 int bid = blockIdx.x;
1296 int tid = threadIdx.x;
1301 if (direction == 0) {
1302 int k = bid / len.y;
1303 int j = bid - k*len.y;
1306 for (
int i = blo.x + tid; i < blo.x+len.x; i += nthreads) {
1307 Op().local_update(tmp, f(box_no,i,j,k));
1310 }
else if (direction == 1) {
1311 int k = bid / len.x;
1312 int i = bid - k*len.x;
1315 for (
int j = blo.y + tid; j < blo.y+len.y; j += nthreads) {
1316 Op().local_update(tmp, f(box_no,i,j,k));
1320 int j = bid / len.x;
1321 int i = bid - j*len.x;
1324 for (
int k = blo.z + tid; k < blo.z+len.z; k += nthreads) {
1325 Op().local_update(tmp, f(box_no,i,j,k));
1329#ifdef AMREX_USE_SYCL
1330 Op().template parallel_update<T>(*
p, tmp, h);
1332 Op().template parallel_update<T,nthreads>(*
p, tmp);
1337 if (direction == 0) {
1340 Op().local_update(ar(0,j,k), f(box_no,i,j,k));
1342 }
else if (direction == 1) {
1345 Op().local_update(ar(i,0,k), f(box_no,i,j,k));
1350 Op().local_update(ar(i,j,0), f(box_no,i,j,k));
1358template <
typename Op,
typename T, BaseFabType FAB,
typename F>
1359#ifndef AMREX_USE_CUDA
1360requires (IsCallableR<T,F,int,int,int,int>::value)
1363ReduceToPlane (
int direction,
Box const& a_domain, FabArray<FAB>
const& mf,
F const& f)
1367 Box domain2d = domain;
1375 auto const& ar = r.
array();
1377 for (
MFIter mfi(mf,
MFItInfo().UseDefaultStream().DisableDeviceSync());
1380 Box bx = mfi.validbox() & domain;
1382 int box_no = mfi.LocalIndex();
1383 detail::reduce_to_plane<Op, T>(ar, direction, bx, box_no, f);
1395template <
typename Op, MultiFabLike FA,
typename F>
1396FA reduce_to_plane (
int direction, Box
const& domain, FA
const& mf, F
const& f,
1397 IntVect
const& nghost = IntVect(0))
1399 using T =
typename FA::value_type;
1405 amrex::Abort(
"ReduceToPlaneMF: mf's BoxArray must have a rectangular domain.");
1411 "ReduceToPlaneMF2: nghost must not exceed mf.nGrowVect().");
1420 ng2d[direction] = 0;
1423 BoxList bl = mf.boxArray().boxList();
1424 for (
auto& b : bl) {
1425 b.setRange(direction, 0);
1427 BoxArray ba(std::move(bl));
1428 FA tmpfa(ba, mf.DistributionMap(), 1, ng2d);
1429 tmpfa.setVal(initval);
1431 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
1435 int box_no = mfi.LocalIndex();
1436 detail::reduce_to_plane<Op, T>(tmpfa.array(mfi), direction, bx, box_no, f);
1446template <
typename Op, MultiFabLike FA,
typename F>
1447#ifndef AMREX_USE_CUDA
1448requires (IsCallableR<
typename FA::value_type,
1454 fa3.ParallelCopy(fa2);
1459 return std::move(fa3);
1462template <
typename Op, MultiFabLike FA,
typename F>
1463#ifndef AMREX_USE_CUDA
1464requires (IsCallableR<
typename FA::value_type,
1471 using T =
typename FA::value_type;
1476 auto tmpmf = detail::reduce_to_plane<Op>(direction, domain, mf, f, nghost);
1480 auto const& ba3d = mf.boxArray();
1481 auto const& dm3d = mf.DistributionMap();
1482 int dlo = domain.smallEnd(direction);
1483 for (
int i = 0, N = mf.size(); i < N; ++i) {
1485 if (b.
smallEnd(direction) <= dlo && dlo <= b.
bigEnd(direction)) {
1488 procmap2d.push_back(dm3d[i]);
1495 FA mf2d(ba2d, dm2d, 1, 0);
1496 mf2d.setVal(initval);
1498 static_assert(std::is_same_v<Op, ReduceOpSum>,
"Currently only ReduceOpSum is supported.");
1502 ng2d[direction] = 0;
1503 mf2d.ParallelAdd(tmpmf, 0, 0, 1, ng2d,
IntVect(0),
IntVect(0), period);
1505 return std::make_pair(std::move(tmpmf), std::move(mf2d));
1508template <
typename Op, MultiFabLike FA,
typename F>
1509#ifndef AMREX_USE_CUDA
1510requires (IsCallableR<
typename FA::value_type,
1518 "ReduceToPlaneMF2Patchy: only cell-centered data is supported.");
1522 "ReduceToPlaneMF2Patchy: subdomains are not supported; domain must cover the full extent of mf.boxArray().");
1524 using T =
typename FA::value_type;
1528 BoxList bl_patch2d = mf.boxArray().boxList();
1529 for (
auto& b : bl_patch2d) {
1530 b.setRange(direction, 0);
1532 BoxArray ba_patch2d(std::move(bl_patch2d));
1533 FA tmpmf(ba_patch2d, mf.DistributionMap(), 1, 0);
1534 tmpmf.setVal(initval);
1538 Box bx = mfi.validbox() & ndomain;
1540 int box_no = mfi.LocalIndex();
1541 detail::reduce_to_plane<Op, T>(tmpmf.array(mfi), direction, bx, box_no, f);
1547 BoxArray ba2d(std::move(bl_unique));
1551 "ReduceToPlaneMF2Patchy: plane_max_grid_size must be >= 1 in every direction.");
1552 IntVect mgs2d = plane_max_grid_size;
1553 mgs2d[direction] = 1;
1558 FA mf2d(ba2d, dm2d, 1, 0);
1559 mf2d.setVal(initval);
1561 static_assert(std::is_same_v<Op, ReduceOpSum>,
"Currently only ReduceOpSum is supported.");
1562 mf2d.ParallelAdd(tmpmf);
1564 return std::make_pair(std::move(tmpmf), std::move(mf2d));
Fixed-size array types for use on GPU and CPU.
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_HOST_DEVICE_PARALLEL_FOR_1D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:109
#define AMREX_HOST_DEVICE_PARALLEL_FOR_3D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:110
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:111
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA(...)
Definition AMReX_GpuLaunch.nolint.H:16
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_LOOP_3D(bx, i, j, k, block)
#define AMREX_LOOP_4D(bx, ncomp, i, j, k, n, block)
while parser_exe_t p
Definition AMReX_Parser_Exe_Body.H:33
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:243
Array4< T const > array() const noexcept
Create an Array4 view over all components.
Definition AMReX_BaseFab.H:496
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
IndexType ixType() const noexcept
Return index type of this BoxArray.
Definition AMReX_BoxArray.H:1269
BoxList boxList() const
Create a BoxList from this BoxArray.
Definition AMReX_BoxArray.cpp:968
void removeOverlap(bool simplify=true)
Change the BoxArray to one with no overlap and then simplify it (see the simplify function in BoxList...
Definition AMReX_BoxArray.cpp:1477
BoxArray & coarsen(int refinement_ratio)
Coarsen each Box in the BoxArray by refinement_ratio.
Definition AMReX_BoxArray.cpp:685
Long size() const noexcept
Return the number of boxes in the BoxArray.
Definition AMReX_BoxArray.H:758
BoxArray & maxSize(int block_size)
Split any Box whose side length exceeds block_size.
Definition AMReX_BoxArray.cpp:553
A list of Boxes sharing a common IndexType.
Definition AMReX_BoxList.H:109
bool isEmpty() const noexcept
Is this BoxList empty?
Definition AMReX_BoxList.H:202
int simplify(bool best=false)
Merge adjacent Boxes in this BoxList. Return the number of Boxes merged. If "best" is specified we do...
Definition AMReX_BoxList.cpp:676
void push_back(const Box &bn)
Append a Box to this BoxList.
Definition AMReX_BoxList.H:151
__host__ __device__ const IntVectND< dim > & bigEnd() const &noexcept
Return the inclusive upper bound of the box.
Definition AMReX_Box.H:136
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:233
__host__ __device__ IndexTypeND< dim > ixType() const noexcept
Return the indexing type.
Definition AMReX_Box.H:148
__host__ __device__ BoxND & setRange(int dir, int sm_index, int n_cells=1) noexcept
Set the entire range in a given direction, starting at sm_index with length n_cells....
Definition AMReX_Box.H:1143
__host__ __device__ bool ok() const noexcept
Return true if high bounds are >= low bounds and the index type is valid.
Definition AMReX_Box.H:229
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
Return the inclusive lower bound of the box.
Definition AMReX_Box.H:124
Default FabFactory that calls new / delete on the FAB type directly.
Definition AMReX_FabFactory.H:124
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:55
bool isFusingCandidate() const noexcept
Is this a good candidate for kernel fusing?
Definition AMReX_FabArrayBase.cpp:2795
const CPC & getCPC(const IntVect &dstng, const FabArrayBase &src, const IntVect &srcng, const Periodicity &period, bool to_ghost_cells_only=false, const IntVect &offset=IntVect(0)) const
Retrieve (and cache) the ParallelCopy metadata between two FabArrays.
Definition AMReX_FabArrayBase.cpp:583
int nComp() const noexcept
Return number of variables (aka components) associated with each point.
Definition AMReX_FabArrayBase.H:88
An Array of FortranArrayBox(FAB)-like Objects.
Definition AMReX_FabArray.H:383
LayoutData< int > RecvLayoutMask(const CommMetaData &thecmd)
Definition AMReX_FabArray.H:4258
MultiArray4< typename FabArray< FAB >::value_type > arrays() noexcept
Build, if needed, and return mutable Array4 views for local FABs.
Definition AMReX_FabArray.H:741
void setVal(value_type val)
Set all components in the entire region of each FAB to val.
Definition AMReX_FabArray.H:3068
Array4< typename FabArray< FAB >::value_type const > array(const MFIter &mfi) const noexcept
Read-only Array4 view for the FAB referenced by iterator mfi.
Definition AMReX_FabArray.H:649
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:87
Periodicity periodicity() const noexcept
Return the Periodicity based on the length of the domain.
Definition AMReX_Geometry.H:426
GPU-compatible tuple.
Definition AMReX_Tuple.H:104
static constexpr int warp_size
Definition AMReX_GpuDevice.H:239
__host__ static __device__ constexpr IntVectND< dim > TheUnitVector() noexcept
Definition AMReX_IntVect.H:788
__host__ __device__ constexpr bool allGE(const IntVectND< dim > &rhs) const noexcept
Returns true if this is greater than or equal to argument for all components. NOTE: This is NOT a str...
Definition AMReX_IntVect.H:549
__host__ static __device__ constexpr IntVectND< dim > TheZeroVector() noexcept
Definition AMReX_IntVect.H:778
a one-thingy-per-box distributed object
Definition AMReX_LayoutData.H:13
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:176
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
iterator begin() noexcept
Definition AMReX_PODVector.H:680
iterator end() noexcept
Definition AMReX_PODVector.H:684
T * data() noexcept
Definition AMReX_PODVector.H:672
This provides length of period for periodic domains. 0 means it is not periodic in that direction....
Definition AMReX_Periodicity.H:17
static const Periodicity & NonPeriodic() noexcept
Definition AMReX_Periodicity.cpp:52
A Box with real dimensions.
Definition AMReX_RealBox.H:28
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
Long size() const noexcept
Definition AMReX_Vector.H:54
A Collection of IArrayBoxes.
Definition AMReX_iMultiFab.H:34
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Return the spatial extents of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1391
ArrayND< T, 4, true > Array4
Convenient alias for a 4D ArrayND with three spatial dimensions plus a component dimension.
Definition AMReX_Array4.H:1352
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1363
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1632
__host__ __device__ BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b coarsened by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1471
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Return a copy of b grown uniformly by i cells in every direction.
Definition AMReX_Box.H:1328
std::array< T, N > Array
Definition AMReX_Array.H:31
PinnedVector< T > HostVector
A PODVector that uses pinned host memory. Same as PinnedVector. For a vector class that uses std::all...
Definition AMReX_GpuContainers.H:67
PODVector< T, ArenaAllocator< T > > DeviceVector
A PODVector that uses the standard memory Arena. Note that the memory might or might not be managed d...
Definition AMReX_GpuContainers.H:24
Arena * The_Async_Arena()
Definition AMReX_Arena.cpp:849
void Sum(Gpu::DeviceVector< T > &v, MPI_Comm comm)
Definition AMReX_GpuParallelReduce.H:37
void copy(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition AMReX_GpuContainers.H:128
static constexpr DeviceToHost deviceToHost
Definition AMReX_GpuContainers.H:106
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:329
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
bool inNoSyncRegion() noexcept
Definition AMReX_GpuControl.H:148
gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:310
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
Definition AMReX_Amr.cpp:50
std::pair< FA, FA > ReduceToPlaneMF2Patchy(int direction, Box const &domain, FA const &mf, IntVect const &plane_max_grid_size, F const &f)
Reduce FabArray/MultiFab data to plane FabArray for patchy BoxArrays.
Definition AMReX_MultiFabUtil.H:1515
void FillRandomNormal(MultiFab &mf, int scomp, int ncomp, Real mean, Real stddev)
Fill MultiFab with random numbers from normal distribution.
Definition AMReX_MultiFabUtil.cpp:1326
void FillRandom(MultiFab &mf, int scomp, int ncomp)
Fill MultiFab with random numbers from uniform distribution.
Definition AMReX_MultiFabUtil.cpp:1313
@ F
Definition AMReX_Order.H:7
ReduceData< Ts... >::Type ParReduce(TypeList< Ops... > operation_list, TypeList< Ts... > type_list, FabArray< FAB > const &fa, IntVect const &nghost, F &&f)
Parallel reduce for MultiFab/FabArray. The reduce result is local and it's the user's responsibility ...
Definition AMReX_ParReduce.H:48
void average_down(const MultiFab &S_fine, MultiFab &S_crse, const Geometry &fgeom, const Geometry &cgeom, int scomp, int ncomp, int rr)
Definition AMReX_MultiFabUtil.cpp:360
__host__ __device__ void cast(BaseFab< Tto > &tofab, BaseFab< Tfrom > const &fromfab, Box const &bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Cast components from one BaseFab to another over a region.
Definition AMReX_BaseFabUtility.H:30
void computeDivergence(MultiFab &divu, const Array< MultiFab const *, 3 > &umac, const Geometry &geom)
Definition AMReX_MultiFabUtil.cpp:744
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)
Definition AMReX_MultiFabUtil.cpp:600
void average_face_to_cellcenter(MultiFab &cc, int dcomp, const Vector< const MultiFab * > &fc, IntVect const &ng_vect)
Definition AMReX_MultiFabUtil.cpp:157
iMultiFab makeFineMask(const BoxArray &cba, const DistributionMapping &cdm, const BoxArray &fba, const IntVect &ratio, int crse_value, int fine_value, MFInfo const &info)
Definition AMReX_MultiFabUtil.cpp:655
Vector< MultiFab > convexify(Vector< MultiFab const * > const &mf, Vector< IntVect > const &refinement_ratio)
Convexify AMR data.
Definition AMReX_MultiFabUtil.cpp:1339
MF get_line_data(MF const &mf, int dir, IntVect const &cell, Box const &bnd_bx=Box())
Get data in a line of MultiFab/FabArray.
Definition AMReX_MultiFabUtil.H:1211
FA ReduceToPlaneMF(int direction, Box const &domain, FA const &mf, F const &f)
Reduce FabArray/MultiFab data to plane FabArray.
Definition AMReX_MultiFabUtil.H:1452
MultiFab periodicShift(MultiFab const &mf, IntVect const &offset, Periodicity const &period)
Periodic shift MultiFab.
Definition AMReX_MultiFabUtil.cpp:828
BaseFab< T > ReduceToPlane(int direction, Box const &domain, FabArray< FAB > const &mf, F const &f)
Reduce FabArray/MultiFab data to a plane Fab.
Definition AMReX_MultiFabUtil.H:1364
void launch(T const &n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:122
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
Real volumeWeightedSum(Vector< MultiFab const * > const &mf, int icomp, Vector< Geometry > const &geom, Vector< IntVect > const &ratio, bool local)
Volume weighted sum for a vector of MultiFabs.
Definition AMReX_MultiFabUtil.cpp:1006
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
void average_down_faces(const Vector< const MF * > &fine, const Vector< MF * > &crse, const IntVect &ratio, int ngcrse=0)
Average fine face-based FabArray onto crse face-based FabArray.
Definition AMReX_MultiFabUtil.H:1062
bool isMFIterSafe(const FabArrayBase &x, const FabArrayBase &y)
Definition AMReX_MFIter.H:256
MultiFab ToMultiFab(const iMultiFab &imf)
Convert iMultiFab to MultiFab.
Definition AMReX_MultiFabUtil.cpp:590
Vector< typename MF::value_type > get_cell_data(MF const &mf, IntVect const &cell)
Get data in a cell of MultiFab/FabArray.
Definition AMReX_MultiFabUtil.H:1180
int nComp(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nComp().
Definition AMReX_FabArrayBase.cpp:3028
void writeFabs(const MultiFab &mf, const std::string &name)
Write each fab individually.
Definition AMReX_MultiFabUtil.cpp:577
Real NormHelper(const MultiFab &x, int xcomp, const MultiFab &y, int ycomp, F const &f, int numcomp, IntVect nghost, bool local)
Returns part of a norm based on two MultiFabs.
Definition AMReX_MultiFabUtil.H:867
void average_down_edges(const Vector< const MultiFab * > &fine, const Vector< MultiFab * > &crse, const IntVect &ratio, int ngcrse)
Average fine edge-based MultiFab onto crse edge-based MultiFab.
Definition AMReX_MultiFabUtil.cpp:495
Gpu::HostVector< Real > sumToLine(MultiFab const &mf, int icomp, int ncomp, Box const &domain, int direction, bool local)
Sum MultiFab data to line.
Definition AMReX_MultiFabUtil.cpp:852
@ y
Definition AMReX_Orientation.H:14
@ x
Definition AMReX_Orientation.H:14
std::pair< FA, FA > ReduceToPlaneMF2(int direction, Box const &domain, FA const &mf, F const &f, IntVect const &nghost=IntVect(0), Periodicity const &period=Periodicity::NonPeriodic())
Reduce FabArray/MultiFab data to plane FabArray.
Definition AMReX_MultiFabUtil.H:1469
void print_state(const MultiFab &mf, const IntVect &cell, const int n, const IntVect &ng)
Output state data for a single zone.
Definition AMReX_MultiFabUtil.cpp:572
bool TilingIfNotGPU() noexcept
Definition AMReX_MFIter.H:12
void sum_fine_to_coarse(const MultiFab &S_fine, MultiFab &S_crse, int scomp, int ncomp, const IntVect &ratio, const Geometry &cgeom, const Geometry &)
Definition AMReX_MultiFabUtil.cpp:440
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:239
const int[]
Definition AMReX_BLProfiler.cpp:1665
void average_node_to_cellcenter(MultiFab &cc, int dcomp, const MultiFab &nd, int scomp, int ncomp, int ngrow)
Average nodal-based MultiFab onto cell-centered MultiFab.
Definition AMReX_MultiFabUtil.cpp:63
void FourthOrderInterpFromFineToCoarse(MultiFab &cmf, int scomp, int ncomp, MultiFab const &fmf, IntVect const &ratio)
Fourth-order interpolation from fine to coarse level.
Definition AMReX_MultiFabUtil.cpp:1222
void average_cellcenter_to_face(const Vector< MultiFab * > &fc, const MultiFab &cc, const Geometry &geom, int ncomp, bool use_harmonic_averaging, int ngrow)
Average cell-centered MultiFab onto face-based MultiFab with geometric weighting.
Definition AMReX_MultiFabUtil.cpp:242
FabArray< BaseFab< Long > > ToLongMultiFab(const iMultiFab &imf)
Convert iMultiFab to Long.
Definition AMReX_MultiFabUtil.cpp:595
void computeGradient(MultiFab &grad, const Array< MultiFab const *, 3 > &umac, const Geometry &geom)
Computes gradient of face-data stored in the umac MultiFab.
Definition AMReX_MultiFabUtil.cpp:804
void average_edge_to_cellcenter(MultiFab &cc, int dcomp, const Vector< const MultiFab * > &edge, int ngrow)
Average edge-based MultiFab onto cell-centered MultiFab.
Definition AMReX_MultiFabUtil.cpp:106
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition AMReX_FabArrayUtility.H:2174
void average_down_nodal(const FabArray< FAB > &S_fine, FabArray< FAB > &S_crse, const IntVect &ratio, int ngcrse=0, bool mfiter_is_definitely_safe=false)
Average fine nodal MultiFab onto coarse nodal MultiFab.
Definition AMReX_MultiFabUtil.H:680
parallel copy or add
Definition AMReX_FabArrayBase.H:651
GPU-safe snapshot of Geometry data suitable for capture in GPU kernels.
Definition AMReX_Geometry.H:38
int coord
Coordinate-system type: 0 for Cartesian, 1 for RZ, and 2 for spherical.
Definition AMReX_Geometry.H:72
FabArray memory allocation information.
Definition AMReX_FabArray.H:73
Definition AMReX_MFIter.H:20
Struct for holding types.
Definition AMReX_TypeList.H:13