Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boost to KerrSchild #5610

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ target_link_libraries(
GeneralRelativity
Interpolation
Serialization
SpecialRelativity
)

add_subdirectory(Python)

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ tnsr::ii<DataType, SpatialDim, Frame> time_derivative_of_spatial_metric(
extrinsic_curvature);

GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3), (double, DataVector),
(Frame::Grid, Frame::Inertial))
(Frame::Grid, Frame::Distorted, Frame::Inertial))

#undef DIM
#undef DTYPE
Expand Down
102 changes: 101 additions & 1 deletion src/PointwiseFunctions/SpecialRelativity/LorentzBoostMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "PointwiseFunctions/SpecialRelativity/LorentzBoostMatrix.hpp"

#include <array>
#include <cmath>
#include <cstddef>
#include <limits>
Expand Down Expand Up @@ -58,6 +59,75 @@ void lorentz_boost_matrix(
(*boost_matrix).get(i + 1, i + 1) += 1.0;
}
}

template <size_t SpatialDim>
tnsr::Ab<double, SpatialDim, Frame::NoFrame> lorentz_boost_matrix(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this a symmetric tensor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I? This has one upper and one lower index

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not currently supported.

const std::array<double, SpatialDim>& velocity) {
tnsr::I<double, SpatialDim, Frame::NoFrame> velocity_as_tensor(velocity);
return lorentz_boost_matrix(velocity_as_tensor);
}

template <typename DataType, size_t SpatialDim, typename Frame>
void lorentz_boost(
const gsl::not_null<tnsr::I<DataType, SpatialDim, Frame>*> result,
const tnsr::I<DataType, SpatialDim, Frame>& vector,
const double vector_component_0,
const std::array<double, SpatialDim>& velocity) {
if (velocity == make_array<SpatialDim>(0.)) {
*result = vector;
return;
}
// Inverse matrix with respect to the boost applied to one forms
const auto boost_matrix = lorentz_boost_matrix(-velocity);
for (size_t i = 0; i < SpatialDim; ++i) {
result->get(i) = boost_matrix.get(i + 1, 0) * vector_component_0;
for (size_t j = 0; j < SpatialDim; ++j) {
result->get(i) += boost_matrix.get(i + 1, j + 1) * vector.get(j);
}
}
}

template <typename DataType, size_t SpatialDim, typename Frame>
void lorentz_boost(
const gsl::not_null<tnsr::a<DataType, SpatialDim, Frame>*> result,
const tnsr::a<DataType, SpatialDim, Frame>& one_form,
const std::array<double, SpatialDim>& velocity) {
if (velocity == make_array<SpatialDim>(0.)) {
*result = one_form;
return;
}
const auto boost_matrix = lorentz_boost_matrix(velocity);
for (size_t i = 0; i < SpatialDim + 1; ++i) {
result->get(i) = 0.;
for (size_t j = 0; j < SpatialDim + 1; ++j) {
result->get(i) += boost_matrix.get(i, j) * one_form.get(j);
}
}
}

template <typename DataType, size_t SpatialDim, typename Frame>
void lorentz_boost(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a sensible situation where different indices of a tensor would be boosted with different velocities? Is this generalization necessary?

Copy link
Contributor Author

@guilara guilara Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also inherited from the implementation in SpEC, maybe to save overloads when boosting tensors with mixed up/down indices. Then one just changes the sign of the velocity in the relevant entry.

const gsl::not_null<tnsr::ab<DataType, SpatialDim, Frame>*> result,
const tnsr::ab<DataType, SpatialDim, Frame>& tensor,
const std::array<double, SpatialDim>& velocity) {
if (velocity == make_array<SpatialDim>(0.)) {
*result = tensor;
return;
}
const auto boost_matrix = lorentz_boost_matrix(velocity);
for (size_t i = 0; i < SpatialDim + 1; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] tenex::evaluate<ti::a, ti::b>(result, boost_matrix_1(ti::C, ti::a) * boost_matrix_2(ti::D, ti::b) * tensor(ti::c, ti::d) is quite concise.

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.get(i, j) * boost_matrix.get(k, l) *
tensor.get(j, l);
}
}
}
}
}

} // namespace sr

