-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.cpp
More file actions
149 lines (129 loc) · 4.63 KB
/
system.cpp
File metadata and controls
149 lines (129 loc) · 4.63 KB
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
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
#include "system.h"
#include "velocityverlet.h"
#include "lennardjones.h"
#include "statisticssampler.h"
#include "unitconverter.h"
#include "math/random.h"
<<<<<<< HEAD
#include <iostream>
=======
>>>>>>> Intial Install of Project 5 software
System::System()
{
}
System::~System()
{
for(Atom *atom : m_atoms) {
delete atom;
}
m_atoms.clear();
}
<<<<<<< HEAD
void System::applyPeriodicBoundaryConditions()
{
// Read here: http://en.wikipedia.org/wiki/Periodic_boundary_conditions#Practical_implementation:_continuity_and_the_minimum_image_convention
double x_size = m_systemSize.x();
double y_size = m_systemSize.y();
double z_size = m_systemSize.z();
for(Atom *atom : m_atoms)
{
// Update x dimension
if (atom->position.x() < 0) atom->position.setX(atom->position.x() + x_size);
if (atom->position.x() >= x_size) atom->position.setX(atom->position.x() - x_size);
if (atom->position.y() < 0) atom->position.setY(atom->position.y() + y_size);
if (atom->position.y() >= y_size) atom->position.setX(atom->position.y() - y_size);
if (atom->position.z() < 0) atom->position.setZ(atom->position.z() + z_size);
if (atom->position.z() >= z_size) atom->position.setZ(atom->position.z() - z_size);
}
}
void System::removeTotalMomentum()
{
// Find the total momentum and remove momentum equally on each atom so the total momentum becomes zero.
m_momentum.zeros();
for(Atom *atom : m_atoms)
{
m_momentum += atom->mass() * atom->velocity;
}
vec3 scaling_factor = m_momentum/m_atoms.size();
for(Atom *atom : m_atoms)
{
atom->velocity -= scaling_factor/atom->mass();
}
m_momentum.zeros();
for(Atom *atom : m_atoms)
{
m_momentum += atom->mass() * atom->velocity;
}
}
void System::createFCCLattice(int numberOfUnitCellsEachDimension, double latticeConstant, double temperature)
{
setSystemSize(vec3(0, 0, 0) + numberOfUnitCellsEachDimension * latticeConstant); // Remember to set the correct system size!
vec3 latticePositions[4];
for (int i=0; i < numberOfUnitCellsEachDimension; ++i)
{
for (int j=0; j < numberOfUnitCellsEachDimension; ++j)
{
for (int k=0; k < numberOfUnitCellsEachDimension; ++k)
{
Atom *atom1
}
}
}
}
// You should implement this function properly. Right now, 100 atoms are created uniformly placed in the system of size (10, 10, 10)
//for(int i=0; i<100; i++)
//{
// Atom *atom = new Atom(UnitConverter::massFromSI(6.63352088e-26)); // mu of Argon
// // random number in the interval [0,10]
// double x = Random::nextDouble(0, 10);
// double y = Random::nextDouble(0, 10);
// double z = Random::nextDouble(0, 10);
// atom->position.set(x,y,z);
// atom->resetVelocityMaxwellian(temperature);
// m_atoms.push_back(atom);
//}
void System::calculateForces()
{
for(Atom *atom : m_atoms)
{
=======
void System::applyPeriodicBoundaryConditions() {
// Read here: http://en.wikipedia.org/wiki/Periodic_boundary_conditions#Practical_implementation:_continuity_and_the_minimum_image_convention
}
void System::removeTotalMomentum() {
// Find the total momentum and remove momentum equally on each atom so the total momentum becomes zero.
}
void System::createFCCLattice(int numberOfUnitCellsEachDimension, double latticeConstant, double temperature) {
// You should implement this function properly. Right now, 100 atoms are created uniformly placed in the system of size (10, 10, 10).
for(int i=0; i<100; i++) {
Atom *atom = new Atom(UnitConverter::massFromSI(6.63352088e-26));
double x = Random::nextDouble(0, 10); // random number in the interval [0,10]
double y = Random::nextDouble(0, 10);
double z = Random::nextDouble(0, 10);
atom->position.set(x,y,z);
atom->resetVelocityMaxwellian(temperature);
m_atoms.push_back(atom);
}
setSystemSize(vec3(10, 10, 10)); // Remember to set the correct system size!
}
void System::calculateForces() {
for(Atom *atom : m_atoms) {
>>>>>>> Intial Install of Project 5 software
atom->resetForce();
}
m_potential.calculateForces(*this); // this is a pointer, *this is a reference to this object
}
<<<<<<< HEAD
void System::step(double dt)
{
// find new partical configuration by applying forces
m_integrator.integrate(*this, dt);
// Apply periodic boundary conditions
applyPeriodicBoundaryConditions();
=======
void System::step(double dt) {
m_integrator.integrate(*this, dt);
>>>>>>> Intial Install of Project 5 software
m_steps++;
m_time += dt;
}