This project is worth of the total grade for the course. The deadline for submitting the completed project is
~p373/public_html/assign/projectthere are the following files: The file molecular_dynamics.C intializes a typical molecular dynamics run. The program uses three classes:
When the project is completed, the program can be compiled and run using
g++ molecular_dynamics.C nr_gasdev.C a.out < inputThe output from the student's program should agree with the file output .
The program molecular_dynamics.C should not be modified.
The solution is now available.
This file contains the particle class. This stores the coordinates and velocities of a given number of particles. This class calculates the kinetic energy of the particles, however it does not calculate the potential energy. We suggest the particle's position and velocities are stored as
float mass ;
#define MAX_PARTICLES 5
float x[MAX_PARTICLES ] ,y[MAX_PARTICLES ] ,z[MAX_PARTICLES ] ;
float vx[MAX_PARTICLES ] , vy[MAX_PARTICLES ] , vz[MAX_PARTICLES ] ;
The above data structures are not a very flexible way of storing the
particle coordinates. However it makes the class implementation
simple.
Here is the list of the required methods (class functions)
vx[i] = gasdev(seed) ;
vy[i] = gasdev(seed) ;
vz[i] = gasdev(seed) ;
This class inherits the particle class. It provides a specific implementation of the potential energy. These particle interact via a Lenoard-Jones potential.
V(r_ij) = epsilon * ( (sigma/r_ij) **12 - (sigma/r_ij) **6 )Where r_ij is the distance between particle i and particle j.
This class only has sigma and epsilon as internal data. The constructor, called particle_argon, takes three arguments: the mass, the value of sigma, and the value of epsilon
The second class method is called calc_potential_energy() This function loops over all the particles and calculates the total potential energy between the particles. The interaction of a particle with itself is ignored. The result is printed to the screen.
The solution is now available.
This class inherits the particle class. It provides a specific implementation of the potential energy. These particle interact via a box like potential.
V(r_ij) = -V0 if r_ij < r_0
= 0 r_ij >= r_0
Where r_ij is the distance between particle i and particle j.
This class only has r0 and v0 as internal data. The constructor, called particle_hardcore, takes three arguments: the mass, the value of r0, and the value of v0.
The second class method is called calc_potential_energy() This function loops over all the particles and calculates the total potential energy between the particles. The interaction of a particle with itself is ignored. The result is printed to the screen.
This class is very similar to the particle_argon class.
The C++ FAQ answers the question: what is a class? There is also a nice discussion about classes in the tutorial by tlardaro.
There is a page that shows how the molecular dynamics program is similar to a vector class program. I recommend that the students work through this example.
I have made some notes on inheritance and virtual functions Students should read this document. Students can also look at the examples I showed the class on using virtual functions.
The example of a vector class may be profitably be consulted.