Dear dokken,
Following up on our previous discussion, I have the following questions:
1. I would like to compare the results between FEniCSx and Firedrake.
The system environment is WSL2 Ubuntu, and I have created two separate virtual environments using micromamba. The FEniCSx version is 0.9.0, while Firedrake was installed according to the instructions in the Firedrake 2025.10.3.dev0 documentation. Installing Firedrake — Firedrake 2025.10.3.dev0 documentation.
I executed your code using the command mpirun -n 1 python3 KMV_test.py in the FEniCSx 0.9.0 environment (installed via conda-forge) on WSL2 Ubuntu. The execution command and corresponding results are as follows:
from mpi4py import MPI
import ufl
import symfem
import numpy as np
import symfem.basix_interface
import dolfinx
element = symfem.create_element("triangle", "KMV", 2)
basix_ufl_element = symfem.basix_interface.create_basix_element(element, ufl=True)
def f(x):
return (1 - x[0] - x[1]) * x[0] * x[1] + x[0] ** 2 - 2 * x[1] ** 2
for n in [4, 8, 16, 32, 64]:
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, n, n)
V = dolfinx.fem.functionspace(mesh, basix_ufl_element)
u = dolfinx.fem.Function(V)
u.interpolate(f)
x = ufl.SpatialCoordinate(mesh)
error_L2 = mesh.comm.allreduce(
dolfinx.fem.assemble_scalar(dolfinx.fem.form((u - f(x)) ** 2 * ufl.dx)),
op=MPI.SUM,
)
print(f"{n=} L2 error: {np.sqrt(error_L2)}")
n=4 L2 error: 0.0005391137182342338
n=8 L2 error: 6.738921477825666e-05
n=16 L2 error: 8.423651846508915e-06
n=32 L2 error: 1.0529564801666114e-06
n=64 L2 error: 1.3161955942545088e-07
I have executed my Firedrake code as follows:
import numpy as np
from firedrake import (
Function, FunctionSpace,
errornorm, UnitSquareMesh, SpatialCoordinate
)
def f(mesh):
x = SpatialCoordinate(mesh)
return (1 - x[0] - x[1]) * x[0] * x[1] + x[0] ** 2 - 2 * x[1] ** 2
for n in [4, 8, 16, 32, 64]:
mesh = UnitSquareMesh(n, n)
V = FunctionSpace(mesh, "KMV", 2)
VE = FunctionSpace(mesh, "CG", 3)
u = Function(V); u.interpolate(f(mesh))
u_ = Function(VE); u_.interpolate(f(mesh))
x = SpatialCoordinate(mesh)
error_m = errornorm(u, u_, norm_type='L2')
print(f"{n=} L2 error: {error_m}")
The result is
/.local/lib/python3.10/site-packages/numpy/_core/getlimits.py:551: UserWarning: Signature b'\x00\xd0\xcc\xcc\xcc\xcc\xcc\xcc\xfb\xbf\x00\x00\x00\x00\x00\x00' for <class 'numpy.longdouble'> does not match any known type: falling back to type probe function.
This warnings indicates broken support for the dtype!
machar = _get_machar(dtype)
firedrake:WARNING OMP_NUM_THREADS is not set or is set to a value greater than 1, we suggest setting OMP_NUM_THREADS=1 to improve performance
firedrake:WARNING Degree of exact solution less than approximation degree
n=4 L2 error: 2.388585201114899e-16
firedrake:WARNING Degree of exact solution less than approximation degree
n=8 L2 error: 2.1926452124941248e-16
firedrake:WARNING Degree of exact solution less than approximation degree
n=16 L2 error: 2.269577765062539e-16
firedrake:WARNING Degree of exact solution less than approximation degree
n=32 L2 error: 2.0988940267773374e-16
firedrake:WARNING Degree of exact solution less than approximation degree
n=64 L2 error: 2.156275105378545e-16
The results clearly do not match.
2. The support degree order for KMV element
3. Are there any specialized quadrature rules for the KMV element in FEniCSx?
The adoption of the KMV element is driven by its application as a mass-lumped triangular element. Crucially, obtaining a lumped mass matrix requires both this special element and appropriate quadrature rules. This is implemented within Firedrake through the FInAT library, see Scalar wave equation with higher-order mass lumping — Firedrake 2025.10.3.dev0 documentation
import finat
quad_rule = finat.quadrature.make_quadrature(V.finat_element.cell, V.ufl_element().degree(), "KMV")
dxlump=dx(scheme=quad_rule)
However, when I tried to install the FInAT or FIAT package in my FEniCSx virtual environment, I encountered an error.
micromamba install finat -c conda-forge
nodefaults/linux-64 ??.?MB @ ??.?MB/s 0.6s
nodefaults/noarch ??.?MB @ ??.?MB/s 0.6s
conda-forge/noarch 23.4MB @ 3.4MB/s 6.8s
conda-forge/linux-64 48.9MB @ 6.6MB/s 7.3s
Pinned packages:
- python=3.13
error libmamba Could not solve for environment specs
The following package could not be installed
└─ finat =* * does not exist (perhaps a typo or a missing channel).
critical libmamba Could not solve for environment specs
I have also attempted to install it via pip , but without success. What is the recommended approach to implement the specific quadrature rules for mass lumping with the KMV element in FEniCSx?
4. Another question
Also, where can I see the basis functions of predefined elements in FEniCSx? Given that the KMV element is new, I’m skeptical if the basis functions in symfem and Firedrake are the same.
I’m new to this, so please forgive any naive questions. Thanks again to you and the FEniCSx team for your amazing work.