SOFA API  1df67014
Open source framework for multi-physics simuation
sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector > Class Template Reference

#include <CGLinearSolver.h>

Linear system solver using the conjugate gradient iterative algorithm. More...

Inheritance diagram for sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >:

Detailed Description

template<class TMatrix, class TVector>
class sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >

Linear system solver using the conjugate gradient iterative algorithm.

Public Attributes

Data< unsigned > d_maxIter
 maximum number of iterations of the Conjugate Gradient solution More...
 
Data< Reald_tolerance
 desired precision of the Conjugate Gradient Solution (ratio of current residual norm over initial residual norm) More...
 
Data< Reald_smallDenominatorThreshold
 minimum value of the denominator in the conjugate Gradient solution More...
 
Data< boold_warmStart
 Use previous solution as initial solution. More...
 
Data< std::map< std::string, sofa::type::vector< Real > > > d_graph
 Graph of residuals at each iteration. More...
 

Protected Attributes

int timeStepCount {0}
 
bool equilibriumReached {false}
 

Public Member Functions

 SOFA_CLASS (SOFA_TEMPLATE2(CGLinearSolver, TMatrix, TVector), SOFA_TEMPLATE2(sofa::component::linearsolver::MatrixLinearSolver, TMatrix, TVector))
 
void init () override
 Initialization function checking input Data. More...
 
void reinit () override
 
void resetSystem () override
 Clear graph and clean the RHS / LHS vectors. More...
 
void setSystemMBKMatrix (const sofa::core::MechanicalParams *mparams) override
 
void solve (Matrix &A, Vector &x, Vector &b) override
 Solve iteratively the linear system Ax=b following a conjugate gradient descent. More...
 
- Public Member Functions inherited from sofa::component::linearsolver::MatrixLinearSolver< TMatrix, TVector >
void resetSystem ()
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void resetSystem ()
 
void resizeSystem (Size n)
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void resizeSystem (Size)
 
void setSystemMBKMatrix (const core::MechanicalParams *mparams)
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void setSystemMBKMatrix (const core::MechanicalParams *mparams)
 
void rebuildSystem (SReal, SReal)
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void rebuildSystem (SReal massFactor, SReal forceFactor)
 
void setSystemLHVector (core::MultiVecDerivId v)
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void setSystemLHVector (core::MultiVecDerivId v)
 
void applySystemSolution ()
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void applySystemSolution ()
 
void applyConstraintForce (const sofa::core::ConstraintParams *, sofa::core::MultiVecDerivId, const linearalgebra::BaseVector *)
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void applyConstraintForce (const sofa::core::ConstraintParams *, sofa::core::MultiVecDerivId, const linearalgebra::BaseVector *)
 
void computeResidual (const core::ExecParams *, linearalgebra::BaseVector *)
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void computeResidual (const core::ExecParams *params, linearalgebra::BaseVector *f)
 
GraphScatteredVectorcreatePersistentVector ()
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API GraphScatteredVectorcreatePersistentVector ()
 
linearalgebra::BaseMatrixgetSystemBaseMatrix ()
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API linearalgebra::BaseMatrixgetSystemBaseMatrix ()
 
linearalgebra::BaseVectorgetSystemRHBaseVector ()
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API linearalgebra::BaseVectorgetSystemRHBaseVector ()
 
linearalgebra::BaseVectorgetSystemLHBaseVector ()
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API linearalgebra::BaseVectorgetSystemLHBaseVector ()
 
void checkLinearSystem ()
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void checkLinearSystem ()
 
bool addJMInvJtLocal (GraphScatteredMatrix *M, MatrixLinearSolver< GraphScatteredMatrix, GraphScatteredVector, NoThreadManager >::ResMatrixType *result, const MatrixLinearSolver< GraphScatteredMatrix, GraphScatteredVector, NoThreadManager >::JMatrixType *J, const SReal fact)
 

Protected Member Functions

 CGLinearSolver ()
 Linear system solver using the conjugate gradient iterative algorithm. More...
 
void cgstep_beta (const core::ExecParams *params, Vector &p, Vector &r, Real beta)
 
void cgstep_alpha (const core::ExecParams *params, Vector &x, Vector &r, Vector &p, Vector &q, Real alpha)
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void cgstep_beta (const core::ExecParams *, Vector &p, Vector &r, Real beta)
 
SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void cgstep_alpha (const core::ExecParams *params, Vector &x, Vector &r, Vector &p, Vector &q, Real alpha)
 
