8.22.2 Functions defined in the surface module

areaNormals( x)
Compute the area and normal vectors of a collection of triangles.

x is an (ntri,3,3) array of coordinates.

Returns a tuple of areas,normals. The normal vectors are normalized. The area is always positive.

stlConvert( stlname,outname=None,options='-d')
Transform an .stl file to .off or .gts format.

If outname is given, it is either '.off' or '.gts' or a filename ending on one of these extensions. If it is only an extension, the stlname will be used with extension changed.

If the outname file exists and its mtime is more recent than the stlname, the outname file is considered uptodate and the conversion programwill not be run.

The conversion program will be choosen depending on the extension. This uses the external commands 'admesh' or 'stl2gts'.

The return value is a tuple of the output file name, the conversion program exit code (0 if succesful) and the stdout of the conversion program (or a 'file is already uptodate' message).

read_gts( fn)
Read a GTS surface mesh.

Return a coords,edges,faces tuple.

read_off( fn)
Read an OFF surface mesh.

The mesh should consist of only triangles! Returns a nodes,elems tuple.

read_stl( fn,intermediate=None)
Read a surface from .stl file.

This is done by first coverting the .stl to .gts or .off format. The name of the intermediate file may be specified. If not, it will be generated by changing the extension of fn to '.gts' or '.off' depending on the setting of the 'surface/stlread' config setting.

Return a coords,edges,faces or a coords,elems tuple, depending on the intermediate format.

read_gambit_neutral( fn)
Read a triangular surface mesh in Gambit neutral format.

The .neu file nodes are numbered from 1! Returns a nodes,elems tuple.

write_gts( fn,nodes,edges,faces)

write_stla( f,x)
Export an x[n,3,3] float array as an ascii .stl file.

write_stlb( f,x)
Export an x[n,3,3] float array as an binary .stl file.

write_gambit_neutral( fn,nodes,elems)

write_off( fn,nodes,elems)

write_smesh( fn,nodes,elems)

surface_volume( x,pt=None)
Return the volume inside a 3-plex Formex.

For each element of Formex, return the volume of the tetrahedron formed by the point pt (default the center of x) and the 3 points of the element.

surfaceInsideLoop( coords,elems)
Create a surface inside a closed curve defined by coords and elems.

coords is a set of coordinates. elems is an (nsegments,2) shaped connectivity array defining a set of line segments forming a closed loop.

The return value is coords,elems tuple where coords has one more point: the center of th original coords elems is (nsegment,3) and defines triangles describing a surface inside the original curve.

fillHole( coords,elems)
Fill a hole surrounded by the border defined by coords and elems.

Coords is a (npoints,3) shaped array of floats. Elems is a (nelems,2) shaped array of integers representing the border element numbers and must be ordered.

create_border_triangle( coords,elems)
Create a triangle within a border.

The triangle is created from the two border elements with the sharpest angle. Coords is a (npoints,3) shaped array of floats. Elems is a (nelems,2) shaped array of integers representing the border element numbers and must be ordered. A list of two objects is returned: the new border elements and the triangle.

read_error( cnt,line)
Raise an error on reading the stl file.

degenerate( area,norm)
Return a list of the degenerate faces according to area and normals.

A face is degenerate if its surface is less or equal to zero or the normal has a nan.

read_stla( fn,dtype=Float,large=False,guess=True)
Read an ascii .stl file into an [n,3,3] float array.

If the .stl is large, read_ascii_large() is recommended, as it is a lot faster.

read_ascii_large( fn,dtype=Float)
Read an ascii .stl file into an [n,3,3] float array.

This is an alternative for read_ascii, which is a lot faster on large STL models. It requires the 'awk' command though, so is probably only useful on Linux/UNIX. It works by first transforming the input file to a .nodes file and then reading it through numpy's fromfile() function.

off_to_tet( fn)
Transform an .off model to tetgen (.node/.smesh) format.

find_row( mat,row,nmatch=None)
Find all rows in matrix matching given row.

find_nodes( nodes,coords)
Find nodes with given coordinates in a node set.

nodes is a (nnodes,3) float array of coordinates. coords is a (npts,3) float array of coordinates.

Returns a (n,) integer array with ALL the node numbers matching EXACTLY ALL the coordinates of ANY of the given points.

find_first_nodes( nodes,coords)
Find nodes with given coordinates in a node set.

nodes is a (nnodes,3) float array of coordinates. coords is a (npts,3) float array of coordinates.

Returns a (n,) integer array with THE FIRST node number matching EXACTLY ALL the coordinates of EACH of the given points.

find_triangles( elems,triangles)
Find triangles with given node numbers in a surface mesh.

elems is a (nelems,3) integer array of triangles. triangles is a (ntri,3) integer array of triangles to find.

Returns a (ntri,) integer array with the triangles numbers.

remove_triangles( elems,remove)
Remove triangles from a surface mesh.

elems is a (nelems,3) integer array of triangles. remove is a (nremove,3) integer array of triangles to remove.

Returns a (nelems-nremove,3) integer array with the triangles of nelems where the triangles of remove have been removed.

Rectangle( nx,ny)
Create a plane rectangular surface consisting of a nx,ny grid.

Cube( )
Create a surface in the form of a cube

Sphere( level=4,verbose=False,filename=None)
Create a spherical surface by caling the gtssphere command.

If a filename is given, it is stored under that name, else a temporary file is created. Beware: this may take a lot of time if level is 8 or higher.