GaussianPlusConstant.hpp
2 // See LICENSE.txt for details.
3
4 #pragma once
5
6 #include <array>
7 #include <cstddef>
8 #include <limits>
9 #include <memory>
10 #include <string>
11 #include <unordered_map>
12
14 #include "Evolution/Systems/GeneralizedHarmonic/ConstraintDamping/DampingFunction.hpp"
15 #include "Options/Options.hpp"
17 #include "Utilities/TMPL.hpp"
18
19 /// \cond
20 class DataVector;
21 namespace PUP {
22 class er;
23 } // namespace PUP
24 namespace domain::FunctionsOfTime {
25 class FunctionOfTime;
26 } // namespace domain::FunctionsOfTime
27 /// \endcond
28
30 /*!
31  * \brief A Gaussian plus a constant: \f$f = C + A 32 * \exp\left(-\frac{(x-x_0)^2}{w^2}\right)\f$
33  *
34  * \details Input file options are: Constant \f$C\f$, Amplitude \f$A\f$,
35  * Width \f$w\f$, and Center\f$x_0\f$. The function takes input coordinates
36  * of type tnsr::I<T, VolumeDim, Fr>, where T is e.g. double or
37  * DataVector, Fr is a frame (e.g. Frame::Inertial), and VolumeDim is
38  * the dimension of the spatial volume.
39  */
40 template <size_t VolumeDim, typename Fr>
41 class GaussianPlusConstant : public DampingFunction<VolumeDim, Fr> {
42  public:
43  struct Constant {
44  using type = double;
45  static constexpr Options::String help = {"The constant."};
46  };
47
48  struct Amplitude {
49  using type = double;
50  static constexpr Options::String help = {"The amplitude of the Gaussian."};
51  };
52
53  struct Width {
54  using type = double;
55  static constexpr Options::String help = {"The width of the Gaussian."};
56  static type lower_bound() noexcept { return 0.; }
57  };
58
59  struct Center {
61  static constexpr Options::String help = {"The center of the Gaussian."};
62  };
63  using options = tmpl::list<Constant, Amplitude, Width, Center>;
64
65  static constexpr Options::String help = {
66  "Computes a Gaussian plus a constant about an arbitrary coordinate "
67  "center with given width and amplitude"};
68
69  /// \cond
71  GaussianPlusConstant); // NOLINT
72
73  explicit GaussianPlusConstant(CkMigrateMessage* msg) noexcept;
74  /// \endcond
75
76  GaussianPlusConstant(double constant, double amplitude, double width,
77  const std::array<double, VolumeDim>& center) noexcept;
78
79  GaussianPlusConstant() = default;
80  ~GaussianPlusConstant() override = default;
81  GaussianPlusConstant(const GaussianPlusConstant& /*rhs*/) = default;
82  GaussianPlusConstant& operator=(const GaussianPlusConstant& /*rhs*/) =
83  default;
84  GaussianPlusConstant(GaussianPlusConstant&& /*rhs*/) noexcept = default;
85  GaussianPlusConstant& operator=(GaussianPlusConstant&& /*rhs*/) noexcept =
86  default;
87
88  void operator()(const gsl::not_null<Scalar<double>*> value_at_x,
89  const tnsr::I<double, VolumeDim, Fr>& x, double time,
90  const std::unordered_map<
91  std::string,
92  std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>&
93  functions_of_time) const noexcept override;
94  void operator()(const gsl::not_null<Scalar<DataVector>*> value_at_x,
95  const tnsr::I<DataVector, VolumeDim, Fr>& x, double time,
96  const std::unordered_map<
97  std::string,
98  std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>&
99  functions_of_time) const noexcept override;
100
101  auto get_clone() const noexcept
102  -> std::unique_ptr<DampingFunction<VolumeDim, Fr>> override;
103
105  void pup(PUP::er& p) override; // NOLINT
106
107  private:
108  friend bool operator==(const GaussianPlusConstant& lhs,
109  const GaussianPlusConstant& rhs) noexcept {
110  return lhs.constant_ == rhs.constant_ and
111  lhs.amplitude_ == rhs.amplitude_ and
112  lhs.inverse_width_ == rhs.inverse_width_ and
113  lhs.center_ == rhs.center_;
114  }
115
116  double constant_ = std::numeric_limits<double>::signaling_NaN();
117  double amplitude_ = std::numeric_limits<double>::signaling_NaN();
118  double inverse_width_ = std::numeric_limits<double>::signaling_NaN();
120
121  template <typename T>
122  void apply_call_operator(const gsl::not_null<Scalar<T>*> value_at_x,
123  const tnsr::I<T, VolumeDim, Fr>& x) const noexcept;
124 };
125
126 template <size_t VolumeDim, typename Fr>
127 bool operator!=(const GaussianPlusConstant<VolumeDim, Fr>& lhs,
128  const GaussianPlusConstant<VolumeDim, Fr>& rhs) noexcept {
129  return not(lhs == rhs);
130 }
131 } // namespace GeneralizedHarmonic::ConstraintDamping
132
133 /// \cond
134 template <size_t VolumeDim, typename Fr>
136  VolumeDim, Fr>::my_PUP_ID = 0; // NOLINT
137 /// \endcond
GeneralizedHarmonic::ConstraintDamping
Holds classes implementing DampingFunction (functions ).
Definition: DampingFunction.hpp:24
CharmPupable.hpp
GeneralizedHarmonic::ConstraintDamping::GaussianPlusConstant
A Gaussian plus a constant: .
Definition: GaussianPlusConstant.hpp:41
std::rel_ops::operator!=
T operator!=(T... args)
Options.hpp
domain::FunctionsOfTime
Contains functions of time to support the dual frame system.
Definition: FixedSpeedCubic.hpp:17
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:53
cstddef
GeneralizedHarmonic::ConstraintDamping::GaussianPlusConstant::Amplitude
Definition: GaussianPlusConstant.hpp:48
array
GeneralizedHarmonic::ConstraintDamping::GaussianPlusConstant::Constant
Definition: GaussianPlusConstant.hpp:43
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
std::numeric_limits::signaling_NaN
T signaling_NaN(T... args)
memory
GeneralizedHarmonic::ConstraintDamping::GaussianPlusConstant::Center
Definition: GaussianPlusConstant.hpp:59
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:39
unordered_map
gsl
Implementations from the Guideline Support Library.