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(double t) const override;
57 : /// Returns the function and its first derivative at an arbitrary time `t`.
58 1 : std::array<DataVector, 2> func_and_deriv(double t) const override;
59 : /// Returns the function and the first two derivatives at an arbitrary time
60 : /// `t`.
61 1 : std::array<DataVector, 3> func_and_2_derivs(double t) const override;
62 :
63 : /// Returns the domain of validity of the function.
64 1 : std::array<double, 2> time_bounds() const override;
65 :
66 1 : double expiration_after(double time) const override;
67 :
68 1 : void truncate_at_time(double time) override;
69 :
70 : /// Returns the velocity that the function approaches
71 1 : double velocity() const;
72 :
73 : /// Returns the timescale at which the function approaches a constant
74 : /// velocity.
75 1 : double decay_timescale() const;
76 :
77 : // NOLINTNEXTLINE(google-runtime-references)
78 0 : void pup(PUP::er& p) override;
79 :
80 : private:
81 0 : friend bool operator==(const FixedSpeedCubic& lhs,
82 : const FixedSpeedCubic& rhs);
83 :
84 0 : friend std::ostream& operator<<( // NOLINT(readability-redundant-declaration
85 : std::ostream& os, const FixedSpeedCubic& fixed_speed_cubic);
86 :
87 : template <size_t MaxDerivReturned = 2>
88 0 : std::array<DataVector, MaxDerivReturned + 1> func_and_derivs(double t) const;
89 :
90 0 : double initial_function_value_{std::numeric_limits<double>::signaling_NaN()};
91 0 : double initial_time_{std::numeric_limits<double>::signaling_NaN()};
92 0 : double velocity_{std::numeric_limits<double>::signaling_NaN()};
93 0 : double squared_decay_timescale_{std::numeric_limits<double>::signaling_NaN()};
94 : };
95 :
96 0 : bool operator!=(const FixedSpeedCubic& lhs, const FixedSpeedCubic& rhs);
97 : } // namespace FunctionsOfTime
98 : } // namespace domain
|