Consider simulating a ball on a rippled surface, resting on a rightward-facing slope.
The force of gravity is balanced by the force of the ground to give a rightward down-hill acceleration
From here we consider two possible time steps
Applying that acceleration and the resulting velocity with an Euler time step puts the ball inside the ground
Correcting that penetration we now have a ball moving to the right in the bottom of the valley.
Here gravity and the ground fully cancel each other out, so next step only momenum moves the ball, again into the ground which we correct
From here gravity will pull it back down, oscillating back and forth across the valley until friction stops it.
Applying that acceleration and the resulting velocity with an Euler time step puts the ball inside the ground
Correcting that penetration we now have a ball moving to the right and, because of the large time step, having jumped over to the next hill.
Because the ball is on another rightward-facing slope, gravity will pull it further to the right, causing it to jump even more hills next time step.
This will continue with the ball jumping ever further each new time step.
In most time-step simulations, there is a time step that is too large
can causes instability. Courant, Friedrichs and Lewy introduced some
criteria describing time steps that do not have that instability; it is
not common to call whatever time step ensures stability the CFL
condition
even if the particular simulation does not fit their
original discussion.
Common CFL conditions look something like the time step has to be
small enough that no particle can move further than X in a
single time step.
The specific Xs vary, but may include
simulation-specific features like half of a particle diameter
and
physically-defined features like the speed of sound
. Because CFL
conditions are often defined base on the distance particles would move
in a single time step the time steps they allow are generally different
each frame, allowing large time steps when things are mostly still but
requiring small time steps when things are moving quickly.
Details of how to compute CFL conditions for a specific simulation are beyond the scope of this page. A reasonable first step is
Each frame, find the speed of the fastest-moving thing
Divide the time from that frame to the next into a set of time steps such that that fastest-moving thing only moves at most x per step, where x is a parameter you tuned via guess-and-check in advance.
One particle radius is a good initial guess for x because it will prevent particles from passing completely through one another in a single step. Depending on the simulation, a larger or smaller x might be needed.
This simple constant-based approach will not always work. If you are implementing a method others have published, look for what CFL condition they used. CFL conditions are often mentioned only in passing as part of presenting timing results.