SpECTRE Documentation Coverage Report
 Current view: top level - PointwiseFunctions/MathFunctions - MathFunction.hpp Hit Total Coverage Commit: 2ae2b99409ac582030d56a4560a92a3e066a7e54 Lines: 15 45 33.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 base-class MathFunction. 6 : 7 : #pragma once 8 : 9 : #include 10 : #include 11 : 12 : #include "DataStructures/Tensor/Tensor.hpp" 13 : #include "Parallel/CharmPupable.hpp" 14 : #include "Utilities/MakeWithValue.hpp" 15 : 16 : /// \ingroup MathFunctionsGroup 17 : /// Holds classes implementing MathFunction (functions \f$R^n \to R\f$). 18 : namespace MathFunctions {} 19 : 20 : /*! 21 : * \ingroup MathFunctionsGroup 22 : * Encodes a function \f$R^n \to R\f$ where n is VolumeDim. 23 : */ 24 : template 25 : class MathFunction; 26 : 27 : /*! 28 : * \ingroup MathFunctionsGroup 29 : * Encodes a function \f$R^n \to R\f$ where n is VolumeDim and where the 30 : * function input (i.e., the spatial coordinates) is given as a rank-1 tensor. 31 : */ 32 : template 33 1 : class MathFunction : public PUP::able { 34 : public: 35 0 : constexpr static size_t volume_dim = VolumeDim; 36 0 : using frame = Fr; 37 : 38 0 : WRAPPED_PUPable_abstract(MathFunction); // NOLINT 39 : 40 0 : MathFunction() = default; 41 0 : MathFunction(const MathFunction& /*rhs*/) = delete; 42 0 : MathFunction& operator=(const MathFunction& /*rhs*/) = delete; 43 0 : MathFunction(MathFunction&& /*rhs*/) = default; 44 0 : MathFunction& operator=(MathFunction&& /*rhs*/) = default; 45 0 : ~MathFunction() override = default; 46 : 47 : /// @{ 48 : /// Returns the value of the function at the coordinate 'x'. 49 1 : virtual Scalar operator()( 50 : const tnsr::I& x) const = 0; 51 1 : virtual Scalar operator()( 52 : const tnsr::I& x) const = 0; 53 : /// @} 54 : 55 : /// @{ 56 : /// Returns the first partial derivatives of the function at 'x'. 57 1 : virtual tnsr::i first_deriv( 58 : const tnsr::I& x) const = 0; 59 1 : virtual tnsr::i first_deriv( 60 : const tnsr::I& x) const = 0; 61 : /// @} 62 : 63 : /// @{ 64 : /// Returns the second partial derivatives of the function at 'x'. 65 1 : virtual tnsr::ii second_deriv( 66 : const tnsr::I& x) const = 0; 67 1 : virtual tnsr::ii second_deriv( 68 : const tnsr::I& x) const = 0; 69 : /// @} 70 : 71 : /// @{ 72 : /// Returns the third partial derivatives of the function at 'x'. 73 1 : virtual tnsr::iii third_deriv( 74 : const tnsr::I& x) const = 0; 75 1 : virtual tnsr::iii third_deriv( 76 : const tnsr::I& x) const = 0; 77 : /// @} 78 : }; 79 : 80 : /*! 81 : * \ingroup MathFunctionsGroup 82 : * Partial template specialization of MathFunction which encodes a 83 : * function \f$R \to R\f$. In this 1D specialization, the input and output can 84 : * be Tensors, doubles, or DataVectors. 85 : */ 86 : template 87 1 : class MathFunction<1, Fr> : public PUP::able { 88 : public: 89 0 : constexpr static size_t volume_dim = 1; 90 0 : using frame = Fr; 91 : 92 0 : WRAPPED_PUPable_abstract(MathFunction); // NOLINT 93 : 94 0 : MathFunction() = default; 95 0 : MathFunction(const MathFunction& /*rhs*/) = delete; 96 0 : MathFunction& operator=(const MathFunction& /*rhs*/) = delete; 97 0 : MathFunction(MathFunction&& /*rhs*/) = default; 98 0 : MathFunction& operator=(MathFunction&& /*rhs*/) = default; 99 0 : ~MathFunction() override = default; 100 : 101 : /// Returns the function value at the coordinate 'x' 102 1 : virtual double operator()(const double& x) const = 0; 103 0 : virtual DataVector operator()(const DataVector& x) const = 0; 104 0 : Scalar operator()(const tnsr::I& x) const { 105 : return Scalar{{{operator()(get<0>(x))}}}; 106 : } 107 0 : Scalar operator()(const tnsr::I& x) const { 108 : return Scalar{{{operator()(get<0>(x))}}}; 109 : } 110 : 111 : /// Returns the first derivative at 'x' 112 1 : virtual double first_deriv(const double& x) const = 0; 113 0 : virtual DataVector first_deriv(const DataVector& x) const = 0; 114 0 : tnsr::i first_deriv(const tnsr::I& x) const { 115 : auto result = make_with_value>(get<0>(x), 0.0); 116 : get<0>(result) = first_deriv(get<0>(x)); 117 : return result; 118 : } 119 0 : tnsr::i first_deriv( 120 : const tnsr::I& x) const { 121 : auto result = make_with_value>(get<0>(x), 0.0); 122 : get<0>(result) = first_deriv(get<0>(x)); 123 : return result; 124 : } 125 : 126 : /// Returns the second derivative at 'x' 127 1 : virtual double second_deriv(const double& x) const = 0; 128 0 : virtual DataVector second_deriv(const DataVector& x) const = 0; 129 0 : tnsr::ii second_deriv(const tnsr::I& x) const { 130 : auto result = make_with_value>(get<0>(x), 0.0); 131 : get<0, 0>(result) = second_deriv(get<0>(x)); 132 : return result; 133 : } 134 0 : tnsr::ii second_deriv( 135 : const tnsr::I& x) const { 136 : auto result = make_with_value>(get<0>(x), 0.0); 137 : get<0, 0>(result) = second_deriv(get<0>(x)); 138 : return result; 139 : } 140 : 141 : /// Returns the third derivative at 'x' 142 1 : virtual double third_deriv(const double& x) const = 0; 143 0 : virtual DataVector third_deriv(const DataVector& x) const = 0; 144 0 : tnsr::iii third_deriv(const tnsr::I& x) const { 145 : auto result = make_with_value>(get<0>(x), 0.0); 146 : get<0, 0, 0>(result) = third_deriv(get<0>(x)); 147 : return result; 148 : } 149 0 : tnsr::iii third_deriv( 150 : const tnsr::I& x) const { 151 : auto result = make_with_value>(get<0>(x), 0.0); 152 : get<0, 0, 0>(result) = third_deriv(get<0>(x)); 153 : return result; 154 : } 155 : }; 

 Generated by: LCOV version 1.14