diff --git a/MANIFEST.in b/MANIFEST.in index 4022a96..9c1d980 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,6 +3,7 @@ include src/generate_from_inr.hpp include src/generate_from_off.hpp include src/generate_periodic.hpp include src/generate.hpp +include src/generate_2d.hpp include src/generate_surface_mesh.hpp include src/polygon2d.hpp include src/primitives.hpp diff --git a/README.md b/README.md index bb3084e..58541a8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
Create high-quality 3D meshes with ease.
+Create high-quality meshes with ease.
[![PyPi Version](https://img.shields.io/pypi/v/pygalmesh.svg?style=flat-square)](https://pypi.org/project/pygalmesh) @@ -18,38 +18,29 @@ [![LGTM](https://img.shields.io/lgtm/grade/python/github/nschloe/pygalmesh.svg?style=flat-square)](https://lgtm.com/projects/g/nschloe/pygalmesh) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black) -pygalmesh is a Python frontend to [CGAL](https://www.cgal.org/)'s [3D mesh generation -capabilities](https://doc.cgal.org/latest/Mesh_3/index.html). -pygalmesh makes it easy to create high-quality 3D volume meshes, periodic volume meshes, -and surface meshes. +pygalmesh is a Python frontend to [CGAL](https://www.cgal.org/)'s +[2D](https://doc.cgal.org/latest/Mesh_2/index.html) and [3D mesh generation +capabilities](https://doc.cgal.org/latest/Mesh_3/index.html). pygalmesh makes it easy +to create high-quality 2D, 3D volume meshes, periodic volume meshes, and surface meshes. -### Background - -CGAL offers two different approaches for mesh generation: - -1. Meshes defined implicitly by level sets of functions. -2. Meshes defined by a set of bounding planes. - -pygalmesh provides a front-end to the first approach, which has the following advantages -and disadvantages: - -* All boundary points are guaranteed to be in the level set within any specified - residual. This results in smooth curved surfaces. -* Sharp intersections of subdomains (e.g., in unions or differences of sets) need to be - specified manually (via feature edges, see below), which can be tedious. +### Examples -On the other hand, the bounding-plane approach (realized by -[mshr](https://bitbucket.org/fenics-project/mshr)), has the following properties: +#### 2D meshes + -* Smooth, curved domains are approximated by a set of bounding planes, resulting in more - of less visible edges. -* Intersections of domains can be computed automatically, so domain unions etc. have - sharp edges where they belong. +CGAL generates 2D meshes from linear contraints. +```python +import numpy +import pygalmesh -See [here](https://github.com/nschloe/awesome-scientific-computing#meshing) for other -mesh generation tools. +points = numpy.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]) +constraints = [[0, 1], [1, 2], [2, 3], [3, 0]] -### Examples +mesh = pygalmesh.generate_2d(points, constraints, cell_size=1.0e-1, num_lloyd_steps=10) +# mesh.points, mesh.cells +``` +The quality of the mesh isn't very good, but can be improved with +[optimesh](https://github.com/nschloe/optimesh). #### A simple ball @@ -446,6 +437,34 @@ To run the pygalmesh unit tests, check out this repository and type pytest ``` + +### Background + +CGAL offers two different approaches for mesh generation: + +1. Meshes defined implicitly by level sets of functions. +2. Meshes defined by a set of bounding planes. + +pygalmesh provides a front-end to the first approach, which has the following advantages +and disadvantages: + +* All boundary points are guaranteed to be in the level set within any specified + residual. This results in smooth curved surfaces. +* Sharp intersections of subdomains (e.g., in unions or differences of sets) need to be + specified manually (via feature edges, see below), which can be tedious. + +On the other hand, the bounding-plane approach (realized by +[mshr](https://bitbucket.org/fenics-project/mshr)), has the following properties: + +* Smooth, curved domains are approximated by a set of bounding planes, resulting in more + of less visible edges. +* Intersections of domains can be computed automatically, so domain unions etc. have + sharp edges where they belong. + +See [here](https://github.com/nschloe/awesome-scientific-computing#meshing) for other +mesh generation tools. + + ### License pygalmesh is published under the [GPLv3 license](https://www.gnu.org/licenses/gpl-3.0.en.html). diff --git a/pygalmesh/__init__.py b/pygalmesh/__init__.py index 697dff0..f5bd6dc 100644 --- a/pygalmesh/__init__.py +++ b/pygalmesh/__init__.py @@ -25,6 +25,7 @@ from . import _cli from .__about__ import __version__ from .main import ( + generate_2d, generate_from_array, generate_from_inr, generate_mesh, @@ -62,6 +63,7 @@ "RingExtrude", # "generate_mesh", + "generate_2d", "generate_periodic_mesh", "generate_surface_mesh", "generate_volume_mesh_from_surface_mesh", diff --git a/pygalmesh/main.py b/pygalmesh/main.py index c597be8..cafe383 100644 --- a/pygalmesh/main.py +++ b/pygalmesh/main.py @@ -1,9 +1,12 @@ +import math import os import tempfile import meshio +import numpy from _pygalmesh import ( SizingFieldBase, + _generate_2d, _generate_from_inr, _generate_from_inr_with_subdomain_sizing, _generate_from_off, @@ -67,6 +70,11 @@ def generate_mesh( return mesh +def generate_2d(points, constraints, B=math.sqrt(2), cell_size=0.0, num_lloyd_steps=0): + points, cells = _generate_2d(points, constraints, B, cell_size, num_lloyd_steps) + return meshio.Mesh(numpy.array(points), {"triangle": numpy.array(cells)}) + + def generate_periodic_mesh( domain, bounding_cuboid, diff --git a/setup.cfg b/setup.cfg index 02dbc42..210bae3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,10 @@ [metadata] name = pygalmesh -version = 0.7.1 +version = 0.7.2 url = https://github.com/nschloe/pygalmesh author = Nico Schlömer author_email = nico.schloemer@gmail.com -description = Python frontend to CGAL's 3D mesh generation capabilities +description = Python frontend to CGAL's mesh generation capabilities long_description = file: README.md long_description_content_type = text/markdown license = GPL-3.0-or-later @@ -14,7 +14,6 @@ classifiers = License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+) Operating System :: OS Independent Programming Language :: Python :: 3 - Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 @@ -31,7 +30,7 @@ install_requires = meshio >= 4.0.0, < 5.0.0 numpy pybind11 >= 2.2 -python_requires = >=3.5 +python_requires = >=3.6 [options.entry_points] console_scripts = diff --git a/setup.py b/setup.py index 3b20d21..0cd468d 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,7 @@ def __str__(self): "_pygalmesh", [ "src/generate.cpp", + "src/generate_2d.cpp", "src/generate_from_inr.cpp", "src/generate_from_off.cpp", "src/generate_periodic.cpp", diff --git a/src/generate_2d.cpp b/src/generate_2d.cpp new file mode 100644 index 0000000..b7596ce --- /dev/null +++ b/src/generate_2d.cpp @@ -0,0 +1,90 @@ +#define CGAL_MESH_3_VERBOSE 1 + +#include "generate_2d.hpp" + +#include