Algorithmresearch
Particle strength exchange
Approximates the Laplacian on scattered particles by an integral operator, so viscous diffusion in vortex methods becomes an exchange of strength between neighbors.
- Time
- Θ(N + P) worst
- Space
- Θ(N + P) extra
- Where
- N = the number of particles; P = the number of interacting pairs
- Model
- Real RAM
- Properties
- conservativedeterministic
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Pierre Degond, Sylvie Mas Gallic, 1989
Particle strength exchange (PSE) adds diffusion, such as the viscous term of a vortex particle method, to a set of scattered particles. It replaces the Laplacian by an integral operator over a small kernel, and evaluates the integral as a sum over the nearby particles. Every pair of particles then trades strength in proportion to the difference of their values, so whatever one particle gains, its partner loses, and the total circulation is conserved exactly.
In plain words
Think of the particles as cups of water at different temperatures standing on a table. Each cup passes a little heat to every nearby cup that is colder, and takes a little heat from every nearby cup that is warmer. Cups that are close trade more than cups that are far apart. The heat that leaves one cup goes into another, so the total heat on the table never changes. Over time the warm and the cold cups even out, which is what diffusion does. In a vortex method the cups are vortex particles, the heat is their spin, and the friction of the fluid sets how fast they trade.
The problem
Given particles at in the plane with volumes and values (circulation ), a diffusivity and a step , approximate the diffusion equation at the particles. PSE uses a radial, integrable kernel with the second moments , here , and . By a Taylor expansion of about ,
since the odd moments of vanish. The particles are the quadrature points of this integral:
In a vortex method the particles also move, and a step of the vortex particle method alternates with a PSE step (operator splitting).
The algorithm
PSE-STEP(x, ω, V, ν, ε, h)- 1
for each pair p < q with |x_p - x_q| < c ε do ▷ c = 5 in the code - 2
w ← (ν / ε²) η_ε(x_p - x_q) - 3
d ← w (ω_q - ω_p) - 4
r_p ← r_p + V_q d; r_q ← r_q - V_p d ▷ the exchange, all r start at 0 - 5
ω_p ← ω_p + h r_p for every p ▷ explicit Euler - 6
return ω ▷ Σ_p V_p ω_p is unchanged
Line L1 needs the pairs within the cutoff; with a cell list of cells of size this costs . If the particles do not move between steps, as on a remeshed lattice, the pairs and their weights from lines L1 and L2 are computed once. Line L4 is the exchange: the circulation that receives from the pair is , and loses the same amount.
Example
Two particles by hand. Put particles at and with , and take , . Line L2 gives , so , and an Euler step with gives . The sum is still exactly 1.
The Lamb-Oseen vortex. The vorticity with solves the diffusion equation, so the vortex at should become the vortex at after the time with . Take , a lattice with spacing on (441 particles, ) and . The bound below asks for , so two Euler steps of are taken. The largest error against the exact vortex is 0.28 percent of the peak value 1.59, and the total circulation 0.99962 is unchanged to rounding (measurements).
At the centre, the rate from lines L1 to L4 is , while the exact Laplacian gives . This 12 percent gap is the smoothing error of the operator for ; the rate agrees with the value of the integral operator to , so the lattice sum adds almost no error. With , equal to the spacing, the rate is against for the integral, a quadrature error of 0.24 percent.
Correctness
The full proof is in the correctness proof. It proves these facts (theorems, in exact arithmetic):
- Exact conservation. Every step leaves unchanged, for any positions, any volumes and any symmetric kernel, because the change from a pair is .
- Maximum principle. If for every , with , then each new is a convex combination of old values, so does not decrease and does not increase. This is also the stability condition of the explicit step.
- Consistency. The integral operator differs from by for smooth , and on Gaussians it is the exact difference . It reproduces the Laplacian of every quadratic exactly.
Degond and Mas-Gallic (1989) proved that the particle scheme converges to the solution of the convection-diffusion equation as and the particle spacing goes to zero faster than , with the order of the kernel. The overlap condition matters: the quadrature error of the lattice sum is small only when the spacing is smaller than .
Proof: Particle strength exchange conserves the total circulation exactly, keeps the maximum principle under the step limit, and is a consistent approximation of the Laplacianfull
We use the pseudocode of the page in exact arithmetic. For a pair in the pair list, line L2 sets , and we put and for pairs not in the list. After line L4,
since the pair with adds to , and the pair with subtracts , which is the same term.
Claim 1 (exact conservation). Line L5 leaves unchanged.
Proof. The change is . Each pair contributes to this sum, with .
The proof uses only the symmetry and the form of line L4, so it holds for any positions, volumes, kernel and step. In floating point the pair contributions and are equal and opposite, so changes only by the rounding of the sums.
Claim 2 (maximum principle). Let . If for every , then after line L5, for every .
Proof. By (R),
The coefficients and are nonnegative and add up to . So is a convex combination of old values.
In particular a nonnegative field stays nonnegative, and the step is stable in the maximum norm: the map has norm 1 in .
Claim 3 (consistency). Let be radial and integrable, with and , and let have bounded third derivatives. Then
and if has bounded fourth derivatives and . For a quadratic the operator is exact.
Proof. Substitute , so . By Taylor's theorem, , with the Hessian of at and . A radial kernel has , so the first term integrates to 0. The second gives . Dividing by leaves plus a remainder of size . With fourth derivatives, the cubic term of the Taylor series integrates to 0 by symmetry, and the remainder is . For a quadratic the Taylor series stops after the second term, so .
For , and , so the kernel of the page satisfies the hypotheses.
Claim 4 (the operator on Gaussians). Let . Then .
Proof. and , so . is the density of a 2D normal law with variance in each coordinate, and the convolution of two such densities is the density of the sum of independent variables, .
Since with solves the heat equation, , and Claim 4 shows that is a forward difference in with step : its error against is . It also shows that one Euler step of with the exact integral maps to exactly, which is the cancellation named under Pitfalls on the page.
Complexity
In the real-RAM model, lines L3 to L5 cost for pairs, and lines L1 and L2 cost with a cell list (the code on this page scans all pairs, at , and is meant for small tests). With a spacing and a cutoff , each particle has about neighbours in 2D, so for a fixed ratio . The explicit step needs , the same kind of limit as for an explicit finite difference scheme with grid size .
Properties
- Conservative. Total circulation is exact, to rounding in floating point.
- Grid free. It works on scattered particles of different volumes, with no mesh.
- Symmetric. The exchange is a sum over pairs, so its cost and its communication pattern match those of short-range molecular dynamics.
- Second order in space for a kernel with zero odd moments and second moments 2, given enough overlap.
- First order in time with explicit Euler, and limited by roughly.
- Positivity. Under the step limit a nonnegative field stays nonnegative.
Variants and improvements
- Kernels of higher order. Kernels with more vanishing moments give errors; they are no longer positive, so the maximum principle is lost.
- Anisotropic and variable diffusion. Part 2 of Degond and Mas-Gallic handles a general diffusion matrix.
- Other operators. The same idea gives integral approximations of first derivatives and other differential operators on particles, with kernels chosen for the moments that each operator needs.
- Remeshing. Interpolating the particles to a regular lattice every few steps keeps the overlap that the quadrature needs.
- Other viscous schemes. Chorin's random walk, core spreading, and the diffusion velocity method add viscosity without exchange; the random walk is simple but has a statistical error that shrinks only like (a heuristic estimate for Monte Carlo sampling).
- Higher order time steps. Runge-Kutta steps replace line L5 when the advection step is of higher order.
When to use it
Use PSE to add viscosity or another diffusion term to a Lagrangian particle method, mainly vortex methods but also particle methods for heat or species transport, when conservation of the total amount matters. Prefer core spreading for a few large blobs, the random walk when a stochastic model is acceptable, and a grid method for diffusion-dominated problems, where the step limit makes explicit PSE slow.
Pitfalls
- Lost overlap. If the particles spread out so that their spacing exceeds , the sum no longer approximates the integral. Remesh.
- The step limit. Halving cuts the stable step by 4; a step above gives growing oscillations.
- Boundaries. Near a wall or the edge of the particle set the integral is cut, so the operator is no longer consistent there; image particles or one-sided kernels are needed.
- A Gaussian test that looks exact. On a Gaussian field with a Gaussian kernel, one Euler step of exactly maps to , the exact solution, so the space and time errors cancel. Check convergence with other steps or other data.
- Wrong normalisation. The kernel must have second moments 2 in each direction; with a kernel normalised to integral 1 instead, the rate is off by a constant factor.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/particle-strength-exchange/. The authors are listed in prov/0HQEAM.jsonl.
"""Particle strength exchange (PSE) for the diffusion term nu * Laplacian(omega) in 2D.
Particle p at x_p has volume V_p and vorticity omega_p (circulation V_p omega_p).
The Laplacian is replaced by the integral operator
L_eps omega(x) = (1 / eps^2) * integral (omega(y) - omega(x)) eta_eps(y - x) dy,
with eta(x) = (4 / pi) exp(-|x|^2), whose second moments are 2, and
eta_eps(x) = eta(x / eps) / eps^2. The integral is a sum over the particles:
d omega_p / dt = (nu / eps^2) * sum_q V_q (omega_q - omega_p) eta_eps(x_q - x_p).
Each pair adds to p what it takes from q, weighted by the volumes, so the total
circulation sum_p V_p omega_p does not change.
Cost: Theta(P) time per step for P interacting pairs (Theta(N) with a cutoff
and a cell list, Theta(N^2) for all pairs).
"""
import math
def eta(r2: float) -> float:
"""The kernel eta at |x|^2 = r2."""
return 4 / math.pi * math.exp(-r2)
def exchange_pairs(xs: list[float], ys: list[float], nu: float, eps: float, cutoff: float = 5.0):
"""(p, q, w) for p < q within cutoff * eps, with w = (nu / eps^2) eta_eps(x_p - x_q)."""
pairs = []
c2 = (cutoff * eps) ** 2
for p in range(len(xs)): # @line L1
for q in range(p + 1, len(xs)): # @line L1
r2 = (xs[p] - xs[q]) ** 2 + (ys[p] - ys[q]) ** 2
if r2 < c2: # @line L1
pairs.append((p, q, nu / eps ** 2 * eta(r2 / eps ** 2) / eps ** 2)) # @line L2
return pairs
def exchange_rates(omega: list[float], vol: list[float], pairs) -> list[float]:
"""d omega_p / dt for every particle."""
rate = [0.0] * len(omega)
for p, q, w in pairs:
d = w * (omega[q] - omega[p]) # @line L3
rate[p] += vol[q] * d # @line L4
rate[q] -= vol[p] * d # @line L4
return rate
def pse_step(omega: list[float], vol: list[float], pairs, h: float) -> list[float]:
"""One explicit Euler step of the exchange."""
rate = exchange_rates(omega, vol, pairs)
return [o + h * r for o, r in zip(omega, rate)] # @line L5
def stable_step(vol: list[float], pairs) -> float:
"""The largest h with h * D_p <= 1, D_p = sum_q V_q w_pq; it keeps the maximum principle."""
d = [0.0] * len(vol)
for p, q, w in pairs:
d[p] += vol[q] * w
d[q] += vol[p] * w
return 1 / max(d)
def diffuse(omega: list[float], vol: list[float], pairs, time: float) -> list[float]:
"""Diffuse for the given time with equal Euler steps that satisfy h * D_p <= 1."""
steps = max(1, math.ceil(time / stable_step(vol, pairs)))
for _ in range(steps):
omega = pse_step(omega, vol, pairs, time / steps)
return omega # @line L6
def lattice(spacing: float, half_width: float):
"""A square lattice on [-half_width, half_width]^2 with particle volumes spacing^2."""
k = round(half_width / spacing)
xs = [i * spacing for i in range(-k, k + 1) for _ in range(-k, k + 1)]
ys = [j * spacing for _ in range(-k, k + 1) for j in range(-k, k + 1)]
return xs, ys, [spacing * spacing] * len(xs)
test_particle_strength_exchange.py 92 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/particle-strength-exchange/. The authors are listed in prov/0HQEAM.jsonl.
import math
import random
import pytest
from particle_strength_exchange import diffuse, exchange_pairs, exchange_rates, lattice, pse_step, stable_step
def gaussian(x, y, s2):
# the Lamb-Oseen vorticity with circulation 1 and s2 = 4 nu t
return math.exp(-(x * x + y * y) / s2) / (math.pi * s2)
def test_page_example_two_particles():
pairs = exchange_pairs([0.0, 1.0], [0.0, 0.0], 1.0, 1.0)
w = 4 / math.pi * math.exp(-1)
assert pairs[0][2] == pytest.approx(w, abs=1e-15)
assert exchange_rates([1.0, 0.0], [1.0, 1.0], pairs) == pytest.approx([-w, w], abs=1e-15)
om = pse_step([1.0, 0.0], [1.0, 1.0], pairs, 0.5)
assert om == pytest.approx([0.765801, 0.234199], abs=1e-6)
assert sum(om) == 1.0
def test_total_circulation_is_conserved_exactly():
rng = random.Random(1)
n = 120
xs = [rng.uniform(0, 1) for _ in range(n)]
ys = [rng.uniform(0, 1) for _ in range(n)]
vol = [rng.uniform(0.005, 0.02) for _ in range(n)]
om = [rng.uniform(-5, 5) for _ in range(n)]
pairs = exchange_pairs(xs, ys, 0.3, 0.12)
c0 = sum(v * o for v, o in zip(vol, om))
h = stable_step(vol, pairs)
for _ in range(50):
om = pse_step(om, vol, pairs, h)
assert sum(v * o for v, o in zip(vol, om)) == pytest.approx(c0, abs=1e-12)
def test_laplacian_of_a_quadratic_is_exact_on_a_fine_lattice():
xs, ys, vol = lattice(0.1, 1.0)
pairs = exchange_pairs(xs, ys, 1.0, 0.15)
om = [3 * x * x - x * y + 2 * y * y + x for x, y in zip(xs, ys)]
rate = exchange_rates(om, vol, pairs)
for p in range(len(xs)):
if abs(xs[p]) < 0.2 and abs(ys[p]) < 0.2:
assert rate[p] == pytest.approx(10.0, abs=1e-6)
def test_rate_on_a_gaussian_matches_the_integral_operator():
# for the Gaussian kernel, L_eps g_s = (4 / eps^2) (g_{s + eps^2} - g_s) exactly, and L_eps -> Laplacian
xs, ys, vol = lattice(0.1, 1.0)
s2 = 0.16
om = [gaussian(x, y, s2) for x, y in zip(xs, ys)]
centre = len(xs) // 2
assert xs[centre] == 0.0 and ys[centre] == 0.0
laplacian = -4 / s2 * gaussian(0, 0, s2)
last = math.inf
for eps in (0.25, 0.2, 0.15):
rate = exchange_rates(om, vol, exchange_pairs(xs, ys, 1.0, eps))[centre]
operator = 4 / eps ** 2 * (gaussian(0, 0, s2 + eps * eps) - gaussian(0, 0, s2))
assert rate == pytest.approx(operator, rel=1e-6)
assert abs(rate - laplacian) < last
last = abs(rate - laplacian)
def test_stable_step_keeps_the_maximum_principle():
rng = random.Random(2)
n = 100
xs = [rng.uniform(0, 1) for _ in range(n)]
ys = [rng.uniform(0, 1) for _ in range(n)]
vol = [0.01] * n
om = [rng.uniform(0, 1) for _ in range(n)]
pairs = exchange_pairs(xs, ys, 0.5, 0.1)
h = stable_step(vol, pairs)
lo, hi = min(om), max(om)
for _ in range(100):
om = pse_step(om, vol, pairs, h)
assert lo - 1e-12 <= min(om) and max(om) <= hi + 1e-12
# spread is reduced: diffusion smooths the data
assert max(om) - min(om) < hi - lo
def test_lamb_oseen_vortex_diffuses_at_the_right_rate():
nu, xs, ys, vol = 1.0, *lattice(0.1, 1.0)
assert len(xs) <= 500
om = [gaussian(x, y, 0.16) for x, y in zip(xs, ys)]
pairs = exchange_pairs(xs, ys, nu, 0.15)
om = diffuse(om, vol, pairs, 0.01)
exact = [gaussian(x, y, 0.16 + 4 * nu * 0.01) for x, y in zip(xs, ys)]
assert max(abs(a - b) for a, b in zip(om, exact)) < 0.01 * max(exact)
History
Mas-Gallic had earlier approximated the diffusion operator by an integral operator and solved the resulting equation by a particle method. Degond and Mas-Gallic (1989) analysed this weighted particle method for convection and diffusion, in two papers, for an isotropic and for an anisotropic diffusion, and proved its convergence. The method became the standard deterministic way to add viscosity to vortex particle methods, and with remeshing it is the basis of accurate viscous vortex codes, as described by Cottet and Koumoutsakos (2000).
References
- Pierre Degond and Sylvie Mas-Gallic, The weighted particle method for convection-diffusion equations. Part 1, The case of an isotropic viscosity, Mathematics of Computation 53(188), 1989, 485-507, the integral approximation of the Laplacian, its consistency, and the convergence of the particle scheme
- Pierre Degond and Sylvie Mas-Gallic, The weighted particle method for convection-diffusion equations. Part 2, The anisotropic case, Mathematics of Computation 53(188), 1989, 509-525, the extension to a general diffusion matrix
- Georges-Henri Cottet and Petros D. Koumoutsakos, Vortex Methods, Theory and Practice, Cambridge University Press, 2000, the chapter on viscous vortex methods
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 | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 0HQEAM Edit this page History Report an error Markdown