27 for (
int row = 0; row <
N; ++row)
28 for (
int col = 0; col <
N; ++col) {
29 const int i = row *
N + col;
30 up[i] = ((row - 1 +
N) %
N) *
N + col;
31 dn[i] = ((row + 1) %
N) *
N + col;
32 lt[i] = row *
N + (col - 1 +
N) %
N;
33 rt[i] = row *
N + (col + 1) %
N;
4-neighbor periodic-boundary index arrays for an NxN lattice.
std::vector< int > rt
up/dn = row +/-1, lt/rt = col +/-1 (PBC)
int N
Side length; total sites = N*N.