TimeDependentTripleGaussian.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 #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 sum of three Gaussians plus a constant, where the Gaussian widths
32  * are scaled by a domain::FunctionsOfTime::FunctionOfTime.
33  *
34  * \details The function \f$f\f$ is given by
35  * \f{align}{
36  * f = C + \sum_{\alpha=1}^3
37  * A_\alpha \exp\left(-\frac{(x-(x_0)_\alpha)^2}{w_\alpha^2(t)}\right).
38  * \f}
39  * Input file options are: `Constant` \f$C\f$, `Amplitude[1-3]`
40  * \f$A_\alpha\f$, `Width[1-3]` \f$w_\alpha\f$, `Center[1-3]
41  * `\f$(x_0)_\alpha\f$, and `FunctionOfTimeForScaling`, a string naming a
42  * domain::FunctionsOfTime::FunctionOfTime in the domain::Tags::FunctionsOfTime
43  * that will be passed to the call operator. The function takes input
44  * coordinates \f$x\f$ of type `tnsr::I<T, 3, Frame::Grid>`, where `T` is e.g.
45  * `double` or `DataVector`; note that this DampingFunction is only defined
46  * for three spatial dimensions and for the grid frame. The Gaussian widths
47  * \f$w_\alpha\f$ are scaled by the inverse of the value of a scalar
48  * domain::FunctionsOfTime::FunctionOfTime \f$f(t)\f$ named
49  * `FunctionOfTimeForScaling`: \f$w_\alpha(t) = w_\alpha / f(t)\f$.
50  */
51 class TimeDependentTripleGaussian : public DampingFunction<3, Frame::Grid> {
52  public:
53  template <size_t GaussianNumber>
54  struct Gaussian {
55  static constexpr Options::String help = {
56  "Parameters for one of the Gaussians."};
57  static std::string name() noexcept {
58  return "Gaussian" + std::to_string(GaussianNumber);
59  };
60  };
61  struct Constant {
62  using type = double;
63  static constexpr Options::String help = {"The constant."};
64  };
65 
66  template <typename Group>
67  struct Amplitude {
68  using group = Group;
69  using type = double;
70  static constexpr Options::String help = {"The amplitude of the Gaussian."};
71  };
72 
73  template <typename Group>
74  struct Width {
75  using group = Group;
76  using type = double;
77  static constexpr Options::String help = {
78  "The unscaled width of the Gaussian."};
79  static type lower_bound() noexcept { return 0.; }
80  };
81 
82  template <typename Group>
83  struct Center {
84  using group = Group;
86  static constexpr Options::String help = {"The center of the Gaussian."};
87  };
88 
90  using type = std::string;
91  static constexpr Options::String help = {"The name of the FunctionOfTime."};
92  };
93 
94  using options =
95  tmpl::list<Constant, Amplitude<Gaussian<1>>, Width<Gaussian<1>>,
100 
101  static constexpr Options::String help = {
102  "Computes a sum of a constant and 3 Gaussians (each with its own "
103  "amplitude, width, and coordinate center), with the Gaussian widths "
104  "scaled by the inverse of a FunctionOfTime."};
105 
106  /// \cond
109  TimeDependentTripleGaussian); // NOLINT
110  /// \endcond
111 
112  explicit TimeDependentTripleGaussian(CkMigrateMessage* msg) noexcept;
113 
115  double constant, double amplitude_1, double width_1,
116  const std::array<double, 3>& center_1, double amplitude_2, double width_2,
117  const std::array<double, 3>& center_2, double amplitude_3, double width_3,
118  const std::array<double, 3>& center_3,
119  std::string function_of_time_for_scaling) noexcept;
120 
121  TimeDependentTripleGaussian() = default;
122  ~TimeDependentTripleGaussian() override = default;
124  default;
125  TimeDependentTripleGaussian& operator=(
126  const TimeDependentTripleGaussian& /*rhs*/) = default;
128  default;
129  TimeDependentTripleGaussian& operator=(
130  TimeDependentTripleGaussian&& /*rhs*/) noexcept = default;
131 
132  void operator()(const gsl::not_null<Scalar<double>*> value_at_x,
133  const tnsr::I<double, 3, Frame::Grid>& x, double time,
134  const std::unordered_map<
135  std::string,
136  std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>&
137  functions_of_time) const noexcept override;
138  void operator()(const gsl::not_null<Scalar<DataVector>*> value_at_x,
139  const tnsr::I<DataVector, 3, Frame::Grid>& x, double time,
140  const std::unordered_map<
141  std::string,
142  std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>&
143  functions_of_time) const noexcept override;
144 
145  auto get_clone() const noexcept
146  -> std::unique_ptr<DampingFunction<3, Frame::Grid>> override;
147 
148  // clang-tidy: google-runtime-references
149  void pup(PUP::er& p) override; // NOLINT
150 
151  private:
152  friend bool operator==(const TimeDependentTripleGaussian& lhs,
153  const TimeDependentTripleGaussian& rhs) noexcept {
154  return lhs.constant_ == rhs.constant_ and
155  lhs.amplitude_1_ == rhs.amplitude_1_ and
156  lhs.inverse_width_1_ == rhs.inverse_width_1_ and
157  lhs.center_1_ == rhs.center_1_ and
158  lhs.amplitude_2_ == rhs.amplitude_2_ and
159  lhs.inverse_width_2_ == rhs.inverse_width_2_ and
160  lhs.center_2_ == rhs.center_2_ and
161  lhs.amplitude_3_ == rhs.amplitude_3_ and
162  lhs.inverse_width_3_ == rhs.inverse_width_3_ and
163  lhs.center_3_ == rhs.center_3_ and
164  lhs.function_of_time_for_scaling_ ==
165  rhs.function_of_time_for_scaling_;
166  }
167 
168  double constant_ = std::numeric_limits<double>::signaling_NaN();
169  double amplitude_1_ = std::numeric_limits<double>::signaling_NaN();
170  double inverse_width_1_ = std::numeric_limits<double>::signaling_NaN();
171  std::array<double, 3> center_1_{};
172  double amplitude_2_ = std::numeric_limits<double>::signaling_NaN();
173  double inverse_width_2_ = std::numeric_limits<double>::signaling_NaN();
174  std::array<double, 3> center_2_{};
175  double amplitude_3_ = std::numeric_limits<double>::signaling_NaN();
176  double inverse_width_3_ = std::numeric_limits<double>::signaling_NaN();
177  std::array<double, 3> center_3_{};
178  std::string function_of_time_for_scaling_;
179 
180  template <typename T>
181  void apply_call_operator(
182  const gsl::not_null<Scalar<T>*> value_at_x,
183  const tnsr::I<T, 3, Frame::Grid>& x, double time,
184  const std::unordered_map<
185  std::string,
187  functions_of_time) const noexcept;
188 };
189 } // namespace GeneralizedHarmonic::ConstraintDamping
GeneralizedHarmonic::ConstraintDamping
Holds classes implementing DampingFunction (functions ).
Definition: DampingFunction.hpp:24
std::string
CharmPupable.hpp
GeneralizedHarmonic::ConstraintDamping::TimeDependentTripleGaussian::Width
Definition: TimeDependentTripleGaussian.hpp:74
Options.hpp
domain::FunctionsOfTime
Contains functions of time to support the dual frame system.
Definition: FunctionOfTime.hpp:17
GeneralizedHarmonic::ConstraintDamping::TimeDependentTripleGaussian::Gaussian
Definition: TimeDependentTripleGaussian.hpp:54
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::TimeDependentTripleGaussian::Constant
Definition: TimeDependentTripleGaussian.hpp:61
cstddef
array
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
GeneralizedHarmonic::ConstraintDamping::TimeDependentTripleGaussian::Amplitude
Definition: TimeDependentTripleGaussian.hpp:67
std::numeric_limits::signaling_NaN
T signaling_NaN(T... args)
memory
GeneralizedHarmonic::ConstraintDamping::TimeDependentTripleGaussian::Center
Definition: TimeDependentTripleGaussian.hpp:83
tnsr
Type aliases to construct common Tensors.
Definition: TypeAliases.hpp:31
GeneralizedHarmonic::ConstraintDamping::TimeDependentTripleGaussian
A sum of three Gaussians plus a constant, where the Gaussian widths are scaled by a domain::Functions...
Definition: TimeDependentTripleGaussian.hpp:51
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
Frame
Definition: IndexType.hpp:36
GeneralizedHarmonic::ConstraintDamping::TimeDependentTripleGaussian::FunctionOfTimeForScaling
Definition: TimeDependentTripleGaussian.hpp:89
std::unique_ptr
unordered_map
gsl
Implementations from the Guideline Support Library.
Definition: ReadSpecPiecewisePolynomial.hpp:11
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13
string