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