numerics
Loading...
Searching...
No Matches
pbc_lattice.hpp
Go to the documentation of this file.
1
/// @file spatial/pbc_lattice.hpp
2
/// @brief Precomputed periodic-boundary neighbor arrays for a 2D square lattice.
3
///
4
/// PBCLattice2D builds up[i], dn[i], lt[i], rt[i] once from modulo arithmetic
5
/// so the hot-path (Metropolis sweeps, BFS cluster detection) never calls %.
6
///
7
/// Flat layout: i = row * N + col, row and col in [0, N).
8
#pragma once
9
10
#include <vector>
11
12
namespace
num
{
13
14
/// 4-neighbor periodic-boundary index arrays for an N×N lattice.
15
struct
PBCLattice2D
{
16
int
N
;
///< Side length; total sites = N*N
17
std::vector<int>
up
,
dn
,
lt
,
rt
;
///< up/dn = row±1, lt/rt = col±1 (PBC)
18
19
explicit
PBCLattice2D
(
int
N
)
20
:
N
(
N
),
up
(
N
*
N
),
dn
(
N
*
N
),
lt
(
N
*
N
),
rt
(
N
*
N
)
21
{
22
for
(
int
row
= 0;
row
<
N
; ++
row
)
23
for
(
int
col = 0; col <
N
; ++col) {
24
const
int
i
=
row
*
N
+ col;
25
up
[
i
] = ((
row
- 1 +
N
) %
N
) *
N
+ col;
26
dn
[
i
] = ((
row
+ 1) %
N
) *
N
+ col;
27
lt
[
i
] =
row
*
N
+ (col - 1 +
N
) %
N
;
28
rt
[
i
] =
row
*
N
+ (col + 1) %
N
;
29
}
30
}
31
};
32
33
}
// namespace num
num
Definition
quadrature.hpp:8
num::ipow
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
Definition
integer_pow.hpp:34
num::PBCLattice2D
4-neighbor periodic-boundary index arrays for an N×N lattice.
Definition
pbc_lattice.hpp:15
num::PBCLattice2D::up
std::vector< int > up
Definition
pbc_lattice.hpp:17
num::PBCLattice2D::dn
std::vector< int > dn
Definition
pbc_lattice.hpp:17
num::PBCLattice2D::rt
std::vector< int > rt
up/dn = row±1, lt/rt = col±1 (PBC)
Definition
pbc_lattice.hpp:17
num::PBCLattice2D::PBCLattice2D
PBCLattice2D(int N)
Definition
pbc_lattice.hpp:19
num::PBCLattice2D::N
int N
Side length; total sites = N*N.
Definition
pbc_lattice.hpp:16
num::PBCLattice2D::lt
std::vector< int > lt
Definition
pbc_lattice.hpp:17
include
spatial
pbc_lattice.hpp
Generated by
1.9.8