[BUG] Writing a mesh using meshio results in KeyError: dtype('uint64') in _ansys.py
mildblimp opened this issue · 3 comments
Describe the bug
Creating a simple rectangle mesh using pygmsh
results in the following error
Traceback (most recent call last):
File "/.../rectangle.py", line 7, in <module>
mesh.write("rectangle.msh")
File "/usr/local/lib/python3.10/dist-packages/meshio/_mesh.py", line 241, in write
write(path_or_buf, self, file_format, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/meshio/_helpers.py", line 188, in write
return writer(filename, mesh, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/meshio/ansys/_ansys.py", line 442, in write
key = binary_dtypes[values.dtype] if binary else "12"
KeyError: dtype('uint64')
It can be circumvented by using pygmsh
's internal write function.
To Reproduce
Run the following script
import pygmsh
with pygmsh.geo.Geometry() as geom:
rec = geom.add_rectangle(0, 1, 0, 2, 0, mesh_size=0.05)
mesh = geom.generate_mesh()
mesh.write("rectangle.msh")
Diagnose
meshio==5.3.4
pygmsh==7.1.17
Just hit this issue myself. Looks like it is expecting the dtypes of mesh.cells[...].data
to be int32/int64.
Looks like the simplest workaround is to use the gmsh
write method as from here.
import gmsh
import pygmsh
with pygmsh.geo.Geometry() as geom:
rec = geom.add_rectangle(0, 1, 0, 2, 0, mesh_size=0.05)
mesh = geom.generate_mesh()
gmsh.write("rectangle.msh")
gmsh.clear()
Doesn't solve the underlying issue with mesh.write(...)
, but appears to be a clean solution in the interim.
Looks like the simplest workaround is to use the
gmsh
write method as from here.import gmsh import pygmsh with pygmsh.geo.Geometry() as geom: rec = geom.add_rectangle(0, 1, 0, 2, 0, mesh_size=0.05) mesh = geom.generate_mesh() gmsh.write("rectangle.msh") gmsh.clear()Doesn't solve the underlying issue with
mesh.write(...)
, but appears to be a clean solution in the interim.
@shinstra
Hi! I use you code but:
Traceback (most recent call last):
File ~\.conda\envs\pygmsh\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File d:\tmp\测试他人有限元库\test.py:28
gmsh.write("test.msh")
File ~\.conda\envs\pygmsh\lib\site-packages\gmsh.py:370 in write
raise Exception(logger.getLastError())
File ~\.conda\envs\pygmsh\lib\site-packages\gmsh.py:10614 in getLastError
raise Exception('Could not get last error')
Exception: Could not get last error
Error : Gmsh has not been initialized
Error : Gmsh has not been initialized
Did you omit some details?
How gmsh
know which mesh to write? (that means the variable mesh
is not a param for gmsh
)