SpECTRE Documentation Coverage Report
Current view: top level - PointwiseFunctions/AnalyticSolutions/Poisson - ProductOfSinusoids.hpp Hit Total Coverage
Commit: 7b84572e7f3b8c8fb2d105e3d4e12204a244a350 Lines: 1 26 3.8 %
Date: 2025-04-18 14:09:55
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #pragma once
       5             : 
       6             : #include <array>
       7             : #include <cstddef>
       8             : #include <limits>
       9             : #include <pup.h>
      10             : 
      11             : #include "DataStructures/CachedTempBuffer.hpp"
      12             : #include "DataStructures/ComplexDataVector.hpp"
      13             : #include "DataStructures/DataBox/Prefixes.hpp"
      14             : #include "DataStructures/DataVector.hpp"
      15             : #include "DataStructures/Tensor/Tensor.hpp"
      16             : #include "Elliptic/Systems/Poisson/Tags.hpp"
      17             : #include "NumericalAlgorithms/LinearOperators/PartialDerivatives.hpp"
      18             : #include "Options/String.hpp"
      19             : #include "PointwiseFunctions/InitialDataUtilities/AnalyticSolution.hpp"
      20             : #include "Utilities/ContainerHelpers.hpp"
      21             : #include "Utilities/Gsl.hpp"
      22             : #include "Utilities/TMPL.hpp"
      23             : #include "Utilities/TaggedTuple.hpp"
      24             : 
      25             : namespace Poisson::Solutions {
      26             : 
      27             : namespace detail {
      28             : template <typename DataType, size_t Dim>
      29             : struct ProductOfSinusoidsVariables {
      30             :   using Cache = CachedTempBuffer<
      31             :       Tags::Field<DataType>,
      32             :       ::Tags::deriv<Tags::Field<DataType>, tmpl::size_t<Dim>, Frame::Inertial>,
      33             :       ::Tags::Flux<Tags::Field<DataType>, tmpl::size_t<Dim>, Frame::Inertial>,
      34             :       ::Tags::FixedSource<Tags::Field<DataType>>>;
      35             : 
      36             :   // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
      37             :   const tnsr::I<DataVector, Dim>& x;
      38             :   std::array<double, Dim> wave_numbers;
      39             :   double complex_phase;
      40             : 
      41             :   void operator()(gsl::not_null<Scalar<DataType>*> field,
      42             :                   gsl::not_null<Cache*> cache,
      43             :                   Tags::Field<DataType> /*meta*/) const;
      44             :   void operator()(gsl::not_null<tnsr::i<DataType, Dim>*> field_gradient,
      45             :                   gsl::not_null<Cache*> cache,
      46             :                   ::Tags::deriv<Tags::Field<DataType>, tmpl::size_t<Dim>,
      47             :                                 Frame::Inertial> /*meta*/) const;
      48             :   void operator()(gsl::not_null<tnsr::I<DataType, Dim>*> flux_for_field,
      49             :                   gsl::not_null<Cache*> cache,
      50             :                   ::Tags::Flux<Tags::Field<DataType>, tmpl::size_t<Dim>,
      51             :                                Frame::Inertial> /*meta*/) const;
      52             :   void operator()(gsl::not_null<Scalar<DataType>*> fixed_source_for_field,
      53             :                   gsl::not_null<Cache*> cache,
      54             :                   ::Tags::FixedSource<Tags::Field<DataType>> /*meta*/) const;
      55             : };
      56             : }  // namespace detail
      57             : 
      58             : /*!
      59             :  * \brief A product of sinusoids \f$u(\boldsymbol{x}) = \prod_i \sin(k_i x_i)\f$
      60             :  *
      61             :  * \details Solves the Poisson equation \f$-\Delta u(x)=f(x)\f$ for a source
      62             :  * \f$f(x)=\boldsymbol{k}^2\prod_i \sin(k_i x_i)\f$.
      63             :  *
      64             :  * If `DataType` is `ComplexDataVector`, the solution is multiplied by
      65             :  * `exp(i * complex_phase)` to rotate it in the complex plane. This allows to
      66             :  * use this solution for the complex Poisson equation.
      67             :  */
      68             : template <size_t Dim, typename DataType = DataVector>
      69           1 : class ProductOfSinusoids : public elliptic::analytic_data::AnalyticSolution {
      70             :  public:
      71           0 :   struct WaveNumbers {
      72           0 :     using type = std::array<double, Dim>;
      73           0 :     static constexpr Options::String help{"The wave numbers of the sinusoids"};
      74             :   };
      75             : 
      76           0 :   struct ComplexPhase {
      77           0 :     using type = double;
      78           0 :     static constexpr Options::String help{
      79             :         "Phase 'phi' of a complex exponential 'exp(i phi)' that rotates the "
      80             :         "solution in the complex plane."};
      81             :   };
      82             : 
      83           0 :   using options = tmpl::flatten<tmpl::list<
      84             :       WaveNumbers,
      85             :       tmpl::conditional_t<std::is_same_v<DataType, ComplexDataVector>,
      86             :                           ComplexPhase, tmpl::list<>>>>;
      87           0 :   static constexpr Options::String help{
      88             :       "A product of sinusoids that are taken of a wave number times the "
      89             :       "coordinate in each dimension."};
      90             : 
      91           0 :   ProductOfSinusoids() = default;
      92           0 :   ProductOfSinusoids(const ProductOfSinusoids&) = default;
      93           0 :   ProductOfSinusoids& operator=(const ProductOfSinusoids&) = default;
      94           0 :   ProductOfSinusoids(ProductOfSinusoids&&) = default;
      95           0 :   ProductOfSinusoids& operator=(ProductOfSinusoids&&) = default;
      96           0 :   ~ProductOfSinusoids() override = default;
      97           0 :   std::unique_ptr<elliptic::analytic_data::AnalyticSolution> get_clone()
      98             :       const override {
      99             :     return std::make_unique<ProductOfSinusoids>(*this);
     100             :   }
     101             : 
     102             :   /// \cond
     103             :   explicit ProductOfSinusoids(CkMigrateMessage* m)
     104             :       : elliptic::analytic_data::AnalyticSolution(m) {}
     105             :   using PUP::able::register_constructor;
     106             :   WRAPPED_PUPable_decl_template(ProductOfSinusoids);  // NOLINT
     107             :   /// \endcond
     108             : 
     109           0 :   explicit ProductOfSinusoids(const std::array<double, Dim>& wave_numbers,
     110             :                               const double complex_phase = 0.)
     111             :       : wave_numbers_(wave_numbers), complex_phase_(complex_phase) {
     112             :     ASSERT((std::is_same_v<DataType, ComplexDataVector> or complex_phase == 0.),
     113             :            "The complex phase is only supported for ComplexDataVector.");
     114             :   }
     115             : 
     116             :   template <typename... RequestedTags>
     117           0 :   tuples::TaggedTuple<RequestedTags...> variables(
     118             :       const tnsr::I<DataVector, Dim>& x,
     119             :       tmpl::list<RequestedTags...> /*meta*/) const {
     120             :     using VarsComputer = detail::ProductOfSinusoidsVariables<DataType, Dim>;
     121             :     typename VarsComputer::Cache cache{get_size(*x.begin())};
     122             :     const VarsComputer computer{x, wave_numbers_, complex_phase_};
     123             :     return {cache.get_var(computer, RequestedTags{})...};
     124             :   }
     125             : 
     126             :   // NOLINTNEXTLINE(google-runtime-references)
     127           0 :   void pup(PUP::er& p) override {
     128             :     elliptic::analytic_data::AnalyticSolution::pup(p);
     129             :     p | wave_numbers_;
     130             :     p | complex_phase_;
     131             :   }
     132             : 
     133           0 :   const std::array<double, Dim>& wave_numbers() const { return wave_numbers_; }
     134           0 :   double complex_phase() const { return complex_phase_; }
     135             : 
     136             :  private:
     137           0 :   std::array<double, Dim> wave_numbers_{
     138             :       {std::numeric_limits<double>::signaling_NaN()}};
     139           0 :   double complex_phase_ = std::numeric_limits<double>::signaling_NaN();
     140             : };
     141             : 
     142             : /// \cond
     143             : template <size_t Dim, typename DataType>
     144             : PUP::able::PUP_ID ProductOfSinusoids<Dim, DataType>::my_PUP_ID = 0;  // NOLINT
     145             : /// \endcond
     146             : 
     147             : template <size_t Dim, typename DataType>
     148           0 : bool operator==(const ProductOfSinusoids<Dim, DataType>& lhs,
     149             :                 const ProductOfSinusoids<Dim, DataType>& rhs) {
     150             :   return lhs.wave_numbers() == rhs.wave_numbers() and
     151             :          lhs.complex_phase() == rhs.complex_phase();
     152             : }
     153             : 
     154             : template <size_t Dim, typename DataType>
     155           0 : bool operator!=(const ProductOfSinusoids<Dim, DataType>& lhs,
     156             :                 const ProductOfSinusoids<Dim, DataType>& rhs) {
     157             :   return not(lhs == rhs);
     158             : }
     159             : 
     160             : }  // namespace Poisson::Solutions

Generated by: LCOV version 1.14