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/Info.hpp"
18 #include "Parallel/Invoke.hpp"
19 #include "Utilities/TaggedTuple.hpp"
20 
21 namespace observers::Actions {
22 /*!
23  * \brief Registers a singleton with the ObserverWriter.
24  *
25  * The singleton that observes is expected to call WriteReductionData
26  * on node 0.
27  */
28 template <typename RegisterHelper>
30  template <typename DbTagList, typename... InboxTags, typename Metavariables,
31  typename ArrayIndex, typename ActionList,
32  typename ParallelComponent>
33  static std::tuple<db::DataBox<DbTagList>&&, bool> apply(
34  db::DataBox<DbTagList>& box,
35  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
37  const ArrayIndex& array_index, const ActionList /*meta*/,
38  const ParallelComponent* const /*meta*/) noexcept {
39  const auto [type_of_observation, observation_key] =
40  RegisterHelper::template register_info<ParallelComponent>(box,
41  array_index);
42 
43  switch (type_of_observation) {
45  break;
47  ERROR(
48  "Registering volume observations is not supported for singletons. "
49  "The TypeOfObservation should be 'Reduction'.");
50  default:
51  ERROR(
52  "Registering an unknown TypeOfObservation. It should be "
53  "'Reduction' for singleton.");
54  };
55 
56  // We call only on node 0; the observation call will occur only
57  // on node 0.
58  Parallel::simple_action<Actions::RegisterReductionNodeWithWritingNode>(
61  observation_key, static_cast<size_t>(Parallel::my_node()));
62  return {std::move(box), true};
63  }
64 };
65 } // namespace observers::Actions
utility
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
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:454
Error.hpp
tuple
Info.hpp
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:51
Parallel::my_node
int my_node()
Index of my node.
Definition: Info.hpp:34
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:29
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:30
unordered_map