Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <memory> 7 : #include <optional> 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 Time; 22 : } // namespace Tags 23 : /// \endcond 24 : 25 : namespace Triggers { 26 : /// \ingroup EventsAndTriggersGroup 27 : /// \ingroup TimeGroup 28 : /// Trigger at particular times. 29 : /// 30 : /// \warning This trigger will only fire if it is actually checked at 31 : /// the times specified. The StepToTimes StepChooser can be useful 32 : /// for this. 33 1 : class Times : public Trigger { 34 : public: 35 : /// \cond 36 : Times() = default; 37 : explicit Times(CkMigrateMessage* /*unused*/) {} 38 : using PUP::able::register_constructor; 39 : WRAPPED_PUPable_decl_template(Times); // NOLINT 40 : /// \endcond 41 : 42 0 : static constexpr Options::String help{"Trigger at particular times."}; 43 : 44 0 : explicit Times(std::unique_ptr<TimeSequence<double>> times) 45 : : times_(std::move(times)) {} 46 : 47 0 : using argument_tags = tmpl::list<Tags::Time>; 48 : 49 0 : bool operator()(const double now) const { 50 : return times_->times_near(now)[1] == std::optional(now); 51 : } 52 : 53 : // NOLINTNEXTLINE(google-runtime-references) 54 0 : void pup(PUP::er& p) override { p | times_; } 55 : 56 : private: 57 0 : std::unique_ptr<TimeSequence<double>> times_; 58 : }; 59 : } // namespace Triggers 60 : 61 : template <> 62 0 : struct Options::create_from_yaml<Triggers::Times> { 63 : template <typename Metavariables> 64 0 : static Triggers::Times create(const Option& options) { 65 : return Triggers::Times( 66 : options 67 : .parse_as<std::unique_ptr<TimeSequence<double>>, Metavariables>()); 68 : } 69 : };