Implements a Conjugate Gradient method for solving a linear system of the type Ax = b.
When using no preconditioner, no actual system is built by this component, meaning that the matrix A, and the vectors x and b are never accumulated into memory. Instead, this solver relies on the vectors stored in the mechanical objects of the current scene context graph. The multiplication of the matrix A and a given vector x is computed by accumulating the result b=Ax from ff.addDForce(x, b) of every forcefields acting on a given mechanical object.
When using a preconditioner, the matrix has to be assembled since the preconditioner needs to factorize it. In this case, the complete system matrix A and dense vector b are first accumulated from the mechanical objects of the current scene context graph. Once the dense vector x is found, it is propagated back to the mechanical object's vectors.
|
| SOFA_CLASS (ConjugateGradientSolver, LinearSolver) |
|
void | resetSystem () final |
| Reset the complete system (A, x and b are cleared). More...
|
|
void | setSystemMBKMatrix (const sofa::core::MechanicalParams *mparams) final |
| Set the linear system matrix A = (mM + bB + kK), storing the coefficients m, b and k of the mechanical M,B,K matrices. More...
|
|
void | setSystemRHVector (sofa::core::MultiVecDerivId b_id) final |
| Gives the identifier of the right-hand side vector b. More...
|
|
void | setSystemLHVector (sofa::core::MultiVecDerivId x_id) final |
| Gives the identifier of the left-hand side vector x. More...
|
|
void | solveSystem () final |
| Solves the system by the conjugate gradient method using the coefficients m, b and k; and the vectors x and b.
|
|
auto | squared_residuals () const -> const std::vector< FLOATING_POINT_TYPE > & |
| List of squared residual norms (||r||^2) of every CG iterations of the last solve call.
|
|
auto | squared_initial_residual () const -> const FLOATING_POINT_TYPE & |
| Squared residual norm (||r||^2) of the last right-hand side term (b in Ax=b) of the last solve call.
|
|
auto | system_matrix () const -> const SparseMatrix & |
| Get the system matrix.
|
|
void | assemble (const sofa::core::MechanicalParams *mparams) |
| Assemble the system matrix A = (mM + bB + kK). More...
|
|
virtual sofa::defaulttype::BaseMatrix * | create_new_matrix (unsigned int rows, unsigned int cols) const =0 |
| Creates a new BaseMatrix of size rows x cols. More...
|
|
virtual sofa::defaulttype::BaseVector * | create_new_vector (unsigned int n) const =0 |
| Creates a new BaseVector of size n. More...
|
|
virtual bool | solve (const sofa::defaulttype::BaseMatrix *A, const sofa::defaulttype::BaseVector *F, sofa::defaulttype::BaseVector *X) const =0 |
| Solve the linear system A [X] = F. More...
|
|
void SofaCaribou::solver::ConjugateGradientSolver::resetSystem |
( |
| ) |
|
|
final |
Reset the complete system (A, x and b are cleared).
When using no preconditioner (None), this does absolutely nothing here since the complete system is never built.
This method is called by the MultiMatrix::clear() and MultiMatrix::reset() methods.
void SofaCaribou::solver::ConjugateGradientSolver::setSystemMBKMatrix |
( |
const sofa::core::MechanicalParams * |
mparams | ) |
|
|
final |
Set the linear system matrix A = (mM + bB + kK), storing the coefficients m, b and k of the mechanical M,B,K matrices.
When using no preconditioner (None), no actual matrix is built by this method since it is not required by the Conjugate Gradient algorithm. Only the coefficients m, b and k are stored.
When using a preconditioner, the complete system A is accumulated into a sparse matrix, and the preconditioner factorize this resulting matrix for later use during the solve step.
- Parameters
-
mparams | Contains the coefficients m, b and k of the matrices M, B and K |