ElementSizeCfl.hpp
1 // 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 
12 #include "Options/Options.hpp"
14 #include "Time/StepChoosers/StepChooser.hpp"
15 #include "Domain/SizeOfElement.hpp"
16 #include "Time/Tags.hpp"
17 #include "Utilities/TMPL.hpp"
18 
19 /// \cond
20 namespace Parallel {
21 template <typename Metavariables>
22 class GlobalCache;
23 } // namespace Parallel
24 namespace domain {
25 namespace Tags {
26 template <size_t Dim>
27 struct SizeOfElement;
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, but uses the full
35 /// size of the element as the length scale in question.
36 ///
37 /// This is useful as a coarse estimate for slabs, or to place a ceiling on
38 /// another dynamically-adjusted step chooser.
39 template <typename StepChooserUse, size_t Dim, typename System>
40 class ElementSizeCfl : public StepChooser<StepChooserUse> {
41  public:
42  /// \cond
43  ElementSizeCfl() = default;
44  explicit ElementSizeCfl(CkMigrateMessage* /*unused*/) noexcept {}
45  using PUP::able::register_constructor;
47  /// \endcond
48 
49  struct SafetyFactor {
50  using type = double;
51  static constexpr Options::String help{"Multiplier for computed step"};
52  static type lower_bound() noexcept { return 0.0; }
53  };
54 
55  static constexpr Options::String help{
56  "Suggests a step size based on the CFL stability criterion, but in which "
57  "the entire size of the element is used as the spacing in the "
58  "computation. This is useful primarily for placing a ceiling on another "
59  "dynamically-adjusted step chooser"};
60  using options = tmpl::list<SafetyFactor>;
61 
62  explicit ElementSizeCfl(const double safety_factor) noexcept
63  : safety_factor_(safety_factor) {}
64 
65  using argument_tags =
66  tmpl::list<::Tags::TimeStepper<>, domain::Tags::SizeOfElement<Dim>,
67  typename System::compute_largest_characteristic_speed>;
68  using return_tags = tmpl::list<>;
69  using compute_tags =
70  tmpl::list<domain::Tags::SizeOfElementCompute<Dim>,
71  typename System::compute_largest_characteristic_speed>;
72 
73  template <typename Metavariables>
74  std::pair<double, bool> operator()(
75  const typename Metavariables::time_stepper_tag::type::element_type&
76  time_stepper,
77  const std::array<double, Dim>& element_size, const double speed,
78  const double last_step_magnitude,
79  const Parallel::GlobalCache<Metavariables>& /*cache*/) const noexcept {
80  double min_size_of_element = std::numeric_limits<double>::infinity();
81  for (auto face_to_face_dimension : element_size) {
82  if (face_to_face_dimension < min_size_of_element) {
83  min_size_of_element = face_to_face_dimension;
84  }
85  }
86  const double time_stepper_stability_factor = time_stepper.stable_step();
87  const double step_size = safety_factor_ * time_stepper_stability_factor *
88  min_size_of_element / (speed * Dim);
89  // Reject the step if the CFL condition is violated.
90  return std::make_pair(step_size, last_step_magnitude <= step_size);
91  }
92 
93  // NOLINTNEXTLINE(google-runtime-references)
94  void pup(PUP::er& p) noexcept override { p | safety_factor_; }
95 
96  private:
97  double safety_factor_ = std::numeric_limits<double>::signaling_NaN();
98 };
99 
100 /// \cond
101 template <typename StepChooserUse, size_t Dim, typename System>
102 PUP::able::PUP_ID ElementSizeCfl<StepChooserUse, Dim, System>::my_PUP_ID =
103  0; // NOLINT
104 /// \endcond
105 } // namespace StepChoosers
StepChoosers::ElementSizeCfl
Suggests a step size based on the CFL stability criterion, but uses the full size of the element as t...
Definition: ElementSizeCfl.hpp:40
CharmPupable.hpp
StepChoosers
Definition: ByBlock.hpp:33
utility
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
std::pair
Options.hpp
StepChoosers::ElementSizeCfl::SafetyFactor
Definition: ElementSizeCfl.hpp:49
domain::Tags::SizeOfElement
Definition: SizeOfElement.hpp:77
WRAPPED_PUPable_decl_template
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
DataBox.hpp
std::numeric_limits::infinity
T infinity(T... args)
cstddef
std::array< double, Dim >
std::numeric_limits::signaling_NaN
T signaling_NaN(T... args)
limits
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
StepChooser
StepChoosers suggest upper bounds on step sizes.
Definition: StepChooser.hpp:56
Parallel
Functionality for parallelization.
Definition: ElementReceiveInterpPoints.hpp:13
TMPL.hpp