Models#
Models built on sumfem, to be summed and extended.
Accumulation, diffusion, advection and sources:
Accumulation,Diffusion,ConvectiveAdvectionandConservativeAdvection,SourceandPoisson, and OhmicConduction.Boundaries:
BoundaryFlux,Outflow, and constraints with Lagrange multipliers,BoundaryConstraintandDirichletMultiplier.Interfaces between subdomains:
InterfaceLagrangeMultiplier, a condition across an interface with a Lagrange multiplier for the flux, or penalized, by an exchange flux,InterfacePenalty, or by an energy,InterfacePenaltyEnergy.Reactions between species in volumes, on surfaces and across membranes between two volumes:
Reactionby mass action andRateReactionat any rate, withmass_action(),arrhenius()andbutler_volmer().Flow:
Darcythrough a porous medium, andStokesflow with the momentum termsConvection,DarcyDragandForchheimerDragand grad-div stabilization,GradDiv, summed intoNavierStokes,BrinkmanandBrinkmanForchheimer.Effective properties of porous media: the Bruggeman, Kozeny-Carman and Ergun relations.
Models of electrochemistry are in sumfem.electrochemistry.
Accumulation, diffusion, advection and sources#
- class sumfem.models.Accumulation(name, field, weight=1, markers=())[source]#
The term
(w * du/dt, v)for a fielduwith test functionv.- Parameters:
name (str) – Name of the model.
field (Field) – The field whose time derivative is added to its equation.
weight (ufl.core.expr.Expr | npt.ArrayLike) – Weight
w, such as a porosity or a heat capacity, one by default. Any model input is accepted, seeas_expr().markers (tuple[str, ...]) – Optional cell markers restricting the term to subdomains.
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.Diffusion(name, field, coefficient=None, markers=())[source]#
Diffusion
(k grad(u), grad(v)), the weak form of-div(k grad(u)).Subclasses name the coefficient and give it a unit, e.g.
Conduction.- Parameters:
name (str) – Name of the model.
field (Field) – The diffusing field
u.coefficient (ufl.core.expr.Expr | npt.ArrayLike | None) – The coefficient
k, a scalar or a matrix. Defaults to a scalar parameter"<name>.<coefficient name>".markers (tuple[str, ...]) – Cell markers of the region. Empty for the whole domain.
- coefficient_doc: ClassVar[str] = 'Diffusion coefficient'#
Description of the parameter created for the coefficient.
- viscous_flux(u, grad_u)[source]#
The viscous flux
F(u, grad_u) = k grad_uof-div(F) = f.The field and its gradient are separate arguments, the form of a general flux
F(u, grad(u)), so that other terms can evaluate it at other arguments, e.g. a boundary value in place ofu. This flux does not depend onu. It has the opposite sign of the physical flux,flux(), which is-Fat the field.
- flux()[source]#
The flux
-k grad(u).The physical flux of the field, down its gradient, as in Fick’s or Fourier’s law. It is minus the
viscous_flux()at the field, a function of other arguments too, which Nitsche’s method and DG need.- Return type:
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.Advection(name, field, velocity, markers=(), quantity=None)[source]#
Advection of a field by a velocity
The velocity is any expression, e.g. a field solved by a flow model or data transferred from another mesh. The advected quantity is the field, or an expression of it, e.g. an enthalpy of a temperature. The subclasses write the term in the convective form,
ConvectiveAdvection, or the conservative one,ConservativeAdvection.For a continuous field \(c\) and test function \(v\), integration by parts on each cell \(K\) relates the two forms,
(41)#\[\begin{aligned} -(c \mathbf{u}, \nabla v) &= (\mathbf{u} \cdot \nabla c, v) + \sum_K (c \nabla \cdot \mathbf{u}, v)_K - \sum_F ([\![\mathbf{u} \cdot \mathbf{n}]\!] c, v)_F - (\mathbf{u} \cdot \mathbf{n} c, v)_{\partial \Omega}, \end{aligned}\]with the jump \([\![\mathbf{u} \cdot \mathbf{n}]\!] = \mathbf{u}^+ \cdot \mathbf{n}^+ + \mathbf{u}^- \cdot \mathbf{n}^-\) of the normal velocity across the interior facets \(F\), and the outward normal \(\mathbf{n}\).
The term holds only the integrals over the cells. A field that is not continuous, e.g. with a discontinuous element or one mapped by a Piola map, needs a numerical flux on the interior facets as well, e.g. an upwind flux, added as a model of its own.
- Parameters:
name (str) – Name of the model.
field (Field) – The field
cwhose equation has the term.velocity (ufl.core.expr.Expr | npt.ArrayLike) – The velocity
u.markers (tuple[str, ...]) – Cell markers restricting the term. Empty for the whole domain.
quantity (ufl.core.expr.Expr | None) – The advected quantity, in place of
c. Defaults to the field.
- class sumfem.models.ConvectiveAdvection(name, field, velocity, markers=(), quantity=None)[source]#
Advection in convective form,
(grad(c) u, v).It has no boundary term. It misses the jumps of the normal velocity in (41), so it equals
ConservativeAdvection, up to the boundary term, only for a velocity that is divergence free in each cell with a continuous normal component, e.g. one in H(div).- Parameters:
name (str) – Name of the model.
field (Field) – The field
cwhose equation has the term.velocity (ufl.core.expr.Expr | npt.ArrayLike) – The velocity
u.markers (tuple[str, ...]) – Cell markers restricting the term. Empty for the whole domain.
quantity (ufl.core.expr.Expr | None) – The advected quantity, in place of
c. Defaults to the field.
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.ConservativeAdvection(name, field, velocity, markers=(), quantity=None)[source]#
Advection in conservative form,
-(c u, grad(v)).Its boundary term is the advective flux
(u . n c, v):Outflowon outlets, and the inflow on inlets. It holds the jumps of the normal velocity in (41), so it needs no facet term, and conserves the advected quantity for any velocity: withv = 1the interior terms cancel. Use it with a velocity whose normal component jumps across facets, e.g. the gradient of a Lagrange pressure, as inDarcyflow.- Parameters:
name (str) – Name of the model.
field (Field) – The field
cwhose equation has the term.velocity (ufl.core.expr.Expr | npt.ArrayLike) – The velocity
u.markers (tuple[str, ...]) – Cell markers restricting the term. Empty for the whole domain.
quantity (ufl.core.expr.Expr | None) – The advected quantity, in place of
c. Defaults to the field.
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.Source(name, field, source=None, markers=())[source]#
A source
fin the equation of a field,-(f, v).- Parameters:
name (str) – Name of the model.
field (Field) – The field whose equation has the source.
source (ufl.core.expr.Expr | npt.ArrayLike | None) – The source, of the field’s shape. Defaults to the parameter
"<name>.source".markers (tuple[str, ...]) – Cell markers of the region. Empty for the whole domain.
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.Poisson(name, field, source=None, coefficient=1.0, markers=())[source]#
Poisson’s equation
-div(k grad(u)) = f.The sum of a
Diffusionand aSource, both namedname, so that the source is the parameter"<name>.source"by default. In a sum with other models, the two are summands of their own.- Parameters:
name (str) – Name of the model.
field (Field) – The unknown
u, of any shape.source (ufl.core.expr.Expr | npt.ArrayLike | None) – The right-hand side
f, of the field’s shape. Defaults to the parameter"<name>.source".coefficient (ufl.core.expr.Expr | npt.ArrayLike) – The coefficient
k, one by default.markers (tuple[str, ...]) – Cell markers of the region. Empty for the whole domain.
- viscous_flux(u, grad_u)[source]#
The viscous flux
k grad_uof the diffusion, seeDiffusion.viscous_flux(), e.g. for Nitsche’s method.
- flux()[source]#
The flux
-k grad(u)of the diffusion, minus itsviscous_flux()at the field, seeDiffusion.flux().- Return type:
- class sumfem.models.Conduction(name, potential, conductivity=None, markers=())[source]#
Ohmic conduction
(sigma grad(phi), grad(v)).Used for the solid phase of a porous electrode, with an effective conductivity such as
bruggeman()’s, or for an electrolyte of uniform composition.- Parameters:
name (str) – Name of the model.
potential (Field) – The potential
phi.conductivity (ufl.core.expr.Expr | npt.ArrayLike | None) – The conductivity
sigma. Defaults to the parameter"<name>.conductivity"in S/m.markers (tuple[str, ...]) – Cell markers of the conducting region. Empty for the whole domain.
- coefficient_name: ClassVar[str] = 'conductivity'#
Name of the parameter created for the coefficient.
- coefficient_unit: ClassVar[Unit | None] = siemens/meter#
Unit of the parameter created for the coefficient.
Boundaries#
- class sumfem.models.BoundaryFlux(name, field, inflow, markers)[source]#
An inflow
qinto the domain through marked facets,-(q, v) ds.Applied currents, the proton flux through a membrane and a prescribed inflow all take this form.
The inflow is what enters per unit area of the boundary, of the field’s shape, and is used as given: the model takes no normal component. For a scalar field with a flux vector
j, the inflow isq = -j . n, e.g.-ufl.dot(j, ufl.FacetNormal(domain)). For a vector field, it is a vector, e.g. a traction, tangential components included.Outflow, by contrast, is given a velocity and takes its normal component itself.- Parameters:
name (str) – Name of the model.
field (Field) – The field whose equation receives the inflow.
inflow (ufl.core.expr.Expr | npt.ArrayLike) – The inflow
q, per unit area, of the field’s shape.
- Raises:
ValueError – If the inflow has another shape than the field, e.g. a flux vector for a scalar field.
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.Outflow(name, field, velocity, markers)[source]#
Advection of a field out of the domain,
(u . n c, w) ds.- Parameters:
name (str) – Name of the model.
field (Field) – The advected field
c.velocity (ufl.core.expr.Expr) – The velocity
u.
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.BoundaryConstraint(name, field, multiplier, constraint, markers=())[source]#
A constraint
c(u) = 0on marked facets, with a Lagrange multiplier.The constraint is imposed at the stationary point of the Lagrangian
L(u, lambda) = (lambda, c(u)) ds, so the model adds its variations:(lambda, c'(u)[v]) ds + (c(u), mu) ds
with
vthe test function of the fieldu,muthat of the multiplierlambdaandc'(u)[v]the derivative of the constraint in the directionv. The multiplier has the constraint’s shape, e.g. a scalar for the normal component of a velocity,c(u) = u . n - g. It usually lives on a submesh of the facets, seeDiscretizationfor the entity maps between meshes.DirichletMultiplieris the constraintu - g.- Parameters:
name (str) – Name of the model.
field (Field) – The constrained field
u.multiplier (Field) – The multiplier
lambda, of the constraint’s shape.constraint (ufl.core.expr.Expr | None) – The constraint
c(u), an expression of the field. Subclasses may giveNoneand overrideconstraint().markers (tuple[str, ...]) – Facet markers of the constrained boundary, on the field’s domain.
- Raises:
ValueError – If the multiplier has another shape than the constraint.
Example
No flow through a wall,
u . n = 0, for a velocityu:n = ufl.FacetNormal(domain) wall = BoundaryConstraint("wall", u, p_wall, ufl.dot(u, n), ("Wall",))
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.DirichletMultiplier(name, field, multiplier, value=None, markers=())[source]#
A Dirichlet condition
u = gimposed with a Lagrange multiplier.The
BoundaryConstraintc(u) = u - g, which adds(lambda, v) + (u - g, mu)on the marked facets. Integrating by parts identifies the multiplier as the normal flux-grad(u) . nof a diffusion equation, as in Babuška (1973) and Gunzburger and Hou (1992).- Parameters:
name (str) – Name of the model.
field (Field) – The constrained field
u.multiplier (Field) – The multiplier
lambda, of the field’s shape.value (ufl.core.expr.Expr | npt.ArrayLike | None) – The prescribed value
g. Defaults to the parameter"<name>.value".markers (tuple[str, ...]) – Facet markers of the constrained boundary, on the field’s domain.
- Raises:
ValueError – If the multiplier has another shape than the field.
Interfaces#
- class sumfem.models.InterfaceLagrangeMultiplier(name, first, second, first_value, second_value, multiplier, measure)[source]#
A condition
a = bacross an interface, with a Lagrange multiplier.Two fields on the subdomains on either side of an interface are coupled by a condition between a quantity
aof the first side andbof the second, e.g. the continuity of the partial pressure of hydrogen across a material interface, which makes the concentrations jump. The multiplierlambdais the flux from the first subdomain to the second, so that the coupling conserves the transported quantity:(lambda, v_0) - (lambda, v_1) + (a - b, mu)
on the interface, with
v_0,v_1andmuthe test functions of the two fields and of the multiplier. Unlike aBoundaryConstraint, whose multiplier enters through the derivative of the constraint, the flux is the same on both sides for anyaandb, also nonlinear ones.Partitioned methods for interface problems use such a flux multiplier (Peterson, Bochev and Kuberry, 2019; Sockwell et al., 2020), as does a Lagrange multiplier method for fluid-structure interaction (de Castro, Lee and Wiecek, 2025). For a nonlinear condition, it corresponds to the augmented Lagrangian of large-strain contact in which the multiplier acts on both bodies instead of through the derivative of the gap (Poulios and Renard, 2015; Chouly, Hild and Renard, 2023, Section 11.2.2). The Jacobian is then not symmetric.
- Parameters:
name (str) – Name of the model.
first (Field) – The field of the subdomain on the
"+"side.second (Field) – The field of the subdomain on the
"-"side.first_value (ufl.core.expr.Expr | npt.ArrayLike) – The quantity
aof the first side, unrestricted, e.g.(c_0 / K_S)**2for Sieverts’ law.second_value (ufl.core.expr.Expr | npt.ArrayLike) – The quantity
bof the second side, unrestricted, e.g.c_1 / K_Hfor Henry’s law.multiplier (Field) – The multiplier
lambda, a scalar field on the interface, e.g. on aSubdomainof its facets.measure (ufl.Measure) – The interface measure, from
interface().
- Raises:
ValueError – If the quantities or the multiplier are not scalars.
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.InterfacePenalty(name, first, second, first_value, second_value, conductance, measure)[source]#
A condition
a = bacross an interface, by a penalty flux.The exchange flux
q = k (a+ - b-)leaves the first subdomain and enters the second:+(q, v_0)in the first field’s equation and-(q, v_1)in the second’s, so the exchange conserves the transported quantity exactly. A large conductancekdrivesa = b, with a jump of orderq / k. Witha = c_0 / K_0andb = c_1 / K_1it is the penalty coupling of FESTIM’s interfaces, the Robin-type condition of Dark et al., 2026, Section 5.2.2. Its Jacobian is not symmetric for a nonlinear condition;InterfacePenaltyEnergyis the symmetric penalty of an energy.- Parameters:
name (str) – Name of the model.
first (Field) – The field of the subdomain on the
"+"side.second (Field) – The field of the subdomain on the
"-"side.first_value (ufl.core.expr.Expr | npt.ArrayLike) – The quantity
aof the first side, unrestricted, e.g.c_0 / K_0.second_value (ufl.core.expr.Expr | npt.ArrayLike) – The quantity
bof the second side, unrestricted.conductance (ufl.core.expr.Expr | npt.ArrayLike) – The conductance
k.measure (ufl.Measure) – The interface measure, from
interface().
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.InterfacePenaltyEnergy(name, first, second, first_value, second_value, penalty, measure)[source]#
A condition
a = bacross an interface, by the penalty energyalpha / 2 int (a+ - b-)^2 ds.Added to the energy of the subdomains, its variation,
to_residual(), penalizes the condition:alpha (a - b) (da/dc_0 v_0 - db/dc_1 v_1)on the interface, the energy-based coupling of Dark et al., 2026, Section 5.2.1. The Jacobian is symmetric, as the second variation of an energy. The flux that leaves the first subdomain,alpha (a - b) da/dc_0, and the one that enters the second,alpha (a - b) db/dc_1, differ unless the two derivatives agree, so the coupling conserves the transported quantity only up to an error that vanishes withalphagrowing; for exact conservation useInterfacePenalty. For Sieverts’ law withb = (c_1 / K)^(1/2),db/dc_1grows without bound wherec_1vanishes.- Parameters:
name (str) – Name of the model.
first (Field) – The field of the subdomain on the
"+"side.second (Field) – The field of the subdomain on the
"-"side.first_value (ufl.core.expr.Expr | npt.ArrayLike) – The quantity
aof the first side, unrestricted, e.g.c_0.second_value (ufl.core.expr.Expr | npt.ArrayLike) – The quantity
bof the second side, unrestricted, e.g.K_0 (c_1 / K_1)^n.penalty (ufl.core.expr.Expr | npt.ArrayLike) – The penalty
alpha.measure (ufl.Measure) – The interface measure, from
interface().
Flow#
- class sumfem.models.Darcy(name, pressure, permeability=None, viscosity=None, markers=())[source]#
Darcy flow through a porous medium,
(K / mu grad(p), grad(q)).The superficial velocity is
u = -K / mu grad(p). Prescribe inflow with aBoundaryFluxon the pressure, and the outlet pressure with a Dirichlet condition.- Parameters:
name (str) – Name of the model.
pressure (Field) – The pressure
p.permeability (ExpressionOrValue) – Permeability
K. Defaults to the parameter"<name>.permeability"in m^2.viscosity (ExpressionOrValue) – Dynamic viscosity
mu. Defaults to the parameter"<name>.viscosity"in Pa s.markers (tuple[str, ...]) – Cell markers of the porous medium. Empty for the whole domain.
- property superficial_velocity: Expr#
The superficial velocity
-K / mu grad(p), the volume flux per unit area of the medium, not the velocity of the fluid in its pores.
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.Stokes(name, velocity, pressure, viscosity=None, markers=())[source]#
Steady incompressible Stokes flow.
(2 mu epsilon(u), epsilon(w)) - (p, div(w)) - (div(u), q)with the symmetric gradient
epsilon(u) = (grad(u) + grad(u)^T) / 2, the velocityuand its test functionw, and the pressurepand its test functionq. The stress is2 mu epsilon(u) - p I, so the term holds for a viscosity that varies in space, e.g.mu / epswith a porosity field, and its natural boundary condition is a traction that vanishes. Add the other terms of the momentum equation as components, e.g.Convection.- Parameters:
- viscous_flux(u, grad_u)[source]#
The stress
2 mu epsilon(u) - p Iof the momentum equation.A function of
uandgrad_useparately, for Nitsche’s method, which evaluates it at the boundary.
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- class sumfem.models.Convection(name, velocity, density=None, markers=())[source]#
Convection of momentum,
(rho grad(u) u, w).- Parameters:
- class sumfem.models.DarcyDrag(name, velocity, viscosity=None, permeability=None, markers=())[source]#
Darcy’s drag of a porous medium,
(mu / K u, w).- Parameters:
name (str) – Name of the model.
velocity (Field) – The superficial velocity
u.viscosity (ExpressionOrValue) – Dynamic viscosity
mu. Defaults to the parameter"<name>.viscosity"in Pa s.permeability (ExpressionOrValue) – Permeability
K. Defaults to the parameter"<name>.permeability"in m^2.markers (tuple[str, ...]) – Cell markers of the porous medium. Empty for the whole domain.
- class sumfem.models.ForchheimerDrag(name, velocity, density=None, coefficient=None, markers=(), speed_floor=1e-12)[source]#
Forchheimer’s inertial drag of a porous medium,
(rho beta |u| u, w).The speed is regularized,
|u| = sqrt(u . u + s^2), so that the term is differentiable where the fluid rests.- Parameters:
name (str) – Name of the model.
velocity (Field) – The superficial velocity
u.density (ExpressionOrValue) – Density
rho. Defaults to the parameter"<name>.density"in kg/m^3.coefficient (ExpressionOrValue) – Inertial drag coefficient
beta, e.g. Ergun’s,ergun_coefficient(). Defaults to the parameter"<name>.forchheimer"in 1/m.markers (tuple[str, ...]) – Cell markers of the porous medium. Empty for the whole domain.
speed_floor (ufl.core.expr.Expr | float) – Regularization
sof the speed, in m/s, or the default of the parameter"<name>.speed_floor".
- class sumfem.models.GradDiv(name, velocity, weight=None, markers=())[source]#
Grad-div stabilization,
(gamma div(u), div(w)).The term vanishes for a velocity without divergence, so it leaves the exact solution unchanged, and penalizes the divergence of the discrete velocity: it improves the conservation of mass of Taylor-Hood elements, and the robustness of the velocity against the pressure. See John et al., 2017, Section 4.2.
- Parameters:
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
Steady incompressible flow with convection.
The sum of
Stokesflow,"<name>_stokes", andConvection,"<name>_convection".- Parameters:
name (str) – Name of the model.
velocity (Field) – The velocity
u.pressure (Field) – The pressure
p.viscosity (ExpressionOrValue) – Dynamic viscosity
mu. Defaults to the parameter"<name>.viscosity"in Pa s.density (ExpressionOrValue) – Density
rho. Defaults to the parameter"<name>.density"in kg/m^3.markers (tuple[str, ...]) – Cell markers of the flow region. Empty for the whole domain.
- class sumfem.models.Brinkman(name, velocity, pressure, porosity=None, permeability=None, viscosity=None, markers=())[source]#
Steady creeping flow through a porous medium.
The sum of
Stokesflow of the superficial velocityuwith the viscositymu / epsin the pores,"<name>_stokes", andDarcyDrag,"<name>_drag". The pressure is that of the fluid in the pores. Of the effective viscosities of the Brinkman term in the literature,mu,mu / epsand others, this is the one of volume averaging.- Parameters:
name (str) – Name of the model.
velocity (Field) – The superficial velocity
u.pressure (Field) – The pressure
p.porosity (ExpressionOrValue) – Porosity
eps. Defaults to the parameter"<name>.porosity".permeability (ExpressionOrValue) – Permeability
K. Defaults to the parameter"<name>.permeability"in m^2.viscosity (ExpressionOrValue) – Dynamic viscosity
mu. Defaults to the parameter"<name>.viscosity"in Pa s.markers (tuple[str, ...]) – Cell markers of the porous medium. Empty for the whole domain.
- class sumfem.models.BrinkmanForchheimer(name, velocity, pressure, porosity=None, permeability=None, forchheimer=None, viscosity=None, density=None, markers=(), speed_floor=1e-12)[source]#
Steady flow through a porous medium, with inertia.
The sum of
Brinkmanflow,Convectionin the pores with the densityrho / eps^2,"<name>_convection", andForchheimerDrag,"<name>_forchheimer". With the superficial velocity, this is the generalized model of flow through porous media of Hsu and Cheng, 1990 and Nithiarasu, Seetharamu and Sundararajan, 1997.- Parameters:
name (str) – Name of the model.
porosity (ExpressionOrValue) – See
Brinkman.permeability (ExpressionOrValue) – See
Brinkman.forchheimer (ExpressionOrValue) – Inertial drag coefficient
beta. Defaults to the parameter"<name>.forchheimer"in 1/m.viscosity (ExpressionOrValue) – See
Brinkman.density (ExpressionOrValue) – Density
rho. Defaults to the parameter"<name>.density"in kg/m^3.speed_floor (float) – Default of the regularization of
|u|, the parameter"<name>.speed_floor"in m/s.
Reactions#
- class sumfem.models.Reaction(name, reactants, products, forward_rate=None, backward_rate=0.0, measure=None)[source]#
A reaction
sum_i nu_i A_i <-> sum_j nu_j B_jby mass action.For example,
3 A + 4 B <-> 4 C, withreactants={A: 3, B: 4}andproducts={C: 4}. By the law of mass action, it runs forward more often the moreAandBthere are, at the ratek_f A^3 B^4, and backward at the ratek_b C^4. Its rate is the difference, negative where it runs backwards:R(A, B, C) = k_f A^3 B^4 - k_b C^4
with the forward and backward rate constants
k_fandk_b. In general, each reactant and each product is raised to its coefficient. The law holds for elementary reactions; for any other rate law, useRateReaction.The rate enters the equations of the species as in
RateReaction, and as it depends on all three, it couples them:Dt(A) + ... + 3 R(A, B, C) = 0 Dt(B) + ... + 4 R(A, B, C) = 0 Dt(C) + ... - 4 R(A, B, C) = 0
- Parameters:
name (str) – Name of the model.
reactants (Participants) – The coefficient
nu_iof each reactant, e.g.{A: 3, B: 4}.products (Participants) – The coefficient
nu_jof each product, e.g.{C: 4}.forward_rate (ufl.core.expr.Expr | npt.ArrayLike | None) – The rate constant
k_f. Defaults to the parameter"<name>.forward_rate".backward_rate (ufl.core.expr.Expr | npt.ArrayLike) – The rate constant
k_b, zero for an irreversible reaction. Defaults to zero.measure (ufl.Measure | None) – See
RateReaction.
Example
The reversible reaction above, with the forward rate constant a parameter
"r.forward_rate", set when it is discretized:A, B, C = (Field(name, domain, ("Lagrange", 1)) for name in "ABC") reaction = Reaction("r", {A: 3, B: 4}, {C: 4}, backward_rate=0.5)
- class sumfem.models.RateReaction(name, reactants, products, rate=None, measure=None)[source]#
A reaction
sum_i nu_i A_i -> sum_j nu_j B_jat a rateR.Each time the reaction happens, it consumes
nu_iof each reactantA_iand producesnu_jof each productB_j. The rateRis how many times it happens, per unit volume and time. So a reactant is consumed atnu_i Rand a product produced atnu_j R.For example,
3 A + 4 B -> 4 Cisreactants={A: 3, B: 4}andproducts={C: 4}, here at the rateR(A, B, C) = k A B / (K + A), one expression of the concentrations for the whole reaction. The same rate, times the coefficient of each species, enters the equations of the three species, whose other terms, e.g. diffusion, are left as...:Dt(A) + ... + 3 R(A, B, C) = 0 Dt(B) + ... + 4 R(A, B, C) = 0 Dt(C) + ... - 4 R(A, B, C) = 0
As the rate depends on the species, it couples their equations. The reaction adds their weak form,
3 (R, v_A) + 4 (R, v_B) - 4 (R, v_C), to the residual, withv_A,v_Bandv_Cthe test functions.The coefficients and the rate are independent here.
Reactiontakes the rate from the law of mass action instead.A negative rate runs the reaction backwards. A participant that is an expression rather than a field, e.g. the free sites of a trap, may enter the rate, but has no equation of its own.
The reaction is integrated over the domain of its species. If one of them lives on a
Subdomainof lower dimension, e.g. a surface, the reaction happens on that surface,Ris per unit area and time, and it is a flux for the species of the volume, e.g. the adsorption of a volume species onto a surface species.A reaction may also couple the species on the two sides of an interface between two subdomains of cells, e.g. a release from the ER into the cytosol across the ER membrane. Its measure is then the interface measure of
interface(),(first, second, marker), and each field is taken on its own side: those offirston"+", those ofsecondon"-", and the others, e.g. of the membrane itself, on"+".- Parameters:
name (str) – Name of the model.
reactants (Participants) – The coefficient
nu_iof each reactant, e.g.{A: 3, B: 4}.products (Participants) – The coefficient
nu_jof each product, e.g.{C: 4}.rate (ufl.core.expr.Expr | npt.ArrayLike | None) – The rate
R. Defaults to the parameter"<name>.rate".measure (ufl.Measure | None) – The measure to integrate over, e.g.
domain.dx("Electrode"),domain.ds("Surface")for a reaction of volume species at a surface, or an interface measure. Defaults to the whole domain of the participants. A measure of cells or facets gives the domain of the reaction, so its species may live on several subdomains that overlap there.
Example
An enzyme converts a substrate
Sinto a productPat the rateR = v_max S / (K_m + S)of Michaelis-Menten kinetics, soSgets+RandPgets-Rin its equation:S = Field("S", domain, ("Lagrange", 1)) P = Field("P", domain, ("Lagrange", 1)) v_max, K_m = 2.0, 0.5 enzyme = RateReaction("enzyme", {S: 1}, {P: 1}, rate=v_max * S / (K_m + S))
- residual()[source]#
Return this component’s contribution to the residual.
The form must be linear in test functions
field.vand contain no trial functions. A contribution that is zero, e.g. for some inputs, isufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.- Return type:
- sumfem.models.mass_action(rate, participants)[source]#
The rate of a reaction by the law of mass action,
k prod(c_i ** nu_i).By the law of mass action, the rate of an elementary reaction is proportional to the product of the concentrations of its participants, each to the power of its stoichiometric coefficient.
- sumfem.models.arrhenius(prefactor, activation_energy, temperature, boltzmann=None)[source]#
The rate constant by the Arrhenius law,
k_0 exp(-E / (k_B T)).The Arrhenius equation gives the dependence of a rate constant on the temperature, through the activation energy of the reaction (Arrhenius, 1889; on its origin and status, Logan, 1982).
- Parameters:
activation_energy (Expr | float) –
E, in the energy unit ofboltzmann.boltzmann (Expr | float | None) –
k_B. Defaults to the parameter ofboltzmann_constant()on the domain of the temperature, in J/K, so that units are checked, or to its SI value for a temperature without a domain, e.g. a number. A number is in J/K, or e.g. in eV/K forEin eV.
- Returns:
The rate constant
k_0 exp(-E / (k_B T)).- Return type:
- sumfem.models.butler_volmer(exchange_current, scaled_overpotential, anodic_transfer=0.5, cathodic_transfer=0.5)[source]#
Butler-Volmer’s current density
i0 (exp(alpha_a x) - exp(-alpha_c x)).The current density of an electrode reaction at the overpotential
eta, by the Butler-Volmer equation of Butler, 1924 and Erdey-Grúz and Volmer, 1930.- Parameters:
exchange_current (Expr) – Exchange current density
i0.scaled_overpotential (Expr) – The overpotential over the thermal voltage per electron,
x = n F eta / (R T).anodic_transfer (Expr | float) – Anodic transfer coefficient
alpha_a.cathodic_transfer (Expr | float) – Cathodic transfer coefficient
alpha_c.
- Return type:
Porous media#
- sumfem.models.bruggeman(value, fraction, exponent=1.5)[source]#
Bruggeman’s effective property
value * fraction**exponent.It corrects a transport property of a phase for the volume the other phase takes and for the tortuosity of the paths through it. The exponent
3/2is that of spherical obstructions, see Tjaden et al., 2016, where the tortuosity scales with the fraction to the power-1/2. It suits macroporous electrodes; where the tortuosity is measured, the propertyvalue * fraction / tortuosityis the alternative of Barzegari et al., 2026.
- sumfem.models.kozeny_carman(fiber_diameter, porosity, constant)[source]#
Kozeny-Carman permeability
d^2 eps^3 / (K (1 - eps)^2)of a fibrous medium.An estimate of the permeability of a fibrous porous electrode, such as a carbon felt, from the diameter of its fibres, with an empirical constant
K. The carbon fibres of commercial cloths, papers and felts have diameters of 7 to 9 micrometres, see Barzegari et al., 2026. The estimate is of limited use for complex media, whose permeability is best fitted to measured pressure drops.
- sumfem.models.kozeny_carman_permeability(porosity, reference, floor=1e-06)[source]#
Kozeny-Carman permeability
K_0 phi^3 / ((1 - phi)^2 + e).The relation
K_0 phi^3 / (1 - phi)^2of equation 3 of Terschanski et al., CMAME 442, 117962, 2025, with a floorethat keeps it finite in pure fluid,phi = 1. It vanishes with the porosity, so the Darcy dragphi eta / Kof a solid needs the porosity bounded away from zero.
- sumfem.models.ergun_coefficient(porosity, length)[source]#
Ergun’s inertial drag coefficient
1.75 (1 - eps) / (L eps^3).The coefficient
beta, in 1/m, of Forchheimer’s dragrho beta |u| uon the superficial velocityu, from Ergun’s relation for randomly packed beds of spheres of diameterL(Ergun and Orning, 1949). For a fibrous electrode, such as a carbon felt, it is an estimate only: the model of Tomadakis and Robertson, 2005 is made for random fibre structures, and fits to experiments give the coefficient of a given electrode, e.g. of the order of Ergun’s for the 3D printed electrodes of van der Heijden et al., 2023.
Operators#
- sumfem.models.apply_coefficient(coefficient, vector)[source]#
A scalar or matrix coefficient applied to a vector.
- Parameters:
- Raises:
ValueError – If the coefficient is neither a scalar nor a matrix.
- Return type: