SpECTRE Documentation Coverage Report
Current view: top level - Time/Triggers - Times.hpp Hit Total Coverage
Commit: d0fc80462417e83e5cddfa1b9901bb4a9b6af4d6 Lines: 1 10 10.0 %
Date: 2024-03-29 00:33:31
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 <cmath>
       7             : #include <memory>
       8             : #include <pup.h>
       9             : #include <pup_stl.h>
      10             : #include <utility>
      11             : 
      12             : #include "Options/ParseOptions.hpp"
      13             : #include "Options/String.hpp"
      14             : #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
      15             : #include "Time/TimeSequence.hpp"
      16             : #include "Time/TimeStepId.hpp"
      17             : #include "Time/Utilities.hpp"
      18             : #include "Utilities/Serialization/CharmPupable.hpp"
      19             : #include "Utilities/TMPL.hpp"
      20             : 
      21             : /// \cond
      22             : namespace Tags {
      23             : struct Time;
      24             : struct TimeStepId;
      25             : }  // namespace Tags
      26             : /// \endcond
      27             : 
      28             : namespace Triggers {
      29             : /// \ingroup EventsAndTriggersGroup
      30             : /// \ingroup TimeGroup
      31             : /// Trigger at particular times.
      32             : ///
      33             : /// \warning This trigger will only fire if it is actually checked at
      34             : /// the times specified.  The StepToTimes StepChooser can be useful
      35             : /// for this.
      36           1 : class Times : public Trigger {
      37             :  public:
      38             :   /// \cond
      39             :   Times() = default;
      40             :   explicit Times(CkMigrateMessage* /*unused*/) {}
      41             :   using PUP::able::register_constructor;
      42             :   WRAPPED_PUPable_decl_template(Times);  // NOLINT
      43             :   /// \endcond
      44             : 
      45           0 :   static constexpr Options::String help{"Trigger at particular times."};
      46             : 
      47           0 :   explicit Times(std::unique_ptr<TimeSequence<double>> times)
      48             :       : times_(std::move(times)) {}
      49             : 
      50           0 :   using argument_tags = tmpl::list<Tags::Time, Tags::TimeStepId>;
      51             : 
      52           0 :   bool operator()(const double now, const TimeStepId& time_id) const {
      53             :     const auto& step_time = time_id.step_time();
      54             :     // Trying to step to a given time might not get us exactly there
      55             :     // because of rounding errors.
      56             :     const double sloppiness = slab_rounding_error(step_time);
      57             : 
      58             :     const auto nearby_time = times_->times_near(now)[1];
      59             :     return nearby_time and std::abs(*nearby_time - now) < sloppiness;
      60             :   }
      61             : 
      62             :   // NOLINTNEXTLINE(google-runtime-references)
      63           0 :   void pup(PUP::er& p) override { p | times_; }
      64             : 
      65             :  private:
      66           0 :   std::unique_ptr<TimeSequence<double>> times_;
      67             : };
      68             : }  // namespace Triggers
      69             : 
      70             : template <>
      71           0 : struct Options::create_from_yaml<Triggers::Times> {
      72             :   template <typename Metavariables>
      73           0 :   static Triggers::Times create(const Option& options) {
      74             :     return Triggers::Times(
      75             :         options
      76             :             .parse_as<std::unique_ptr<TimeSequence<double>>, Metavariables>());
      77             :   }
      78             : };

Generated by: LCOV version 1.14