microstructpy.meshing.polymesh module

Polygon Meshing

This module contains the class definition for the PolyMesh class.

class microstructpy.meshing.polymesh.PolyMesh(points, facets, regions, seed_numbers=None, phase_numbers=None, facet_neighbors=None, volumes=None)[source]

Bases: object

Polygonal/Polyhedral mesh.

The PolyMesh class contains the points, edges, regions, etc. in a polygon (2D) or polyhedron (3D) mesh.

The points attribute is a numpy array containing the (x, y) or (x, y, z) coordinates of each point in the mesh. This is the only attribute that contains floating point numbers. The rest contain indices/integers.

The facets attribute describes the interfaces between the polygons/ polyhedra. In 2D, these interfaces are line segments and each facet contains the indices of the points at each end of the line segment. These indices are unorderd. In 3D, the interfaces are polygons so each facet contains the indices of the points on that polygon. These indices are ordered such that neighboring keypoints are connected by line segments that form the polygon.

The regions attribute contains the area (2D) or volume (3D). In 2D, a region is given by an ordered list of facets, or edges, that enclose the polygon. In 3D, the region is given by an un-ordered list of facets, or polygons, that enclose the polyhedron.

For each region, there is also an associated seed number and material phase. These data are stored in the seed_number and phase_number attributes, which have the same length as the regions list.

Parameters:
  • points (numpy.ndarray) – An Nx2 or Nx3 array of coordinates in the mesh.
  • facets (list) – List of facets between regions. In 2D, this is a list of edges (Nx2). In 3D, this is a list of 3D polygons.
  • regions (list) – A list of polygons (2D) or polyhedra (3D), with each element of the list being a list of facet indices.
  • seed_numbers (list, optional) – The seed number associated with each region.
  • phase_numbers (list, optional) – The phase number associated with each region.
  • facet_neighbors (list, optional) – The region numbers on either side of each facet
  • volumes (list, optional) – The area/volume of each region.
classmethod from_file(filename)[source]

Read PolyMesh from file.

This function reads in a polygon mesh from a file and creates an instance from that file. Currently the only supported file type is the output from write() with the format='str' option.

Parameters:filename (str) – Name of file to read from.
Returns:The instance of the class written to the file.
Return type:PolyMesh
classmethod from_seeds(seedlist, domain)[source]

Create from SeedList and Domain.

This function creates a polygon/polyhedron mesh from a seed list and a domain. It relies on the pyvoro package, which wraps Voro++. The mesh is a Voronoi power diagram / Laguerre tessellationself.

The pyvoro package operates on rectangular domains, so other domains are meshed by reflecting seeds across their boundaries and meshing a larger domain. The reflection process will double the number of points in the voro++ input, which may cause a noticable slow-down for high-population microstructures. This reflection process is unnecessary for rectangular and box domains.

Parameters:
  • seedlist (SeedList) – A list of seeds in the microstructure.
  • domain (Domain) – The domain to be filled by the seeds.
Returns:

A polygon/polyhedron mesh.

Return type:

PolyMesh

plot(**kwargs)[source]

Plot the mesh.

This function plots the polygon mesh. The keyword arguments are passed though to matplotlib.

Parameters:**kwargs – Keyword arguments for matplotlib.
plot_facets(**kwargs)[source]

Plot PolyMesh facets.

This function plots the facets of the polygon mesh, rather than the regions.

Parameters:**kwargs (dict) – Keyword arguments for matplotlib.
write(filename, format='txt')[source]

Write the mesh to a fileself.

This function writes the polygon/polyhedron mesh to a file. The format of the file can be specified, with the options described in the table below.

PolyMesh Write Formats
Format format kD Description
Text String txt ND The Python string representation of the mesh. Human readable, but not in a standard file format.
POLY File poly 2D A poly file that contains a planar straight line graph (PSLG). This file can be read by the Triangle program from J. Shewchuk.
PLY File ply ND A PLY file containing the mesh facets.
VTK Legacy vtk 3D A VTK file containing the mesh as a POLYDATA dataset. Note: seed number and phase number information are not written to the VTK file.

The text string output file is meant solely for saving the polygon/ polyhedron mesh as an intermediate step in the meshing process. The other file types lists are meant for processing and interpretation by other programs. The format for the text string file is:

Mesh Points: <numPoints>
    x1, y1(, z1)      <- tab character at line start
    x2, y2(, z2)
    ...
    xn, yn(, zn)
Mesh Facets: <numFacets>
    f1_1, f1_2, f1_3, ...
    f2_1, f2_2, f2_3, ...
    ...
    fn_1, fn_2, fn_3, ...
Mesh Regions: <numRegions>
    r1_1, r1_2, r1_3, ...
    r2_1, r2_2, r2_3, ...
    ...
    rn_1, rn_2, rn_3, ...
Seed Numbers: <numRegions>
    s1
    s2
    ...
    sn
Phase Numbers: <numRegions>
    p1
    p2
    ...
    pn

For example:

Mesh Points: 4
    0.0, 0.0
    1.0, 0.0
    3.0, 2.0
    2.0, 2.0
Mesh Facets: 5
    0, 1
    1, 2
    2, 3
    3, 0
    1, 3
Mesh Regions: 2
    0, 4, 3
    1, 2, 4
Seed Numbers: 2
    0
    1
Phase Numbers: 2
    0
    0

Note that everything is indexed from 0 since this is produced in Python. In this example, the polygon mesh contains a parallelogram that has been divided into two triangles. In general, the regions do not need to have the same number of facets.

See also

.poly files Description and examples of poly files.
PLY - Polygon File Format Description and examples of ply files.
File Formats for VTK Version 4.2 PDF guide for VTK legacy format.
Parameters:
  • filename (str) – Name of the file to be written.
  • format (str) – Format of the data in the file.