SpECTRE Documentation Coverage Report
Current view: top level - PointwiseFunctions/MathFunctions - Gaussian.hpp Hit Total Coverage
Commit: 2ae2b99409ac582030d56a4560a92a3e066a7e54 Lines: 15 82 18.3 %
Date: 2022-01-15 08:40:38
Legend: Lines: hit not hit

          Line data    Source code
       1           1 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : /// \file
       5             : /// Defines MathFunctions::Gaussian.
       6             : 
       7             : #pragma once
       8             : 
       9             : #include <array>
      10             : #include <pup.h>
      11             : 
      12             : #include "Options/Options.hpp"
      13             : #include "Parallel/CharmPupable.hpp"
      14             : #include "PointwiseFunctions/MathFunctions/MathFunction.hpp"  // IWYU pragma: keep
      15             : #include "Utilities/TMPL.hpp"
      16             : 
      17             : /// \cond
      18             : class DataVector;
      19             : /// \endcond
      20             : 
      21             : namespace MathFunctions {
      22             : template <size_t VolumeDim, typename Fr>
      23             : class Gaussian;
      24             : 
      25             : /*!
      26             :  *  \ingroup MathFunctionsGroup
      27             :  *  \brief 1D Gaussian \f$f = A \exp\left(-\frac{(x-x_0)^2}{w^2}\right)\f$
      28             :  *
      29             :  *  \details Input file options are: Amplitude, Width, and Center. The function
      30             :  *  takes input of type `double` or `DataVector` and returns
      31             :  *  the same type as the input type.
      32             :  */
      33             : template <typename Fr>
      34           1 : class Gaussian<1, Fr> : public MathFunction<1, Fr> {
      35             :  public:
      36           0 :   struct Amplitude {
      37           0 :     using type = double;
      38           0 :     static constexpr Options::String help = {"The amplitude."};
      39             :   };
      40             : 
      41           0 :   struct Width {
      42           0 :     using type = double;
      43           0 :     static constexpr Options::String help = {"The width."};
      44           0 :     static type lower_bound() { return 0.; }
      45             :   };
      46             : 
      47           0 :   struct Center {
      48           0 :     using type = double;
      49           0 :     static constexpr Options::String help = {"The center."};
      50             :   };
      51           0 :   using options = tmpl::list<Amplitude, Width, Center>;
      52             : 
      53           0 :   static constexpr Options::String help = {
      54             :       "Computes a Gaussian about an arbitrary coordinate center with given "
      55             :       "width and amplitude"};
      56             : 
      57           0 :   WRAPPED_PUPable_decl_base_template(SINGLE_ARG(MathFunction<1, Fr>),
      58             :                                      Gaussian);  // NOLINT
      59             : 
      60           0 :   explicit Gaussian(CkMigrateMessage* /*unused*/) {}
      61             : 
      62           0 :   Gaussian(double amplitude, double width, double center);
      63           0 :   Gaussian(double amplitude, double width, const std::array<double, 1>& center);
      64             : 
      65           0 :   Gaussian() = default;
      66           0 :   ~Gaussian() override = default;
      67           0 :   Gaussian(const Gaussian& /*rhs*/) = delete;
      68           0 :   Gaussian& operator=(const Gaussian& /*rhs*/) = delete;
      69           0 :   Gaussian(Gaussian&& /*rhs*/) = default;
      70           0 :   Gaussian& operator=(Gaussian&& /*rhs*/) = default;
      71             : 
      72           1 :   double operator()(const double& x) const override;
      73           0 :   DataVector operator()(const DataVector& x) const override;
      74             :   using MathFunction<1, Fr>::operator();
      75             : 
      76           1 :   double first_deriv(const double& x) const override;
      77           0 :   DataVector first_deriv(const DataVector& x) const override;
      78             :   using MathFunction<1, Fr>::first_deriv;
      79             : 
      80           1 :   double second_deriv(const double& x) const override;
      81           0 :   DataVector second_deriv(const DataVector& x) const override;
      82             :   using MathFunction<1, Fr>::second_deriv;
      83             : 
      84           1 :   double third_deriv(const double& x) const override;
      85           0 :   DataVector third_deriv(const DataVector& x) const override;
      86             :   using MathFunction<1, Fr>::third_deriv;
      87             : 
      88             :   // NOLINTNEXTLINE(google-runtime-references)
      89           0 :   void pup(PUP::er& p) override;
      90             : 
      91             :  private:
      92           0 :   double amplitude_{};
      93           0 :   double inverse_width_{};
      94           0 :   double center_{};
      95           0 :   friend bool operator==(const Gaussian<1, Fr>& lhs,
      96             :                          const Gaussian<1, Fr>& rhs) {
      97             :     return lhs.amplitude_ == rhs.amplitude_ and
      98             :            lhs.inverse_width_ == rhs.inverse_width_ and
      99             :            lhs.center_ == rhs.center_;
     100             :   }
     101             : 
     102             :   template <typename T>
     103           0 :   T apply_call_operator(const T& x) const;
     104             :   template <typename T>
     105           0 :   T apply_first_deriv(const T& x) const;
     106             :   template <typename T>
     107           0 :   T apply_second_deriv(const T& x) const;
     108             :   template <typename T>
     109           0 :   T apply_third_deriv(const T& x) const;
     110             : };
     111             : 
     112             : /*!
     113             :  * \ingroup MathFunctionsGroup
     114             :  * \brief Gaussian \f$f = A \exp\left(-\frac{(x-x_0)^2}{w^2}\right)\f$
     115             :  *
     116             :  * \details Input file options are: Amplitude, Width, and Center. The function
     117             :  * takes input coordinates of type `tnsr::I<T, VolumeDim, Fr>`, where `T` is
     118             :  * e.g. `double` or `DataVector`, `Fr` is a frame (e.g. `Frame::Inertial`), and
     119             :  * `VolumeDim` is the dimension of the spatial volume, i.e. 2 or 3. (The case of
     120             :  * VolumeDim == 1 is handled specially by Gaussian<1, T, Frame::Inertial>.)
     121             :  */
     122             : template <size_t VolumeDim, typename Fr>
     123           1 : class Gaussian : public MathFunction<VolumeDim, Fr> {
     124             :  public:
     125           0 :   struct Amplitude {
     126           0 :     using type = double;
     127           0 :     static constexpr Options::String help = {"The amplitude."};
     128             :   };
     129             : 
     130           0 :   struct Width {
     131           0 :     using type = double;
     132           0 :     static constexpr Options::String help = {"The width."};
     133           0 :     static type lower_bound() { return 0.; }
     134             :   };
     135             : 
     136           0 :   struct Center {
     137           0 :     using type = std::array<double, VolumeDim>;
     138           0 :     static constexpr Options::String help = {"The center."};
     139             :   };
     140           0 :   using options = tmpl::list<Amplitude, Width, Center>;
     141             : 
     142           0 :   static constexpr Options::String help = {
     143             :       "Computes a Gaussian about an arbitrary coordinate center with given "
     144             :       "width and amplitude"};
     145             : 
     146           0 :   WRAPPED_PUPable_decl_base_template(SINGLE_ARG(MathFunction<VolumeDim, Fr>),
     147             :                                      Gaussian);  // NOLINT
     148             : 
     149           0 :   explicit Gaussian(CkMigrateMessage* /*unused*/) {}
     150             : 
     151           0 :   Gaussian(double amplitude, double width,
     152             :            const std::array<double, VolumeDim>& center);
     153             : 
     154           0 :   Gaussian() = default;
     155           0 :   ~Gaussian() override = default;
     156           0 :   Gaussian(const Gaussian& /*rhs*/) = delete;
     157           0 :   Gaussian& operator=(const Gaussian& /*rhs*/) = delete;
     158           0 :   Gaussian(Gaussian&& /*rhs*/) = default;
     159           0 :   Gaussian& operator=(Gaussian&& /*rhs*/) = default;
     160             : 
     161           1 :   Scalar<double> operator()(
     162             :       const tnsr::I<double, VolumeDim, Fr>& x) const override;
     163           1 :   Scalar<DataVector> operator()(
     164             :       const tnsr::I<DataVector, VolumeDim, Fr>& x) const override;
     165             : 
     166           1 :   tnsr::i<double, VolumeDim, Fr> first_deriv(
     167             :       const tnsr::I<double, VolumeDim, Fr>& x) const override;
     168           1 :   tnsr::i<DataVector, VolumeDim, Fr> first_deriv(
     169             :       const tnsr::I<DataVector, VolumeDim, Fr>& x) const override;
     170             : 
     171           1 :   tnsr::ii<double, VolumeDim, Fr> second_deriv(
     172             :       const tnsr::I<double, VolumeDim, Fr>& x) const override;
     173           1 :   tnsr::ii<DataVector, VolumeDim, Fr> second_deriv(
     174             :       const tnsr::I<DataVector, VolumeDim, Fr>& x) const override;
     175             : 
     176           1 :   tnsr::iii<double, VolumeDim, Fr> third_deriv(
     177             :       const tnsr::I<double, VolumeDim, Fr>& x) const override;
     178           1 :   tnsr::iii<DataVector, VolumeDim, Fr> third_deriv(
     179             :       const tnsr::I<DataVector, VolumeDim, Fr>& x) const override;
     180             : 
     181             :   // NOLINTNEXTLINE(google-runtime-references)
     182           0 :   void pup(PUP::er& p) override;
     183             : 
     184             :  private:
     185           0 :   double amplitude_{};
     186           0 :   double inverse_width_{};
     187           0 :   std::array<double, VolumeDim> center_{};
     188           0 :   friend bool operator==(const Gaussian& lhs, const Gaussian& rhs) {
     189             :     return lhs.amplitude_ == rhs.amplitude_ and
     190             :            lhs.inverse_width_ == rhs.inverse_width_ and
     191             :            lhs.center_ == rhs.center_;
     192             :   }
     193             : 
     194             :   template <typename T>
     195           0 :   tnsr::I<T, VolumeDim, Fr> centered_coordinates(
     196             :       const tnsr::I<T, VolumeDim, Fr>& x) const;
     197             :   template <typename T>
     198           0 :   Scalar<T> apply_call_operator(
     199             :       const tnsr::I<T, VolumeDim, Fr>& centered_coords) const;
     200             :   template <typename T>
     201           0 :   tnsr::i<T, VolumeDim, Fr> apply_first_deriv(
     202             :       const tnsr::I<T, VolumeDim, Fr>& centered_coords,
     203             :       const Scalar<T>& gaussian) const;
     204             :   template <typename T>
     205           0 :   tnsr::ii<T, VolumeDim, Fr> apply_second_deriv(
     206             :       const tnsr::I<T, VolumeDim, Fr>& centered_coords,
     207             :       const Scalar<T>& gaussian,
     208             :       const tnsr::i<T, VolumeDim, Fr>& d_gaussian) const;
     209             :   template <typename T>
     210           0 :   tnsr::iii<T, VolumeDim, Fr> apply_third_deriv(
     211             :       const tnsr::I<T, VolumeDim, Fr>& centered_coords,
     212             :       const Scalar<T>& gaussian, const tnsr::i<T, VolumeDim, Fr>& d_gaussian,
     213             :       const tnsr::ii<T, VolumeDim, Fr>& d2_gaussian) const;
     214             : };
     215             : 
     216             : template <size_t VolumeDim, typename Fr>
     217           0 : bool operator!=(const Gaussian<VolumeDim, Fr>& lhs,
     218             :                 const Gaussian<VolumeDim, Fr>& rhs) {
     219             :   return not(lhs == rhs);
     220             : }
     221             : }  // namespace MathFunctions
     222             : 
     223             : /// \cond
     224             : template <size_t VolumeDim, typename Fr>
     225             : PUP::able::PUP_ID MathFunctions::Gaussian<VolumeDim, Fr>::my_PUP_ID =
     226             :     0;  // NOLINT
     227             : 
     228             : template <typename Fr>
     229             : PUP::able::PUP_ID MathFunctions::Gaussian<1, Fr>::my_PUP_ID = 0;  // NOLINT
     230             : /// \endcond

Generated by: LCOV version 1.14