Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_PhysBCFunct.H
Go to the documentation of this file.
1#ifndef AMREX_PhysBCFunct_H_
2#define AMREX_PhysBCFunct_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_BCRec.H>
6#include <AMReX_Geometry.H>
7#include <AMReX_MultiFab.H>
8#include <AMReX_ArrayLim.H>
9#include <AMReX_FilCC_C.H>
10#include <AMReX_FilND_C.H>
11#include <AMReX_FilFC_C.H>
12#include <AMReX_TypeTraits.H>
13
14namespace amrex {
15
16extern "C"
17{
18 using BndryFuncDefault = void (*)(Real* data, AMREX_ARLIM_P(lo), AMREX_ARLIM_P(hi),
19 const int* dom_lo, const int* dom_hi,
20 const Real* dx, const Real* grd_lo,
21 const Real* time, const int* bc);
22 using BndryFunc3DDefault = void (*)(Real* data, const int* lo, const int* hi,
23 const int* dom_lo, const int* dom_hi,
24 const Real* dx, const Real* grd_lo,
25 const Real* time, const int* bc);
26}
27
28using UserFillBox = void (*)(Box const& bx, Array4<Real> const& dest,
29 int dcomp, int numcomp,
30 GeometryData const& geom, Real time,
31 const BCRec* bcr, int bcomp,
32 int orig_comp);
33
36{
37public:
38 BndryFuncArray () noexcept = default;
39 BndryFuncArray (BndryFuncDefault inFunc) noexcept : m_func(inFunc) {}
40 BndryFuncArray (BndryFunc3DDefault inFunc) noexcept : m_func3D(inFunc) {}
41
42 void operator() (Box const& bx, FArrayBox& dest,
43 int dcomp, int numcomp,
44 Geometry const& geom, Real time,
45 const Vector<BCRec>& bcr, int bcomp,
46 int orig_comp);
47
48 [[nodiscard]] bool RunOnGPU () const noexcept { return m_run_on_gpu; }
49// void setRunOnGPU (bool b) noexcept { m_run_on_gpu = b; }
50
51protected:
54 bool m_run_on_gpu = false;
55};
56
67template <class F>
69{
70public:
71 GpuBndryFuncFab () = default;
72 GpuBndryFuncFab (F const& a_f) : m_user_f(a_f) {}
73 GpuBndryFuncFab (F&& a_f) : m_user_f(std::move(a_f)) {}
74
75 void operator() (Box const& bx, FArrayBox& dest,
76 int dcomp, int numcomp,
77 Geometry const& geom, Real time,
78 const Vector<BCRec>& bcr, int bcomp,
79 int orig_comp);
80
81 template <class FF>
82 void ccfcdoit (Box const& bx, FArrayBox& dest,
83 int dcomp, int numcomp,
84 Geometry const& geom, Real time,
85 const Vector<BCRec>& bcr, int bcomp,
86 int orig_comp, FF const& fillfunc);
87
88 void nddoit (Box const& bx, FArrayBox& dest,
89 int dcomp, int numcomp,
90 Geometry const& geom, Real time,
91 const Vector<BCRec>& bcr, int bcomp,
92 int orig_comp);
93
94protected:
96};
97
99{
102 int, int, amrex::GeometryData const&, amrex::Real,
103 const amrex::BCRec*, int, int) const
104 {}
105};
106
112{
113public:
114 CpuBndryFuncFab () = default;
116
117 void operator() (Box const& bx, FArrayBox& dest,
118 int dcomp, int numcomp,
119 Geometry const& geom, Real time,
120 const Vector<BCRec>& bcr, int bcomp,
121 int orig_comp);
122
123protected:
125};
126
128{
129public:
130 void operator() (MultiFab& /*mf*/, int /*dcomp*/, int /*ncomp*/, IntVect const& /*nghost*/,
131 Real /*time*/, int /*bccomp*/) {}
132};
133
135{
136public:
137
138 PhysBCFunctUseCoarseGhost (IntVect const& a_fp1_src_ghost)
139 : fp1_src_ghost(a_fp1_src_ghost) {}
140
141 template <typename MF, typename Interp>
142 PhysBCFunctUseCoarseGhost (MF const& cmf, IntVect const& a_nghost,
143 IntVect const& a_nghost_outside_domain,
144 IntVect const& ratio, Interp* mapper)
145 : nghost(a_nghost),
146 nghost_outside_domain(a_nghost_outside_domain),
147 cghost(cmf.nGrowVect())
148 {
149 IndexType typ = cmf.ixType();
150
151 const auto& coarsener = mapper->BoxCoarsener(ratio);
152 Box tmp(-nghost, IntVect(32), typ);
153 Box tmp2 = coarsener.doit(tmp);
154 src_ghost = -tmp2.smallEnd();
155
156 tmp = Box(-nghost_outside_domain, IntVect(32), typ);
157 tmp2 = coarsener.doit(tmp);
159
160 cghost.min(src_ghost);
162 }
163
164 void operator() (MultiFab& /*mf*/, int /*dcomp*/, int /*ncomp*/, IntVect const& /*nghost*/,
165 Real /*time*/, int /*bccomp*/) {}
166
167 IntVect nghost; // # of fine ghosts inside domain to be filled
168
169 IntVect nghost_outside_domain; // # of fine ghosts outside domain to be filled
170
171 // This is the number of coarse ghost cells needed to interpolate fine
172 // ghost cells inside the domain
174
175 // This is the number of coarse ghost cells needed to interpolate
176 // nghost_outside_domain fine ghost cells outside the domain
178
179 // This is the minimum number of ghost cells needed in coarse MF
181
182 IntVect fp1_src_ghost; // Used to pass information into FillPatchSingleLevel
183};
184
185template <class F>
187{
188public:
189 PhysBCFunct () = default;
190
191 PhysBCFunct (const Geometry& geom, const Vector<BCRec>& bcr, F const& f)
192 : m_geom(geom), m_bcr(bcr), m_f(f)
193 {}
194
195 PhysBCFunct (const Geometry& geom, const Vector<BCRec>& bcr, F&& f)
196 : m_geom(geom), m_bcr(bcr), m_f(std::move(f))
197 {}
198
199 void define (const Geometry& geom, const Vector<BCRec>& bcr, F const& f) {
200 m_geom = geom; m_bcr = bcr; m_f = f;
201 }
202
203 void define (const Geometry& geom, const Vector<BCRec>& bcr, F&& f) {
204 m_geom = geom; m_bcr = bcr; m_f = std::move(f);
205 }
206
207 void operator() (MultiFab& mf, int icomp, int ncomp, IntVect const& nghost,
208 Real time, int bccomp)
209 {
210 if (m_geom.isAllPeriodic()) { return; }
211
212 BL_PROFILE("PhysBCFunct::()");
213
214 AMREX_ASSERT(nghost.allLE(mf.nGrowVect()));
215
217 const Box& domain = amrex::convert(m_geom.Domain(), mf.boxArray().ixType());
218 Box gdomain = domain;
219 for (int i = 0; i < AMREX_SPACEDIM; ++i) {
220 if (m_geom.isPeriodic(i)) {
221 gdomain.grow(i, nghost[i]);
222 }
223 }
224
225#ifdef AMREX_USE_OMP
226#pragma omp parallel if (Gpu::notInLaunchRegion())
227#endif
228 {
229 Vector<BCRec> bcrs(ncomp);
230 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
231 {
232 FArrayBox& dest = mf[mfi];
233 const Box& bx = grow(mfi.validbox(),nghost);
234
238 if (!gdomain.contains(bx))
239 {
241 amrex::setBC(bx, domain, bccomp, 0, ncomp, m_bcr, bcrs);
242
244 m_f(bx, dest, icomp, ncomp, m_geom, time, bcrs, 0, bccomp);
245 }
246 }
247 }
248 }
249
250 // For backward compatibility
251 void FillBoundary (MultiFab& mf, int icomp, int ncomp, IntVect const& nghost,
252 Real time, int bccomp) {
253 // NOLINTNEXTLINE(readability-suspicious-call-argument)
254 this->operator()(mf,icomp,ncomp,nghost,time,bccomp);
255 }
256
257private:
258 Geometry m_geom;
259 Vector<BCRec> m_bcr;
260 F m_f;
261};
262
263template <class F>
264void
266 int dcomp, int numcomp,
267 Geometry const& geom, Real time,
268 const Vector<BCRec>& bcr, int bcomp,
269 int orig_comp)
270{
271 if (bx.ixType().cellCentered()) {
272 ccfcdoit(bx,dest,dcomp,numcomp,geom,time,bcr,bcomp,orig_comp, FilccCell{});
273 } else if (bx.ixType().nodeCentered()) {
274 nddoit(bx,dest,dcomp,numcomp,geom,time,bcr,bcomp,orig_comp);
275 } else {
276 ccfcdoit(bx,dest,dcomp,numcomp,geom,time,bcr,bcomp,orig_comp, FilfcFace{});
277 }
278}
279
280template <class F>
281void
283 int dcomp, int numcomp,
284 Geometry const& geom, Real time,
285 const Vector<BCRec>& bcr, int bcomp,
286 int orig_comp)
287{
288 const IntVect& len = bx.length();
289
290 Box const& domain = amrex::convert(geom.Domain(),IntVect::TheNodeVector());
291 Box gdomain = domain;
292 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
293 if (geom.isPeriodic(idim)) {
294 gdomain.grow(idim,len[idim]);
295 }
296 }
297
298 if (gdomain.contains(bx)) { return; }
299
300 Array4<Real> const& fab = dest.array();
301
302 AsyncArray<BCRec> bcr_aa(bcr.data()+bcomp, numcomp);
303 BCRec* bcr_p = bcr_aa.data();
304
305 // Like CpuBndryFuncFab, fill the ghost nodes first and then call the
306 // user function.
307
308 // xlo
309 if (!geom.isPeriodic(0) && bx.smallEnd(0) < domain.smallEnd(0)) {
310 Box bndry = bx;
311 int dxlo = domain.smallEnd(0);
312 bndry.setBig(0,dxlo-1);
313 amrex::ParallelFor(bndry, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
314 {
315 for (int n = dcomp; n < dcomp+numcomp; ++n) {
316 if (bcr_p[n-dcomp].lo(0) != BCType::int_dir) {
317 fab(i,j,k,n) = fab(dxlo,j,k,n);
318 }
319 }
320 });
321 }
322
323 // xhi
324 if (!geom.isPeriodic(0) && bx.bigEnd(0) > domain.bigEnd(0)) {
325 Box bndry = bx;
326 int dxhi = domain.bigEnd(0);
327 bndry.setSmall(0,dxhi+1);
328 amrex::ParallelFor(bndry, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
329 {
330 for (int n = dcomp; n < dcomp+numcomp; ++n) {
331 if (bcr_p[n-dcomp].hi(0) != BCType::int_dir) {
332 fab(i,j,k,n) = fab(dxhi,j,k,n);
333 }
334 }
335 });
336 }
337
338#if (AMREX_SPACEDIM >= 2)
339 // ylo
340 if (!geom.isPeriodic(1) && bx.smallEnd(1) < domain.smallEnd(1)) {
341 Box bndry = bx;
342 int dylo = domain.smallEnd(1);
343 bndry.setBig(1,dylo-1);
344 amrex::ParallelFor(bndry, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
345 {
346 for (int n = dcomp; n < dcomp+numcomp; ++n) {
347 if (bcr_p[n-dcomp].lo(1) != BCType::int_dir) {
348 fab(i,j,k,n) = fab(i,dylo,k,n);
349 }
350 }
351 });
352 }
353
354 // yhi
355 if (!geom.isPeriodic(1) && bx.bigEnd(1) > domain.bigEnd(1)) {
356 Box bndry = bx;
357 int dyhi = domain.bigEnd(1);
358 bndry.setSmall(1,dyhi+1);
359 amrex::ParallelFor(bndry, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
360 {
361 for (int n = dcomp; n < dcomp+numcomp; ++n) {
362 if (bcr_p[n-dcomp].hi(1) != BCType::int_dir) {
363 fab(i,j,k,n) = fab(i,dyhi,k,n);
364 }
365 }
366 });
367 }
368#endif
369
370#if (AMREX_SPACEDIM == 3)
371 // zlo
372 if (!geom.isPeriodic(2) && bx.smallEnd(2) < domain.smallEnd(2)) {
373 Box bndry = bx;
374 int dzlo = domain.smallEnd(2);
375 bndry.setBig(2,dzlo-1);
376 amrex::ParallelFor(bndry, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
377 {
378 for (int n = dcomp; n < dcomp+numcomp; ++n) {
379 if (bcr_p[n-dcomp].lo(2) != BCType::int_dir) {
380 fab(i,j,k,n) = fab(i,j,dzlo,n);
381 }
382 }
383 });
384 }
385
386 // zhi
387 if (!geom.isPeriodic(2) && bx.bigEnd(2) > domain.bigEnd(2)) {
388 Box bndry = bx;
389 int dzhi = domain.bigEnd(2);
390 bndry.setSmall(2,dzhi+1);
391 amrex::ParallelFor(bndry, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
392 {
393 for (int n = dcomp; n < dcomp+numcomp; ++n) {
394 if (bcr_p[n-dcomp].hi(2) != BCType::int_dir) {
395 fab(i,j,k,n) = fab(i,j,dzhi,n);
396 }
397 }
398 });
399 }
400#endif
401
402 // The user function is called once on every node on or outside the
403 // domain boundary.
404 if constexpr (!std::is_same_v<F,FabFillNoOp>) {
405 const auto geomdata = geom.data();
406 const auto f_user = m_user_f;
407 Box rem = bx; // nodes not visited yet
408 for (int idim = 0; idim < AMREX_SPACEDIM && rem.ok(); ++idim) {
409 if (geom.isPeriodic(idim)) { continue; }
410 Box blo = rem;
411 blo.setBig(idim, std::min(rem.bigEnd(idim), domain.smallEnd(idim)));
412 rem.setSmall(idim, std::max(rem.smallEnd(idim), domain.smallEnd(idim)+1));
413 Box bhi = rem;
414 bhi.setSmall(idim, std::max(rem.smallEnd(idim), domain.bigEnd(idim)));
415 rem.setBig(idim, std::min(rem.bigEnd(idim), domain.bigEnd(idim)-1));
416 for (Box const& b : {blo, bhi}) {
417 if (b.ok()) {
418 amrex::ParallelFor(b, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
419 {
421 f_user(IntVect(AMREX_D_DECL(i,j,k)), fab, dcomp, numcomp, geomdata, time,
422 bcr_p, 0, orig_comp);
423 });
424 }
425 }
426 }
427 } else {
428 amrex::ignore_unused(time, orig_comp);
429 }
430}
431
432template <class F>
433template <class FF>
434void
436 int dcomp, int numcomp,
437 Geometry const& geom, Real time,
438 const Vector<BCRec>& bcr, int bcomp,
439 int orig_comp, FF const& fillfunc)
440{
441 const IntVect& len = bx.length();
442
443 IndexType idxType = bx.ixType();
444 Box const& domain = amrex::convert(geom.Domain(),idxType);
445 Box gdomain = domain;
446 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
447 if (geom.isPeriodic(idim)) {
448 gdomain.grow(idim,len[idim]);
449 }
450 }
451
452 if (gdomain.contains(bx)) { return; }
453
454 Array4<Real> const& fab = dest.array();
455 const auto geomdata = geom.data();
456
457#ifdef AMREX_USE_GPU
458 AsyncArray<BCRec> bcr_aa(bcr.data()+bcomp, numcomp);
459 BCRec* bcr_p = bcr_aa.data();
460
461 const auto f_user = m_user_f;
462
463 // fill on the faces first
464 {
465 Array<Box,2*AMREX_SPACEDIM> dom_face_boxes
466 = { AMREX_D_DECL(amrex::convert(amrex::adjCellLo(gdomain, 0, len[0]),idxType),
467 amrex::convert(amrex::adjCellLo(gdomain, 1, len[1]),idxType),
468 amrex::convert(amrex::adjCellLo(gdomain, 2, len[2]),idxType)),
469 AMREX_D_DECL(amrex::convert(amrex::adjCellHi(gdomain, 0, len[0]),idxType),
470 amrex::convert(amrex::adjCellHi(gdomain, 1, len[1]),idxType),
471 amrex::convert(amrex::adjCellHi(gdomain, 2, len[2]),idxType)) };
472
473 Vector<Box> face_boxes;
474 for (const Box& b : dom_face_boxes) {
475 Box tmp = b & bx;
476 if (tmp.ok()) { face_boxes.push_back(tmp); }
477 }
478 const int n_face_boxes = face_boxes.size();
479 // For non-cell-centered data the boxes share nodes, so they must be
480 // launched separately to avoid races, like in the CPU version below.
481 if (n_face_boxes == 1 || ! idxType.cellCentered()) {
482 for (const Box& b : face_boxes) {
484 [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
485 {
487 IntVect const idx(AMREX_D_DECL(i,j,k));
488 fillfunc(idx, fab, dcomp, numcomp, domain, bcr_p, 0);
489 f_user(idx, fab, dcomp, numcomp, geomdata, time,
490 bcr_p, 0, orig_comp);
491 });
492 }
493 } else if (n_face_boxes > 1) {
494 AsyncArray<Box> face_boxes_aa(face_boxes.data(), n_face_boxes);
495 Box* boxes_p = face_boxes_aa.data();
496 Long ncounts = 0;
497 for (const auto& b : face_boxes) {
498 ncounts += b.numPts();
499 }
500 amrex::ParallelFor(ncounts,
501 [=] AMREX_GPU_DEVICE (Long icount) noexcept
502 {
503 const auto& idx = getCell(boxes_p, n_face_boxes, icount);
504 fillfunc(idx, fab, dcomp, numcomp, domain, bcr_p, 0);
505 f_user(idx, fab, dcomp, numcomp, geomdata, time,
506 bcr_p, 0, orig_comp);
507 });
508 }
509 }
510
511#if (AMREX_SPACEDIM >= 2)
512 // fill on the box edges
513 {
514#if (AMREX_SPACEDIM == 2)
515 Array<Box,4> dom_edge_boxes
516 = {{ amrex::convert(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),idxType),
517 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),idxType),
518 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),idxType),
519 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),idxType) }};
520#else
521 Array<Box,12> dom_edge_boxes
522 = {{ amrex::convert(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),idxType),
523 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),idxType),
524 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),idxType),
525 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),idxType),
526 //
527 amrex::convert(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),2,len[2]),idxType),
528 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),2,len[2]),idxType),
529 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),2,len[2]),idxType),
530 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),2,len[2]),idxType),
531 //
532 amrex::convert(amrex::adjCellLo(amrex::adjCellLo(gdomain,1,len[1]),2,len[2]),idxType),
533 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(gdomain,1,len[1]),2,len[2]),idxType),
534 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(gdomain,1,len[1]),2,len[2]),idxType),
535 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(gdomain,1,len[1]),2,len[2]),idxType) }};
536#endif
537 Vector<Box> edge_boxes;
538 for (const Box& b : dom_edge_boxes) {
539 Box tmp = b & bx;
540 if (tmp.ok()) { edge_boxes.push_back(tmp); }
541 }
542 const int n_edge_boxes = edge_boxes.size();
543 // For non-cell-centered data the boxes share nodes, so they must be
544 // launched separately to avoid races, like in the CPU version below.
545 if (n_edge_boxes == 1 || ! idxType.cellCentered()) {
546 for (const Box& b : edge_boxes) {
548 [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
549 {
551 IntVect const idx(AMREX_D_DECL(i,j,k));
552 fillfunc(idx, fab, dcomp, numcomp, domain, bcr_p, 0);
553 f_user(idx, fab, dcomp, numcomp, geomdata, time,
554 bcr_p, 0, orig_comp);
555 });
556 }
557 } else if (n_edge_boxes > 1) {
558 AsyncArray<Box> edge_boxes_aa(edge_boxes.data(), n_edge_boxes);
559 Box* boxes_p = edge_boxes_aa.data();
560 Long ncounts = 0;
561 for (const auto& b : edge_boxes) {
562 ncounts += b.numPts();
563 }
564 amrex::ParallelFor(ncounts,
565 [=] AMREX_GPU_DEVICE (Long icount) noexcept
566 {
567 const auto& idx = getCell(boxes_p, n_edge_boxes, icount);
568 fillfunc(idx, fab, dcomp, numcomp, domain, bcr_p, 0);
569 f_user(idx, fab, dcomp, numcomp, geomdata, time,
570 bcr_p, 0, orig_comp);
571 });
572 }
573 }
574#endif
575
576#if (AMREX_SPACEDIM == 3)
577 // fill on corners
578 {
579 Array<Box,8> dom_corner_boxes
580 = {{ amrex::convert(amrex::adjCellLo(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
581 amrex::convert(amrex::adjCellLo(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
582 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
583 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
584 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
585 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
586 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
587 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType) }};
588
589 Vector<Box> corner_boxes;
590 for (const Box& b : dom_corner_boxes) {
591 Box tmp = b & bx;
592 if (tmp.ok()) { corner_boxes.push_back(tmp); }
593 }
594 const int n_corner_boxes = corner_boxes.size();
595 if (n_corner_boxes == 1) {
596 amrex::ParallelFor(corner_boxes[0],
597 [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
598 {
599 IntVect const idx(AMREX_D_DECL(i,j,k));
600 fillfunc(idx, fab, dcomp, numcomp, domain, bcr_p, 0);
601 f_user(idx, fab, dcomp, numcomp, geomdata, time,
602 bcr_p, 0, orig_comp);
603 });
604 } else if (n_corner_boxes > 1) {
605 AsyncArray<Box> corner_boxes_aa(corner_boxes.data(), n_corner_boxes);
606 Box* boxes_p = corner_boxes_aa.data();
607 Long ncounts = 0;
608 for (const auto& b : corner_boxes) {
609 ncounts += b.numPts();
610 }
611 amrex::ParallelFor(ncounts,
612 [=] AMREX_GPU_DEVICE (Long icount) noexcept
613 {
614 const auto& idx = getCell(boxes_p, n_corner_boxes, icount);
615 fillfunc(idx, fab, dcomp, numcomp, domain, bcr_p, 0);
616 f_user(idx, fab, dcomp, numcomp, geomdata, time,
617 bcr_p, 0, orig_comp);
618 });
619 }
620 }
621#endif
622
623#else
624 BCRec const* bcr_p = bcr.data()+bcomp;
625
626 const auto& f_user = m_user_f;
627
628 // fill on the box faces first
629 {
630 Array<Box,2*AMREX_SPACEDIM> dom_face_boxes
631 = {{ AMREX_D_DECL(amrex::convert(amrex::adjCellLo(gdomain, 0, len[0]),idxType),
632 amrex::convert(amrex::adjCellLo(gdomain, 1, len[1]),idxType),
633 amrex::convert(amrex::adjCellLo(gdomain, 2, len[2]),idxType)),
634 AMREX_D_DECL(amrex::convert(amrex::adjCellHi(gdomain, 0, len[0]),idxType),
635 amrex::convert(amrex::adjCellHi(gdomain, 1, len[1]),idxType),
636 amrex::convert(amrex::adjCellHi(gdomain, 2, len[2]),idxType)) }};
637
638 for (const Box& b : dom_face_boxes) {
639 Box tmp = b & bx;
640 amrex::For(tmp, [=] (int i, int j, int k) noexcept
641 {
643 IntVect const idx(AMREX_D_DECL(i,j,k));
644 fillfunc(idx, fab, dcomp, numcomp, domain, bcr_p, 0);
645 f_user(idx, fab, dcomp, numcomp, geomdata, time,
646 bcr_p, 0, orig_comp);
647 });
648 }
649 }
650
651#if (AMREX_SPACEDIM >= 2)
652 // fill on the box edges
653 {
654#if (AMREX_SPACEDIM == 2)
655 Array<Box,4> dom_edge_boxes
656 = {{ amrex::convert(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),idxType),
657 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),idxType),
658 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),idxType),
659 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),idxType) }};
660#else
661 Array<Box,12> dom_edge_boxes
662 = {{ amrex::convert(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),idxType),
663 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),idxType),
664 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),idxType),
665 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),idxType),
666 //
667 amrex::convert(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),2,len[2]),idxType),
668 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),2,len[2]),idxType),
669 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),2,len[2]),idxType),
670 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),2,len[2]),idxType),
671 //
672 amrex::convert(amrex::adjCellLo(amrex::adjCellLo(gdomain,1,len[1]),2,len[2]),idxType),
673 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(gdomain,1,len[1]),2,len[2]),idxType),
674 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(gdomain,1,len[1]),2,len[2]),idxType),
675 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(gdomain,1,len[1]),2,len[2]),idxType) }};
676#endif
677
678 for (const Box& b : dom_edge_boxes) {
679 Box tmp = b & bx;
680 amrex::For(tmp, [=] (int i, int j, int k) noexcept
681 {
683 IntVect const idx(AMREX_D_DECL(i,j,k));
684 fillfunc(idx, fab, dcomp, numcomp, domain, bcr_p, 0);
685 f_user(idx, fab, dcomp, numcomp, geomdata, time,
686 bcr_p, 0, orig_comp);
687 });
688 }
689 }
690#endif
691
692#if (AMREX_SPACEDIM == 3)
693 // fill on box corners
694 {
695 Array<Box,8> dom_corner_boxes
696 = {{ amrex::convert(amrex::adjCellLo(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
697 amrex::convert(amrex::adjCellLo(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
698 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
699 amrex::convert(amrex::adjCellLo(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
700 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
701 amrex::convert(amrex::adjCellHi(amrex::adjCellLo(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
702 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(amrex::adjCellLo(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType),
703 amrex::convert(amrex::adjCellHi(amrex::adjCellHi(amrex::adjCellHi(gdomain,0,len[0]),1,len[1]),2,len[2]),idxType) }};
704
705 for (const Box& b : dom_corner_boxes) {
706 Box tmp = b & bx;
707 amrex::For(tmp, [=] (int i, int j, int k) noexcept
708 {
709 IntVect const idx(AMREX_D_DECL(i,j,k));
710 fillfunc(idx, fab, dcomp, numcomp, domain, bcr_p, 0);
711 f_user(idx, fab, dcomp, numcomp, geomdata, time,
712 bcr_p, 0, orig_comp);
713 });
714 }
715 }
716#endif
717
718#endif
719}
720
721}
722#endif
#define AMREX_ARLIM_P(x)
Definition AMReX_ArrayLim.H:30
Boundary condition descriptors used throughout AMReX.
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
Problem-domain geometry: maps between index space and physical space.
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_D_PICK(a, b, c)
Definition AMReX_SPACE.H:173
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Boundary condition record storing low/high face types per coordinate.
Definition AMReX_BCRec.H:25
Array4< T const > array() const noexcept
Create an Array4 view over all components.
Definition AMReX_BaseFab.H:496
BndryFuncArray() noexcept=default
bool m_run_on_gpu
Definition AMReX_PhysBCFunct.H:54
void operator()(Box const &bx, FArrayBox &dest, int dcomp, int numcomp, Geometry const &geom, Real time, const Vector< BCRec > &bcr, int bcomp, int orig_comp)
Definition AMReX_PhysBCFunct.cpp:7
BndryFuncArray(BndryFunc3DDefault inFunc) noexcept
Definition AMReX_PhysBCFunct.H:40
BndryFunc3DDefault m_func3D
Definition AMReX_PhysBCFunct.H:53
BndryFuncDefault m_func
Definition AMReX_PhysBCFunct.H:52
bool RunOnGPU() const noexcept
Definition AMReX_PhysBCFunct.H:48
IndexType ixType() const noexcept
Return index type of this BoxArray.
Definition AMReX_BoxArray.H:1269
__host__ __device__ BoxND & grow(int i) noexcept
Grow in all directions by i cells (negative shrinks).
Definition AMReX_Box.H:668
__host__ __device__ const IntVectND< dim > & bigEnd() const &noexcept
Return the inclusive upper bound of the box.
Definition AMReX_Box.H:136
__host__ __device__ BoxND & setBig(const IntVectND< dim > &bg) noexcept
Redefine the big end of the BoxND.
Definition AMReX_Box.H:516
__host__ __device__ IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:167
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:233
__host__ __device__ IndexTypeND< dim > ixType() const noexcept
Return the indexing type.
Definition AMReX_Box.H:148
__host__ __device__ bool ok() const noexcept
Return true if high bounds are >= low bounds and the index type is valid.
Definition AMReX_Box.H:229
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
Return the inclusive lower bound of the box.
Definition AMReX_Box.H:124
__host__ __device__ BoxND & setSmall(const IntVectND< dim > &sm) noexcept
Definition AMReX_Box.H:508
UserFillBox f_user
Definition AMReX_PhysBCFunct.H:124
CpuBndryFuncFab(UserFillBox a_f)
Definition AMReX_PhysBCFunct.H:115
void operator()(Box const &bx, FArrayBox &dest, int dcomp, int numcomp, Geometry const &geom, Real time, const Vector< BCRec > &bcr, int bcomp, int orig_comp)
Definition AMReX_PhysBCFunct.cpp:48
A Fortran Array of REALs.
Definition AMReX_FArrayBox.H:237
IntVect nGrowVect() const noexcept
Definition AMReX_FabArrayBase.H:85
const BoxArray & boxArray() const noexcept
Return a constant reference to the BoxArray that defines the valid region associated with this FabArr...
Definition AMReX_FabArrayBase.H:100
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:87
const Box & Domain() const noexcept
Returns our rectangular domain.
Definition AMReX_Geometry.H:246
GeometryData data() const noexcept
Return a GPU-safe snapshot of the Geometry data.
Definition AMReX_Geometry.H:136
bool isPeriodic(int dir) const noexcept
Is the domain periodic in the specified direction?
Definition AMReX_Geometry.H:399
GpuBndryFuncFab(F const &a_f)
Definition AMReX_PhysBCFunct.H:72
void nddoit(Box const &bx, FArrayBox &dest, int dcomp, int numcomp, Geometry const &geom, Real time, const Vector< BCRec > &bcr, int bcomp, int orig_comp)
Definition AMReX_PhysBCFunct.H:282
GpuBndryFuncFab(F &&a_f)
Definition AMReX_PhysBCFunct.H:73
void ccfcdoit(Box const &bx, FArrayBox &dest, int dcomp, int numcomp, Geometry const &geom, Real time, const Vector< BCRec > &bcr, int bcomp, int orig_comp, FF const &fillfunc)
Definition AMReX_PhysBCFunct.H:435
void operator()(Box const &bx, FArrayBox &dest, int dcomp, int numcomp, Geometry const &geom, Real time, const Vector< BCRec > &bcr, int bcomp, int orig_comp)
Definition AMReX_PhysBCFunct.H:265
F m_user_f
Definition AMReX_PhysBCFunct.H:95
Definition AMReX_GpuAsyncArray.H:20
T const * data() const noexcept
Definition AMReX_GpuAsyncArray.H:61
__host__ __device__ bool cellCentered() const noexcept
True if the IndexTypeND is CELL based in all directions.
Definition AMReX_IndexType.H:102
__host__ static __device__ constexpr IntVectND< dim > TheNodeVector() noexcept
Definition AMReX_IntVect.H:830
__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:499
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:176
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
Definition AMReX_PhysBCFunct.H:128
void operator()(MultiFab &, int, int, IntVect const &, Real, int)
Definition AMReX_PhysBCFunct.H:130
IntVect src_ghost_outside_domain
Definition AMReX_PhysBCFunct.H:177
IntVect fp1_src_ghost
Definition AMReX_PhysBCFunct.H:182
PhysBCFunctUseCoarseGhost(IntVect const &a_fp1_src_ghost)
Definition AMReX_PhysBCFunct.H:138
IntVect cghost
Definition AMReX_PhysBCFunct.H:180
void operator()(MultiFab &, int, int, IntVect const &, Real, int)
Definition AMReX_PhysBCFunct.H:164
IntVect src_ghost
Definition AMReX_PhysBCFunct.H:173
IntVect nghost
Definition AMReX_PhysBCFunct.H:167
PhysBCFunctUseCoarseGhost(MF const &cmf, IntVect const &a_nghost, IntVect const &a_nghost_outside_domain, IntVect const &ratio, Interp *mapper)
Definition AMReX_PhysBCFunct.H:142
IntVect nghost_outside_domain
Definition AMReX_PhysBCFunct.H:169
void define(const Geometry &geom, const Vector< BCRec > &bcr, F const &f)
Definition AMReX_PhysBCFunct.H:199
void define(const Geometry &geom, const Vector< BCRec > &bcr, F &&f)
Definition AMReX_PhysBCFunct.H:203
PhysBCFunct(const Geometry &geom, const Vector< BCRec > &bcr, F const &f)
Definition AMReX_PhysBCFunct.H:191
void operator()(MultiFab &mf, int icomp, int ncomp, IntVect const &nghost, Real time, int bccomp)
Definition AMReX_PhysBCFunct.H:207
PhysBCFunct(const Geometry &geom, const Vector< BCRec > &bcr, F &&f)
Definition AMReX_PhysBCFunct.H:195
PhysBCFunct()=default
void FillBoundary(MultiFab &mf, int icomp, int ncomp, IntVect const &nghost, Real time, int bccomp)
Definition AMReX_PhysBCFunct.H:251
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
Long size() const noexcept
Definition AMReX_Vector.H:54
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
amrex_long Long
Definition AMReX_INT.H:30
ArrayND< T, 4, true > Array4
Convenient alias for a 4D ArrayND with three spatial dimensions plus a component dimension.
Definition AMReX_Array4.H:1352
__host__ __device__ BoxND< dim > adjCellHi(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the high end along coordinate direction dir.
Definition AMReX_Box.H:1850
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1632
__host__ __device__ BoxND< dim > adjCellLo(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the low end along coordinate direction dir.
Definition AMReX_Box.H:1819
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Return a copy of b grown uniformly by i cells in every direction.
Definition AMReX_Box.H:1328
std::array< T, N > Array
Definition AMReX_Array.H:31
@ int_dir
Definition AMReX_BC_TYPES.H:89
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:273
@ F
Definition AMReX_Order.H:7
void For(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:400
void(*)(Box const &bx, Array4< Real > const &dest, int dcomp, int numcomp, GeometryData const &geom, Real time, const BCRec *bcr, int bcomp, int orig_comp) UserFillBox
Definition AMReX_PhysBCFunct.H:28
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
IndexTypeND< 3 > IndexType
IndexType is an alias for amrex::IndexTypeND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:41
void(*)(Real *data, const int *lo, const int *hi, const int *dom_lo, const int *dom_hi, const Real *dx, const Real *grd_lo, const Real *time, const int *bc) BndryFunc3DDefault
Definition AMReX_PhysBCFunct.H:22
IntVect nGrowVect(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nGrowVect().
Definition AMReX_FabArrayBase.cpp:3033
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
void setBC(const Box &bx, const Box &domain, int src_comp, int dest_comp, int ncomp, const Vector< BCRec > &bc_dom, Vector< BCRec > &bcr) noexcept
Populate a span of BCRec objects based on a domain record.
Definition AMReX_BCRec.cpp:8
__host__ __device__ IntVectND< dim > getCell(BoxND< dim > const *boxes, int nboxes, Long icell) noexcept
Return the point coordinate corresponding to the flattened index icell.
Definition AMReX_Box.H:2410
void(*)(Real *data, const int &, const int &, const int &, const int &, const int &, const int &, const int *dom_lo, const int *dom_hi, const Real *dx, const Real *grd_lo, const Real *time, const int *bc) BndryFuncDefault
Definition AMReX_PhysBCFunct.H:18
Definition AMReX_PhysBCFunct.H:99
__device__ void operator()(const amrex::IntVect &, amrex::Array4< amrex::Real > const &, int, int, amrex::GeometryData const &, amrex::Real, const amrex::BCRec *, int, int) const
Definition AMReX_PhysBCFunct.H:101
GPU-safe snapshot of Geometry data suitable for capture in GPU kernels.
Definition AMReX_Geometry.H:38