// Explicit Instantiations
Expand All @@ -70,10 +140,40 @@ void lorentz_boost_matrix(
template void sr::lorentz_boost_matrix( \
gsl::not_null<tnsr::Ab<double, DIM(data), Frame::NoFrame>*> \
boost_matrix, \
const tnsr::I<double, DIM(data), Frame::NoFrame>& velocity);
const tnsr::I<double, DIM(data), Frame::NoFrame>& velocity); \
template tnsr::Ab<double, DIM(data), Frame::NoFrame> \
sr::lorentz_boost_matrix(const std::array<double, DIM(data)>& velocity);

GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3))

#undef DIM
#undef INSTANTIATE

#define DIM(data) BOOST_PP_TUPLE_ELEM(0, data)
#define DTYPE(data) BOOST_PP_TUPLE_ELEM(1, data)
#define FRAME(data) BOOST_PP_TUPLE_ELEM(2, data)

#define INSTANTIATE(_, data) \
template void sr::lorentz_boost( \
const gsl::not_null<tnsr::I<DTYPE(data), DIM(data), FRAME(data)>*> \
result, \
const tnsr::I<DTYPE(data), DIM(data), FRAME(data)>& one_form, \
const double one_form_component_0, \
const std::array<double, DIM(data)>& velocity); \
template void sr::lorentz_boost( \
const gsl::not_null<tnsr::a<DTYPE(data), DIM(data), FRAME(data)>*> \
result, \
const tnsr::a<DTYPE(data), DIM(data), FRAME(data)>& one_form, \
const std::array<double, DIM(data)>& velocity); \
template void sr::lorentz_boost( \
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);

GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3), (double, DataVector),
(Frame::Grid, Frame::Distorted, Frame::Inertial))

#undef DIM
#undef DTYPE
#undef FRAME
Expand Down
43 changes: 42 additions & 1 deletion src/PointwiseFunctions/SpecialRelativity/LorentzBoostMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

#pragma once

#include <array>
#include <cstddef>

#include "DataStructures/Tensor/TypeAliases.hpp"
#include "DataStructures/Tensor/Tensor.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/MakeArray.hpp"

