39template <base::concepts::sparse_matrix Matrix>
40class gauss_seidel_iterative_solver;
49template <base::concepts::sparse_matrix Matrix>
63template <base::concepts::sparse_matrix Matrix>
66 static_assert(Matrix::IsRowMajor == 1,
"Row major matrix is required.");
68 "Complex matrices are not supported.");
102 "All diagonal elements of the coefficient matrix must not be "
114 template <base::concepts::dense_vector_of<scalar_type> Right,
115 base::concepts::dense_vector_of<scalar_type> Solution>
117 const auto& coeff_ref =
coeff();
120 "Coefficient matrix must be a square matrix.");
122 "Right-hand-side vector must have the number of elements same as "
123 "the size of the coefficient matrix.");
125 "Solution vector must have the number of elements same as the size "
126 "of the coefficient matrix.");
129 const scalar_type right_norm = right.squaredNorm();
132 iterate(coeff_ref, right, solution);
174 template <base::concepts::dense_vector_of<scalar_type> Right,
175 base::concepts::dense_vector_of<scalar_type> Solution>
177 Solution& solution)
const {
182 for (
typename matrix_type::InnerIterator iter(coeff_ref, i); iter;
184 if (iter.index() != i) {
185 numerator -= iter.value() * solution(iter.index());
190 residual_ += row_residual * row_residual;
Class to solve linear equations using Gauss-Seidel iteration golub2013.
scalar_type residual_rate_
Rate of last residual.
auto iterations() const noexcept -> index_type
Get the number of iterations.
void compute(const matrix_type &coeff)
Prepare to solve.
void iterate(const matrix_type &coeff_ref, const Right &right, Solution &solution) const
Iterate once.
gauss_seidel_iterative_solver()=default
Constructor.
scalar_type residual_
Last residual.
Eigen::VectorX< scalar_type > vector_type
Type of vectors.
vector_type diag_
Diagonal coefficients.
index_type iterations_
Number of iterations.
vector_type inv_diag_
Inverse of diagonal coefficients.
void solve_vector_in_place(const Right &right, Solution &solution) const
Iterate repeatedly until stop criterion is satisfied for a vector.
auto residual_rate() const noexcept -> scalar_type
Get the rate of the last residual.
Base class of iterative solvers.
StorageIndex storage_index_type
auto coeff() const noexcept -> const matrix_type &
auto tolerance() const noexcept -> real_scalar_type
RealScalar real_scalar_type
auto compute(const matrix_type &coeff) -> gauss_seidel_iterative_solver< Matrix > &
auto max_iterations() const noexcept -> index_type
Definition of dense_vector_of concept.
Definition of exceptions.
Definition of index_type type.
Definition of iterative_solver_base class.
Definition of macros for logging.
std::ptrdiff_t index_type
Type of indices in this library.
Namespace of solvers of linear equations.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of real_scalar concept.
Definition of sparse_matrix concept.
Matrix matrix_type
Type of the matrix.
Traits of iterative solvers.