Loading...
Searching...
No Matches
diagonal_solver.hpp
Go to the documentation of this file.
1#pragma once
2
6
8
9/// @brief "Diagonal solver" for linear systems.
10///
11/// Implements a diagonal solve operation by inverting a given diagonal
12/// in the constructor and assigning a scaled rhs to the solution for the
13/// solve: x \gets D^{-1}b \f$.
14/// Satisfies the SolverLike concept (see solver.hpp).
15///
16/// OperatorT is essentially ignored (does not need to be the identity operator).
17///
18/// @tparam OperatorT Operator type (must satisfy OperatorLike).
19template < OperatorLike OperatorT >
20class DiagonalSolver
21{
22 public:
23 /// @brief Operator type to be solved.
24 using OperatorType = OperatorT;
25 /// @brief Solution vector type.
26 using SolutionVectorType = SrcOf< OperatorType >;
27 /// @brief Right-hand side vector type.
28 using RHSVectorType = DstOf< OperatorType >;
29
30 private:
31 SolutionVectorType& inv_diagonal_;
32
33 public:
34 DiagonalSolver( SolutionVectorType& diagonal )
35 : inv_diagonal_( diagonal )
36 {
37 linalg::invert_entries( inv_diagonal_ );
38 }
39
40 /// @brief Solve the diagonal linear system by just scaling the rhs with the inverse diagonal.
41 /// Implements \f$ x = b \f$.
42 /// @param A Operator (matrix), unused.
43 /// @param x Solution vector (output).
44 /// @param b Right-hand side vector (input).
45 void solve_impl( OperatorType& A, SolutionVectorType& x, const RHSVectorType& b )
46 {
47 assign( x, b );
48 scale_in_place( x, inv_diagonal_ );
49 }
50};
51
52/// @brief Static assertion: IdentitySolver satisfies SolverLike concept.
53static_assert( SolverLike< DiagonalSolver< linalg::detail::DummyOperator<
54 linalg::detail::DummyVector< double >,
55 linalg::detail::DummyVector< double > > > > );
56
57} // namespace terra::linalg::solvers
diagonal
Definition EpsilonDivDiv_kernel_gen.py:101
Definition block_preconditioner_2x2.hpp:7
void scale_in_place(Vector &y, const Vector &x)
Scale a vector in place with another vector. For each entry , computes .
Definition vector.hpp:137
void assign(Vector &y, const ScalarOf< Vector > &c0)
Assign a scalar value to a vector. Implements: .
Definition vector.hpp:97