# This is a module for 8.08 - 8.S308 numerics recitation. module Rec #parameters of the model mutable struct Param dt::Float64 # time step L::Int64 # number of sites per dimension J::Float64 # interaction strength T::Float64 # Temperature end #constructor function setParam(L, J, T) param = Param(0, L, J, T) return param end #state variables of the model mutable struct State t::Float64 # current time s::Array{Int8, 2} # spin array end #constructor function setState(param) s = zeros(Float64, param.L, param.L) state = State(0, s) return state end end function tower_sampling(w, W, rng) ### Implement your tower sampling algorithm index = 1 return index end function run_simulation!(state, param, t_run, rng) t_now = state.t # time at the beginning of your simulation L, J, T = param.L, param.J, param.T # loading parameters beta = 1/T x, y = 0, 0 ei, ef = 0.0, 0.0 m = 0.0 move = 0 w = zeros(Float64, 2) W = 0.0 # move(1) = flip spin, 1 -> -1 or -1 -> 1 # move(2) = don't do anything dt = 1/exp(4*J/T) while state.t < t_now + t_run # I selected a spin location for you x = rand(rng, 1:L) y = rand(rng, 1:L) ### Please write your algorithm for simulation the model here # magnetization of the neighbors felt by the spin m = # energy of the initial configuration ei = # energy of the final configuration ef = # your transition probabilities w[1] = w[2] = W = sum(w) move = tower_sampling(w, W, rng) if move==1 state.s[x,y] = elseif move==2 state.s[x,y] = end state.t += dt/(L^2) end end function get_movie!(state, param, rng, t_gap, n_frame, in_fps) x_range = range(1,L, length = L) # lattice x coordinates y_range = range(1,L, length = L) # lattice y coordinates anim = @animate for frame in 1:n_frame run_simulation!(state, param, t_gap, rng) heatmap(x_range, y_range, transpose(state.s), size=(600,600), c=cgrad(:inferno), clim=(-1.2,1.2), aspectratio=1, xlabel="x", ylabel="y") end name = "Rec11_Ising.gif" gif(anim, name, fps=in_fps) end