Skip to content

Fix gsMaterialMatrixComposite basis change, B coupling and ply order - #37

Draft
hverhelst wants to merge 9 commits into
mainfrom
composite-fixes
Draft

hverhelst wants to merge 9 commits into
mainfrom
composite-fixes

Conversation

@hverhelst

@hverhelst hverhelst commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

FIXED: gsMaterialMatrixComposite basis change from the ply frame to the contravariant basis. A, B and D were up to ~35 % non-symmetric, and wrong on any non-orthogonal parametrisation
FIXED: VectorN/VectorM of gsMaterialMatrixComposite omitted the coupling B; now N = A eps + B kappa and M = B^T eps + D kappa, consistent with the tangent
FIXED: gsMaterialMatrixComposite::thickness_into returned an unsized, per-ply result that ignored the patch index; it now returns the total laminate thickness of the requested patch (1 x npts)
FIXED: example_shell2D --composite aborted at start-up (TensionField option set on a material that does not have it)
FIXED: Modal_composite test ply angles were integer division (all 0)
FIXED: gsCompositeMatrix checked the ply reciprocity nu21E1 == nu12E2 with an exact == in a debug-only assert; it now throws std::runtime_error in every build type above a 1 % relative mismatch and symmetrises the off-diagonals below it (new unit test suite gsCompositeMatrix_test)
IMPROVED: gsMaterialMatrixComposite::eval3D_vector evaluates A (or D) and B in one pass over points and plies instead of two full evaluations
IMPROVED: gsMaterialMatrixComposite rejects zero plies, an unsupported eval3D_matrix output and density_into without densities with an exception, instead of 0/0, a late error or a null dereference
API: ply stacking order: ply 0 is now the ply at the most negative z along the normal; unsymmetric layups given in the old order give the mirrored laminate
API: protected helpers gsMaterialMatrixComposite::_cart2cov and _con2cart removed
NEW: unit test suite gsMaterialMatrixComposite_test (14 tests: independent tensor oracles for A/B/D on orthogonal and skewed patches, symmetry, N/M consistency, stacking direction, thickness, density, input validation)

What and why

The basis change in gsMaterialMatrixComposite had three defects: a typo in one entry, the factor 2 of the
engineering shear on the wrong side, and no congruence. The result was laminate matrices that were not
symmetric and not correct on non-orthogonal parametrisations. It is now the congruence C^con = Qᵀ C_cart Q,
built with gsMaterialMatrixBaseDim::_transformation. That form is symmetric by construction and needs no
inverse.

The membrane and bending resultants now include the coupling matrix B, so the residual matches the tangent
the assembler already used. Several smaller defects found along the way are fixed as well:

  • thickness_into now follows the base-class contract.
  • Inputs are validated up front.
  • eval3D_vector no longer evaluates the laminate twice.
  • example_shell2D --composite runs.

All changes are in src/gsMaterialMatrixComposite.{h,hpp}, examples/example_shell2D.cpp and the unit tests.

