Or.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <algorithm>
7 #include <limits>
8 #include <memory>
9 #include <pup.h>
10 #include <pup_stl.h>
11 #include <utility>
12 #include <vector>
13 
15 #include "Evolution/EventsAndDenseTriggers/DenseTrigger.hpp"
16 #include "Options/Options.hpp"
17 #include "Options/ParseOptions.hpp"
19 #include "Time/EvolutionOrdering.hpp"
20 #include "Time/TimeStepId.hpp"
21 #include "Utilities/Algorithm.hpp"
22 #include "Utilities/Registration.hpp"
23 #include "Utilities/TMPL.hpp"
24 
25 /// \cond
26 namespace Tags {
27 struct TimeStepId;
28 } // namespace Tags
29 /// \endcond
30 
31 namespace DenseTriggers {
32 /// \cond
33 template <typename TriggerRegistrars>
34 class Or;
35 /// \endcond
36 
37 namespace Registrars {
39 } // namespace Registrars
40 
41 /// \ingroup EventsAndTriggersGroup
42 /// Trigger when any of a collection of DenseTriggers triggers.
43 template <typename TriggerRegistrars>
44 class Or : public DenseTrigger<TriggerRegistrars> {
45  public:
46  /// \cond
47  Or() = default;
48  explicit Or(CkMigrateMessage* const msg) noexcept
50  using PUP::able::register_constructor;
52  /// \endcond
53 
54  using Result = typename DenseTrigger<TriggerRegistrars>::Result;
55 
56  static constexpr Options::String help =
57  "Trigger when any of a collection of triggers triggers.";
58 
60  triggers) noexcept
61  : triggers_(std::move(triggers)) {}
62 
63  using is_triggered_argument_tags =
64  tmpl::list<Tags::TimeStepId, Tags::DataBox>;
65 
66  template <typename DbTags>
67  Result is_triggered(const TimeStepId& time_step_id,
68  const db::DataBox<DbTags>& box) const noexcept {
69  const evolution_less<double> before{time_step_id.time_runs_forward()};
70  Result result{false, time_step_id.time_runs_forward()
73  for (const auto& trigger : triggers_) {
74  const auto sub_result = trigger->is_triggered(box);
75  if (sub_result.is_triggered) {
76  // We can't short-circuit because we need to make sure we
77  // report the next time that any of the triggers wants to be
78  // checked, whether they triggered now or not.
79  result.is_triggered = true;
80  }
81  result.next_check =
82  std::min(sub_result.next_check, result.next_check, before);
83  }
84  return result;
85  }
86 
87  using is_ready_argument_tags = tmpl::list<Tags::DataBox>;
88 
89  template <typename DbTags>
90  bool is_ready(const db::DataBox<DbTags>& box) const noexcept {
91  return alg::all_of(
92  triggers_,
94  trigger) noexcept { return trigger->is_ready(box); });
95  }
96 
97  // NOLINTNEXTLINE(google-runtime-references)
98  void pup(PUP::er& p) noexcept override {
100  p | triggers_;
101  }
102 
103  private:
105 };
106 
107 /// \cond
108 template <typename TriggerRegistrars>
109 PUP::able::PUP_ID Or<TriggerRegistrars>::my_PUP_ID = 0; // NOLINT
110 /// \endcond
111 } // namespace DenseTriggers
112 
113 template <typename TriggerRegistrars>
114 struct Options::create_from_yaml<DenseTriggers::Or<TriggerRegistrars>> {
115  template <typename Metavariables>
116  static DenseTriggers::Or<TriggerRegistrars> create(const Option& options) {
118  options.parse_as<
120  }
121 };
DenseTriggers::Or
Definition: Or.hpp:44
CharmPupable.hpp
utility
Options.hpp
vector
evolution_comparator
Definition: EvolutionOrdering.hpp:20
ParseOptions.hpp
algorithm
Options::Option
Definition: Options.hpp:108
Registration::Registrar
A template for defining a registrar.
Definition: Registration.hpp:42
DenseTrigger
Definition: DenseTrigger.hpp:31
WRAPPED_PUPable_decl_template
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
DataBox.hpp
std::numeric_limits::infinity
T infinity(T... args)
Options::create_from_yaml
Definition: MinmodType.hpp:11
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
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
std::unique_ptr
alg::all_of
decltype(auto) all_of(const Container &c, UnaryPredicate &&unary_predicate)
Convenience wrapper around std::all_of.
Definition: Algorithm.hpp:181
TMPL.hpp