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 <utility> 10 : 11 : #include "DataStructures/DataBox/DataBox.hpp" 12 : #include "DataStructures/DataBox/PrefixHelpers.hpp" 13 : #include "IO/Logging/Tags.hpp" 14 : #include "NumericalAlgorithms/Convergence/Tags.hpp" 15 : #include "Parallel/AlgorithmExecution.hpp" 16 : #include "Parallel/Algorithms/AlgorithmSingleton.hpp" 17 : #include "Parallel/GlobalCache.hpp" 18 : #include "Parallel/Local.hpp" 19 : #include "Parallel/ParallelComponentHelpers.hpp" 20 : #include "Parallel/Phase.hpp" 21 : #include "Parallel/PhaseDependentActionList.hpp" 22 : #include "ParallelAlgorithms/Initialization/MutateAssign.hpp" 23 : #include "ParallelAlgorithms/LinearSolver/Tags.hpp" 24 : #include "Utilities/TMPL.hpp" 25 : 26 : /// \cond 27 : namespace tuples { 28 : template <typename...> 29 : class TaggedTuple; 30 : } // namespace tuples 31 : namespace LinearSolver::gmres::detail { 32 : template <typename FieldsTag, typename OptionsGroup> 33 : struct InitializeResidualMonitor; 34 : } // namespace LinearSolver::gmres::detail 35 : /// \endcond 36 : 37 : namespace LinearSolver::gmres::detail { 38 : 39 : template <typename Metavariables, typename FieldsTag, typename OptionsGroup> 40 : struct ResidualMonitor { 41 : using chare_type = Parallel::Algorithms::Singleton; 42 : static constexpr bool checkpoint_data = true; 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::gmres::Gmres` for details. 50 : using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions< 51 : Parallel::Phase::Initialization, 52 : tmpl::list<InitializeResidualMonitor<FieldsTag, OptionsGroup>>>>; 53 : using simple_tags_from_options = Parallel::get_simple_tags_from_options< 54 : Parallel::get_initialization_actions_list<phase_dependent_action_list>>; 55 : 56 : static void execute_next_phase( 57 : const Parallel::Phase next_phase, 58 : Parallel::CProxy_GlobalCache<Metavariables>& global_cache) { 59 : auto& local_cache = *Parallel::local_branch(global_cache); 60 : Parallel::get_parallel_component<ResidualMonitor>(local_cache) 61 : .start_phase(next_phase); 62 : } 63 : }; 64 : 65 : template <typename FieldsTag, typename OptionsGroup> 66 : struct InitializeResidualMonitor { 67 : private: 68 : using fields_tag = FieldsTag; 69 : using residual_magnitude_tag = LinearSolver::Tags::Magnitude< 70 : db::add_tag_prefix<LinearSolver::Tags::Residual, fields_tag>>; 71 : using initial_residual_magnitude_tag = 72 : ::Tags::Initial<residual_magnitude_tag>; 73 : using previous_residual_magnitude_tag = 74 : ::Tags::Previous<residual_magnitude_tag>; 75 : using orthogonalization_history_tag = 76 : LinearSolver::Tags::OrthogonalizationHistory<fields_tag>; 77 : 78 : public: 79 : using simple_tags = tmpl::list<initial_residual_magnitude_tag, 80 : previous_residual_magnitude_tag, 81 : orthogonalization_history_tag>; 82 : using compute_tags = tmpl::list<>; 83 : 84 : template <typename DbTagsList, typename... InboxTags, typename ArrayIndex, 85 : typename Metavariables, typename ActionList, 86 : typename ParallelComponent> 87 : static Parallel::iterable_action_return_t apply( 88 : db::DataBox<DbTagsList>& box, 89 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, 90 : const Parallel::GlobalCache<Metavariables>& /*cache*/, 91 : const ArrayIndex& /*array_index*/, const ActionList /*meta*/, 92 : const ParallelComponent* const /*meta*/) { 93 : // The `InitializeResidualMagnitude` action populates these tags 94 : // with initial values 95 : Initialization::mutate_assign<tmpl::list<initial_residual_magnitude_tag, 96 : previous_residual_magnitude_tag>>( 97 : make_not_null(&box), std::numeric_limits<double>::signaling_NaN(), 98 : std::numeric_limits<double>::signaling_NaN()); 99 : return {Parallel::AlgorithmExecution::Pause, std::nullopt}; 100 : } 101 : }; 102 : 103 : } // namespace LinearSolver::gmres::detail