API reference#
- class DirichletBCBase(subdomain: SurfaceSubdomain, value: ndarray | Constant | int | float | Callable)[source]#
Bases:
objectDirichlet boundary condition class u = value.
- Parameters:
subdomain β The surface subdomain where the boundary condition is applied
value β The value of the boundary condition
- Variables:
subdomain (festim.subdomain.surface_subdomain.SurfaceSubdomain) β The surface subdomain where the boundary condition is applied
value (numpy.ndarray | dolfinx.fem.function.Constant | int | float | collections.abc.Callable[[numpy.ndarray], numpy.ndarray] | collections.abc.Callable[[numpy.ndarray, float], numpy.ndarray] | collections.abc.Callable[[float], float]) β The value of the boundary condition
value_fenics (None | dolfinx.fem.function.Function | dolfinx.fem.function.Constant | numpy.ndarray | float) β The value of the boundary condition in fenics format
bc_expr (dolfinx.fem.function.Expression) β The expression of the boundary condition that is used to update the value_fenics
- define_surface_subdomain_dofs(facet_meshtags: MeshTags, function_space: FunctionSpace | tuple[FunctionSpace, FunctionSpace]) ndarray[Any, dtype[int32]] | tuple[ndarray[Any, dtype[int32]], ndarray[Any, dtype[int32]]][source]#
Defines the facets and the degrees of freedom of the boundary condition.
Given the input meshtags, find all facets matching the boundary condition subdomain ID, and locate all DOFs associated with the input function space(s).
Note
For sub-spaces, a tuple of sub-spaces are expected as input, and a tuple of arrays associated to each of the function spaces are returned.
- Parameters:
facet_meshtags β MeshTags describing some facets in the domain
mesh
function_space β The function space or a tuple of function spaces:
(sub
collapsed)
- property time_dependent: bool#
Returns true if the value of the boundary condition is time dependent.
- class FixedConcentrationBC(subdomain: SurfaceSubdomain, value: ndarray | Constant | int | float | Callable, species: Species)[source]#
Bases:
DirichletBCBase- Parameters:
subdomain (festim.Subdomain) β the surface subdomain where the boundary condition is applied
value β The value of the boundary condition. It can be a function of
time (space and/or)
species β The name of the species
- Variables:
temperature_dependent (bool) β True if the value of the bc is
dependent (temperature)
Examples
FixedConcentrationBC(subdomain=my_subdomain, value=1, species="H") FixedConcentrationBC(subdomain=my_subdomain, value=lambda x: 1 + x[0], species="H") FixedConcentrationBC(subdomain=my_subdomain, value=lambda t: 1 + t, species="H") FixedConcentrationBC(subdomain=my_subdomain, value=lambda T: 1 + T, species="H") FixedConcentrationBC(subdomain=my_subdomain, value=lambda x, t: 1 + x[0] + t, species="H")
- create_value(function_space: FunctionSpace, temperature: float | Constant, t: float | Constant, K_S: Function = None)[source]#
Creates the value of the boundary condition as a fenics object and sets it to self.value_fenics. If the value is a constant, it is converted to a dolfinx.fem.Constant. If the value is a function of t, it is converted to dolfinx.fem.Constant. Otherwise, it is converted to a dolfinx.fem.Function.Function and the expression of the function is stored in bc_expr.
- Parameters:
function_space β the function space
temperature β The temperature
t β the time
K_S β The solubility of the species. If provided, the value of the
condition (boundary) β is divided by K_S (change of variable method).
- class FixedTemperatureBC(subdomain: SurfaceSubdomain, value: ndarray | Constant | int | float | Callable)[source]#
Bases:
DirichletBCBase- create_value(function_space: FunctionSpace, t: Constant)[source]#
Creates the value of the boundary condition as a fenics object and sets it to self.value_fenics. If the value is a constant, it is converted to a dolfinx.fem.Constant. If the value is a function of t, it is converted to a dolfinx.fem.Constant. Otherwise, it is converted to a` dolfinx.fem.Function` and the expression of the function is stored in bc_expr.
- Parameters:
function_space β the function space
t β the time
- class FluxBCBase(subdomain: SurfaceSubdomain, value)[source]#
Bases:
objectFlux boundary condition class.
Ensuring the gradient of the solution u at a boundary:
\[-A \nabla u \cdot \mathbf{n} = f\]where \(A\) is some material property (diffusivity for particle flux and thermal conductivity for heat flux), \(\mathbf{n}\) is the outwards normal vector of the boundary, \(f\) is a function of space and time.
- Parameters:
subdomain (festim.SurfaceSubdomain) β the surface subdomain where the boundary condition is applied
value (float, fem.Constant, callable) β the value of the boundary condition
- Variables:
subdomain (festim.SurfaceSubdomain) β the surface subdomain where the boundary condition is applied
value (float, fem.Constant, callable) β the value of the boundary condition
value_fenics (fem.Function or fem.Constant) β the value of the boundary
in (condition) β fenics format
bc_expr (fem.Expression) β the expression of the boundary condition that
to (is used) β update the value_fenics
- create_value_fenics(mesh, temperature, t: Constant)[source]#
Creates the value of the boundary condition as a fenics object and sets it to self.value_fenics. If the value is a constant, it is converted to a fenics.Constant. If the value is a function of t, it is converted to a fenics.Constant. Otherwise, it is converted to a ufl Expression.
- Parameters:
mesh (dolfinx.mesh.Mesh) β the mesh
temperature (float) β the temperature
t (dolfinx.fem.Constant) β the time
- class HeatFluxBC(subdomain, value)[source]#
Bases:
FluxBCBaseHeat flux boundary condition class.
Ensuring the gradient of the solution T at a boundary: -lambda * grad(T) * n = f where lambda is the thermal conductivity , n is the outwards normal vector of the boundary, f is a function of space and time.
- Parameters:
subdomain (festim.SurfaceSubdomain) β the surface subdomain where the heat flux is applied
value (float, callable, fem.Constant) β the value of the heat flux
- Variables:
subdomain (festim.SurfaceSubdomain) β the surface subdomain where the heat flux is applied
value (float, callable, fem.Constant) β the value of the heat flux
value_fenics (fem.Function or fem.Constant) β the value of the heat flux in fenics format
bc_expr (fem.Expression) β the expression of the heat flux that is used to update the value_fenics
Examples
HeatFluxBC(subdomain=my_subdomain, value=1) HeatFluxBC(subdomain=my_subdomain, value=lambda x: 1 + x[0]) HeatFluxBC(subdomain=my_subdomain, value=lambda t: 1 + t) HeatFluxBC(subdomain=my_subdomain, value=lambda x, t: 1 + x[0] + t)
- class HenrysBC(subdomain, H_0, E_H, pressure, species)[source]#
Bases:
FixedConcentrationBCHenrys boundary condition class.
c = H * pressure H = H_0 * exp(-E_H / k_B / T)
- Parameters:
subdomain (festim.Subdomain) β the subdomain where the boundary condition is applied
species (str) β the name of the species
H_0 (float or fem.Constant) β the Henrys constant pre-exponential factor
(H/m3/Pa)
E_H (float or fem.Constant) β the Henrys constant activation energy (eV)
pressure (float or callable) β the pressure at the boundary (Pa)
- Variables:
subdomain (festim.Subdomain) β the subdomain where the boundary condition is applied
value (float or fem.Constant) β the value of the boundary condition
species (festim.Species or str) β the name of the species
H_0 (float or fem.Constant) β the Henrys constant pre-exponential factor
(H/m3/Pa)
E_H (float or fem.Constant) β the Henrys constant activation energy (eV)
pressure (float or callable) β the pressure at the boundary (Pa)
Examples
HenrysBC(subdomain=my_subdomain, H_0=1e-6, E_H=0.2, pressure=1e5, species="H") HenrysBC(subdomain=my_subdomain, H_0=1e-6, E_H=0.2, pressure=lambda x: 1e5 + x[0], species="H") HenrysBC(subdomain=my_subdomain, H_0=1e-6, E_H=0.2, pressure=lambda t: 1e5 + t, species="H") HenrysBC(subdomain=my_subdomain, H_0=1e-6, E_H=0.2, pressure=lambda T: 1e5 + T, species="H") HenrysBC(subdomain=my_subdomain, H_0=1e-6, E_H=0.2, pressure=lambda x, t: 1e5 + x[0] + t, species="H")
- class ParticleFluxBC(subdomain, value, species, species_dependent_value={})[source]#
Bases:
FluxBCBaseParticle flux boundary condition class.
Ensuring the gradient of the solution c at a boundary: -D * grad(c) * n = f where D is the material diffusivity, n is the outwards normal vector of the boundary, f is a function of space and time.
- Parameters:
subdomain (festim.SurfaceSubdomain) β the surface subdomain where the
flux (particle) β is applied
value (float, fem.Constant, callable) β the value of the particle flux
species (festim.Species) β the species to which the flux is applied
species_dependent_value (dict) β a dictionary containing the species
Example (that the value.) β {βnameβ: species} where βnameβ is the variable name in the callable value and species is a festim.Species object.
- Variables:
subdomain (festim.SurfaceSubdomain) β the surface subdomain where the
flux (particle) β is applied
value (float or fem.Constant) β the value of the particle flux
species (festim.Species) β the species to which the flux is applied
value_fenics (fem.Function or fem.Constant) β the value of the particle flux in fenics format
bc_expr (fem.Expression) β the expression of the particle flux that is used to update the value_fenics
species_dependent_value (dict) β a dictionary containing the species
Example (that the value.) β {βnameβ: species} where βnameβ is the variable name in the callable value and species is a festim.Species object.
Examples
ParticleFluxBC(subdomain=my_subdomain, value=1, species="H") ParticleFluxBC(subdomain=my_subdomain, value=lambda x: 1 + x[0], species="H") ParticleFluxBC(subdomain=my_subdomain, value=lambda t: 1 + t, species="H") ParticleFluxBC(subdomain=my_subdomain, value=lambda T: 1 + T, species="H") ParticleFluxBC(subdomain=my_subdomain, value=lambda x, t: 1 + x[0] + t, species="H") ParticleFluxBC(subdomain=my_subdomain, value=lambda c1: 2 * c1**2, species="H", species_dependent_value={"c1": species1})
- create_value_fenics(mesh, temperature, t: Constant)[source]#
Creates the value of the boundary condition as a fenics object and sets it to self.value_fenics. If the value is a constant, it is converted to a fenics.Constant. If the value is a function of t, it is converted to a fenics.Constant. Otherwise, it is converted to a ufl Expression.
- Parameters:
mesh (dolfinx.mesh.Mesh) β the mesh
temperature (float) β the temperature
t (dolfinx.fem.Constant) β the time
- class SievertsBC(subdomain, S_0, E_S, pressure, species)[source]#
Bases:
FixedConcentrationBCSieverts boundary condition class.
c = S * sqrt(pressure) S = S_0 * exp(-E_S / k_B / T)
- Parameters:
subdomain (festim.Subdomain) β the subdomain where the boundary condition is applied
species (str) β the name of the species
S_0 (float or fem.Constant) β the Sieverts constant pre-exponential
factor (H/m3/Pa0.5)
E_S (float or fem.Constant) β the Sieverts constant activation energy (eV)
pressure (float or callable) β the pressure at the boundary (Pa)
- Variables:
subdomain (festim.Subdomain) β the subdomain where the boundary condition is applied
value (float or fem.Constant) β the value of the boundary condition
species (festim.Species or str) β the name of the species
S_0 (float or fem.Constant) β the Sieverts constant pre-exponential
factor (H/m3/Pa0.5)
E_S (float or fem.Constant) β the Sieverts constant activation energy (eV)
pressure (float or callable) β the pressure at the boundary (Pa)
Examples
SievertsBC(subdomain=my_subdomain, S_0=1e-6, E_S=0.2, pressure=1e5, species="H") SievertsBC(subdomain=my_subdomain, S_0=1e-6, E_S=0.2, pressure=lambda x: 1e5 + x[0], species="H") SievertsBC(subdomain=my_subdomain, S_0=1e-6, E_S=0.2, pressure=lambda t: 1e5 + t, species="H") SievertsBC(subdomain=my_subdomain, S_0=1e-6, E_S=0.2, pressure=lambda T: 1e5 + T, species="H") SievertsBC(subdomain=my_subdomain, S_0=1e-6, E_S=0.2, pressure=lambda x, t: 1e5 + x[0] + t, species="H")
- class SurfaceReactionBC(reactant, gas_pressure, k_r0, E_kr, k_d0, E_kd, subdomain)[source]#
Bases:
objectBoundary 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
- Parameters:
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
- class SurfaceReactionBCpartial(reactant, gas_pressure, k_r0, E_kr, k_d0, E_kd, subdomain, species)[source]#
Bases:
ParticleFluxBCBoundary 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.
- Parameters:
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
- create_value_fenics(mesh, temperature, t: Constant)[source]#
Creates the value of the boundary condition as a fenics object and sets it to self.value_fenics. If the value is a constant, it is converted to a fenics.Constant. If the value is a function of t, it is converted to a fenics.Constant. Otherwise, it is converted to a ufl Expression.
- Parameters:
mesh (dolfinx.mesh.Mesh) β the mesh
temperature (float) β the temperature
t (dolfinx.fem.Constant) β the time
- class AverageSurface(field: Species | str, surface: SurfaceSubdomain | int, filename: str | None = None)[source]#
Bases:
SurfaceQuantityComputes the average value of a field on a given surface.
- Parameters:
field (festim.Species) β species for which the average surface is computed
surface (festim.SurfaceSubdomain) β surface subdomain
filename (str, optional) β name of the file to which the average surface is exported
- Variables:
festim.SurfaceQuantity (see)
- compute(u: Function | Indexed, ds: Measure, entity_maps=None)[source]#
Computes the average value of the field on the defined surface subdomain, and appends it to the data list.
- Parameters:
u β field for which the average value is computed
ds β surface measure of the model
entity_maps β entity maps relating parent mesh and submesh
- class AverageVolume(field: Species | str, volume: VolumeSubdomain | int, filename: str | None = None)[source]#
Bases:
VolumeQuantityComputes the average value of a field in a given volume.
- Parameters:
field (festim.Species) β species for which the average volume is computed
volume (festim.VolumeSubdomain) β volume subdomain
filename (str, optional) β name of the file to which the average volume
exported (is)
- Variables:
festim.VolumeQuantity (see)
- class CustomFieldExport(filename: str | Path, expression: Callable, species_dependent_value: dict[str, Species] | None = None, times: list[float] | list[int] | None = None, subdomain: VolumeSubdomain = None, checkpoint: bool = False)[source]#
Bases:
ExportBaseClassExport a custom field to a VTX file
- Parameters:
filename β The name of the output file
expression β A function evaluating the custom field. Positional arguments of the function can be βtβ (time), βxβ (spatial coordinate), βTβ (temperature), or any key from the species_dependent_value dictionary.
species_dependent_value β A dictionary mapping argument names in expression to Species objects. Defaults to None.
times β if provided, the field will be exported at these timesteps. Otherwise exports at all timesteps. Defaults to None.
subdomain β The volume subdomain on which the custom field is evaluated. Defaults to None.
checkpoint β If True, the export will be a checkpoint file using adios4dolfinx and wonβt be readable by ParaView. Default is False.
- Variables:
filename β The name of the output file
expression (collections.abc.Callable) β A function evaluating the custom field.
species_dependent_value (dict[str, festim.species.Species]) β A dictionary mapping argument names to Species objects.
subdomain (festim.subdomain.volume_subdomain.VolumeSubdomain) β The volume subdomain on which the custom field is evaluated.
checkpoint (bool) β If True, the export will be a checkpoint file.
times β if provided, the field will be exported at these timesteps. Otherwise exports at all timesteps.
function (dolfinx.fem.function.Function) β the function containing the custom field values
writer (dolfinx.io.utils.VTXWriter) β The VTXWriter object used to write the file
dolfinx_expression (dolfinx.fem.function.Expression) β the dolfinx expression used to evaluate the function
- check_valid_inputs(kwargs: dict)[source]#
Check if we are in the mixed domain/discontinuous case and if the user-provided expression is valid in this case. dolfinx.fem.Expression does not support co-dim 0 submeshes and time is defined on the parent mesh, so we cannot have time-dependent custom fields in the mixed domain/discontinuous case.
When FEniCS/dolfinx#3207 is resolved we should be able to support this
- property mixed_domain: bool#
Check if we are in a mixed domain/discontinuous case. This is the case if at least one of the species in species_dependent_value is defined on a subdomain or if the custom field is defined on a subdomain.
- Returns:
True if we are in a mixed domain/discontinuous case, False otherwise.
- set_dolfinx_expression(temperature: Constant | Function, time: Constant)[source]#
Set the dolfinx expression used to evaluate the custom field. This is done by evaluating the user-provided expression with the appropriate arguments and using the result to create a dolfinx expression.
- Parameters:
temperature β The temperature field to use in the expression
time β The time to use in the expression
- class CustomQuantity(expr: Callable, subdomain: SurfaceSubdomain | VolumeSubdomain, title: str = 'Custom Quantity', filename: str | None = None)[source]#
Bases:
DerivedQuantityExport CustomQuantity.
- Parameters:
expr β function that returns a UFL expression
subdomain β subdomain on which the quantity is evaluated
title β title of the exported quantity
filename β name of the file to which the quantity is exported
- Variables:
expr β function that returns a UFL expression
subdomain β subdomain on which the quantity is evaluated
title β title of the exported quantity
filename (str | None) β name of the file to which the quantity is exported
t (list[float]) β list of time values
data (list[float]) β list of values of the quantity
Usage:
import numpy as np import festim as F material = F.Material(D_0=1, E_D=0) volume = F.VolumeSubdomain(id=1, material=material) surface = F.SurfaceSubdomain(id=1, locator=lambda x: np.isclose(x[1], 1)) def total_concentration(**kwargs): return kwargs["A"] + kwargs["B"] quantity = F.CustomQuantity( expr=total_concentration, subdomain=volume, title="Total quantity", ) surface_quantity = F.CustomQuantity( expr=lambda **kwargs: -kwargs["D_A"] * ufl.dot( ufl.grad(kwargs["A"]), kwargs["n"] ), subdomain=surface, title="Surface flux", )
The callable passed to
exprreceives keyword arguments assembled by the problem class. Common entries are:A,B, β¦Concentrations of the species present in the problem (here A and B).
nThe facet normal on the selected surface subdomain.
TThe temperature field.
D_A,D_B, β¦Species-specific diffusion coefficients.
DThe diffusion coefficient data, either a single field for one species or a dictionary keyed by species name when several species are present.
xThe spatial coordinate (x[0], x[1], x[2]).
For a surface quantity, the returned UFL expression can represent a flux such as
\[q = -D\,\nabla c \cdot n\]and FESTIM will assemble
\[Q = \int_{\Gamma} q\,\mathrm{d}\Gamma\]over the selected surface subdomain.
The expression returned by
expris treated as an integrand and assembled over the chosen subdomain.\[Q = \int_{\Omega} q\,\mathrm{d}\Omega\]where
qis the UFL expression returned byexprand\Omegais either a surface or a volume subdomain.
- class DerivedQuantity(filename: str | None = None)[source]#
Bases:
ABCBase class for all derived quantities.
- Variables:
filename (str | None) β name of the file to which the quantity is exported
t (list[float]) β list of time values
data (list[float]) β list of values of the quantity
- class ExportBaseClass(filename: str | Path, ext: str, times: list[float] | list[int] | None = None)[source]#
Bases:
objectExport functions to VTX file.
- Parameters:
filename β The name of the output file
times β if provided, the field will be exported at these timesteps. Otherwise exports at all timesteps. Defaults to None.
- Variables:
filename β The name of the output file
times β if provided, the field will be exported at these timesteps. Otherwise exports at all timesteps. Defaults to None.
- class MaximumSurface(field: Species | str, surface: SurfaceSubdomain | int, filename: str | None = None)[source]#
Bases:
SurfaceQuantityComputes the maximum value of a field on a given surface.
- Parameters:
field (festim.Species) β species for which the maximum surface is computed
surface (festim.SurfaceSubdomain) β surface subdomain
filename (str, optional) β name of the file to which the maximum surface
exported (is)
- Variables:
festim.SurfaceQuantity (see)
- class MaximumVolume(field: Species | str, volume: VolumeSubdomain | int, filename: str | None = None)[source]#
Bases:
VolumeQuantityComputes the maximum value of a field in a given volume.
- Parameters:
field (festim.Species) β species for which the maximum volume is computed
volume (festim.VolumeSubdomain) β volume subdomain
filename (str, optional) β name of the file to which the maximum volume
exported (is)
- Variables:
festim.VolumeQuantity (see)
- class MinimumSurface(field: Species | str, surface: SurfaceSubdomain | int, filename: str | None = None)[source]#
Bases:
SurfaceQuantityComputes the minimum value of a field on a given surface.
- Parameters:
field (festim.Species) β species for which the minimum surface is computed
surface (festim.SurfaceSubdomain) β surface subdomain
filename (str, optional) β name of the file to which the minimum surface
exported (is)
- Variables:
festim.SurfaceQuantity (see)
- class MinimumVolume(field: Species | str, volume: VolumeSubdomain | int, filename: str | None = None)[source]#
Bases:
VolumeQuantityComputes the minimum value of a field in a given volume.
- Parameters:
field (festim.Species) β species for which the minimum volume is computed
volume (festim.VolumeSubdomain) β volume subdomain
filename (str, optional) β name of the file to which the minimum volume
exported (is)
- Variables:
festim.VolumeQuantity (see)
- class Profile1DExport(field: Species, subdomain: VolumeSubdomain = None, times: list[float] | None = None)[source]#
Bases:
objectClass to export 1D profiles of a field in a simulation.
- Parameters:
field β the species for which the profile is computed.
subdomain β the volume subdomain to compute the profile on. If None, the profile is computed over the entire domain.
times β if provided, the profile will be exported at these timesteps. Otherwise, exports at all timesteps. Defaults to None.
- Variables:
field (festim.species.Species) β the species for which the profile is computed.
subdomain (festim.subdomain.volume_subdomain.VolumeSubdomain | None) β the volume subdomain to compute the profile on. If None, the profile is computed over the entire domain.
times (list[float] | None) β if provided, the profile will be exported at these timesteps. Otherwise, exports at all timesteps.
x (numpy.ndarray) β the coordinates along which the profile is computed.
data (list) β the computed profile data.
t (list[float]) β the list of time values at which the profile is computed.
- class ReactionRateExport(reaction: Reaction, filename: str | Path, direction: str = 'both', times: list[float] | None = None, subdomain: VolumeSubdomain | None = None, checkpoint: bool = False)[source]#
Bases:
CustomFieldExportExport a reaction rate to a VTX file
- Parameters:
reaction β The reaction to export the rate of.
filename β The name of the output file.
direction β The direction of the reaction to export. Can be βforwardβ, βbackwardβ or βbothβ. Defaults to βbothβ.
times β if provided, the field will be exported at these timesteps. Otherwise exports at all timesteps. Defaults to None.
subdomain β The volume subdomain on which the reaction rate is evaluated. Defaults to None.
checkpoint β If True, the export will be a checkpoint file using adios4dolfinx and wonβt be readable by ParaView. Default is False.
- override_signature(expression: Callable, reactant_names: list[str], product_names: list[str])[source]#
Override the signature of the expression function. This is needed to ensure that the expression has the correct arguments for set_dolfinx_expression().
- Parameters:
expression β The user-provided expression for the reaction rate. The arguments of the expression must be T (temperature) and the names of the reactants and products.
- class SurfaceFlux(field: Species, surface: SurfaceSubdomain, filename: str | None = None)[source]#
Bases:
SurfaceQuantityComputes the flux of a field on a given surface.
- Parameters:
field β species for which the surface flux is computed
surface β surface subdomain
filename β name of the file to which the surface flux is exported
- Variables:
festim.SurfaceQuantity (see)
- class SurfaceQuantity(field: Species | str, surface: SurfaceSubdomain | int, filename: str | None = None)[source]#
Bases:
DerivedQuantityExport SurfaceQuantity.
- Parameters:
field β species for which the surface flux is computed
surface β surface subdomain
filename β name of the file to which the surface flux is exported
- Variables:
field (festim.species.Species) β species for which the surface flux is computed
surface (festim.subdomain.surface_subdomain.SurfaceSubdomain) β surface subdomain
filename (str | None) β name of the file to which the surface flux is exported
t (list[float]) β list of time values
data (list[float]) β list of values of the surface quantity
- class TotalSurface(field: Species | str, surface: SurfaceSubdomain | int, filename: str | None = None)[source]#
Bases:
SurfaceQuantityComputes the total value of a field on a given surface.
- Parameters:
field (festim.Species) β species for which the total volume is computed
surface (festim.SurfaceSubdomain) β surface subdomain
filename (str, optional) β name of the file to which the total volume is exported
- Variables:
festim.SurfaceQuantity (see)
- compute(u: Function | Indexed, ds: Measure, entity_maps=None)[source]#
Computes the total value of the field on the defined surface subdomain, and appends it to the data list.
- Parameters:
u β field for which the total value is computed
ds β surface measure of the model
entity_maps β entity maps relating parent mesh and submesh
- class TotalVolume(field: Species | str, volume: VolumeSubdomain | int, filename: str | None = None)[source]#
Bases:
VolumeQuantityComputes the total value of a field in a given volume.
- Parameters:
field (festim.Species) β species for which the total volume is computed
volume (festim.VolumeSubdomain) β volume subdomain
filename (str, optional) β name of the file to which the total volume is exported
- Variables:
festim.VolumeQuantity (see)
- compute(u, dx: Measure, entity_maps=None)[source]#
Computes the value of the total volume of the field in the volume subdomain and appends it to the data list.
- Parameters:
u β field for which the total volume is computed
dx β volume measure of the model
entity_maps β entity maps relating parent mesh and submesh
- class VTXSpeciesExport(filename: str | Path, field: Species | list[Species], subdomain: VolumeSubdomain = None, checkpoint: bool = False, times: list[float] | list[int] | None = None)[source]#
Bases:
ExportBaseClassExport species field functions to VTX file.
- Parameters:
filename β The name of the output file
field β Set of species to export
subdomain β A field can be defined on multiple domains. This arguments specifies what subdomains we export on. If None we export on all domains.
checkpoint β If True, the export will be a checkpoint file using adios4dolfinx and wonβt be readable by ParaView. Default is False.
times β if provided, the field will be exported at these timesteps. Otherwise exports at all timesteps. Defaults to None.
- Variables:
filename β The name of the output file
field β Set of species to export
times β if provided, the field will be exported at these timesteps. Otherwise exports at all timesteps. Defaults to None.
writer (dolfinx.io.utils.VTXWriter) β The VTXWriter object used to write the file
- class VTXTemperatureExport(filename: str | Path, times: list[float] | list[int] | None = None)[source]#
Bases:
ExportBaseClassExport temperature field functions to VTX file.
- Parameters:
filename β The name of the output file
times β if provided, the field will be exported at these timesteps. Otherwise exports at all timesteps. Defaults to None.
- Variables:
filename β The name of the output file
times β if provided, the field will be exported at these timesteps. Otherwise exports at all timesteps. Defaults to None.
writer (dolfinx.io.utils.VTXWriter) β The VTXWriter object used to write the file
- class VolumeQuantity(field: Species | str, volume: VolumeSubdomain | int, filename: str | None = None)[source]#
Bases:
DerivedQuantityExport VolumeQuantity.
- Parameters:
field β species for which the volume quantity is computed
volume β volume subdomain
filename β name of the file to which the volume quantity is exported
- Variables:
field (festim.species.Species) β species for which the volume quantity is computed
volume (festim.subdomain.volume_subdomain.VolumeSubdomain) β volume subdomain
filename (str | None) β name of the file to which the volume quantity is exported
t (list[float]) β list of time values
data (list[float]) β list of values of the volume quantity
- class XDMFExport(filename: str | Path, field: list[Species] | Species)[source]#
Bases:
ExportBaseClassExport functions to XDMFfile.
- Parameters:
filename β The name of the output file
field β The field(s) to export
- Variables:
_writer (dolfinx.io.XDMFFile) β the XDMF writer
_field (festim.Species, list of festim.Species) β the field index to export
- class Mesh(mesh: Mesh | None = None, coordinate_system: str | CoordinateSystem = CoordinateSystem.CARTESIAN)[source]#
Bases:
objectMesh class.
- Parameters:
mesh β The mesh. Defaults to None.
coordinate_system β the coordinate system of the mesh (βcartesianβ, βcylindricalβ, βsphericalβ). Defaults to βcartesianβ.
- Variables:
mesh (mesh The)
vdim (int) β the dimension of the mesh cells
fdim (int) β the dimension of the mesh facets
n (ufl.geometry.FacetNormal) β Symbolic representation of the vector normal to the facets of the mesh.
- check_mesh_dim_coords()[source]#
Checks if the used coordinates can be applied for geometry with the specified dimensions.
- define_meshtags(surface_subdomains, volume_subdomains, interfaces=None)[source]#
Defines the facet and volume meshtags of the mesh.
- Parameters:
surface_subdomains (list of festim.SufaceSubdomains) β the surface
model (subdomains of the)
volume_subdomains (list of festim.VolumeSubdomains) β the volume
model
interfaces (dict, optional) β the interfaces between volume subdomains {int: [VolumeSubdomain, VolumeSubdomain]}. Defaults to None.
- Returns:
the facet meshtags dolfinx.mesh.MeshTags: the volume meshtags
- Return type:
dolfinx.mesh.MeshTags
- class Mesh1D(vertices, **kwargs)[source]#
Bases:
Mesh1D Mesh.
- Parameters:
vertices (list or np.ndarray) β the mesh x-coordinates (m)
- Variables:
vertices (np.ndarray) β the mesh x-coordinates (m)
- check_borders(volume_subdomains)[source]#
Checks that the borders of the subdomain are within the domain.
- Parameters:
volume_subdomains (list of festim.VolumeSubdomain1D) β the volume subdomains
- Raises:
Value error β if borders outside the domain
- define_meshtags(surface_subdomains, volume_subdomains, interfaces=None)[source]#
Defines the facet and volume meshtags of the mesh.
- Parameters:
surface_subdomains (list of festim.SufaceSubdomains) β the surface
model (subdomains of the)
volume_subdomains (list of festim.VolumeSubdomains) β the volume
model
interfaces (dict, optional) β the interfaces between volume subdomains {int: [VolumeSubdomain, VolumeSubdomain]}. Defaults to None.
- Returns:
the facet meshtags dolfinx.mesh.MeshTags: the volume meshtags
- Return type:
dolfinx.mesh.MeshTags
- class MeshFromXDMF(volume_file, facet_file, mesh_name='Grid', surface_meshtags_name='Grid', volume_meshtags_name='Grid')[source]#
Bases:
MeshMesh read from the XDMF files.
- Parameters:
volume_file (str) β path to the volume file
facet_file (str) β path to the facet file
mesh_name (str, optional) β name of the mesh in the volume XDMF file. Defaults to βGridβ.
surface_meshtags_name (str, optional) β name of the surface meshtags in the facet XDMF file. Defaults to βGridβ.
volume_meshtags_name (str, optional) β name of the volume meshtags in the volume XDMF file. Defaults to βGridβ.
- Variables:
volume_file (str) β path to the volume file
facet_file (str) β path to the facet file
mesh_name (str) β name of the mesh in the volume XDMF file.
surface_meshtags_name (str) β name of the surface meshtags in the facet
file. (XDMF)
volume_meshtags_name (str) β name of the volume meshtags in the volume XDMF file
mesh (fenics.mesh.Mesh) β the fenics mesh
- class Interface(id: int, subdomains: list[VolumeSubdomain], penalty_term: float = 10.0, method: InterfaceMethod = InterfaceMethod.penalty)[source]#
Bases:
InterfaceBaseRepresents an interface between two subdomains with discontinuous solutions.
This class handles the coupling of solutions across an interface between two volume subdomains using either penalty or Nitsche methods. It manages the exchange of boundary conditions and enforces continuity across the interface.
- Variables:
id (int) β Tag of the interface subdomain in the parent mesh tags.
subdomains (tuple[festim.subdomain.volume_subdomain.VolumeSubdomain, festim.subdomain.volume_subdomain.VolumeSubdomain]) β The two subdomains sharing this interface.
parent_mesh (dolfinx.mesh.Mesh) β The parent mesh containing the interface.
mt (dolfinx.mesh.MeshTags) β Mesh tags for the parent mesh.
restriction (list[str, str]) β FEniCS restriction operators for each side of the interface, defaults to (β+β, β-β).
padded (bool) β Whether the parent-to-submesh maps have been padded.
method (festim.subdomain.interface.InterfaceMethod) β The method used to enforce interface conditions (penalty or Nitsche).
penalty_term β Penalty parameter for the interface formulation.
- Ks(species: Species, temperature)[source]#
Get solubility coefficients for both sides of the interface.
Computes the solubility coefficient at the interface temperature for each subdomainβs material.
- Parameters:
species β The species for which to compute solubility.
temperature β A function that returns temperature at given restrictions.
- Returns:
Solubility coefficients (K_0, K_1) for subdomains 0 and 1.
- get_formulation(dS: Measure, species: list[Species], temperature) tuple[Form, Form][source]#
Generate the interface formulation for all species.
- Parameters:
dS β Integration measure for the interface, with correct integration data.
species β Species for which interface conditions should be applied. Must be defined in both subdomains of the interface.
temperature β Temperature field/function for temperature-dependent laws.
- Returns:
Variational forms to be added to each subdomain.
- Raises:
AssertionError β If the interface method is unknown or species is not defined in both subdomains.
- property method: InterfaceMethod#
Get the interface coupling method.
- Returns:
The current interface method (penalty or Nitsche).
- Return type:
InterfaceMethod
- nitsche_method(dS, species, temperature)[source]#
Generate interface formulation using the Nitsche method.
The Nitsche method is a stabilized discontinuous Galerkin approach that enforces interface continuity through a combination of: - Average gradient terms - Jump-based penalty stabilization
This method is more stable for certain problems compared to pure penalty.
- Parameters:
dS β Integration measure for the interface.
species β The species for which to compute the interface form.
temperature β A function returning temperature at given restrictions.
- Returns:
Variational forms for subdomains 0 and 1.
- penalty_method(dS, species, temperature)[source]#
Generate interface formulation using the penalty method.
The penalty method enforces interface continuity through a penalty term: penalty_term * (u_1/K_1 - u_0/K_0) applied symmetrically to both sides. Handles different solubility laws (Henry vs Sievert) on each side.
- Parameters:
dS β Integration measure for the interface.
species β The species for which to compute the interface form.
temperature β A function returning temperature at given restrictions.
- Returns:
Variational forms for subdomains 0 and 1.
- class SurfaceSubdomain(id: int, locator: Callable | None = None)[source]#
Bases:
objectSurface subdomain class.
- Parameters:
id β the id of the surface subdomain
locator β a callable function that locates the boundary facets of the subdomain
Examples
SurfaceSubdomain(id=1, locator=lambda x: np.isclose(x[0], 1.0)) SurfaceSubdomain(id=1, locator=lambda x: np.logical_or(np.isclose(x[1], 0.0), np.isclose(x[1], 1.0))) SurfaceSubdomain(id=1, locator=lambda x: np.logical_and(np.isclose(x[0], 0.0), np.isclose(x[1], 1.0))) SurfaceSubdomain(id=1, locator=lambda x: np.logical_and(np.isclose(x[0], 0.0), x[1] <= 0.5))
- class SurfaceSubdomain1D(id: int, x: float)[source]#
Bases:
SurfaceSubdomainSurface subdomain class for 1D cases.
- Parameters:
id β the id of the surface subdomain
x β the x coordinate of the surface subdomain
- Variables:
id (int) β the id of the surface subdomain
x (float) β the x coordinate of the surface subdomain
Examples
SurfaceSubdomain1D(id=1, x=1)
- class VolumeSubdomain(id, material, locator: Callable | None = None, name: str | None = None)[source]#
Bases:
objectVolume subdomain class.
- Parameters:
id β the id of the volume subdomain (> 0)
submesh β the submesh of the volume subdomain
cell_map β the cell map of the volume subdomain
parent_mesh β the parent mesh of the volume subdomain
parent_to_submesh β the parent to submesh map of the volume subdomain
v_map β the vertex map of the volume subdomain
n_map β the normal map of the volume subdomain
facet_to_parent β the facet to parent map of the volume subdomain
ft β the facet meshtags of the volume subdomain
padded β whether the subdomain is padded (for 0.9 compatibility)
u β the solution function of the subdomain
u_n β the previous solution function of the subdomain
material β the material assigned to the subdomain
sub_T β the sub temperature field in the subdomain
- create_subdomain(mesh: Mesh, marker: MeshTags)[source]#
Creates the following attributes:
.parent_mesh,.submesh,.cell_map,.v_map,padded, and the entity mapparent_to_submesh.Only used in
festim.HydrogenTransportProblemDiscontinuous- Parameters:
mesh (dolfinx.mesh.Mesh) β the parent mesh
marker (dolfinx.mesh.MeshTags) β the parent volume markers
- class VolumeSubdomain1D(id, borders, material)[source]#
Bases:
VolumeSubdomainVolume subdomain class for 1D cases.
- Parameters:
id (int) β the id of the volume subdomain
borders (list of float) β the borders of the volume subdomain
material (festim.Material) β the material of the volume subdomain
- Variables:
id (int) β the id of the volume subdomain
borders (list of float) β the borders of the volume subdomain
material (festim.Material) β the material of the volume subdomain
Examples
VolumeSubdomain1D(id=1, borders=[0, 1], material=my_mat)
- map_surface_to_volume_subdomains(ft: MeshTags, ct: MeshTags, facet_to_cell: AdjacencyList_int32, volume_subdomains: list[VolumeSubdomain], surface_subdomains: list[SurfaceSubdomain], comm=None) dict[SurfaceSubdomain, VolumeSubdomain][source]#
Maps surface subdomains to volume subdomains based on the facet and cell meshtags and the facet to cell connectivity.
- Raises:
AssertionError β if a surface subdomain is connected to multiple volume subdomains
- Parameters:
ft β the facet meshtags of the parent mesh
ct β the cell meshtags of the parent mesh
facet_to_cell β the facet to cell connectivity of the parent mesh
volume_subdomains β the list of volume subdomains
surface_subdomains β the list of surface subdomains
comm β MPI communicator (required for parallel runs)
- Returns:
- a dictionary mapping surface subdomains
to volume subdomains
- Return type:
dict[SurfaceSubdomain, VolumeSubdomain]
- class AdvectionTerm(velocity: Function, subdomain: VolumeSubdomain, species: Species)[source]#
Bases:
objectAdvection term class.
- Parameters:
velocity β the velocity field or function
subdomain β the volume subdomain where the velocity is to be applied
species β the species to which the velocity field is acting on
- Variables:
velocity (dolfinx.fem.function.Function) β the velocity field or function
subdomain (festim.subdomain.volume_subdomain.VolumeSubdomain) β the volume subdomain where the velocity is to be applied
species (festim.species.Species) β the species to which the velocity field is acting on
- class VelocityField(input_value)[source]#
Bases:
ValueA class to handle input values of velocity fields from users and convert them to a relevent fenics object.
- Parameters:
input_value β The value of the user input
- Variables:
input_value (dolfinx.fem.function.Function | collections.abc.Callable) β The value of the user input
fenics_interpolation_expression (dolfinx.fem.function.Expression) β The expression of the user input that is used to update the fenics_object
fenics_object (dolfinx.fem.function.Function) β The value of the user input in fenics format
explicit_time_dependent (bool) β True if the user input value is explicitly time dependent
temperature_dependent (bool) β True if the user input value is temperature dependent
vector_function_space (dolfinx.fem.function.FunctionSpace) β the vector function space of the fenics object
- class CoupledTransientHeatTransferHydrogenTransport(heat_problem: HeatTransferProblem, hydrogen_problem: HydrogenTransportProblem)[source]#
Bases:
objectCoupled heat transfer and hydrogen transport transient problem.
- Parameters:
heat_problem β the heat transfer problem
hydrogen_problem β the hydrogen transport problem
- Variables:
heat_problem (festim.heat_transfer_problem.HeatTransferProblem) β the heat transfer problem
hydrogen_problem (festim.hydrogen_transport_problem.HydrogenTransportProblem) β the hydrogen transport problem
non_matching_meshes (bool) β True if the meshes in the heat_problem and hydrogen_problem are not matching
Examples
import festim as F my_heat_transfer_model = F.HeatTransferProblem(...) my_h_transport_model = F.HydrogenTransportProblem(...) coupled_problem = F.CoupledTransientHeatTransferHydrogenTransport( heat_problem=my_heat_transfer_model, hydrogen_problem=my_h_transport_model, )
- class HeatTransferProblem(mesh=None, subdomains=None, initial_condition=None, boundary_conditions=None, sources=None, exports=None, settings=None)[source]#
Bases:
ProblemBase- create_dirichletbc_form(bc)[source]#
Creates a dirichlet boundary condition form.
- Parameters:
bc (festim.FixedTemperatureBC) β the boundary condition
- Returns:
- A representation of
the boundary condition for modifying linear systems.
- Return type:
dolfinx.fem.bcs.DirichletBC
- create_initial_conditions()[source]#
For each initial condition, create the value_fenics and assign it to the previous solution of the conditionβs species.
- define_function_space()[source]#
Creates the function space of the model, creates a mixed element if model is multispecies.
Creates the main solution and previous solution function u and u_n. Create global DG function spaces of degree 0 and 1 for the global diffusion coefficient
- class Value(input_value)[source]#
Bases:
objectA class to handle input values from users and convert them to a relevent fenics object.
- Parameters:
input_value β The value of the user input
- Variables:
input_value (float | int | dolfinx.fem.function.Constant | numpy.ndarray | dolfinx.fem.function.Expression | ufl.core.expr.Expr | dolfinx.fem.function.Function) β The value of the user input
fenics_interpolation_expression (dolfinx.fem.function.Expression) β The expression of the user input that is used to update the fenics_object
fenics_object (dolfinx.fem.function.Function | dolfinx.fem.function.Constant | ufl.core.expr.Expr) β The value of the user input in fenics format
explicit_time_dependent (bool) β True if the user input value is explicitly time dependent
temperature_dependent (bool) β True if the user input value is temperature dependent
- convert_input_value(function_space: FunctionSpace | None = None, t: Constant | None = None, temperature: Function | Constant | Expr | None = None, up_to_ufl_expr: bool | None = False)[source]#
Converts a user given value to a relevent fenics object depending on the type of the value provided.
- Parameters:
function_space β the function space of the fenics object, optional
t β the time, optional
temperature β the temperature, optional
up_to_ufl_expr β if True, the value is only mapped to a function if the input is callable, not interpolated or converted to a function, optional
- property explicit_time_dependent: bool#
Returns true if the value given is time dependent.
- property temperature_dependent: bool#
Returns true if the value given is temperature dependent.
- as_fenics_constant(value: float | int | Constant, mesh: Mesh) Constant[source]#
Converts a value to a dolfinx.Constant.
- Parameters:
value β the value to convert
mesh β the mesh of the domiain
- Returns:
The converted value
- Raises:
TypeError β if the value is not a float, an int or a dolfinx.Constant
- as_fenics_interp_expr_and_function(value: Callable, function_space: FunctionSpace, t: Constant | None = None, temperature: Function | Constant | Expr | None = None) tuple[Expression, Function][source]#
Takes a user given callable function, maps the function to the mesh, time or temperature within festim as needed. Then creates the fenics interpolation expression and function objects.
- Parameters:
value β the callable to convert
function_space β The function space to interpolate function over
t β the time, optional
temperature β the temperature, optional
- Returns:
fenics interpolation expression, fenics function
- as_mapped_function(value: Callable, function_space: FunctionSpace | None = None, t: Constant | None = None, temperature: Function | Constant | Expr | None = None) Expr[source]#
Maps a user given callable function to the mesh, time or temperature within festim as needed.
- Parameters:
value β the callable to convert
function_space β the function space of the domain, optional
t β the time, optional
temperature β the temperature, optional
- Returns:
The mapped function
- is_it_time_to_export(times: list | None, current_time: float, atol=0, rtol=1e-05) bool[source]#
Checks if the exported field should be written to a file or not based on the current time and the times in export.times
After a successful match, the corresponding time is removed from the list to prevent multiple exports for the same target time.
- Parameters:
current_time β the current simulation time
atol β absolute tolerance for time comparison
rtol β relative tolerance for time comparison
times β the times at which the field should be exported, if None, returns True
- Returns:
True if the exported field should be written to a file, else False
- Return type:
bool
- nmm_interpolate(f_out: Function, f_in: Function, cells: MeshTags | None = None, padding: float | None = 1e-11)[source]#
Non Matching Mesh Interpolate: interpolate one function (f_in) from one mesh into another function (f_out) with a mismatching mesh
- Parameters:
f_out β function to interpolate into
f_in β function to interpolate from
- class HydrogenTransportProblem(mesh: Mesh | None = None, subdomains: list[VolumeSubdomain | SurfaceSubdomain] | None = None, species: list[Species] | None = None, reactions: list[Reaction] | None = None, temperature: float | int | Constant | Function | Callable[[ndarray[Any, dtype[float64]]], ndarray[Any, dtype[float64]]] | Callable[[ndarray[Any, dtype[float64]], Constant], ndarray[Any, dtype[float64]]] | None = None, sources=None, initial_conditions=None, boundary_conditions=None, settings=None, exports=None, traps=None, advection_terms=None, petsc_options=None, element_immobile: str = 'CG')[source]#
Bases:
ProblemBaseHydrogen Transport Problem.
- Parameters:
mesh β The mesh
subdomains β list containing the subdomains
species β list containing the species
reactions β list containing the reactions
temperature β The temperature or a function describing the temperature as a model of either space or space and time. Unit (K)
sources β The hydrogen sources
initial_conditions β The initial conditions
boundary_conditions β The boundary conditions
exports (list of festim.Export) β the exports of the model
traps (list of F.Trap) β the traps of the model
advection_terms β the advection terms of the model
- Variables:
mesh (festim.mesh.mesh.Mesh) β The mesh
subdomains (list[festim.subdomain.volume_subdomain.VolumeSubdomain]) β The subdomains
species β The species
reactions β the reaction
temperature β The temperature in unit K
sources (list[festim.source.SourceBase]) β The hydrogen sources
initial_conditions β The initial conditions
boundary_conditions β list of Dirichlet boundary conditions
exports (list of festim.Export) β the export
traps (list of F.Trap) β the traps of the model
advection_terms β the advection terms of the model
dx (dolfinx.fem.dx) β the volume measure of the model
ds (dolfinx.fem.ds) β the surface measure of the model
function_space (dolfinx.fem.FunctionSpaceBase) β the function space of the model
facet_meshtags (dolfinx.mesh.MeshTags) β the facet meshtags of the model
volume_meshtags (dolfinx.mesh.MeshTags) β the volume meshtags of the model
formulation (ufl.form.Form) β the formulation of the model
solver (dolfinx.nls.newton.NewtonSolver) β the solver of the model
temperature_fenics (fem.Constant or fem.Function) β the temperature of the model as a fenics object (fem.Constant or fem.Function).
temperature_expr (fem.Expression) β the expression of the temperature that is used to update the temperature_fenics
temperature_time_dependent (bool) β True if the temperature is time dependent
V_DG_0 (dolfinx.fem.FunctionSpaceBase) β A DG function space of degree 0 over domain
V_DG_1 (dolfinx.fem.FunctionSpaceBase) β A DG function space of degree 1 over domain
volume_subdomains (list of festim.VolumeSubdomain) β the volume subdomains of the model
surface_subdomains (list of festim.SurfaceSubdomain) β the surface subdomains of the model
Examples
Can be used as either
import festim as F my_model = F.HydrogenTransportProblem() my_model.mesh = F.Mesh(...) my_model.subdomains = [F.Subdomain(...)] my_model.species = [F.Species(name="H"), F.Species(name="Trap")] my_model.temperature = 500 my_model.sources = [F.ParticleSource(...)] my_model.boundary_conditions = [F.BoundaryCondition(...)] my_model.initialise()
or
my_model = F.HydrogenTransportProblem( mesh=F.Mesh(...), subdomains=[F.Subdomain(...)], species=[F.Species(name="H"), F.Species(name="Trap")], ) my_model.initialise()
- assign_functions_to_species()[source]#
Creates the solution, prev solution, test function and post-processing solution for each species, as well as a collapsed function space for each species.
- convert_advection_term_to_fenics_objects()[source]#
For each advection term convert the input value.
- create_dirichletbc_form(bc)[source]#
Creates a dirichlet boundary condition form.
- Parameters:
bc (festim.DirichletBC) β the boundary condition
- Returns:
- A representation of
the boundary condition for modifying linear systems.
- Return type:
dolfinx.fem.bcs.DirichletBC
- create_initial_conditions()[source]#
For each initial condition, create the value_fenics and assign it to the previous solution of the conditionβs species.
- create_species_from_traps()[source]#
Generate a species and reaction per trap defined in self.traps.
- define_D_global(species)[source]#
Defines the global diffusion coefficient for a given species.
- Parameters:
species (F.Species) β the species
- Returns:
- the global diffusion
coefficient and the expression of the global diffusion coefficient for a given species
- Return type:
dolfinx.fem.Function, dolfinx.fem.Expression
- define_function_spaces(element_degree: int = 1)[source]#
Creates the function space of the modelw with a mixed element. Creates the main solution and previous solution function u and u_n. Create global DG function spaces of degree 0 and 1 for the global diffusion coefficient.
- Parameters:
element_degree β Degree order for finite element. Defaults to 1.
- define_temperature()[source]#
Sets the value of temperature_fenics_value.
The type depends on self.temperature. If self.temperature is a function on t only, create a fem.Constant. Else, create an dolfinx.fem.Expression (stored in self.temperature_expr) to be updated, a dolfinx.fem.Function object is created from the Expression (stored in self.temperature_fenics_value). Raise a ValueError if temperature is None.
- class HydrogenTransportProblemDiscontinuous(mesh=None, subdomains=None, species=None, reactions=None, temperature=None, sources=None, initial_conditions=None, boundary_conditions=None, settings=None, exports=None, traps=None, interfaces: list[Interface] | None = None, petsc_options: dict | None = None)[source]#
Bases:
HydrogenTransportProblem- convert_advection_term_to_fenics_objects()[source]#
For each advection term convert the input value.
- create_dirichletbc_form(bc: FixedConcentrationBC)[source]#
Creates the
value_fenicsattribute for a givenfestim.FixedConcentrationBCand returns the appropriatedolfinx.fem.DirichletBCobject.- Parameters:
bc (festim.FixedConcentrationBC) β the dirichlet BC
- Returns:
- the appropriate dolfinx representation
generated from
dolfinx.fem.dirichletbc()
- Return type:
dolfinx.fem.DirichletBC
- create_formulation()[source]#
Takes all the formulations for each subdomain and adds the interface conditions.
Finally compute the jacobian matrix and store it in the
Jattribute, adds theentity_mapsto the forms and store them in theformsattribute
- create_initial_conditions()[source]#
For each intial condition, create the value_fenics and assign it to the previous solution of the conditionβs species.
- create_subdomain_formulation(subdomain: VolumeSubdomain)[source]#
Creates the variational formulation for each subdomain and stores it in
subdomain.F- Parameters:
subdomain (F.VolumeSubdomain) β a subdomain of the geometry
- define_function_spaces(subdomain: VolumeSubdomain, element_degree=1)[source]#
Creates appropriate function space and functions for a given subdomain (submesh) based on the number of species existing in this subdomain. Then stores the functionspace, the current solution (
u) and the previous solution (u_n) functions. It also populates the correspondance dicts attributes of the species (eg.species.subdomain_to_solution,species.subdomain_to_test_function, etc) for easy access to the right subfunctions, sub-testfunctions etc.- Parameters:
subdomain (F.VolumeSubdomain) β a subdomain of the geometry
element_degree (int, optional) β Degree order for finite element. Defaults to 1.
- define_temperature()[source]#
Sets the value of temperature_fenics_value.
The type depends on self.temperature. If self.temperature is a function on t only, create a fem.Constant. Else, create an dolfinx.fem.Expression (stored in self.temperature_expr) to be updated, a dolfinx.fem.Function object is created from the Expression (stored in self.temperature_fenics_value). Raise a ValueError if temperature is None.
- class InitialConcentration(value, volume, species: Species)[source]#
Bases:
InitialConditionBaseInitial concentration class.
- Parameters:
value β the value of the initial concentration of a given species.
species β the species to which the condition is applied
volume β the volume subdomain where the initial condition is applied
- Variables:
value (float | int | dolfinx.fem.function.Constant | numpy.ndarray | dolfinx.fem.function.Expression | ufl.core.expr.Expr | dolfinx.fem.function.Function) β the value of the initial concentration of a given species.
species (festim.species.Species) β the species to which the condition is applied
volume (festim.subdomain.volume_subdomain.VolumeSubdomain) β the volume subdomain where the initial condition is applied
expr_fenics (collections.abc.Callable | dolfinx.fem.function.Expression) β the value of the initial condition in fenics expr format
Examples
InitialConcentration(value=1, species=my_species, volume=my_vol) InitialConcentration( value=lambda x: 1 + x[0], species=my_species, volume=my_vol ) InitialConcentration( value=lambda T: 1 + T, species=my_species, volume=my_vol ) InitialConcentration( value=lambda x, T: 1 + x[0] + T, species=my_species, volume=my_vol )
- create_expr_fenics(mesh: Mesh, temperature: Function | Constant, function_space: functionspace)[source]#
Creates the expr_fenics of the initial condition.
If the value is a float or int, a function is created with an array with the shape of the mesh and all set to the value. Otherwise, it is converted to a fem.Expression.
- Parameters:
mesh β the mesh
temperature β the temperature
function_space β the function space of the species
- class InitialConditionBase(value: float | int | Constant | ndarray | Expression | Expr | Function, volume: VolumeSubdomain)[source]#
Bases:
objectBase initial condition class.
- Parameters:
value β the value of the initial condition.
volume β the volume subdomain where the initial condition is applied
- Variables:
value (float | int | dolfinx.fem.function.Constant | numpy.ndarray | dolfinx.fem.function.Expression | ufl.core.expr.Expr | dolfinx.fem.function.Function) β the value of the initial condition.
volume (festim.subdomain.volume_subdomain.VolumeSubdomain) β the volume subdomain where the initial condition is applied
- class InitialTemperature(value, volume)[source]#
Bases:
InitialConditionBaseInitial temperature class.
- Parameters:
value β the value of the initial temperature
volume β the volume subdomain where the initial condition is applied
- Variables:
value (float | int | dolfinx.fem.function.Constant | numpy.ndarray | dolfinx.fem.function.Expression | ufl.core.expr.Expr | dolfinx.fem.function.Function) β the value of the initial temperature
volume (festim.subdomain.volume_subdomain.VolumeSubdomain) β the volume subdomain where the initial condition is applied
expr_fenics β the value of the initial condition in fenics expr format
Examples
InitialTemperature(value=1, volume=my_vol) InitialTemperature(value=lambda x: 1 + x[0], volume=my_vol) InitialTemperature(value=lambda x, t: 1 + x[0] + t, volume=my_vol)
- create_expr_fenics(mesh: Mesh, function_space: functionspace)[source]#
Creates the expr_fenics of the initial condition.
If the value is a float or int, a function is created with an array with the shape of the mesh and all set to the value. Otherwise, it is converted to a fem.Expression.
- Parameters:
mesh β the mesh
function_space β the function space of the species
- read_function_from_file(filename: str, name: str, timestamp: int | float, family='P', order: int = 1, mesh: Mesh | None = None) Function[source]#
Read a function from a file.
- note::
The function is read from a file using adios4dolfinx. For more information see the [adios4dolfinx documentation](https://jsdokken.com/adios4dolfinx/README.html).
- Parameters:
filename β the filename
name β the name of the function
timestamp β the timestamp of the function
family β the family of the function space
order β the order of the function space
mesh β Mesh to create input space on.
- Returns:
the function
- class Material(D_0: float | int | Function | dict[float, int] | None = None, E_D: float | int | Function | dict[float, int] | None = None, K_S_0: float | int | dict[float, int] | None = None, E_K_S: float | int | dict[float, int] | None = None, thermal_conductivity: float | None = None, density: float | None = None, heat_capacity: float | None = None, name: str | None = None, solubility_law: SolubilityLaw | str = SolubilityLaw.NONE, D: Function | None = None)[source]#
Bases:
objectMaterial class.
- Parameters:
D_0 β the pre-exponential factor of the diffusion coefficient (m2/s)
E_D β the activation energy of the diffusion coeficient (eV)
K_S_0 β the pre-exponential factor of the solubility coefficient (H/m3/Pa0.5)
E_K_S β the activation energy of the solubility coeficient (eV)
name β the name of the material
thermal_conductivity β the thermal conductivity of the material (W/m/K)
density β the density of the material (kg/m3)
heat_capacity β the heat capacity of the material (J/kg/K)
solubility_law β the solubility law of the material (SIEVERT, HENRY or NONE). For single material problems one can use NONE. This does not work for multi-material problems
D β the diffusion coefficient of the material (m2/s)
- Variables:
D_0 β the pre-exponential factor of the diffusion coefficient (m2/s)
E_D β the activation energy of the diffusion coeficient (eV)
K_S_0 β the pre-exponential factor of the solubility coefficient (H/m3/Pa0.5)
E_K_S β the activation energy of the solubility coeficient (eV)
name β the name of the material
thermal_conductivity β the thermal conductivity of the material (W/m/K)
density β the density of the material (kg/m3)
heat_capacity β the heat capacity of the material (J/kg/K)
solubility_law β the solubility law of the material (SIEVERT, HENRY or NONE). For single material problems one can use NONE. This does not work for multi-material problems
Examples
# if only one species: Material(D_0=1.9e-7, E_D=0.2, name="my_mat") # if several species: Material( D_0={"Species_1": 1.9e-7, "Species_2": 2.0e-7}, E_D={"Species_1": 0.2, "Species_2": 0.3}, name="my_mat" )
- get_D_0(species=None)[source]#
Returns the pre-exponential factor of the diffusion coefficient.
- Parameters:
species (festim.Species or str, optional) β the species we want the pre-exponential factor of the diffusion coefficient of. Only needed if D_0 is a dict.
- Returns:
the pre-exponential factor of the diffusion coefficient
- Return type:
float
- get_E_D(species=None)[source]#
Returns the activation energy of the diffusion coefficient.
- Parameters:
species (festim.Species or str, optional) β the species we want the activation energy of the diffusion coefficient of. Only needed if E_D is a dict.
- Returns:
the activation energy of the diffusion coefficient
- Return type:
float
- get_E_K_S(species=None) float[source]#
Returns the activation energy of the solubility coefficient.
- Parameters:
species β the species we want the activation energy of the solubility coefficient of. Only needed if E_K_S is a dict.
- Returns:
the activation energy of the solubility coefficient
- get_K_S_0(species=None) float[source]#
Returns the pre-exponential factor of the solubility coefficient.
- Parameters:
species β the species we want the pre-exponential factor of the solubility coefficient of. Only needed if K_S_0 is a dict.
- Returns:
the pre-exponential factor of the solubility coefficient
- get_diffusion_coefficient(mesh=None, temperature=None, species=None)[source]#
Defines the diffusion coefficient.
- Parameters:
mesh (dolfinx.mesh.Mesh) β the domain mesh
temperature (dolfinx.fem.Constant) β the temperature
species (festim.Species, optional) β the species we want the diffusion coefficient of. Only needed if D_0 and E_D are dicts.
- Returns:
the diffusion coefficient
- Return type:
ufl.algebra.Product
- get_solubility_coefficient(mesh, temperature, species=None)[source]#
Defines the solubility coefficient.
- Parameters:
mesh (dolfinx.mesh.Mesh) β the domain mesh
temperature (dolfinx.fem.Constant) β the temperature
species (festim.Species, optional) β the species we want the solubility coefficient of. Only needed if K_S_0 and E_K_S are dicts.
- Returns:
the solubility coefficient
- Return type:
ufl.algebra.Product
- class ProblemBase(mesh: Mesh = None, sources=None, exports=None, subdomains=None, boundary_conditions=None, settings=None, petsc_options=None)[source]#
Bases:
objectBase class for
HeatTransferProblemandHydrogenTransportProblem.- Variables:
show_progress_bar (bool) β If True a progress bar is displayed during the simulation
progress_bar (None | tqdm.asyncio.tqdm_asyncio) β the progress bar
- define_meshtags_and_measures()[source]#
Defines the facet and volume meshtags of the model which are used to define the measures fo the model, dx and ds.
- class Reaction(reactant: Species | ImplicitSpecies | list[Species | ImplicitSpecies], k_0: float, E_k: float, volume: VolumeSubdomain1D, product: Species | list[Species] | None = [], p_0: float | None = None, E_p: float | None = None)[source]#
Bases:
objectA reaction between two species, with a forward and backward rate.
- Parameters:
(Union[F.Species (reactant)
F.ImplicitSpecies]
List[Union[F.Species
:param : :param F.ImplicitSpecies]]): The reactant. :param product: The product. :type product: Optional[Union[F.Species, List[F.Species]]] :param k_0: The forward rate constant pre-exponential factor. :type k_0: float :param E_k: The forward rate constant activation energy. :type E_k: float :param p_0: The backward rate constant pre-exponential factor. :type p_0: float :param E_p: The backward rate constant activation energy. :type E_p: float :param volume: The volume subdomain where the reaction :type volume: F.VolumeSubdomain1D :param takes place.:
- Variables:
List[Union[F.Species, (reactant (Union[F.Species, F.ImplicitSpecies],)
F.ImplicitSpecies]]) β The reactant.
product (Optional[Union[F.Species, List[F.Species]]]) β The product.
k_0 (float) β The forward rate constant pre-exponential factor.
E_k (float) β The forward rate constant activation energy.
p_0 (float) β The backward rate constant pre-exponential factor.
E_p (float) β The backward rate constant activation energy.
volume (F.VolumeSubdomain1D) β The volume subdomain where the reaction
place. (takes)
Examples
:: testsetup:: Reaction
from festim import Reaction, Species, ImplicitSpecies
:: testcode:: Reaction
# create a volume subdomain # create two species reactant = [F.Species(βAβ), F.Species(βBβ)]
# create a product species product = F.Species(βCβ)
# create a reaction between the two species reaction = Reaction(reactant, product, k_0=1.0, E_k=0.2, p_0=0.1, E_p=0.3) print(reaction) # A + B <β> C
# compute the reaction term at a given temperature temperature = 300.0 reaction_term = reaction.reaction_term(temperature)
- reaction_term(temperature, reactant_concentrations: list | None = None, product_concentrations: list | None = None) Expr[source]#
Compute the reaction term at a given temperature.
- Parameters:
temperature β The temperature at which the reaction term is computed.
reactant_concentrations β The concentrations of the reactants. Must be the same length as the reactants. If None, the
concentrationattribute of each reactant is used. If an element is None, theconcentrationattribute of the reactant is used.product_concentrations β The concentrations of the products. Must be the same length as the products. If None, the
concentrationattribute of each product is used. If an element is None, theconcentrationattribute of the product is used.
- Returns:
The reaction term to be used in a formulation.
- class Settings(atol, rtol, max_iterations=30, transient=True, final_time=None, element_degree=1, stepsize=None, convergence_criterion: Literal['residual', 'incremental'] = 'residual')[source]#
Bases:
objectSettings for a festim simulation.
- Parameters:
atol (float or callable) β Absolute tolerance for the solver.
rtol (float or callable) β Relative tolerance for the solver.
max_iterations (int, optional) β Maximum number of iterations for the solver. Defaults to 30.
transient (bool, optional) β Whether the simulation is transient or not.
final_time (float, optional) β Final time for a transient simulation. Defaults to None
element_degree (int, optional) β Degree order for finite element. Defaults to 1.
stepsize (festim.Stepsize, optional) β stepsize for a transient simulation. Defaults to None
convergence_criterion β resiudal or incremental (for Newton solver)
- Variables:
atol (float or callable) β Absolute tolerance for the solver.
rtol (float or callable) β Relative tolerance for the solver.
max_iterations (int) β Maximum number of iterations for the solver.
transient (bool) β Whether the simulation is transient or not.
final_time (float) β Final time for a transient simulation.
element_degree (int) β Degree order for finite element.
stepsize (festim.Stepsize) β stepsize for a transient simulation.
convergence_criterion β resiudal or incremental (for Newton solver)
- class HeatSource(value, volume)[source]#
Bases:
SourceBaseHeat source class.
- Parameters:
value β the value of the source
volume β the volume subdomains where the source is applied
- Variables:
value (float | int | dolfinx.fem.function.Constant | numpy.ndarray | dolfinx.fem.function.Expression | ufl.core.expr.Expr | dolfinx.fem.function.Function) β the value of the source
volume (festim.subdomain.volume_subdomain.VolumeSubdomain) β the volume subdomains where the source is applied
Examples
from festim import HeatSource HeatSource(volume=my_vol, value=1) HeatSource(volume=my_vol, value=lambda x: 1 + x[0]) HeatSource(volume=my_vol, value=lambda t: 1 + t) HeatSource(volume=my_vol, value=lambda x, t: 1 + x[0] + t)
- class ParticleSource(value, volume, species: Species)[source]#
Bases:
SourceBaseParticle source class.
- Parameters:
value β the value of the source
volume β the volume subdomains where the source is applied
species β the species to which the source is applied
- Variables:
value (float | int | dolfinx.fem.function.Constant | numpy.ndarray | dolfinx.fem.function.Expression | ufl.core.expr.Expr | dolfinx.fem.function.Function) β the value of the source
volume (festim.subdomain.volume_subdomain.VolumeSubdomain) β the volume subdomains where the source is applied
species (festim.species.Species) β the species to which the source is applied
Examples
from festim import ParticleSource ParticleSource(volume=my_vol, value=1, species="H") ParticleSource(volume=my_vol, value=lambda x: 1 + x[0], species="H") ParticleSource(volume=my_vol, value=lambda t: 1 + t, species="H") ParticleSource(volume=my_vol, value=lambda T: 1 + T, species="H") ParticleSource(volume=my_vol, value=lambda x, t: 1 + x[0] + t, species="H")
- class SourceBase(value: float | int | Constant | ndarray | Expression | Expr | Function | Value, volume: VolumeSubdomain)[source]#
Bases:
objectSource base class.
- Parameters:
value β the value of the source
volume β the volume subdomains where the source is applied
- Variables:
value (float | int | dolfinx.fem.function.Constant | numpy.ndarray | dolfinx.fem.function.Expression | ufl.core.expr.Expr | dolfinx.fem.function.Function) β the value of the source
volume (festim.subdomain.volume_subdomain.VolumeSubdomain) β the volume subdomains where the source is applied
- class ImplicitSpecies(n: float | callable, others: list[Species] | None = None, name: str | None = None)[source]#
Bases:
objectImplicit species class for H transport simulation. c = n - others
- Parameters:
n β the total concentration of the species
others β the list of species from which the implicit species concentration is computed (c = n - others)
name β a name given to the species. Defaults to None.
- Variables:
n (float | callable) β the total concentration of the species
others (list[festim.species.Species] | None) β the list of species from which the implicit species concentration is computed (c = n - others)
name (str | None) β a name given to the species. Defaults to None.
concentration (ufl.form.Form) β the concentration of the species
value_fenics (dolfinx.fem.function.Constant | ufl.core.expr.Expr) β the total concentration as a fenics object
- create_value_fenics(mesh, t: Constant)[source]#
Creates the value of the density as a fenics object and sets it to self.value_fenics. If the value is a constant, it is converted to a fenics.Constant. If the value is a function of t, it is converted to a fenics.Constant. Otherwise, it is converted to a ufl Expression.
- Parameters:
mesh (dolfinx.mesh.Mesh) β the mesh
t (dolfinx.fem.Constant) β the time
- class Species(name: str | None = None, mobile: bool = True, subdomains: list[VolumeSubdomain] | VolumeSubdomain | None = None)[source]#
Bases:
objectHydrogen species class for H transport simulation.
- Parameters:
name β a name given to the species. Defaults to None.
mobile β whether the species is mobile or not. Defaults to True.
subdomain β the volume subdomain where the species is. Defaults to None.
- Variables:
name (str | None) β a name given to the species.
mobile (bool) β whether the species is mobile or not.
solution (dolfinx.fem.function.Function | None) β the solution for the current timestep
prev_solution (dolfinx.fem.function.Function | None) β the solution for the previous timestep
test_function (ufl.argument.Argument | None) β the testfunction associated with this species
sub_function β the sub function of the species in case of multiple species in the same function space
sub_function_space (dolfinx.fem.function.FunctionSpace | None) β the subspace of the function space
collapsed_function_space (dolfinx.fem.function.FunctionSpace | None) β the collapsed function space for a species in the function space. In case single species case, this is None.
map_sub_to_main_solution (list | None) β the mapping from the sub solution dofs to the main solution dofs
post_processing_solution (dolfinx.fem.function.Function | None) β the solution for post processing
concentration (dolfinx.fem.function.Function | None) β the concentration of the species
subdomains (list[festim.subdomain.volume_subdomain.VolumeSubdomain] | festim.subdomain.volume_subdomain.VolumeSubdomain | None) β the volume subdomains where the species is
subdomain_to_solution (dict) β a dictionary mapping subdomains to solutions
subdomain_to_prev_solution (dict) β a dictionary mapping subdomains to previous solutions
subdomain_to_test_function (dict) β a dictionary mapping subdomains to test functions
subdomain_to_post_processing_solution (dict) β a dictionary mapping subdomains to post processing solutions
subdomain_to_collapsed_function_space (dict) β a dictionary mapping subdomains to collapsed function spaces
subdomain_to_function_space (dict) β a dictionary mapping subdomains to function spaces
Examples
:: testsetup:: Species
from festim import Species
:: testcode:: Species
Species(name=βHβ) Species(name=βTrapβ, mobile=False)
- property legacy: bool#
Check if we are using FESTIM 1.0 implementation or FESTIM 2.0.
- find_species_from_name(name: str, species: list)[source]#
Returns the correct species object from a list of species based on a string.
- Parameters:
name (str) β the name of the species
species (list) β the list of species
- Returns:
the species object with the correct name
- Return type:
species (festim.Species)
- Raises:
ValueError β if the species name is not found in the list of species
- class Stepsize(initial_value, growth_factor=None, cutback_factor=None, target_nb_iterations=None, max_stepsize=None, milestones=None)[source]#
Bases:
objectA class for evaluating the stepsize of transient simulations.
- Parameters:
initial_value (float, int) β initial stepsize.
growth_factor (float, optional) β factor by which the stepsize is increased when adapting
cutback_factor (float, optional) β factor by which the stepsize is decreased when adapting
target_nb_iterations (int, optional) β number of Newton iterations over (resp. under) which the stepsize is increased (resp. decreased)
max_stepsize (float or callable, optional) β Maximum stepsize. If callable, has to be a function of t. Defaults to None.
milestones (list, optional) β list of times by which the simulation must pass. Defaults to an empty list.
- Variables:
initial_value (float, int) β initial stepsize.
growth_factor (float) β factor by which the stepsize is increased when adapting
cutback_factor (float) β factor by which the stepsize is decreased when adapting
target_nb_iterations (int) β number of Newton iterations over (resp. under) which the stepsize is increased (resp. decreased)
adaptive (bool) β True if the stepsize is adaptive, False otherwise.
max_stepsize (float, callable) β Maximum stepsize.
milestones (list) β list of times by which the simulation must pass.
- get_max_stepsize(t)[source]#
Returns the maximum stepsize at time t.
- Parameters:
t (float) β the current time
- Returns:
the maximum stepsize at time t
- Return type:
float or None
- class Trap(name: str, mobile_species, k_0, E_k, p_0, E_p, n, volume)[source]#
Bases:
SpeciesTrap species class for H transport simulation.
This class only works for 1 mobile species and 1 trapping level and is for convenience, for more details see notes.
- Parameters:
name (str, optional) β a name given to the trap. Defaults to None.
mobile_species (_Species) β the mobile species to be trapped
k_0 (float) β the trapping rate constant pre-exponential factor (m3 s-1)
E_k (float) β the trapping rate constant activation energy (eV)
p_0 (float) β the detrapping rate constant pre-exponential factor (s-1)
E_p (float) β the detrapping rate constant activation energy (eV)
volume (F.VolumeSubdomain1D) β The volume subdomain where the trap is.
- Variables:
name (str, optional) β a name given to the trap. Defaults to None.
mobile_species (_Species) β the mobile species to be trapped
k_0 (float) β the trapping rate constant pre-exponential factor (m3 s-1)
E_k (float) β the trapping rate constant activation energy (eV)
p_0 (float) β the detrapping rate constant pre-exponential factor (s-1)
E_p (float) β the detrapping rate constant activation energy (eV)
volume (F.VolumeSubdomain1D) β The volume subdomain where the trap is.
trapped_concentration (_Species) β The immobile trapped concentration
trap_reaction (_Reaction) β The reaction for trapping the mobile conc.
empty_trap_sites (F.ImplicitSpecies) β The implicit species for the
sites (empty trap)
Examples
trap = Trap(name="Trap", mobile_species=H, k_0=1.0, E_k=0.2, p_0=0.1, E_p=0.3, n=100, volume=my_vol) my_model = HydrogenTransportProblem() my_model.traps = [trap]
Notes
This convenience class replaces the need to specify an implicit species and the associated reaction, thus:
cm = _Species("mobile") my_trap = F.Trap( name="trapped", mobile_species=cm, k_0=1, E_k=1, p_0=1, E_p=1, n=1, volume=my_vol, ) my_model.species = [cm] my_model.traps = [my_trap]
is equivalent to:
cm = _Species("mobile") ct = _Species("trapped") trap_sites = F.ImplicitSpecies(n=1, others=[ct]) trap_reaction = _Reaction( reactant=[cm, trap_sites], product=ct, k_0=1, E_k=1, p_0=1, E_p=1, volume=my_vol, ) my_model.species = [cm, ct] my_model.reactions = [trap_reaction]