-
Notifications
You must be signed in to change notification settings - Fork 0
/
smit.cpp
97 lines (76 loc) · 2.4 KB
/
smit.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "smit.h"
#include <vector>
#include "system.h"
#include "units.h"
#include "utilities.h"
#include "math.h"
#include "config.h"
void Smit::setupSystem() {
this->numberOfParticles = numParticles;
this->systemDimensionality = 1;
for(int i = 0 ; i < this->numberOfParticles ; i++)
this->masses.push_back(1.0f);
// read from rst file if required
}
void Smit::initializePositions() {
this->positions = initializeRandomVector(this->numberOfParticles,
this->systemDimensionality,
-2.0f, 2.0f);
}
Smit::Smit() {
this->setupSystem();
this->initializePositions();
this->initializeVelocities();
}
float Smit::potentialEnergy() {
return this->potentialEnergy(this->positions);
}
float Smit::potentialEnergy(std::vector<std::vector<float>>& positions) {
float totalPE = 0;
for(int i = 0 ; i < this->numberOfParticles ; i++) {
totalPE += this->U(positions[i][0]);
}
return totalPE;
}
std::vector<std::vector<float>> Smit::force() {
std::vector<std::vector<float>> force_vector(
this->numberOfParticles,
std::vector<float>(this->systemDimensionality, 0)
);
for(int i = 0 ; i < this->numberOfParticles ; i++) {
force_vector[i][0] = this->F(this->positions[i][0]);
}
return force_vector;
}
std::vector<std::vector<float>> Smit::force(std::vector<std::vector<float>>& positions) {
std::vector<std::vector<float>> force_vector(
this->numberOfParticles,
std::vector<float>(this->systemDimensionality, 0)
);
for(int i = 0 ; i < this->numberOfParticles ; i++) {
force_vector[i][0] = this->F(positions[i][0]);
}
return force_vector;
}
float Smit::U(float x) {
if (x < -1.25)
return 4 * pow(M_PI, 2) * pow((x + 1.25), 2);
if (x < -0.25)
return 2 * (1 + sin(2 * M_PI * x));
if (x < 0.75)
return 3 * (1 + sin(2 * M_PI * x));
if (x < 1.75)
return 4 * (1 + sin(2 * M_PI * x));
return 8 * pow(M_PI, 2) * pow((x - 1.75), 2);
}
float Smit::F(float x) {
if (x < -1.25)
return -8 * pow(M_PI, 2) * (x + 1.25);
if (x < -0.25)
return -4 * M_PI * cos(2 * M_PI * x);
if (x < 0.75)
return -6 * M_PI * cos(2 * M_PI * x);
if (x < 1.75)
return -8 * M_PI * cos(2 * M_PI * x);
return -16 * pow(M_PI, 2) * (x - 1.75);
}