SpECTRE Documentation Coverage Report
Current view: top level - Time/StepChoosers - Cfl.hpp Hit Total Coverage
Commit: 1c32b58340e006addc79befb2cdaa7547247e09c Lines: 2 15 13.3 %
Date: 2024-04-19 07:30:15
Legend: Lines: hit not hit

          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 <limits>
       8             : #include <pup.h>
       9             : #include <utility>
      10             : 
      11             : #include "DataStructures/DataBox/DataBox.hpp"
      12             : #include "Domain/MinimumGridSpacing.hpp"
      13             : #include "Options/String.hpp"
      14             : #include "Time/StepChoosers/StepChooser.hpp"  // IWYU pragma: keep
      15             : #include "Time/TimeSteppers/TimeStepper.hpp"
      16             : #include "Utilities/Serialization/CharmPupable.hpp"
      17             : #include "Utilities/TMPL.hpp"
      18             : 
      19             : /// \cond
      20             : namespace Tags {
      21             : template <typename StepperInterface>
      22             : struct TimeStepper;
      23             : }  // namespace Tags
      24             : namespace domain {
      25             : namespace Tags {
      26             : template <size_t Dim, typename Frame>
      27             : struct MinimumGridSpacing;
      28             : }  // namespace Tags
      29             : }  // namespace domain
      30             : // IWYU pragma: no_forward_declare db::DataBox
      31             : /// \endcond
      32             : 
      33             : namespace StepChoosers {
      34             : /// Suggests a step size based on the CFL stability criterion.
      35             : template <typename StepChooserUse, typename Frame, typename System>
      36           1 : class Cfl : public StepChooser<StepChooserUse> {
      37             :  public:
      38             :   /// \cond
      39             :   Cfl() = default;
      40             :   explicit Cfl(CkMigrateMessage* /*unused*/) {}
      41             :   using PUP::able::register_constructor;
      42             :   WRAPPED_PUPable_decl_template(Cfl);  // NOLINT
      43             :   /// \endcond
      44             : 
      45           0 :   struct SafetyFactor {
      46           0 :     using type = double;
      47           0 :     static constexpr Options::String help{"Multiplier for computed step"};
      48           0 :     static type lower_bound() { return 0.0; }
      49             :   };
      50             : 
      51           0 :   static constexpr Options::String help{
      52             :       "Suggests a step size based on the CFL stability criterion."};
      53           0 :   using options = tmpl::list<SafetyFactor>;
      54             : 
      55           0 :   explicit Cfl(const double safety_factor) : safety_factor_(safety_factor) {}
      56             : 
      57           0 :   using argument_tags =
      58             :       tmpl::list<domain::Tags::MinimumGridSpacing<System::volume_dim, Frame>,
      59             :                  ::Tags::TimeStepper<TimeStepper>,
      60             :                  typename System::compute_largest_characteristic_speed>;
      61             : 
      62           0 :   using compute_tags = tmpl::list<
      63             :       domain::Tags::MinimumGridSpacingCompute<System::volume_dim, Frame>,
      64             :       typename System::compute_largest_characteristic_speed>;
      65             : 
      66           0 :   std::pair<double, bool> operator()(
      67             :       const double minimum_grid_spacing,
      68             :       const TimeStepper& time_stepper,
      69             :       const double speed, const double last_step_magnitude) const {
      70             :     const double time_stepper_stability_factor = time_stepper.stable_step();
      71             :     const double step_size = safety_factor_ * time_stepper_stability_factor *
      72             :                              minimum_grid_spacing /
      73             :                              (speed * System::volume_dim);
      74             :     // Reject the step if the CFL condition is violated.
      75             :     return std::make_pair(step_size, last_step_magnitude <= step_size);
      76             :   }
      77             : 
      78           1 :   bool uses_local_data() const override { return true; }
      79             : 
      80             :   // NOLINTNEXTLINE(google-runtime-references)
      81           0 :   void pup(PUP::er& p) override { p | safety_factor_; }
      82             : 
      83             :  private:
      84           0 :   double safety_factor_ = std::numeric_limits<double>::signaling_NaN();
      85             : };
      86             : 
      87             : /// \cond
      88             : template <typename StepChooserUse, typename Frame, typename System>
      89             : PUP::able::PUP_ID Cfl<StepChooserUse, Frame, System>::my_PUP_ID = 0;  // NOLINT
      90             : /// \endcond
      91             : }  // namespace StepChoosers

Generated by: LCOV version 1.14