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/TMPL.hpp"
15 
16 /// \cond
17 namespace Tags {
18 struct TimeStepId;
19 } // namespace Tags
20 /// \endcond
21 
22 namespace Triggers {
23 /// \ingroup EventsAndTriggersGroup
24 /// \ingroup TimeGroup
25 /// Trigger based on a comparison with the slab number.
26 class SlabCompares : public Trigger {
27  public:
28  /// \cond
29  SlabCompares() = default;
30  explicit SlabCompares(CkMigrateMessage* /*unused*/) noexcept {}
31  using PUP::able::register_constructor;
33  /// \endcond
34 
35  struct Comparison {
36  using type = Options::Comparator;
37  constexpr static Options::String help = "Comparison type";
38  };
39 
40  struct Value {
41  using type = uint64_t;
42  constexpr static Options::String help = "Value to compare to";
43  };
44 
45  using options = tmpl::list<Comparison, Value>;
46  static constexpr Options::String help{
47  "Trigger based on a comparison with the slab number."};
48 
49  explicit SlabCompares(const Options::Comparator comparator,
50  const uint64_t slab_number) noexcept
51  : comparator_(comparator), slab_number_(slab_number) {}
52 
53  using argument_tags = tmpl::list<Tags::TimeStepId>;
54 
55  bool operator()(const TimeStepId& time_step_id) const noexcept {
56  return comparator_(static_cast<uint64_t>(time_step_id.slab_number()),
57  slab_number_);
58  }
59 
60  // NOLINTNEXTLINE(google-runtime-references)
61  void pup(PUP::er& p) noexcept {
62  p | comparator_;
63  p | slab_number_;
64  }
65 
66  private:
67  Options::Comparator comparator_{};
68  uint64_t slab_number_{};
69 };
70 } // namespace Triggers
Triggers::SlabCompares
Definition: SlabCompares.hpp:26
CharmPupable.hpp
Options.hpp
Triggers::SlabCompares::Comparison
Definition: SlabCompares.hpp:35
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:40
Trigger
Definition: Trigger.hpp:17
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