CodeCodeCode

PHYS 172: Entropy & Temperature

Apr 22nd, 2011
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.44 KB | None | 0 0
  1. from __future__ import division
  2. from visual.factorial import *
  3. from visual.graph import *
  4.  
  5. ## Setting up Graphing Windows
  6. #Ways graph
  7. gdisplay(xtitle='q1',ytitle='Ways', x=500, y=0, width=600,height=300)
  8. waygraph = gvbars(delta=0.7, color=color.red) # to make vertical bar graph
  9.  
  10. #entropy graphs
  11. gdisplay(xtitle='q1',ytitle='Entropy', x=500, y=300, width=600,height=300)
  12. S1graph = gcurve(color=color.red)
  13. S2graph = gcurve(color=color.blue)
  14. S1S2graph = gcurve(color=color.green)
  15.  
  16. #temperature graphs
  17. gdisplay(xtitle='q1',ytitle='Temp.', x=500, y=600, width=600,height=300)
  18. T1graph = gcurve(color=color.red)
  19. T2graph = gcurve(color=color.blue)
  20.  
  21. ## Constants
  22.  
  23. hbar= 1e-34     # Planck's constant divided by 2pi
  24. k=1.38e-23      # Boltzmann's constant
  25. mAL= 27*1.7e-27  # Mass of Al (27 nucleons)
  26. kAL= 16         # Interatomic spring constant for Aluminum
  27.  
  28. ## Initial Conditions
  29. Ntotal = 500 # total number of oscillators
  30. N1 = 300 # number of oscillators in object 1
  31. N2 = Ntotal-N1 # number of oscillators in object 2
  32. qtotal = 100 # total quanta of energy shared among all the oscillators
  33.  
  34. q1 = 0 # start with no quanta of energy in object 1
  35.  
  36. while q1 <= qtotal: # for each possible value of energy in object 1
  37.     q2 = qtotal - q1 # number of quanta of energy in object 2
  38.    
  39.     # Calculate number of ways to arrange q1 quanta in object 1:
  40.     ways1 = combin(q1+N1-1, q1)
  41.     # Calculate number of ways to arrange q2 quanta in object 2:
  42.     ways2 = combin(q2+N2-1, q2)
  43.     Tways = ways1*ways2
  44.     # Plot number of ways to arrange energy in the two objects:
  45.     waygraph.plot( pos=(q1, Tways) )
  46.     #print 'ways: ',  Tways
  47.  
  48.  
  49.     S1 = k*log(ways1) #entropy in block 1
  50.     S2 = k*log(ways2) #entropy in block 2
  51.     q1t = q1 + 1
  52.     q2t = q2 + 1
  53.  
  54.     S1t = k * log(combin(q1t+N1-1, q1t)) #enropy in block 1 with q1t quanta of energy in block 1
  55.     S2t = k * log(combin(q2t+N2-1, q2t)) #enropy in block 2 with q1t quanta of energy in block 2
  56.  
  57.     deltaE = hbar * sqrt((4*kAL) / mAL)
  58.     deltaS1 = S1t - S1
  59.     deltaS2 = S2t - S2
  60.  
  61.     # Temperatures of each block.
  62.     T1 = deltaE / deltaS1
  63.     T2 = deltaE / deltaS2
  64.    
  65.     # Plot Entropies
  66.     S1graph.plot( pos=(q1,log(ways1)) ) # log of ways1
  67.     S2graph.plot( pos=(q1,log(ways2)) ) # log of ways2
  68.     S1S2graph.plot( pos=(q1,log(ways1*ways2)) ) # log of ways1*ways2
  69.  
  70.     # Plot Temperatures
  71.     T1graph.plot( pos=(q1,T1) )
  72.     T2graph.plot( pos=(q1,T2) )
  73.  
  74.     q1 = q1+1
Advertisement
Add Comment
Please, Sign In to add comment