An example of Monte Carlo simulations for the Ising model in ALPSAndriy Zhugayevych, azh@ukr.net17.03.2010My system is: ALPS for Windows 2.0, Maple 14, Windows 7BasicTools package is required: either install it or read the provided with this example BasicTools.ini fileunwith(BasicTools);
read "BasicTools.ini":
with(BasicTools):Set ALPS paths and filenamesfolder:="A:/homepage/maple/ALPS_spinmc/";
binfolder:="C:/Sci/ALPS/bin/";
job:=cat(folder,"job.xml");
inp:=cat(folder,"inp.xml");
out:=cat(folder,"out.xml");
lOg:=cat(folder,"log.log");
latticelib:="C:/Sci/ALPS/lib/xml/lattices.xml";
with(XMLTools):Initialize routinesWriteParameters:=proc(L::posint,T::numeric,sweeps::posint,thermalization::posint,seed::posint,
{print_sweeps::posint:=sweeps+1,filename::string:=inp},$)
local fd;
fd:=fopen(filename,WRITE,TEXT);
writeline(fd,"<SIMULATION>","<PARAMETERS>");
fprintf(fd,"<PARAMETER name=\134"LATTICE_LIBRARY\134">%s</PARAMETER>\134n",latticelib);
writeline(fd,"<PARAMETER name=\134"LATTICE\134">square lattice</PARAMETER>");
writeline(fd,"<PARAMETER name=\134"MODEL\134">Ising</PARAMETER>");
writeline(fd,"<PARAMETER name=\134"J\134">-1</PARAMETER>");
fprintf(fd,"<PARAMETER name=\134"L\134">%d</PARAMETER>\134n",L);
fprintf(fd,"<PARAMETER name=\134"T\134">%a</PARAMETER>\134n",T);
fprintf(fd,"<PARAMETER name=\134"THERMALIZATION\134">%d</PARAMETER>\134n",thermalization);
fprintf(fd,"<PARAMETER name=\134"SWEEPS\134">%d</PARAMETER>\134n",sweeps);
if (print_sweeps<=sweeps) then fprintf(fd,"<PARAMETER name=\134"PRINT_SWEEPS\134">%d</PARAMETER>\134n",print_sweeps) end;
writeline(fd,"<PARAMETER name=\134"UPDATE\134">cluster</PARAMETER>");
fprintf(fd,"<PARAMETER name=\134"SEED\134">%d</PARAMETER>\134n",seed);
writeline(fd,"</PARAMETERS>","</SIMULATION>");
fclose(fd);
NULL
end:
ReadParameters:=proc({filename::string:=inp},$)
local xd,e;
xd:=ParseFile(filename):
for e in GetChildByName(op(GetChildByName(xd,"PARAMETERS")),"PARAMETER") do printf("%s=%s\134n",AttributeValue(e,"name"),TextText(GetChild(e,1))) end;
NULL
end:
Write the input files...seed:=1470669691;
L,T:= 150, 2.0;
WriteParameters(L,T,5000,1000,seed,'print_sweeps'=1000);... and check them if you wantReadParameters();Run spinmcct:=time[real]():
ssystem(cat(binfolder,"spinmc --Tmin 10 --write-xml ",job," >",lOg));
time[real]()-ct;Read snapshots...ct:=time():
n:=nops(GetKeyPos(lOg,"Dumping configuration:"));
Sz:=Vector(n):
for i from 1 to n do
ls:=ReadLines(lOg,'key'="Dumping configuration:",'nlines'=L^2,'skip'=i-1):
M:=ImageTools[Create](L,L,1,format=Matrix):
for s in ls do x,y,sz:=op(sscanf(s,"%d%d%d%d")[2..4]); M[x+1,y+1]:=sz end:
Sz[i]:=copy(M) end:
time()-ct;... and print them as tif-filesfor i from 1 to n do ImageTools[Write](sprintf("snapshot%02d.tif",i),ImageTools[Scale](Sz[i],floor(1024/L),method=nearest)) end: