1 #ifndef ERF_SURFACE_GRID_H
2 #define ERF_SURFACE_GRID_H
6 #include <AMReX_BoxArray.H>
7 #include <AMReX_DistributionMapping.H>
8 #include <AMReX_Geometry.H>
9 #include <AMReX_MultiFab.H>
10 #include <AMReX_MFIter.H>
36 amrex::DistributionMapping
dm;
70 const amrex::DistributionMapping& dm_atm,
71 const amrex::Geometry& geom_atm,
81 if (a.size() != b.size()) {
return false; }
82 for (
int n = 0; n < a.size(); ++n) {
85 ba.setSmall(2, 0); ba.setBig(2, 0);
86 bb.setSmall(2, 0); bb.setBig(2, 0);
87 if (ba != bb) {
return false; }
101 const amrex::BoxArray& sba = surf_mf.boxArray();
102 const amrex::BoxArray& aba = atm_mf.boxArray();
103 if (!sba.ixType().cellCentered() || !aba.ixType().cellCentered()) {
106 if (sba.size() != aba.size() || surf_mf.DistributionMap() != atm_mf.DistributionMap()) {
109 for (
int n = 0; n < aba.size(); ++n) {
110 amrex::Box ab = aba[n];
111 amrex::Box sb = sba[n];
112 ab.setSmall(2, 0); ab.setBig(2, 0);
113 sb.setSmall(2, 0); sb.setBig(2, 0);
115 ab.refine(amrex::IntVect(sg.
C, sg.
C, 1));
116 if (ab != sb) {
return false; }
134 (names.
tag() +
" Filling the ghost cells of the " + names.
grid()
135 +
": the MultiFab must be cell-centred").c_str());
136 mf.FillBoundary(geom.periodicity());
137 const auto ng = mf.nGrowVect();
138 const bool px = geom.isPeriodic(0) ||
ng[0] == 0;
139 const bool py = geom.isPeriodic(1) ||
ng[1] == 0;
140 const bool pz = geom.isPeriodic(2) ||
ng[2] == 0;
141 if (px && py && pz) {
return; }
142 const amrex::Box& dom = geom.Domain();
143 const auto dlo = dom.smallEnd();
144 const auto dhi = dom.bigEnd();
145 const int ncomp = mf.nComp();
146 for (amrex::MFIter mfi(mf); mfi.isValid(); ++mfi) {
147 const amrex::Box& gbx = mfi.fabbox();
148 if (dom.contains(gbx)) {
continue; }
149 auto a = mf.array(mfi);
150 amrex::ParallelFor(gbx, ncomp, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k,
int n) noexcept
152 int ic = i, jc = j, kc = k;
153 if (!px) { ic = amrex::min(amrex::max(i,
dlo[0]),
dhi[0]); }
154 if (!py) { jc = amrex::min(amrex::max(j,
dlo[1]),
dhi[1]); }
155 if (!pz) { kc = amrex::min(amrex::max(k,
dlo[2]),
dhi[2]); }
156 if (ic != i || jc != j || kc != k) { a(i, j, k, n) = a(ic, jc, kc, n); }
172 int scomp = 0,
int acomp = 0)
176 (names.
tag() +
" Copying the atmospheric columns to the " + names.
grid()
177 +
": the two must pair box for box").c_str());
179 const int lo_x = sg.
atm_lo[0];
180 const int lo_y = sg.
atm_lo[1];
181 for (amrex::MFIter mfi(surf_mf,
false); mfi.isValid(); ++mfi) {
182 auto f = surf_mf.array(mfi);
183 auto a = atm_k0.const_array(mfi);
184 const int ka = atm_k0.boxArray()[mfi.index()].smallEnd(2);
185 amrex::ParallelFor(mfi.validbox(), [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
187 f(i, j, k, scomp) = a(i / C + lo_x, j / C + lo_y, ka, acomp);
206 (names.
tag() +
" Averaging the " + names.
grid()
207 +
" onto the atmospheric columns: the two must pair box for box").c_str());
210 const int lo_x = sg.
atm_lo[0];
211 const int lo_y = sg.
atm_lo[1];
212 const int ncomp = surf.nComp();
213 const amrex::Real inv_cells = amrex::Real(1.0) / amrex::Real(C * C);
214 for (amrex::MFIter mfi(atm_out); mfi.isValid(); ++mfi) {
215 auto crse = atm_out.array(mfi);
216 auto fine = surf.const_array(mfi);
217 const int kf = surf.boxArray()[mfi.index()].smallEnd(2);
218 amrex::ParallelFor(mfi.validbox(), ncomp, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k,
int n) noexcept
220 const int ii = (i - lo_x) * C;
221 const int jj = (j - lo_y) * C;
222 amrex::Real c = amrex::Real(0.0);
223 for (
int q = 0;
q < C; ++
q) {
224 for (
int r = 0; r < C; ++r) {
225 c += fine(ii + r, jj +
q, kf, n);
228 crse(i, j, k, n) = inv_cells * c;
GpuArray< int, AMREX_SPACEDIM > dhi
Definition: ERF_ActuatorSpreading.cpp:132
GpuArray< int, AMREX_SPACEDIM > dlo
Definition: ERF_ActuatorSpreading.cpp:132
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);})
The names a surface coupling uses in its inputs and messages.
bool surface_pairs_with_atm(const amrex::MultiFab &surf_mf, const amrex::MultiFab &atm_mf, const SurfaceGrid &sg)
Definition: ERF_SurfaceGrid.H:98
void surface_fill_boundary(amrex::MultiFab &mf, const amrex::Geometry &geom, const SurfaceCouplingNames &names)
Definition: ERF_SurfaceGrid.H:130
void surface_fill_from_atm_k0(amrex::MultiFab &surf_mf, const amrex::MultiFab &atm_k0, const SurfaceGrid &sg, const SurfaceCouplingNames &names, int scomp=0, int acomp=0)
Definition: ERF_SurfaceGrid.H:170
bool surface_same_columns(const amrex::BoxArray &a, const amrex::BoxArray &b)
Definition: ERF_SurfaceGrid.H:79
void surface_coarsen_to_atm(amrex::MultiFab &atm_out, const amrex::MultiFab &surf, const SurfaceGrid &sg, const SurfaceCouplingNames &names)
Definition: ERF_SurfaceGrid.H:201
SurfaceGrid create_surface_grid(const amrex::BoxArray &ba_atm, const amrex::DistributionMapping &dm_atm, const amrex::Geometry &geom_atm, int C, const SurfaceCouplingNames &names)
Construct a refined 2D surface grid over one atmospheric level's boxes.
@ ng
Definition: ERF_Morrison.H:51
@ q
Definition: ERF_WSM6.H:296
Definition: ERF_SurfaceCouplingNames.H:18
std::string tag() const
"[FIRE]"
Definition: ERF_SurfaceCouplingNames.H:24
std::string grid() const
"fire grid"
Definition: ERF_SurfaceCouplingNames.H:28
2D horizontal surface grid
Definition: ERF_SurfaceGrid.H:34
amrex::Geometry geom
2D Geometry in physical coordinates [m]
Definition: ERF_SurfaceGrid.H:37
int lev
The atmospheric level (anchor_level, resolved)
Definition: ERF_SurfaceGrid.H:44
amrex::IntVect atm_lo
Definition: ERF_SurfaceGrid.H:43
amrex::BoxArray ba
2D BoxArray (C*nx x C*ny x 1), box n refines atmospheric box n
Definition: ERF_SurfaceGrid.H:35
amrex::DistributionMapping dm
The atmospheric level's owners.
Definition: ERF_SurfaceGrid.H:36
int C
Definition: ERF_SurfaceGrid.H:38