InitializeDampedHarmonic.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 <tuple>
9 #include <utility>
10 
13 #include "DataStructures/VariablesTag.hpp"
15 #include "Domain/CoordinateMaps/Tags.hpp"
16 #include "Domain/ElementMap.hpp"
17 #include "Domain/FunctionsOfTime/FunctionOfTime.hpp"
18 #include "Domain/FunctionsOfTime/Tags.hpp"
19 #include "Domain/Tags.hpp"
20 #include "Domain/TagsTimeDependent.hpp"
21 #include "Evolution/Initialization/Tags.hpp"
22 #include "Evolution/Systems/GeneralizedHarmonic/GaugeSourceFunctions/DampedHarmonic.hpp"
23 #include "Evolution/Systems/GeneralizedHarmonic/GaugeSourceFunctions/DhGaugeParameters.hpp"
24 #include "Evolution/Systems/GeneralizedHarmonic/GaugeSourceFunctions/Tags/DhGaugeParameters.hpp"
25 #include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp"
27 #include "Options/Options.hpp"
28 #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
29 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
30 #include "Time/Tags.hpp"
33 #include "Utilities/TMPL.hpp"
34 
35 namespace GeneralizedHarmonic::gauges::Actions {
36 /*!
37  * \brief Initialize the damped harmonic gauge, either with or without a rollon
38  * function.
39  *
40  * See `GeneralizedHarmonic::gauges::damped_harmonic()` for details on the
41  * condition.
42  *
43  * When the non-rollon gauge is initialized, Eq. 9 and 10 of
44  * \cite Lindblom2005qh are used to compute the time derivatives for the lapse
45  * and shift to compute the new \f$\Pi_{ab}\f$.
46  *
47  * \warning The rollon gauge does not support moving meshes.
48  *
49  * When the rollon gauge is used:
50  *
51  * DataBox:
52  * - Uses:
53  * - `domain::Tags::Domain<Dim, Frame::Inertial>`
54  * - `domain::CoordinateMaps::Tags::CoordinateMap<Dim,
55  * Frame::Grid, Frame::Inertial>`
56  * - `domain::Tags::InverseJacobian<Dim, Frame::Logical, Frame::Inertial>`
57  * - `domain::Tags::Mesh<Dim>`
58  * - `gr::Tags::SpacetimeMetric<Dim, Frame::Inertial>`
59  * - `GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>`
60  * - `GeneralizedHarmonic::Tags::Phi<Dim, Frame::Inertial>`
61  * - Adds:
62  * - `GeneralizedHarmonic::Tags::InitialGaugeH<Dim, Frame::Inertial>`
63  * - `GeneralizedHarmonic::Tags::SpacetimeDerivInitialGaugeH<Dim,
64  * Frame::Inertial>`
65  * - `GeneralizedHarmonic::Tags::GaugeH<Dim, Frame::Inertial>`
66  * - `GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame::Inertial>`
67  * - Removes: nothing
68  * - Modifies: nothing
69  *
70  * When the non-rollon gauge is used:
71  *
72  * DataBox:
73  * - Uses:
74  * - `Initialization::Tags::InitialTime`
75  * - `domain::Tags::ElementMap<Dim, Frame::Grid>`
76  * - `domain::CoordinateMaps::Tags::CoordinateMap<Dim,
77  * Frame::Grid, Frame::Inertial>`
78  * - `domain::Tags::Coordinates<Dim, Frame::Logical>`
79  * - `domain::Tags::FunctionsOfTime`
80  * - `gr::Tags::SpacetimeMetric<Dim, Frame::Inertial>`
81  * - `GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>`
82  * - `GeneralizedHarmonic::Tags::Phi<Dim, Frame::Inertial>`
83  * - Adds:
84  * - `GeneralizedHarmonic::Tags::GaugeH<Dim, Frame::Inertial>`
85  * - `GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame::Inertial>`
86  * - Removes: nothing
87  * - Modifies:
88  * - `GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>`
89  *
90  * \note This action relies on the `SetupDataBox` aggregated initialization
91  * mechanism, so `Actions::SetupDataBox` must be present in the `Initialization`
92  * phase action list prior to this action.
93  */
94 template <size_t Dim, bool UseRollon>
96  private:
97  template <typename Frame>
98  struct DampedHarmonicRollonCompute
100  ::Tags::Variables<tmpl::list<
101  ::GeneralizedHarmonic::Tags::GaugeH<Dim, Frame>,
102  ::GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame>>> {
103  using base = ::Tags::Variables<tmpl::list<
106  static std::string name() noexcept { return "DampedHarmonicRollonCompute"; }
107  using argument_tags = tmpl::list<
120  using return_type = Variables<tmpl::list<
123 
124  static void function(
125  gsl::not_null<return_type*> h_and_d4_h,
126  const tnsr::a<DataVector, Dim, Frame>& gauge_h_init,
127  const tnsr::ab<DataVector, Dim, Frame>& dgauge_h_init,
128  const Scalar<DataVector>& lapse,
129  const tnsr::I<DataVector, Dim, Frame>& shift,
130  const tnsr::a<DataVector, Dim, Frame>& spacetime_unit_normal_one_form,
131  const Scalar<DataVector>& sqrt_det_spatial_metric,
132  const tnsr::II<DataVector, Dim, Frame>& inverse_spatial_metric,
133  const tnsr::aa<DataVector, Dim, Frame>& spacetime_metric,
134  const tnsr::aa<DataVector, Dim, Frame>& pi,
135  const tnsr::iaa<DataVector, Dim, Frame>& phi, double time,
136  const tnsr::I<DataVector, Dim, Frame>& coords,
138  parameters) noexcept;
139  };
140 
141  template <typename Frame>
142  struct DampedHarmonicCompute
143  : db::ComputeTag,
144  ::Tags::Variables<tmpl::list<
145  ::GeneralizedHarmonic::Tags::GaugeH<Dim, Frame>,
146  ::GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame>>> {
147  using base = ::Tags::Variables<tmpl::list<
150  static std::string name() noexcept { return "DampedHarmonicCompute"; }
151  using argument_tags = tmpl::list<
162  using return_type = Variables<tmpl::list<
165 
166  static void function(
168  const tnsr::I<DataVector, Dim, Frame>& shift,
169  const tnsr::a<DataVector, Dim, Frame>& spacetime_unit_normal_one_form,
170  const Scalar<DataVector>& sqrt_det_spatial_metric,
171  const tnsr::II<DataVector, Dim, Frame>& inverse_spatial_metric,
172  const tnsr::aa<DataVector, Dim, Frame>& spacetime_metric,
173  const tnsr::aa<DataVector, Dim, Frame>& pi,
174  const tnsr::iaa<DataVector, Dim, Frame>& phi,
175  const tnsr::I<DataVector, Dim, Frame>& coords,
177  parameters) noexcept;
178  };
179 
180  public:
181  using frame = Frame::Inertial;
182 
183  using const_global_cache_tags = tmpl::list<
185 
186  using simple_tags = tmpl::conditional_t<
187  UseRollon,
188  tmpl::list<
191  tmpl::list<>>;
192 
193  using compute_tags =
194  tmpl::conditional_t<UseRollon, DampedHarmonicRollonCompute<frame>,
195  DampedHarmonicCompute<frame>>;
196 
197  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
198  typename ArrayIndex, typename ActionList,
199  typename ParallelComponent>
200  static auto apply(db::DataBox<DbTagsList>& box,
201  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
202  const Parallel::GlobalCache<Metavariables>& /*cache*/,
203  const ArrayIndex& /*array_index*/,
204  const ActionList /*meta*/,
205  const ParallelComponent* const /*meta*/) noexcept {
206  if constexpr (UseRollon) {
208  Metavariables::volume_dim, Frame::Grid, Frame::Inertial>>(box)
209  .is_identity()) {
210  ERROR(
211  "Cannot use the damped harmonic rollon gauge with a moving mesh "
212  "because the rollon is not implemented for a moving mesh. The "
213  "issue is that the initial H_a needs to be in the grid frame, and "
214  "then transformed to the inertial frame at each time step. "
215  "Transforming the spacetime derivative requires spacetime "
216  "Hessians, which are not implemented for the maps and there is "
217  "currently no plan to add them because we do not need them for "
218  "anything else.");
219  }
220  const auto& inverse_jacobian =
221  db::get<domain::Tags::InverseJacobian<Dim, Frame::Logical, frame>>(
222  box);
223 
224  auto [initial_gauge_h, initial_d4_gauge_h] = impl_rollon(
226  box),
229  db::get<domain::Tags::Mesh<Dim>>(box), inverse_jacobian);
230 
231  // Finally, update gauge related quantities in the box
232  Initialization::mutate_assign<simple_tags>(make_not_null(&box),
233  std::move(initial_gauge_h),
234  std::move(initial_d4_gauge_h));
235  return std::make_tuple(std::move(box));
236  } else {
237  const double initial_time =
238  db::get<::Initialization::Tags::InitialTime>(box);
239  const auto inertial_coords =
241  Metavariables::volume_dim, Frame::Grid, Frame::Inertial>>(box)(
242  db::get<::domain::Tags::ElementMap<Metavariables::volume_dim,
243  Frame::Grid>>(box)(
244  db::get<domain::Tags::Coordinates<Dim, Frame::Logical>>(box)),
245  initial_time, db::get<::domain::Tags::FunctionsOfTime>(box));
246 
247  db::mutate<GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>>(
248  make_not_null(&box), &new_pi_from_gauge_h,
249  db::get<gr::Tags::SpacetimeMetric<Dim, Frame::Inertial, DataVector>>(
250  box),
252  inertial_coords,
253  db::get<
255  box));
256 
257  // Add gauge tags
258  return std::make_tuple(std::move(box));
259  }
260  }
261 
262  private:
264  tnsr::ab<DataVector, Dim, Frame::Inertial>>
265  impl_rollon(
266  const tnsr::aa<DataVector, Dim, Frame::Inertial>& spacetime_metric,
267  const tnsr::aa<DataVector, Dim, Frame::Inertial>& pi,
268  const tnsr::iaa<DataVector, Dim, Frame::Inertial>& phi,
269  const Mesh<Dim>& mesh,
270  const InverseJacobian<DataVector, Dim, Frame::Logical, Frame::Inertial>&
271  inverse_jacobian) noexcept;
272 
273  static void new_pi_from_gauge_h(
274  gsl::not_null<tnsr::aa<DataVector, Dim, Frame::Inertial>*> pi,
275  const tnsr::aa<DataVector, Dim, Frame::Inertial>& spacetime_metric,
276  const tnsr::iaa<DataVector, Dim, Frame::Inertial>& phi,
277  const tnsr::I<DataVector, Dim, Frame::Inertial>& coords,
279  parameters) noexcept;
280 };
281 } // namespace GeneralizedHarmonic::gauges::Actions
GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH
Spacetime derivatives of the gauge source function for the generalized harmonic system.
Definition: Tags.hpp:67
db::ComputeTag
Mark a struct as a compute tag by inheriting from this.
Definition: Tag.hpp:157
GeneralizedHarmonic::pi
void pi(gsl::not_null< tnsr::aa< DataType, SpatialDim, Frame > * > pi, const Scalar< DataType > &lapse, const Scalar< DataType > &dt_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::I< DataType, SpatialDim, Frame > &dt_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const tnsr::ii< DataType, SpatialDim, Frame > &dt_spatial_metric, const tnsr::iaa< DataType, SpatialDim, Frame > &phi) noexcept
Computes the conjugate momentum of the spacetime metric .
std::string
utility
Frame::Inertial
Definition: IndexType.hpp:44
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
domain::Tags::Coordinates
Definition: Tags.hpp:130
Frame::Grid
Definition: IndexType.hpp:43
Options.hpp
Tags.hpp
Error.hpp
Tags::Variables
Definition: VariablesTag.hpp:21
domain::Tags::Mesh
The computational grid of the Element in the DataBox.
Definition: Tags.hpp:107
tuple
GeneralizedHarmonic::gauges::DhGaugeParameters
A struct holding the parameters for initializing damped harmonic gauge.
Definition: DhGaugeParameters.hpp:26
db::get
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:786
GeneralizedHarmonic::gauges::Actions::InitializeDampedHarmonic
Initialize the damped harmonic gauge, either with or without a rollon function.
Definition: InitializeDampedHarmonic.hpp:95
CoordinateMap.hpp
gr::lapse
Scalar< DataType > lapse(const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::aa< DataType, SpatialDim, Frame > &spacetime_metric) noexcept
Compute lapse from shift and spacetime metric.
ERROR
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:37
DataBox.hpp
cstddef
MakeWithValue.hpp
array
GeneralizedHarmonic::Tags::Pi
Conjugate momentum to the spacetime metric.
Definition: Tags.hpp:29
gr::Tags::SpacetimeMetric
Definition: Tags.hpp:17
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
Tags::Time
Tag for the current time as a double.
Definition: Tags.hpp:73
GeneralizedHarmonic::phi
void phi(gsl::not_null< tnsr::iaa< DataType, SpatialDim, Frame > * > phi, const Scalar< DataType > &lapse, const tnsr::i< DataType, SpatialDim, Frame > &deriv_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::iJ< DataType, SpatialDim, Frame > &deriv_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const tnsr::ijj< DataType, SpatialDim, Frame > &deriv_spatial_metric) noexcept
Computes the auxiliary variable used by the generalized harmonic formulation of Einstein's equations...
GeneralizedHarmonic::Tags::GaugeH
Gauge source function for the generalized harmonic system.
Definition: Tags.hpp:53
gr::Tags::Shift
Definition: Tags.hpp:48
domain::CoordinateMaps::Tags::CoordinateMap
Definition: Tags.hpp:30
gr::Tags::SpacetimeNormalOneForm
Definition: Tags.hpp:83
Mesh
Holds the number of grid points, basis, and quadrature in each direction of the computational grid.
Definition: Mesh.hpp:48
gr::shift
tnsr::I< DataType, SpatialDim, Frame > shift(const tnsr::aa< DataType, SpatialDim, Frame > &spacetime_metric, const tnsr::II< DataType, SpatialDim, Frame > &inverse_spatial_metric) noexcept
Compute shift from spacetime metric and inverse spatial metric.
GeneralizedHarmonic::Tags::Phi
Auxiliary variable which is analytically the spatial derivative of the spacetime metric.
Definition: Tags.hpp:40
GeneralizedHarmonic::gauges::Tags::DhGaugeParameters
Input option tags for the generalized harmonic evolution system.
Definition: DhGaugeParameters.hpp:31
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
gr::spacetime_metric
void spacetime_metric(gsl::not_null< tnsr::aa< DataType, Dim, Frame > * > spacetime_metric, const Scalar< DataType > &lapse, const tnsr::I< DataType, Dim, Frame > &shift, const tnsr::ii< DataType, Dim, Frame > &spatial_metric) noexcept
Computes the spacetime metric from the spatial metric, lapse, and shift.
Tensor.hpp
GeneralizedHarmonic::Tags::InitialGaugeH
Initial value of the gauge source function for the generalized harmonic system.
Definition: Tags.hpp:82
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
gr::Tags::Lapse
Definition: Tags.hpp:52
TMPL.hpp
gr::Tags::InverseSpatialMetric
Inverse of the spatial metric.
Definition: Tags.hpp:33
Mesh.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:13
GeneralizedHarmonic::Tags::SpacetimeDerivInitialGaugeH
Initial spacetime derivatives of the gauge source function for the generalized harmonic system.
Definition: Tags.hpp:97
domain::Tags::ElementMap
Definition: Tags.hpp:115
gr::Tags::SqrtDetSpatialMetric
Definition: Tags.hpp:44