#Final Programming Project, 12/17/01

from visual import *

#Atom class - contains characteristics of each atoms.
#Note methods replace direct attribute references- this allows changes
#to the an Atom object to not only affect the numerical attributes
#but also the sphereical representation of the atom.
#
#If mehtods called without parameters, returns values.
#Otherwise, changes values of attributes and sphere object.

#Boltzman's constant (joules/K)

k=1.38e-23

class Atom:  
    def radius(self, r=''):
        try:
            test=r+1
        except:
            return self.r
        
        self.r=r
        self.ball.radius=r

    def momentum(self, m=''):
        try:
            test=m+1
        except:
            return self.m
        
        self.m=m
#        self.ball.color.red=colormom(m

    def position(self, p=''):
        try:
            test=p+1
        except:
            return self.p

        self.p=p
        self.ball.position=p

    def __init__(self, pos, momentum, mass, radius):
        self.p=pos
        self.m=momentum
        self.r=radius
        self.mass=mass
        self.ball=sphere(pos=pos, radius=radius, color=(1,0,0))
        #print self.ball.position #debugging point

#Get user input

print "Heat Transfer in a Gas"
print "-/-\--/--\--/--\--/-\-"
print
maxt=input("Enter the tempreture of heated gas(K):")
ratio=input("Ratio of height to length of face of square side of container:")

#Try block allows default value to be set for mint.

try:
    T=input("Enter the tempreture of rest of gas(K) (entering nothing for default value of 300K):")
except SyntaxError:
    T=300

#Try block allows default value to be set for Natoms

try:
    Natoms=input("Enter density of atoms(/m^3) (enter nothing for default value of 100/m^3):")
except SyntaxError:
    Datoms=100

#Container is a long rectangular prism with two of the sides as squares.
#User enters ratio of h to L
V=2.

L=(V/ratio)**(1./3.)

h=L*ratio
print V,ratio,L,h
#print L*L*h
 # height of container
white = (1,1,1) # color of edges of container
Raxes = 0.005 # radius of lines drawn on edges of cube
Matom = 4E-3/6E23 # helium mass
Ratom = 3e-2 # wildly exaggerated size of helium atom
k = 1.4E-23 # Boltzmann constant
dt = 1E-5
Natoms=Datoms*h*L*L#Number of atoms in container

#Scales the visual display

win=500
scene = display(title="Gas", width=win, height=win, x=0, y=0,
                range=h, center=(L/2.,h/2.,L/2.))

#Makes visual display of box

xaxis = curve(pos=[(0,0,0), (L,0,0)], color=white, radius=Raxes)
yaxis = curve(pos=[(0,0,0), (0,h,0)], color=white, radius=Raxes)
zaxis = curve(pos=[(0,0,0), (0,0,L)], color=white, radius=Raxes)
xaxis2 = curve(pos=[(L,h,L), (0,h,L), (0,0,L), (L,0,L)], color=white, radius=Raxes)
yaxis2 = curve(pos=[(L,h,L), (L,0,L), (L,0,0), (L,h,0)], color=white, radius=Raxes)
zaxis2 = curve(pos=[(L,h,L), (L,h,0), (0,h,0), (0,h,L)], color=white, radius=Raxes)
#atomlist contains instances of Atom class objects

atomlist=[]

#randomly places atoms within constraint that the atoms is no closer to
#any wall than 1.1 of the atoms' radii

for i in range(Natoms):
    dmin = 1.1*Ratom
    Lmax = L-dmin
    hmax = h-dmin
    x = dmin+Lmax*random()
    y = dmin+hmax*random()
    z = dmin+Lmax*random()
    atomlist.append(Atom(vector(x,y,z), vector(0,0,0), Matom, Ratom))
    momavg= sqrt(2.*atomlist[-1].mass*1.5*k*T)
#print len(atomlist)
#for i in range(Natoms):
#    print atomlist[i].ball.position
#    print atomlist[-1].position() #debugging point
