TimeCompares.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 "Utilities/Registration.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 /// \cond
17 namespace Tags {
18 struct Time;
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 based on a comparison with the time.
33 template <typename TriggerRegistrars = tmpl::list<Registrars::TimeCompares>>
34 class TimeCompares : public Trigger<TriggerRegistrars> {
35  public:
36  /// \cond
37  TimeCompares() = default;
38  explicit TimeCompares(CkMigrateMessage* /*unused*/) noexcept {}
39  using PUP::able::register_constructor;
40  WRAPPED_PUPable_decl_template(TimeCompares); // NOLINT
41  /// \endcond
42 
43  struct Comparison {
44  using type = Options::Comparator;
45  constexpr static Options::String help = "Comparison type";
46  };
47 
48  struct Value {
49  using type = double;
50  constexpr static Options::String help = "Value to compare to";
51  };
52 
53  using options = tmpl::list<Comparison, Value>;
54  static constexpr Options::String help{
55  "Trigger based on a comparison with the time."};
56 
57  explicit TimeCompares(const Options::Comparator comparator,
58  const double time) noexcept
59  : comparator_(comparator), time_(time) {}
60 
61  using argument_tags = tmpl::list<Tags::Time>;
62 
63  bool operator()(const double& time) const noexcept {
64  return comparator_(time, time_);
65  }
66 
67  // NOLINTNEXTLINE(google-runtime-references)
68  void pup(PUP::er& p) noexcept {
69  p | comparator_;
70  p | time_;
71  }
72 
73  private:
74  Options::Comparator comparator_{};
75  double time_{};
76 };
77 
78 /// \cond
79 template <typename TriggerRegistrars>
80 PUP::able::PUP_ID TimeCompares<TriggerRegistrars>::my_PUP_ID = 0; // NOLINT
81 /// \endcond
82 } // namespace Triggers
CharmPupable.hpp
Triggers::TimeCompares::Value
Definition: TimeCompares.hpp:48
Options.hpp
Triggers::TimeCompares
Definition: TimeCompares.hpp:24
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
Trigger
Definition: Trigger.hpp:34
Triggers::TimeCompares::Comparison
Definition: TimeCompares.hpp:43
Options::Comparator
An option-creatable mathematical comparison.
Definition: Comparator.hpp:21
limits
Time
Definition: Time.hpp:29
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
TMPL.hpp