/
Potts.jl
46 lines (41 loc) · 1.39 KB
/
Potts.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@doc doc"""
`Q` state Potts model with energy $E = -\sum_{i,j} \delta_{\sigma_i, \sigma_j}$,
where $\sigma_i$ takes an integer value from $1$ to $Q$ and $\delta$ is a Kronecker's delta.
Order parameter (total magnetization) is defined as
\begin{equation}
M = \frac{Q-1}{Q}N_1 - \frac{1}{Q}(N-N_1),
\end{equation}
where $N$ is the number of sites and $N_1$ is the number of $\sigma=1$ spins.
"""
mutable struct Potts <: Model
lat :: Lattice
Q :: Int
spins :: Matrix{Int}
rng :: Random.MersenneTwister
function Potts(lat::Lattice, Q::Integer, rng::Random.AbstractRNG)
if Q < 2
error("Q should be 2 or more: Q = $Q")
end
spins = rand(rng, 1:Q, 1, numsites(lat))
return new(lat, Q, spins, rng)
end
end
Potts(lat::Lattice, Q::Integer) = Potts(lat, Q, Random.seed!(Random.MersenneTwister(0)))
Potts(lat::Lattice, Q::Integer, seed) = Potts(lat, Q, Random.seed!(Random.MersenneTwister(0), seed...))
@doc doc"""
Potts(param)
Generates `Potts` using `param["Lattice"]`, `param["Q"]`, and `param["Seed"]` (if defined).
Each spin will be initialized randomly and independently.
"""
function Potts(param::Parameter)
lat = generatelattice(param)
Q = param["Q"]
if "Seed" in keys(param)
return Potts(lat, Q, param["Seed"])
else
return Potts(lat, Q)
end
end
include("update.jl")
include("estimator.jl")
include("postproc.jl")