Modelintro
Gerstner waves
Also called trochoidal waves.
Model ocean waves by moving surface points on circles, which gives sharp crests and flat troughs, summed over several wave trains.
A Gerstner wave moves each point of the water surface on a circle, so that the points crowd together at the crests and spread out in the troughs. The surface that results is a trochoid: the crests are sharper and the troughs flatter than those of a sine wave of the same height. Gerstner found in 1802 that this motion is an exact solution of the equations of an ideal fluid in deep water, with a free surface at a constant pressure. In computer graphics, Fournier and Reeves (1986) and Peachey (1986) used trochoidal waves for the sea, and real-time water adds a few of them in different directions, as in Finch (2004). The waves come from a closed formula, so there is no simulation and no grid.
The machine
One wave, the exact model. The water fills at rest and is deep compared with the wavelength. Each water particle has a label , its rest position, with . At the time it is at
and the surface is the curve of the particles with . The parameters are:
- the amplitude in m,
- the wave number in rad/m, for the wavelength in m,
- the angular frequency in rad/s, fixed by the deep water dispersion relation , with m/s²,
- a phase in rad,
- the steepness , with no loops for ; the exact model needs .
The wave runs in the direction at the phase speed . The standing assumptions are deep water, an incompressible fluid with no viscosity, gravity as the only force, a constant pressure on the surface, no wind and no surface tension. The surface is a parametric curve, not a height field, so it can hold a sharp crest.
A sum of waves, the graphics model. On a 3D surface, the rest point moves to
with a unit direction , an amplitude and a wave number for each wave, , and a choppiness that scales the horizontal motion. For one wave and , this is the exact model. A sum of exact solutions of these nonlinear equations is not shown to be a solution, so the sum is a model for images, not a solution of the flow.
What it counts
The model gives the position of the surface at each time: the height and the horizontal displacement of each rest point. It also gives the velocity of each particle, for one wave, and so the motion of a floating object that follows the water. The surface normal comes from the two tangents and of the formula.
For one wave of wavelength 10 m on deep water, rad/m, rad/s, the period is s and the phase speed is m/s. The table gives the values that the model predicts for three amplitudes of this wave, computed by the code. The mean level is the mean surface height over .
| (m) | mean level (m) | crest above the mean (m) | trough below the mean (m) | particle speed at the surface (m/s) | vorticity at the surface (1/s) | part of the wavelength above the mean | |
|---|---|---|---|---|---|---|---|
| 0.3 | 0.189 | -0.028 | 0.328 | 0.272 | 0.745 | 0.183 | 0.470 |
| 0.8 | 0.503 | -0.201 | 1.001 | 0.599 | 1.986 | 1.679 | 0.426 |
| 1.592 | 1.000 | -0.796 | 2.387 | 0.796 | 3.951 | no limit | 0.391 |
The crest stands higher above the mean level than the trough falls below it, and it is narrower; at the crest is a cusp. Five meters below the surface, the orbits of this wave have only percent of the radius at the surface.
Relation to other models
- Linear (sine) waves. For small , the height of a Gerstner wave at a fixed is plus terms of order . So to first order it is the sine wave of linear theory, with the same dispersion relation.
- Stokes waves. A wave that starts from water at rest in an ideal fluid has no vorticity, by the theorem of Kelvin. The Gerstner flow has vorticity, so it is not that wave; the periodic waves of the irrotational theory are the Stokes waves, which this page does not cover.
- FFT ocean synthesis. The choppy displacement of FFT ocean synthesis moves each point by times a sine term for each wave, the horizontal motion of a sum of Gerstner waves with random amplitudes and phases. FFT synthesis uses thousands of waves from a spectrum; a Gerstner sum uses a few that the artist chooses.
- Height field water. Height field water and the shallow water equations simulate the water and so react to objects and to the ground, but have no sharp crests. A Gerstner wave reacts to nothing.
- Shallow water. Near a beach the deep water assumption fails. Fournier and Reeves, and Peachey, changed the waves with the depth of the water; with depth , the linear dispersion relation becomes , and for long waves the speed tends to , which is m/s for m.
- Fluid equations. The model is a special solution of the incompressible Euler equations, the Navier-Stokes equations with no viscosity.
Known results in the model
The proof page has the proofs, and the tests check each result with the code.
- Exact solution (proved). With and , the motion satisfies the Euler equations in Lagrangian form, with a pressure that depends on only. So the pressure is constant on the surface , as the free surface needs. With any other , the equations fail.
- Incompressible (proved). The Jacobian of the map from to is , which does not change in time, so every part of the water keeps its area.
- Circular orbits (proved). Each particle moves on a circle of radius about its label, once per period, so the radius falls by the factor for each meter of depth.
- Rotational flow (proved). The vorticity is with . It is not 0, and it turns the other way from the particles on their orbits.
- Shape (proved). The crest is at and the trough at , but the mean level of the surface over is . The surface is stretched by the factor at the crest and at the trough, so the crest is sharp. At the crest is a cusp, and for the curve crosses itself and makes a loop. The part of the wavelength above the mean level is measured in the table.
- Crest speed (proved). At the crest the surface particle moves forward at , which equals the phase speed exactly when .
- No loops in a sum (proved). If , the horizontal map is one to one at every time, so the 3D surface does not fold over itself. Finch (2004) gives the same kind of condition: the sum of at most 1, with one for each wave. The condition is sufficient, not necessary.
- Dispersion (law). is the dispersion law of small waves on deep water, and the Gerstner wave has it for every amplitude.
Proof: The Gerstner wave is an exact rotational solution, and a sum with small steepness has no loopsfull
We use the notation of the page. For one wave, write , and , so that and . The derivatives with respect to the labels are
because . The velocity is and , and the acceleration is and .
Area and orbits
Claim 1. The Jacobian is . It does not depend on , so the flow keeps the area of every part of the water. For the map from the labels to the positions is one to one at every time.
Proof. . Area preservation is the statement that is constant in time. For one to one, note that for . Its Hessian is the symmetric matrix with the entries , and , with trace 2 and determinant , so its eigenvalues are on . The half plane is convex, so for two labels in it, , and the two positions differ.
Claim 2. Each particle moves on the circle of radius about , once per period .
Proof. , and changes by in the time .
The exact solution
Claim 3. If and , the motion satisfies the Euler equations of an incompressible ideal fluid under gravity, with the pressure
which is constant on the surface . If , no pressure that is constant on the surface fits the motion.
Proof. The Euler equations are and , and incompressibility holds by Claim 1. By the chain rule and , so in the labels the equations are
The first right side is , since the terms cancel and . The second right side is . With , the first is 0 and the second is , and these are and of the pressure above divided by . With , the first right side is not 0 at for , so along the surface and the pressure there is not constant.
Vorticity
Claim 4. The vorticity is , which is positive, while the particles turn clockwise.
Proof. Inverting the label map gives , , and . With , , and : and . The difference is . The position on the circle is , at the angle , which decreases in time, so the particles turn clockwise.
Shape of the surface
Take , and , so , , and the surface is , . Other times and phases only shift it.
Claim 5. The crest is at and the trough at . The surface is stretched by at the crest and at the trough. For the mean height over is . At the crest is a cusp, and for the surface crosses itself.
Proof. The values of and at and are direct. For , is nondecreasing and , so the mean over one wavelength is . At , both and are 0 at , and near it while , so grows like : a cusp. For , is negative for small and equals at , so for some . Since is odd and is even in , the points and have the same and the same , and they are different points of the curve.
Claim 6. At the crest the surface particle moves forward at , and this equals the phase speed exactly when .
Proof. At , and . if and only if .
A sum of waves
Claim 7. Let . Then at every time the horizontal map satisfies , so it is one to one, and its Jacobian matrix is symmetric with eigenvalues at least .
Proof. for , because . The Hessian is , which is the Jacobian matrix of and is symmetric. For a unit vector , , so . Then , which is positive for , so .
The test checks Claims 1 to 7 with the code, by finite differences for Claims 1, 3 and 4 and on random sums of waves for Claim 7.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gerstner-waves/. The authors are listed in prov/4CGSP7.jsonl.
"""Gerstner (trochoidal) waves on deep water.
One wave in 2D, in Lagrangian form. The water particle with the label (a, b),
b <= 0, is at
x = a - A e^(k b) sin(theta), z = b + A e^(k b) cos(theta),
theta = k a - w t + phase, w^2 = g k.
The surface is the line of particles with b = 0. The wave runs in the +x
direction, and each particle moves on a circle of radius A e^(k b).
The sum of several waves on a surface in 3D, as used in graphics, moves the
rest point p = (p_x, p_y) to
p - chop * sum_i d_i A_i sin(theta_i), height sum_i A_i cos(theta_i),
theta_i = k_i d_i . p - w_i t + phase_i,
for unit directions d_i. A sum is not an exact solution of the flow
equations; it is a model of this file and of the graphics papers.
"""
import math
G = 9.81
def dispersion(k, g=G, depth=None):
"""The angular frequency w: (g k)^(1/2) in deep water, (g k tanh(k d))^(1/2) at the depth d."""
if depth is None:
return math.sqrt(g * k)
return math.sqrt(g * k * math.tanh(k * depth))
def deep_water(wavelength, g=G):
"""(k, w, period, phase speed) of a deep water wave of the given wavelength (m)."""
k = 2.0 * math.pi / wavelength
w = dispersion(k, g)
return k, w, 2.0 * math.pi / w, w / k
def phase_speed(k, g=G, depth=None):
"""w / k. In deep water (g / k)^(1/2); for k d small at the depth d it tends to (g d)^(1/2)."""
return dispersion(k, g, depth) / k
def particle(a, b, t, amplitude, k, g=G, phase=0.0, w=None):
"""The position (x, z) of the particle with the label (a, b) at the time t. w defaults to (g k)^(1/2)."""
if w is None:
w = dispersion(k, g)
r = amplitude * math.exp(k * b)
theta = k * a - w * t + phase
return a - r * math.sin(theta), b + r * math.cos(theta)
def particle_velocity(a, b, t, amplitude, k, g=G, phase=0.0):
"""The velocity (u, v) of the particle with the label (a, b): the time derivative of particle()."""
w = dispersion(k, g)
r = amplitude * math.exp(k * b)
theta = k * a - w * t + phase
return r * w * math.cos(theta), r * w * math.sin(theta)
def jacobian(a, b, amplitude, k):
"""det d(x, z) / d(a, b) = 1 - (k A e^(k b))^2. It does not depend on the time."""
s = k * amplitude * math.exp(k * b)
return 1.0 - s * s
def vorticity(b, amplitude, k, g=G):
"""The vorticity dv/dx - du/dz at the particle with the depth label b: 2 w s^2 / (1 - s^2), s = k A e^(k b).
It is positive (counterclockwise), while the particles turn clockwise for a wave that runs in +x.
"""
s = k * amplitude * math.exp(k * b)
return 2.0 * dispersion(k, g) * s * s / (1.0 - s * s)
def surface_point(px, py, t, waves, chop=1.0, g=G):
"""The surface point (x, y, z) of the rest point (px, py) for a sum of waves.
waves is a list of (amplitude, wavelength, (dx, dy), phase) with a unit direction (dx, dy).
"""
x, y, z = px, py, 0.0
for amp, wavelength, (dx, dy), phase in waves:
k = 2.0 * math.pi / wavelength
theta = k * (dx * px + dy * py) - dispersion(k, g) * t + phase
s, c = math.sin(theta), math.cos(theta)
x -= chop * dx * amp * s
y -= chop * dy * amp * s
z += amp * c
return x, y, z
def horizontal_jacobian(px, py, t, waves, chop=1.0, g=G):
"""The 2 by 2 matrix d(x, y) / d(px, py) of surface_point, as ((j11, j12), (j21, j22))."""
j11, j12, j22 = 1.0, 0.0, 1.0
for amp, wavelength, (dx, dy), phase in waves:
k = 2.0 * math.pi / wavelength
theta = k * (dx * px + dy * py) - dispersion(k, g) * t + phase
f = chop * k * amp * math.cos(theta)
j11 -= f * dx * dx
j12 -= f * dx * dy
j22 -= f * dy * dy
return (j11, j12), (j12, j22)
def steepness(waves, chop=1.0):
"""chop * sum_i k_i A_i. If it is below 1, the surface has no loops (see the proof page)."""
return chop * sum(2.0 * math.pi / wl * amp for amp, wl, _, _ in waves)
def mean_level(amplitude, k, samples=4096):
"""The mean surface height over x of one wave (b = 0, t = 0), by a sum over equally spaced labels a.
Each label carries the length dx/da da of the surface, so the mean is
sum z dx/da / sum dx/da. The proof page shows it is -k A^2 / 2 for k A < 1.
"""
num = 0.0
den = 0.0
for i in range(samples):
theta = 2.0 * math.pi * i / samples
dxda = 1.0 - k * amplitude * math.cos(theta)
num += amplitude * math.cos(theta) * dxda
den += dxda
return num / den
test_gerstner_waves.py 166 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gerstner-waves/. The authors are listed in prov/4CGSP7.jsonl.
import math
import random
import unittest
import gerstner_waves as gw
def euler_residuals(a, b, t, amp, k, w, g=gw.G, h=1e-4):
"""The two Lagrangian momentum equations, by central differences.
Returns (x_tt x_a + (z_tt + g) z_a, x_tt x_b + (z_tt + g) z_b), which equal -p_a / rho and -p_b / rho.
"""
def pos(aa, bb, tt):
return gw.particle(aa, bb, tt, amp, k, g, w=w)
xp, zp = pos(a, b, t + h)
x0, z0 = pos(a, b, t)
xm, zm = pos(a, b, t - h)
xtt, ztt = (xp - 2 * x0 + xm) / h ** 2, (zp - 2 * z0 + zm) / h ** 2
xa = (pos(a + h, b, t)[0] - pos(a - h, b, t)[0]) / (2 * h)
za = (pos(a + h, b, t)[1] - pos(a - h, b, t)[1]) / (2 * h)
xb = (pos(a, b + h, t)[0] - pos(a, b - h, t)[0]) / (2 * h)
zb = (pos(a, b + h, t)[1] - pos(a, b - h, t)[1]) / (2 * h)
return xtt * xa + (ztt + g) * za, xtt * xb + (ztt + g) * zb
class TestDispersion(unittest.TestCase):
def test_deep_water_check_values(self):
k, w, period, speed = gw.deep_water(10.0, 9.81)
self.assertAlmostEqual(k, 0.628319, places=6)
self.assertAlmostEqual(w, 2.482701, places=6)
self.assertAlmostEqual(period, 2.530786, places=6)
self.assertAlmostEqual(speed, 3.951342, places=6)
self.assertAlmostEqual(gw.phase_speed(k), speed, places=12)
def test_shallow_limit(self):
k = 2 * math.pi / 2000.0
self.assertAlmostEqual(gw.phase_speed(k, depth=1.0), 3.13209, places=4)
self.assertAlmostEqual(math.sqrt(9.81 * 1.0), 3.13209, places=5)
self.assertLess(gw.phase_speed(0.628319, depth=1.0), gw.phase_speed(0.628319))
class TestOneWave(unittest.TestCase):
def test_circular_orbits(self):
rng = random.Random(1)
k, amp = 0.628319, 0.6
for _ in range(50):
a, b, t = rng.uniform(-20, 20), rng.uniform(-5, 0), rng.uniform(0, 10)
x, z = gw.particle(a, b, t, amp, k)
self.assertAlmostEqual(math.hypot(x - a, z - b), amp * math.exp(k * b), places=12)
u, v = gw.particle_velocity(a, b, t, amp, k)
self.assertAlmostEqual(math.hypot(u, v), amp * math.exp(k * b) * gw.dispersion(k), places=12)
def test_crest_moves_at_phase_speed(self):
k, amp = 0.628319, 0.5
_, _, _, speed = gw.deep_water(2 * math.pi / k)
for t in (0.0, 1.0, 3.7):
crest = gw.dispersion(k) * t / k
x, z = gw.particle(crest, 0.0, t, amp, k)
self.assertAlmostEqual(x, speed * t, places=9)
self.assertAlmostEqual(z, amp, places=12)
def test_exact_euler_solution(self):
rng = random.Random(2)
k, amp = 0.5, 1.2
w = gw.dispersion(k)
for _ in range(20):
a, b, t = rng.uniform(-10, 10), rng.uniform(-3, 0), rng.uniform(0, 5)
ra, rb = euler_residuals(a, b, t, amp, k, w)
self.assertLess(abs(ra), 1e-5)
s = k * amp * math.exp(k * b)
self.assertAlmostEqual(rb, gw.G * (1 - s * s), places=4)
ra, _ = euler_residuals(1.0, 0.0, 0.3, amp, k, 1.2 * w)
self.assertGreater(abs(ra), 0.1)
def test_volume_and_vorticity(self):
rng = random.Random(3)
k, amp, h = 0.7, 1.0, 1e-5
for _ in range(20):
a, b, t = rng.uniform(-5, 5), rng.uniform(-2, 0), rng.uniform(0, 5)
p = lambda aa, bb: gw.particle(aa, bb, t, amp, k)
xa = [(p(a + h, b)[i] - p(a - h, b)[i]) / (2 * h) for i in (0, 1)]
xb = [(p(a, b + h)[i] - p(a, b - h)[i]) / (2 * h) for i in (0, 1)]
jac = xa[0] * xb[1] - xb[0] * xa[1]
self.assertAlmostEqual(jac, gw.jacobian(a, b, amp, k), places=7)
vel = lambda aa, bb: gw.particle_velocity(aa, bb, t, amp, k)
ua = [(vel(a + h, b)[i] - vel(a - h, b)[i]) / (2 * h) for i in (0, 1)]
ub = [(vel(a, b + h)[i] - vel(a, b - h)[i]) / (2 * h) for i in (0, 1)]
dv_dx = (ua[1] * xb[1] - ub[1] * xa[1]) / jac
du_dz = (ub[0] * xa[0] - ua[0] * xb[0]) / jac
self.assertAlmostEqual(dv_dx - du_dz, gw.vorticity(b, amp, k), places=5)
self.assertGreater(gw.vorticity(0.0, amp, k), 0.0)
def test_crest_shape_and_loops(self):
k = 1.0
n = 2000
def surface_x(amp):
return [gw.particle(2 * math.pi * i / n, 0.0, 0.0, amp, k)[0] for i in range(-n // 2, n // 2)]
for ka, loops in ((0.5, False), (0.99, False), (1.2, True)):
xs = surface_x(ka / k)
self.assertEqual(any(x2 <= x1 for x1, x2 in zip(xs, xs[1:])), loops)
self.assertAlmostEqual(gw.jacobian(0.0, 0.0, 1.0, 1.0), 0.0, places=15)
def test_mean_level(self):
for k, amp in ((0.628319, 0.5), (1.0, 0.8), (0.2, 3.0)):
self.assertAlmostEqual(gw.mean_level(amp, k), -k * amp * amp / 2, places=12)
class TestSum(unittest.TestCase):
def waves(self, rng, count, total):
out = []
weights = [rng.uniform(0.2, 1.0) for _ in range(count)]
for wt in weights:
wl = rng.uniform(2.0, 40.0)
ang = rng.uniform(0, 2 * math.pi)
k = 2 * math.pi / wl
out.append((total * wt / sum(weights) / k, wl, (math.cos(ang), math.sin(ang)), rng.uniform(0, 6)))
return out
def test_jacobian_matches_differences(self):
rng = random.Random(4)
waves = self.waves(rng, 5, 0.8)
h = 1e-5
for _ in range(10):
px, py, t = rng.uniform(-30, 30), rng.uniform(-30, 30), rng.uniform(0, 9)
(j11, j12), (j21, j22) = gw.horizontal_jacobian(px, py, t, waves)
f = lambda qx, qy: gw.surface_point(qx, qy, t, waves)
self.assertAlmostEqual(j11, (f(px + h, py)[0] - f(px - h, py)[0]) / (2 * h), places=6)
self.assertAlmostEqual(j21, (f(px + h, py)[1] - f(px - h, py)[1]) / (2 * h), places=6)
self.assertAlmostEqual(j12, (f(px, py + h)[0] - f(px, py - h)[0]) / (2 * h), places=6)
def test_no_loops_below_steepness_one(self):
rng = random.Random(5)
for trial in range(5):
waves = self.waves(rng, 6, 0.9)
s = gw.steepness(waves)
self.assertAlmostEqual(s, 0.9, places=12)
for _ in range(200):
p = (rng.uniform(-50, 50), rng.uniform(-50, 50))
q = (rng.uniform(-50, 50), rng.uniform(-50, 50))
t = rng.uniform(0, 20)
fp = gw.surface_point(p[0], p[1], t, waves)
fq = gw.surface_point(q[0], q[1], t, waves)
dot = (fp[0] - fq[0]) * (p[0] - q[0]) + (fp[1] - fq[1]) * (p[1] - q[1])
d2 = (p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2
self.assertGreaterEqual(dot, (1 - s) * d2 - 1e-9)
(j11, j12), (_, j22) = gw.horizontal_jacobian(p[0], p[1], t, waves)
self.assertGreater(j11 * j22 - j12 * j12, 0.0)
def test_one_wave_sum_equals_particle(self):
k, amp = 0.628319, 0.4
waves = [(amp, 2 * math.pi / k, (1.0, 0.0), 0.3)]
for px in (-3.0, 0.0, 2.5):
x, y, z = gw.surface_point(px, 7.0, 1.1, waves)
xe, ze = gw.particle(px, 0.0, 1.1, amp, k, phase=0.3)
self.assertAlmostEqual(x, xe, places=12)
self.assertAlmostEqual(z, ze, places=12)
self.assertEqual(y, 7.0)
if __name__ == "__main__":
unittest.main()
References
- Alain Fournier and William T. Reeves, A simple model of ocean waves, Proceedings of SIGGRAPH 86, 75-84, 1986, the whole paper (the Gerstner model of the surface and the orbits of the particles)
- Darwyn R. Peachey, Modeling waves and surf, Proceedings of SIGGRAPH 86, 65-74, 1986, the whole paper (wave profiles, the depth of the water and spray)
- Mark Finch, Effective water simulation from physical models, Chapter 1 (the sum of Gerstner waves, the steepness parameter Q and the condition against loops at the crests)
- Simulating Ocean Water, the notes as a whole (Gerstner waves and the dispersion relation, general locator)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H2 full proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 4CGSP7 Edit this page History Report an error Markdown