3 #include <Caribou/config.h>
4 #include <sofa/core/behavior/OdeSolver.h>
5 #include <sofa/core/behavior/LinearSolver.h>
6 #include <sofa/core/objectmodel/Data.h>
7 #include <sofa/defaulttype/BaseMatrix.h>
8 #include <sofa/defaulttype/BaseVector.h>
9 #include <sofa/core/objectmodel/Link.h>
10 #include <SofaBaseLinearSolver/DefaultMultiMatrixAccessor.h>
13 namespace SofaCaribou::ode {
45 using Data = sofa::core::objectmodel::Data<T>;
48 using Link = sofa::core::objectmodel::SingleLink<NewtonRaphsonSolver, T, sofa::core::objectmodel::BaseLink::FLAG_STRONGLINK>;
54 void solve (
const sofa::core::ExecParams* params, SReal dt, sofa::core::MultiVecCoordId x_id, sofa::core::MultiVecDerivId v_id)
override;
57 auto iteration_times() const -> const std::vector<UNSIGNED_INTEGER_TYPE> & {
return p_times; }
60 auto squared_residuals() const -> const std::vector<FLOATING_POINT_TYPE> & {
return p_squared_residuals; }
84 virtual void assemble_rhs_vector(
const sofa::core::MechanicalParams & mechanical_parameters,
85 const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor,
86 sofa::core::MultiVecDerivId & f_id,
87 sofa::defaulttype::BaseVector * f) = 0;
108 virtual void assemble_system_matrix(
const sofa::core::MechanicalParams & mechanical_parameters,
109 sofa::component::linearsolver::DefaultMultiMatrixAccessor & matrix_accessor,
110 sofa::defaulttype::BaseMatrix * A) = 0;
131 virtual void propagate_position_increment(
const sofa::core::MechanicalParams & mechanical_parameters,
132 const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor,
133 const sofa::defaulttype::BaseVector * dx,
134 sofa::core::MultiVecCoordId & x_id,
135 sofa::core::MultiVecDerivId & v_id,
136 sofa::core::MultiVecDerivId & dx_id) = 0;
139 bool has_valid_linear_solver ()
const;
142 Data<unsigned> d_newton_iterations;
143 Data<double> d_correction_tolerance_threshold;
144 Data<double> d_residual_tolerance_threshold;
146 Link<sofa::core::behavior::LinearSolver> l_linear_solver;
150 Data<bool> d_converged;
155 std::unique_ptr<sofa::defaulttype::BaseMatrix> p_A;
158 std::unique_ptr<sofa::defaulttype::BaseVector> p_DX;
161 std::unique_ptr<sofa::defaulttype::BaseVector> p_F;
164 sofa::core::MultiVecDerivId p_U_id;
167 std::vector<UNSIGNED_INTEGER_TYPE> p_times;
170 std::vector<FLOATING_POINT_TYPE> p_squared_residuals;
173 FLOATING_POINT_TYPE p_squared_initial_residual;