Skip to content

Weakly enforced Dirichlet BCs#1158

Open
RemDelaporteMathurin wants to merge 21 commits into
mainfrom
weak_dirichlet
Open

Weakly enforced Dirichlet BCs#1158
RemDelaporteMathurin wants to merge 21 commits into
mainfrom
weak_dirichlet

Conversation

@RemDelaporteMathurin
Copy link
Copy Markdown
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin commented May 18, 2026

Description

Summary

This PR adds the possibility to weakly enforce dirichlet BCs.

Related Issues

Fixes #1153

Motivation and Context

Sometimes, it is necessary to weakly impose a Dirichlet BC (eg. flux conservation). So far FESTIM only allowed strongly enforced BCs but it wasn't too complicated to weakly enforce it in the variational formulation thanks to @jorgensd tutorials.

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

Breaking Changes

Screenshots/Examples

Additional Notes

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.76%. Comparing base (0605dd2) to head (ad8d19e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1158      +/-   ##
==========================================
+ Coverage   94.72%   94.76%   +0.03%     
==========================================
  Files          46       46              
  Lines        3508     3534      +26     
==========================================
+ Hits         3323     3349      +26     
  Misses        185      185              

☔ View full report in Codecov by Sentry.
📢 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 RemDelaporteMathurin marked this pull request as ready for review May 18, 2026 14:22
@RemDelaporteMathurin
Copy link
Copy Markdown
Collaborator Author

@jorgensd @jhdark The Docker CI for dolfinx 0.9 doesn't go pas the install and I'm confused as to why. It seems related to some pip PEP8 rules about the license in scifem being "MIT" instead of { text = "MIT" } ???? but for some reason that's not required in the 0.10.... I'm keen on ignoring this for now but I thought I'd bring it up with you

Copy link
Copy Markdown
Collaborator

@jhdark jhdark left a comment

Choose a reason for hiding this comment

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

Looks great, that was a quick turn around, are we going to add this to the discontinuous class too?

Comment thread .github/workflows/ci_docker.yml Outdated
- name: Install local package and dependencies
run: |
pip install .[test]
python -m pip install --upgrade pip
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.

Whats this for?

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.

Oh never mind, saw the final comment on the PR

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll revert this cause i don't think it's related to this. See this PR scientificcomputing/scifem#213

Comment on lines +171 to +176
assert alpha is not None, (
"Penalty parameter must be given for weakly enforced Dirichlet BCs"
)
assert self.value_fenics is not None, (
"value_fenics must be defined for weakly enforced Dirichlet BCs"
)
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.

Should this not be done in a setter instead? Only if the enforce_weakly is True?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No not in a setter because then you always have to set say enforce_weakly before alpha or the opposite because there is no way to set them both at the same time.

This method is only called if enforce_weakly is True anyway.

"""
mesh = ds.ufl_domain()
n = ufl.FacetNormal(mesh)
h = ufl.Circumradius(mesh) # FIXME this doesn't work for rectangles
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.

Will this break for hex meshes or only give the wrong value? Because if it breaks, maybe we could have a mini test in here and give a more descriptive error?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It will break. But because there is an open issue for this elswhere I'm hoping we can fix this pretty soon anyway

Comment thread src/festim/boundary_conditions/dirichlet_bc.py
Copy link
Copy Markdown
Collaborator Author

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

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

are we going to add this to the discontinuous class too?

It has already been added to the discontinuous case.

"""
mesh = ds.ufl_domain()
n = ufl.FacetNormal(mesh)
h = ufl.Circumradius(mesh) # FIXME this doesn't work for rectangles
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It will break. But because there is an open issue for this elswhere I'm hoping we can fix this pretty soon anyway

Comment on lines +171 to +176
assert alpha is not None, (
"Penalty parameter must be given for weakly enforced Dirichlet BCs"
)
assert self.value_fenics is not None, (
"value_fenics must be defined for weakly enforced Dirichlet BCs"
)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No not in a setter because then you always have to set say enforce_weakly before alpha or the opposite because there is no way to set them both at the same time.

This method is only called if enforce_weakly is True anyway.

@jorgensd
Copy link
Copy Markdown
Collaborator

@jorgensd @jhdark The Docker CI for dolfinx 0.9 doesn't go pas the install and I'm confused as to why. It seems related to some pip PEP8 rules about the license in scifem being "MIT" instead of { text = "MIT" } ???? but for some reason that's not required in the 0.10.... I'm keen on ignoring this for now but I thought I'd bring it up with you

Try setting a bound on setuptools, like: https://github.com/FEniCS/ufl/blob/main/pyproject.toml#L3

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.

Option to impose Dirichlet BC's weakly

3 participants