Algorithm Search⌘K

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
Properties
conservativedeterministic
Origin
Pierre Degond, Sylvie Mas Gallic, 1989

Particle strength exchange (PSE) adds diffusion, such as the viscous term νΔω\nu \Delta \omega 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 NN particles at xpx_p in the plane with volumes VpV_p and values ωp\omega_p (circulation Γp=Vpωp\Gamma_p = V_p \omega_p), a diffusivity ν\nu and a step hh, approximate the diffusion equation ∂tω=νΔω\partial_t \omega = \nu \Delta \omega at the particles. PSE uses a radial, integrable kernel η\eta with the second moments ∫xixjη(x) dx=2δij\int x_i x_j \eta(x)\, dx = 2 \delta_{ij}, here η(x)=(4/π)e−∣x∣2\eta(x) = (4/\pi) e^{-|x|^2}, and ηε(x)=ε−2η(x/ε)\eta_\varepsilon(x) = \varepsilon^{-2} \eta(x / \varepsilon). By a Taylor expansion of ω(y)\omega(y) about xx,

Δεω(x)=1ε2∫(ω(y)−ω(x)) ηε(y−x) dy=Δω(x)+O(ε2),\Delta_\varepsilon \omega(x) = \frac{1}{\varepsilon^2} \int \bigl(\omega(y) - \omega(x)\bigr)\, \eta_\varepsilon(y - x)\, dy = \Delta \omega(x) + O(\varepsilon^2),

since the odd moments of η\eta vanish. The particles are the quadrature points of this integral:

dωpdt=νε2∑qVq (ωq−ωp) ηε(xq−xp).\frac{d \omega_p}{dt} = \frac{\nu}{\varepsilon^2} \sum_q V_q\, (\omega_q - \omega_p)\, \eta_\varepsilon(x_q - x_p).

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

  1. PSE-STEP(x, ω, V, ν, ε, h)
  2. 1for each pair p < q with |x_p - x_q| < c ε do ▷ c = 5 in the code
  3. 2w ← (ν / ε²) η_ε(x_p - x_q)
  4. 3d ← w (ω_q - ω_p)
  5. 4r_p ← r_p + V_q d; r_q ← r_q - V_p d ▷ the exchange, all r start at 0
  6. 5ω_p ← ω_p + h r_p for every p ▷ explicit Euler
  7. 6return ω ▷ Σ_p V_p ω_p is unchanged

Line L1 needs the pairs within the cutoff; with a cell list of cells of size cεc \varepsilon this costs Θ(N+P)\Theta(N + P). 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 VprpV_p r_p that pp receives from the pair is VpVqdV_p V_q d, and qq loses the same amount.

Example

Two particles by hand. Put V=1V = 1 particles at (0,0)(0, 0) and (1,0)(1, 0) with ω=(1,0)\omega = (1, 0), and take ν=1\nu = 1, ε=1\varepsilon = 1. Line L2 gives w=(4/π)e−1=0.468399w = (4/\pi) e^{-1} = 0.468399, so r=(−0.468399,0.468399)r = (-0.468399, 0.468399), and an Euler step with h=0.5h = 0.5 gives ω=(0.765801,0.234199)\omega = (0.765801, 0.234199). The sum is still exactly 1.

The Lamb-Oseen vortex. The vorticity ω=Γ/(πs) e−r2/s\omega = \Gamma / (\pi s)\, e^{-r^2 / s} with s=4νts = 4 \nu t solves the diffusion equation, so the vortex at s=0.16s = 0.16 should become the vortex at s=0.20s = 0.20 after the time 0.010.01 with ν=1\nu = 1. Take Γ=1\Gamma = 1, a lattice with spacing 0.10.1 on [−1,1]2[-1, 1]^2 (441 particles, V=0.01V = 0.01) and ε=0.15\varepsilon = 0.15. The bound hDp≤1h D_p \le 1 below asks for h≤0.0066h \le 0.0066, so two Euler steps of 0.0050.005 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 −43.604-43.604, while the exact Laplacian gives −49.736-49.736. This 12 percent gap is the smoothing error of the operator for ε2/s=0.14\varepsilon^2 / s = 0.14; the rate agrees with the value (4/ε2)(ωs+ε2−ωs)(0)=−43.604094(4/\varepsilon^2)(\omega_{s + \varepsilon^2} - \omega_s)(0) = -43.604094 of the integral operator Δε\Delta_\varepsilon to 10−710^{-7}, so the lattice sum adds almost no error. With ε=0.1\varepsilon = 0.1, equal to the spacing, the rate is −46.698-46.698 against −46.810-46.810 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 ∑pVpωp\sum_p V_p \omega_p unchanged, for any positions, any volumes and any symmetric kernel, because the change from a pair is h(VpVqd−VqVpd)=0h(V_p V_q d - V_q V_p d) = 0.
  • Maximum principle. If hDp≤1h D_p \le 1 for every pp, with Dp=∑qVqwpqD_p = \sum_q V_q w_{pq}, then each new ωp\omega_p is a convex combination of old values, so min⁡ω\min \omega does not decrease and max⁡ω\max \omega does not increase. This is also the stability condition of the explicit step.
  • Consistency. The integral operator Δε\Delta_\varepsilon differs from Δ\Delta by O(ε2)O(\varepsilon^2) for smooth ω\omega, and on Gaussians it is the exact difference (4/ε2)(ωs+ε2−ωs)(4/\varepsilon^2)(\omega_{s+\varepsilon^2} - \omega_s). 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 ε→0\varepsilon \to 0 and the particle spacing goes to zero faster than ε\varepsilon, 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 ε\varepsilon.

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 p<qp < q in the pair list, line L2 sets wpq=(ν/ε2) ηε(xp−xq)≥0w_{pq} = (\nu / \varepsilon^2)\, \eta_\varepsilon(x_p - x_q) \ge 0, and we put wqp=wpqw_{qp} = w_{pq} and wpq=0w_{pq} = 0 for pairs not in the list. After line L4,

