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