Slabs.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstdint>
7 #include <memory>
8 #include <pup.h>
9 #include <pup_stl.h>
10 #include <utility>
11 
12 #include "Options/Options.hpp"
13 #include "Options/ParseOptions.hpp"
15 #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
16 #include "Time/TimeSequence.hpp"
17 #include "Time/TimeStepId.hpp"
18 #include "Utilities/TMPL.hpp"
19 
20 /// \cond
21 namespace Tags {
22 struct TimeStepId;
23 } // namespace Tags
24 /// \endcond
25 
26 namespace Triggers {
27 /// \ingroup EventsAndTriggersGroup
28 /// \ingroup TimeGroup
29 /// Trigger at specified numbers of slabs after the simulation start.
30 class Slabs : public Trigger {
31  public:
32  /// \cond
33  Slabs() = default;
34  explicit Slabs(CkMigrateMessage* /*unused*/) noexcept {}
35  using PUP::able::register_constructor;
37  /// \endcond
38 
39  static constexpr Options::String help{
40  "Trigger at specified numbers of slabs after the simulation start."};
41 
42  explicit Slabs(std::unique_ptr<TimeSequence<uint64_t>> slabs) noexcept
43  : slabs_(std::move(slabs)) {}
44 
45  using argument_tags = tmpl::list<Tags::TimeStepId>;
46 
47  bool operator()(const TimeStepId& time_id) const noexcept {
48  if (not time_id.is_at_slab_boundary() or time_id.slab_number() < 0) {
49  return false;
50  }
51  const auto unsigned_slab =
52  static_cast<std::uint64_t>(time_id.slab_number());
53  return slabs_->times_near(unsigned_slab)[1] == unsigned_slab;
54  }
55 
56  // clang-tidy: google-runtime-references
57  void pup(PUP::er& p) noexcept override { // NOLINT
58  p | slabs_;
59  }
60 
61  private:
63 };
64 } // namespace Triggers
65 
66 template <>
67 struct Options::create_from_yaml<Triggers::Slabs> {
68  template <typename Metavariables>
69  static Triggers::Slabs create(const Option& options) {
70  return Triggers::Slabs(
71  options.parse_as<std::unique_ptr<TimeSequence<uint64_t>>,
72  Metavariables>());
73  }
74 };
CharmPupable.hpp
utility
Options.hpp
ParseOptions.hpp
Options::Option
Definition: Options.hpp:108
TimeSequence
Represents a sequence of times.
Definition: TimeSequence.hpp:21
WRAPPED_PUPable_decl_template
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
Options::create_from_yaml
Definition: MinmodType.hpp:11
cstdint
std::uint64_t
Trigger
Definition: Trigger.hpp:17
Triggers::Slabs
Definition: Slabs.hpp:30
memory
TimeStepId
Definition: TimeStepId.hpp:25
TimeStepId.hpp
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
std::unique_ptr
TMPL.hpp