Files
2022-04-07 18:46:57 +02:00

10 KiB

Description

This notebook intends to gather all the functionalities you'll have to implement for assignment 2.1. You will have to generate an elastic solid, deform it, compute the associated Jacobian of the deformation map \phi, and implement pinning constraints. You will also visualize the eigenvectors and eigenvalues of the metric tensor, given a prescribed deformation.

Load libraries

In [1]:
import numpy as np
import igl
import meshplot as mp

import sys as _sys
_sys.path.append("../src")
from elasticsolid import *
from eigendecomposition_metric import *

shadingOptions = {
    "flat":True,
    "wireframe":False,   
}

rot = np.array(
    [[1, 0, 0 ],
     [0, 0, 1],
     [0, -1, 0 ]]
)

Load mesh

Several meshes are available for you to play with under data/: ball.obj, dinosaur.obj, and beam.obj. You can also uncomment the few commented lines below to manipulate a simple mesh made out of 2 tetrahedra.

In [2]:
v, _, _, t, _, _ = igl.read_obj("../data/dinosaur.obj")

# t = np.array([
#         [0, 1, 2, 3],
#         [1, 2, 3, 4]
#     ])
# v = np.array([
#     [0., 0., 0.],
#     [1., 0., 0.],
#     [0., 1., 0.],
#     [0., 0., 1.],
#     [2/3, 2/3, 2/3]
# ])

aabb = np.max(v, axis=0) - np.min(v, axis=0)
length_scale = np.mean(aabb)

p = mp.plot(v @ rot.T, t, shading=shadingOptions)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987469…

Manipulate elastic solids

Instanciation

The rest shape matrices D_m and their inverse matrices B_m are computed during instanciation.

In [3]:
rho   = 131  # [kg.m-3]
solid = ElasticSolid(v, t, rho=rho)

Deform the mesh

This part involves Jacobian computation which relies on deformed shape matrices D_s.

In [4]:
v_def = v.copy()
v_def[:, 2] *= 2.
solid.update_def_shape(v_def)

mp.plot(solid.v_def @ rot.T, solid.t, shading=shadingOptions)
Out [4]:
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987469…
<meshplot.Viewer.Viewer at 0x7fa7dc789070>

Visualize some properties of the metric tensor

The metric tensor measures how stretched and sheared directions in the undeformed space are under the deformation \phi. It is defined from the Jacobian of the deformation \mathbf{F} as follow (see the handout for a derivation):

\mathbf{M} = \mathbf{F}^T \mathbf{F}

We intend to plot the eigenvectors coloured by the corresponding eigenvalues in the next cell.

In [11]:
# We limit ourselves to stretching the mesh in the z direction
# Feel free to experiment with other kinds of deformations!

v_def = v.copy()
v_def[:, 2] *= 2.0
solid.update_def_shape(v_def)

squared_eigvals, eigvecs = compute_eigendecomposition_metric(solid.F)
plot_eigendecomposition_metric(solid, squared_eigvals, eigvecs, rot, scale=0.05)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987469…

Pin vertices of the mesh

Pass a pin_idx to the constructor, compute the mask for deformations.

In [6]:
maxZ    = np.max(solid.v_rest[:, 2])
pin_idx = np.arange(solid.v_rest.shape[0])[solid.v_rest[:, 2] > maxZ - 0.1 * aabb[2]]

v_def = v.copy()
v_def[:, 2] -= 0.1 * aabb[2]
solid.update_def_shape(v_def)

solid_pinned = ElasticSolid(v, t, rho=rho, pin_idx=pin_idx)
solid_pinned.update_def_shape(v_def)
In [7]:
p = mp.plot(solid_pinned.v_def @ rot.T, t, shading=shadingOptions)
p.add_points(solid_pinned.v_def[pin_idx, :] @ rot.T, shading={"point_color":"black", "point_size": 0.1 * length_scale})
Out [7]:
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987469…
1

1.2.4 Derivation

Volume of tetrahedron (X_1, X_2, X_3, X_4) is given by \frac{1}{6}|det(D_m)|

We can decompose the provided formula:

Vol = \frac{1}{6}|det(D_m)| = \frac{1}{6}|D_{m1}^T \cdot (D_{m2} \times D_{m3})|

Next, we build 3 vectors:

V_0 = X_1 - X_4 = \begin{pmatrix}X_{x1}-X_{x4} \\ Y_{x1}-Y_{x4} \\ Z_{x1}- Z_{x4} \end{pmatrix}

V_1 = X_2 - X_4 = \begin{pmatrix}X_{x2}-X_{x4} \\ Y_{x2}-Y_{x4} \\ Z_{x2}- Z_{x4} \end{pmatrix}

V_2 = X_3 - X_4 = \begin{pmatrix}X_{x3}-X_{x4} \\ Y_{x3}-Y_{x4} \\ Z_{x3}- Z_{x4} \end{pmatrix}

We then compute the base as:

B = V_1 \times V_2

And also the height as:

H = V_0

From this we can compute the volume:

Vol = \frac{1}{6} \cdot B \cdot H = \frac{1}{6} V_0 \cdot (V_1 \times V_2)

We can note the similarity between both fomulas. We can note the equality between both formulas:

V_0 = D_{m1}, V_1 = D_{m2}, V_2 = D_{m3}

Note that the absolute value is not directly taken into account since its absolute volume and not signed volume.

1.2.7 Derivation

Show that: Vol(x_1, x_2, x_3, x_4)/Vol(X_1, X_2, X_3, X_4) = |det(F)|

Since we know that F = D_s D_m^{-1}, and that: V = \frac{1}{6}|det(D_m)|

We can drag the det and abs into it:

|det(F)| = \frac{|det(D_s)|}{|det(D_m)|} = \frac{\frac{1}{6}|det(D_s)|}{\frac{1}{6}|det(D_m)|} = \frac{Vol(x_1, x_2, x_3, x_4)}{Vol(X_1, X_2, X_3, X_4)}

In [ ]: