Block-Structured AMR Software Framework
AMReX_EB2_IF_Difference.H
Go to the documentation of this file.
1 #ifndef AMREX_EB2_IF_DIFFERENCE_H_
2 #define AMREX_EB2_IF_DIFFERENCE_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_Array.H>
6 #include <AMReX_EB2_IF_Base.H>
7 
8 #include <type_traits>
9 #include <algorithm>
10 #include <utility>
11 
12 // For all implicit functions, >0: body; =0: boundary; <0: fluid
13 
14 namespace amrex::EB2 {
15 
16 template <class F, class G>
18 {
19 public:
20 
21  DifferenceIF (F a_f, G a_g)
22  : m_f(std::move(a_f)),
23  m_g(std::move(a_g))
24  {}
25 
26  [[nodiscard]] inline Real operator() (const RealArray& p) const noexcept
27  {
28  Real r1 = m_f(p);
29  Real r2 = m_g(p);
30  return amrex::min(r1, -r2);
31  }
32 
33  template <class U=F, class V=G,
34  std::enable_if_t<IsGPUable<U>::value &&
35  IsGPUable<V>::value, int> = 0>
36  [[nodiscard]] AMREX_GPU_HOST_DEVICE inline
37  Real operator() (AMREX_D_DECL(Real x, Real y, Real z)) const noexcept
38  {
39  Real r1 = m_f(AMREX_D_DECL(x,y,z));
40  Real r2 = m_g(AMREX_D_DECL(x,y,z));
41  return amrex::min(r1, -r2);
42  }
43 
44 protected:
45 
46  F m_f;
47  G m_g;
48 };
49 
50 template <class F, class G>
51 struct IsGPUable<DifferenceIF<F,G>, std::enable_if_t<IsGPUable<F>::value &&
52  IsGPUable<G>::value>>
53  : std::true_type {};
54 
55 template <class F, class G>
57  std::decay_t<G>>
58 makeDifference (F&& f, G&& g)
59 {
61  std::decay_t<G>>
62  (std::forward<F>(f), std::forward<G>(g));
63 }
64 
65 }
66 
67 #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_Difference.H:18
DifferenceIF(F a_f, G a_g)
Definition: AMReX_EB2_IF_Difference.H:21
Real operator()(const RealArray &p) const noexcept
Definition: AMReX_EB2_IF_Difference.H:26
G m_g
Definition: AMReX_EB2_IF_Difference.H:47
F m_f
Definition: AMReX_EB2_IF_Difference.H:46
Definition: AMReX_FabArrayBase.H:32
constexpr DifferenceIF< std::decay_t< F >, std::decay_t< G > > makeDifference(F &&f, G &&g)
Definition: AMReX_EB2_IF_Difference.H:58
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