SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/ApparentHorizonFinder/Callbacks - SendDependencyToObserverWriter.hpp Hit Total Coverage
Commit: 1f2210958b4f38fdc0400907ee7c6d5af5111418 Lines: 2 7 28.6 %
Date: 2025-12-05 05:03:31
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 <type_traits>
       7             : 
       8             : #include "DataStructures/DataBox/DataBox.hpp"
       9             : #include "DataStructures/LinkedMessageId.hpp"
      10             : #include "IO/Logging/Verbosity.hpp"
      11             : #include "IO/Observer/ObserverComponent.hpp"
      12             : #include "IO/Observer/VolumeActions.hpp"
      13             : #include "Parallel/GlobalCache.hpp"
      14             : #include "Parallel/Invoke.hpp"
      15             : #include "Parallel/Printf/Printf.hpp"
      16             : #include "ParallelAlgorithms/ApparentHorizonFinder/FastFlow.hpp"
      17             : #include "ParallelAlgorithms/ApparentHorizonFinder/InterpolationTarget.hpp"
      18             : #include "ParallelAlgorithms/ApparentHorizonFinder/Protocols/Callback.hpp"
      19             : #include "ParallelAlgorithms/ApparentHorizonFinder/Tags.hpp"
      20             : #include "ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp"
      21             : #include "ParallelAlgorithms/Interpolation/Tags.hpp"
      22             : #include "Utilities/PrettyType.hpp"
      23             : #include "Utilities/ProtocolHelpers.hpp"
      24             : 
      25             : /// \cond
      26             : namespace logging::Tags {
      27             : template <typename OptionsGroup>
      28             : struct Verbosity;
      29             : }  // namespace logging::Tags
      30             : /// \endcond
      31             : 
      32             : namespace intrp::callbacks {
      33             : /*!
      34             :  * \brief Post horizon find callback that will send a message to the
      35             :  * ObserverWriter if we have a dependency telling it to write the volume data to
      36             :  * disk or not depending on the \p WriteVolumeData template bool.
      37             :  *
      38             :  * \details Can be used whether the horizon finder fails or not. The
      39             :  * `failure_reason` is not used when the horizon find fails.
      40             :  */
      41             : template <bool WriteVolumeData, typename InterpolationTargetTag>
      42           1 : struct SendDependencyToObserverWriter {
      43             :   // Callback for when horizon find succeeds
      44             :   template <typename DbTags, typename Metavariables, typename TemporalId>
      45           0 :   static void apply(const db::DataBox<DbTags>& box,
      46             :                     Parallel::GlobalCache<Metavariables>& cache,
      47             :                     const TemporalId& temporal_id) {
      48             :     static_assert(WriteVolumeData);
      49             :     apply_impl<InterpolationTargetTag>(box, cache, temporal_id);
      50             :   }
      51             : 
      52             :   // Callback for when horizon find fails
      53             :   template <typename LocalInterpolationTargetTag, typename DbTags,
      54             :             typename Metavariables, typename TemporalId>
      55           0 :   static void apply(const db::DataBox<DbTags>& box,
      56             :                     Parallel::GlobalCache<Metavariables>& cache,
      57             :                     const TemporalId& temporal_id,
      58             :                     const FastFlow::Status /*failure_reason*/) {
      59             :     static_assert(not WriteVolumeData);
      60             :     apply_impl<LocalInterpolationTargetTag>(box, cache, temporal_id);
      61             :   }
      62             : 
      63             :  private:
      64             :   template <typename LocalInterpolationTargetTag, typename DbTags,
      65             :             typename Metavariables, typename TemporalId>
      66           0 :   static void apply_impl(const db::DataBox<DbTags>& box,
      67             :                          Parallel::GlobalCache<Metavariables>& cache,
      68             :                          const TemporalId& temporal_id) {
      69             :     static_assert(
      70             :         std::is_same_v<InterpolationTargetTag, LocalInterpolationTargetTag>);
      71             : 
      72             :     const auto& dependencies =
      73             :         db::get<intrp::Tags::Dependencies<TemporalId>>(box);
      74             : 
      75             :     ASSERT(dependencies.contains(temporal_id),
      76             :            "TemporalId " << temporal_id
      77             :                          << " not found in dependencies: " << dependencies);
      78             : 
      79             :     const auto& dependency = dependencies.at(temporal_id);
      80             : 
      81             :     if (dependency.has_value()) {
      82             :       const auto& verbosity =
      83             :           db::get<logging::Tags::Verbosity<InterpolationTargetTag>>(box);
      84             : 
      85             :       auto& observer_writer_proxy = Parallel::get_parallel_component<
      86             :           observers::ObserverWriter<Metavariables>>(cache);
      87             : 
      88             :       Parallel::threaded_action<
      89             :           observers::ThreadedActions::ContributeDependency>(
      90             :           observer_writer_proxy,
      91             :           InterpolationTarget_detail::get_temporal_id_value(temporal_id),
      92             :           pretty_type::name<InterpolationTargetTag>(), dependency.value(),
      93             :           WriteVolumeData);
      94             : 
      95             :       if (verbosity >= ::Verbosity::Verbose) {
      96             :         Parallel::printf(
      97             :             "Remark: We are%s writing volume data for horizon finder %s",
      98             :             WriteVolumeData ? "" : " not",
      99             :             pretty_type::name<InterpolationTargetTag>());
     100             :       }
     101             :     }
     102             :   }
     103             : };
     104             : }  // namespace intrp::callbacks
     105             : 
     106             : namespace ah::callbacks {
     107             : /*!
     108             :  * \brief A `ah::protocols::Callback` that will send a message to the
     109             :  * ObserverWriter if we have a dependency using the
     110             :  * `observers::ThreadedActions::ContributeDependency` action.
     111             :  *
     112             :  * \details If we have a dependency, the template bool \p WriteVolumeData
     113             :  * determines if the message sent to the ObserverWriter says to write the volume
     114             :  * data to disk or not.
     115             :  */
     116             : template <typename HorizonMetavars, bool WriteVolumeData>
     117           1 : struct SendDependencyToObserverWriter
     118             :     : tt::ConformsTo<ah::protocols::Callback> {
     119             :   // Callback for when horizon find succeeds
     120             :   template <typename DbTags, typename Metavariables>
     121           0 :   static void apply(const db::DataBox<DbTags>& box,
     122             :                     Parallel::GlobalCache<Metavariables>& cache,
     123             :                     const FastFlow::Status /*status*/) {
     124             :     const auto& time = db::get<ah::Tags::CurrentTime>(box).value();
     125             :     const auto& dependency = db::get<ah::Tags::Dependency>(box);
     126             : 
     127             :     if (dependency.has_value()) {
     128             :       const auto& verbosity = db::get<ah::Tags::Verbosity>(box);
     129             : 
     130             :       auto& observer_writer_proxy = Parallel::get_parallel_component<
     131             :           observers::ObserverWriter<Metavariables>>(cache);
     132             : 
     133             :       Parallel::threaded_action<
     134             :           observers::ThreadedActions::ContributeDependency>(
     135             :           observer_writer_proxy, time.id, pretty_type::name<HorizonMetavars>(),
     136             :           dependency.value(), WriteVolumeData);
     137             : 
     138             :       if (verbosity >= ::Verbosity::Verbose) {
     139             :         Parallel::printf(
     140             :             "Remark: We are%s writing volume data for horizon finder %s\n",
     141             :             WriteVolumeData ? "" : " not",
     142             :             pretty_type::name<HorizonMetavars>());
     143             :       }
     144             :     }
     145             :   }
     146             : };
     147             : }  // namespace ah::callbacks

Generated by: LCOV version 1.14