Observe.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
7 #include "IO/Observer/ObservationId.hpp"
8 #include "IO/Observer/ObserverComponent.hpp"
9 #include "IO/Observer/ReductionActions.hpp"
12 #include "Parallel/Info.hpp"
13 #include "Parallel/Invoke.hpp"
14 #include "Parallel/Reduction.hpp"
15 
16 namespace LinearSolver {
17 namespace observe_detail {
18 
19 using reduction_data = Parallel::ReductionData<
20  // Iteration
22  // Residual
24 
25 struct ObservationType {};
26 
27 /*!
28  * \brief Contributes data from the residual monitor to the reduction observer
29  *
30  * With:
31  * - `residual_magnitude_tag` = `db::add_tag_prefix<
32  * LinearSolver::Tags::Magnitude, db::add_tag_prefix<
33  * LinearSolver::Tags::Residual, fields_tag>>`
34  *
35  * Uses:
36  * - System:
37  * - `fields_tag`
38  * - DataBox:
39  * - `LinearSolver::Tags::IterationId`
40  * - `residual_magnitude_tag`
41  */
42 template <typename DbTagsList, typename Metavariables>
43 void contribute_to_reduction_observer(
46  using fields_tag = typename Metavariables::system::fields_tag;
47  using residual_magnitude_tag = db::add_tag_prefix<
50 
51  const auto observation_id = observers::ObservationId(
52  get<LinearSolver::Tags::IterationId>(box), ObservationType{});
53  auto& reduction_writer = Parallel::get_parallel_component<
55  Parallel::threaded_action<observers::ThreadedActions::WriteReductionData>(
56  // Node 0 is always the writer, so directly call the component on that
57  // node
58  reduction_writer[0], observation_id,
59  // When multiple linear solves are performed, e.g. for the nonlinear
60  // solver, we'll need to write into separate subgroups, e.g.:
61  // `/linear_residuals/<nonlinear_iteration_id>`
62  std::string{"/linear_residuals"},
63  std::vector<std::string>{"Iteration", "Residual"},
64  reduction_data{get<LinearSolver::Tags::IterationId>(box),
65  get<residual_magnitude_tag>(box)});
66 }
67 
68 } // namespace observe_detail
69 } // namespace LinearSolver
The magnitude w.r.t. the LinearSolver::inner_product
Definition: Tags.hpp:115
Prefix< DataBox_detail::dispatch_add_tag_prefix_impl< Prefix, Tag, Args... >, Args... > add_tag_prefix
Wrap Tag in Prefix<_, Args...>, also wrapping variables tags if Tag is a Tags::Variables.
Definition: DataBoxTag.hpp:533
Definition: Variables.hpp:46
Defines functions for interfacing with the parallelization framework.
Defines DataBox tags for the linear solver.
Functionality for solving linear systems of equations.
Definition: TerminateIfConverged.hpp:22
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:55
Defines classes and functions used for manipulating DataBox&#39;s.
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
auto get_parallel_component(ConstGlobalCache< Metavariables > &cache) noexcept -> Parallel::proxy_from_parallel_component< ConstGlobalCache_detail::get_component_if_mocked< typename Metavariables::component_list, ParallelComponentTag >> &
Access the Charm++ proxy associated with a ParallelComponent.
Definition: ConstGlobalCache.hpp:163
A type-erased identifier that combines the identifier&#39;s type and hash used to uniquely identify an ob...
Definition: ObservationId.hpp:42
Defines class template ConstGlobalCache.
The data to be reduced, and invokables to be called whenever two reduction messages are combined and ...
Definition: Reduction.hpp:64