Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <cmath> 7 : #include <cstddef> 8 : #include <limits> 9 : #include <pup.h> 10 : 11 : #include "DataStructures/DataBox/DataBox.hpp" 12 : #include "Domain/MinimumGridSpacing.hpp" 13 : #include "Options/String.hpp" 14 : #include "Time/StepChoosers/StepChooser.hpp" 15 : #include "Time/TimeStepRequest.hpp" 16 : #include "Time/TimeSteppers/TimeStepper.hpp" 17 : #include "Utilities/Serialization/CharmPupable.hpp" 18 : #include "Utilities/TMPL.hpp" 19 : 20 : /// \cond 21 : namespace Tags { 22 : template <typename StepperInterface> 23 : struct TimeStepper; 24 : } // namespace Tags 25 : namespace domain { 26 : namespace Tags { 27 : template <size_t Dim, typename Frame> 28 : struct MinimumGridSpacing; 29 : } // namespace Tags 30 : } // namespace domain 31 : 32 : /// \endcond 33 : 34 : namespace StepChoosers { 35 : /// Sets a goal based on the CFL stability criterion. 36 : template <typename Frame, typename System> 37 1 : class Cfl : public StepChooser<StepChooserUse::Slab>, 38 : public StepChooser<StepChooserUse::LtsStep> { 39 : public: 40 : /// \cond 41 : Cfl() = default; 42 : explicit Cfl(CkMigrateMessage* /*unused*/) {} 43 : using PUP::able::register_constructor; 44 : WRAPPED_PUPable_decl_template(Cfl); // NOLINT 45 : /// \endcond 46 : 47 0 : struct SafetyFactor { 48 0 : using type = double; 49 0 : static constexpr Options::String help{"Multiplier for computed step"}; 50 0 : static type lower_bound() { return 0.0; } 51 : }; 52 : 53 0 : static constexpr Options::String help{ 54 : "Sets a goal based on the CFL stability criterion."}; 55 0 : using options = tmpl::list<SafetyFactor>; 56 : 57 0 : explicit Cfl(const double safety_factor) : safety_factor_(safety_factor) {} 58 : 59 0 : using argument_tags = 60 : tmpl::list<domain::Tags::MinimumGridSpacing<System::volume_dim, Frame>, 61 : ::Tags::TimeStepper<TimeStepper>, 62 : typename System::compute_largest_characteristic_speed::base>; 63 : 64 0 : using compute_tags = tmpl::list< 65 : domain::Tags::MinimumGridSpacingCompute<System::volume_dim, Frame>, 66 : typename System::compute_largest_characteristic_speed>; 67 : 68 0 : TimeStepRequest operator()(const double minimum_grid_spacing, 69 : const TimeStepper& time_stepper, 70 : const double speed, const double last_step) const { 71 : const double time_stepper_stability_factor = time_stepper.stable_step(); 72 : const double step_size = safety_factor_ * time_stepper_stability_factor * 73 : minimum_grid_spacing / 74 : (speed * System::volume_dim); 75 : return {.size_goal = std::copysign(step_size, last_step)}; 76 : } 77 : 78 1 : bool uses_local_data() const override { return true; } 79 1 : bool can_be_delayed() const override { return true; } 80 : 81 : // NOLINTNEXTLINE(google-runtime-references) 82 0 : void pup(PUP::er& p) override { 83 : StepChooser<StepChooserUse::Slab>::pup(p); 84 : StepChooser<StepChooserUse::LtsStep>::pup(p); 85 : p | safety_factor_; 86 : } 87 : 88 : private: 89 0 : double safety_factor_ = std::numeric_limits<double>::signaling_NaN(); 90 : }; 91 : 92 : /// \cond 93 : template <typename Frame, typename System> 94 : PUP::able::PUP_ID Cfl<Frame, System>::my_PUP_ID = 0; // NOLINT 95 : /// \endcond 96 : } // namespace StepChoosers