Finite Elements¶
The voids.fem sub-package provides optional FEniCSx-backed finite-element
single-phase solvers for porosity/permeability maps. These APIs require a
compatible DOLFINx installation, such as the Pixi fem feature in this
repository. The PyPI package does not install FEniCSx automatically.
The current single-phase FEM backends report effective permeability from the computed outlet flux and Darcy's law. They are numerical upscaling tools, not experimental validation claims by themselves.
The default FEniCSSolverOptions use PETSc LU with MUMPS. For high-contrast
mixed Darcy-Brinkman maps, avoid treating PETSc's built-in LU backend as a
scientific fallback unless it has been checked against a robust factorization
package on the same problem class; it can return nonphysical permeabilities for
these saddle-point systems.
The USFEM backend is especially sensitive to the external factorization package and workspace settings on larger 3-D maps. Record the PETSc options from the result metadata with any reported USFEM permeability.
Thread environment for FEM solves
For robust FEniCSx/PETSc direct solves, pin BLAS/OpenMP thread variables
before Python imports NumPy, SciPy, PETSc, or DOLFINx. voids.fem applies
conservative defaults when those variables are unset, but it does not
override user-provided values. See the detailed warning in
Map-Based Single-Phase Solvers.
For the governing equations, boundary conditions, spaces, stabilization terms, and permeability reporting convention, see Map-Based Single-Phase Solvers.
Common Types¶
voids.fem.singlephase
¶
Single-phase finite-element Darcy and Brinkman backends.
FEMMapProblem
dataclass
¶
Porosity/permeability coefficient maps for FEM single-phase solves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
permeability_map
|
PermeabilityMap
|
Scalar cell-wise permeability map. |
required |
porosity_map
|
PorosityMap | None
|
Optional porosity map on the same grid. Brinkman solves use this field
in |
None
|
viscosity
|
float
|
Dynamic viscosity |
1.0
|
porosity_floor
|
float
|
Lower bound used only in the Brinkman effective-viscosity coefficient. |
1e-06
|
permeability_floor
|
float
|
Lower bound used in |
1e-30
|
Source code in src/voids/fem/singlephase/_common.py
FEMSinglePhaseResult
dataclass
¶
Finite-element single-phase flow result.
Source code in src/voids/fem/singlephase/_common.py
FEniCSSolverOptions
dataclass
¶
Linear solver controls for FEniCSx linear problems.
The default linear_backend="auto" preserves the PETSc/MUMPS path on
platforms with a full DOLFINx/PETSc stack. On native Windows, where that
PETSc stack is not available in the conda-forge FEniCSx packages used by
voids, auto uses DOLFINx assembly plus SciPy's direct sparse solver.
Use linear_backend="scipy" or "umfpack" to request the serial
DOLFINx-assembly/direct-sparse path explicitly on any platform. These paths
use the same weak form and boundary conditions as PETSc; only the linear
algebra backend changes. "umfpack" requires the optional
scikits.umfpack package.
Source code in src/voids/fem/singlephase/_common.py
direct_lu
classmethod
¶
direct_lu(
backend="mumps",
*,
linear_backend="petsc",
petsc_options_prefix="voids_fem_",
shift_amount=1e-12,
mumps_memory_relaxation_percent=None,
mumps_workspace_mb=None,
)
Create PETSc options for a direct sparse LU solve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
PETSc factorization package, for example |
'mumps'
|
linear_backend
|
LinearSolverBackend
|
Linear algebra backend. This builder configures PETSc options, so
the default is |
'petsc'
|
petsc_options_prefix
|
str
|
Prefix used by DOLFINx for PETSc runtime options. |
'voids_fem_'
|
shift_amount
|
float | None
|
Nonzero diagonal shift used during factorization. Pass |
1e-12
|
mumps_memory_relaxation_percent
|
int | None
|
Optional MUMPS memory controls. They are added only when the backend
is |
None
|
mumps_workspace_mb
|
int | None
|
Optional MUMPS memory controls. They are added only when the backend
is |
None
|
Source code in src/voids/fem/singlephase/_common.py
scipy_direct
classmethod
¶
Create options for the serial DOLFINx-assembly/SciPy direct backend.
umfpack_direct
classmethod
¶
Create options for the serial DOLFINx-assembly/UMFPACK backend.
FEMUpscalingResult
dataclass
¶
Principal-direction FEM micro-continuum permeability result.
Source code in src/voids/fem/singlephase/upscaling.py
solve_brinkman_taylor_hood
¶
solve_brinkman_taylor_hood(
problem,
*,
flow_axis="x",
pressure_inlet=1.0,
pressure_outlet=0.0,
options=None,
)
Solve the Darcy-Brinkman micro-continuum model with Taylor-Hood elements.
The weak form uses CG2 velocity and CG1 pressure:
(mu / phi grad u, grad v) + (mu / K u, v)
- (p, div v) + (q, div u) = boundary pressure work.
K and phi are piecewise-constant maps supplied through
:class:~voids.fem.singlephase.FEMMapProblem.
Source code in src/voids/fem/singlephase/taylorhood.py
solve_darcy_taylor_hood
¶
solve_darcy_taylor_hood(
problem,
*,
flow_axis="x",
pressure_inlet=1.0,
pressure_outlet=0.0,
options=None,
)
Solve the mixed Darcy-Darcy comparison model with Taylor-Hood elements.
The weak form uses a CG2 velocity approximation and a CG1 pressure approximation:
(mu / K u, v) - (p, div v) + (q, div u) = boundary pressure work.
Side boundaries impose only zero normal velocity on faces transverse to the flow axis. Inlet and outlet pressures are applied as natural traction terms.
Source code in src/voids/fem/singlephase/taylorhood.py
upscale_permeability_fem
¶
upscale_permeability_fem(
problem,
*,
backend="taylor_hood_brinkman",
axes=None,
pressure_inlet=1.0,
pressure_outlet=0.0,
options=None,
backend_kwargs=None,
)
Compute principal-direction FEM permeability estimates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
FEMMapProblem
|
Porosity/permeability map problem. |
required |
backend
|
FEMBackend
|
Either a backend name or a compatible solver callable. Supported names
are |
'taylor_hood_brinkman'
|
axes
|
tuple[str, ...] | None
|
Principal axes to solve. By default all axes supported by the map dimensionality are solved. |
None
|
pressure_inlet
|
float
|
Natural pressure values imposed on opposite faces of each flow axis. |
1.0
|
pressure_outlet
|
float
|
Natural pressure values imposed on opposite faces of each flow axis. |
1.0
|
options
|
FEniCSSolverOptions | None
|
Linear solver options passed to the FEM backend. The default preserves PETSc where available and uses a serial SciPy direct solve on native Windows when PETSc is unavailable. |
None
|
backend_kwargs
|
dict[str, object] | None
|
Additional backend-specific keyword arguments. |
None
|
Source code in src/voids/fem/singlephase/upscaling.py
upscale_principal_permeabilities_fem
¶
upscale_principal_permeabilities_fem(
problem,
*,
backend="taylor_hood_brinkman",
axes=None,
pressure_inlet=1.0,
pressure_outlet=0.0,
options=None,
backend_kwargs=None,
)
Return only the principal FEM permeability values.
Source code in src/voids/fem/singlephase/upscaling.py
solve_brinkman_usfem
¶
solve_brinkman_usfem(
problem,
*,
flow_axis="x",
pressure_inlet=1.0,
pressure_outlet=0.0,
tau_factor=1.0,
m_t=1.0 / 3.0,
alpha_edge=1.0,
options=None,
)
Solve a stabilized Darcy-Brinkman micro-continuum model.
The formulation uses CG1 velocity and DG1 pressure fields. It augments the Brinkman weak form with a residual-based cell stabilization term and an interior pressure-jump penalty. The coefficients are intended for porosity/permeability maps obtained from a segmented image.
Source code in src/voids/fem/singlephase/usfem.py
Taylor-Hood Backends¶
voids.fem.singlephase.taylorhood
¶
solve_darcy_taylor_hood
¶
solve_darcy_taylor_hood(
problem,
*,
flow_axis="x",
pressure_inlet=1.0,
pressure_outlet=0.0,
options=None,
)
Solve the mixed Darcy-Darcy comparison model with Taylor-Hood elements.
The weak form uses a CG2 velocity approximation and a CG1 pressure approximation:
(mu / K u, v) - (p, div v) + (q, div u) = boundary pressure work.
Side boundaries impose only zero normal velocity on faces transverse to the flow axis. Inlet and outlet pressures are applied as natural traction terms.
Source code in src/voids/fem/singlephase/taylorhood.py
solve_brinkman_taylor_hood
¶
solve_brinkman_taylor_hood(
problem,
*,
flow_axis="x",
pressure_inlet=1.0,
pressure_outlet=0.0,
options=None,
)
Solve the Darcy-Brinkman micro-continuum model with Taylor-Hood elements.
The weak form uses CG2 velocity and CG1 pressure:
(mu / phi grad u, grad v) + (mu / K u, v)
- (p, div v) + (q, div u) = boundary pressure work.
K and phi are piecewise-constant maps supplied through
:class:~voids.fem.singlephase.FEMMapProblem.
Source code in src/voids/fem/singlephase/taylorhood.py
USFEM Backends¶
voids.fem.singlephase.usfem
¶
solve_brinkman_usfem
¶
solve_brinkman_usfem(
problem,
*,
flow_axis="x",
pressure_inlet=1.0,
pressure_outlet=0.0,
tau_factor=1.0,
m_t=1.0 / 3.0,
alpha_edge=1.0,
options=None,
)
Solve a stabilized Darcy-Brinkman micro-continuum model.
The formulation uses CG1 velocity and DG1 pressure fields. It augments the Brinkman weak form with a residual-based cell stabilization term and an interior pressure-jump penalty. The coefficients are intended for porosity/permeability maps obtained from a segmented image.
Source code in src/voids/fem/singlephase/usfem.py
Upscaling¶
voids.fem.singlephase.upscaling
¶
FEMUpscalingResult
dataclass
¶
Principal-direction FEM micro-continuum permeability result.
Source code in src/voids/fem/singlephase/upscaling.py
upscale_permeability_fem
¶
upscale_permeability_fem(
problem,
*,
backend="taylor_hood_brinkman",
axes=None,
pressure_inlet=1.0,
pressure_outlet=0.0,
options=None,
backend_kwargs=None,
)
Compute principal-direction FEM permeability estimates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
FEMMapProblem
|
Porosity/permeability map problem. |
required |
backend
|
FEMBackend
|
Either a backend name or a compatible solver callable. Supported names
are |
'taylor_hood_brinkman'
|
axes
|
tuple[str, ...] | None
|
Principal axes to solve. By default all axes supported by the map dimensionality are solved. |
None
|
pressure_inlet
|
float
|
Natural pressure values imposed on opposite faces of each flow axis. |
1.0
|
pressure_outlet
|
float
|
Natural pressure values imposed on opposite faces of each flow axis. |
1.0
|
options
|
FEniCSSolverOptions | None
|
Linear solver options passed to the FEM backend. The default preserves PETSc where available and uses a serial SciPy direct solve on native Windows when PETSc is unavailable. |
None
|
backend_kwargs
|
dict[str, object] | None
|
Additional backend-specific keyword arguments. |
None
|
Source code in src/voids/fem/singlephase/upscaling.py
upscale_principal_permeabilities_fem
¶
upscale_principal_permeabilities_fem(
problem,
*,
backend="taylor_hood_brinkman",
axes=None,
pressure_inlet=1.0,
pressure_outlet=0.0,
options=None,
backend_kwargs=None,
)
Return only the principal FEM permeability values.