SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/LinearSolver/ConjugateGradient - ResidualMonitor.hpp Hit Total Coverage
Commit: 058fd9f3a53606b32c6beec17aafdb5fcf4268be Lines: 0 1 0.0 %
Date: 2024-04-27 02:05: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 <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             :   using const_global_cache_tags =
      44             :       tmpl::list<logging::Tags::Verbosity<OptionsGroup>,
      45             :                  Convergence::Tags::Criteria<OptionsGroup>>;
      46             :   using metavariables = Metavariables;
      47             :   // The actions in `ResidualMonitorActions.hpp` are invoked as simple actions
      48             :   // on this component as the result of reductions from the actions in
      49             :   // `ElementActions.hpp`. See `LinearSolver::cg::ConjugateGradient` for
      50             :   // details.
      51             :   using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
      52             :       Parallel::Phase::Initialization,
      53             :       tmpl::list<InitializeResidualMonitor<FieldsTag, OptionsGroup>>>>;
      54             :   using simple_tags_from_options = Parallel::get_simple_tags_from_options<
      55             :       Parallel::get_initialization_actions_list<phase_dependent_action_list>>;
      56             : 
      57             :   static void execute_next_phase(
      58             :       const Parallel::Phase next_phase,
      59             :       Parallel::CProxy_GlobalCache<Metavariables>& global_cache) {
      60             :     auto& local_cache = *Parallel::local_branch(global_cache);
      61             :     Parallel::get_parallel_component<ResidualMonitor>(local_cache)
      62             :         .start_phase(next_phase);
      63             :   }
      64             : };
      65             : 
      66             : template <typename FieldsTag, typename OptionsGroup>
      67             : struct InitializeResidualMonitor {
      68             :  private:
      69             :   using fields_tag = FieldsTag;
      70             :   using residual_square_tag = LinearSolver::Tags::MagnitudeSquare<
      71             :       db::add_tag_prefix<LinearSolver::Tags::Residual, fields_tag>>;
      72             :   using initial_residual_magnitude_tag =
      73             :       ::Tags::Initial<LinearSolver::Tags::Magnitude<
      74             :           db::add_tag_prefix<LinearSolver::Tags::Residual, fields_tag>>>;
      75             : 
      76             :  public:
      77             :   using simple_tags =
      78             :       tmpl::list<residual_square_tag, initial_residual_magnitude_tag>;
      79             :   using compute_tags = tmpl::list<>;
      80             :   template <typename DbTagsList, typename... InboxTags, typename Metavariables,
      81             :             typename ArrayIndex, typename ActionList,
      82             :             typename ParallelComponent>
      83             :   static Parallel::iterable_action_return_t apply(
      84             :       db::DataBox<DbTagsList>& box,
      85             :       const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
      86             :       const Parallel::GlobalCache<Metavariables>& /*cache*/,
      87             :       const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
      88             :       const ParallelComponent* const /*meta*/) {
      89             :     // The `InitializeResidual` action populates these tags with initial values
      90             :     Initialization::mutate_assign<simple_tags>(
      91             :         make_not_null(&box), std::numeric_limits<double>::signaling_NaN(),
      92             :         std::numeric_limits<double>::signaling_NaN());
      93             :     return {Parallel::AlgorithmExecution::Pause, std::nullopt};
      94             :   }
      95             : };
      96             : 
      97             : }  // namespace LinearSolver::cg::detail

Generated by: LCOV version 1.14