93. plugins.tetgen — Interface with tetgen

A collection of functions to read/write tetgen files and to run the tetgen program

tetgen is a quality tetrahedral mesh generator and a 3D Delaunay triangulator. See http://tetgen.org

93.1. Functions defined in module plugins.tetgen

plugins.tetgen.readNodeFile(fn)[source]

Read a tetgen .node file.

Returns a tuple as described in readNodesBlock().

plugins.tetgen.readEleFile(fn)[source]

Read a tetgen .ele file.

Returns a tuple as described in readElemsBlock.

plugins.tetgen.readFaceFile(fn)[source]

Read a tetgen .face file.

Returns a tuple as described in readFacesBlock.

plugins.tetgen.readSmeshFile(fn)[source]

Read a tetgen .smesh file.

Returns an array of triangle elements.

plugins.tetgen.readPolyFile(fn)[source]

Read a tetgen .poly file.

Returns an array of triangle elements.

plugins.tetgen.readSurface(fn)[source]

Read a tetgen surface from a .node/.face file pair.

The given filename is either the .node or .face file. Returns a tuple of (nodes,elems).

plugins.tetgen.skipComments(fil)[source]

Skip comments and blank lines on a tetgen file.

Reads from a file until the first non-comment and non-empty line. Then returns the non-empty, non-comment line, stripped from possible trailing comments. Returns None if end of file is reached.

plugins.tetgen.stripLine(line)[source]

Strip blanks, newline and comments from a line of text.

plugins.tetgen.getInts(line, nint)[source]

Read a number of ints from a line, adding zero for omitted values.

line is a string with b;anks separated integer values. Returns a list of nint integers. The trailing ones are set to zero if the strings contains less values.

plugins.tetgen.addElem(elems, nrs, e, n, nplex)[source]

Add an element to a collection.

plugins.tetgen.readNodesBlock(fil, npts, ndim, nattr, nbmark)[source]

Read a tetgen nodes block.

Returns a tuple with:

  • coords: Coords array with nodal coordinates

  • nrs: node numbers

  • attr: node attributes

  • bmrk: node boundary marker

The last two may be None.

plugins.tetgen.readElemsBlock(fil, nelems, nplex, nattr)[source]

Read a tetgen elems block.

Returns a tuple with:

  • elems: Connectivity of type ‘tet4’ or ‘tet10’

  • nrs: the element numbers

  • attr: the element attributes

The last can be None.

plugins.tetgen.readFacesBlock(fil, nelems, nbmark)[source]

Read a tetgen faces block.

Returns a a tuple with:

  • elems: Connectivity of type ‘tri3’

  • nrs: face numbers

  • bmrk: face boundary marker

The last can be None.

plugins.tetgen.readSmeshFacetsBlock(fil, nfacets, nbmark)[source]

Read a tetgen .smesh facets bock.

Returns a tuple of dictionaries with plexitudes as keys:

  • elems: for each plexitude a Connectivity array

  • nrs: for each plexitude a list of element numbers in corresponding elems

plugins.tetgen.readNeigh(fn)[source]

Read a tetgen .neigh file.

Returns an array containing the tetrahedra neighbours:

plugins.tetgen.writeNodes(fn, coords, offset=0)[source]

Write a tetgen .node file

plugins.tetgen.writeSmesh(fn, facets, coords=None, holes=None, regions=None)[source]

Write a tetgen .smesh file.

Currently it only writes the facets of a triangular surface mesh. Coords should be written independently to a .node file.

plugins.tetgen.writeTmesh(fn, elems, offset=0)[source]

Write a tetgen .ele file.

Writes elements of a tet4 mesh.

plugins.tetgen.writeSurface(fn, coords, elems)[source]

Write a tetgen surface model to .node and .smesh files.

Parameters:
  • fn (path_like) – Filename of the files to which the model sohould be exported. The provided file name is either the .node or the .smesh filename, or else it is the basename where .node and .smesh extensions will be appended.

  • coords (Coords) – The vertices in the surface model.

  • elems (array) – The element definitions in function of the vertex numbers.

plugins.tetgen.writeTetMesh(fn, coords, elems)[source]

Write a tetgen tetrahedral mesh model to .node and .ele files.

The provided file name is either the .node or the .smesh filename, or else it is the basename where .node and .ele extensions will be appended.

plugins.tetgen.runTetgen(fn, options='')[source]

Run tetgen mesher on the specified file.

The input file is a closed triangulated surface. tetgen will generate a volume tetraeder mesh inside the surface, and create a new approximation of the surface as a by-product.

plugins.tetgen.readTetgen(fn)[source]

Read a tetgen model.

This reads a file created by the ‘tetgen’ tetrahedral mesher and returns corresponding pyFormex objects.

Parameters:

fn (path_like) – Path to a tetgen file. This can be one of .node, .ele, .face, .smesh or .poly files.

Returns:

dict – If the suffix of fn is one of .node, .ele or .face, the dict contains one item with key ‘tetgen.SUFFIX’. For suffix .node, the value is a Coords read from the .node file, for suffix .ele or .face, the value is a Mesh with elems read from the .ele or .face, and coords read from the corresponding .node. If the suffix is .smesh or .poly, the dict contains a number of Meshes, with keys ‘Mesh-NPLEX’ where NPLEX is the plexitude of the corresponding Mesh.

plugins.tetgen.tetgenConvexHull(pts)[source]

Tetralize the convex hull of some points.

Parameters:

pts (Coords) – A collection of points to find the convex hull of.

Returns:

  • convexhull (TriSurface) – The smallest TriSurface enclosing all the points.

  • tetmesh (Mesh) – A tetraeder Mesh filling the convex hull.

  • If all points are on the same plane there is no convex hull.

plugins.tetgen.checkSelfIntersectionsWithTetgen(self, verbose=False)[source]

check self intersections using tetgen

Returns pairs of intersecting triangles

plugins.tetgen.tetMesh(surfacefile, quality=2.0, volume=None, outputdir=None)[source]

Create a tetrahedral mesh inside a surface

This uses the external program ‘tetgen’ to create a tetrahedral mesh inside a closed manifold surface.

Parameters:
  • surfacefile (path_like) – Path to a file holding a surface model. The file can be either a .off or .stl.

  • quality (float) – The quality of the output tetrahedral mesh. The value is a constraint on the circumradius-to-shortest-edge ratio. The default (2.0) already provides a high quality mesh. Providing a larger value will reduce quality but increase speed. With quality=None, no quality constraint will be imposed.

  • volume (float, optional) – If provided, applies a maximum tetrahedron volume constraint.

  • outputdir (path_like) – Path to an existing directory where the results will be placed. The default is to use the directory where the input file resides.

Returns:

Mesh – A tetrahedral Mesh (eltype=’tet4’) filling the input surface, provided the tetgen program finished successfully.