SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/Interpolation/Actions - DumpInterpolatorVolumeData.hpp Hit Total Coverage
Commit: eded15d6fcfa762a5dfde087b28df9bcedd8b386 Lines: 1 4 25.0 %
Date: 2024-04-15 22:23:51
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 <optional>
       7             : #include <string>
       8             : #include <type_traits>
       9             : #include <vector>
      10             : 
      11             : #include "DataStructures/DataBox/DataBox.hpp"
      12             : #include "Domain/Tags.hpp"
      13             : #include "IO/H5/TensorData.hpp"
      14             : #include "IO/Observer/Actions/ObserverRegistration.hpp"
      15             : #include "IO/Observer/ObservationId.hpp"
      16             : #include "IO/Observer/ObserverComponent.hpp"
      17             : #include "IO/Observer/Tags.hpp"
      18             : #include "IO/Observer/VolumeActions.hpp"
      19             : #include "NumericalAlgorithms/Spectral/Mesh.hpp"
      20             : #include "NumericalAlgorithms/Spectral/Spectral.hpp"
      21             : #include "Parallel/AlgorithmExecution.hpp"
      22             : #include "Parallel/ArrayComponentId.hpp"
      23             : #include "Parallel/GlobalCache.hpp"
      24             : #include "Parallel/Info.hpp"
      25             : #include "Parallel/Invoke.hpp"
      26             : #include "Parallel/Local.hpp"
      27             : #include "ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp"
      28             : #include "ParallelAlgorithms/Interpolation/Tags.hpp"
      29             : #include "Utilities/GetOutput.hpp"
      30             : #include "Utilities/MakeString.hpp"
      31             : #include "Utilities/TMPL.hpp"
      32             : #include "Utilities/TaggedTuple.hpp"
      33             : 
      34             : namespace intrp::Actions {
      35             : namespace detail {
      36             : // This requires there to be a type alias named `interpolator_source_vars` in
      37             : // the metavariables
      38             : template <typename TemporalIdTag, typename Metavariables>
      39             : ElementVolumeData construct_element_volume_data(
      40             :     const ElementId<Metavariables::volume_dim>& element_id,
      41             :     const typename intrp::Tags::VolumeVarsInfo<Metavariables,
      42             :                                                TemporalIdTag>::Info& info) {
      43             :   std::vector<TensorComponent> components{};
      44             : 
      45             :   const auto& all_source_vars = info.source_vars_from_element;
      46             :   tmpl::for_each<typename Metavariables::interpolator_source_vars>(
      47             :       [&components, &all_source_vars](auto source_var_tag_v) {
      48             :         using source_var_tag =
      49             :             tmpl::type_from<std::decay_t<decltype(source_var_tag_v)>>;
      50             :         const auto& tensor = get<source_var_tag>(all_source_vars);
      51             :         for (size_t i = 0; i < tensor.size(); i++) {
      52             :           const auto& tensor_component = tensor[i];
      53             :           components.emplace_back(
      54             :               db::tag_name<source_var_tag>() + tensor.component_suffix(i),
      55             :               tensor_component);
      56             :         }
      57             :       });
      58             : 
      59             :   return ElementVolumeData{element_id, std::move(components), info.mesh};
      60             : }
      61             : }  // namespace detail
      62             : 
      63             : /*!
      64             :  * \brief Dump all volume data at all temporal IDs stored in the interpolator.
      65             :  *
      66             :  * All dumped data will be in the usual volume files, but under different
      67             :  * subfiles. There will be one subfile for every temporal ID type (as the
      68             :  * interpolator can have multiple different temporal ID types from different
      69             :  * interpolation targets). The tensors that are dumped are the ones defined in
      70             :  * the `interpolator_source_vars` type alias in the Metavariables.
      71             :  */
      72             : template <typename AllTemporalIds>
      73           1 : struct DumpInterpolatorVolumeData {
      74           0 :   using const_global_cache_tags =
      75             :       tmpl::list<intrp::Tags::DumpVolumeDataOnFailure>;
      76             : 
      77             :   template <typename DbTagList, typename... InboxTags, typename Metavariables,
      78             :             typename ArrayIndex, typename ActionList,
      79             :             typename ParallelComponent>
      80           0 :   static Parallel::iterable_action_return_t apply(
      81             :       db::DataBox<DbTagList>& box,
      82             :       const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
      83             :       Parallel::GlobalCache<Metavariables>& cache,
      84             :       const ArrayIndex& array_index, const ActionList /*meta*/,
      85             :       const ParallelComponent* const /*meta*/) {
      86             :     if (not Parallel::get<intrp::Tags::DumpVolumeDataOnFailure>(cache)) {
      87             :       return {Parallel::AlgorithmExecution::Continue, std::nullopt};
      88             :     }
      89             : 
      90             :     auto& observer_writer = *Parallel::local_branch(
      91             :         Parallel::get_parallel_component<
      92             :             observers::ObserverWriter<Metavariables>>(cache));
      93             : 
      94             :     const Parallel::ArrayComponentId array_component_id =
      95             :         Parallel::make_array_component_id<ParallelComponent>(array_index);
      96             : 
      97             :     tmpl::for_each<AllTemporalIds>([&box, &observer_writer,
      98             :                                     &array_component_id](auto temporal_id_v) {
      99             :       using temporal_id_t =
     100             :           tmpl::type_from<std::decay_t<decltype(temporal_id_v)>>;
     101             :       const auto& volume_vars_info =
     102             :           db::get<intrp::Tags::VolumeVarsInfo<Metavariables, temporal_id_t>>(
     103             :               box);
     104             :       const std::string subfile_name{"/InterpolatorVolumeData_"s +
     105             :                                      db::tag_name<temporal_id_t>()};
     106             : 
     107             :       for (const auto& [temporal_id, info_map] : volume_vars_info) {
     108             :         std::vector<ElementVolumeData> element_volume_data{};
     109             :         for (const auto& [element_id, info] : info_map) {
     110             :           element_volume_data.emplace_back(
     111             :               detail::construct_element_volume_data<temporal_id_t,
     112             :                                                     Metavariables>(element_id,
     113             :                                                                    info));
     114             :         }
     115             : 
     116             :         Parallel::threaded_action<
     117             :             observers::ThreadedActions::ContributeVolumeDataToWriter>(
     118             :             observer_writer,
     119             :             observers::ObservationId{
     120             :                 InterpolationTarget_detail::get_temporal_id_value(temporal_id),
     121             :                 subfile_name},
     122             :             array_component_id, subfile_name,
     123             :             std::unordered_map<Parallel::ArrayComponentId,
     124             :                                std::vector<ElementVolumeData>>{
     125             :                 {array_component_id, std::move(element_volume_data)}});
     126             :       }
     127             :     });
     128             : 
     129             :     return {Parallel::AlgorithmExecution::Continue, std::nullopt};
     130             :   }
     131             : };
     132             : }  // namespace intrp::Actions

Generated by: LCOV version 1.14