SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/EventsAndTriggers - Event.hpp Hit Total Coverage
Commit: 5b6dac11263b5fb9107cb6ea064c64c61b65a417 Lines: 2 11 18.2 %
Date: 2024-04-19 22:56:45
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 <limits>
       7             : 
       8             : #include "DataStructures/DataBox/ObservationBox.hpp"
       9             : #include "Parallel/GlobalCache.hpp"
      10             : #include "Parallel/Tags/Metavariables.hpp"
      11             : #include "Utilities/CallWithDynamicType.hpp"
      12             : #include "Utilities/Serialization/CharmPupable.hpp"
      13             : #include "Utilities/TMPL.hpp"
      14             : 
      15             : /// \ingroup EventsAndTriggersGroup
      16             : namespace Events {}
      17             : 
      18             : /// \ingroup EventsAndTriggersGroup
      19             : /// Base class for something that can happen during a simulation (such
      20             : /// as an observation).
      21             : ///
      22             : /// Derived events must have a `compute_tags_for_observation_box` that is a
      23             : /// `tmpl::list` of simple or compute tags. Simple tags are assumed to already
      24             : /// be in the `DataBox`. Evolved variables, for example, would be listed as
      25             : /// simple tags. The compute tags are used to compute additional quantities that
      26             : /// may be observed. For example, in the scalar wave system the 1- and 2-index
      27             : /// constraints would be added as compute tags, as well as anything they depend
      28             : /// on that's not already in the `DataBox`.
      29           1 : class Event : public PUP::able {
      30             :  protected:
      31             :   /// \cond
      32             :   Event() = default;
      33             :   Event(const Event&) = default;
      34             :   Event(Event&&) = default;
      35             :   Event& operator=(const Event&) = default;
      36             :   Event& operator=(Event&&) = default;
      37             :   /// \endcond
      38             : 
      39             :  public:
      40           0 :   ~Event() override = default;
      41           0 :   explicit Event(CkMigrateMessage* msg) : PUP::able(msg) {}
      42             : 
      43           0 :   WRAPPED_PUPable_abstract(Event);  // NOLINT
      44             : 
      45           0 :   struct ObservationValue {
      46           0 :     std::string name{};
      47           0 :     double value = std::numeric_limits<double>::signaling_NaN();
      48             :   };
      49             : 
      50             :   template <typename ComputeTagsList, typename DataBoxType,
      51             :             typename Metavariables, typename ArrayIndex,
      52             :             typename ComponentPointer>
      53           0 :   void run(
      54             :       const gsl::not_null<ObservationBox<ComputeTagsList, DataBoxType>*> box,
      55             :       Parallel::GlobalCache<Metavariables>& cache,
      56             :       const ArrayIndex& array_index, const ComponentPointer /*meta*/,
      57             :       const ObservationValue& observation_value) const {
      58             :     using factory_classes =
      59             :         typename std::decay_t<Metavariables>::factory_creation::factory_classes;
      60             :     call_with_dynamic_type<void, tmpl::at<factory_classes, Event>>(
      61             :         this, [&](auto* const event) {
      62             :           mutate_apply(*event, box, cache, array_index, ComponentPointer{},
      63             :                        observation_value);
      64             :         });
      65             :   }
      66             : 
      67             :   template <typename DbTags, typename Metavariables, typename ArrayIndex,
      68             :             typename ComponentPointer>
      69           0 :   bool is_ready(const db::DataBox<DbTags>& box,
      70             :                 Parallel::GlobalCache<Metavariables>& cache,
      71             :                 const ArrayIndex& array_index,
      72             :                 const ComponentPointer /*meta*/) const {
      73             :     using factory_classes =
      74             :         typename std::decay_t<decltype(db::get<Parallel::Tags::Metavariables>(
      75             :             box))>::factory_creation::factory_classes;
      76             :     return call_with_dynamic_type<bool, tmpl::at<factory_classes, Event>>(
      77             :         this, [&box, &cache, &array_index](auto* const event) {
      78             :           return db::apply<
      79             :               typename std::decay_t<decltype(*event)>::is_ready_argument_tags>(
      80             :               [&event, &cache, &array_index](const auto&... args) {
      81             :                 return event->is_ready(args..., cache, array_index,
      82             :                                        ComponentPointer{});
      83             :               },
      84             :               box);
      85             :         });
      86             :   }
      87             : 
      88             :   /// Whether the event uses anything depending on the
      89             :   /// evolved_variables.  If this returns false, anything depending on
      90             :   /// the evolved variables may have an incorrect value when the event
      91             :   /// is run.
      92           1 :   virtual bool needs_evolved_variables() const = 0;
      93             : };

Generated by: LCOV version 1.14