lapy.TetMesh

class lapy.TetMesh(v, t)[source]

Class representing a tetraheral mesh.

This is an efficient implementation of a tetrahedral mesh data structure with core functionality using sparse matrices internally (Scipy).

Parameters:
varray_like

List of lists of 3 float coordinates.

tarray_like

List of lists of 4 int of indices (>=0) into v array. Ordering is important: so that t0, t1, t2 are oriented counterclockwise when looking from above, and t3 is on top of that triangle.

Methods

avg_edge_length()

Get average edge lengths in tet mesh.

boundary_tria([tetfunc])

Get boundary triangle mesh of tetrahedra.

construct_adj_sym()

Create adjacency symmetric matrix.

has_free_vertices()

Check if the vertex list has more vertices than what is used in tetra.

is_oriented()

Check if tet mesh is oriented.

orient_()

Ensure that tet mesh is oriented.

read_gmsh(filename)

Load GMSH tetrahedron mesh.

read_vtk(filename)

Load VTK tetrahedron mesh.

rm_free_vertices_()

Remove unused (free) vertices from v and t.

write_vtk(filename)

Save as VTK file.

Notes

The class has static class methods to read tetrahera meshes from GMSH and VTK files.

avg_edge_length()[source]

Get average edge lengths in tet mesh.

Returns:
float

Average edge length.

boundary_tria(tetfunc=None)[source]

Get boundary triangle mesh of tetrahedra.

It can have multiple connected components. Tria will have same vertices (including free vertices), so that the tria indices agree with the tet-mesh, in case we want to transfer information back, e.g. a FEM boundary condition, or to access a TetMesh vertex function with TriaMesh.t indices.

Warning

Note, that it seems to be returning non-oriented triangle meshes, may need some debugging, until then use tria.orient_() after this.

Parameters:
tetfuncarray | None

List of tetra function values (optional).

Returns:
TriaMesh

TriaMesh of boundary (potentially >1 components).

triafuncarray

List of tria function values (only returned if tetfunc is provided).

construct_adj_sym()[source]

Create adjacency symmetric matrix.

The adjacency matrix will be symmetric. Each inner edge will get the number of tetrahedra that contain this edge. Inner edges are usually 3 or larger, boundary, 2 or 1. Works on tetras only.

Returns:
adjcsc_matrix

Symmetric adjacency matrix as csc sparse matrix.

has_free_vertices()[source]

Check if the vertex list has more vertices than what is used in tetra.

(same implementation as in TriaMesh)

Returns:
bool

Whether vertex list has more vertices than tetra or not.

is_oriented()[source]

Check if tet mesh is oriented.

True if all tetrahedra are oriented so that v0,v1,v2 are oriented counterclockwise when looking from above, and v3 is on top of that triangle.

Returns:
oriented: bool

True if max(adj_directed)=1.

orient_()[source]

Ensure that tet mesh is oriented.

Re-orient tetras so that v0,v1,v2 are oriented counterclockwise when looking from above, and v3 is on top of that triangle.

Returns:
onumint

Number of re-oriented tetras.

classmethod read_gmsh(filename)[source]

Load GMSH tetrahedron mesh.

Parameters:
filenamestr

Filename to load.

Returns:
tetTetMesh

Object of loaded GMSH tetrahedron mesh.

classmethod read_vtk(filename)[source]

Load VTK tetrahedron mesh.

Parameters:
filenamestr

Filename to load.

Returns:
tetTetMesh

Object of loaded VTK tetrahedron mesh.

rm_free_vertices_()[source]

Remove unused (free) vertices from v and t.

These are vertices that are not used in any triangle. They can produce problems when constructing, e.g., Laplace matrices.

Will update v and t in mesh. Same implementation as in TriaMesh.

Returns:
vkeep: array

Indices (from original list) of kept vertices.

vdel: array

Indices of deleted (unused) vertices.

write_vtk(filename)[source]

Save as VTK file.

Parameters:
filenamestr

Filename to save to.