SpECTRE Documentation Coverage Report
Current view: top level - IO/Importers/Actions - RegisterWithElementDataReader.hpp Hit Total Coverage
Commit: d0fc80462417e83e5cddfa1b9901bb4a9b6af4d6 Lines: 2 5 40.0 %
Date: 2024-03-29 00:33: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 <cstddef>
       7             : #include <optional>
       8             : #include <tuple>
       9             : 
      10             : #include "DataStructures/DataBox/DataBox.hpp"
      11             : #include "Domain/Structure/ElementId.hpp"
      12             : #include "Domain/Tags.hpp"
      13             : #include "IO/Importers/Tags.hpp"
      14             : #include "Parallel/AlgorithmExecution.hpp"
      15             : #include "Parallel/ArrayComponentId.hpp"
      16             : #include "Parallel/ArrayIndex.hpp"
      17             : #include "Parallel/GlobalCache.hpp"
      18             : #include "Parallel/Invoke.hpp"
      19             : #include "Parallel/Local.hpp"
      20             : #include "Utilities/Gsl.hpp"
      21             : #include "Utilities/Literals.hpp"
      22             : #include "Utilities/MakeString.hpp"
      23             : #include "Utilities/Requires.hpp"
      24             : #include "Utilities/TMPL.hpp"
      25             : #include "Utilities/TaggedTuple.hpp"
      26             : 
      27             : /// \cond
      28             : namespace importers {
      29             : template <typename Metavariables>
      30             : struct ElementDataReader;
      31             : namespace Actions {
      32             : struct RegisterElementWithSelf;
      33             : }  // namespace Actions
      34             : }  // namespace importers
      35             : namespace evolution::dg::subcell {
      36             : template <typename DgTag, typename SubcellTag, typename DbTagsList>
      37             : const typename DgTag::type& get_active_tag(const db::DataBox<DbTagsList>& box);
      38             : namespace Tags {
      39             : template <size_t Dim, typename Frame>
      40             : struct Coordinates;
      41             : struct ActiveGrid;
      42             : }  // namespace Tags
      43             : }  // namespace evolution::dg::subcell
      44             : /// \endcond
      45             : 
      46             : namespace importers::Actions {
      47             : 
      48             : /*!
      49             :  * \brief Register an element with the volume data reader component.
      50             :  *
      51             :  * Invoke this action on each element of an array parallel component to register
      52             :  * them for receiving imported volume data.
      53             :  *
      54             :  * \note If the tags `evolution::dg::subcell::Tags::ActiveGrid` and
      55             :  * `evolution::dg::subcell::Tags::Coordinates<Dim, Frame::Inertial>` are
      56             :  * retrievable from the DataBox, then interpolation to the FD/subcell grid is
      57             :  * possible.
      58             :  *
      59             :  * \see Dev guide on \ref dev_guide_importing
      60             :  */
      61           1 : struct RegisterWithElementDataReader {
      62             :   template <typename DbTagsList, typename... InboxTags, typename Metavariables,
      63             :             size_t Dim, typename ActionList, typename ParallelComponent>
      64           0 :   static Parallel::iterable_action_return_t apply(
      65             :       db::DataBox<DbTagsList>& box,
      66             :       const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
      67             :       Parallel::GlobalCache<Metavariables>& cache,
      68             :       const ElementId<Dim>& array_index, const ActionList /*meta*/,
      69             :       const ParallelComponent* const /*meta*/) {
      70             :     auto& local_reader_component = *Parallel::local_branch(
      71             :         Parallel::get_parallel_component<
      72             :             importers::ElementDataReader<Metavariables>>(cache));
      73             :     const auto& coords = [&box]() {
      74             :       if constexpr (db::tag_is_retrievable_v<
      75             :                         evolution::dg::subcell::Tags::ActiveGrid,
      76             :                         db::DataBox<DbTagsList>> and
      77             :                     db::tag_is_retrievable_v<
      78             :                         evolution::dg::subcell::Tags::Coordinates<
      79             :                             Dim, Frame::Inertial>,
      80             :                         db::DataBox<DbTagsList>>) {
      81             :         return evolution::dg::subcell::get_active_tag<
      82             :             domain::Tags::Coordinates<Dim, Frame::Inertial>,
      83             :             evolution::dg::subcell::Tags::Coordinates<Dim, Frame::Inertial>>(
      84             :             box);
      85             :       } else {
      86             :         return db::get<domain::Tags::Coordinates<Dim, Frame::Inertial>>(box);
      87             :       }
      88             :     }();
      89             :     Parallel::simple_action<importers::Actions::RegisterElementWithSelf>(
      90             :         local_reader_component,
      91             :         Parallel::make_array_component_id<ParallelComponent>(array_index),
      92             :         coords);
      93             :     return {Parallel::AlgorithmExecution::Continue, std::nullopt};
      94             :   }
      95             : };
      96             : 
      97             : /*!
      98             :  * \brief Invoked on the `importers::ElementDataReader` component to store the
      99             :  * registered data.
     100             :  *
     101             :  * The `importers::Actions::RegisterWithElementDataReader` action, which is
     102             :  * performed on each element of an array parallel component, invokes this action
     103             :  * on the `importers::ElementDataReader` component.
     104             :  *
     105             :  * \see Dev guide on \ref dev_guide_importing
     106             :  */
     107           1 : struct RegisterElementWithSelf {
     108             :   template <typename ParallelComponent, typename DbTagsList,
     109             :             typename Metavariables, typename ArrayIndex, size_t Dim>
     110           0 :   static void apply(
     111             :       db::DataBox<DbTagsList>& box,
     112             :       const Parallel::GlobalCache<Metavariables>& /*cache*/,
     113             :       const ArrayIndex& /*array_index*/,
     114             :       const Parallel::ArrayComponentId& array_component_id,
     115             :       const tnsr::I<DataVector, Dim, Frame::Inertial>& inertial_coords) {
     116             :     db::mutate<Tags::RegisteredElements<Dim>>(
     117             :         [&array_component_id, &inertial_coords](
     118             :             const gsl::not_null<
     119             :                 std::unordered_map<Parallel::ArrayComponentId,
     120             :                                    tnsr::I<DataVector, Dim, Frame::Inertial>>*>
     121             :                 registered_elements) {
     122             :           (*registered_elements)[array_component_id] = inertial_coords;
     123             :         },
     124             :         make_not_null(&box));
     125             :   }
     126             : };
     127             : 
     128             : }  // namespace importers::Actions

Generated by: LCOV version 1.14