HomePart 3: Animation of a mass-spring system

Part 3: Animation of a mass-spring system

Running FORTRAN programs using modules in Ubuntu:

gfortran -o file.exe usedmodule1.o usedmodule2.o program.f90
./file.exe

A damped mass-spring system

Let us consider a simple case of a mass and a spring. There is a spring attached to the wall and a mass. The equilibrium position is at x=0. The spring has been stretched to x=1 and released. We can ignore gravity, friction, and other forces. However, there is a velocity dependent damping force.

By Hooke’s Law, we know:

F = -kx

Let’s say the damping force is:

G = γv, against the motion

Thus we have the equation of motion. For integrating, I will be using the leapfrog algorithm. There are multiple algorithms available for the purpose, so feel free to choose whichever you want. For details on such algorithms, click here.

I have used a dummy point outside the range of the graph window to generate a straight line which represents the spring. If you’re a perfectionist, you may use a triangular wave equation with varying periods to generate a proper compressing and stretching spring. The maximum number of frames is 10,000, but you may not want all of them, so there’s an option to skip frames (to make the animation faster and shorter).

The actual time of animation will be set by ti and tf, but the perceived time will depend on the number of frames generated (since the video will be made at a specific frames/second). So let’s say you chose to keep 5000 frames (by setting frame skip to 2), you’ll get an animation of around 3 mins at 24fps. Now within that length, you’ll see whatever happens between ti and tf. So a large difference between ti and tf would mean a faster animation.

The “call system” function allows us to type stuff into the terminal from within the program itself. All the data files are being stored in a folder called ‘data’, and their respective plots are being stored in a folder called ‘frames’. These plots are being combined to form the video, and the two folders are being deleted.

In case of any problems regarding the program, leave a comment.

Download links: writing.f90  plotting.f90  mass_spring.f90

<<Part 2|Part 4>>

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s