Skip to content

Dirichlet BC attempt 3#609

Merged
jhdark merged 41 commits into
fenicsxfrom
time_as_Constant
Oct 18, 2023
Merged

Dirichlet BC attempt 3#609
jhdark merged 41 commits into
fenicsxfrom
time_as_Constant

Conversation

@RemDelaporteMathurin
Copy link
Copy Markdown
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
Copy Markdown

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
Comment thread festim/boundary_conditions/dirichlet_bc.py Outdated
@RemDelaporteMathurin RemDelaporteMathurin added the fenicsx Issue that is related to the fenicsx support label Oct 18, 2023
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.

Just some minor refactoring

Comment thread festim/boundary_conditions/dirichlet_bc.py Outdated
Comment thread festim/helpers.py Outdated
Comment thread test/test_dirichlet_bc.py Outdated
Comment thread test/test_dirichlet_bc.py
Comment thread test/test_dirichlet_bc.py
Comment thread festim/hydrogen_transport_problem.py Outdated
@RemDelaporteMathurin
Copy link
Copy Markdown
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
Copy Markdown
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
@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