Sei sulla pagina 1di 3

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <cmath> #include <cmath> #include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib> #include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream> #include <fstream> #include <fstream>
#include <iostream> #include <iostream> #include <iostream> #include <iostream>
#include <string> #include <string> #include <string> #include <string>
using namespace std; using namespace std; using namespace std; using namespace std; using namespace std; using namespace std;
/********************************** /**********************************
Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D Basic MD of Lennard-Jonesium in 1D
**********************************/ **********************************/
/************************ /************************
declare global variables declare global variables declare global variables declare global variables declare global variables
************************/ ************************/
// values that stay fixed during the simulation
const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control) const int N = 36; // number of particles (integer for loop control)
const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths) const double dN = 36.; // number of particles (double for doing maths)
const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box const double L = 36.; // length of (1D) box
const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing const double a = L / dN; // lattice spacing
const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting) const int tsteps = 100; // number of time steps (integer for counting)
const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths) const double dtsteps = tsteps; // number of time steps (double for maths)
const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep const double dt = 0.01; // integration timestep
const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions const double rc = 18.; // distance cutoff for computing LJ interactions
const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared const double rc2 = rc * rc; // distance cutoff squared
const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6}) const double ecut = 4. * ((pow(rc,-12.)) - (pow(rc,-6.))); // value of LJ potential at r = rc: 4(1/rc^{12} - 1/rc^{6})
// values that change during the simulation
double en; // potential energy double en; // potential energy double en; // potential energy double en; // potential energy double en; // potential energy double en; // potential energy
double etot; // total energy (pot + kin) double etot; // total energy (pot + kin) double etot; // total energy (pot + kin) double etot; // total energy (pot + kin) double etot; // total energy (pot + kin) double etot; // total energy (pot + kin)
double temp = 0.728; // temperature double temp = 0.728; // temperature double temp = 0.728; // temperature double temp = 0.728; // temperature double temp = 0.728; // temperature double temp = 0.728; // temperature double temp = 0.728; // temperature double temp = 0.728; // temperature double temp = 0.728; // temperature double temp = 0.728; // temperature
// arrays for storing stuff
double x[N]; // coordinates double x[N]; // coordinates double x[N]; // coordinates double x[N]; // coordinates double x[N]; // coordinates double x[N]; // coordinates double x[N]; // coordinates double x[N]; // coordinates double x[N]; // coordinates
double xp[N]; // previous coordinates double xp[N]; // previous coordinates double xp[N]; // previous coordinates double xp[N]; // previous coordinates double xp[N]; // previous coordinates double xp[N]; // previous coordinates double xp[N]; // previous coordinates double xp[N]; // previous coordinates double xp[N]; // previous coordinates
double v[N]; // velocities double v[N]; // velocities double v[N]; // velocities double v[N]; // velocities double v[N]; // velocities double v[N]; // velocities double v[N]; // velocities double v[N]; // velocities double v[N]; // velocities
double f[N]; // forces double f[N]; // forces double f[N]; // forces double f[N]; // forces double f[N]; // forces double f[N]; // forces double f[N]; // forces double f[N]; // forces double f[N]; // forces
// store data for averaging
double sumTemp = 0.; double sumTemp = 0.; double sumTemp = 0.; double sumTemp = 0.; double sumTemp = 0.; double sumTemp = 0.; double sumTemp = 0.; double sumTemp = 0.;
double sumEtot = 0.; double sumEtot = 0.; double sumEtot = 0.; double sumEtot = 0.; double sumEtot = 0.; double sumEtot = 0.; double sumEtot = 0.; double sumEtot = 0.;
double temps[tsteps]; double temps[tsteps]; double temps[tsteps]; double temps[tsteps]; double temps[tsteps]; double temps[tsteps]; double temps[tsteps];
double etots[tsteps]; double etots[tsteps]; double etots[tsteps]; double etots[tsteps]; double etots[tsteps]; double etots[tsteps]; double etots[tsteps];
/********************* /*********************
function declarations function declarations function declarations
*********************/ *********************/
void void init(); (); ();
double double lattice_pos(int i); (int i); (int i); (int i); (int i); (int i);
void void force(); (); ();
void void integrate(int t); (int t); (int t); (int t); (int t); (int t);
void void printcoords(double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile); (double time, FILE* ofile);
void void statistics(FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile); (FILE* tfile, FILE* efile);
/********** /**********
MD program MD program MD program
**********/ **********/
int int main() { () { () { () {
//cout << "ecut = " << ecut << endl; //cout << "ecut = " << ecut << endl;
double time = 0.; // initialise time double time = 0.; // initialise time double time = 0.; // initialise time double time = 0.; // initialise time double time = 0.; // initialise time double time = 0.; // initialise time double time = 0.; // initialise time double time = 0.; // initialise time double time = 0.; // initialise time double time = 0.; // initialise time double time = 0.; // initialise time
init(); // initialisation init(); // initialisation init(); // initialisation init(); // initialisation init(); // initialisation init(); // initialisation init(); // initialisation
// open coordinate output file // open coordinate output file
FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE; FILE * cfile = new FILE;
cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w"); cfile = fopen ("coords.xyz","w");
// open temperature output file // open temperature output file
FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE; FILE * tfile = new FILE;
tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w"); tfile = fopen ("temperature.dat","w");
fprintf (tfile,"# time temperature fprintf (tfile,"# time temperature fprintf (tfile,"# time temperature fprintf (tfile,"# time temperature fprintf (tfile,"# time temperature fprintf (tfile,"# time temperature fprintf (tfile,"# time temperature fprintf (tfile,"# time temperature\n"); "); ");
// open energy output file // open energy output file
FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE; FILE * efile = new FILE;
efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w"); efile = fopen ("energy.dat","w");
fprintf (efile,"# time energy fprintf (efile,"# time energy fprintf (efile,"# time energy fprintf (efile,"# time energy fprintf (efile,"# time energy fprintf (efile,"# time energy fprintf (efile,"# time energy fprintf (efile,"# time energy\n"); "); ");
// main MD loop // main MD loop
for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) { for (int t = 0; t < tsteps; t++) {

cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl; cout << "#---- Time = " << time << " ---- Steps = " << t << " ---- " << endl;
force(); // calculate forces force(); // calculate forces force(); // calculate forces force(); // calculate forces force(); // calculate forces force(); // calculate forces force(); // calculate forces
integrate(t); // integrate equations of motion integrate(t); // integrate equations of motion integrate(t); // integrate equations of motion integrate(t); // integrate equations of motion integrate(t); // integrate equations of motion integrate(t); // integrate equations of motion integrate(t); // integrate equations of motion integrate(t); // integrate equations of motion
// print current coordinates to file // print current coordinates to file
printcoords(time, cfile); printcoords(time, cfile); printcoords(time, cfile); printcoords(time, cfile); printcoords(time, cfile); printcoords(time, cfile); printcoords(time, cfile); printcoords(time, cfile); printcoords(time, cfile);
// print current temperature to file // print current temperature to file
fprintf (tfile,"%10.10f %10.10f fprintf (tfile,"%10.10f %10.10f fprintf (tfile,"%10.10f %10.10f fprintf (tfile,"%10.10f %10.10f fprintf (tfile,"%10.10f %10.10f fprintf (tfile,"%10.10f %10.10f fprintf (tfile,"%10.10f %10.10f fprintf (tfile,"%10.10f %10.10f\n",time,temp); ",time,temp); ",time,temp); ",time,temp); ",time,temp); ",time,temp); ",time,temp);
// print current energy to file // print current energy to file
fprintf (efile,"%10.10f %10.10f fprintf (efile,"%10.10f %10.10f fprintf (efile,"%10.10f %10.10f fprintf (efile,"%10.10f %10.10f fprintf (efile,"%10.10f %10.10f fprintf (efile,"%10.10f %10.10f fprintf (efile,"%10.10f %10.10f fprintf (efile,"%10.10f %10.10f\n",time,etot); ",time,etot); ",time,etot); ",time,etot); ",time,etot); ",time,etot); ",time,etot);
time += dt; // increase time by dt time += dt; // increase time by dt time += dt; // increase time by dt time += dt; // increase time by dt time += dt; // increase time by dt time += dt; // increase time by dt time += dt; // increase time by dt time += dt; // increase time by dt time += dt; // increase time by dt
} }
statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc statistics(tfile, efile); // calculate averages, SD, etc
// close output files // close output files
fclose(cfile); fclose(cfile); fclose(cfile); fclose(cfile); fclose(cfile); fclose(cfile);
fclose(tfile); fclose(tfile); fclose(tfile); fclose(tfile); fclose(tfile); fclose(tfile);
fclose(efile); fclose(efile); fclose(efile); fclose(efile); fclose(efile); fclose(efile);
}
/******************** /********************
1.1 of 3 2014.06.04 18:01:19
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/******************** /********************
function definitions function definitions function definitions
********************/ ********************/
// initialise positions and velocities
void void init() { () { () { () {
cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl; cout << endl << "#---- Initialising positions and velocities ----" << endl;
double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities double sumv = 0; // sum of velocities
double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared double sumv2 = 0; // sum of velocities squared
// loop over particles // loop over particles
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice x[i] = lattice_pos(i); // place particles on a lattice
v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5] v[i] = ((rand() % N) / dN) - 0.5; // assign velocities uniformly (but randomly) in range [-0.5,0.5]
sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities sumv += v[i]; // sum vlocities
sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities sumv2 += v[i]*v[i]; // sum squared velocities
} }
sumv /= dN; // velocity centre of mass sumv /= dN; // velocity centre of mass sumv /= dN; // velocity centre of mass sumv /= dN; // velocity centre of mass sumv /= dN; // velocity centre of mass sumv /= dN; // velocity centre of mass sumv /= dN; // velocity centre of mass sumv /= dN; // velocity centre of mass sumv /= dN; // velocity centre of mass
sumv2 /= dN; // mean-squared velocity sumv2 /= dN; // mean-squared velocity sumv2 /= dN; // mean-squared velocity sumv2 /= dN; // mean-squared velocity sumv2 /= dN; // mean-squared velocity sumv2 /= dN; // mean-squared velocity sumv2 /= dN; // mean-squared velocity sumv2 /= dN; // mean-squared velocity sumv2 /= dN; // mean-squared velocity
double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature double sf = sqrt(3. * temp / sumv2); // scale factor for velocities to achieve desired temperature
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities v[i] = (v[i] - sumv) * sf; // scale velocities
xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions xp[i] = x[i] - v[i] * dt; // set previous positions
} }
}
// place particle on a lattice
double double lattice_pos(int i) { (int i) { (int i) { (int i) { (int i) { (int i) { (int i) {

double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a; double pos = (i + 0.5) * a;
return pos; return pos; return pos; return pos; return pos;
}
// calculate forces
void void force() { () { () { () {
cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl; cout << endl << "#---- Calculating forces ----" << endl;
en = 0; // (re)set energy to zero en = 0; // (re)set energy to zero en = 0; // (re)set energy to zero en = 0; // (re)set energy to zero en = 0; // (re)set energy to zero en = 0; // (re)set energy to zero en = 0; // (re)set energy to zero en = 0; // (re)set energy to zero en = 0; // (re)set energy to zero
// (re)set forces to zero // (re)set forces to zero
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
f[i] = 0.0; f[i] = 0.0; f[i] = 0.0; f[i] = 0.0; f[i] = 0.0; f[i] = 0.0; f[i] = 0.0; f[i] = 0.0; f[i] = 0.0; f[i] = 0.0;
} }
// loop (inefficiently) over all pairs of atoms // loop (inefficiently) over all pairs of atoms
for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){ for (int i = 0; i < N-1; i++){
for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) { for (int j = i+1; j < N; j++) {
double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j double xr = x[i] - x[j]; // distance between atoms i and j
xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions xr -= L * rint(xr / L); // periodic boundary conditions
double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff double r2 = xr * xr; // square to compare to cutoff
if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff if (r2 < rc2) { // test cutoff
// compute Lennard-Jones interaction // compute Lennard-Jones interaction
double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2; double r2i = 1. / r2;
double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0); double r6i = pow(r2i, 3.0);
double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5); double ff = 48. * r2i * r6i * (r6i - 0.5);
// update forces // update forces
f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr; f[i] += ff * xr;
f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr; f[j] -= ff * xr;
// update energy // update energy
en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut; en += 4. * r6i * (r6i - 1.) - ecut;
} }
} }
} }
}
// integrate equations of motion
void void integrate(int t) { (int t) { (int t) { (int t) { (int t) { (int t) { (int t) {
cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl; cout << endl << "#---- Integrating equations of motion ----" << endl << endl;
double sumv = 0; double sumv = 0; double sumv = 0; double sumv = 0; double sumv = 0; double sumv = 0; double sumv = 0; double sumv = 0; double sumv = 0;
double sumv2 = 0; double sumv2 = 0; double sumv2 = 0; double sumv2 = 0; double sumv2 = 0; double sumv2 = 0; double sumv2 = 0; double sumv2 = 0; double sumv2 = 0;
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm double xx = 2. * x[i] - xp[i] + dt*dt*f[i]; // Verlet algorithm
double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity double vi = (xx - xp[i]) / (2. * dt); // velocity
sumv += vi; // velocity centre of mass sumv += vi; // velocity centre of mass sumv += vi; // velocity centre of mass sumv += vi; // velocity centre of mass sumv += vi; // velocity centre of mass sumv += vi; // velocity centre of mass sumv += vi; // velocity centre of mass sumv += vi; // velocity centre of mass sumv += vi; // velocity centre of mass
sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy sumv2 += vi*vi; // total kinetic energy
xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions xp[i] = x[i]; // update previous positions
x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions x[i] = xx; // update current positions
} }
temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature temp = sumv2 / (3. * dN); // instantaneous temperature
// store for calculating SD // store for calculating SD
sumTemp += temp; sumTemp += temp; sumTemp += temp; sumTemp += temp; sumTemp += temp; sumTemp += temp; sumTemp += temp;
temps[t] = temp; temps[t] = temp; temps[t] = temp; temps[t] = temp; temps[t] = temp; temps[t] = temp; temps[t] = temp; temps[t] = temp; temps[t] = temp; temps[t] = temp;
etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle etot = (en + 0.5 * sumv2) / dN; // total energy per particle
// store for calculating SD // store for calculating SD
sumEtot += etot; sumEtot += etot; sumEtot += etot; sumEtot += etot; sumEtot += etot; sumEtot += etot; sumEtot += etot;
etots[t] = etot; etots[t] = etot; etots[t] = etot; etots[t] = etot; etots[t] = etot; etots[t] = etot; etots[t] = etot; etots[t] = etot; etots[t] = etot; etots[t] = etot;
}
// print coordinates
void void printcoords(double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) { (double time, FILE* cfile) {
fprintf (cfile,"%d fprintf (cfile,"%d fprintf (cfile,"%d fprintf (cfile,"%d fprintf (cfile,"%d fprintf (cfile,"%d fprintf (cfile,"%d fprintf (cfile,"%d\n",N); ",N); ",N); ",N); ",N);
fprintf (cfile,"time %10.10f fprintf (cfile,"time %10.10f fprintf (cfile,"time %10.10f fprintf (cfile,"time %10.10f fprintf (cfile,"time %10.10f fprintf (cfile,"time %10.10f fprintf (cfile,"time %10.10f fprintf (cfile,"time %10.10f\n",time); ",time); ",time); ",time); ",time);
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
fprintf (cfile, "C %-8.8f 0.0 0.0 fprintf (cfile, "C %-8.8f 0.0 0.0 fprintf (cfile, "C %-8.8f 0.0 0.0 fprintf (cfile, "C %-8.8f 0.0 0.0 fprintf (cfile, "C %-8.8f 0.0 0.0 fprintf (cfile, "C %-8.8f 0.0 0.0 fprintf (cfile, "C %-8.8f 0.0 0.0 fprintf (cfile, "C %-8.8f 0.0 0.0 fprintf (cfile, "C %-8.8f 0.0 0.0\n",x[i]); ",x[i]); ",x[i]); ",x[i]); ",x[i]); ",x[i]); ",x[i]); ",x[i]);
} }
2.1 of 3 2014.06.04 18:01:19
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
}
// calculate averages, etc and print to file
void void statistics(FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) { (FILE* tfile, FILE* efile) {
// averages // averages
double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps; double aveTemp = sumTemp / dtsteps;
double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps; double aveEtot = sumEtot / dtsteps;
// standard deviation // standard deviation
double varTemp = 0.; double varTemp = 0.; double varTemp = 0.; double varTemp = 0.; double varTemp = 0.; double varTemp = 0.; double varTemp = 0.; double varTemp = 0.; double varTemp = 0.;
double varEtot = 0.; double varEtot = 0.; double varEtot = 0.; double varEtot = 0.; double varEtot = 0.; double varEtot = 0.; double varEtot = 0.; double varEtot = 0.; double varEtot = 0.;
for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) { for (int i = 0; i < tsteps; i++) {
varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp); varTemp += (temps[i] - aveTemp)*(temps[i] - aveTemp);
varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot); varEtot += (etots[i] - aveEtot)*(etots[i] - aveEtot);
} }
double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps); double sdTemp = sqrt(varTemp / dtsteps);
double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps); double sdEtot = sqrt(varEtot / dtsteps);
fprintf (tfile, "# Average temperature: %10.2f fprintf (tfile, "# Average temperature: %10.2f fprintf (tfile, "# Average temperature: %10.2f fprintf (tfile, "# Average temperature: %10.2f fprintf (tfile, "# Average temperature: %10.2f fprintf (tfile, "# Average temperature: %10.2f fprintf (tfile, "# Average temperature: %10.2f fprintf (tfile, "# Average temperature: %10.2f fprintf (tfile, "# Average temperature: %10.2f\n", aveTemp); ", aveTemp); ", aveTemp); ", aveTemp); ", aveTemp); ", aveTemp);
fprintf (tfile, "# Standard deviation: %10.2f fprintf (tfile, "# Standard deviation: %10.2f fprintf (tfile, "# Standard deviation: %10.2f fprintf (tfile, "# Standard deviation: %10.2f fprintf (tfile, "# Standard deviation: %10.2f fprintf (tfile, "# Standard deviation: %10.2f fprintf (tfile, "# Standard deviation: %10.2f fprintf (tfile, "# Standard deviation: %10.2f fprintf (tfile, "# Standard deviation: %10.2f\n", sdTemp); ", sdTemp); ", sdTemp); ", sdTemp); ", sdTemp); ", sdTemp);
fprintf (efile, "# Average total energy: %10.2f fprintf (efile, "# Average total energy: %10.2f fprintf (efile, "# Average total energy: %10.2f fprintf (efile, "# Average total energy: %10.2f fprintf (efile, "# Average total energy: %10.2f fprintf (efile, "# Average total energy: %10.2f fprintf (efile, "# Average total energy: %10.2f fprintf (efile, "# Average total energy: %10.2f fprintf (efile, "# Average total energy: %10.2f\n", aveEtot); ", aveEtot); ", aveEtot); ", aveEtot); ", aveEtot); ", aveEtot);
fprintf (efile, "# Standard deviation: %10.2f fprintf (efile, "# Standard deviation: %10.2f fprintf (efile, "# Standard deviation: %10.2f fprintf (efile, "# Standard deviation: %10.2f fprintf (efile, "# Standard deviation: %10.2f fprintf (efile, "# Standard deviation: %10.2f fprintf (efile, "# Standard deviation: %10.2f fprintf (efile, "# Standard deviation: %10.2f fprintf (efile, "# Standard deviation: %10.2f\n", sdEtot); ", sdEtot); ", sdEtot); ", sdEtot); ", sdEtot); ", sdEtot);
}
3.1 of 3 2014.06.04 18:01:19

Potrebbero piacerti anche