Block-Structured AMR Software Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
AMReX_EB2_IF_Union.H
Go to the documentation of this file.
1#ifndef AMREX_EB2_IF_UNION_H_
2#define AMREX_EB2_IF_UNION_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
12namespace amrex::EB2 {
13
14// For all implicit functions, >0: body; =0: boundary; <0: fluid
15
16// Union of bodies
17
18namespace UIF_detail {
19 template <typename F>
20 [[nodiscard]] inline Real do_max (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_max (const RealArray& p, F&& f, Fs&... fs) noexcept
27 {
28 return amrex::max(std::forward<F>(f)(p), do_max(p, std::forward<Fs>(fs)...));
29 }
30
31 template <typename F>
32 [[nodiscard]] AMREX_GPU_HOST_DEVICE inline
33 Real do_max (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_max (AMREX_D_DECL(Real x, Real y, Real z), F&& f, Fs&... fs) noexcept
41 {
42 return amrex::max(std::forward<F>(f)(AMREX_D_DECL(x,y,z)), do_max(AMREX_D_DECL(x,y,z), std::forward<Fs>(fs)...));
43 }
44}
45
46template <class... Fs>
48 : public GpuTuple<Fs...>
49{
50public:
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=UnionIF<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
65protected:
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 UIF_detail::do_max(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 UIF_detail::do_max(AMREX_D_DECL(x,y,z), amrex::get<Is>(*this)...);
78 }
79};
80
81template <class Head, class... Tail>
82struct IsGPUable<UnionIF<Head, Tail...>, std::enable_if_t<IsGPUable<Head>::value>>
83 : IsGPUable<UnionIF<Tail...> > {};
84
85template <class F>
86struct IsGPUable<UnionIF<F>, std::enable_if_t<IsGPUable<F>::value>>
87 : std::true_type {};
88
89template <class... Fs>
90constexpr UnionIF<std::decay_t<Fs> ...>
91makeUnion (Fs&&... fs)
92{
93 return UnionIF<std::decay_t<Fs> ...>(std::forward<Fs>(fs)...);
94}
95
96}
97
98#endif
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Definition AMReX_EB2_IF_Union.H:49
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_Union.H:75
Real operator()(const RealArray &p) const noexcept
Definition AMReX_EB2_IF_Union.H:53
Real op_impl(const RealArray &p, std::index_sequence< Is... >) const noexcept
Definition AMReX_EB2_IF_Union.H:68
Definition AMReX_Tuple.H:93
AMREX_GPU_HOST_DEVICE constexpr GpuTuple()=default
Real do_max(const RealArray &p, F &&f) noexcept
Definition AMReX_EB2_IF_Union.H:20
Definition AMReX_FabArrayBase.H:32
constexpr UnionIF< std::decay_t< Fs > ... > makeUnion(Fs &&... fs)
Definition AMReX_EB2_IF_Union.H:91
Array< Real, AMREX_SPACEDIM > RealArray
Definition AMReX_Array.H:26
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:35
Definition AMReX_EB2_IF_Base.H:15