ResidualMonitor.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <limits>
8 #include <tuple>
9 #include <utility>
10 
12 #include "DataStructures/DataBox/PrefixHelpers.hpp"
13 #include "IO/Observer/Actions/RegisterSingleton.hpp"
14 #include "Informer/Tags.hpp"
15 #include "NumericalAlgorithms/Convergence/Tags.hpp"
16 #include "Parallel/Actions/SetupDataBox.hpp"
18 #include "Parallel/GlobalCache.hpp"
19 #include "Parallel/ParallelComponentHelpers.hpp"
20 #include "Parallel/PhaseDependentActionList.hpp"
21 #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
22 #include "ParallelAlgorithms/LinearSolver/Observe.hpp"
24 #include "Utilities/TMPL.hpp"
25 
26 /// \cond
27 namespace tuples {
28 template <typename...>
29 class TaggedTuple;
30 } // namespace tuples
31 namespace LinearSolver::cg::detail {
32 template <typename FieldsTag, typename OptionsGroup>
33 struct InitializeResidualMonitor;
34 } // namespace LinearSolver::cg::detail
35 /// \endcond
36 
37 namespace LinearSolver::cg::detail {
38 
39 template <typename Metavariables, typename FieldsTag, typename OptionsGroup>
40 struct ResidualMonitor {
41  using chare_type = Parallel::Algorithms::Singleton;
42  using const_global_cache_tags =
43  tmpl::list<logging::Tags::Verbosity<OptionsGroup>,
45  using metavariables = Metavariables;
46  // The actions in `ResidualMonitorActions.hpp` are invoked as simple actions
47  // on this component as the result of reductions from the actions in
48  // `ElementActions.hpp`. See `LinearSolver::cg::ConjugateGradient` for
49  // details.
50  using phase_dependent_action_list = tmpl::list<
52  typename Metavariables::Phase, Metavariables::Phase::Initialization,
53  tmpl::list<::Actions::SetupDataBox,
54  InitializeResidualMonitor<FieldsTag, OptionsGroup>>>,
56  typename Metavariables::Phase,
57  Metavariables::Phase::RegisterWithObserver,
59  LinearSolver::observe_detail::Registration<OptionsGroup>>>>>;
60  using initialization_tags = Parallel::get_initialization_tags<
62 
63  static void execute_next_phase(
64  const typename Metavariables::Phase next_phase,
65  Parallel::CProxy_GlobalCache<Metavariables>& global_cache) noexcept {
66  auto& local_cache = *(global_cache.ckLocalBranch());
67  Parallel::get_parallel_component<ResidualMonitor>(local_cache)
68  .start_phase(next_phase);
69  }
70 };
71 
72 template <typename FieldsTag, typename OptionsGroup>
73 struct InitializeResidualMonitor {
74  private:
75  using fields_tag = FieldsTag;
76  using residual_square_tag = LinearSolver::Tags::MagnitudeSquare<
78  using initial_residual_magnitude_tag =
81 
82  public:
83  using simple_tags =
84  tmpl::list<residual_square_tag, initial_residual_magnitude_tag>;
85  using compute_tags = tmpl::list<>;
86  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
87  typename ArrayIndex, typename ActionList,
88  typename ParallelComponent>
89  static auto apply(db::DataBox<DbTagsList>& box,
90  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
91  const Parallel::GlobalCache<Metavariables>& /*cache*/,
92  const ArrayIndex& /*array_index*/,
93  const ActionList /*meta*/,
94  const ParallelComponent* const /*meta*/) noexcept {
95  // The `InitializeResidual` action populates these tags with initial values
96  Initialization::mutate_assign<simple_tags>(
99  return std::make_tuple(std::move(box), true);
100  }
101 };
102 
103 } // namespace LinearSolver::cg::detail
std::apply
T apply(T... args)
Actions::SetupDataBox
Add into the DataBox default constructed items for the collection of tags requested by any of the act...
Definition: SetupDataBox.hpp:102
LinearSolver::Tags::MagnitudeSquare
The magnitude square w.r.t. the LinearSolver::inner_product
Definition: Tags.hpp:100
utility
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
Tags::Initial
Prefix indicating the initial value of a quantity.
Definition: Prefixes.hpp:85
GlobalCache.hpp
db::add_tag_prefix
typename detail::add_tag_prefix_impl< Prefix, Tag, Args... >::type add_tag_prefix
Definition: PrefixHelpers.hpp:51
tuple
Tags.hpp
Parallel::get_initialization_tags
tmpl::remove_duplicates< tmpl::flatten< tmpl::list< AllocationTagsList, tmpl::transform< InitializationActionsList, detail::get_initialization_tags_from_action< tmpl::_1 > >> >> get_initialization_tags
Given a list of initialization actions, and possibly a list of tags needed for allocation of an array...
Definition: ParallelComponentHelpers.hpp:254
Parallel::get_initialization_actions_list
tmpl::flatten< tmpl::transform< PhaseDepActionList, detail::get_initialization_actions_list< tmpl::_1 > >> get_initialization_actions_list
Given the phase dependent action list, return the list of actions in the Initialization phase (or an ...
Definition: ParallelComponentHelpers.hpp:218
Parallel::PhaseActions
List of all the actions to be executed in the specified phase.
Definition: PhaseDependentActionList.hpp:16
DataBox.hpp
cstddef
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
observers::Actions::RegisterSingletonWithObserverWriter
Registers a singleton with the ObserverWriter.
Definition: RegisterSingleton.hpp:30
Parallel::Algorithms::Singleton
A struct that stores the charm++ types relevant for a particular singleton component.
Definition: AlgorithmSingletonDeclarations.hpp:29
limits
LinearSolver::Tags::Magnitude
The magnitude w.r.t. the LinearSolver::inner_product
Definition: Tags.hpp:114
AlgorithmSingleton.hpp
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
Convergence::Tags::Criteria
Convergence::Criteria that determine the iterative algorithm has converged
Definition: Tags.hpp:43
std::numeric_limits
TMPL.hpp