Docsity

Python Practice and an Introduction to Waves - Lab 4 | PHY 300, Lab Reports of Physics

Toggle sidebar
bg1
Lab 4 - Python practice and an introduction
to Waves
Thursday 8 February - Due: Thursday 15 February
In this lab we will practice our Python programming and go on to explore a
simple model for a 1D elastic solid and try to understand some of the properties
of the waves that propagate in such a medium
1 Python practice
Open up an IDLE file window.
1. Write some Python code to create an empty list called mylist
2. This list will contain a set of sphere objects which are to be placed on the vertices of a
3D lattice with lattice spacing a. There should be Lpoints on each side of this lattice
extending from coordinate 0to La. Define Land aat the top of your code. Also you
will need to import the visual module of course.
3. Use 3 nested for loops to assign the coordinates of these lattice points to the position
vectors pos of the spheres. Look back at last week’s lab for hints on how to do this.
4. Make the radius of the spheres be 0.25*a.
5. Write a simple while loop to update the system. In this toy program just imagine
that the position of each sphere is changed randomly at each time step in the range
-0.1*a to 0.1*a. You will need the random module. Look back at your old labs to see
how to use the random() function. Use a for loop of the simple form
for i in range(0,L*L*L):
to loop over all spheres on the lattice.
6. Include a snap shot of your running program in addition to the final program code.
7. How would I modify the code to cope with differing lattice spacings ax,ay and az in
the different coordinate directions.
2 Elastic solids - simulation
Download the codes wave.py and integrate.py from the PHY300 webpage. These contain
most of the code you need to simulate wave motion in a 1d elastic medium. They correspond
to a simple modification of our molecular dynamics program in which the motion is restricted
to 1D, the forces are harmonic and only nearest neighbors on the lattice interact. We also
set the initial conditions to a pulse at the lefthand end of the lattice by displacing the first
two masses a little from their equilibrium positions.
pf2

Partial preview of the text

Download Python Practice and an Introduction to Waves - Lab 4 | PHY 300 and more Lab Reports Physics in PDF only on Docsity!

Lab 4 - Python practice and an introduction

to Waves

Thursday 8 February - Due: Thursday 15 February

In this lab we will practice our Python programming and go on to explore a simple model for a 1D elastic solid and try to understand some of the properties of the waves that propagate in such a medium

1 Python practice

Open up an IDLE file window.

  1. Write some Python code to create an empty list called mylist
  2. This list will contain a set of sphere objects which are to be placed on the vertices of a 3D lattice with lattice spacing a. There should be L points on each side of this lattice extending from coordinate 0 to La. Define L and a at the top of your code. Also you will need to import the visual module of course.
  3. Use 3 nested for loops to assign the coordinates of these lattice points to the position vectors pos of the spheres. Look back at last week’s lab for hints on how to do this.
  4. Make the radius of the spheres be 0.25*a.
  5. Write a simple while loop to update the system. In this toy program just imagine that the position of each sphere is changed randomly at each time step in the range -0.1a to 0.1a. You will need the random module. Look back at your old labs to see how to use the random() function. Use a for loop of the simple form

for i in range(0,LLL):

to loop over all spheres on the lattice.

  1. Include a snap shot of your running program in addition to the final program code.
  2. How would I modify the code to cope with differing lattice spacings ax, ay and az in the different coordinate directions.

2 Elastic solids - simulation

Download the codes wave.py and integrate.py from the PHY300 webpage. These contain most of the code you need to simulate wave motion in a 1d elastic medium. They correspond to a simple modification of our molecular dynamics program in which the motion is restricted to 1D, the forces are harmonic and only nearest neighbors on the lattice interact. We also set the initial conditions to a pulse at the lefthand end of the lattice by displacing the first two masses a little from their equilibrium positions.

  1. Load wave.py into IDLE. We first need to stipulate the boundary conditions. We will assume the first and last mass are constrained to remain fixed throughout. The first mass corresponds to chain[0]. What is the name of the last mass? The code under the comment marked leapfrog contains the update. Modify the limits of the range() function in each of these subsequent for loops so that masses at the end of the chain are never updated.
  2. Next load integrate.py. This computes the force on any mass. The line

xn=objlist[a+1].pos-(a+1)*vspacing

calculates the displacement of the mass a+1 from its equilibrium lattice position, The subsequent line computes the resultant elastic force due the relative displacement of the mass at a from the one at position a+1. Write two similar lines of code to handle the additional elastic force on a from site a-1. Save the new integrate.py.

  1. Run the code and capture a screen shot of the resultant motion. You should see a wave pulse which initially travels to the right (the additional graphical display shows the displacement from equilibrium of each mass as a function of time.

3 Wave velocity

  1. We would like to investigate how fast these waves travel as a function of the strength of the elastic forces between masses. To do this we need to measure the first time at which the mass given by chain[N-1] has a non-zero displacement from its equilibrium posi- tion. Add the following line of code after the comment # insert code to flag ..

if(fabs(chain[N-1].pos.x-(N-1)*spacing>0.0001)): print "time to end is " , t

  1. The only problem with this is that it will write out the first time this mass moves and all subsequent times. Suggest how to modify this so that the print is only executed once.
  2. Now run the code and measure this time of travel of the pulse for a variety of spring constants k (as defined in integrate.py) in the range 0. 1 , 2 .0. Since the waves prop- agate over a fixed distance this time of travel is inversely proportional to the wave velocity. Plot the wave velocity against the square root of the spring constant k using Excel for example. What do you see?
  3. Repeat this experiment keeping k fixed at say unity and varying the magnitude of the mass (as set in wave.py). What is now the dependence of the wave velocity on mass?