SpECTRE Documentation Coverage Report
Current view: top level - Domain/FunctionsOfTime - FunctionOfTime.hpp Coverage Total Hit
Commit: 0d1d717af84a81fb1284a20c4013708fe85cc2f0 Lines: 50.0 % 20 10
Test Date: 2026-10-22 17:29:42
Legend: Lines:     hit not hit

            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 <memory>
       8              : #include <pup.h>
       9              : #include <vector>
      10              : 
      11              : #include "DataStructures/DataVector.hpp"
      12              : #include "Utilities/ErrorHandling/Error.hpp"
      13              : #include "Utilities/Serialization/CharmPupable.hpp"
      14              : 
      15              : namespace domain {
      16              : /// \ingroup ComputationalDomainGroup
      17              : /// \brief Contains functions of time to support the dual frame system.
      18              : namespace FunctionsOfTime {
      19              : /// \ingroup ComputationalDomainGroup
      20              : /// \brief Base class for FunctionsOfTime
      21              : ///
      22              : /// A FunctionOfTime is a function that will return the same value for
      23              : /// a time `t`, regardless of when that function is called during a run
      24              : /// (provided that the time `t` is in the domain of validity of the function).
      25              : /// All FunctionsOfTime have members
      26              : ///   - `func`, that returns a `std::array<DataVector, 1>`
      27              : ///   - `func_and_deriv`, that returns a `std::array<DataVector, 2>`
      28              : ///   - `func_and_2_derivs`, that returns a `std::array<DataVector, 3>`
      29              : ///
      30              : /// The DataVectors that are returned can be of any size: e.g. a scalar
      31              : /// FunctionOfTime will have DataVectors with one component and a 3-vector
      32              : /// FunctionOfTime will have DataVectors with three components.
      33              : ///
      34              : /// The domain of validity of the function is given by the `time_bounds` member
      35              : /// function.
      36              : ///
      37              : /// The function and all of its derivatives are left-continuous, that
      38              : /// is, when evaluated at a time when the function was updated, they
      39              : /// return the values just before the update, ignoring the updated
      40              : /// value.
      41            1 : class FunctionOfTime : public PUP::able {
      42              :  public:
      43            0 :   FunctionOfTime() = default;
      44            0 :   FunctionOfTime(FunctionOfTime&&) = default;
      45            0 :   FunctionOfTime& operator=(FunctionOfTime&&) = default;
      46            0 :   FunctionOfTime(const FunctionOfTime&) = default;
      47            0 :   FunctionOfTime& operator=(const FunctionOfTime&) = default;
      48            0 :   ~FunctionOfTime() override = default;
      49              : 
      50            0 :   virtual auto get_clone() const -> std::unique_ptr<FunctionOfTime> = 0;
      51              : 
      52              :   /// Create a FunctionOfTime at time \p t as if one had created a new
      53              :   /// FunctionOfTime with \p t as its initial time, except the initial values of
      54              :   /// new FunctionOfTime are the exact values of the old FunctionOfTime at time
      55              :   /// \p t, and the new expriation is \p expiration_time.
      56              :   ///
      57              :   /// \details This defaults to just `get_clone()` since some functions can't be
      58              :   /// updated/don't expire.
      59            1 :   virtual std::unique_ptr<FunctionOfTime> create_at_time(
      60              :       const double /*t*/, const double /*expiration_time*/) const {
      61              :     return get_clone();
      62              :   }
      63              : 
      64              :   /// Returns the domain of validity of the function.
      65              :   /// For FunctionsOfTime that allow a small amount of time extrapolation,
      66              :   /// `time_bounds` tells you the bounds including the allowed extrapolation
      67              :   /// interval.
      68            1 :   virtual std::array<double, 2> time_bounds() const = 0;
      69              : 
      70              :   /// \brief The first expiration time after \p time.
      71              :   ///
      72              :   /// \details For non-updatable functions, this returns infinity. For
      73              :   /// updatable functions, the first expiration time after \p time is
      74              :   /// found by determining the update immediately before \p time. The
      75              :   /// expiration time of this update is what is returned. If \p time
      76              :   /// happens to be an update itself, then the expiration of that
      77              :   /// update is returned.
      78            1 :   virtual double expiration_after(double time) const = 0;
      79              : 
      80              :   /// Updates the maximum derivative of the FunctionOfTime at a given time while
      81              :   /// also resetting the expiration. By default, a FunctionOfTime cannot be
      82              :   /// updated.
      83            1 :   virtual void update(double /*time_of_update*/,
      84              :                       DataVector /*updated_max_deriv*/,
      85              :                       double /*next_expiration_time*/) {
      86              :     ERROR("Cannot update this FunctionOfTime.");
      87              :   }
      88              : 
      89              :   /// Discards data only needed before the passed time, to reduce
      90              :   /// memory use.
      91              :   ///
      92              :   /// It should be safe to call this method concurrently with update
      93              :   /// and access of any data not before \p time.
      94            1 :   virtual void truncate_at_time(double time) = 0;
      95              : 
      96              :   /// The DataVector can be of any size
      97            1 :   virtual std::array<DataVector, 1> func(double t) const = 0;
      98              :   /// The DataVector can be of any size
      99            1 :   virtual std::array<DataVector, 2> func_and_deriv(double t) const = 0;
     100              :   /// The DataVector can be of any size
     101            1 :   virtual std::array<DataVector, 3> func_and_2_derivs(double t) const = 0;
     102              : 
     103              :   /// \brief All derivatives a function of time has to offer (because it can be
     104              :   /// more than 2)
     105              :   ///
     106              :   /// \details Defaults to the return values from `func_and_2_derivs` since some
     107              :   /// functions of time only go up to 2 derivatives by design
     108            1 :   virtual std::vector<DataVector> func_and_all_derivs(double t) const {
     109              :     std::array<DataVector, 3> tmp_func_and_2_derivs = func_and_2_derivs(t);
     110              : 
     111              :     return std::vector{std::move(tmp_func_and_2_derivs[0]),
     112              :                        std::move(tmp_func_and_2_derivs[1]),
     113              :                        std::move(tmp_func_and_2_derivs[2])};
     114              :   }
     115              : 
     116            0 :   WRAPPED_PUPable_abstract(FunctionOfTime);  // NOLINT
     117              : };
     118              : }  // namespace FunctionsOfTime
     119              : 
     120            0 : using FunctionsOfTimeMap = std::unordered_map<
     121              :     std::string, std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>;
     122              : 
     123              : }  // namespace domain
        

Generated by: LCOV version 2.0-1