Skip to content

Fix BUG-004/005: mixed-materials load accumulation and plane-stress postprocessing - #94

Open
knutambot wants to merge 1 commit into
KnutAM:mainfrom
knutambot:cb/BUG004_BUG005
Open

knutambot wants to merge 1 commit into
KnutAM:mainfrom
knutambot:cb/BUG004_BUG005

Conversation

@knutambot

Copy link
Copy Markdown
Contributor

Summary

  • BUG-004: fext accumulated across time steps in the mixed-materials tutorial (never cleared before apply!(fext, lh, t)), so the solver applied the sum of all previous loads instead of the current one. Fixed with fill!(fext, 0) before each step's apply!.
  • BUG-005: the tutorial's calculate_stress postprocessing zero-padded the out-of-plane strain and applied the full 3d elastic stiffness directly, which is only valid for plane strain, not plane stress (whose eliminated out-of-plane strain must satisfy σ33 = 0). Fixed by delegating to MaterialModelsBase.material_response on the actual (stress_state, material) pair for the elastic response, and by using the already-converged 3d plastic strain (reduced to in-plane) to form the elastic strain for the plastic branch — without re-invoking Plastic's own material_response a second time, which would otherwise double-advance the already-converged state during postprocessing.
  • Added hidden (#src) regression checks: per-timestep fext reconstruction check, an elastic plane-stress analytical reference (E/(1-ν²) form) plus an out-of-plane-stress check, and a pinned end-to-end regression value for the full solve's postprocessed stresses.

Verified the corrected formula numerically against MaterialModelsBase.material_response directly: for E=210e3, ν=0.3, ϵ11=0.01, it gives (σ11, σ22) = (2307.69, 692.31), matching the documented correct reference (vs. the buggy (2826.92, 1211.54)).

Test plan

  • Pkg.test() — full suite passes (3236 assertions, no failures)
  • All tutorials (heat_equation, iga, incompressible_elasticity, mixed_materials, viscoelasticity) run successfully, each in an isolated module
  • All how-tos (automatic_differentiation, local_constraints, robin_bc, surface_integral, threaded_assembly, volume_integral) run successfully
  • Full docs/make.jl build succeeds (only the pre-existing benign viscoelasticity image-size-threshold warning)
  • Independent Codex review of the plan and of the final diff (same review thread)

Remaining risk

Codex's review flagged (medium, both passes) that docs/src/literate_tutorials/mixed_materials.png is a downloaded external asset (via FerriteAssembly.asset_url, not tracked in this repo / not regenerated by the docs build), so this PR does not update the published tutorial image — it will keep showing results from the old, incorrect loading/postprocessing until that asset is separately regenerated and republished upstream.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KySgpVgJ5fWR9AvPK1JQoU

…-stress postprocessing

BUG-004: `fext` was allocated once outside the time loop and never cleared,
so `apply!(fext, lh, t)` added each step's load onto the running total
instead of replacing it, ending with 10x the intended final load after the
20-step history. Fixed by `fill!(fext, 0)` before each `apply!` call.

BUG-005: `calculate_stress` computed plane-stress output by zero-padding the
in-plane strain's out-of-plane components and applying the full 3d elastic
stiffness tensor directly, which is only correct for plane strain, not plane
stress (whose eliminated out-of-plane strain must satisfy sigma_33 = 0).
Fixed by delegating to `MaterialModelsBase.material_response` on the actual
stress state + material pair for the elastic case (which performs the same
plane-stress-consistent solve used during assembly), and, for the plastic
case, using the already-converged 3d plastic strain (reduced to in-plane
components) to form the elastic strain directly rather than re-invoking
`Plastic`'s own `material_response` a second time (which would otherwise
double-advance the already-converged state during postprocessing).

Added hidden (`#src`) regression checks: per-timestep verification that
`fext` matches a freshly evaluated load vector, an elastic plane-stress
analytical reference check (matches E/(1-nu^2) form) including an
out-of-plane stress check, and a pinned end-to-end regression value for the
full solve's postprocessed stresses.

Verified numerically against MaterialModelsBase.material_response directly:
for E=210e3, nu=0.3, eps11=0.01, the corrected formula gives
(sigma11, sigma22) = (2307.69, 692.31), matching the documented correct
reference (vs. the buggy (2826.92, 1211.54)).

Test results: full Pkg.test() suite passes (3236 assertions across all
testsets). All 5 unaffected tutorials, all 6 how-tos, and the fixed
mixed_materials tutorial (with its new #src regression tests) run
successfully. Full docs build succeeds with only the pre-existing benign
viscoelasticity image-size-threshold warning.

Independent Codex review (plan + final diff, same thread) raised one
remaining medium finding both times: mixed_materials.png is a downloaded
external asset (via FerriteAssembly.asset_url) rather than a file generated
by the docs build, so this PR's fix does not regenerate the published
tutorial image, which will keep showing results from the old, incorrect
loading/postprocessing until that asset is separately replaced upstream.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KySgpVgJ5fWR9AvPK1JQoU
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.17%. Comparing base (d30c676) to head (0111539).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #94   +/-   ##
=======================================
  Coverage   97.17%   97.17%           
=======================================
  Files          32       32           
  Lines        1347     1347           
=======================================
  Hits         1309     1309           
  Misses         38       38           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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