Problem Description
Molecules is a simulation of random
molecular motion. Several predefined setups illustrate
transfer of kinetic energy and Brownian motion.
Background & Techniques
This is one of the few programs here at DFF that I did not write.
Viewer Arne, a retired Science teacher and amateur Delphi programmer
thought it might interest me and he was right! It simulates
molecular motion for 5 predefined setups. Molecules are
defined with a mass and velocity which reflects their kinetic
energy. (Kinetic Energy = 1/2 m v2 ).
There is not much interaction with the program but it is kind of
fascinating to watch and could provide base code for further
projects.
The coding is straightforward - a TMolecule class defines the
mass, color, current position and current velocity of each molecule.
An array of these molecules is set in motion in the main processing loop
which calls three procedures: Move updates the molecule positions
for the next time increment; Reflect detects collisions with walls
and changes the sign of the velocity component (x or y) which caused
the collision; and Collisions, the most complex part of the
job, detects collisions between molecules and determines
their new velocities. I'll let you examine the code for
details.
A delay routine in the loop prevents molecule positions from
being updated more than 10000 times per second. Unless
you have a fast computer, excessive speed will probably not be a
problem - molecules on my 255mhz laptop move like they are really
cold!
Running/Exploring the Program
Suggestions for Further Explorations
 |
Perhaps a temperature control which would increase
or decrease molecule speeds to change the kinetic
energy. |
 |
Since our "system" does not gain or lose
heat, the total kinetic energy should remain constant. That is
to say, the total kinetic energy of the system (the sum of the
kinetic energies of all the molecules) should remain
constant. I wonder if it does. |
 |
As a coding exercise, it would be interesting to see
if the processing power required to move the molecules could be
reduced - perhaps making TMolecule a Tshape
descendant so that images are maintained as bitmaps
rather than being redrawn each time. |
| Original Date: January 4,
2003 |
Modified: September 08, 2006
|
|