GaussianPlusConstant.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <cstddef>
8 #include <limits>
9 
11 #include "Evolution/Systems/GeneralizedHarmonic/ConstraintDamping/DampingFunction.hpp"
12 #include "Options/Options.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 /// \cond
17 class DataVector;
18 namespace PUP {
19 class er;
20 } // namespace PUP
21 /// \endcond
22 
24 /*!
25  * \brief A Gaussian plus a constant: \f$f = C + A
26  * \exp\left(-\frac{(x-x_0)^2}{w^2}\right)\f$
27  *
28  * \details Input file options are: `Constant` \f$C\f$, `Amplitude` \f$A\f$,
29  * `Width` \f$w\f$, and `Center`\f$x_0\f$. The function takes input coordinates
30  * of type `tnsr::I<T, VolumeDim, Fr>`, where `T` is e.g. `double` or
31  * `DataVector`, `Fr` is a frame (e.g. `Frame::Inertial`), and `VolumeDim` is
32  * the dimension of the spatial volume.
33  */
34 template <size_t VolumeDim, typename Fr>
35 class GaussianPlusConstant : public DampingFunction<VolumeDim, Fr> {
36  public:
37  struct Constant {
38  using type = double;
39  static constexpr Options::String help = {"The constant."};
40  };
41 
42  struct Amplitude {
43  using type = double;
44  static constexpr Options::String help = {"The amplitude of the Gaussian."};
45  };
46 
47  struct Width {
48  using type = double;
49  static constexpr Options::String help = {"The width of the Gaussian."};
50  static type lower_bound() noexcept { return 0.; }
51  };
52 
53  struct Center {
55  static constexpr Options::String help = {"The center of the Gaussian."};
56  };
57  using options = tmpl::list<Constant, Amplitude, Width, Center>;
58 
59  static constexpr Options::String help = {
60  "Computes a Gaussian plus a constant about an arbitrary coordinate "
61  "center with given width and amplitude"};
62 
63  /// \cond
65  GaussianPlusConstant); // NOLINT
66 
67  explicit GaussianPlusConstant(CkMigrateMessage* /*unused*/) noexcept {}
68  /// \endcond
69 
70  GaussianPlusConstant(double constant, double amplitude, double width,
71  const std::array<double, VolumeDim>& center) noexcept;
72 
73  GaussianPlusConstant() = default;
74  ~GaussianPlusConstant() override = default;
75  GaussianPlusConstant(const GaussianPlusConstant& /*rhs*/) = default;
76  GaussianPlusConstant& operator=(const GaussianPlusConstant& /*rhs*/) =
77  default;
78  GaussianPlusConstant(GaussianPlusConstant&& /*rhs*/) noexcept = default;
79  GaussianPlusConstant& operator=(GaussianPlusConstant&& /*rhs*/) noexcept =
80  default;
81 
82  Scalar<double> operator()(
83  const tnsr::I<double, VolumeDim, Fr>& x) const noexcept override;
84  Scalar<DataVector> operator()(
85  const tnsr::I<DataVector, VolumeDim, Fr>& x) const noexcept override;
86 
87  auto get_clone() const noexcept
88  -> std::unique_ptr<DampingFunction<VolumeDim, Fr>> override;
89 
90  // clang-tidy: google-runtime-references
91  void pup(PUP::er& p) override; // NOLINT
92 
93  private:
94  friend bool operator==(const GaussianPlusConstant& lhs,
95  const GaussianPlusConstant& rhs) noexcept {
96  return lhs.constant_ == rhs.constant_ and
97  lhs.amplitude_ == rhs.amplitude_ and
98  lhs.inverse_width_ == rhs.inverse_width_ and
99  lhs.center_ == rhs.center_;
100  }
101 
102  double constant_ = std::numeric_limits<double>::signaling_NaN();
103  double amplitude_ = std::numeric_limits<double>::signaling_NaN();
104  double inverse_width_ = std::numeric_limits<double>::signaling_NaN();
106 
107  template <typename T>
108  tnsr::I<T, VolumeDim, Fr> centered_coordinates(
109  const tnsr::I<T, VolumeDim, Fr>& x) const noexcept;
110  template <typename T>
111  Scalar<T> apply_call_operator(
112  const tnsr::I<T, VolumeDim, Fr>& centered_coords) const noexcept;
113 };
114 
115 template <size_t VolumeDim, typename Fr>
116 bool operator!=(const GaussianPlusConstant<VolumeDim, Fr>& lhs,
117  const GaussianPlusConstant<VolumeDim, Fr>& rhs) noexcept {
118  return not(lhs == rhs);
119 }
120 } // namespace GeneralizedHarmonic::ConstraintDamping
121 
122 /// \cond
123 template <size_t VolumeDim, typename Fr>
125  VolumeDim, Fr>::my_PUP_ID = 0; // NOLINT
126 /// \endcond
GeneralizedHarmonic::ConstraintDamping
Holds classes implementing DampingFunction (functions ).
Definition: DampingFunction.hpp:17
CharmPupable.hpp
GeneralizedHarmonic::ConstraintDamping::GaussianPlusConstant
A Gaussian plus a constant: .
Definition: GaussianPlusConstant.hpp:35
std::rel_ops::operator!=
T operator!=(T... args)
Options.hpp
WRAPPED_PUPable_decl_base_template
#define WRAPPED_PUPable_decl_base_template(baseClassName, className)
Mark derived template classes as serializable.
Definition: CharmPupable.hpp:32
GeneralizedHarmonic::ConstraintDamping::GaussianPlusConstant::Width
Definition: GaussianPlusConstant.hpp:47
cstddef
GeneralizedHarmonic::ConstraintDamping::GaussianPlusConstant::Amplitude
Definition: GaussianPlusConstant.hpp:42
array
GeneralizedHarmonic::ConstraintDamping::GaussianPlusConstant::Constant
Definition: GaussianPlusConstant.hpp:37
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:42
std::numeric_limits::signaling_NaN
T signaling_NaN(T... args)
GeneralizedHarmonic::ConstraintDamping::GaussianPlusConstant::Center
Definition: GaussianPlusConstant.hpp:53
tnsr
Type aliases to construct common Tensors.
Definition: TypeAliases.hpp:31
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
limits
TypeAliases.hpp
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
GeneralizedHarmonic::ConstraintDamping::DampingFunction
Base class defining interface for constraint damping functions.
Definition: DampingFunction.hpp:31
TMPL.hpp