SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/Amr/Actions - InitializeChild.hpp Hit Total Coverage
Commit: 1f2210958b4f38fdc0400907ee7c6d5af5111418 Lines: 1 3 33.3 %
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 <array>
       7             : #include <cstddef>
       8             : #include <limits>
       9             : #include <unordered_map>
      10             : #include <utility>
      11             : 
      12             : #include "DataStructures/DataBox/DataBox.hpp"
      13             : #include "Domain/Amr/Flag.hpp"
      14             : #include "Domain/Amr/NeighborsOfChild.hpp"
      15             : #include "Domain/Amr/Tags/Flags.hpp"
      16             : #include "Domain/Amr/Tags/NeighborFlags.hpp"
      17             : #include "Domain/Structure/DirectionMap.hpp"
      18             : #include "Domain/Structure/DirectionalIdMap.hpp"
      19             : #include "Domain/Structure/Element.hpp"
      20             : #include "Domain/Structure/ElementId.hpp"
      21             : #include "Domain/Structure/Neighbors.hpp"
      22             : #include "Domain/Tags.hpp"
      23             : #include "Domain/Tags/NeighborMesh.hpp"
      24             : #include "NumericalAlgorithms/Spectral/Mesh.hpp"
      25             : #include "Parallel/ElementRegistration.hpp"
      26             : #include "ParallelAlgorithms/Amr/Projectors/Mesh.hpp"
      27             : #include "ParallelAlgorithms/Amr/Tags.hpp"
      28             : #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
      29             : #include "Utilities/Gsl.hpp"
      30             : #include "Utilities/TMPL.hpp"
      31             : #include "Utilities/TaggedTuple.hpp"
      32             : 
      33             : /// \cond
      34             : namespace Parallel {
      35             : template <typename Metavariables>
      36             : class GlobalCache;
      37             : }  // namespace Parallel
      38             : /// \endcond
      39             : 
      40             : namespace amr::Actions {
      41             : /// \brief Initializes the data of a newly created child element from the data
      42             : /// of its parent element
      43             : ///
      44             : /// DataBox:
      45             : /// - Modifies:
      46             : ///   * domain::Tags::Element<volume_dim>
      47             : ///   * domain::Tags::Mesh<volume_dim>
      48             : ///   * all return_tags of Metavariables::amr::projectors
      49             : ///
      50             : /// \details This action is meant to be invoked by
      51             : /// amr::Actions::SendDataToChildren
      52           1 : struct InitializeChild {
      53             :   template <typename ParallelComponent, typename DbTagList,
      54             :             typename Metavariables, typename... Tags>
      55           0 :   static void apply(db::DataBox<DbTagList>& box,
      56             :                     Parallel::GlobalCache<Metavariables>& cache,
      57             :                     const ElementId<Metavariables::volume_dim>& child_id,
      58             :                     const tuples::TaggedTuple<Tags...>& parent_items) {
      59             :     constexpr size_t volume_dim = Metavariables::volume_dim;
      60             :     const auto& parent =
      61             :         tuples::get<::domain::Tags::Element<volume_dim>>(parent_items);
      62             :     const auto& parent_info =
      63             :         tuples::get<amr::Tags::Info<volume_dim>>(parent_items);
      64             :     const auto& parent_neighbor_info =
      65             :         tuples::get<amr::Tags::NeighborInfo<volume_dim>>(parent_items);
      66             :     const auto& parent_mesh =
      67             :         tuples::get<::domain::Tags::Mesh<volume_dim>>(parent_items);
      68             :     auto neighbors = amr::neighbors_of_child(parent, parent_info,
      69             :                                              parent_neighbor_info, child_id);
      70             :     Element<volume_dim> child(child_id, std::move(neighbors.first));
      71             :     Mesh<volume_dim> child_mesh =
      72             :         amr::projectors::mesh(parent_mesh, parent_info.flags);
      73             : 
      74             :     // Default initialization of amr::Tags::Info and amr::Tags::NeighborInfo
      75             :     // is okay
      76             :     ::Initialization::mutate_assign<tmpl::list<
      77             :         ::domain::Tags::Element<volume_dim>, ::domain::Tags::Mesh<volume_dim>,
      78             :         ::domain::Tags::NeighborMesh<volume_dim>>>(
      79             :         make_not_null(&box), std::move(child), std::move(child_mesh),
      80             :         std::move(neighbors.second));
      81             : 
      82             :     if constexpr (Metavariables::amr::keep_coarse_grids) {
      83             :       if (db::get<amr::Tags::MaxCoarseLevels>(box).value_or(
      84             :               std::numeric_limits<size_t>::max()) > 0) {
      85             :         ::Initialization::mutate_assign<
      86             :             tmpl::list<amr::Tags::ParentId<volume_dim>,
      87             :                        amr::Tags::ParentMesh<volume_dim>>>(
      88             :             make_not_null(&box), parent.id(), parent_mesh);
      89             :       }
      90             :     }
      91             : 
      92             :     tmpl::for_each<typename Metavariables::amr::projectors>(
      93             :         [&box, &parent_items](auto projector_v) {
      94             :           using projector = typename decltype(projector_v)::type;
      95             :           try {
      96             :             db::mutate_apply<projector>(make_not_null(&box), parent_items);
      97             :           } catch (std::exception& e) {
      98             :             ERROR("Error in AMR projector '"
      99             :                   << pretty_type::get_name<projector>() << "':\n"
     100             :                   << e.what());
     101             :           }
     102             :         });
     103             : 
     104             :     Parallel::register_element<ParallelComponent>(box, cache, child_id);
     105             :   }
     106             : };
     107             : }  // namespace amr::Actions

Generated by: LCOV version 1.14