Ising2D

Ising2D.Ising2DModule

Ising2D is a simple Julia module of 2D Ising model.

Benchmark 1:

using Ising2D, BenchmarkTools
s = rand_ising2d()
print("VERSION = $VERSION:")
@btime ising2d!($s; algorithm=IfElse());

Benchmark 2:

using Ising2D, BenchmarkTools
s = rand_ising2d()
print("VERSION = $VERSION:")
@btime ising2d!($s; algorithm=MultiFor());
source
Ising2D.β_ising2dConstant
β_ising2d = log(1 + √2)/2

is the critical inverse temperature of 2D Ising model on the square lattice.

source
Ising2D.gif_ising2dMethod
gif_ising2d(; s=rand_ising2d(), k=1.0, β=k*β_ising2d, rng=default_rng(),
    algorithm=default_algorithm(), progress=true,
    nwarmups=0, nskips=10, niters=100, 
    gifname="ising2d.gif", fps=10,
    size=(201.5, 217.5), color=:gist_earth, clim=(-2, 1.1), kwargs...
)

creates the gif animation of 2D Ising model.

Example: To create a 200x200 GIF animation, run

gif_ising2d(s=rand_ising2d(200))
source
Ising2D.gif_mcmc_ising2dFunction
gif_mcmc_ising2d(S=nothing, E=nothing, M=nothing;
    s=rand_ising2d(), k=1.0, β=k*β_ising2d, rng=default_rng(),
    algorithm=default_algorithm(), progress=true,
    nwarmups=1000, nskips=1000, niters=500,
    ylim_E=(-1.55, -1.30), ylim_M=(-0.8, 0.8), lw=1.0, alpha=0.8,
    gifname="ising2d_mcmc.gif", fps=10,
    size=(600, 300), color=:gist_earth, clim=(-2, 1.1), kwargs...
)

creates the gif animation of 2D Ising model with energy per site and magnetization.

Example:

gif_mcmc_ising2d()
source
Ising2D.histogram_mcmc_ising2dFunction
histogram_mcmc_ising2d(S, E=nothing, M=nothing;
    niters=length(S), bin=min(100, max(10, round(Int, 1.2*√niters))), 
    size=(600, 200), kwargs...
)

plots the histogram of energy per site and magnetization of the MCMC result S.

source
Ising2D.ising2d!Function
ising2d!(s=rand_ising2d(), β=β_ising2d, niters=10^3, rng=default_rng();
    algorithm=default_algorithm())

updates the 2-dimensional array s with values ±1 randomly by 2D Ising model rule.

Example 1:

using Ising2D
@time s = ising2d!(rand_ising2d(), β_ising2d, 10^5)
plot_ising2d(s)

Example 2:

using Ising2D
@time s = ising2d!(rand_ising2d(), β_ising2d, 10^5; algorithm=IfElse())
plot_ising2d(s)
source
Ising2D.ising2d!Function
ising2d!(::MultiFor, s=rand_ising2d(), β=β_ising2d, niters=10^3, rng=default_rng())

uses the algorithm using multiple for-loops.

Example:

s = ones_ising2d()
ising2d!(MultiFor(), s)
plot_ising2d(s)
source
Ising2D.ising2d!Function
ising2d!(::IfElse, s=rand_ising2d(), β=β_ising2d, niters=10^3, rng=default_rng())

uses the algorithm using ifelse in only one for-loop.

Example:

s = ones_ising2d()
ising2d!(IfElse(), s)
plot_ising2d(s)
source
Ising2D.mcmc_ising2d!Method
mcmc_ising2d!(; s=rand_ising2d(), k=1.0, β=k*β_ising2d, rng=default_rng(),
    algorithm=default_algorithm(), progress=true, 
    nwarmups=1000, nskips=100, niters=5000
)

returns the result of the Markov Chain Monte Carlo simulation with length niters, which is the array of the states of 2D Ising model.

source
Ising2D.plot_ising2dMethod
plot_ising2d(s; size=(201.5, 201.5), color=:gist_earth, clim=(-2, 1.1), kwargs...)

plots the state s of 2D Ising model.

source
Ising2D.plot_mcmc_ising2dFunction
plot_mcmc_ising2d(S, E=nothing, M=nothing;
    k=1.0, β=k*β_ising2d, niters=length(S), t=niters,   
    ylim_E=(-1.50, -1.35), ylim_M=(-0.75, 0.75), lw=0.5, alpha=0.8,
    size=(600, 300), color=:gist_earth, clim=(-2, 1.1), kwargs...
)

plots the MCMC result S with energy per site and magnetization.

source
Ising2D.rand_ising2dFunction
rand_ising2d(rng::AbstractRNG, m=100, n=m)
rand_ising2d(m=100, n=m)

generate the random state of 2D Ising model.

source