1#ifndef AMREX_EB2_GEOMETRYSHOP_H_
2#define AMREX_EB2_GEOMETRYSHOP_H_
3#include <AMReX_Config.H>
19requires (IsGPUable<F>::value)
28requires (!IsGPUable<F>::value)
46 int rangedir,
F const& f)
49 const Real tol = 1.e-4_rt;
50 const Real EPS = 1.0e-6_rt;
52 const Real tol = 1.e-12;
53 const Real EPS = 3.0e-15;
55 const int MAXITER = 100;
64 Real c = bPt[rangedir];
69 amrex::Error(
"BrentRootFinder. Root must be bracketed, but instead the supplied end points have the same sign.");
71 }
else if (fa == 0.0_rt) {
73 }
else if (fb == 0.0_rt) {
77 Real d = 0.0_rt, e = 0.0_rt;
79 for (i = 0; i < MAXITER; ++i)
86 d = bPt[rangedir] - aPt[rangedir];
90 if (std::abs(fc) < std::abs(fb))
92 aPt[rangedir] = bPt[rangedir];
101 Real tol1 = 2.0_rt * EPS * std::abs(bPt[rangedir]) + 0.5_rt * tol;
102 Real xm = 0.5_rt * (c - bPt[rangedir]);
104 if (std::abs(xm) <= tol1 || fb == 0.0_rt)
109 if (std::abs(e) >= tol1 && std::abs(fa) > std::abs(fb))
113 if (aPt[rangedir] == c)
122 p = s * (2.0_rt * xm * q * (q-r) - (bPt[rangedir]-aPt[rangedir]) * (r-1.0_rt));
123 q = (q-1.0_rt) * (r-1.0_rt) * (s-1.0_rt);
127 if (p > 0) { q = -q; }
131 if (2.0_rt * p <
amrex::min(3.0_rt*xm*q-std::abs(tol1*q), 1.0_rt*std::abs(e*q)))
152 aPt[rangedir] = bPt[rangedir];
156 if (std::abs(d) > tol1)
158 bPt[rangedir] = bPt[rangedir] + d;
162 if (xm < 0) { bPt[rangedir] = bPt[rangedir] - tol1; }
163 else { bPt[rangedir] = bPt[rangedir] + tol1; }
171 amrex::Error(
"BrentRootFinder: exceeding maximum iterations.");
174 return bPt[rangedir];
183template <
class F,
class R =
int>
204 : m_f(std::move(f)), m_resource()
214 : m_f(std::move(f)), m_resource(std::move(r))
223 const Real* problo = geom.ProbLo();
224 const Real* dx = geom.CellSize();
225 const auto& len3 = bx.length3d();
226 const int* blo = bx.loVect();
227 int nbody = 0, nzero = 0, nfluid = 0;
228 for (
int k = 0; k < len3[2]; ++k) {
229 for (
int j = 0; j < len3[1]; ++j) {
230 for (
int i = 0; i < len3[0]; ++i) {
232 problo[1]+(j+blo[1])*dx[1],
233 problo[2]+(k+blo[2])*dx[2])};
237 }
else if (v > 0.0_rt) {
242 if (nbody > 0 && nfluid > 0) {
return mixedcells; }
250 }
else if (nfluid == 0) {
269 const auto& problo = geom.ProbLoArray();
270 const auto& dx = geom.CellSizeArray();
274 using ReduceTuple =
typename decltype(reduce_data)::Type;
275 reduce_op.
eval(bx, reduce_data,
282 int nbody = 0, nzero = 0, nfluid = 0;
285 }
else if (v > 0.0_rt) {
290 return {nbody,nzero,nfluid};
292 ReduceTuple hv = reduce_data.
value(reduce_op);
293 int nbody = amrex::get<0>(hv);
295 int nfluid = amrex::get<2>(hv);
299 }
else if (nfluid == 0) {
335 Box const& bounding_box)
const noexcept
338 const auto& problo = geom.ProbLoArray();
339 const auto& dx = geom.CellSizeArray();
355 Box const& bounding_box)
const noexcept
359 if (!
levelset.arena()->isHostAccessible()) {
375 Box const& bounding_box)
const noexcept
377 const auto& problo = geom.ProbLoArray();
378 const auto& dx = geom.CellSizeArray();
405 Box const& bounding_box)
const noexcept
408 auto const& dx = geom.CellSizeArray();
409 auto const& problo = geom.ProbLoArray();
413 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
432 inter(i,j,k) = std::numeric_limits<Real>::quiet_NaN();
442 Box const& bounding_box)
const noexcept
445 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
456 h_type_fab.
nBytes(bx, 1));
458 const auto& h_inter = h_inter_fab.
array();
462 h_inter_fab.
nBytes(bx, 1));
477 Box const& bounding_box,
478 const int idim)
const noexcept
480 auto const& dx = geom.CellSizeArray();
481 auto const& problo = geom.ProbLoArray();
500 inter(i,j,k) = std::numeric_limits<Real>::quiet_NaN();
517 auto const& dx = geom.CellSizeArray();
518 auto const& problo = geom.ProbLoArray();
519 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
526 bool is_nan = amrex::isnan(inter(i,j,k));
528 if (lst(i,j,k) ==
Real(0.0) ||
529 (lst(i,j,k) >
Real(0.0) && is_nan))
534 inter(i,j,k) = problo[0] + i*dx[0];
536 else if (lst(i+1,j,k) ==
Real(0.0) ||
537 (lst(i+1,j,k) >
Real(0.0) && is_nan))
539 inter(i,j,k) = problo[0] + (i+1)*dx[0];
541 }
else if (idim == 1) {
542 if (lst(i,j,k) ==
Real(0.0) ||
543 (lst(i,j,k) >
Real(0.0) && is_nan))
545 inter(i,j,k) = problo[1] + j*dx[1];
547 else if (lst(i,j+1,k) ==
Real(0.0) ||
548 (lst(i,j+1,k) >
Real(0.0) && is_nan))
550 inter(i,j,k) = problo[1] + (j+1)*dx[1];
553 if (lst(i,j,k) ==
Real(0.0) ||
554 (lst(i,j,k) >
Real(0.0) && is_nan))
556 inter(i,j,k) = problo[2] + k*dx[2];
558 else if (lst(i,j,k+1) ==
Real(0.0) ||
559 (lst(i,j,k+1) >
Real(0.0) && is_nan))
561 inter(i,j,k) = problo[2] + (k+1)*dx[2];
582GeometryShop<std::decay_t<F>>
595template <
class F,
class R>
596GeometryShop<std::decay_t<F>, std::decay_t<R>>
601 (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:104
#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
virtual bool isHostAccessible() const
Definition AMReX_Arena.cpp:76
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:194
Array4< T const > const_array() const noexcept
Definition AMReX_BaseFab.H:423
std::size_t nBytes() const noexcept
Returns how many bytes used.
Definition AMReX_BaseFab.H:274
Array4< T const > array() const noexcept
Definition AMReX_BaseFab.H:387
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:360
Samples an implicit function on boxes and fills EB data.
Definition AMReX_EB2_GeometryShop.H:185
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:264
F const & GetImpFunc() const &
Immutable access to the underlying implicit function.
Definition AMReX_EB2_GeometryShop.H:218
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:354
GeometryShop(F f, R r)
Construct a GeometryShop with an implicit function and resource handle.
Definition AMReX_EB2_GeometryShop.H:213
static constexpr int in_body
Definition AMReX_EB2_GeometryShop.H:190
static constexpr bool isGPUable() noexcept
Definition AMReX_EB2_GeometryShop.H:318
static constexpr int allcovered
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:334
GeometryShop(F f)
Construct a GeometryShop that owns an implicit function f.
Definition AMReX_EB2_GeometryShop.H:203
static constexpr int in_fluid
Definition AMReX_EB2_GeometryShop.H:188
int getBoxType(const Box &bx, const Geometry &geom, RunOn) const noexcept
CPU-only fallback for getBoxType().
Definition AMReX_EB2_GeometryShop.H:312
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:402
void fillFab_Cpu(BaseFab< Real > &levelset, const Geometry &geom, Box const &bounding_box) const noexcept
Definition AMReX_EB2_GeometryShop.H:374
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:439
F FunctionType
Definition AMReX_EB2_GeometryShop.H:196
static constexpr int mixedcells
Definition AMReX_EB2_GeometryShop.H:193
static constexpr int allregular
Definition AMReX_EB2_GeometryShop.H:192
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:474
static constexpr int on_boundary
Definition AMReX_EB2_GeometryShop.H:189
static constexpr bool isGPUable() noexcept
Definition AMReX_EB2_GeometryShop.H:322
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:513
F && GetImpFunc() &&
Definition AMReX_EB2_GeometryShop.H:219
int getBoxType_Cpu(const Box &bx, Geometry const &geom) const noexcept
Definition AMReX_EB2_GeometryShop.H:221
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:75
Definition AMReX_Reduce.H:438
Type value()
Definition AMReX_Reduce.H:473
Definition AMReX_Reduce.H:597
void eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:731
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:1359
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1345
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:44
__host__ __device__ Real IF_f(F const &f, GpuArray< Real, 3 > const &p) noexcept
Definition AMReX_EB2_GeometryShop.H:22
GeometryShop< std::decay_t< F > > makeShop(F &&f)
Helper that constructs a GeometryShop owning the supplied implicit function.
Definition AMReX_EB2_GeometryShop.H:583
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:88
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:65
__host__ __device__ constexpr const T & Clamp(const T &v, const T &lo, const T &hi)
Definition AMReX_Algorithm.H:107
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:25
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:235
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:285
__host__ __device__ constexpr T * dataPtr() const noexcept
Get raw data pointer.
Definition AMReX_Array4.H:613
Type trait that reports whether a functor derives from GPUable.
Definition AMReX_EB2_IF_Base.H:24
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:43