Skip to content

[FEM.HyperElastic] Integration of hyperelasticity from Elasticity plugin to SOFA - #6206

Open
alxbilger wants to merge 8 commits into
sofa-framework:masterfrom
alxbilger:hyperelasticity
Open

[FEM.HyperElastic] Integration of hyperelasticity from Elasticity plugin to SOFA#6206
alxbilger wants to merge 8 commits into
sofa-framework:masterfrom
alxbilger:hyperelasticity

Conversation

@alxbilger

@alxbilger alxbilger commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Introduction of hyperelasticity with a few materials, and validation scenes

[with-all-tests]

Note that Ogen was added in alxbilger/Elasticity#6 by @th-skam


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: new feature Implement a new feature pr: highlighted in next release Highlight this contribution in the notes of the upcoming release labels Jul 25, 2026

@th-skam th-skam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Few comments and porting corrections from SOFA's Ogden.h here.


find_package(Sofa.Config QUIET REQUIRED)
sofa_find_package(Sofa.Simulation.Core QUIET REQUIRED)
sofa_find_package(Sofa.Component.SolidMechanics.FEM.Elastic QUITE REQUIRED)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
sofa_find_package(Sofa.Component.SolidMechanics.FEM.Elastic QUITE REQUIRED)
sofa_find_package(Sofa.Component.SolidMechanics.FEM.Elastic QUIET REQUIRED)

* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#define ELASTICITY_COMPONENT_PK2HYPERELASTIC_MATERIAL_CPP

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A last pass on the guards with ELASTICITY prefix.

Comment on lines +135 to +140
if (l_material.empty())
{
msg_info() << "Link to a valid material should be set to ensure right behavior. First "
"material found in current context will be used.";
l_material.set(this->getContext()->template get<HyperelasticMaterial<DataTypes>>());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not initialized somewhere so user cannot set it.

Comment on lines +65 to +68
// The SelfAdjointEigenSolver is normally the suitable choice for symmetric matrices
// However, it has produced wrong results in some previous tests
// Disable temporarilly until fixed /*Eigen::SelfAdjointEigenSolver<EigenMatrix>*/
Eigen::EigenSolver<EigenMatrix> EigenProblemSolver(CEigen, true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The SelfAdjointEigenSolver is normally the suitable choice for symmetric matrices
// However, it has produced wrong results in some previous tests
// Disable temporarilly until fixed /*Eigen::SelfAdjointEigenSolver<EigenMatrix>*/
Eigen::EigenSolver<EigenMatrix> EigenProblemSolver(CEigen, true);
Eigen::SelfAdjointEigenSolver<EigenMatrix> EigenProblemSolver(CEigen, Eigen::ComputeEigenvectors);

Have changed this in old Ogden.

Comment on lines +134 to +135
// Disable temporarilly until fixed /*Eigen::SelfAdjointEigenSolver<EigenMatrix>*/
Eigen::EigenSolver<EigenMatrix> EigenProblemSolver(CEigen, true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Disable temporarilly until fixed /*Eigen::SelfAdjointEigenSolver<EigenMatrix>*/
Eigen::EigenSolver<EigenMatrix> EigenProblemSolver(CEigen, true);
Eigen::SelfAdjointEigenSolver<EigenMatrix> EigenProblemSolver(CEigen, Eigen::ComputeEigenvectors);

Comment on lines +138 to +139
const auto eigenvectors = EigenProblemSolver.eigenvectors().real().eval();
const auto eigenvalues = EigenProblemSolver.eigenvalues().real().eval();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const auto eigenvectors = EigenProblemSolver.eigenvectors().real().eval();
const auto eigenvalues = EigenProblemSolver.eigenvalues().real().eval();
const auto eigenvectors = EigenProblemSolver.eigenvectors();
const auto eigenvalues = EigenProblemSolver.eigenvalues();

These are not needed after the SelfAdjoint change.

Comment on lines +72 to +73
const auto eigenvectors = EigenProblemSolver.eigenvectors().real().eval();
const auto eigenvalues = EigenProblemSolver.eigenvalues().real().eval();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const auto eigenvectors = EigenProblemSolver.eigenvectors().real().eval();
const auto eigenvalues = EigenProblemSolver.eigenvalues().real().eval();
const auto eigenvectors = EigenProblemSolver.eigenvectors();
const auto eigenvalues = EigenProblemSolver.eigenvalues();

Comment on lines +187 to +190
const Real eigenvalueMultiplier =
std::fabs(eigenvalues[n] - eigenvalues[m]) < std::numeric_limits<Real>::epsilon()
? aBy2Minus1 * eigenvaluePowers2(n)
: (eigenvaluePowers1(n) - eigenvaluePowers1(m)) / (eigenvalues(n) - eigenvalues(m));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const Real eigenvalueMultiplier =
std::fabs(eigenvalues[n] - eigenvalues[m]) < std::numeric_limits<Real>::epsilon()
? aBy2Minus1 * eigenvaluePowers2(n)
: (eigenvaluePowers1(n) - eigenvaluePowers1(m)) / (eigenvalues(n) - eigenvalues(m));
constexpr Real tol = static_cast<Real>(1e-8);
const Real maxEval = std::max(std::fabs(eigenvalues(n)), std::fabs(eigenvalues(m)));
const bool isDegenerate = std::fabs(eigenvalues(n) - eigenvalues(m)) < maxEval * tol;
const Real eigenvalueMultiplier = isDegenerate
? aBy2Minus1 * eigenvaluePowers2(n)
: (eigenvaluePowers1(n) - eigenvaluePowers1(m)) / (eigenvalues(n) - eigenvalues(m));

This is ported from Ogden.h already in SOFA. The eigenvalue difference should be scaled by their magnitudes.

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

Labels

pr: highlighted in next release Highlight this contribution in the notes of the upcoming release pr: new feature Implement a new feature 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.

2 participants