Skip to content

Commit

Permalink
Add test of boosted spacetime metric
Browse files Browse the repository at this point in the history
  • Loading branch information
guilara committed Feb 21, 2024
1 parent f409711 commit b2532c8
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void KerrSchild::IntermediateComputer<DataType, Frame>::operator()(
// Inverse-boost the first index, because it represents the derivative which
// is given in the boosted frame
sr::lorentz_boost(deriv_null_form_boosted, deriv_null_form,
-solution_.boost_velocity(), -solution_.boost_velocity());
-solution_.boost_velocity());
}

template <typename DataType, typename Frame>
Expand Down
16 changes: 6 additions & 10 deletions src/PointwiseFunctions/SpecialRelativity/LorentzBoostMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,19 @@ template <typename DataType, size_t SpatialDim, typename Frame>
void lorentz_boost(
const gsl::not_null<tnsr::ab<DataType, SpatialDim, Frame>*> result,
const tnsr::ab<DataType, SpatialDim, Frame>& tensor,
const std::array<double, SpatialDim>& velocity_first_index,
const std::array<double, SpatialDim>& velocity_second_index) {
if (velocity_first_index == make_array<SpatialDim>(0.) and
velocity_second_index == make_array<SpatialDim>(0.)) {
const std::array<double, SpatialDim>& velocity) {
if (velocity == make_array<SpatialDim>(0.)) {
*result = tensor;
return;
}
const auto boost_matrix_1 = lorentz_boost_matrix(velocity_first_index);
const auto boost_matrix_2 = lorentz_boost_matrix(velocity_second_index);
const auto boost_matrix = lorentz_boost_matrix(velocity);
for (size_t i = 0; i < SpatialDim + 1; ++i) {
for (size_t k = 0; k < SpatialDim + 1; ++k) {
result->get(i, k) = 0.;
for (size_t j = 0; j < SpatialDim + 1; ++j) {
for (size_t l = 0; l < SpatialDim + 1; ++l) {
result->get(i, k) += boost_matrix_1.get(i, j) *
boost_matrix_2.get(k, l) * tensor.get(j, l);
result->get(i, k) += boost_matrix.get(i, j) * boost_matrix.get(k, l) *
tensor.get(j, l);
}
}
}
Expand Down Expand Up @@ -171,8 +168,7 @@ GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3))
const gsl::not_null<tnsr::ab<DTYPE(data), DIM(data), FRAME(data)>*> \
result, \
const tnsr::ab<DTYPE(data), DIM(data), FRAME(data)>& tensor, \
const std::array<double, DIM(data)>& velocity_first_index, \
const std::array<double, DIM(data)>& velocity_second_index);
const std::array<double, DIM(data)>& velocity);

GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3), (double, DataVector),
(Frame::Grid, Frame::Distorted, Frame::Inertial))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ void lorentz_boost(
* a tensor of arbitrary rank.
*/
template <typename DataType, size_t SpatialDim, typename Frame>
void lorentz_boost(
gsl::not_null<tnsr::ab<DataType, SpatialDim, Frame>*> result,
const tnsr::ab<DataType, SpatialDim, Frame>& tensor,
const std::array<double, SpatialDim>& velocity_first_index,
const std::array<double, SpatialDim>& velocity_second_index);
void lorentz_boost(gsl::not_null<tnsr::ab<DataType, SpatialDim, Frame>*> result,
const tnsr::ab<DataType, SpatialDim, Frame>& tensor,
const std::array<double, SpatialDim>& velocity);
/// @}
} // namespace sr
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "NumericalAlgorithms/Spectral/Quadrature.hpp"
#include "PointwiseFunctions/AnalyticSolutions/GeneralRelativity/KerrSchild.hpp"
#include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
#include "PointwiseFunctions/SpecialRelativity/LorentzBoostMatrix.hpp"
#include "Utilities/ConstantExpressions.hpp"
#include "Utilities/MakeWithValue.hpp"
#include "Utilities/TMPL.hpp"
Expand Down Expand Up @@ -403,6 +404,83 @@ void test_boosted_for_zero_velocity(const DataType& used_for_size) {
});
}

