SpECTRE Documentation Coverage Report
Current view: top level - Evolution/Systems/ScalarWave - Characteristics.cpp Hit Total Coverage
Commit: b1342d46f40e2d46bbd11d0cef68fd973031a24b Lines: 4 10 40.0 %
Date: 2020-09-24 20:24:42
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 "Evolution/Systems/ScalarWave/Characteristics.hpp"
       5             : 
       6             : #include <array>
       7             : 
       8             : #include "DataStructures/Tensor/EagerMath/DotProduct.hpp"
       9             : #include "DataStructures/Tensor/Tensor.hpp"
      10             : #include "DataStructures/Variables.hpp"  // IWYU pragma: keep
      11             : #include "Utilities/ContainerHelpers.hpp"
      12             : #include "Utilities/GenerateInstantiations.hpp"
      13             : #include "Utilities/Gsl.hpp"
      14             : #include "Utilities/TMPL.hpp"
      15             : 
      16           1 : namespace ScalarWave {
      17             : template <size_t Dim>
      18           0 : void characteristic_speeds(
      19             :     const gsl::not_null<std::array<DataVector, 4>*> char_speeds,
      20             :     const tnsr::i<DataVector, Dim, Frame::Inertial>&
      21             :         unit_normal_one_form) noexcept {
      22             :   destructive_resize_components(char_speeds,
      23             :                                 get<0>(unit_normal_one_form).size());
      24             :   (*char_speeds)[0] = 0.;   // v(VPsi)
      25             :   (*char_speeds)[1] = 0.;   // v(VZero)
      26             :   (*char_speeds)[2] = 1.;   // v(VPlus)
      27             :   (*char_speeds)[3] = -1.;  // v(VMinus)
      28             : }
      29             : 
      30             : template <size_t Dim>
      31           1 : std::array<DataVector, 4> characteristic_speeds(
      32             :     const tnsr::i<DataVector, Dim, Frame::Inertial>&
      33             :         unit_normal_one_form) noexcept {
      34             :   auto char_speeds = make_with_value<std::array<DataVector, 4>>(
      35             :       get<0>(unit_normal_one_form), 0.);
      36             :   characteristic_speeds(make_not_null(&char_speeds), unit_normal_one_form);
      37             :   return char_speeds;
      38             : }
      39             : 
      40             : template <size_t Dim>
      41           0 : void characteristic_fields(
      42             :     const gsl::not_null<Variables<
      43             :         tmpl::list<Tags::VPsi, Tags::VZero<Dim>, Tags::VPlus, Tags::VMinus>>*>
      44             :         char_fields,
      45             :     const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& psi,
      46             :     const Scalar<DataVector>& pi,
      47             :     const tnsr::i<DataVector, Dim, Frame::Inertial>& phi,
      48             :     const tnsr::i<DataVector, Dim, Frame::Inertial>&
      49             :         unit_normal_one_form) noexcept {
      50             :   if (UNLIKELY(char_fields->number_of_grid_points() != get(psi).size())) {
      51             :     char_fields->initialize(get(psi).size());
      52             :   }
      53             :   // Compute phi_dot_normal = n^i \Phi_{i} = \sum_i n_i \Phi_{i}
      54             :   // (we use normal_one_form and normal_vector interchangeably in flat space)
      55             :   const auto phi_dot_normal = dot_product(unit_normal_one_form, phi);
      56             : 
      57             :   // Eq.(34) of Holst+ (2004) for VZero
      58             :   for (size_t i = 0; i < Dim; ++i) {
      59             :     get<Tags::VZero<Dim>>(*char_fields).get(i) =
      60             :         phi.get(i) - unit_normal_one_form.get(i) * get(phi_dot_normal);
      61             :   }
      62             : 
      63             :   // Eq.(33) of Holst+ (2004) for VPsi
      64             :   get<Tags::VPsi>(*char_fields) = psi;
      65             : 
      66             :   // Eq.(35) of Holst+ (2004) for VPlus and VMinus
      67             :   get(get<Tags::VPlus>(*char_fields)) =
      68             :       get(pi) + get(phi_dot_normal) - get(gamma_2) * get(psi);
      69             :   get(get<Tags::VMinus>(*char_fields)) =
      70             :       get(pi) - get(phi_dot_normal) - get(gamma_2) * get(psi);
      71             : }
      72             : 
      73             : template <size_t Dim>
      74             : Variables<tmpl::list<Tags::VPsi, Tags::VZero<Dim>, Tags::VPlus, Tags::VMinus>>
      75           1 : characteristic_fields(const Scalar<DataVector>& gamma_2,
      76             :                       const Scalar<DataVector>& psi,
      77             :                       const Scalar<DataVector>& pi,
      78             :                       const tnsr::i<DataVector, Dim, Frame::Inertial>& phi,
      79             :                       const tnsr::i<DataVector, Dim, Frame::Inertial>&
      80             :                           unit_normal_one_form) noexcept {
      81             :   Variables<tmpl::list<Tags::VPsi, Tags::VZero<Dim>, Tags::VPlus, Tags::VMinus>>
      82             :       char_fields(get_size(get(gamma_2)));
      83             :   characteristic_fields(make_not_null(&char_fields), gamma_2, psi, pi, phi,
      84             :                         unit_normal_one_form);
      85             :   return char_fields;
      86             : }
      87             : 
      88             : template <size_t Dim>
      89           0 : void evolved_fields_from_characteristic_fields(
      90             :     const gsl::not_null<Variables<tmpl::list<Psi, Pi, Phi<Dim>>>*>
      91             :         evolved_fields,
      92             :     const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& v_psi,
      93             :     const tnsr::i<DataVector, Dim, Frame::Inertial>& v_zero,
      94             :     const Scalar<DataVector>& v_plus, const Scalar<DataVector>& v_minus,
      95             :     const tnsr::i<DataVector, Dim, Frame::Inertial>&
      96             :         unit_normal_one_form) noexcept {
      97             :   if (UNLIKELY(evolved_fields->number_of_grid_points() != get(v_psi).size())) {
      98             :     evolved_fields->initialize(get(v_psi).size());
      99             :   }
     100             :   // Eq.(36) of Holst+ (2004) for Psi
     101             :   get<Psi>(*evolved_fields) = v_psi;
     102             : 
     103             :   // Eq.(37) - (38) of Holst+ (2004) for Pi and Phi
     104             :   get<Pi>(*evolved_fields).get() =
     105             :       0.5 * (get(v_plus) + get(v_minus)) + get(gamma_2) * get(v_psi);
     106             :   for (size_t i = 0; i < Dim; ++i) {
     107             :     get<Phi<Dim>>(*evolved_fields).get(i) =
     108             :         0.5 * (get(v_plus) - get(v_minus)) * unit_normal_one_form.get(i) +
     109             :         v_zero.get(i);
     110             :   }
     111             : }
     112             : 
     113             : template <size_t Dim>
     114             : Variables<tmpl::list<Psi, Pi, Phi<Dim>>>
     115           1 : evolved_fields_from_characteristic_fields(
     116             :     const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& v_psi,
     117             :     const tnsr::i<DataVector, Dim, Frame::Inertial>& v_zero,
     118             :     const Scalar<DataVector>& v_plus, const Scalar<DataVector>& v_minus,
     119             :     const tnsr::i<DataVector, Dim, Frame::Inertial>&
     120             :         unit_normal_one_form) noexcept {
     121             :   Variables<tmpl::list<Psi, Pi, Phi<Dim>>> evolved_fields(
     122             :       get_size(get(gamma_2)));
     123             :   evolved_fields_from_characteristic_fields(make_not_null(&evolved_fields),
     124             :                                             gamma_2, v_psi, v_zero, v_plus,
     125             :                                             v_minus, unit_normal_one_form);
     126             :   return evolved_fields;
     127             : }
     128             : }  // namespace ScalarWave
     129             : 
     130           0 : #define DIM(data) BOOST_PP_TUPLE_ELEM(0, data)
     131             : 
     132           0 : #define INSTANTIATE(_, data)                                                   \
     133             :   template void ScalarWave::characteristic_speeds(                             \
     134             :       const gsl::not_null<std::array<DataVector, 4>*> char_speeds,             \
     135             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>&                   \
     136             :           unit_normal_one_form) noexcept;                                      \
     137             :   template std::array<DataVector, 4> ScalarWave::characteristic_speeds(        \
     138             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>&                   \
     139             :           unit_normal_one_form) noexcept;                                      \
     140             :   template struct ScalarWave::Tags::CharacteristicSpeedsCompute<DIM(data)>;    \
     141             :   template void ScalarWave::characteristic_fields(                             \
     142             :       const gsl::not_null<Variables<tmpl::list<                                \
     143             :           ScalarWave::Tags::VPsi, ScalarWave::Tags::VZero<DIM(data)>,          \
     144             :           ScalarWave::Tags::VPlus, ScalarWave::Tags::VMinus>>*>                \
     145             :           char_fields,                                                         \
     146             :       const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& psi,        \
     147             :       const Scalar<DataVector>& pi,                                            \
     148             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>& phi,              \
     149             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>&                   \
     150             :           unit_normal_one_form) noexcept;                                      \
     151             :   template Variables<                                                          \
     152             :       tmpl::list<ScalarWave::Tags::VPsi, ScalarWave::Tags::VZero<DIM(data)>,   \
     153             :                  ScalarWave::Tags::VPlus, ScalarWave::Tags::VMinus>>           \
     154             :   ScalarWave::characteristic_fields(                                           \
     155             :       const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& psi,        \
     156             :       const Scalar<DataVector>& pi,                                            \
     157             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>& phi,              \
     158             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>&                   \
     159             :           unit_normal_one_form) noexcept;                                      \
     160             :   template struct ScalarWave::Tags::CharacteristicFieldsCompute<DIM(data)>;    \
     161             :   template void ScalarWave::evolved_fields_from_characteristic_fields(         \
     162             :       const gsl::not_null<Variables<tmpl::list<                                \
     163             :           ScalarWave::Psi, ScalarWave::Pi, ScalarWave::Phi<DIM(data)>>>*>      \
     164             :           evolved_fields,                                                      \
     165             :       const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& v_psi,      \
     166             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>& v_zero,           \
     167             :       const Scalar<DataVector>& v_plus, const Scalar<DataVector>& v_minus,     \
     168             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>&                   \
     169             :           unit_normal_one_form) noexcept;                                      \
     170             :   template Variables<                                                          \
     171             :       tmpl::list<ScalarWave::Psi, ScalarWave::Pi, ScalarWave::Phi<DIM(data)>>> \
     172             :   ScalarWave::evolved_fields_from_characteristic_fields(                       \
     173             :       const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& v_psi,      \
     174             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>& v_zero,           \
     175             :       const Scalar<DataVector>& v_plus, const Scalar<DataVector>& v_minus,     \
     176             :       const tnsr::i<DataVector, DIM(data), Frame::Inertial>&                   \
     177             :           unit_normal_one_form) noexcept;                                      \
     178             :   template struct ScalarWave::Tags::                                           \
     179             :       EvolvedFieldsFromCharacteristicFieldsCompute<DIM(data)>;
     180             : 
     181             : GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3))
     182             : 
     183             : #undef INSTANTIATE
     184             : #undef DIM

Generated by: LCOV version 1.14