1#ifndef AMREX_EB2_GEOMETRYSHOP_H_
2#define AMREX_EB2_GEOMETRYSHOP_H_
3#include <AMReX_Config.H>
18template <class F, std::enable_if_t<IsGPUable<F>::value>* FOO =
nullptr>
26template <class F, std::enable_if_t<!IsGPUable<F>::value>* BAR =
nullptr>
44 int rangedir,
F const& f)
47 const Real tol = 1.e-4_rt;
48 const Real EPS = 1.0e-6_rt;
50 const Real tol = 1.e-12;
51 const Real EPS = 3.0e-15;
53 const int MAXITER = 100;
62 Real c = bPt[rangedir];
67 amrex::Error(
"BrentRootFinder. Root must be bracketed, but instead the supplied end points have the same sign.");
69 }
else if (fa == 0.0_rt) {
71 }
else if (fb == 0.0_rt) {
75 Real d = 0.0_rt, e = 0.0_rt;
77 for (i = 0; i < MAXITER; ++i)
84 d = bPt[rangedir] - aPt[rangedir];
88 if (std::abs(fc) < std::abs(fb))
90 aPt[rangedir] = bPt[rangedir];
99 Real tol1 = 2.0_rt * EPS * std::abs(bPt[rangedir]) + 0.5_rt * tol;
100 Real xm = 0.5_rt * (c - bPt[rangedir]);
102 if (std::abs(xm) <= tol1 || fb == 0.0_rt)
107 if (std::abs(e) >= tol1 && std::abs(fa) > std::abs(fb))
111 if (aPt[rangedir] == c)
120 p = s * (2.0_rt * xm * q * (q-r) - (bPt[rangedir]-aPt[rangedir]) * (r-1.0_rt));
121 q = (q-1.0_rt) * (r-1.0_rt) * (s-1.0_rt);
125 if (p > 0) { q = -q; }
129 if (2.0_rt * p <
amrex::min(3.0_rt*xm*q-std::abs(tol1*q), 1.0_rt*std::abs(e*q)))
150 aPt[rangedir] = bPt[rangedir];
154 if (std::abs(d) > tol1)
156 bPt[rangedir] = bPt[rangedir] + d;
160 if (xm < 0) { bPt[rangedir] = bPt[rangedir] - tol1; }
161 else { bPt[rangedir] = bPt[rangedir] + tol1; }
169 amrex::Error(
"BrentRootFinder: exceeding maximum iterations.");
172 return bPt[rangedir];
181template <
class F,
class R =
int>
202 : m_f(std::move(f)), m_resource()
212 : m_f(std::move(f)), m_resource(std::move(r))
221 const Real* problo = geom.ProbLo();
222 const Real* dx = geom.CellSize();
223 const auto& len3 = bx.length3d();
224 const int* blo = bx.loVect();
225 int nbody = 0, nzero = 0, nfluid = 0;
226 for (
int k = 0; k < len3[2]; ++k) {
227 for (
int j = 0; j < len3[1]; ++j) {
228 for (
int i = 0; i < len3[0]; ++i) {
230 problo[1]+(j+blo[1])*dx[1],
231 problo[2]+(k+blo[2])*dx[2])};
235 }
else if (v > 0.0_rt) {
240 if (nbody > 0 && nfluid > 0) {
return mixedcells; }
248 }
else if (nfluid == 0) {
262 template <class U=F, std::enable_if_t<IsGPUable<U>::value>* FOO =
nullptr >
267 const auto& problo = geom.ProbLoArray();
268 const auto& dx = geom.CellSizeArray();
272 using ReduceTuple =
typename decltype(reduce_data)::Type;
273 reduce_op.
eval(bx, reduce_data,
280 int nbody = 0, nzero = 0, nfluid = 0;
283 }
else if (v > 0.0_rt) {
288 return {nbody,nzero,nfluid};
290 ReduceTuple hv = reduce_data.
value(reduce_op);
291 int nbody = amrex::get<0>(hv);
293 int nfluid = amrex::get<2>(hv);
297 }
else if (nfluid == 0) {
310 template <class U=F, std::enable_if_t<!IsGPUable<U>::value>* BAR =
nullptr >
316 template <class U=F, std::enable_if_t<IsGPUable<U>::value>* FOO =
nullptr >
317 static constexpr bool isGPUable () noexcept {
return true; }
319 template <class U=F, std::enable_if_t<!IsGPUable<U>::value>* BAR =
nullptr >
320 static constexpr bool isGPUable () noexcept {
return false; }
330 template <class U=F, std::enable_if_t<IsGPUable<U>::value>* FOO =
nullptr >
332 Box const& bounding_box)
const noexcept
334 const auto& problo = geom.ProbLoArray();
335 const auto& dx = geom.CellSizeArray();
350 template <class U=F, std::enable_if_t<!IsGPUable<U>::value>* BAR =
nullptr >
352 Box const& bounding_box)
const noexcept
355 if (!
levelset.arena()->isHostAccessible()) {
371 Box const& bounding_box)
const noexcept
373 const auto& problo = geom.ProbLoArray();
374 const auto& dx = geom.CellSizeArray();
398 template <class U=F, std::enable_if_t<IsGPUable<U>::value>* FOO =
nullptr >
402 Box const& bounding_box)
const noexcept
404 auto const& dx = geom.CellSizeArray();
405 auto const& problo = geom.ProbLoArray();
409 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
428 inter(i,j,k) = std::numeric_limits<Real>::quiet_NaN();
435 template <class U=F, std::enable_if_t<!IsGPUable<U>::value>* BAR =
nullptr >
439 Box const& bounding_box)
const noexcept
441 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
452 h_type_fab.
nBytes(bx, 1));
454 const auto& h_inter = h_inter_fab.
array();
458 h_inter_fab.
nBytes(bx, 1));
473 Box const& bounding_box,
474 const int idim)
const noexcept
476 auto const& dx = geom.CellSizeArray();
477 auto const& problo = geom.ProbLoArray();
496 inter(i,j,k) = std::numeric_limits<Real>::quiet_NaN();
513 auto const& dx = geom.CellSizeArray();
514 auto const& problo = geom.ProbLoArray();
515 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
522 bool is_nan = amrex::isnan(inter(i,j,k));
524 if (lst(i,j,k) ==
Real(0.0) ||
525 (lst(i,j,k) >
Real(0.0) && is_nan))
530 inter(i,j,k) = problo[0] + i*dx[0];
532 else if (lst(i+1,j,k) ==
Real(0.0) ||
533 (lst(i+1,j,k) >
Real(0.0) && is_nan))
535 inter(i,j,k) = problo[0] + (i+1)*dx[0];
537 }
else if (idim == 1) {
538 if (lst(i,j,k) ==
Real(0.0) ||
539 (lst(i,j,k) >
Real(0.0) && is_nan))
541 inter(i,j,k) = problo[1] + j*dx[1];
543 else if (lst(i,j+1,k) ==
Real(0.0) ||
544 (lst(i,j+1,k) >
Real(0.0) && is_nan))
546 inter(i,j,k) = problo[1] + (j+1)*dx[1];
549 if (lst(i,j,k) ==
Real(0.0) ||
550 (lst(i,j,k) >
Real(0.0) && is_nan))
552 inter(i,j,k) = problo[2] + k*dx[2];
554 else if (lst(i,j,k+1) ==
Real(0.0) ||
555 (lst(i,j,k+1) >
Real(0.0) && is_nan))
557 inter(i,j,k) = problo[2] + (k+1)*dx[2];
578GeometryShop<std::decay_t<F>>
591template <
class F,
class R>
592GeometryShop<std::decay_t<F>, std::decay_t<R>>
597 (std::forward<F>(f), std::forward<R>(r));
#define AMREX_HOST_DEVICE_PARALLEL_FOR_3D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:110
#define AMREX_HOST_DEVICE_FOR_3D_FLAG(where_to_run, box, i, j, k, block)
Definition AMReX_GpuLaunch.nolint.H:100
#define AMREX_IF_ON_DEVICE(CODE)
Definition AMReX_GpuQualifiers.H:56
#define AMREX_IF_ON_HOST(CODE)
Definition AMReX_GpuQualifiers.H:58
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:190
Array4< T const > const_array() const noexcept
Definition AMReX_BaseFab.H:418
std::size_t nBytes() const noexcept
Returns how many bytes used.
Definition AMReX_BaseFab.H:269
Array4< T const > array() const noexcept
Definition AMReX_BaseFab.H:382
T * dataPtr(int n=0) noexcept
Returns a pointer to an object of type T that is the value of the Nth component associated with the c...
Definition AMReX_BaseFab.H:355
Samples an implicit function on boxes and fills EB data.
Definition AMReX_EB2_GeometryShop.H:183
F const & GetImpFunc() const &
Immutable access to the underlying implicit function.
Definition AMReX_EB2_GeometryShop.H:216
void getIntercept(Array< Array4< Real >, 3 > const &inter_arr, Array< Array4< Type_t const >, 3 > const &type_arr, Array4< Real const > const &, Geometry const &geom, RunOn, Box const &bounding_box) const noexcept
CPU-only overload of getIntercept().
Definition AMReX_EB2_GeometryShop.H:436
void fillFab(BaseFab< Real > &levelset, const Geometry &geom, RunOn, Box const &bounding_box) const noexcept
CPU-only overload of fillFab().
Definition AMReX_EB2_GeometryShop.H:351
static constexpr bool isGPUable() noexcept
Definition AMReX_EB2_GeometryShop.H:317
GeometryShop(F f, R r)
Construct a GeometryShop with an implicit function and resource handle.
Definition AMReX_EB2_GeometryShop.H:211
static constexpr int in_body
Definition AMReX_EB2_GeometryShop.H:188
static constexpr int allcovered
Definition AMReX_EB2_GeometryShop.H:192
int getBoxType(const Box &bx, const Geometry &geom, RunOn) const noexcept
CPU-only fallback for getBoxType().
Definition AMReX_EB2_GeometryShop.H:311
GeometryShop(F f)
Construct a GeometryShop that owns an implicit function f.
Definition AMReX_EB2_GeometryShop.H:201
static constexpr int in_fluid
Definition AMReX_EB2_GeometryShop.H:186
void fillFab_Cpu(BaseFab< Real > &levelset, const Geometry &geom, Box const &bounding_box) const noexcept
Definition AMReX_EB2_GeometryShop.H:370
F FunctionType
Definition AMReX_EB2_GeometryShop.H:194
void fillFab(BaseFab< Real > &levelset, const Geometry &geom, RunOn run_on, Box const &bounding_box) const noexcept
Fill a level-set FAB by sampling the implicit function on each point in the FAB.
Definition AMReX_EB2_GeometryShop.H:331
static constexpr int mixedcells
Definition AMReX_EB2_GeometryShop.H:191
static constexpr int allregular
Definition AMReX_EB2_GeometryShop.H:190
void getIntercept_Cpu(Array4< Real > const &inter, Array4< Type_t const > const &type, Geometry const &geom, Box const &bounding_box, const int idim) const noexcept
Definition AMReX_EB2_GeometryShop.H:470
void getIntercept(Array< Array4< Real >, 3 > const &inter_arr, Array< Array4< Type_t const >, 3 > const &type_arr, Array4< Real const > const &, Geometry const &geom, RunOn run_on, Box const &bounding_box) const noexcept
Compute EB intercepts for irregular edges (GPU-capable case).
Definition AMReX_EB2_GeometryShop.H:399
static constexpr int on_boundary
Definition AMReX_EB2_GeometryShop.H:187
void updateIntercept(Array< Array4< Real >, 3 > const &inter_arr, Array< Array4< Type_t const >, 3 > const &type_arr, Array4< Real const > const &lst, Geometry const &geom) const noexcept
Update intercepts when level-set data has been adjusted (e.g., fixing small cells).
Definition AMReX_EB2_GeometryShop.H:509
F && GetImpFunc() &&
Definition AMReX_EB2_GeometryShop.H:217
int getBoxType_Cpu(const Box &bx, Geometry const &geom) const noexcept
Definition AMReX_EB2_GeometryShop.H:219
int getBoxType(const Box &bx, const Geometry &geom, RunOn run_on) const noexcept
Classify bx as regular, covered, or mixed (GPU-capable case).
Definition AMReX_EB2_GeometryShop.H:263
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
Definition AMReX_Reduce.H:453
Type value()
Definition AMReX_Reduce.H:488
Definition AMReX_Reduce.H:612
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:746
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Return the inclusive upper bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1331
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1317
std::array< T, N > Array
Definition AMReX_Array.H:26
Arena * The_Pinned_Arena()
Definition AMReX_Arena.cpp:860
Arena * The_Arena()
Definition AMReX_Arena.cpp:820
static constexpr Type_t irregular
Definition AMReX_EB2_Graph.H:51
Definition AMReX_FabArrayBase.H:33
__host__ __device__ Real BrentRootFinder(GpuArray< Real, 3 > const &lo, GpuArray< Real, 3 > const &hi, int rangedir, F const &f)
Definition AMReX_EB2_GeometryShop.H:42
__host__ __device__ Real IF_f(F const &f, GpuArray< Real, 3 > const &p) noexcept
Definition AMReX_EB2_GeometryShop.H:21
GeometryShop< std::decay_t< F > > makeShop(F &&f)
Helper that constructs a GeometryShop owning the supplied implicit function.
Definition AMReX_EB2_GeometryShop.H:579
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:310
void dtoh_memcpy_async(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:435
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:92
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:421
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:139
RunOn
Definition AMReX_GpuControl.H:69
__host__ __device__ constexpr const T & Clamp(const T &v, const T &lo, const T &hi)
Definition AMReX_Algorithm.H:106
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:24
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:234
void LoopOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition AMReX_Loop.H:365
Array< Real, 3 > RealArray
Definition AMReX_Array.H:28
A multidimensional array accessor.
Definition AMReX_Array4.H:283
__host__ __device__ constexpr T * dataPtr() const noexcept
Get raw data pointer.
Definition AMReX_Array4.H:612
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:43