Ising2D
Ising2D.Ising2D
Ising2D.β_ising2d
Ising2D.IfElse
Ising2D.MultiFor
Ising2D.default_algorithm
Ising2D.energy_density_ising2d
Ising2D.gif_ising2d
Ising2D.gif_mcmc_ising2d
Ising2D.histogram_mcmc_ising2d
Ising2D.ising2d!
Ising2D.ising2d!
Ising2D.ising2d!
Ising2D.magnetization_ising2d
Ising2D.mcmc_ising2d!
Ising2D.ones_ising2d
Ising2D.plot_ising2d
Ising2D.plot_mcmc_ising2d
Ising2D.rand_ising2d
Ising2D.Ising2D
— ModuleIsing2D 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());
Ising2D.β_ising2d
— Constantβ_ising2d = log(1 + √2)/2
is the critical inverse temperature of 2D Ising model on the square lattice.
Ising2D.IfElse
— TypeIfElse()
= Algorithm using ifelse
Ising2D.MultiFor
— TypeMultiFor()
= Algorithm using multiple for-loops
Ising2D.default_algorithm
— Methoddefault_algorithm() = MultiFor()
Ising2D.energy_density_ising2d
— Methodenergy_ising2d(s)
returns the energy density (energy per site) of the state s
of 2D Ising model.
Ising2D.gif_ising2d
— Methodgif_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))
Ising2D.gif_mcmc_ising2d
— Functiongif_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()
Ising2D.histogram_mcmc_ising2d
— Functionhistogram_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.
Ising2D.ising2d!
— Functionising2d!(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)
Ising2D.ising2d!
— Functionising2d!(::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)
Ising2D.ising2d!
— Functionising2d!(::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)
Ising2D.magnetization_ising2d
— Methodmagnetization_ising2d(s)
returns the magnetization of the state s
of 2D Ising model.
Ising2D.mcmc_ising2d!
— Methodmcmc_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.
Ising2D.ones_ising2d
— Functionones_ising2d(m=100, n=m)
generates the all-one state of 2D Ising model.
Ising2D.plot_ising2d
— Methodplot_ising2d(s; size=(201.5, 201.5), color=:gist_earth, clim=(-2, 1.1), kwargs...)
plots the state s
of 2D Ising model.
Ising2D.plot_mcmc_ising2d
— Functionplot_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.
Ising2D.rand_ising2d
— Functionrand_ising2d(rng::AbstractRNG, m=100, n=m)
rand_ising2d(m=100, n=m)
generate the random state of 2D Ising model.