Sinusoid.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 /// \file
5 /// Defines MathFunctions::Sinusoid.
6 
7 #pragma once
8 
9 #include <pup.h>
10 
11 #include "Options/Options.hpp"
13 #include "PointwiseFunctions/MathFunctions/MathFunction.hpp" // IWYU pragma: keep
14 #include "Utilities/TMPL.hpp"
15 
16 /// \cond
17 class DataVector;
18 /// \endcond
19 
20 namespace MathFunctions {
21 
22 /*!
23  * \ingroup MathFunctionsGroup
24  * \brief Sinusoid \f$f = A \sin\left(k x + \delta \right)\f$.
25  *
26  * \details Input file options are: Amplitude, Phase, and Wavenumber
27  */
28 class Sinusoid : public MathFunction<1> {
29  public:
30  struct Amplitude {
31  using type = double;
32  static constexpr OptionString help = {"The amplitude."};
33  };
34 
35  struct Wavenumber {
36  using type = double;
37  static constexpr OptionString help = {"The wavenumber."};
38  };
39 
40  struct Phase {
41  using type = double;
42  static constexpr OptionString help = {"The phase shift."};
43  static type default_value() noexcept { return 0.; }
44  };
45  using options = tmpl::list<Amplitude, Wavenumber, Phase>;
46 
47  static constexpr OptionString help = {
48  "Applies a Sinusoid function to the input value"};
49 
50  Sinusoid(double amplitude, double wavenumber, double phase) noexcept;
51 
52  Sinusoid() = default;
53  ~Sinusoid() override = default;
54  Sinusoid(const Sinusoid& /*rhs*/) = delete;
55  Sinusoid& operator=(const Sinusoid& /*rhs*/) = delete;
56  Sinusoid(Sinusoid&& /*rhs*/) noexcept = default;
57  Sinusoid& operator=(Sinusoid&& /*rhs*/) noexcept = default;
58 
60 
61  explicit Sinusoid(CkMigrateMessage* /*unused*/) noexcept {}
62 
63  double operator()(const double& x) const noexcept override;
64  DataVector operator()(const DataVector& x) const noexcept override;
65 
66  double first_deriv(const double& x) const noexcept override;
67  DataVector first_deriv(const DataVector& x) const noexcept override;
68 
69  double second_deriv(const double& x) const noexcept override;
70  DataVector second_deriv(const DataVector& x) const noexcept override;
71 
72  double third_deriv(const double& x) const noexcept override;
73  DataVector third_deriv(const DataVector& x) const noexcept override;
74 
75  // clang-tidy: google-runtime-references
76  void pup(PUP::er& p) override; // NOLINT
77 
78  private:
79  friend bool operator==(const Sinusoid& lhs, const Sinusoid& rhs) noexcept;
80  template <typename T>
81  T apply_call_operator(const T& x) const noexcept;
82  template <typename T>
83  T apply_first_deriv(const T& x) const noexcept;
84  template <typename T>
85  T apply_second_deriv(const T& x) const noexcept;
86  template <typename T>
87  T apply_third_deriv(const T& x) const noexcept;
88 
89  double amplitude_{};
90  double wavenumber_{};
91  double phase_{};
92 };
93 
94 bool operator!=(const Sinusoid& lhs, const Sinusoid& rhs) noexcept;
95 
96 } // namespace MathFunctions
Definition: Sinusoid.hpp:35
double third_deriv(const double &x) const noexcept override
Returns the third derivative at &#39;x&#39;.
Definition: Sinusoid.cpp:38
double operator()(const double &x) const noexcept override
Returns the function value at the coordinate &#39;x&#39;.
Definition: Sinusoid.cpp:17
double second_deriv(const double &x) const noexcept override
Returns the second derivative at &#39;x&#39;.
Definition: Sinusoid.cpp:31
Definition: Sinusoid.hpp:40
Definition: MathFunction.hpp:27
Defines classes and functions for making classes creatable from input files.
Defines macros to allow serialization of abstract template base classes.
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
Sinusoid .
Definition: Sinusoid.hpp:28
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:26
Definition: Sinusoid.hpp:30
Holds classes implementing MathFunction (functions ).
Definition: Gaussian.cpp:11
Defines base-class MathFunction.
Stores a collection of function values.
Definition: DataVector.hpp:46
Wraps the template metaprogramming library used (brigand)
double first_deriv(const double &x) const noexcept override
Returns the first derivative at &#39;x&#39;.
Definition: Sinusoid.cpp:24