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/Actions.hpp" // IWYU pragma: keep
11 #include "IO/Observer/Helpers.hpp"
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 "Utilities/Functional.hpp"
18 #include "Utilities/TMPL.hpp"
19 
20 /// \cond
21 namespace db {
22 template <typename TagsList>
23 class DataBox;
24 } // namespace db
25 /// \endcond
26 
27 namespace TestObservers_detail {
28 using ElementIndexType = ElementIndex<2>;
29 
30 template <observers::TypeOfObservation TypeOfObservation>
31 struct RegisterThisObsType {
32  struct ElementObservationType {};
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::ObservationId{3.0, ElementObservationType{}}};
40  }
41 };
42 
43 template <typename Metavariables,
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 = ElementIndexType;
50 
51  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
52  typename Metavariables::Phase,
53  Metavariables::Phase::RegisterWithObservers,
55  RegisterThisObsType<TypeOfObservation>>,
57 };
58 
59 template <typename Metavariables>
60 struct observer_component {
61  using metavariables = Metavariables;
62  using chare_type = ActionTesting::MockArrayChare;
63  using array_index = size_t;
64 
65  using component_being_mocked = observers::Observer<Metavariables>;
66  using simple_tags =
67  typename observers::Actions::Initialize<Metavariables>::simple_tags;
68  using compute_tags =
69  typename observers::Actions::Initialize<Metavariables>::compute_tags;
70 
71  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
72  typename Metavariables::Phase, Metavariables::Phase::Initialization,
73  tmpl::list<observers::Actions::Initialize<Metavariables>>>>;
74 };
75 
76 template <typename Metavariables>
77 struct observer_writer_component {
78  using metavariables = Metavariables;
79  using chare_type = ActionTesting::MockArrayChare;
80  using array_index = size_t;
81  using const_global_cache_tags = tmpl::list<observers::Tags::ReductionFileName,
83 
84  using component_being_mocked = observers::ObserverWriter<Metavariables>;
85  using simple_tags =
86  typename observers::Actions::InitializeWriter<Metavariables>::simple_tags;
87  using compute_tags = typename observers::Actions::InitializeWriter<
88  Metavariables>::compute_tags;
89 
90  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
91  typename Metavariables::Phase, Metavariables::Phase::Initialization,
92  tmpl::list<observers::Actions::InitializeWriter<Metavariables>>>>;
93 };
94 
98 using reduction_data_from_doubles = Parallel::ReductionData<
101  l2_error_datum>;
102 
103 using reduction_data_from_vector = Parallel::ReductionData<
104  Parallel::ReductionDatum<double, funcl::AssertEqual<>>,
105  Parallel::ReductionDatum<size_t, funcl::Plus<>>,
107 
108 // Nothing special about the order. We just want doubles and std::vector's.
109 using reduction_data_from_ds_and_vs = Parallel::ReductionData<
110  Parallel::ReductionDatum<double, funcl::AssertEqual<>>,
111  Parallel::ReductionDatum<size_t, funcl::Plus<>>, l2_error_datum,
112  Parallel::ReductionDatum<std::vector<double>, funcl::VectorPlus>,
113  Parallel::ReductionDatum<std::vector<double>, funcl::VectorPlus>,
114  l2_error_datum>;
115 
116 template <observers::TypeOfObservation TypeOfObservation>
117 struct Metavariables {
118  using component_list =
119  tmpl::list<element_component<Metavariables, TypeOfObservation>,
120  observer_component<Metavariables>,
121  observer_writer_component<Metavariables>>;
122 
123  /// [make_reduction_data_tags]
124  using observed_reduction_data_tags = observers::make_reduction_data_tags<
125  tmpl::list<reduction_data_from_doubles, reduction_data_from_vector,
126  reduction_data_from_ds_and_vs>>;
127  /// [make_reduction_data_tags]
128 
129  enum class Phase { Initialization, RegisterWithObservers, Testing, Exit };
130 };
131 } // namespace TestObservers_detail
Definition: ObserverHelpers.hpp:27
Definition: ConservativeSystem.hpp:50
Registers itself with the local observer parallel component so the observer knows to expect data from...
Definition: Actions.hpp:232
Definition: Tags.hpp:166
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:48
TypeOfObservation
Specifies the type of observation.
Definition: TypeOfObservation.hpp:18
The group parallel component that is responsible for reducing data to be observed.
Definition: ObserverComponent.hpp:27
A mock class for the CMake-generated Parallel::Algorithms::Array
Definition: ActionTesting.hpp:1589
Definition: Tags.hpp:155
Definition: InterpolationTargetWedgeSectionTorus.hpp:25
Namespace for DataBox related things.
Definition: DataBox.hpp:42
Terminate the algorithm to proceed to the next phase.
Definition: TerminatePhase.hpp:26
Defines class ElementIndex.
Functional for computing sqrt on an object.
Definition: Functional.hpp:273
Wraps the template metaprogramming library used (brigand)
Function for adding two std::vectors of double component-wise.
Definition: Functional.hpp:312
List of all the actions to be executed in the specified phase.
Definition: PhaseDependentActionList.hpp:16
A class for indexing a Charm array by Element.
Definition: ElementIndex.hpp:53
A type-erased identifier that combines the identifier&#39;s type and hash used to uniquely identify an ob...
Definition: ObservationId.hpp:42
The data to be reduced, and invokables to be called whenever two reduction messages are combined and ...
Definition: Reduction.hpp:64
Initializes the DataBox of the observer parallel component that writes to disk.
Definition: Initialize.hpp:98