Solver#
Time integration solvers for physics simulation
This module implements semi-implicit (symplectic Euler) time integration for tetrahedral FEM simulation. The integration scheme updates velocities using forces at the current position, then updates positions using the new velocities:
This is a first-order symplectic method that provides better energy conservation than explicit Euler integration.
- class diffsim.solver.SemiImplicitSolver(dt=0.01, gravity=-9.8, damping=0.99, substeps=4, enable_self_collision=False, collision_method='simplified')[source]#
Bases:
objectSemi-implicit (symplectic Euler) solver for dynamic FEM simulation
This solver implements a first-order symplectic integration scheme. Velocities are updated using forces at the current position, then positions are updated using the new velocities. This scheme is symplectic (preserves phase space volume) and provides better energy conservation than explicit methods.
The integration follows:
\[ \begin{align}\begin{aligned}\mathbf{v}^{n+1} &= \mathbf{v}^n + h \, \mathbf{M}^{-1} (\mathbf{f}_{\text{elastic}}(\mathbf{x}^n) + \mathbf{f}_{\text{gravity}} + \mathbf{f}_{\text{contact}})\\\mathbf{x}^{n+1} &= \mathbf{x}^n + h \, \mathbf{v}^{n+1}\end{aligned}\end{align} \]where \(h = \Delta t / \text{substeps}\) is the substep size.
- __init__(dt=0.01, gravity=-9.8, damping=0.99, substeps=4, enable_self_collision=False, collision_method='simplified')[source]#
Initialize solver
- Parameters:
dt – time step size
gravity – gravity acceleration (m/s^2)
damping – velocity damping factor
substeps – number of substeps per timestep
enable_self_collision – enable self-collision detection
collision_method – ‘simplified’ (fast) or ‘ipc’ (accurate but slower)
- step(mesh, material, positions, velocities, masses, fixed_vertices=None)[source]#
Perform one semi-implicit time step with stability controls
- Parameters:
mesh – TetrahedralMesh object
material – Material model (e.g., StableNeoHookean)
positions – \((N, 3)\) current positions
velocities – \((N, 3)\) current velocities
masses – \((N,)\) vertex masses
fixed_vertices – list of fixed vertex indices
- Returns:
\((N, 3)\) updated positions new_velocities: \((N, 3)\) updated velocities
- Return type:
new_positions