Skip to content

Add StressDriftTerm: stress-assisted diffusion (closes #1261) - #1288

Merged
RemDelaporteMathurin merged 2 commits into
festim-dev:mainfrom
zer00318:stress-drift-term
Nov 6, 2026
Merged

RemDelaporteMathurin merged 2 commits into
festim-dev:mainfrom
zer00318:stress-drift-term

Conversation

@zer00318

@zer00318 zer00318 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Description

Summary

Adds festim.StressDriftTerm, stress-assisted diffusion of an interstitial species along a hydrostatic stress gradient (Sofronis & McMeeking, 1989):

$$J = -D \nabla c + \frac{D c V_H}{R T} \nabla \sigma_h$$

with partial_molar_volume $V_H$ in m³/mol and hydrostatic_stress $\sigma_h$ in Pa (positive in tension). It is a DriftTermBase subclass built exactly like SoretTerm and ElectromigrationTerm, so it reuses the conservative drift_form, the 0D handling and the structural-zero warning. FESTIM does not solve for the stress: like the potential of ElectromigrationTerm, it is an input (float, callable of x/t/T, or a fenics object), typically the hydrostatic part of a separate dolfinx mechanics solve on the same mesh.

Related Issues

Closes #1261

Motivation and Context

Hydrogen accumulation in tensile regions matters for crack tips and for thermally mismatched joints such as W/CuCrZr plasma-facing components, where the cool-down after joining leaves large residual stresses at the interface.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 📝 Documentation update
  • ✅ Test update (adding missing tests or correcting existing tests)

Testing

  • All existing tests pass locally (pytest) — dolfinx 0.10.0, macOS arm64, conda-forge env: 1206 passed, 66 skipped; the one failure, test_heat_transfer_problem.py::test_sympify, is ModuleNotFoundError because sympy is not installed in my env
  • I have added new tests that prove my fix is effective or that my feature works

New tests in test/test_drift.py: the term joins the existing parametrisations (0D warning, subdomain/species validation, shared base class); a uniform stress gives a structural-zero velocity and the "no effect" warning; the velocity equals D V_H / (R T) grad(sigma_h); the drift points towards tension for V_H > 0 and reverses with the sign of V_H.

New system test in test/system_tests/test_drift.py: a closed slab under a linear stress gradient relaxes to the closed form c ∝ exp(V_H σ_h / RT) (max relative error < 1e-5), with the stress span chosen so that the tensile end holds e times the unstressed end.

I also checked the fenics-object path end to end (not added to the suite, script below): plane-strain elasticity of a bent beam in dolfinx, σ_h = tr(σ)/3 interpolated into P1 and passed to StressDriftTerm on the same mesh. The closed transient run gives c_top / c_bottom = 1.0030 against the Boltzmann value 1.0030.

bent-beam check
# plane-strain elasticity on a 10 x 2 mm beam, end moments imposed as a linear axial displacement
uh = LinearProblem(a, L, bcs=bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu"},
                   petsc_options_prefix="elastic").solve()
s = sig(uh)
sigma_h = fem.Function(fem.functionspace(msh, ("Lagrange", 1)))
sigma_h.interpolate(fem.Expression((1 + nu) * (s[0, 0] + s[1, 1]) / 3,
                                   sigma_h.function_space.element.interpolation_points))
model = F.HydrogenTransportProblem(
    mesh=F.Mesh(msh), subdomains=[vol], species=[H], temperature=600.0,
    initial_conditions=[F.InitialConcentration(value=1.0, volume=vol, species=H)],
    drift_terms=[F.StressDriftTerm(species=H, partial_molar_volume=2e-6,
                                   hydrostatic_stress=sigma_h, subdomain=vol)],
    settings=F.Settings(atol=1e-12, rtol=1e-10, transient=True, final_time=200.0),
)

Code Quality Checklist

  • My code follows the code style of this project (Ruff formatted: ruff format .)
  • My code passes linting checks (ruff check .)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

Documentation

  • I have updated the documentation accordingly (user guide section, theory equation eq_stress_drift, Sofronis1989 reference)
  • I have added docstrings to new functions/classes following the project conventions

Additional Notes

  • V_H = 2e-6 m³/mol in the examples is the classic value for H in iron used by Sofronis & McMeeking; the docstring says so rather than suggesting a tungsten value.
  • Only the hydrostatic part of the stress enters, as in the standard model; trap-binding changes with plastic strain are out of scope.
  • Written with AI assistance (Claude); I reviewed and ran everything above.

Drift of an interstitial species along a hydrostatic stress gradient,
J = -D grad(c) + D c V_H / (R T) grad(sigma_h) (Sofronis & McMeeking 1989),
built on DriftTermBase like SoretTerm and ElectromigrationTerm. The stress is
an input field (float, callable or fenics object), e.g. the hydrostatic part of
a separate dolfinx mechanics solve on the same mesh.

Tests: constructor/validation parametrisations, structural-zero warning for a
uniform stress, velocity expression, sign (drift towards tension for V_H > 0),
and a system test that a closed slab relaxes to c ~ exp(V_H sigma_h / RT).
Docs: user guide section, theory equation, Sofronis1989 reference.

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

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.15%. Comparing base (1bd7a80) to head (57a9d95).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1288      +/-   ##
==========================================
+ Coverage   96.14%   96.15%   +0.01%     
==========================================
  Files          57       57              
  Lines        5165     5181      +16     
==========================================
+ Hits         4966     4982      +16     
  Misses        199      199              
Flag Coverage Δ
dolfinx-v0.10.0 93.28% <100.00%> (+0.02%) ⬆️
dolfinx-v0.11.0 96.02% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@RemDelaporteMathurin

Copy link
Copy Markdown
Collaborator

Thanks for this @zer00318 i’ll try to give it a look later today

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @zer00318 for this contribution and congrats on your first PR! 🎉

@jhdark do you want to have a look at this or shall I merge?

@RemDelaporteMathurin
RemDelaporteMathurin merged commit 3ec62f2 into festim-dev:main Nov 6, 2026
11 of 13 checks passed
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.

Could add stress-assisted diffusion drift term

2 participants