Hello,
I’m trying to compute the integral of fv, where f is a function defined in a finite element function space V, and v is the test function of the same space.
In Python, this is very straightforward and works correctly for any degree I specify. Here is a minimal working example:
from mpi4py import MPI
from dolfinx import fem, mesh
import ufl
from ufl import dx
degree = 3
msh = mesh.create_interval(comm=MPI.COMM_WORLD, nx=10, points=(0.0, 1.0))
V = fem.functionspace(msh, ("Lagrange", degree))
v = ufl.TestFunction(V)
x = ufl.SpatialCoordinate(msh)
f = 10 * ufl.exp(-((x[0] - 0.5) ** 2) / 0.01)
L = fem.form(f * v * dx)
print(fem.assemble_scalar(L))
No matter what degree I choose, this implementation runs smoothly.
However, when I attempt a similar approach using the C++ interface, I encounter issues. I construct the form using UFL and Basix as follows:
from basix.ufl import element
from basix import LagrangeVariant
from ufl import *
cell = "interval"
degree_cg = 3
e = element("Lagrange", cell, degree_cg, LagrangeVariant.equispaced)
coord = element("Lagrange", cell, 1, shape=(1,))
mesh = Mesh(coord)
V = FunctionSpace(mesh, e)
v = TestFunction(V)
f = Coefficient(V)
a = f * v * dx
Then, in C++, I create and assemble the form as:
auto a = std::make_shared<Form<T,U>>(fem::create_form<T,U>(*form_test_1D_P3_gauss1, {V_}, {{"f", Ff_}}, {}, {}));
T g = dolfinx::fem::assemble_scalar(*a);
This works fine for polynomial degrees 1 and 2. However, when I use degree 3, I encounter the following error:
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://petsc.org/release/faq/#valgrind and https://petsc.org/release/faq/
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run
[0]PETSC ERROR: to get more information on the crash.
[0]PETSC ERROR: Run with -malloc_debug to check if memory corruption is causing the crash.
Abort(59) on node 0 (rank 0 in comm 0): application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0
It seems like the issue is specific to higher-order elements, possibly related to quadrature or DOF mapping. I’d appreciate any insights into what might be causing this or suggestions for resolving it.