Skip to main content

A Python package for polygonal mesh generation

Project description

License Made with love in SUT (Iran) GitHub Stars DOI PyPI Downloads PyPI Downloads


Logo

pyPolyMesher

Generation of polygonal Mesh
Explore the docs »

View Demo · Report Bug · Request Feature · Citations

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
    1. Basic Usage
    2. Internal SDFs
    3. Example Domains
    4. Import Polygon Domain from DXF
    5. Custom Domain: Heart Example
  4. Roadmap
  5. Contributing
  6. License
  7. Contact

About The Project

pyPolyMesher is a python package for generating unstructured polygonal meshes in arbitrarily defined 2D domains. It allows users to mathematically specify domains using signed distance functions (SDFs) and generates high-quality meshes adapted to the geometry and features of the domain. pyPolyMesher was initially created as a Python version of the MATLAB PolyMesher program but has since been enriched with additional features.

Key capabilities:

  • Define 2D domains mathematically using signed distance functions
  • Built-in library of SDF primitives (circles, rectangles, polygons, etc.) and operations to construct complex domains
  • Ability to define custom SDFs for new domain geometries
  • Generate unstructured polygonal meshes adapted to domains
  • Apply boundary conditions and mark fixed points
  • Assess mesh quality metrics like element aspect ratio
  • Animate mesh generation process
  • Import and mesh polygons from DXF files

By leveraging SDFs to represent domains, pyPolyMesher can capture intricate geometries and generate optimized meshes tailored to them, making it useful for simulations and analysis.

The package provides Lloyd's algorithm for efficient and robust meshing of arbitrary SDF-based domains. Researchers can conveniently translate geometric constructs and concepts into code using the SDF formalism.

Overall, pyPolyMesher simplifies the entire workflow - from domain specification to quality polygonal mesh generation to numerical analysis.

(back to top)

Getting Started

This part explains how to install and use this package.

Installation

You can install this package using pip:

pip install PolyMesher

Please note that pyPolyMesher is published as PolyMesher on PYPI.

(back to top)

Usage

Basic Usage:

pyPolyMesher.PolyMesherPolyMesher(Domain, NElem, MaxIter, P=None, anim=False): Generate polygon mesh on Domain with NElem number of elements. Improve mesh for MaxIter iterations. Can be given an initial point set P.

import pyPolyMesher
from pyPolyMesher.exampleDomains import MichellDomain
MichellDomain.Plot()
Node, Element, Supp, Load, P = pyPolyMesher.PolyMesher(MichellDomain, 50, 100)

Internal SDFs:

from pyPolyMesher import dFunctions as DF
  1. DF.dLine(P, x1, y1, x2, y2): Calculate the signed distance from points P to a line segment defined by two endpoints (x1, y1) and (x2, y2).
  2. DF.dCircle(P, xc, yc, r): Calculate the signed distance from points P to a circle defined by its center (xc, yc) and radius (r).
  3. DF.dRectangle(P, x1, x2, y1, y2): Calculate the signed distance from points P to a rectangle defined by its bottom-left (x1, y1) and top-right (x2, y2) coordinates.
  4. DF.dPolygon(P, vertices): Calculate the signed distance from points P to a polygon defined by its vertices.
  5. DF.dUnion(d1, d2): Calculate the signed distance field resulting from the union of two distance fields (d1 and d2).
  6. DF.dIntersect(d1, d2): Calculate the signed distance field resulting from the intersection of two distance fields (d1 and d2).
  7. DF.dDiff(d1, d2): Calculate the signed distance field resulting from the difference of two distance fields (d1 and d2).

Example Domains:

Example Domains
  1. pyPolyMesher.exampleDomains.MbbDomain

MbbDomain

  1. pyPolyMesher.exampleDomains.HornDomain

HornDomain

  1. pyPolyMesher.exampleDomains.WrenchDomain

WrenchDomain

  1. pyPolyMesher.exampleDomains.MichellDomain

MichellDomain

  1. pyPolyMesher.exampleDomains.SuspensionDomain

SuspensionDomain

  1. pyPolyMesher.exampleDomains.CookDomain

CooksMembrane

Import Polygon Domain from DXF:

