Constant.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 
10 #include "Options/Options.hpp"
12 #include "Time/StepChoosers/StepChooser.hpp" // IWYU pragma: keep
13 #include "Utilities/Registration.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 /// \cond
17 namespace Parallel {
18 template <typename Metavariables>
19 class ConstGlobalCache;
20 } // namespace Parallel
21 /// \endcond
22 
23 namespace StepChoosers {
24 template <typename StepChooserRegistrars>
25 class Constant;
26 
27 namespace Registrars {
29 } // namespace Registrars
30 
31 /// Suggests a constant step size.
32 template <typename StepChooserRegistrars = tmpl::list<Registrars::Constant>>
33 class Constant : public StepChooser<StepChooserRegistrars> {
34  public:
35  /// \cond
36  Constant() = default;
37  explicit Constant(CkMigrateMessage* /*unused*/) noexcept {}
38  using PUP::able::register_constructor;
40  /// \endcond
41 
42  static constexpr OptionString help{"Suggests a constant step size."};
43 
44  explicit Constant(const double value) noexcept : value_(value) {
45  ASSERT(value_ > 0., "Requested step magnitude should be positive.");
46  }
47 
48  using argument_tags = tmpl::list<>;
49 
50  template <typename Metavariables>
51  double operator()(const Parallel::ConstGlobalCache<Metavariables>& /*cache*/)
52  const noexcept {
53  return value_;
54  }
55 
56  // NOLINTNEXTLINE(google-runtime-references)
57  void pup(PUP::er& p) noexcept override { p | value_; }
58 
59  private:
61 };
62 
63 /// \cond
64 template <typename StepChooserRegistrars>
65 PUP::able::PUP_ID Constant<StepChooserRegistrars>::my_PUP_ID = 0; // NOLINT
66 /// \endcond
67 
68 namespace Constant_detail {
69 double parse_options(const Option& options);
70 } // namespace Constant_detail
71 } // namespace StepChoosers
72 
73 template <typename StepChooserRegistrars>
74 struct create_from_yaml<StepChoosers::Constant<StepChooserRegistrars>> {
75  template <typename Metavariables>
77  const Option& options) {
79  StepChoosers::Constant_detail::parse_options(options));
80  }
81 };
Suggests a constant step size.
Definition: Constant.hpp:25
The type that options are passed around as. Contains YAML node data and an OptionContext.
Definition: Options.hpp:104
T signaling_NaN(T... args)
Used by the parser to create an object. The default action is to parse options using T::options...
Definition: Options.hpp:144
Defines classes and functions for making classes creatable from input files.
Defines macros to allow serialization of abstract template base classes.
constexpr auto create(Args &&... args)
Create a new DataBox.
Definition: DataBox.hpp:1259
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:49
Contains functions that forward to Charm++ parallel functions.
Definition: Abort.hpp:13
#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
A template for defining a registrar.
Definition: Registration.hpp:42
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Defines macro ASSERT.
Wraps the template metaprogramming library used (brigand)
Holds all the StepChoosers.
Definition: Cfl.hpp:25