PastTime.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 "Evolution/EventsAndTriggers/Trigger.hpp"
10 #include "Options/Options.hpp"
12 #include "Time/EvolutionOrdering.hpp"
13 #include "Time/TimeId.hpp"
14 #include "Utilities/Registration.hpp"
15 #include "Utilities/TMPL.hpp"
16 
17 /// \cond
18 namespace Tags {
19 struct TimeId;
20 struct TimeValue;
21 } // namespace Tags
22 /// \endcond
23 
24 namespace Triggers {
25 template <typename TriggerRegistrars>
26 class PastTime;
27 
28 namespace Registrars {
30 } // namespace Registrars
31 
32 /// \ingroup EventsAndTriggersGroup
33 /// \ingroup TimeGroup
34 /// Trigger when the simulation is past a certain time (after that
35 /// time if time is running forward, before that time if time is
36 /// running backward).
37 template <typename TriggerRegistrars = tmpl::list<Registrars::PastTime>>
38 class PastTime : public Trigger<TriggerRegistrars> {
39  public:
40  /// \cond
41  PastTime() = default;
42  explicit PastTime(CkMigrateMessage* /*unused*/) noexcept {}
43  using PUP::able::register_constructor;
45  /// \endcond
46 
47  static constexpr OptionString help{
48  "Trigger if the simulation is past a given time."};
49 
50  explicit PastTime(const double trigger_time) noexcept
51  : trigger_time_(trigger_time) {}
52 
53  using argument_tags = tmpl::list<Tags::TimeValue, Tags::TimeId>;
54 
55  bool operator()(const double time, const TimeId& time_id) const noexcept {
56  return evolution_greater<double>{time_id.time_runs_forward()}(
57  time, trigger_time_);
58  }
59 
60  // clang-tidy: google-runtime-references
61  void pup(PUP::er& p) noexcept { // NOLINT
62  p | trigger_time_;
63  }
64 
65  private:
66  double trigger_time_{std::numeric_limits<double>::signaling_NaN()};
67 };
68 
69 /// \cond
70 template <typename TriggerRegistrars>
71 PUP::able::PUP_ID PastTime<TriggerRegistrars>::my_PUP_ID = 0; // NOLINT
72 /// \endcond
73 } // namespace Triggers
74 
75 template <typename TriggerRegistrars>
76 struct create_from_yaml<Triggers::PastTime<TriggerRegistrars>> {
77  static Triggers::PastTime<TriggerRegistrars> create(const Option& options) {
78  return Triggers::PastTime<TriggerRegistrars>(options.parse_as<double>());
79  }
80 };
The type that options are passed around as. Contains YAML node data and an OptionContext.
Definition: Options.hpp:103
T parse_as() const
Convert to an object of type T.
Definition: ParseOptions.hpp:69
T signaling_NaN(T... args)
Used by the parser to create an object. The default action is to parse options using T::options...
Definition: Options.hpp:143
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.
Definition: EvolutionOrdering.hpp:27
Defines macros to allow serialization of abstract template base classes.
constexpr auto create(Args &&... args)
Create a new DataBox.
Definition: DataBox.hpp:1259
Defines class TimeId.
Trigger when the simulation is past a certain time (after that time if time is running forward...
Definition: PastTime.hpp:26
#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