Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dirichlet BC attempt 3 #609

Merged
merged 41 commits into from
Oct 18, 2023
Merged

Dirichlet BC attempt 3 #609

merged 41 commits into from
Oct 18, 2023

Conversation

RemDelaporteMathurin
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin commented Oct 17, 2023

Proposed changes

Attempt 3 at #602

Based on @jorgensd 's response on the fenics Discourse, I tried reimplementing the DirichletBC with time as a constant.

Users can give values as functions of x, t, and T.

Example:

F.DirichletBC(..., value=lambda x, t: 2*x[0] + t, ...)
F.DirichletBC(..., value=2.0, ...)
F.DirichletBC(..., value=lambda t, T: T + t, ...)

Building from this fairly generic DirichletBC class, we can implement subclasses like SievertsBC:

F.SievertsBC(
        subdomain=..., S_0=1.0, E_S=1.0, pressure=lambda x, t: 2*x[0] + t, species=...
    )

Which is equivalent to:

def value(x, t, T):
    pressure = 2*x[0] + t
    S = S_0 * ufl.exp(-E_S / F.k_B / T)
    return S * pressure**0.5

F.DirichletBC(..., value=value, ...)

TODO:

  • Find a way to not have the DirichletBC objects updated when they don't need to to avoid performance losses

Types of changes

What types of changes does your code introduce to FESTIM?

  • Bugfix (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
  • Documentation Update (if none of the other choices apply)
  • New tests

Checklist

  • Black formatted
  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (45c988f) 95.89% compared to head (33decd8) 96.65%.

Additional details and impacted files
@@             Coverage Diff             @@
##           fenicsx     #609      +/-   ##
===========================================
+ Coverage    95.89%   96.65%   +0.76%     
===========================================
  Files           10       12       +2     
  Lines          268      359      +91     
===========================================
+ Hits           257      347      +90     
- Misses          11       12       +1     
Files Coverage Δ
festim/__init__.py 70.83% <100.00%> (+2.65%) ⬆️
festim/boundary_conditions/dirichlet_bc.py 100.00% <100.00%> (ø)
festim/hydrogen_transport_problem.py 97.74% <100.00%> (+0.22%) ⬆️
festim/boundary_conditions/sieverts_bc.py 95.45% <95.45%> (ø)

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

@RemDelaporteMathurin RemDelaporteMathurin changed the title Time as constant Dirichlet BC attempt 3 Oct 17, 2023
@RemDelaporteMathurin RemDelaporteMathurin marked this pull request as ready for review October 17, 2023 20:34
@RemDelaporteMathurin RemDelaporteMathurin added the fenicsx Issue that is related to the fenicsx support label Oct 18, 2023
Copy link
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.

Just some minor refactoring

festim/boundary_conditions/dirichlet_bc.py Outdated Show resolved Hide resolved
festim/helpers.py Outdated Show resolved Hide resolved
test/test_dirichlet_bc.py Outdated Show resolved Hide resolved
test/test_dirichlet_bc.py Show resolved Hide resolved
test/test_dirichlet_bc.py Show resolved Hide resolved
festim/hydrogen_transport_problem.py Outdated Show resolved Hide resolved
@RemDelaporteMathurin
Copy link
Collaborator Author

@jhdark I addressed your comments.

How about I open an issue to track progress on "only update the BC when needed" and we can merge this?

@jhdark
Copy link
Collaborator

jhdark commented Oct 18, 2023

@jhdark I addressed your comments.

How about I open an issue to track progress on "only update the BC when needed" and we can merge this?

Yep sounds good

@jhdark jhdark merged commit b96c636 into fenicsx Oct 18, 2023
9 checks passed
@RemDelaporteMathurin RemDelaporteMathurin deleted the time_as_Constant branch October 18, 2023 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fenicsx Issue that is related to the fenicsx support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants