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 <utility> 10 : 11 : #include "DataStructures/DataBox/DataBox.hpp" 12 : #include "DataStructures/VariablesTag.hpp" 13 : #include "Evolution/Initialization/Tags.hpp" 14 : #include "Evolution/Systems/Cce/OptionTags.hpp" 15 : #include "Parallel/AlgorithmExecution.hpp" 16 : #include "ParallelAlgorithms/Initialization/MutateAssign.hpp" 17 : #include "Time/ChooseLtsStepSize.hpp" 18 : #include "Time/Slab.hpp" 19 : #include "Time/Tags/AdaptiveSteppingDiagnostics.hpp" 20 : #include "Time/Tags/HistoryEvolvedVariables.hpp" 21 : #include "Time/Tags/StepChoosers.hpp" 22 : #include "Time/Tags/StepNumberWithinSlab.hpp" 23 : #include "Time/Tags/Time.hpp" 24 : #include "Time/Tags/TimeStep.hpp" 25 : #include "Time/Tags/TimeStepId.hpp" 26 : #include "Time/Tags/TimeStepper.hpp" 27 : #include "Time/Time.hpp" 28 : #include "Time/TimeStepId.hpp" 29 : #include "Time/TimeSteppers/LtsTimeStepper.hpp" 30 : #include "Time/TimeSteppers/TimeStepper.hpp" 31 : #include "Utilities/Rational.hpp" 32 : #include "Utilities/Requires.hpp" 33 : #include "Utilities/TMPL.hpp" 34 : #include "Utilities/TaggedTuple.hpp" 35 : 36 : namespace Cce { 37 : namespace Actions { 38 : 39 : /*! 40 : * \ingroup ActionsGroup 41 : * \brief Initializes the contents of the `CharacteristicEvolution` component 42 : * for performing the time evolution of the system, which is the singleton that 43 : * handles the main evolution system for CCE computations. 44 : * 45 : * \details Sets up the \ref DataBoxGroup to be ready to perform the 46 : * time-stepping associated with the CCE system. 47 : * 48 : * \ref DataBoxGroup changes: 49 : * - Modifies: nothing 50 : * - Adds: 51 : * - `Tags::TimeStepId` 52 : * - `Tags::Next<Tags::TimeStepId>` 53 : * - `Tags::TimeStep` 54 : * - `Tags::Time` 55 : * - `Tags::AdaptiveSteppingDiagnostics` 56 : * ``` 57 : * Tags::HistoryEvolvedVariables< 58 : * metavariables::evolved_coordinates_variables_tag, 59 : * db::add_tag_prefix<Tags::dt, 60 : * metavariables::evolved_coordinates_variables_tag>> 61 : * ``` 62 : * - 63 : * ``` 64 : * Tags::HistoryEvolvedVariables< 65 : * ::Tags::Variables<metavariables::evolved_swsh_tags>, 66 : * ::Tags::Variables<metavariables::evolved_swsh_dt_tags>> 67 : * ``` 68 : * - Removes: nothing 69 : */ 70 : template <typename EvolvedCoordinatesVariablesTag, typename EvolvedSwshTag, 71 : bool local_time_stepping> 72 1 : struct InitializeCharacteristicEvolutionTime { 73 0 : using simple_tags_from_options = tmpl::flatten<tmpl::list< 74 : Initialization::Tags::InitialSlabSize<local_time_stepping>, 75 : Tags::CceEvolutionPrefix<::Tags::ConcreteTimeStepper<LtsTimeStepper>>, 76 : Tags::CceEvolutionPrefix<::Tags::StepChoosers>, 77 : ::Initialization::Tags::InitialTimeDelta>>; 78 : 79 0 : using const_global_cache_tags = tmpl::list<>; 80 : 81 0 : using evolved_swsh_variables_tag = ::Tags::Variables<EvolvedSwshTag>; 82 0 : using simple_tags = tmpl::list< 83 : ::Tags::TimeStepId, ::Tags::Next<::Tags::TimeStepId>, ::Tags::TimeStep, 84 : ::Tags::Time, ::Tags::StepNumberWithinSlab, 85 : ::Tags::AdaptiveSteppingDiagnostics, 86 : ::Tags::HistoryEvolvedVariables<EvolvedCoordinatesVariablesTag>, 87 : ::Tags::HistoryEvolvedVariables<evolved_swsh_variables_tag>>; 88 0 : using compute_tags = time_stepper_ref_tags<LtsTimeStepper>; 89 : 90 : template <typename DbTags, typename... InboxTags, typename Metavariables, 91 : typename ArrayIndex, typename ActionList, 92 : typename ParallelComponent> 93 0 : static Parallel::iterable_action_return_t apply( 94 : db::DataBox<DbTags>& box, 95 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, 96 : const Parallel::GlobalCache<Metavariables>& /*cache*/, 97 : const ArrayIndex& /*array_index*/, const ActionList /*meta*/, 98 : const ParallelComponent* const /*meta*/) { 99 : const double initial_time_value = db::get<Tags::StartTime>(box); 100 : const double slab_size = 101 : db::get<::Initialization::Tags::InitialSlabSize<local_time_stepping>>( 102 : box); 103 : 104 : const Slab single_step_slab{initial_time_value, 105 : initial_time_value + slab_size}; 106 : const Time initial_time = single_step_slab.start(); 107 : TimeDelta initial_time_step; 108 : const double initial_time_delta = 109 : db::get<Initialization::Tags::InitialTimeDelta>(box); 110 : if constexpr (local_time_stepping) { 111 : initial_time_step = 112 : choose_lts_step_size(initial_time, initial_time_delta); 113 : } else { 114 : (void)initial_time_delta; 115 : initial_time_step = initial_time.slab().duration(); 116 : } 117 : 118 : const auto& time_stepper = db::get<::Tags::TimeStepper<TimeStepper>>(box); 119 : 120 : const size_t starting_order = 121 : visit( 122 : []<typename Tag>( 123 : const std::pair<tmpl::type_<Tag>, typename Tag::type&&> order) { 124 : if constexpr (std::is_same_v<Tag, 125 : TimeSteppers::Tags::FixedOrder>) { 126 : return order.second; 127 : } else { 128 : return order.second.minimum; 129 : } 130 : }, 131 : time_stepper.order()) - 132 : time_stepper.number_of_past_steps(); 133 : 134 : typename ::Tags::HistoryEvolvedVariables<EvolvedCoordinatesVariablesTag>:: 135 : type coordinate_history(starting_order); 136 : 137 : typename ::Tags::HistoryEvolvedVariables<evolved_swsh_variables_tag>::type 138 : swsh_history(starting_order); 139 : Initialization::mutate_assign<tmpl::list< 140 : ::Tags::TimeStepId, ::Tags::Next<::Tags::TimeStepId>, ::Tags::TimeStep, 141 : ::Tags::Time, 142 : ::Tags::HistoryEvolvedVariables<EvolvedCoordinatesVariablesTag>, 143 : ::Tags::HistoryEvolvedVariables<evolved_swsh_variables_tag>>>( 144 : make_not_null(&box), TimeStepId{}, 145 : TimeStepId{true, 146 : -static_cast<int64_t>(time_stepper.number_of_past_steps()), 147 : initial_time}, 148 : initial_time_step, initial_time_value, std::move(coordinate_history), 149 : std::move(swsh_history)); 150 : return {Parallel::AlgorithmExecution::Continue, std::nullopt}; 151 : } 152 : }; 153 : 154 : } // namespace Actions 155 : } // namespace Cce