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 "IO/Observer/Actions/ObserverRegistration.hpp"
13 #include "IO/Observer/ObserverComponent.hpp"
14 #include "IO/Observer/TypeOfObservation.hpp"
15 #include "Parallel/GlobalCache.hpp"
16 #include "Parallel/Info.hpp"
17 #include "Parallel/Invoke.hpp"
18 #include "Parallel/ParallelComponentHelpers.hpp"
20 #include "Utilities/TaggedTuple.hpp"
21 
22 namespace observers::Actions {
23 /*!
24  * \brief Registers a singleton with the ObserverWriter.
25  *
26  * The singleton that observes is expected to call WriteReductionData
27  * on node 0.
28  */
29 template <typename RegisterHelper>
31  template <typename DbTagList, typename... InboxTags, typename Metavariables,
32  typename ArrayIndex, typename ActionList,
33  typename ParallelComponent>
34  static std::tuple<db::DataBox<DbTagList>&&, bool> apply(
35  db::DataBox<DbTagList>& box,
36  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
38  const ArrayIndex& array_index, const ActionList /*meta*/,
39  const ParallelComponent* const /*meta*/) noexcept {
40  const auto [type_of_observation, observation_key] =
41  RegisterHelper::template register_info<ParallelComponent>(box,
42  array_index);
43 
44  switch (type_of_observation) {
46  break;
48  ERROR(
49  "Registering volume observations is not supported for singletons. "
50  "The TypeOfObservation should be 'Reduction'.");
51  default:
52  ERROR(
53  "Registering an unknown TypeOfObservation. It should be "
54  "'Reduction' for singleton.");
55  };
56 
57  // We call only on node 0; the observation call will occur only
58  // on node 0.
59  auto& my_proxy = Parallel::get_parallel_component<ParallelComponent>(cache);
60  Parallel::simple_action<Actions::RegisterReductionNodeWithWritingNode>(
63  observation_key,
64  static_cast<size_t>(Parallel::my_node(*my_proxy.ckLocal())));
65  return {std::move(box), true};
66  }
67 };
68 } // 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:535
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(const DistribObject &distributed_object) noexcept
Index of my node.
Definition: Info.hpp:51
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:30
ActionTesting::cache
Parallel::GlobalCache< Metavariables > & cache(MockRuntimeSystem< Metavariables > &runner, const ArrayIndex &array_index) noexcept
Returns the GlobalCache of Component with index array_index.
Definition: MockRuntimeSystemFreeFunctions.hpp:362
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: GetLockPointer.hpp:13
unordered_map