1 #ifndef ERF_SEB_LAND_AVERAGE_DOWN_H_
2 #define ERF_SEB_LAND_AVERAGE_DOWN_H_
4 #include <AMReX_BoxArray.H>
5 #include <AMReX_GpuQualifiers.H>
6 #include <AMReX_MFIter.H>
7 #include <AMReX_MultiFab.H>
8 #include <AMReX_Vector.H>
9 #include <AMReX_iMultiFab.H>
40 const amrex::Vector<amrex::MultiFab*>& crse,
41 const amrex::iMultiFab& fine_mask,
const amrex::iMultiFab& crse_mask,
42 const amrex::IntVect& ratio)
48 amrex::Vector<int> used;
49 amrex::Vector<int> first;
51 for (
int f = 0; f < fine.size(); ++f) {
52 if (fine[f] ==
nullptr || crse[f] ==
nullptr) {
continue; }
58 nc += fine[f]->nComp();
60 if (used.empty()) {
return; }
62 "seb_average_down_land: the fine grids are not aligned with the refinement ratio");
64 const int rx = ratio[0];
65 const int ry = ratio[1];
69 amrex::BoxArray cba = fine_mask.boxArray();
71 amrex::MultiFab cfine(cba, fine_mask.DistributionMap(),
nc + 1, 0);
72 for (amrex::MFIter mfi(cfine, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
73 const amrex::Box& bx = mfi.tilebox();
74 const auto c = cfine.array(mfi);
79 for (
int jj = ry * j; jj < ry * (j + 1); ++jj) {
80 for (
int ii = rx * i; ii < rx * (i + 1); ++ii) {
81 if (!fm.
water(ii, jj)) { ++n_land; }
84 c(i, j, k,
nc) =
static_cast<Real
>(n_land);
86 for (
int u = 0; u < used.size(); ++u) {
87 const auto f = fine[used[u]]->const_array(mfi);
88 const int nf = fine[used[u]]->nComp();
89 const int c0 = first[u];
94 const Real n_land = c(i, j, k,
nc);
95 const Real divisor = (n_land > Real(0.5)) ? n_land : Real(1.0);
97 for (
int jj = ry * j; jj < ry * (j + 1); ++jj) {
98 for (
int ii = rx * i; ii < rx * (i + 1); ++ii) {
99 if (!fm.
water(ii, jj)) { sum += f(ii, jj, k, n); }
102 c(i, j, k, c0 + n) = sum / divisor;
108 const amrex::MultiFab& crse0 = *crse[used[0]];
109 amrex::MultiFab cover(crse0.boxArray(), crse0.DistributionMap(),
nc + 1, 0);
110 cover.setVal(Real(0.0));
111 cover.ParallelCopy(cfine, 0, 0,
nc + 1);
112 for (amrex::MFIter mfi(cover, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
113 const amrex::Box& bx = mfi.tilebox();
114 const auto v = cover.const_array(mfi);
116 for (
int u = 0; u < used.size(); ++u) {
117 const auto c = crse[used[u]]->array(mfi);
118 const int nf = crse[used[u]]->nComp();
119 const int c0 = first[u];
122 if (cm.
water(i, j) || v(i, j, k,
nc) < Real(0.5)) {
return; }
123 c(i, j, k, n) = v(i, j, k, c0 + n);
132 const amrex::iMultiFab& fine_mask,
const amrex::iMultiFab& crse_mask,
133 const amrex::IntVect& ratio)
136 amrex::Vector<amrex::MultiFab*>{&crse}, fine_mask, crse_mask, ratio);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
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);})
void seb_average_down_land(const amrex::Vector< const amrex::MultiFab * > &fine, const amrex::Vector< amrex::MultiFab * > &crse, const amrex::iMultiFab &fine_mask, const amrex::iMultiFab &crse_mask, const amrex::IntVect &ratio)
Definition: ERF_SEBLandAverageDown.H:39
The one place that says how the two-stream force-restore balance reads the land mask (ERF::lmask_lev:...
SEBLandMaskView seb_land_mask_view(const amrex::iMultiFab *mask, const amrex::MFIter &mfi)
The view of mask on the box of mfi; off when mask is nullptr.
Definition: ERF_SEBLandMask.H:54
void seb_assert_land_mask_layout(const amrex::iMultiFab *mask, const amrex::FabArrayBase &field, const char *who)
Stop when mask is given and is not on the grids of field.
Definition: ERF_SEBLandMask.H:43
@ nc
Definition: ERF_Morrison.H:47
The land mask of one box, for a device kernel. Captured by value.
Definition: ERF_SEBLandMask.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool water(int i, int j) const noexcept
True when the balance does not run on column (i, j).
Definition: ERF_SEBLandMask.H:35