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 : 9 : #include "DataStructures/DataBox/DataBox.hpp" 10 : #include "DataStructures/DataBox/PrefixHelpers.hpp" 11 : #include "DataStructures/DataBox/Prefixes.hpp" 12 : #include "DataStructures/Variables.hpp" 13 : #include "Evolution/Imex/Protocols/ImexSystem.hpp" 14 : #include "Evolution/Imex/Tags/ImplicitHistory.hpp" 15 : #include "Parallel/AlgorithmExecution.hpp" 16 : #include "Utilities/Gsl.hpp" 17 : #include "Utilities/ProtocolHelpers.hpp" 18 : #include "Utilities/TMPL.hpp" 19 : 20 : /// \cond 21 : class TimeStepId; 22 : namespace Parallel { 23 : template <typename Metavariables> 24 : class GlobalCache; 25 : } // namespace Parallel 26 : namespace Tags { 27 : struct TimeStepId; 28 : } // namespace Tags 29 : namespace tuples { 30 : template <class... Tags> 31 : class TaggedTuple; 32 : } // namespace tuples 33 : /// \endcond 34 : 35 : namespace imex::Actions { 36 : /// \ingroup ActionsGroup 37 : /// \brief Records the implicit sources in the implicit time stepper history. 38 : /// 39 : /// Uses: 40 : /// - GlobalCache: nothing 41 : /// - DataBox: 42 : /// - Tags::TimeStepId 43 : /// - system::variables_tag 44 : /// - as required by source terms 45 : /// 46 : /// DataBox changes: 47 : /// - imex::Tags::ImplicitHistory<sector> for each sector 48 : template <typename System> 49 1 : struct RecordTimeStepperData { 50 : template <typename DbTags, typename... InboxTags, typename Metavariables, 51 : typename ArrayIndex, typename ActionList, 52 : typename ParallelComponent> 53 0 : static Parallel::iterable_action_return_t apply( 54 : db::DataBox<DbTags>& box, tuples::TaggedTuple<InboxTags...>& /*inboxes*/, 55 : const Parallel::GlobalCache<Metavariables>& /*cache*/, 56 : const ArrayIndex& /*array_index*/, ActionList /*meta*/, 57 : const ParallelComponent* const /*meta*/) { // NOLINT const 58 : static_assert(tt::assert_conforms_to_v<System, protocols::ImexSystem>); 59 : 60 : const size_t number_of_grid_points = 61 : db::get<typename System::variables_tag>(box).number_of_grid_points(); 62 : 63 : tmpl::for_each<typename System::implicit_sectors>([&](auto sector_v) { 64 : using sector = tmpl::type_from<decltype(sector_v)>; 65 : using source = 66 : typename tmpl::front<typename sector::solve_attempts>::source; 67 : using history_tag = Tags::ImplicitHistory<sector>; 68 : using DtSectorVars = 69 : Variables<db::wrap_tags_in<::Tags::dt, typename sector::tensors>>; 70 : db::mutate_apply< 71 : tmpl::list<history_tag>, 72 : tmpl::push_front<typename source::argument_tags, ::Tags::TimeStepId>>( 73 : [&](const gsl::not_null<typename history_tag::type*> history, 74 : const TimeStepId& time_step_id, const auto&... source_arguments) { 75 : history->insert_in_place( 76 : time_step_id, history_tag::type::no_value, 77 : [&](const gsl::not_null<DtSectorVars*> source_result) { 78 : source_result->initialize(number_of_grid_points); 79 : tmpl::as_pack<typename source::return_tags>( 80 : [&](auto... source_tags) { 81 : // The history stores derivatives as 82 : // ::Tags::dt<Var>, but the source provides 83 : // ::Tags::Source<Var>. Since the only 84 : // implicit equations we support are source 85 : // terms, these quantities are equal, but we 86 : // still need to make the types match. 87 : source::apply( 88 : make_not_null( 89 : &get<::Tags::dt<db::remove_tag_prefix< 90 : tmpl::type_from<decltype(source_tags)>>>>( 91 : *source_result))..., 92 : source_arguments...); 93 : }); 94 : }); 95 : }, 96 : make_not_null(&box)); 97 : }); 98 : 99 : return {Parallel::AlgorithmExecution::Continue, std::nullopt}; 100 : } 101 : }; 102 : } // namespace imex::Actions