SpECTRE Documentation Coverage Report
Current view: top level - Elliptic/Triggers - EveryNIterations.hpp Hit Total Coverage
Commit: 1c32b58340e006addc79befb2cdaa7547247e09c Lines: 2 18 11.1 %
Date: 2024-04-19 07:30:15
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 <cstdint>
       7             : #include <pup.h>
       8             : 
       9             : #include "NumericalAlgorithms/Convergence/Tags.hpp"
      10             : #include "Options/String.hpp"
      11             : #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
      12             : #include "Utilities/Serialization/CharmPupable.hpp"
      13             : #include "Utilities/TMPL.hpp"
      14             : 
      15           1 : namespace elliptic::Triggers {
      16             : /// \ingroup EventsAndTriggersGroup
      17             : /// Trigger every N iterations of the solver identifid by the `Label`, after a
      18             : /// given offset.
      19             : template <typename Label>
      20           1 : class EveryNIterations : public Trigger {
      21             :  public:
      22             :   /// \cond
      23             :   EveryNIterations() = default;
      24             :   explicit EveryNIterations(CkMigrateMessage* /*unused*/) {}
      25             :   using PUP::able::register_constructor;
      26             :   WRAPPED_PUPable_decl_template(EveryNIterations);  // NOLINT
      27             :   /// \endcond
      28             : 
      29           0 :   struct N {
      30           0 :     using type = uint64_t;
      31           0 :     static constexpr Options::String help{"How frequently to trigger."};
      32           0 :     static type lower_bound() { return 1; }
      33             :   };
      34           0 :   struct Offset {
      35           0 :     using type = uint64_t;
      36           0 :     static constexpr Options::String help{"First iteration to trigger on."};
      37             :   };
      38             : 
      39           0 :   using options = tmpl::list<N, Offset>;
      40           0 :   static constexpr Options::String help{
      41             :       "Trigger every N iterations after a given offset."};
      42             : 
      43           0 :   EveryNIterations(const uint64_t interval, const uint64_t offset)
      44             :       : interval_(interval), offset_(offset) {}
      45             : 
      46           0 :   using argument_tags = tmpl::list<Convergence::Tags::IterationId<Label>>;
      47             : 
      48           0 :   bool operator()(const size_t iteration_id) const {
      49             :     const auto step_number = static_cast<uint64_t>(iteration_id);
      50             :     return step_number >= offset_ and (step_number - offset_) % interval_ == 0;
      51             :   }
      52             : 
      53             :   // NOLINTNEXTLINE(google-runtime-references)
      54           0 :   void pup(PUP::er& p) {
      55             :     p | interval_;
      56             :     p | offset_;
      57             :   }
      58             : 
      59             :  private:
      60           0 :   uint64_t interval_{0};
      61           0 :   uint64_t offset_{0};
      62             : };
      63             : 
      64             : /// \cond
      65             : template <typename Label>
      66             : PUP::able::PUP_ID EveryNIterations<Label>::my_PUP_ID = 0;  // NOLINT
      67             : /// \endcond
      68             : }  // namespace elliptic::Triggers

Generated by: LCOV version 1.14