rp=∑qVq wpq (ωq−ωp),(R)r_p = \sum_q V_q\, w_{pq}\, (\omega_q - \omega_p), \tag{R}

since the pair (p,q)(p, q) with p<qp < q adds Vqwpq(ωq−ωp)V_q w_{pq} (\omega_q - \omega_p) to rpr_p, and the pair (q,p)(q, p) with q<pq < p subtracts Vqwqp(ωp−ωq)V_q w_{qp} (\omega_p - \omega_q), which is the same term.

Claim 1 (exact conservation). Line L5 leaves C=∑pVpωpC = \sum_p V_p \omega_p unchanged.

Proof. The change is h∑pVprph \sum_p V_p r_p. Each pair p<qp < q contributes Vp(Vqd)+Vq(−Vpd)=0V_p (V_q d) + V_q (-V_p d) = 0 to this sum, with d=wpq(ωq−ωp)d = w_{pq}(\omega_q - \omega_p). □\square

The proof uses only the symmetry wpq=wqpw_{pq} = w_{qp} and the form of line L4, so it holds for any positions, volumes, kernel and step. In floating point the pair contributions VpVqdV_p V_q d and −VqVpd-V_q V_p d are equal and opposite, so CC changes only by the rounding of the sums.

Claim 2 (maximum principle). Let Dp=∑qVqwpqD_p = \sum_q V_q w_{pq}. If hDp≤1h D_p \le 1 for every pp, then after line L5, min⁡qωqold≤ωpnew≤max⁡qωqold\min_q \omega_q^{old} \le \omega_p^{new} \le \max_q \omega_q^{old} for every pp.

Proof. By (R),

ωpnew=ωp+hrp=(1−hDp) ωp+∑qhVqwpq ωq.\omega_p^{new} = \omega_p + h r_p = (1 - h D_p)\, \omega_p + \sum_q h V_q w_{pq}\, \omega_q.

The coefficients 1−hDp1 - h D_p and hVqwpqh V_q w_{pq} are nonnegative and add up to 1−hDp+hDp=11 - h D_p + h D_p = 1. So ωpnew\omega_p^{new} is a convex combination of old values. □\square

In particular a nonnegative field stays nonnegative, and the step is stable in the maximum norm: the map ω↦ωnew\omega \mapsto \omega^{new} has norm 1 in ℓ∞\ell^\infty.

Claim 3 (consistency). Let η\eta be radial and integrable, with ∫∣x∣3η(x) dx<∞\int |x|^3 \eta(x)\, dx < \infty and ∫xixjη(x) dx=2δij\int x_i x_j \eta(x)\, dx = 2\delta_{ij}, and let ω\omega have bounded third derivatives. Then

Δεω(x)=1ε2∫(ω(y)−ω(x)) ηε(y−x) dy=Δω(x)+O(ε),\Delta_\varepsilon \omega(x) = \frac{1}{\varepsilon^2} \int (\omega(y) - \omega(x))\, \eta_\varepsilon(y - x)\, dy = \Delta \omega(x) + O(\varepsilon),

and O(ε2)O(\varepsilon^2) if ω\omega has bounded fourth derivatives and ∫∣x∣4η<∞\int |x|^4 \eta < \infty. For a quadratic ω\omega the operator is exact.

