Loading...
Searching...
No Matches
richardson.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "solver.hpp"
4
6
7/// @brief Richardson iterative solver for linear systems.
8/// Satisfies the SolverLike concept (see solver.hpp).
9/// Implements the update rule:
10/// \f[ x^{(k+1)} = x^{(k)} + \omega (b - Ax^{(k)}) \f]
11/// where \f$ \omega \f$ is the relaxation parameter.
12/// @tparam OperatorT Operator type (must satisfy OperatorLike).
13template < OperatorLike OperatorT >
15{
16 public:
17 /// @brief Operator type to be solved.
18 using OperatorType = OperatorT;
19 /// @brief Solution vector type.
21 /// @brief Right-hand side vector type.
23
24 /// @brief Construct a Richardson solver.
25 /// @param iterations Number of Richardson iterations to perform.
26 /// @param omega Relaxation parameter.
27 /// @param r_tmp Temporary vector for workspace.
28 Richardson( const int iterations, const double omega, const RHSVectorType& r_tmp )
29 : iterations_( iterations )
30 , omega_( omega )
31 , r_( r_tmp )
32 {}
33
34 /// @brief Solve the linear system using Richardson iteration.
35 /// Applies the update rule for the specified number of iterations.
36 /// @param A Operator (matrix).
37 /// @param x Solution vector (output).
38 /// @param b Right-hand side vector (input).
40 {
41 for ( int iteration = 0; iteration < iterations_; ++iteration )
42 {
43 apply( A, x, r_ );
44 lincomb( x, { 1.0, omega_, -omega_ }, { x, b, r_ } );
45 }
46 }
47
48 private:
49 int iterations_; ///< Number of iterations.
50 double omega_; ///< Relaxation parameter.
51 RHSVectorType r_; ///< Temporary workspace vector.
52};
53
54/// @brief Static assertion: Richardson satisfies SolverLike concept.
55static_assert( SolverLike< Richardson< linalg::detail::DummyConcreteOperator > > );
56
57} // namespace terra::linalg::solvers
Richardson iterative solver for linear systems. Satisfies the SolverLike concept (see solver....
Definition richardson.hpp:15
SrcOf< OperatorType > SolutionVectorType
Solution vector type.
Definition richardson.hpp:20
OperatorT OperatorType
Operator type to be solved.
Definition richardson.hpp:18
Richardson(const int iterations, const double omega, const RHSVectorType &r_tmp)
Construct a Richardson solver.
Definition richardson.hpp:28
void solve_impl(OperatorType &A, SolutionVectorType &x, const RHSVectorType &b)
Solve the linear system using Richardson iteration. Applies the update rule for the specified number ...
Definition richardson.hpp:39
DstOf< OperatorType > RHSVectorType
Right-hand side vector type.
Definition richardson.hpp:22
Definition block_preconditioner_2x2.hpp:7
void lincomb(Vector &y, const std::vector< ScalarOf< Vector > > &c, const std::vector< Vector > &x, const ScalarOf< Vector > &c0)
Compute a linear combination of vectors. Implements: .
Definition vector.hpp:72
Operator::SrcVectorType SrcOf
Alias for the source vector type of an operator.
Definition operator.hpp:145
void apply(LinearForm &L, typename LinearForm::DstVectorType &dst)
Apply a linear form and write to a destination vector.
Definition linear_form.hpp:37
Operator::DstVectorType DstOf
Alias for the destination vector type of an operator.
Definition operator.hpp:149