12 #ifndef AMREX_ALGOIM_K_H_
13 #define AMREX_ALGOIM_K_H_
14 #include <AMReX_Config.H>
38 EBPlane (Real cx, Real cy, Real cz, Real nx, Real ny, Real nz) noexcept
56 Real
grad (
int d)
const noexcept
77 for (
int i = 0; i <
nnodes; ++i) {
86 eval (
const F&
f)
const noexcept
89 for (
int i = 0; i <
nnodes; ++i) {
113 void swap (T& a, T& b) noexcept {
126 determineSigns (
bool positiveAbove,
int sign,
int& bottomSign,
int& topSign) noexcept
143 bottomSign = positiveAbove? -1 : 1;
144 topSign = positiveAbove? 1 : -1;
148 bottomSign = positiveAbove? 0 : 1;
149 topSign = positiveAbove? 1 : 0;
153 bottomSign = positiveAbove? -1 : 0;
154 topSign = positiveAbove? 0 : -1;
157 bottomSign = topSign = 0;
179 static_assert(N <= 3,
"algoim::PsiCode: N must be <= 3");
180 for (
int dim = 0; dim < N; ++dim) {
181 if (sides[dim] == 1) {
190 bits |= (1 << (N+1));
208 bits |= (1 << (N+1));
214 int side (
int dim)
const noexcept
216 return bits & (1 << dim);
222 return (
bits & (1 << N)) ? 0 : ((
bits & (1 << (N+1))) ? 1 : -1);
229 static constexpr Real
min (
int ) noexcept {
return -0.5_rt; }
231 static constexpr Real
max (
int ) noexcept {
return 0.5_rt; }
233 static constexpr Real
extent (
int ) noexcept {
return 1.0_rt; }
239 static constexpr Real
midpoint (
int ) noexcept {
return 0.0_rt; }
242 return (side == 0) ? -0.5_rt : 0.5_rt;
248 Real
alpha = std::numeric_limits<Real>::lowest();
253 template<
int M,
int N,
typename Phi,
typename F,
bool S>
264 static constexpr
int p = 4;
275 static constexpr Real
eps = std::numeric_limits<Real>::epsilon();
281 Real dphi_max = 0.0_rt;
282 for (
int dim = 0; dim < N; ++dim) {
290 const Real phi_0 = (*phi)(mid);
291 bool uniform_sign = (phi_0 > dphi_max) || (phi_0 < -dphi_max);
294 if ((phi_0 >= 0.0 &&
psi[i].sign() >= 0) ||
295 (phi_0 <= 0.0 &&
psi[i].sign() <= 0) )
316 constexpr Real gauss_x[4]={0.069431844202973712388026755553595247452_rt,
317 0.33000947820757186759866712044837765640_rt,
318 0.66999052179242813240133287955162234360_rt,
319 0.93056815579702628761197324444640475255_rt};
320 constexpr Real gauss_w[4]={0.173927422568726928686531974610999703618_rt,
321 0.326072577431273071313468025389000296382_rt,
322 0.326072577431273071313468025389000296382_rt,
323 0.173927422568726928686531974610999703618_rt};
326 for (
int i = 0; i <
M; ++i) {
330 for (
int iloop = 0; iloop < nloops; ++iloop)
334 for (
int dim = 0, k = 0; dim < N; ++dim) {
336 x[dim] =
xrange.min(dim) +
xrange.extent(dim) * gauss_x[i[k]];
337 w *=
xrange.extent(dim) * gauss_w[i[k]];
341 f->evalIntegrand(
x, w);
343 for (
int m =
M-1; m >= 0; --m) {
361 constexpr Real gauss_x[4]={0.069431844202973712388026755553595247452_rt,
362 0.33000947820757186759866712044837765640_rt,
363 0.66999052179242813240133287955162234360_rt,
364 0.93056815579702628761197324444640475255_rt};
365 constexpr Real gauss_w[4]={0.173927422568726928686531974610999703618_rt,
366 0.326072577431273071313468025389000296382_rt,
367 0.326072577431273071313468025389000296382_rt,
368 0.173927422568726928686531974610999703618_rt};
388 Real phi_lo = (*phi)(
x);
389 Real xroot =
x[
e0] - phi_lo /
phi->grad(
e0);
390 if (xroot > x_min && xroot < x_max) {
391 roots[nroots++] = xroot;
396 for (
int i = 0; i < nroots; ++i)
400 for (
int dim = 0; dim < N; ++dim) {
401 mag +=
phi->grad(dim)*
phi->grad(dim);
415 if (
phi->grad(
e0) != Real(0.0)) {
418 for (
int dim = 0; dim < N; ++dim) {
425 Real phi_lo = (*phi)(
x);
426 Real xroot =
x[
e0] - phi_lo /
phi->grad(
e0);
427 if (xroot > x_min && xroot < x_max) {
428 roots[nroots++] = xroot;
433 if (nroots == 3 && roots[1] > roots[2]) {
436 roots[nroots++] = x_max;
439 static constexpr Real
eps = std::numeric_limits<Real>::epsilon();
440 constexpr Real tol = 50.0*
eps;
443 for (
int i = 0; i < nroots - 1; ++i)
445 if (roots[i+1] - roots[i] < tol) {
continue; }
449 x[
e0] = (roots[i] + roots[i+1])*0.5;
450 for (
int j = 0; j <
psiCount && okay; ++j)
452 for (
int dim = 0; dim < N; ++dim) {
457 bool new_ok = ((*phi)(
x) > 0.0) ? (
psi[j].sign() >= 0) : (
psi[j].sign() <= 0);
458 okay = okay && new_ok;
460 if (!okay) {
continue; }
462 for (
int j = 0; j <
p; ++j)
464 x[
e0] = roots[i] + (roots[i+1] - roots[i]) * gauss_x[j];
465 Real gw = (roots[i+1] - roots[i]) * gauss_w[j];
466 f->evalIntegrand(
x, w * gw);
473 template <
int K = M, std::enable_if_t<K==1,
int> = 0>
477 int psiCount_) noexcept
483 for (
int dim = 0; dim < N; ++dim) {
493 template <
int K = M, std::enable_if_t<(K>1),
int> = 0>
497 int psiCount_) noexcept
502 for (
int dim = 0; dim < N; ++dim)
510 xint[dim].alpha = 0.0_rt;
540 for (
int dim = 0; dim < N; ++dim) {
555 for (
int dim = 0; dim < N; ++dim) {
562 int bottomSign, topSign;
563 detail::determineSigns<S>(
phi->grad(
e0) > 0.0,
psi[i].sign(),
564 bottomSign, topSign);
572 new_free[
e0] =
false;
574 (*
phi, *
this, new_free, newPsi, newPsiCount);
579 template<
int N,
typename Phi,
typename F,
bool S>
615 constexpr Real
twelfth = 1._rt/12._rt;
616 constexpr Real offth = 1._rt/144._rt;
617 intg(i,j,k,
i_S_x ) = 0.0_rt;
618 intg(i,j,k,
i_S_y ) = 0.0_rt;
619 intg(i,j,k,
i_S_z ) = 0.0_rt;
641 sintg(i,j,k,
i_B_x ) = 0.0_rt;
642 sintg(i,j,k,
i_B_y ) = 0.0_rt;
643 sintg(i,j,k,
i_B_z ) = 0.0_rt;
644 sintg(i,j,k,
i_B_x_y ) = 0.0_rt;
645 sintg(i,j,k,
i_B_x_z ) = 0.0_rt;
646 sintg(i,j,k,
i_B_y_z ) = 0.0_rt;
647 sintg(i,j,k,
i_B_xyz ) = 0.0_rt;
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_GPU_HOST
Definition: AMReX_GpuQualifiers.H:17
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void swap(T &a, T &b) noexcept
Definition: AMReX_algoim_K.H:113
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void determineSigns(bool positiveAbove, int sign, int &bottomSign, int &topSign) noexcept
Definition: AMReX_algoim_K.H:126
Definition: AMReX_algoim.cpp:6
static constexpr int i_B_xyz
Definition: AMReX_algoim.H:42
static constexpr int i_S_y_z2
Definition: AMReX_algoim.H:26
static constexpr int i_S_y_z
Definition: AMReX_algoim.H:20
AMREX_GPU_HOST_DEVICE QuadratureRule quadGen(EBPlane const &phi) noexcept
Definition: AMReX_algoim_K.H:590
static constexpr int i_S_x2
Definition: AMReX_algoim.H:15
static constexpr int i_S_x_y
Definition: AMReX_algoim.H:18
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void set_regular_surface(int i, int j, int k, Array4< Real > const &sintg) noexcept
Definition: AMReX_algoim_K.H:639
static constexpr int i_S_y
Definition: AMReX_algoim.H:13
static constexpr int i_S_x_z
Definition: AMReX_algoim.H:19
static constexpr int i_B_z
Definition: AMReX_algoim.H:38
static constexpr int i_S_x_y2
Definition: AMReX_algoim.H:23
static constexpr int i_S_xyz
Definition: AMReX_algoim.H:30
static constexpr int i_S_y2_z2
Definition: AMReX_algoim.H:29
static constexpr int i_B_x_y
Definition: AMReX_algoim.H:39
static constexpr int i_B_x_z
Definition: AMReX_algoim.H:40
static constexpr int i_S_x2_y2
Definition: AMReX_algoim.H:27
static constexpr int i_S_x2_z2
Definition: AMReX_algoim.H:28
static constexpr int i_S_x
Definition: AMReX_algoim.H:12
static constexpr int i_S_y2_z
Definition: AMReX_algoim.H:24
static constexpr int i_S_x2_y
Definition: AMReX_algoim.H:21
static constexpr int i_B_y_z
Definition: AMReX_algoim.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void set_regular(int i, int j, int k, Array4< Real > const &intg) noexcept
Definition: AMReX_algoim_K.H:613
static constexpr int i_B_x
Definition: AMReX_algoim.H:36
static constexpr int i_S_z
Definition: AMReX_algoim.H:14
static constexpr int i_S_z2
Definition: AMReX_algoim.H:17
static constexpr int i_S_x_z2
Definition: AMReX_algoim.H:25
static constexpr int i_S_x2_z
Definition: AMReX_algoim.H:22
AMREX_GPU_HOST_DEVICE QuadratureRule quadGenSurf(EBPlane const &phi) noexcept
Definition: AMReX_algoim_K.H:602
static constexpr int i_B_y
Definition: AMReX_algoim.H:37
static constexpr int i_S_y2
Definition: AMReX_algoim.H:16
constexpr double eps
Definition: AMReX_MLNodeLap_K.H:19
constexpr Real almostone
Definition: AMReX_MLNodeLap_K.H:21
static constexpr int M
Definition: AMReX_OpenBC.H:13
real(kind=amrex_real), parameter twelfth
Definition: AMReX_constants_mod.f90:32
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition: AMReX_GpuComplex.H:356
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition: AMReX_GpuComplex.H:373
Definition: AMReX_FabArrayCommI.H:841
Definition: AMReX_Array4.H:61
Definition: AMReX_algoim_K.H:228
static constexpr Real min(int) noexcept
Definition: AMReX_algoim_K.H:229
static constexpr Real max(int) noexcept
Definition: AMReX_algoim_K.H:231
static constexpr GpuArray< Real, N > midpoint() noexcept
Definition: AMReX_algoim_K.H:235
constexpr Real operator()(int side, int) const noexcept
Definition: AMReX_algoim_K.H:241
static constexpr Real midpoint(int) noexcept
Definition: AMReX_algoim_K.H:239
static constexpr Real extent(int) noexcept
Definition: AMReX_algoim_K.H:233
Definition: AMReX_algoim_K.H:24
GpuArray< Real, 3 > cent
Definition: AMReX_algoim_K.H:25
constexpr AMREX_GPU_HOST_DEVICE EBPlane(Real cx, Real cy, Real cz, Real nx, Real ny, Real nz) noexcept
Definition: AMReX_algoim_K.H:38
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real grad(int d) const noexcept
Definition: AMReX_algoim_K.H:56
constexpr AMREX_GPU_HOST_DEVICE EBPlane(GpuArray< Real, 3 > const &c, GpuArray< Real, 3 > const n) noexcept
Definition: AMReX_algoim_K.H:32
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real operator()(Real x, Real y, Real z) const noexcept
Definition: AMReX_algoim_K.H:43
GpuArray< Real, 3 > norm
Definition: AMReX_algoim_K.H:26
AMREX_GPU_HOST_DEVICE ImplicitIntegral(const Phi &, F &, const GpuArray< bool, N > &, const GpuArray< PsiCode< N >, 1<<(N-1)> &, int) noexcept
Definition: AMReX_algoim_K.H:583
Definition: AMReX_algoim_K.H:255
static constexpr int p
Definition: AMReX_algoim_K.H:264
BoundingBox< N > xrange
Definition: AMReX_algoim_K.H:261
F * f
Definition: AMReX_algoim_K.H:257
const Phi * phi
Definition: AMReX_algoim_K.H:256
AMREX_GPU_HOST_DEVICE ImplicitIntegral(const Phi &phi_, F &f_, const GpuArray< bool, N > &free_, const GpuArray< PsiCode< N >, 1<<(N-1)> &psi_, int psiCount_) noexcept
Definition: AMReX_algoim_K.H:475
int e0
Definition: AMReX_algoim_K.H:262
AMREX_GPU_HOST_DEVICE void evalIntegrand(GpuArray< Real, N > x, Real w) const noexcept
Definition: AMReX_algoim_K.H:359
int psiCount
Definition: AMReX_algoim_K.H:260
GpuArray< bool, N > free
Definition: AMReX_algoim_K.H:258
GpuArray< Interval, N > xint
Definition: AMReX_algoim_K.H:263
AMREX_GPU_HOST_DEVICE bool prune() noexcept
Definition: AMReX_algoim_K.H:273
AMREX_GPU_HOST_DEVICE void tensorProductIntegral() noexcept
Definition: AMReX_algoim_K.H:314
GpuArray< PsiCode< N >, 1<<(N - 1)> psi
Definition: AMReX_algoim_K.H:259
Definition: AMReX_algoim_K.H:247
Real alpha
Definition: AMReX_algoim_K.H:248
Definition: AMReX_algoim_K.H:170
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int side(int dim) const noexcept
Definition: AMReX_algoim_K.H:214
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE PsiCode() noexcept=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int sign() const noexcept
Definition: AMReX_algoim_K.H:220
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE PsiCode(const PsiCode &i, int dim, int side, int sign) noexcept
Definition: AMReX_algoim_K.H:197
unsigned char bits
Definition: AMReX_algoim_K.H:171
Definition: AMReX_algoim_K.H:65
Real w
Definition: AMReX_algoim_K.H:66
Real z
Definition: AMReX_algoim_K.H:66
Real y
Definition: AMReX_algoim_K.H:66
Real x
Definition: AMReX_algoim_K.H:66
Definition: AMReX_algoim_K.H:63
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void evalIntegrand(const GpuArray< Real, 3 > &x_, Real w_) noexcept
Definition: AMReX_algoim_K.H:99
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real operator()(const F &f) const noexcept
Definition: AMReX_algoim_K.H:74
AMREX_GPU_HOST AMREX_FORCE_INLINE Real eval(const F &f) const noexcept
Definition: AMReX_algoim_K.H:86
int nnodes
Definition: AMReX_algoim_K.H:68
GpuArray< Node, 256 > nodes
Definition: AMReX_algoim_K.H:69