Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <cstddef> 7 : #include <optional> 8 : #include <tuple> 9 : #include <unordered_map> 10 : #include <utility> 11 : 12 : #include "DataStructures/DataBox/DataBox.hpp" 13 : #include "IO/Observer/Actions/ObserverRegistration.hpp" 14 : #include "IO/Observer/ObserverComponent.hpp" 15 : #include "IO/Observer/TypeOfObservation.hpp" 16 : #include "Parallel/AlgorithmExecution.hpp" 17 : #include "Parallel/GlobalCache.hpp" 18 : #include "Parallel/Info.hpp" 19 : #include "Parallel/Invoke.hpp" 20 : #include "Parallel/Local.hpp" 21 : #include "Parallel/ParallelComponentHelpers.hpp" 22 : #include "Utilities/ErrorHandling/Error.hpp" 23 : #include "Utilities/TaggedTuple.hpp" 24 : 25 : namespace observers::Actions { 26 : /*! 27 : * \brief Registers a singleton with the ObserverWriter. 28 : * 29 : * The singleton that observes is expected to call WriteReductionData 30 : * on node 0. 31 : */ 32 : template <typename RegisterHelper> 33 1 : struct RegisterSingletonWithObserverWriter { 34 : template <typename DbTagList, typename... InboxTags, typename Metavariables, 35 : typename ArrayIndex, typename ActionList, 36 : typename ParallelComponent> 37 0 : static Parallel::iterable_action_return_t apply( 38 : db::DataBox<DbTagList>& box, 39 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, 40 : Parallel::GlobalCache<Metavariables>& cache, 41 : const ArrayIndex& array_index, const ActionList /*meta*/, 42 : const ParallelComponent* const /*meta*/) { 43 : const auto [type_of_observation, observation_key] = 44 : RegisterHelper::template register_info<ParallelComponent>(box, 45 : array_index); 46 : 47 : switch (type_of_observation) { 48 : case TypeOfObservation::Reduction: 49 : break; 50 : case TypeOfObservation::Volume: 51 : ERROR( 52 : "Registering volume observations is not supported for singletons. " 53 : "The TypeOfObservation should be 'Reduction'."); 54 : default: 55 : ERROR( 56 : "Registering an unknown TypeOfObservation. It should be " 57 : "'Reduction' for singleton."); 58 : }; 59 : 60 : // We call only on node 0; the observation call will occur only 61 : // on node 0. 62 : auto& my_proxy = Parallel::get_parallel_component<ParallelComponent>(cache); 63 : Parallel::simple_action<Actions::RegisterReductionNodeWithWritingNode>( 64 : Parallel::get_parallel_component< 65 : observers::ObserverWriter<Metavariables>>(cache)[0], 66 : observation_key, Parallel::my_node<size_t>(*Parallel::local(my_proxy))); 67 : return {Parallel::AlgorithmExecution::Pause, std::nullopt}; 68 : } 69 : }; 70 : } // namespace observers::Actions