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