SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/Interpolation - InterpolatedVars.hpp Hit Total Coverage
Commit: 1f2210958b4f38fdc0400907ee7c6d5af5111418 Lines: 10 21 47.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 <cstddef>
       7             : #include <deque>
       8             : #include <optional>
       9             : #include <unordered_map>
      10             : #include <unordered_set>
      11             : #include <vector>
      12             : 
      13             : #include "DataStructures/IdPair.hpp"
      14             : #include "DataStructures/Tensor/TypeAliases.hpp"
      15             : #include "DataStructures/Variables.hpp"
      16             : #include "Domain/BlockLogicalCoordinates.hpp"
      17             : #include "Domain/Structure/BlockId.hpp"
      18             : #include "Domain/Structure/ElementId.hpp"
      19             : 
      20             : namespace intrp {
      21             : 
      22             : /// Data structures holding quantities that are interpolated by
      23             : /// `Interpolator` for use by `InterpolationTarget`s
      24           1 : namespace Vars {
      25             : /// \brief Holds a `Variables` interpolated onto a list of points, and
      26             : /// information about those points, for a local `Interpolator`.
      27             : ///
      28             : /// `TagList` is a `tmpl::list` of tags that go into the `Variables`.
      29             : template <size_t VolumeDim, typename TagList>
      30           1 : struct Info {
      31             :   /// `block_coord_holders` holds the list of all points (in block
      32             :   /// logical coordinates) that need to be interpolated onto for a
      33             :   /// given `InterpolationTarget`.
      34             :   ///
      35             :   /// The number of interpolated points for which results are stored
      36             :   /// in this `Info` (in `vars` and `global_offsets` below)
      37             :   /// corresponds to only the subset of the points in
      38             :   /// `block_coord_holders` that are contained in local `Element`s.
      39             :   /// Moreover, the number of interpolated points stored in this
      40             :   /// `Info` will change as more `Elements` send data to this
      41             :   /// `Interpolator`, and will be less than or equal to the size of
      42             :   /// `block_coord_holders` even after all `Element`s have sent their
      43             :   /// data (this is because this `Info` lives only on a single core,
      44             :   /// and this core will have access only to the local `Element`s).
      45           1 :   std::vector<BlockLogicalCoords<VolumeDim>> block_coord_holders;
      46             :   /// If a target needs to send points in a specific order, it should also send
      47             :   /// along which iteration the `block_coord_holders` are for. That way they can
      48             :   /// be properly ordered in the Interpolator.
      49           1 :   size_t iteration{0_st};
      50             :   /// Sometimes during a single iteration, we are unable to interpolate, but the
      51             :   /// target has a method of retrying the interpolation for the same overall
      52             :   /// iteration. This keeps track of how many times we've tried to reinterpolate
      53             :   /// for a given iteration.
      54           1 :   size_t reinterpolation_iteration{0_st};
      55             :   /// `vars` holds the interpolated `Variables` on some subset of the
      56             :   /// points in `block_coord_holders`.  The grid points inside vars
      57             :   /// are indexed according to `global_offsets` below.  The size of
      58             :   /// `vars` changes as more `Element`s send data to this `Interpolator`.
      59           1 :   std::vector<Variables<TagList>> vars{};
      60             :   /// `global_offsets[j][i]` is the index into `block_coord_holders` that
      61             :   /// corresponds to the index `i` of the `DataVector` held in `vars[j]`.
      62             :   /// The size of `global_offsets` changes as more `Element`s
      63             :   /// send data to this `Interpolator`.
      64           1 :   std::vector<std::vector<size_t>> global_offsets{};
      65             :   /// Holds the `ElementId`s of `Element`s for which interpolation has
      66             :   /// already been done for this `Info`.
      67             :   std::unordered_set<ElementId<VolumeDim>>
      68           1 :       interpolation_is_done_for_these_elements{};
      69             : 
      70           0 :   Info() = default;
      71           0 :   explicit Info(
      72             :       std::vector<BlockLogicalCoords<VolumeDim>> block_coord_holders_in,
      73             :       const size_t iteration_in = 0,
      74             :       std::vector<Variables<TagList>> vars_in = {},
      75             :       std::vector<std::vector<size_t>> global_offsets_in = {},
      76             :       std::unordered_set<ElementId<VolumeDim>>
      77             :           interpolation_is_done_for_these_elements_in = {})
      78             :       : block_coord_holders(std::move(block_coord_holders_in)),
      79             :         iteration(iteration_in),
      80             :         vars(std::move(vars_in)),
      81             :         global_offsets(std::move(global_offsets_in)),
      82             :         interpolation_is_done_for_these_elements(
      83             :             std::move(interpolation_is_done_for_these_elements_in)) {}
      84             : };
      85             : 
      86             : template <size_t VolumeDim, typename TagList>
      87           0 : void pup(PUP::er& p, Info<VolumeDim, TagList>& t) {  // NOLINT
      88             :   p | t.block_coord_holders;
      89             :   p | t.vars;
      90             :   p | t.global_offsets;
      91             :   p | t.interpolation_is_done_for_these_elements;
      92             : }
      93             : 
      94             : template <size_t VolumeDim, typename TagList>
      95           0 : void operator|(PUP::er& p, Info<VolumeDim, TagList>& t) {  // NOLINT
      96             :   pup(p, t);
      97             : }
      98             : 
      99             : /// Holds `Info`s at all `temporal_id`s for a given
     100             : /// `InterpolationTargetTag`.  Also holds `temporal_id`s when data has
     101             : /// been interpolated; this is used for cleanup purposes.  All
     102             : /// `Holder`s for all `InterpolationTargetTags` are held in a single
     103             : /// `TaggedTuple` that is in the `Interpolator`'s `DataBox` with the
     104             : /// tag `Tags::InterpolatedVarsHolders`.
     105             : template <typename Metavariables,
     106             :           typename InterpolationTargetTag, typename TagList>
     107           1 : struct Holder {
     108           0 :   using temporal_id = typename InterpolationTargetTag::temporal_id;
     109             :   std::unordered_map<typename InterpolationTargetTag::temporal_id::type,
     110             :                      Info<Metavariables::volume_dim, TagList>>
     111           0 :       infos;
     112             :   std::deque<typename InterpolationTargetTag::temporal_id::type>
     113           0 :       temporal_ids_when_data_has_been_interpolated;
     114             : };
     115             : 
     116             : template <typename Metavariables, typename InterpolationTargetTag,
     117             :           typename TagList>
     118           0 : void pup(PUP::er& p,                                              // NOLINT
     119             :          Holder<Metavariables, InterpolationTargetTag, TagList>&  // NOLINT
     120             :              t) {                                                 // NOLINT
     121             :   p | t.infos;
     122             :   p | t.temporal_ids_when_data_has_been_interpolated;
     123             : }
     124             : 
     125             : template <typename Metavariables, typename InterpolationTargetTag,
     126             :           typename TagList>
     127           0 : void operator|(
     128             :     PUP::er& p,                                                   // NOLINT
     129             :     Holder<Metavariables, InterpolationTargetTag, TagList>& t) {  // NOLINT
     130             :   pup(p, t);
     131             : }
     132             : 
     133             : /// Indexes a particular `Holder` in the `TaggedTuple` that is
     134             : /// accessed from the `Interpolator`'s `DataBox` with tag
     135             : /// `Tags::InterpolatedVarsHolders`.
     136             : template <typename InterpolationTargetTag, typename Metavariables>
     137           1 : struct HolderTag {
     138           0 :   using type =
     139             :       Holder<Metavariables, InterpolationTargetTag,
     140             :              typename InterpolationTargetTag::vars_to_interpolate_to_target>;
     141             : };
     142             : 
     143             : }  // namespace Vars
     144             : }  // namespace intrp

Generated by: LCOV version 1.14