Eigen::DGMRES< MatrixType_, Preconditioner_ > Class Template Reference

A Restarted GMRES with deflation. This class implements a modification of the GMRES solver for sparse linear systems. The basis is built with modified Gram-Schmidt. At each restart, a few approximated eigenvectors corresponding to the smallest eigenvalues are used to build a preconditioner for the next cycle. This preconditioner for deflation can be combined with any other preconditioner, the IncompleteLUT for instance. The preconditioner is applied at right of the matrix and the combination is multiplicative. More...

#include <DGMRES.h>

+ Inheritance diagram for Eigen::DGMRES< MatrixType_, Preconditioner_ >:

Public Types

typedef MatrixType_ MatrixType
 
typedef MatrixType::Scalar Scalar
 
typedef MatrixType::StorageIndex StorageIndex
 
typedef MatrixType::RealScalar RealScalar
 
typedef Preconditioner_ Preconditioner
 
typedef Matrix< Scalar, Dynamic, DynamicDenseMatrix
 
typedef Matrix< RealScalar, Dynamic, DynamicDenseRealMatrix
 
typedef Matrix< Scalar, Dynamic, 1 > DenseVector
 
typedef Matrix< RealScalar, Dynamic, 1 > DenseRealVector
 
typedef Matrix< std::complex< RealScalar >, Dynamic, 1 > ComplexVector
 
- Public Types inherited from Eigen::IterativeSolverBase< DGMRES< MatrixType_, Preconditioner_ > >
enum  
 
typedef internal::traits< DGMRES< MatrixType_, Preconditioner_ > >::MatrixType MatrixType
 
typedef internal::traits< DGMRES< MatrixType_, Preconditioner_ > >::Preconditioner Preconditioner
 
typedef MatrixType::Scalar Scalar
 
typedef MatrixType::StorageIndex StorageIndex
 
typedef MatrixType::RealScalar RealScalar
 

Public Member Functions

 DGMRES ()
 
template<typename MatrixDerived >
 DGMRES (const EigenBase< MatrixDerived > &A)
 
 ~DGMRES ()
 
template<typename Rhs , typename Dest >
void _solve_vector_with_guess_impl (const Rhs &b, Dest &x) const
 
Index restart ()
 
void set_restart (const Index restart)
 
void setEigenv (const Index neig)
 
Index deflSize ()
 
void setMaxEigenv (const Index maxNeig)
 
template<typename Rhs , typename Dest >
void _solve_impl (const Rhs &b, Dest &x) const
 
template<typename Rhs , typename DestDerived >
void _solve_with_guess_impl (const Rhs &b, SparseMatrixBase< DestDerived > &aDest) const
 
template<typename Rhs , typename DestDerived >
std::enable_if_t< Rhs::ColsAtCompileTime !=1 &&DestDerived::ColsAtCompileTime !=1 > _solve_with_guess_impl (const Rhs &b, MatrixBase< DestDerived > &aDest) const
 
template<typename Rhs , typename DestDerived >
std::enable_if_t< Rhs::ColsAtCompileTime==1||DestDerived::ColsAtCompileTime==1 > _solve_with_guess_impl (const Rhs &b, MatrixBase< DestDerived > &dest) const
 
- Public Member Functions inherited from Eigen::IterativeSolverBase< DGMRES< MatrixType_, Preconditioner_ > >
 IterativeSolverBase ()
 
 IterativeSolverBase (const EigenBase< MatrixDerived > &A)
 
 IterativeSolverBase (IterativeSolverBase &&)=default
 
 ~IterativeSolverBase ()
 
DGMRES< MatrixType_, Preconditioner_ > & analyzePattern (const EigenBase< MatrixDerived > &A)
 
DGMRES< MatrixType_, Preconditioner_ > & factorize (const EigenBase< MatrixDerived > &A)
 
DGMRES< MatrixType_, Preconditioner_ > & compute (const EigenBase< MatrixDerived > &A)
 
EIGEN_CONSTEXPR Index rows () const EIGEN_NOEXCEPT
 
EIGEN_CONSTEXPR Index cols () const EIGEN_NOEXCEPT
 
RealScalar tolerance () const
 
DGMRES< MatrixType_, Preconditioner_ > & setTolerance (const RealScalar &tolerance)
 
Preconditionerpreconditioner ()
 
const Preconditionerpreconditioner () const
 
Index maxIterations () const
 
DGMRES< MatrixType_, Preconditioner_ > & setMaxIterations (Index maxIters)
 
Index iterations () const
 
RealScalar error () const
 
const SolveWithGuess< DGMRES< MatrixType_, Preconditioner_ >, Rhs, Guess > solveWithGuess (const MatrixBase< Rhs > &b, const Guess &x0) const
 
ComputationInfo info () const
 
void _solve_with_guess_impl (const Rhs &b, SparseMatrixBase< DestDerived > &aDest) const
 
std::enable_if_t< Rhs::ColsAtCompileTime !=1 &&DestDerived::ColsAtCompileTime !=1 > _solve_with_guess_impl (const Rhs &b, MatrixBase< DestDerived > &aDest) const
 
std::enable_if_t< Rhs::ColsAtCompileTime==1||DestDerived::ColsAtCompileTime==1 > _solve_with_guess_impl (const Rhs &b, MatrixBase< DestDerived > &dest) const
 
