SettleToConstant.hpp
2 // See LICENSE.txt for details.
3
4 #pragma once
5
6 #include <array>
7 #include <cstddef>
8 #include <limits>
9
10 #include "ControlSystem/FunctionOfTime.hpp"
11 #include "DataStructures/DataVector.hpp"
12
13 namespace FunctionsOfTime {
14 /// \ingroup ControlSystemGroup
15 /// Given an initial function \f$f(t)\f$ and its first two derivatives
16 /// at the matching time \f$t_0\f$, the constant coefficients \f$A,B,C\f$
17 /// are computed such that the resulting function of time
18 /// \f$g(t)\f$ satisfies \f$g(t=t_0)=f(t=t_0)\f$ and
19 /// approaches a constant value for \f$t > t_0\f$ on a timescale
20 /// of \f$\tau\f$. The resultant
21 /// function is \f[ g(t) = A + (B+C(t-t_0)) e^{-(t-t_0)/\tau} \f]
22 /// where \f$\tau\f$=decay_time and \f$t_0\f$=match_time.
23
25  public:
26  SettleToConstant(const std::array<DataVector, 3>& initial_func_and_derivs,
27  double match_time, double decay_time) noexcept;
28
29  ~SettleToConstant() override = default;
30  SettleToConstant(SettleToConstant&&) noexcept = default;
31  SettleToConstant& operator=(SettleToConstant&&) noexcept = default;
32  SettleToConstant(const SettleToConstant&) = delete;
33  SettleToConstant& operator=(const SettleToConstant&) = delete;
34
35  /// Returns the function at an arbitrary time t.
36  std::array<DataVector, 1> func(double t) const noexcept override {
37  return func_and_derivs<0>(t);
38  }
39  /// Returns the function and its first derivative at an arbitrary time t.
40  std::array<DataVector, 2> func_and_deriv(double t) const noexcept override {
41  return func_and_derivs<1>(t);
42  }
43  /// Returns the function and the first two derivatives at an arbitrary time
44  /// t.
46  noexcept override {
47  return func_and_derivs<2>(t);
48  }
49
50  /// Returns the domain of validity of the function.
51  std::array<double, 2> time_bounds() const noexcept override {
52  return {{match_time_, std::numeric_limits<double>::max()}};
53  }
54
55  private:
56  template <size_t MaxDerivReturned = 2>
57  std::array<DataVector, MaxDerivReturned + 1> func_and_derivs(double t) const
58  noexcept;
59
60  DataVector coef_a_, coef_b_, coef_c_;
61  double match_time_;
62  double inv_decay_time_;
63 };
64 } // namespace FunctionsOfTime
std::array< double, 2 > time_bounds() const noexcept override
Returns the domain of validity of the function.
Definition: SettleToConstant.hpp:51
Contains functions of time to support the dual frame system.
Definition: PiecewisePolynomial.hpp:15
Given an initial function and its first two derivatives at the matching time , the constant coeffici...
Definition: SettleToConstant.hpp:24
std::array< DataVector, 3 > func_and_2_derivs(double t) const noexcept override
Returns the function and the first two derivatives at an arbitrary time t.
Definition: SettleToConstant.hpp:45
T max(T... args)
Stores a collection of function values.
Definition: DataVector.hpp:46
Base class for FunctionsOfTime.
Definition: FunctionOfTime.hpp:13
std::array< DataVector, 2 > func_and_deriv(double t) const noexcept override
Returns the function and its first derivative at an arbitrary time t.
Definition: SettleToConstant.hpp:40
std::array< DataVector, 1 > func(double t) const noexcept override
Returns the function at an arbitrary time t.
Definition: SettleToConstant.hpp:36