From e1c9a948f09a15d675db7088c9f2118a30d991eb Mon Sep 17 00:00:00 2001 From: Tetsuo Koyama Date: Fri, 26 Jul 2024 08:49:50 +0900 Subject: [PATCH 1/3] Update --- examples/__init__.py | 1 + examples/delaunay.py | 13 +++++++++++++ pyproject.toml | 6 ++++-- src/skgmsh/__init__.py | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 examples/__init__.py create mode 100644 examples/delaunay.py diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 00000000..627c7a31 --- /dev/null +++ b/examples/__init__.py @@ -0,0 +1 @@ +"""Example of a package skgmsh file.""" diff --git a/examples/delaunay.py b/examples/delaunay.py new file mode 100644 index 00000000..2efdb615 --- /dev/null +++ b/examples/delaunay.py @@ -0,0 +1,13 @@ +"""Example of Delaunay triangulation in 2D.""" + +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() diff --git a/pyproject.toml b/pyproject.toml index 8756fa56..4e456944 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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' @@ -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' diff --git a/src/skgmsh/__init__.py b/src/skgmsh/__init__.py index 96cc0f0d..75aaa522 100644 --- a/src/skgmsh/__init__.py +++ b/src/skgmsh/__init__.py @@ -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 @@ -258,3 +260,33 @@ def frontal_delaunay_2d( ind.append(index) return mesh.remove_cells(ind) + + +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) From 8643b9383dad616b6a3af8d8b1f9c709e05a6c51 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 07:20:59 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/skgmsh/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/skgmsh/__init__.py b/src/skgmsh/__init__.py index c6bd2f3f..1eba2c8d 100644 --- a/src/skgmsh/__init__.py +++ b/src/skgmsh/__init__.py @@ -300,6 +300,7 @@ def mesh(self: Delaunay2D) -> pv.UnstructuredGrid: """Get the mesh.""" return self._mesh + class FrontalDelaunay2D: """ Frontal Delaunay 2D mesh algorithm. From af94543d1dc4d5998dd859c4ef077aca577dac14 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 11 Aug 2024 11:19:45 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/delaunay.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/delaunay.py b/examples/delaunay.py index 2efdb615..afb67d86 100644 --- a/examples/delaunay.py +++ b/examples/delaunay.py @@ -1,5 +1,7 @@ """Example of Delaunay triangulation in 2D.""" +from __future__ import annotations + import matplotlib.pyplot as plt import numpy as np from scipy.spatial import Delaunay