SpECTRE Documentation Coverage Report
Current view: top level - Domain/FunctionsOfTime - FunctionOfTime.hpp Hit Total Coverage
Commit: f81419eb45f381cdf5c6c7751685b35483e19db9 Lines: 9 19 47.4 %
Date: 2025-04-20 16:13:24
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             :   /// The DataVector can be of any size
      90           1 :   virtual std::array<DataVector, 1> func(double t) const = 0;
      91             :   /// The DataVector can be of any size
      92           1 :   virtual std::array<DataVector, 2> func_and_deriv(double t) const = 0;
      93             :   /// The DataVector can be of any size
      94           1 :   virtual std::array<DataVector, 3> func_and_2_derivs(double t) const = 0;
      95             : 
      96             :   /// \brief All derivatives a function of time has to offer (because it can be
      97             :   /// more than 2)
      98             :   ///
      99             :   /// \details Defaults to the return values from `func_and_2_derivs` since some
     100             :   /// functions of time only go up to 2 derivatives by design
     101           1 :   virtual std::vector<DataVector> func_and_all_derivs(double t) const {
     102             :     std::array<DataVector, 3> tmp_func_and_2_derivs = func_and_2_derivs(t);
     103             : 
     104             :     return std::vector{std::move(tmp_func_and_2_derivs[0]),
     105             :                        std::move(tmp_func_and_2_derivs[1]),
     106             :                        std::move(tmp_func_and_2_derivs[2])};
     107             :   }
     108             : 
     109           0 :   WRAPPED_PUPable_abstract(FunctionOfTime);  // NOLINT
     110             : };
     111             : }  // namespace FunctionsOfTime
     112             : 
     113           0 : using FunctionsOfTimeMap = std::unordered_map<
     114             :     std::string, std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>;
     115             : 
     116             : }  // namespace domain

Generated by: LCOV version 1.14