EveryNSlabs.hpp
1 // 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 "Evolution/EventsAndTriggers/Trigger.hpp"
10 #include "Options/Options.hpp"
12 #include "Time/TimeId.hpp"
13 #include "Utilities/Registration.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 /// \cond
17 namespace Tags {
18 struct TimeId;
19 } // namespace Tags
20 /// \endcond
21 
22 namespace Triggers {
23 template <typename TriggerRegistrars>
25 
26 namespace Registrars {
28 } // namespace Registrars
29 
30 /// \ingroup EventsAndTriggersGroup
31 /// \ingroup TimeGroup
32 /// Trigger every N time slabs after a given offset.
33 template <typename TriggerRegistrars = tmpl::list<Registrars::EveryNSlabs>>
34 class EveryNSlabs : public Trigger<TriggerRegistrars> {
35  public:
36  /// \cond
37  EveryNSlabs() = default;
38  explicit EveryNSlabs(CkMigrateMessage* /*unused*/) noexcept {}
39  using PUP::able::register_constructor;
41  /// \endcond
42 
43  struct N {
44  using type = uint64_t;
45  static constexpr OptionString help{"How frequently to trigger."};
46  static type lower_bound() noexcept { return 1; }
47  };
48  struct Offset {
49  using type = uint64_t;
50  static constexpr OptionString help{"First slab to trigger on."};
51  static type default_value() noexcept { return 0; }
52  };
53 
54  using options = tmpl::list<N, Offset>;
55  static constexpr OptionString help{
56  "Trigger every N time slabs after a given offset."};
57 
58  EveryNSlabs(const uint64_t interval, const uint64_t offset) noexcept
59  : interval_(interval), offset_(offset) {}
60 
61  using argument_tags = tmpl::list<Tags::TimeId>;
62 
63  bool operator()(const TimeId& time_id) const noexcept {
64  const auto slab_number = static_cast<uint64_t>(time_id.slab_number());
65  return slab_number >= offset_ and (slab_number - offset_) % interval_ == 0;
66  }
67 
68  // clang-tidy: google-runtime-references
69  void pup(PUP::er& p) noexcept { // NOLINT
70  p | interval_;
71  p | offset_;
72  }
73 
74  private:
75  uint64_t interval_{0};
76  uint64_t offset_{0};
77 };
78 
79 /// \cond
80 template <typename TriggerRegistrars>
81 PUP::able::PUP_ID EveryNSlabs<TriggerRegistrars>::my_PUP_ID = 0; // NOLINT
82 /// \endcond
83 } // namespace Triggers
Definition: EveryNSlabs.hpp:43
A unique identifier for the temporal state of an integrated system.
Definition: TimeId.hpp:25
Defines classes and functions for making classes creatable from input files.
Defines macros to allow serialization of abstract template base classes.
Defines class TimeId.
Trigger every N time slabs after a given offset.
Definition: EveryNSlabs.hpp:24
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:26
A template for defining a registrar.
Definition: Registration.hpp:42
Definition: DataBoxTag.hpp:29
Wraps the template metaprogramming library used (brigand)
Base class for checking whether to run an Event.
Definition: Trigger.hpp:35
Definition: LogicalTriggers.hpp:13
Definition: EveryNSlabs.hpp:48