Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include "DataStructures/DataBox/DataBox.hpp" 7 : #include "DataStructures/DataBox/TagName.hpp" 8 : #include "IO/Observer/Actions/ObserverRegistration.hpp" 9 : #include "IO/Observer/Actions/RegisterWithObservers.hpp" 10 : #include "IO/Observer/ObservationId.hpp" 11 : #include "IO/Observer/TypeOfObservation.hpp" 12 : #include "Parallel/Algorithms/AlgorithmGroup.hpp" 13 : #include "Parallel/ArrayComponentId.hpp" 14 : #include "Parallel/GlobalCache.hpp" 15 : #include "Parallel/Local.hpp" 16 : #include "Parallel/ParallelComponentHelpers.hpp" 17 : #include "Parallel/Phase.hpp" 18 : #include "Parallel/PhaseDependentActionList.hpp" 19 : #include "ParallelAlgorithms/Actions/TerminatePhase.hpp" 20 : #include "ParallelAlgorithms/Interpolation/Actions/DumpInterpolatorVolumeData.hpp" 21 : #include "ParallelAlgorithms/Interpolation/Actions/InitializeInterpolator.hpp" 22 : #include "Utilities/GetOutput.hpp" 23 : #include "Utilities/TMPL.hpp" 24 : #include "Utilities/TypeTraits/IsA.hpp" 25 : 26 : namespace intrp { 27 : namespace Actions { 28 : template <typename TemporalIdTag> 29 0 : struct RegisterWithObserverWriter { 30 : template <typename DbTagList, typename... InboxTags, typename Metavariables, 31 : typename ArrayIndex, typename ActionList, 32 : typename ParallelComponent> 33 0 : static Parallel::iterable_action_return_t apply( 34 : db::DataBox<DbTagList>& /*box*/, 35 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, 36 : Parallel::GlobalCache<Metavariables>& cache, 37 : const ArrayIndex& array_index, const ActionList /*meta*/, 38 : const ParallelComponent* const /*meta*/) { 39 : // This has to be the local observer writer or else registration will be 40 : // messed up 41 : auto& observer_writer = *Parallel::local_branch( 42 : Parallel::get_parallel_component< 43 : observers::ObserverWriter<Metavariables>>(cache)); 44 : 45 : const observers::ObservationKey observation_key{ 46 : "/InterpolatorVolumeData_"s + db::tag_name<TemporalIdTag>()}; 47 : const Parallel::ArrayComponentId array_component_id = 48 : Parallel::make_array_component_id<ParallelComponent>(array_index); 49 : 50 : Parallel::simple_action< 51 : observers::Actions::RegisterVolumeContributorWithObserverWriter>( 52 : observer_writer, observation_key, array_component_id); 53 : 54 : return {Parallel::AlgorithmExecution::Continue, std::nullopt}; 55 : } 56 : }; 57 : } // namespace Actions 58 : 59 : namespace detail { 60 : template <typename InterpolationTarget> 61 : struct get_interpolation_target_tag { 62 : using type = typename InterpolationTarget::interpolation_target_tag; 63 : }; 64 : template <typename InterpolationTargetTag> 65 : struct get_temporal_id { 66 : using type = typename InterpolationTargetTag::temporal_id; 67 : }; 68 : } // namespace detail 69 : 70 : /// \brief ParallelComponent responsible for collecting data from 71 : /// `Element`s and interpolating it onto `InterpolationTarget`s. 72 : /// 73 : /// For requirements on Metavariables, see InterpolationTarget 74 : template <class Metavariables> 75 1 : struct Interpolator { 76 0 : using chare_type = Parallel::Algorithms::Group; 77 0 : static constexpr bool checkpoint_data = true; 78 0 : using metavariables = Metavariables; 79 0 : using all_interpolation_target_tags = tmpl::transform< 80 : tmpl::filter<typename Metavariables::component_list, 81 : tt::is_a<intrp::InterpolationTarget, tmpl::_1>>, 82 : detail::get_interpolation_target_tag<tmpl::_1>>; 83 0 : using all_temporal_ids = tmpl::remove_duplicates<tmpl::transform< 84 : all_interpolation_target_tags, detail::get_temporal_id<tmpl::_1>>>; 85 0 : using phase_dependent_action_list = tmpl::list< 86 : Parallel::PhaseActions< 87 : Parallel::Phase::Initialization, 88 : tmpl::list<Actions::InitializeInterpolator< 89 : Metavariables::volume_dim, 90 : tmpl::transform< 91 : all_temporal_ids, 92 : tmpl::bind<Tags::VolumeVarsInfo, 93 : tmpl::pin<Metavariables>, tmpl::_1>>, 94 : Tags::InterpolatedVarsHolders<Metavariables>>, 95 : Parallel::Actions::TerminatePhase>>, 96 : Parallel::PhaseActions< 97 : Parallel::Phase::Register, 98 : tmpl::flatten<tmpl::list< 99 : tmpl::transform< 100 : all_temporal_ids, 101 : tmpl::bind<Actions::RegisterWithObserverWriter, tmpl::_1>>, 102 : Parallel::Actions::TerminatePhase>>>, 103 : Parallel::PhaseActions< 104 : Parallel::Phase::Restart, 105 : tmpl::flatten<tmpl::list< 106 : tmpl::transform< 107 : all_temporal_ids, 108 : tmpl::bind<Actions::RegisterWithObserverWriter, tmpl::_1>>, 109 : Parallel::Actions::TerminatePhase>>>, 110 : Parallel::PhaseActions< 111 : Parallel::Phase::PostFailureCleanup, 112 : tmpl::list<Actions::DumpInterpolatorVolumeData<all_temporal_ids>, 113 : Parallel::Actions::TerminatePhase>>>; 114 0 : using simple_tags_from_options = Parallel::get_simple_tags_from_options< 115 : Parallel::get_initialization_actions_list<phase_dependent_action_list>>; 116 0 : static void execute_next_phase( 117 : Parallel::Phase next_phase, 118 : const Parallel::CProxy_GlobalCache<Metavariables>& global_cache) { 119 : auto& local_cache = *Parallel::local_branch(global_cache); 120 : Parallel::get_parallel_component<Interpolator>(local_cache) 121 : .start_phase(next_phase); 122 : }; 123 : }; 124 : } // namespace intrp