Skip to content

Conversation

@remibessard
Copy link
Contributor

@remibessard remibessard commented Dec 11, 2025

Update SpringForceField so that it handles configuration singularity in simulation by adding regularization term (so that matrix can be inverted).


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

…in simulation by adding regularisation term (so that matrix can be inverted)
@fredroy fredroy added pr: enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request labels Dec 11, 2025
{
m(j,k) = ((Real)spring.ks-tgt) * u[j] * u[k];
m[j][k] = ((Real)spring.ks-tgt) * u[j] * u[k];
m[j][k] += (isSingular) ? regParam * spring.ks * (((j==k) ? 1.0: 0.0) - u[j] * u[k]) : 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
m[j][k] += (isSingular) ? regParam * spring.ks * (((j==k) ? 1.0: 0.0) - u[j] * u[k]) : 0.0;
if (isSingular && (j==k))
m[j][k] += regParam * spring.ks * (1 - u[j] * u[k]);

This is more readable.

@hugtalbot hugtalbot changed the title [Spring] UPDATE SpringForceField so that it handles configuration singularity … [Spring] SpringForceField now handles configuration singularity Dec 11, 2025
@hugtalbot
Copy link
Contributor

Very nice to see your contributions @remibessard 👍 👍 👍 👍

@hugtalbot hugtalbot added this to the v26.06 milestone Dec 12, 2025
Comment on lines +555 to +556
m[j][k] = ((Real)spring.ks-tgt) * u[j] * u[k];
m[j][k] += (isSingular) ? regParam * spring.ks * (((j==k) ? 1.0: 0.0) - u[j] * u[k]) : 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
m[j][k] = ((Real)spring.ks-tgt) * u[j] * u[k];
m[j][k] += (isSingular) ? regParam * spring.ks * (((j==k) ? 1.0: 0.0) - u[j] * u[k]) : 0.0;
m(j,k) = ((Real)spring.ks-tgt) * u[j] * u[k];
m(j,k) += (isSingular) ? regParam * spring.ks * (((j==k) ? 1.0: 0.0) - u[j] * u[k]) : 0.0;

// dF = k_s.U.U^T.dX + f/l.(I-U.U^T).dX = ((k_s-f/l).U.U^T + f/l.I).dX
auto& m = springForce->dForce_dX;
Real tgt = forceIntensity * inverseLength;
Real tol = 1e-8;
Copy link
Contributor

@hugtalbot hugtalbot Dec 18, 2025

Choose a reason for hiding this comment

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

should we not use std::limit ?

I agree that a user-defined data would not be appropriate, but I do not like hard-coded value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants