3 #include <Caribou/config.h>
4 #include <sofa/core/behavior/LinearSolver.h>
5 #include <sofa/core/behavior/MultiVec.h>
6 #include <SofaBaseLinearSolver/DefaultMultiMatrixAccessor.h>
7 #include <sofa/helper/OptionsGroup.h>
10 #include <Eigen/IterativeLinearSolvers>
12 namespace SofaCaribou::solver {
14 using sofa::core::objectmodel::Data;
15 using namespace sofa::component::linearsolver;
16 using namespace sofa::core::behavior;
37 using SparseMatrix = Eigen::SparseMatrix<FLOATING_POINT_TYPE, Eigen::ColMajor>;
38 using Vector = Eigen::Matrix<FLOATING_POINT_TYPE, Eigen::Dynamic, 1>;
51 #if EIGEN_VERSION_AT_LEAST(3,3,0)
52 IncompleteCholesky = 4,
68 void resetSystem() final;
82 void setSystemMBKMatrix(const sofa::core::MechanicalParams* mparams) final;
89 void setSystemRHVector(sofa::core::MultiVecDerivId b_id) final;
96 void setSystemLHVector(sofa::core::MultiVecDerivId x_id) final;
102 void solveSystem() final;
107 auto squared_residuals() const -> const std::vector<FLOATING_POINT_TYPE> & {
108 return p_squared_residuals;
115 return p_squared_initial_residual;
129 void assemble (
const sofa::core::MechanicalParams* mparams);
147 void solve(sofa::core::behavior::MultiVecDeriv & b, sofa::core::behavior::MultiVecDeriv & x);
160 template <
typename Matrix,
typename Preconditioner>
161 void solve(
const Preconditioner & precond,
const Matrix & A,
const Vector & b, Vector & x);
165 Data<unsigned int> d_maximum_number_of_iterations;
166 Data<FLOATING_POINT_TYPE> d_residual_tolerance_threshold;
167 Data< sofa::helper::OptionsGroup > d_preconditioning_method;
174 PreconditioningMethod get_preconditioning_method_from_string(
const std::string & preconditioner_name)
const;
178 sofa::core::MechanicalParams p_mechanical_params;
181 DefaultMultiMatrixAccessor p_accessor;
184 sofa::core::MultiVecDerivId p_b_id;
187 sofa::core::MultiVecDerivId p_x_id;
199 Eigen::IdentityPreconditioner p_identity;
202 Eigen::DiagonalPreconditioner<FLOATING_POINT_TYPE> p_diag;
204 #if EIGEN_VERSION_AT_LEAST(3,3,0)
205 Eigen::IncompleteCholesky<FLOATING_POINT_TYPE> p_ichol;
210 Eigen::IncompleteLUT<FLOATING_POINT_TYPE> p_iLU;
213 std::vector<std::pair<std::string, PreconditioningMethod>> p_preconditioners;
216 std::vector<FLOATING_POINT_TYPE> p_squared_residuals;
219 FLOATING_POINT_TYPE p_squared_initial_residual;