GaugeSource.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 
9 #include "DataStructures/DataBox/Tag.hpp"
10 #include "DataStructures/DataVector.hpp"
12 #include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp"
14 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
15 #include "Utilities/ContainerHelpers.hpp"
16 #include "Utilities/Gsl.hpp"
17 #include "Utilities/TMPL.hpp"
18 
19 // IWYU pragma: no_forward_declare Tags::deriv
20 
21 /// \cond
22 namespace domain {
23 namespace Tags {
24 template <size_t Dim, typename Frame>
25 struct Coordinates;
26 } // namespace Tags
27 } // namespace domain
28 class DataVector;
29 template <typename X, typename Symm, typename IndexList>
30 class Tensor;
31 /// \endcond
32 
33 namespace GeneralizedHarmonic {
34 //@{
35 /*!
36  * \ingroup GeneralRelativityGroup
37  * \brief Computes generalized harmonic gauge source function.
38  * \details If \f$N, N^i, g_{ij}, \Gamma_{ijk}, K\f$ are the lapse, shift,
39  * spatial metric, spatial Christoffel symbols, and trace of the extrinsic
40  * curvature, then we compute
41  * \f{align}
42  * H_l &= N^{-2} g_{il}(\partial_t N^i - N^k \partial_k N^i)
43  * + N^{-1} \partial_l N - g^{km}\Gamma_{lkm} \\
44  * H_0 &= -N^{-1} \partial_t N + N^{-1} N^k\partial_k N + N^k H_k - N K
45  * \f}
46  * See Eqs. 8 and 9 of \cite Lindblom2005qh
47  */
48 template <size_t SpatialDim, typename Frame, typename DataType>
49 void gauge_source(
50  gsl::not_null<tnsr::a<DataType, SpatialDim, Frame>*> gauge_source_h,
51  const Scalar<DataType>& lapse, const Scalar<DataType>& dt_lapse,
52  const tnsr::i<DataType, SpatialDim, Frame>& deriv_lapse,
53  const tnsr::I<DataType, SpatialDim, Frame>& shift,
54  const tnsr::I<DataType, SpatialDim, Frame>& dt_shift,
55  const tnsr::iJ<DataType, SpatialDim, Frame>& deriv_shift,
56  const tnsr::ii<DataType, SpatialDim, Frame>& spatial_metric,
57  const Scalar<DataType>& trace_extrinsic_curvature,
58  const tnsr::i<DataType, SpatialDim, Frame>&
59  trace_christoffel_last_indices) noexcept;
60 
61 template <size_t SpatialDim, typename Frame, typename DataType>
62 tnsr::a<DataType, SpatialDim, Frame> gauge_source(
63  const Scalar<DataType>& lapse, const Scalar<DataType>& dt_lapse,
64  const tnsr::i<DataType, SpatialDim, Frame>& deriv_lapse,
65  const tnsr::I<DataType, SpatialDim, Frame>& shift,
66  const tnsr::I<DataType, SpatialDim, Frame>& dt_shift,
67  const tnsr::iJ<DataType, SpatialDim, Frame>& deriv_shift,
68  const tnsr::ii<DataType, SpatialDim, Frame>& spatial_metric,
69  const Scalar<DataType>& trace_extrinsic_curvature,
70  const tnsr::i<DataType, SpatialDim, Frame>&
71  trace_christoffel_last_indices) noexcept;
72 //@}
73 
74 namespace Tags {
75 /*!
76  * \brief Compute item to get the implicit gauge source function from 3 + 1
77  * quantities.
78  *
79  * \details See `gauge_source()`. Can be retrieved using
80  * `GeneralizedHarmonic::Tags::GaugeH`.
81  */
82 template <size_t SpatialDim, typename Frame>
83 struct GaugeHImplicitFrom3p1QuantitiesCompute : GaugeH<SpatialDim, Frame>,
85  using argument_tags =
86  tmpl::list<gr::Tags::Lapse<DataVector>,
89  tmpl::size_t<SpatialDim>, Frame>,
93  tmpl::size_t<SpatialDim>, Frame>,
97  DataVector>>;
98 
99  using return_type = tnsr::a<DataVector, SpatialDim, Frame>;
100 
101  static constexpr auto function = static_cast<void (*)(
103  const Scalar<DataVector>&, const Scalar<DataVector>&,
104  const tnsr::i<DataVector, SpatialDim, Frame>&,
105  const tnsr::I<DataVector, SpatialDim, Frame>&,
106  const tnsr::I<DataVector, SpatialDim, Frame>&,
107  const tnsr::iJ<DataVector, SpatialDim, Frame>&,
108  const tnsr::ii<DataVector, SpatialDim, Frame>&, const Scalar<DataVector>&,
109  const tnsr::i<DataVector, SpatialDim, Frame>&) noexcept>(
110  &gauge_source<SpatialDim, Frame, DataVector>);
111 
113 };
114 
115 /*!
116  * \brief Compute item to get spacetime derivative of the gauge source function
117  * from its spatial and time derivatives.
118  *
119  * \details Can be retrieved using
120  * `GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH`.
121  */
122 template <size_t SpatialDim, typename Frame>
125  using argument_tags = tmpl::list<
128  tmpl::size_t<SpatialDim>, Frame>>;
129 
130  using return_type = tnsr::ab<DataVector, SpatialDim, Frame>;
131 
132  static constexpr void function(
134  spacetime_deriv_gauge_source,
135  const tnsr::a<DataVector, SpatialDim, Frame>& time_deriv_gauge_source,
136  const tnsr::ia<DataVector, SpatialDim, Frame>&
137  deriv_gauge_source) noexcept {
138  destructive_resize_components(spacetime_deriv_gauge_source,
139  get<0>(time_deriv_gauge_source).size());
140  for (size_t b = 0; b < SpatialDim + 1; ++b) {
141  spacetime_deriv_gauge_source->get(0, b) = time_deriv_gauge_source.get(b);
142  for (size_t a = 1; a < SpatialDim + 1; ++a) {
143  spacetime_deriv_gauge_source->get(a, b) =
144  deriv_gauge_source.get(a - 1, b);
145  }
146  }
147  }
148 
150 };
151 } // namespace Tags
152 } // namespace GeneralizedHarmonic
GeneralizedHarmonic::Tags::SpacetimeDerivGaugeH
Spacetime derivatives of the gauge source function for the generalized harmonic system.
Definition: Tags.hpp:77
gr::Tags::TraceExtrinsicCurvature< DataVector >
GeneralizedHarmonic::Tags::GaugeHImplicitFrom3p1QuantitiesCompute
Compute item to get the implicit gauge source function from 3 + 1 quantities.
Definition: GaugeSource.hpp:83
db::ComputeTag
Marks a DataBoxTag as being a compute item that executes a function.
Definition: Tag.hpp:109
gr::Tags::SpatialMetric
Definition: Tags.hpp:26
GeneralizedHarmonic
Items related to evolving the first-order generalized harmonic system.
Definition: Characteristics.cpp:21
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.
cstddef
GeneralizedHarmonic::gauge_source
void gauge_source(gsl::not_null< tnsr::a< DataType, SpatialDim, Frame > * > gauge_source_h, const Scalar< DataType > &lapse, const Scalar< DataType > &dt_lapse, const tnsr::i< DataType, SpatialDim, Frame > &deriv_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::I< DataType, SpatialDim, Frame > &dt_shift, const tnsr::iJ< DataType, SpatialDim, Frame > &deriv_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const Scalar< DataType > &trace_extrinsic_curvature, const tnsr::i< DataType, SpatialDim, Frame > &trace_christoffel_last_indices) noexcept
Computes generalized harmonic gauge source function.
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:42
GeneralizedHarmonic::Tags::SpacetimeDerivGaugeHCompute
Compute item to get spacetime derivative of the gauge source function from its spatial and time deriv...
Definition: GaugeSource.hpp:123
GeneralizedHarmonic::Tags::GaugeH
Gauge source function for the generalized harmonic system.
Definition: Tags.hpp:63
gr::Tags::Shift
Definition: Tags.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.
Tags::dt
Prefix indicating a time derivative.
Definition: Prefixes.hpp:29
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
Gsl.hpp
Frame
Definition: IndexType.hpp:36
Tensor.hpp
Tags::deriv
Prefix indicating spatial derivatives.
Definition: PartialDerivatives.hpp:54
gr::spatial_metric
tnsr::ii< DataType, SpatialDim, Frame > spatial_metric(const tnsr::aa< DataType, SpatialDim, Frame > &spacetime_metric) noexcept
Compute spatial metric from spacetime metric.
gr::Tags::TraceSpatialChristoffelFirstKind
Trace of the spatial Christoffel symbols of the first kind , where are Christoffel symbols of the fi...
Definition: Tags.hpp:101
PartialDerivatives.hpp
Prefixes.hpp
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183
destructive_resize_components
void destructive_resize_components(const gsl::not_null< Container * > container, const size_t new_size, DestructiveResizeFunction destructive_resize=ContainerDestructiveResize{}) noexcept
Checks the size of each component of the container, and resizes if necessary.
Definition: ContainerHelpers.hpp:177