SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/ApparentHorizonFinder/Events - FindCommonHorizon.hpp Hit Total Coverage
Commit: 3ffcbc8ecf43797401b60bcca17d6040ee06f013 Lines: 4 44 9.1 %
Date: 2026-03-03 02:01:44
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 <cstddef>
       7             : #include <optional>
       8             : #include <pup.h>
       9             : #include <string>
      10             : #include <type_traits>
      11             : 
      12             : #include "DataStructures/DataVector.hpp"
      13             : #include "Options/String.hpp"
      14             : #include "Parallel/ArrayCollection/IsDgElementCollection.hpp"
      15             : #include "Parallel/ArrayCollection/PerformAlgorithmOnElement.hpp"
      16             : #include "Parallel/ArrayCollection/Tags/ElementLocations.hpp"
      17             : #include "Parallel/GlobalCache.hpp"
      18             : #include "ParallelAlgorithms/Actions/GetItemFromDistributedObject.hpp"
      19             : #include "ParallelAlgorithms/ApparentHorizonFinder/Events/FindApparentHorizon.hpp"
      20             : #include "ParallelAlgorithms/Events/ObserveFields.hpp"
      21             : #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
      22             : #include "ParallelAlgorithms/Interpolation/Events/GetComputeItemsOnSource.hpp"
      23             : #include "ParallelAlgorithms/Interpolation/Events/Interpolate.hpp"
      24             : #include "ParallelAlgorithms/Interpolation/Interpolate.hpp"
      25             : #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
      26             : #include "Utilities/PrettyType.hpp"
      27             : #include "Utilities/Serialization/CharmPupable.hpp"
      28             : #include "Utilities/TMPL.hpp"
      29             : 
      30             : /// \cond
      31             : template <size_t Dim>
      32             : class Mesh;
      33             : template <size_t VolumeDim>
      34             : class ElementId;
      35             : namespace Parallel {
      36             : template <typename Metavariables>
      37             : class GlobalCache;
      38             : }  // namespace Parallel
      39             : namespace Tags {
      40             : struct Time;
      41             : }  // namespace Tags
      42             : namespace Events::Tags {
      43             : template <size_t Dim>
      44             : struct ObserverMesh;
      45             : }  // namespace Events::Tags
      46             : /// \endcond
      47             : 
      48           0 : namespace intrp::Events {
      49             : /*!
      50             :  * \brief Event that combines the `intrp::Events::interpolate` event with
      51             :  * `dg::Events::ObserveFields` specifically for common horizon finding.
      52             :  *
      53             :  * \details This is just a thin wrapper around each event and doesn't do
      54             :  * anything extra.
      55             :  */
      56             : template <size_t VolumeDim, typename InterpolationTargetTag,
      57             :           typename InterpolatorSourceVarTags, typename Tensors,
      58             :           typename NonTensorComputeTagsList = tmpl::list<>>
      59           1 : class FindCommonHorizon;
      60             : 
      61             : template <size_t VolumeDim, typename InterpolationTargetTag,
      62             :           typename... InterpolatorSourceVarTags, typename... Tensors,
      63             :           typename... NonTensorComputeTags>
      64           0 : class FindCommonHorizon<
      65             :     VolumeDim, InterpolationTargetTag, tmpl::list<InterpolatorSourceVarTags...>,
      66             :     tmpl::list<Tensors...>, tmpl::list<NonTensorComputeTags...>>
      67             :     : public Event {
      68           0 :   using ObserveFieldsEvent =
      69             :       dg::Events::ObserveFields<VolumeDim, tmpl::list<Tensors...>,
      70             :                                 tmpl::list<NonTensorComputeTags...>>;
      71           0 :   using InterpolateEvent =
      72             :       intrp::Events::Interpolate<VolumeDim, InterpolationTargetTag,
      73             :                                  tmpl::list<InterpolatorSourceVarTags...>>;
      74             : 
      75             :  public:
      76             :   /// \cond
      77             :   explicit FindCommonHorizon(CkMigrateMessage* /*unused*/) {}
      78             :   using PUP::able::register_constructor;
      79             :   WRAPPED_PUPable_decl_template(FindCommonHorizon);  // NOLINT
      80             :   /// \endcond
      81             : 
      82           0 :   using options = tmpl::append<typename ObserveFieldsEvent::options,
      83             :                                typename InterpolateEvent::options>;
      84           0 :   static constexpr Options::String help =
      85             :       "Starts a common horizon find and sends the evolved variables to be "
      86             :       "written to disk.";
      87             : 
      88           0 :   static std::string name() {
      89             :     return pretty_type::name<InterpolationTargetTag>();
      90             :   }
      91             : 
      92           0 :   FindCommonHorizon() = default;
      93             : 
      94           0 :   FindCommonHorizon(
      95             :       const std::string& subfile_name,
      96             :       FloatingPointType coordinates_floating_point_type,
      97             :       const std::vector<FloatingPointType>& floating_point_types,
      98             :       const std::vector<std::string>& variables_to_observe,
      99             :       std::optional<std::vector<std::string>> active_block_or_block_groups = {},
     100             :       std::optional<Mesh<VolumeDim>> interpolation_mesh = {},
     101             :       std::optional<Mesh<VolumeDim>> projection_mesh = {},
     102             :       const Options::Context& context = {})
     103             :       : observe_fields_event_(subfile_name, coordinates_floating_point_type,
     104             :                               floating_point_types, variables_to_observe,
     105             :                               active_block_or_block_groups, interpolation_mesh,
     106             :                               projection_mesh, std::nullopt, context),
     107             :         interpolate_event_(subfile_name) {}
     108             : 
     109           0 :   using compute_tags_for_observation_box = tmpl::remove_duplicates<tmpl::append<
     110             :       typename ObserveFieldsEvent::compute_tags_for_observation_box,
     111             :       typename InterpolateEvent::compute_tags_for_observation_box>>;
     112             : 
     113           0 :   using return_tags = tmpl::list<>;
     114           0 :   using argument_tags = tmpl::list<::Tags::ObservationBox,
     115             :                                    ::Events::Tags::ObserverMesh<VolumeDim>>;
     116             : 
     117             :   template <typename DataBoxType, typename ComputeTagsList,
     118             :             typename Metavariables, typename ParallelComponent>
     119           0 :   void operator()(const ObservationBox<DataBoxType, ComputeTagsList>& box,
     120             :                   const Mesh<VolumeDim>& mesh,
     121             :                   Parallel::GlobalCache<Metavariables>& cache,
     122             :                   const ElementId<VolumeDim>& element_id,
     123             :                   const ParallelComponent* const component,
     124             :                   const ObservationValue& observation_value) const {
     125             :     observe_fields_event_(box, mesh, cache, element_id, component,
     126             :                           observation_value);
     127             : 
     128             :     interpolate_event_(get<typename InterpolationTargetTag::temporal_id>(box),
     129             :                        mesh, get<InterpolatorSourceVarTags>(box)..., cache,
     130             :                        element_id, component, observation_value);
     131             :   }
     132             : 
     133           0 :   using observation_registration_tags = tmpl::list<::Tags::DataBox>;
     134             : 
     135             :   template <typename DbTagsList>
     136             :   std::optional<
     137             :       std::pair<observers::TypeOfObservation, observers::ObservationKey>>
     138           0 :   get_observation_type_and_key_for_registration(
     139             :       const db::DataBox<DbTagsList>& box) const {
     140             :     return observe_fields_event_.get_observation_type_and_key_for_registration(
     141             :         box);
     142             :   }
     143             : 
     144           0 :   using is_ready_argument_tags = tmpl::list<>;
     145             : 
     146             :   template <typename Metavariables, typename Component>
     147           0 :   bool is_ready(Parallel::GlobalCache<Metavariables>& /*cache*/,
     148             :                 const ElementId<3>& /*element_id*/,
     149             :                 const Component* const /*meta*/) const {
     150             :     return true;
     151             :   }
     152             : 
     153           1 :   bool needs_evolved_variables() const override { return true; }
     154             : 
     155             :   // NOLINTNEXTLINE(google-runtime-references)
     156           0 :   void pup(PUP::er& p) override {
     157             :     Event::pup(p);
     158             :     p | observe_fields_event_;
     159             :     p | interpolate_event_;
     160             :   }
     161             : 
     162             :  private:
     163           0 :   ObserveFieldsEvent observe_fields_event_;
     164           0 :   InterpolateEvent interpolate_event_;
     165             : };
     166             : 
     167             : /// \cond
     168             : // NOLINTBEGIN
     169             : template <size_t VolumeDim, typename InterpolationTargetTag,
     170             :           typename... InterpolatorSourceVarTags, typename... Tensors,
     171             :           typename... NonTensorComputeTags>
     172             : PUP::able::PUP_ID FindCommonHorizon<
     173             :     VolumeDim, InterpolationTargetTag, tmpl::list<InterpolatorSourceVarTags...>,
     174             :     tmpl::list<Tensors...>, tmpl::list<NonTensorComputeTags...>>::my_PUP_ID = 0;
     175             : // NOLINTEND
     176             : /// \endcond
     177             : }  // namespace intrp::Events
     178             : 
     179             : namespace ah::Events {
     180             : /*!
     181             :  * \brief Event that combines the `ah::Events::FindApparentHorizon` event with
     182             :  * `dg::Events::ObserveFields` specifically for common horizon finding.
     183             :  *
     184             :  * \details This is just a thin wrapper around each event and doesn't do
     185             :  * anything extra.
     186             :  */
     187             : template <typename HorizonMetavars, typename Tensors,
     188             :           typename NonTensorComputeTagsList = tmpl::list<>>
     189           1 : class FindCommonHorizon;
     190             : 
     191             : template <typename HorizonMetavars, typename... Tensors,
     192             :           typename... NonTensorComputeTags>
     193           0 : class FindCommonHorizon<HorizonMetavars, tmpl::list<Tensors...>,
     194             :                         tmpl::list<NonTensorComputeTags...>> : public Event {
     195           0 :   using ObserveFieldsEvent =
     196             :       dg::Events::ObserveFields<3, tmpl::list<Tensors...>,
     197             :                                 tmpl::list<NonTensorComputeTags...>>;
     198           0 :   using HorizonFindEvent = ah::Events::FindApparentHorizon<HorizonMetavars>;
     199             : 
     200             :  public:
     201             :   /// \cond
     202             :   explicit FindCommonHorizon(CkMigrateMessage* /*unused*/) {}
     203             :   using PUP::able::register_constructor;
     204             :   WRAPPED_PUPable_decl_template(FindCommonHorizon);  // NOLINT
     205             :   /// \endcond
     206             : 
     207           0 :   using options = tmpl::append<typename ObserveFieldsEvent::options,
     208             :                                typename HorizonFindEvent::options>;
     209           0 :   static constexpr Options::String help =
     210             :       "Starts a common horizon find and sends the evolved variables to be "
     211             :       "written to disk.";
     212             : 
     213           0 :   static std::string name() { return pretty_type::name<HorizonMetavars>(); }
     214             : 
     215           0 :   FindCommonHorizon() = default;
     216             : 
     217           0 :   FindCommonHorizon(
     218             :       const std::string& subfile_name,
     219             :       FloatingPointType coordinates_floating_point_type,
     220             :       const std::vector<FloatingPointType>& floating_point_types,
     221             :       const std::vector<std::string>& variables_to_observe,
     222             :       std::optional<std::vector<std::string>> active_block_or_block_groups = {},
     223             :       std::optional<Mesh<3>> interpolation_mesh = {},
     224             :       std::optional<Mesh<3>> projection_mesh = {},
     225             :       const Options::Context& context = {})
     226             :       : observe_fields_event_(subfile_name, coordinates_floating_point_type,
     227             :                               floating_point_types, variables_to_observe,
     228             :                               active_block_or_block_groups, interpolation_mesh,
     229             :                               projection_mesh, std::nullopt, context),
     230             :         horizon_find_event_(subfile_name) {}
     231             : 
     232           0 :   using compute_tags_for_observation_box = tmpl::remove_duplicates<tmpl::append<
     233             :       typename ObserveFieldsEvent::compute_tags_for_observation_box,
     234             :       typename HorizonFindEvent::compute_tags_for_observation_box>>;
     235             : 
     236           0 :   using return_tags = tmpl::list<>;
     237           0 :   using argument_tags =
     238             :       tmpl::list<::Tags::ObservationBox, ::Events::Tags::ObserverMesh<3>,
     239             :                  domain::Tags::Element<3>>;
     240             : 
     241             :   template <typename DataBoxType, typename ComputeTagsList,
     242             :             typename Metavariables, typename ParallelComponent>
     243           0 :   void operator()(const ObservationBox<DataBoxType, ComputeTagsList>& box,
     244             :                   const Mesh<3>& mesh, const Element<3>& element,
     245             :                   Parallel::GlobalCache<Metavariables>& cache,
     246             :                   const ElementId<3>& element_id,
     247             :                   const ParallelComponent* const component,
     248             :                   const ObservationValue& observation_value) const {
     249             :     observe_fields_event_(box, mesh, cache, element_id, component,
     250             :                           observation_value);
     251             : 
     252             :     horizon_find_event_(
     253             :         get<typename HorizonMetavars::time_tag>(box), mesh, element,
     254             :         get<gr::Tags::SpacetimeMetric<DataVector, 3>>(box),
     255             :         get<gh::Tags::Pi<DataVector, 3>>(box),
     256             :         get<gh::Tags::Phi<DataVector, 3>>(box),
     257             :         get<::Tags::deriv<gh::Tags::Phi<DataVector, 3>, tmpl::size_t<3>,
     258             :                           Frame::Inertial>>(box),
     259             :         cache, element_id, component, observation_value);
     260             :   }
     261             : 
     262           0 :   using observation_registration_tags = tmpl::list<::Tags::DataBox>;
     263             : 
     264             :   template <typename DbTagsList>
     265             :   std::optional<
     266             :       std::pair<observers::TypeOfObservation, observers::ObservationKey>>
     267           0 :   get_observation_type_and_key_for_registration(
     268             :       const db::DataBox<DbTagsList>& box) const {
     269             :     return observe_fields_event_.get_observation_type_and_key_for_registration(
     270             :         box);
     271             :   }
     272             : 
     273           0 :   using is_ready_argument_tags = tmpl::list<>;
     274             : 
     275             :   template <typename Metavariables, typename Component>
     276           0 :   bool is_ready(Parallel::GlobalCache<Metavariables>& /*cache*/,
     277             :                 const ElementId<3>& /*element_id*/,
     278             :                 const Component* const /*meta*/) const {
     279             :     return true;
     280             :   }
     281             : 
     282           1 :   bool needs_evolved_variables() const override { return true; }
     283             : 
     284             :   // NOLINTNEXTLINE(google-runtime-references)
     285           0 :   void pup(PUP::er& p) override {
     286             :     Event::pup(p);
     287             :     p | observe_fields_event_;
     288             :     p | horizon_find_event_;
     289             :   }
     290             : 
     291             :  private:
     292           0 :   ObserveFieldsEvent observe_fields_event_;
     293           0 :   HorizonFindEvent horizon_find_event_;
     294             : };
     295             : 
     296             : /// \cond
     297             : // NOLINTBEGIN
     298             : template <typename HorizonMetavars, typename... Tensors,
     299             :           typename... NonTensorComputeTags>
     300             : PUP::able::PUP_ID
     301             :     FindCommonHorizon<HorizonMetavars, tmpl::list<Tensors...>,
     302             :                       tmpl::list<NonTensorComputeTags...>>::my_PUP_ID = 0;
     303             : // NOLINTEND
     304             : /// \endcond
     305             : }  // namespace ah::Events

Generated by: LCOV version 1.14