ElementDataReader.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <string>
7 #include <unordered_set>
8 
9 #include "AlgorithmNodegroup.hpp"
10 #include "IO/Importers/Tags.hpp"
11 #include "Parallel/GlobalCache.hpp"
12 #include "Parallel/ParallelComponentHelpers.hpp"
13 #include "Parallel/PhaseDependentActionList.hpp"
14 #include "ParallelAlgorithms/Initialization/MergeIntoDataBox.hpp"
15 
16 namespace importers {
17 
18 namespace detail {
19 struct InitializeElementDataReader;
20 } // namespace detail
21 
22 /*!
23  * \brief A nodegroup parallel component that reads in a volume data file and
24  * distributes its data to elements of an array parallel component.
25  *
26  * Each element of the array parallel component must register itself before
27  * data can be sent to it. To do so, invoke
28  * `importers::Actions::RegisterWithElementDataReader` on each element. In a
29  * subsequent phase you can then invoke
30  * `importers::ThreadedActions::ReadVolumeData` on the `ElementDataReader`
31  * component to read in the file and distribute its data to the registered
32  * elements.
33  *
34  * \see Dev guide on \ref dev_guide_importing
35  */
36 template <typename Metavariables>
38  using chare_type = Parallel::Algorithms::Nodegroup;
39  using metavariables = Metavariables;
40  using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
41  typename Metavariables::Phase, Metavariables::Phase::Initialization,
42  tmpl::list<detail::InitializeElementDataReader>>>;
43  using initialization_tags = Parallel::get_initialization_tags<
45 
46  static void initialize(Parallel::CProxy_GlobalCache<
47  Metavariables>& /*global_cache*/) noexcept {}
48 
49  static void execute_next_phase(
50  const typename Metavariables::Phase next_phase,
51  Parallel::CProxy_GlobalCache<Metavariables>& global_cache) noexcept {
52  auto& local_cache = *(global_cache.ckLocalBranch());
53  Parallel::get_parallel_component<ElementDataReader>(local_cache)
54  .start_phase(next_phase);
55  }
56 };
57 
58 namespace detail {
59 struct InitializeElementDataReader {
60  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
61  typename ArrayIndex, typename ActionList,
62  typename ParallelComponent>
63  static auto apply(db::DataBox<DbTagsList>& box,
64  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
65  const Parallel::GlobalCache<Metavariables>& /*cache*/,
66  const ArrayIndex& /*array_index*/,
67  const ActionList /*meta*/,
68  const ParallelComponent* const /*meta*/) noexcept {
69  using simple_tags = db::AddSimpleTags<Tags::RegisteredElements,
71  using compute_tags = db::AddComputeTags<>;
72 
73  return std::make_tuple(
74  ::Initialization::merge_into_databox<InitializeElementDataReader,
75  simple_tags, compute_tags>(
78  true);
79  }
80 };
81 } // namespace detail
82 
83 } // namespace importers
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:16
unordered_set
GlobalCache.hpp
importers::Tags::RegisteredElements
The elements that will receive data from the importer.
Definition: Tags.hpp:173
importers
Items related to loading data from files.
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:32
db::AddComputeTags
tmpl::flatten< tmpl::list< Tags... > > AddComputeTags
List of Compute Item Tags to add to the DataBox.
Definition: DataBox.hpp:1153
Parallel::get_initialization_tags
tmpl::remove_duplicates< tmpl::flatten< tmpl::list< AllocationTagsList, tmpl::transform< InitializationActionsList, detail::get_initialization_tags_from_action< tmpl::_1 > >> >> get_initialization_tags
Given a list of initialization actions, and possibly a list of tags needed for allocation of an array...
Definition: ParallelComponentHelpers.hpp:140
Parallel::get_initialization_actions_list
tmpl::flatten< tmpl::transform< PhaseDepActionList, detail::get_initialization_actions_list< tmpl::_1 > >> get_initialization_actions_list
Given the phase dependent action list, return the list of actions in the Initialization phase (or an ...
Definition: ParallelComponentHelpers.hpp:104
Parallel::PhaseActions
List of all the actions to be executed in the specified phase.
Definition: PhaseDependentActionList.hpp:16
db::apply
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args) noexcept
Apply the invokable f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1424
importers::ElementDataReader
A nodegroup parallel component that reads in a volume data file and distributes its data to elements ...
Definition: ElementDataReader.hpp:37
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
db::AddSimpleTags
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:1132
Initialization::merge_into_databox
auto merge_into_databox(db::DataBox< DbTagsList > &&box, Args &&... args) noexcept
Add tags that are not yet in the DataBox.
Definition: MergeIntoDataBox.hpp:133
db::DataBox
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
string
importers::Tags::ElementDataAlreadyRead
Indicates which volume data files have already been read.
Definition: Tags.hpp:178