Mesh#

Tetrahedral mesh representation for finite element simulation

This module provides the TetrahedralMesh class, which represents volumetric geometry using tetrahedral elements. The mesh stores vertex positions and element connectivity, and computes the deformation gradient for each element during simulation.

The deformation gradient \(\mathbf{F}\) maps from the reference (rest) configuration to the current (deformed) configuration:

\[\mathbf{F} = \mathbf{D}_s \mathbf{D}_m^{-1}\]

where \(\mathbf{D}_s\) contains edge vectors in the current configuration and \(\mathbf{D}_m\) contains edge vectors in the rest configuration.

class diffsim.mesh.TetrahedralMesh(vertices, tetrahedra, device='cpu')[source]#

Bases: object

Tetrahedral mesh for finite element simulation

This class represents a volumetric mesh using tetrahedral elements. Each tetrahedron is defined by four vertices, and the mesh computes quantities needed for FEM simulation such as the deformation gradient, element volumes, and shape matrices.

The mesh automatically computes and caches rest-state quantities when initialized:

  • \(\mathbf{D}_m\): Rest shape matrix for each element (3×3)

  • \(\mathbf{D}_m^{-1}\): Inverse rest shape matrix

  • \(V_0\): Rest volume for each element

vertices#

Vertex positions \((N \times 3)\)

Type:

torch.Tensor

tetrahedra#

Element connectivity \((M \times 4)\) indices

Type:

torch.Tensor

num_vertices#

Number of vertices \(N\)

Type:

int

num_elements#

Number of tetrahedral elements \(M\)

Type:

int

Dm#

Rest shape matrices \((M \times 3 \times 3)\)

Type:

torch.Tensor

Dm_inv#

Inverse rest shape matrices \((M \times 3 \times 3)\)

Type:

torch.Tensor

rest_volume#

Rest volumes \((M,)\)

Type:

torch.Tensor

device#

Device where tensors are stored

Type:

torch.device

__init__(vertices, tetrahedra, device='cpu')[source]#

Initialize tetrahedral mesh

Parameters:
  • vertices\((N, 3)\) array of vertex positions

  • tetrahedra\((M, 4)\) array of tetrahedron indices

  • device – ‘cpu’ or ‘cuda’

compute_deformation_gradient(current_vertices)[source]#

Compute deformation gradient F for each element

Parameters:

current_vertices\((N, 3)\) current vertex positions

Returns:

\((M, 3, 3)\) deformation gradient for each element

Return type:

F

classmethod from_file(filename, device='cpu')[source]#

Load mesh from file using meshio

classmethod create_cube(resolution=5, size=1.0, device='cpu')[source]#

Create a cube mesh with tetrahedral elements

Parameters:
  • resolution – number of divisions along each axis

  • size – size of the cube

  • device – ‘cpu’ or ‘cuda’