ObserverHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <functional>
7 
9 #include "Framework/ActionTesting.hpp"
10 #include "IO/Observer/Helpers.hpp"
11 #include "IO/Observer/Initialize.hpp" // IWYU pragma: keep
12 #include "IO/Observer/ObservationId.hpp" // IWYU pragma: keep
13 #include "IO/Observer/ObserverComponent.hpp" // IWYU pragma: keep
14 #include "IO/Observer/Tags.hpp"
15 #include "IO/Observer/TypeOfObservation.hpp"
16 #include "Parallel/Actions/SetupDataBox.hpp"
17 #include "Parallel/Actions/TerminatePhase.hpp"
18 #include "Parallel/ArrayIndex.hpp"
19 #include "Utilities/Functional.hpp"
20 #include "Utilities/TMPL.hpp"
21 
22 /// \cond
23 namespace db {
24 template <typename TagsList>
25 class DataBox;
26 } // namespace db
27 /// \endcond
28 
29 namespace TestObservers_detail {
30 using ElementIdType = ElementId<2>;
31 
32 template <observers::TypeOfObservation TypeOfObservation>
33 struct RegisterObservers {
34  template <typename ParallelComponent, typename DbTagsList,
35  typename ArrayIndex>
37  register_info(const db::DataBox<DbTagsList>& /*box*/,
38  const ArrayIndex& /*array_index*/) noexcept {
39  return {TypeOfObservation,
40  observers::ObservationKey{"ElementObservationType"}};
41  }
42 };
43 
44 template <typename Metavariables, typename RegistrationActionsList>
45 struct element_component {
46  using component_being_mocked = void; // Not needed
47  using metavariables = Metavariables;
48  using chare_type = ActionTesting::MockArrayChare;
49  using array_index = ElementIdType;
50 
51  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
52  typename Metavariables::Phase,
53  Metavariables::Phase::RegisterWithObservers, RegistrationActionsList>>;
54 };
55 
56 template <typename Metavariables>
57 struct observer_component {
58  using metavariables = Metavariables;
59  using chare_type = ActionTesting::MockArrayChare;
60  using array_index = int;
61 
62  using component_being_mocked = observers::Observer<Metavariables>;
63  using simple_tags =
64  typename observers::Actions::Initialize<Metavariables>::simple_tags;
65  using compute_tags =
66  typename observers::Actions::Initialize<Metavariables>::compute_tags;
67 
68  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
69  typename Metavariables::Phase, Metavariables::Phase::Initialization,
70  tmpl::list<Actions::SetupDataBox,
72 };
73 
74 template <typename Metavariables>
75 struct observer_writer_component {
76  using metavariables = Metavariables;
77  using chare_type = ActionTesting::MockArrayChare;
78  using array_index = int;
79  using const_global_cache_tags = tmpl::list<observers::Tags::ReductionFileName,
81 
82  using component_being_mocked = observers::ObserverWriter<Metavariables>;
83  using simple_tags =
84  typename observers::Actions::InitializeWriter<Metavariables>::simple_tags;
85  using compute_tags = typename observers::Actions::InitializeWriter<
86  Metavariables>::compute_tags;
87 
88  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
89  typename Metavariables::Phase, Metavariables::Phase::Initialization,
90  tmpl::list<Actions::SetupDataBox,
92 };
93 
97 using reduction_data_from_doubles = Parallel::ReductionData<
100  l2_error_datum>;
101 
102 using reduction_data_from_vector = Parallel::ReductionData<
106 
107 // Nothing special about the order. We just want doubles and std::vector's.
108 using reduction_data_from_ds_and_vs = Parallel::ReductionData<
113  l2_error_datum>;
114 
115 template <typename RegistrationActionsList>
116 struct Metavariables {
117  using component_list =
118  tmpl::list<element_component<Metavariables, RegistrationActionsList>,
119  observer_component<Metavariables>,
120  observer_writer_component<Metavariables>>;
121 
122  /// [make_reduction_data_tags]
123  using observed_reduction_data_tags = observers::make_reduction_data_tags<
124  tmpl::list<reduction_data_from_doubles, reduction_data_from_vector,
125  reduction_data_from_ds_and_vs>>;
126  /// [make_reduction_data_tags]
127 
128  enum class Phase { Initialization, RegisterWithObservers, Testing, Exit };
129 };
130 } // namespace TestObservers_detail
Actions::SetupDataBox
Add into the DataBox default constructed items for the collection of tags requested by any of the act...
Definition: SetupDataBox.hpp:81
observers::Tags::ReductionFileName
The name of the HDF5 file on disk into which reduction data is written.
Definition: Tags.hpp:195
funcl::VectorPlus
Function for adding two std::vectors of double component-wise.
Definition: Functional.hpp:312
Parallel::ReductionDatum
The data to be reduced, and invokables to be called whenever two reduction messages are combined and ...
Definition: Reduction.hpp:63
functional
std::pair
std::index_sequence
observers::ObservationKey
Used as a key in maps to keep track of how many elements have registered.
Definition: ObservationId.hpp:28
observers::TypeOfObservation
TypeOfObservation
Specifies the type of observation.
Definition: TypeOfObservation.hpp:18
ElementId
An ElementId uniquely labels an Element.
Definition: ElementId.hpp:49
ElementId.hpp
funcl::Sqrt
Functional for computing sqrt on an object.
Definition: Functional.hpp:273
Parallel::PhaseActions
List of all the actions to be executed in the specified phase.
Definition: PhaseDependentActionList.hpp:16
observers::ObserverWriter
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:51
observers::Actions::Initialize
Initializes the DataBox on the observer parallel component.
Definition: Initialize.hpp:33
observers::Observer
The group parallel component that is responsible for reducing data to be observed.
Definition: ObserverComponent.hpp:29
observers::Actions::InitializeWriter
Initializes the DataBox of the observer parallel component that writes to disk.
Definition: Initialize.hpp:71
ActionTesting::MockArrayChare
A mock class for the CMake-generated Parallel::Algorithms::Array
Definition: ActionTesting.hpp:556
observers::Tags::VolumeFileName
The name of the HDF5 file on disk into which volume data is written.
Definition: Tags.hpp:177
TMPL.hpp
db
Namespace for DataBox related things.
Definition: DataBox.hpp:43