Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <cstdint> 7 : #include <type_traits> 8 : 9 : #include "DataStructures/DataBox/DataBox.hpp" 10 : #include "Time/Actions/ChangeStepSize.hpp" 11 : #include "Time/Actions/RecordTimeStepperData.hpp" 12 : #include "Time/Actions/UpdateU.hpp" 13 : #include "Time/AdaptiveSteppingDiagnostics.hpp" 14 : #include "Time/Tags/AdaptiveSteppingDiagnostics.hpp" 15 : #include "Time/Time.hpp" 16 : #include "Utilities/Gsl.hpp" 17 : 18 : /// \cond 19 : namespace Parallel::Tags { 20 : struct Metavariables; 21 : } // namespace Parallel::Tags 22 : namespace Tags { 23 : struct TimeStep; 24 : } // namespace Tags 25 : /// \endcond 26 : 27 : /// Bundled method for recording the current system state in the history, and 28 : /// updating the evolved variables and step size. 29 : /// 30 : /// This function is used to encapsulate any needed logic for updating the 31 : /// system, and in the case for which step parameters may need to be rejected 32 : /// and re-tried, looping until an acceptable step is performed. 33 : template <typename System, bool LocalTimeStepping, 34 : typename StepChoosersToUse = AllStepChoosers, typename DbTags> 35 1 : void take_step(const gsl::not_null<db::DataBox<DbTags>*> box) { 36 : record_time_stepper_data<System>(box); 37 : if constexpr (LocalTimeStepping) { 38 : uint64_t step_attempts = 0; 39 : const auto original_step = db::get<Tags::TimeStep>(*box); 40 : do { 41 : ++step_attempts; 42 : update_u<System>(box); 43 : } while (not change_step_size<StepChoosersToUse>(box)); 44 : db::mutate<Tags::AdaptiveSteppingDiagnostics>( 45 : [&](const gsl::not_null<AdaptiveSteppingDiagnostics*> diags, 46 : const TimeDelta& new_step) { 47 : diags->number_of_step_rejections += step_attempts - 1; 48 : if (original_step != new_step) { 49 : ++diags->number_of_step_fraction_changes; 50 : } 51 : }, 52 : box, db::get<Tags::TimeStep>(*box)); 53 : } else { 54 : update_u<System>(box); 55 : } 56 : }