Filter.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <memory>
7 #include <pup.h>
8 #include <string>
9 
10 #include "Evolution/EventsAndDenseTriggers/DenseTrigger.hpp"
11 #include "Options/Options.hpp"
13 #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 /// \cond
17 namespace Tags {
18 struct DataBox;
19 } // namespace Tags
20 namespace db {
21 template <typename TagsList> class DataBox;
22 } // namespace db
23 /// \endcond
24 
25 namespace DenseTriggers {
26 /// \ingroup EventsAndTriggersGroup
27 /// %Filter activations of a dense trigger using a non-dense trigger.
28 ///
29 /// For example, to trigger every 10 starting at 100, one could use
30 ///
31 /// \snippet Test_Filter.cpp example
32 class Filter : public DenseTrigger {
33  public:
34  /// \cond
35  Filter() = default;
36  explicit Filter(CkMigrateMessage* const msg) noexcept : DenseTrigger(msg) {}
37  using PUP::able::register_constructor;
39  /// \endcond
40 
41  struct TriggerOption {
42  static std::string name() noexcept { return "Trigger"; }
44  static constexpr Options::String help = "Dense trigger to filter";
45  };
46 
47  struct FilterOption {
48  static std::string name() noexcept { return "Filter"; }
50  static constexpr Options::String help = "Non-dense trigger to filter with";
51  };
52 
53  using options = tmpl::list<TriggerOption, FilterOption>;
54  static constexpr Options::String help =
55  "Filter activations of a dense trigger using a non-dense trigger.";
56 
57  explicit Filter(std::unique_ptr<DenseTrigger> trigger,
58  std::unique_ptr<Trigger> filter) noexcept;
59 
60  using is_triggered_argument_tags = tmpl::list<Tags::DataBox>;
61 
62  template <typename DbTags>
63  Result is_triggered(const db::DataBox<DbTags>& box) const noexcept {
64  auto result = trigger_->is_triggered(box);
65  if (not filter_->is_triggered(box)) {
66  result.is_triggered = false;
67  }
68  return result;
69  }
70 
71  using is_ready_argument_tags = tmpl::list<Tags::DataBox>;
72 
73  template <typename DbTags>
74  bool is_ready(const db::DataBox<DbTags>& box) const noexcept {
75  return trigger_->is_ready(box);
76  }
77 
78  // NOLINTNEXTLINE(google-runtime-references)
79  void pup(PUP::er& p) noexcept override;
80 
81  private:
83  std::unique_ptr<Trigger> filter_{};
84 };
85 } // namespace DenseTriggers
std::string
CharmPupable.hpp
Options.hpp
DenseTriggers::Filter::TriggerOption
Definition: Filter.hpp:41
DenseTrigger
Definition: DenseTrigger.hpp:27
WRAPPED_PUPable_decl_template
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
DenseTriggers::Filter::FilterOption
Definition: Filter.hpp:47
memory
DenseTrigger::Result
Result type for the is_triggered method.
Definition: DenseTrigger.hpp:34
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
DenseTriggers::Filter
Definition: Filter.hpp:32
std::unique_ptr< DenseTrigger >
TMPL.hpp
db
Namespace for DataBox related things.
Definition: DataBox.hpp:44
string