StepChooser.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <pup.h>
7 #include <type_traits>
8 
10 #include "ErrorHandling/Assert.hpp"
12 #include "Utilities/FakeVirtual.hpp"
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 // IWYU pragma: no_forward_declare db::DataBox
22 /// \endcond
23 
24 /// \ingroup TimeSteppersGroup
25 ///
26 /// Holds all the StepChoosers
27 namespace StepChoosers {
28 /// Holds all the StepChooser registrars
29 ///
30 /// These can be passed in a list to the template argument of
31 /// StepChooser to choose which StepChoosers can be constructed.
32 namespace Registrars {}
33 } // namespace StepChoosers
34 
35 /// \ingroup TimeSteppersGroup
36 ///
37 /// StepChoosers suggest upper bounds on step sizes. Concrete
38 /// StepChoosers should define operator() returning the magnitude of
39 /// the desired step (as a double).
40 ///
41 /// The step choosers valid for the integration being controlled are
42 /// specified by passing a `tmpl::list` of the corresponding
43 /// registrars.
44 template <typename StepChooserRegistrars>
45 class StepChooser : public PUP::able {
46  protected:
47  /// \cond HIDDEN_SYMBOLS
48  StepChooser() = default;
49  StepChooser(const StepChooser&) = default;
50  StepChooser(StepChooser&&) = default;
51  StepChooser& operator=(const StepChooser&) = default;
52  StepChooser& operator=(StepChooser&&) = default;
53  /// \endcond
54 
55  public:
56  ~StepChooser() override = default;
57 
59 
60  using creatable_classes = Registration::registrants<StepChooserRegistrars>;
61 
62  template <typename Metavariables, typename DbTags>
63  double desired_step(
64  const db::DataBox<DbTags>& box,
65  const Parallel::ConstGlobalCache<Metavariables>& cache) const noexcept {
66  const auto result = call_with_dynamic_type<double, creatable_classes>(
67  this, [&box, &cache](const auto* const chooser) noexcept {
68  using ChooserType = std::decay_t<decltype(*chooser)>;
69  return db::apply<typename ChooserType::argument_tags>(*chooser, box,
70  cache);
71  });
72  ASSERT(
73  result > 0.,
74  "StepChoosers should always return positive values. Got " << result);
75  return result;
76  }
77 };
tmpl::transform< tmpl::remove_duplicates< RegistrarList >, detail::registrant< tmpl::pin< tmpl::remove_duplicates< RegistrarList > >, tmpl::_1 > > registrants
Transform a list of registrars into the list of associated registrants. This is usually used to defin...
Definition: Registration.hpp:65
Defines macros to allow serialization of abstract template base classes.
#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
StepChoosers suggest upper bounds on step sizes. Concrete StepChoosers should define operator() retur...
Definition: StepChooser.hpp:45
Defines classes and functions used for manipulating DataBox&#39;s.
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Defines macro ASSERT.
#define WRAPPED_PUPable_abstract(className)
Wraps the Charm++ macro, see the Charm++ documentation.
Definition: CharmPupable.hpp:39
Wraps the template metaprogramming library used (brigand)
Holds all the StepChoosers.
Definition: Cfl.hpp:25