-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex2d.cpp
62 lines (49 loc) · 1.75 KB
/
complex2d.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
#include "complex2d.h"
#include "utilities.h"
Complex2D::Complex2D()
{
this->setupSystem();
this->initializePositions();
this->initializeVelocities();
}
void Complex2D::setupSystem() {
this->numberOfParticles = numParticles;
this->systemDimensionality = 2;
for(int i = 0 ; i < this->numberOfParticles ; i++)
this->masses.push_back(1.0f);
}
void Complex2D::initializePositions() {
this->positions = initializeRandomVector(this->numberOfParticles,
this->systemDimensionality,
-1.0f, 1.0f);
}
float Complex2D::potentialEnergy(std::vector<std::vector<float>>& pos) {
float peValue = 0;
for(int i = 0 ; i < this->numberOfParticles ; i++)
peValue += U(pos[i]);
return peValue;
}
float Complex2D::potentialEnergy() {
return potentialEnergy(this->positions);
}
std::vector<std::vector<float>> Complex2D::force(std::vector<std::vector<float>>& pos) {
std::vector<std::vector<float>> returnValue;
for(int i = 0 ; i < this->numberOfParticles ; i++)
returnValue.push_back(F(pos[i]));
return returnValue;
}
std::vector<std::vector<float>> Complex2D::force() {
return this->force(this->positions);
}
float Complex2D::U(std::vector<float>& pos) {
float x = pos[0];
float y = pos[1];
return 10 * (pow(x, 10) + pow(y, 10)) + 5 * sin(2 * M_PI * x) * cos(2 * M_PI * y);
}
std::vector<float> Complex2D::F(std::vector<float>& pos) {
float x = pos[0];
float y = pos[1];
float fX = -1 * (100 * pow(x, 9) + 10 * M_PI * cos(2 * M_PI * x) * cos(2 * M_PI * y));
float fY = -1 * (100 * pow(y, 9) - 10 * M_PI * sin(2 * M_PI * x) * sin(2 * M_PI * y));
return {fX, fY};
}