Triangle/TetGen interface#

Some common notions#

class meshpy.ForeignArray#

Note that ForeignArray instances are not usually created by users, and ForeignArray is not a class name available in MeshPy. It is just used to explain the interface provided.

Almost all input and output data in MeshPy can be accessed using the ForeignArray interface. It is called “foreign” because it provides access to an area of memory accessible by a pointer managed by an outside piece of software, such as a mesh generator.

Note that ForeignArray has no append method. Instead, use ForeignArray.resize() and then set the consecutive entries of the array.

__len__()#

Return the number of entries in the array. If the array is 2D (i.e. has non-1 unit), ForeignArray.__len__() only returns the length of the leading dimension. For example, for an array of points in n-dimensional space, __len__() returns the number of points.

unit#

If this ForeignArray represents a two-dimensional array, such as an array of point coordinates, ForeignArray.unit() gives the size of the subordinate dimension.

For example, for an array of points in 3-dimensional space, ForeignArray.__len__() returns the number of dimensions (3).

allocated#

Return a bool indicating whether storage has been allocated for this array. This is only meaningful if the size of this array is tied to that of another, see ForeignArray.setup().

resize(new_size)#

Change the length of the array as returned by ForeignArray.__len__().

setup()#

Set up (i.e. allocate) storage for the array. This only works on arrays whose size is tied to that of other arrays, such as an array of point markers, which necessarily has the same size as the associated array of points, if it is allocated.

deallocate()#

Release any storage associated with the array.

__getitem__(index)#
__setitem__(index, value)#

Get and set entries in the array. If this foreign array is 2D (see ForeignArray.unit), index may be a 2-tuple of integers, as in:

points[2,1] = 17

meshpy.triangle – Triangular Meshing#

class meshpy.triangle.ForeignArray#

See meshpy.ForeignArray for shared documentation.

class meshpy.triangle.MeshInfo[source]#

MeshInfo objects are picklable.

points#

A 2D ForeignArray of float with dimension (N,2), providing a list of points that are referred to by index from other entries of this structure.

point_attributes#

If MeshInfo.number_of_point_attributes is non-zero, this is a ForeignArray of floats of point attributes.

This element’s size is tied to that of MeshInfo.points.

point_markers#

ForeignArray of floats of point attributes.

This element’s size is tied to that of MeshInfo.points.

elements#
element_attributes#

This element’s size is tied to that of MeshInfo.elements.

element_volumes#

This element’s size is tied to that of MeshInfo.elements.

neighbors#
facets#
facet_markers#
holes#
regions#
faces#
face_markers#
normals#
number_of_point_attributes#
number_of_element_vertices#

Defautls to 4 for linear tetrahedra. Change to 10 for second-order tetrahedra.

number_of_element_attributes#

Convenient setters:

set_points(points, point_markers=None)#
set_holes(points, hole_starts)#
set_facets(facets, facet_markers=None)[source]#

Other functionality:

copy()#

Return a duplicate copy of this object.

meshpy.triangle.subdivide_facets(subdivisions, points, facets, facet_markers)[source]#

Subdivide facets into subdivisions subfacets.

This routine is useful if you have to prohibit the insertion of Steiner points on the boundary of your triangulation to allow the mesh to conform either to itself periodically or another given mesh. In this case, you may use this routine to create the necessary resolution along the boundary in a predefined way.

subdivisions is either an int, indicating a uniform number of subdivisions throughout, or a list of the same length as facets, specifying a subdivision count for each individual facet.

points

a list of points referred to from the facets list.

facets

a list of old facets, in the form [(p1, p2), (p3,p4), …].

facet_markers

either None or a list of facet markers of the same length as facets.

Returns a tuple (new_points, new_facets), or (new_points, new_facets, new_facet_markers) if facet_markers is not None.

meshpy.triangle.build(mesh_info, verbose=False, refinement_func=None, attributes=False, volume_constraints=True, max_volume=None, allow_boundary_steiner=True, allow_volume_steiner=True, quality_meshing=True, generate_edges=None, generate_faces=False, min_angle=None)[source]#
meshpy.triangle.refine(input_p, verbose=False, refinement_func=None, quality_meshing=True, min_angle=None)[source]#
meshpy.triangle.write_gnuplot_mesh(filename, out_p, facets=False)[source]#

