Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <memory> 7 : #include <type_traits> 8 : #include <typeindex> 9 : #include <vector> 10 : 11 : #include "DataStructures/DataBox/Tag.hpp" 12 : #include "ParallelAlgorithms/EventsAndTriggers/WhenToCheck.hpp" 13 : #include "Time/Tags/StepperErrorEstimatesEnabled.hpp" 14 : #include "Time/Tags/StepperErrorTolerances.hpp" 15 : #include "Utilities/Gsl.hpp" 16 : #include "Utilities/TMPL.hpp" 17 : 18 : /// \cond 19 : class EventsAndTriggers; 20 : template <typename StepChooserUse> 21 : class StepChooser; 22 : struct StepperErrorTolerances; 23 : class TimeStepper; 24 : class VariableOrderAlgorithm; 25 : namespace StepChooserUse { 26 : struct LtsStep; 27 : } // namespace StepChooserUse 28 : namespace Tags { 29 : template <Triggers::WhenToCheck WhenToCheck> 30 : struct EventsAndTriggers; 31 : struct LtsStepChoosers; 32 : template <typename StepperInterface> 33 : struct TimeStepper; 34 : struct VariableOrderAlgorithm; 35 : } // namespace Tags 36 : /// \endcond 37 : 38 : namespace Tags { 39 : namespace StepperErrorEstimatesEnabledCompute_detail { 40 : void lts_function( 41 : gsl::not_null<bool*> error_estimates_enabled, 42 : const ::EventsAndTriggers& events_and_triggers, 43 : const std::vector<std::unique_ptr<::StepChooser<StepChooserUse::LtsStep>>>& 44 : step_choosers); 45 : 46 : void gts_function(gsl::not_null<bool*> error_estimates_enabled, 47 : const ::EventsAndTriggers& events_and_triggers); 48 : } // namespace StepperErrorEstimatesEnabledCompute_detail 49 : 50 : /// \ingroup TimeGroup 51 : /// \brief Searches the StepChoosers for any requesting error estimates. 52 : template <bool LocalTimeStepping, 53 : template <typename> typename CacheTagPrefix = std::type_identity_t> 54 1 : struct StepperErrorEstimatesEnabledCompute : db::ComputeTag, 55 : StepperErrorEstimatesEnabled { 56 0 : using base = StepperErrorEstimatesEnabled; 57 0 : using return_type = type; 58 0 : using argument_tags = tmpl::conditional_t< 59 : LocalTimeStepping, 60 : tmpl::list<::Tags::EventsAndTriggers<Triggers::WhenToCheck::AtSlabs>, 61 : CacheTagPrefix<::Tags::LtsStepChoosers>>, 62 : tmpl::list<::Tags::EventsAndTriggers<Triggers::WhenToCheck::AtSlabs>>>; 63 : 64 0 : static constexpr auto function = []() { 65 : if constexpr (LocalTimeStepping) { 66 : return &StepperErrorEstimatesEnabledCompute_detail::lts_function; 67 : } else { 68 : return &StepperErrorEstimatesEnabledCompute_detail::gts_function; 69 : } 70 : }(); 71 : }; 72 : 73 : namespace StepperErrorTolerancesCompute_detail { 74 : void lts_impl( 75 : gsl::not_null<::StepperErrorTolerances*> tolerances, 76 : const ::EventsAndTriggers& events_and_triggers, 77 : const std::vector<std::unique_ptr<::StepChooser<StepChooserUse::LtsStep>>>& 78 : step_choosers, 79 : const ::TimeStepper& time_stepper, 80 : const ::VariableOrderAlgorithm& variable_order_algorithm, 81 : const std::type_index& tag_type); 82 : 83 : void gts_impl(gsl::not_null<::StepperErrorTolerances*> tolerances, 84 : const ::EventsAndTriggers& events_and_triggers, 85 : const std::type_index& tag_type); 86 : } // namespace StepperErrorTolerancesCompute_detail 87 : 88 : /// \ingroup TimeGroup 89 : /// \brief A tag that contains the error tolerances if any StepChooser 90 : /// requests an error estimate for the variable. 91 : template <typename EvolvedVariableTag, bool LocalTimeStepping, 92 : template <typename> typename CacheTagPrefix = std::type_identity_t> 93 1 : struct StepperErrorTolerancesCompute 94 : : db::ComputeTag, 95 : StepperErrorTolerances<EvolvedVariableTag> { 96 0 : using base = StepperErrorTolerances<EvolvedVariableTag>; 97 0 : using return_type = typename base::type; 98 0 : using argument_tags = tmpl::conditional_t< 99 : LocalTimeStepping, 100 : tmpl::list<::Tags::EventsAndTriggers<Triggers::WhenToCheck::AtSlabs>, 101 : CacheTagPrefix<::Tags::LtsStepChoosers>, 102 : CacheTagPrefix<::Tags::TimeStepper<::TimeStepper>>, 103 : CacheTagPrefix<::Tags::VariableOrderAlgorithm>>, 104 : tmpl::list<::Tags::EventsAndTriggers<Triggers::WhenToCheck::AtSlabs>>>; 105 : 106 : // local time stepping 107 0 : static void function( 108 : const gsl::not_null<::StepperErrorTolerances*> tolerances, 109 : const ::EventsAndTriggers& events_and_triggers, 110 : const std::vector< 111 : std::unique_ptr<::StepChooser<StepChooserUse::LtsStep>>>& 112 : step_choosers, 113 : const ::TimeStepper& time_stepper, 114 : const ::VariableOrderAlgorithm& variable_order_algorithm) { 115 : StepperErrorTolerancesCompute_detail::lts_impl( 116 : tolerances, events_and_triggers, step_choosers, time_stepper, 117 : variable_order_algorithm, typeid(EvolvedVariableTag)); 118 : } 119 : 120 : // global time stepping 121 0 : static void function( 122 : const gsl::not_null<::StepperErrorTolerances*> tolerances, 123 : const ::EventsAndTriggers& events_and_triggers) { 124 : StepperErrorTolerancesCompute_detail::gts_impl( 125 : tolerances, events_and_triggers, typeid(EvolvedVariableTag)); 126 : } 127 : }; 128 : } // namespace Tags