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 <cstdint> 8 : #include <map> 9 : #include <optional> 10 : #include <utility> 11 : #include <vector> 12 : 13 : #include "DataStructures/DataBox/DataBox.hpp" 14 : #include "Evolution/DiscontinuousGalerkin/EqualRateLts/Tags/ChangeFixedLtsRatioTags.hpp" 15 : #include "Parallel/AlgorithmExecution.hpp" 16 : #include "Utilities/Gsl.hpp" 17 : #include "Utilities/TMPL.hpp" 18 : 19 : /// \cond 20 : class TimeStepId; 21 : namespace Parallel { 22 : template <typename Metavariables> 23 : class GlobalCache; 24 : } // namespace Parallel 25 : namespace Tags { 26 : struct FixedLtsRatio; 27 : struct StepNumberWithinSlab; 28 : struct TimeStepId; 29 : } // namespace Tags 30 : namespace tuples { 31 : template <class... Tags> 32 : class TaggedTuple; 33 : } // namespace tuples 34 : /// \endcond 35 : 36 : namespace evolution::dg::Actions { 37 : /// Adjust Tags::FixedLtsRatio based on previous executions of 38 : /// Events::ChangeFixedLtsRatio. 39 1 : struct ChangeFixedLtsRatio { 40 0 : using simple_tags = 41 : tmpl::list<Tags::ChangeFixedLtsRatio::NumberOfExpectedMessages, 42 : Tags::ChangeFixedLtsRatio::NewStepSize>; 43 : 44 : template <typename DbTags, typename... InboxTags, typename Metavariables, 45 : typename ArrayIndex, typename ActionList, 46 : typename ParallelComponent> 47 0 : static Parallel::iterable_action_return_t apply( 48 : db::DataBox<DbTags>& box, tuples::TaggedTuple<InboxTags...>& /*inboxes*/, 49 : const Parallel::GlobalCache<Metavariables>& /*cache*/, 50 : const ArrayIndex& /*array_index*/, const ActionList /*meta*/, 51 : const ParallelComponent* const /*meta*/) { 52 : if (db::mutate_apply<Impl>(make_not_null(&box))) { 53 : return {Parallel::AlgorithmExecution::Continue, std::nullopt}; 54 : } else { 55 : return {Parallel::AlgorithmExecution::Retry, std::nullopt}; 56 : } 57 : } 58 : 59 : private: 60 0 : struct Impl { 61 0 : using return_tags = 62 : tmpl::list<::Tags::FixedLtsRatio, 63 : Tags::ChangeFixedLtsRatio::NumberOfExpectedMessages, 64 : Tags::ChangeFixedLtsRatio::NewStepSize>; 65 0 : using argument_tags = 66 : tmpl::list<::Tags::TimeStepId, ::Tags::StepNumberWithinSlab>; 67 : 68 0 : using StepId = std::pair<int64_t, uint64_t>; 69 : 70 0 : static bool apply( 71 : gsl::not_null<std::optional<size_t>*> fixed_lts_ratio, 72 : gsl::not_null<std::map<StepId, size_t>*> expected_messages_map, 73 : gsl::not_null<std::map<StepId, std::vector<double>>*> 74 : new_step_size_messages_map, 75 : const TimeStepId& time_step_id, uint64_t step_number_within_slab); 76 : }; 77 : }; 78 : } // namespace evolution::dg::Actions