EventsAndTriggers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <memory>
7 #include <pup.h>
8 #include <unordered_map>
9 
11 #include "Evolution/EventsAndTriggers/Event.hpp"
12 #include "Evolution/EventsAndTriggers/Trigger.hpp"
14 
15 /// \ingroup EventsAndTriggersGroup
16 /// Class that checks triggers and runs events
17 template <typename EventRegistrars, typename TriggerRegistrars>
19  public:
20  using Storage =
23 
24  EventsAndTriggers() = default;
25  explicit EventsAndTriggers(Storage events_and_triggers) noexcept
26  : events_and_triggers_(std::move(events_and_triggers)) {}
27 
28  template <typename DbTags, typename Metavariables, typename ArrayIndex,
29  typename Component>
30  void run_events(const db::DataBox<DbTags>& box,
32  const ArrayIndex& array_index,
33  const Component* component) const noexcept {
34  for (const auto& trigger_and_events : events_and_triggers_) {
35  const auto& trigger = trigger_and_events.first;
36  const auto& events = trigger_and_events.second;
37  if (trigger->is_triggered(box)) {
38  for (const auto& event : events) {
39  event->run(box, cache, array_index, component);
40  }
41  }
42  }
43  }
44 
45  // clang-tidy: google-runtime-references
46  void pup(PUP::er& p) noexcept { // NOLINT
47  p | events_and_triggers_;
48  }
49 
50  private:
51  // The unique pointer contents *must* be treated as const everywhere
52  // in order to make the const global cache behave sanely. They are
53  // only non-const to make pup work.
54  Storage events_and_triggers_;
55 };
56 
57 template <typename EventRegistrars, typename TriggerRegistrars>
58 struct create_from_yaml<EventsAndTriggers<EventRegistrars, TriggerRegistrars>> {
60  static type create(const Option& options) {
61  return type(options.parse_as<typename type::Storage>());
62  }
63 };
64 
65 namespace Tags {
66 /// \cond
67 struct EventsAndTriggersTagBase {};
68 /// \endcond
69 
70 /// \ingroup OptionTagsGroup
71 /// \ingroup EventsAndTriggersGroup
72 /// Contains the events and triggers
73 template <typename EventRegistrars, typename TriggerRegistrars>
74 struct EventsAndTriggers : EventsAndTriggersTagBase {
76 };
77 } // namespace Tags
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
Contains the events and triggers.
Definition: EventsAndTriggers.hpp:74
Used by the parser to create an object. The default action is to parse options using T::options...
Definition: Options.hpp:143
constexpr auto create(Args &&... args)
Create a new DataBox.
Definition: DataBox.hpp:1259
Class that checks triggers and runs events.
Definition: EventsAndTriggers.hpp:18
Defines classes and functions used for manipulating DataBox&#39;s.
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Definition: DataBoxTag.hpp:29
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Definition: SolvePoissonProblem.hpp:38
Defines class template ConstGlobalCache.