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"
14 #include "Domain/CoordinateMaps/Tags.hpp"
15 #include "Domain/FunctionsOfTime/Tags.hpp"
16 #include "Domain/Tags.hpp"
17 #include "Domain/TagsTimeDependent.hpp"
18 #include "ErrorHandling/Error.hpp"
19 #include "Evolution/Initialization/Tags.hpp"
20 #include "Evolution/Systems/GeneralizedHarmonic/GaugeSourceFunctions/DampedHarmonic.hpp"
21 #include "Evolution/Systems/GeneralizedHarmonic/GaugeSourceFunctions/DhGaugeParameters.hpp"
22 #include "Evolution/Systems/GeneralizedHarmonic/GaugeSourceFunctions/Tags/DhGaugeParameters.hpp"
23 #include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp"
25 #include "Options/Options.hpp"
26 #include "ParallelAlgorithms/Initialization/MergeIntoDataBox.hpp"
27 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
28 #include "Time/Tags.hpp"
30 #include "Utilities/TMPL.hpp"
31 
32 namespace GeneralizedHarmonic::gauges::Actions {
33 /*!
34  * \brief Initialize the damped harmonic gauge, either with or without a rollon
35  * function.
36  *
37  * See `GeneralizedHarmonic::gauges::damped_harmonic()` for details on the
38  * condition.
39  *
40  * When the non-rollon gauge is initialized, Eq. 9 and 10 of
41  * \cite Lindblom2005qh are used to compute the time derivatives for the lapse
42  * and shift to compute the new \f$\Pi_{ab}\f$.
43  *
44  * \warning The rollon gauge does not support moving meshes.
45  *
46  * When the rollon gauge is used:
47  *
48  * DataBox:
49  * - Uses:
50  * - `domain::Tags::Domain<Dim, Frame::Inertial>`
51  * - `domain::CoordinateMaps::Tags::CoordinateMap<Dim,
52  * Frame::Grid, Frame::Inertial>`
53  * - `domain::Tags::InverseJacobian<Dim, Frame::Logical, Frame::Inertial>`
54  * - `domain::Tags::Mesh<Dim>`
55  * - `gr::Tags::SpacetimeMetric<Dim, Frame::Inertial>`
56  * - `GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>`
57  * - `GeneralizedHarmonic::Tags::Phi<Dim, Frame::Inertial>`
58  * - Adds:
59  * - `GeneralizedHarmonic::Tags::InitialGaugeH<Dim, Frame::Inertial>`
60  * - `GeneralizedHarmonic::Tags::SpacetimeDerivInitialGaugeH<Dim,
61  * Frame::Inertial>`
62  * - `GeneralizedHarmonic::Tags::GaugeH<Dim, Frame::Inertial>`
63  * - `GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame::Inertial>`
64  * - Removes: nothing
65  * - Modifies: nothing
66  *
67  * When the non-rollon gauge is used:
68  *
69  * DataBox:
70  * - Uses:
71  * - `Initialization::Tags::InitialTime`
72  * - `domain::Tags::ElementMap<Dim, Frame::Grid>`
73  * - `domain::CoordinateMaps::Tags::CoordinateMap<Dim,
74  * Frame::Grid, Frame::Inertial>`
75  * - `domain::Tags::Coordinates<Dim, Frame::Logical>`
76  * - `domain::Tags::FunctionsOfTime`
77  * - `gr::Tags::SpacetimeMetric<Dim, Frame::Inertial>`
78  * - `GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>`
79  * - `GeneralizedHarmonic::Tags::Phi<Dim, Frame::Inertial>`
80  * - Adds:
81  * - `GeneralizedHarmonic::Tags::GaugeH<Dim, Frame::Inertial>`
82  * - `GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame::Inertial>`
83  * - Removes: nothing
84  * - Modifies:
85  * - `GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>`
86  */
87 template <size_t Dim, bool UseRollon>
89  private:
90  template <typename Frame>
91  struct DampedHarmonicRollonCompute
93  ::Tags::Variables<tmpl::list<
94  ::GeneralizedHarmonic::Tags::GaugeH<Dim, Frame>,
95  ::GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame>>> {
96  using base = ::Tags::Variables<tmpl::list<
99  static std::string name() noexcept { return "DampedHarmonicRollonCompute"; }
100  using argument_tags = tmpl::list<
113  using return_type = Variables<tmpl::list<
116 
117  static void function(
118  gsl::not_null<return_type*> h_and_d4_h,
119  const tnsr::a<DataVector, Dim, Frame>& gauge_h_init,
120  const tnsr::ab<DataVector, Dim, Frame>& dgauge_h_init,
121  const Scalar<DataVector>& lapse,
122  const tnsr::I<DataVector, Dim, Frame>& shift,
123  const tnsr::a<DataVector, Dim, Frame>& spacetime_unit_normal_one_form,
124  const Scalar<DataVector>& sqrt_det_spatial_metric,
125  const tnsr::II<DataVector, Dim, Frame>& inverse_spatial_metric,
126  const tnsr::aa<DataVector, Dim, Frame>& spacetime_metric,
127  const tnsr::aa<DataVector, Dim, Frame>& pi,
128  const tnsr::iaa<DataVector, Dim, Frame>& phi, double time,
129  const tnsr::I<DataVector, Dim, Frame>& coords,
131  parameters) noexcept;
132  };
133 
134  template <typename Frame>
135  struct DampedHarmonicCompute
136  : db::ComputeTag,
137  ::Tags::Variables<tmpl::list<
138  ::GeneralizedHarmonic::Tags::GaugeH<Dim, Frame>,
139  ::GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame>>> {
140  using base = ::Tags::Variables<tmpl::list<
143  static std::string name() noexcept { return "DampedHarmonicCompute"; }
144  using argument_tags = tmpl::list<
155  using return_type = Variables<tmpl::list<
158 
159  static void function(
161  const tnsr::I<DataVector, Dim, Frame>& shift,
162  const tnsr::a<DataVector, Dim, Frame>& spacetime_unit_normal_one_form,
163  const Scalar<DataVector>& sqrt_det_spatial_metric,
164  const tnsr::II<DataVector, Dim, Frame>& inverse_spatial_metric,
165  const tnsr::aa<DataVector, Dim, Frame>& spacetime_metric,
166  const tnsr::aa<DataVector, Dim, Frame>& pi,
167  const tnsr::iaa<DataVector, Dim, Frame>& phi,
168  const tnsr::I<DataVector, Dim, Frame>& coords,
170  parameters) noexcept;
171  };
172 
173  public:
174  using frame = Frame::Inertial;
175 
176  using const_global_cache_tags = tmpl::list<
178 
179  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
180  typename ArrayIndex, typename ActionList,
181  typename ParallelComponent>
182  static auto apply(db::DataBox<DbTagsList>& box,
183  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
184  const Parallel::GlobalCache<Metavariables>& /*cache*/,
185  const ArrayIndex& /*array_index*/,
186  const ActionList /*meta*/,
187  const ParallelComponent* const /*meta*/) noexcept {
188  if constexpr (UseRollon) {
190  Metavariables::volume_dim, Frame::Grid, Frame::Inertial>>(box)
191  .is_identity()) {
192  ERROR(
193  "Cannot use the damped harmonic rollon gauge with a moving mesh "
194  "because the rollon is not implemented for a moving mesh. The "
195  "issue is that the initial H_a needs to be in the grid frame, and "
196  "then transformed to the inertial frame at each time step. "
197  "Transforming the spacetime derivative requires spacetime "
198  "Hessians, which are not implemented for the maps and there is "
199  "currently no plan to add them because we do not need them for "
200  "anything else.");
201  }
202  const auto& inverse_jacobian =
203  db::get<domain::Tags::InverseJacobian<Dim, Frame::Logical, frame>>(
204  box);
205 
206  auto [initial_gauge_h, initial_d4_gauge_h] = impl_rollon(
208  box),
211  db::get<domain::Tags::Mesh<Dim>>(box), inverse_jacobian);
212 
213  // Add gauge tags
214  using compute_tags =
216 
217  // Finally, insert gauge related quantities to the box
218  return std::make_tuple(
224  Dim, frame>>,
225  compute_tags>(std::move(box), std::move(initial_gauge_h),
226  std::move(initial_d4_gauge_h)));
227  } else {
228  const double initial_time =
229  db::get<::Initialization::Tags::InitialTime>(box);
230  const auto inertial_coords =
232  Metavariables::volume_dim, Frame::Grid, Frame::Inertial>>(box)(
233  db::get<::domain::Tags::ElementMap<Metavariables::volume_dim,
234  Frame::Grid>>(box)(
235  db::get<domain::Tags::Coordinates<Dim, Frame::Logical>>(box)),
236  initial_time, db::get<::domain::Tags::FunctionsOfTime>(box));
237 
238  db::mutate<GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>>(
239  make_not_null(&box), &new_pi_from_gauge_h,
240  db::get<gr::Tags::SpacetimeMetric<Dim, Frame::Inertial, DataVector>>(
241  box),
243  inertial_coords,
244  db::get<
246  box));
247 
248  // Add gauge tags
250  return std::make_tuple(
252  db::AddSimpleTags<>, compute_tags>(
253  std::move(box)));
254  }
255  }
256 
257  private:
259  tnsr::ab<DataVector, Dim, Frame::Inertial>>
260  impl_rollon(
261  const tnsr::aa<DataVector, Dim, Frame::Inertial>& spacetime_metric,
262  const tnsr::aa<DataVector, Dim, Frame::Inertial>& pi,
263  const tnsr::iaa<DataVector, Dim, Frame::Inertial>& phi,
264  const Mesh<Dim>& mesh,
265  const InverseJacobian<DataVector, Dim, Frame::Logical, Frame::Inertial>&
266  inverse_jacobian) noexcept;
267 
268  static void new_pi_from_gauge_h(
269  gsl::not_null<tnsr::aa<DataVector, Dim, Frame::Inertial>*> pi,
270  const tnsr::aa<DataVector, Dim, Frame::Inertial>& spacetime_metric,
271  const tnsr::iaa<DataVector, Dim, Frame::Inertial>& phi,
272  const tnsr::I<DataVector, Dim, Frame::Inertial>& coords,
274  parameters) noexcept;
275 };
276 } // namespace GeneralizedHarmonic::gauges::Actions
GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH
Spacetime derivatives of the gauge source function for the generalized harmonic system.
Definition: Tags.hpp:77
db::ComputeTag
Marks a DataBoxTag as being a compute item that executes a function.
Definition: Tag.hpp:109
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:16
domain::Tags::Coordinates
Definition: Tags.hpp:131
Frame::Grid
Definition: IndexType.hpp:43
Options.hpp
Tags.hpp
Error.hpp
Tags::Variables
Definition: VariablesTag.hpp:21
db::AddComputeTags
tmpl::flatten< tmpl::list< Tags... > > AddComputeTags
List of Compute Item Tags to add to the DataBox.
Definition: DataBox.hpp:1153
domain::Tags::Mesh
The computational grid of the Element in the DataBox.
Definition: Tags.hpp:108
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:1116
GeneralizedHarmonic::gauges::Actions::InitializeDampedHarmonic
Initialize the damped harmonic gauge, either with or without a rollon function.
Definition: InitializeDampedHarmonic.hpp:88
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:36
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:74
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:63
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:47
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.
db::AddSimpleTags
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:1132
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:92
Initialization::merge_into_databox
auto merge_into_databox(db::DataBox< DbTagsList > &&box, Args &&... args) noexcept
Add tags that are not yet in the DataBox.
Definition: MergeIntoDataBox.hpp:133
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
Mesh.hpp
db::DataBox
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
gr::Tags::Lapse
Definition: Tags.hpp:52
TMPL.hpp
gr::Tags::InverseSpatialMetric
Inverse of the spatial metric.
Definition: Tags.hpp:33
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183
GeneralizedHarmonic::Tags::SpacetimeDerivInitialGaugeH
Initial spacetime derivatives of the gauge source function for the generalized harmonic system.
Definition: Tags.hpp:107
domain::Tags::ElementMap
Definition: Tags.hpp:116
gr::Tags::SqrtDetSpatialMetric
Definition: Tags.hpp:44