p1rx
August 19, 2023, 10:19am
1
Hi,
i am buzzled with an error that i get when trying to transform gmsh mesh to dolfinx with gmshio.model_to_mesh.
The error i get is:
---> meshD = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank)
--> cell_id = cell_information[perm_sort[-1]]["id"]
IndexError: index -1 is out of bounds for axis 0 with size 0
The minimal reproducible example for my problem:
def create_mesh_with_gmsh():
gmsh.initialize()
gmsh.model.add("two_squares")
# Omega1
Omega1 = gmsh.model.occ.addRectangle(-0.5, -0.5, 0, 1, 1)
gmsh.model.occ.synchronize()
# Omega2
sOmega2 = gmsh.model.occ.addRectangle(0.5, -0.5, 0, 1, 1)
gmsh.model.occ.synchronize()
# elem size
gmsh.option.setNumber("Mesh.ElementOrder", 1)
gmsh.option.setNumber("Mesh.CharacteristicLengthMin", 0.05)
gmsh.option.setNumber("Mesh.CharacteristicLengthMax", 0.05)
# Gen 2D mesh
gmsh.model.mesh.generate(2)
# Convert Gmsh --> dolfinx mesh
gdim = 2
gmsh_model_rank = 0
mesh_comm = MPI.COMM_WORLD
meshD = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank)
# gmsh.write("test_mesh.msh")
gmsh.finalize()
return meshD
meshD = create_mesh_with_gmsh()
Mesh saved and inspected in the gmsh gui looks ok.
Dolfinx version: 0.6.0
python-gmsh version: 4.11.1
dokken
August 19, 2023, 10:33am
2
You need to tag your volume (and potential surfaces) with physical markers, as explained in:
# geometry according to the unique index
perm_sort = np.argsort(indices)
assert np.all(indices[perm_sort] == np.arange(len(indices)))
return points[perm_sort]
def model_to_mesh(model: gmsh.model, comm: _MPI.Comm, rank: int, gdim: int = 3,
partitioner: typing.Optional[typing.Callable[
[_MPI.Comm, int, int, AdjacencyList_int32], AdjacencyList_int32]] = None,
dtype=default_real_type) -> typing.Tuple[
Mesh, _cpp.mesh.MeshTags_int32, _cpp.mesh.MeshTags_int32]:
"""Given a Gmsh model, take all physical entities of the highest
topological dimension and create the corresponding DOLFINx mesh.
In parallel, the gmsh model is processed on one MPI rank, and
the resulting mesh is distributed by DOLFINx. For performance,
this function should only be called once for large problems. For
re-use, it is recommended to save the mesh and corresponding
tags using XDMFFile after creation for efficient access.
Args:
model: Gmsh model.
p1rx
August 19, 2023, 11:17am
3
ok, i added physical tags for the surfaces:
gmsh.model.addPhysicalGroup(2, [Omega1], 1)
gmsh.model.addPhysicalGroup(2, [Omega2], 2)
but this produced an error:
---> 247 meshD = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank)
---> gmsh_cell_perm = cell_perm_array(_cpp.mesh.to_type(str(ufl_domain.ufl_cell())), num_nodes)
249 cells = cells[:, gmsh_cell_perm]
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. dolfinx.cpp.fem.CoordinateElement(celltype: dolfinx.cpp.mesh.CellType, degree: int)
2. dolfinx.cpp.fem.CoordinateElement(celltype: dolfinx.cpp.mesh.CellType, degree: int, variant: basix::element::lagrange_variant)
Invoked with: , 1,
dokken
August 19, 2023, 1:50pm
4
I would suggesting looking at this thread, as the error message is the same Error after gmshio.model_to_mesh - #4 by conpierce8
1 Like