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 10 : #include 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 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 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; 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& 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 103 0 : T apply_call_operator(const T& x) const; 104 : template 105 0 : T apply_first_deriv(const T& x) const; 106 : template 107 0 : T apply_second_deriv(const T& x) const; 108 : template 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, 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 123 1 : class Gaussian : public MathFunction { 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; 138 0 : static constexpr Options::String help = {"The center."}; 139 : }; 140 0 : using options = tmpl::list; 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), 147 : Gaussian); // NOLINT 148 : 149 0 : explicit Gaussian(CkMigrateMessage* /*unused*/) {} 150 : 151 0 : Gaussian(double amplitude, double width, 152 : const std::array& 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 operator()( 162 : const tnsr::I& x) const override; 163 1 : Scalar operator()( 164 : const tnsr::I& x) const override; 165 : 166 1 : tnsr::i first_deriv( 167 : const tnsr::I& x) const override; 168 1 : tnsr::i first_deriv( 169 : const tnsr::I& x) const override; 170 : 171 1 : tnsr::ii second_deriv( 172 : const tnsr::I& x) const override; 173 1 : tnsr::ii second_deriv( 174 : const tnsr::I& x) const override; 175 : 176 1 : tnsr::iii third_deriv( 177 : const tnsr::I& x) const override; 178 1 : tnsr::iii third_deriv( 179 : const tnsr::I& 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 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 195 0 : tnsr::I centered_coordinates( 196 : const tnsr::I& x) const; 197 : template 198 0 : Scalar apply_call_operator( 199 : const tnsr::I& centered_coords) const; 200 : template 201 0 : tnsr::i apply_first_deriv( 202 : const tnsr::I& centered_coords, 203 : const Scalar& gaussian) const; 204 : template 205 0 : tnsr::ii apply_second_deriv( 206 : const tnsr::I& centered_coords, 207 : const Scalar& gaussian, 208 : const tnsr::i& d_gaussian) const; 209 : template 210 0 : tnsr::iii apply_third_deriv( 211 : const tnsr::I& centered_coords, 212 : const Scalar& gaussian, const tnsr::i& d_gaussian, 213 : const tnsr::ii& d2_gaussian) const; 214 : }; 215 : 216 : template 217 0 : bool operator!=(const Gaussian& lhs, 218 : const Gaussian& rhs) { 219 : return not(lhs == rhs); 220 : } 221 : } // namespace MathFunctions 222 : 223 : /// \cond 224 : template 225 : PUP::able::PUP_ID MathFunctions::Gaussian::my_PUP_ID = 226 : 0; // NOLINT 227 : 228 : template 229 : PUP::able::PUP_ID MathFunctions::Gaussian<1, Fr>::my_PUP_ID = 0; // NOLINT 230 : /// \endcond 

 Generated by: LCOV version 1.14