ResidualMonitor.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <limits>
7 
10 #include "IO/Logging/Tags.hpp"
11 #include "IO/Observer/Actions/RegisterSingleton.hpp"
12 #include "NumericalAlgorithms/Convergence/Tags.hpp"
13 #include "Parallel/Actions/SetupDataBox.hpp"
15 #include "Parallel/GlobalCache.hpp"
16 #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
18 #include "ParallelAlgorithms/NonlinearSolver/Observe.hpp"
20 
21 /// \cond
22 namespace tuples {
23 template <typename...>
24 class TaggedTuple;
25 } // namespace tuples
26 namespace NonlinearSolver::newton_raphson::detail {
27 template <typename Metavariables, typename FieldsTag>
28 struct InitializeResidualMonitor;
29 } // namespace NonlinearSolver::newton_raphson::detail
30 /// \endcond
31 
32 namespace NonlinearSolver::newton_raphson::detail {
33 
34 template <typename Metavariables, typename FieldsTag, typename OptionsGroup>
35 struct ResidualMonitor {
36  using chare_type = Parallel::Algorithms::Singleton;
37  using const_global_cache_tags =
38  tmpl::list<logging::Tags::Verbosity<OptionsGroup>,
42  using metavariables = Metavariables;
43  using phase_dependent_action_list = tmpl::list<
45  typename Metavariables::Phase, Metavariables::Phase::Initialization,
46  tmpl::list<::Actions::SetupDataBox,
47  InitializeResidualMonitor<FieldsTag, OptionsGroup>>>,
49  typename Metavariables::Phase,
50  Metavariables::Phase::RegisterWithObserver,
52  NonlinearSolver::observe_detail::Registration<OptionsGroup>>>>>;
53 
54  using initialization_tags = Parallel::get_initialization_tags<
56 
57  static void initialize(
58  Parallel::CProxy_GlobalCache<Metavariables>& /*global_cache*/) noexcept {}
59 
60  static void execute_next_phase(
61  const typename Metavariables::Phase next_phase,
62  Parallel::CProxy_GlobalCache<Metavariables>& global_cache) noexcept {
63  auto& local_cache = *(global_cache.ckLocalBranch());
64  Parallel::get_parallel_component<ResidualMonitor>(local_cache)
65  .start_phase(next_phase);
66  }
67 };
68 
69 template <typename FieldsTag, typename OptionsGroup>
70 struct InitializeResidualMonitor {
71  private:
72  using fields_tag = FieldsTag;
73  using residual_tag =
75  using residual_magnitude_square_tag =
77  using initial_residual_magnitude_tag =
79  using prev_residual_magnitude_square_tag =
81 
82  public:
83  using simple_tags =
84  db::AddSimpleTags<residual_magnitude_square_tag,
85  initial_residual_magnitude_tag,
87  prev_residual_magnitude_square_tag>;
88  using compute_tags = tmpl::list<>;
89 
90  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
91  typename ArrayIndex, typename ActionList,
92  typename ParallelComponent>
93  static auto apply(db::DataBox<DbTagsList>& box,
95  const Parallel::GlobalCache<Metavariables>& /*cache*/,
96  const ArrayIndex& /*array_index*/,
97  const ActionList /*meta*/,
98  const ParallelComponent* const /*meta*/) noexcept {
99  Initialization::mutate_assign<simple_tags>(
104  return std::make_tuple(std::move(box), true);
105  }
106 };
107 
108 } // namespace NonlinearSolver::newton_raphson::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:99
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
Tags.hpp
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
NonlinearSolver::Tags::SufficientDecrease
Sufficient decrease parameter of the line search globalization.
Definition: Tags.hpp:195
NonlinearSolver::Tags::StepLength
The length of nonlinear solver steps.
Definition: Tags.hpp:182
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
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
NonlinearSolver::Tags::MaxGlobalizationSteps
The maximum number of allowed globalization steps.
Definition: Tags.hpp:227
observers::Actions::RegisterSingletonWithObserverWriter
Registers a singleton with the ObserverWriter.
Definition: RegisterSingleton.hpp:30
db::AddSimpleTags
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:856
Parallel::Algorithms::Singleton
A struct that stores the charm++ types relevant for a particular singleton component.
Definition: AlgorithmSingletonDeclarations.hpp:29
limits
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
Prefixes.hpp
std::numeric_limits
NonlinearSolver::Tags::Globalization
Prefix indicating the Tag is related to the globalization procedure.
Definition: Tags.hpp:240