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 "Parallel/Reduction.hpp" 17 : #include "Utilities/Functional.hpp" 18 : #include "Utilities/PrettyType.hpp" 19 : #include "Utilities/System/ParallelInfo.hpp" 20 : 21 : namespace NonlinearSolver::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 size_t globalization_iteration_id, 30 : const double residual_magnitude, const double step_length, 31 : Parallel::GlobalCache<Metavariables>& cache) { 32 : auto& reduction_writer = Parallel::get_parallel_component< 33 : observers::ObserverWriter<Metavariables>>(cache); 34 : Parallel::threaded_action<observers::ThreadedActions::WriteReductionDataRow>( 35 : // Node 0 is always the writer, so directly call the component on that 36 : // node 37 : reduction_writer[0], 38 : std::string{"/" + pretty_type::name<OptionsGroup>() + "Residuals"}, 39 : std::vector<std::string>{"Iteration", "GlobalizationStep", "Residual", 40 : "StepLength"}, 41 : std::make_tuple(iteration_id, globalization_iteration_id, 42 : residual_magnitude, step_length)); 43 : } 44 : 45 : } // namespace NonlinearSolver::observe_detail