Some fun with 2-dimensional Ising model and algorithms as Heat Bath, Metropolis and Wolff. This package provides functions to create and play with simples simulations and Monte Carlo algorithms.
To install this package, inside Julia REPL, type:
Pkg.clone("git://github.com/brk00/IsingLite.jl.git")
This package is intended to be used from inside the Julia REPL. To load the package, after installing it, type:
using IsingLite
A n
by n
random grid of spins can be created by using the spingrid
function. The grid created is a simple 2-dimensional Julia Array
, and not a special data type. Example:
g = spingrid(10) # Create a 10x10 spin grid
This package supports heatbath, matropolis and wolff algorithms for the Ising Model. To run any of these, you can use the respective function on a previously created spin grid. Example:
g = spingrid(25) #Create a spin grid
heatbath!(g)
The function will return an array with the values of magnetization of the grid after each iteration. Also, a plot showing the magnetization of the grid by the number of iterations will be saved on working directory.
You can add keyword arguments to the algorithms' functions:
heatbath!(g, verbose=false)
All functions (heatbath!
, metropolis!
, wolff!
) support basically the same API. The supported keyword arguments are:
h
, aFloat64
number indicating the value of the external field (default is0.0
)temp
, aFloat64
number indicating the temperature of the simulation (default is1.0
)iters
, anInteger
indicating the number of iterations to be performed (default is5000
in the case ofheatbath!
andmetropolis!
, and30
in the case ofwolff!
)plot
, aBool
indicating if the user want or not to plot the result (default istrue
)verbose
, aBool
indicating if the user want the function to print something during or after the run (default istrue
)
You can produce a phase diagram, by calling the diagram
function, which returns two arrays: one of temperatures and the other of the grid's magnetization at each temperature. Example:
t, m = diagram(heatbath!)
The only non-optional argument of the diagram
function is a function f
implementing the algorithm you want. As said before, this package only provide the functions heatbath!
, metropolis!
, and wolff!
, but you can pass any function with the same API of these (detailed on the previous section), and the diagram
will produce a phase diagram accordingly. This function also support many keyword arguments:
size
, aInteger
with the size of the spin grid used to generate the diagram (default is10
)ensembles
, anInteger
denoting the number of ensembles (default is50
)h
, aFloat64
number indicating the value of the external field (default is0.0
)mintemp
, aFloat64
number indicating the temperature at which the simulation starts (default is0.5
)step
, aFloat64
number indicating by what value the temperature changes at each iteration (default is0.2
)maxtemp
, aFloat64
number indicating the temperature at which the simulation end (default is0.5
)iters
, anInteger
indicating the number of iterations to be performed inside the given algorithm (default is5000
)plot
, aBool
indicating if the user want or not to plot the result (default istrue
)verbose
, aBool
indicating if the user want the function to print something during or after the run (default istrue
)
The function neighbors
receives a grid g
, and two coordinates i
and j
inside it, and return an Array
of coordinates (each one in a tuple of the kind (x,y)) of it's neighbors. Example:
g = spingrid(10)
# Get the coordinates of the neighbors of g[1,1]
neighbors(g, 1, 1) # Returns [(2,1), (1,2)]
The function nspins
receives a grid g
, and two coordinates i
and j
inside it, and return an Array
of spins surrounding it.
g = spingrid(10)
# Get the spins of the neighbors of g[1,1]
nspins(g, 1, 1)