The following tutorial pertains to NVT Monte simulation of a Lennard-Jones system.
Linking to the simulation builder library/header
First of all, the Simulation Builder header file should be included:
#include <glotzilla++.h>
This tells the compiler about all of the pre-defined Glotzilla classes. We will now be able to access the McSimulation class within the Simulation Builder library and can create an instance of it:
#include <glotzilla++.h> int main(int argc, char ** argv) { McSimulation my_simulation; return 0; }
Setting up the simulation
Having declared an instance of McSimulation my_simulation, we can now set up the MC simulation. An MC code needs a few aspects of it to be defined in order to work:
- particles - objects that exist in the simulation.
- interaction - specifies how particles interact with each other.
- trial moves - the type of trial moves performed on the particles/system.
- potential routine - calculates the potential energy of the system.
- boundary conditions - the space accessible to the particles.
- random number generator - generates random numbers for performing trial moves.
In the following code, we will:
- add two particles at <0, 0, 0> and <1, 1, 1>
- set the interaction between particles as Lennard-Jones.
- add translation as a trial move.
- set the code to use a brute potential routine.
- set the boundary of the box to be periodic where Lx = Ly = Lz = 5
- set the standard StdLibErand?48 as the random number generator
#include "glotzilla++.h" int main(int argc, char ** argv) { McSimulation my_simulation; my_simulation.AddParticle(new McPointParticle(0,0,0)); my_simulation.AddParticle(new McPointParticle(1,1,1)); my_simulation.SetInteraction(new LennardJones); my_simulation.AddTrialMove (new TrialTranslation); my_simulation.SetPotentialRoutine(new BrutePotential); my_simulation.SetBoundaryConditions(new PeriodicBoundary(5)); my_simulation.SetRandomNumberGenerator(new StdLibErand48); return 0; }
Performing the trial moves
To advance the simulation through simulation i.e. perform the actual MC trial moves, we need only use the "++" operator defined in McSimulation. he following excerpt of code will advance the simulation through 20000 MC cycles and then exit.
#include "glotzilla++.h" int main(int argc, char ** argv) { McSimulation my_simulation; my_simulation.AddParticle(new McPointParticle(0,0,0)); my_simulation.AddParticle(new McPointParticle(1,1,1)); my_simulation.SetInteraction(new LennardJones); my_simulation.AddTrialMove (new TrialTranslation); my_simulation.SetPotentialRoutine(new BrutePotential); my_simulation.SetBoundaryConditions(new PeriodicBoundary(5)); my_simulation.SetRandomNumberGenerator(new StdLibErand48); for (int i=0; i<20000; i++) my_simulation++; return 0; }
Getting information from the simulation
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 MCMinimalSimulation.cpp
where MCMinimalSimulation.cpp is the name of the file where the code resides.
Problems
Refer to the FAQ? page.