Adding inertia: mangroves swaying in the surf
Channel: Nils Berglund
Date: 20/09/2021

In this further step towards more realistic mangrove simulations, this one includes inertia, allowing mangrove trees to sway back and forth. In previous simulations, the motion of the trees was overdamped, meaning that it was governed by a first-order differential equation. Here the motion is generated by a genuine second-order Newton equation.
The motion of the plants is modeled as follows: each plant is attached by a spring to a fixed anchor point. It experiences three forces: a force coming from the wave, modeled by a steepest descent dynamics (the plant is pushed where the water is lower), a harmonic spring force towards the anchor point (harmonic here means the force is proportional to the distance to the anchor point), and a damping force proportional to its velocity. When the spring becomes longer than a threshold, it breaks, meaning that the tree is no longer anchored and can move around. The threshold is proportional to the area of the circle, to represent the fact that larger trees are more resistant. The mass entering the equation of motion is also proportional to the area, which is why bigger circles move more slowly. 
And yes, the trees are still allowed to cross each other, because having them interact would take way more computing ressources - let's just say the trees can wind around each other in the 3rd dimension. But I hope to be able to address that in the future. 
The wave speed is reduced here to 50% inside the plants (corresponding to an index of refraction of 2). As in previous videos, the circles have been generated by a Poisson disc sampling algorithm,  and their radius has been randomized. 
The colors outside the mangrove represent the wave height. Having the waves arrive at a prescribed angle is achieved by imposing suitable oscillating boundary conditions on the left boundary, and on the top and bottom boundary left of the mangrove. There are periodic boundary conditions on the remaining parts of top and bottom (meaning these parts are glued together), and absorbing boundary conditions on the right. 

Render time: 1 hour 24 minutes

Music: "Always the Same" by SefChol@SefChol

See also https://images.math.cnrs.fr/Des-ondes-dans-mon-billard-partie-I.html for more explanations (in French) on  a few previous simulations of wave equations. 

The simulation solves the wave equation by discretization. The algorithm is adapted from the paper https://hplgit.github.io/fdm-book/doc/pub/wave/pdf/wave-4print.pdf 
C code: https://github.com/nilsberglund-orleans/YouTube-simulations
https://www.idpoisson.fr/berglund/software.html 
Many thanks to my colleague Marco Mancini for helping me to accelerate my code!