Dolfinx locate _dof's_geometrically fails on mesh imported from gmsh

Hello,
I am trying to import a mesh from gmsh and locate the dof’s geometrically. However, the code fails with 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 [0]PETSC ERROR: or try http://valgrind.org on GNU/linux and Apple Mac OS X to find memory corruption errors [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. application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0 [unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=59 : system msg for write_line failure : Bad file descriptor

Please note that I am using the gmsh _model_to_mesh from the gmsh_helpers file by @dokken found here (https://jsdokken.com/converted_files/gmsh_helpers.py). Here is the MWE to reproduce the error:

import numpy as np
from gmsh_helpers import gmsh_model_to_mesh
import pygmsh
import gmsh
import dolfinx
import ufl

def clamped_boundary(x):
    return np.isclose(x[1], 0)

with pygmsh.occ.Geometry() as geom:
    geom.characteristic_length_max = 1.2
    geom.characteristic_length_min = 0.8
    obj1 = geom.add_rectangle([0, 0, 0],1,1)
    geom.add_physical(obj1, "Plate")
    mesh2 = geom.generate_mesh(dim=2)
    node_ids = []
    mesh, cell_tags = gmsh_model_to_mesh(gmsh.model, cell_data=True, gdim=2)
deg = 1
We = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), deg)
Te = ufl.VectorElement("Lagrange", mesh.ufl_cell(), deg)
V = dolfinx.FunctionSpace(mesh, ufl.MixedElement([We,Te]))
dofs = dolfinx.fem.locate_dofs_geometrical(V, clamped_boundary)

Kindly help in figuring out what’s the problem here. Thank you.

This has nothing to do with the mesh, but rather with using the mixed space in locate_dofs_geometrical.
I’ve made an issue at: `locate_dofs_geometrical` segfaults on mixedelements · Issue #1764 · FEniCS/dolfinx · GitHub
and I’ll have a look into it.

A work-around for now is to spilt the boundary condition into the sub spaces, and use locate_dofs_geometrical on those:

import numpy as np
import dolfinx
from mpi4py import MPI
import ufl

def clamped_boundary(x):
    return np.isclose(x[1], 0)

mesh =dolfinx.UnitSquareMesh(MPI.COMM_WORLD, 10, 10)
deg = 1
We = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), deg)
Te = ufl.VectorElement("Lagrange", mesh.ufl_cell(), deg)
V = dolfinx.FunctionSpace(mesh, ufl.MixedElement([We,Te]))
Vs = [V.sub(i).collapse() for i in range(V.num_sub_spaces())]
dofs = [dolfinx.fem.locate_dofs_geometrical((V.sub(i), Vs[i]), clamped_boundary) for i in range(V.num_sub_spaces())]
print(dofs)
2 Likes