hermit.fenics.assembly

Thin PETSc/UFL assembly helpers for DOLFINx (0.9 / 0.11).

Slim port of the pieces of femo_alpha/fea/utils_dolfinx.py that Hermit’s custom operations actually need. No CSDL here.

Functions

assemble_matrix() → petsc4py.PETSc.Mat)

Assemble a 2-form to an assembled PETSc matrix.

assemble_scalar(→ float)

Assemble a scalar UFL form to a float.

assemble_vector(→ numpy.ndarray)

Assemble a 1-form to a numpy array.

derivative(f, u[, du])

d f / d u as a UFL form (or w.r.t. a coefficient / SpatialCoordinate).

get_array(→ numpy.ndarray)

Local array of a Function (owned + ghost).

ksp_mumps(→ petsc4py.PETSc.KSP)

A preonly + LU(MUMPS) KSP for the (already assembled) operator A.

matvec(→ numpy.ndarray)

A @ x (x a Function, result a numpy array of A's row layout).

owned_entry_mask(dofmap_list, n_scalar_dofs)

(n_cells, n_local_nodes) bool -- True where the cell owns that dof.

owning_cell(dofmap_list, n_scalar_dofs)

scalar dof -> the cell that writes it last in ascending cell order.

project(→ None)

L2-project a UFL expression onto target's space (used for field outputs).

rmatvec(→ numpy.ndarray)

A.T @ x.

set_array(→ None)

Set a Function from a flat array and sync ghosts.

transpose(→ petsc4py.PETSc.Mat)

Module Contents

hermit.fenics.assembly.assemble_matrix(a, bcs=()) → petsc4py.PETSc.Mat

Assemble a 2-form to an assembled PETSc matrix.

hermit.fenics.assembly.assemble_scalar(f) → float

Assemble a scalar UFL form to a float.

hermit.fenics.assembly.assemble_vector(f) → numpy.ndarray

Assemble a 1-form to a numpy array.

hermit.fenics.assembly.derivative(f, u, du=None)

d f / d u as a UFL form (or w.r.t. a coefficient / SpatialCoordinate).

hermit.fenics.assembly.get_array(f: dolfinx.fem.Function) → numpy.ndarray

Local array of a Function (owned + ghost).

hermit.fenics.assembly.ksp_mumps(A: petsc4py.PETSc.Mat) → petsc4py.PETSc.KSP

A preonly + LU(MUMPS) KSP for the (already assembled) operator A.

hermit.fenics.assembly.matvec(A: petsc4py.PETSc.Mat, x: dolfinx.fem.Function) → numpy.ndarray

A @ x (x a Function, result a numpy array of A’s row layout).

hermit.fenics.assembly.owned_entry_mask(dofmap_list, n_scalar_dofs)

(n_cells, n_local_nodes) bool – True where the cell owns that dof.

hermit.fenics.assembly.owning_cell(dofmap_list, n_scalar_dofs)

scalar dof -> the cell that writes it last in ascending cell order.

Function.interpolate scatters a point evaluation per cell, so a shared (continuous) target dof is written once per adjacent cell and the last writer wins. The interpolation Jacobian must therefore carry only the owning cell’s row – taking the union of every adjacent cell’s contribution (which is what a plain COO scatter does, since each cell contributes on its own source columns) over-counts it. Deduplicating (row, col) pairs is not enough: the columns mostly differ, so the duplicates never collide.

Same construction as hermit._field._Tabulation.dof_cell, and a no-op on DG (every dof has exactly one cell).

hermit.fenics.assembly.project(expr, target: dolfinx.fem.Function, lump_mass: bool = False) → None

L2-project a UFL expression onto target’s space (used for field outputs).

hermit.fenics.assembly.rmatvec(A: petsc4py.PETSc.Mat, x: dolfinx.fem.Function) → numpy.ndarray

A.T @ x.

hermit.fenics.assembly.set_array(f: dolfinx.fem.Function, values) → None

Set a Function from a flat array and sync ghosts.

hermit.fenics.assembly.transpose(A: petsc4py.PETSc.Mat) → petsc4py.PETSc.Mat