Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <utility> 7 : 8 : #include "DataStructures/DataBox/DataBox.hpp" 9 : #include "DataStructures/LinkedMessageId.hpp" 10 : #include "DataStructures/LinkedMessageQueue.hpp" 11 : #include "ParallelAlgorithms/Actions/FunctionsOfTimeAreReady.hpp" 12 : #include "Utilities/ErrorHandling/Error.hpp" 13 : #include "Utilities/Gsl.hpp" 14 : 15 : /// \cond 16 : namespace domain::Tags { 17 : struct FunctionsOfTime; 18 : } // namespace domain::Tags 19 : namespace Parallel { 20 : template <typename Metavariables> 21 : struct GlobalCache; 22 : } // namespace Parallel 23 : /// \endcond 24 : 25 : namespace Actions { 26 : /// \ingroup ActionsGroup 27 : /// \brief Add data to a LinkedMessageQueue 28 : /// 29 : /// Add the passed `id_and_previous` and `message` to the queue 30 : /// `QueueTag` in the `LinkedMessageQueue` stored in the DataBox tag 31 : /// `LinkedMessageQueueTag`. Then, for each ID for which the message 32 : /// queue has all required messages, call `Processor::apply`. The 33 : /// signature for an `apply` function for a message queue containing 34 : /// `Queue1` and `Queue2` with ID type `int` is: 35 : /// 36 : /// \snippet Test_UpdateMessageQueue.cpp Processor::apply 37 : template <typename QueueTag, typename LinkedMessageQueueTag, typename Processor> 38 1 : struct UpdateMessageQueue { 39 : template <typename ParallelComponent, typename DbTags, typename Metavariables, 40 : typename ArrayIndex> 41 0 : static void apply( 42 : db::DataBox<DbTags>& box, Parallel::GlobalCache<Metavariables>& cache, 43 : const ArrayIndex& array_index, 44 : const LinkedMessageId<typename LinkedMessageQueueTag::type::IdType>& 45 : id_and_previous, 46 : typename QueueTag::type message) { 47 : if (not domain::functions_of_time_are_ready_simple_action_callback< 48 : domain::Tags::FunctionsOfTime, UpdateMessageQueue>( 49 : cache, array_index, std::add_pointer_t<ParallelComponent>{nullptr}, 50 : id_and_previous.id, std::nullopt, id_and_previous, message)) { 51 : return; 52 : } 53 : auto& queue = 54 : db::get_mutable_reference<LinkedMessageQueueTag>(make_not_null(&box)); 55 : queue.template insert<QueueTag>(id_and_previous, std::move(message)); 56 : while (auto id = queue.next_ready_id()) { 57 : Processor::apply(make_not_null(&box), cache, array_index, *id, 58 : queue.extract()); 59 : } 60 : } 61 : }; 62 : } // namespace Actions