void cgstep_beta (const core::ExecParams *, Vector &p, Vector &r, Real beta)
 
void cgstep_alpha (const core::ExecParams *params, Vector &x, Vector &r, Vector &p, Vector &q, Real alpha)
 

Attribute details

◆ d_graph

template<class TMatrix , class TVector >
Data<std::map < std::string, sofa::type::vector<Real> > > sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::d_graph

Graph of residuals at each iteration.

◆ d_maxIter

template<class TMatrix , class TVector >
Data<unsigned> sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::d_maxIter

maximum number of iterations of the Conjugate Gradient solution

◆ d_smallDenominatorThreshold

template<class TMatrix , class TVector >
Data<Real> sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::d_smallDenominatorThreshold

minimum value of the denominator in the conjugate Gradient solution

◆ d_tolerance

template<class TMatrix , class TVector >
Data<Real> sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::d_tolerance

desired precision of the Conjugate Gradient Solution (ratio of current residual norm over initial residual norm)

◆ d_warmStart

template<class TMatrix , class TVector >
Data<bool> sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::d_warmStart

Use previous solution as initial solution.

◆ equilibriumReached

template<class TMatrix , class TVector >
bool sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::equilibriumReached {false}
protected

◆ timeStepCount

template<class TMatrix , class TVector >
int sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::timeStepCount {0}
protected

Constructor details

◆ CGLinearSolver()

template<class TMatrix , class TVector >
sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::CGLinearSolver
protected

Linear system solver using the conjugate gradient iterative algorithm.

Function details

◆ cgstep_alpha() [1/3]

SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void sofa::component::linearsolver::iterative::CGLinearSolver< component::linearsolver::GraphScatteredMatrix, component::linearsolver::GraphScatteredVector >::cgstep_alpha ( const core::ExecParams params,
Vector x,
Vector r,
Vector p,
Vector q,
Real  alpha 
)
inlineprotected

◆ cgstep_alpha() [2/3]

template<class TMatrix , class TVector >
void sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::cgstep_alpha ( const core::ExecParams params,
Vector x,
Vector r,
Vector p,
Vector q,
Real  alpha 
)
inlineprotected

This method is separated from the rest to be able to use custom/optimized versions depending on the types of vectors. It computes: x += p*alpha, r -= q*alpha

◆ cgstep_alpha() [3/3]

◆ cgstep_beta() [1/3]

SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API void sofa::component::linearsolver::iterative::CGLinearSolver< component::linearsolver::GraphScatteredMatrix, component::linearsolver::GraphScatteredVector >::cgstep_beta ( const core::ExecParams ,
Vector p,
Vector r,
Real  beta 
)
inlineprotected

◆ cgstep_beta() [2/3]

◆ cgstep_beta() [3/3]

template<class TMatrix , class TVector >
void sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::cgstep_beta ( const core::ExecParams params,
Vector p,
Vector r,
Real  beta 
)
inlineprotected

This method is separated from the rest to be able to use custom/optimized versions depending on the types of vectors. It computes: p = p*beta + r

◆ init()

template<class TMatrix , class TVector >
void sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::init ( void  )
override

Initialization function checking input Data.

◆ reinit()

template<class TMatrix , class TVector >
void sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::reinit ( )
inlineoverride

◆ resetSystem()

template<class TMatrix , class TVector >
void sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::resetSystem
override

Clear graph and clean the RHS / LHS vectors.

◆ setSystemMBKMatrix()

template<class TMatrix , class TVector >
void sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::setSystemMBKMatrix ( const sofa::core::MechanicalParams mparams)
override

For unbuilt approach (e.g. with GraphScattered types), it passes the coefficients multiplying the matrices M, B and K from the ODE to the LinearSolver (MechanicalOperations::setKFactor) and includes a resetSystem In other cases the global system matrix is setup (pass coefficients with MechanicalOperations::setKFactor) and built it by calling the addMBKToMatrix visitor

◆ SOFA_CLASS()

template<class TMatrix , class TVector >
sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::SOFA_CLASS ( SOFA_TEMPLATE2(CGLinearSolver< TMatrix, TVector >, TMatrix, TVector)  ,
SOFA_TEMPLATE2(sofa::component::linearsolver::MatrixLinearSolver, TMatrix, TVector)   
)

◆ solve()

template<class TMatrix , class TVector >
void sofa::component::linearsolver::iterative::CGLinearSolver< TMatrix, TVector >::solve ( Matrix A,
Vector x,
Vector b 
)
override

Solve iteratively the linear system Ax=b following a conjugate gradient descent.