SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/EventsAndTriggers - EventsAndTriggers.hpp Hit Total Coverage
Commit: d07bc7e978f0161d6eb259d687cd7878b5f9f6f0 Lines: 1 14 7.1 %
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             : #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"  // IWYU pragma: keep // for option parsing
      13             : #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"  // IWYU pragma: keep // for option parsing
      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             : template <typename EventRegistrars, typename TriggerRegistrars>
      29           1 : class EventsAndTriggers {
      30             :  public:
      31           0 :   using event_type = Event<EventRegistrars>;
      32           0 :   using trigger_type = Trigger<TriggerRegistrars>;
      33           0 :   using Storage = std::unordered_map<std::unique_ptr<trigger_type>,
      34             :                                      std::vector<std::unique_ptr<event_type>>>;
      35             : 
      36           0 :   EventsAndTriggers() = default;
      37           0 :   explicit EventsAndTriggers(Storage events_and_triggers) noexcept
      38             :       : events_and_triggers_(std::move(events_and_triggers)) {}
      39             : 
      40             :   template <typename DbTags, typename Metavariables, typename ArrayIndex,
      41             :             typename Component>
      42           0 :   void run_events(const db::DataBox<DbTags>& box,
      43             :                   Parallel::GlobalCache<Metavariables>& cache,
      44             :                   const ArrayIndex& array_index,
      45             :                   const Component* component) const noexcept {
      46             :     for (const auto& trigger_and_events : events_and_triggers_) {
      47             :       const auto& trigger = trigger_and_events.first;
      48             :       const auto& events = trigger_and_events.second;
      49             :       if (trigger->is_triggered(box)) {
      50             :         for (const auto& event : events) {
      51             :           event->run(box, cache, array_index, component);
      52             :         }
      53             :       }
      54             :     }
      55             :   }
      56             : 
      57             :   // clang-tidy: google-runtime-references
      58           0 :   void pup(PUP::er& p) noexcept {  // NOLINT
      59             :     p | events_and_triggers_;
      60             :   }
      61             : 
      62           0 :   const Storage& events_and_triggers() const noexcept {
      63             :     return events_and_triggers_;
      64             :   }
      65             : 
      66             :  private:
      67             :   // The unique pointer contents *must* be treated as const everywhere
      68             :   // in order to make the const global cache behave sanely.  They are
      69             :   // only non-const to make pup work.
      70           0 :   Storage events_and_triggers_;
      71             : };
      72             : 
      73             : template <typename EventRegistrars, typename TriggerRegistrars>
      74             : struct Options::create_from_yaml<
      75           0 :     EventsAndTriggers<EventRegistrars, TriggerRegistrars>> {
      76           0 :   using type = EventsAndTriggers<EventRegistrars, TriggerRegistrars>;
      77             :   template <typename Metavariables>
      78           0 :   static type create(const Options::Option& options) {
      79             :     return type(options.parse_as<typename type::Storage>());
      80             :   }
      81             : };

Generated by: LCOV version 1.14