RegisterWithObservers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <type_traits>
7 #include <utility>
8 #include <vector>
9 
11 #include "IO/Observer/Actions/ObserverRegistration.hpp"
12 #include "IO/Observer/ObservationId.hpp"
13 #include "IO/Observer/ObserverComponent.hpp"
14 #include "IO/Observer/TypeOfObservation.hpp"
15 #include "Parallel/ArrayIndex.hpp"
16 #include "Parallel/GlobalCache.hpp"
17 #include "Parallel/Invoke.hpp"
18 
19 /// \cond
20 template <class... Tags>
21 class TaggedTuple;
22 /// \endcond
23 
24 namespace observers::Actions {
25 /*!
26  * \brief Register an observation ID with the observers.
27  *
28  * \warning If registering events, you should use RegisterEventsWithObservers
29  * instead. If your event is not compatible with RegisterEventsWithObservers,
30  * please make it so.
31  *
32  * The `RegisterHelper` passed as a template parameter must have a static
33  * `register_info` function that takes as its first template parameter the
34  * `ParallelComponent` and as function arguments a `db::DataBox` and the array
35  * component index. The function must return a
36  * `std::pair<observers::TypeOfObservation, observers::ObservationId>`
37  */
38 template <typename RegisterHelper>
40  template <typename DbTagList, typename... InboxTags, typename Metavariables,
41  typename ArrayIndex, typename ActionList,
42  typename ParallelComponent>
43  static std::tuple<db::DataBox<DbTagList>&&> apply(
44  db::DataBox<DbTagList>& box,
45  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
47  const ArrayIndex& array_index, const ActionList /*meta*/,
48  const ParallelComponent* const /*meta*/) noexcept {
49  auto& observer =
50  *Parallel::get_parallel_component<observers::Observer<Metavariables>>(
51  cache)
52  .ckLocalBranch();
53  const auto [type_of_observation, observation_id] =
54  RegisterHelper::template register_info<ParallelComponent>(box,
55  array_index);
56 
59  observer, observation_id,
63  type_of_observation);
64  return {std::move(box)};
65  }
66 };
67 } // namespace observers::Actions
utility
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
GlobalCache.hpp
vector
std::tuple
std::add_pointer_t
DataBox.hpp
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
observers::ArrayComponentId
An ID type that identifies both the parallel component and the index in the parallel component.
Definition: ArrayComponentId.hpp:27
Parallel::simple_action
void simple_action(Proxy &&proxy) noexcept
Invoke a simple action on proxy
Definition: Invoke.hpp:82
Parallel::ArrayIndex
The array index used for indexing Chare Arrays, mostly an implementation detail.
Definition: ArrayIndex.hpp:27
observers::Actions
Actions used by the observer parallel component
Definition: ObserverRegistration.hpp:30
type_traits
observers::Actions::RegisterContributorWithObserver
Register the ArrayComponentId that will send the data to the observer for the given ObservationIdRegi...
Definition: ObserverRegistration.hpp:203
observers::Actions::RegisterWithObservers
Register an observation ID with the observers.
Definition: RegisterWithObservers.hpp:39