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 LinkedMessageQueueTag, typename Processor, 38 : typename... QueueTags> 39 1 : struct UpdateMessageQueue { 40 : template <typename ParallelComponent, typename DbTags, typename Metavariables, 41 : typename ArrayIndex> 42 0 : static void apply( 43 : db::DataBox<DbTags>& box, Parallel::GlobalCache<Metavariables>& cache, 44 : const ArrayIndex& array_index, 45 : const LinkedMessageId<typename LinkedMessageQueueTag::type::IdType>& 46 : id_and_previous, 47 : typename QueueTags::type... messages) { 48 : if (not domain::functions_of_time_are_ready_simple_action_callback< 49 : domain::Tags::FunctionsOfTime, UpdateMessageQueue>( 50 : cache, array_index, std::add_pointer_t<ParallelComponent>{nullptr}, 51 : id_and_previous.id, std::nullopt, id_and_previous, 52 : std::move(messages)...)) { 53 : return; 54 : } 55 : auto& queue = 56 : db::get_mutable_reference<LinkedMessageQueueTag>(make_not_null(&box)); 57 : queue.template insert<QueueTags...>(id_and_previous, 58 : std::move(messages)...); 59 : while (auto id = queue.next_ready_id()) { 60 : Processor::apply(make_not_null(&box), cache, array_index, *id, 61 : queue.extract()); 62 : } 63 : } 64 : }; 65 : } // namespace Actions