# SEGV on Dirichlet boundary conditions for mixed element spaces

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)

# %%

# %%
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: 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

1 Like

Can’t replicate on linux, the code converges in one iteration.

Maybe try to move

before the dolfinx imports, since that was the motivation for a patch release to 0.7.*

Thanks for the reply, but nope, that didn’t do the trick on MacOS.
Will try on Linux tonight, thanks for that hint!

I’ve checked, and yes, it runs on linux (with dolfinx-0.7.2).

@minrk any intuition why the code above would segfault on macos?

@tomd please provide @minrk instructions on how you installed dolfinx in conda, and if you have any additional package in your environment.

I’ve installed with `conda install -c conda-forge fenics-dolfinx mpich pyvista` in a dedicated conda env.

The output of `conda list` is:

``````# packages in environment at /Users/<>/anaconda3/envs/fenicsx-env:
#
# Name                    Version                   Build  Channel
aiohttp                   3.9.3           py312he37b823_0    conda-forge
aiosignal                 1.3.1              pyhd8ed1ab_0    conda-forge
aom                       3.8.1                h078ce10_0    conda-forge
appnope                   0.1.4              pyhd8ed1ab_0    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
attrs                     23.2.0             pyh71513ae_0    conda-forge
blosc                     1.21.5               hc338f07_0    conda-forge
brotli-python             1.1.0           py312h9f69965_1    conda-forge
bzip2                     1.0.8                h93a5062_5    conda-forge
c-ares                    1.27.0               h93a5062_0    conda-forge
c-blosc2                  2.13.2               ha57e6be_0    conda-forge
ca-certificates           2024.3.11            hca03da5_0
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
cairo                     1.18.0               hd1e100b_0    conda-forge
cctools_osx-arm64         973.0.1             h62378fb_16    conda-forge
certifi                   2024.2.2        py312hca03da5_0
cffi                      1.16.0          py312h8e38eb3_0    conda-forge
cftime                    1.6.3           py312hf635c46_0    conda-forge
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
clang                     16.0.6               h30cc82d_5    conda-forge
clang-16                  16.0.6          default_he012953_5    conda-forge
clang_impl_osx-arm64      16.0.6               hc421ffc_9    conda-forge
clang_osx-arm64           16.0.6               h54d7cd3_9    conda-forge
clangxx                   16.0.6          default_h4cf2255_5    conda-forge
clangxx_impl_osx-arm64    16.0.6               hcd7bac0_9    conda-forge
clangxx_osx-arm64         16.0.6               h54d7cd3_9    conda-forge
colorcet                  3.1.0                    pypi_0    pypi
comm                      0.2.1              pyhd8ed1ab_0    conda-forge
compiler-rt               16.0.6               h3808999_2    conda-forge
compiler-rt_osx-arm64     16.0.6               h3808999_2    conda-forge
contourpy                 1.2.0           py312h76e736e_0    conda-forge
cycler                    0.12.1             pyhd8ed1ab_0    conda-forge
debugpy                   1.8.1           py312h20a0b95_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
double-conversion         3.3.0                h13dd4ca_0    conda-forge
eigen                     3.4.0                h1995070_0    conda-forge
exceptiongroup            1.2.0              pyhd8ed1ab_2    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
expat                     2.5.0                hb7217d7_1    conda-forge
fenics-basix              0.7.0           py312hb23e587_1    conda-forge
fenics-basix-pybind11-abi 0.4.16               hfeba48c_1    conda-forge
fenics-dolfinx            0.7.3           py312hcb5ac4e_101    conda-forge
fenics-ffcx               0.7.0              pyh4af843d_0    conda-forge
fenics-libbasix           0.7.0                hb1687fd_1    conda-forge
fenics-libdolfinx         0.7.3              h58499c2_101    conda-forge
fenics-ufcx               0.7.0                h4af843d_0    conda-forge
fenics-ufl                2023.2.0           pyhd8ed1ab_0    conda-forge
ffmpeg                    6.1.1           gpl_h31ea89b_104    conda-forge
fftw                      3.3.10          mpi_mpich_h0cb5807_8    conda-forge
fltk                      1.3.9                h31b9a01_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 h77eed37_1    conda-forge
fontconfig                2.14.2               h82840c6_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.49.0          py312he37b823_0    conda-forge
freeimage                 3.18.0              h703098a_19    conda-forge
fribidi                   1.0.10               h27ca646_0    conda-forge
frozenlist                1.4.1           py312he37b823_0    conda-forge
gettext                   0.21.1               h0186832_0    conda-forge
gl2ps                     1.4.2                h17b34a0_0    conda-forge
glew                      2.1.0                h9f76cd9_2    conda-forge
glib                      2.78.4               h1059232_0    conda-forge
glib-tools                2.78.4               h1059232_0    conda-forge
gmp                       6.3.0                h965bd2d_0    conda-forge
gmsh                      4.12.2                   pypi_0    pypi
gnutls                    3.7.9                hd26332c_0    conda-forge
graphite2                 1.3.13            h9f76cd9_1001    conda-forge
gst-plugins-base          1.22.9               h09b4b5e_0    conda-forge
gstreamer                 1.22.9               h551c6ff_0    conda-forge
h5py                      3.10.0          nompi_py312hac0f6fd_101    conda-forge
harfbuzz                  8.3.0                h8f0ba13_0    conda-forge
hdf4                      4.2.15               h2ee6834_7    conda-forge
hdf5                      1.14.3          mpi_mpich_h754b83b_0    conda-forge
hypre                     2.28.0          mpi_mpich_hd226f01_0    conda-forge
icu                       73.2                 hc8870d7_0    conda-forge
idna                      3.6                pyhd8ed1ab_0    conda-forge
imageio                   2.34.0             pyh4b66e23_0    conda-forge
imageio-ffmpeg            0.4.9              pyhd8ed1ab_0    conda-forge
imath                     3.1.10               h1059232_0    conda-forge
ipykernel                 6.29.3             pyh3cd1d5f_0    conda-forge
ipympl                    0.9.3              pyhd8ed1ab_0    conda-forge
ipython                   8.22.1             pyh707e725_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                8.1.2              pyhd8ed1ab_0    conda-forge
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jsoncpp                   1.9.5                hc021e02_1    conda-forge
jupyter_client            8.6.0              pyhd8ed1ab_0    conda-forge
jupyter_core              5.7.1           py312h81bd7bf_0    conda-forge
jupyterlab_widgets        3.0.10             pyhd8ed1ab_0    conda-forge
jxrlib                    1.1                  h93a5062_3    conda-forge
kahip                     3.16            py312h18d51ab_0    conda-forge
kahip-python              3.16            py312h2c784d2_0    conda-forge
kiwisolver                1.4.5           py312h389731b_1    conda-forge
krb5                      1.21.2               h92f50d5_0    conda-forge
lame                      3.100             h1a8c8d9_1003    conda-forge
lcms2                     2.16                 ha0e7c42_0    conda-forge
ld64_osx-arm64            609                 ha4bd21c_16    conda-forge
lerc                      4.0.0                h9a09cb3_0    conda-forge
libabseil                 20240116.1      cxx17_hebf3989_1    conda-forge
libaec                    1.1.2                h13dd4ca_1    conda-forge
libass                    0.17.1               hf7da4fe_1    conda-forge
libblas                   3.9.0           21_osxarm64_openblas    conda-forge
libboost                  1.82.0               h72cdd8a_6    conda-forge
libboost-devel            1.82.0               hf450f58_6    conda-forge
libcblas                  3.9.0           21_osxarm64_openblas    conda-forge
libclang                  15.0.7          default_hd209bcb_4    conda-forge
libclang-cpp16            16.0.6          default_he012953_5    conda-forge
libclang13                15.0.7          default_ha49e599_4    conda-forge
libcurl                   8.5.0                h2d989ff_0    conda-forge
libcxx                    16.0.6               h4653b0c_0    conda-forge
libedit                   3.1.20191231         hc8eb9b7_2    conda-forge
libev                     4.33                 h93a5062_2    conda-forge
libexpat                  2.5.0                hb7217d7_1    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgfortran               5.0.0           13_2_0_hd922786_3    conda-forge
libgfortran5              13.2.0               hf226fd6_3    conda-forge
libglib                   2.78.4               h1635a5e_0    conda-forge
libhwloc                  2.9.3           default_h4394839_1009    conda-forge
libiconv                  1.17                 h0d3ecfb_2    conda-forge
libidn2                   2.3.7                h93a5062_0    conda-forge
liblapack                 3.9.0           21_osxarm64_openblas    conda-forge
libllvm15                 15.0.7               h2621b3d_4    conda-forge
libllvm16                 16.0.6               haab561b_3    conda-forge
libnetcdf                 4.9.2           nompi_h291a7c2_113    conda-forge
libnghttp2                1.58.0               ha4dd798_1    conda-forge
libogg                    1.3.4                h27ca646_1    conda-forge
libopenblas               0.3.26          openmp_h6c19121_0    conda-forge
libopenvino-auto-batch-plugin 2023.3.0             hc9f00d9_2    conda-forge
libopenvino-auto-plugin   2023.3.0             hc9f00d9_2    conda-forge
libopenvino-hetero-plugin 2023.3.0             hf483cef_2    conda-forge
libopenvino-ir-frontend   2023.3.0             hf483cef_2    conda-forge
libopenvino-onnx-frontend 2023.3.0             h9363200_2    conda-forge
libopenvino-pytorch-frontend 2023.3.0             hebf3989_2    conda-forge
libopenvino-tensorflow-frontend 2023.3.0             h64b43cf_2    conda-forge
libopenvino-tensorflow-lite-frontend 2023.3.0             hebf3989_2    conda-forge
libopus                   1.3.1                h27ca646_1    conda-forge
libpng                    1.6.43               h091b4b1_0    conda-forge
libpq                     16.2                 h0f8b458_0    conda-forge
libprotobuf               4.25.2               hbfab5d5_1    conda-forge
libptscotch               7.0.4                h5340af2_1    conda-forge
libraw                    0.21.1               h2ee6834_2    conda-forge
libscotch                 7.0.4                hc938e73_1    conda-forge
libsodium                 1.0.18               h27ca646_1    conda-forge
libsqlite                 3.45.1               h091b4b1_0    conda-forge
libssh2                   1.11.0               h7a5bd25_0    conda-forge
libtasn1                  4.19.0               h1a8c8d9_0    conda-forge
libtheora                 1.1.1             h3422bc3_1005    conda-forge
libtiff                   4.6.0                ha8a6c65_2    conda-forge
libunistring              0.9.10               h3422bc3_0    conda-forge
libvorbis                 1.3.7                h9f76cd9_0    conda-forge
libvpx                    1.13.1               hb765f3a_0    conda-forge
libxcb                    1.15                 hf346824_0    conda-forge
libxml2                   2.12.5               h0d0cfa8_0    conda-forge
libzip                    1.10.1               ha0bc3c6_3    conda-forge
libzlib                   1.2.13               h53f4e23_5    conda-forge
llvm-openmp               17.0.6               hcd81f8e_0    conda-forge
llvm-tools                16.0.6               haab561b_3    conda-forge
loguru                    0.7.2           py312h81bd7bf_1    conda-forge
lz4-c                     1.9.4                hb7217d7_0    conda-forge
markdown-it-py            3.0.0              pyhd8ed1ab_0    conda-forge
matplotlib-base           3.8.3           py312ha6faf65_0    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
mdurl                     0.1.2              pyhd8ed1ab_0    conda-forge
meshio                    5.3.5              pyhd8ed1ab_0    conda-forge
metis                     5.1.1                hebf3989_2    conda-forge
more-itertools            10.2.0             pyhd8ed1ab_0    conda-forge
mpfr                      4.2.1                h9546428_0    conda-forge
mpi                       1.0                       mpich    conda-forge
mpi4py                    3.1.5           py312h8d05a6a_0    conda-forge
mpich                     4.2.0              hd4b5bf3_100    conda-forge
multidict                 6.0.5           py312h670c8ac_0    conda-forge
mumps-include             5.6.2                hce30654_2    conda-forge
mumps-mpi                 5.6.2                hfea86b6_2    conda-forge
mysql-common              8.0.33               hf9e6398_6    conda-forge
mysql-libs                8.0.33               he3dca8b_6    conda-forge
ncurses                   6.4                  h463b476_2    conda-forge
nest-asyncio              1.6.0              pyhd8ed1ab_0    conda-forge
netcdf4                   1.6.5           nompi_py312h9035142_100    conda-forge
nettle                    3.9.1                h40ed0f5_0    conda-forge
nlohmann_json             3.11.2               h2e04ded_0    conda-forge
nspr                      4.35                 hb7217d7_0    conda-forge
nss                       3.98                 h5ce2875_0    conda-forge
numpy                     1.26.4          py312h8442bc7_0    conda-forge
occt                      7.7.2           all_h1e2436f_201    conda-forge
openexr                   3.2.2                h73dd21e_0    conda-forge
openh264                  2.4.1                hebf3989_0    conda-forge
openjpeg                  2.5.1                h9f1df11_0    conda-forge
openssl                   3.2.1                h0d3ecfb_1    conda-forge
p11-kit                   0.24.1               h29577a5_0    conda-forge
packaging                 23.2               pyhd8ed1ab_0    conda-forge
parmetis                  4.0.3             hefa2a9d_1005    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pcre2                     10.42                h26f9a81_0    conda-forge
petsc                     3.20.5          real_h7646cce_100    conda-forge
petsc4py                  3.20.4          real_hd567e68_100    conda-forge
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.2.0          py312hac22aec_0    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
pixman                    0.43.2               hebf3989_0    conda-forge
pkg-config                0.29.2            hab62308_1008    conda-forge
platformdirs              4.2.0              pyhd8ed1ab_0    conda-forge
pooch                     1.8.1              pyhd8ed1ab_0    conda-forge
proj                      9.3.1                h93d94ba_0    conda-forge
prompt-toolkit            3.0.42             pyha770c72_0    conda-forge
psutil                    5.9.8           py312he37b823_0    conda-forge
ptscotch                  7.0.4                heaa5b5c_1    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pugixml                   1.14                 h13dd4ca_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pygments                  2.17.2             pyhd8ed1ab_0    conda-forge
pygmsh                    7.1.17                   pypi_0    pypi
pymobimp                  0.1                       dev_0    <develop>
pyparsing                 3.1.1              pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
python                    3.12.2          hdf0ec26_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-gmsh               4.12.2               h57928b3_0    conda-forge
python_abi                3.12                    4_cp312    conda-forge
pyvista                   0.43.3             pyhd8ed1ab_0    conda-forge
pyyaml                    6.0.1           py312h02f2b3b_1    conda-forge
pyzmq                     25.1.2          py312h1edf716_0    conda-forge
qt-main                   5.15.8              h6bf1bb6_19    conda-forge
rapidjson                 1.1.0             hc88da5d_1002    conda-forge
requests                  2.31.0             pyhd8ed1ab_0    conda-forge
rich                      13.7.1             pyhd8ed1ab_0    conda-forge
scalapack                 2.2.0                hb170938_1    conda-forge
scipy                     1.12.0          py312h9d7df2b_2    conda-forge
scooby                    0.9.2              pyhd8ed1ab_0    conda-forge
scotch                    7.0.4                heaa5b5c_1    conda-forge
setuptools                69.1.1             pyhd8ed1ab_0    conda-forge
sigtool                   0.1.3                h44b9a77_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
slepc                     3.20.1          real_h35c204a_102    conda-forge
slepc4py                  3.20.1          real_hec853a8_100    conda-forge
snappy                    1.1.10               h17c5cce_0    conda-forge
sqlite                    3.45.1               hf2abe2d_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
suitesparse               5.10.1               h88be0ae_2    conda-forge
superlu                   5.2.2                hc615359_0    conda-forge
superlu_dist              8.2.1                h6be7e34_0    conda-forge
svt-av1                   1.8.0                h463b476_0    conda-forge
tapi                      1100.0.11            he4954df_0    conda-forge
tbb                       2021.11.0            h2ffa867_1    conda-forge
tbb-devel                 2021.11.0            hf0e5eac_1    conda-forge
tk                        8.6.13               h5083fa2_1    conda-forge
traitlets                 5.14.1             pyhd8ed1ab_0    conda-forge
trame                     3.5.2              pyhd8ed1ab_0    conda-forge
trame-client              2.16.0             pyhd8ed1ab_0    conda-forge
trame-components          2.2.1              pyhd8ed1ab_0    conda-forge
trame-deckgl              2.0.2              pyhd8ed1ab_0    conda-forge
trame-markdown            2.0.2              pyhd8ed1ab_0    conda-forge
trame-matplotlib          2.0.2              pyhd8ed1ab_0    conda-forge
trame-plotly              2.1.1              pyhd8ed1ab_0    conda-forge
trame-rca                 0.4.1              pyhd8ed1ab_0    conda-forge
trame-router              2.1.1              pyhd8ed1ab_0    conda-forge
trame-server              2.17.2             pyhd8ed1ab_0    conda-forge
trame-simput              2.4.1              pyhd8ed1ab_0    conda-forge
trame-vega                2.1.0              pyhd8ed1ab_0    conda-forge
trame-vtk                 2.8.5              pyhd8ed1ab_0    conda-forge
trame-vuetify             2.4.2              pyhd8ed1ab_0    conda-forge
typing_extensions         4.10.0             pyha770c72_0    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
urllib3                   2.2.1              pyhd8ed1ab_0    conda-forge
utfcpp                    4.0.5                hce30654_0    conda-forge
vtk                       9.2.6           qt_py312h1234567_220    conda-forge
vtk-base                  9.2.6           qt_py312h1234567_220    conda-forge
vtk-io-ffmpeg             9.2.6           qt_py312h1234567_220    conda-forge
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
wheel                     0.42.0             pyhd8ed1ab_0    conda-forge
widgetsnbextension        4.0.10             pyhd8ed1ab_0    conda-forge
x264                      1!164.3095           h57fd34a_2    conda-forge
x265                      3.5                  hbc6ce65_3    conda-forge
xorg-fixesproto           5.0               h3422bc3_1002    conda-forge
xorg-kbproto              1.0.7             h27ca646_1002    conda-forge
xorg-libx11               1.8.7                hfd9643e_0    conda-forge
xorg-libxdmcp             1.1.3                h27ca646_0    conda-forge
xorg-libxext              1.3.4                h1a8c8d9_2    conda-forge
xorg-libxfixes            5.0.3             h3422bc3_1004    conda-forge
xorg-renderproto          0.11.1            h27ca646_1002    conda-forge
xorg-xextproto            7.3.0             h1a8c8d9_1003    conda-forge
xorg-xproto               7.0.31            h27ca646_1007    conda-forge
xz                        5.2.6                h57fd34a_0    conda-forge
yaml                      0.2.5                h3422bc3_2    conda-forge
yarl                      1.9.4           py312he37b823_0    conda-forge
zeromq                    4.3.5                h965bd2d_0    conda-forge
zfp                       0.5.5                hcfdfaf5_8    conda-forge
zipp                      3.17.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h53f4e23_5    conda-forge
zlib-ng                   2.0.7                h1a8c8d9_0    conda-forge
zstd                      1.5.5                h4f39d0f_0    conda-forge
``````

I believe `metis 5.1.1` is the culprit. I’m not sure why this is getting picked up, because when I do a fresh install with the command given, I get `metis 5.1.0`. If you explicitly request `metis=5.1.0`, I believe things will be fixed. I believe the builds depending on metis 5.1.0 have been marked as broken, so shouldn’t get picked up by future installs. Perhaps there is some cached metadata, or this install was done a while ago?

1 Like