Tags.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 /// \file
5 /// Defines DataBox tags for the linear solver
6 
7 #pragma once
8 
9 #include <cstddef>
10 #include <string>
11 #include <utility>
12 #include <vector>
13 
16 #include "NumericalAlgorithms/LinearSolver/Convergence.hpp"
18 #include "Utilities/Requires.hpp"
19 #include "Utilities/TypeTraits.hpp"
20 
21 /*!
22  * \ingroup LinearSolverGroup
23  * \brief Functionality for solving linear systems of equations
24  */
25 namespace LinearSolver {
26 
27 /*!
28  * \ingroup LinearSolverGroup
29  * \brief The \ref DataBoxGroup tags associated with the linear solver
30  */
31 namespace Tags {
32 
33 /*!
34  * \brief The operand that the local linear operator \f$A\f$ is applied to
35  *
36  * \details The result of the operation should be wrapped in
37  * `LinearSolver::Tags::OperatorAppliedTo`.
38  */
39 template <typename Tag>
41  static std::string name() noexcept {
42  // Add "Linear" prefix to abbreviate the namespace for uniqueness
43  return "LinearOperand(" + Tag::name() + ")";
44  }
45  using type = typename Tag::type;
46  using tag = Tag;
47 };
48 
49 /*!
50  * \brief The linear operator \f$A\f$ applied to the data in `Tag`
51  */
52 template <typename Tag>
54  static std::string name() noexcept {
55  // Add "Linear" prefix to abbreviate the namespace for uniqueness
56  return "LinearOperatorAppliedTo(" + Tag::name() + ")";
57  }
58  using type = typename Tag::type;
59  using tag = Tag;
60 };
61 
62 /*!
63  * \brief Holds an `IterationId` that identifies a step in the linear solver
64  * algorithm
65  */
67  static std::string name() noexcept {
68  // Add "Linear" prefix to abbreviate the namespace for uniqueness
69  return "LinearIterationId";
70  }
72  template <typename Tag>
74 };
75 
76 /*!
77  * \brief The residual \f$r=b - Ax\f$
78  */
79 template <typename Tag>
81  static std::string name() noexcept {
82  // Add "Linear" prefix to abbreviate the namespace for uniqueness
83  return "LinearResidual(" + Tag::name() + ")";
84  }
85  using type = typename Tag::type;
86  using tag = Tag;
87 };
88 
89 template <typename Tag>
91  static std::string name() noexcept { return "Initial(" + Tag::name() + ")"; }
92  using type = typename Tag::type;
93  using tag = Tag;
94 };
95 
96 /*!
97  * \brief The magnitude square \f$\langle \cdot,\cdot\rangle\f$ w.r.t.
98  * the `LinearSolver::inner_product`
99  */
100 template <typename Tag>
102  static std::string name() noexcept {
103  // Add "Linear" prefix to abbreviate the namespace for uniqueness
104  return "LinearMagnitudeSquare(" + Tag::name() + ")";
105  }
106  using type = double;
107  using tag = Tag;
108 };
109 
110 /*!
111  * \brief The magnitude \f$\sqrt{\langle \cdot,\cdot\rangle}\f$ w.r.t.
112  * the `LinearSolver::inner_product`
113  */
114 template <typename Tag>
116  static std::string name() noexcept {
117  // Add "Linear" prefix to abbreviate the namespace for uniqueness
118  return "LinearMagnitude(" + Tag::name() + ")";
119  }
120  using type = double;
121  using tag = Tag;
122 };
123 
124 /*!
125  * \brief Compute the `LinearSolver::Magnitude` of a tag from its
126  * `LinearSolver::MagnitudeSquare`.
127  */
128 template <typename MagnitudeSquareTag,
131  : db::add_tag_prefix<Magnitude, db::remove_tag_prefix<MagnitudeSquareTag>>,
133  static constexpr double function(const double& magnitude_square) noexcept {
134  return sqrt(magnitude_square);
135  }
136  using argument_tags = tmpl::list<MagnitudeSquareTag>;
137 };
138 
139 /*!
140  * \brief The prefix for tags related to an orthogonalization procedurce
141  */
142 template <typename Tag>
144  static std::string name() noexcept {
145  // Add "Linear" prefix to abbreviate the namespace for uniqueness
146  return "LinearOrthogonalization(" + Tag::name() + ")";
147  }
148  using type = typename Tag::type;
149  using tag = Tag;
150 };
151 
152 /*!
153  * \brief A Hessenberg matrix built up during an orthogonalization procedure
154  */
155 template <typename Tag>
157  static std::string name() noexcept {
158  // Add "Linear" prefix to abbreviate the namespace for uniqueness
159  return "LinearOrthogonalizationHistory(" + Tag::name() + ")";
160  }
161  using type = DenseMatrix<double>;
162  using tag = Tag;
163 };
164 
165 /*!
166  * \brief A set of \f$n\f$ vectors that form a basis of the \f$n\f$-th Krylov
167  * subspace \f$K_n(A,b)\f$
168  *
169  * \details The Krylov subspace \f$K_n(A,b)\f$ spanned by this basis is the one
170  * generated by the linear operator \f$A\f$ and source \f$b\f$ that are
171  * represented by the tags
172  * `db::add_tag_prefix<LinearSolver::Tags::OperatorAppliedTo,
173  * db::add_tag_prefix<LinearSolver::Tags::Operand, Tag>>` and
174  * `db::add_tag_prefix<::Tags::Source, Tag>`, respectively. Therefore, each
175  * basis vector is of the type `db::item_type<db::add_tag_prefix<Operand,
176  * Tag>>`.
177  */
178 template <typename Tag>
180  static std::string name() noexcept {
181  // No "Linear" prefix since a Krylov subspace always refers to a linear
182  // operator
183  return "KrylovSubspaceBasis(" + Tag::name() + ")";
184  }
186  using tag = Tag;
187 };
188 
189 /*!
190  * \brief `LinearSolver::ConvergenceCriteria` that determine the linear solve
191  * has converged
192  */
194  static std::string name() noexcept { return "ConvergenceCriteria"; }
195  static constexpr OptionString help =
196  "Criteria that determine the linear solve has converged";
198 };
199 
200 /*!
201  * \brief Holds a `LinearSolver::HasConverged` flag that signals the linear
202  * solver has converged, along with the reason for convergence.
203  */
205  static std::string name() noexcept { return "LinearSolverHasConverged"; }
207 };
208 
209 /*
210  * \brief Employs the `LinearSolver::Tags::ConvergenceCriteria` to determine the
211  * linear solver has converged.
212  */
213 template <typename FieldsTag>
215  private:
216  using residual_magnitude_tag = db::add_tag_prefix<
219  using initial_residual_magnitude_tag =
221 
222  public:
223  using argument_tags =
225  LinearSolver::Tags::IterationId, residual_magnitude_tag,
226  initial_residual_magnitude_tag>;
228  const LinearSolver::ConvergenceCriteria& convergence_criteria,
229  const LinearSolver::IterationId& iteration_id,
230  const double& residual_magnitude,
231  const double& initial_residual_magnitude) noexcept {
232  return LinearSolver::HasConverged(convergence_criteria, iteration_id,
233  residual_magnitude,
234  initial_residual_magnitude);
235  }
236 };
237 
238 } // namespace Tags
239 } // 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
Functionality for solving linear systems of equations.
Definition: TerminateIfConverged.hpp:22
Marks a DataBoxTag as being a compute item that executes a function.
Definition: DataBoxTag.hpp:155
The magnitude square w.r.t. the LinearSolver::inner_product
Definition: Tags.hpp:101
Tags for the DataBox inherit from this type.
Definition: DataBoxTag.hpp:65
Holds a LinearSolver::HasConverged flag that signals the linear solver has converged, along with the reason for convergence.
Definition: Tags.hpp:204
Definition: Tags.hpp:90
Criteria that determine the linear solve has converged.
Definition: Convergence.hpp:58
Defines the type alias Requires.
The operand that the local linear operator is applied to.
Definition: Tags.hpp:40
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:26
A set of vectors that form a basis of the -th Krylov subspace .
Definition: Tags.hpp:179
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
Defines class DenseMatrix.
Definition: DataBoxTag.hpp:29
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::item_type_impl< TagList, Tag >::type item_type
Get the type that is returned by the Tag. If it is a base tag then a TagList must be passed as a seco...
Definition: DataBoxTag.hpp:410
Marks an item as being a prefix to another tag.
Definition: DataBoxTag.hpp:112
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t ...
Definition: Requires.hpp:67
Compute the LinearSolver::Magnitude of a tag from its LinearSolver::MagnitudeSquare.
Definition: Tags.hpp:130
The linear operator applied to the data in Tag
Definition: Tags.hpp:53
Identifies a step in the linear solver algorithm.
Definition: IterationId.hpp:25
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines type traits, some of which are future STL type_traits header.
The residual .
Definition: Tags.hpp:80
Signals convergence of the linear solver.
Definition: Convergence.hpp:149
Defines class IterationId.