-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ising-n.f
55 lines (50 loc) · 1.2 KB
/
Ising-n.f
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
\ Ising model simulation in FORTH
\ Andrew Read
\ (C) 2012, GNU General Public License
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Graphical extensions for the NIGE Machine
: render-n ( display the lattice, for NIGE Machine)
csr-off 0 csr-x ! 0 csr-y !
lattice
dimension @ ROWS C@ 2 - min 0 DO
dimension @ COLS c@ min 0 DO
dup c@ 2 = if 159 else 160 then vemitraw
1+
LOOP
dimension @ COLS C@ - dup 0> IF
+ \ update for skipped columns
ELSE
CR \ newline
drop
THEN
LOOP
drop
stats
cr
." Magnetization " 4 .r 9 emit
drop
." Lattice energy " 5 .r 9 emit
." Boltzmann " Boltzmann @ u.
;
: UMAX ( a b -- u, unsigned maximum of a and b)
over over
U> IF DROP ELSE NIP THEN
;
: UMIN ( a b -- u, unsigned minimum of a and b)
over over
U< IF DROP ELSE NIP THEN
;
: run-n ( -- indefinate iteration of the metropolis algorithm for NIGE Machine, press UP / DOWN to raise or lower temp, or ESC to stop)
0 interlace cls \ need non-interlaced screen
BEGIN
1000 0 DO metropolis LOOP
render-n
key? IF
key CASE
4 OF Boltzmann dup @ 10000000 UMAX 1000000 - swap ! ENDOF
5 OF Boltzmann dup @ 4284967295 UMIN 1000000 + swap ! ENDOF
27 OF EXIT ENDOF
ENDCASE
THEN
AGAIN
;