Block-Structured AMR Software Framework
AMReX_EB2_IF_Polynomial.H
Go to the documentation of this file.
1 #ifndef AMREX_EB2_IF_POLYNOMIAL_H_
2 #define AMREX_EB2_IF_POLYNOMIAL_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_EB2_IF_Base.H>
6 #include <AMReX_Array.H>
7 #include <AMReX_Vector.H>
8 #include <AMReX_IntVect.H>
9 #include <memory>
10 #include <cmath>
11 
12 // For all implicit functions, >0: body; =0: boundary; <0: fluid
13 
14 namespace amrex::EB2 {
15 
16 /********************************************************************************
17  * *
18  * Represents one term in a general polynomial *
19  * *
20  ********************************************************************************/
21 class PolyTerm
22 {
23 public:
24 
26  Real coef;
27 
30 };
31 
32 template <unsigned int N>
33 class PolyIF
34  : public GPUable
35 {
36 public:
37 
39  PolyIF (const GpuArray<PolyTerm,N> & a_polynomial, bool a_inside = true)
40  : m_polynomial(a_polynomial),
41  m_sign( a_inside ? 1.0_rt : -1.0_rt )
42  {}
43 
45  Real operator() (AMREX_D_DECL(Real x, Real y, Real z)) const noexcept
46  {
47  Real retval = 0.0_rt;
48  for (auto const& term : m_polynomial) {
49  retval += term.coef * AMREX_D_TERM( std::pow(x, term.powers[0]),
50  * std::pow(y, term.powers[1]),
51  * std::pow(z, term.powers[2]));
52  }
53  return m_sign*retval;
54  }
55 
56  inline Real operator() (const RealArray& p) const noexcept {
57  return this->operator()(AMREX_D_DECL(p[0],p[1],p[2]));
58  }
59 
60 protected:
62  Real m_sign;
63 };
64 
65 
66 class PolynomialIF // No GPU support
67 {
68 public:
69 
71  PolynomialIF (const Vector<PolyTerm> & a_polynomial, bool a_inside = true)
72  : m_polynomial(a_polynomial),
73  m_inside(a_inside),
74  m_sign( a_inside ? 1.0_rt : -1.0_rt ),
76  {}
77 
78  ~PolynomialIF () = default;
79  PolynomialIF (const PolynomialIF& rhs) = default;
80  PolynomialIF (PolynomialIF&& rhs) = default;
81  PolynomialIF& operator= (const PolynomialIF& rhs) = delete;
83 
84  [[nodiscard]] inline
85  Real operator() (AMREX_D_DECL(Real x, Real y, Real z)) const noexcept
86  {
87  Real retval = 0.0_rt;
88  for (auto const& term : m_polynomial) {
89  retval += term.coef * AMREX_D_TERM( std::pow(x, term.powers[0]),
90  * std::pow(y, term.powers[1]),
91  * std::pow(z, term.powers[2]));
92  }
93  return m_sign*retval;
94  }
95 
96  [[nodiscard]] inline Real operator() (const RealArray& p) const noexcept {
97  return this->operator()(AMREX_D_DECL(p[0],p[1],p[2]));
98  }
99 
100 protected:
102  bool m_inside;
103  Real m_sign;
104  int m_size;
105 };
106 
107 }
108 
109 #endif
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_D_TERM(a, b, c)
Definition: AMReX_SPACE.H:129
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
Definition: AMReX_EB2_IF_Polynomial.H:35
Real m_sign
Definition: AMReX_EB2_IF_Polynomial.H:62
GpuArray< PolyTerm, N > m_polynomial
Definition: AMReX_EB2_IF_Polynomial.H:61
AMREX_GPU_HOST_DEVICE Real operator()(AMREX_D_DECL(Real x, Real y, Real z)) const noexcept
Definition: AMReX_EB2_IF_Polynomial.H:45
PolyIF(const GpuArray< PolyTerm, N > &a_polynomial, bool a_inside=true)
inside: is the fluid inside the ellipsoid?
Definition: AMReX_EB2_IF_Polynomial.H:39
Definition: AMReX_EB2_IF_Polynomial.H:22
Real coef
Coefficient of this polynomial term.
Definition: AMReX_EB2_IF_Polynomial.H:26
IntVect powers
Powers of this polynomial term.
Definition: AMReX_EB2_IF_Polynomial.H:29
Definition: AMReX_EB2_IF_Polynomial.H:67
PolynomialIF(PolynomialIF &&rhs)=default
int m_size
Definition: AMReX_EB2_IF_Polynomial.H:104
PolynomialIF(const PolynomialIF &rhs)=default
PolynomialIF & operator=(const PolynomialIF &rhs)=delete
Real operator()(AMREX_D_DECL(Real x, Real y, Real z)) const noexcept
Definition: AMReX_EB2_IF_Polynomial.H:85
Vector< PolyTerm > m_polynomial
Definition: AMReX_EB2_IF_Polynomial.H:101
Real m_sign
Definition: AMReX_EB2_IF_Polynomial.H:103
bool m_inside
Definition: AMReX_EB2_IF_Polynomial.H:102
PolynomialIF(const Vector< PolyTerm > &a_polynomial, bool a_inside=true)
inside: is the fluid inside the ellipsoid?
Definition: AMReX_EB2_IF_Polynomial.H:71
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition: AMReX_Vector.H:27
Definition: AMReX_FabArrayBase.H:32
AMREX_GPU_HOST_DEVICE Long size(T const &b) noexcept
integer version
Definition: AMReX_GpuRange.H:26
Array< Real, AMREX_SPACEDIM > RealArray
Definition: AMReX_Array.H:26
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
Raise a complex number to a (real) power.
Definition: AMReX_GpuComplex.H:418
const int[]
Definition: AMReX_BLProfiler.cpp:1664
Definition: AMReX_EB2_IF_Base.H:11
Definition: AMReX_Array.H:34