Skip to content

[FEM] Introduce higher accuracy quadrature rules - #6225

Merged
hugtalbot merged 19 commits into
sofa-framework:masterfrom
th-skam:quadrature-rules
Oct 8, 2026
Merged

hugtalbot merged 19 commits into
sofa-framework:masterfrom
th-skam:quadrature-rules

Conversation

@th-skam

@th-skam th-skam commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

For each Element, an option is added to use a higher-accuracy quadrature rule. The default behaviour of existing force fields is preserved. Lower-order rules are also included for completeness.

The purpose of this change is to enable more accurate error-norm computations in the V&V suite using the Method of Manufactured Solutions.

If the accuracy is insufficient, the integration introduces errors in the computed norms. This we observe either as the convergence rate approaching the expected one more slowly or as apparent superconvergence that counters the purpose of the test.

The degrees are:

Element Up to degree Default degree
Edge 3 1
Quad 3 2
Tri 2 1
Tetra 2 1
Hex 5 3

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

@th-skam th-skam added pr: status to review To notify reviewers to review this pull-request pr: new feature Implement a new feature labels Aug 10, 2026
@th-skam th-skam added the pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI label Aug 10, 2026

@alxbilger alxbilger 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.

I would be curious to know how you use quadratureRule

@th-skam

th-skam commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

@alxbilger
It was used like so in my cases: 97581c5

@sofabot

sofabot commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

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

To unlock the merge button, you must

@sofabot

sofabot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

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

To unlock the merge button, you must

@alxbilger alxbilger 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.

Could you just add the new quadrature points to the unit tests testSumWeights ? It's not enough, but there are not other tests for now...

@sofabot

sofabot commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

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

To unlock the merge button, you must

@alxbilger

Copy link
Copy Markdown
Contributor

I think you can remove the ci-depends-on. It's actually the other PR that needs this one.

@th-skam

th-skam commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Now that we added quadratic elements, I refactored the quadrature rules. Linear or quadratic, the integration is done over the same reference domain. The rules are now re-used, implemented in QuadratureRules.h. AI was used to help with std usage to have compile-time/runtime paths.

The literals were also substituted by std:: variants, wherever possible. This has triggered a unit test failure in ElementMass__test.

New rules can be added in the existing tables. There are two paths:

Each element has a default and minimum degree, so quadratic elements cannot use 1st order rules.
Will work on populating tests, either here or in subsequent PR.

@th-skam

th-skam commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

For the failing tests on ubuntu, we were failing by a small margin (2.27e-13 and 9.0949e-13 against 2.2204e-13 🥹 ).
I turned the comparison to normalize with the value it's compared against. Which should be more fair in general.

Comment on lines +238 to +248
// 4-point rule
constexpr Real sqrt5 = static_cast<Real>(2.23606797749978969640917366873); // sqrt(5)
constexpr Real a = (static_cast<Real>(5) - sqrt5) / static_cast<Real>(20);
constexpr Real b = (static_cast<Real>(5) + static_cast<Real>(3) * sqrt5) / static_cast<Real>(20);
constexpr Real w = static_cast<Real>(1) / static_cast<Real>(24); // 1/24

return std::array<PointAndWeight, 4>{
std::make_pair(Point(a, a, a), w),
std::make_pair(Point(b, a, a), w),
std::make_pair(Point(a, b, a), w),
std::make_pair(Point(a, a, b), w)

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.

This code appears to be a custom 4-point quadrature rule for a tetrahedron. Is this on purpose?
Yet still valid ✔️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not a custom one. It's the one from FiniteElement[QuadraticTetrahedron] and literals were replaced with a computation involving sqrt(5) etc.
Online I find it as the T3P2 Hammer-Stroud rule, degree 2, 4 points.
Quick example here: https://www.cfd-online.com/Wiki/Code:_Quadrature_on_Tetrahedra

I could catalogue the available rules at some point with references & doc but better not in this PR.

@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 Oct 8, 2026
@hugtalbot
hugtalbot merged commit 538e91d into sofa-framework:master Oct 8, 2026
13 of 14 checks passed
@th-skam
th-skam deleted the quadrature-rules branch October 9, 2026 08:57
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: new feature Implement a new feature pr: status ready Approved a pull-request, ready to be squashed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants