-
Notifications
You must be signed in to change notification settings - Fork 25
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
Surface reactions #753
Merged
RemDelaporteMathurin
merged 26 commits into
festim-dev:fenicsx
from
RemDelaporteMathurin:surface-reactions
Nov 1, 2024
Merged
Surface reactions #753
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
1e686fe
first skeleton of class
RemDelaporteMathurin 2e84a71
ufl
RemDelaporteMathurin b4edc8d
Merge branch 'robin' into surface-reactions
RemDelaporteMathurin 361d776
initial draft
RemDelaporteMathurin acff010
example + working implementation
RemDelaporteMathurin 9544d74
refactoring
RemDelaporteMathurin ef70734
documentation
RemDelaporteMathurin ce7eed4
Merge branch 'robin' into surface-reactions
RemDelaporteMathurin b1f2332
fixed tests
RemDelaporteMathurin 936738d
Merge branch 'fenicsx' into surface-reactions
RemDelaporteMathurin 24225d7
Merge remote-tracking branch 'upstream/fenicsx' into surface-reactions
RemDelaporteMathurin 4a55c64
added HH and DD reactions to surface
RemDelaporteMathurin 575323f
added derived quantities
RemDelaporteMathurin 7695587
added system test
RemDelaporteMathurin 06dbc34
added plots
RemDelaporteMathurin 2612b35
add two system tests
RemDelaporteMathurin 1705786
labels to axes and legend
RemDelaporteMathurin 5d71100
moved to examples folder
RemDelaporteMathurin 8d3c4da
time dependent pressure
RemDelaporteMathurin 00815e7
added additional test
RemDelaporteMathurin e93598b
Merge remote-tracking branch 'upstream/fenicsx' into surface-reactions
RemDelaporteMathurin f8f8513
Merge remote-tracking branch 'upstream/fenicsx' into surface-reactions
RemDelaporteMathurin ad3b10b
Check if BC is a BC....
RemDelaporteMathurin 0ee90b1
Merge remote-tracking branch 'upstream/fenicsx' into surface-reactions
RemDelaporteMathurin 7b5899c
fix tests
RemDelaporteMathurin 9203ac7
ruff
RemDelaporteMathurin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import festim as F | ||
from dolfinx import fem | ||
import ufl | ||
|
||
|
||
class SurfaceReactionBCpartial(F.ParticleFluxBC): | ||
"""Boundary condition representing a surface reaction | ||
A + B <-> C | ||
where A, B are the reactants and C is the product | ||
the forward reaction rate is K_r = k_r0 * exp(-E_kr / (k_B * T)) | ||
and the backward reaction rate is K_d = k_d0 * exp(-E_kd / (k_B * T)) | ||
The reaction rate is: | ||
K = K_r * C_A * C_B - K_d * P_C | ||
with C_A, C_B the concentration of species A and B, | ||
P_C the partial pressure of species C at the surface. | ||
|
||
This class is used to create the flux of a single species entering the surface | ||
Example: The flux of species A entering the surface is K. | ||
|
||
|
||
Args: | ||
reactant (list): list of F.Species objects representing the reactants | ||
gas_pressure (float, callable): the partial pressure of the product species | ||
k_r0 (float): the pre-exponential factor of the forward reaction rate | ||
E_kr (float): the activation energy of the forward reaction rate (eV) | ||
k_d0 (float): the pre-exponential factor of the backward reaction rate | ||
E_kd (float): the activation energy of the backward reaction rate (eV) | ||
subdomain (F.SurfaceSubdomain): the surface subdomain where the reaction occurs | ||
species (F.Species): the species to which the flux is applied | ||
""" | ||
|
||
def __init__( | ||
self, | ||
reactant, | ||
gas_pressure, | ||
k_r0, | ||
E_kr, | ||
k_d0, | ||
E_kd, | ||
subdomain, | ||
species, | ||
): | ||
self.reactant = reactant | ||
self.gas_pressure = gas_pressure | ||
self.k_r0 = k_r0 | ||
self.E_kr = E_kr | ||
self.k_d0 = k_d0 | ||
self.E_kd = E_kd | ||
super().__init__(subdomain=subdomain, value=None, species=species) | ||
|
||
def create_value_fenics(self, mesh, temperature, t: fem.Constant): | ||
kr = self.k_r0 * ufl.exp(-self.E_kr / (F.k_B * temperature)) | ||
kd = self.k_d0 * ufl.exp(-self.E_kd / (F.k_B * temperature)) | ||
if callable(self.gas_pressure): | ||
gas_pressure = self.gas_pressure(t=t) | ||
else: | ||
gas_pressure = self.gas_pressure | ||
|
||
product_of_reactants = self.reactant[0].concentration | ||
for reactant in self.reactant[1:]: | ||
product_of_reactants *= reactant.concentration | ||
|
||
self.value_fenics = kd * gas_pressure - kr * product_of_reactants | ||
|
||
|
||
class SurfaceReactionBC: | ||
"""Boundary condition representing a surface reaction | ||
A + B <-> C | ||
where A, B are the reactants and C is the product | ||
the forward reaction rate is K_r = k_r0 * exp(-E_kr / (k_B * T)) | ||
and the backward reaction rate is K_d = k_d0 * exp(-E_kd / (k_B * T)) | ||
The reaction rate is: | ||
K = K_r * C_A * C_B - K_d * P_C | ||
with C_A, C_B the concentration of species A and B, | ||
P_C the partial pressure of species C at the surface. | ||
|
||
The flux of species A entering the surface is K. | ||
In the special case where A=B, then the flux of particle entering the surface is 2*K | ||
|
||
|
||
Args: | ||
reactant (list): list of F.Species objects representing the reactants | ||
gas_pressure (float, callable): the partial pressure of the product species | ||
k_r0 (float): the pre-exponential factor of the forward reaction rate | ||
E_kr (float): the activation energy of the forward reaction rate (eV) | ||
k_d0 (float): the pre-exponential factor of the backward reaction rate | ||
E_kd (float): the activation energy of the backward reaction rate (eV) | ||
subdomain (F.SurfaceSubdomain): the surface subdomain where the reaction occurs | ||
""" | ||
|
||
def __init__( | ||
self, | ||
reactant, | ||
gas_pressure, | ||
k_r0, | ||
E_kr, | ||
k_d0, | ||
E_kd, | ||
subdomain, | ||
): | ||
|
||
self.reactant = reactant | ||
self.gas_pressure = gas_pressure | ||
self.k_r0 = k_r0 | ||
self.E_kr = E_kr | ||
self.k_d0 = k_d0 | ||
self.E_kd = E_kd | ||
self.subdomain = subdomain | ||
|
||
# create the flux boundary condition for each reactant | ||
self.flux_bcs = [ | ||
SurfaceReactionBCpartial( | ||
reactant=self.reactant, | ||
gas_pressure=self.gas_pressure, | ||
k_r0=self.k_r0, | ||
E_kr=self.E_kr, | ||
k_d0=self.k_d0, | ||
E_kd=self.E_kd, | ||
subdomain=self.subdomain, | ||
species=species, | ||
) | ||
for species in self.reactant | ||
] | ||
|
||
@property | ||
def time_dependent(self): | ||
return False # no need to update if only using ufl.conditional objects | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import festim as F | ||
import numpy as np | ||
import ufl | ||
|
||
|
||
my_model = F.HydrogenTransportProblem() | ||
my_model.mesh = F.Mesh1D(vertices=np.linspace(0, 1, 1000)) | ||
my_mat = F.Material(name="mat", D_0=1, E_D=0) | ||
vol = F.VolumeSubdomain1D(id=1, borders=[0, 1], material=my_mat) | ||
left = F.SurfaceSubdomain1D(id=1, x=0) | ||
right = F.SurfaceSubdomain1D(id=2, x=1) | ||
|
||
my_model.subdomains = [vol, left, right] | ||
|
||
H = F.Species("H") | ||
D = F.Species("D") | ||
my_model.species = [H, D] | ||
|
||
my_model.temperature = 500 | ||
|
||
surface_reaction = F.SurfaceReactionBC( | ||
reactant=[H, D], | ||
gas_pressure=0, | ||
k_r0=0.01, | ||
E_kr=0, | ||
k_d0=0, | ||
E_kd=0, | ||
subdomain=right, | ||
) | ||
|
||
surface_reaction_manual = F.ParticleFluxBC( | ||
subdomain=right, | ||
value=lambda c1, T: -2 * 0.01 * ufl.exp(-0 / F.k_B / T) * c1**2, | ||
species=H, | ||
species_dependent_value={"c1": H}, | ||
) | ||
|
||
my_model.boundary_conditions = [ | ||
F.DirichletBC(subdomain=left, value=5, species=H), | ||
F.DirichletBC(subdomain=left, value=5, species=D), | ||
surface_reaction, | ||
# surface_reaction_manual, | ||
] | ||
|
||
my_model.exports = [F.XDMFExport("test.xdmf", H)] | ||
|
||
my_model.settings = F.Settings(atol=1e-10, rtol=1e-10, final_time=10, transient=True) | ||
|
||
my_model.settings.stepsize = 0.1 | ||
|
||
my_model.initialise() | ||
my_model.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jhdark here
all_bcs
could be a property I just don't want to modifyself.boundary_conditions