Actions.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <unordered_map>
8 
11 #include "DataStructures/Index.hpp"
12 #include "IO/Observer/ArrayComponentId.hpp"
13 #include "IO/Observer/ObserverComponent.hpp"
14 #include "IO/Observer/Tags.hpp"
15 #include "IO/Observer/TypeOfObservation.hpp"
17 #include "Parallel/Invoke.hpp"
19 
20 namespace observers {
21 /*!
22  * \ingroup ObserversGroup
23  * \brief %Actions used by the observer parallel component
24  */
25 namespace Actions {
26 /*!
27  * \brief Action that is called on the Observer parallel component to register
28  * the parallel component that will send the data to the observer
29  */
31  template <
32  typename DbTagList, typename... InboxTags, typename Metavariables,
33  typename ArrayIndex, typename ActionList, typename ParallelComponent,
34  typename TemporalId,
35  Requires<tmpl::list_contains_v<
37  tmpl::list_contains_v<
39  nullptr>
40  static void apply(db::DataBox<DbTagList>& box,
41  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
43  const ArrayIndex& /*array_index*/,
44  const ActionList /*meta*/,
45  const ParallelComponent* const /*meta*/,
46  const TemporalId& /*temporal_id*/,
47  const observers::ArrayComponentId& component_id,
48  const TypeOfObservation& type_of_observation) noexcept {
49  const auto register_reduction = [&box, &component_id]() noexcept {
50  db::mutate<observers::Tags::ReductionArrayComponentIds>(
51  make_not_null(&box), [&component_id](
52  const auto array_component_ids) noexcept {
53  ASSERT(array_component_ids->count(component_id) == 0,
54  "Trying to insert a component_id more than once for "
55  "reduction. This means an element is registering itself "
56  "with the observers more than once.");
57  array_component_ids->insert(component_id);
58  });
59  };
60  const auto register_volume = [&box, &component_id]() noexcept {
61  db::mutate<observers::Tags::VolumeArrayComponentIds>(
62  make_not_null(&box), [&component_id](
63  const auto array_component_ids) noexcept {
64  ASSERT(array_component_ids->count(component_id) == 0,
65  "Trying to insert a component_id more than once for "
66  "volume observation. This means an element is registering "
67  "itself with the observers more than once.");
68  array_component_ids->insert(component_id);
69  });
70  };
71 
72  switch (type_of_observation) {
74  register_reduction();
75  register_volume();
76  return;
78  register_reduction();
79  return;
81  register_volume();
82  return;
83  default:
84  ERROR(
85  "Registering an unknown TypeOfObservation. Should be one of "
86  "'Reduction', 'Volume', or 'ReductionAndVolume'");
87  };
88  }
89 };
90 
91 /*!
92  * \brief Registers itself with the local observer parallel component so the
93  * observer knows to expect data from this component, and also whether to expect
94  * Reduction, Volume, or both Reduction and Volume data observation calls.
95  */
96 template <observers::TypeOfObservation TypeOfObservation>
98  template <typename DbTagList, typename... InboxTags, typename Metavariables,
99  typename ArrayIndex, typename ActionList,
100  typename ParallelComponent, typename TemporalId>
101  static void apply(const db::DataBox<DbTagList>& /*box*/,
102  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
104  const ArrayIndex& array_index, const ActionList /*meta*/,
105  const ParallelComponent* const /*meta*/,
106  const TemporalId& temporal_id) noexcept {
107  auto& observer =
108  *Parallel::get_parallel_component<observers::Observer<Metavariables>>(
109  cache)
110  .ckLocalBranch();
111  // TODO(): We should really loop through all the events, check if there are
112  // any reduction observers, and any volume observers, if so, then we
113  // register us as having one of:
114  // - TypeOfObservation::Reduction
115  // - TypeOfObservation::Volume
116  // - TypeOfObservation::ReductionAndVolume
117  //
118  // At that point we won't need the template parameter on the class anymore
119  // and everything can be read from an input file.
120  Parallel::simple_action<RegisterSenderWithSelf>(
121  observer, temporal_id,
126  }
127 };
128 } // namespace Actions
129 } // namespace observers
Definition: Actions.hpp:20
All the ids of all the components registered to an observer for doing reduction observations.
Definition: Tags.hpp:34
Defines class tuples::TaggedTuple.
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:35
The sender will perform both reduction and volume observations.
Registers itself with the local observer parallel component so the observer knows to expect data from...
Definition: Actions.hpp:97
The sender will only perform reduction observations.
Action that is called on the Observer parallel component to register the parallel component that will...
Definition: Actions.hpp:30
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:49
TypeOfObservation
Specifies the type of observation.
Definition: TypeOfObservation.hpp:18
An ID type that identifies both the parallel component and the index in the parallel component...
Definition: ArrayComponentId.hpp:27
Defines class template Index.
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
Defines classes and functions used for manipulating DataBox&#39;s.
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
All the ids of all the components registered to an observer for doing volume observations.
Definition: Tags.hpp:41
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion, but it may be necessary to perform the conversion explicitly when type deduction is desired.
Definition: Gsl.hpp:863
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t ...
Definition: Requires.hpp:67
Definition: SolvePoissonProblem.hpp:38
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines class template ConstGlobalCache.
The sender will only perform volume observations.
Definition: ComputeTimeDerivative.hpp:28
The array index used for indexing Chare Arrays, mostly an implementation detail.
Definition: ArrayIndex.hpp:20