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
98 void setBndryValues (BndryRegisterT<MF> const& crse, int c_start, const MF& fine, int f_start,
99 int bnd_start, int num_comp, const IntVect& ratio,
100 int max_order = IBD_max_order_DEF, int max_width = 2);
101
113 void updateBndryValues (BndryRegisterT<MF>& crse, int c_start, int bnd_start, int num_comp,
114 const IntVect& ratio, int max_order = IBD_max_order_DEF, int max_width = 2);
115
117 void setHomogValues ();
118
119 // For sliding parabolic interp in bdfuncs
120 static constexpr int IBD_max_order_DEF = 3;
121
122};
123
124template <typename MF>
126 const DistributionMapping& _dmap,
127 int _ncomp,
128 const Geometry& _geom)
129 :
130 BndryDataT<MF>(_grids,_dmap,_ncomp,_geom)
131{}
132
133template <typename MF>
134void
135InterpBndryDataT<MF>::setPhysBndryValues (const MF& mf, int mf_start, int bnd_start, int num_comp)
136{
137 AMREX_ASSERT(this->grids == mf.boxArray());
138
139 const Box& fine_domain = this->geom.Domain();
140
141#ifdef AMREX_USE_OMP
142#pragma omp parallel if (Gpu::notInLaunchRegion())
143#endif
144 for (MFIter mfi(mf,MFItInfo().SetDynamic(true)); mfi.isValid(); ++mfi)
145 {
146 const Box& bx = mfi.validbox();
147 for (OrientationIter fi; fi; ++fi) {
148 const Orientation face = fi();
149 if (bx[face] == fine_domain[face] && !(this->geom.isPeriodic(face.coordDir())))
150 {
151 // Physical bndry, copy from grid.
152 auto & bnd_fab = this->bndry[face][mfi];
153 auto const& src_fab = mf[mfi];
154 auto const& bnd_array = bnd_fab.array();
155 auto const& src_array = src_fab.const_array();
156 const Box& b = src_fab.box() & bnd_fab.box();
157 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( b, num_comp, i, j, k, n,
158 {
159 bnd_array(i,j,k,n+bnd_start) = src_array(i,j,k,n+mf_start);
160 });
161 }
162 }
163 }
164}
165
166template <typename MF>
167void
169 int f_start, int bnd_start, int num_comp, const IntVect& ratio,
170 int max_order, int max_width)
171{
172 AMREX_ASSERT(this->grids == fine.boxArray());
173
174 const Box& fine_domain = this->geom.Domain();
175
176 if (max_order==3 || max_order==1)
177 {
178 MFItInfo info;
179 if (Gpu::notInLaunchRegion()) { info.SetDynamic(true); }
180#ifdef AMREX_USE_OMP
181#pragma omp parallel if (Gpu::notInLaunchRegion())
182#endif
183 for (MFIter mfi(fine,info); mfi.isValid(); ++mfi)
184 {
185 const Box& fine_bx = mfi.validbox();
186 for (OrientationIter fi; fi; ++fi) {
187 const Orientation face = fi();
188 const int dir = face.coordDir();
189 if (fine_bx[face] != fine_domain[face] || this->geom.isPeriodic(dir))
190 { // coarse/fine boundary: interpolate from coarse data stored in BndryRegister crse
191 auto const& crse_array = crse[face].const_array(mfi);
192 auto const& bdry_array = this->bndry[face].array(mfi);
193 Box const& b = this->bndry[face][mfi].box();
194 const auto rr = ratio.dim3();
195
196 if (max_order == 1)
197 {
198 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
199 {
200 interpbndrydata_o1(it,jt,kt,n,bdry_array,bnd_start,
201 crse_array,c_start,rr);
202 });
203 }
204 else
205 {
206 auto const& mask_array = this->masks[face].const_array(mfi);
207 int is_not_covered = BndryData::not_covered;
208 switch (dir) {
209 case 0:
210 {
211 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
212 {
213 interpbndrydata_x_o3(it,jt,kt,n,bdry_array,bnd_start,
214 crse_array,c_start,rr,
215 mask_array, is_not_covered, max_width);
216 });
217 break;
218 }
219#if (AMREX_SPACEDIM >= 2)
220 case 1:
221 {
222 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
223 {
224 interpbndrydata_y_o3(it,jt,kt,n,bdry_array,bnd_start,
225 crse_array,c_start,rr,
226 mask_array, is_not_covered, max_width);
227 });
228 break;
229 }
230#if (AMREX_SPACEDIM == 3)
231 case 2:
232 {
233 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
234 {
235 interpbndrydata_z_o3(it,jt,kt,n,bdry_array,bnd_start,
236 crse_array,c_start,rr,
237 mask_array, is_not_covered, max_width);
238 });
239 break;
240 }
241#endif
242#endif
243 default: {}
244 }
245 }
246 }
247 else if (fine.defined(mfi)) {
248 // Physical bndry
249 auto & bnd_fab = this->bndry[face][mfi];
250 auto const& src_fab = fine[mfi];
251 auto const& bnd_array = bnd_fab.array();
252 auto const& src_array = src_fab.const_array();
253 const Box& b = bnd_fab.box() & src_fab.box();
254 AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, ii, jj, kk, nn,
255 {
256 bnd_array(ii,jj,kk,nn+bnd_start) = src_array(ii,jj,kk,nn+f_start);
257 });
258 }
259 }
260 }
261 }
262 else
263 {
264 amrex::Abort("InterpBndryDataT<MF>::setBndryValues supports only max_order=1 or 3");
265 }
266}
267
268template <typename MF>
269void
271 int num_comp, const IntVect& ratio, int max_order, int max_width)
272{
273 MF foo(this->grids, this->bndry[0].DistributionMap(), 1, num_comp, MFInfo().SetAlloc(false));
274 setBndryValues(crse, c_start, foo, 0, bnd_start, num_comp, ratio, max_order, max_width);
275}
276
277template <typename MF>
278void
283
286
287}
288
289#endif /*AMREX_INTERPBNDRYDATA_H_*/
#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
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:568
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:43
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
const Box & Domain() const noexcept
Returns our rectangular domain.
Definition AMReX_Geometry.H:211
bool isPeriodic(int dir) const noexcept
Is the domain periodic in the specified direction?
Definition AMReX_Geometry.H:332
__host__ __device__ constexpr Dim3 dim3() const noexcept
Definition AMReX_IntVect.H:173
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:135
static constexpr int IBD_max_order_DEF
Definition AMReX_InterpBndryData.H:120
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:270
InterpBndryDataT() noexcept=default
default constructor
void setHomogValues()
Set boundary values to zero.
Definition AMReX_InterpBndryData.H:279
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:168
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:85
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:169
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:93
Definition AMReX_Amr.cpp:49
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:240
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition AMReX_FabArrayUtility.H:1927
FabArray memory allocation information.
Definition AMReX_FabArray.H:66
Definition AMReX_MFIter.H:20
MFItInfo & SetDynamic(bool f) noexcept
Definition AMReX_MFIter.H:40