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 <map> 9 : #include <memory> 10 : #include <ostream> 11 : #include <pup.h> 12 : #include <utility> 13 : 14 : #include "DataStructures/DataVector.hpp" 15 : #include "Domain/FunctionsOfTime/FunctionOfTime.hpp" 16 : #include "Domain/FunctionsOfTime/ThreadsafeList.hpp" 17 : #include "Utilities/Serialization/CharmPupable.hpp" 18 : 19 : namespace domain { 20 : namespace FunctionsOfTime { 21 : /*! 22 : * \ingroup ComputationalDomainGroup 23 : * \brief A function that has a piecewise-constant `MaxDeriv`th derivative. 24 : * 25 : * \note This class conforms to the requirements of the 26 : * `Parallel::GlobalCache` for objects held by mutable global cache tags. 27 : */ 28 : template <size_t MaxDeriv> 29 1 : class PiecewisePolynomial : public FunctionOfTime { 30 : public: 31 0 : PiecewisePolynomial(); 32 0 : PiecewisePolynomial(PiecewisePolynomial&&); 33 0 : PiecewisePolynomial(const PiecewisePolynomial&); 34 0 : PiecewisePolynomial& operator=(PiecewisePolynomial&&); 35 0 : PiecewisePolynomial& operator=(const PiecewisePolynomial&); 36 0 : ~PiecewisePolynomial() override; 37 : 38 0 : PiecewisePolynomial( 39 : double t, std::array<DataVector, MaxDeriv + 1> initial_func_and_derivs, 40 : double expiration_time); 41 : 42 0 : explicit PiecewisePolynomial(CkMigrateMessage* /*unused*/); 43 : 44 0 : auto get_clone() const -> std::unique_ptr<FunctionOfTime> override; 45 : 46 : // clang-tidy: google-runtime-references 47 : // clang-tidy: cppcoreguidelines-owning-memory,-warnings-as-errors 48 0 : WRAPPED_PUPable_decl_template(PiecewisePolynomial<MaxDeriv>); // NOLINT 49 : 50 : /// Returns the function at an arbitrary time `t`. If `MaxDeriv` is 51 : /// 0 and `update` has been called for time `t`, the updated value 52 : /// is ignored. 53 1 : std::array<DataVector, 1> func(double t) const override { 54 : return func_and_derivs<0>(t); 55 : } 56 : /// Returns the function and its first derivative at an arbitrary time `t`. 57 : /// If `MaxDeriv` is 1 and `update` has been called for time `t`, the updated 58 : /// value is ignored. 59 1 : std::array<DataVector, 2> func_and_deriv(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`. If `MaxDeriv` is 2 and `update` has been called for time `t`, the 64 : /// updated value is ignored. 65 1 : std::array<DataVector, 3> func_and_2_derivs(double t) const override { 66 : return func_and_derivs<2>(t); 67 : } 68 : 69 : /// Updates the `MaxDeriv`th derivative of the function at the given time. 70 : /// `updated_max_deriv` is a vector of the `MaxDeriv`ths for each component. 71 : /// `next_expiration_time` is the next expiration time. 72 : /// 73 : /// The \p time_of_update must be the same as the old expiration 74 : /// time. It is passed as a check that the calling code is 75 : /// computing the other arguments with the correct value. 76 1 : void update(double time_of_update, DataVector updated_max_deriv, 77 : double next_expiration_time) override; 78 : 79 : /// Returns the domain of validity of the function, 80 : /// including the extrapolation region. 81 1 : std::array<double, 2> time_bounds() const override; 82 : 83 1 : double expiration_after(double time) const override; 84 : 85 : // NOLINTNEXTLINE(google-runtime-references) 86 0 : void pup(PUP::er& p) override; 87 : 88 : private: 89 : template <size_t LocalMaxDeriv> 90 0 : friend bool operator==( // NOLINT(readability-redundant-declaration) 91 : const PiecewisePolynomial<LocalMaxDeriv>& lhs, 92 : const PiecewisePolynomial<LocalMaxDeriv>& rhs); 93 : 94 : template <size_t LocalMaxDeriv> 95 0 : friend std::ostream& operator<<( // NOLINT(readability-redundant-declaration 96 : std::ostream& os, 97 : const PiecewisePolynomial<LocalMaxDeriv>& piecewise_polynomial); 98 : 99 0 : void unpack_old_version(PUP::er& p, size_t version); 100 : 101 : /// Returns the function and `MaxDerivReturned` derivatives at 102 : /// an arbitrary time `t`. 103 : /// The function has multiple components. 104 : template <size_t MaxDerivReturned = MaxDeriv> 105 1 : std::array<DataVector, MaxDerivReturned + 1> func_and_derivs(double t) const; 106 : 107 0 : void store_entry(double time_of_update, 108 : std::array<DataVector, MaxDeriv + 1> func_and_derivs, 109 : double next_expiration_time); 110 : 111 : FunctionOfTimeHelpers::ThreadsafeList<std::array<DataVector, MaxDeriv + 1>> 112 0 : deriv_info_at_update_times_; 113 0 : std::map<double, std::pair<DataVector, double>> update_backlog_{}; 114 : }; 115 : 116 : template <size_t MaxDeriv> 117 0 : bool operator!=(const PiecewisePolynomial<MaxDeriv>& lhs, 118 : const PiecewisePolynomial<MaxDeriv>& rhs); 119 : 120 : /// \cond 121 : template <size_t MaxDeriv> 122 : PUP::able::PUP_ID PiecewisePolynomial<MaxDeriv>::my_PUP_ID = 0; // NOLINT 123 : /// \endcond 124 : } // namespace FunctionsOfTime 125 : } // namespace domain