ResidualMonitor.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include "AlgorithmSingleton.hpp"
9 #include "Informer/Tags.hpp"
10 #include "Informer/Verbosity.hpp"
11 #include "NumericalAlgorithms/LinearSolver/Convergence.hpp"
14 #include "Options/Options.hpp"
16 #include "Parallel/Info.hpp"
17 #include "Parallel/Invoke.hpp"
18 
19 /// \cond
20 namespace tuples {
21 template <typename...>
22 class TaggedTuple;
23 } // namespace tuples
24 namespace LinearSolver {
25 namespace cg_detail {
26 template <typename Metavariables>
27 struct InitializeResidualMonitor;
28 } // namespace cg_detail
29 } // namespace LinearSolver
30 /// \endcond
31 
32 namespace LinearSolver {
33 namespace cg_detail {
34 
35 template <typename Metavariables>
36 struct ResidualMonitor {
37  struct Verbosity {
38  using type = ::Verbosity;
39  static constexpr OptionString help = {"Verbosity"};
40  static type default_value() noexcept { return ::Verbosity::Quiet; }
41  };
42 
43  using chare_type = Parallel::Algorithms::Singleton;
44  using const_global_cache_tag_list = tmpl::list<>;
45  using options =
46  tmpl::list<Verbosity, LinearSolver::Tags::ConvergenceCriteria>;
47  using metavariables = Metavariables;
48  using action_list = tmpl::list<>;
49  using initial_databox = db::compute_databox_type<tmpl::append<
50  typename InitializeResidualMonitor<Metavariables>::simple_tags,
51  typename InitializeResidualMonitor<Metavariables>::compute_tags>>;
52 
53  static void initialize(
54  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache,
55  ::Verbosity verbosity,
56  LinearSolver::ConvergenceCriteria convergence_criteria) noexcept {
57  Parallel::simple_action<InitializeResidualMonitor<Metavariables>>(
58  Parallel::get_parallel_component<ResidualMonitor>(
59  *(global_cache.ckLocalBranch())),
60  // clang-tidy: std::move of trivially-copyable type
61  std::move(verbosity), // NOLINT
62  std::move(convergence_criteria)); // NOLINT
63  }
64 
65  static void execute_next_phase(
66  const typename Metavariables::Phase /*next_phase*/,
67  const Parallel::CProxy_ConstGlobalCache<
68  Metavariables>& /*global_cache*/) noexcept {}
69 };
70 
71 template <typename Metavariables>
72 struct InitializeResidualMonitor {
73  private:
74  using fields_tag = typename Metavariables::system::fields_tag;
75  using residual_square_tag = db::add_tag_prefix<
78  using initial_residual_magnitude_tag = db::add_tag_prefix<
82  db::add_tag_prefix<LinearSolver::Tags::Residual, fields_tag>>>;
83 
84  public:
85  using simple_tags =
88  ::LinearSolver::Tags::IterationId, residual_square_tag,
89  initial_residual_magnitude_tag>;
90  using compute_tags = db::AddComputeTags<
93 
94  template <typename... InboxTags, typename ArrayIndex, typename ActionList,
95  typename ParallelComponent>
96  static auto apply(
97  const db::DataBox<tmpl::list<>>& /*box*/,
100  const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
101  const ParallelComponent* const /*meta*/, ::Verbosity verbosity,
102  LinearSolver::ConvergenceCriteria convergence_criteria) noexcept {
103  auto box = db::create<simple_tags, compute_tags>(
104  // clang-tidy: std::move of trivially-copyable type
105  std::move(verbosity), // NOLINT
106  std::move(convergence_criteria), // NOLINT
110  return std::make_tuple(std::move(box));
111  }
112 };
113 
114 } // namespace cg_detail
115 } // 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
T signaling_NaN(T... args)
Definition: TaggedTuple.hpp:25
The magnitude square w.r.t. the LinearSolver::inner_product
Definition: Tags.hpp:101
Defines classes and functions for making classes creatable from input files.
Define prefixes for DataBox tags.
Definition: Tags.hpp:90
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:27
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.
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
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
Compute the LinearSolver::Magnitude of a tag from its LinearSolver::MagnitudeSquare.
Definition: Tags.hpp:130
Identifies a step in the linear solver algorithm.
Definition: IterationId.hpp:25
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