SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/EventsAndTriggers - EventsAndTriggers.hpp Hit Total Coverage
Commit: a48770a280d0d66bc04cb5df30de1e3cc4985437 Lines: 1 12 8.3 %
Date: 2021-06-17 20:55:50
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             : #include <pup.h>  // IWYU pragma: keep
       8             : #include <unordered_map>
       9             : #include <vector>
      10             : 
      11             : #include "Options/Options.hpp"
      12             : #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
      13             : #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
      14             : 
      15             : /// \cond
      16             : namespace Parallel {
      17             : template <typename Metavariables>
      18             : class GlobalCache;
      19             : }  // namespace Parallel
      20             : namespace db {
      21             : template <typename TagsList>
      22             : class DataBox;
      23             : }  // namespace db
      24             : /// \endcond
      25             : 
      26             : /// \ingroup EventsAndTriggersGroup
      27             : /// Class that checks triggers and runs events
      28           1 : class EventsAndTriggers {
      29             :  public:
      30           0 :   using Storage = std::unordered_map<std::unique_ptr<Trigger>,
      31             :                                      std::vector<std::unique_ptr<Event>>>;
      32             : 
      33           0 :   EventsAndTriggers() = default;
      34           0 :   explicit EventsAndTriggers(Storage events_and_triggers) noexcept
      35             :       : events_and_triggers_(std::move(events_and_triggers)) {}
      36             : 
      37             :   template <typename DbTags, typename Metavariables, typename ArrayIndex,
      38             :             typename Component>
      39           0 :   void run_events(const db::DataBox<DbTags>& box,
      40             :                   Parallel::GlobalCache<Metavariables>& cache,
      41             :                   const ArrayIndex& array_index,
      42             :                   const Component* component) const noexcept {
      43             :     for (const auto& trigger_and_events : events_and_triggers_) {
      44             :       const auto& trigger = trigger_and_events.first;
      45             :       const auto& events = trigger_and_events.second;
      46             :       if (trigger->is_triggered(box)) {
      47             :         for (const auto& event : events) {
      48             :           event->run(box, cache, array_index, component);
      49             :         }
      50             :       }
      51             :     }
      52             :   }
      53             : 
      54             :   // clang-tidy: google-runtime-references
      55           0 :   void pup(PUP::er& p) noexcept {  // NOLINT
      56             :     p | events_and_triggers_;
      57             :   }
      58             : 
      59           0 :   const Storage& events_and_triggers() const noexcept {
      60             :     return events_and_triggers_;
      61             :   }
      62             : 
      63             :  private:
      64             :   // The unique pointer contents *must* be treated as const everywhere
      65             :   // in order to make the const global cache behave sanely.  They are
      66             :   // only non-const to make pup work.
      67           0 :   Storage events_and_triggers_;
      68             : };
      69             : 
      70             : template <>
      71           0 : struct Options::create_from_yaml<EventsAndTriggers> {
      72           0 :   using type = EventsAndTriggers;
      73             :   template <typename Metavariables>
      74           0 :   static type create(const Options::Option& options) {
      75             :     return type(options.parse_as<typename type::Storage, Metavariables>());
      76             :   }
      77             : };

Generated by: LCOV version 1.14