Hi all,
I am rather new to Fenicsx and currently running into a problem related to Dirichlet boundary conditions for mixed-element spaces. I’ve condensed the problem to the following MWE
# %%
import dolfinx as dfx
from dolfinx.fem.petsc import NonlinearProblem
from dolfinx.nls.petsc import NewtonSolver
from mpi4py.MPI import COMM_WORLD as comm
import numpy as np
import ufl
mesh = dfx.mesh.create_unit_square(comm, 128, 128)
P1 = ufl.FiniteElement("CG", mesh.ufl_cell(), 1)
mixed_element = P1 * P1
V = dfx.fem.FunctionSpace(mesh, mixed_element)
# %%
u = dfx.fem.Function(V)
u0, u1 = ufl.split(u) # <- for use in form assembly, use ufl.split, not dfx.fem.Function.split!
v0, v1 = ufl.TestFunctions(V)
# %%
def boundary_locator(x):
return np.isclose(x[1], 0.) | np.isclose(x[1], 1.)
W, _ = V.sub(0).collapse()
uD = dfx.fem.Function(V)
uD.sub(0).interpolate(lambda x: x[1])
uD.sub(1).interpolate(lambda x: x[1] + 1)
# Facets
# ------
tdim = mesh.topology.dim - 1
facets = dfx.mesh.locate_entities_boundary(mesh, tdim, boundary_locator)
dofs0 = dfx.fem.locate_dofs_topological((V.sub(0), W), tdim, facets)
dofs1 = dfx.fem.locate_dofs_topological((V.sub(1), W), tdim, facets)
# Boundary conditions
# -------------------
bcs = [
dfx.fem.dirichletbc(uD.sub(0).collapse(), dofs0, V.sub(0)),
dfx.fem.dirichletbc(uD.sub(1).collapse(), dofs1, V.sub(1))
]
# This works.
dfx.fem.set_bc(u.vector, bcs)
# %%
F = ufl.inner(ufl.grad(u0), ufl.grad(v0)) * ufl.dx
F += ufl.inner(ufl.grad(u1), ufl.grad(v1)) * ufl.dx
# %%
problem = NonlinearProblem(F, u, bcs)
solver = NewtonSolver(comm, problem)
# %%
solver.solve(u) # <- Here, we got a segmentation fault.
for which I obtain the segfault
[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
I am running the code with the conda-forge package fenics-dolfinx-0.7.3 on MacOS.
Not sure, how to hunt down the error. Any help solving this issue would be highly appreciated!
Thanks a lot,
Tom