Minimal Simulation
The following tutorial pertains to a single component Lennard-Jones, NVE molecular dynamics simulation.
- Verified 10-4-07; code revision 390
- Created 5-8-07; code revision 173
Linking to the simulation builder library/header
First we must include the Simulation Builder header file:
#include <glotzilla++.h>
This tells the compiler about all of the pre-defined Glotzilla classes. We will now be able to access the MdSimulation class within the Simulation Builder library and can create an instance of it:
#include <glotzilla++.h> int main(int argc, char ** argv) { MdSimulation my_simulation; return 0; }
Setting up the simulation
Now that we have declared an instance of the MdSimulation called my_simulation, we can now set up the simulation. An MD simulation needs a few aspects of it defined in order to work:
- particles - objects that exist in the simulation
- interactions - defines how particles interact
- force routine - calculates force particles exert on one another
- boundary conditions - the space accessable to the particles
- integration routine - defines how the equations of motion are integrated
In the following code excerpt, we will:
- add 2 particles at <0,0,0> and <1,1,1>
- set the interaction between particles to Lennard-Jones
- set the code to use a brute force routine for calculating pair interactions
- set the boundaries of the box to be periodic where Lx = Ly = Lz = 10
- set the integration routine to VelocityVerletIntegrator
#include <glotzilla++.h> int main(int argc, char ** argv) { MdSimulation my_simulation; my_simulation.AddParticle(new MdPointParticle(0,0,0)); my_simulation.AddParticle(new MdPointParticle(1,1,1)); my_simulation.SetInteraction(new LennardJones); my_simulation.SetForceRoutine(new BruteForce); my_simulation.SetBoundaryConditions(new PeriodicBoundary(10)); my_simulation.SetIntegrationRoutine(new VelocityVerletIntegrator); return 0; }
Integrating the equations of motion
To advance the simulation through time, i.e. integrate the equations of motion, we need only use the "++" operator declared in MdSimulation. The following excerpt of code will advance the simulation through 10000 timesteps and then exit.
#include <glotzilla++.h> int main(int argc, char ** argv) { MdSimulation my_simulation; my_simulation.AddParticle(new MdPointParticle(0,0,0)); my_simulation.AddParticle(new MdPointParticle(1,1,1)); my_simulation.SetInteraction(new LennardJones); my_simulation.SetForceRoutine(new BruteForce); my_simulation.SetBoundaryConditions(new PeriodicBoundary(10)); my_simulation.SetIntegrationRoutine(new VelocityVerletIntegrator); for(int i=0; i<10000; i++) my_simulation ++; return 0; }
Getting information from the simulation
The MdSimulation class provides a variety of methods to query the simulation.
- Temperature
- Pressure
- Potential Energy
- Kinetic Energy
- Virial
- Positions
- Velocities
- Forces
- Visualization data
Temperature
The following code excerpt will print temperature to the screen (std::cout) every 5 timesteps.
for(int i=0; i<10000; i++) { my_simulation ++; if(i%5 == 0) my_simulation.PrintTemperature(std::cout); }
Visualization
The following code excerpt will print visualization data to a pipe for the "vis3d" application every 5 timesteps. The topic of pipes will be covered in depth in the the pipes tutorial?.
opstream vis_pipe("vis3d"); for(int timesteps=0; timesteps<10000; timesteps++) { my_simulation ++; if(timesteps%5 == 0) my_simulation.PrintVisual(vis_pipe); }
Compiling the code
To compile the code you will need to use the "glotzcc" command. The glotzcc command calls the mpic++ compiler and gives it the appropriate library and header search paths. Within your shell, execute the following command:
glotzcc MDMinimalSimulation.cpp
where MDMinimalSimulation.cpp is the name of the file where the code resides.
Problems
Refer to the FAQ? page.
Attachments
-
MDMinimalSimulation.cpp
(0.6 kB) - added by cri
20 months ago.
Minimal NVE Lennard-Jones Simulation