Gaussian.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::Gaussian.
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 Gaussian \f$f = A \exp\left(-\frac{(x-x_0)^2}{w^2}\right)\f$.
25  *
26  * \details Input file options are: Amplitude, Width, and Center
27  */
28 class Gaussian : public MathFunction<1> {
29  public:
30  struct Amplitude {
31  using type = double;
32  static constexpr OptionString help = {"The amplitude."};
33  };
34 
35  struct Width {
36  using type = double;
37  static constexpr OptionString help = {"The width."};
38  static type lower_bound() noexcept { return 0.; }
39  };
40 
41  struct Center {
42  using type = double;
43  static constexpr OptionString help = {"The center."};
44  };
45  using options = tmpl::list<Amplitude, Width, Center>;
46 
47  static constexpr OptionString help = {
48  "Applies a Gaussian function to the input value"};
49 
51 
52  explicit Gaussian(CkMigrateMessage* /*unused*/) noexcept {}
53 
54  Gaussian(double amplitude, double width, double center) noexcept;
55 
56  Gaussian() = default;
57  ~Gaussian() override = default;
58  Gaussian(const Gaussian& /*rhs*/) = delete;
59  Gaussian& operator=(const Gaussian& /*rhs*/) = delete;
60  Gaussian(Gaussian&& /*rhs*/) noexcept = default;
61  Gaussian& operator=(Gaussian&& /*rhs*/) noexcept = default;
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 Gaussian& lhs, const Gaussian& 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 inverse_width_{};
91  double center_{};
92 };
93 
94 bool operator!=(const Gaussian& lhs, const Gaussian& rhs) noexcept;
95 
96 } // namespace MathFunctions
double second_deriv(const double &x) const noexcept override
Returns the second derivative at &#39;x&#39;.
Definition: Gaussian.cpp:31
Gaussian .
Definition: Gaussian.hpp:28
Definition: Gaussian.hpp:41
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.
Definition: Gaussian.hpp:30
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:27
double third_deriv(const double &x) const noexcept override
Returns the third derivative at &#39;x&#39;.
Definition: Gaussian.cpp:38
Holds classes implementing MathFunction (functions ).
Definition: Gaussian.cpp:11
Defines base-class MathFunction.
double operator()(const double &x) const noexcept override
Returns the function value at the coordinate &#39;x&#39;.
Definition: Gaussian.cpp:17
Definition: Gaussian.hpp:35
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: Gaussian.cpp:24