template <typename Frame, typename DataType>
void test_boosted_spacetime_metric(const DataType& used_for_size) {
// Test that the extrinsic curvature of the boosted solution indeed
// corresponds to the boosted extrinsic curvature tensor

const auto x = spatial_coords<Frame>(used_for_size);
const double t = 0.0;

// KerrSchild solution
const double mass = 1.0;
const std::array<double, 3> spin{{0.0, 0.0, 0.0}};
const std::array<double, 3> center{{0.0, 0.0, 0.0}};
gr::Solutions::KerrSchild solution(mass, spin, center);

// Boosted KerrSchild solution
const std::array<double, 3> velocity{{0.5, 0.0, 0.0}};
gr::Solutions::KerrSchild boosted_solution(mass, spin, center, velocity);

// Need to evaluate at the boosted coordinates
// Boost coordinates
tnsr::I<DataType, 3, Frame> x_boosted;
sr::lorentz_boost(make_not_null(&x_boosted), x, 0., -velocity);
const auto vars = solution.variables(
x_boosted, t,
typename gr::Solutions::KerrSchild::tags<DataType, Frame>{});
const auto& lapse = get<typename gr::Tags::Lapse<DataType>>(vars);
const auto& shift = get<typename gr::Tags::Shift<DataType, 3, Frame>>(vars);
const auto& spatial_metric =
get<typename gr::Tags::SpatialMetric<DataType, 3, Frame>>(vars);

// Compute spacetime metric
tnsr::aa<DataType, 3, Frame> spacetime_metric;
gr::spacetime_metric(make_not_null(&spacetime_metric), lapse, shift,
spatial_metric);

auto spacetime_metric_as_asymmetric_tensor =
make_with_value<tnsr::ab<DataType, 3, Frame>>(x, 0.0);
for (size_t a = 0; a < 4; ++a) {
for (size_t b = 0; b < 4; ++b) {
spacetime_metric_as_asymmetric_tensor.get(a, b) =
spacetime_metric.get(a, b);
}
}

tnsr::ab<DataType, 3, Frame> expected_boosted_spacetime_metric;
sr::lorentz_boost(make_not_null(&expected_boosted_spacetime_metric),
spacetime_metric_as_asymmetric_tensor, -velocity);

// Boosted metric quantities
const auto boosted_vars = boosted_solution.variables(
x, t, typename gr::Solutions::KerrSchild::tags<DataType, Frame>{});
const auto& lapse_from_boosted_solution =
get<typename gr::Tags::Lapse<DataType>>(boosted_vars);
const auto& shift_from_boosted_solution =
get<typename gr::Tags::Shift<DataType, 3, Frame>>(boosted_vars);
const auto& spatial_metric_from_boosted_solution =
get<typename gr::Tags::SpatialMetric<DataType, 3, Frame>>(boosted_vars);

tnsr::aa<DataType, 3, Frame> spacetime_metric_from_boosted_solution;
gr::spacetime_metric(make_not_null(&spacetime_metric_from_boosted_solution),
lapse_from_boosted_solution, shift_from_boosted_solution,
spatial_metric_from_boosted_solution);

auto spacetime_metric_from_boosted_solution_as_asymmetric_tensor =
make_with_value<tnsr::ab<DataType, 3, Frame>>(x, 0.0);
for (size_t a = 0; a < 4; ++a) {
for (size_t b = 0; b < 4; ++b) {
spacetime_metric_from_boosted_solution_as_asymmetric_tensor.get(a, b) =
spacetime_metric_from_boosted_solution.get(a, b);
}
}

CHECK_ITERABLE_APPROX(
expected_boosted_spacetime_metric,
spacetime_metric_from_boosted_solution_as_asymmetric_tensor);
}

void test_serialize() {
gr::Solutions::KerrSchild solution(3.0, {{0.2, 0.3, 0.2}}, {{0.0, 3.0, 4.0}},
{{0.1, 0.2, 0.3}});
Expand Down Expand Up @@ -448,6 +526,7 @@ SPECTRE_TEST_CASE("Unit.PointwiseFunctions.AnalyticSolutions.Gr.KerrSchild",
test_zero_spin_optimization<Frame::Inertial>(0.0);
test_boosted_for_zero_velocity<Frame::Inertial>(DataVector(5));
test_boosted_for_zero_velocity<Frame::Inertial>(0.0);
test_boosted_spacetime_metric<Frame::Inertial, double>(0.0);

test_schwarzschild<Frame::Grid>(DataVector(5));
test_schwarzschild<Frame::Grid>(0.0);
Expand All @@ -460,6 +539,7 @@ SPECTRE_TEST_CASE("Unit.PointwiseFunctions.AnalyticSolutions.Gr.KerrSchild",
test_zero_spin_optimization<Frame::Grid>(0.0);
test_boosted_for_zero_velocity<Frame::Grid>(DataVector(5));
test_boosted_for_zero_velocity<Frame::Grid>(0.0);
test_boosted_spacetime_metric<Frame::Grid, double>(0.0);

CHECK_THROWS_WITH(
[]() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ void test_lorentz_boost_matrix_analytic(const double& velocity_squared) {
}

template <typename DataType, size_t SpatialDim, typename Frame>
void test_lorentz_boost(const std::array<double, SpatialDim> velocity,
const std::array<double, SpatialDim> velocity_2) {
void test_lorentz_boost(const std::array<double, SpatialDim> velocity) {
const DataVector used_for_size{3., 4., 5.};

MAKE_GENERATOR(generator);
Expand Down Expand Up @@ -127,8 +126,7 @@ void test_lorentz_boost(const std::array<double, SpatialDim> velocity,
// We boost it as well, but with possibly another velocity
tnsr::a<DataType, SpatialDim, Frame> boosted_covariant_vector_2;
sr::lorentz_boost<DataType, SpatialDim, Frame>(
make_not_null(&boosted_covariant_vector_2), covariant_vector_2,
velocity_2);
make_not_null(&boosted_covariant_vector_2), covariant_vector_2, velocity);

for (size_t i = 0; i < SpatialDim + 1; ++i) {
for (size_t j = 0; j < SpatialDim + 1; ++j) {
Expand All @@ -139,7 +137,7 @@ void test_lorentz_boost(const std::array<double, SpatialDim> velocity,
}

sr::lorentz_boost<DataType, SpatialDim, Frame>(make_not_null(&boosted_tensor),
tensor, velocity, velocity_2);
tensor, velocity);
CHECK_ITERABLE_APPROX(expected_tensor, boosted_tensor);
}

Expand Down Expand Up @@ -173,6 +171,5 @@ SPECTRE_TEST_CASE(
SPECTRE_TEST_CASE("Unit.PointwiseFunctions.SpecialRelativity.LorentzBoost",
"[PointwiseFunctions][Unit]") {
const std::array<double, 3> velocity{{0.1, -0.4, 0.3}};
const std::array<double, 3> velocity_2{{0.2, -0.1, -0.5}};
test_lorentz_boost<double, 3, Frame::Inertial>(velocity, velocity_2);
test_lorentz_boost<double, 3, Frame::Inertial>(velocity);
}

0 comments on commit b2532c8

Please sign in to comment.