Block-Structured AMR Software Framework
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 
12 namespace amrex::EB2 {
13 
14 // For all implicit functions, >0: body; =0: boundary; <0: fluid
15 
16 // Intersection of bodies
17 
18 namespace IIF_detail {
19  template <typename F>
20  [[nodiscard]] inline Real do_min (const RealArray& p, F&& f) noexcept
21  {
22  return std::forward<F>(f)(p);
23  }
24 
25  template <typename F, typename... Fs>
26  [[nodiscard]] inline Real do_min (const RealArray& p, F&& f, Fs&... fs) noexcept
27  {
28  return amrex::min(std::forward<F>(f)(p), do_min(p, std::forward<Fs>(fs)...));
29  }
30 
31  template <typename F>
32  [[nodiscard]] AMREX_GPU_HOST_DEVICE inline
33  Real do_min (AMREX_D_DECL(Real x, Real y, Real z), F&& f) noexcept
34  {
35  return std::forward<F>(f)(AMREX_D_DECL(x,y,z));
36  }
37 
38  template <typename F, typename... Fs>
39  [[nodiscard]] AMREX_GPU_HOST_DEVICE inline
40  Real do_min (AMREX_D_DECL(Real x, Real y, Real z), F&& f, Fs&... fs)
41  {
42  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)...));
43  }
44 }
45 
46 template <class... Fs>
48  : public GpuTuple<Fs...>
49 {
50 public:
51  using GpuTuple<Fs...>::GpuTuple;
52 
53  [[nodiscard]] inline Real operator() (const RealArray& p) const noexcept
54  {
55  return op_impl(p, std::make_index_sequence<sizeof...(Fs)>());
56  }
57 
58  template <class U=IntersectionIF<Fs...>, std::enable_if_t<IsGPUable<U>::value,int> = 0>
59  [[nodiscard]] AMREX_GPU_HOST_DEVICE inline
60  Real operator() (AMREX_D_DECL(Real x, Real y, Real z)) const noexcept
61  {
62  return op_impl(AMREX_D_DECL(x,y,z), std::make_index_sequence<sizeof...(Fs)>());
63  }
64 
65 protected:
66 
67  template <std::size_t... Is>
68  [[nodiscard]] inline Real op_impl (const RealArray& p, std::index_sequence<Is...>) const noexcept
69  {
70  return IIF_detail::do_min(p, amrex::get<Is>(*this)...);
71  }
72 
73  template <std::size_t... Is>
74  [[nodiscard]] AMREX_GPU_HOST_DEVICE inline
75  Real op_impl (AMREX_D_DECL(Real x, Real y, Real z), std::index_sequence<Is...>) const noexcept
76  {
77  return IIF_detail::do_min(AMREX_D_DECL(x,y,z), amrex::get<Is>(*this)...);
78  }
79 };
80 
81 template <class Head, class... Tail>
82 struct IsGPUable<IntersectionIF<Head, Tail...>, std::enable_if_t<IsGPUable<Head>::value>>
83  : IsGPUable<IntersectionIF<Tail...> > {};
84 
85 template <class F>
86 struct IsGPUable<IntersectionIF<F>, std::enable_if_t<IsGPUable<F>::value>>
87  : std::true_type {};
88 
89 template <class... Fs>
91 makeIntersection (Fs&&... fs)
92 {
93  return IntersectionIF<std::decay_t<Fs> ...>(std::forward<Fs>(fs)...);
94 }
95 
96 }
97 
98 #endif
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
Definition: AMReX_EB2_IF_Intersection.H:49
Real operator()(const RealArray &p) const noexcept
Definition: AMReX_EB2_IF_Intersection.H:53
Real op_impl(const RealArray &p, std::index_sequence< Is... >) const noexcept
Definition: AMReX_EB2_IF_Intersection.H:68
AMREX_GPU_HOST_DEVICE Real op_impl(AMREX_D_DECL(Real x, Real y, Real z), std::index_sequence< Is... >) const noexcept
Definition: AMReX_EB2_IF_Intersection.H:75
Definition: AMReX_Tuple.H:93
constexpr AMREX_GPU_HOST_DEVICE GpuTuple()=default
Real do_min(const RealArray &p, F &&f) noexcept
Definition: AMReX_EB2_IF_Intersection.H:20
Definition: AMReX_FabArrayBase.H:32
constexpr IntersectionIF< std::decay_t< Fs > ... > makeIntersection(Fs &&... fs)
Definition: AMReX_EB2_IF_Intersection.H:91
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 constexpr AMREX_FORCE_INLINE const T & min(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:21
Array< Real, AMREX_SPACEDIM > RealArray
Definition: AMReX_Array.H:26
Definition: AMReX_EB2_IF_Base.H:15