Thermo ising.py

From Werner KRAUTH

(Difference between revisions)
Jump to: navigation, search
Revision as of 21:39, 22 September 2015
Werner (Talk | contribs)

← Previous diff
Current revision
Werner (Talk | contribs)

Line 1: Line 1:
-This page presents the program markov_disks_box.py, a Markov-chain algorithm for four disks in a square box of sides 1.+This page presents the program thermo_ising.py, an algorithm for computing thermodynamic properties of the Ising model from a given density of states.
__FORCETOC__ __FORCETOC__
Line 6: Line 6:
=Program= =Program=
- import random 
-  
- L = [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]] 
- sigma = 0.15 
- sigma_sq = sigma ** 2 
- delta = 0.1 
- n_steps = 1000 
- for steps in range(n_steps): 
- a = random.choice(L) 
- b = [a[0] + random.uniform(-delta, delta), a[1] + random.uniform(-delta, delta)] 
- min_dist = min((b[0] - c[0]) ** 2 + (b[1] - c[1]) ** 2 for c in L if c != a) 
- box_cond = min(b[0], b[1]) < sigma or max(b[0], b[1]) > 1.0 - sigma 
- if not (box_cond or min_dist < 4.0 * sigma ** 2): 
- a[:] = b 
- print L 
- 
-=Version= 
-See history for version information. 
- 
-[[Category:Python]] 
Line 57: Line 37:
cv = (E2_av - E_av ** 2) / N / T ** 2 cv = (E2_av - E_av ** 2) / N / T ** 2
print T, E_av / float(N), cv print T, E_av / float(N), cv
 +
 +=Version=
 +See history for version information.
 +
 +[[Category:Python]] [[Category:Honnef_2015]] [[Category:MOOC_SMAC]]

Current revision

This page presents the program thermo_ising.py, an algorithm for computing thermodynamic properties of the Ising model from a given density of states.


Contents

Description

Program

import math, os 

L = 6
N = L * L
filename = 'data_dos_L%i.txt' % L
if os.path.isfile(filename):
    dos = {}
    f = open(filename, 'r')
    for line in f:
        E, N_E = line.split()
        dos[int(E)] = int(N_E)
    f.close()
else:
   exit('input file missing')
list_T = [0.5 + 0.5 * i for i in range(10)]
for T in list_T:
    Z = 0.0
    E_av = 0.0
    M_av = 0.0
    E2_av = 0.0
    for E in dos.keys():
        weight = math.exp(- E / T) * dos[E]
        Z += weight
        E_av += weight * E
        E2_av += weight * E ** 2
    E2_av /= Z
    E_av /= Z
    cv = (E2_av - E_av ** 2) / N / T ** 2
    print T, E_av / float(N), cv

Version

See history for version information.

Personal tools