YlmTestFunctions.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <cmath>
8 #include <cstddef>
9 #include <vector>
10 
11 #include "ApparentHorizons/YlmSpherepack.hpp"
12 #include "DataStructures/DataVector.hpp"
13 #include "Utilities/Gsl.hpp"
14 
15 namespace YlmTestFunctions {
16 
17 using SecondDeriv = YlmSpherepack::SecondDeriv;
18 
20  public:
21  virtual ~ScalarFunctionWithDerivs() = default;
22  ScalarFunctionWithDerivs() = default;
26  default;
27  ScalarFunctionWithDerivs& operator=(ScalarFunctionWithDerivs&&) noexcept =
28  default;
29  virtual void func(gsl::not_null<DataVector*> u, size_t stride, size_t offset,
30  const std::vector<double>& thetas,
31  const std::vector<double>& phis) const noexcept = 0;
32  virtual void dfunc(gsl::not_null<std::array<double*, 2>*> du, size_t stride,
33  size_t offset, const std::vector<double>& thetas,
34  const std::vector<double>& phis) const noexcept = 0;
35  virtual void ddfunc(gsl::not_null<SecondDeriv*> ddu, size_t stride,
36  size_t offset, const std::vector<double>& thetas,
37  const std::vector<double>& phis) const noexcept = 0;
38  virtual void scalar_laplacian(gsl::not_null<DataVector*> slap, size_t stride,
39  size_t offset,
40  const std::vector<double>& thetas,
41  const std::vector<double>& phis) const
42  noexcept = 0;
43  virtual double integral() const noexcept = 0;
44 };
45 
46 class Y00 : public ScalarFunctionWithDerivs {
47  public:
48  ~Y00() override = default;
49  Y00() = default;
50  Y00(const Y00&) = default;
51  Y00(Y00&&) noexcept = default;
52  Y00& operator=(const Y00&) = default;
53  Y00& operator=(Y00&&) noexcept = default;
54  void func(gsl::not_null<DataVector*> u, size_t stride, size_t offset,
55  const std::vector<double>& thetas,
56  const std::vector<double>& phis) const noexcept override;
57  void dfunc(gsl::not_null<std::array<double*, 2>*> du, size_t stride,
58  size_t offset, const std::vector<double>& thetas,
59  const std::vector<double>& phis) const noexcept override;
60  void ddfunc(gsl::not_null<SecondDeriv*> ddu, size_t stride, size_t offset,
61  const std::vector<double>& thetas,
62  const std::vector<double>& phis) const noexcept override;
63  void scalar_laplacian(gsl::not_null<DataVector*> slap, size_t stride,
64  size_t offset, const std::vector<double>& thetas,
65  const std::vector<double>& phis) const
66  noexcept override;
67  double integral() const noexcept override { return sqrt(4.0 * M_PI); }
68 };
69 
70 class Y10 : public ScalarFunctionWithDerivs {
71  public:
72  ~Y10() override = default;
73  Y10() = default;
74  Y10(const Y10&) = default;
75  Y10(Y10&&) noexcept = default;
76  Y10& operator=(const Y10&) = default;
77  Y10& operator=(Y10&&) noexcept = default;
78  void func(gsl::not_null<DataVector*> u, size_t stride, size_t offset,
79  const std::vector<double>& thetas,
80  const std::vector<double>& phis) const noexcept override;
81  void dfunc(gsl::not_null<std::array<double*, 2>*> du, size_t stride,
82  size_t offset, const std::vector<double>& thetas,
83  const std::vector<double>& phis) const noexcept override;
84  void ddfunc(gsl::not_null<SecondDeriv*> ddu, size_t stride, size_t offset,
85  const std::vector<double>& thetas,
86  const std::vector<double>& phis) const noexcept override;
87  void scalar_laplacian(gsl::not_null<DataVector*> slap, size_t stride,
88  size_t offset, const std::vector<double>& thetas,
89  const std::vector<double>& phis) const
90  noexcept override;
91  double integral() const noexcept override { return 0.0; }
92 };
93 
94 // Im(Y11(theta,phi))
95 class Y11 : public ScalarFunctionWithDerivs {
96  public:
97  ~Y11() override = default;
98  Y11() = default;
99  Y11(const Y11&) = default;
100  Y11(Y11&&) noexcept = default;
101  Y11& operator=(const Y11&) = default;
102  Y11& operator=(Y11&&) noexcept = default;
103  void func(gsl::not_null<DataVector*> u, size_t stride, size_t offset,
104  const std::vector<double>& thetas,
105  const std::vector<double>& phis) const noexcept override;
106  void dfunc(gsl::not_null<std::array<double*, 2>*> du, size_t stride,
107  size_t offset, const std::vector<double>& thetas,
108  const std::vector<double>& phis) const noexcept override;
109  void ddfunc(gsl::not_null<SecondDeriv*> ddu, size_t stride, size_t offset,
110  const std::vector<double>& thetas,
111  const std::vector<double>& phis) const noexcept override;
112  void scalar_laplacian(gsl::not_null<DataVector*> slap, size_t stride,
113  size_t offset, const std::vector<double>& thetas,
114  const std::vector<double>& phis) const
115  noexcept override;
116  double integral() const noexcept override { return 0.0; }
117 };
118 
120  public:
121  virtual ~SimpleScalarFunction() = default;
122  SimpleScalarFunction() = default;
123  SimpleScalarFunction(const SimpleScalarFunction&) = default;
124  SimpleScalarFunction(SimpleScalarFunction&&) noexcept = default;
125  SimpleScalarFunction& operator=(const SimpleScalarFunction&) = default;
126  SimpleScalarFunction& operator=(SimpleScalarFunction&&) noexcept = default;
127  virtual DataVector func(const std::vector<double>& thetas,
128  const std::vector<double>& phis) const noexcept = 0;
129 };
130 
131 // Re Y(10,10) + Im Y(10,7) + Re Y(6,2)
132 class FuncA : public SimpleScalarFunction {
133  public:
134  ~FuncA() override = default;
135  FuncA() = default;
136  FuncA(const FuncA&) = default;
137  FuncA(FuncA&&) noexcept = default;
138  FuncA& operator=(const FuncA&) = default;
139  FuncA& operator=(FuncA&&) noexcept = default;
140  DataVector func(const std::vector<double>& thetas,
141  const std::vector<double>& phis) const noexcept override;
142 };
143 
144 // Im Y(10,7)+ Re Y(6,2)
145 class FuncB : public SimpleScalarFunction {
146  public:
147  ~FuncB() override = default;
148  FuncB() = default;
149  FuncB(const FuncB&) = default;
150  FuncB(FuncB&&) noexcept = default;
151  FuncB& operator=(const FuncB&) = default;
152  FuncB& operator=(FuncB&&) noexcept = default;
153  DataVector func(const std::vector<double>& thetas,
154  const std::vector<double>& phis) const noexcept override;
155 };
156 
157 // Re Y(6,2)
158 class FuncC : public SimpleScalarFunction {
159  public:
160  ~FuncC() override = default;
161  FuncC() = default;
162  FuncC(const FuncC&) = default;
163  FuncC(FuncC&&) noexcept = default;
164  FuncC& operator=(const FuncC&) = default;
165  FuncC& operator=(FuncC&&) noexcept = default;
166  DataVector func(const std::vector<double>& thetas,
167  const std::vector<double>& phis) const noexcept override;
168 };
169 
170 } // namespace YlmTestFunctions
YlmTestFunctions::SimpleScalarFunction
Definition: YlmTestFunctions.hpp:119
YlmTestFunctions::FuncA
Definition: YlmTestFunctions.hpp:132
vector
YlmTestFunctions::Y10
Definition: YlmTestFunctions.hpp:70
YlmTestFunctions::ScalarFunctionWithDerivs
Definition: YlmTestFunctions.hpp:19
cmath
YlmTestFunctions::FuncB
Definition: YlmTestFunctions.hpp:145
YlmSpherepack::SecondDeriv
tnsr::ij< DataVector, 2, Frame::Logical > SecondDeriv
Type returned by second derivative function.
Definition: YlmSpherepack.hpp:26
YlmTestFunctions::FuncC
Definition: YlmTestFunctions.hpp:158
cstddef
array
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:42
Gsl.hpp
YlmTestFunctions::Y00
Definition: YlmTestFunctions.hpp:46
YlmTestFunctions::Y11
Definition: YlmTestFunctions.hpp:95
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183