Interplay with the open tft-membranes PR (#36). Both branches add unittests/gsMaterialMatrixComposite_test.cpp, so a
merge gives one add/add conflict. Resolve it by keeping both halves in one suite. The helper functions are identical
on both sides.

  • The source files merge cleanly. With both branches merged the full suite passes: 585 tests.
  • TFT's eval3D_energy builds on the same A, B and D, so it follows the new ply order and B sign.
  • Once both are in, one doxygen remark on eval3D_energy needs rewording. It says "dW/dε equals VectorN only for
    B = 0", but with this PR VectorN includes B, so the equality holds for any B.

API and semantic changes

  • Stacking order (behaviour change). Ply 0 is the ply at the most negative z along n = a1×a2/|a1×a2|, and
    B = Σ tᵢ zᵢ Cᵢ with zᵢ the signed height of ply i. The previous code was consistent with the opposite order
    (ply 0 on top). This is a change of convention, not a sign fix. An unsymmetric layup that was given in the old
    order now describes the mirrored laminate, and its B changes sign. Symmetric layups are unaffected.
  • A, B, D on non-orthogonal patches (behaviour change). Results change wherever the parametrisation is not
    orthogonal. On orthogonal patches A and D are unchanged.
  • VectorN / VectorM (behaviour change). They now include B κ and Bᵀ ε, so nonlinear runs of unsymmetric
    laminates converge to a different, now consistent, solution.
  • thickness_into. It now returns 1 × u.cols(), the sum of the ply thicknesses on the requested patch.
    Before, it returned one row per ply, evaluated on patch 0, and did not resize result. Callers in
    gsMaterialMatrixIntegrate already read row 0 as the total thickness, but Composite is Integrated and does
    not reach them.
  • New exceptions (std::runtime_error, in every build type):
    • a Composite constructed with zero plies;
    • eval3D_matrix called with an output other than MatrixA/B/C/D, the default Generic included. This
      was already an error, but it was raised later, inside the loops;
    • density_into on a laminate constructed without densities. This was a null dereference.
  • Removed the protected gsMaterialMatrixComposite::_cart2cov and _con2cart. No class in gsKLShell derives
    from gsMaterialMatrixComposite.
  • Added a private helper _eval3D_laminate, which is not part of the API.
  • For dim == 2 the doxygen now states that n = e3 and κ = 0, so B does not enter N.

Callers in this repository that see changed values are example_shell3D, example_parametric_panel and
gsThinShellAssembler_test (Modal_composite). The two examples use isotropic plies, so B = 0 there.
Modal_composite now uses orthotropic plies, with a new reference (see Verification).

Verification

  • Full unit-test suite: Success: 406 tests passed. (Release, gsKLShell enabled).

  • gsMaterialMatrixComposite_test, 14 tests: the A/B/D tests compare with references that do not use the class
    under test:

    • gsMaterialMatrixLinear for a single isotropic ply;
    • a per-component tensor oracle for orthotropic laminates.

    Before the fix, the value tests failed on the original code with relative errors of 0.13–0.35.

  • Modal_composite:

    • The test now uses orthotropic plies at distinct angles. Its 10 eigenvalues are a regression reference from
      this version, stored at 17 digits with a 1e-8 relative tolerance.
    • It fails for swapped plies (3e-3 to 1.3e-2) and for all-zero angles (up to 0.15).
    • Reversing the whole stack is a symmetry of the pinned flat plate, so this test does not detect it. Stacking
      direction is covered by Skewed_StackingDirection_MatchesKinematics.
    • It passes with 1, 3 and 8 OpenMP threads.
  • example_shell3D --composite --nl: Newton update norms 4.1e-2, 5.3e-2, 5.3e-4, 6.0e-6, 1.0e-11, and
    displacement 0.00826805 at the reference point. These are unchanged by the follow-up commits, including the
    one-pass eval3D_vector. A serial -r 3 Newton trace is identical to all printed digits before and after it.

  • example_shell2D: --composite (nonlinear and -t 2), the default, and --composite -m 1 all exit 0.

  • Cost of eval3D_vector: measured before fusing. The removed second matrix evaluation was about 43 % of
    eval3D_vector at 1, 4 and 8 plies. No same-load before/after timing of the assembly was made.

Review

Automated reviews, all by AI agents:

  • 2026-11-13, medium level: 0 blockers, 10 majors, 3 minors, 3 notes. Each was fixed or decided before the
    first two commits. One of those decisions is to describe the ply-order change as a convention change.

  • 2026-11-16, light level: 2 findings, fixed (naming and layout in the test file).

  • 2026-11-18, medium level, on the branch up to the one-pass eval3D_vector commit: 0 blockers, 3 majors,
    2 minors, 3 notes. All 8 are fixed in the last two commits:

    • a test for density_into;
    • comments in two tests;
    • the example guard;
    • the formulas stated in one place;
    • an assert in the private helper;
    • the 2D normal documented;
    • the modal test made anisotropic.

    These two commits came after that review. Each was reviewed separately, per change, by an adversarial agent.

  • Not checked by the reviews: no mutation proof was run; no dedicated numerics or test-quality reviewer
    (medium level); the examples were run by the implementation runs, not by the reviews.

  • Known, not fixed here (pre-existing):

    • example_shell2D --TFT crashes: a null materialMatrixTFT is passed to the assembler.
    • The Composite default constructor leaves the ply count uninitialised.
    • The constructors check the sizes of the ply vectors only with GISMO_ASSERT, so they are not checked in
      Release.

Checklist

  • Explanation of what the changes do and why
  • New code documented with Doxygen comments
  • New tests or examples for the changes

AI assistance

The implementation, the tests, the example change and this description were generated with an AI coding
assistant (Claude Code with the gismo plugin). I have not yet reviewed the code myself. The checks so far
are the automated reviews and the tests listed above. Please review accordingly.

hverhelst and others added 7 commits November 16, 2026 19:30
…ange ply stacking order

The laminate matrices A, B, D were wrong on any non-orthogonal parametrisation:
on a skewed patch they were up to ~35% unsymmetric, and a single isotropic ply
deviated from gsMaterialMatrixLinear by ~25%. The removed _cart2cov/_con2cart
maps had a typo in entry (0,1), put the engineering-shear factor 2 on the wrong
side of the strain map, and were not applied as a congruence.

  * Basis change: C^con = Tc C_cart Tc^T with Tc = _transformation([e1 e2], gcon)
    from gsMaterialMatrixBaseDim, e1 = a1/|a1|, e2 = a^2/|a^2|. Symmetric by
    construction and free of matrix inversion. _cart2cov and _con2cart are deleted.
  * eval3D_vector: N = A eps + B kappa and M = B^T eps + D kappa. The B coupling
    was missing. Only the two matrices each output needs are evaluated, with no
    per-point allocation. The unreachable Generic branch is removed.
  * Stacking-order change: ply 0 is now the ply at the most negative z along the
    normal n = a1 x a2 / |a1 x a2|, so B = +sum_i t_i z_i C_i. The old formula
    corresponded to ply 0 at the top. This is a change of convention, not a sign
    fix: unsymmetric layups given in the old order now give the mirrored laminate
    and must be reversed to reproduce previous results.
  * Doxygen for the class and constructors: ply order, angle unit and reference
    direction, layout of G, and the A/B/D/N/M definitions.

Tests:
  * New suite gsMaterialMatrixComposite_test (9 tests): isotropic ply against
    gsMaterialMatrixLinear on orthogonal and skewed patches; orthotropic
    laminates against an independent tensor-contraction oracle (A, B, D; 3D
    and planar 2D); symmetry of A, B, D; N/M against fundamental-form strains;
    and the stacking direction against a through-thickness integral of
    gsMaterialMatrixLinear stresses at physical heights, which the reversed
    ply order misses. Skewed tests assert that their patch is really skewed,
    non-unit and curved.
  * gsThinShellAssembler_test Modal_composite: ply angles used integer division
    (all 0); now floating point. Result unchanged (isotropic plies).

Results change for every skewed parametrisation and for every unsymmetric
laminate. No existing example or test covers either case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Prefix the data members of the test helpers Laminate and GeometryGuards
with m_ (G+Smo member naming convention), and put the opening brace of the
anonymous namespace on its own line. No change in behaviour; the 9 tests
are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gsMaterialMatrixComposite has no TensionField option, so --composite
aborted at start-up in gsOptionList::setInt. Skip the option and the
per-iteration tension-field plot when --composite is given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- thickness_into returns the total laminate thickness (1 x u.cols(),
  sum over plies), the gsMaterialMatrixBaseDim contract. It used to leave
  result unsized, ignore the patch index, loop over the density vector and
  write one row per ply.
- eval3D_matrix checks the requested output once, before the point and ply
  loops, and documents its real contract (z ignored, 9 x u.cols(), A/B/D).
- Construction with zero plies is rejected.
- density_into reports a missing density instead of dereferencing null.
- Tests: per-patch thickness_into on a two-patch laminate, Generic output
  throws, zero plies throws. Laminate test helper checks its input sizes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ector

eval3D_vector needs A (for N) or D (for M) plus B. It used to call
eval3D_matrix twice, repeating the point computation, the evaluation of
the ply data, the per-point metric and the ply loop. A private helper
_eval3D_laminate now accumulates both matrices in the same loops and
applies the basis change to each; eval3D_matrix calls it for a single
matrix. Arithmetic and accumulation order per ply are unchanged.

In isolation the removed evaluation was about 43 % of eval3D_vector at
1, 4 and 8 plies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- gsMaterialMatrixComposite_test: density_into throws without rho and
  returns sum_i t_i rho_i with rho; block comments in the two throw tests.
- gsThinShellAssembler_test, Modal_composite: orthotropic plies at
  distinct angles instead of identical isotropic ones, so the eigenvalues
  depend on the ply rotation and the layup. The reference is a regression
  value from this code version (17 digits, 1e-8 relative). It fails for
  swapped plies or all-zero angles; reversing the whole stack is a symmetry
  of the pinned flat plate and is not detected (stacking direction is
  covered by Skewed_StackingDirection_MatchesKinematics).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ate helper

- Class doxygen: for dim == 2 the normal is e3 and kappa = 0, so B and
  the ply order do not enter N. The A/B/D formulas are stated there once.
- _eval3D_laminate asserts that the requested output is a laminate matrix.
- example_shell2D: the TensionField guards test whether a composite was
  actually built, not only the --composite switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hverhelst and others added 2 commits November 20, 2026 09:19
The exact == check on nu21*E1 = nu12*E2 was a debug-only assert, so
inconsistent ply input gave a non-symmetric stiffness in Release, while
rounded or computed ratios could fail it in Debug. It is now a
GISMO_ENSURE with a 1% relative tolerance; within it, the off-diagonals
are set to their mean so G is exactly symmetric. Adds doxygen and the
gsCompositeMatrix_test suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015qurMPkppMMnMXasAHCVaE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant