SpECTRE Documentation Coverage Report
Current view: top level - PointwiseFunctions/SpecialRelativity - LorentzBoostMatrix.cpp Hit Total Coverage
Commit: d9f43616963a69a193384e1ff0dc4ca65cff5a4d Lines: 2 4 50.0 %
Date: 2021-01-20 21:07:37
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #include "PointwiseFunctions/SpecialRelativity/LorentzBoostMatrix.hpp"
       5             : 
       6             : #include <cmath>
       7             : #include <cstddef>
       8             : #include <limits>
       9             : 
      10             : #include "DataStructures/Tensor/EagerMath/DotProduct.hpp"
      11             : #include "DataStructures/Tensor/TypeAliases.hpp"
      12             : #include "Utilities/ConstantExpressions.hpp"
      13             : #include "Utilities/GenerateInstantiations.hpp"
      14             : #include "Utilities/Gsl.hpp"
      15             : #include "Utilities/MakeWithValue.hpp"
      16             : 
      17           1 : namespace sr {
      18             : template <size_t SpatialDim>
      19           1 : tnsr::Ab<double, SpatialDim, Frame::NoFrame> lorentz_boost_matrix(
      20             :     const tnsr::I<double, SpatialDim, Frame::NoFrame>& velocity) noexcept {
      21             :   auto boost_matrix =
      22             :       make_with_value<tnsr::Ab<double, SpatialDim, Frame::NoFrame>>(
      23             :           get<0>(velocity), std::numeric_limits<double>::signaling_NaN());
      24             :   lorentz_boost_matrix<SpatialDim>(&boost_matrix, velocity);
      25             :   return boost_matrix;
      26             : }
      27             : 
      28             : template <size_t SpatialDim>
      29           0 : void lorentz_boost_matrix(
      30             :     gsl::not_null<tnsr::Ab<double, SpatialDim, Frame::NoFrame>*> boost_matrix,
      31             :     const tnsr::I<double, SpatialDim, Frame::NoFrame>& velocity) noexcept {
      32             :   const double velocity_squared{get(dot_product(velocity, velocity))};
      33             :   const double lorentz_factor{1.0 / sqrt(1.0 - velocity_squared)};
      34             : 
      35             :   // For the spatial-spatial terms of the boost matrix, we need to compute
      36             :   // a prefactor, which is essentially kinetic energy per mass per velocity
      37             :   // squared. Specifically, the prefactor is
      38             :   //
      39             :   // kinetic_energy_per_v_squared = (lorentz_factor-1.0)/velocity^2
      40             :   //
      41             :   // This is algebraically equivalent to
      42             :   //
      43             :   // kinetic_energy_per_v_squared = lorentz_factor / ((1 + sqrt(1-velocity^2))),
      44             :   //
      45             :   // a form that avoids division by zero as v->0.
      46             : 
      47             :   double kinetic_energy_per_v_squared{square(lorentz_factor) /
      48             :                                       (1.0 + lorentz_factor)};
      49             : 
      50             :   get<0, 0>(*boost_matrix) = lorentz_factor;
      51             :   for (size_t i = 0; i < SpatialDim; ++i) {
      52             :     (*boost_matrix).get(0, i + 1) = velocity.get(i) * lorentz_factor;
      53             :     (*boost_matrix).get(i + 1, 0) = velocity.get(i) * lorentz_factor;
      54             :     for (size_t j = 0; j < SpatialDim; ++j) {
      55             :       (*boost_matrix).get(i + 1, j + 1) =
      56             :           velocity.get(i) * velocity.get(j) * kinetic_energy_per_v_squared;
      57             :     }
      58             :     (*boost_matrix).get(i + 1, i + 1) += 1.0;
      59             :   }
      60             : }
      61             : }  // namespace sr
      62             : 
      63             : // Explicit Instantiations
      64             : /// \cond
      65             : #define DIM(data) BOOST_PP_TUPLE_ELEM(0, data)
      66             : 
      67             : #define INSTANTIATE(_, data)                                                \
      68             :   template tnsr::Ab<double, DIM(data), Frame::NoFrame>                      \
      69             :   sr::lorentz_boost_matrix(                                                 \
      70             :       const tnsr::I<double, DIM(data), Frame::NoFrame>& velocity) noexcept; \
      71             :   template void sr::lorentz_boost_matrix(                                   \
      72             :       gsl::not_null<tnsr::Ab<double, DIM(data), Frame::NoFrame>*>           \
      73             :           boost_matrix,                                                     \
      74             :       const tnsr::I<double, DIM(data), Frame::NoFrame>& velocity) noexcept;
      75             : 
      76             : GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3))
      77             : 
      78             : #undef DIM
      79             : #undef DTYPE
      80             : #undef FRAME
      81             : #undef INSTANTIATE
      82             : /// \endcond

Generated by: LCOV version 1.14