scallop dome pyformex logo

Previous topic

60. sectionize — sectionize.py

Next topic

62. tools — tools.py

[FSF Associate Member]

Valid XHTML 1.0 Transitional

61. 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

Classes defined in module tetgen

Functions defined in module tetgen

tetgen.readNodeFile(fn)

Read a tetgen .node file.

Returns a tuple as described in readNodesBlock.

tetgen.readEleFile(fn)

Read a tetgen .ele file.

Returns a tuple as described in readElemsBlock.

tetgen.readFaceFile(fn)

Read a tetgen .face file.

Returns a tuple as described in readFacesBlock.

tetgen.readSmeshFile(fn)

Read a tetgen .smesh file.

Returns an array of triangle elements.

tetgen.readPolyFile(fn)

Read a tetgen .poly file.

Returns an array of triangle elements.

tetgen.readSurface(fn)

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).

tetgen.skipComments(fil)

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.

tetgen.stripLine(line)

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

tetgen.getInts(line, nint)

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.

tetgen.addElem(elems, nrs, e, n, nplex)

Add an element to a collection.

tetgen.readNodesBlock(fil, npts, ndim, nattr, nbmark)

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.

tetgen.readElemsBlock(fil, nelems, nplex, nattr)

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.

tetgen.readFacesBlock(fil, nelems, nbmark)

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.

tetgen.readSmeshFacetsBlock(fil, nfacets, nbmark)

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
tetgen.readNeigh(fn)

Read a tetgen .neigh file.

Returns an arrays containing the tetrahedra neighbours:

tetgen.writeNodes(fn, coords, offset=0)

Write a tetgen .node file.

tetgen.writeSmesh(fn, facets, coords=None, holes=None, regions=None)

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.

tetgen.writeTmesh(fn, elems, offset=0)

Write a tetgen .ele file.

Writes elements of a tet4 mesh.

tetgen.writeSurface(fn, coords, elems)

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

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.

tetgen.writeTetMesh(fn, coords, elems)

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.

tetgen.nextFilename(fn)

Returns the next file name in a family of tetgen file names.

tetgen.runTetgen(fn, options='')

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.

tetgen.readTetgen(fn)

Read and draw a tetgen file.

This is an experimental function for the geometry import menu.

tetgen.tetgenConvexHull(pts)

Tetralize the convex hull of some points.

Finds the convex hull some points and returns a tet mesh of the convex hull and the convex hull (tri3 mesh).

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

This could be made an example:

from simple import regularGrid X = Coords(regularGrid([0., 0., 0.], [1., 1., 1.], [10, 10, 10]).reshape(-1, 3)).addNoise(rsize=0.05,asize=0.5) draw(X) from plugins.tetgen import tetgenConvexHull tch, ch =tetgenConvexHull( X) draw(ch, color=’red’, marksize=10)

tetgen.checkSelfIntersectionsWithTetgen(self, verbose=False)

check self intersections using tetgen

Returns couples of intersecting triangles

tetgen.tetMesh(surfacefile, quality=False, volume=None, outputdir=None)

Create a tetrahedral mesh inside a surface

  • surfacefile: a file representing a surface. It can be an .off or .stl file (or other?)
  • quality: if True, the output will be a quality mesh The circumradius-to-shortest-edge ratio can be constrained by specifying a float value for quality (default is 2.0)
  • volume: float: applies a maximum tetrahedron volume constraint
  • outputdir: if specified, the results will be placed in this directory. The default is to place the results in the same directory as the input file.

If the creation of the tetrahedral model is succesful, the results are read back using readTetgen and returned.