ScalarWaveGr.hpp
2 // See LICENSE.txt for details.
3
4 #pragma once
5
6 #include <cstddef>
7 #include <string>
8 #include <utility>
9
13 #include "Options/Options.hpp"
14 #include "PointwiseFunctions/AnalyticData/AnalyticData.hpp"
15
16 /// \cond
17 namespace PUP {
18 class er; // IWYU pragma: keep
19 } // namespace PUP
20 /// \endcond
21
22 // IWYU pragma: no_include <pup.h>
23
24 namespace CurvedScalarWave {
25 namespace AnalyticData {
26 /*!
27  * \brief Analytic initial data for scalar waves in curved spacetime
28  *
29  * \details When evolving a scalar field propagating through curved spacetime,
30  * this class provides a method to initialize the scalar-field and spacetime
31  * variables using analytic solution(s) of the flat-space scalar-wave equation
32  * and of the Einstein equations. Note that the coordinate profile of the scalar
33  * field \f$\Psi\f$ in curved spacetime being the same as \f$\Psi\f$ in flat
34  * spacetime is our primary identification, allowing it to be initialized using
35  * any member class of ScalarWave::Solutions. We initialize \f$\Phi_i\f$ in
36  * curved spacetime to the coordinate spatial derivative of \f$\Psi\f$ in flat
37  * spacetime. The definition of \f$\Pi\f$ comes from requiring it to be the
38  * future-directed time derivative of the scalar field in curved spacetime:
39  *
40  * \f{align}
41  * \Pi :=& -n^a \partial_a \Psi \\
42  * =& \frac{1}{\alpha}\left(\beta^k \Phi_k - {\partial_t\Psi}\right),\\
43  * =& \frac{1}{\alpha}\left(\beta^k \Phi_k + {\Pi}_{\mathrm{flat}}\right),
44  * \f}
45  *
46  * where \f$n^a\f$ is the unit normal to spatial slices of the spacetime
47  * foliation, and \f${\Pi}_{\mathrm{flat}}\f$ comes from the flat spacetime
48  * solution.
49  */
50 template <typename ScalarFieldData, typename BackgroundGrData>
51 class ScalarWaveGr : public MarkAsAnalyticData {
52  static_assert(
53  ScalarFieldData::volume_dim == BackgroundGrData::volume_dim,
54  "Scalar field data and background spacetime data should have the same "
55  "spatial dimensionality. Currently provided template arguments do not.");
56
57  public:
58  static constexpr size_t volume_dim = ScalarFieldData::volume_dim;
59
60  struct ScalarField {
61  using type = ScalarFieldData;
62  static constexpr Options::String help = {"Flat space scalar field."};
63  };
64  struct Background {
65  using type = BackgroundGrData;
66  static constexpr Options::String help = {"Background spacetime."};
67  };
68
69  using options = tmpl::list<Background, ScalarField>;
70  static constexpr Options::String help{
71  "A scalar field in curved background spacetime\n\n"};
72  static std::string name() noexcept { return "ScalarWaveGr"; };
73
74  // Construct from options
75  ScalarWaveGr(BackgroundGrData background,
76  ScalarFieldData scalar_field) noexcept
77  : flat_space_scalar_wave_data_(std::move(scalar_field)),
78  background_gr_data_(std::move(background)) {}
79
80  explicit ScalarWaveGr(CkMigrateMessage* /*unused*/) noexcept {}
81
82  ScalarWaveGr() = default;
83  ScalarWaveGr(const ScalarWaveGr& /*rhs*/) = delete;
84  ScalarWaveGr& operator=(const ScalarWaveGr& /*rhs*/) = delete;
85  ScalarWaveGr(ScalarWaveGr&& /*rhs*/) noexcept = default;
86  ScalarWaveGr& operator=(ScalarWaveGr&& /*rhs*/) noexcept = default;
87  ~ScalarWaveGr() = default;
88
89  // Tags
90  template <typename DataType>
91  using spacetime_tags = typename BackgroundGrData::template tags<DataType>;
92  using tags = tmpl::append<spacetime_tags<DataVector>,
93  tmpl::list<Pi, Phi<volume_dim>, Psi>>;
94
95  /// Retrieve spacetime variables
96  template <
97  typename DataType, typename Tag,
98  Requires<tmpl::list_contains_v<spacetime_tags<DataType>, Tag>> = nullptr>
99  tuples::TaggedTuple<Tag> variables(const tnsr::I<DataType, volume_dim>& x,
100  tmpl::list<Tag> /*meta*/) const noexcept {
101  constexpr double default_initial_time = 0.;
102  return {std::move(get<Tag>(background_gr_data_.variables(
103  x, default_initial_time, spacetime_tags<DataType>{})))};
104  }
105
106  /// Retrieve scalar wave variables
107  tuples::TaggedTuple<Pi> variables(const tnsr::I<DataVector, volume_dim>& x,
108  tmpl::list<Pi> /*meta*/) const noexcept;
109
111  const tnsr::I<DataVector, volume_dim>& x,
112  tmpl::list<Phi<volume_dim>> /*meta*/) const noexcept {
113  constexpr double default_initial_time = 0.;
114  return {std::move(
115  get<ScalarWave::Phi<volume_dim>>(flat_space_scalar_wave_data_.variables(
116  x, default_initial_time,
118  ScalarWave::Psi>{})))};
119  }
120  tuples::TaggedTuple<Psi> variables(const tnsr::I<DataVector, volume_dim>& x,
121  tmpl::list<Psi> /*meta*/) const noexcept {
122  constexpr double default_initial_time = 0.;
123  return {
124  std::move(get<ScalarWave::Psi>(flat_space_scalar_wave_data_.variables(
125  x, default_initial_time,
127  ScalarWave::Psi>{})))};
128  }
129
130  // Retrieve one or more tags
131  template <typename DataType, typename... Tags>
132  tuples::TaggedTuple<Tags...> variables(const tnsr::I<DataType, volume_dim>& x,
133  tmpl::list<Tags...> /*meta*/) const
134  noexcept {
135  static_assert(sizeof...(Tags) > 1,
136  "This generic template will recurse infinitely if only one "
137  "tag is being retrieved through it.");
138
139  static_assert(tmpl2::flat_all_v<tmpl::list_contains_v<tags, Tags>...>,
140  "At least one of the requested tags is not supported.");
141
142  return {tuples::get<Tags>(variables(x, tmpl::list<Tags>{}))...};
143  }
144
145  // clang-tidy: no runtime references
146  void pup(PUP::er& p) noexcept; // NOLINT
147
148  private:
149  template <typename LocalScalarFieldData, // NOLINT
150  typename LocalBackgroundData> // NOLINT
151  friend bool // NOLINT
152  operator==(const ScalarWaveGr<LocalScalarFieldData, // NOLINT
153  LocalBackgroundData>& lhs, // NOLINT
154  const ScalarWaveGr<LocalScalarFieldData, // NOLINT
155  LocalBackgroundData>& rhs) // NOLINT
156  noexcept; // NOLINT
157
158  ScalarFieldData flat_space_scalar_wave_data_;
159  BackgroundGrData background_gr_data_;
160 };
161
162 template <typename ScalarFieldData, typename BackgroundData>
163 bool operator!=(
164  const ScalarWaveGr<ScalarFieldData, BackgroundData>& lhs,
165  const ScalarWaveGr<ScalarFieldData, BackgroundData>& rhs) noexcept;
166
167 } // namespace AnalyticData
168 } // namespace CurvedScalarWave
CurvedScalarWave::AnalyticData::ScalarWaveGr::variables
tuples::TaggedTuple< Tag > variables(const tnsr::I< DataType, volume_dim > &x, tmpl::list< Tag >) const noexcept
Retrieve spacetime variables.
Definition: ScalarWaveGr.hpp:99
std::string
utility
std::rel_ops::operator!=
T operator!=(T... args)
Options.hpp
ScalarWave::Phi
Definition: Tags.hpp:31
Tags.hpp
Tags.hpp
CurvedScalarWave::AnalyticData::ScalarWaveGr
Analytic initial data for scalar waves in curved spacetime.
Definition: ScalarWaveGr.hpp:51
tmpl2::flat_all_v
constexpr bool flat_all_v
A non-short-circuiting logical AND between bools 'B"".
Definition: TMPL.hpp:545
db::get
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:791
CurvedScalarWave::Phi
Definition: Tags.hpp:32
cstddef
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
CurvedScalarWave::AnalyticData::ScalarWaveGr::Background
Definition: ScalarWaveGr.hpp:64
AnalyticData
Provides analytic tensor data as a function of the spatial coordinates.
Definition: AnalyticData.hpp:34
tnsr
Type aliases to construct common Tensors.
Definition: TypeAliases.hpp:31
TypeAliases.hpp
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
ScalarWave::Psi
Definition: Tags.hpp:20
Requires
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t
Definition: Requires.hpp:67
CurvedScalarWave::AnalyticData::ScalarWaveGr::ScalarField
Definition: ScalarWaveGr.hpp:60
ScalarWave::Pi
Definition: Tags.hpp:25
CurvedScalarWave
Items related to evolving a scalar wave on a curved background.
Definition: Characteristics.hpp:18
string