Proof. Substitute y=x+εzy = x + \varepsilon z, so ηε(y−x) dy=η(z) dz\eta_\varepsilon(y - x)\, dy = \eta(z)\, dz. By Taylor's theorem, ω(x+εz)−ω(x)=ε z⋅∇ω+ε22zTHz+R\omega(x + \varepsilon z) - \omega(x) = \varepsilon\, z \cdot \nabla \omega + \frac{\varepsilon^2}{2} z^T H z + R, with HH the Hessian of ω\omega at xx and ∣R∣≤Cε3∣z∣3|R| \le C \varepsilon^3 |z|^3. A radial kernel has ∫z η=0\int z\, \eta = 0, so the first term integrates to 0. The second gives ε22∑i,jHij⋅2δij=ε2Δω\frac{\varepsilon^2}{2} \sum_{i,j} H_{ij} \cdot 2\delta_{ij} = \varepsilon^2 \Delta\omega. Dividing by ε2\varepsilon^2 leaves Δω\Delta \omega plus a remainder of size Cε∫∣z∣3ηC \varepsilon \int |z|^3 \eta. With fourth derivatives, the cubic term of the Taylor series integrates to 0 by symmetry, and the remainder is O(ε2)O(\varepsilon^2). For a quadratic ω\omega the Taylor series stops after the second term, so R=0R = 0. □\square

For η=(4/π)e−∣z∣2\eta = (4/\pi) e^{-|z|^2}, ∫z12η=(4/π)(π/2)π=2\int z_1^2 \eta = (4/\pi)(\sqrt\pi / 2)\sqrt\pi = 2 and ∫z1z2η=0\int z_1 z_2 \eta = 0, so the kernel of the page satisfies the hypotheses.

Claim 4 (the operator on Gaussians). Let gs(x)=e−∣x∣2/s/(πs)g_s(x) = e^{-|x|^2/s} / (\pi s). Then Δεgs=(4/ε2)(gs+ε2−gs)\Delta_\varepsilon g_s = (4 / \varepsilon^2)(g_{s + \varepsilon^2} - g_s).

Proof. ηε=4gε2\eta_\varepsilon = 4 g_{\varepsilon^2} and ∫η=4\int \eta = 4, so Δεgs=ε−2(4 gε2∗gs−4gs)\Delta_\varepsilon g_s = \varepsilon^{-2}(4\, g_{\varepsilon^2} * g_s - 4 g_s). gsg_s is the density of a 2D normal law with variance s/2s/2 in each coordinate, and the convolution of two such densities is the density of the sum of independent variables, gs+ε2g_{s + \varepsilon^2}. □\square

Since gsg_s with s=4νts = 4\nu t solves the heat equation, ∂sgs=Δgs/4\partial_s g_s = \Delta g_s / 4, and Claim 4 shows that Δεgs\Delta_\varepsilon g_s is a forward difference in ss with step ε2\varepsilon^2: its error against Δgs\Delta g_s is O(ε2)O(\varepsilon^2). It also shows that one Euler step of h=ε2/(4ν)h = \varepsilon^2 / (4\nu) with the exact integral maps gsg_s to gs+ε2g_{s + \varepsilon^2} exactly, which is the cancellation named under Pitfalls on the page. ■\blacksquare

Complexity

In the real-RAM model, lines L3 to L5 cost Θ(N+P)\Theta(N + P) for PP pairs, and lines L1 and L2 cost Θ(N+P)\Theta(N + P) with a cell list (the code on this page scans all pairs, at Θ(N2)\Theta(N^2), and is meant for small tests). With a spacing ℓ\ell and a cutoff cεc\varepsilon, each particle has about π(cε/ℓ)2\pi (c \varepsilon / \ell)^2 neighbours in 2D, so P=Θ(N)P = \Theta(N) for a fixed ratio ε/ℓ\varepsilon / \ell. The explicit step needs h≤1/max⁡pDp≈ε2/(4ν)h \le 1 / \max_p D_p \approx \varepsilon^2 / (4 \nu), the same kind of limit as for an explicit finite difference scheme with grid size ε\varepsilon.

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 h≤ε2/(4ν)h \le \varepsilon^2 / (4\nu) roughly.
  • Positivity. Under the step limit a nonnegative field stays nonnegative.

Variants and improvements

  • Kernels of higher order. Kernels with more vanishing moments give O(εm)O(\varepsilon^m) 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 1/N1/\sqrt N (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 h≈ε2/(4ν)h \approx \varepsilon^2 / (4\nu) makes explicit PSE slow.

Pitfalls

  • Lost overlap. If the particles spread out so that their spacing exceeds ε\varepsilon, the sum no longer approximates the integral. Remesh.
  • The step limit. Halving ε\varepsilon cuts the stable step by 4; a step above 1/max⁡pDp1 / \max_p D_p 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 h=ε2/(4ν)h = \varepsilon^2 / (4\nu) maps ωs\omega_s to ωs+ε2\omega_{s + \varepsilon^2}, 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.

particle_strength_exchange.pyI0RawGitHub
# 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

  1. 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
  2. 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
  3. 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.

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