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/TerminatePhase.hpp"
17 #include "Parallel/ArrayIndex.hpp"
18 #include "Utilities/Functional.hpp"
19 #include "Utilities/TMPL.hpp"
20 
21 /// \cond
22 namespace db {
23 template <typename TagsList>
24 class DataBox;
25 } // namespace db
26 /// \endcond
27 
28 namespace TestObservers_detail {
29 using ElementIdType = ElementId<2>;
30 
31 template <observers::TypeOfObservation TypeOfObservation>
32 struct RegisterObservers {
33  template <typename ParallelComponent, typename DbTagsList,
34  typename ArrayIndex>
36  register_info(const db::DataBox<DbTagsList>& /*box*/,
37  const ArrayIndex& /*array_index*/) noexcept {
38  return {TypeOfObservation,
39  observers::ObservationKey{"ElementObservationType"}};
40  }
41 };
42 
43 template <typename Metavariables, typename RegistrationActionsList>
44 struct element_component {
45  using component_being_mocked = void; // Not needed
46  using metavariables = Metavariables;
47  using chare_type = ActionTesting::MockArrayChare;
48  using array_index = ElementIdType;
49 
50  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
51  typename Metavariables::Phase,
52  Metavariables::Phase::RegisterWithObservers, RegistrationActionsList>>;
53 };
54 
55 template <typename Metavariables>
56 struct observer_component {
57  using metavariables = Metavariables;
58  using chare_type = ActionTesting::MockArrayChare;
59  using array_index = int;
60 
61  using component_being_mocked = observers::Observer<Metavariables>;
62  using simple_tags =
63  typename observers::Actions::Initialize<Metavariables>::simple_tags;
64  using compute_tags =
65  typename observers::Actions::Initialize<Metavariables>::compute_tags;
66 
67  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
68  typename Metavariables::Phase, Metavariables::Phase::Initialization,
69  tmpl::list<observers::Actions::Initialize<Metavariables>>>>;
70 };
71 
72 template <typename Metavariables>
73 struct observer_writer_component {
74  using metavariables = Metavariables;
75  using chare_type = ActionTesting::MockArrayChare;
76  using array_index = int;
77  using const_global_cache_tags = tmpl::list<observers::Tags::ReductionFileName,
79 
80  using component_being_mocked = observers::ObserverWriter<Metavariables>;
81  using simple_tags =
82  typename observers::Actions::InitializeWriter<Metavariables>::simple_tags;
83  using compute_tags = typename observers::Actions::InitializeWriter<
84  Metavariables>::compute_tags;
85 
86  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
87  typename Metavariables::Phase, Metavariables::Phase::Initialization,
88  tmpl::list<observers::Actions::InitializeWriter<Metavariables>>>>;
89 };
90 
94 using reduction_data_from_doubles = Parallel::ReductionData<
97  l2_error_datum>;
98 
99 using reduction_data_from_vector = Parallel::ReductionData<
103 
104 // Nothing special about the order. We just want doubles and std::vector's.
105 using reduction_data_from_ds_and_vs = Parallel::ReductionData<
110  l2_error_datum>;
111 
112 template <typename RegistrationActionsList>
113 struct Metavariables {
114  using component_list =
115  tmpl::list<element_component<Metavariables, RegistrationActionsList>,
116  observer_component<Metavariables>,
117  observer_writer_component<Metavariables>>;
118 
119  /// [make_reduction_data_tags]
120  using observed_reduction_data_tags = observers::make_reduction_data_tags<
121  tmpl::list<reduction_data_from_doubles, reduction_data_from_vector,
122  reduction_data_from_ds_and_vs>>;
123  /// [make_reduction_data_tags]
124 
125  enum class Phase { Initialization, RegisterWithObservers, Testing, Exit };
126 };
127 } // namespace TestObservers_detail
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:48
observers::Observer
The group parallel component that is responsible for reducing data to be observed.
Definition: ObserverComponent.hpp:27
observers::Actions::InitializeWriter
Initializes the DataBox of the observer parallel component that writes to disk.
Definition: Initialize.hpp:84
ActionTesting::MockArrayChare
A mock class for the CMake-generated Parallel::Algorithms::Array
Definition: ActionTesting.hpp:1588
observers::Tags::VolumeFileName
The name of the HDF5 file on disk into which volume data is written.
Definition: Tags.hpp:177
db::DataBox
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
TMPL.hpp
db
Namespace for DataBox related things.
Definition: DataBox.hpp:43