SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/LinearSolver/ConjugateGradient - ResidualMonitor.hpp Coverage Total Hit
Commit: 0d1d717af84a81fb1284a20c4013708fe85cc2f0 Lines: 0.0 % 1 0
Test Date: 2026-10-22 17:29:42
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 <limits>
       8              : #include <optional>
       9              : #include <tuple>
      10              : #include <utility>
      11              : 
      12              : #include "DataStructures/DataBox/DataBox.hpp"
      13              : #include "DataStructures/DataBox/PrefixHelpers.hpp"
      14              : #include "IO/Logging/Tags.hpp"
      15              : #include "NumericalAlgorithms/Convergence/Tags.hpp"
      16              : #include "Parallel/AlgorithmExecution.hpp"
      17              : #include "Parallel/Algorithms/AlgorithmSingleton.hpp"
      18              : #include "Parallel/GlobalCache.hpp"
      19              : #include "Parallel/Local.hpp"
      20              : #include "Parallel/ParallelComponentHelpers.hpp"
      21              : #include "Parallel/Phase.hpp"
      22              : #include "Parallel/PhaseDependentActionList.hpp"
      23              : #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
      24              : #include "ParallelAlgorithms/LinearSolver/Tags.hpp"
      25              : #include "Utilities/TMPL.hpp"
      26              : 
      27              : /// \cond
      28              : namespace tuples {
      29              : template <typename...>
      30              : class TaggedTuple;
      31              : }  // namespace tuples
      32              : namespace LinearSolver::cg::detail {
      33              : template <typename FieldsTag, typename OptionsGroup>
      34              : struct InitializeResidualMonitor;
      35              : }  // namespace LinearSolver::cg::detail
      36              : /// \endcond
      37              : 
      38              : namespace LinearSolver::cg::detail {
      39              : 
      40              : template <typename Metavariables, typename FieldsTag, typename OptionsGroup>
      41              : struct ResidualMonitor {
      42              :   using chare_type = Parallel::Algorithms::Singleton;
      43              :   static constexpr bool checkpoint_data = true;
      44              :   using const_global_cache_tags =
      45              :       tmpl::list<logging::Tags::Verbosity<OptionsGroup>,
      46              :                  Convergence::Tags::Criteria<OptionsGroup>>;
      47              :   using metavariables = Metavariables;
      48              :   // The actions in `ResidualMonitorActions.hpp` are invoked as simple actions
      49              :   // on this component as the result of reductions from the actions in
      50              :   // `ElementActions.hpp`. See `LinearSolver::cg::ConjugateGradient` for
      51              :   // details.
      52              :   using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
      53              :       Parallel::Phase::Initialization,
      54              :       tmpl::list<InitializeResidualMonitor<FieldsTag, OptionsGroup>>>>;
      55              :   using simple_tags_from_options = Parallel::get_simple_tags_from_options<
      56              :       Parallel::get_initialization_actions_list<phase_dependent_action_list>>;
      57              : 
      58              :   static void execute_next_phase(
      59              :       const Parallel::Phase next_phase,
      60              :       Parallel::CProxy_GlobalCache<Metavariables>& global_cache) {
      61              :     auto& local_cache = *Parallel::local_branch(global_cache);
      62              :     Parallel::get_parallel_component<ResidualMonitor>(local_cache)
      63              :         .start_phase(next_phase);
      64              :   }
      65              : };
      66              : 
      67              : template <typename FieldsTag, typename OptionsGroup>
      68              : struct InitializeResidualMonitor {
      69              :  private:
      70              :   using fields_tag = FieldsTag;
      71              :   using residual_square_tag = LinearSolver::Tags::MagnitudeSquare<
      72              :       db::add_tag_prefix<LinearSolver::Tags::Residual, fields_tag>>;
      73              :   using initial_residual_magnitude_tag =
      74              :       ::Tags::Initial<LinearSolver::Tags::Magnitude<
      75              :           db::add_tag_prefix<LinearSolver::Tags::Residual, fields_tag>>>;
      76              : 
      77              :  public:
      78              :   using simple_tags =
      79              :       tmpl::list<residual_square_tag, initial_residual_magnitude_tag>;
      80              :   using compute_tags = tmpl::list<>;
      81              :   template <typename DbTagsList, typename... InboxTags, typename Metavariables,
      82              :             typename ArrayIndex, typename ActionList,
      83              :             typename ParallelComponent>
      84              :   static Parallel::iterable_action_return_t apply(
      85              :       db::DataBox<DbTagsList>& box,
      86              :       const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
      87              :       const Parallel::GlobalCache<Metavariables>& /*cache*/,
      88              :       const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
      89              :       const ParallelComponent* const /*meta*/) {
      90              :     // The `InitializeResidual` action populates these tags with initial values
      91              :     Initialization::mutate_assign<simple_tags>(
      92              :         make_not_null(&box), std::numeric_limits<double>::signaling_NaN(),
      93              :         std::numeric_limits<double>::signaling_NaN());
      94              :     return {Parallel::AlgorithmExecution::Pause, std::nullopt};
      95              :   }
      96              : };
      97              : 
      98              : }  // namespace LinearSolver::cg::detail
        

Generated by: LCOV version 2.0-1