RegisterSingleton.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <tuple>
8 #include <unordered_map>
9 #include <utility>
10 
12 #include "ErrorHandling/Error.hpp"
13 #include "IO/Observer/Actions/ObserverRegistration.hpp"
14 #include "IO/Observer/ObserverComponent.hpp"
15 #include "IO/Observer/TypeOfObservation.hpp"
16 #include "Parallel/GlobalCache.hpp"
17 #include "Parallel/Invoke.hpp"
18 #include "Utilities/TaggedTuple.hpp"
19 
20 namespace observers::Actions {
21 /*!
22  * \brief Registers a singleton with the ObserverWriter.
23  *
24  * The singleton that observes is expected to call WriteReductionData
25  * on node 0.
26  */
27 template <typename RegisterHelper>
29  template <typename DbTagList, typename... InboxTags, typename Metavariables,
30  typename ArrayIndex, typename ActionList,
31  typename ParallelComponent>
32  static std::tuple<db::DataBox<DbTagList>&&, bool> apply(
34  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
36  const ArrayIndex& array_index, const ActionList /*meta*/,
37  const ParallelComponent* const /*meta*/) noexcept {
38  const auto [type_of_observation, observation_key] =
39  RegisterHelper::template register_info<ParallelComponent>(box,
40  array_index);
41 
42  switch (type_of_observation) {
44  break;
46  ERROR(
47  "Registering volume observations is not supported for singletons. "
48  "The TypeOfObservation should be 'Reduction'.");
49  default:
50  ERROR(
51  "Registering an unknown TypeOfObservation. It should be "
52  "'Reduction' for singleton.");
53  };
54 
55  // The actual value of the processing element doesn't matter
56  // here; it is used only to give an ObserverWriter a count of how many
57  // times it will be called.
58  constexpr size_t fake_processing_element = 0;
59 
60  // We call only on node 0; the observation call will occur only
61  // on node 0.
62  Parallel::simple_action<Actions::RegisterReductionNodeWithWritingNode>(
65  observation_key, fake_processing_element);
66  return {std::move(box), true};
67  }
68 };
69 } // namespace observers::Actions
utility
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:16
GlobalCache.hpp
Parallel::get_parallel_component
auto get_parallel_component(GlobalCache< Metavariables > &cache) noexcept -> Parallel::proxy_from_parallel_component< GlobalCache_detail::get_component_if_mocked< typename Metavariables::component_list, ParallelComponentTag >> &
Access the Charm++ proxy associated with a ParallelComponent.
Definition: GlobalCache.hpp:223
Error.hpp
tuple
ERROR
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:36
observers::ObserverWriter
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:48
DataBox.hpp
cstddef
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
observers::Actions::RegisterSingletonWithObserverWriter
Registers a singleton with the ObserverWriter.
Definition: RegisterSingleton.hpp:28
observers::TypeOfObservation::Volume
@ Volume
The sender will only perform volume observations.
observers::TypeOfObservation::Reduction
@ Reduction
The sender will only perform reduction observations.
observers::Actions
Actions used by the observer parallel component
Definition: ObserverRegistration.hpp:31
unordered_map
db::DataBox
Definition: InterpolationTargetWedgeSectionTorus.hpp:24