Algorithmadvanced
Particle-particle particle-mesh method
Also called P3M.
Splits the force into a short-range part summed directly over near neighbors and a smooth long-range part computed on a mesh by FFT.
- Time
- Θ(N^2) worstΘ(N P^2 + M^2 log M + N^2 r^2) averageΘ(N P^2 + M^2 log M) best
- Space
- Θ(N + M^2) extra
- Where
- M = the number of mesh points per side; N = the number of particles; P = the order of the charge assignment; r = the cutoff radius of the short-range part in units of the box
- Model
- Real RAM
- Properties
- deterministic
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Roger W. Hockney, James W. Eastwood, 1981
The particle-particle particle-mesh method (P3M) computes the forces of particles that interact by a long-range law, such as gravity or the Coulomb force, in a periodic box. It splits each pair force into a short-range part, which falls off fast and is summed directly over the pairs closer than a cutoff , and a smooth long-range part, which is computed for all particles at once on a mesh with the fast Fourier transform. The mesh part assigns the charges to the mesh, solves the Poisson equation in Fourier space with an influence function , and interpolates the field back. Hockney and Eastwood chose to minimize the force error of the mesh, which makes P3M the most accurate of the mesh versions of Ewald summation. With a fixed number of neighbours per particle, the work is for mesh points, instead of .
In plain words
Every particle pulls on every other one. Near pulls change quickly with the distance; far pulls change slowly.
So cut each pull into two pieces. The near piece is strong only at short range, and you add it up pair by pair, but only for close pairs. The far piece is smooth, so you can blur the particles onto a regular grid, find the pull of the blurred grid with a fast wave method, and read the pull at each particle back from the grid.
The grid makes small errors, mostly where particles sit between grid points. P3M picks the grid formula that makes these errors as small as possible on average. A finer grid, or a smoother blur, gives smaller errors.
The problem
The input is charges at positions in the periodic unit square, a mesh size (a power of 2), an assignment order , a splitting parameter and a cutoff . The output is an approximation of the force on each charge,
the force of the 2D Coulomb potential over all periodic images, defined by Ewald summation; the prime omits , . For gravity, replace by , up to the constant.
The algorithm
The pair force is split as
The long-range part is the force between Gaussian clouds of width , and its potential has the Fourier coefficients . The mesh has points of spacing . The assignment function is CIC (cloud in cell, ) or TSC (triangular shaped cloud, ); its Fourier transform is . The optimal influence function is
where the sums over the alias vectors run over .
P3M(q, x, M, P, α, r_c)- 1
Q_g ← Σ_i q_i W(x_i - x_g) for each mesh point g (charge assignment) - 2
ρ̂ ← FFT(Q) - 3
Ê(k) ← -i k G(k) ρ̂(k) for each k, with k_c = 0 at the Nyquist index - 4
E ← inverse FFT(Ê), one transform for each component - 5
F_i ← q_i Σ_g W(x_i - x_g) E_g for each particle (interpolation) - 6
for each pair i ≠ j with minimum image distance r < r_c: F_i ← F_i + q_i q_j e^{-α²r²} (x_i - x_j) / r² - 7
return F
Lines L1 to L5 are a particle-mesh solver with the smooth kernel and the optimal . Line L6 finds the close pairs with a chaining mesh, the cell list of Hockney and Eastwood: cells of side at least , so that each close pair lies in the same or in adjacent cells. The table depends only on , and , and is computed once.
Example
Take charges, alternately and , uniform in the unit square (seed 21), with and . The short-range sum uses 7632 ordered pairs. The reference is an Ewald sum with , 3 by 3 images and all wave vectors with ; with it agrees to . The relative error of the forces in the 2-norm is:
| mesh | assignment | plain | deconvolved | optimal |
|---|---|---|---|---|
| CIC | ||||
| TSC | ||||
| CIC | ||||
| TSC | ||||
| CIC | ||||
| TSC |
These are measurements. Without correction for the blur of the assignment, the mesh force is too weak at short wavelengths, and the error is 3 to 100 times larger. Here the long-range kernel is smooth on the mesh, so the plain deconvolution is already close to optimal. The optimal gains more when the kernel is rough on the mesh: with , and CIC, the errors are deconvolved and optimal.
The parameter moves work between the two parts. On the mesh with CIC and :
| short-range pairs | relative error | ||
|---|---|---|---|
| 8 | 0.375 | 17418 | |
| 10 | 0.3 | 11118 | |
| 12 | 0.25 | 7632 | |
| 16 | 0.1875 | 4402 | |
| 20 | 0.15 | 2840 |
The sum of all P3M forces is , against a typical force of about 99.
Correctness
The proof file is partial. It proves that the split is exact and that the long-range part has the Fourier coefficients (Lemma 1). It proves that the chaining mesh adds the short-range term of every pair closer than once and of no other pair, and that the omitted short-range force is (Lemma 2). It proves that, for any real even and the same weights for assignment and interpolation, the mesh forces add up to zero, so the total momentum is conserved and a lone particle feels no force from itself (Lemma 3). It does not prove that the mesh force converges to the long-range force, nor that Hockney and Eastwood's minimizes the mean square force error; it states the formula and leaves the accuracy to the measurements above and to the error estimate of Deserno and Holm.
Proof: The P3M split is exact, the short-range sum finds every close pair, and the mesh force conserves total momentumpartial
We use exact arithmetic. The charges are in the periodic unit square, the mesh has points with even, , and . The exact force on charge is , where the prime omits , ; it is the force of the potential over all images, defined as the limit of the Ewald sums.
Lemma 1 (the split). For every , , and the second term is the field, at distance , of a unit charge spread with the density . In the periodic square, the potential of these Gaussian clouds has the Fourier coefficients , , with .
Proof. The identity is algebra. The density has total charge , and the charge inside the radius is . In 2D, Gauss's law for the potential gives the radial field (charge inside) . The potential solves , and the Fourier transform of the density is ; dividing by gives the coefficients. The mode adds a constant to the potential and no force.
So , where is the sum of over all images, which converges absolutely, and , which converges absolutely too. This is the Ewald sum that the reference function computes.
Lemma 2 (the short-range sum). Line L6 adds the short-range term of every ordered pair , , whose minimum image distance is below , exactly once, and of no other pair. The omitted short-range force on charge is at most times a factor that tends to 1, and in particular it is .
Proof. The chaining mesh has cells per side, of side . If , two charges closer than in the minimum image lie in the same or in adjacent cells (modulo the period), and the 9 offsets visit each adjacent cell once, because makes them distinct. If , all pairs of cells are visited once. Since , an image closer than is the minimum image, and it is unique. The test then keeps exactly the pairs claimed. For the omitted part, every omitted image is at distance at least , and the sum of over the images of a pair at distances is times a factor bounded by a sum of Gaussian tails over the lattice, which tends to 1 as grows.
Lemma 3 (total momentum). For any influence function with real, if the same weights are used for the assignment (line L1) and for the interpolation (line L5), and the derivative is set to 0 at the Nyquist index, then the mesh forces satisfy . In particular, a single charge feels no mesh force from itself.
Proof. Let be the mesh charge, , and , where is with the Nyquist components set to 0. Then
because is real, so . The map on the FFT indices fixes exactly the indices whose components are 0 or Nyquist, where has the corresponding component 0, and it pairs the other indices. Along each pair, and are equal and changes sign, so the terms cancel, and every fixed index contributes a zero vector component.
The short-range forces satisfy Newton's third law pair by pair, so the total P3M force is zero, as the test checks to rounding.
What is not proved here. The mesh force is an approximation of with an error from the charge assignment and from aliasing. Hockney and Eastwood derive the optimal influence function
with and the assignment function ( for CIC, for TSC), as the minimizer of the mean square force error, averaged over the positions of the charges, for this assignment and ik differentiation. We do not prove this, nor a rate of convergence of the mesh force as ; the code sums the aliases with , and the errors against the Ewald sum are measured on the page.
Complexity
The model is the real RAM.
- Mesh part (theorem). Lines L1 and L5 cost per particle in 2D ( in 3D). Line L2 is one FFT and line L4 two, each. Line L3 is , and so is the table, up to the alias sums.
- Short-range part. Line L6 costs to fill the chaining mesh plus the number of pairs examined. For a uniform distribution, each particle has about neighbours, so the part costs . P3M keeps bounded by choosing and the mesh with , which gives with proportional to .
- Worst case. If the particles cluster, many pairs fall inside and line L6 costs up to . This is the weakness that the TreePM method and adaptive P3M address.
- Space. .
Properties
- Exact split. The two parts add up to the exact force law; all the error comes from the mesh and from the cutoff.
- Momentum. With ik differentiation and the same assignment and interpolation, the total mesh force is zero, and the short-range part obeys Newton's third law. Single pair forces of the mesh are not exactly antisymmetric, and they depend slightly on the positions relative to the mesh.
- Periodic. The FFT makes the result periodic, so P3M suits periodic systems: plasmas, molecular dynamics and cosmological boxes. For open boundaries, the mesh must be doubled in each direction and padded with zeros.
- Tunable. , , and trade accuracy against time, and the error estimate of Deserno and Holm predicts the force error before the run.
- Deterministic. The result does not depend on the order of the particles, up to rounding.
Variants and improvements
- Particle mesh Ewald. The particle mesh Ewald method of molecular dynamics uses Lagrange interpolation, and smooth particle mesh Ewald uses B-splines. Deserno and Holm found that P3M with the optimal influence function is the most accurate of these for a given mesh and order.
- Finite difference gradients. Instead of ik differentiation (three or two inverse FFTs), the field can be taken from the mesh potential by finite differences, with one inverse FFT; the optimal changes accordingly.
- Interlacing. Averaging the results of two meshes shifted by half a mesh cell cancels the main alias errors.
- Adaptive P3M. Refined meshes over dense regions, as in the adaptive P3M codes of cosmology, keep the number of close pairs small when particles cluster.
- Tree for the short range. Replacing the direct sum of line L6 by a Barnes-Hut tree gives the TreePM method.
When to use it
Use P3M for periodic systems with many particles and a long-range force, when the particles are spread fairly evenly: plasma simulation, molecular dynamics with charges, and cosmological simulations at early times. For strongly clustered particles, use TreePM or a fast multipole method. For non-periodic systems, use a fast multipole method, or P3M with a zero padded mesh. For small , direct Ewald summation is simpler.
Pitfalls
- No deconvolution. Using ignores the blur of the assignment and makes the short wavelengths too weak; in the example the errors are up to 100 times larger.
- Cutoff too short for . The short-range part is cut at with an error of about . Keep near 3 or more.
- Kernel too rough for the mesh. If is not small, the long-range kernel has power beyond the Nyquist frequency, and aliasing dominates the error whatever is.
- Different weights for assignment and interpolation. Then the total force is no longer zero, and a lone particle accelerates by itself.
- Nyquist modes. With ik differentiation, the derivative at the Nyquist index must be set to 0, or the field gets an imaginary part and the momentum is lost.
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/p3m-method/. The authors are listed in prov/J50KQM.jsonl.
"""Particle-particle particle-mesh (P3M) forces of Hockney and Eastwood, in 2D.
N charges q[i] at positions pos[i] = (x, y) in the periodic unit square
interact by the 2D Coulomb law: the potential of a pair is -q_i q_j log r and
the force on i is q_i q_j (x_i - x_j) / r^2, summed over all periodic images.
The force of a pair is split with a Gaussian of width 1/alpha:
1/r = exp(-alpha^2 r^2) / r + (1 - exp(-alpha^2 r^2)) / r.
The first part is short-range and is summed directly over the pairs closer
than r_c, found with a chaining mesh. The second part is smooth; it is the
field of Gaussian charge clouds, with the Fourier potential
(2 pi / k^2) exp(-k^2 / (4 alpha^2)), and it is computed on an M x M mesh:
charge assignment (CIC or TSC), FFT, multiplication by -i k G(k), inverse
FFT and interpolation with the same weights. G is the optimal influence
function of Hockney and Eastwood, which minimizes the mean square force
error of the mesh part.
"""
import cmath
import math
from typing import Sequence
Point = tuple[float, float]
def fft(a: Sequence[complex], inverse: bool = False) -> list[complex]:
"""Radix-2 FFT without normalization: sum_g a[g] exp(-+2 pi i n g / len(a))."""
n = len(a)
if n == 1:
return [complex(a[0])]
even = fft(a[0::2], inverse)
odd = fft(a[1::2], inverse)
sign = 1 if inverse else -1
out = [0j] * n
for k in range(n // 2):
w = cmath.exp(sign * 2j * math.pi * k / n) * odd[k]
out[k] = even[k] + w
out[k + n // 2] = even[k] - w
return out
def fft2(grid: list[list[complex]], inverse: bool = False) -> list[list[complex]]:
"""2D FFT of a square grid, rows then columns, without normalization."""
rows = [fft(r, inverse) for r in grid]
cols = [fft([rows[i][j] for i in range(len(rows))], inverse) for j in range(len(rows))]
return [[cols[j][i] for j in range(len(cols))] for i in range(len(rows))]
def weights(x: float, m: int, order: int) -> list[tuple[int, float]]:
"""Mesh points (index mod m) and weights for one coordinate; order 2 is CIC, 3 is TSC."""
u = x * m
if order == 2:
g = math.floor(u)
t = u - g
return [(g % m, 1 - t), ((g + 1) % m, t)]
g = round(u)
t = u - g
return [((g - 1) % m, 0.5 * (0.5 - t) ** 2), (g % m, 0.75 - t * t), ((g + 1) % m, 0.5 * (0.5 + t) ** 2)]
def wavenumber(n: int, m: int) -> float:
"""The wave number 2 pi n of the FFT index n, folded to -m/2 .. m/2 - 1."""
return 2 * math.pi * (n - m if n >= m // 2 else n)
def sinc(x: float) -> float:
return 1.0 if x == 0 else math.sin(x) / x
def influence(m: int, alpha: float, order: int, kind: str = "optimal", alias: int = 2) -> list[list[float]]:
"""G(k) on the mesh: "optimal" (Hockney-Eastwood), "deconvolved" (phi / U^2) or "plain" (phi)."""
h = 1.0 / m
def phi(kx: float, ky: float) -> float:
k2 = kx * kx + ky * ky
return 2 * math.pi / k2 * math.exp(-k2 / (4 * alpha * alpha))
def u2(kx: float, ky: float) -> float:
return (sinc(kx * h / 2) * sinc(ky * h / 2)) ** (2 * order)
g = [[0.0] * m for _ in range(m)]
for i in range(m):
for j in range(m):
kx, ky = wavenumber(i, m), wavenumber(j, m)
if i == 0 and j == 0:
continue
if kind == "plain":
g[i][j] = phi(kx, ky)
elif kind == "deconvolved":
g[i][j] = phi(kx, ky) / u2(kx, ky)
else:
num = 0.0
den = 0.0
for ax in range(-alias, alias + 1):
for ay in range(-alias, alias + 1):
qx, qy = kx + 2 * math.pi * m * ax, ky + 2 * math.pi * m * ay
w = u2(qx, qy)
num += w * (kx * qx + ky * qy) * phi(qx, qy)
den += w
g[i][j] = num / ((kx * kx + ky * ky) * den * den)
return g
def short_range(q: Sequence[float], pos: Sequence[Point], alpha: float, r_c: float) -> tuple[list[Point], int]:
"""Short-range forces over pairs closer than r_c (minimum image), found with a chaining mesh."""
n = len(q)
nc = max(1, int(1 / r_c))
cells: dict[tuple[int, int], list[int]] = {}
for i, (x, y) in enumerate(pos):
cells.setdefault((int(x * nc) % nc, int(y * nc) % nc), []).append(i)
if nc >= 3:
offsets = [(dx, dy) for dx in (-1, 0, 1) for dy in (-1, 0, 1)]
else:
offsets = [(dx, dy) for dx in range(nc) for dy in range(nc)]
f = [[0.0, 0.0] for _ in range(n)]
pairs = 0
for (cx, cy), idx in cells.items():
for dx, dy in offsets:
other = cells.get(((cx + dx) % nc, (cy + dy) % nc), ())
for i in idx:
for j in other:
if i == j:
continue
rx = pos[i][0] - pos[j][0]
ry = pos[i][1] - pos[j][1]
rx -= round(rx)
ry -= round(ry)
r2 = rx * rx + ry * ry
if r2 < r_c * r_c:
c = q[i] * q[j] * math.exp(-alpha * alpha * r2) / r2
f[i][0] += c * rx
f[i][1] += c * ry
pairs += 1
return [(a, b) for a, b in f], pairs
def p3m_forces(q: Sequence[float], pos: Sequence[Point], m: int = 32, alpha: float = 12.0, r_c: float = 0.25,
order: int = 2, kind: str = "optimal"):
"""P3M forces on all charges. m is a power of 2. Returns (forces, stats)."""
n = len(q)
w = [(weights(x, m, order), weights(y, m, order)) for x, y in pos]
rho = [[0j] * m for _ in range(m)]
for i in range(n): # @line L1
for gx, wx in w[i][0]:
for gy, wy in w[i][1]:
rho[gx][gy] += q[i] * wx * wy
rho_k = fft2(rho) # @line L2
g = influence(m, alpha, order, kind)
ex_k = [[0j] * m for _ in range(m)]
ey_k = [[0j] * m for _ in range(m)]
for i in range(m): # @line L3
for j in range(m):
kx = 0.0 if i == m // 2 else wavenumber(i, m)
ky = 0.0 if j == m // 2 else wavenumber(j, m)
ex_k[i][j] = -1j * kx * g[i][j] * rho_k[i][j]
ey_k[i][j] = -1j * ky * g[i][j] * rho_k[i][j]
ex = fft2(ex_k, inverse=True) # @line L4
ey = fft2(ey_k, inverse=True)
forces = []
for i in range(n): # @line L5
fx = fy = 0.0
for gx, wx in w[i][0]:
for gy, wy in w[i][1]:
fx += wx * wy * ex[gx][gy].real
fy += wx * wy * ey[gx][gy].real
forces.append([q[i] * fx, q[i] * fy])
sr, pairs = short_range(q, pos, alpha, r_c) # @line L6
out = [(a + c, b + d) for (a, b), (c, d) in zip(forces, sr)]
return out, {"pairs": pairs, "mesh": m * m} # @line L7
def ewald_forces(q: Sequence[float], pos: Sequence[Point], alpha: float = 8.0, kmax: int = 14) -> list[Point]:
"""Reference forces by Ewald summation: real space over 3 x 3 images, Fourier space up to |n| <= kmax."""
n = len(q)
f = [[0.0, 0.0] for _ in range(n)]
for i in range(n):
for j in range(n):
for ix in (-1, 0, 1):
for iy in (-1, 0, 1):
if i == j and ix == 0 and iy == 0:
continue
rx = pos[i][0] - pos[j][0] + ix
ry = pos[i][1] - pos[j][1] + iy
r2 = rx * rx + ry * ry
c = q[i] * q[j] * math.exp(-alpha * alpha * r2) / r2
f[i][0] += c * rx
f[i][1] += c * ry
for a in range(-kmax, kmax + 1):
for b in range(-kmax, kmax + 1):
if a == 0 and b == 0:
continue
kx, ky = 2 * math.pi * a, 2 * math.pi * b
k2 = kx * kx + ky * ky
coef = 2 * math.pi / k2 * math.exp(-k2 / (4 * alpha * alpha))
s = sum(qj * cmath.exp(-1j * (kx * x + ky * y)) for qj, (x, y) in zip(q, pos))
for i, (x, y) in enumerate(pos):
im = (s * cmath.exp(1j * (kx * x + ky * y))).imag
f[i][0] += q[i] * coef * kx * im
f[i][1] += q[i] * coef * ky * im
return [(a, b) for a, b in f]
test_p3m_method.py 131 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/p3m-method/. The authors are listed in prov/J50KQM.jsonl.
"""Tests for P3M: the FFT, the assignment weights, the short-range sum, and the forces against Ewald summation."""
import cmath
import math
import random
import unittest
from p3m_method import ewald_forces, fft, fft2, p3m_forces, short_range, weights
def rms_err(f, ref):
num = sum((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 for a, b in zip(f, ref))
den = sum(b[0] ** 2 + b[1] ** 2 for b in ref)
return math.sqrt(num / den)
def charges(n, seed):
rng = random.Random(seed)
pos = [(rng.random(), rng.random()) for _ in range(n)]
q = [1.0 if i % 2 == 0 else -1.0 for i in range(n)]
return q, pos
class TestPieces(unittest.TestCase):
def test_fft_matches_dft(self):
rng = random.Random(1)
a = [complex(rng.random(), rng.random()) for _ in range(16)]
for inverse, sign in ((False, -1), (True, 1)):
b = fft(a, inverse)
for k in range(16):
d = sum(a[g] * cmath.exp(sign * 2j * math.pi * k * g / 16) for g in range(16))
self.assertAlmostEqual(abs(b[k] - d), 0.0, places=12)
def test_fft2_round_trip(self):
rng = random.Random(2)
grid = [[complex(rng.random(), 0) for _ in range(8)] for _ in range(8)]
back = fft2(fft2(grid), inverse=True)
for i in range(8):
for j in range(8):
self.assertAlmostEqual(abs(back[i][j] / 64 - grid[i][j]), 0.0, places=12)
def test_weights_conserve_charge_and_center(self):
rng = random.Random(3)
m = 16
for order in (2, 3):
for _ in range(20):
x = rng.uniform(0.1, 0.9)
w = weights(x, m, order)
self.assertAlmostEqual(sum(v for _, v in w), 1.0, places=14)
u = x * m
center = sum(v * (g + m * round((u - g) / m)) for g, v in w)
self.assertAlmostEqual(center, u, places=12)
def test_short_range_matches_brute_force(self):
q, pos = charges(120, 4)
alpha, r_c = 12.0, 0.25
f, pairs = short_range(q, pos, alpha, r_c)
count = 0
for i in range(120):
fx = fy = 0.0
for j in range(120):
if i == j:
continue
rx = pos[i][0] - pos[j][0]
ry = pos[i][1] - pos[j][1]
rx -= round(rx)
ry -= round(ry)
r2 = rx * rx + ry * ry
if r2 < r_c * r_c:
c = q[i] * q[j] * math.exp(-alpha * alpha * r2) / r2
fx += c * rx
fy += c * ry
count += 1
self.assertAlmostEqual(f[i][0], fx, places=9)
self.assertAlmostEqual(f[i][1], fy, places=9)
self.assertEqual(pairs, count)
def test_ewald_does_not_depend_on_alpha(self):
q, pos = charges(60, 5)
self.assertLess(rms_err(ewald_forces(q, pos, alpha=6.0, kmax=12), ewald_forces(q, pos)), 1e-10)
class TestP3M(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.q, cls.pos = charges(200, 21)
cls.ref = ewald_forces(cls.q, cls.pos)
def test_accuracy_against_ewald(self):
cases = ((32, 2, 5e-3), (32, 3, 6e-4), (64, 3, 1e-4))
for m, order, tol in cases:
f, st = p3m_forces(self.q, self.pos, m=m, order=order)
self.assertLess(rms_err(f, self.ref), tol)
self.assertEqual(st["mesh"], 64 * 64)
def test_influence_functions(self):
errs = [rms_err(p3m_forces(self.q, self.pos, m=16, alpha=16.0, r_c=0.1875, kind=k)[0], self.ref)
for k in ("plain", "deconvolved", "optimal")]
self.assertLess(errs[1], errs[0] / 1.5)
self.assertLess(errs[2], errs[1])
def test_smaller_alpha_moves_work_to_the_pairs(self):
prev_err, prev_pairs = 0.0, 10 ** 9
for alpha, r_c in ((8.0, 0.375), (12.0, 0.25), (20.0, 0.15)):
f, st = p3m_forces(self.q, self.pos, m=32, alpha=alpha, r_c=r_c)
e = rms_err(f, self.ref)
self.assertGreater(e, prev_err)
self.assertLess(st["pairs"], prev_pairs)
prev_err, prev_pairs = e, st["pairs"]
def test_total_force_is_zero(self):
f, _ = p3m_forces(self.q, self.pos, m=32)
scale = math.sqrt(sum(a * a + b * b for a, b in self.ref) / len(self.ref))
self.assertLess(abs(sum(a for a, _ in f)), 1e-10 * scale)
self.assertLess(abs(sum(b for _, b in f)), 1e-10 * scale)
single, _ = p3m_forces([1.0], [(0.3, 0.6)], m=32)
self.assertLess(math.hypot(*single[0]), 1e-12)
def test_pair_force(self):
for d in (0.05, 0.2, 0.4):
pos2 = [(0.3, 0.5), (0.3 + d, 0.5)]
f, _ = p3m_forces([1.0, -1.0], pos2, m=32)
r = ewald_forces([1.0, -1.0], pos2)
self.assertLess(abs(f[0][0] - r[0][0]), 0.01 * abs(r[0][0]))
self.assertGreater(f[0][0], 0.0)
if __name__ == "__main__":
unittest.main()
History
Hockney and Eastwood developed the particle-particle particle-mesh method for plasma and gravitational simulation and described it in their book Computer Simulation Using Particles (1981; second edition 1988), together with the chaining mesh and the optimal influence function. The method was used in cosmological simulations from the 1980s, where adaptive versions refine the mesh over clusters. Deserno and Holm (1998) compared P3M with the particle mesh Ewald methods of molecular dynamics and gave an accurate error estimate for it.
References
- Roger W. Hockney and James W. Eastwood, Computer Simulation Using Particles, Adam Hilger, 1988, Chapter 8, the particle-particle particle-mesh algorithm, the chaining mesh and the optimal influence function
- Markus Deserno and Christian Holm, How to mesh up Ewald sums. I. A theoretical and numerical comparison of various particle mesh routines, Journal of Chemical Physics 109, 1998, 7678, the comparison of P3M with particle mesh Ewald and smooth particle mesh Ewald, the optimal influence function and the ik and finite difference derivatives
- Markus Deserno and Christian Holm, How to mesh up Ewald sums. II. An accurate error estimate for the particle-particle-particle-mesh algorithm, Journal of Chemical Physics 109, 1998, 7694, the error estimate of P3M from the optimal influence function and its use to choose the parameters
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.
| 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 J50KQM Edit this page History Report an error Markdown