lapy.TetMesh¶
- class lapy.TetMesh(v, t)[source]¶
Class representing a tetrahedral 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, shape (n_vertices, 3).
- tarray_like
List of lists of 4 int of indices (>=0) into
varray, shape (n_tetrahedra, 4). Ordering is important: so that t0, t1, t2 are oriented counterclockwise when looking from above, and t3 is on top of that triangle.
Attributes
v
(np.ndarray) Vertex coordinates, shape (n_vertices, 3).
t
(np.ndarray) Tetrahedron vertex indices, shape (n_tetrahedra, 4).
adj_sym
(scipy.sparse.csc_matrix) Symmetric adjacency matrix as csc sparse matrix.
Methods
Get average edge lengths in tet mesh.
boundary_tria([tetfunc])Get boundary triangle mesh of tetrahedra.
Create adjacency symmetric matrix.
Check if the vertex list has more vertices than what is used in tetra.
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.
Remove unused (free) vertices from v and t.
write_vtk(filename)Save as VTK file.
- Raises:
ValueErrorIf max index in t exceeds number of vertices.
Notes
The class has static class methods to read tetrahedra meshes from GMSH and VTK files.
- 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:
- tetfunc
np.ndarrayorNone, default=None List of tetra function values, shape (n_tetrahedra,). Optional.
- tetfunc
- Returns:
TriaMeshTriaMesh of boundary (potentially >1 components).
- triafunc
np.ndarray List of tria function values, shape (n_boundary_triangles,). Only returned if
tetfuncis 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 edges are 2 or 1. Works on tetras only.
- Returns:
scipy.sparse.csc_matrixSymmetric 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:
boolWhether vertex list has more vertices than tetrahedra use 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:
boolTrue if all tet volumes are positive, False if some or all are negative.
- Raises:
ValueErrorIf degenerate (zero-volume) tets are found.
- 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:
intNumber of re-oriented tetras.
- Raises:
ValueErrorIf degenerate (zero-volume) tetrahedra are detected.
- rm_free_vertices_()[source]¶
Remove unused (free) vertices from v and t.
These are vertices that are not used in any tetrahedron. They can produce problems when constructing, e.g., Laplace matrices.
Will update v and t in mesh. Same implementation as in
TriaMesh.- Returns:
- vkeep
np.ndarray Indices (from original list) of kept vertices.
- vdel
np.ndarray Indices of deleted (unused) vertices.
- vkeep
- Raises:
ValueErrorIf max index in t exceeds number of vertices.