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/Info.hpp"
15 #include "Parallel/Invoke.hpp"
16 #include "Utilities/Gsl.hpp"
17 #include "Utilities/Literals.hpp"
18 #include "Utilities/MakeString.hpp"
19 #include "Utilities/Requires.hpp"
20 #include "Utilities/TMPL.hpp"
21 #include "Utilities/TaggedTuple.hpp"
22 
23 /// \cond
24 namespace importers {
25 template <typename Metavariables>
26 struct ElementDataReader;
27 namespace Actions {
28 struct RegisterElementWithSelf;
29 } // namespace Actions
30 } // namespace importers
31 /// \endcond
32 
33 namespace importers::Actions {
34 
35 /*!
36  * \brief Register an element with the volume data reader component.
37  *
38  * Invoke this action on each element of an array parallel component to register
39  * them for receiving imported volume data.
40  *
41  * \see Dev guide on \ref dev_guide_importing
42  */
44  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
45  size_t Dim, typename ActionList, typename ParallelComponent>
46  static std::tuple<db::DataBox<DbTagsList>&&> apply(
48  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
50  const ElementId<Dim>& array_index, const ActionList /*meta*/,
51  const ParallelComponent* const /*meta*/) noexcept {
52  const std::string element_name = MakeString{}
53  << ElementId<Dim>(array_index);
54  auto& local_reader_component =
57  .ckLocalBranch();
58  Parallel::simple_action<importers::Actions::RegisterElementWithSelf>(
59  local_reader_component,
63  element_name);
64  return {std::move(box)};
65  }
66 };
67 
68 /*!
69  * \brief Invoked on the `importers::ElementDataReader` component to store the
70  * registered data.
71  *
72  * The `importers::Actions::RegisterWithElementDataReader` action, which is
73  * performed on each element of an array parallel component, invokes this action
74  * on the `importers::ElementDataReader` component.
75  *
76  * \see Dev guide on \ref dev_guide_importing
77  */
79  template <
80  typename ParallelComponent, typename DbTagsList, typename Metavariables,
81  typename ArrayIndex, typename DataBox = db::DataBox<DbTagsList>,
83  nullptr>
84  static void apply(db::DataBox<DbTagsList>& box,
85  const Parallel::GlobalCache<Metavariables>& /*cache*/,
86  const ArrayIndex& /*array_index*/,
87  const observers::ArrayComponentId& array_component_id,
88  const std::string& grid_name) noexcept {
89  db::mutate<Tags::RegisteredElements>(
90  make_not_null(&box),
91  [&array_component_id, &grid_name](
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:16
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:223
importers
Items related to loading data from files.
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:32
tuple
Info.hpp
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:37
cstddef
db::item_type
typename DataBox_detail::item_type_impl< TagList, Tag >::type item_type
Get the type that can be written to the Tag. If it is a base tag then a TagList must be passed as a s...
Definition: DataBoxTag.hpp:247
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
Gsl.hpp
Requires.hpp
importers::Actions::RegisterElementWithSelf
Invoked on the importers::ElementDataReader component to store the registered data.
Definition: RegisterWithElementDataReader.hpp:78
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:27
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
db::DataBox
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
importers::Actions::RegisterWithElementDataReader
Register an element with the volume data reader component.
Definition: RegisterWithElementDataReader.hpp:43
TMPL.hpp
MakeString
Make a string by streaming into object.
Definition: MakeString.hpp:16
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183