Skip to content

fix Nitsche symmetry term on cylindrical and spherical meshes - #1289

Open
hhy2022 wants to merge 2 commits into
festim-dev:mainfrom
hhy2022:fix-nitsche-non-cartesian
Open

hhy2022 wants to merge 2 commits into
festim-dev:mainfrom
hhy2022:fix-nitsche-non-cartesian

Conversation

@hhy2022

@hhy2022 hhy2022 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Description

Summary

The symmetry term of weakly enforced Dirichlet BCs (Nitsche) is now written like the bulk diffusion term in cylindrical and spherical coordinates:

Coordinate system Before After
cartesian n·grad(v) n·grad(v) (unchanged)
cylindrical n·grad(v) r n·grad(v / r)
spherical n·grad(v) r**2 n·grad(v / r**2)

This follows the diffusion term in HydrogenTransportProblem.create_formulation and festim.drift.drift_form. DirichletBCBase.weak_formulation takes a new coordinate_system argument (default cartesian), passed by both HydrogenTransportProblem and HydrogenTransportProblemDiscontinuous.

Related Issues

Fixes #1278

Motivation and Context

In cylindrical coordinates, conservation comes from the test function v = r, which is in the P1 space. The bulk term r grad(u)·grad(v/r) vanishes for it, but the symmetry term n·grad(v) does not (grad(r) = 1), so particles are not conserved when a weakly enforced HenrysBC / SievertsBC is coupled to an enclosure.

With the MWE posted in #1278 (largest relative change of the total number of H atoms):

Henry before Henry after Sieverts before Sieverts after
cartesian 2.6e-11 2.6e-11 1.4e-16 1.4e-16
cylindrical 3.7e-06 5.3e-11 4.4e-07 2.8e-16
spherical 1.7e-04 1.8e-04 2.4e-05 2.6e-05

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🔨 Code refactoring (no functional changes, no API changes)
  • 📝 Documentation update
  • ✅ Test update (adding missing tests or correcting existing tests)
  • 🔧 Build/CI configuration change

Testing

  • All existing tests pass locally (pytest)
  • I have added new tests that prove my fix is effective or that my feature works

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 (if applicable)
  • I have added docstrings to new functions/classes following the project conventions

Additional Notes

Spherical is not exact, and cannot be with P1 elements. Conservation would need v = r**2 in the test space. The remaining drift is the same as with SurfaceReactionBC (no Nitsche) and is O(h^2):

n cells Henry before Henry after SurfaceReactionBC
60 1.72e-04 1.83e-04 1.85e-04
120 4.29e-05 4.58e-05 4.63e-05
240 1.07e-05 1.14e-05 1.16e-05

The spherical symmetry term is changed for consistency with the bulk term.

With assistance from AI.

@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 (2e567ff).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1289   +/-   ##
=======================================
  Coverage   96.14%   96.15%           
=======================================
  Files          57       57           
  Lines        5165     5177   +12     
=======================================
+ Hits         4966     4978   +12     
  Misses        199      199           
Flag Coverage Δ
dolfinx-v0.10.0 93.27% <100.00%> (+0.01%) ⬆️
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.

@hhy2022
hhy2022 marked this pull request as ready for review November 5, 2026 16:38
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.

[BUG] Weakly enforced BCs not exact with non-cartesian meshes

1 participant