void _solve_impl (const Rhs &b, Dest &x) const
 
DGMRES< MatrixType_, Preconditioner_ > & derived ()
 
const DGMRES< MatrixType_, Preconditioner_ > & derived () const
 
- Public Member Functions inherited from Eigen::SparseSolverBase< Derived >
 SparseSolverBase ()
 
 SparseSolverBase (SparseSolverBase &&other)
 
 ~SparseSolverBase ()
 
Derived & derived ()
 
const Derived & derived () const
 
template<typename Rhs >
const Solve< Derived, Rhs > solve (const MatrixBase< Rhs > &b) const
 
template<typename Rhs >
const Solve< Derived, Rhs > solve (const SparseMatrixBase< Rhs > &b) const
 
template<typename Rhs , typename Dest >
void _solve_impl (const SparseMatrixBase< Rhs > &b, SparseMatrixBase< Dest > &dest) const
 

Protected Member Functions

template<typename Rhs , typename Dest >
void dgmres (const MatrixType &mat, const Rhs &rhs, Dest &x, const Preconditioner &precond) const
 Perform several cycles of restarted GMRES with modified Gram Schmidt,. More...
 
template<typename Dest >
Index dgmresCycle (const MatrixType &mat, const Preconditioner &precond, Dest &x, DenseVector &r0, RealScalar &beta, const RealScalar &normRhs, Index &nbIts) const
 Perform one restart cycle of DGMRES. More...
 
Index dgmresComputeDeflationData (const MatrixType &mat, const Preconditioner &precond, const Index &it, StorageIndex &neig) const
 
template<typename RhsType , typename DestType >
Index dgmresApplyDeflation (const RhsType &In, DestType &Out) const
 
ComplexVector schurValues (const ComplexSchur< DenseMatrix > &schurofH) const
 
ComplexVector schurValues (const RealSchur< DenseMatrix > &schurofH) const
 
void dgmresInitDeflation (Index &rows) const
 
- Protected Member Functions inherited from Eigen::IterativeSolverBase< DGMRES< MatrixType_, Preconditioner_ > >
void init ()
 
const ActualMatrixTypematrix () const
 
void grab (const InputType &A)
 

Protected Attributes

DenseMatrix m_V
 
DenseMatrix m_H
 
DenseMatrix m_Hes
 
Index m_restart
 
DenseMatrix m_U
 
DenseMatrix m_MU
 
DenseMatrix m_T
 
PartialPivLU< DenseMatrixm_luT
 
StorageIndex m_neig
 
Index m_r
 
Index m_maxNeig
 
RealScalar m_lambdaN
 
bool m_isDeflAllocated
 
bool m_isDeflInitialized
 
RealScalar m_smv
 
bool m_force
 
- Protected Attributes inherited from Eigen::IterativeSolverBase< DGMRES< MatrixType_, Preconditioner_ > >
MatrixWrapper m_matrixWrapper
 
Preconditioner m_preconditioner
 
Index m_maxIterations
 
RealScalar m_tolerance
 
RealScalar m_error
 
Index m_iterations
 
ComputationInfo m_info
 
bool m_analysisIsOk
 
bool m_factorizationIsOk
 
bool m_isInitialized
 
- Protected Attributes inherited from Eigen::SparseSolverBase< Derived >
bool m_isInitialized
 

Private Types

typedef IterativeSolverBase< DGMRESBase
 

Private Member Functions

const ActualMatrixTypematrix () const
 

Private Attributes

RealScalar m_error
 
ComputationInfo m_info
 
bool m_isInitialized
 
Index m_iterations
 
RealScalar m_tolerance
 

Additional Inherited Members

- Protected Types inherited from Eigen::IterativeSolverBase< DGMRES< MatrixType_, Preconditioner_ > >
typedef SparseSolverBase< DGMRES< MatrixType_, Preconditioner_ > > Base
 
typedef internal::generic_matrix_wrapper< MatrixTypeMatrixWrapper
 
typedef MatrixWrapper::ActualMatrixType ActualMatrixType
 

Detailed Description

template<typename MatrixType_, typename Preconditioner_>
class Eigen::DGMRES< MatrixType_, Preconditioner_ >

A Restarted GMRES with deflation. This class implements a modification of the GMRES solver for sparse linear systems. The basis is built with modified Gram-Schmidt. At each restart, a few approximated eigenvectors corresponding to the smallest eigenvalues are used to build a preconditioner for the next cycle. This preconditioner for deflation can be combined with any other preconditioner, the IncompleteLUT for instance. The preconditioner is applied at right of the matrix and the combination is multiplicative.

Template Parameters
MatrixType_the type of the sparse matrix A, can be a dense or a sparse matrix.
Preconditioner_the type of the preconditioner. Default is DiagonalPreconditioner Typical usage :
SparseMatrix<double> A;
VectorXd x, b;
//Fill A and b ...
DGMRES<SparseMatrix<double> > solver;
solver.set_restart(30); // Set restarting value
solver.setEigenv(1); // Set the number of eigenvalues to deflate
solver.compute(A);
x = solver.solve(b);
BiCGSTAB< SparseMatrix< double > > solver
Definition: BiCGSTAB_simple.cpp:5
Scalar * b
Definition: benchVecAdd.cpp:17
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
list x
Definition: plotDoE.py:28

