Skip to content

Commit

Permalink
fixed major speed bug (abstract cubiclattice)
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenbauer committed Jan 2, 2018
1 parent b1c2f0d commit c8449b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 8 additions & 0 deletions example/Ising2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,23 @@ for g in grps
fig, ax = subplots(2,2, figsize=(12,8))
ax[1][:plot](g[:T], g[:E], "o", color="darkred", markeredgecolor="black")
ax[1][:set_ylabel]("Energy")
ax[1][:set_xlabel]("Temperature")

ax[2][:plot](g[:T], g[:C_V], "o", color="darkred", markeredgecolor="black")
ax[2][:set_ylabel]("Specific heat")
ax[2][:set_xlabel]("Temperature")

ax[3][:plot](g[:T], g[:M], "o", color="C0", markeredgecolor="black")
ax[3][:axvline](x=MonteCarlo.IsingTc, color="black", linewidth=2.0, label="\$ T_c \$")
# ax[3][:legend](loc="best")
ax[3][:set_ylabel]("Magnetization")
ax[3][:set_xlabel]("Temperature")

ax[4][:plot](g[:T], g[], "o", color="C0", markeredgecolor="black")
ax[4][:axvline](x=MonteCarlo.IsingTc, color="black", linewidth=2.0, label="\$ T_c \$")
# ax[4][:legend](loc="best")
ax[4][:set_ylabel]("Susceptibility χ")
ax[4][:set_xlabel]("Temperature")
tight_layout()
savefig("ising2d_L_$(L).pdf")
end
Expand All @@ -79,15 +83,19 @@ for g in grps
end
ax[1][:legend](loc="best")
ax[1][:set_ylabel]("Energy")
ax[1][:set_xlabel]("Temperature")

ax[2][:legend](loc="best")
ax[2][:set_ylabel]("Specific heat")
ax[2][:set_xlabel]("Temperature")

ax[3][:legend](loc="best")
ax[3][:set_ylabel]("Magnetization")
ax[3][:set_xlabel]("Temperature")
ax[3][:axvline](x=MonteCarlo.IsingTc, linewidth=2.0, color="black", label="\$ T_c \$")

ax[4][:set_ylabel]("Susceptibility χ")
ax[4][:set_xlabel]("Temperature")
ax[4][:axvline](x=MonteCarlo.IsingTc, linewidth=2.0, color="black", label="\$ T_c \$")
ax[4][:legend](loc="best")
tight_layout()
Expand Down
8 changes: 4 additions & 4 deletions src/flavors/MC/mc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ function run!(mc::MC{<:Model, S}; verbose::Bool=true, sweeps::Int=mc.p.sweeps, t

(i > mc.p.thermalization) && measure_observables!(mc.model, mc.obs, mc.conf, mc.energy)

if mod(i, 100) == 0
mc.a.acc_rate = mc.a.acc_rate / 100
mc.a.acc_rate_global = mc.a.acc_rate_global / (100 / mc.p.global_rate)
if mod(i, 1000) == 0
mc.a.acc_rate = mc.a.acc_rate / 1000
mc.a.acc_rate_global = mc.a.acc_rate_global / (1000 / mc.p.global_rate)
add!(sweep_dur, toq()/1000)
if verbose
println("\t", i)
add!(sweep_dur, toq()/100)
@printf("\t\tsweep dur: %.3fs\n", sweep_dur[end])
@printf("\t\tacc rate (local) : %.1f%%\n", mc.a.acc_rate*100)
if mc.p.global_moves
Expand Down
18 changes: 9 additions & 9 deletions src/models/Ising/IsingModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mutable struct IsingModel <: Model
L::Int
dims::Int
β::Float64
l::CubicLattice
l::SquareLattice # TODO: parametrize on lattice to allow general cubiclattice
end

"""
Expand Down Expand Up @@ -134,17 +134,17 @@ See also [measure_observables!](@ref) and [finish_observables!](@ref).
"""
function prepare_observables(m::IsingModel)
obs = Dict{String,Observable}()
obs["E"] = Observable(Float64, "Total energy")
obs["E2"] = Observable(Float64, "Total energy squared")
obs["e"] = Observable(Float64, "Energy (per site)")
obs["E"] = Observable(Float64, "Total energy", alloc=50000)
obs["E2"] = Observable(Float64, "Total energy squared", alloc=50000)
obs["e"] = Observable(Float64, "Energy (per site)", alloc=50000)

obs["M"] = Observable(Float64, "Total magnetization")
obs["M2"] = Observable(Float64, "Total magnetization squared")
obs["m"] = Observable(Float64, "Magnetization (per site)")
obs["M"] = Observable(Float64, "Total magnetization", alloc=50000)
obs["M2"] = Observable(Float64, "Total magnetization squared", alloc=50000)
obs["m"] = Observable(Float64, "Magnetization (per site)", alloc=50000)

obs["χ"] = Observable(Float64, "Susceptibility")
obs["χ"] = Observable(Float64, "Susceptibility", alloc=50000)

obs["C"] = Observable(Float64, "Specific Heat")
obs["C"] = Observable(Float64, "Specific Heat", alloc=50000)

return obs
end
Expand Down

0 comments on commit c8449b1

Please sign in to comment.