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 : using metavariables = Metavariables; 46 0 : using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions< 47 : Parallel::Phase::Initialization, 48 : tmpl::list<detail::InitializeElementDataReader<Dim>>>>; 49 0 : using simple_tags_from_options = Parallel::get_simple_tags_from_options< 50 : Parallel::get_initialization_actions_list<phase_dependent_action_list>>; 51 : 52 0 : static void initialize( 53 : Parallel::CProxy_GlobalCache<Metavariables>& /*global_cache*/) {} 54 : 55 0 : static void execute_next_phase( 56 : const Parallel::Phase next_phase, 57 : Parallel::CProxy_GlobalCache<Metavariables>& global_cache) { 58 : auto& local_cache = *Parallel::local_branch(global_cache); 59 : Parallel::get_parallel_component<ElementDataReader>(local_cache) 60 : .start_phase(next_phase); 61 : } 62 : }; 63 : 64 : namespace detail { 65 : template <size_t Dim> 66 : struct InitializeElementDataReader { 67 : using simple_tags = 68 : tmpl::list<Tags::RegisteredElements<Dim>, Tags::ElementDataAlreadyRead>; 69 : using compute_tags = tmpl::list<>; 70 : 71 : template <typename DbTagsList, typename... InboxTags, typename Metavariables, 72 : typename ArrayIndex, typename ActionList, 73 : typename ParallelComponent> 74 : static Parallel::iterable_action_return_t apply( 75 : db::DataBox<DbTagsList>& /*box*/, 76 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, 77 : const Parallel::GlobalCache<Metavariables>& /*cache*/, 78 : const ArrayIndex& /*array_index*/, const ActionList /*meta*/, 79 : const ParallelComponent* const /*meta*/) { 80 : return {Parallel::AlgorithmExecution::Pause, std::nullopt}; 81 : } 82 : }; 83 : } // namespace detail 84 : 85 : } // namespace importers