|
numerics 0.1.0
|
include/spatial/pbc_lattice.hpp provides num::PBCLattice2D, a small struct that precomputes the four periodic-boundary neighbor index arrays for an \(N \times N\) square lattice.
Periodic square-lattice algorithms repeatedly access the four nearest neighbors of each site. Precomputed neighbor arrays replace modulo operations inside sweeps and cluster traversals.
Construction is \(O(N^2)\) and done once; subsequent lookups are direct array reads.
Flat row-major layout: site \((row, col)\) has flat index \(i = row \cdot N + col\).
\[ \texttt{up}[i] = ((row - 1 + N) \bmod N) \cdot N + col \]
\[ \texttt{dn}[i] = ((row + 1) \bmod N) \cdot N + col \]
\[ \texttt{lt}[i] = row \cdot N + (col - 1 + N) \bmod N \]
\[ \texttt{rt}[i] = row \cdot N + (col + 1) \bmod N \]
Used by: Ising IsingLattice::sweep, IsingLattice::sweep_umbrella.