DGMRES can also be used in a matrix-free context, see the following example .

References : [1] D. NUENTSA WAKAM and F. PACULL, Memory Efficient Hybrid Algebraic Solvers for Linear Systems Arising from Compressible Flows, Computers and Fluids, In Press, https://doi.org/10.1016/j.compfluid.2012.03.023 [2] K. Burrage and J. Erhel, On the performance of various adaptive preconditioned GMRES strategies, 5(1998), 101-121. [3] J. Erhel, K. Burrage and B. Pohl, Restarted GMRES preconditioned by deflation,J. Computational and Applied Mathematics, 69(1996), 303-318.

Member Typedef Documentation

◆ Base

template<typename MatrixType_ , typename Preconditioner_ >
typedef IterativeSolverBase<DGMRES> Eigen::DGMRES< MatrixType_, Preconditioner_ >::Base
private

◆ ComplexVector

template<typename MatrixType_ , typename Preconditioner_ >
typedef Matrix<std::complex<RealScalar>, Dynamic, 1> Eigen::DGMRES< MatrixType_, Preconditioner_ >::ComplexVector

◆ DenseMatrix

template<typename MatrixType_ , typename Preconditioner_ >
typedef Matrix<Scalar, Dynamic, Dynamic> Eigen::DGMRES< MatrixType_, Preconditioner_ >::DenseMatrix

◆ DenseRealMatrix

template<typename MatrixType_ , typename Preconditioner_ >
typedef Matrix<RealScalar, Dynamic, Dynamic> Eigen::DGMRES< MatrixType_, Preconditioner_ >::DenseRealMatrix

◆ DenseRealVector

template<typename MatrixType_ , typename Preconditioner_ >
typedef Matrix<RealScalar, Dynamic, 1> Eigen::DGMRES< MatrixType_, Preconditioner_ >::DenseRealVector

◆ DenseVector

template<typename MatrixType_ , typename Preconditioner_ >
typedef Matrix<Scalar, Dynamic, 1> Eigen::DGMRES< MatrixType_, Preconditioner_ >::DenseVector

◆ MatrixType

template<typename MatrixType_ , typename Preconditioner_ >
typedef MatrixType_ Eigen::DGMRES< MatrixType_, Preconditioner_ >::MatrixType

◆ Preconditioner

template<typename MatrixType_ , typename Preconditioner_ >
typedef Preconditioner_ Eigen::DGMRES< MatrixType_, Preconditioner_ >::Preconditioner

◆ RealScalar

template<typename MatrixType_ , typename Preconditioner_ >
typedef MatrixType::RealScalar Eigen::DGMRES< MatrixType_, Preconditioner_ >::RealScalar

◆ Scalar

template<typename MatrixType_ , typename Preconditioner_ >
typedef MatrixType::Scalar Eigen::DGMRES< MatrixType_, Preconditioner_ >::Scalar

◆ StorageIndex

template<typename MatrixType_ , typename Preconditioner_ >
typedef MatrixType::StorageIndex Eigen::DGMRES< MatrixType_, Preconditioner_ >::StorageIndex

Constructor & Destructor Documentation

◆ DGMRES() [1/2]

template<typename MatrixType_ , typename Preconditioner_ >
Eigen::DGMRES< MatrixType_, Preconditioner_ >::DGMRES ( )
inline

Default constructor.

123  : Base(), m_restart(30), m_neig(0), m_r(0), m_maxNeig(5), m_isDeflAllocated(false), m_isDeflInitialized(false) {}
IterativeSolverBase< DGMRES > Base
Definition: DGMRES.h:99
StorageIndex m_neig
Definition: DGMRES.h:213
bool m_isDeflAllocated
Definition: DGMRES.h:217
Index m_restart
Definition: DGMRES.h:208
Index m_maxNeig
Definition: DGMRES.h:215
Index m_r
Definition: DGMRES.h:214
bool m_isDeflInitialized
Definition: DGMRES.h:218

◆ DGMRES() [2/2]

template<typename MatrixType_ , typename Preconditioner_ >
template<typename MatrixDerived >
Eigen::DGMRES< MatrixType_, Preconditioner_ >::DGMRES ( const EigenBase< MatrixDerived > &  A)
inlineexplicit

Initialize the solver with matrix A for further Ax=b solving.

This constructor is a shortcut for the default constructor followed by a call to compute().

Warning
this class stores a reference to the matrix A as well as some precomputed values that depend on it. Therefore, if A is changed this class becomes invalid. Call compute() to update it with the new matrix A, or modify a copy of A.
137  : Base(A.derived()),
138  m_restart(30),
139  m_neig(0),
140  m_r(0),
141  m_maxNeig(5),
142  m_isDeflAllocated(false),
143  m_isDeflInitialized(false) {}

◆ ~DGMRES()

template<typename MatrixType_ , typename Preconditioner_ >
Eigen::DGMRES< MatrixType_, Preconditioner_ >::~DGMRES ( )
inline
145 {}

Member Function Documentation

◆ _solve_impl()

