MultilevelSummation.Reference submodule
The Reference submodule hosts the two absolute baseline implementations used by the test suite and the tuning scripts:
naive_energy/naive_energy_forces— directO(N²)sum, generic in the pair kernel and boundary conditions.ewald_energy/ewald_energy_forces— naive 3D Ewald reference for fully periodic Coulomb.
using MultilevelSummation.Reference: naive_energy, naive_energy_forces
using MultilevelSummation.Reference: ewald_energy, ewald_energy_forcesnaive_energy / naive_energy_forces
Useful for small-system sanity checks. Periodic axes are handled by truncating the lattice-image sum to a user-supplied R_cut.
MultilevelSummation.Reference.naive_energy — Function
naive_energy(positions, charges, cell, periodic, kernel; R_cut=Inf)Direct O(N²) reference energy
U = ½ Σ_{i,j,n}' q_i · kernel(r_i − r_j + n·L) · q_j(scalar charge case). The primed sum excludes the term (i = j, n = 0). Periodic axes are summed over image translations n whose shift is within R_cut; non-periodic axes are restricted to n_α = 0.
Restricted to orthorhombic cells (diagonal lattice matrix). R_cut must be finite when any axis is periodic; for fully open systems the default Inf works.
MultilevelSummation.Reference.naive_energy_forces — Function
naive_energy_forces(positions, charges, cell, periodic, kernel; R_cut=Inf)Like naive_energy, but additionally returns the per-particle forces F_i = −∂U/∂r_i. Same O(N²) cost and same restrictions (orthorhombic cell, finite R_cut for periodic axes).
ewald_energy / ewald_energy_forces
U = ewald_energy(positions, charges, cell; α=0.7, R_cut=10.0, k_cut=12.0)
U, F = ewald_energy_forces(positions, charges, cell; α=0.7, R_cut=10.0, k_cut=12.0)For a convenient auto-tuned call (it picks $α$, $R_\text{cut}$, $k_\text{cut}$ from the cell extent and a target tolerance), see MultilevelSummation.Tune.ewald_reference on the Tune page.
It self-validates via the α-invariance property (Ewald's defining property: total energy is independent of $α$ when $R_\text{cut}$ and $k_\text{cut}$ are large enough). See test/test_ewald.jl for the checks.
MultilevelSummation.Reference.ewald_energy — Function
ewald_energy(positions, charges, cell; α, R_cut, k_cut) -> RealNaive 3D Ewald total energy for fully-periodic orthorhombic Coulomb. The charge sum must be (approximately) zero.
MultilevelSummation.Reference.ewald_energy_forces — Function
ewald_energy_forces(positions, charges, cell; α, R_cut, k_cut)
-> (energy::Real, forces::Vector{SVector{3,T}})Same as ewald_energy, but also returns the per-particle forces F_i = -∂U/∂r_i.