Skip to content

Commit

Permalink
Add recombine option to generate quadrilateral meshes (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoyama010 authored Jul 23, 2024
1 parent 631139e commit 1eeaa3b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/skgmsh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def delaunay_3d(
def frontal_delaunay_2d(
edge_source: pv.PolyData,
target_sizes: float | Sequence[float] | None = None,
) -> pv.PolyData | None:
recombine: bool = False, # noqa: FBT001, FBT002
) -> pv.UnstructuredGrid | None:
"""
Frontal-Delaunay 2D mesh algorithm.
Expand All @@ -195,9 +196,12 @@ def frontal_delaunay_2d(
Target mesh size close to the points.
Default max size of edge_source in each direction.
recombine : bool
Recombine the generated mesh into quadrangles.
Returns
-------
pyvista.PolyData
pyvista.UnstructuredGrid
Mesh from the 2D delaunay generation.
Notes
Expand Down Expand Up @@ -240,12 +244,17 @@ def frontal_delaunay_2d(

gmsh.model.mesh.embed(0, embedded_points, 2, 1)

if recombine:
gmsh.model.mesh.setRecombine(2, 1)

gmsh.model.mesh.generate(2)
mesh = extract_to_meshio()
mesh = pv.from_meshio(extract_to_meshio())
gmsh.clear()
gmsh.finalize()

for cell in mesh.cells:
if cell.type == "triangle":
return pv.PolyData.from_regular_faces(mesh.points, cell.data)
return None
ind = []
for index, cell in enumerate(mesh.cell):
if cell.type in [pv.CellType.VERTEX, pv.CellType.LINE]:
ind.append(index)

return mesh.remove_cells(ind)
11 changes: 11 additions & 0 deletions tests/test_skgmsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def test_frontal_delaunay_2d_default() -> None:
# https://github.com/pyvista/scikit-gmsh/pull/125


def test_frontal_delaunay_2d_recombine() -> None:
"""Frontal-Delaunay 2D mesh algorithm test code."""
edge_source = pv.Polygon(n_sides=4, radius=8)
mesh = sg.frontal_delaunay_2d(edge_source, recombine=True)
assert mesh.number_of_points == edge_source.number_of_points
assert mesh.number_of_cells == 1
assert np.allclose(mesh.volume, edge_source.volume)
for cell in mesh.cell:
assert cell.type == pv.CellType.QUAD


@pytest.mark.parametrize("edge_source", EDGE_SOURCES)
@pytest.mark.parametrize("target_sizes", [2.0, [1.0, 2.0, 3.0, 4.0]])
def test_frontal_delaunay_2d(
Expand Down

0 comments on commit 1eeaa3b

Please sign in to comment.