SlabCompares.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <limits>
7 #include <pup.h>
8 
9 #include "Options/Comparator.hpp"
10 #include "Options/Options.hpp"
12 #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
13 #include "Time/TimeStepId.hpp"
14 #include "Utilities/Registration.hpp"
15 #include "Utilities/TMPL.hpp"
16 
17 /// \cond
18 namespace Tags {
19 struct TimeStepId;
20 } // namespace Tags
21 /// \endcond
22 
23 namespace Triggers {
24 template <typename TriggerRegistrars>
26 
27 namespace Registrars {
29 } // namespace Registrars
30 
31 /// \ingroup EventsAndTriggersGroup
32 /// \ingroup TimeGroup
33 /// Trigger based on a comparison with the slab number.
34 template <typename TriggerRegistrars = tmpl::list<Registrars::SlabCompares>>
35 class SlabCompares : public Trigger<TriggerRegistrars> {
36  public:
37  /// \cond
38  SlabCompares() = default;
39  explicit SlabCompares(CkMigrateMessage* /*unused*/) noexcept {}
40  using PUP::able::register_constructor;
41  WRAPPED_PUPable_decl_template(SlabCompares); // NOLINT
42  /// \endcond
43 
44  struct Comparison {
45  using type = Options::Comparator;
46  constexpr static Options::String help = "Comparison type";
47  };
48 
49  struct Value {
50  using type = uint64_t;
51  constexpr static Options::String help = "Value to compare to";
52  };
53 
54  using options = tmpl::list<Comparison, Value>;
55  static constexpr Options::String help{
56  "Trigger based on a comparison with the slab number."};
57 
58  explicit SlabCompares(const Options::Comparator comparator,
59  const uint64_t slab_number) noexcept
60  : comparator_(comparator), slab_number_(slab_number) {}
61 
62  using argument_tags = tmpl::list<Tags::TimeStepId>;
63 
64  bool operator()(const TimeStepId& time_step_id) const noexcept {
65  return comparator_(static_cast<uint64_t>(time_step_id.slab_number()),
66  slab_number_);
67  }
68 
69  // NOLINTNEXTLINE(google-runtime-references)
70  void pup(PUP::er& p) noexcept {
71  p | comparator_;
72  p | slab_number_;
73  }
74 
75  private:
76  Options::Comparator comparator_{};
77  uint64_t slab_number_{};
78 };
79 
80 /// \cond
81 template <typename TriggerRegistrars>
82 PUP::able::PUP_ID SlabCompares<TriggerRegistrars>::my_PUP_ID = 0; // NOLINT
83 /// \endcond
84 } // namespace Triggers
Triggers::SlabCompares
Definition: SlabCompares.hpp:25
CharmPupable.hpp
Options.hpp
Triggers::SlabCompares::Comparison
Definition: SlabCompares.hpp:44
Registration::Registrar
A template for defining a registrar.
Definition: Registration.hpp:42
WRAPPED_PUPable_decl_template
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
Triggers::SlabCompares::Value
Definition: SlabCompares.hpp:49
Trigger
Definition: Trigger.hpp:34
TimeStepId
Definition: TimeStepId.hpp:25
Options::Comparator
An option-creatable mathematical comparison.
Definition: Comparator.hpp:21
TimeStepId.hpp
limits
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
TMPL.hpp