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"
10 #include "IO/Observer/TypeOfObservation.hpp"
12 #include "Parallel/Info.hpp"
13 #include "Parallel/Invoke.hpp"
14 #include "Parallel/Reduction.hpp"
16 
17 namespace LinearSolver {
18 namespace observe_detail {
19 
20 using reduction_data = Parallel::ReductionData<
21  // Iteration
23  // Residual
25 
26 struct ObservationType {};
27 
28 struct Registration {
29  template <typename ParallelComponent, typename DbTagsList,
30  typename ArrayIndex>
32  register_info(const db::DataBox<DbTagsList>& /*box*/,
33  const ArrayIndex& /*array_index*/) noexcept {
34  observers::ObservationId fake_initial_observation_id{0., ObservationType{}};
35  return {
37  std::move(fake_initial_observation_id) // NOLINT
38  };
39  }
40 };
41 
42 /*!
43  * \brief Contributes data from the residual monitor to the reduction observer
44  *
45  * With:
46  * - `residual_magnitude_tag` = `db::add_tag_prefix<
47  * LinearSolver::Tags::Magnitude, db::add_tag_prefix<
48  * LinearSolver::Tags::Residual, fields_tag>>`
49  *
50  * Uses:
51  * - System:
52  * - `fields_tag`
53  * - DataBox:
54  * - `LinearSolver::Tags::IterationId`
55  * - `residual_magnitude_tag`
56  */
57 template <typename FieldsTag, typename DbTagsList, typename Metavariables>
58 void contribute_to_reduction_observer(
61  using fields_tag = FieldsTag;
62  using residual_magnitude_tag = db::add_tag_prefix<
65 
66  const auto observation_id = observers::ObservationId(
67  get<LinearSolver::Tags::IterationId>(box), ObservationType{});
68  auto& reduction_writer = Parallel::get_parallel_component<
70  Parallel::threaded_action<observers::ThreadedActions::WriteReductionData>(
71  // Node 0 is always the writer, so directly call the component on that
72  // node
73  reduction_writer[0], observation_id,
74  // When multiple linear solves are performed, e.g. for the nonlinear
75  // solver, we'll need to write into separate subgroups, e.g.:
76  // `/linear_residuals/<nonlinear_iteration_id>`
77  std::string{"/linear_residuals"},
78  std::vector<std::string>{"Iteration", "Residual"},
79  reduction_data{get<LinearSolver::Tags::IterationId>(box),
80  get<residual_magnitude_tag>(box)});
81 }
82 
83 } // namespace observe_detail
84 } // namespace LinearSolver
The magnitude w.r.t. the LinearSolver::inner_product
Definition: Tags.hpp:125
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:616
Defines functions for interfacing with the parallelization framework.
Functionality for solving linear systems of equations.
Definition: TerminateIfConverged.hpp:22
The sender will only perform reduction observations.
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:48
Defines classes and functions used for manipulating DataBox&#39;s.
Helpers for derived class registration.
Definition: Registration.hpp:32
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:135
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:222
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.
Defines DataBox tags for the linear solver.
The data to be reduced, and invokables to be called whenever two reduction messages are combined and ...
Definition: Reduction.hpp:64