Finite Element Simulation

Developed deformable solid objects simulation based on tetrahedral meshes using FEM.
Code Logic
Extracting the surface mesh
For each face, sort the vertex indices and store to the map
<index, index, index>to<count>. Loop through all the tets to build the map and surface meshes is faces withcount == 1.Computing and applying internal forces
Calculate
Fandstressfor each tet and loop through particles to update internal forces based onf = F * stress * area * normal. Detailed calculation ofFandstressis shown onutils.cpp.Collision resolution
When a particle hits the collider, apply a penalty force to the tet in the direction of the normal of the collider. The magnitude of the penalty force is calculated by
f = k * |v|. Any particle that is inside the collider will be projected out later.Explicit integration method
Store the original state and update the position and velocity of particles on midpoint. Then calculate one step
dxanddvon the midpoint state and apply them to the original state.
Extra Features
Runge-Kutta 4 Integrator
Store the original state. Take one step from original state and store
dx, dvtok1. Take half step from original state and storedx, dvtok2. Take half step fromk2and storedx, dvtok3. Take one step fromk3and storedx, dvtok4. Update from original state withdelta = 1 / 6 * (k1 + 2k2 + 2k3 + k4).Adaptive time stepping
Take one step from original state to get state
xa. Take two half step from original state to get statexb. Calculate the error based onxaandxb. Update the time stepttot' = sqrt(max_error / error) * t.
Demo Video
Single tetrahedron falling on the floor (
./inis/tet.ini$\rightarrow$./demo-video/tet.mp4)Cube falling on the floor (
./inis/cube.ini$\rightarrow$./demo-video/cube.mp4)Ellipsoid falling on the floor with fixed sphere (
./inis/ellipsoid.ini$\rightarrow$./demo-video/ellipsoid.mp4)Higher-order explicit integrator
With Runge-Kutta 4 Integrator (
./inis/rk4_on.ini$\rightarrow$./demo-video/rk4_on.mp4)Without Runge-Kutta 4 Integrator (
./inis/rk4_off.ini$\rightarrow$./demo-video/rk4_off.mp4)
Adaptive time stepping
With Adaptive time stepping (
./inis/adapt_on.ini$\rightarrow$./demo-video/adapt_on.mp4)Without Adaptive time stepping (
./inis/adapt_off.ini$\rightarrow$./demo-video/adapt_off.mp4)