-
Notifications
You must be signed in to change notification settings - Fork 32
/
main.cpp
69 lines (58 loc) · 2.82 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "math/random.h"
#include "lennardjones.h"
#include "velocityverlet.h"
#include "system.h"
#include "statisticssampler.h"
#include "atom.h"
#include "io.h"
#include "unitconverter.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main(int numberOfArguments, char **argumentList)
{
int numberOfUnitCells = 5;
double initialTemperature = UnitConverter::temperatureFromSI(300.0); // measured in Kelvin
double latticeConstant = UnitConverter::lengthFromAngstroms(5.26); // measured in angstroms
// If a first argument is provided, it is the number of unit cells
if(numberOfArguments > 1) numberOfUnitCells = atoi(argumentList[1]);
// If a second argument is provided, it is the initial temperature (measured in kelvin)
if(numberOfArguments > 2) initialTemperature = UnitConverter::temperatureFromSI(atof(argumentList[2]));
// If a third argument is provided, it is the lattice constant determining the density (measured in angstroms)
if(numberOfArguments > 3) latticeConstant = UnitConverter::lengthFromAngstroms(atof(argumentList[3]));
double dt = UnitConverter::timeFromSI(1e-15); // Measured in seconds.
cout << "One unit of length is " << UnitConverter::lengthToSI(1.0) << " meters" << endl;
cout << "One unit of velocity is " << UnitConverter::velocityToSI(1.0) << " meters/second" << endl;
cout << "One unit of time is " << UnitConverter::timeToSI(1.0) << " seconds" << endl;
cout << "One unit of mass is " << UnitConverter::massToSI(1.0) << " kg" << endl;
cout << "One unit of temperature is " << UnitConverter::temperatureToSI(1.0) << " K" << endl;
System system;
system.createFCCLattice(numberOfUnitCells, latticeConstant, initialTemperature);
system.potential().setEpsilon(1.0);
system.potential().setSigma(1.0);
system.removeTotalMomentum();
StatisticsSampler statisticsSampler;
IO movie("movie.xyz"); // To write the state to file
cout << setw(20) << "Timestep" <<
setw(20) << "Time" <<
setw(20) << "Temperature" <<
setw(20) << "KineticEnergy" <<
setw(20) << "PotentialEnergy" <<
setw(20) << "TotalEnergy" << endl;
for(int timestep=0; timestep<1000; timestep++) {
system.step(dt);
statisticsSampler.sample(system);
if( timestep % 100 == 0 ) {
// Print the timestep every 100 timesteps
cout << setw(20) << system.steps() <<
setw(20) << system.time() <<
setw(20) << statisticsSampler.temperature() <<
setw(20) << statisticsSampler.kineticEnergy() <<
setw(20) << statisticsSampler.potentialEnergy() <<
setw(20) << statisticsSampler.totalEnergy() << endl;
}
movie.saveState(system);
}
movie.close();
return 0;
}