pygmsh
pygmsh copied to clipboard
set_mesh_size_callback does not work with new version of gmsh
Hi @nschloe,
The sample problem in the README file no longer works:
import pygmsh
with pygmsh.geo.Geometry() as geom:
geom.add_polygon(
[
[-1.0, -1.0],
[+1.0, -1.0],
[+1.0, +1.0],
[-1.0, +1.0],
]
)
geom.set_mesh_size_callback(
lambda dim, tag, x, y, z: 6.0e-2 + 2.0e-1 * (x**2 + y**2)
)
mesh = geom.generate_mesh()
Basically, it seems that gmsh
is expecting 5 arguments in the callback functions, but 6 are given.
I am using gmsh v4.10.5 and pygmsh v7.1.17. No problem with gmsh v4.8.4, though. The fastest fix would be to add a version requirement in pyproject.toml
.
Below the full error:
Exception ignored on calling ctypes callback function: <function model.mesh.setSizeCallback.<locals>.<lambda> at 0x000001E8A714E3A0>
Traceback (most recent call last):
File "c:\Users\keurf\anaconda3\lib\site-packages\gmsh.py", line 3219, in <lambda>
api_callback_ = api_callback_type_(lambda dim, tag, x, y, z, lc, _ : callback(dim, tag, x, y, z, lc))
TypeError: <lambda>() takes 5 positional arguments but 6 were given
Output exceeds the [size limit](command:workbench.action.openSettings?[). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?9777202c-aab9-499c-8e72-01d361232c84)
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Input In [8], in <cell line: 4>()
5 geom.add_polygon(
6 [
7 [-1.0, -1.0],
(...)
11 ]
12 )
13 geom.set_mesh_size_callback(
14 lambda dim, tag, x, y, z: 6.0e-2 + 2.0e-1 * (x**2 + y**2)
15 )
---> 17 mesh = geom.generate_mesh()
File c:\Users\keurf\anaconda3\lib\site-packages\pygmsh\common\geometry.py:374, in CommonGeometry.generate_mesh(self, dim, order, algorithm, verbose)
[371](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/pygmsh/common/geometry.py?line=370) if algorithm:
[372](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/pygmsh/common/geometry.py?line=371) gmsh.option.setNumber("Mesh.Algorithm", algorithm)
--> [374](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/pygmsh/common/geometry.py?line=373) gmsh.model.mesh.generate(dim)
[376](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/pygmsh/common/geometry.py?line=375) # setOrder() after generate(), see
[377](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/pygmsh/common/geometry.py?line=376) # <https://github.com/nschloe/pygmsh/issues/515#issuecomment-1020106499>
[378](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/pygmsh/common/geometry.py?line=377) if order is not None:
File c:\Users\keurf\anaconda3\lib\site-packages\gmsh.py:1599, in model.mesh.generate(dim)
[1595](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/gmsh.py?line=1594) lib.gmshModelMeshGenerate(
[1596](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/gmsh.py?line=1595) c_int(dim),
...
[1597](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/gmsh.py?line=1596) byref(ierr))
[1598](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/gmsh.py?line=1597) if ierr.value != 0:
-> [1599](file:///c%3A/Users/keurf/anaconda3/lib/site-packages/gmsh.py?line=1598) raise Exception(logger.getLastError())
Exception: Wrong mesh element size lc = 0 (lcmin = 0, lcmax = 1e+22)