from pyPolyMesher import PolyMesher, Domain, mesh_assessment
from pyPolyMesher.dxfImporter import dxf_polygon
from pyPolyMesher.dFunctions import dPolygon

dxf_file_path = 'examples/polygon1.dxf'
v = dxf_polygon(dxf_file_path)

SDF = lambda P: dPolygon(P, v)
dxfDomain = Domain("DXF Polygon Domain", [0,100,0,100], SDF)
dxfDomain.Plot()

polygon_dxf

Node, Element, Supp, Load, P = PolyMesher(dxfDomain, 50, 100)

area = dxfDomain.CalculateArea()
metrics = mesh_assessment(Node, Element, area, verbose = True)

polygon_dxf_mesh

It should be noted that the CalculateArea method calculates the approximate area of the domain using the Monte Carlo method.

The mesh_assessment function calculates the following mesh quality metrics:

  • Maximum aspect ratio (AR)
  • Average AR
  • Average edge length across all elements
  • Range of element areas (minimum and maximum)
  • Standard deviation of element areas
  • Total area error between domain area and total element areas (obviously in case the domain area is provided)

Custom Domain: Heart Example

The custom domain build from the SDF definition of heart geometry is available at heart_example.py.

heart_domain heart_mesh

See Examples.py and Example Notebook for more examples.

(back to top)

Roadmap

Section 1 - Current Focus and Issue Resolution

  1. Define Domain from dxf files
    • Polygon importer
    • Circle importer
    • Spline importer
    • Automatic SDF for geometries
  2. Add mesh quality assessments
    • Aspect Ratio
    • Standard Deviation of Elements Areas

Section 2 - Upcoming Priorities

  1. Enhance the README with more detailed information.
  2. Publish the package on PYPI and Zenodo for wider distribution.
  3. Add some tests.

Section 3 - Vision and Future Prospects

  1. Develop a GUI for domain definition to improve user interaction.
  2. Plugin for CAD programs.
  3. Explore and brainstorm alternative options for domain definition and future possible expansions.

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". We appreciate your interest in pyPolyMesher!. Don't forget to give the project a star! Thanks again!

v1.2 Release Notes

This release focuses on reliability, test coverage, and release readiness:

  • Added a comprehensive automated test suite covering signed-distance functions, domain abstraction, meshing, example domains, DXF import, and progress utilities
  • Added smoke tests for the documented example script and example assets
  • Improved meshing behavior and fixed-point plotting handling
  • Hardened DXF import handling for testability and portability
  • Updated README citations and release metadata

Publications Using pyPolyMesher

This package has been used in the following research:

  • S.S. Abedi-Shahri et al. (2025). "NL-SBFEM: A pure SBFEM formulation for geometrically and materially nonlinear problems" Engineering Analysis with Boundary Elements. Link
  • R. Dupont (2025). "An arbitrary-order Virtual Element Method for the Helmholtz equation applied to wave field calculation in port" Results in Applied Mathematics. Link

(back to top)

License

This project is licensed under the GPLv3 License - see the LICENSE file for details. Contact

(back to top)

Contact

If you have any questions or feedback, feel free to reach out:

Email: AbediSadjad@gmail.com

GitHub: Sad-Abd

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polymesher-1.2.tar.gz (36.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polymesher-1.2-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file polymesher-1.2.tar.gz.

File metadata

  • Download URL: polymesher-1.2.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polymesher-1.2.tar.gz
Algorithm Hash digest
SHA256 c17eabc2919a506822ced009b1cfaef05c8084b18af554861baee2c96c85278b
MD5 5724f7661166b402ecc0564216845f0f
BLAKE2b-256 df8ce07b45f855ab29ce1f311ca0756d1f598acbd7d2f9f38c77782339dc5846

See more details on using hashes here.

File details

Details for the file polymesher-1.2-py3-none-any.whl.

File metadata

  • Download URL: polymesher-1.2-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polymesher-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c9fbdf6e47b11c7e9a473c8abf4b6f52e8346b5e8d84656bc2ea6333dddc0f24
MD5 088db4a629c4349b5f610a8092531cfd
BLAKE2b-256 a9d2f3d5939d87991156cef1edd31a78d1cbde5365d49a35cf718163f68fd0c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page