Times.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cmath>
7 #include <memory>
8 #include <pup.h>
9 #include <pup_stl.h>
10 #include <utility>
11 
12 #include "Options/Options.hpp"
13 #include "Options/ParseOptions.hpp"
15 #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
16 #include "Time/TimeSequence.hpp"
17 #include "Time/TimeStepId.hpp"
18 #include "Time/Utilities.hpp"
19 #include "Utilities/Registration.hpp"
20 #include "Utilities/TMPL.hpp"
21 
22 /// \cond
23 namespace Tags {
24 struct Time;
25 struct TimeStepId;
26 } // namespace Tags
27 /// \endcond
28 
29 namespace Triggers {
30 template <typename TriggerRegistrars>
31 class Times;
32 
33 namespace Registrars {
35 } // namespace Registrars
36 
37 /// \ingroup EventsAndTriggersGroup
38 /// \ingroup TimeGroup
39 /// Trigger at particular times.
40 ///
41 /// \warning This trigger will only fire if it is actually checked at
42 /// the times specified. The StepToTimes StepChooser can be useful
43 /// for this.
44 template <typename TriggerRegistrars = tmpl::list<Registrars::Times>>
45 class Times : public Trigger<TriggerRegistrars> {
46  public:
47  /// \cond
48  Times() = default;
49  explicit Times(CkMigrateMessage* /*unused*/) noexcept {}
50  using PUP::able::register_constructor;
51  WRAPPED_PUPable_decl_template(Times); // NOLINT
52  /// \endcond
53 
54  static constexpr Options::String help{"Trigger at particular times."};
55 
56  explicit Times(std::unique_ptr<TimeSequence<double>> times) noexcept
57  : times_(std::move(times)) {}
58 
59  using argument_tags = tmpl::list<Tags::Time, Tags::TimeStepId>;
60 
61  bool operator()(const double now, const TimeStepId& time_id) const noexcept {
62  const auto& substep_time = time_id.substep_time();
63  // Trying to step to a given time might not get us exactly there
64  // because of rounding errors.
65  const double sloppiness = slab_rounding_error(substep_time);
66 
67  const auto nearby_time = times_->times_near(now)[1];
68  return nearby_time and std::abs(*nearby_time - now) < sloppiness;
69  }
70 
71  // NOLINTNEXTLINE(google-runtime-references)
72  void pup(PUP::er& p) noexcept override { p | times_; }
73 
74  private:
76 };
77 
78 /// \cond
79 template <typename TriggerRegistrars>
80 PUP::able::PUP_ID Times<TriggerRegistrars>::my_PUP_ID = 0; // NOLINT
81 /// \endcond
82 } // namespace Triggers
83 
84 template <typename TriggerRegistrars>
85 struct Options::create_from_yaml<Triggers::Times<TriggerRegistrars>> {
86  template <typename Metavariables>
87  static Triggers::Times<TriggerRegistrars> create(const Option& options) {
90  }
91 };
CharmPupable.hpp
utility
Options.hpp
slab_rounding_error
double slab_rounding_error(const Time &time) noexcept
Definition: Utilities.cpp:12
ParseOptions.hpp
cmath
Triggers::Times
Definition: Times.hpp:31
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
WRAPPED_PUPable_decl_template
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
Options::create_from_yaml
Definition: MinmodType.hpp:11
Trigger
Definition: Trigger.hpp:34
memory
TimeStepId
Definition: TimeStepId.hpp:25
TimeStepId.hpp
Options::Option::parse_as
T parse_as() const
Convert to an object of type T.
Definition: ParseOptions.hpp:75
Time
Definition: Time.hpp:29
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
std::unique_ptr
TMPL.hpp