/// \cond
namespace gsl {
Expand Down Expand Up @@ -53,5 +56,43 @@ template <size_t SpatialDim>
void lorentz_boost_matrix(
gsl::not_null<tnsr::Ab<double, SpatialDim, Frame::NoFrame>*> boost_matrix,
const tnsr::I<double, SpatialDim, Frame::NoFrame>& velocity);

template <size_t SpatialDim>
tnsr::Ab<double, SpatialDim, Frame::NoFrame> lorentz_boost_matrix(
const std::array<double, SpatialDim>& velocity);
/// @}

/// @{
/*!
* \ingroup SpecialRelativityGroup
* \brief Apply a Lorentz boost to the spatial part of a vector.
* \details This requires passing the 0th component of the vector as an
* additional argument.
*/
template <typename DataType, size_t SpatialDim, typename Frame>
void lorentz_boost(gsl::not_null<tnsr::I<DataType, SpatialDim, Frame>*> result,
const tnsr::I<DataType, SpatialDim, Frame>& vector,
double vector_component_0,
const std::array<double, SpatialDim>& velocity);

/*!
* \brief Apply a Lorentz boost to a one form.
*/
template <typename DataType, size_t SpatialDim, typename Frame>
void lorentz_boost(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, there would be one implementation that works for a generic tensor type so do not have all of these overloads. If you think that would be overkill for now, maybe just add a comment that this can be done in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I wouldn't want to delay this anymore. Added comment.

gsl::not_null<tnsr::a<DataType, SpatialDim, Frame>*> result,
const tnsr::a<DataType, SpatialDim, Frame>& one_form,
const std::array<double, SpatialDim>& velocity);

/*!
* \brief Apply a Lorentz boost to each component of a rank-2 tensor with
* lower or covariant indices.
* \note In the future we might want to write a single function capable to 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);
/// @}
} // namespace sr
2 changes: 2 additions & 0 deletions support/Pipelines/Bbh/InitialData.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Background: &background
- {{ DimensionlessSpinLeft_y }}
- {{ DimensionlessSpinLeft_z }}
Center: [0., 0., 0.]
Velocity: [0., 0., 0.]
ObjectRight: &kerr_right
KerrSchild:
Mass: &mass_right {{ MassRight }}
Expand All @@ -42,6 +43,7 @@ Background: &background
- {{ DimensionlessSpinRight_y }}
- {{ DimensionlessSpinRight_z }}
Center: [0., 0., 0.]
Velocity: [0., 0., 0.]
AngularVelocity: {{ OrbitalAngularVelocity }}
Expansion: {{ RadialExpansionVelocity }}
LinearVelocity: [0., 0., 0.]
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/CurvedScalarWave/WorldtubeKerrSchild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ BackgroundSpacetime:
Mass: 1.
Center: [0., 0., 0.]
Spin: [0., 0., 0.]
Velocity: [0., 0., 0.]

ResourceInfo:
AvoidGlobalProc0: false
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/GeneralizedHarmonic/KerrSchild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ InitialData: &InitialData
Mass: 1.0
Spin: [0.0, 0.0, 0.0]
Center: &Center [0.0, 0.0, 0.0]
Velocity: [0.0, 0.0, 0.0]

DomainCreator:
Sphere:
Expand Down
2 changes: 2 additions & 0 deletions tests/InputFiles/Xcts/BinaryBlackHole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ Background: &background
Mass: 0.4229
Spin: [0., 0., 0.]
Center: [0., 0., 0.]
Velocity: [0., 0., 0.]
ObjectRight: &kerr_right
KerrSchild:
Mass: 0.4229
Spin: [0., 0., 0.]
Center: [0., 0., 0.]
Velocity: [0., 0., 0.]
AngularVelocity: 0.0144
Expansion: 0.
LinearVelocity: [0., 0., 0.]
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Xcts/KerrSchild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Background: &solution
Mass: &KerrMass 1.
Spin: &KerrSpin [0., 0., 0.6]
Center: &KerrCenter [0., 0., 0.]
Velocity: [0., 0., 0.]

InitialGuess: Flatness

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ void test_consistency_with_kerr(const bool compute_expansion) {
std::array<double, 3> rotation =
-0.5 * dimensionless_spin / horizon_kerrschild_radius;
CAPTURE(rotation);
const KerrSchild solution{mass, dimensionless_spin, {{0., 0., 0.}}};
const KerrSchild solution{
mass, dimensionless_spin, {{0., 0., 0.}}, {{0., 0., 0.}}};
const ApparentHorizon<Xcts::Geometry::Curved> kerr_horizon{
center, rotation, std::make_unique<KerrSchild>(solution),
// Check with and without the negative-expansion condition. Either the
Expand Down Expand Up @@ -579,8 +580,8 @@ SPECTRE_TEST_CASE("Unit.Xcts.BoundaryConditions.ApparentHorizon",
" Lapse: Auto\n"
" NegativeExpansion: None\n");
test_creation({{1., 2., 3.}}, {{0.1, 0.2, 0.3}},
{{2.3, {{0.4, 0.5, 0.6}}, {{0., 0., 0.}}}},
{{3.4, {{0.3, 0.2, 0.1}}, {{0., 0., 0.}}}},
{{2.3, {{0.4, 0.5, 0.6}}, {{0., 0., 0.}}, {{0., 0., 0.}}}},
{{3.4, {{0.3, 0.2, 0.1}}, {{0., 0., 0.}}, {{0., 0., 0.}}}},
"ApparentHorizon:\n"
" Center: [1., 2., 3.]\n"
" Rotation: [0.1, 0.2, 0.3]\n"
Expand All @@ -589,11 +590,13 @@ SPECTRE_TEST_CASE("Unit.Xcts.BoundaryConditions.ApparentHorizon",
" Mass: 2.3\n"
" Spin: [0.4, 0.5, 0.6]\n"
" Center: [0., 0., 0.]\n"
" Velocity: [0., 0., 0.]\n"
" NegativeExpansion:\n"
" KerrSchild:\n"
" Mass: 3.4\n"
" Spin: [0.3, 0.2, 0.1]\n"
" Center: [0., 0., 0.]\n");
" Center: [0., 0., 0.]\n"
" Velocity: [0., 0., 0.]\n");
test_with_random_values();
test_consistency_with_kerr(false);
test_consistency_with_kerr(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ SPECTRE_TEST_CASE("Unit.Evolution.Systems.CurvedScalarWave.BackgroundSpacetime",
const auto ks_background =
gr::Solutions::KerrSchild(0.5, {{0.1, 0.2, 0.3}}, {{1.0, 3.0, 2.0}});
const std::string& ks_option_string =
"Mass: 0.5\nSpin: [0.1,0.2,0.3]\nCenter: [1.0,3.0,2.0]";
"Mass: 0.5\nSpin: [0.1,0.2,0.3]\nCenter: [1.0,3.0,2.0]\nVelocity: "
"[0.0,0.0,0.0]";
test_option_parsing(ks_background, ks_option_string);

const auto spherical_ks_background = gr::Solutions::SphericalKerrSchild(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ SPECTRE_TEST_CASE("Unit.Evolution.Systems.Gh.NumericInitialData",
"GeneralizedHarmonic(KerrSchild):\n"
" Mass: 1.\n"
" Spin: [0, 0, 0]\n"
" Center: [0, 0, 0]",
" Center: [0, 0, 0]\n"
" Velocity: [0, 0, 0]",
false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ void test_ks(const Mesh<3>& mesh) {
" GeneralizedHarmonic(KerrSchild):\n"
" Mass: 1.2\n"
" Spin: [0.1, 0.2, 0.3]\n"
" Center: [-0.1, -0.2, -0.4]\n")
" Center: [-0.1, -0.2, -0.4]\n"
" Velocity: [0.0, 0.0, 0.0]\n")
->get_clone());
CHECK_FALSE(gauge_condition->is_harmonic());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,5 +426,55 @@ void verify_consistency(const Solution& solution, const double time,
derivative_delta),
derivative_approx);
}

/// Check the consistency of quantities dependent on other metric quantities
/// returned by a solution. This includes checking pointwise relations such as
/// consistency of the metric and inverse and comparing returned and
/// numerical derivatives.
template <typename Solution, typename Frame>
void verify_spatial_consistency(const Solution& solution, const double time,
const tnsr::I<double, 3, Frame>& position,
const double derivative_delta,
const double derivative_tolerance) {
using Lapse = gr::Tags::Lapse<double>;
using Shift = gr::Tags::Shift<double, 3, Frame>;
using SpatialMetric = gr::Tags::SpatialMetric<double, 3, Frame>;
using SqrtDetSpatialMetric = gr::Tags::SqrtDetSpatialMetric<double>;
using InverseSpatialMetric = gr::Tags::InverseSpatialMetric<double, 3, Frame>;
using ExtrinsicCurvature = gr::Tags::ExtrinsicCurvature<double, 3, Frame>;
using tags =
tmpl::list<SpatialMetric, SqrtDetSpatialMetric, InverseSpatialMetric,
ExtrinsicCurvature, Lapse, Shift, detail::deriv<Shift, Frame>,
Tags::dt<SpatialMetric>, detail::deriv<SpatialMetric, Frame>,
Tags::dt<Lapse>, Tags::dt<Shift>, detail::deriv<Lapse, Frame>>;

auto derivative_approx = approx.epsilon(derivative_tolerance);

const auto vars = solution.variables(position, time, tags{});

const auto numerical_metric_det_and_inverse =
determinant_and_inverse(get<SpatialMetric>(vars));
CHECK_ITERABLE_APPROX(get(get<SqrtDetSpatialMetric>(vars)),
sqrt(get(numerical_metric_det_and_inverse.first)));
CHECK_ITERABLE_APPROX(get<InverseSpatialMetric>(vars),
numerical_metric_det_and_inverse.second);

CHECK_ITERABLE_CUSTOM_APPROX(
SINGLE_ARG(get<detail::deriv<Lapse, Frame>>(vars)),
detail::space_derivative<Lapse>(solution, position, time,
derivative_delta),
derivative_approx);
CHECK_ITERABLE_CUSTOM_APPROX(
SINGLE_ARG(get<detail::deriv<Shift, Frame>>(vars)),
detail::space_derivative<Shift>(solution, position, time,
derivative_delta),
derivative_approx);
CHECK_ITERABLE_CUSTOM_APPROX(
SINGLE_ARG(get<detail::deriv<SpatialMetric, Frame>>(vars)),
detail::space_derivative<SpatialMetric>(solution, position, time,
derivative_delta),
derivative_approx);
}

} // namespace VerifyGrSolution
} // namespace TestHelpers
Loading
Loading