Class myphysicslab.sims.springs.Molecule3Sim
Provided By  

Extends  
All Implemented Interfaces 
Simulation of a 'molecule' made of 2 to 6 masses with springs between, moving freely in 2D, and bouncing against the four walls. A small subset of the springs and masses are designated as 'special' so that their parameters (mass, spring stiffness, spring rest length) can be set separately from the others.
This uses the same physics as myphysicslab.sims.springs.Molecule1Sim
but allows for
more springs and masses.
Variables and Parameters
Here is a diagram of two masses showing the definition of the angle th
:
m2 .
\ .
\ th .
\ .
\ .
\ .
m1
Variables:
U1, U2 = position of center of mass of atom 1 or 2
V1, V2 = velocity of atom 1 or 2
th = angle with vertical (radians); 0 = up; positive is counter clockwise
L = displacement of spring from rest length
F1, F2 = force on atom
Parameters:
m1, m2 = masses of atom 1 and 2
R = rest length of spring
k = spring constant
b = damping constant
Equations of Motion
For each pair of masses, they experience the following forces from the spring connecting them (but the damping force occurs only once for each mass).
F1x = k L sin(th) b V1x = m1 V1x'
F1y = m1 g +k L cos(th) b V1y = m1 V1y'
F2x = k L sin(th) b V2x = m2 V2x'
F2y = m2 g k L cos(th) b V2y = m2 V2y'
xx = U2x  U1x
yy = U2y  U1y
len = sqrt(xx^2+yy^2)
L = len  R
cos(th) = yy / len
sin(th) = xx / len
Variables Array
The variables are stored in the VarsList as follows. Each atom has four variables,
so the i
th atom has variables for position and velocity:
var[4*i + 0] = Ux
var[4*i + 1] = Uy
var[4*i + 2] = Vx
var[4*i + 3] = Vy
At the end of the VarsList are variables for time and energy. If there are n
atoms
these will be at:
var[4*n + 0] = time
var[4*n + 1] = KE kinetic energy
var[4*n + 2] = PE potential energy
var[4*n + 3] = TE total energy
Contact Force
We detect when an atom is in resting contact with floor or wall. Consider contact with the floor. Suppose the atom is 'close' to the floor, then there are 3 cases:

vertical velocity is 'large' and positive. Then the atom is separating from the floor, so nothing needs to be done.

vertical velocity is 'large' and negative. A collision is imminent, so let the collision software handle this case.

vertical velocity is 'small'. Now the atom is likely in contact with the floor. There are two cases:
a. Net force positive: atom is being pulled off floor. In this case do nothing, there is no reaction force from the floor.
b. Net force negative: atom is being pulled downwards. Here, we set the net force to zero, because the force is resisted by the reaction force from the floor.
How small is 'small' velocity?
We are trying to avoid the case where there is a tiny upwards velocity and a large downwards force, which just results in zillions of collisions over the time step we are solving (typically about 0.03 seconds). Instead, we assume that the atom stops bouncing and comes into contact with the floor in this case.
For a given force (assuming it stays approx constant over the time span of 0.03 seconds), there is an 'escape velocity' that would allow the atom to leave contact and be above the floor at the end of the time step.
Let
h = time step
F = force
m = mass
v0 = initial vertical velocity
Then we have (using simple calculus; 2 integrations)
v' = F/m
v = (F/m)t + v0
y = (F/2m)t^2 + v0*t
Requiring the atom to be below the floor at time h gives the condition
0 > y = (F/2m)h^2 + v0*h
Dividing by h gives
0 > F*h/2m + v0
F*h/2m > v0
For the case of interest, we have that F
is a large downward force, so F << 0
.
If the initial velocity v0
is less than F*h/2m
then (assuming constant F over
the timespan h
) the atom starting at the floor will still be on or below
the floor at the end of the timespan h
.
This is our definition of a small velocity. Note that it depends on the net force. Because with a large downward force, it would take a big velocity to actually result in contact being lost at the end of the time period. Equivalently, if there is just a slight downward force (e.g. spring almost offsetting gravity), then just a little velocity is enough to result in contact being broken.
new Molecule3Sim( nm, opt_name )
Parameters 

