Line data Source code
1 0 : // 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/ParseOptions.hpp"
13 : #include "Options/String.hpp"
14 : #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
15 : #include "Time/TimeSequence.hpp"
16 : #include "Utilities/Serialization/CharmPupable.hpp"
17 : #include "Utilities/TMPL.hpp"
18 :
19 : /// \cond
20 : namespace Tags {
21 : struct StepNumberWithinSlab;
22 : } // namespace Tags
23 : /// \endcond
24 :
25 : namespace Triggers {
26 : /// \ingroup EventsAndTriggersGroup
27 : /// \ingroup TimeGroup
28 : /// Trigger at specified steps within each slab.
29 1 : class StepsWithinSlab : public Trigger {
30 : public:
31 : /// \cond
32 : StepsWithinSlab() = default;
33 : explicit StepsWithinSlab(CkMigrateMessage* /*unused*/) {}
34 : using PUP::able::register_constructor;
35 : WRAPPED_PUPable_decl_template(StepsWithinSlab); // NOLINT
36 : /// \endcond
37 :
38 0 : static constexpr Options::String help{
39 : "Trigger at specified steps within each slab."};
40 :
41 0 : explicit StepsWithinSlab(
42 : std::unique_ptr<TimeSequence<uint64_t>> steps_within_slab)
43 : : steps_within_slab_(std::move(steps_within_slab)) {}
44 :
45 0 : using argument_tags = tmpl::list<Tags::StepNumberWithinSlab>;
46 :
47 0 : bool operator()(const uint64_t step_within_slab) const {
48 : return steps_within_slab_->times_near(step_within_slab)[1] ==
49 : step_within_slab;
50 : }
51 :
52 : // NOLINTNEXTLINE(google-runtime-references)
53 0 : void pup(PUP::er& p) override { p | steps_within_slab_; }
54 :
55 : private:
56 0 : std::unique_ptr<TimeSequence<uint64_t>> steps_within_slab_{};
57 : };
58 : } // namespace Triggers
59 :
60 : template <>
61 0 : struct Options::create_from_yaml<Triggers::StepsWithinSlab> {
62 : template <typename Metavariables>
63 0 : static Triggers::StepsWithinSlab create(const Option& options) {
64 : return Triggers::StepsWithinSlab(
65 : options.parse_as<std::unique_ptr<TimeSequence<uint64_t>>,
66 : Metavariables>());
67 : }
68 : };
|