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 : #include "Utilities/System/ParallelInfo.hpp"
20 :
21 : namespace LinearSolver {
22 : namespace observe_detail {
23 :
24 : /*!
25 : * \brief Contributes data from the residual monitor to the reduction observer
26 : */
27 : template <typename OptionsGroup, typename ParallelComponent,
28 : typename Metavariables>
29 : void contribute_to_reduction_observer(
30 : const size_t iteration_id, const double residual_magnitude,
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 : // When multiple linear solves are performed, e.g. for the nonlinear
39 : // solver, we'll need to write into separate subgroups, e.g.:
40 : // `/linear_residuals/<nonlinear_iteration_id>`
41 : std::string{"/" + pretty_type::name<OptionsGroup>() + "Residuals"},
42 : std::vector<std::string>{"Iteration", "Walltime", "Residual"},
43 : std::make_tuple(iteration_id, sys::wall_time(), residual_magnitude));
44 : }
45 :
46 : } // namespace observe_detail
47 : } // namespace LinearSolver
|