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 : 10 : #include "Options/Options.hpp" 11 : #include "Options/ParseOptions.hpp" 12 : #include "Options/String.hpp" 13 : #include "ParallelAlgorithms/EventsAndDenseTriggers/DenseTrigger.hpp" 14 : #include "Time/TimeSequence.hpp" 15 : #include "Utilities/Serialization/CharmPupable.hpp" 16 : #include "Utilities/TMPL.hpp" 17 : 18 : /// \cond 19 : class TimeStepId; 20 : namespace Parallel { 21 : template <typename Metavariables> 22 : class GlobalCache; 23 : } // namespace Parallel 24 : namespace Tags { 25 : struct Time; 26 : struct TimeStepId; 27 : } // namespace Tags 28 : /// \endcond 29 : 30 : namespace DenseTriggers { 31 : /// \ingroup EventsAndTriggersGroup 32 : /// \ingroup TimeGroup 33 : /// Trigger at specified times. 34 1 : class Times : public DenseTrigger { 35 : public: 36 : /// \cond 37 : Times() = default; 38 : explicit Times(CkMigrateMessage* const msg) : DenseTrigger(msg) {} 39 : using PUP::able::register_constructor; 40 : WRAPPED_PUPable_decl_template(Times); // NOLINT 41 : /// \endcond 42 : 43 0 : static constexpr Options::String help{"Trigger at specified times."}; 44 : 45 0 : explicit Times(std::unique_ptr<TimeSequence<double>> times); 46 : 47 0 : using is_triggered_return_tags = tmpl::list<>; 48 0 : using is_triggered_argument_tags = tmpl::list<Tags::Time>; 49 : 50 : template <typename Metavariables, typename ArrayIndex, typename Component> 51 0 : std::optional<bool> is_triggered( 52 : Parallel::GlobalCache<Metavariables>& /*cache*/, 53 : const ArrayIndex& /*array_index*/, const Component* /*component*/, 54 : const double time) const { 55 : return is_triggered_impl(time); 56 : } 57 : 58 0 : using next_check_time_return_tags = tmpl::list<>; 59 0 : using next_check_time_argument_tags = 60 : tmpl::list<Tags::TimeStepId, Tags::Time>; 61 : 62 : template <typename Metavariables, typename ArrayIndex, typename Component> 63 0 : std::optional<double> next_check_time( 64 : Parallel::GlobalCache<Metavariables>& /*cache*/, 65 : const ArrayIndex& /*array_index*/, const Component* /*component*/, 66 : const TimeStepId& time_step_id, const double time) const { 67 : return next_check_time_impl(time_step_id, time); 68 : } 69 : 70 : // NOLINTNEXTLINE(google-runtime-references) 71 0 : void pup(PUP::er& p) override; 72 : 73 : private: 74 0 : std::optional<bool> is_triggered_impl(const double time) const; 75 : 76 0 : std::optional<double> next_check_time_impl(const TimeStepId& time_step_id, 77 : const double time) const; 78 : 79 0 : std::unique_ptr<TimeSequence<double>> times_{}; 80 : }; 81 : } // namespace DenseTriggers 82 : 83 : template <> 84 0 : struct Options::create_from_yaml<DenseTriggers::Times> { 85 : template <typename Metavariables> 86 0 : static DenseTriggers::Times create(const Option& options) { 87 : return DenseTriggers::Times( 88 : options 89 : .parse_as<std::unique_ptr<TimeSequence<double>>, Metavariables>()); 90 : } 91 : };