A Python package for polygonal mesh generation
Project description
pyPolyMesher
Generation of polygonal Mesh
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
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.
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.
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
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).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).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.DF.dPolygon(P, vertices)
: Calculate the signed distance from points P to a polygon defined by its vertices.DF.dUnion(d1, d2)
: Calculate the signed distance field resulting from the union of two distance fields (d1 and d2).DF.dIntersect(d1, d2)
: Calculate the signed distance field resulting from the intersection of two distance fields (d1 and d2).DF.dDiff(d1, d2)
: Calculate the signed distance field resulting from the difference of two distance fields (d1 and d2).
Example Domains:
pyPolyMesher.exampleDomains.MbbDomain
pyPolyMesher.exampleDomains.HornDomain
pyPolyMesher.exampleDomains.WrenchDomain
pyPolyMesher.exampleDomains.MichellDomain
pyPolyMesher.exampleDomains.SuspensionDomain
pyPolyMesher.exampleDomains.CookDomain
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()
Node, Element, Supp, Load, P = PolyMesher(dxfDomain, 50, 100)
mesh_assessment(Node, Element)
Custom Domain: Heart Example
The custom domain build from the SDF definition of heart geometry is available at heart_example.py.
See Examples.py and Example Notebook for more examples.
Roadmap
Section 1 - Current Focus and Issue Resolution
- Define
Domain
fromdxf
filesPolygon importer- Circle importer
- Spline importer
- Automatic SDF for geometries
- Add mesh quality assessments
Aspect RatioStandard Deviation of Elements Areas
Section 2 - Upcoming Priorities
- Enhance the README with more detailed information.
- Publish the package on PYPI and Zenodo for wider distribution.
- Add some tests.
Section 3 - Vision and Future Prospects
- Develop a GUI for domain definition to improve user interaction.
- Plugin for CAD programs.
- 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).
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!
License
This project is licensed under the GPLv3 License - see the LICENSE file for details. Contact
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
Built Distribution
File details
Details for the file polymesher-1.0.3.tar.gz
.
File metadata
- Download URL: polymesher-1.0.3.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6477548e01f4ffc791be41331dad3ea9bcd6a706662e1e991ee94980850e0054 |
|
MD5 | c9af2e167ec51c6fe57181405b0e1503 |
|
BLAKE2b-256 | ea681b4afa8169ae8b1f4bf99e5af6054f30ae930cc8955c19a52bb33f5c63ba |
File details
Details for the file PolyMesher-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: PolyMesher-1.0.3-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c2f85f539489e733e63e697cb33f87ddc6ab9ee60ce59e8169dc4637fa08fda |
|
MD5 | 5a55661d81a0920f0596e375bc329224 |
|
BLAKE2b-256 | d3d65e7f4b08b5fea36daa041f92424ec8db543cddac8da7b34c9f2644292fb9 |