Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_EB2_IF_Intersection.H
Go to the documentation of this file.
1#ifndef AMREX_EB2_IF_INTERSECTION_H_
2#define AMREX_EB2_IF_INTERSECTION_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_EB2_IF_Base.H>
6#include <AMReX_Array.H>
7#include <AMReX_Tuple.H>
8
9#include <algorithm>
10#include <utility>
11
18namespace amrex::EB2 {
19
20// For all implicit functions, >0: body; =0: boundary; <0: fluid
21
22// Intersection of bodies
23
25namespace IIF_detail {
26 template <typename F>
27 [[nodiscard]] AMREX_FORCE_INLINE Real do_min (const RealArray& p, F&& f) noexcept
28 {
29 return std::forward<F>(f)(p);
30 }
31
32 template <typename F, typename... Fs>
33 [[nodiscard]] AMREX_FORCE_INLINE Real do_min (const RealArray& p, F&& f, Fs&... fs) noexcept
34 {
35 return amrex::min(std::forward<F>(f)(p), do_min(p, std::forward<Fs>(fs)...));
36 }
37
38 template <typename F>
40 Real do_min (AMREX_D_DECL(Real x, Real y, Real z), F&& f) noexcept
41 {
42 return std::forward<F>(f)(AMREX_D_DECL(x,y,z));
43 }
44
45 template <typename F, typename... Fs>
47 Real do_min (AMREX_D_DECL(Real x, Real y, Real z), F&& f, Fs&... fs)
48 {
49 return amrex::min(std::forward<F>(f)(AMREX_D_DECL(x,y,z)), do_min(AMREX_D_DECL(x,y,z), std::forward<Fs>(fs)...));
50 }
51}
53
54template <class... Fs>
57 : public GpuTuple<Fs...>
58{
59public:
60 using GpuTuple<Fs...>::GpuTuple;
61
62 [[nodiscard]] AMREX_FORCE_INLINE Real operator() (const RealArray& p) const noexcept
63 {
64 return op_impl(p, std::make_index_sequence<sizeof...(Fs)>());
65 }
66
67 template <class U=IntersectionIF<Fs...>, std::enable_if_t<IsGPUable<U>::value,int> = 0>
70 {
71 return op_impl(AMREX_D_DECL(x,y,z), std::make_index_sequence<sizeof...(Fs)>());
72 }
73
74protected:
75
76 template <std::size_t... Is>
77 [[nodiscard]] AMREX_FORCE_INLINE Real op_impl (const RealArray& p, std::index_sequence<Is...>) const noexcept
78 {
79 return IIF_detail::do_min(p, amrex::get<Is>(*this)...);
80 }
81
82 template <std::size_t... Is>
84 Real op_impl (AMREX_D_DECL(Real x, Real y, Real z), std::index_sequence<Is...>) const noexcept
85 {
86 return IIF_detail::do_min(AMREX_D_DECL(x,y,z), amrex::get<Is>(*this)...);
87 }
88};
89
90template <class Head, class... Tail>
91struct IsGPUable<IntersectionIF<Head, Tail...>, std::enable_if_t<IsGPUable<Head>::value>>
92 : IsGPUable<IntersectionIF<Tail...> > {};
93
94template <class F>
95struct IsGPUable<IntersectionIF<F>, std::enable_if_t<IsGPUable<F>::value>>
96 : std::true_type {};
97
98template <class... Fs>
101{
102 return IntersectionIF<std::decay_t<Fs> ...>(std::forward<Fs>(fs)...);
103}
104
105}
106
107#endif
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Implicit function that evaluates the intersection of multiple objects.
Definition AMReX_EB2_IF_Intersection.H:58
__host__ __device__ Real op_impl(Real x, Real y, Real z, std::index_sequence< Is... >) const noexcept
Definition AMReX_EB2_IF_Intersection.H:84
Real operator()(const RealArray &p) const noexcept
Definition AMReX_EB2_IF_Intersection.H:62
Real op_impl(const RealArray &p, std::index_sequence< Is... >) const noexcept
Definition AMReX_EB2_IF_Intersection.H:77
GPU-compatible tuple.
Definition AMReX_Tuple.H:98
__host__ __device__ constexpr GpuTuple()=default
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
Definition AMReX_FabArrayBase.H:33
constexpr IntersectionIF< std::decay_t< Fs > ... > makeIntersection(Fs &&... fs)
Definition AMReX_EB2_IF_Intersection.H:100
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:24
Array< Real, 3 > RealArray
Definition AMReX_Array.H:28
Type trait that reports whether a functor derives from GPUable.
Definition AMReX_EB2_IF_Base.H:24