Meshing, but poly
Project description
Poly Mesher
PolyMesher is a package aimed at mathematical and industrial applications where polygonal meshes are required for uses in finite element methods, finite volumes methods amongst many others. This package was adapted from a package developed in MATLAB [1]. Over recent years, Python has been used more extensively in scientific applications and the need for easy generation of polygonal meshes in Python is now required.
Fundamentally, the meshes generated are Voronoi tessellations, bounded by the computation domain in question. These computational domains can be built up and customised by the user. There is the option for further processing to remove certain artifacts of the Lloyd's algorithm used, including very small edges of machine precision length but note that this removes the Voronoi property. Also included is geometry generation which generates additional information about the mesh. This is then able to used in subsequent numerical methods.
Examples
-
800 polygon decomposition of the computational domain $[0, 1]^2$.
import numpy as np from poly_mesher.poly_mesher_domain import RectangleDomain from poly_mesher.poly_mesher_main import poly_mesher domain = RectangleDomain(bounding_box=np.array([[0, 1], [0, 1]])) poly_mesh = poly_mesher(domain, n_points=800, max_iterations=1)
This code will generate the mesh required for a follwing numerical method. Figure .... demonstrates a potential mesh with a finite volumes solution overlapped.
-
Demonstration of
CircleCircleDomainas in Figure 2.from poly_mesher.poly_mesher_domain import CircleCircleDomain from poly_mesher.show_mesh import show_mesh domain = CircleCircleDomain() mesh = poly_mesher(domain, n_points=800) show_mesh(mesh.vertices, mesh.regions, bounding_box = domain.bounding_box)
Fig. 1 - 800-Polygon decomposition Fig. 2 - 800-Polygon decomposition of the circle-circle domain -
Demonstration of mesh cleaning and geometry generation with a numerical application in DGFEM [2].
from poly_mesher.poly_mesher_clean import poly_mesher_cleaner from poly_mesher.geometry_generation import GeneralGeometry domain = RectangleDomain(bounding_box=np.array([[0, 1], [0, 1]])) poly_mesh = poly_mesher(domain, n_points=1024) clean_poly_mesh = poly_mesher_cleaner(poly_mesh) mesh_geometry = GeneralGeometry(clean_mesh)
An image of this is shown in Figure 3.
Fig. 3 - 1024 Element Clean Mesh under a DGFEM scheme Fig. 4 - Example of future 3D meshes
Modules
poly_mesher_main: This is the main module. It contains thepoly_mesherfunction which generates the Voronoi spatial decompositions. It also contains additional subfunctions which are not required for general use.poly_mesher_domain: This module contains some prebuiltDomainsub-classes. These include theCircleDomainand theRectangleDomainas well as the more complicatedLShapeDomain,RectangleCircleDomainandHornDomain. These are also additional examples of how to generate the more complicated domains which are possible from the basic distance functions.poly_mesher_distance_functions: This module contains the basic distance functions. The idea is to create a full function which is negative within the computational domain and positive otherwise. Combinations of these functions allows these domains to be built up.poly_mesher_clean: This module contains the clean up algorithm. Artifacts of the bounded Voronoi generation can interfere with the subsequent numerical method. The functionpoly_mesher_cleanergenerates aPseudoVoronoiobject which contains all the information required for a clean polygonal mesh but lacks the property of being Voronoi (despite being close).geometry_generation: This module contains the dataclassGeneralGeometry. This generates the geometry for aPseudoVoronoiobject. Properties of this dataclass are generated when initialising through the.generate()method. Properties that are generated include a subtriangulation, normals to each element and separation of edges into interior and boundary edges.show_mesh: This contains one functionshow_meshwhich displays the generated mesh from its vertices and elements.
Future Updates
With the code that is in place, there is the option of extending to three dimensions. This is currently being developed and tested with an emphasis on keeping the new code consistent. An early example of which is shown in Figure 4.
How to install
The current best approach is to use pip to install github packages which are not on pypi or condaforge. The following code run in the approapriate environment is suitable.
pip install git+"https://github.bath.ac.uk/mje45/poly_mesher"
References
[1] Talischi, C., Paulino, G., Pereira, A. and Menezes, I. (2012) PolyMesher: a general-purpose mesh generator for polygonal elements written in MATLAB
[2] Cangiani, A., Georgoulis, E. H. and Houston, P. (2014) hp-version discontinuous Galerkin methods on polygonal and polyhedral meshes
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polyfem-1.0.0.tar.gz.
File metadata
- Download URL: polyfem-1.0.0.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcda8c31bcc919285d4c35f445111ca82872dd069f1a19890c8b61fb00a14239
|
|
| MD5 |
389786b5907b4b0811adbb0bceda587c
|
|
| BLAKE2b-256 |
0debea7c5bd538d00b0b87447e42958da4e93281f162d7fc32d958a459cdac1e
|
File details
Details for the file polyfem-1.0.0-py3-none-any.whl.
File metadata
- Download URL: polyfem-1.0.0-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3ff8f619776ed2da452211b2ce289ad1778fda26ee9807deba15fd7db36ee1e
|
|
| MD5 |
ba6c252d9f40ae26dee4a0ab6fcc3872
|
|
| BLAKE2b-256 |
2bd83064f7e656cf3f99f294c7782cdc8c296cdb766f449611c6036932213ca5
|