Resolving Gmsh Tag
Error in Python
#383
tkoyama010
started this conversation in
Ideas
Replies: 1 comment
-
import pygmsh
import pyvista as pv
def delaunay_3d_pygmsh(
edge_source: pv.PolyData,
target_sizes: float | list[float] | None = None,
) -> pv.UnstructuredGrid | None:
"""
Delaunay 3D mesh algorithm using pygmsh.
Parameters
----------
edge_source : pyvista.PolyData
Source object specifying constrained edges and loops. If set,
and lines/polygons are defined, a constrained triangulation is created.
The lines/polygons are assumed to reference points in the input point
set (i.e., point ids are identical in the input and source).
target_sizes : float | list[float]
Target mesh size close to the points.
Returns
-------
pyvista.UnstructuredGrid
Mesh from the 3D Delaunay generation.
Notes
-----
.. versionadded:: 0.2.0
"""
points = edge_source.points
faces = edge_source.faces.reshape(-1, 4)[:, 1:] # Assuming triangular faces
with pygmsh.geo.Geometry() as geom:
# Add points to the geometry
point_tags = []
for i, point in enumerate(points):
if isinstance(target_sizes, float):
target_size = target_sizes
elif isinstance(target_sizes, list):
target_size = target_sizes[i]
else:
target_size = None
point_tags.append(geom.add_point(point, lcar=target_size))
# Add lines and surfaces
surface_loop = []
for face in faces:
line_tags = []
for j in range(3):
start_point = point_tags[face[j - 1]]
end_point = point_tags[face[j]]
line_tags.append(geom.add_line(start_point, end_point))
line_loop = geom.add_curve_loop(line_tags)
surface_loop.append(geom.add_plane_surface(line_loop))
# Create the volume
geom.add_surface_loop(surface_loop)
volume = geom.add_volume([surface_loop])
# Generate the mesh
mesh = geom.generate_mesh()
# Convert the mesh to PyVista format
cells = mesh.cells_dict['tetra']
cell_types = [pv.CellType.TETRA] * len(cells)
pv_mesh = pv.UnstructuredGrid(mesh.points, cells.ravel(), cell_types)
return pv_mesh |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the feature you would like to be added.
The
tag
error in Gmsh is typically caused by duplicated or invalid tags (IDs) for entities or elements. To resolve this issue, you can consider the following steps:1. Avoid Duplicate Tags
Gmsh requires unique IDs for geometry and mesh elements. In your code, you're assigning point IDs with
id_ = i + 1
, but it's possible that these IDs are conflicting with others. You need to ensure that the IDs for points, curves, and surfaces are unique across all entities.For example, you can manage the tags using offset variables to avoid overlap between different entities:
2. Timing of
remove_all_duplicates
The
gmsh.model.geo.remove_all_duplicates()
function is used to remove duplicates, but it should be called at the appropriate time. Generally, this should be done after defining all geometry and before the finalsynchronize()
.Example:
3. Timing of
synchronize
CallsFrequent calls to
synchronize
can cause inconsistencies within Gmsh's internal state. It's best to define all geometry first and then callsynchronize
once, rather than multiple times throughout the code.Example:
4. Check the Error Message
Understanding the specific error message can help diagnose the problem. You can set
gmsh.option.set_number("General.Verbosity", 5)
right aftergmsh.initialize()
to get more detailed error messages, which can provide more insight into what's going wrong.5. General Workflow in Gmsh
Ensure you follow the typical workflow in Gmsh:
By following these steps, you should be able to resolve the
tag
error in your Gmsh script.Links to Gmsh Documentation, Examples, or Class Definitions.
No response
Pseudocode or Screenshots
Or drag your screenshot here!
Beta Was this translation helpful? Give feedback.
All reactions