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:

\[ \begin{align}\begin{aligned}\mathbf{v}^{n+1} = \mathbf{v}^n + \Delta t \, \mathbf{M}^{-1} \mathbf{f}(\mathbf{x}^n)\\\mathbf{x}^{n+1} = \mathbf{x}^n + \Delta t \, \mathbf{v}^{n+1}\end{aligned}\end{align} \]

The undamped, unclamped, contact-free core is a first-order symplectic method. The solver also applies damping, velocity limiting, and contact response.

class diffsim.solver.SemiImplicitSolver(dt=0.01, gravity=-9.8, damping=0.99, substeps=4, enable_self_collision=False, collision_method='simplified')[source]#

Bases: object

Semi-implicit (symplectic Euler) solver for dynamic FEM simulation

This solver implements a first-order semi-implicit integration scheme. Velocities are updated using forces at the current position, then positions are updated using the new velocities. Its core update is symplectic; damping, clamping, constraints, and contact make the complete implemented map non-symplectic.

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.

dt#

Time step size in seconds

Type:

float

gravity_value#

Gravity acceleration in m/s² (negative for downward)

Type:

float

damping#

Velocity damping coefficient applied per substep

Type:

float

substeps#

Number of substeps per timestep for stability

Type:

int

enable_self_collision#

Whether to compute self-collision forces

Type:

bool

collision_method#

Approximate self-collision method ('simplified')

Type:

str

__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 applied per substep

  • substeps – number of substeps per timestep

  • enable_self_collision – enable self-collision detection

  • collision_method – must be 'simplified'; use IPCImplicitEulerSolver for frictionless IPC

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