SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/Amr/Actions - SendAmrDiagnostics.hpp Hit Total Coverage
Commit: c7c91c0aa25aeda7dc9e4c735164d2bb71ebe72e Lines: 1 5 20.0 %
Date: 2024-03-28 06:01:39
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 <boost/rational.hpp>
       7             : #include <cstddef>
       8             : #include <vector>
       9             : 
      10             : #include "DataStructures/DataBox/DataBox.hpp"
      11             : #include "Domain/Amr/Helpers.hpp"
      12             : #include "Domain/Structure/ElementId.hpp"
      13             : #include "IO/Logging/Tags.hpp"
      14             : #include "IO/Logging/Verbosity.hpp"
      15             : #include "Parallel/AlgorithmExecution.hpp"
      16             : #include "Parallel/GlobalCache.hpp"
      17             : #include "Parallel/Printf.hpp"
      18             : #include "Parallel/Reduction.hpp"
      19             : #include "ParallelAlgorithms/Amr/Actions/Component.hpp"
      20             : #include "ParallelAlgorithms/Amr/Actions/RunAmrDiagnostics.hpp"
      21             : #include "ParallelAlgorithms/Amr/Tags.hpp"
      22             : #include "Utilities/GetOutput.hpp"
      23             : #include "Utilities/Serialization/PupBoost.hpp"
      24             : #include "Utilities/StdHelpers.hpp"
      25             : 
      26             : namespace amr::Actions {
      27             : 
      28             : /// \brief Send AMR diagnostics about Element%s to amr::Component
      29             : ///
      30             : /// Sends the following:
      31             : /// - The fraction of a Block volume (in the logical coordinate frame) covered
      32             : ///   by the Element
      33             : /// - One, in order to count the number of Element%s
      34             : /// - The number of grid points
      35             : /// - The refinement level in each logical dimension
      36             : /// - The number of grid points in each logical dimension
      37             : ///
      38             : /// The information is sent to amr::Component which runs the action
      39             : /// amr::Actions::RunAmrDiagnostics after all Element%s have contributed to the
      40             : /// reduction
      41           1 : struct SendAmrDiagnostics {
      42           0 :   using const_global_cache_tags =
      43             :       tmpl::list<logging::Tags::Verbosity<amr::OptionTags::AmrGroup>>;
      44             : 
      45           0 :   using ReductionData = Parallel::ReductionData<
      46             :       // fraction of Block volume
      47             :       Parallel::ReductionDatum<boost::rational<size_t>, funcl::Plus<>>,
      48             :       // number of elements
      49             :       Parallel::ReductionDatum<size_t, funcl::Plus<>>,
      50             :       // number of grid points
      51             :       Parallel::ReductionDatum<size_t, funcl::Plus<>>,
      52             :       // average refinement level by dimension
      53             :       Parallel::ReductionDatum<
      54             :           std::vector<double>, funcl::ElementWise<funcl::Plus<>>,
      55             :           funcl::ElementWise<funcl::Divides<>>, std::index_sequence<1>>,
      56             :       // average number of grid points by dimension
      57             :       Parallel::ReductionDatum<
      58             :           std::vector<double>, funcl::ElementWise<funcl::Plus<>>,
      59             :           funcl::ElementWise<funcl::Divides<>>, std::index_sequence<1>>>;
      60             : 
      61             :   template <typename DbTagList, typename... InboxTags, typename Metavariables,
      62             :             size_t Dim, typename ActionList, typename ParallelComponent>
      63           0 :   static Parallel::iterable_action_return_t apply(
      64             :       db::DataBox<DbTagList>& box,
      65             :       tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
      66             :       const Parallel::GlobalCache<Metavariables>& cache,
      67             :       const ElementId<Dim>& element_id, const ActionList /*meta*/,
      68             :       const ParallelComponent* /*meta*/) {
      69             :     const auto& mesh = db::get<::domain::Tags::Mesh<Dim>>(box);
      70             :     const auto& my_proxy =
      71             :         Parallel::get_parallel_component<ParallelComponent>(cache)[element_id];
      72             :     const auto& target_proxy =
      73             :         Parallel::get_parallel_component<amr::Component<Metavariables>>(cache);
      74             :     std::vector<double> refinement_levels_by_dim(Dim);
      75             :     std::vector<double> extents_by_dim(Dim);
      76             :     const auto refinement_levels = element_id.refinement_levels();
      77             :     for (size_t d = 0; d < Dim; ++d) {
      78             :       refinement_levels_by_dim[d] = gsl::at(refinement_levels, d);
      79             :       extents_by_dim[d] = mesh.extents(d);
      80             :     }
      81             :     if (db::get<logging::Tags::Verbosity<amr::OptionTags::AmrGroup>>(box) >=
      82             :         Verbosity::Debug) {
      83             :       Parallel::printf("%s h-refinement %s, p-refinement %s\n",
      84             :                        get_output(element_id), get_output(refinement_levels),
      85             :                        get_output(mesh.extents()));
      86             :     }
      87             :     Parallel::contribute_to_reduction<amr::Actions::RunAmrDiagnostics>(
      88             :         ReductionData{amr::fraction_of_block_volume(element_id), 1,
      89             :                       mesh.number_of_grid_points(), refinement_levels_by_dim,
      90             :                       extents_by_dim},
      91             :         my_proxy, target_proxy);
      92             :     return {Parallel::AlgorithmExecution::Continue, std::nullopt};
      93             :   }
      94             : };
      95             : }  // namespace amr::Actions

Generated by: LCOV version 1.14