Times.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <limits>
8 #include <memory>
9 #include <optional>
10 #include <pup.h>
11 #include <pup_stl.h>
12 #include <utility>
13 
14 #include "Options/Options.hpp"
15 #include "Options/ParseOptions.hpp"
17 #include "Evolution/EventsAndDenseTriggers/DenseTrigger.hpp"
18 #include "Time/EvolutionOrdering.hpp"
19 #include "Time/TimeSequence.hpp"
20 #include "Time/TimeStepId.hpp"
21 #include "Utilities/Registration.hpp"
22 #include "Utilities/TMPL.hpp"
23 
24 /// \cond
25 namespace Tags {
26 struct Time;
27 struct TimeStepId;
28 } // namespace Tags
29 /// \endcond
30 
31 namespace DenseTriggers {
32 /// \cond
33 template <typename TriggerRegistrars>
34 class Times;
35 /// \endcond
36 
37 namespace Registrars {
39 } // namespace Registrars
40 
41 /// \ingroup EventsAndTriggersGroup
42 /// \ingroup TimeGroup
43 /// Trigger at specified times.
44 template <typename TriggerRegistrars = tmpl::list<Registrars::Times>>
45 class Times : public DenseTrigger<TriggerRegistrars> {
46  public:
47  /// \cond
48  Times() = default;
49  explicit Times(CkMigrateMessage* const msg) noexcept
51  using PUP::able::register_constructor;
53  /// \endcond
54 
55  using Result = typename DenseTrigger<TriggerRegistrars>::Result;
56 
57  static constexpr Options::String help{"Trigger at specified times."};
58 
59  explicit Times(std::unique_ptr<TimeSequence<double>> times) noexcept
60  : times_(std::move(times)) {}
61 
62  using is_triggered_argument_tags = tmpl::list<Tags::TimeStepId, Tags::Time>;
63 
64  Result is_triggered(const TimeStepId& time_step_id,
65  const double time) const noexcept {
66  const evolution_less<double> before{time_step_id.time_runs_forward()};
67 
68  const auto trigger_times = times_->times_near(time);
69  double next_time = time_step_id.time_runs_forward()
72  for (const auto& trigger_time : trigger_times) {
73  if (trigger_time.has_value() and before(time, *trigger_time) and
74  before(*trigger_time, next_time)) {
75  next_time = *trigger_time;
76  }
77  }
78 
79  return {time == trigger_times[1], next_time};
80  }
81 
82  using is_ready_argument_tags = tmpl::list<>;
83 
84  bool is_ready() const noexcept {
85  return true;
86  }
87 
88  // NOLINTNEXTLINE(google-runtime-references)
89  void pup(PUP::er& p) noexcept override {
91  p | times_;
92  }
93 
94  private:
96 };
97 
98 /// \cond
99 template <typename TriggerRegistrars>
100 PUP::able::PUP_ID Times<TriggerRegistrars>::my_PUP_ID = 0; // NOLINT
101 /// \endcond
102 } // namespace DenseTriggers
103 
104 template <typename TriggerRegistrars>
105 struct Options::create_from_yaml<DenseTriggers::Times<TriggerRegistrars>> {
106  template <typename Metavariables>
107  static DenseTriggers::Times<TriggerRegistrars> create(const Option& options) {
110  }
111 };
CharmPupable.hpp
utility
Options.hpp
evolution_comparator
Definition: EvolutionOrdering.hpp:20
ParseOptions.hpp
Options::Option
Definition: Options.hpp:108
Registration::Registrar
A template for defining a registrar.
Definition: Registration.hpp:42
TimeSequence
Represents a sequence of times.
Definition: TimeSequence.hpp:31
DenseTrigger
Definition: DenseTrigger.hpp:31
WRAPPED_PUPable_decl_template
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
std::numeric_limits::infinity
T infinity(T... args)
Options::create_from_yaml
Definition: MinmodType.hpp:11
array
memory
TimeStepId
Definition: TimeStepId.hpp:25
TimeStepId.hpp
limits
Options::Option::parse_as
T parse_as() const
Convert to an object of type T.
Definition: ParseOptions.hpp:93
Time
Definition: Time.hpp:29
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
optional
std::unique_ptr
TMPL.hpp
DenseTriggers::Times
Definition: Times.hpp:45