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 <string> 8 : #include <tuple> 9 : #include <utility> 10 : #include <vector> 11 : 12 : #include "IO/Observer/ObserverComponent.hpp" 13 : #include "IO/Observer/ReductionActions.hpp" 14 : #include "Parallel/GlobalCache.hpp" 15 : #include "Parallel/Invoke.hpp" 16 : #include "ParallelAlgorithms/LinearSolver/Tags.hpp" 17 : #include "Utilities/Functional.hpp" 18 : #include "Utilities/PrettyType.hpp" 19 : 20 : namespace LinearSolver { 21 : namespace observe_detail { 22 : 23 : /*! 24 : * \brief Contributes data from the residual monitor to the reduction observer 25 : */ 26 : template <typename OptionsGroup, typename ParallelComponent, 27 : typename Metavariables> 28 : void contribute_to_reduction_observer( 29 : const size_t iteration_id, const double residual_magnitude, 30 : Parallel::GlobalCache<Metavariables>& cache) { 31 : auto& reduction_writer = Parallel::get_parallel_component< 32 : observers::ObserverWriter<Metavariables>>(cache); 33 : Parallel::threaded_action<observers::ThreadedActions::WriteReductionDataRow>( 34 : // Node 0 is always the writer, so directly call the component on that 35 : // node 36 : reduction_writer[0], 37 : // When multiple linear solves are performed, e.g. for the nonlinear 38 : // solver, we'll need to write into separate subgroups, e.g.: 39 : // `/linear_residuals/<nonlinear_iteration_id>` 40 : std::string{"/" + pretty_type::name<OptionsGroup>() + "Residuals"}, 41 : std::vector<std::string>{"Iteration", "Residual"}, 42 : std::make_tuple(iteration_id, residual_magnitude)); 43 : } 44 : 45 : } // namespace observe_detail 46 : } // namespace LinearSolver