Skip to content

Conversation

@alxbilger
Copy link
Contributor

@alxbilger alxbilger commented Aug 6, 2025

In #2777, the matrix assembly was removed from the linear solver. Instead, the assembly is done in a dedicated component, a linear system. However, linear solvers still kept an API related to the matrix assembly. This PR removes this API for a clearer one, where both solvers and systems have their own responsibilities.

With this work, we will be able to assemble different systems while keeping the same linear solvers. For example, an augmented system containing also lagrangian constraints.

An interesting consequence is that a linear solver is now agnostic to the simulated physic: no mass factor, stiffness factor, damping factor. The assembly of the mass, damping and stiffness is now totally in the linear system. We can now imagine a linear system assembling different types of physics, while keeping the same linear solvers.

I took the opportunity to clean a few things in the preconditioners.

Additions:

  • A new Data authorizeAssembly in BaseMatrixLinearSystem. This Data is hidden to the user. This Data exists to use the DDGNode system, in particular in the asynchronous solver.
  • Similarly, a new Data factorizationInvalidation is introduced in MatrixLinearSolver. This Data is linked to the Data matrixChanged, also newly introduced, and serves as an observer for matrix changes. That way, the solver decompose the matrix only if a change in the matrix occurred.
  • CompositeLinearSystem is now templated also on GraphScatteredMatrix.
  • PreconditionedMatrixFreeSystem is a new component of the categories of the linear systems. It is intended to work with PCGLinearSolver. The specificity of this linear system is the link toward a the linear system of the preconditioner. It has a Data assemblingRate, allowing to assemble the matrix of the preconditioner only at a given rate. It is templated only on GraphScatteredMatrix since it works only with PCGLinearSolver.

Changes:

  • Some types involving scalar types are changed from double to Real
  • When there is no linear system in the scene, the linear solver instantiates automatically a linear system component. Before it was added as a slave, mainly for UX reasons. However, slaves are not visited by the visitors. Therefore, linear systems are no longer a slave when instantiated automatically.
  • The Data update_step is removed in PCGLinearSolver. Since the solvers are no longer responsible to assemble the matrices, this Data is no longer used. Instead, the equivalent of this Data is now in PreconditionedMatrixFreeSystem.
  • The assembly in the WarpPreconditioner is now transferred to RotationMatrixSystem. Similarly to PreconditionedMatrixFreeSystem, it has also a Data assemblingRate.
  • The rotation finder is now an explicit link in RotationMatrixSystem. Before it was found implicitly with an index in WarpPreconditioner.

To do:

  • Fix warp preconditioner
  • Proper deprecation
  • Review of the constraints, including the preconditioners
  • Fix MechanicalMultiVectorPeqBaseVectorVisitor in MatrixLinearSolver

