Cfl.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <limits>
7 #include <pup.h>
8 
9 #include "Domain/MinimumGridSpacing.hpp"
10 #include "Options/Options.hpp"
13 #include "Time/StepChoosers/StepChooser.hpp" // IWYU pragma: keep
14 #include "Time/Tags.hpp"
15 #include "Utilities/Registration.hpp"
16 #include "Utilities/TMPL.hpp"
17 
18 /// \cond
19 namespace Parallel {
20 template <typename Metavariables>
21 class ConstGlobalCache;
22 } // namespace Parallel
23 /// \endcond
24 
25 namespace StepChoosers {
26 template <size_t Dim, typename Frame, typename StepChooserRegistrars>
27 class Cfl;
28 
29 namespace Registrars {
30 template <size_t Dim, typename Frame>
31 struct Cfl {
32  template <typename StepChooserRegistrars>
34 };
35 } // namespace Registrars
36 
37 /// Suggests a step size based on the CFL stability criterion.
38 template <size_t Dim, typename Frame,
39  typename StepChooserRegistrars =
40  tmpl::list<Registrars::Cfl<Dim, Frame>>>
41 class Cfl : public StepChooser<StepChooserRegistrars> {
42  public:
43  /// \cond
44  Cfl() = default;
45  explicit Cfl(CkMigrateMessage* /*unused*/) noexcept {}
46  using PUP::able::register_constructor;
48  /// \endcond
49 
50  struct SafetyFactor {
51  using type = double;
52  static constexpr OptionString help{"Multiplier for computed step"};
53  static type default_value() noexcept { return 1.0; }
54  static type lower_bound() noexcept { return 0.0; }
55  };
56 
57  static constexpr OptionString help{
58  "Suggests a step size based on the CFL stability criterion."};
59  using options = tmpl::list<SafetyFactor>;
60 
61  explicit Cfl(const double safety_factor) noexcept
62  : safety_factor_(safety_factor) {}
63 
64  using argument_tags =
65  tmpl::list<Tags::MinimumGridSpacing<Dim, Frame>, Tags::DataBox>;
66 
67  template <typename Metavariables, typename DbTags>
68  double operator()(
69  const double minimum_grid_spacing, const db::DataBox<DbTags>& box,
70  const Parallel::ConstGlobalCache<Metavariables>& cache) const noexcept {
71  using compute_largest_characteristic_speed =
72  typename Metavariables::system::compute_largest_characteristic_speed;
73  const double speed =
74  db::apply<typename compute_largest_characteristic_speed::argument_tags>(
75  compute_largest_characteristic_speed{}, box);
76  const double time_stepper_stability_factor =
77  Parallel::get<OptionTags::TimeStepper>(cache).stable_step();
78 
79  return safety_factor_ * time_stepper_stability_factor *
80  minimum_grid_spacing / speed;
81  }
82 
83  // NOLINTNEXTLINE(google-runtime-references)
84  void pup(PUP::er& p) noexcept override { p | safety_factor_; }
85 
86  private:
87  double safety_factor_ = std::numeric_limits<double>::signaling_NaN();
88 };
89 
90 /// \cond
91 template <size_t Dim, typename Frame, typename StepChooserRegistrars>
93  0; // NOLINT
94 /// \endcond
95 } // namespace StepChoosers
double minimum_grid_spacing(const Index< Dim > &extents, const tnsr::I< DataVector, Dim, Frame > &coords) noexcept
Finds the minimum coordinate distance between grid points.
Definition: MinimumGridSpacing.cpp:33
T signaling_NaN(T... args)
Defines classes and functions for making classes creatable from input files.
Defines macros to allow serialization of abstract template base classes.
Definition: Cfl.hpp:31
Contains functions that forward to Charm++ parallel functions.
Definition: Abort.hpp:13
Definition: Cfl.hpp:50
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
StepChoosers suggest upper bounds on step sizes. Concrete StepChoosers should define operator() retur...
Definition: StepChooser.hpp:45
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:27
Tag used to retrieve the DataBox from the db::get function.
Definition: DataBoxTag.hpp:40
Indicates the Frame that a TensorIndexType is in.
Definition: IndexType.hpp:36
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Suggests a step size based on the CFL stability criterion.
Definition: Cfl.hpp:27
Wraps the template metaprogramming library used (brigand)
Defines class template ConstGlobalCache.
Defines tags related to Time quantities.
Holds all the StepChoosers.
Definition: Cfl.hpp:25