Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_InterpBndryData.H
Go to the documentation of this file.
1
2#ifndef AMREX_INTERPBNDRYDATA_H_
3#define AMREX_INTERPBNDRYDATA_H_
4#include <AMReX_Config.H>
5
6#include <AMReX_BCRec.H>
7#include <AMReX_BndryData.H>
8#include <AMReX_InterpBndryData_K.H>
9
15namespace amrex {
16
41template <typename MF>
43 :
44 public BndryDataT<MF>
45{
46public:
47
48 using value_type = typename MF::value_type;
49
53 InterpBndryDataT () noexcept = default;
54
63 InterpBndryDataT (const BoxArray& _grids,
64 const DistributionMapping& _dmap,
65 int _ncomp,
66 const Geometry& geom);
67
68 ~InterpBndryDataT () = default;
69
70 InterpBndryDataT (const InterpBndryDataT<MF>& rhs) = delete;
71 InterpBndryDataT (InterpBndryDataT<MF>&& rhs) = delete;
72 InterpBndryDataT<MF>& operator= (const InterpBndryDataT<MF>& rhs) = delete;
73 InterpBndryDataT<MF>& operator= (InterpBndryDataT<MF>&& rhs) = delete;
74
83 void setPhysBndryValues (const MF& mf, int mf_start, int bnd_start, int num_comp);
84
104 void setBndryValues (BndryRegisterT<MF> const& crse, int c_start, const MF& fine, int f_start,
105 int bnd_start, int num_comp, const IntVect& ratio,
106 int max_order = IBD_max_order_DEF, int max_width = 2);
107
119 void updateBndryValues (BndryRegisterT<MF>& crse, int c_start, int bnd_start, int num_comp,
120 const IntVect& ratio, int max_order = IBD_max_order_DEF, int max_width = 2);
121
123 void setHomogValues ();
124
125 // For sliding parabolic interp in bdfuncs
126 static constexpr int IBD_max_order_DEF = 3;
127
128};
129
130template <typename MF>
132 const DistributionMapping& _dmap,
133 int _ncomp,
134 const Geometry& _geom)
135 :
136 BndryDataT<MF>(_grids,_dmap,_ncomp,_geom)
137{}
138
139template <typename MF>
140void
141InterpBndryDataT<MF>::setPhysBndryValues (const MF& mf, int mf_start, int bnd_start, int num_comp)
142{
143 AMREX_ASSERT(this->grids == mf.boxArray());
144
145 const Box& fine_domain = this->geom.Domain();
146
147#ifdef AMREX_USE_OMP
148#pragma omp parallel if (Gpu::notInLaunchRegion())
149#endif
150 for (MFIter mfi(mf,MFItInfo().SetDynamic(true)); mfi.isValid(); ++mfi)
151 {
152 const Box& bx = mfi.validbox();
153 for (OrientationIter fi; fi; ++fi) {
154 const Orientation face = fi();
155 if (bx[face] == fine_domain[face] && !(this->geom.isPeriodic(face.coordDir())))
156 {
157 // Physical bndry, copy from grid.
158 auto & bnd_fab = this->bndry[face][mfi];
159 auto const& src_fab = mf[mfi];
160 auto const& bnd_array = bnd_fab.array();
161 auto const& src_array = src_fab.const_array();
162 const Box& b = src_fab.box() & bnd_fab.box();
163 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( b, num_comp, i, j, k, n,
164 {
165 bnd_array(i,j,k,n+bnd_start) = src_array(i,j,k,n+mf_start);
166 });
167 }
168 }
169 }
170}
171
172template <typename MF>
173void
175 int f_start, int bnd_start, int num_comp, const IntVect& ratio,
176 int max_order, int max_width)
177{
178 AMREX_ASSERT(this->grids == fine.boxArray());
179
180 const Box& fine_domain = this->geom.Domain();
181
182 // Order-3 interpolation reads the boundary mask at tangential offsets of
183 // ±ratio. The masks are built with a fixed tangential half-width
184 // (BndryDataT::NTangHalfWidth == 5, i.e. ref_ratio + 1), so ratios above 4
185 // would walk past the allocated mask halo. Order-1 does not touch the mask.
186 if (max_order == 3) {
188 "InterpBndryDataT<MF>::setBndryValues: max_order=3 requires refinement ratio <= 4");
189 }
190
191 if (max_order==3 || max_order==1)
192 {
193 MFItInfo info;
194 if (Gpu::notInLaunchRegion()) { info.SetDynamic(true); }
195#ifdef AMREX_USE_OMP
196#pragma omp parallel if (Gpu::notInLaunchRegion())
197#endif
198 for (MFIter mfi(fine,info); mfi.isValid(); ++mfi)
199 {
200 const Box& fine_bx = mfi.validbox();
201 for (OrientationIter fi; fi; ++fi) {
202 const Orientation face = fi();
203 const int dir = face.coordDir();
204 if (fine_bx[face] != fine_domain[face] || this->geom.isPeriodic(dir))
205 { // coarse/fine boundary: interpolate from coarse data stored in BndryRegister crse
206 auto const& crse_array = crse[face].const_array(mfi);
207 auto const& bdry_array = this->bndry[face].array(mfi);
208 Box const& b = this->bndry[face][mfi].box();
209 const auto rr = ratio.dim3();
210
211 if (max_order == 1)
212 {
213 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
214 {
215 interpbndrydata_o1(it,jt,kt,n,bdry_array,bnd_start,
216 crse_array,c_start,rr);
217 });
218 }
219 else
220 {
221 auto const& mask_array = this->masks[face].const_array(mfi);
222 int is_not_covered = BndryData::not_covered;
223 switch (dir) {
224 case 0:
225 {
226 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
227 {
228 interpbndrydata_x_o3(it,jt,kt,n,bdry_array,bnd_start,
229 crse_array,c_start,rr,
230 mask_array, is_not_covered, max_width);
231 });
232 break;
233 }
234#if (AMREX_SPACEDIM >= 2)
235 case 1:
236 {
237 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
238 {
239 interpbndrydata_y_o3(it,jt,kt,n,bdry_array,bnd_start,
240 crse_array,c_start,rr,
241 mask_array, is_not_covered, max_width);
242 });
243 break;
244 }
245#if (AMREX_SPACEDIM == 3)
246 case 2:
247 {
248 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
249 {
250 interpbndrydata_z_o3(it,jt,kt,n,bdry_array,bnd_start,
251 crse_array,c_start,rr,
252 mask_array, is_not_covered, max_width);
253 });
254 break;
255 }
256#endif
257#endif
258 default: {}
259 }
260 }
261 }
262 else if (fine.defined(mfi)) {
263 // Physical bndry
264 auto & bnd_fab = this->bndry[face][mfi];
265 auto const& src_fab = fine[mfi];
266 auto const& bnd_array = bnd_fab.array();
267 auto const& src_array = src_fab.const_array();
268 const Box& b = bnd_fab.box() & src_fab.box();
269 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, ii, jj, kk, nn,
270 {
271 bnd_array(ii,jj,kk,nn+bnd_start) = src_array(ii,jj,kk,nn+f_start);
272 });
273 }
274 }
275 }
276 }
277 else
278 {
279 amrex::Abort("InterpBndryDataT<MF>::setBndryValues supports only max_order=1 or 3");
280 }
281}
282
283template <typename MF>
284void
286 int num_comp, const IntVect& ratio, int max_order, int max_width)
287{
288 MF foo(this->grids, this->bndry[0].DistributionMap(), 1, num_comp, MFInfo().SetAlloc(false));
289 setBndryValues(crse, c_start, foo, 0, bnd_start, num_comp, ratio, max_order, max_width);
290}
291
292template <typename MF>
293void
298
301
302}
303
304#endif /*AMREX_INTERPBNDRYDATA_H_*/
Boundary condition descriptors used throughout AMReX.
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
Boundary data container that owns masks, boundary values, and metadata.
#define AMREX_HOST_DEVICE_FOR_4D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:107
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:111
Array4< Real > fine
Definition AMReX_InterpFaceRegister.cpp:90
Array4< Real const > crse
Definition AMReX_InterpFaceRegister.cpp:92
A BndryData stores and manipulates boundary data information on each side of each box in a BoxArray.
Definition AMReX_BndryData.H:46
Vector< MultiMask > masks
Boundary condition mask.
Definition AMReX_BndryData.H:171
@ not_covered
Location is inside the domain but does not coincide with any valid grid points.
Definition AMReX_BndryData.H:50
Geometry geom
Domain used for mask definitions.
Definition AMReX_BndryData.H:173
A BndryRegister organizes FabSets bounding each grid in a BoxArray. A FabSet is maintained for each b...
Definition AMReX_BndryRegister.H:46
BoxArray grids
Definition AMReX_BndryRegister.H:173
const DistributionMapping & DistributionMap() const noexcept
Returns the DistributionMapping describing which MPI ranks own each boundary FAB.
Definition AMReX_BndryRegister.H:143
FabSetT< MF > bndry[2 *3]
The data.
Definition AMReX_BndryRegister.H:172
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:676
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:51
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:75
const Box & Domain() const noexcept
Returns our rectangular domain.
Definition AMReX_Geometry.H:216
bool isPeriodic(int dir) const noexcept
Is the domain periodic in the specified direction?
Definition AMReX_Geometry.H:337
__host__ __device__ constexpr Dim3 dim3() const noexcept
Definition AMReX_IntVect.H:262
__host__ __device__ constexpr bool allLE(const IntVectND< dim > &rhs) const noexcept
Returns true if this is less than or equal to argument for all components. NOTE: This is NOT a strict...
Definition AMReX_IntVect.H:492
An InterpBndryData object adds to a BndryData object the ability to manipulate and set the data store...
Definition AMReX_InterpBndryData.H:45
void setPhysBndryValues(const MF &mf, int mf_start, int bnd_start, int num_comp)
Set bndry values at physical boundaries.
Definition AMReX_InterpBndryData.H:141
static constexpr int IBD_max_order_DEF
Definition AMReX_InterpBndryData.H:126
void updateBndryValues(BndryRegisterT< MF > &crse, int c_start, int bnd_start, int num_comp, const IntVect &ratio, int max_order=IBD_max_order_DEF, int max_width=2)
Update boundary values at coarse/fine boundaries.
Definition AMReX_InterpBndryData.H:285
InterpBndryDataT() noexcept=default
default constructor
void setHomogValues()
Set boundary values to zero.
Definition AMReX_InterpBndryData.H:294
void setBndryValues(BndryRegisterT< MF > const &crse, int c_start, const MF &fine, int f_start, int bnd_start, int num_comp, const IntVect &ratio, int max_order=IBD_max_order_DEF, int max_width=2)
Sset bndry values at coarse/fine and physical boundaries.
Definition AMReX_InterpBndryData.H:174
typename MF::value_type value_type
Definition AMReX_InterpBndryData.H:48
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:172
An Iterator over the Orientation of Faces of a Box.
Definition AMReX_Orientation.H:135
Encapsulation of the Orientation of the Faces of a Box.
Definition AMReX_Orientation.H:29
__host__ __device__ int coordDir() const noexcept
Returns the coordinate direction.
Definition AMReX_Orientation.H:83
bool notInLaunchRegion() noexcept
Definition AMReX_GpuControl.H:89
Definition AMReX_Amr.cpp:50
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:241
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition AMReX_FabArrayUtility.H:1861
FabArray memory allocation information.
Definition AMReX_FabArray.H:68
Definition AMReX_MFIter.H:20
MFItInfo & SetDynamic(bool f) noexcept
Definition AMReX_MFIter.H:43