When trying to create mesh using gmsh I am getting PETSC ERROR

from mpi4py import MPI
import numpy as np
import ufl
import gmsh
import dolfinx
from mpi4py import MPI
from dolfinx.io import (VTXWriter, distribute_entity_data, gmshio)
from dolfinx.fem.petsc import LinearProblem
from basix.ufl import element, mixed_element
from dolfinx import default_scalar_type, plot
from dolfinx.fem import (functionspace, dirichletbc)


# Physical parameters
D = 1
Ht = 1.62 # height till top
Hb = 1.9 # height till bottom

L = 6
H = Ht+Hb
c_x = 0
c_y = 0
r = D/2

# Numerical parameters
resolution = 0.1  # Target characteristic length factor #0.05


# EPS = np.finfo(float).eps  # Machine epsilon for float

model_rank = 0
mesh_comm = MPI.COMM_WORLD

gdim=2

# Create gmsh geometry
gmsh.initialize()

# Create channel
rectangle = gmsh.model.occ.addRectangle(-L/2, -Hb, 0, L, H)

# Create circle
obstacle = gmsh.model.occ.addDisk(c_x, c_y, 0, r, r)


gmsh.model.occ.cut([(gdim, rectangle)], [(gdim, obstacle)])
gmsh.model.occ.synchronize()



# # Set mesh resolution
gmsh.option.setNumber("Mesh.CharacteristicLengthFactor", resolution)
gmsh.option.setNumber("Mesh.Algorithm", 8)
gmsh.option.setNumber("Mesh.RecombinationAlgorithm", 2)
gmsh.option.setNumber("Mesh.RecombineAll", 1)
gmsh.option.setNumber("Mesh.SubdivisionAlgorithm", 1)
gmsh.model.mesh.generate(gdim)
gmsh.model.mesh.setOrder(2)
gmsh.model.mesh.optimize("Netgen")
# 
# 
gmsh.write("mesh2.msh")
# 
# # gmsh.fltk().run()
# # Convert gmsh mesh to dolfinx mesh
mesh_obj, _, _ = gmshio.model_to_mesh(gmsh.model, mesh_comm, model_rank, gdim=gdim)
gmsh.finalize()

Getting this error

Info    : Meshing 1D...
Info    : [  0%] Meshing curve 5 (Ellipse)
Info    : [ 20%] Meshing curve 6 (Line)
Info    : [ 40%] Meshing curve 7 (Line)
Info    : [ 60%] Meshing curve 8 (Line)
Info    : [ 80%] Meshing curve 9 (Line)
Info    : Done meshing 1D (Wall 0.000345293s, CPU 9e-05s)
Info    : Meshing 2D...
Info    : Meshing surface 1 (Plane, Frontal-Delaunay for Quads)
[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.
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
with errorcode 59.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------

Process ended with exit code 59.

Drop every FEniCSx related import and command to confirm that the error is still there.

from mpi4py import MPI
import numpy as np
import gmsh

# Physical parameters
D = 1
Ht = 1.62 # height till top
Hb = 1.9 # height till bottom

L = 6
H = Ht+Hb
c_x = 0
c_y = 0
r = D/2

# Numerical parameters
resolution = 0.1  # Target characteristic length factor #0.05


# EPS = np.finfo(float).eps  # Machine epsilon for float

model_rank = 0
mesh_comm = MPI.COMM_WORLD

gdim=2

# Create gmsh geometry
gmsh.initialize()

# Create channel
rectangle = gmsh.model.occ.addRectangle(-L/2, -Hb, 0, L, H)

# Create circle
obstacle = gmsh.model.occ.addDisk(c_x, c_y, 0, r, r)


gmsh.model.occ.cut([(gdim, rectangle)], [(gdim, obstacle)])
gmsh.model.occ.synchronize()



# # Set mesh resolution
gmsh.option.setNumber("Mesh.CharacteristicLengthFactor", resolution)
gmsh.option.setNumber("Mesh.Algorithm", 8)
gmsh.option.setNumber("Mesh.RecombinationAlgorithm", 2)
gmsh.option.setNumber("Mesh.RecombineAll", 1)
gmsh.option.setNumber("Mesh.SubdivisionAlgorithm", 1)
gmsh.model.mesh.generate(gdim)
gmsh.model.mesh.setOrder(2)
gmsh.model.mesh.optimize("Netgen")

gmsh.finalize()

and get

[ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x3f5d0) [0x7f54bc5b85d0]
[ 1] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_ZNK14MElementOctree4findEdddib+0x1e) [0x7f54b2cb720e]
[ 2] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_ZNK14backgroundMesh8getAngleEddd+0x5a) [0x7f54b2e1939a]
[ 3] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_ZN5MTri3C2EP9MTriangledP8SMetric3P13bidimMeshDataP5GFace+0xa7b) [0x7f54b2d646cb]
[ 4] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_Z33buildMeshGenerationDataStructuresP5GFaceRSt3setIP5MTri314compareTri3PtrSaIS3_EER13bidimMeshData+0x1333) [0x7f54b2d76633]
[ 5] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_Z25bowyerWatsonFrontalLayersP5GFacebPSt3mapIP7MVertexS3_St4lessIS3_ESaISt4pairIKS3_S3_EEEPS1_IS3_7SPoint2S5_SaIS6_IS7_SC_EEE+0x1ba) [0x7f54b2d6a23a]
[ 6] /lib/x86_64-linux-gnu/libgmsh.so.4.12(+0x737077) [0x7f54b2d37077]
[ 7] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_ZN9meshGFaceclEP5GFaceb+0x3d3) [0x7f54b2d40e53]
[ 8] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_ZN5GFace4meshEb+0x67) [0x7f54b2b0cad7]
[ 9] /lib/x86_64-linux-gnu/libgmsh.so.4.12(+0x716c8b) [0x7f54b2d16c8b]
[10] /lib/x86_64-linux-gnu/libgomp.so.1(GOMP_parallel+0x46) [0x7f54b8021866]
[11] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_Z12GenerateMeshP6GModeli+0xa6f) [0x7f54b2d1ed5f]
[12] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_ZN6GModel4meshEi+0x29) [0x7f54b2b5f2d9]
[13] /lib/x86_64-linux-gnu/libgmsh.so.4.12(_ZN4gmsh5model4mesh8generateEi+0x34) [0x7f54b29993b4]
[14] /lib/x86_64-linux-gnu/libgmsh.so.4.12(gmshModelMeshGenerate+0x18) [0x7f54b34cc328]

Therefore, this is an error in gmsh, and not in dolfinx. Hence support must be asked on the gmsh support channel Issues · gmsh / gmsh · GitLab and not here.

1 Like