Tsunami Wave Runup and Debris Modeling in Matter.js

This article explains how to simulate 2D tsunami wave runup and onshore debris transport using the Matter.js physics engine. By representing water mass as an ensemble of clustered circular rigid bodies—a technique adapted from discrete element methods—developers can approximate complex hydrodynamic phenomena such as shoaling, shoreline inundation, and floating object dynamics directly within a browser environment.

1. Representing Fluid with Clustered Discs

Matter.js is a rigid-body physics engine rather than a continuous fluid solver. To simulate water, you must discretize the fluid mass into a large cluster of small, uniform circular bodies (Matter.Bodies.circle).

For fluid-like behavior, configure the particle properties to minimize shearing resistance while preserving volume:

2. Setting Up Bathymetry and Coastal Incline

To observe wave shoaling and runup, construct the physical domain using static composite bodies (isStatic: true):

3. Generating the Tsunami Wave

Unlike wind-driven surface waves, a tsunami involves the displacement of an entire water column. You can generate this wave using two primary methods in Matter.js:

As the dense cluster of discs enters the shallow slope, the narrowing vertical space forces the particles upward and forward, creating shoaling and overland runup.

4. Simulating Buoyancy and Debris Dynamics

Solid debris (shipping containers, vehicles, or structural fragments) can be modeled as dynamic rectangular bodies positioned along the coastline.

Matter.js does not calculate fluid displacement buoyancy out of the box. You can handle debris interaction through two methods:

Matter.Events.on(engine, 'beforeUpdate', () => {
    const overlappingDiscs = Matter.Query.collides(debrisBody, waterDiscs);
    const buoyantFactor = 0.0005;
    
    if (overlappingDiscs.length > 0) {
        Matter.Body.applyForce(debrisBody, debrisBody.position, {
            x: 0,
            y: -buoyantFactor * overlappingDiscs.length
        });
    }
});

5. Engine Optimization for Particle Stability

Running hundreds or thousands of rigid discs simultaneously can strain browser performance. Optimize the simulation with the following adjustments: