Algorithm Search⌘K

Algorithmadvanced

Vortex particle method

Also called vortex blob method.

Represents an incompressible flow by particles that carry vorticity and moves them with the velocity from the Biot-Savart law, often summed by a tree or FMM.

Time
Θ(N^2) worst
Space
Θ(N) extra
Where
N = the number of vortex particles
Properties
conservativedeterministic
Origin
Alexandre J. Chorin, 1973

A vortex particle method simulates an incompressible flow with particles that carry vorticity, the local spin of the fluid, instead of a velocity grid. The velocity at any point is the sum of the swirls induced by all the particles (the Biot-Savart law), each swirl smoothed over a small core so that it stays finite, and the particles simply move with that velocity. There is no pressure solve, no grid, and no numerical diffusion from advection, and the particles go only where the flow has vorticity, so wakes, vortex rings and mixing layers are cheap to follow. In computer graphics, vortex particles are added to a grid fluid solver to keep small swirls in smoke and fire, close to what vorticity confinement does; the method on this page is the full flow solver, with a smoothed kernel whose error goes to zero as the cores and the spacing shrink, and with viscosity added by particle strength exchange.

In plain words

Think of the flow as many small whirlpools. Each whirlpool is a particle that knows how strong it is and which way it turns. Every whirlpool pushes every other one around it, more strongly when they are close. To move the flow forward, add up the push from all the whirlpools at each particle, move each particle a little, and repeat. A whirlpool keeps its strength as it moves, as long as the fluid has no friction. To stop two whirlpools from flinging each other away when they come very close, each one is a soft blob with a small round core.

The problem

In 2D, an incompressible inviscid flow with velocity uu has the scalar vorticity ω=∂xu2−∂yu1\omega = \partial_x u_2 - \partial_y u_1, and the Euler equations become the transport equation

∂ω∂t+u⋅∇ω=0,u=K∗ω,K(x)=12π(−x2,x1)∣x∣2,\frac{\partial \omega}{\partial t} + u \cdot \nabla \omega = 0, \qquad u = K * \omega, \qquad K(x) = \frac{1}{2 \pi} \frac{(-x_2, x_1)}{|x|^2},

where the second equation is the Biot-Savart law for a flow in the whole plane that is at rest at infinity. So vorticity is carried by the flow: each fluid element keeps its vorticity.

The method writes the vorticity as a sum of NN blobs, ωh(x)=∑pΓpζδ(x−xp)\omega_h(x) = \sum_p \Gamma_p \zeta_\delta(x - x_p), with the circulations Γp=ω0(xp0) ℓ2\Gamma_p = \omega_0(x_p^0)\, \ell^2 from the initial vorticity on a lattice of spacing ℓ\ell, and the Gaussian core ζδ(x)=e−∣x∣2/δ2/(πδ2)\zeta_\delta(x) = e^{-|x|^2 / \delta^2} / (\pi \delta^2). The velocity of this field is the sum over the smoothed kernel

Kδ(x)=(−x2,x1)2π∣x∣2(1−e−∣x∣2/δ2),u(x)=∑qΓqKδ(x−xq),K_\delta(x) = \frac{(-x_2, x_1)}{2 \pi |x|^2} \bigl(1 - e^{-|x|^2 / \delta^2}\bigr), \qquad u(x) = \sum_q \Gamma_q K_\delta(x - x_q),

and the particles solve x˙p=u(xp)\dot x_p = u(x_p) with fixed Γp\Gamma_p. The code on this page uses direct summation and the explicit midpoint rule in time.

The algorithm

  1. VORTEX-STEP(x, Γ, δ, h)
  2. 1for each particle p do
  3. 2u_p ← Σ_{q ≠ p} Γ_q K_δ(x_p - x_q) ▷ Biot-Savart law with the blob kernel
  4. 3x_p* ← x_p + (h / 2) u_p for every p ▷ half step
  5. 4u_p* ← Σ_{q ≠ p} Γ_q K_δ(x_p* - x_q*) for every p ▷ velocity at the midpoint
  6. 5x_p ← x_p + h u_p* for every p
  7. 6return x; the circulations Γ_p do not change

Lines L1 and L2 are an N-body sum like gravity, with the kernel turned by 90 degrees. The code visits each pair once and uses Kδ(−x)=−Kδ(x)K_\delta(-x) = -K_\delta(x) to add the two contributions. Kδ(0)=0K_\delta(0) = 0, so a particle does not move itself. Lines L3 to L5 are the explicit midpoint method. For viscous flow, a diffusion step changes the Γp\Gamma_p after line L5, for example by particle strength exchange.

Example

A pair of equal blobs. Put Γ=2π\Gamma = 2\pi at (−0.5,0)(-0.5, 0) and at (0.5,0)(0.5, 0), with δ=0.5\delta = 0.5. Line L2 gives the right particle the velocity ΓKδ(1,0)=(0, 1−e−4)=(0,0.98168)\Gamma K_\delta(1, 0) = (0,\ 1 - e^{-4}) = (0, 0.98168) and the left one (0,−0.98168)(0, -0.98168). The pair turns counterclockwise about its centre at Ω=2⋅0.98168/1=1.9634\Omega = 2 \cdot 0.98168 / 1 = 1.9634, a little slower than the Ω=Γ/(πd2)=2\Omega = \Gamma / (\pi d^2) = 2 of two point vortices at distance d=1d = 1. The code reproduces this rotation over 200 steps.

The Lamb-Oseen vortex. The vorticity ω=Γ/(4πνt) e−r2/(4νt)\omega = \Gamma / (4 \pi \nu t)\, e^{-r^2 / (4 \nu t)} has the azimuthal velocity uθ=Γ/(2πr) (1−e−r2/(4νt))u_\theta = \Gamma / (2 \pi r)\, (1 - e^{-r^2 / (4 \nu t)}), and every radial vorticity is a steady solution of the Euler equations. Take Γ=1\Gamma = 1, 4νt=0.044 \nu t = 0.04, a lattice with ℓ=0.05\ell = 0.05 cut to the disc r≤0.6r \le 0.6 (437 particles, total circulation 0.99984) and δ=0.1\delta = 0.1. A Gaussian blob of size δ\delta convolved with a Gaussian vorticity of size 4νt\sqrt{4 \nu t} is a Gaussian of size 4νt+δ2\sqrt{4 \nu t + \delta^2}, so the blob field should be the Lamb-Oseen vortex at the later time t+δ2/(4ν)t + \delta^2 / (4 \nu). The measured velocity at radii 0.05 to 0.5 matches that vortex within 3.3×10−63.3 \times 10^{-6}; against the vortex at time tt the error is 0.065, and with δ=0.05\delta = 0.05 it is 0.018, close to the ratio 4 of a second order smoothing error (measurements; the largest speed is 0.51). In a run of 20 midpoint steps of h=0.05h = 0.05 with ℓ=0.1\ell = 0.1 (109 particles) and δ=0.15\delta = 0.15, every particle stays on its circle within 10−410^{-4} and turns at the predicted rate.

Correctness

The proofs of the facts below about the kernel, the Lamb-Oseen check and the invariants are in the correctness proof.

The method conserves the invariants of 2D Euler flow (theorems for the particle equations x˙p=u(xp)\dot x_p = u(x_p)). Write Kpq=Kδ(xp−xq)K_{pq} = K_\delta(x_p - x_q). Since Kδ(−x)=−Kδ(x)K_\delta(-x) = -K_\delta(x), the linear impulse ∑pΓpxp\sum_p \Gamma_p x_p has the derivative ∑p,qΓpΓqKpq=0\sum_{p, q} \Gamma_p \Gamma_q K_{pq} = 0. Since also x⋅Kδ(x)=0x \cdot K_\delta(x) = 0, the angular impulse ∑pΓp∣xp∣2\sum_p \Gamma_p |x_p|^2 has the derivative 2∑p,qΓpΓq xp⋅Kpq=∑p,qΓpΓq(xp−xq)⋅Kpq=02 \sum_{p, q} \Gamma_p \Gamma_q\, x_p \cdot K_{pq} = \sum_{p, q} \Gamma_p \Gamma_q (x_p - x_q) \cdot K_{pq} = 0. The total circulation ∑pΓp\sum_p \Gamma_p is constant because no Γp\Gamma_p changes. The particle system is also Hamiltonian, with the interaction energy of the blobs as the Hamiltonian, and that energy is conserved. Each stage of the midpoint rule moves the points by a sum of the same antisymmetric terms, so the linear impulse stays exact to rounding; the angular impulse and the energy change by O(h3)O(h^3) per step.

The velocity field is exact for the blob vorticity. Kδ=K∗ζδK_\delta = K * \zeta_\delta, so u=∑qΓqKδ(⋅−xq)u = \sum_q \Gamma_q K_\delta(\cdot - x_q) is the divergence free velocity whose curl is ωh\omega_h (a theorem; the tests check both by finite differences).

Convergence. The error of the method has two parts: the smoothing error, from replacing ω\omega by ω∗ζδ\omega * \zeta_\delta, which is O(δ2)O(\delta^2) for the Gaussian, and the quadrature error of the lattice sum, which is very small while the blobs overlap (ℓ<δ\ell < \delta). Beale and Majda (1982) proved that for smooth flows over a finite time the blob method converges with the order of the kernel, if ℓ\ell goes to zero faster than δ\delta; kernels of higher order give higher orders. Over long times the particles spread unevenly, the overlap is lost and the error grows, which is why practical codes remesh.

Proof: The blob velocity is the exact velocity of the blob vorticity, and the particle equations conserve circulation, linear impulse and angular impulsefull

We work in the plane with x⊥=(−x2,x1)x^\perp = (-x_2, x_1), the Gaussian core ζδ(x)=e−∣x∣2/δ2/(πδ2)\zeta_\delta(x) = e^{-|x|^2/\delta^2} / (\pi \delta^2) and the kernel

Kδ(x)=x⊥2π∣x∣2(1−e−∣x∣2/δ2),Kδ(0)=0.K_\delta(x) = \frac{x^\perp}{2 \pi |x|^2} \bigl(1 - e^{-|x|^2/\delta^2}\bigr), \qquad K_\delta(0) = 0.

Write q(r)=(1−e−r2/δ2)/(2πr2)q(r) = (1 - e^{-r^2/\delta^2}) / (2 \pi r^2), so Kδ(x)=q(∣x∣) x⊥K_\delta(x) = q(|x|)\, x^\perp. As r→0r \to 0, q(r)→1/(2πδ2)q(r) \to 1 / (2 \pi \delta^2), so KδK_\delta is continuous and smooth at 0.

Claim 1 (the velocity of one blob). u=Kδu = K_\delta is divergence free, and its curl is ζδ\zeta_\delta.

Proof. Kδ=∇⊥ψK_\delta = \nabla^\perp \psi with ∇⊥ψ=(−∂2ψ,∂1ψ)\nabla^\perp \psi = (-\partial_2 \psi, \partial_1 \psi) for any radial ψ\psi with ψ′(r)=r q(r)\psi'(r) = r\, q(r), since ∇ψ=ψ′(r) x/r\nabla \psi = \psi'(r)\, x / r. A field of the form ∇⊥ψ\nabla^\perp \psi has divergence −∂1∂2ψ+∂2∂1ψ=0-\partial_1 \partial_2 \psi + \partial_2 \partial_1 \psi = 0 and curl ∂1∂1ψ+∂2∂2ψ=Δψ\partial_1 \partial_1 \psi + \partial_2 \partial_2 \psi = \Delta \psi. For a radial function, Δψ=1r(rψ′)′\Delta \psi = \frac{1}{r} (r \psi')', and rψ′=r2q(r)=(1−e−r2/δ2)/(2π)r \psi' = r^2 q(r) = (1 - e^{-r^2/\delta^2}) / (2\pi), whose derivative is 2rδ2e−r2/δ2/(2π)\frac{2 r}{\delta^2} e^{-r^2/\delta^2} / (2 \pi). Dividing by rr gives e−r2/δ2/(πδ2)=ζδe^{-r^2/\delta^2} / (\pi \delta^2) = \zeta_\delta. □\square

By linearity, u(x)=∑qΓqKδ(x−xq)u(x) = \sum_q \Gamma_q K_\delta(x - x_q) is divergence free with curl ωh=∑qΓqζδ(⋅−xq)\omega_h = \sum_q \Gamma_q \zeta_\delta(\cdot - x_q). It also tends to 0 at infinity, like 1/∣x∣1/|x|, so it is the velocity that the Biot-Savart law gives for ωh\omega_h.

Claim 2 (the Lamb-Oseen check). If ω\omega is the Lamb-Oseen vorticity Γζa\Gamma \zeta_a with a2=4νta^2 = 4 \nu t, then ω∗ζδ=Γζb\omega * \zeta_\delta = \Gamma \zeta_b with b2=a2+δ2b^2 = a^2 + \delta^2, whose velocity is the Lamb-Oseen velocity at time t+δ2/(4ν)t + \delta^2 / (4 \nu).

Proof. ζa\zeta_a is the density of a 2D normal law with variance a2/2a^2 / 2 in each coordinate. The convolution of two such densities is the density of the sum of independent variables, which is normal with variance (a2+δ2)/2(a^2 + \delta^2)/2, that is ζb\zeta_b. By Claim 1 with δ\delta replaced by bb, its velocity is ΓKb\Gamma K_b, with azimuthal component Γ(1−e−r2/b2)/(2πr)\Gamma (1 - e^{-r^2/b^2}) / (2 \pi r), and b2=4ν(t+δ2/(4ν))b^2 = 4 \nu (t + \delta^2/(4\nu)). □\square

So the lattice sum on the page approximates ΓKb\Gamma K_b with no smoothing error, and only the quadrature and truncation errors remain; the test checks this to 10−410^{-4}.

Claim 3 (invariants). Let xp(t)x_p(t) solve x˙p=∑qΓqKδ(xp−xq)\dot x_p = \sum_{q} \Gamma_q K_\delta(x_p - x_q) with constant Γp\Gamma_p. Then the circulation ∑pΓp\sum_p \Gamma_p, the linear impulse I=∑pΓpxpI = \sum_p \Gamma_p x_p and the angular impulse A=∑pΓp∣xp∣2A = \sum_p \Gamma_p |x_p|^2 are constant.

Proof. The circulations do not change, so neither does their sum. Write Kpq=Kδ(xp−xq)K_{pq} = K_\delta(x_p - x_q). The kernel is odd, Kqp=−KpqK_{qp} = -K_{pq}, so

I˙=∑p∑qΓpΓqKpq=0,\dot I = \sum_p \sum_q \Gamma_p \Gamma_q K_{pq} = 0,

because the terms (p,q)(p, q) and (q,p)(q, p) cancel and the terms with p=qp = q are 0. For AA,

A˙=2∑p,qΓpΓq xp⋅Kpq.\dot A = 2 \sum_{p, q} \Gamma_p \Gamma_q\, x_p \cdot K_{pq}.

Swapping the names pp and qq and using Kqp=−KpqK_{qp} = -K_{pq} shows that the same sum equals −2∑p,qΓpΓq xq⋅Kpq-2 \sum_{p, q} \Gamma_p \Gamma_q\, x_q \cdot K_{pq}. Adding the two forms, A˙=∑p,qΓpΓq(xp−xq)⋅Kpq=0\dot A = \sum_{p, q} \Gamma_p \Gamma_q (x_p - x_q) \cdot K_{pq} = 0, since Kδ(x)K_\delta(x) is a multiple of x⊥x^\perp and x⋅x⊥=0x \cdot x^\perp = 0. □\square

Claim 4 (the midpoint rule keeps the linear impulse). One step of lines L1 to L5 leaves II unchanged in exact arithmetic.

Proof. Line L3 changes II by h2∑pΓpup=h2I˙=0\frac{h}{2} \sum_p \Gamma_p u_p = \frac{h}{2} \dot I = 0 for the old positions, and line L5 changes it by h∑pΓpup∗h \sum_p \Gamma_p u_p^*, which is the same antisymmetric double sum at the midpoint positions, and so is 0 as in Claim 3. ■\blacksquare

The midpoint rule does not keep AA exactly, since the second form of A˙\dot A uses the positions at which the velocity was computed; its error per step is the local error O(h3)O(h^3) of the method.

Complexity

In the real-RAM model, line L2 costs Θ(N2)\Theta(N^2) for NN particles, done twice per step, so one step costs Θ(N2)\Theta(N^2) time and Θ(N)\Theta(N) extra space. A Barnes-Hut tree brings a step to O(Nlog⁡N)O(N \log N) and the fast multipole method to O(N)O(N) for a fixed accuracy; both are standard in vortex codes. The vortex-in-cell variant solves the Poisson equation for the stream function on a grid instead, at O(N+Mlog⁡M)O(N + M \log M) for MM grid nodes. The time step is limited by accuracy, not by a CFL condition on a grid: hh should be small against the turnover time 1/max⁡∣ω∣1 / \max |\omega|.

Properties

  • Lagrangian and grid free. Advection is exact for the particles, so there is no numerical diffusion from the transport term.
  • Compact support of the work. Particles are needed only where ω≠0\omega \ne 0, which is a small part of the domain in many flows.
  • Divergence free by construction. The velocity comes from the Biot-Savart law, so ∇⋅u=0\nabla \cdot u = 0 exactly, with no projection step.
  • Boundary conditions at infinity are exact. The kernel already has the flow at rest at infinity, so no artificial outer boundary is needed.
  • Conservation. Circulation and linear impulse are exact, angular impulse and energy are conserved by the ODE.
  • Loss of overlap. Strain stretches the particle distribution, and in time the blobs no longer overlap and the accuracy drops.

Variants and improvements

  • Point vortices. δ=0\delta = 0 gives the singular point vortex model of Helmholtz and Kirchhoff; it is a Hamiltonian system but it does not converge to smooth Euler flow without a core.
  • Kernels of higher order. Beale and Majda built kernels with vanishing moments that give O(δm)O(\delta^m) smoothing errors.
  • Viscous diffusion. Chorin's random walk, core spreading, particle strength exchange, and the diffusion velocity method add the term νΔω\nu \Delta \omega.
  • Remeshing. Interpolating the circulations back to a regular lattice every few steps restores the overlap; it is what makes long runs accurate.
  • 3D vortex particles. In 3D the particles carry a vector strength, and the stretching term (ω⋅∇)u(\omega \cdot \nabla) u changes it; the vorticity can then lose its divergence free property, which needs a correction.
  • Vortex-in-cell. A hybrid that puts the vorticity on a grid, solves for the stream function by FFT, and moves the particles with the grid velocity.
  • Boundaries. Panels or a boundary element method enforce no flow through a wall, and the vorticity created at the wall is released as new particles.

When to use it

Use a vortex particle method for flows dominated by compact vortical structures in large or unbounded domains: wakes of bluff bodies, rotor and wind turbine wakes, vortex rings, jets and mixing layers, and studies of vortex dynamics. Prefer a grid solver, such as the vorticity-streamfunction formulation or a projection method, for confined flows with complex walls, for turbulence that fills the domain, and for compressible flow. In graphics, a few vortex particles on top of a grid solver are a cheap way to keep swirls; a full vortex method is worth it when the flow itself must be right.

Pitfalls

  • Blobs that do not overlap. With δ≤ℓ\delta \le \ell for the particle spacing ℓ\ell, the lattice sum no longer approximates the convolution, and the velocity becomes noisy. Keep δ/ℓ\delta / \ell above 1, and remesh.
  • Point vortices for smooth flow. Without a core, close pairs get huge velocities and the time step collapses.
  • Truncating the vortex. Cutting the vorticity to a finite disc drops circulation; check ∑pΓp\sum_p \Gamma_p against the exact total.
  • Errors of the fast summation. A tree or FMM with a loose accuracy parameter can spoil the conservation of the impulses, which direct summation keeps.
  • 3D divergence. In 3D, the particle vorticity field is not divergence free after stretching; ignoring this lets spurious vorticity grow.
  • Wrong sign convention. The 2D kernel turns the separation by +90 degrees for counterclockwise vorticity; with the wrong sign the vortices spin backwards.

Implementations

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.

vortex_particle_method.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/vortex-particle-method/. The authors are listed in prov/4WPAHS.jsonl.
"""The 2D vortex blob method for the incompressible Euler equations.

Particle p sits at (x_p, y_p) and carries the circulation g_p. The vorticity
is the sum of Gaussian blobs of core size delta,

    omega(x) = sum_p g_p zeta(x - x_p),   zeta(x) = exp(-|x|^2 / delta^2) / (pi delta^2),

and the Biot-Savart law gives the velocity with the smoothed kernel

    K(x, y) = (-y, x) (1 - exp(-r^2 / delta^2)) / (2 pi r^2),   r^2 = x^2 + y^2.

The particles move with this velocity (explicit midpoint rule) and keep their
circulations, since vorticity is carried by an inviscid 2D flow.

Cost: Theta(N^2) time per velocity evaluation by direct summation.
"""

import math


def kernel(dx: float, dy: float, delta: float) -> tuple[float, float]:
    """The blob kernel K_delta(dx, dy); K(0, 0) = (0, 0)."""
    r2 = dx * dx + dy * dy
    if r2 == 0.0:
        return 0.0, 0.0
    s = -math.expm1(-r2 / (delta * delta)) / (2 * math.pi * r2)
    return -dy * s, dx * s


def velocity_at(x: float, y: float, xs: list[float], ys: list[float], gs: list[float], delta: float):
    """The velocity of the blob field at the point (x, y)."""
    u = v = 0.0
    for xq, yq, g in zip(xs, ys, gs):
        ku, kv = kernel(x - xq, y - yq, delta)
        u += g * ku
        v += g * kv
    return u, v


def velocities(xs: list[float], ys: list[float], gs: list[float], delta: float):
    """u_p = sum_q g_q K(x_p - x_q) for every particle, by direct summation over the pairs."""
    n = len(xs)
    us, vs = [0.0] * n, [0.0] * n
    for p in range(n):  # @line L1
        for q in range(p + 1, n):  # @line L2
            ku, kv = kernel(xs[p] - xs[q], ys[p] - ys[q], delta)  # @line L2
            us[p] += gs[q] * ku  # @line L2
            vs[p] += gs[q] * kv  # @line L2
            us[q] -= gs[p] * ku  # @line L2
            vs[q] -= gs[p] * kv  # @line L2
    return us, vs


def vortex_step(xs: list[float], ys: list[float], gs: list[float], delta: float, h: float):
    """One explicit midpoint step of dx_p/dt = u(x_p); the circulations do not change."""
    us, vs = velocities(xs, ys, gs, delta)
    xm = [x + 0.5 * h * u for x, u in zip(xs, us)]  # @line L3
    ym = [y + 0.5 * h * v for y, v in zip(ys, vs)]  # @line L3
    us, vs = velocities(xm, ym, gs, delta)  # @line L4
    xs = [x + h * u for x, u in zip(xs, us)]  # @line L5
    ys = [y + h * v for y, v in zip(ys, vs)]  # @line L5
    return xs, ys  # @line L6


def lamb_oseen_vorticity(r: float, gamma: float, nu: float, t: float) -> float:
    """omega = gamma / (4 pi nu t) exp(-r^2 / (4 nu t))."""
    return gamma / (4 * math.pi * nu * t) * math.exp(-r * r / (4 * nu * t))


def lamb_oseen_speed(r: float, gamma: float, nu: float, t: float) -> float:
    """The azimuthal velocity gamma / (2 pi r) (1 - exp(-r^2 / (4 nu t)))."""
    return -gamma * math.expm1(-r * r / (4 * nu * t)) / (2 * math.pi * r)


def lattice_particles(omega, spacing: float, radius: float):
    """Particles on a square lattice inside the disc of the given radius, with g_p = omega(r_p) spacing^2."""
    xs, ys, gs = [], [], []
    k = int(radius / spacing)
    for i in range(-k, k + 1):
        for j in range(-k, k + 1):
            x, y = i * spacing, j * spacing
            if x * x + y * y <= radius * radius:
                xs.append(x)
                ys.append(y)
                gs.append(omega(math.hypot(x, y)) * spacing * spacing)
    return xs, ys, gs
test_vortex_particle_method.py 126 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/vortex-particle-method/. The authors are listed in prov/4WPAHS.jsonl.
import math
import random

import pytest

from vortex_particle_method import (kernel, lamb_oseen_speed, lamb_oseen_vorticity, lattice_particles, velocities,
                                    velocity_at, vortex_step)


def blob_vorticity(x, y, xs, ys, gs, delta):
    return sum(g * math.exp(-((x - a) ** 2 + (y - b) ** 2) / delta ** 2) for a, b, g in zip(xs, ys, gs)) / (
        math.pi * delta ** 2)


def test_page_example_pair_velocities():
    us, vs = velocities([-0.5, 0.5], [0.0, 0.0], [2 * math.pi, 2 * math.pi], 0.5)
    w = 1 - math.exp(-4)
    assert us == pytest.approx([0.0, 0.0], abs=1e-15)
    assert vs == pytest.approx([-w, w], abs=1e-15)
    assert w == pytest.approx(0.981684, abs=1e-6)


def test_direct_sum_matches_the_pointwise_sum_and_has_no_self_velocity():
    rng = random.Random(1)
    xs = [rng.uniform(-1, 1) for _ in range(40)]
    ys = [rng.uniform(-1, 1) for _ in range(40)]
    gs = [rng.uniform(-1, 1) for _ in range(40)]
    us, vs = velocities(xs, ys, gs, 0.3)
    for p in range(40):
        u, v = velocity_at(xs[p], ys[p], xs, ys, gs, 0.3)
        assert (us[p], vs[p]) == pytest.approx((u, v), abs=1e-12)
    assert velocities([0.3], [0.7], [5.0], 0.2) == ([0.0], [0.0])


def test_velocity_is_divergence_free_and_its_curl_is_the_blob_vorticity():
    rng = random.Random(2)
    xs = [rng.uniform(-1, 1) for _ in range(10)]
    ys = [rng.uniform(-1, 1) for _ in range(10)]
    gs = [rng.uniform(-1, 1) for _ in range(10)]
    delta, e = 0.4, 1e-4
    for _ in range(20):
        x, y = rng.uniform(-1, 1), rng.uniform(-1, 1)
        ue, ve = velocity_at(x + e, y, xs, ys, gs, delta)
        uw, vw = velocity_at(x - e, y, xs, ys, gs, delta)
        un, vn = velocity_at(x, y + e, xs, ys, gs, delta)
        us, vs = velocity_at(x, y - e, xs, ys, gs, delta)
        div = (ue - uw + vn - vs) / (2 * e)
        curl = (ve - vw - (un - us)) / (2 * e)
        assert div == pytest.approx(0, abs=1e-6)
        assert curl == pytest.approx(blob_vorticity(x, y, xs, ys, gs, delta), abs=1e-5)


def test_far_field_is_the_point_vortex():
    u, v = kernel(0.0, 3.0, 0.1)
    assert u == pytest.approx(-1 / (2 * math.pi * 3.0), rel=1e-12) and v == 0.0


def test_co_rotating_pair_rotates_at_the_predicted_rate():
    d, delta, g = 1.0, 0.5, 1.0
    omega = g * (1 - math.exp(-d * d / delta ** 2)) / (math.pi * d * d)
    xs, ys, gs = [-d / 2, d / 2], [0.0, 0.0], [g, g]
    h, steps = 0.05, 200
    for _ in range(steps):
        xs, ys = vortex_step(xs, ys, gs, delta, h)
    assert math.hypot(xs[1] - xs[0], ys[1] - ys[0]) == pytest.approx(d, abs=1e-3)
    angle = math.atan2(ys[1], xs[1])
    expected = (omega * h * steps + math.pi) % (2 * math.pi) - math.pi
    assert angle == pytest.approx(expected, abs=2e-3)


def test_linear_impulse_is_exact_and_angular_impulse_is_nearly_conserved():
    rng = random.Random(3)
    n = 30
    xs = [rng.uniform(-1, 1) for _ in range(n)]
    ys = [rng.uniform(-1, 1) for _ in range(n)]
    gs = [rng.uniform(-1, 1) for _ in range(n)]

    def impulses(xs, ys):
        return (sum(g * x for g, x in zip(gs, xs)), sum(g * y for g, y in zip(gs, ys)),
                sum(g * (x * x + y * y) for g, x, y in zip(gs, xs, ys)))

    i0 = impulses(xs, ys)
    for _ in range(50):
        xs, ys = vortex_step(xs, ys, gs, 0.2, 0.01)
    i1 = impulses(xs, ys)
    assert i1[0] == pytest.approx(i0[0], abs=1e-12) and i1[1] == pytest.approx(i0[1], abs=1e-12)
    assert i1[2] == pytest.approx(i0[2], abs=1e-4)


def test_lamb_oseen_velocity_is_reproduced():
    # Gaussian blobs smear the vortex: the blob field is the Lamb-Oseen vortex at t + delta^2 / (4 nu)
    g, nu, t = 1.0, 0.01, 1.0
    xs, ys, gs = lattice_particles(lambda r: lamb_oseen_vorticity(r, g, nu, t), 0.05, 0.6)
    assert len(xs) <= 500
    assert sum(gs) == pytest.approx(g, abs=1e-3)
    errors = {}
    for delta in (0.1, 0.05):
        smeared, exact = 0.0, 0.0
        for r in (0.05, 0.1, 0.2, 0.3, 0.5):
            for a in (0.3, 1.1):
                u, v = velocity_at(r * math.cos(a), r * math.sin(a), xs, ys, gs, delta)
                ut = -u * math.sin(a) + v * math.cos(a)
                smeared = max(smeared, abs(ut - lamb_oseen_speed(r, g, nu, t + delta * delta / (4 * nu))))
                exact = max(exact, abs(ut - lamb_oseen_speed(r, g, nu, t)))
        assert smeared < 1e-4
        errors[delta] = exact
    # the smoothing error is second order in delta
    assert 3.0 < errors[0.1] / errors[0.05] < 4.5


def test_lamb_oseen_vortex_is_a_steady_rotation():
    g, nu, t, delta = 1.0, 0.01, 1.0, 0.15
    xs, ys, gs = lattice_particles(lambda r: lamb_oseen_vorticity(r, g, nu, t), 0.1, 0.6)
    r0 = [math.hypot(x, y) for x, y in zip(xs, ys)]
    a0 = [math.atan2(y, x) for x, y in zip(xs, ys)]
    h, steps = 0.05, 20
    for _ in range(steps):
        xs, ys = vortex_step(xs, ys, gs, delta, h)
    for x, y, r, a in zip(xs, ys, r0, a0):
        assert math.hypot(x, y) == pytest.approx(r, abs=5e-4)
        if r > 0:
            w = lamb_oseen_speed(r, g, nu, t + delta * delta / (4 * nu)) / r
            turn = (math.atan2(y, x) - a - w * h * steps + math.pi) % (2 * math.pi) - math.pi
            assert abs(turn) < 5e-3

History

Rosenhead (1931) followed the roll-up of a vortex sheet with point vortices by hand, and the instability of that computation stopped progress for decades. Chorin (1973) smoothed the core of each vortex into a blob and added viscosity with a random walk, which made the method a practical solver for slightly viscous flow. Hald (1979) and Beale and Majda (1982) proved convergence for the blob method. Fast summation with trees and the fast multipole method of Greengard and Rokhlin (1987), together with remeshing and particle strength exchange, made large and accurate simulations possible; Cottet and Koumoutsakos (2000) give the theory and the practice.

References

  1. Georges-Henri Cottet and Petros D. Koumoutsakos, Vortex Methods, Theory and Practice, Cambridge University Press, 2000, the 2D vortex blob method, its convergence, viscous vortex methods and remeshing
  2. Alexandre Joel Chorin, Numerical study of slightly viscous flow, Journal of Fluid Mechanics 57(4), 1973, 785-796, the vortex blobs and the random walk for the viscous term
  3. J. Thomas Beale and Andrew Majda, Vortex methods. II. Higher order accuracy in two and three dimensions, Mathematics of Computation 39(159), 1982, 29-52, the convergence of the blob method and kernels of higher order

Where this leads

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example