template<typename MatrixType_ , typename Preconditioner_ >
template<typename Rhs , typename Dest >
void Eigen::IterativeSolverBase< Derived >::_solve_impl ( typename Rhs  ,
typename Dest   
)
inline

default initial guess = 0

357  {
358  x.setZero();
359  derived()._solve_with_guess_impl(b, x);
360  }
DGMRES< MatrixType_, Preconditioner_ > & derived()
Definition: SparseSolverBase.h:76

◆ _solve_vector_with_guess_impl()

template<typename MatrixType_ , typename Preconditioner_ >
template<typename Rhs , typename Dest >
void Eigen::DGMRES< MatrixType_, Preconditioner_ >::_solve_vector_with_guess_impl ( const Rhs &  b,
Dest &  x 
) const
inline
149  {
150  EIGEN_STATIC_ASSERT(Rhs::ColsAtCompileTime == 1 || Dest::ColsAtCompileTime == 1,
151  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
152 
155 
157  }
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
void dgmres(const MatrixType &mat, const Rhs &rhs, Dest &x, const Preconditioner &precond) const
Perform several cycles of restarted GMRES with modified Gram Schmidt,.
Definition: DGMRES.h:232
RealScalar m_error
Definition: IterativeSolverBase.h:387
Index m_iterations
Definition: IterativeSolverBase.h:388
const ActualMatrixType & matrix() const
Definition: IterativeSolverBase.h:374
Index maxIterations() const
Definition: IterativeSolverBase.h:251
Preconditioner m_preconditioner
Definition: IterativeSolverBase.h:382
RealScalar m_tolerance
Definition: IterativeSolverBase.h:385

References b, Eigen::DGMRES< MatrixType_, Preconditioner_ >::dgmres(), EIGEN_STATIC_ASSERT, Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_error, Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_iterations, Eigen::IterativeSolverBase< Derived >::m_preconditioner, Eigen::IterativeSolverBase< Derived >::m_tolerance, Eigen::DGMRES< MatrixType_, Preconditioner_ >::matrix(), Eigen::IterativeSolverBase< Derived >::maxIterations(), and plotDoE::x.

◆ _solve_with_guess_impl() [1/3]

template<typename MatrixType_ , typename Preconditioner_ >
template<typename Rhs , typename DestDerived >
std::enable_if_t<Rhs::ColsAtCompileTime != 1 && DestDerived::ColsAtCompileTime != 1> Eigen::IterativeSolverBase< Derived >::_solve_with_guess_impl ( typename Rhs  ,
typename DestDerived   
)
inline
328  {
329  eigen_assert(rows() == b.rows());
330 
331  Index rhsCols = b.cols();
332  DestDerived& dest(aDest.derived());
333  ComputationInfo global_info = Success;
334  for (Index k = 0; k < rhsCols; ++k) {
335  typename DestDerived::ColXpr xk(dest, k);
336  typename Rhs::ConstColXpr bk(b, k);
337  derived()._solve_vector_with_guess_impl(bk, xk);
338 
339  // The call to _solve_vector_with_guess updates m_info, so if it failed for a previous column
340  // we need to restore it to the worst value.
341  if (m_info == NumericalIssue)
342  global_info = NumericalIssue;
343  else if (m_info == NoConvergence)
344  global_info = NoConvergence;
345  }
346  m_info = global_info;
347  }
#define eigen_assert(x)
Definition: Macros.h:910
ComputationInfo m_info
Definition: IterativeSolverBase.h:389
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: IterativeSolverBase.h:221
ComputationInfo
Definition: Constants.h:438
@ NumericalIssue
Definition: Constants.h:442
@ Success
Definition: Constants.h:440
@ NoConvergence
Definition: Constants.h:444
char char char int int * k
Definition: level2_impl.h:374
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83

◆ _solve_with_guess_impl() [2/3]

template<typename MatrixType_ , typename Preconditioner_ >
template<typename Rhs , typename DestDerived >
std::enable_if_t<Rhs::ColsAtCompileTime == 1 || DestDerived::ColsAtCompileTime == 1> Eigen::IterativeSolverBase< Derived >::_solve_with_guess_impl ( typename Rhs  ,
typename DestDerived   
)
inline
351  {
352  derived()._solve_vector_with_guess_impl(b, dest.derived());
353  }

◆ _solve_with_guess_impl() [3/3]

template<typename MatrixType_ , typename Preconditioner_ >
template<typename Rhs , typename DestDerived >
void Eigen::IterativeSolverBase< Derived >::_solve_with_guess_impl ( typename Rhs  ,
typename DestDerived   
)
inline
295  {
296  eigen_assert(rows() == b.rows());
297 
298  Index rhsCols = b.cols();
299  Index size = b.rows();
300  DestDerived& dest(aDest.derived());
301  typedef typename DestDerived::Scalar DestScalar;
304  // We do not directly fill dest because sparse expressions have to be free of aliasing issue.
305  // For non square least-square problems, b and dest might not have the same size whereas they might alias
306  // each-other.
307  typename DestDerived::PlainObject tmp(cols(), rhsCols);
308  ComputationInfo global_info = Success;
309  for (Index k = 0; k < rhsCols; ++k) {
310  tb = b.col(k);
311  tx = dest.col(k);
312  derived()._solve_vector_with_guess_impl(tb, tx);
313  tmp.col(k) = tx.sparseView(0);
314 
315  // The call to _solve_vector_with_guess_impl updates m_info, so if it failed for a previous column
316  // we need to restore it to the worst value.
317  if (m_info == NumericalIssue)
318  global_info = NumericalIssue;
319  else if (m_info == NoConvergence)
320  global_info = NoConvergence;
321  }
322  m_info = global_info;
323  dest.swap(tmp);
324  }
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: IterativeSolverBase.h:224
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365

◆ deflSize()

template<typename MatrixType_ , typename Preconditioner_ >
Index Eigen::DGMRES< MatrixType_, Preconditioner_ >::deflSize ( )
inline

Get the size of the deflation subspace size

180 { return m_r; }

References Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_r.

◆ dgmres()

template<typename MatrixType_ , typename Preconditioner_ >
template<typename Rhs , typename Dest >
void Eigen::DGMRES< MatrixType_, Preconditioner_ >::dgmres ( const MatrixType mat,
const Rhs &  rhs,
Dest &  x,
const Preconditioner precond 
) const
protected

Perform several cycles of restarted GMRES with modified Gram Schmidt,.

A right preconditioner is used combined with deflation.

233  {
234  const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)();
235 
236  RealScalar normRhs = rhs.norm();
237  if (normRhs <= considerAsZero) {
238  x.setZero();
239  m_error = 0;
240  return;
241  }
242 
243  // Initialization
244  m_isDeflInitialized = false;
245  Index n = mat.rows();
246  DenseVector r0(n);
247  Index nbIts = 0;
250  m_V.resize(n, m_restart + 1);
251  // Initial residual vector and initial norm
252  if (x.squaredNorm() == 0) x = precond.solve(rhs);
253  r0 = rhs - mat * x;
254  RealScalar beta = r0.norm();
255 
256  m_error = beta / normRhs;
257  if (m_error < m_tolerance)
258  m_info = Success;
259  else
261 
262  // Iterative process
263  while (nbIts < m_iterations && m_info == NoConvergence) {
264  dgmresCycle(mat, precond, x, r0, beta, normRhs, nbIts);
265 
266  // Compute the new residual vector for the restart
267  if (nbIts < m_iterations && m_info == NoConvergence) {
268  r0 = rhs - mat * x;
269  beta = r0.norm();
270  }
271  }
272 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
Index dgmresCycle(const MatrixType &mat, const Preconditioner &precond, Dest &x, DenseVector &r0, RealScalar &beta, const RealScalar &normRhs, Index &nbIts) const
Perform one restart cycle of DGMRES.
Definition: DGMRES.h:286
DenseMatrix m_H
Definition: DGMRES.h:206
DenseMatrix m_V
Definition: DGMRES.h:205
DenseMatrix m_Hes
Definition: DGMRES.h:207
RealScalar m_tolerance
Definition: IterativeSolverBase.h:385
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:294
Index rows() const
Definition: SparseMatrix.h:159
#define min(a, b)
Definition: datatypes.h:22
Scalar beta
Definition: level2_cplx_impl.h:36

References beta, min, n, Eigen::NoConvergence, Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::rows(), Eigen::Success, and plotDoE::x.

Referenced by Eigen::DGMRES< MatrixType_, Preconditioner_ >::_solve_vector_with_guess_impl().

◆ dgmresApplyDeflation()

template<typename MatrixType_ , typename Preconditioner_ >
template<typename RhsType , typename DestType >
Index Eigen::DGMRES< MatrixType_, Preconditioner_ >::dgmresApplyDeflation ( const RhsType &  In,
DestType &  Out 
) const
protected
484  {
485  DenseVector x1 = m_U.leftCols(m_r).transpose() * x;
486  y = x + m_U.leftCols(m_r) * (m_lambdaN * m_luT.solve(x1) - x1);
487  return 0;
488 }
PartialPivLU< DenseMatrix > m_luT
Definition: DGMRES.h:212
DenseMatrix m_U
Definition: DGMRES.h:209
RealScalar m_lambdaN
Definition: DGMRES.h:216
Scalar * y
Definition: level1_cplx_impl.h:128
Vector< double > x1(const Vector< double > &coord)
Cartesian coordinates centered at the point (0.5,1)
Definition: poisson/poisson_with_singularity/two_d_poisson.cc:86

References plotDoE::x, Global_parameters::x1(), and y.

◆ dgmresComputeDeflationData()

template<typename MatrixType_ , typename Preconditioner_ >
Index Eigen::DGMRES< MatrixType_, Preconditioner_ >::dgmresComputeDeflationData ( const MatrixType mat,
const Preconditioner precond,
const Index it,
StorageIndex neig 
) const
protected
407  {
408  // First, find the Schur form of the Hessenberg matrix H
409  std::conditional_t<NumTraits<Scalar>::IsComplex, ComplexSchur<DenseMatrix>, RealSchur<DenseMatrix> > schurofH;
410  bool computeU = true;
411  DenseMatrix matrixQ(it, it);
412  matrixQ.setIdentity();
413  schurofH.computeFromHessenberg(m_Hes.topLeftCorner(it, it), matrixQ, computeU);
414 
415  ComplexVector eig(it);
416  Matrix<StorageIndex, Dynamic, 1> perm(it);
417  eig = this->schurValues(schurofH);
418 
419  // Reorder the absolute values of Schur values
420  DenseRealVector modulEig(it);
421  for (Index j = 0; j < it; ++j) modulEig(j) = std::abs(eig(j));
422  perm.setLinSpaced(it, 0, internal::convert_index<StorageIndex>(it - 1));
423  internal::sortWithPermutation(modulEig, perm, neig);
424 
425  if (!m_lambdaN) {
426  m_lambdaN = (std::max)(modulEig.maxCoeff(), m_lambdaN);
427  }
428  // Count the real number of extracted eigenvalues (with complex conjugates)
429  Index nbrEig = 0;
430  while (nbrEig < neig) {
431  if (eig(perm(it - nbrEig - 1)).imag() == RealScalar(0))
432  nbrEig++;
433  else
434  nbrEig += 2;
435  }
436  // Extract the Schur vectors corresponding to the smallest Ritz values
437  DenseMatrix Sr(it, nbrEig);
438  Sr.setZero();
439  for (Index j = 0; j < nbrEig; j++) {
440  Sr.col(j) = schurofH.matrixU().col(perm(it - j - 1));
441  }
442 
443  // Form the Schur vectors of the initial matrix using the Krylov basis
444  DenseMatrix X;
445  X = m_V.leftCols(it) * Sr;
446  if (m_r) {
447  // Orthogonalize X against m_U using modified Gram-Schmidt
448  for (Index j = 0; j < nbrEig; j++)
449  for (Index k = 0; k < m_r; k++) X.col(j) = X.col(j) - (m_U.col(k).dot(X.col(j))) * m_U.col(k);
450  }
451 
452  // Compute m_MX = A * M^-1 * X
453  Index m = m_V.rows();
455  DenseMatrix MX(m, nbrEig);
456  DenseVector tv1(m);
457  for (Index j = 0; j < nbrEig; j++) {
458  tv1 = mat * X.col(j);
459  MX.col(j) = precond.solve(tv1);
460  }
461 
462  // Update m_T = [U'MU U'MX; X'MU X'MX]
463  m_T.block(m_r, m_r, nbrEig, nbrEig) = X.transpose() * MX;
464  if (m_r) {
465  m_T.block(0, m_r, m_r, nbrEig) = m_U.leftCols(m_r).transpose() * MX;
466  m_T.block(m_r, 0, nbrEig, m_r) = X.transpose() * m_MU.leftCols(m_r);
467  }
468 
469  // Save X into m_U and m_MX in m_MU
470  for (Index j = 0; j < nbrEig; j++) m_U.col(m_r + j) = X.col(j);
471  for (Index j = 0; j < nbrEig; j++) m_MU.col(m_r + j) = MX.col(j);
472  // Increase the size of the invariant subspace
473  m_r += nbrEig;
474 
475  // Factorize m_T into m_luT
476  m_luT.compute(m_T.topLeftCorner(m_r, m_r));
477 
478  // FIXME CHeck if the factorization was correctly done (nonsingular matrix)
479  m_isDeflInitialized = true;
480  return 0;
481 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
void dgmresInitDeflation(Index &rows) const
Definition: DGMRES.h:369
Matrix< RealScalar, Dynamic, 1 > DenseRealVector
Definition: DGMRES.h:118
Matrix< std::complex< RealScalar >, Dynamic, 1 > ComplexVector
Definition: DGMRES.h:119
DenseMatrix m_T
Definition: DGMRES.h:211
DenseMatrix m_MU
Definition: DGMRES.h:210
MatrixType::RealScalar RealScalar
Definition: DGMRES.h:113
ComplexVector schurValues(const ComplexSchur< DenseMatrix > &schurofH) const
Definition: DGMRES.h:378
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:191
@ IsComplex
Definition: common.h:73
#define max(a, b)
Definition: datatypes.h:23
#define X
Definition: icosphere.cpp:20
int * m
Definition: level2_cplx_impl.h:294
void sortWithPermutation(VectorType &vec, IndexType &perm, typename IndexType::Scalar &ncut)
Computes a permutation vector to have a sorted sequence.
Definition: DGMRES.h:40
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References abs(), IsComplex, j, k, m, max, Eigen::PlainObjectBase< Derived >::setZero(), Eigen::internal::sortWithPermutation(), and X.

◆ dgmresCycle()

template<typename MatrixType_ , typename Preconditioner_ >
template<typename Dest >
Index Eigen::DGMRES< MatrixType_, Preconditioner_ >::dgmresCycle ( const MatrixType mat,
const Preconditioner precond,
Dest &  x,
DenseVector r0,
RealScalar beta,
const RealScalar normRhs,
Index nbIts 
) const
protected

Perform one restart cycle of DGMRES.

Parameters
matThe coefficient matrix
precondThe preconditioner
xthe new approximated solution
r0The initial residual vector
betaThe norm of the residual computed so far
normRhsThe norm of the right hand side vector
nbItsThe number of iterations
288  {
289  // Initialization
290  DenseVector g(m_restart + 1); // Right hand side of the least square problem
291  g.setZero();
292  g(0) = Scalar(beta);
293  m_V.col(0) = r0 / beta;
295  std::vector<JacobiRotation<Scalar> > gr(m_restart); // Givens rotations
296  Index it = 0; // Number of inner iterations
297  Index n = mat.rows();
298  DenseVector tv1(n), tv2(n); // Temporary vectors
299  while (m_info == NoConvergence && it < m_restart && nbIts < m_iterations) {
300  // Apply preconditioner(s) at right
301  if (m_isDeflInitialized) {
302  dgmresApplyDeflation(m_V.col(it), tv1); // Deflation
303  tv2 = precond.solve(tv1);
304  } else {
305  tv2 = precond.solve(m_V.col(it)); // User's selected preconditioner
306  }
307  tv1 = mat * tv2;
308 
309  // Orthogonalize it with the previous basis in the basis using modified Gram-Schmidt
310  Scalar coef;
311  for (Index i = 0; i <= it; ++i) {
312  coef = tv1.dot(m_V.col(i));
313  tv1 = tv1 - coef * m_V.col(i);
314  m_H(i, it) = coef;
315  m_Hes(i, it) = coef;
316  }
317  // Normalize the vector
318  coef = tv1.norm();
319  m_V.col(it + 1) = tv1 / coef;
320  m_H(it + 1, it) = coef;
321  // m_Hes(it+1,it) = coef;
322 
323  // FIXME Check for happy breakdown
324 
325  // Update Hessenberg matrix with Givens rotations
326  for (Index i = 1; i <= it; ++i) {
327  m_H.col(it).applyOnTheLeft(i - 1, i, gr[i - 1].adjoint());
328  }
329  // Compute the new plane rotation
330  gr[it].makeGivens(m_H(it, it), m_H(it + 1, it));
331  // Apply the new rotation
332  m_H.col(it).applyOnTheLeft(it, it + 1, gr[it].adjoint());
333  g.applyOnTheLeft(it, it + 1, gr[it].adjoint());
334 
335  beta = std::abs(g(it + 1));
336  m_error = beta / normRhs;
337  // std::cerr << nbIts << " Relative Residual Norm " << m_error << std::endl;
338  it++;
339  nbIts++;
340 
341  if (m_error < m_tolerance) {
342  // The method has converged
343  m_info = Success;
344  break;
345  }
346  }
347 
348  // Compute the new coefficients by solving the least square problem
349  // it++;
350  // FIXME Check first if the matrix is singular ... zero diagonal
351  DenseVector nrs(m_restart);
352  nrs = m_H.topLeftCorner(it, it).template triangularView<Upper>().solve(g.head(it));
353 
354  // Form the new solution
355  if (m_isDeflInitialized) {
356  tv1 = m_V.leftCols(it) * nrs;
357  dgmresApplyDeflation(tv1, tv2);
358  x = x + precond.solve(tv2);
359  } else
360  x = x + precond.solve(m_V.leftCols(it) * nrs);
361 
362  // Go for a new cycle and compute data for deflation
363  if (nbIts < m_iterations && m_info == NoConvergence && m_neig > 0 && (m_r + m_neig) < m_maxNeig)
364  dgmresComputeDeflationData(mat, precond, it, m_neig);
365  return 0;
366 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
void adjoint(const MatrixType &m)
Definition: adjoint.cpp:85
Index dgmresApplyDeflation(const RhsType &In, DestType &Out) const
Definition: DGMRES.h:484
MatrixType::Scalar Scalar
Definition: DGMRES.h:111
Index dgmresComputeDeflationData(const MatrixType &mat, const Preconditioner &precond, const Index &it, StorageIndex &neig) const
Definition: DGMRES.h:405
Scalar dot(const MatrixBase< OtherDerived > &other) const

References abs(), adjoint(), beta, i, n, Eigen::NoConvergence, Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::rows(), Eigen::PlainObjectBase< Derived >::setZero(), Eigen::Success, and plotDoE::x.

◆ dgmresInitDeflation()

template<typename MatrixType_ , typename Preconditioner_ >
void Eigen::DGMRES< MatrixType_, Preconditioner_ >::dgmresInitDeflation ( Index rows) const
protected
369  {
373  m_lambdaN = 0.0;
374  m_isDeflAllocated = true;
375 }

References rows.

◆ matrix()

template<typename MatrixType_ , typename Preconditioner_ >
const ActualMatrixType& Eigen::IterativeSolverBase< Derived >::matrix
inlineprivate

◆ restart()

template<typename MatrixType_ , typename Preconditioner_ >
Index Eigen::DGMRES< MatrixType_, Preconditioner_ >::restart ( )
inline

◆ schurValues() [1/2]

template<typename MatrixType_ , typename Preconditioner_ >
DGMRES< MatrixType_, Preconditioner_ >::ComplexVector Eigen::DGMRES< MatrixType_, Preconditioner_ >::schurValues ( const ComplexSchur< DenseMatrix > &  schurofH) const
inlineprotected
379  {
380  return schurofH.matrixT().diagonal();
381 }

References Eigen::ComplexSchur< MatrixType_ >::matrixT().

◆ schurValues() [2/2]

template<typename MatrixType_ , typename Preconditioner_ >
DGMRES< MatrixType_, Preconditioner_ >::ComplexVector Eigen::DGMRES< MatrixType_, Preconditioner_ >::schurValues ( const RealSchur< DenseMatrix > &  schurofH) const
inlineprotected
385  {
386  const DenseMatrix& T = schurofH.matrixT();
387  Index it = T.rows();
388  ComplexVector eig(it);
389  Index j = 0;
390  while (j < it - 1) {
391  if (T(j + 1, j) == Scalar(0)) {
392  eig(j) = std::complex<RealScalar>(T(j, j), RealScalar(0));
393  j++;
394  } else {
395  eig(j) = std::complex<RealScalar>(T(j, j), T(j + 1, j));
396  eig(j + 1) = std::complex<RealScalar>(T(j, j + 1), T(j + 1, j + 1));
397  j++;
398  }
399  }
400  if (j < it - 1) eig(j) = std::complex<RealScalar>(T(j, j), RealScalar(0));
401  return eig;
402 }
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11

References j, and Eigen::RealSchur< MatrixType_ >::matrixT().

◆ set_restart()

template<typename MatrixType_ , typename Preconditioner_ >
void Eigen::DGMRES< MatrixType_, Preconditioner_ >::set_restart ( const Index  restart)
inline

Set the restart value (default is 30)

167 { m_restart = restart; }
Index restart()
Definition: DGMRES.h:162

References Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_restart, and Eigen::DGMRES< MatrixType_, Preconditioner_ >::restart().

◆ setEigenv()

template<typename MatrixType_ , typename Preconditioner_ >
void Eigen::DGMRES< MatrixType_, Preconditioner_ >::setEigenv ( const Index  neig)
inline

Set the number of eigenvalues to deflate at each restart

172  {
173  m_neig = neig;
174  if (neig + 1 > m_maxNeig) m_maxNeig = neig + 1; // To allow for complex conjugates
175  }

References Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_maxNeig, and Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_neig.

◆ setMaxEigenv()

template<typename MatrixType_ , typename Preconditioner_ >
void Eigen::DGMRES< MatrixType_, Preconditioner_ >::setMaxEigenv ( const Index  maxNeig)
inline

Set the maximum size of the deflation subspace

185 { m_maxNeig = maxNeig; }

References Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_maxNeig.

Member Data Documentation

◆ m_error

template<typename MatrixType_ , typename Preconditioner_ >
RealScalar Eigen::IterativeSolverBase< Derived >::m_error
mutableprivate

◆ m_force

template<typename MatrixType_ , typename Preconditioner_ >
bool Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_force
mutableprotected

◆ m_H

template<typename MatrixType_ , typename Preconditioner_ >
DenseMatrix Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_H
mutableprotected

◆ m_Hes

template<typename MatrixType_ , typename Preconditioner_ >
DenseMatrix Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_Hes
mutableprotected

◆ m_info

template<typename MatrixType_ , typename Preconditioner_ >
ComputationInfo Eigen::IterativeSolverBase< Derived >::m_info
mutableprivate

◆ m_isDeflAllocated

template<typename MatrixType_ , typename Preconditioner_ >
bool Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_isDeflAllocated
mutableprotected

◆ m_isDeflInitialized

template<typename MatrixType_ , typename Preconditioner_ >
bool Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_isDeflInitialized
mutableprotected

◆ m_isInitialized

template<typename MatrixType_ , typename Preconditioner_ >
bool Eigen::SparseSolverBase< Derived >::m_isInitialized
mutableprivate

◆ m_iterations

template<typename MatrixType_ , typename Preconditioner_ >
Index Eigen::IterativeSolverBase< Derived >::m_iterations
mutableprivate

◆ m_lambdaN

template<typename MatrixType_ , typename Preconditioner_ >
RealScalar Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_lambdaN
mutableprotected

◆ m_luT

template<typename MatrixType_ , typename Preconditioner_ >
PartialPivLU<DenseMatrix> Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_luT
mutableprotected

◆ m_maxNeig

template<typename MatrixType_ , typename Preconditioner_ >
Index Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_maxNeig
mutableprotected

◆ m_MU

template<typename MatrixType_ , typename Preconditioner_ >
DenseMatrix Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_MU
mutableprotected

◆ m_neig

template<typename MatrixType_ , typename Preconditioner_ >
StorageIndex Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_neig
mutableprotected

◆ m_r

template<typename MatrixType_ , typename Preconditioner_ >
Index Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_r
mutableprotected

◆ m_restart

template<typename MatrixType_ , typename Preconditioner_ >
Index Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_restart
mutableprotected

◆ m_smv

template<typename MatrixType_ , typename Preconditioner_ >
RealScalar Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_smv
mutableprotected

◆ m_T

template<typename MatrixType_ , typename Preconditioner_ >
DenseMatrix Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_T
mutableprotected

◆ m_tolerance

template<typename MatrixType_ , typename Preconditioner_ >
RealScalar Eigen::IterativeSolverBase< Derived >::m_tolerance
private

◆ m_U

template<typename MatrixType_ , typename Preconditioner_ >
DenseMatrix Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_U
mutableprotected

◆ m_V

template<typename MatrixType_ , typename Preconditioner_ >
DenseMatrix Eigen::DGMRES< MatrixType_, Preconditioner_ >::m_V
mutableprotected

The documentation for this class was generated from the following file: