Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <optional>
7 : #include <string>
8 : #include <unordered_set>
9 :
10 : #include "IO/Importers/Tags.hpp"
11 : #include "Parallel/AlgorithmExecution.hpp"
12 : #include "Parallel/Algorithms/AlgorithmNodegroup.hpp"
13 : #include "Parallel/GlobalCache.hpp"
14 : #include "Parallel/Local.hpp"
15 : #include "Parallel/ParallelComponentHelpers.hpp"
16 : #include "Parallel/Phase.hpp"
17 : #include "Parallel/PhaseDependentActionList.hpp"
18 :
19 : namespace importers {
20 :
21 : namespace detail {
22 : template <size_t Dim>
23 : struct InitializeElementDataReader;
24 : } // namespace detail
25 :
26 : /*!
27 : * \brief A nodegroup parallel component that reads in a volume data file and
28 : * distributes its data to elements of an array parallel component.
29 : *
30 : * Each element of the array parallel component must register itself before
31 : * data can be sent to it. To do so, invoke
32 : * `importers::Actions::RegisterWithElementDataReader` on each element. In a
33 : * subsequent phase you can then invoke
34 : * `importers::ThreadedActions::ReadVolumeData` on the `ElementDataReader`
35 : * component to read in the file and distribute its data to the registered
36 : * elements.
37 : *
38 : * \see Dev guide on \ref dev_guide_importing
39 : */
40 : template <typename Metavariables>
41 1 : struct ElementDataReader {
42 0 : static constexpr size_t Dim = Metavariables::volume_dim;
43 :
44 0 : using chare_type = Parallel::Algorithms::Nodegroup;
45 0 : static constexpr bool checkpoint_data = false;
46 0 : using metavariables = Metavariables;
47 0 : using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
48 : Parallel::Phase::Initialization,
49 : tmpl::list<detail::InitializeElementDataReader<Dim>>>>;
50 0 : using simple_tags_from_options = Parallel::get_simple_tags_from_options<
51 : Parallel::get_initialization_actions_list<phase_dependent_action_list>>;
52 :
53 0 : static void initialize(
54 : Parallel::CProxy_GlobalCache<Metavariables>& /*global_cache*/) {}
55 :
56 0 : static void execute_next_phase(
57 : const Parallel::Phase next_phase,
58 : Parallel::CProxy_GlobalCache<Metavariables>& global_cache) {
59 : auto& local_cache = *Parallel::local_branch(global_cache);
60 : Parallel::get_parallel_component<ElementDataReader>(local_cache)
61 : .start_phase(next_phase);
62 : }
63 : };
64 :
65 : namespace detail {
66 : template <size_t Dim>
67 : struct InitializeElementDataReader {
68 : using simple_tags =
69 : tmpl::list<Tags::RegisteredElements<Dim>, Tags::ElementDataAlreadyRead>;
70 : using compute_tags = tmpl::list<>;
71 :
72 : template <typename DbTagsList, typename... InboxTags, typename Metavariables,
73 : typename ArrayIndex, typename ActionList,
74 : typename ParallelComponent>
75 : static Parallel::iterable_action_return_t apply(
76 : db::DataBox<DbTagsList>& /*box*/,
77 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
78 : const Parallel::GlobalCache<Metavariables>& /*cache*/,
79 : const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
80 : const ParallelComponent* const /*meta*/) {
81 : return {Parallel::AlgorithmExecution::Pause, std::nullopt};
82 : }
83 : };
84 : } // namespace detail
85 :
86 : } // namespace importers
|