Line data Source code
1 1 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : /// \file
5 : /// Defines tags related to Events and Triggers
6 :
7 : #pragma once
8 :
9 : #include <memory>
10 : #include <pup_stl.h>
11 : #include <vector>
12 :
13 : #include "DataStructures/DataBox/Tag.hpp"
14 : #include "Options/String.hpp"
15 : #include "ParallelAlgorithms/EventsAndTriggers/EventsAndTriggers.hpp"
16 : #include "ParallelAlgorithms/EventsAndTriggers/WhenToCheck.hpp"
17 : #include "Utilities/GetOutput.hpp"
18 : #include "Utilities/Serialization/Serialize.hpp"
19 : #include "Utilities/TMPL.hpp"
20 :
21 : namespace OptionTags {
22 : /// \ingroup OptionTagsGroup
23 : /// \ingroup EventsAndTriggersGroup
24 : /// Contains the events and triggers
25 : ///
26 : /// In yaml this is specified as a map of triggers to lists of events:
27 : /// \code{.yaml}
28 : /// EventsAndTriggersAtSlabs:
29 : /// ? TriggerA:
30 : /// OptionsForTriggerA
31 : /// : - Event1:
32 : /// OptionsForEvent1
33 : /// - Event2:
34 : /// OptionsForEvent2
35 : /// ? TriggerB:
36 : /// OptionsForTriggerB
37 : /// : - Event3:
38 : /// OptionsForEvent3
39 : /// - Event4:
40 : /// OptionsForEvent4
41 : /// \endcode
42 : template <Triggers::WhenToCheck WhenToCheck>
43 1 : struct EventsAndTriggers {
44 0 : using type = ::EventsAndTriggers;
45 0 : static constexpr Options::String help = "Events to run at triggers";
46 : // When the template arguments to this struct are sufficiently
47 : // complicated, pretty_type::short_name() run on this struct returns
48 : // something that is neither pretty nor short, and leads to an
49 : // OptionParser run-time error saying that an option name is greater
50 : // than 21 characters. Adding the name() function below bypasses
51 : // pretty_type::short_name().
52 0 : static std::string name() {
53 : return "EventsAndTriggers" + get_output(WhenToCheck);
54 : }
55 : };
56 :
57 0 : namespace EventsRunAtCleanup {
58 0 : struct Group {
59 0 : static std::string name() { return "EventsRunAtCleanup"; }
60 0 : static constexpr Options::String help =
61 : "Options related to running events on failure. This is generally "
62 : "intended for dumping volume data to diagnose failure reasons.";
63 : };
64 :
65 : /// \brief A list of events to run at cleanup.
66 : ///
67 : /// See `Actions::RunEventsOnFailure` for details and caveats.
68 1 : struct Events {
69 0 : static std::string name() { return "Events"; }
70 0 : using type = std::vector<std::unique_ptr<::Event>>;
71 0 : static constexpr Options::String help =
72 : "Events to run during the cleanup phase.";
73 0 : using group = Group;
74 : };
75 :
76 : /// \brief Observation value for Actions::RunEventsOnFailure.
77 1 : struct ObservationValue {
78 0 : using type = double;
79 0 : static constexpr Options::String help =
80 : "Observation value for events run during the cleanup phase.";
81 0 : using group = Group;
82 : };
83 : } // namespace EventsRunAtCleanup
84 : } // namespace OptionTags
85 :
86 : namespace Tags {
87 : /// \ingroup EventsAndTriggersGroup
88 : /// Contains the events and triggers
89 : template <Triggers::WhenToCheck WhenToCheck>
90 1 : struct EventsAndTriggers : db::SimpleTag {
91 0 : using type = ::EventsAndTriggers;
92 0 : using option_tags = tmpl::list<::OptionTags::EventsAndTriggers<WhenToCheck>>;
93 0 : static constexpr bool is_overlayable = true;
94 :
95 0 : static constexpr bool pass_metavariables = false;
96 0 : static type create_from_options(const type& events_and_triggers) {
97 : return serialize_and_deserialize<type>(events_and_triggers);
98 : }
99 0 : static std::string name() {
100 : return "EventsAndTriggers" + get_output(WhenToCheck);
101 : }
102 : };
103 :
104 : /// \brief Events to be run on elements during the
105 : /// `Parallel::Phase::PostFailureCleanup` phase.
106 : ///
107 : /// Useful for troubleshooting runs that are failing.
108 1 : struct EventsRunAtCleanup : db::SimpleTag {
109 0 : using type = std::vector<std::unique_ptr<::Event>>;
110 0 : using option_tags = tmpl::list<OptionTags::EventsRunAtCleanup::Events>;
111 :
112 0 : static constexpr bool pass_metavariables = false;
113 0 : static type create_from_options(const type& events_run_at_cleanup) {
114 : return serialize_and_deserialize<type>(events_run_at_cleanup);
115 : }
116 : };
117 :
118 : /// \brief Observation value for Actions::RunEventsOnFailure.
119 1 : struct EventsRunAtCleanupObservationValue : db::SimpleTag {
120 0 : using type = double;
121 0 : using option_tags =
122 : tmpl::list<OptionTags::EventsRunAtCleanup::ObservationValue>;
123 :
124 0 : static constexpr bool pass_metavariables = false;
125 0 : static type create_from_options(const type& value) { return value; }
126 : };
127 : } // namespace Tags
|