SpECTRE Documentation Coverage Report
Current view: top level - PointwiseFunctions/AnalyticSolutions/GeneralRelativity - GaugeWave.cpp Hit Total Coverage
Commit: 2db722c93a8e9b106e406b439b79c8e05c2057fb Lines: 0 1 0.0 %
Date: 2021-03-03 22:01:00
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/AnalyticSolutions/GeneralRelativity/GaugeWave.hpp"
       5             : 
       6             : #include <cmath>
       7             : #include <cstddef>
       8             : #include <pup.h>  // IWYU pragma: keep
       9             : 
      10             : #include "DataStructures/DataBox/Prefixes.hpp"  // IWYU pragma: keep
      11             : #include "DataStructures/DataVector.hpp"  // IWYU pragma: keep
      12             : #include "DataStructures/Tensor/Tensor.hpp"  // IWYU pragma: keep
      13             : #include "DataStructures/Tensor/TypeAliases.hpp"
      14             : #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
      15             : #include "Utilities/GenerateInstantiations.hpp"
      16             : #include "Utilities/MakeWithValue.hpp"
      17             : #include "Utilities/TMPL.hpp"
      18             : 
      19             : /// \cond
      20             : namespace {
      21             : // compute gauge wave H
      22             : template <typename DataType, size_t Dim>
      23             : DataType gauge_wave_h(const tnsr::I<DataType, Dim>& x, const double t,
      24             :                       const double amplitude,
      25             :                       const double wavelength) noexcept {
      26             :   return {-1.0 * amplitude * sin((get<0>(x) - t) * (2.0 * M_PI / wavelength)) +
      27             :           1.0};
      28             : }
      29             : 
      30             : // compute gauge wave derivH: \partial_x H
      31             : template <typename DataType, size_t Dim>
      32             : DataType gauge_wave_deriv_h(const tnsr::I<DataType, Dim>& x, const double t,
      33             :                             const double amplitude,
      34             :                             const double wavelength) noexcept {
      35             :   return {-1.0 * amplitude * (2.0 * M_PI / wavelength) *
      36             :           cos((get<0>(x) - t) * (2.0 * M_PI / wavelength))};
      37             : }
      38             : }  // namespace
      39             : 
      40             : namespace gr {
      41             : namespace Solutions {
      42             : template <size_t Dim>
      43             : GaugeWave<Dim>::GaugeWave(const double amplitude, const double wavelength,
      44             :                           const Options::Context& context)
      45             :     : amplitude_(amplitude), wavelength_(wavelength) {
      46             :   if (abs(amplitude) >= 1.0) {
      47             :     PARSE_ERROR(context,
      48             :                 "Amplitude must be less than one. Given amplitude: "
      49             :                 << amplitude_);
      50             :   }
      51             :   if (wavelength <= 0.0) {
      52             :     PARSE_ERROR(context,
      53             :                 "Wavelength must be non-negative. Given wavelength: "
      54             :                 << wavelength_);
      55             :   }
      56             : }
      57             : 
      58             : template <size_t Dim>
      59             : void GaugeWave<Dim>::pup(PUP::er& p) noexcept {
      60             :   p | amplitude_;
      61             :   p | wavelength_;
      62             : }
      63             : 
      64             : template <size_t Dim>
      65             : template <typename DataType>
      66             : GaugeWave<Dim>::IntermediateVars<DataType>::IntermediateVars(
      67             :     const double amplitude, const double wavelength,
      68             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x,
      69             :     const double t) noexcept {
      70             :   h = gauge_wave_h(x, t, amplitude, wavelength);
      71             :   dx_h = gauge_wave_deriv_h(x, t, amplitude, wavelength);
      72             :   sqrt_h = sqrt(h);
      73             :   dx_h_over_2_sqrt_h = 0.5 * dx_h / sqrt(h);
      74             : }
      75             : 
      76             : template <size_t Dim>
      77             : template <typename DataType>
      78             : auto GaugeWave<Dim>::variables(
      79             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& /*x*/,
      80             :     const double /*t*/, const IntermediateVars<DataType>& vars,
      81             :     tmpl::list<gr::Tags::Lapse<DataType>> /*meta*/) const noexcept
      82             :     -> tuples::TaggedTuple<gr::Tags::Lapse<DataType>> {
      83             :   return {Scalar<DataType>{vars.sqrt_h}};
      84             : }
      85             : 
      86             : template <size_t Dim>
      87             : template <typename DataType>
      88             : auto GaugeWave<Dim>::variables(
      89             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& /*x*/,
      90             :     const double /*t*/, const IntermediateVars<DataType>& vars,
      91             :     tmpl::list<::Tags::dt<gr::Tags::Lapse<DataType>>> /*meta*/) const noexcept
      92             :     -> tuples::TaggedTuple<::Tags::dt<gr::Tags::Lapse<DataType>>> {
      93             :   return {Scalar<DataType>{-1.0 * vars.dx_h_over_2_sqrt_h}};
      94             : }
      95             : 
      96             : template <size_t Dim>
      97             : template <typename DataType>
      98             : auto GaugeWave<Dim>::variables(
      99             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x, const double /*t*/,
     100             :     const IntermediateVars<DataType>& vars,
     101             :     tmpl::list<DerivLapse<DataType>> /*meta*/) const noexcept
     102             :     -> tuples::TaggedTuple<DerivLapse<DataType>> {
     103             :   // most parts of d_lapse are zero, so make_with_value() here
     104             :   auto d_lapse =
     105             :       make_with_value<tnsr::i<DataType, volume_dim, Frame::Inertial>>(x, 0.0);
     106             :   get<0>(d_lapse) = vars.dx_h_over_2_sqrt_h;
     107             :   return d_lapse;
     108             : }
     109             : 
     110             : template <size_t Dim>
     111             : template <typename DataType>
     112             : auto GaugeWave<Dim>::variables(
     113             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x, const double /*t*/,
     114             :     const IntermediateVars<DataType>& /*vars*/,
     115             :     tmpl::list<gr::Tags::Shift<volume_dim, Frame::Inertial, DataType>> /*meta*/)
     116             :     const noexcept -> tuples::TaggedTuple<
     117             :         gr::Tags::Shift<volume_dim, Frame::Inertial, DataType>> {
     118             :   return {
     119             :       make_with_value<tnsr::I<DataType, volume_dim, Frame::Inertial>>(x, 0.0)};
     120             : }
     121             : 
     122             : template <size_t Dim>
     123             : template <typename DataType>
     124             : auto GaugeWave<Dim>::variables(
     125             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x, const double /*t*/,
     126             :     const IntermediateVars<DataType>& /*vars*/,
     127             :     tmpl::list<::Tags::dt<
     128             :         gr::Tags::Shift<volume_dim, Frame::Inertial, DataType>>> /*meta*/) const
     129             :     noexcept -> tuples::TaggedTuple<
     130             :         ::Tags::dt<gr::Tags::Shift<volume_dim, Frame::Inertial, DataType>>> {
     131             :   return {
     132             :       make_with_value<tnsr::I<DataType, volume_dim, Frame::Inertial>>(x, 0.0)};
     133             : }
     134             : 
     135             : template <size_t Dim>
     136             : template <typename DataType>
     137             : auto GaugeWave<Dim>::variables(
     138             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x, const double /*t*/,
     139             :     const IntermediateVars<DataType>& /*vars*/,
     140             :     tmpl::list<DerivShift<DataType>> /*meta*/) const noexcept
     141             :     -> tuples::TaggedTuple<DerivShift<DataType>> {
     142             :   return {
     143             :       make_with_value<tnsr::iJ<DataType, volume_dim, Frame::Inertial>>(x, 0.0)};
     144             : }
     145             : 
     146             : template <size_t Dim>
     147             : template <typename DataType>
     148             : auto GaugeWave<Dim>::variables(
     149             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x, const double /*t*/,
     150             :     const IntermediateVars<DataType>& vars,
     151             :     tmpl::list<gr::Tags::SpatialMetric<volume_dim, Frame::Inertial,
     152             :                                        DataType>> /*meta*/) const noexcept
     153             :     -> tuples::TaggedTuple<
     154             :         gr::Tags::SpatialMetric<volume_dim, Frame::Inertial, DataType>> {
     155             :   auto spatial_metric =
     156             :       make_with_value<tnsr::ii<DataType, volume_dim, Frame::Inertial>>(x, 0.0);
     157             :   get<0, 0>(spatial_metric) = vars.h;
     158             :   for (size_t i = 1; i < volume_dim; ++i) {
     159             :     spatial_metric.get(i, i) = 1.0;
     160             :   }
     161             :   return spatial_metric;
     162             : }
     163             : 
     164             : template <size_t Dim>
     165             : template <typename DataType>
     166             : auto GaugeWave<Dim>::variables(
     167             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x, const double /*t*/,
     168             :     const IntermediateVars<DataType>& vars,
     169             :     tmpl::list<::Tags::dt<gr::Tags::SpatialMetric<volume_dim, Frame::Inertial,
     170             :                                                   DataType>>> /*meta*/) const
     171             :     noexcept -> tuples::TaggedTuple<::Tags::dt<
     172             :         gr::Tags::SpatialMetric<volume_dim, Frame::Inertial, DataType>>> {
     173             :   auto dt_spatial_metric =
     174             :       make_with_value<tnsr::ii<DataType, volume_dim, Frame::Inertial>>(x, 0.0);
     175             :   get<0, 0>(dt_spatial_metric) = -1.0 * vars.dx_h;
     176             :   return dt_spatial_metric;
     177             : }
     178             : 
     179             : template <size_t Dim>
     180             : template <typename DataType>
     181             : auto GaugeWave<Dim>::variables(
     182             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x, const double /*t*/,
     183             :     const IntermediateVars<DataType>& vars,
     184             :     tmpl::list<DerivSpatialMetric<DataType>> /*meta*/) const noexcept
     185             :     -> tuples::TaggedTuple<DerivSpatialMetric<DataType>> {
     186             :   auto d_spatial_metric =
     187             :       make_with_value<tnsr::ijj<DataType, volume_dim, Frame::Inertial>>(x, 0.0);
     188             :   get<0, 0, 0>(d_spatial_metric) = vars.dx_h;
     189             :   return d_spatial_metric;
     190             : }
     191             : 
     192             : template <size_t Dim>
     193             : template <typename DataType>
     194             : auto GaugeWave<Dim>::variables(
     195             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& /*x*/,
     196             :     const double /*t*/, const IntermediateVars<DataType>& vars,
     197             :     tmpl::list<gr::Tags::SqrtDetSpatialMetric<DataType>> /*meta*/) const
     198             :     noexcept -> tuples::TaggedTuple<gr::Tags::SqrtDetSpatialMetric<DataType>> {
     199             :   return {Scalar<DataType>{vars.sqrt_h}};
     200             : }
     201             : 
     202             : template <size_t Dim>
     203             : template <typename DataType>
     204             : auto GaugeWave<Dim>::variables(
     205             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x, const double /*t*/,
     206             :     const IntermediateVars<DataType>& vars,
     207             :     tmpl::list<gr::Tags::ExtrinsicCurvature<volume_dim, Frame::Inertial,
     208             :                                             DataType>> /*meta*/) const noexcept
     209             :     -> tuples::TaggedTuple<
     210             :         gr::Tags::ExtrinsicCurvature<volume_dim, Frame::Inertial, DataType>> {
     211             :   auto extrinsic_curvature =
     212             :       make_with_value<tnsr::ii<DataType, volume_dim, Frame::Inertial>>(x, 0.0);
     213             :   get<0, 0>(extrinsic_curvature) = vars.dx_h_over_2_sqrt_h;
     214             :   return extrinsic_curvature;
     215             : }
     216             : 
     217             : template <size_t Dim>
     218             : template <typename DataType>
     219             : auto GaugeWave<Dim>::variables(
     220             :     const tnsr::I<DataType, volume_dim, Frame::Inertial>& x, const double /*t*/,
     221             :     const IntermediateVars<DataType>& vars,
     222             :     tmpl::list<gr::Tags::InverseSpatialMetric<volume_dim, Frame::Inertial,
     223             :                                               DataType>> /*meta*/) const
     224             :     noexcept -> tuples::TaggedTuple<
     225             :         gr::Tags::InverseSpatialMetric<volume_dim, Frame::Inertial, DataType>> {
     226             :   auto inverse_spatial_metric =
     227             :       make_with_value<tnsr::II<DataType, volume_dim, Frame::Inertial>>(x, 0.0);
     228             :   get<0, 0>(inverse_spatial_metric) = 1.0 / vars.h;
     229             :   for (size_t i = 1; i < volume_dim; ++i) {
     230             :     inverse_spatial_metric.get(i, i) = 1.0;
     231             :   }
     232             :   return inverse_spatial_metric;
     233             : }
     234             : 
     235             : template <size_t Dim>
     236             : bool operator==(const GaugeWave<Dim>& lhs, const GaugeWave<Dim>& rhs) noexcept {
     237             :   return lhs.amplitude() == rhs.amplitude() and
     238             :          lhs.wavelength() == rhs.wavelength();
     239             : }
     240             : 
     241             : template <size_t Dim>
     242             : bool operator!=(const GaugeWave<Dim>& lhs, const GaugeWave<Dim>& rhs) noexcept {
     243             :   return not(lhs == rhs);
     244             : }
     245             : 
     246             : #define DIM(data) BOOST_PP_TUPLE_ELEM(0, data)
     247             : #define DTYPE(data) BOOST_PP_TUPLE_ELEM(1, data)
     248             : 
     249             : #define INSTANTIATE(_, data)                                                   \
     250             :   template GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>::               \
     251             :       IntermediateVars(                                                        \
     252             :           const double amplitude, const double wavelength,                     \
     253             :           const tnsr::I<DTYPE(data), DIM(data), Frame::Inertial>& x,           \
     254             :           const double t) noexcept;                                            \
     255             :   template tuples::TaggedTuple<gr::Tags::Lapse<DTYPE(data)>>                   \
     256             :   GaugeWave<DIM(data)>::variables(                                             \
     257             :       const tnsr::I<DTYPE(data), DIM(data), Frame::Inertial>& /*x*/,           \
     258             :       const double /*t*/,                                                      \
     259             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     260             :       tmpl::list<gr::Tags::Lapse<DTYPE(data)>> /*meta*/) const noexcept;       \
     261             :   template tuples::TaggedTuple<::Tags::dt<gr::Tags::Lapse<DTYPE(data)>>>       \
     262             :   GaugeWave<DIM(data)>::variables(                                             \
     263             :       const tnsr::I<DTYPE(data), DIM(data)>& /*x*/, const double /*t*/,        \
     264             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     265             :       tmpl::list<::Tags::dt<gr::Tags::Lapse<DTYPE(data)>>> /*meta*/)           \
     266             :       const noexcept;                                                          \
     267             :   template tuples::TaggedTuple<::Tags::deriv<                                  \
     268             :       gr::Tags::Lapse<DTYPE(data)>, tmpl::size_t<DIM(data)>, Frame::Inertial>> \
     269             :   GaugeWave<DIM(data)>::variables(                                             \
     270             :       const tnsr::I<DTYPE(data), DIM(data)>& x, const double /*t*/,            \
     271             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     272             :       tmpl::list<                                                              \
     273             :           ::Tags::deriv<gr::Tags::Lapse<DTYPE(data)>, tmpl::size_t<DIM(data)>, \
     274             :                         Frame::Inertial>> /*meta*/) const noexcept;            \
     275             :   template tuples::TaggedTuple<                                                \
     276             :       gr::Tags::Shift<DIM(data), Frame::Inertial, DTYPE(data)>>                \
     277             :   GaugeWave<DIM(data)>::variables(                                             \
     278             :       const tnsr::I<DTYPE(data), DIM(data)>& x, const double /*t*/,            \
     279             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     280             :       tmpl::list<                                                              \
     281             :           gr::Tags::Shift<DIM(data), Frame::Inertial, DTYPE(data)>> /*meta*/)  \
     282             :       const noexcept;                                                          \
     283             :   template tuples::TaggedTuple<                                                \
     284             :       ::Tags::dt<gr::Tags::Shift<DIM(data), Frame::Inertial, DTYPE(data)>>>    \
     285             :   GaugeWave<DIM(data)>::variables(                                             \
     286             :       const tnsr::I<DTYPE(data), DIM(data)>& x, const double /*t*/,            \
     287             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     288             :       tmpl::list<::Tags::dt<                                                   \
     289             :           gr::Tags::Shift<DIM(data), Frame::Inertial, DTYPE(data)>>> /*meta*/) \
     290             :       const noexcept;                                                          \
     291             :   template tuples::TaggedTuple<                                                \
     292             :       ::Tags::deriv<gr::Tags::Shift<DIM(data), Frame::Inertial, DTYPE(data)>,  \
     293             :                     tmpl::size_t<DIM(data)>, Frame::Inertial>>                 \
     294             :   GaugeWave<DIM(data)>::variables(                                             \
     295             :       const tnsr::I<DTYPE(data), DIM(data)>& x, const double /*t*/,            \
     296             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     297             :       tmpl::list<::Tags::deriv<                                                \
     298             :           gr::Tags::Shift<DIM(data), Frame::Inertial, DTYPE(data)>,            \
     299             :           tmpl::size_t<DIM(data)>, Frame::Inertial>> /*meta*/) const noexcept; \
     300             :   template tuples::TaggedTuple<                                                \
     301             :       gr::Tags::SpatialMetric<DIM(data), Frame::Inertial, DTYPE(data)>>        \
     302             :   GaugeWave<DIM(data)>::variables(                                             \
     303             :       const tnsr::I<DTYPE(data), DIM(data)>& x, const double /*t*/,            \
     304             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     305             :       tmpl::list<gr::Tags::SpatialMetric<DIM(data), Frame::Inertial,           \
     306             :                                          DTYPE(data)>> /*meta*/)               \
     307             :       const noexcept;                                                          \
     308             :   template tuples::TaggedTuple<::Tags::dt<                                     \
     309             :       gr::Tags::SpatialMetric<DIM(data), Frame::Inertial, DTYPE(data)>>>       \
     310             :   GaugeWave<DIM(data)>::variables(                                             \
     311             :       const tnsr::I<DTYPE(data), DIM(data)>& x, const double /*t*/,            \
     312             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     313             :       tmpl::list<::Tags::dt<gr::Tags::SpatialMetric<                           \
     314             :           DIM(data), Frame::Inertial, DTYPE(data)>>> /*meta*/) const noexcept; \
     315             :   template tuples::TaggedTuple<::Tags::deriv<                                  \
     316             :       gr::Tags::SpatialMetric<DIM(data), Frame::Inertial, DTYPE(data)>,        \
     317             :       tmpl::size_t<DIM(data)>, Frame::Inertial>>                               \
     318             :   GaugeWave<DIM(data)>::variables(                                             \
     319             :       const tnsr::I<DTYPE(data), DIM(data)>& x, const double /*t*/,            \
     320             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     321             :       tmpl::list<::Tags::deriv<                                                \
     322             :           gr::Tags::SpatialMetric<DIM(data), Frame::Inertial, DTYPE(data)>,    \
     323             :           tmpl::size_t<DIM(data)>, Frame::Inertial>> /*meta*/) const noexcept; \
     324             :   template tuples::TaggedTuple<                                                \
     325             :       gr::Tags::InverseSpatialMetric<DIM(data), Frame::Inertial, DTYPE(data)>> \
     326             :   GaugeWave<DIM(data)>::variables(                                             \
     327             :       const tnsr::I<DTYPE(data), DIM(data)>& x, const double /*t*/,            \
     328             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     329             :       tmpl::list<gr::Tags::InverseSpatialMetric<DIM(data), Frame::Inertial,    \
     330             :                                                 DTYPE(data)>> /*meta*/)        \
     331             :       const noexcept;                                                          \
     332             :   template tuples::TaggedTuple<                                                \
     333             :       gr::Tags::ExtrinsicCurvature<DIM(data), Frame::Inertial, DTYPE(data)>>   \
     334             :   GaugeWave<DIM(data)>::variables(                                             \
     335             :       const tnsr::I<DTYPE(data), DIM(data)>& x, const double /*t*/,            \
     336             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     337             :       tmpl::list<gr::Tags::ExtrinsicCurvature<DIM(data), Frame::Inertial,      \
     338             :                                               DTYPE(data)>> /*meta*/)          \
     339             :       const noexcept;                                                          \
     340             :   template tuples::TaggedTuple<gr::Tags::SqrtDetSpatialMetric<DTYPE(data)>>    \
     341             :   GaugeWave<DIM(data)>::variables(                                             \
     342             :       const tnsr::I<DTYPE(data), DIM(data)>& /*x*/, const double /*t*/,        \
     343             :       const GaugeWave<DIM(data)>::IntermediateVars<DTYPE(data)>& vars,         \
     344             :       tmpl::list<gr::Tags::SqrtDetSpatialMetric<DTYPE(data)>> /*meta*/)        \
     345             :       const noexcept;
     346             : 
     347             : GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3), (double, DataVector))
     348             : 
     349             : #undef INSTANTIATE
     350             : #define INSTANTIATE(_, data)                                          \
     351             :   template class GaugeWave<DIM(data)>;                                \
     352             :   template bool operator==(const GaugeWave<DIM(data)>& lhs,           \
     353             :                            const GaugeWave<DIM(data)>& rhs) noexcept; \
     354             :   template bool operator!=(const GaugeWave<DIM(data)>& lhs,           \
     355             :                            const GaugeWave<DIM(data)>& rhs) noexcept;
     356             : 
     357             : GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3))
     358             : 
     359             : #undef INSTANTIATE
     360             : #undef DTYPE
     361             : #undef DIM
     362             : }  // namespace Solutions
     363             : }  // namespace gr
     364             : /// \endcond

Generated by: LCOV version 1.14