Hello, I am trying to run old codes in the new 0.8.0 version and I have an issue with the function gmshio.model_to_mesh. Please find my code bellow.
import gmsh
from mpi4py import MPI
from dolfinx.io import gmshio, XDMFFile
Lx = 1.
Ly = .5
Lcrack = 0.3
lc = 0.1
dist_min = .1
dist_max = .3
refinement_ratio = 10
gdim = 2
mesh_comm = MPI.COMM_WORLD
model_rank = 0
gmsh.initialize()
facet_tags = {"left": 1, "right": 2, "top": 3, "crack": 4, "bottom_no_crack": 5}
cell_tags = {"all": 20}
if mesh_comm.rank == model_rank:
model = gmsh.model()
model.add("Rectangle")
model.setCurrent("Rectangle")
# Create the points
p1 = model.geo.addPoint(0.0, 0.0, 0, lc)
p2 = model.geo.addPoint(Lcrack, 0.0, 0, lc)
p3 = model.geo.addPoint(Lx, 0, 0, lc)
p4 = model.geo.addPoint(Lx, Ly, 0, lc)
p5 = model.geo.addPoint(0, Ly, 0, lc)
# Create the lines
l1 = model.geo.addLine(p1, p2, tag=facet_tags["crack"])
l2 = model.geo.addLine(p2, p3, tag=facet_tags["bottom_no_crack"])
l3 = model.geo.addLine(p3, p4, tag=facet_tags["right"])
l4 = model.geo.addLine(p4, p5, tag=facet_tags["top"])
l5 = model.geo.addLine(p5, p1, tag=facet_tags["left"])
# Create the surface
cloop1 = model.geo.addCurveLoop([l1, l2, l3, l4, l5])
surface_1 = model.geo.addPlaneSurface([cloop1])
# Define the mesh size and fields for the mesh refinement
model.mesh.field.add("Distance", 1)
model.mesh.field.setNumbers(1, "NodesList", [p2])
model.mesh.field.add("Threshold", 2)
model.mesh.field.setNumber(2, "IField", 1)
model.mesh.field.setNumber(2, "LcMin", lc / refinement_ratio)
model.mesh.field.setNumber(2, "LcMax", lc)
model.mesh.field.setNumber(2, "DistMin", dist_min)
model.mesh.field.setNumber(2, "DistMax", dist_max)
model.mesh.field.setAsBackgroundMesh(2)
model.geo.synchronize()
# Assign mesh and facet tags
surface_entities = [entity[1] for entity in model.getEntities(2)]
model.addPhysicalGroup(2, surface_entities, tag=cell_tags["all"])
model.setPhysicalName(2, 2, "Rectangle surface")
model.mesh.generate(gdim)
for (key,value) in facet_tags.items():
model.addPhysicalGroup(1, [value], tag=value)
model.setPhysicalName(1, value, key)
msh, cell_tags, facet_tags = gmshio.model_to_mesh(model, mesh_comm, model_rank, gdim=gdim)
I obtain the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File ~/anaconda3/envs/fenicsx-cism-2024/lib/python3.12/site-packages/dolfinx/fem/element.py:91, in _(e)
90 try:
---> 91 return CoordinateElement(_cpp.fem.CoordinateElement_float32(e._e))
92 except TypeError:
TypeError: __init__(): incompatible function arguments. The following argument types are supported:
1. __init__(self, celltype: dolfinx.cpp.mesh.CellType, degree: int) -> None
2. __init__(self, element: basix::FiniteElement<float>) -> None
3. __init__(self, celltype: dolfinx.cpp.mesh.CellType, degree: int, variant: int) -> None
Invoked with types: dolfinx.cpp.fem.CoordinateElement_float32, basix._basixcpp.FiniteElement_float64
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Cell In[6], line 1
----> 1 msh, cell_tags, facet_tags = gmshio.model_to_mesh(model, mesh_comm, model_rank, gdim=gdim)
File ~/anaconda3/envs/fenicsx-cism-2024/lib/python3.12/site-packages/dolfinx/io/gmshio.py:293, in model_to_mesh(model, comm, rank, gdim, partitioner, dtype)
291 gmsh_cell_perm = cell_perm_array(_cpp.mesh.to_type(str(ufl_domain.ufl_cell())), num_nodes)
292 cells = cells[:, gmsh_cell_perm].copy()
--> 293 mesh = create_mesh(comm, cells, x[:, :gdim].astype(dtype, copy=False), ufl_domain, partitioner)
295 # Create MeshTags for cells
296 local_entities, local_values = distribute_entity_data(
297 mesh._cpp_object, mesh.topology.dim, cells, cell_values
298 )
File ~/anaconda3/envs/fenicsx-cism-2024/lib/python3.12/site-packages/dolfinx/mesh.py:407, in create_mesh(comm, cells, x, e, partitioner)
404 try:
405 # e is a UFL domain
406 e_ufl = e.ufl_coordinate_element() # type: ignore
--> 407 cmap = _coordinate_element(e_ufl.basix_element) # type: ignore
408 domain = e
409 dtype = cmap.dtype
File ~/anaconda3/envs/fenicsx-cism-2024/lib/python3.12/functools.py:907, in singledispatch.<locals>.wrapper(*args, **kw)
903 if not args:
904 raise TypeError(f'{funcname} requires at least '
905 '1 positional argument')
--> 907 return dispatch(args[0].__class__)(*args, **kw)
File ~/anaconda3/envs/fenicsx-cism-2024/lib/python3.12/site-packages/dolfinx/fem/element.py:93, in _(e)
91 return CoordinateElement(_cpp.fem.CoordinateElement_float32(e._e))
92 except TypeError:
---> 93 return CoordinateElement(_cpp.fem.CoordinateElement_float64(e._e))
TypeError: __init__(): incompatible function arguments. The following argument types are supported:
1. __init__(self, celltype: dolfinx.cpp.mesh.CellType, degree: int) -> None
2. __init__(self, element: basix::FiniteElement<double>) -> None
3. __init__(self, celltype: dolfinx.cpp.mesh.CellType, degree: int, variant: int) -> None
Invoked with types: dolfinx.cpp.fem.CoordinateElement_float64, basix._basixcpp.FiniteElement_float64
Many thanks in advance for your help!
best,
Claire