meshpy.tet – Tetrahedral Meshing#

class meshpy.tet.ForeignArray#

See meshpy.ForeignArray for shared documentation.

class meshpy.tet.Options(switches='pq', **kwargs)[source]#

Run time switches for TetGen. See the TetGen documentation for the meaning of each switch.

Using the kwargs constructor argument, all the attributes defined below can be set. This setting will occur after Options.parse_switches() is called with the switches parameter.

plc#
quality#
refine#
coarse#
metric#
varvolume#
fixedvolume#
insertaddpoints#
regionattrib#
conformdel#
diagnose#
zeroindex#
optlevel#
optpasses#
order#
facesout#
edgesout#
neighout#
voroout#
meditview#
gidview#
geomview#
nobound#
nonodewritten#
noelewritten#
nofacewritten#
noiterationnum#
nomerge#
nobisect#
noflip#
nojettison#
steiner#
fliprepair#
docheck#
quiet#
verbose#
useshelles#
minratio#
goodratio#
minangle#
goodangle#
maxvolume#
maxdihedral#
alpha1#
alpha2#
alpha3#
epsilon#
epsilon2#
parse_switches(switches)#
class meshpy.tet.Polygon#
vertices#
class meshpy.tet.Facet#
polygons#
holes#
class meshpy.tet.PBCGroup#
facet_marker_1#
facet_marker_2#
point_pairs#
matrix#
class meshpy.tet.MeshInfo[source]#
points#
point_attributes#
point_metric_tensors#
point_markers#
elements#
element_attributes#
element_volumes#
neighbors#
facets#
facet_markers#
holes#
regions#
facet_constraints#
segment_constraints#
pbc_groups#
faces#
adjacent_elements#
face_markers#
edges#
edge_markers#
edge_adjacent_elements#

New in version 2016.1.

number_of_point_attributes#
number_of_element_attributes#

Convenient setters:

set_points(points, point_markers=None)#
set_holes(points, hole_starts)#
set_facets(facets, markers=None)[source]#

Set a list of simple, single-polygon factes. Unlike MeshInfo.set_facets_ex(), this method does not allow holes and only lets you use a single polygon per facet.

facets

a list of facets, where each facet is a single polygons, represented by a list of point indices.

markers

Either None or a list of integers of the same length as facets. Each integer is the facet marker assigned to its corresponding facet.

Note

When the above says “list”, any repeatable iterable also accepted instead.

set_facets_ex(facets, facet_holestarts=None, markers=None)[source]#

Set a list of complicated facets. Unlike MeshInfo.set_facets(), this method allows holes and multiple polygons per facet.

facets

a list of facets, where each facet is a list of polygons, and each polygon is represented by a list of point indices.

facet_holestarts

Either None or a list of hole starting points for each facet. Each facet may have several hole starting points. The mesh generator starts “eating” a hole into the facet at each starting point and continues until it hits a polygon specified in this facet’s record in facets.

markers

Either None or a list of integers of the same length as facets. Each integer is the facet marker assigned to its corresponding facet.

Note

When the above says “list”, any repeatable iterable also accepted instead.

Other functionality:

face_vertex_indices_to_face_marker#
dump()[source]#
write_vtk(filename)[source]#

TetGen-provided loading and saving:

save_nodes(filename)#
save_elements(filename)#
save_faces(filename)#
save_edges(filename)#
save_neighbors(filename)#
save_poly(filename)#
load_node(filename)#
load_pbc(filename)#
load_var(filename)#
load_mtr(filename)#
load_poly(filename)#
load_ply(filename)#
load_stl(filename)#
load_medit(filename)#
load_plc(filename)#
load_tetmesh(filename)#
meshpy.tet.build(mesh_info, options=Options('pq'), verbose=False, attributes=False, volume_constraints=False, max_volume=None, diagnose=False, insert_points=None, mesh_order=None)[source]#
Parameters:

insert_points – a MeshInfo object specifying additional points to be inserted