-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
77 lines (60 loc) · 2.19 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
70
71
72
73
74
75
76
77
#include "main.h"
int main(int argc, char* argv[])
{
// Class for dealing with the input
Input sInput;
// Read from a parameter file if provided on the command line, else use defaults
if (argc > 1)
sInput.readParameters(argv[1]);
// Check the input parameters for consistency
sInput.checkValues();
// Creating simulation object
Simulation Simulation(sInput.getParams());
// Place atoms randomly in the initial box or load initial positions from a file if provided
if (sInput.getParams().strPosInputFile.empty())
Simulation.generateRandomPositions();
else
Simulation.loadPositions(sInput.getParams().strPosInputFile);
// Generate initial velocities or load them from a file if provided
if (sInput.getParams().strVelInputFile.empty())
Simulation.generateVelocities();
else
Simulation.loadVelocities(sInput.getParams().strVelInputFile);
// Remove center of mass motion
Simulation.removeTranslation(true);
// Report on everything at step zero
Simulation.reportStep();
Simulation.logPositions();
Simulation.calculateEnergies();
Simulation.logEnergies(true);
// Start the timer for the integration loop
clock_t cTime = std::clock();
// Main integration loop (Velocity Verlet)
// The initial time and step are set by the Simulation constructor
do
{
Simulation.advanceTime();
if (Simulation.getStep() % 1000 == 0)
Simulation.reportStep();
if (Simulation.getStep() % 100 == 0)
Simulation.logPositions();
// Update the position according to Verlet algorithm
Simulation.updatePositions();
Simulation.correctPositions(); // Enforce PBC
// Update forces for all atoms
Simulation.updateForces();
// Update the velocities now
Simulation.updateVelocities();
// Calculate the kinetic and potential energies of the system, record them
if (Simulation.getStep() % 10 == 0)
{
Simulation.calculateEnergies();
Simulation.logEnergies(Simulation.getStep() % 1000 == 0);
}
}
while (!Simulation.isFinished());
// Report on time spent
cTime = std::clock() - cTime;
std::cout << "\nTotal run time of the integration loop: " << double(cTime) / CLOCKS_PER_SEC << "s\n";
return error::noError;
}