Created
April 3, 2021 08:17
-
-
Save genkuroki/993711198d581de9e0ebf69f72b95ab3 to your computer and use it in GitHub Desktop.
2d_Ising.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Pkg | |
Pkg.add("Plots") | |
Pkg.add("ProgressMeter") | |
previous_GKSwstype = get(ENV, "GKSwstype", "") | |
ENV["GKSwstype"] = "100" | |
using Plots, ProgressMeter, Random, Printf | |
N(i, m) = ifelse(i == 1, m, i-1) | |
P(i, m) = ifelse(i == m, m, i+1) | |
function ising2d!(s, skip, prob, rng) | |
(m, n) = size(s) | |
for _ in 1:skip, j in 1:n, i in 1:m | |
sij = s[i,j] | |
k = sij * (s[N(i, m), j] + s[P(i, m), j] + s[i, N(j, n)] + s[i, P(j, n)]) | |
s[i, j] = ifelse(rand(rng) < prob[k+5], -sij, sij) | |
end | |
end | |
n, skip, L = 200, 1, 500 | |
β = log(1 + √2)/2 | |
prob = ((exp(-2β*k) for k in -4:4)...,); | |
rng = Random.default_rng(); | |
s = rand(rng, Int8[-1,1], n, n); | |
prog = Progress(L, 0); | |
anim = @animate for t in 0:L | |
heatmap(s; size=(240, 260), colorbar=false, frame=false, axis=false, ticks=false) | |
title!("$(n)×$(n) × $(skip) skip × $(@sprintf("%3d", t))"; titlefontsize=11) | |
ising2d!(s, skip, prob, rng) | |
next!(prog) | |
end | |
gif(anim, "2d_Ising.gif") |
Author
genkuroki
commented
Apr 3, 2021
For the setting ENV["GKSwstype"] = 100 or ENV["GKSwstype"] = "null", see https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment