Models#

Models built on sumfem, to be summed and extended.

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 field u with test function v.

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, see as_expr().

  • markers (tuple[str, ...]) – Optional cell markers restricting the term to subdomains.

property field: Field#

The field whose time derivative is added.

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

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_name: ClassVar[str] = 'coefficient'#

Name of the parameter created for the coefficient.

coefficient_unit: ClassVar[Unit | None] = None#

Unit of the parameter created for the coefficient.

coefficient_doc: ClassVar[str] = 'Diffusion coefficient'#

Description of the parameter created for the coefficient.

property field: Field#

The diffusing field.

property coefficient: Expr#

The diffusion coefficient.

property markers: tuple[str, ...]#

Cell markers of the region.

viscous_flux(u, grad_u)[source]#

The viscous flux F(u, grad_u) = k grad_u of -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 of u. This flux does not depend on u. It has the opposite sign of the physical flux, flux(), which is -F at the field.

Parameters:
Return type:

Expr

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:

Expr

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

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 c whose 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.

property field: Field#

The advected field.

property velocity: Expr#

The velocity.

property quantity: Expr#

The advected quantity.

flux()[source]#

The advective flux c u, the outer product for a vector c.

Return type:

Expr

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 c whose 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.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

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): Outflow on 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: with v = 1 the interior terms cancel. Use it with a velocity whose normal component jumps across facets, e.g. the gradient of a Lagrange pressure, as in Darcy flow.

Parameters:
  • name (str) – Name of the model.

  • field (Field) – The field c whose 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.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

class sumfem.models.Source(name, field, source=None, markers=())[source]#

A source f in 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.

property source: Expr#

The source.

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

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 Diffusion and a Source, both named name, 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.

property diffusion: Diffusion#

The diffusion term, e.g. for its flux.

property field: Field#

The unknown.

property coefficient: Expr#

The coefficient k.

property markers: tuple[str, ...]#

Cell markers of the region.

property source: Expr#

The right-hand side.

viscous_flux(u, grad_u)[source]#

The viscous flux k grad_u of the diffusion, see Diffusion.viscous_flux(), e.g. for Nitsche’s method.

Parameters:
Return type:

Expr

flux()[source]#

The flux -k grad(u) of the diffusion, minus its viscous_flux() at the field, see Diffusion.flux().

Return type:

Expr

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.

coefficient_doc: ClassVar[str] = 'Conductivity'#

Description of the parameter created for the coefficient.

current_density()[source]#

Current density -sigma grad(phi).

Return type:

Expr

Boundaries#

class sumfem.models.BoundaryFlux(name, field, inflow, markers)[source]#

An inflow q into 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 is q = -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.

  • markers (tuple[str, ...]) – Facet markers of the boundary.

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.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

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.

  • markers (tuple[str, ...]) – Facet markers of the outlet.

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

class sumfem.models.BoundaryConstraint(name, field, multiplier, constraint, markers=())[source]#

A constraint c(u) = 0 on 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 v the test function of the field u, mu that of the multiplier lambda and c'(u)[v] the derivative of the constraint in the direction v. 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, see Discretization for the entity maps between meshes. DirichletMultiplier is the constraint u - 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 give None and override constraint().

  • 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 velocity u:

n = ufl.FacetNormal(domain)
wall = BoundaryConstraint("wall", u, p_wall, ufl.dot(u, n), ("Wall",))
constraint()[source]#

The constraint c(u).

Return type:

Expr

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

class sumfem.models.DirichletMultiplier(name, field, multiplier, value=None, markers=())[source]#

A Dirichlet condition u = g imposed with a Lagrange multiplier.

The BoundaryConstraint c(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) . n of 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.

constraint()[source]#

The constraint u - g.

Return type:

Expr

Interfaces#

class sumfem.models.InterfaceLagrangeMultiplier(name, first, second, first_value, second_value, multiplier, measure)[source]#

A condition a = b across 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 a of the first side and b of the second, e.g. the continuity of the partial pressure of hydrogen across a material interface, which makes the concentrations jump. The multiplier lambda is 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_1 and mu the test functions of the two fields and of the multiplier. Unlike a BoundaryConstraint, whose multiplier enters through the derivative of the constraint, the flux is the same on both sides for any a and b, 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 a of the first side, unrestricted, e.g. (c_0 / K_S)**2 for Sieverts’ law.

  • second_value (ufl.core.expr.Expr | npt.ArrayLike) – The quantity b of the second side, unrestricted, e.g. c_1 / K_H for Henry’s law.

  • multiplier (Field) – The multiplier lambda, a scalar field on the interface, e.g. on a Subdomain of its facets.

  • measure (ufl.Measure) – The interface measure, from interface().

Raises:

ValueError – If the quantities or the multiplier are not scalars.

flux()[source]#

The flux from the first subdomain to the second, the multiplier.

Return type:

Expr

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

class sumfem.models.InterfacePenalty(name, first, second, first_value, second_value, conductance, measure)[source]#

A condition a = b across 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 conductance k drives a = b, with a jump of order q / k. With a = c_0 / K_0 and b = c_1 / K_1 it 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; InterfacePenaltyEnergy is 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 a of the first side, unrestricted, e.g. c_0 / K_0.

  • second_value (ufl.core.expr.Expr | npt.ArrayLike) – The quantity b of the second side, unrestricted.

  • conductance (ufl.core.expr.Expr | npt.ArrayLike) – The conductance k.

  • measure (ufl.Measure) – The interface measure, from interface().

flux()[source]#

The exchange flux from the first subdomain to the second.

Return type:

Expr

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

class sumfem.models.InterfacePenaltyEnergy(name, first, second, first_value, second_value, penalty, measure)[source]#

A condition a = b across an interface, by the penalty energy alpha / 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 with alpha growing; for exact conservation use InterfacePenalty. For Sieverts’ law with b = (c_1 / K)^(1/2), db/dc_1 grows without bound where c_1 vanishes.

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 a of the first side, unrestricted, e.g. c_0.

  • second_value (ufl.core.expr.Expr | npt.ArrayLike) – The quantity b of 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().

mismatch()[source]#

The violation a+ - b- of the condition on the interface.

Return type:

Expr

functional()[source]#

Return this component’s contribution to the functional.

Return type:

Form

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 a BoundaryFlux on 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.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

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 velocity u and its test function w, and the pressure p and its test function q. The stress is 2 mu epsilon(u) - p I, so the term holds for a viscosity that varies in space, e.g. mu / eps with 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:
  • 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.

  • markers (tuple[str, ...]) – Cell markers of the flow region. Empty for the whole domain.

property velocity: Field#

The velocity.

property pressure: Field#

The pressure.

property viscosity: Expr#

The viscosity of the viscous term.

viscous_flux(u, grad_u)[source]#

The stress 2 mu epsilon(u) - p I of the momentum equation.

A function of u and grad_u separately, for Nitsche’s method, which evaluates it at the boundary.

Parameters:
Return type:

Expr

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

class sumfem.models.Convection(name, velocity, density=None, markers=())[source]#

Convection of momentum, (rho grad(u) u, w).

Parameters:
  • name (str) – Name of the model.

  • velocity (Field) – The velocity u.

  • density (ExpressionOrValue) – Density rho. Defaults to the parameter "<name>.density" in kg/m^3.

  • markers (tuple[str, ...]) – Cell markers of the term. Empty for the whole domain.

force()[source]#

The term f, per unit volume.

Return type:

Expr

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.

force()[source]#

The term f, per unit volume.

Return type:

Expr

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 s of the speed, in m/s, or the default of the parameter "<name>.speed_floor".

force()[source]#

The term f, per unit volume.

Return type:

Expr

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:
  • name (str) – Name of the model.

  • velocity (Field) – The velocity u.

  • weight (ExpressionOrValue) – The weight gamma, a viscosity. Defaults to the parameter "<name>.weight" in Pa s.

  • markers (tuple[str, ...]) – Cell markers of the term. Empty for the whole domain.

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

class sumfem.models.NavierStokes(name, velocity, pressure, viscosity=None, density=None, markers=())[source]#

Steady incompressible flow with convection.

The sum of Stokes flow, "<name>_stokes", and Convection, "<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 Stokes flow of the superficial velocity u with the viscosity mu / eps in the pores, "<name>_stokes", and DarcyDrag, "<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 / eps and 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 Brinkman flow, Convection in the pores with the density rho / eps^2, "<name>_convection", and ForchheimerDrag, "<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.

  • velocity (Field) – See Brinkman.

  • pressure (Field) – See Brinkman.

  • 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.

  • markers (tuple[str, ...]) – See Brinkman.

  • 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_j by mass action.

For example, 3 A + 4 B <-> 4 C, with reactants={A: 3, B: 4} and products={C: 4}. By the law of mass action, it runs forward more often the more A and B there are, at the rate k_f A^3 B^4, and backward at the rate k_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_f and k_b. In general, each reactant and each product is raised to its coefficient. The law holds for elementary reactions; for any other rate law, use RateReaction.

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_i of each reactant, e.g. {A: 3, B: 4}.

  • products (Participants) – The coefficient nu_j of 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)
rate()[source]#

The rate R = k_f prod(c_i ** nu_i) - k_b prod(c_j ** nu_j).

Return type:

Expr

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_j at a rate R.

Each time the reaction happens, it consumes nu_i of each reactant A_i and produces nu_j of each product B_j. The rate R is how many times it happens, per unit volume and time. So a reactant is consumed at nu_i R and a product produced at nu_j R.

For example, 3 A + 4 B -> 4 C is reactants={A: 3, B: 4} and products={C: 4}, here at the rate R(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, with v_A, v_B and v_C the test functions.

The coefficients and the rate are independent here. Reaction takes 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 Subdomain of lower dimension, e.g. a surface, the reaction happens on that surface, R is 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 of first on "+", those of second on "-", and the others, e.g. of the membrane itself, on "+".

Parameters:
  • name (str) – Name of the model.

  • reactants (Participants) – The coefficient nu_i of each reactant, e.g. {A: 3, B: 4}.

  • products (Participants) – The coefficient nu_j of 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 S into a product P at the rate R = v_max S / (K_m + S) of Michaelis-Menten kinetics, so S gets +R and P gets -R in 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))
property domain: Domain#

The domain of the participants, which holds the rate’s parameters.

rate()[source]#

The rate R.

Return type:

Expr

residual()[source]#

Return this component’s contribution to the residual.

The form must be linear in test functions field.v and contain no trial functions. A contribution that is zero, e.g. for some inputs, is ufl.ZeroBaseForm((field.v,)): UFL drops the test function from a form whose terms vanish.

Return type:

Form

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.

Parameters:
  • rate (Expr) – The rate constant k.

  • participants (Mapping[Expr, int]) – The participants c_i and their stoichiometric coefficients nu_i, e.g. the reactants of the forward reaction.

Returns:

The rate k prod(c_i ** nu_i).

Return type:

Expr

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:
  • prefactor (Expr | float) – k_0.

  • activation_energy (Expr | float) – E, in the energy unit of boltzmann.

  • temperature (Expr | float) – T, in K.

  • boltzmann (Expr | float | None) – k_B. Defaults to the parameter of boltzmann_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 for E in eV.

Returns:

The rate constant k_0 exp(-E / (k_B T)).

Return type:

Expr

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:

Expr

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/2 is 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 property value * fraction / tortuosity is the alternative of Barzegari et al., 2026.

Parameters:
  • value (Expr | float) – The property of the phase, e.g. a diffusivity or the conductivity of the solid.

  • fraction (Expr | float) – Volume fraction of the phase, e.g. the porosity for the electrolyte, or one minus it for the solid.

  • exponent (float) – Bruggeman exponent.

Return type:

Expr

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.

Parameters:
  • fiber_diameter (Expr) – Fiber diameter d.

  • porosity (Expr) – Porosity eps.

  • constant (Expr | float) – Kozeny-Carman constant K.

Return type:

Expr

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)^2 of equation 3 of Terschanski et al., CMAME 442, 117962, 2025, with a floor e that keeps it finite in pure fluid, phi = 1. It vanishes with the porosity, so the Darcy drag phi eta / K of a solid needs the porosity bounded away from zero.

Parameters:
  • porosity (Expr) – The porosity, or liquid fraction, phi.

  • reference (Expr | float) – The reference permeability K_0.

  • floor (float) – The floor e.

Return type:

Expr

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 drag rho beta |u| u on the superficial velocity u, from Ergun’s relation for randomly packed beds of spheres of diameter L (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.

Parameters:
  • porosity (Expr) – Porosity eps.

  • length (Expr) – Characteristic pore length L.

Return type:

Expr

Operators#

sumfem.models.apply_coefficient(coefficient, vector)[source]#

A scalar or matrix coefficient applied to a vector.

Parameters:
  • coefficient (Expr) – A scalar, such as an isotropic diffusivity, or a matrix, such as an anisotropic one.

  • vector (Expr) – The vector, such as a gradient or a facet normal.

Raises:

ValueError – If the coefficient is neither a scalar nor a matrix.

Return type:

Expr

sumfem.models.normal_projection(vector, normal)[source]#

The normal component (n (x) n) w = (w . n) n of a vector w.

Parameters:
Return type:

Expr

sumfem.models.tangential_projection(vector, normal)[source]#

The tangential component (I - n (x) n) w of a vector w.

Parameters:
Return type:

Expr