The main class is MDUnit which is the kernel of Molecular Dynamics (MD) codes. Each simulation corresponds to an instance of Project class. ProjectManager class creates an instance of MDUnit and passes it to an appropriate instance of Project. A programer should overwrite Run method of Project class in order to perform MD simulations.
MPI libralies are required for compilation. If you do not have MPI emvironment, you should prepare it before buiding of MDACP.
Describe a compiler (CC), compile options (CPPFLAGS), and library options (LDFLAGS) in makefile.opt. Some examples of makefile.opt are as follows.
CC=mpic++ CPPFLAGS= -O3 -funroll-loops LDFLAGS=-lmpi
CC=mpicxx CPPFLAGS=-Os -noparallel +Op -DPOWER
CC=g++ LDFLAGS=-lmpich CPPFLAGS=-O3 -funroll-loops
CC=mpCC CPPFLAGS= -O5 -q64 -DPOWER
MDACP performs a benchmark if it is executed without options. The following is an example of outputs.
$ ./mdacp # Number of Processes: 1 # Input file is not specified. input.cfg is used. # Mode = Benchmark # Number of Particles = 62500 # System Size = (50,50,50) # Desity = 0.5 # Cutoff Length = 2.5 # TimeStep = 0.001 # ControlTemperature = no # IsPeriodic = yes #Energy = -2.00818 0.151 0.364681 -2.00818# observe 0.251 0.36874 -2.00819# observe 0.351 0.444665 -2.00816# observe 0.451 0.496116 -2.00817# observe 0.551 0.518531 -2.00817# observe 0.651 0.541055 -2.00817# observe 0.751 0.559876 -2.00817# observe 0.851 0.577013 -2.00817# observe 0.951 0.588248 -2.00818# observe 1.051 0.599503 -2.00818# observe #Energy = -2.00817 # N=62500 21.6639 [SEC] 2.88498 [MUPS] # Number of Pair-list Construction: 17
For parallel execution, use mpirun as follows. The default mode is weak scaling.
$ mpirun -np 8 ./mdacp # Number of Processes: 8 # Input file is not specified. input.cfg is used. # Mode = Benchmark # Number of Particles = 500000 # System Size = (100,100,100) # Desity = 0.5 # Cutoff Length = 2.5 # TimeStep = 0.001 # ControlTemperature = no # IsPeriodic = yes #Energy = -2.00818 0.151 0.365109 -2.00818# observe 0.251 0.369157 -2.00819# observe 0.351 0.445891 -2.00816# observe 0.451 0.496593 -2.00817# observe 0.551 0.521196 -2.00817# observe 0.651 0.542904 -2.00817# observe 0.751 0.561414 -2.00817# observe 0.851 0.576258 -2.00817# observe 0.951 0.588979 -2.00817# observe 1.051 0.599142 -2.00817# observe #Energy = -2.00817 # N=500000 43.1095 [SEC] 11.5984 [MUPS] # Number of Pair-list Construction: 18
Prepare a parameter file (*.cfg) and pass it as the first argument.
$ mpirun -np 8 ./mdacp hoge.cfgWhen an input file is omitted, "input.cfg" will be passed.
The format of parameter files are as follows.
parameter1=value1 parameter2=value2 parameter3=value3Here are some reserved keywords.
SystemSizeX=100 SystemSizeY=50 SystemSizeZ=50
One can use any keywords except for reserved ones, for example, InitialVelocity, TotalLoop, ControlTemperature, etc. All parameters are stored an instance of Paramater class. One can have the value of parameter with Parameter::GetInteger, etc.
Simulation mode is specified by "Mode" in a parameter file. The simulation mode is checked in ProjectManager::ExecuteProject and ProjectManager calls Benchmark::Run in benchmark.cc when Mode=Benchmark or calls Collision::Run in collision.cc when Mode=Collision, and so forth. User performs simulation with mdu (an instance of MDUnit) and param (an instance of Parameter) which are passed to Hoge::Run method.
One can create new project by inheriting Project class. For example, the mode "Collision" is the simulator for droplet collisions which is implemented in collision.cc/collision.h. In the constructor of Collision class, the project is registered to ProjectManager as follows.
ProjectManager::GetInstance().AddProject("Collision",this);The above code is called when the instance is created by the following definition.
Collision collision;
Parameters in a parameter file can be recieved by calling methods of Parameter. Suppose a instance of Parameter class is param and the density is defined in the parameter file as follows.
Density=0.70One can get the value by the following code.
double density = param.GetDoubleDef("Density",0.5)In this example, density will have value 0.5 when "Density" is not defined in the parameter file. Similarly, one can recieve integer and boolean. Suppose a number of loop is defined as follows.
TotalLoop=1000One can recieve it by the following code.
const int TOTAL_LOOP =param.GetIntegerDef("TotalLoop",1000);One can also recieve boolean values as follows.
IsPeriodic=yes ControlTemperature=no
bool isPeriodic = param.GetBooleanDef("IsPeriodic",false); bool controlTemperature = param.GetBooleanDef("ControlTemperature",false);
One can put particles with MDUnit::AddParticle(double x[D], double v[D]), where x is position, v is velocity, respectively. Here is an example.
double x[D],v[D]; x[X] =50.0; y[Y] =50.0; z[Z] =50.0; v[X] = 0; v[Y] = 0; v[Z] = 0; mdu->AddParticle(x,v);
MDUnit::Calculate involves one step. The current simulation time is given by MDUnit::GetSimulationTime, temperature is given by MDUnit::GetSimulationTime, and the total energy is given by MDUnit::TotalEnergy. Here is an example.
for (int i=0; i<TOTAL_LOOP; i++) { mdu->Calculate(); if (i%OBSERVE_LOOP==0) { mout << mdu->GetSimulationTime() << " "<< mdu->Temperature() << endl; } }
Key=ValueParameter class reads parameters from a file, and stores them in std::map. The stored values can be obtained by methods such as GetInteger, GetDouble, GetBoolean, and so forth.
$ mpirun -np 8 ./mdacp collision.cfgThe above example will output conf000.cd to conf40.cd. These files can be visualized by cdview by
$ cdview conf*.cd