Model Seismic Waves in Layered Soil Using Matter.js

This article explains how to simulate seismic wave propagation through stratified soil layers using a discrete particle-lattice approach in the 2D physics engine Matter.js. By representing soil strata as an interconnected network of mass particles and viscoelastic constraints, you can model how seismic body and shear waves refract, attenuate, and amplify across varying geological media. The following guide covers domain setup, layer parameterization, boundary conditions, and seismic excitation.

Representing Soil as a Discrete Element Network

Matter.js is a rigid-body physics engine, so continuous soil mechanics must be discretized using a bonded-particle or lattice-spring model. In this approach, soil mass is concentrated at nodal particles (Matter.Bodies.circle), while inter-particle forces (elasticity and damping) are handled via distance constraints (Matter.Constraint.create).

To model different soil strata—such as bedrock, dense sand, and soft clay—you vary three fundamental physical parameters across vertical depth:

Constructing Layered Strata

Generate the domain on a regular triangular or hexagonal grid to ensure isotropic wave propagation. Divide your domain vertically into distinct strata:

  1. Bedrock Layer (Bottom): High particle mass, maximum constraint stiffness (e.g., stiffness: 0.9 to 1.0), and low damping.
  2. Intermediate Layer (e.g., Dense Sand/Gravel): Moderate mass, moderate constraint stiffness (e.g., stiffness: 0.4 to 0.6).
  3. Near-Surface Layer (e.g., Soft Clay/Alluvium): Lower mass, low constraint stiffness (e.g., stiffness: 0.05 to 0.2), and higher damping.

Each particle is connected to its nearest neighbors using cross-braced constraints to support both compressional (P) waves and shear (S) waves. Setting collisionFilter.group = -1 on all soil particles disables default contact collisions between bonded neighbors, allowing the constraints alone to dictate the linear elastic response without erratic contact chatter.

Applying Non-Reflecting Boundary Conditions

A common issue in computational geomechanics is the reflection of waves off domain edges. To mitigate artificial boundary reflections:

Simulating Seismic Input

Seismic excitation is introduced by driving the base layer particles. Instead of fixing the bottom particles in place, manipulate their kinematics directly in each simulation tick of the beforeUpdate event:

Tuning the Engine for Wave Fidelity

Standard physics engines prioritize speed over numerical precision. To accurately resolve dynamic wave propagation without numerical instability or artificial dispersion: