Py Con Presentation
Py Con Presentation
Computational Physics
Course
Richard P. Olenick
David Case
Eric Pepin
William Spearman
Outline
• Physical Modeling Demos with VPython
– How Does a Slider Differ from a Fastball?
– Boids
– Stability of L44 and L55 Lagrange Points
– How Lightning Forms
• Background and Mathematical Tools
– Euler Methods, Runge-Kutta, Poincare Maps
• Advantages of VPython
• Demos of Students’ Semester Projects
– 3D Dynamic Lattice
– Gravitational Shaping by Galactic Encounters
– Sand Avalanches
– Percolation Growth of Galaxies
– Non-relativistic Electron Scattering
Elements of the
Computational Physics
• Emphasizes the Course
modeling of physical
systems.
• Lectures are kept to a
minimum and students
work on programs
during classes.
• Instructor provides in-
class debugging.
• Students have different
initial conditions to run
and their results are
shown to the entire
class and discussed.
Magnus Effect and Baseball
Pitches
body2pos=rotate(body2pos, angle=omega*t,axis=[0,0,1])
body1pos=vector(-mu, 0,0)
body1pos=rotate(body1pos, angle=omega*t,axis=[0,0,1])
object.pos=objectpos
body2.pos=body2pos
body1.pos=body1pos
object.trail.append(pos=object.pos)
How Lightning Forms—Fractal
Growth Processes
• Diffusion-limited
growth is simulated.
• Box method used to
calculate the fractal
dimension.
• The effects of growth
time and fractal
dimension can be
studied.
def walk ():
Checks to see if particle became attached from the movement of another
particle,
If not, moves the particles,
Checks for attachment
Only checks if particle is within the radius of the existing structure
def move(point):
Move the particle randomly,
The grid is cyclic - going off one side puts it on the other
def check(point):
Checks to see if the particle is touching any particle in the aggregate
• Euler Methods
yn yn 1 f tn 1 t
• Improved Euler
f tn f tn t
y tn t y tn h
2
•Runge-Kutta 4th order
k1 f tn , yn t
Dt k
k 2 = f(tn + , y n + 1 )D t,
2 2
Dt k2
k3 = f(t n + , y n + ) D t,
2 2
k 4 = f(tn + D t , y n + k 3 ) D t,
5
y n + 1 = y n + 61 ( k 1 + 2 k 2 + 2 k 3 + k 4 ) + O[( D t ) ].
Poincare Maps
•Choose any three from x, y, vx, and vy and calculate the
fourth using the integral of the system, such as x, y, and vy.
•Follow a solution in the three-dimensional space of these
three coordinates. If the surface is the plane x = 0, then we
are looking at points that cross in the y-vy plane.
• Now let a solution cross this plane at the point P, where x is
increasing or vx > 0. The next crossing occurs at Q, where vx
< 0. The next cross occurs when x is increasing, at R.
Poincaré map for the
Hénon-Heiles problem
with E = 0.1053,
x(0)=0.4, y(0) = 0,
vx(0) = 0, vy(0) = 0.225
x2 y 2 1 y3
E k x y x y
2 2 2
2 2m 2 3
d 2x
x 2 xy
dt 2
d2y 2 2
y x y
dt 2
As a galaxy
encounters
another galaxy
(represented as
a point mass),
the orbits of
individual stars
are perturbed.
Avalanches—An Example of
Self-Organized Criticality
Avalanches
occur when a
critical threshold
is exceeded.
def fall(x,y,D):
global grid, sand
grid[x+D%3-1][y+1-D/3][0]+=1 #adds one to
receiving square
s=grid[x][y][1].pop() #index of sand
being moved
grid[x+D%3-1][y+1-D/3][1].append(s) #adds
index to receiving square
grid[x][y][0]-=1 # removes one from
falling square
sand[s].pos=(x+D%3-1,y+1-D/3,grid[x+D%3-
1][y+1-D/3][0]) # relocates sand
Percolation Growth of
Galaxies
In this percolation
model of galaxies,
long range spiral
structure is achieved
through local
interactions.
def growth():
Each inhabited sector has a p chance of
giving birth to a new star, in which case it
is destroyed
def rotate():
Rotates each sector according to the
angular velocity
def spiral():
Determines if stars are born or have died
in each sector, updates image to reflect
current population and position
3D Dynamic Lattice
A 3D lattice of
particle connected
by springs allows
for an investigation
of normal modes.
# sum the forces acting on the
# current particle
Forces = (Force(i,j,k,k,j,idim)
+Force(i,j,k,k,j,iaug)
+Force(i,j,k,k,jdim,i)
+Force(i,j,k,k,jaug,i)
+Force(i,j,k,kdim,j,i)
+Force(i,j,k,kaug,j,i))
Forces += -(mass[k][j][i].velocity*b)
if dropping:
# add gravity and handle collisions
Forces += m*g*vector(0,1,0)
if mass[k][j][i].pos.y < floor:
if mass[k][j][i].velocity.y < 0:
mass[k][j][i].velocity.y = -mass[k][j][i].velocity.y
if mass[k][j][i].fixed:
# do no move if particle is fixed in place
Forces = vector(0,0,0)
mass[k][j][i].velocity = vector(0,0,0)
cur_Forces = Forces
# set variables for passing to rkf4
var[0]=mass[k][j][i].pos
var[1]=mass[k][j][i].velocity
# use RKF4 to evaluate differential equation
Non-relativistic Electron
Scattering
This project
involves a Monte
Carlo simulation
of non-relativistic
electron scattering
in a thin film. The
backscattering,
transmission, and
absorption can be
studied for various
metals.
# calcluate new positions for particles
for n in range(0, maxn):
c1.interact()
theta.append(0) # add the n+1 element
phi.append(0) # add the n+1 element
s.append(0) # initialize position element to 0
T.append(0)
R.append(vector(0,0,0))
Rtheta = random()
Rphi = random()
Rs = random()
p_costheta = 1-(2*beta*Rtheta / (1+beta-Rtheta))
p_theta = acos(1-(2*beta*Rtheta / (1+beta-Rtheta)))
#p_theta = 1 - p_theta
p_phi = 2*pi*Rphi
costhetanew = cos(theta[n])*cos(p_theta)+sin(theta[n])*sin(p_theta)*cos(p_phi)
theta[n+1] = acos(costhetanew)
top = ( sin(theta[n])*sin(p_theta)*sin(p_phi) )
bottom = ( cos(p_theta)-(costhetanew)*cos(theta[n]))
if bottom == 0:
bottom = 1
top = sin(p_theta)*sin(p_phi)
phi[n+1] = atan( top / bottom ) + phi[n]
s[n] = (-1.02*beta*(beta+1)*A*(T[n])**2 / (Z*(Z+1)*rho)) * log(Rs)
T[n+1] = T[n] - abs(dTds(T[n]))*s[n]
R[n+1] = R[n] + s[n]*(sin(theta[n+1])*cos(phi[n+1]) *vector(1,0,0)
+ sin(theta[n+1])*sin(phi[n+1])*vector(0,1,0)
+ cos(theta[n+1])*vector(0,0,1))
Follow-Up