Block-Structured AMR Software Framework
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>
9 
10 namespace amrex {
11 
36 template <typename MF>
38  :
39  public BndryDataT<MF>
40 {
41 public:
42 
43  using value_type = typename MF::value_type;
44 
48  InterpBndryDataT () noexcept = default;
49 
58  InterpBndryDataT (const BoxArray& _grids,
59  const DistributionMapping& _dmap,
60  int _ncomp,
61  const Geometry& geom);
62 
63  ~InterpBndryDataT () = default;
64 
65  InterpBndryDataT (const InterpBndryDataT<MF>& rhs) = delete;
66  InterpBndryDataT (InterpBndryDataT<MF>&& rhs) = delete;
67  InterpBndryDataT<MF>& operator= (const InterpBndryDataT<MF>& rhs) = delete;
68  InterpBndryDataT<MF>& operator= (InterpBndryDataT<MF>&& rhs) = delete;
69 
78  void setPhysBndryValues (const MF& mf, int mf_start, int bnd_start, int num_comp);
79 
92  void setBndryValues (BndryRegisterT<MF> const& crse, int c_start, const MF& fine, int f_start,
93  int bnd_start, int num_comp, const IntVect& ratio,
94  int max_order = IBD_max_order_DEF, int max_width = 2);
95 
106  void updateBndryValues (BndryRegisterT<MF>& crse, int c_start, int bnd_start, int num_comp,
107  const IntVect& ratio, int max_order = IBD_max_order_DEF, int max_width = 2);
108 
110  void setHomogValues ();
111 
112  // For sliding parabolic interp in bdfuncs
113  static constexpr int IBD_max_order_DEF = 3;
114 
115 };
116 
117 template <typename MF>
119  const DistributionMapping& _dmap,
120  int _ncomp,
121  const Geometry& _geom)
122  :
123  BndryDataT<MF>(_grids,_dmap,_ncomp,_geom)
124 {}
125 
126 template <typename MF>
127 void
128 InterpBndryDataT<MF>::setPhysBndryValues (const MF& mf, int mf_start, int bnd_start, int num_comp)
129 {
130  AMREX_ASSERT(this->grids == mf.boxArray());
131 
132  const Box& fine_domain = this->geom.Domain();
133 
134 #ifdef AMREX_USE_OMP
135 #pragma omp parallel if (Gpu::notInLaunchRegion())
136 #endif
137  for (MFIter mfi(mf,MFItInfo().SetDynamic(true)); mfi.isValid(); ++mfi)
138  {
139  const Box& bx = mfi.validbox();
140  for (OrientationIter fi; fi; ++fi) {
141  const Orientation face = fi();
142  if (bx[face] == fine_domain[face] && !(this->geom.isPeriodic(face.coordDir())))
143  {
144  // Physical bndry, copy from grid.
145  auto & bnd_fab = this->bndry[face][mfi];
146  auto const& src_fab = mf[mfi];
147  auto const& bnd_array = bnd_fab.array();
148  auto const& src_array = src_fab.const_array();
149  const Box& b = src_fab.box() & bnd_fab.box();
150  AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( b, num_comp, i, j, k, n,
151  {
152  bnd_array(i,j,k,n+bnd_start) = src_array(i,j,k,n+mf_start);
153  });
154  }
155  }
156  }
157 }
158 
159 template <typename MF>
160 void
162  int f_start, int bnd_start, int num_comp, const IntVect& ratio,
163  int max_order, int max_width)
164 {
165  AMREX_ASSERT(this->grids == fine.boxArray());
166 
167  const Box& fine_domain = this->geom.Domain();
168 
169  if (max_order==3 || max_order==1)
170  {
171  MFItInfo info;
172  if (Gpu::notInLaunchRegion()) { info.SetDynamic(true); }
173 #ifdef AMREX_USE_OMP
174 #pragma omp parallel if (Gpu::notInLaunchRegion())
175 #endif
176  for (MFIter mfi(fine,info); mfi.isValid(); ++mfi)
177  {
178  const Box& fine_bx = mfi.validbox();
179  for (OrientationIter fi; fi; ++fi) {
180  const Orientation face = fi();
181  const int dir = face.coordDir();
182  if (fine_bx[face] != fine_domain[face] || this->geom.isPeriodic(dir))
183  { // coarse/fine boundary: interpolate from coarse data stored in BndryRegister crse
184  auto const& crse_array = crse[face].const_array(mfi);
185  auto const& bdry_array = this->bndry[face].array(mfi);
186  Box const& b = this->bndry[face][mfi].box();
187  const auto rr = ratio.dim3();
188 
189  if (max_order == 1)
190  {
191  AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
192  {
193  interpbndrydata_o1(it,jt,kt,n,bdry_array,bnd_start,
194  crse_array,c_start,rr);
195  });
196  }
197  else
198  {
199  auto const& mask_array = this->masks[face].const_array(mfi);
200  int is_not_covered = BndryData::not_covered;
201  switch (dir) {
202  case 0:
203  {
204  AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
205  {
206  interpbndrydata_x_o3(it,jt,kt,n,bdry_array,bnd_start,
207  crse_array,c_start,rr,
208  mask_array, is_not_covered, max_width);
209  });
210  break;
211  }
212 #if (AMREX_SPACEDIM >= 2)
213  case 1:
214  {
215  AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
216  {
217  interpbndrydata_y_o3(it,jt,kt,n,bdry_array,bnd_start,
218  crse_array,c_start,rr,
219  mask_array, is_not_covered, max_width);
220  });
221  break;
222  }
223 #if (AMREX_SPACEDIM == 3)
224  case 2:
225  {
226  AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, it, jt, kt, n,
227  {
228  interpbndrydata_z_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 #endif
235 #endif
236  default: {}
237  }
238  }
239  }
240  else if (fine.defined(mfi)) {
241  // Physical bndry
242  auto & bnd_fab = this->bndry[face][mfi];
243  auto const& src_fab = fine[mfi];
244  auto const& bnd_array = bnd_fab.array();
245  auto const& src_array = src_fab.const_array();
246  const Box& b = bnd_fab.box() & src_fab.box();
247  AMREX_HOST_DEVICE_FOR_4D ( b, num_comp, ii, jj, kk, nn,
248  {
249  bnd_array(ii,jj,kk,nn+bnd_start) = src_array(ii,jj,kk,nn+f_start);
250  });
251  }
252  }
253  }
254  }
255  else
256  {
257  amrex::Abort("InterpBndryDataT<MF>::setBndryValues supports only max_order=1 or 3");
258  }
259 }
260 
261 template <typename MF>
262 void
264  int num_comp, const IntVect& ratio, int max_order, int max_width)
265 {
266  MF foo(this->grids, this->bndry[0].DistributionMap(), 1, num_comp, MFInfo().SetAlloc(false));
267  setBndryValues(crse, c_start, foo, 0, bnd_start, num_comp, ratio, max_order, max_width);
268 }
269 
270 template <typename MF>
271 void
273 {
274  this->setVal(0.);
275 }
276 
279 
280 }
281 
282 #endif /*AMREX_INTERPBNDRYDATA_H_*/
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_HOST_DEVICE_FOR_4D(...)
Definition: AMReX_GpuLaunch.nolint.H:51
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D(...)
Definition: AMReX_GpuLaunch.nolint.H:55
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:41
Vector< MultiMask > masks
Boundary condition mask.
Definition: AMReX_BndryData.H:146
typename MF::value_type value_type
Definition: AMReX_BndryData.H:46
@ not_covered
Definition: AMReX_BndryData.H:44
Geometry geom
Domain used for mask definitions.
Definition: AMReX_BndryData.H:148
A BndryRegister organizes FabSets bounding each grid in a BoxArray. A FabSet is maintained for each b...
Definition: AMReX_BndryRegister.H:41
void setVal(value_type v)
Set all boundary FABs to given value.
Definition: AMReX_BndryRegister.H:210
const DistributionMapping & DistributionMap() const noexcept
Returns constant reference to associated DistributionMapping.
Definition: AMReX_BndryRegister.H:111
BoxArray grids
Definition: AMReX_BndryRegister.H:126
FabSetT< MF > bndry[2 *AMREX_SPACEDIM]
The data.
Definition: AMReX_BndryRegister.H:125
A collection of Boxes stored in an Array.
Definition: AMReX_BoxArray.H:549
Calculates the distribution of FABs to MPI processes.
Definition: AMReX_DistributionMapping.H:41
Rectangular problem domain geometry.
Definition: AMReX_Geometry.H:73
const Box & Domain() const noexcept
Returns our rectangular domain.
Definition: AMReX_Geometry.H:210
bool isPeriodic(int dir) const noexcept
Is the domain periodic in the specified direction?
Definition: AMReX_Geometry.H:331
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 dim3() const noexcept
Definition: AMReX_IntVect.H:163
An InterpBndryData object adds to a BndryData object the ability to manipulate and set the data store...
Definition: AMReX_InterpBndryData.H:40
void setPhysBndryValues(const MF &mf, int mf_start, int bnd_start, int num_comp)
Set bndry values at physical boundaries.
Definition: AMReX_InterpBndryData.H:128
static constexpr int IBD_max_order_DEF
Definition: AMReX_InterpBndryData.H:113
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:263
InterpBndryDataT() noexcept=default
default constructor
void setHomogValues()
Set boundary values to zero.
Definition: AMReX_InterpBndryData.H:272
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)
Definition: AMReX_InterpBndryData.H:161
Definition: AMReX_MFIter.H:57
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition: AMReX_MFIter.H:141
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
AMREX_GPU_HOST_DEVICE int coordDir() const noexcept
Returns the coordinate direction.
Definition: AMReX_Orientation.H:83
bool notInLaunchRegion() noexcept
Definition: AMReX_GpuControl.H:87
static int fi(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:49
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void interpbndrydata_y_o3(int i, int j, int, int n, Array4< T > const &bdry, int nb, Array4< T const > const &crse, int nc, Dim3 const &r, Array4< int const > const &mask, int not_covered, int max_width) noexcept
Definition: AMReX_InterpBndryData_2D_K.H:75
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void interpbndrydata_x_o3(int i, int, int, int n, Array4< T > const &bdry, int nb, Array4< T const > const &crse, int nc, Dim3 const &r, Array4< int const > const &, int, int) noexcept
Definition: AMReX_InterpBndryData_1D_K.H:22
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void interpbndrydata_z_o3(int i, int j, int k, int n, Array4< T > const &bdry, int nb, Array4< T const > const &crse, int nc, Dim3 const &r, Array4< int const > const &mask, int not_covered, int) noexcept
Definition: AMReX_InterpBndryData_3D_K.H:90
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void interpbndrydata_o1(int i, int, int, int n, Array4< T > const &bdry, int nb, Array4< T const > const &crse, int nc, Dim3 const &r) noexcept
Definition: AMReX_InterpBndryData_1D_K.H:11
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
FabArray memory allocation information.
Definition: AMReX_FabArray.H:66
Definition: AMReX_MFIter.H:20
MFItInfo & SetDynamic(bool f) noexcept
Definition: AMReX_MFIter.H:34