InitializeDampedHarmonic.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <tuple>
8 #include <utility>
9 
12 #include "Domain/CoordinateMaps/Tags.hpp"
13 #include "Domain/FunctionsOfTime/Tags.hpp"
14 #include "Domain/Tags.hpp"
15 #include "Domain/TagsTimeDependent.hpp"
16 #include "ErrorHandling/Error.hpp"
17 #include "Evolution/Initialization/Tags.hpp"
18 #include "Evolution/Systems/GeneralizedHarmonic/GaugeSourceFunctions/DampedHarmonic.hpp"
19 #include "Evolution/Systems/GeneralizedHarmonic/GaugeSourceFunctions/OptionTags.hpp"
20 #include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp"
22 #include "Options/Options.hpp"
23 #include "ParallelAlgorithms/Initialization/MergeIntoDataBox.hpp"
24 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
25 #include "Time/Tags.hpp"
27 #include "Utilities/TMPL.hpp"
28 
29 namespace GeneralizedHarmonic::gauges::Actions {
30 /// Option tags for the gauges
31 namespace OptionTags {
32 /// The rollon start time
34  using type = double;
35  static std::string name() noexcept { return "RollOnStartTime"; }
36  static constexpr OptionString help{
37  "Simulation time to start rolling on the damped harmonic gauge"};
39 };
40 
41 /// The width of the Gaussian for the gauge rollon
43  using type = double;
44  static std::string name() noexcept { return "RollOnTimeWindow"; }
45  static constexpr OptionString help{
46  "The width of the Gaussian that controls how quickly the gauge is "
47  "rolled on."};
49 };
50 
51 /// The width of the Gaussian for the spatial decay of the damped harmonic
52 /// gauge.
53 template <typename Frame>
55  using type = double;
56  static std::string name() noexcept { return "SpatialDecayWidth"; }
57  static constexpr OptionString help{
58  "Spatial width of weight function used in the damped harmonic "
59  "gauge."};
61 };
62 } // namespace OptionTags
63 
64 /*!
65  * \brief Initialize the damped harmonic gauge, either with or without a rollon
66  * function.
67  *
68  * See `GeneralizedHarmonic::gauges::damped_harmonic()` for details on the
69  * condition.
70  *
71  * When the non-rollon gauge is initialized, Eq. 9 and 10 of
72  * \cite Lindblom2005qh are used to compute the time derivatives for the lapse
73  * and shift to compute the new \f$\Pi_{ab}\f$.
74  *
75  * \warning The rollon gauge does not support moving meshes.
76  *
77  * When the rollon gauge is used:
78  *
79  * DataBox:
80  * - Uses:
81  * - `domain::Tags::Domain<Dim, Frame::Inertial>`
82  * - `domain::CoordinateMaps::Tags::CoordinateMap<Dim,
83  * Frame::Grid, Frame::Inertial>`
84  * - `domain::Tags::InverseJacobian<Dim, Frame::Logical, Frame::Inertial>`
85  * - `domain::Tags::Mesh<Dim>`
86  * - `gr::Tags::SpacetimeMetric<Dim, Frame::Inertial>`
87  * - `GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>`
88  * - `GeneralizedHarmonic::Tags::Phi<Dim, Frame::Inertial>`
89  * - Adds:
90  * - `GeneralizedHarmonic::Tags::InitialGaugeH<Dim, Frame::Inertial>`
91  * - `GeneralizedHarmonic::Tags::SpacetimeDerivInitialGaugeH<Dim,
92  * Frame::Inertial>`
93  * - `GeneralizedHarmonic::Tags::GaugeH<Dim, Frame::Inertial>`
94  * - `GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame::Inertial>`
95  * - Removes: nothing
96  * - Modifies: nothing
97  *
98  * When the non-rollon gauge is used:
99  *
100  * DataBox:
101  * - Uses:
102  * - `Initialization::Tags::InitialTime`
103  * - `domain::Tags::ElementMap<Dim, Frame::Grid>`
104  * - `domain::CoordinateMaps::Tags::CoordinateMap<Dim,
105  * Frame::Grid, Frame::Inertial>`
106  * - `domain::Tags::Coordinates<Dim, Frame::Logical>`
107  * - `domain::Tags::FunctionsOfTime`
108  * - `gr::Tags::SpacetimeMetric<Dim, Frame::Inertial>`
109  * - `GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>`
110  * - `GeneralizedHarmonic::Tags::Phi<Dim, Frame::Inertial>`
111  * - Adds:
112  * - `GeneralizedHarmonic::Tags::GaugeH<Dim, Frame::Inertial>`
113  * - `GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH<Dim, Frame::Inertial>`
114  * - Removes: nothing
115  * - Modifies:
116  * - `GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>`
117  */
118 template <size_t Dim, bool UseRollon>
120  private:
121  struct GaugeHRollOnStartTime : db::SimpleTag {
122  using type = double;
123  using option_tags = tmpl::list<OptionTags::DampedHarmonicRollOnStart>;
124 
125  static constexpr bool pass_metavariables = false;
126  static double create_from_options(
127  const double gauge_roll_on_start_time) noexcept {
128  return gauge_roll_on_start_time;
129  }
130  };
131 
132  struct GaugeHRollOnTimeWindow : db::SimpleTag {
133  using type = double;
134  using option_tags = tmpl::list<OptionTags::DampedHarmonicRollOnWindow>;
135 
136  static constexpr bool pass_metavariables = false;
137  static double create_from_options(
138  const double gauge_roll_on_window) noexcept {
139  return gauge_roll_on_window;
140  }
141  };
142 
143  template <typename Frame>
144  struct GaugeHSpatialWeightDecayWidth : db::SimpleTag {
145  using type = double;
146  using option_tags =
147  tmpl::list<OptionTags::DampedHarmonicSpatialDecayWidth<Frame>>;
148 
149  static constexpr bool pass_metavariables = false;
150  static double create_from_options(
151  const double gauge_spatial_decay_width) noexcept {
152  return gauge_spatial_decay_width;
153  }
154  };
155 
156  template <typename Frame>
157  struct DampedHarmonicRollonCompute : db::ComputeTag {
158  static std::string name() noexcept { return "DampedHarmonicRollonCompute"; }
159  using argument_tags =
160  tmpl::list<Tags::InitialGaugeH<Dim, Frame>,
169  GaugeHRollOnStartTime, GaugeHRollOnTimeWindow,
171  GaugeHSpatialWeightDecayWidth<Frame>>;
172  using return_type =
173  Variables<tmpl::list<Tags::GaugeH<Dim, Frame>,
175 
176  static void function(
177  gsl::not_null<return_type*> h_and_d4_h,
180  dgauge_h_init,
181  const Scalar<DataVector>& lapse,
182  const tnsr::I<DataVector, Dim, Frame>& shift,
183  const tnsr::a<DataVector, Dim, Frame>& spacetime_unit_normal_one_form,
184  const Scalar<DataVector>& sqrt_det_spatial_metric,
185  const tnsr::II<DataVector, Dim, Frame>& inverse_spatial_metric,
186  const tnsr::aa<DataVector, Dim, Frame>& spacetime_metric,
187  const tnsr::aa<DataVector, Dim, Frame>& pi,
188  const tnsr::iaa<DataVector, Dim, Frame>& phi, double time,
189  double rollon_start_time, double rollon_width,
190  const tnsr::I<DataVector, Dim, Frame>& coords, double sigma_r) noexcept;
191  };
192 
193  template <typename Frame>
194  struct DampedHarmonicCompute : db::ComputeTag {
195  static std::string name() noexcept { return "DampedHarmonicCompute"; }
196  using argument_tags =
197  tmpl::list<::gr::Tags::Lapse<DataVector>,
205  GaugeHSpatialWeightDecayWidth<Frame>>;
206  using return_type =
207  Variables<tmpl::list<Tags::GaugeH<Dim, Frame>,
209 
210  static void function(
212  const tnsr::I<DataVector, Dim, Frame>& shift,
213  const tnsr::a<DataVector, Dim, Frame>& spacetime_unit_normal_one_form,
214  const Scalar<DataVector>& sqrt_det_spatial_metric,
215  const tnsr::II<DataVector, Dim, Frame>& inverse_spatial_metric,
216  const tnsr::aa<DataVector, Dim, Frame>& spacetime_metric,
217  const tnsr::aa<DataVector, Dim, Frame>& pi,
218  const tnsr::iaa<DataVector, Dim, Frame>& phi,
219  const tnsr::I<DataVector, Dim, Frame>& coords, double sigma_r) noexcept;
220  };
221 
222  public:
223  using frame = Frame::Inertial;
224 
225  using const_global_cache_tags = tmpl::append<
226  tmpl::list<GaugeHSpatialWeightDecayWidth<frame>>,
227  tmpl::conditional_t<
228  UseRollon, tmpl::list<GaugeHRollOnStartTime, GaugeHRollOnTimeWindow>,
229  tmpl::list<>>>;
230 
231  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
232  typename ArrayIndex, typename ActionList,
233  typename ParallelComponent>
234  static auto apply(db::DataBox<DbTagsList>& box,
235  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
237  const ArrayIndex& /*array_index*/,
238  const ActionList /*meta*/,
239  const ParallelComponent* const /*meta*/) noexcept {
240  if constexpr (UseRollon) {
242  Metavariables::volume_dim, Frame::Grid, Frame::Inertial>>(box)
243  .is_identity()) {
244  ERROR(
245  "Cannot use the damped harmonic rollon gauge with a moving mesh "
246  "because the rollon is not implemented for a moving mesh. The "
247  "issue is that the initial H_a needs to be in the grid frame, and "
248  "then transformed to the inertial frame at each time step. "
249  "Transforming the spacetime derivative requires spacetime "
250  "Hessians, which are not implemented for the maps and there is "
251  "currently no plan to add them because we do not need them for "
252  "anything else.");
253  }
254  const auto& inverse_jacobian =
255  db::get<domain::Tags::InverseJacobian<Dim, Frame::Logical, frame>>(
256  box);
257 
258  auto [initial_gauge_h, initial_d4_gauge_h] = impl_rollon(
260  box),
263  db::get<domain::Tags::Mesh<Dim>>(box), inverse_jacobian);
264 
265  // Add gauge tags
266  using compute_tags =
268 
269  // Finally, insert gauge related quantities to the box
270  return std::make_tuple(
276  Dim, frame>>,
277  compute_tags>(std::move(box), std::move(initial_gauge_h),
278  std::move(initial_d4_gauge_h)));
279  } else {
280  const double initial_time =
281  db::get<::Initialization::Tags::InitialTime>(box);
282  const auto inertial_coords =
284  Metavariables::volume_dim, Frame::Grid, Frame::Inertial>>(box)(
285  db::get<::domain::Tags::ElementMap<Metavariables::volume_dim,
286  Frame::Grid>>(box)(
287  db::get<domain::Tags::Coordinates<Dim, Frame::Logical>>(box)),
288  initial_time, db::get<::domain::Tags::FunctionsOfTime>(box));
289 
290  db::mutate<GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>>(
291  make_not_null(&box), &new_pi_from_gauge_h,
292  db::get<gr::Tags::SpacetimeMetric<Dim, Frame::Inertial, DataVector>>(
293  box),
295  inertial_coords, db::get<GaugeHSpatialWeightDecayWidth<frame>>(box));
296 
297  // Add gauge tags
299  return std::make_tuple(
301  db::AddSimpleTags<>, compute_tags>(
302  std::move(box)));
303  }
304  }
305 
306  private:
308  tnsr::ab<DataVector, Dim, Frame::Inertial>>
309  impl_rollon(
310  const tnsr::aa<DataVector, Dim, Frame::Inertial>& spacetime_metric,
311  const tnsr::aa<DataVector, Dim, Frame::Inertial>& pi,
312  const tnsr::iaa<DataVector, Dim, Frame::Inertial>& phi,
313  const Mesh<Dim>& mesh,
314  const InverseJacobian<DataVector, Dim, Frame::Logical, Frame::Inertial>&
315  inverse_jacobian) noexcept;
316 
317  static void new_pi_from_gauge_h(
318  gsl::not_null<tnsr::aa<DataVector, Dim, Frame::Inertial>*> pi,
319  const tnsr::aa<DataVector, Dim, Frame::Inertial>& spacetime_metric,
320  const tnsr::iaa<DataVector, Dim, Frame::Inertial>& phi,
321  const tnsr::I<DataVector, Dim, Frame::Inertial>& coords,
322  double sigma_r) noexcept;
323 };
324 } // namespace GeneralizedHarmonic::gauges::Actions
Parallel::ConstGlobalCache
Definition: ElementReceiveInterpPoints.hpp:16
GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH
Spacetime derivatives of the gauge source function for the generalized harmonic system.
Definition: Tags.hpp:77
GeneralizedHarmonic::gauges::Actions::OptionTags::DampedHarmonicRollOnWindow
The width of the Gaussian for the gauge rollon.
Definition: InitializeDampedHarmonic.hpp:42
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
domain::Tags::Coordinates
Definition: Tags.hpp:129
GeneralizedHarmonic::gauges::Actions::OptionTags::DampedHarmonicSpatialDecayWidth
The width of the Gaussian for the spatial decay of the damped harmonic gauge.
Definition: InitializeDampedHarmonic.hpp:54
Frame::Grid
Definition: IndexType.hpp:43
Options.hpp
Tags.hpp
Error.hpp
db::AddComputeTags
tmpl::flatten< tmpl::list< Tags... > > AddComputeTags
List of Compute Item Tags to add to the DataBox.
Definition: DataBox.hpp:1171
domain::Tags::Mesh
The computational grid of the Element in the DataBox.
Definition: Tags.hpp:106
tuple
db::get
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:1134
db::SimpleTag
Tags for the DataBox inherit from this type.
Definition: Tag.hpp:23
GeneralizedHarmonic::gauges::Actions::InitializeDampedHarmonic
Initialize the damped harmonic gauge, either with or without a rollon function.
Definition: InitializeDampedHarmonic.hpp:119
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
Parallel::create_from_options
tuples::TaggedTuple< Tags... > create_from_options(const tuples::TaggedTuple< OptionTags... > &options, tmpl::list< Tags... >) noexcept
Given a list of tags and a tagged tuple containing items created from input options,...
Definition: CreateFromOptions.hpp:40
DataBox.hpp
cstddef
GeneralizedHarmonic::gauges::OptionTags::GaugeGroup
Gauge-related option tags for the GeneralizedHarmonic evolution system.
Definition: OptionTags.hpp:15
MakeWithValue.hpp
db::item_type
typename DataBox_detail::item_type_impl< TagList, Tag >::type item_type
Get the type that can be written to the Tag. If it is a base tag then a TagList must be passed as a s...
Definition: DataBoxTag.hpp:246
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:272
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...
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:50
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:1150
GeneralizedHarmonic::Tags::Phi
Auxiliary variable which is analytically the spatial derivative of the spacetime metric.
Definition: Tags.hpp:40
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
GeneralizedHarmonic::gauges::Actions::OptionTags::DampedHarmonicRollOnStart
The rollon start time.
Definition: InitializeDampedHarmonic.hpp:33
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
OptionString
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:30
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:114
gr::Tags::SqrtDetSpatialMetric
Definition: Tags.hpp:44