sofa icon indicating copy to clipboard operation
sofa copied to clipboard

[SofaSparseSolver] Fix the assembling of the constraint matrix

Open dessteph opened this issue 3 years ago • 15 comments

It seems that there was an error in the code of the SparseLDLSolver in the assembling of the constraint matrix. I tried to see the execution of this function in the scene InextensiblePendulum.scn and it produced a wrong result at the first step (with the current master branch). After this fix, it starts with a coherent behaviour but then it still fails.

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).

dessteph avatar Jun 07 '22 07:06 dessteph

  1. Indeed I changed the linear solver used in the scene. In the master branch, the code actually compute another matrix which is not the one we need. Hence the simulation fail at the first step. For this branch the smilation failed when the message "D(k,k) is zero" appear. I don't know if there is an issue with this scene or with the solver.

  2. In the code, we exploit the LDL factorization in order to solve only one triangular system (and not two). We are allowed to do that by rewriting the matricial product we need to compute. It will then write as A *D^-1 * A^t. We need to apply D^-1 and it won't commute, that is why there is two matrices in memory (we could store only one with the Cholesky factorization).

dessteph avatar Jun 07 '22 08:06 dessteph

@dessteph On my setup with the master branch, I manage to run the simulation several tens of iterations (see screenshot). So I would like to know what you mean by "the simulation fails".

image

alxbilger avatar Jun 07 '22 08:06 alxbilger

After a certain number of iterations (on my computer), an error message appears in the terminal and the simulation becomes unstable (it explodes) and that doesn't append with LU or Cholesky.

dessteph avatar Jun 07 '22 11:06 dessteph

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

alxbilger avatar Jun 10 '22 07:06 alxbilger

@dessteph I suggest you start again your investigation but taking into account https://github.com/sofa-framework/sofa/pull/3072. In other words, in your CMake, enable the variable METIS-GKLIB_GKRAND. This way we should have comparable results across different architectures.

alxbilger avatar Jun 27 '22 12:06 alxbilger

Please add unit tests based on the PR #3050

alxbilger avatar Jun 29 '22 09:06 alxbilger

Rebase on #3050 and then create a unit test on SparseLDLSolver: doAddJMInvJtLocal

hugtalbot avatar Jun 29 '22 09:06 hugtalbot

@dessteph I prepared the test in Sofa/Component/LinearSolver/Direct/tests/SparseLDLSolver_test.cpp. Could you add the check of the result at the end? You will need to use another software (matlab?) to compute the ground truth and compare it to the variable JMInvJt containing our result. Thanks

alxbilger avatar Jul 05 '22 10:07 alxbilger

[ci-build]

alxbilger avatar Jul 05 '22 10:07 alxbilger

@dessteph What is the status of this pull request? Can you provide details why we should continue working on it or not?

alxbilger avatar Jul 21 '22 13:07 alxbilger

I made an unitary test to compare the results of the LDL solver to those of the LU solver. The difference goes up to 9e-13. I would have like to compare LU and Cholesky to see if that difference is realy significative.

dessteph avatar Jul 21 '22 13:07 dessteph

And what about the result of the LDL solver with and without your changes?

alxbilger avatar Jul 21 '22 13:07 alxbilger

I tested the master branch.

dessteph avatar Jul 21 '22 13:07 dessteph

So you cannot say if your fix really fixes anything

alxbilger avatar Jul 21 '22 13:07 alxbilger

It seems it didn't need any fixing, there is a math error but compensated by a roundabout use of the CSC format.

dessteph avatar Jul 21 '22 13:07 dessteph