# microstructpy.meshing.PolyMesh¶

class microstructpy.meshing.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 (list or 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 or numpy.ndarray) – (optional) The seed number associated with each region. Defaults to 0 for all regions. phase_numbers (list or numpy.ndarray) – (optional) The phase number associated with each region. Defaults to 0 for all regions. facet_neighbors (list or numpy.ndarray) – (optional) The region numbers on either side of each facet. If not givien, a neighbor list is computed from regions. volumes (list or numpy.ndarray) – (optional) The area/volume of each region. If not given, region volumes are calculated based on points, facets, and regions.
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='txt' option.

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

Create from SeedList and a 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 in 2D by meshing in a bounding box then the boundary cells are clipped to the domain boundary. Currently non-rectangular domains in 3D are not supported.

Parameters: seedlist (SeedList) – A list of seeds in the microstructure. domain (from microstructpy.geometry) – The domain to be filled by the seed. A polygon/polyhedron mesh. PolyMesh
plot(**kwargs)[source]

Plot the mesh.

This function plots the polygon mesh. In 2D, this creates a class:matplotlib.collections.PolyCollection and adds it to the current axes. In 3D, it creates a mpl_toolkits.mplot3d.art3d.Poly3DCollection and adds it to the current axes. 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. In 2D, it adds a matplotlib.collections.LineCollection to the current axes. In 3D, it adds a mpl_toolkits.mplot3d.art3d.Poly3DCollection with facecolors='none'. The keyword arguments are passed though to matplotlib.

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

Write the mesh to a file.

This function writes the polygon/polyhedron mesh to a file. See the Polygonal Mesh section of the Output File Formats guide for more information about the available output file formats.

Parameters: filename (str) – Name of the file to be written. format (str) – (optional) {‘txt’ | ‘poly’ | ‘ply’ | ‘vtk’ } Format of the data in the file. Defaults to 'txt'.