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/Registration.hpp"
19 #include "Utilities/TMPL.hpp"
20 
21 /// \cond
22 namespace Tags {
23 struct TimeStepId;
24 } // namespace Tags
25 /// \endcond
26 
27 namespace Triggers {
28 template <typename TriggerRegistrars>
29 class Slabs;
30 
31 namespace Registrars {
33 } // namespace Registrars
34 
35 /// \ingroup EventsAndTriggersGroup
36 /// \ingroup TimeGroup
37 /// Trigger at specified numbers of slabs after the simulation start.
38 template <typename TriggerRegistrars = tmpl::list<Registrars::Slabs>>
39 class Slabs : public Trigger<TriggerRegistrars> {
40  public:
41  /// \cond
42  Slabs() = default;
43  explicit Slabs(CkMigrateMessage* /*unused*/) noexcept {}
44  using PUP::able::register_constructor;
45  WRAPPED_PUPable_decl_template(Slabs); // NOLINT
46  /// \endcond
47 
48  static constexpr Options::String help{
49  "Trigger at specified numbers of slabs after the simulation start."};
50 
51  explicit Slabs(std::unique_ptr<TimeSequence<uint64_t>> slabs) noexcept
52  : slabs_(std::move(slabs)) {}
53 
54  using argument_tags = tmpl::list<Tags::TimeStepId>;
55 
56  bool operator()(const TimeStepId& time_id) const noexcept {
57  if (not time_id.is_at_slab_boundary() or time_id.slab_number() < 0) {
58  return false;
59  }
60  const auto unsigned_slab =
61  static_cast<std::uint64_t>(time_id.slab_number());
62  return slabs_->times_near(unsigned_slab)[1] == unsigned_slab;
63  }
64 
65  // clang-tidy: google-runtime-references
66  void pup(PUP::er& p) noexcept override { // NOLINT
67  p | slabs_;
68  }
69 
70  private:
72 };
73 
74 /// \cond
75 template <typename TriggerRegistrars>
76 PUP::able::PUP_ID Slabs<TriggerRegistrars>::my_PUP_ID = 0; // NOLINT
77 /// \endcond
78 } // namespace Triggers
79 
80 template <typename TriggerRegistrars>
81 struct Options::create_from_yaml<Triggers::Slabs<TriggerRegistrars>> {
82  template <typename Metavariables>
83  static Triggers::Slabs<TriggerRegistrars> create(const Option& options) {
86  }
87 };
CharmPupable.hpp
utility
Options.hpp
ParseOptions.hpp
Options::Option
Definition: Options.hpp:108
Registration::Registrar
A template for defining a registrar.
Definition: Registration.hpp:42
TimeSequence
Represents a sequence of times.
Definition: TimeSequence.hpp:31
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:34
Triggers::Slabs
Definition: Slabs.hpp:29
memory
TimeStepId
Definition: TimeStepId.hpp:25
TimeStepId.hpp
Options::Option::parse_as
T parse_as() const
Convert to an object of type T.
Definition: ParseOptions.hpp:75
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
std::unique_ptr
TMPL.hpp