Created
December 6, 2019 06:56
-
-
Save HamletWantToCode/8eedd4f2625b70869f367927d3c95e2d to your computer and use it in GitHub Desktop.
Adjacent table for 2D Ising model
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
function ising2d(N; BC="PBC") | |
J = zeros(N^2, N^2) | |
for i in 1:N^2-1 | |
i₁, i₂ = i%N, i÷N | |
if i₁==0 | |
if BC == "PBC" | |
J[1+(i₂-1)*N,i] = J[i,1+(i₂-1)*N] = 1.0 | |
end | |
J[(i₂+1)*N,i] = J[i,(i₂+1)*N] = 1.0 | |
continue | |
end | |
if i₂==N-1 | |
if BC == "PBC" | |
J[i₁,i] = J[i,i₁] = 1.0 | |
end | |
J[i+1,i] = J[i,i+1] = 1.0 | |
continue | |
end | |
J[i,i+1] = J[i+1,i] = 1.0 | |
J[i,i₁+(i₂+1)*N] = J[i₁+(i₂+1)*N,i] = 1.0 | |
end | |
if BC == "PBC" | |
J[N,N^2] = J[N^2,N] = 1.0 | |
J[N^2-N+1,N^2] = J[N^2,N^2-N+1] = 1.0 | |
end | |
return J | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment