|
30 | 30 | namespace sofa::component::constraint::lagrangian::solver |
31 | 31 | { |
32 | 32 |
|
| 33 | +ImprovedJacobiConstraintSolver::ImprovedJacobiConstraintSolver() |
| 34 | + : BuiltConstraintSolver() |
| 35 | + , d_useSpectralCorrection(initData(&d_useSpectralCorrection,false,"useSpectralCorrection","If set to true, the solution found after each iteration will be multiplied by spectralCorrectionFactor*2/spr(W), with spr() denoting the spectral radius.")) |
| 36 | + , d_spectralCorrectionFactor(initData(&d_spectralCorrectionFactor,1.0,"spectralCorrectionFactor","Factor used to modulate the spectral correction")) |
| 37 | + , d_useConjugateResidue(initData(&d_useConjugateResidue,false,"useConjugateResidue","If set to true, the solution found after each iteration will be corrected along the solution direction using `\\lambda^{i+1} -= beta^{i} * (\\lambda^{i} - \\lambda^{i-1})` with beta following the formula beta^{i} = min(1, (i/maxIterations)^{conjugateResidueSpeedFactor}) ")) |
| 38 | + , d_conjugateResidueSpeedFactor(initData(&d_conjugateResidueSpeedFactor,10.0,"conjugateResidueSpeedFactor","FActor used to modulate the speed in which beta used in the conjugate residue part reaches 1.0. The higher the value, the slower the reach. ")) |
| 39 | +{ |
| 40 | + |
| 41 | +} |
| 42 | + |
| 43 | + |
33 | 44 | void ImprovedJacobiConstraintSolver::doSolve( SReal timeout) |
34 | 45 | { |
35 | 46 | SCOPED_TIMER_VARNAME(gaussSeidelTimer, "ImprovedJacobiConstraintSolver"); |
@@ -90,21 +101,26 @@ void ImprovedJacobiConstraintSolver::doSolve( SReal timeout) |
90 | 101 |
|
91 | 102 | int iterCount = 0; |
92 | 103 |
|
93 | | - Eigen::Map<Eigen::MatrixX<SReal>> EigenW(w[0],dimension, dimension) ; |
94 | | - SReal eigenRadius = 0; |
95 | | - for(auto s : EigenW.eigenvalues()) |
| 104 | + SReal rho = 1.0; |
| 105 | + |
| 106 | + if (d_useSpectralCorrection.getValue()) |
96 | 107 | { |
97 | | - eigenRadius=std::max(eigenRadius,norm(s)); |
| 108 | + Eigen::Map<Eigen::MatrixX<SReal>> EigenW(w[0],dimension, dimension) ; |
| 109 | + SReal eigenRadius = 0; |
| 110 | + for(auto s : EigenW.eigenvalues()) |
| 111 | + { |
| 112 | + eigenRadius=std::max(eigenRadius,norm(s)); |
| 113 | + } |
| 114 | + rho = d_spectralCorrectionFactor.getValue()*std::min(1.0, 0.9 * 2/eigenRadius); |
98 | 115 | } |
99 | | - const SReal rho = std::min(1.0, 0.9 * 2/eigenRadius); |
100 | 116 |
|
101 | 117 | for(int i=0; i<current_cp->maxIterations; i++) |
102 | 118 | { |
103 | 119 | iterCount ++; |
104 | 120 | bool constraintsAreVerified = true; |
105 | 121 |
|
106 | 122 | error=0.0; |
107 | | - SReal beta = std::min(1.0, pow( ((float)i)/current_cp->maxIterations,0.6)); |
| 123 | + SReal beta = d_useConjugateResidue.getValue() * std::min(1.0, pow( ((float)i)/current_cp->maxIterations,d_conjugateResidueSpeedFactor.getValue())); |
108 | 124 |
|
109 | 125 | for(int j=0; j<dimension; ) // increment of j realized at the end of the loop |
110 | 126 | { |
|
0 commit comments