SplitRemaining.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 /// \file
5 /// Defines class StepControllers::SplitRemaining
6 
7 #pragma once
8 
9 #include <algorithm>
10 #include <cmath>
11 #include <cstddef>
12 #include <cstdint>
13 #include <pup.h>
14 
15 #include "Options/Options.hpp"
17 #include "Time/Slab.hpp"
18 #include "Time/StepControllers/StepController.hpp" // IWYU pragma: keep
19 #include "Time/Time.hpp"
20 #include "Utilities/TMPL.hpp"
21 
22 namespace StepControllers {
23 
24 /// \ingroup TimeSteppersGroup
25 ///
26 /// A StepController that chooses steps to be 1/n of the remainder of
27 /// the slab.
29  public:
30  /// \cond
31  SplitRemaining() = default;
32  explicit SplitRemaining(CkMigrateMessage* /*unused*/) noexcept {}
34  /// \endcond
35 
36  using options = tmpl::list<>;
37  static constexpr OptionString help = {
38  "Chooses steps by dividing the remainder of the slab evenly.\n"
39  "WARNING: With many steps per slab this often leads to overflow in the\n"
40  " time representations."};
41 
42  TimeDelta choose_step(const Time& time,
43  const double desired_step) const noexcept override {
44  const Time goal =
45  desired_step > 0 ? time.slab().end() : time.slab().start();
46  const TimeDelta remaining = goal - time;
47  const auto steps = std::max(
48  static_cast<int32_t>(std::ceil(remaining.value() / desired_step)), 1);
49 
50  return remaining / steps;
51  }
52 };
53 } // namespace StepControllers
The time in a simulation. Times can be safely compared for exact equality as long as they do not belo...
Definition: Time.hpp:31
Defines base class StepController.
Defines classes and functions for making classes creatable from input files.
Defines macros to allow serialization of abstract template base classes.
Defines Time and TimeDelta.
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:26
StepControllers take desired step sizes (generally determined by StepChoosers) and convert them into ...
Definition: StepController.hpp:31
#define WRAPPED_PUPable_decl(className)
Wraps the Charm++ macro, see the Charm++ documentation.
Definition: CharmPupable.hpp:36
A StepController that chooses steps to be 1/n of the remainder of the slab.
Definition: SplitRemaining.hpp:28
Holds all the StepControllers.
Definition: BinaryFraction.cpp:6
Represents an interval of time within a single slab.
Definition: Time.hpp:108
Defines class Slab.
Wraps the template metaprogramming library used (brigand)
double value() const noexcept
Approximate numerical length of the interval.
Definition: Time.hpp:131