Skip to content

[SolidMechanics.Testing] ADD generic derivative checks for force fields - #6474

Open
alxbilger wants to merge 2 commits into
sofa-framework:masterfrom
alxbilger:genericderivativechecks
Open

alxbilger wants to merge 2 commits into
sofa-framework:masterfrom
alxbilger:genericderivativechecks

Conversation

@alxbilger

Copy link
Copy Markdown
Contributor

ForceField_test required hand-written positions and expected forces, so few force fields used it. This PR makes it usable on any force field with just a scene.

Changes

  • New one-call entry point checkForceFieldDerivatives(sceneXML, options). No fixture or expected forces are needed. The options use named fields (ForceFieldDerivativesTestOptions).
  • Consistency checks, always run:
    • addDForce, addKToMatrix and buildStiffnessMatrix must represent the same matrix;
    • addKToMatrix must give the same result with a non-zero offset in the global matrix, and must not write outside its own block.
    • These hold even when the tangent is approximate (corotational models).
  • Finite-difference checks are now optional (TEST_FINITE_DIFFERENCES, on by default), for models whose tangent is exact.
  • Random geometry: random rest shape (restShapePerturbation), random deformation (initialPerturbation), and random rotation and translation (randomRigidMotion, in 1D/2D/3D), so tests don't pass just because of a special geometry.
  • Clearer interface: the internals of ForceField_test are now protected. The public interface is the scene setup, the options and run_test / run_stiffness_test. Existing tests are unaffected.
  • New test ElasticForceFieldsStiffness_test: all instantiated (DataTypes, element) combinations of LinearSmallStrainFEMForceField and CorotationalFEMForceField, from 1D to 3D, including prisms, pyramids and quadratic elements, plus the other elastic force fields. Each test uses a single random element built from the reference element.

Findings

  • HexahedralFEMForceField: addKToMatrix and buildStiffnessMatrix assemble Rᵀ·K·R instead of R·K·Rᵀ, which is inconsistent with addDForce. The test is commented out until a separate fix.
  • CorotationalFEMForceField with consistentTangent: the tangent is not exact for embedded elements (edges in 2D/3D, and quads, quadratic quads and quadratic triangles in 3D). Only the consistency checks run for those.

Note: existing run_test users now also get the consistency checks, including the offset check.

[with-all-tests]


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 pr: status to review To notify reviewers to review this pull-request pr: test PR adding test(s) in SOFA pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels Nov 30, 2026
@alxbilger

Copy link
Copy Markdown
Contributor Author

Notes:

  • The diff is large in ForceFieldTestCreation: because of additions, but also code moves
  • 69 new unit tests. They run in ~200 ms.

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

Labels

pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: status to review To notify reviewers to review this pull-request pr: test PR adding test(s) in SOFA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant