File: ising2

package info (click to toggle)
saml 970418-9
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,188 kB
  • ctags: 1,703
  • sloc: ansic: 17,186; sh: 2,573; yacc: 497; perl: 264; makefile: 242; python: 242
file content (28 lines) | stat: -rwxr-xr-x 892 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl
#
# The Ising model on a two-dimensional torus with L lines and C columns.
# As in "count_colors", it's more efficient to take L <= C.
# The result is a polynomial in f, and the coefficient a_k of f^k is the
# number of combinations such that there are k edges between vertices of
# different spins. So high values of k correspond to high energies, and
# the sum of all a_k is 2^(L.C).
#
die "Usage: $0 <lines> <columns>\n" unless ($#ARGV == 1);
$lines = $ARGV[0];
$columns = $ARGV[1];
print <<"EOF" ;
Up = Down = 1;
Cell =	Up	* L!1.D!1.(R!1+f.R!2).(U!1+f.U!2) +
	Down	* L!2.D!2.(f.R!1+R!2).(f.U!1+U!2);	
Nb = 1;
EOF
foreach $x (0 .. $columns-1) {
    foreach $y (0 .. $lines-1) {
    	$X = $x+1; $X = 0 if ($X == $columns);
    	$Y = $y+1; $Y = 0 if ($Y == $lines);
	print <<"EOL";
Nb = Nb * (Cell,L=>H[$x,$y],R=>H[$X,$y],D=>V[$x,$y],U=>V[$x,$Y]);
EOL
    }
}
print "Nb;\n";