SpECTRE Documentation Coverage Report
Current view: top level - NumericalAlgorithms/Interpolation - ZeroCrossingPredictor.hpp Hit Total Coverage
Commit: 9f349d3c09e1c03107f00c2135ca40e209d3b84c Lines: 7 16 43.8 %
Date: 2023-06-09 21:05:06
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 <cstddef>
       7             : #include <deque>
       8             : 
       9             : #include "DataStructures/DataVector.hpp"
      10             : 
      11             : /// \cond
      12             : namespace PUP {
      13             : class er;
      14             : }  // namespace PUP
      15             : /// \endcond
      16             : 
      17             : namespace intrp {
      18             : 
      19             : /// \ingroup NumericalAlgorithmsGroup
      20             : /// \brief A class that predicts when a function crosses zero
      21           1 : class ZeroCrossingPredictor {
      22             :  public:
      23             :   /// Uses at most max_size times for the fit; throws away old
      24             :   /// times as new times are added.
      25             :   /// The is_valid function returns false until min_size times
      26             :   /// have been added.  min_size must be at least 3.
      27           1 :   ZeroCrossingPredictor(size_t min_size, size_t max_size);
      28             : 
      29           0 :   ZeroCrossingPredictor() = default;
      30             : 
      31             :   /// Adds a data point at time t to the ZeroCrossingPredictor.
      32           1 :   void add(double t, DataVector data_at_time_t);
      33             : 
      34             :   /// For each component of the data, returns the time, relative to
      35             :   /// current_time, that a linear fit to the given component of the
      36             :   /// data crosses zero.  The length of the return value is the same
      37             :   /// as the length of `data_at_time_t` in the `add` function.
      38             :   ///
      39             :   /// The zero-crossing time that is computed has error bars
      40             :   /// associated with it.  If the error bars are large enough that it
      41             :   /// is not clear whether the zero-crossing time is positive or
      42             :   /// negative, then zero is returned instead of the best-fit
      43             :   /// zero-crossing time.
      44           1 :   DataVector zero_crossing_time(double current_time) const;
      45             : 
      46             :   /// The minimum positive value over the DataVector returned
      47             :   /// by zero_crossing_time.  Returns zero if is_valid() is false.
      48           1 :   double min_positive_zero_crossing_time(double current_time) const;
      49             : 
      50             :   /// Returns whether we have enough data to call zero_crossing_time.
      51           1 :   bool is_valid() const;
      52             : 
      53             :   /// Clears the internal arrays.  Used to reset if there is a
      54             :   /// discontinuous change in the data that should not be fit over.
      55           1 :   void clear();
      56             : 
      57             :   // NOLINTNEXTLINE(google-runtime-references)
      58           0 :   void pup(PUP::er& p);
      59             : 
      60           0 :   friend bool operator==(const ZeroCrossingPredictor&,   // NOLINT
      61             :                          const ZeroCrossingPredictor&);  // NOLINT
      62             : 
      63             :  private:
      64           0 :   size_t min_size_{3};
      65           0 :   size_t max_size_{3};
      66           0 :   std::deque<double> times_{};
      67           0 :   std::deque<DataVector> data_{};
      68             : };
      69             : 
      70           0 : bool operator!=(const ZeroCrossingPredictor&, const ZeroCrossingPredictor&);
      71             : 
      72             : }  // namespace intrp

Generated by: LCOV version 1.14