SpecifiedSlabs.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstdint>
7 #include <pup.h>
8 #include <unordered_set>
9 #include <vector>
10 
11 #include "Evolution/EventsAndTriggers/Trigger.hpp"
12 #include "Options/Options.hpp"
14 #include "Time/TimeId.hpp"
15 #include "Utilities/Registration.hpp"
16 #include "Utilities/TMPL.hpp"
17 
18 /// \cond
19 namespace Tags {
20 struct TimeId;
21 } // namespace Tags
22 /// \endcond
23 
24 namespace Triggers {
25 template <typename TriggerRegistrars>
27 
28 namespace Registrars {
30 } // namespace Registrars
31 
32 /// \ingroup EventsAndTriggersGroup
33 /// \ingroup TimeGroup
34 /// Trigger at specified numbers of slabs after the simulation start.
35 template <typename TriggerRegistrars = tmpl::list<Registrars::SpecifiedSlabs>>
36 class SpecifiedSlabs : public Trigger<TriggerRegistrars> {
37  public:
38  /// \cond
39  SpecifiedSlabs() = default;
40  explicit SpecifiedSlabs(CkMigrateMessage* /*unused*/) noexcept {}
41  using PUP::able::register_constructor;
43  /// \endcond
44 
45  struct Slabs {
46  // No observing negative slabs. That's the initialization phase.
48  static constexpr OptionString help{
49  "List of slab numbers on which to trigger."};
50  };
51 
52  using options = tmpl::list<Slabs>;
53  static constexpr OptionString help{
54  "Trigger at specified numbers of slabs after the simulation start."};
55 
56  explicit SpecifiedSlabs(const std::vector<uint64_t>& slabs) noexcept
57  : slabs_(slabs.begin(), slabs.end()) {}
58 
59  using argument_tags = tmpl::list<Tags::TimeId>;
60 
61  bool operator()(const TimeId& time_id) const noexcept {
62  return slabs_.count(static_cast<uint64_t>(time_id.slab_number())) == 1;
63  }
64 
65  // clang-tidy: google-runtime-references
66  void pup(PUP::er& p) noexcept { // NOLINT
67  p | slabs_;
68  }
69 
70  private:
72 };
73 
74 /// \cond
75 template <typename TriggerRegistrars>
76 PUP::able::PUP_ID SpecifiedSlabs<TriggerRegistrars>::my_PUP_ID = 0; // NOLINT
77 /// \endcond
78 } // namespace Triggers
Definition: SpecifiedSlabs.hpp:45
A unique identifier for the temporal state of an integrated system.
Definition: TimeId.hpp:25
Defines classes and functions for making classes creatable from input files.
Defines macros to allow serialization of abstract template base classes.
Defines class TimeId.
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:26
A template for defining a registrar.
Definition: Registration.hpp:42
Definition: DataBoxTag.hpp:29
Trigger at specified numbers of slabs after the simulation start.
Definition: SpecifiedSlabs.hpp:26
Wraps the template metaprogramming library used (brigand)
Base class for checking whether to run an Event.
Definition: Trigger.hpp:35
Definition: LogicalTriggers.hpp:13