ResidualMonitor.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include "AlgorithmSingleton.hpp"
10 #include "Informer/Tags.hpp"
11 #include "Informer/Verbosity.hpp"
12 #include "NumericalAlgorithms/LinearSolver/Convergence.hpp"
15 #include "Options/Options.hpp"
17 #include "Parallel/Info.hpp"
18 #include "Parallel/Invoke.hpp"
19 
20 /// \cond
21 namespace tuples {
22 template <typename...>
23 class TaggedTuple;
24 } // namespace tuples
25 namespace LinearSolver {
26 namespace gmres_detail {
27 template <typename Metavariables>
28 struct InitializeResidualMonitor;
29 } // namespace gmres_detail
30 } // namespace LinearSolver
31 /// \endcond
32 
33 namespace LinearSolver {
34 namespace gmres_detail {
35 
36 template <typename Metavariables>
37 struct ResidualMonitor {
38  struct Verbosity {
39  using type = ::Verbosity;
40  static constexpr OptionString help = {"Verbosity"};
41  static type default_value() { return ::Verbosity::Quiet; }
42  };
43 
44  using chare_type = Parallel::Algorithms::Singleton;
45  using const_global_cache_tag_list = tmpl::list<>;
46  using options =
47  tmpl::list<Verbosity, LinearSolver::Tags::ConvergenceCriteria>;
48  using metavariables = Metavariables;
49  using action_list = tmpl::list<>;
50  using initial_databox = db::compute_databox_type<tmpl::append<
51  typename InitializeResidualMonitor<Metavariables>::simple_tags,
52  typename InitializeResidualMonitor<Metavariables>::compute_tags>>;
53 
54  static void initialize(
55  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache,
56  ::Verbosity verbosity,
57  LinearSolver::ConvergenceCriteria convergence_criteria) noexcept {
58  Parallel::simple_action<InitializeResidualMonitor<Metavariables>>(
59  Parallel::get_parallel_component<ResidualMonitor>(
60  *(global_cache.ckLocalBranch())),
61  // clang-tidy: std::move of trivially-copyable type
62  std::move(verbosity), // NOLINT
63  std::move(convergence_criteria)); // NOLINT
64  }
65 
66  static void execute_next_phase(
67  const typename Metavariables::Phase /*next_phase*/,
68  const Parallel::CProxy_ConstGlobalCache<
69  Metavariables>& /*global_cache*/) noexcept {}
70 };
71 
72 template <typename Metavariables>
73 struct InitializeResidualMonitor {
74  private:
75  using fields_tag = typename Metavariables::system::fields_tag;
76  using residual_magnitude_tag = db::add_tag_prefix<
79  using initial_residual_magnitude_tag =
81  using orthogonalization_iteration_id_tag =
84  using orthogonalization_history_tag =
86  fields_tag>;
87 
88  public:
89  using simple_tags = db::AddSimpleTags<
91  residual_magnitude_tag, initial_residual_magnitude_tag,
92  LinearSolver::Tags::IterationId, orthogonalization_iteration_id_tag,
93  orthogonalization_history_tag>;
94  using compute_tags =
96 
97  template <typename... InboxTags, typename ArrayIndex, typename ActionList,
98  typename ParallelComponent>
99  static auto apply(
100  const db::DataBox<tmpl::list<>>& /*box*/,
103  const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
104  const ParallelComponent* const /*meta*/, ::Verbosity verbosity,
105  LinearSolver::ConvergenceCriteria convergence_criteria) noexcept {
106  auto box = db::create<simple_tags, compute_tags>(
107  // clang-tidy: std::move of trivially-copyable type
108  std::move(verbosity), // NOLINT
109  std::move(convergence_criteria), // NOLINT
112  IterationId{0}, DenseMatrix<double>{2, 1, 0.});
113  return std::make_tuple(std::move(box));
114  }
115 };
116 
117 } // namespace gmres_detail
118 } // 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
A Hessenberg matrix built up during an orthogonalization procedure.
Definition: Tags.hpp:156
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
T signaling_NaN(T... args)
Definition: TaggedTuple.hpp:25
Defines classes and functions for making classes creatable from input files.
Define prefixes for DataBox tags.
Criteria that determine the linear solve has converged.
Definition: Convergence.hpp:58
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args)
Apply the function f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1595
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:26
A dynamically sized matrix of arbitrary type.
Definition: DenseMatrix.hpp:29
Holds an IterationId that identifies a step in the linear solver algorithm.
Definition: Tags.hpp:66
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
Defines classes and functions used for manipulating DataBox&#39;s.
Defines class DenseMatrix.
Verbosity
Indicates how much informative output a class should output.
Definition: Verbosity.hpp:16
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:1227
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
The prefix for tags related to an orthogonalization procedurce.
Definition: Tags.hpp:143
LinearSolver::ConvergenceCriteria that determine the linear solve has converged
Definition: Tags.hpp:193
typename DataBox_detail::compute_dbox_type< get_items< TagList >, get_compute_items< TagList > >::type compute_databox_type
Returns the type of the DataBox that would be constructed from the TagList of tags.
Definition: DataBox.hpp:1827
Definition: SolvePoissonProblem.hpp:38
Defines class template ConstGlobalCache.
Defines class IterationId.
tmpl::flatten< tmpl::list< Tags... > > AddComputeTags
List of Compute Item Tags to add to the DataBox.
Definition: DataBox.hpp:1234