Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FrontalDelaunay2D class inspired from scipy.spatial.Delaunay #291

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Example of a package skgmsh file."""
15 changes: 15 additions & 0 deletions examples/delaunay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Example of Delaunay triangulation in 2D."""

from __future__ import annotations

import matplotlib.pyplot as plt
import numpy as np
from scipy.spatial import Delaunay

points = np.array([[0, 0], [0, 1.1], [1, 0], [1, 1]])

tri = Delaunay(points)

plt.triplot(points[:, 0], points[:, 1], tri.simplices)
plt.plot(points[:, 0], points[:, 1], "o")
plt.show()
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ requires = [
'pygmsh<7.1.18',
'pyvista',
'scooby<0.9.3',
'setuptools<69.0.4'
'setuptools<69.0.4',
'scipy<1.14.1'
]
build-backend = 'setuptools.build_meta'

Expand All @@ -20,7 +21,8 @@ dependencies = [
'meshio<5.3.6',
'pygmsh<7.1.18',
'pyvista',
'scooby<0.9.3'
'scooby<0.9.3',
'scipy<1.14.1'
]
requires-python = '>=3.9'

Expand Down
32 changes: 32 additions & 0 deletions src/skgmsh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
if TYPE_CHECKING:
from collections.abc import Sequence

import numpy as np

INITIAL_MESH_ONLY_2D = 3
FRONTAL_DELAUNAY_2D = 6
DELAUNAY_3D = 1
Expand Down Expand Up @@ -291,3 +293,33 @@ def edge_source(self: Delaunay2D) -> pv.PolyData:
def mesh(self: Delaunay2D) -> pv.UnstructuredGrid:
"""Get the mesh."""
return self._mesh


class FrontalDelaunay2D:
"""
Frontal Delaunay 2D mesh algorithm.

Parameters
----------
points : np.ndarray
Coordinates of the points to triangulate.

"""

# TODO @tkoyama010: Need to consider how to handle gmsh with two or more instances. # noqa: FIX002, TD003

def __init__(self: FrontalDelaunay2D, points: np.ndarray) -> None: # noqa: ARG002
"""Initialize the FrontalDelaunay2D class."""
gmsh.initialize()
gmsh.option.set_number("Mesh.Algorithm", FRONTAL_DELAUNAY_2D)
gmsh.option.set_number("General.Verbosity", SILENT)

def __del__(self: FrontalDelaunay2D) -> None:
"""Finalize the FrontalDelaunay2D class."""
gmsh.clear()
gmsh.finalize()

def enable_recombine(self: FrontalDelaunay2D) -> None:
"""Enable recombine the generated mesh into quadrangles."""
# TODO @tkoyama010: Define ID of surface clearly. # noqa: FIX002, TD003
gmsh.model.mesh.setRecombine(2, 1)