SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/EventsAndTriggers - LogicalTriggers.hpp Hit Total Coverage
Commit: d07bc7e978f0161d6eb259d687cd7878b5f9f6f0 Lines: 4 35 11.4 %
Date: 2020-09-24 02:51:00
Legend: Lines: hit not hit

          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             : 
       8             : #include "Options/Options.hpp"
       9             : #include "Parallel/CharmPupable.hpp"
      10             : #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
      11             : #include "Utilities/TMPL.hpp"
      12             : 
      13           0 : namespace Triggers {
      14             : /// \ingroup EventsAndTriggersGroup
      15             : /// Always triggers.  This trigger is automatically registered.
      16             : template <typename TriggerRegistrars = tmpl::list<>>
      17           1 : class Always : public Trigger<TriggerRegistrars> {
      18             :  public:
      19             :   /// \cond
      20             :   explicit Always(CkMigrateMessage* /*unused*/) noexcept {}
      21             :   using PUP::able::register_constructor;
      22             :   WRAPPED_PUPable_decl_template(Always);  // NOLINT
      23             :   /// \endcond
      24             : 
      25           0 :   using options = tmpl::list<>;
      26           0 :   static constexpr Options::String help = {"Always trigger."};
      27             : 
      28           0 :   Always() = default;
      29             : 
      30           0 :   using argument_tags = tmpl::list<>;
      31             : 
      32           0 :   bool operator()() const noexcept { return true; }
      33             : };
      34             : 
      35             : /// \ingroup EventsAndTriggersGroup
      36             : /// Negates another trigger.  This trigger is automatically registered.
      37             : template <typename TriggerRegistrars>
      38           1 : class Not : public Trigger<TriggerRegistrars> {
      39             :  public:
      40             :   /// \cond
      41             :   Not() = default;
      42             :   explicit Not(CkMigrateMessage* /*unused*/) noexcept {}
      43             :   using PUP::able::register_constructor;
      44             :   WRAPPED_PUPable_decl_template(Not);  // NOLINT
      45             :   /// \endcond
      46             : 
      47           0 :   static constexpr Options::String help = {"Negates another trigger."};
      48             : 
      49           0 :   explicit Not(
      50             :       std::unique_ptr<Trigger<TriggerRegistrars>> negated_trigger) noexcept
      51             :       : negated_trigger_(std::move(negated_trigger)) {}
      52             : 
      53           0 :   using argument_tags = tmpl::list<Tags::DataBox>;
      54             : 
      55             :   template <typename DbTags>
      56           0 :   bool operator()(const db::DataBox<DbTags>& box) noexcept {
      57             :     return not negated_trigger_->is_triggered(box);
      58             :   }
      59             : 
      60             :   // clang-tidy: google-runtime-references
      61           0 :   void pup(PUP::er& p) noexcept {  // NOLINT
      62             :     p | negated_trigger_;
      63             :   }
      64             : 
      65             :  private:
      66           0 :   std::unique_ptr<Trigger<TriggerRegistrars>> negated_trigger_;
      67             : };
      68             : 
      69             : /// \ingroup EventsAndTriggersGroup
      70             : /// Short-circuiting logical AND of other triggers.  This trigger is
      71             : /// automatically registered.
      72             : template <typename TriggerRegistrars>
      73           1 : class And : public Trigger<TriggerRegistrars> {
      74             :  public:
      75             :   /// \cond
      76             :   And() = default;
      77             :   explicit And(CkMigrateMessage* /*unused*/) noexcept {}
      78             :   using PUP::able::register_constructor;
      79             :   WRAPPED_PUPable_decl_template(And);  // NOLINT
      80             :   /// \endcond
      81             : 
      82           0 :   static constexpr Options::String help = {
      83             :       "Short-circuiting logical AND of other triggers."};
      84             : 
      85           0 :   explicit And(std::vector<std::unique_ptr<Trigger<TriggerRegistrars>>>
      86             :                    combined_triggers) noexcept
      87             :       : combined_triggers_(std::move(combined_triggers)) {}
      88             : 
      89           0 :   using argument_tags = tmpl::list<Tags::DataBox>;
      90             : 
      91             :   template <typename DbTags>
      92           0 :   bool operator()(const db::DataBox<DbTags>& box) noexcept {
      93             :     for (auto& trigger : combined_triggers_) {
      94             :       if (not trigger->is_triggered(box)) {
      95             :         return false;
      96             :       }
      97             :     }
      98             :     return true;
      99             :   }
     100             : 
     101             :   // clang-tidy: google-runtime-references
     102           0 :   void pup(PUP::er& p) noexcept {  // NOLINT
     103             :     p | combined_triggers_;
     104             :   }
     105             : 
     106             :  private:
     107           0 :   std::vector<std::unique_ptr<Trigger<TriggerRegistrars>>> combined_triggers_;
     108             : };
     109             : 
     110             : /// \ingroup EventsAndTriggersGroup
     111             : /// Short-circuiting logical OR of other triggers.  This trigger is
     112             : /// automatically registered.
     113             : template <typename TriggerRegistrars>
     114           1 : class Or : public Trigger<TriggerRegistrars> {
     115             :  public:
     116             :   /// \cond
     117             :   Or() = default;
     118             :   explicit Or(CkMigrateMessage* /*unused*/) noexcept {}
     119             :   using PUP::able::register_constructor;
     120             :   WRAPPED_PUPable_decl_template(Or);  // NOLINT
     121             :   /// \endcond
     122             : 
     123           0 :   static constexpr Options::String help = {
     124             :       "Short-circuiting logical OR of other triggers."};
     125             : 
     126           0 :   explicit Or(std::vector<std::unique_ptr<Trigger<TriggerRegistrars>>>
     127             :                   combined_triggers) noexcept
     128             :       : combined_triggers_(std::move(combined_triggers)) {}
     129             : 
     130           0 :   using argument_tags = tmpl::list<Tags::DataBox>;
     131             : 
     132             :   template <typename DbTags>
     133           0 :   bool operator()(const db::DataBox<DbTags>& box) noexcept {
     134             :     for (auto& trigger : combined_triggers_) {
     135             :       if (trigger->is_triggered(box)) {
     136             :         return true;
     137             :       }
     138             :     }
     139             :     return false;
     140             :   }
     141             : 
     142             :   // clang-tidy: google-runtime-references
     143           0 :   void pup(PUP::er& p) noexcept {  // NOLINT
     144             :     p | combined_triggers_;
     145             :   }
     146             : 
     147             :  private:
     148           0 :   std::vector<std::unique_ptr<Trigger<TriggerRegistrars>>> combined_triggers_;
     149             : };
     150             : 
     151             : /// \cond
     152             : template <typename TriggerRegistrars>
     153             : PUP::able::PUP_ID Always<TriggerRegistrars>::my_PUP_ID = 0;  // NOLINT
     154             : template <typename TriggerRegistrars>
     155             : PUP::able::PUP_ID Not<TriggerRegistrars>::my_PUP_ID = 0;  // NOLINT
     156             : template <typename TriggerRegistrars>
     157             : PUP::able::PUP_ID And<TriggerRegistrars>::my_PUP_ID = 0;  // NOLINT
     158             : template <typename TriggerRegistrars>
     159             : PUP::able::PUP_ID Or<TriggerRegistrars>::my_PUP_ID = 0;  // NOLINT
     160             : /// \endcond
     161             : }  // namespace Triggers
     162             : 
     163             : template <typename TriggerRegistrars>
     164           0 : struct Options::create_from_yaml<Triggers::Not<TriggerRegistrars>> {
     165             :   template <typename Metavariables>
     166           0 :   static Triggers::Not<TriggerRegistrars> create(
     167             :       const Options::Option& options) {
     168             :     return Triggers::Not<TriggerRegistrars>(
     169             :         options.parse_as<std::unique_ptr<Trigger<TriggerRegistrars>>>());
     170             :   }
     171             : };
     172             : 
     173             : template <typename TriggerRegistrars>
     174           0 : struct Options::create_from_yaml<Triggers::And<TriggerRegistrars>> {
     175             :   template <typename Metavariables>
     176           0 :   static Triggers::And<TriggerRegistrars> create(
     177             :       const Options::Option& options) {
     178             :     return Triggers::And<TriggerRegistrars>(
     179             :         options.parse_as<
     180             :             std::vector<std::unique_ptr<Trigger<TriggerRegistrars>>>>());
     181             :   }
     182             : };
     183             : 
     184             : template <typename TriggerRegistrars>
     185           0 : struct Options::create_from_yaml<Triggers::Or<TriggerRegistrars>> {
     186             :   template <typename Metavariables>
     187           0 :   static Triggers::Or<TriggerRegistrars> create(
     188             :       const Options::Option& options) {
     189             :     return Triggers::Or<TriggerRegistrars>(
     190             :         options.parse_as<
     191             :             std::vector<std::unique_ptr<Trigger<TriggerRegistrars>>>>());
     192             :   }
     193             : };

Generated by: LCOV version 1.14