TetMesh Geodesics

import numpy as np
from lapy import TetMesh
from lapy.plot import plot_tet_mesh
import plotly
# plotly.offline.init_notebook_mode(connected=True)
import plotly.io as pio
pio.renderers.default = "sphinx_gallery"

First we need a TetMesh, so lets open a cube with 48K tetrahedra and make sure it is oriented consistently.

T = TetMesh.read_vtk('../data/cubeTetra.vtk')

--> VTK format         ...
 --> DONE ( V: 9261 , T: 48000 )

Flipped 24000 tetrahedra


Next we solve the Laplace eigenvalue problem to get 10 eigenvalues and -vectors/functions.

from lapy import Solver
fem = Solver(T,lump=True)

evals, evec = fem.eigs(10)

TetMesh with regular Laplace
Solver: spsolve (LU decomposition) ...

To better see the first non-constant function also in the interior we slice the cube at x<0.5.

# also get A,B (lumped), and inverse of B (easy as it is diagonal)
A, B = fem.stiffness, fem.mass
Bi = B.copy()
Bi.data **= -1
cutting = ['x<0.5']
# also here we comment all plots to reduce file size
# uncomment and take a look

Mesh is oriented, nothing to do
Found 3040 triangles on boundary.

Similar to the triangle case, computing the - divergence of the gradient of an eigenfunctions (and multiplying with inv(B)) yields a scaled version of that function.

from lapy.diffgeo import compute_gradient
from lapy.diffgeo import compute_divergence
grad = compute_gradient(T,evec[:,evnum])
divx = -compute_divergence(T,grad)
vfunc = Bi*divx

cutting = ['x<0.5']

Mesh is oriented, nothing to do
Found 3040 triangles on boundary.