Creating a simulation
The following code creates a MD simulation with two particles interacting via the 12-6 Lennard-Jones (LJ) potential.
Example Code
#include <iostream> //Use the iostream library #include <glotzmd.h> //Use the glotzmd libarary using namespace glotzmd; //Use the glotzmd namespace int main() { MdSimulation s; // 1. declare a new simulation s.SetForceRoutine(new BruteForce); // 2. set force routine s.SetBoundaryConditions(new PeriodicBoundary(15)); // 3. set a 15x15x15 periodic box s.AddInteraction(type::A, type::A, new LjPotential); // 4. use LJ for A-A interactions s.SetIntegrationScheme(new VelocityVerletIntegrator); // 5. use velocity verlet s.AddParticle(new PointParticle( 1, 0, 0)); // 6. Point particle at 1,0,0 s.AddParticle(new PointParticle( -1, 0, 0)); // 7. Point particle at -1,0,0 s.StepForward(1000); // 8. Do 1000 MD timesteps std::cout << s.ComputePotentialEnergy() << "\n"; // 9. Print the potential energy return 0; }
Some Notes
- Simulation is of type MdSimulation
- Carries out a molecular dynamics-like simulation (MD simulation, BD simulation, DPD simulation)
- The MdSimulation class acts as a container to hold the parts comprising an MD simulation
- Different parts communicate with each other via the MdSimulation class
- Force routine is of type Brute Force.
- Calculates the distance between all pairs of particles
- Simplest possible force routine
- Boundary conditions are of type PeriodicBoundary
- Box size is set to 5x5x5 in the constructor
- Applies periodic boundary conditions at the edge of the box
- Interactions between A-A particles are of type LjPotential
- Interacting types must be set to know which particles the potential applies to
- Implements the Lennard-Jones potential
- Default is the standard 12-6 form, although this can be altered
- Integration scheme is of type VelocityVerletIntegrator
- Integrates Newton's equations of motion
- Implements the Velocity-Verlet algorithm
- Default timestep is 0.005
- Particle 1 is of type MdPointParticle
- Position is set to <1,0,0> in the constructor
- Default type is type::A, although type can be explicitly set
- Particle 2 is of type MdPointParticle
- Position is set to <-1,0,0> in the constructor
- Default type is type::A, although type can be explicitly set
- StepForward(N) steps the simulaton forward N timesteps
- Another way to write this would be s += 1000
- Can also do "StepBackward" to go back in time (only certain integrators)
- ComputePotentialEnergy() returns the potential energy of the system