scikit-fem
raw JSON → 12.0.1 verified Mon Apr 27 auth: no python
A simple finite element assembler library for Python. Current version 12.0.1, requires Python >=3.10. Released roughly every few months on GitHub. Provides a high-level interface for assembling finite element matrices and vectors, with support for various element types and mesh formats.
pip install scikit-fem Common errors
error ModuleNotFoundError: No module named 'skfem' ↓
cause scikit-fem not installed or environment not activated.
fix
Run 'pip install scikit-fem' in your terminal.
error AttributeError: module 'skfem' has no attribute 'ElementTriP1' ↓
cause ElementTriP1 is in skfem.element module but often imported directly. The error may occur if using old import path.
fix
Use 'from skfem import ElementTriP1' or 'from skfem.element import ElementTriP1'.
error TypeError: 'BilinearForm' object is not callable ↓
cause Incorrect usage of BilinearForm decorator; likely calling the decorator incorrectly.
fix
Use '@BilinearForm' on a function that takes (u, v, w) and returns a scalar expression. Then pass to asm.
Warnings
breaking Mesh.with_defaults now uses np.isclose for facet matching, which may cause previously unmatched facets to be tagged. Check your mesh boundary tags after upgrading to 12.0.0+. ↓
fix Review Mesh.boundaries after call to with_defaults; adjust tolerance or explicitly tag facets if needed.
deprecated skfem.visuals.glvis has been deprecated in 9.0.0 and is broken; no replacement planned. ↓
fix Use alternative visualization like matplotlib or PyVista directly on mesh data.
breaking MortarFacetBasis and MappingMortar removed in 9.0.0; use skfem.supermeshing instead. ↓
fix Replace imports from skfem.assembly.mortar with skfem.supermeshing.
gotcha Initializing Basis for ElementTetP0 without intorder or quadrature will now automatically fall back to a one-point integration rule (since 10.0.0). This may affect accuracy. ↓
fix Explicitly set intorder when using ElementTetP0 with Basis.
Imports
- Basis wrong
from skfem.basis import Basiscorrectfrom skfem import Basis - Mesh wrong
from skfem.mesh import Meshcorrectfrom skfem import Mesh - BilinearForm wrong
from skfem.assembly import BilinearFormcorrectfrom skfem import BilinearForm - asm wrong
from skfem.assembly import asmcorrectfrom skfem import asm - np
import numpy as np
Quickstart
import numpy as np
from skfem import Mesh, Basis, BilinearForm, LinearForm, asm
from skfem.helpers import dot, grad
# Create a simple unit square mesh
mesh = Mesh().refined(2)
# Define basis for linear elements
basis = Basis(mesh, ElementTriP1())
# Define bilinear form for Laplacian
@BilinearForm
def laplace(u, v, w):
return dot(grad(u), grad(v))
# Assemble stiffness matrix
A = asm(laplace, basis)
# Define linear form for rhs
@LinearForm
def rhs(v, w):
return 1.0 * v
# Assemble rhs vector
b = asm(rhs, basis)
# Solve (requires scipy or similar)
# x = np.linalg.solve(A, b)
print(A.shape)