Skip to content

Commit 3241a23

Browse files
alxbilgerepernod
authored andcommitted
[LinearSolver] Fix applyConstraintForce broken in sofa-framework#5648
1 parent 1c72584 commit 3241a23

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ProjectedGaussSeidelConstraintSolver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ void ProjectedGaussSeidelConstraintSolver::gaussSeidel_increment(bool measureErr
204204
{
205205
for(int j=0; j<dim; ) // increment of j realized at the end of the loop
206206
{
207+
assert(j < constraintCorrections.size());
208+
assert(constraintCorrections[j] != nullptr);
209+
207210
//1. nbLines provide the dimension of the constraint
208211
const unsigned int nb = constraintCorrections[j]->getNbLines();
209212

@@ -288,4 +291,4 @@ void registerProjectedGaussSeidelConstraintSolver(sofa::core::ObjectFactory* fac
288291
}
289292

290293

291-
}
294+
}

Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,15 @@ template<class Matrix, class Vector>
492492
void MatrixLinearSolver<Matrix,Vector>::applyConstraintForce(const sofa::core::ConstraintParams* cparams, sofa::core::MultiVecDerivId dx, const linearalgebra::BaseVector* f)
493493
{
494494
auto* systemMatrix = l_linearSystem->getSystemMatrix();
495+
auto* lhsVector = l_linearSystem->getSolutionVector();
495496
auto* rhsVector = l_linearSystem->getRHSVector();
496497

497498
rhsVector->clear();
498499
rhsVector->resize(systemMatrix->colSize());
499500
/// rhs = J^t * f
500501
internalData.projectForceInConstraintSpace(rhsVector, f);
501502
/// lhs = M^-1 * rhs
502-
this->solve(*systemMatrix, *rhsVector, *rhsVector);
503+
this->solve(*systemMatrix, *lhsVector, *rhsVector);
503504

504505
l_linearSystem->dispatchSystemSolution(dx);
505506
l_linearSystem->dispatchSystemRHS(cparams->lambda());

examples/Component/Constraint/Lagrangian/InextensiblePendulum.scn

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
<!-- A pendulum made of a string of particles connected by distance constraints -->
44
<!-- Inspired by the CompliantPendulum.scn from the Compliant plugin -->
55
<Node name="Root" gravity="0 -10 0" time="0" animate="0" dt="0.01">
6-
<RequiredPlugin name="Sofa.Component.AnimationLoop"/> <!-- Needed to use components [FreeMotionAnimationLoop] -->
7-
<RequiredPlugin name="Sofa.Component.Constraint.Lagrangian.Correction"/> <!-- Needed to use components [GenericConstraintCorrection] -->
8-
<RequiredPlugin name="Sofa.Component.Constraint.Lagrangian.Model"/> <!-- Needed to use components [UniformLagrangianConstraint] -->
9-
<RequiredPlugin name="Sofa.Component.Constraint.Lagrangian.Solver"/> <!-- Needed to use components [GenericConstraintSolver] -->
10-
<RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedProjectiveConstraint] -->
11-
<RequiredPlugin name="Sofa.Component.Engine.Select"/> <!-- Needed to use components [PointsFromIndices] -->
12-
<RequiredPlugin name="Sofa.Component.Engine.Transform"/> <!-- Needed to use components [TransformEngine] -->
13-
<RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [StringMeshCreator] -->
14-
<RequiredPlugin name="Sofa.Component.LinearSolver.Direct"/> <!-- Needed to use components [EigenSimplicialLLT] -->
15-
<RequiredPlugin name="Sofa.Component.Mapping.NonLinear"/> <!-- Needed to use components [DistanceMapping] -->
16-
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [DiagonalMass] -->
17-
<RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] -->
18-
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
19-
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [EdgeSetGeometryAlgorithms EdgeSetTopologyContainer] -->
20-
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [TrailRenderer VisualStyle] -->
6+
<Node name="plugins">
7+
<RequiredPlugin name="Sofa.Component.AnimationLoop"/> <!-- Needed to use components [FreeMotionAnimationLoop] -->
8+
<RequiredPlugin name="Sofa.Component.Constraint.Lagrangian.Correction"/> <!-- Needed to use components [GenericConstraintCorrection] -->
9+
<RequiredPlugin name="Sofa.Component.Constraint.Lagrangian.Model"/> <!-- Needed to use components [UniformLagrangianConstraint] -->
10+
<RequiredPlugin name="Sofa.Component.Constraint.Lagrangian.Solver"/> <!-- Needed to use components [GenericConstraintSolver] -->
11+
<RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedProjectiveConstraint] -->
12+
<RequiredPlugin name="Sofa.Component.Engine.Select"/> <!-- Needed to use components [PointsFromIndices] -->
13+
<RequiredPlugin name="Sofa.Component.Engine.Transform"/> <!-- Needed to use components [TransformEngine] -->
14+
<RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [StringMeshCreator] -->
15+
<RequiredPlugin name="Sofa.Component.LinearSolver.Direct"/> <!-- Needed to use components [EigenSimplicialLLT] -->
16+
<RequiredPlugin name="Sofa.Component.Mapping.NonLinear"/> <!-- Needed to use components [DistanceMapping] -->
17+
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [DiagonalMass] -->
18+
<RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] -->
19+
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
20+
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [EdgeSetGeometryAlgorithms EdgeSetTopologyContainer] -->
21+
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [TrailRenderer VisualStyle] -->
22+
</Node>
2123

2224
<DefaultVisualManagerLoop/>
2325
<VisualStyle displayFlags="showVisualModels showBehaviorModels showMappings showForceFields" />

0 commit comments

Comments
 (0)