SpecBoundaryData.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 
8 #include "DataStructures/ComplexDataVector.hpp"
10 #include "DataStructures/DataVector.hpp"
11 #include "DataStructures/SpinWeighted.hpp"
12 #include "DataStructures/Tags/TempTensor.hpp"
16 #include "Evolution/Systems/Cce/BoundaryData.hpp"
17 #include "Evolution/Systems/Cce/BoundaryDataTags.hpp"
18 #include "Evolution/Systems/Cce/Tags.hpp"
19 #include "NumericalAlgorithms/Spectral/SwshCollocation.hpp"
20 #include "NumericalAlgorithms/Spectral/SwshDerivatives.hpp"
21 #include "PointwiseFunctions/GeneralRelativity/GeneralizedHarmonic/Phi.hpp"
22 #include "PointwiseFunctions/GeneralRelativity/SpacetimeMetric.hpp"
23 #include "PointwiseFunctions/GeneralRelativity/TimeDerivativeOfSpacetimeMetric.hpp"
24 #include "Utilities/Gsl.hpp"
25 
26 namespace Cce {
27 /*
28  * \brief Compute \f$\gamma_{i j}\f$, \f$\gamma^{i j}\f$,
29  * \f$\partial_i \gamma_{j k}\f$, and
30  * \f$\partial_t g_{i j}\f$ from input libsharp-compatible modal spatial
31  * metric quantities.
32  *
33  * \details This function will apply a correction factor associated with a SpEC
34  * bug.
35  */
36 void cartesian_spatial_metric_and_derivatives_from_unnormalized_spec_modes(
37  gsl::not_null<tnsr::ii<DataVector, 3>*> cartesian_spatial_metric,
38  gsl::not_null<tnsr::II<DataVector, 3>*> inverse_cartesian_spatial_metric,
39  gsl::not_null<tnsr::ijj<DataVector, 3>*> d_cartesian_spatial_metric,
40  gsl::not_null<tnsr::ii<DataVector, 3>*> dt_cartesian_spatial_metric,
42  interpolation_modal_buffer,
44  interpolation_buffer,
46  gsl::not_null<Scalar<DataVector>*> radial_correction_factor,
47  const tnsr::ii<ComplexModalVector, 3>& spatial_metric_coefficients,
48  const tnsr::ii<ComplexModalVector, 3>& dr_spatial_metric_coefficients,
49  const tnsr::ii<ComplexModalVector, 3>& dt_spatial_metric_coefficients,
50  const CartesianiSphericalJ& inverse_cartesian_to_spherical_jacobian,
51  const tnsr::I<DataVector, 3>& unit_cartesian_coords, size_t l_max) noexcept;
52 
53 /*!
54  * \brief Compute \f$\beta^{i}\f$, \f$\partial_i \beta^{j}\f$, and
55  * \f$\partial_t \beta^i\f$ from input libsharp-compatible modal spatial
56  * metric quantities.
57  *
58  * \details This function will apply a correction factor associated with a SpEC
59  * bug.
60  */
61 void cartesian_shift_and_derivatives_from_unnormalized_spec_modes(
62  gsl::not_null<tnsr::I<DataVector, 3>*> cartesian_shift,
63  gsl::not_null<tnsr::iJ<DataVector, 3>*> d_cartesian_shift,
64  gsl::not_null<tnsr::I<DataVector, 3>*> dt_cartesian_shift,
66  interpolation_modal_buffer,
68  interpolation_buffer,
70  const tnsr::I<ComplexModalVector, 3>& shift_coefficients,
71  const tnsr::I<ComplexModalVector, 3>& dr_shift_coefficients,
72  const tnsr::I<ComplexModalVector, 3>& dt_shift_coefficients,
73  const CartesianiSphericalJ& inverse_cartesian_to_spherical_jacobian,
74  const Scalar<DataVector>& radial_derivative_correction_factor,
75  size_t l_max) noexcept;
76 
77 /*!
78  * \brief Compute \f$\alpha\f$, \f$\partial_i \alpha\f$, and
79  * \f$\partial_t \beta^i\f$ from input libsharp-compatible modal spatial
80  * metric quantities.
81  *
82  * \details This function will apply a correction factor associated with a SpEC
83  * bug.
84  */
85 void cartesian_lapse_and_derivatives_from_unnormalized_spec_modes(
86  gsl::not_null<Scalar<DataVector>*> cartesian_lapse,
87  gsl::not_null<tnsr::i<DataVector, 3>*> d_cartesian_lapse,
88  gsl::not_null<Scalar<DataVector>*> dt_cartesian_lapse,
90  interpolation_modal_buffer,
92  interpolation_buffer,
94  const Scalar<ComplexModalVector>& lapse_coefficients,
95  const Scalar<ComplexModalVector>& dr_lapse_coefficients,
96  const Scalar<ComplexModalVector>& dt_lapse_coefficients,
97  const CartesianiSphericalJ& inverse_cartesian_to_spherical_jacobian,
98  const Scalar<DataVector>& radial_derivative_correction_factor,
99  size_t l_max) noexcept;
100 
101 /*!
102  * \brief Process the worldtube data from modal metric components and
103  * derivatives with incorrectly normalized radial derivatives from an old
104  * version of SpEC to desired Bondi quantities, placing the result in the passed
105  * \ref DataBoxGroup.
106  *
107  * \details
108  * The mathematics are a bit complicated for all of the coordinate
109  * transformations that are necessary to obtain the Bondi gauge quantities.
110  * For full mathematical details, see the documentation for functions in
111  * `BoundaryData.hpp` and \cite Barkett2019uae \cite Bishop1998uk.
112  *
113  * This function takes as input the full set of ADM metric data and its radial
114  * and time derivatives on a two-dimensional surface of constant \f$r\f$ and
115  * \f$t\f$ in numerical coordinates. This data must be provided as spherical
116  * harmonic coefficients in the libsharp format. This data is provided in nine
117  * `Tensor`s.
118  *
119  * Sufficient tags to provide full worldtube boundary data at a particular
120  * time are set in `bondi_boundary_data`. In particular, the set of tags in
121  * `Tags::characteristic_worldtube_boundary_tags` in the provided \ref
122  * DataBoxGroup are assigned to the worldtube boundary values associated with
123  * the input metric components.
124  *
125  * The majority of the mathematical transformations are implemented as a set of
126  * individual cascaded functions below. The details of the manipulations that
127  * are performed to the input data may be found in the individual functions
128  * themselves, which are called in the following order:
129  * - `trigonometric_functions_on_swsh_collocation()`
130  * - `cartesian_to_spherical_coordinates_and_jacobians()`
131  * - `cartesian_spatial_metric_and_derivatives_from_unnormalized_spec_modes()`
132  * - `cartesian_shift_and_derivatives_from_unnormalized_spec_modes()`
133  * - `cartesian_lapse_and_derivatives_from_unnormalized_spec_modes()`
134  * - `GeneralizedHarmonic::phi()`
135  * - `gr::time_derivative_of_spacetime_metric`
136  * - `gr::spacetime_metric`
137  * - `generalized_harmonic_quantities()`
138  * - `worldtube_normal_and_derivatives()`
139  * - `null_vector_l_and_derivatives()`
140  * - `null_metric_and_derivative()`
141  * - `dlambda_null_metric_and_inverse()`
142  * - `bondi_r()`
143  * - `d_bondi_r()`
144  * - `dyads()`
145  * - `beta_worldtube_data()`
146  * - `bondi_u_worldtube_data()`
147  * - `bondi_w_worldtube_data()`
148  * - `bondi_j_worldtube_data()`
149  * - `dr_bondi_j()`
150  * - `d2lambda_bondi_r()`
151  * - `bondi_q_worldtube_data()`
152  * - `bondi_h_worldtube_data()`
153  * - `du_j_worldtube_data()`
154  */
155 template <typename TagList>
157  const gsl::not_null<Variables<TagList>*> bondi_boundary_data,
158  const tnsr::ii<ComplexModalVector, 3>& spatial_metric_coefficients,
159  const tnsr::ii<ComplexModalVector, 3>& dt_spatial_metric_coefficients,
160  const tnsr::ii<ComplexModalVector, 3>& dr_spatial_metric_coefficients,
161  const tnsr::I<ComplexModalVector, 3>& shift_coefficients,
162  const tnsr::I<ComplexModalVector, 3>& dt_shift_coefficients,
163  const tnsr::I<ComplexModalVector, 3>& dr_shift_coefficients,
164  const Scalar<ComplexModalVector>& lapse_coefficients,
165  const Scalar<ComplexModalVector>& dt_lapse_coefficients,
166  const Scalar<ComplexModalVector>& dr_lapse_coefficients,
167  const double extraction_radius, const size_t l_max) noexcept {
168  const size_t size = Spectral::Swsh::number_of_swsh_collocation_points(l_max);
169 
170  // Most allocations required for the full boundary computation are merged into
171  // a single, large Variables allocation. There remain a handful of cases in
172  // the computational functions called where an intermediate quantity that is
173  // not re-used is allocated rather than taking a buffer. These cases are
174  // marked with code comments 'Allocation'; In future, allocations are
175  // identified as a point to optimize, those buffers may be allocated here and
176  // passed as function arguments
177  Variables<tmpl::list<
178  Tags::detail::CosPhi, Tags::detail::CosTheta, Tags::detail::SinPhi,
179  Tags::detail::SinTheta, Tags::detail::CartesianCoordinates,
180  Tags::detail::CartesianToSphericalJacobian,
181  Tags::detail::InverseCartesianToSphericalJacobian,
185  tmpl::size_t<3>, ::Frame::Inertial>,
189  tmpl::size_t<3>, ::Frame::Inertial>,
198  Tags::detail::WorldtubeNormal, ::Tags::dt<Tags::detail::WorldtubeNormal>,
199  Tags::detail::NullL, ::Tags::dt<Tags::detail::NullL>,
200  // for the detail function called at the end
204  Tags::detail::AngularDNullL,
205  Tags::detail::DLambda<
207  Tags::detail::DLambda<
211  Tags::detail::DLambda<Tags::detail::DLambda<Tags::detail::RealBondiR>>,
213  tmpl::size_t<2>, Frame::RadialNull>,
215  computation_variables{size};
216 
217  Variables<
218  tmpl::list<::Tags::SpinWeighted<::Tags::TempScalar<0, ComplexDataVector>,
222  derivative_buffers{size};
223  auto& cos_phi = get<Tags::detail::CosPhi>(computation_variables);
224  auto& cos_theta = get<Tags::detail::CosTheta>(computation_variables);
225  auto& sin_phi = get<Tags::detail::SinPhi>(computation_variables);
226  auto& sin_theta = get<Tags::detail::SinTheta>(computation_variables);
227  trigonometric_functions_on_swsh_collocation(
228  make_not_null(&cos_phi), make_not_null(&cos_theta),
229  make_not_null(&sin_phi), make_not_null(&sin_theta), l_max);
230 
231  // NOTE: to handle the singular values of polar coordinates, the phi
232  // components of all tensors are scaled according to their sin(theta)
233  // prefactors.
234  // so, any down-index component get<2>(A) represents 1/sin(theta) A_\phi,
235  // and any up-index component get<2>(A) represents sin(theta) A^\phi.
236  // This holds for Jacobians, and so direct application of the Jacobians
237  // brings the factors through.
238  auto& cartesian_coords =
239  get<Tags::detail::CartesianCoordinates>(computation_variables);
240  auto& cartesian_to_spherical_jacobian =
241  get<Tags::detail::CartesianToSphericalJacobian>(computation_variables);
242  auto& inverse_cartesian_to_spherical_jacobian =
243  get<Tags::detail::InverseCartesianToSphericalJacobian>(
244  computation_variables);
245  cartesian_to_spherical_coordinates_and_jacobians(
246  make_not_null(&cartesian_coords),
247  make_not_null(&cartesian_to_spherical_jacobian),
248  make_not_null(&inverse_cartesian_to_spherical_jacobian), cos_phi,
249  cos_theta, sin_phi, sin_theta, extraction_radius);
250 
251  auto& cartesian_spatial_metric =
252  get<gr::Tags::SpatialMetric<3, ::Frame::Inertial, DataVector>>(
253  computation_variables);
254  auto& inverse_spatial_metric =
255  get<gr::Tags::InverseSpatialMetric<3, ::Frame::Inertial, DataVector>>(
256  computation_variables);
257  auto& d_cartesian_spatial_metric = get<
259  tmpl::size_t<3>, ::Frame::Inertial>>(computation_variables);
260  auto& dt_cartesian_spatial_metric = get<
262  computation_variables);
263  auto& interpolation_buffer =
264  get<::Tags::SpinWeighted<::Tags::TempScalar<0, ComplexDataVector>,
266  derivative_buffers);
267  Scalar<SpinWeighted<ComplexModalVector, 0>> interpolation_modal_buffer{size};
268  auto& eth_buffer =
269  get<::Tags::SpinWeighted<::Tags::TempScalar<0, ComplexDataVector>,
271  derivative_buffers);
272  auto& radial_correction_factor =
273  get<::Tags::TempScalar<0, DataVector>>(computation_variables);
274  cartesian_spatial_metric_and_derivatives_from_unnormalized_spec_modes(
275  make_not_null(&cartesian_spatial_metric),
276  make_not_null(&inverse_spatial_metric),
277  make_not_null(&d_cartesian_spatial_metric),
278  make_not_null(&dt_cartesian_spatial_metric),
279  make_not_null(&interpolation_modal_buffer),
280  make_not_null(&interpolation_buffer), make_not_null(&eth_buffer),
281  make_not_null(&radial_correction_factor), spatial_metric_coefficients,
282  dr_spatial_metric_coefficients, dt_spatial_metric_coefficients,
283  inverse_cartesian_to_spherical_jacobian, cartesian_coords, l_max);
284 
285  auto& cartesian_shift =
286  get<gr::Tags::Shift<3, ::Frame::Inertial, DataVector>>(
287  computation_variables);
288  auto& d_cartesian_shift =
289  get<::Tags::deriv<gr::Tags::Shift<3, ::Frame::Inertial, DataVector>,
290  tmpl::size_t<3>, ::Frame::Inertial>>(
291  computation_variables);
292  auto& dt_cartesian_shift =
293  get<::Tags::dt<gr::Tags::Shift<3, ::Frame::Inertial, DataVector>>>(
294  computation_variables);
295 
296  cartesian_shift_and_derivatives_from_unnormalized_spec_modes(
297  make_not_null(&cartesian_shift), make_not_null(&d_cartesian_shift),
298  make_not_null(&dt_cartesian_shift),
299  make_not_null(&interpolation_modal_buffer),
300  make_not_null(&interpolation_buffer), make_not_null(&eth_buffer),
301  shift_coefficients, dr_shift_coefficients, dt_shift_coefficients,
302  inverse_cartesian_to_spherical_jacobian, radial_correction_factor, l_max);
303 
304  auto& cartesian_lapse =
305  get<gr::Tags::Lapse<DataVector>>(computation_variables);
306  auto& d_cartesian_lapse =
307  get<::Tags::deriv<gr::Tags::Lapse<DataVector>, tmpl::size_t<3>,
308  ::Frame::Inertial>>(computation_variables);
309  auto& dt_cartesian_lapse =
310  get<::Tags::dt<gr::Tags::Lapse<DataVector>>>(computation_variables);
311  cartesian_lapse_and_derivatives_from_unnormalized_spec_modes(
312  make_not_null(&cartesian_lapse), make_not_null(&d_cartesian_lapse),
313  make_not_null(&dt_cartesian_lapse),
314  make_not_null(&interpolation_modal_buffer),
315  make_not_null(&interpolation_buffer), make_not_null(&eth_buffer),
316  lapse_coefficients, dr_lapse_coefficients, dt_lapse_coefficients,
317  inverse_cartesian_to_spherical_jacobian, radial_correction_factor, l_max);
318 
319  auto& phi = get<GeneralizedHarmonic::Tags::Phi<3, ::Frame::Inertial>>(
320  computation_variables);
321  auto& dt_spacetime_metric = get<
323  computation_variables);
324  auto& spacetime_metric =
325  get<gr::Tags::SpacetimeMetric<3, ::Frame::Inertial, DataVector>>(
326  computation_variables);
328  make_not_null(&phi), cartesian_lapse, d_cartesian_lapse, cartesian_shift,
329  d_cartesian_shift, cartesian_spatial_metric, d_cartesian_spatial_metric);
331  make_not_null(&dt_spacetime_metric), cartesian_lapse, dt_cartesian_lapse,
332  cartesian_shift, dt_cartesian_shift, cartesian_spatial_metric,
333  dt_cartesian_spatial_metric);
335  cartesian_shift, cartesian_spatial_metric);
336 
337  auto& dt_worldtube_normal =
338  get<::Tags::dt<Tags::detail::WorldtubeNormal>>(computation_variables);
339  auto& worldtube_normal =
340  get<Tags::detail::WorldtubeNormal>(computation_variables);
341  worldtube_normal_and_derivatives(
342  make_not_null(&worldtube_normal), make_not_null(&dt_worldtube_normal),
343  cos_phi, cos_theta, spacetime_metric, dt_spacetime_metric, sin_phi,
344  sin_theta, inverse_spatial_metric);
345 
346  auto& du_null_l = get<::Tags::dt<Tags::detail::NullL>>(computation_variables);
347  auto& null_l = get<Tags::detail::NullL>(computation_variables);
348  null_vector_l_and_derivatives(
349  make_not_null(&du_null_l), make_not_null(&null_l), dt_worldtube_normal,
350  dt_cartesian_lapse, dt_spacetime_metric, dt_cartesian_shift,
351  cartesian_lapse, spacetime_metric, cartesian_shift, worldtube_normal);
352 
353  // pass to the next step that is common between the 'modal' input and 'GH'
354  // input strategies
355  detail::create_bondi_boundary_data(
356  bondi_boundary_data, make_not_null(&computation_variables),
357  make_not_null(&derivative_buffers), dt_spacetime_metric, phi,
358  spacetime_metric, null_l, du_null_l, cartesian_to_spherical_jacobian,
359  l_max, extraction_radius);
360 }
361 } // namespace Cce
std::integral_constant
Frame::Inertial
Definition: IndexType.hpp:44
gr::Tags::SpatialMetric
Definition: Tags.hpp:26
get
constexpr Tag::type & get(Variables< TagList > &v) noexcept
Return Tag::type pointing into the contiguous array.
Definition: Variables.hpp:639
DeterminantAndInverse.hpp
Tags::SpinWeighted
Given a Tag with a type of Tensor<VectorType, ...>, acts as a new version of the tag with type of Ten...
Definition: Tags.hpp:56
SpinWeighted
Make a spin-weighted type T with spin-weight Spin. Mathematical operators are restricted to addition,...
Definition: SpinWeighted.hpp:24
Cce::create_bondi_boundary_data_from_unnormalized_spec_modes
void create_bondi_boundary_data_from_unnormalized_spec_modes(const gsl::not_null< Variables< TagList > * > bondi_boundary_data, const tnsr::ii< ComplexModalVector, 3 > &spatial_metric_coefficients, const tnsr::ii< ComplexModalVector, 3 > &dt_spatial_metric_coefficients, const tnsr::ii< ComplexModalVector, 3 > &dr_spatial_metric_coefficients, const tnsr::I< ComplexModalVector, 3 > &shift_coefficients, const tnsr::I< ComplexModalVector, 3 > &dt_shift_coefficients, const tnsr::I< ComplexModalVector, 3 > &dr_shift_coefficients, const Scalar< ComplexModalVector > &lapse_coefficients, const Scalar< ComplexModalVector > &dt_lapse_coefficients, const Scalar< ComplexModalVector > &dr_lapse_coefficients, const double extraction_radius, const size_t l_max) noexcept
Process the worldtube data from modal metric components and derivatives with incorrectly normalized r...
Definition: SpecBoundaryData.hpp:156
DataBox.hpp
cstddef
Tags::spacetime_deriv
Prefix indicating spacetime derivatives.
Definition: PartialDerivatives.hpp:76
gr::Tags::InverseSpacetimeMetric
Definition: Tags.hpp:21
gr::Tags::SpacetimeMetric
Definition: Tags.hpp:17
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
gr::time_derivative_of_spacetime_metric
void time_derivative_of_spacetime_metric(gsl::not_null< tnsr::aa< DataType, SpatialDim, Frame > * > dt_spacetime_metric, 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) noexcept
Computes the time derivative of the spacetime metric from spatial metric, lapse, shift,...
Variables.hpp
GeneralizedHarmonic::Tags::Phi
Auxiliary variable which is analytically the spatial derivative of the spacetime metric.
Definition: Tags.hpp:40
Tags::dt
Prefix indicating a time derivative.
Definition: Prefixes.hpp:29
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
Cce
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: BoundaryComputeAndSendToEvolution.hpp:28
Tags::TempTensor
Definition: TempTensor.hpp:21
Gsl.hpp
Cce::Frame::RadialNull
The frame for the spherical metric in which the radial coordinate is an affine parameter along outwar...
Definition: BoundaryDataTags.hpp:21
TypeAliases.hpp
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.
Tags::deriv
Prefix indicating spatial derivatives.
Definition: PartialDerivatives.hpp:53
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
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
Spectral::Swsh::number_of_swsh_collocation_points
constexpr size_t number_of_swsh_collocation_points(const size_t l_max) noexcept
Convenience function for determining the number of spin-weighted spherical harmonic collocation value...
Definition: SwshCollocation.hpp:25