[ci-depends-on https://github.com/sofa-framework/SofaPython3/pull/528]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@alxbilger alxbilger added the pr: clean Cleaning the code label Aug 6, 2025
@alxbilger
Copy link
Contributor Author

[ci-build][with-all-tests]

@sofabot
Copy link
Collaborator

sofabot commented Aug 7, 2025

[ci-depends-on] detected during build #2.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Aug 7, 2025

[ci-depends-on] detected during build #3.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Aug 7, 2025

[ci-depends-on] detected during build #4.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Aug 7, 2025

[ci-depends-on] detected during build #5.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Aug 8, 2025

[ci-depends-on] detected during build #6.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Aug 8, 2025

[ci-depends-on] detected during build #7.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Aug 8, 2025

[ci-depends-on] detected during build #8.

To unlock the merge button, you must

@alxbilger alxbilger added this to the v25.12 milestone Aug 8, 2025
@alxbilger alxbilger added the pr: status to review To notify reviewers to review this pull-request label Sep 1, 2025
@sofabot
Copy link
Collaborator

sofabot commented Sep 8, 2025

[ci-depends-on] detected during build #9.

To unlock the merge button, you must

virtual void applyConstraintForce(const sofa::core::ConstraintParams* /*cparams*/,sofa::core::MultiVecDerivId /*dx*/, const linearalgebra::BaseVector* /*f*/) {
msg_error() << "applyConstraintForce has not been implemented.";
}
virtual void applyConstraintForce(const sofa::core::ConstraintParams* /*cparams*/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, not in the scope of this PR, but why do we need this ? Isn't addMinvJt enough ?

@bakpaul
Copy link
Contributor

bakpaul commented Sep 8, 2025

Ok so now the only purpose of a linear solver is to solve inverse linear problem given a LinearSystem that is responsible of defining the RHS and the LHS ?

If the solver is a direct one, let's says a Cholesky solver, where is the decomposition supposed to be stored ? If the Solver is agnostic to the system, then it should not keep track of this decomposition no ? If in the future we would like to have many different LinearSystem using the same solver then they should somehow keep this info. Or maybe an intermediate map in the solver ?

@alxbilger
Copy link
Contributor Author

Ok so now the only purpose of a linear solver is to solve inverse linear problem given a LinearSystem that is responsible of defining the RHS and the LHS ?

If the solver is a direct one, let's says a Cholesky solver, where is the decomposition supposed to be stored ? If the Solver is agnostic to the system, then it should not keep track of this decomposition no ? If in the future we would like to have many different LinearSystem using the same solver then they should somehow keep this info. Or maybe an intermediate map in the solver ?

@bakpaul The linear solver is still bound to a single linear system through its Link. It think it still makes sense to have the decomposition in the solver because of that.

The intention with this PR was only to remove the assembly part in the API of the solver.

@sofabot
Copy link
Collaborator

sofabot commented Sep 18, 2025

[ci-depends-on] detected during build #10.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Sep 18, 2025

[ci-depends-on] detected during build #11.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Sep 19, 2025

[ci-depends-on] detected during build #12.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Sep 19, 2025

[ci-depends-on] detected during build #13.

To unlock the merge button, you must

@bakpaul bakpaul added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Sep 24, 2025
@sofabot
Copy link
Collaborator

sofabot commented Oct 9, 2025

[ci-depends-on] detected during build #14.

To unlock the merge button, you must

@alxbilger alxbilger added pr: breaking Change possibly inducing a compilation error pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Oct 9, 2025
@alxbilger alxbilger marked this pull request as ready for review October 9, 2025 15:49
@alxbilger
Copy link
Contributor Author

[ci-build][with-all-tests]

@sofabot
Copy link
Collaborator

sofabot commented Oct 9, 2025

[ci-depends-on] detected during build #15.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Oct 10, 2025

[ci-depends-on] detected during build #16.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Nov 6, 2025

[ci-depends-on] detected during build #24.

To unlock the merge button, you must

@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Nov 6, 2025
@fredroy
Copy link
Contributor

fredroy commented Nov 7, 2025

[ci-build][with-all-tests][force-full-build]

@sofabot
Copy link
Collaborator

sofabot commented Nov 7, 2025

[ci-depends-on] detected during build #25.

To unlock the merge button, you must

@hugtalbot hugtalbot removed the request for review from bakpaul November 11, 2025 13:25
@hugtalbot
Copy link
Contributor

[ci-build][with-all-tests][force-full-build]

@sofabot
Copy link
Collaborator

sofabot commented Nov 11, 2025

[ci-depends-on] detected during build #26.

All dependencies are merged/closed. Congrats! 👍

@hugtalbot hugtalbot merged commit 60d44cf into sofa-framework:master Nov 11, 2025
11 of 15 checks passed
alxbilger added a commit to alxbilger/sofa that referenced this pull request Nov 12, 2025
epernod pushed a commit to alxbilger/sofa that referenced this pull request Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: breaking Change possibly inducing a compilation error pr: clean Cleaning the code pr: status ready Approved a pull-request, ready to be squashed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants