RegisterWithElementDataReader.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 
11 #include "IO/Importers/Tags.hpp"
12 #include "IO/Observer/ArrayComponentId.hpp"
13 #include "Parallel/GlobalCache.hpp"
14 #include "Parallel/Invoke.hpp"
15 #include "Utilities/Gsl.hpp"
16 #include "Utilities/Literals.hpp"
17 #include "Utilities/MakeString.hpp"
18 #include "Utilities/Requires.hpp"
19 #include "Utilities/TMPL.hpp"
20 #include "Utilities/TaggedTuple.hpp"
21 
22 /// \cond
23 namespace importers {
24 template <typename Metavariables>
25 struct ElementDataReader;
26 namespace Actions {
27 struct RegisterElementWithSelf;
28 } // namespace Actions
29 } // namespace importers
30 /// \endcond
31 
32 namespace importers::Actions {
33 
34 /*!
35  * \brief Register an element with the volume data reader component.
36  *
37  * Invoke this action on each element of an array parallel component to register
38  * them for receiving imported volume data.
39  *
40  * \see Dev guide on \ref dev_guide_importing
41  */
43  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
44  size_t Dim, typename ActionList, typename ParallelComponent>
45  static std::tuple<db::DataBox<DbTagsList>&&> apply(
46  db::DataBox<DbTagsList>& box,
47  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
49  const ElementId<Dim>& array_index, const ActionList /*meta*/,
50  const ParallelComponent* const /*meta*/) noexcept {
51  const std::string element_name = MakeString{}
52  << ElementId<Dim>(array_index);
53  auto& local_reader_component =
56  .ckLocalBranch();
57  Parallel::simple_action<importers::Actions::RegisterElementWithSelf>(
58  local_reader_component,
62  element_name);
63  return {std::move(box)};
64  }
65 };
66 
67 /*!
68  * \brief Invoked on the `importers::ElementDataReader` component to store the
69  * registered data.
70  *
71  * The `importers::Actions::RegisterWithElementDataReader` action, which is
72  * performed on each element of an array parallel component, invokes this action
73  * on the `importers::ElementDataReader` component.
74  *
75  * \see Dev guide on \ref dev_guide_importing
76  */
78  template <
79  typename ParallelComponent, typename DbTagsList, typename Metavariables,
80  typename ArrayIndex, typename DataBox = db::DataBox<DbTagsList>,
82  nullptr>
83  static void apply(db::DataBox<DbTagsList>& box,
84  const Parallel::GlobalCache<Metavariables>& /*cache*/,
85  const ArrayIndex& /*array_index*/,
86  const observers::ArrayComponentId& array_component_id,
87  const std::string& grid_name) noexcept {
88  db::mutate<Tags::RegisteredElements>(
89  make_not_null(&box),
90  [&array_component_id, &grid_name ](
91  const gsl::not_null<
93  registered_elements) noexcept {
94  (*registered_elements)[array_component_id] = grid_name;
95  });
96  }
97 };
98 
99 } // namespace importers::Actions
std::string
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
Literals.hpp
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
importers
Items related to loading data from files.
Definition: ReadVolumeData.hpp:39
tuple
ElementId< Dim >
ElementId.hpp
std::add_pointer_t
DataBox.hpp
importers::ElementDataReader
A nodegroup parallel component that reads in a volume data file and distributes its data to elements ...
Definition: ElementDataReader.hpp:38
cstddef
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
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:382
Gsl.hpp
Requires.hpp
importers::Actions::RegisterElementWithSelf
Invoked on the importers::ElementDataReader component to store the registered data.
Definition: RegisterWithElementDataReader.hpp:77
observers::ArrayComponentId
An ID type that identifies both the parallel component and the index in the parallel component.
Definition: ArrayComponentId.hpp:27
make_not_null
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,...
Definition: Gsl.hpp:880
Parallel::ArrayIndex
The array index used for indexing Chare Arrays, mostly an implementation detail.
Definition: ArrayIndex.hpp:28
Requires
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
std::unordered_map
importers::Actions::RegisterWithElementDataReader
Register an element with the volume data reader component.
Definition: RegisterWithElementDataReader.hpp:42
TMPL.hpp
MakeString
Make a string by streaming into object.
Definition: MakeString.hpp:18
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13