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 <cmath> 8 : #include <cstddef> 9 : #include <limits> 10 : #include <memory> 11 : #include <ostream> 12 : #include <pup.h> 13 : 14 : #include "DataStructures/DataVector.hpp" 15 : #include "Domain/FunctionsOfTime/FunctionOfTime.hpp" 16 : #include "Utilities/Serialization/CharmPupable.hpp" 17 : 18 : namespace domain { 19 1 : namespace FunctionsOfTime { 20 : /*! 21 : * \ingroup ControlSystemGroup 22 : * \brief Sets \f$f(t)\f$ and derivatives using cubic rational functions, 23 : * such that the first derivative approaches a constant and the second 24 : * derivative approaches zero. 25 : * 26 : * The resultant function of time is 27 : * 28 : * \f{align*}{ 29 : * f(t) &= f_0 + \frac{v(t-t_0)^3}{\tau^2+(t-t_0)^2}, 30 : * \f} 31 : * 32 : * where \f$f_0\f$ is the value of the function \f$f\f$ at the initial time 33 : * \f$t_0\f$, and \f$v\f$ is the velocity that \f$f^\prime(t)\f$ approaches on a 34 : * timescale of \f$\tau\f$. 35 : */ 36 1 : class FixedSpeedCubic : public FunctionOfTime { 37 : public: 38 0 : FixedSpeedCubic() = default; 39 0 : FixedSpeedCubic(double initial_function_value, double initial_time, 40 : double velocity, double decay_timescale); 41 : 42 0 : ~FixedSpeedCubic() override = default; 43 0 : FixedSpeedCubic(FixedSpeedCubic&&) = default; 44 0 : FixedSpeedCubic& operator=(FixedSpeedCubic&&) = default; 45 0 : FixedSpeedCubic(const FixedSpeedCubic&) = default; 46 0 : FixedSpeedCubic& operator=(const FixedSpeedCubic&) = default; 47 : 48 : // NOLINTNEXTLINE(google-runtime-references) 49 0 : WRAPPED_PUPable_decl_template(FixedSpeedCubic); 50 : 51 0 : explicit FixedSpeedCubic(CkMigrateMessage* /*unused*/) {} 52 : 53 0 : auto get_clone() const -> std::unique_ptr<FunctionOfTime> override; 54 : 55 : /// Returns the function at an arbitrary time `t`. 56 1 : std::array<DataVector, 1> func(const double t) const override { 57 : return func_and_derivs<0>(t); 58 : } 59 : /// Returns the function and its first derivative at an arbitrary time `t`. 60 1 : std::array<DataVector, 2> func_and_deriv(const double t) const override { 61 : return func_and_derivs<1>(t); 62 : } 63 : /// Returns the function and the first two derivatives at an arbitrary time 64 : /// `t`. 65 1 : std::array<DataVector, 3> func_and_2_derivs(const double t) const override { 66 : return func_and_derivs<2>(t); 67 : } 68 : 69 : /// Returns the domain of validity of the function. 70 1 : std::array<double, 2> time_bounds() const override { 71 : return {{initial_time_, std::numeric_limits<double>::infinity()}}; 72 : } 73 : 74 1 : double expiration_after(const double /*time*/) const override { 75 : return std::numeric_limits<double>::infinity(); 76 : } 77 : 78 : /// Returns the velocity that the function approaches 79 1 : double velocity() const { return velocity_; } 80 : 81 : /// Returns the timescale at which the function approaches a constant 82 : /// velocity. 83 1 : double decay_timescale() const { return sqrt(squared_decay_timescale_); } 84 : 85 : // NOLINTNEXTLINE(google-runtime-references) 86 0 : void pup(PUP::er& p) override; 87 : 88 : private: 89 0 : friend bool operator==(const FixedSpeedCubic& lhs, 90 : const FixedSpeedCubic& rhs); 91 : 92 0 : friend std::ostream& operator<<( // NOLINT(readability-redundant-declaration 93 : std::ostream& os, const FixedSpeedCubic& fixed_speed_cubic); 94 : 95 : template <size_t MaxDerivReturned = 2> 96 0 : std::array<DataVector, MaxDerivReturned + 1> func_and_derivs(double t) const; 97 : 98 0 : double initial_function_value_{std::numeric_limits<double>::signaling_NaN()}; 99 0 : double initial_time_{std::numeric_limits<double>::signaling_NaN()}; 100 0 : double velocity_{std::numeric_limits<double>::signaling_NaN()}; 101 0 : double squared_decay_timescale_{std::numeric_limits<double>::signaling_NaN()}; 102 : }; 103 : 104 0 : bool operator!=(const FixedSpeedCubic& lhs, const FixedSpeedCubic& rhs); 105 : } // namespace FunctionsOfTime 106 : } // namespace domain