DenseTrigger.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <limits>
7 #include <pup.h>
8 #include <type_traits>
9 
12 #include "Utilities/FakeVirtual.hpp"
13 #include "Utilities/Registration.hpp"
14 
15 /// \ingroup EventsAndDenseTriggersGroup
16 namespace DenseTriggers {
17 /// Registrars for DenseTriggers
18 namespace Registrars {}
19 } // namespace DenseTriggers
20 
21 /// \ingroup EventsAndTriggersGroup
22 /// Base class for checking whether to run an Event at arbitrary times.
23 ///
24 /// The DataBox passed to the member functions will have
25 /// `::Tags::Time`, and therefore any compute tags depending on that
26 /// value, set to the time to be tested. Any discrete properties of
27 /// steps or slabs, such as the step size, may have the values from
28 /// times off by one step. The evolved variables will be in an
29 /// unspecified state.
30 template <typename DenseTriggerRegistrars>
31 class DenseTrigger : public PUP::able {
32  public:
33  /// %Result type for the `is_triggered` method.
34  ///
35  /// This indicates whether the trigger has fired and the next time
36  /// the trigger should be checked. The consumer is not required to
37  /// wait until the requested time before testing the trigger again.
38  struct Result {
39  bool is_triggered;
40  double next_check;
41  };
42 
43  protected:
44  /// \cond
45  DenseTrigger() = default;
46  DenseTrigger(const DenseTrigger&) = default;
47  DenseTrigger(DenseTrigger&&) = default;
48  DenseTrigger& operator=(const DenseTrigger&) = default;
49  DenseTrigger& operator=(DenseTrigger&&) = default;
50  /// \endcond
51 
52  public:
53  ~DenseTrigger() override = default;
54 
55  /// \cond
56  explicit DenseTrigger(CkMigrateMessage* const msg) noexcept
57  : PUP::able(msg) {}
59  /// \endcond
60 
61  using creatable_classes = Registration::registrants<DenseTriggerRegistrars>;
62 
63  /// Check whether the trigger fires.
64  template <typename DbTags>
65  Result is_triggered(const db::DataBox<DbTags>& box) const noexcept {
66  return call_with_dynamic_type<Result, creatable_classes>(
67  this, [&box](auto* const trigger) noexcept {
68  using TriggerType = std::decay_t<decltype(*trigger)>;
69  return db::apply<typename TriggerType::is_triggered_argument_tags>(
70  [&trigger](const auto&... args) noexcept {
71  return trigger->is_triggered(args...);
72  },
73  box);
74  });
75  }
76 
77  /// Check whether all data required to evaluate the trigger is
78  /// available. The trigger is not responsible for checking whether
79  /// dense output of the evolved variables is possible, but may need
80  /// to check things such as the availability of FunctionOfTime data.
81  template <typename DbTags>
82  bool is_ready(const db::DataBox<DbTags>& box) const noexcept {
83  return call_with_dynamic_type<bool, creatable_classes>(
84  this, [&box](auto* const trigger) noexcept {
85  using TriggerType = std::decay_t<decltype(*trigger)>;
86  return db::apply<typename TriggerType::is_ready_argument_tags>(
87  [&trigger](const auto&... args) noexcept {
88  return trigger->is_ready(args...);
89  },
90  box);
91  });
92  }
93 };
CharmPupable.hpp
DenseTrigger
Definition: DenseTrigger.hpp:31
DataBox.hpp
WRAPPED_PUPable_abstract
#define WRAPPED_PUPable_abstract(className)
Wraps the Charm++ macro, see the Charm++ documentation.
Definition: CharmPupable.hpp:41
DenseTrigger::Result
Result type for the is_triggered method.
Definition: DenseTrigger.hpp:38
std::decay_t
DenseTrigger::is_triggered
Result is_triggered(const db::DataBox< DbTags > &box) const noexcept
Check whether the trigger fires.
Definition: DenseTrigger.hpp:65
limits
DenseTrigger::is_ready
bool is_ready(const db::DataBox< DbTags > &box) const noexcept
Check whether all data required to evaluate the trigger is available. The trigger is not responsible ...
Definition: DenseTrigger.hpp:82
Registration::registrants
tmpl::transform< tmpl::remove_duplicates< RegistrarList >, detail::registrant< tmpl::pin< tmpl::remove_duplicates< RegistrarList > >, tmpl::_1 > > registrants
Transform a list of registrars into the list of associated registrants. This is usually used to defin...
Definition: Registration.hpp:65
type_traits