diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d4d13ad --- /dev/null +++ b/.clang-format @@ -0,0 +1,10 @@ +UseTab: Never +IndentWidth: 4 +TabWidth: 4 +AccessModifierOffset: -4 +IndentAccessModifiers: false +AllowShortFunctionsOnASingleLine: false +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + BeforeElse: true diff --git a/Doxyfile b/Doxyfile index ea0f35d..eeba27f 100644 --- a/Doxyfile +++ b/Doxyfile @@ -68,7 +68,7 @@ PROJECT_LOGO = # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = docs +OUTPUT_DIRECTORY = # If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096 # sub-directories (in 2 levels) under the output directory of each output format @@ -1070,7 +1070,7 @@ EXAMPLE_RECURSIVE = NO # that contain images that are to be included in the documentation (see the # \image command). -IMAGE_PATH = +IMAGE_PATH = ./images # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program @@ -1303,7 +1303,7 @@ GENERATE_HTML = YES # The default directory is: html. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_OUTPUT = html +HTML_OUTPUT = docs # The HTML_FILE_EXTENSION tag can be used to specify the file extension for each # generated HTML page (for example: .htm, .php, .asp). @@ -2183,7 +2183,7 @@ GENERATE_MAN = YES # The default directory is: man. # This tag requires that the tag GENERATE_MAN is set to YES. -MAN_OUTPUT = man +MAN_OUTPUT = man_pages # The MAN_EXTENSION tag determines the extension that is added to the generated # man pages. In case the manual section does not start with a number, the number diff --git a/README.md b/README.md index 9d655f4..254c153 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Penning trap simulation +![](./images/100_particles.gif) + + ## Credits The Doxygen theme used here is diff --git a/docs/100_particles.gif b/docs/100_particles.gif new file mode 100644 index 0000000..337c6e5 Binary files /dev/null and b/docs/100_particles.gif differ diff --git a/docs/Particle_8cpp.html b/docs/Particle_8cpp.html index 9f88834..b3fd0e9 100644 --- a/docs/Particle_8cpp.html +++ b/docs/Particle_8cpp.html @@ -113,8 +113,7 @@ $(document).ready(function(){initNavTree('Particle_8cpp.html',''); initResizable
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
0.1
-
Bug:
No known bugs
-
Todo:
Implement constructor
+
Bug:
No known bugs

Definition in file Particle.cpp.

diff --git a/docs/Particle_8cpp_source.html b/docs/Particle_8cpp_source.html index 159fd35..13c1950 100644 --- a/docs/Particle_8cpp_source.html +++ b/docs/Particle_8cpp_source.html @@ -102,16 +102,24 @@ $(document).ready(function(){initNavTree('Particle_8cpp_source.html',''); initRe
Go to the documentation of this file.
1
-
15#include "Particle.hpp"
-
16
-
17Particle::Particle(double q, double m,
-
18 arma::vec::fixed<3> r_vec,
-
19 arma::vec::fixed<3> v_vec)
-
20{
-
21
-
22}
+
13#include "Particle.hpp"
+
14
+
15Particle::Particle(double q, double m,
+
16 arma::vec::fixed<3> r_vec,
+
17 arma::vec::fixed<3> v_vec)
+
18{
+
19 // Giving the particle its properties
+
20 this->q = q;
+
21 this->m = m;
+
22 this->r_vec = r_vec;
+
23 this->v_vec = v_vec;
+
24}
A class that holds the properties of a particle.
-
Particle(double q, double m, arma::vec::fixed< 3 > r_vec, arma::vec::fixed< 3 > v_vec)
Initialize the particle.
Definition: Particle.cpp:17
+
double q
Charge.
Definition: Particle.hpp:23
+
Particle(double q, double m, vec_3d r_vec, vec_3d v_vec)
Initialize the particle.
Definition: Particle.cpp:15
+
vec_3d v_vec
velocity
Definition: Particle.hpp:26
+
double m
Mass.
Definition: Particle.hpp:24
+
vec_3d r_vec
position
Definition: Particle.hpp:25
diff --git a/docs/Particle_8hpp.html b/docs/Particle_8hpp.html index 3516260..00fc0e2 100644 --- a/docs/Particle_8hpp.html +++ b/docs/Particle_8hpp.html @@ -107,6 +107,7 @@ $(document).ready(function(){initNavTree('Particle_8hpp.html',''); initResizable

A class that holds the properties of a particle. More...

#include <armadillo>
+#include "typedefs.hpp"

Go to the source code of this file.

diff --git a/docs/Particle_8hpp_source.html b/docs/Particle_8hpp_source.html index 76031eb..f3339f5 100644 --- a/docs/Particle_8hpp_source.html +++ b/docs/Particle_8hpp_source.html @@ -107,28 +107,30 @@ $(document).ready(function(){initNavTree('Particle_8hpp_source.html',''); initRe
14
15#include <armadillo>
16
-
19class Particle {
-
20private:
-
21 double q;
-
22 double m;
-
23 arma::vec::fixed<3> r_vec;
-
24 arma::vec::fixed<3> v_vec;
-
25
-
26public:
-
32 Particle(double q, double m,
-
33 arma::vec::fixed<3> r_vec,
-
34 arma::vec::fixed<3> v_vec);
-
35
-
38 friend class PenningTrap;
-
39};
+
17#include "typedefs.hpp"
+
18
+
21class Particle {
+
22private:
+
23 double q;
+
24 double m;
+
25 vec_3d r_vec;
+
26 vec_3d v_vec;
+
27
+
28public:
+
39 Particle(double q, double m, vec_3d r_vec, vec_3d v_vec);
40
-
41#endif
-
Particle
A class that holds attributes of a particle.
Definition: Particle.hpp:19
-
Particle::v_vec
arma::vec::fixed< 3 > v_vec
velocity
Definition: Particle.hpp:24
-
Particle::q
double q
Charge.
Definition: Particle.hpp:21
-
Particle::r_vec
arma::vec::fixed< 3 > r_vec
position
Definition: Particle.hpp:23
-
Particle::m
double m
Mass.
Definition: Particle.hpp:22
-
PenningTrap
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:25
+
43 friend class PenningTrap;
+
44};
+
45
+
46#endif
+
Particle
A class that holds attributes of a particle.
Definition: Particle.hpp:21
+
Particle::q
double q
Charge.
Definition: Particle.hpp:23
+
Particle::v_vec
vec_3d v_vec
velocity
Definition: Particle.hpp:26
+
Particle::m
double m
Mass.
Definition: Particle.hpp:24
+
Particle::r_vec
vec_3d r_vec
position
Definition: Particle.hpp:25
+
PenningTrap
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:30
+
typedefs.hpp
Useful typedefs for cleaner code.
+
vec_3d
arma::vec::fixed< 3 > vec_3d
Typedef for a fixed 3d arma vector.
Definition: typedefs.hpp:36
diff --git a/docs/PenningTrap_8cpp.html b/docs/PenningTrap_8cpp.html index e572253..5817ff6 100644 --- a/docs/PenningTrap_8cpp.html +++ b/docs/PenningTrap_8cpp.html @@ -105,6 +105,9 @@ $(document).ready(function(){initNavTree('PenningTrap_8cpp.html',''); initResiza

The implementation of the PenningTrap class. More...

#include "PenningTrap.hpp"
+#include "constants.hpp"
+#include "typedefs.hpp"
+#include "utils.hpp"

Go to the source code of this file.

Detailed Description

@@ -113,18 +116,7 @@ $(document).ready(function(){initNavTree('PenningTrap_8cpp.html',''); initResiza
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
0.1
-
Bug:
No known bugs
-
Todo:

Implement constructor

-

Implement add_particle

-

Implement external_E_field

-

Implement external_B_field

-

Implement force_on_particle

-

Implement total_force_external

-

Implement total_force_particles

-

Implement total_force

-

Implement evolve_RK4

-

Implement evolve_forward_euler

-
+
Bug:
No known bugs

Definition in file PenningTrap.cpp.

diff --git a/docs/PenningTrap_8cpp_source.html b/docs/PenningTrap_8cpp_source.html index a4eb76f..282e5c2 100644 --- a/docs/PenningTrap_8cpp_source.html +++ b/docs/PenningTrap_8cpp_source.html @@ -102,69 +102,311 @@ $(document).ready(function(){initNavTree('PenningTrap_8cpp_source.html',''); ini
Go to the documentation of this file.
1
-
24#include "PenningTrap.hpp"
-
25
-
26PenningTrap::PenningTrap(double B_0, double V_0, double d)
-
27{
-
28
-
29}
-
30
- -
32{
-
33
-
34}
-
35
-
36arma::vec PenningTrap::external_E_field(arma::vec r)
-
37{
+
13#include "PenningTrap.hpp"
+
14#include "constants.hpp"
+
15#include "typedefs.hpp"
+
16#include "utils.hpp"
+
17
+
18PenningTrap::PenningTrap(double B_0, std::function<double(double)> V_0,
+
19 double d, double t)
+
20{
+
21 this->B_0 = B_0;
+
22 this->V_0 = V_0;
+
23 this->d = d;
+
24 this->t = t;
+
25}
+
26
+
27PenningTrap::PenningTrap(unsigned int i, double B_0,
+
28 std::function<double(double)> V_0, double d, double t)
+
29 : PenningTrap::PenningTrap(B_0, V_0, d)
+
30{
+
31 vec_3d r, v;
+
32 for (size_t j = 0; j < i; j++) {
+
33 r = vec_3d().randn() * .1 * this->d;
+
34 v = vec_3d().randn() * .1 * this->d;
+
35 this->add_particle(Particle(1., 40., r, v));
+
36 }
+
37}
38
-
39}
-
40
-
41arma::vec PenningTrap::external_B_field(arma::vec r)
+
39PenningTrap::PenningTrap(std::vector<Particle> particles, double B_0,
+
40 std::function<double(double)> V_0, double d, double t)
+
41 : PenningTrap::PenningTrap(B_0, V_0, d)
42{
-
43
+
43 this->particles = particles;
44}
45
-
46arma::vec PenningTrap::force_on_particle(int i, int j)
+
46vec_3d PenningTrap::v_func(unsigned int i, unsigned int j, double dt)
47{
-
48
-
49}
-
50
- -
52{
-
53
-
54}
-
55
- -
57{
-
58
-
59}
-
60
- -
62{
+
48 switch (i) {
+
49 case 0:
+
50 return .5 * dt * this->k_v[0][j];
+
51 case 1:
+
52 return .5 * dt * this->k_v[1][j];
+
53 case 2:
+
54 return dt * this->k_v[2][j];
+
55 case 3:
+
56 return (dt / 6.) * (this->k_v[0][j].eval() + this->k_v[1][j].eval() +
+
57 this->k_v[2][j].eval() + this->k_v[3][j].eval());
+
58 default:
+
59 std::cout << "Not valid!" << std::endl;
+
60 abort();
+
61 }
+
62}
63
-
64}
-
65
- -
67{
-
68
-
69}
-
70
- -
72{
-
73
-
74}
+
64vec_3d PenningTrap::r_func(unsigned int i, unsigned int j, double dt)
+
65{
+
66 switch (i) {
+
67 case 0:
+
68 return .5 * dt * this->k_r[0][j];
+
69 case 1:
+
70 return .5 * dt * this->k_r[1][j];
+
71 case 2:
+
72 return dt * this->k_r[2][j];
+
73 case 3:
+
74 return (dt / 6.) * (this->k_r[0][j].eval() + this->k_r[1][j].eval() +
+
75 this->k_r[2][j].eval() + this->k_r[3][j].eval());
+
76 default:
+
77 std::cout << "Not valid!" << std::endl;
+
78 abort();
+
79 }
+
80}
+
81
+ +
83{
+
84 this->particles.push_back(particle);
+
85}
+
86
+ +
88{
+
89 r(2) *= -2.;
+
90 double f = this->V_0(this->t) / (this->d * this->d);
+
91
+
92 return f * r;
+
93}
+
94
+ +
96{
+
97 return vec_3d{0., 0., this->B_0};
+
98}
+
99
+
100vec_3d PenningTrap::force_on_particle(unsigned int i, unsigned int j)
+
101{
+
102 Particle p_j = this->particles[j];
+
103 // Calculate the difference between the particles' position
+
104 vec_3d res = this->particles[i].r_vec - p_j.r_vec;
+
105
+
106 // Get the distance between the particles
+
107 double norm = arma::norm(res, 2);
+
108
+
109 // Multiply res with p_j's charge divided by the norm cubed
+
110
+
111 return vec_3d(res * p_j.q / (norm * norm * norm));
+
112}
+
113
+ +
115{
+
116 Particle p = this->particles[i];
+
117
+
118 if (arma::norm(p.r_vec) > this->d) {
+
119 return vec_3d{0., 0., 0.};
+
120 }
+
121
+
122 vec_3d force =
+
123 p.q * (this->external_E_field(p.r_vec) +
+
124 arma::cross(p.v_vec, this->external_B_field(p.r_vec)));
+
125
+
126 return force;
+
127}
+
128
+ +
130{
+
131 Particle p = this->particles[i];
+
132
+
133 vec_3d res;
+
134
+
135 for (size_t j = 0; j < this->particles.size(); j++) {
+
136 if (i == j) {
+
137 continue;
+
138 }
+
139
+
140 res += this->force_on_particle(i, j);
+
141 }
+
142
+
143 return vec_3d(res * K_E * (p.q / p.m));
+
144}
+
145
+ +
147{
+
148 return this->total_force_external(i) - this->total_force_particles(i);
+
149}
+
150
+
151void PenningTrap::evolve_RK4(double dt, bool particle_interaction)
+
152{
+
153
+
154 std::vector<Particle> original_particles = this->particles;
+
155 std::vector<Particle> tmp_particles = this->particles;
+
156
+
157 vec_3d (PenningTrap::*force)(unsigned int);
+
158 if (particle_interaction) {
+ +
160 }
+
161 else {
+ +
163 }
+
164
+
165 size_t size = this->particles.size();
+
166
+
167 this->k_v = sim_arr(4, sim_cols(size));
+
168 this->k_r = sim_arr(4, sim_cols(size));
+
169
+
170 for (size_t i = 0; i < 4; i++) {
+
171#pragma omp parallel for
+
172 for (size_t j = 0; j < this->particles.size(); j++) {
+
173 this->k_v[i][j] = (this->*force)(j) / this->particles[j].m;
+
174 this->k_r[i][j] = this->particles[j].v_vec;
+
175
+
176 Particle *p = &tmp_particles[j];
+
177
+
178 p->v_vec = original_particles[j].v_vec + this->v_func(i, j, dt);
+
179 p->r_vec = original_particles[j].r_vec + this->r_func(i, j, dt);
+
180 }
+
181 this->particles = tmp_particles;
+
182 }
+
183 this->t += dt;
+
184}
+
185
+
186void PenningTrap::evolve_forward_euler(double dt, bool particle_interaction)
+
187{
+
188 std::vector<Particle> new_state = this->particles;
+
189
+
190 Particle *p;
+
191
+
192 vec_3d (PenningTrap::*force)(unsigned int);
+
193 if (particle_interaction) {
+ +
195 }
+
196 else {
+ +
198 }
+
199
+
200#pragma omp parallel for private(p)
+
201 for (size_t i = 0; i < this->particles.size(); i++) {
+
202 p = &new_state[i];
+
203 p->v_vec += dt * (this->*force)(i) / p->m;
+
204 p->r_vec += dt * this->particles[i].v_vec;
+
205 }
+
206
+
207 this->particles = new_state;
+
208 this->t += dt;
+
209}
+
210
+
211sim_arr PenningTrap::simulate(double time, unsigned int steps,
+
212 std::string method, bool particle_interaction)
+
213{
+
214 double dt = time / (double)steps;
+
215
+
216 sim_arr res(this->particles.size(), sim_cols(steps));
+
217
+
218 void (PenningTrap::*func)(double, bool);
+
219 if (method == "rk4") {
+ +
221 }
+
222 else if (method == "euler") {
+ +
224 }
+
225 else {
+
226 std::cout << "Not a valid method!" << std::endl;
+
227 abort();
+
228 }
+
229
+
230 for (size_t j = 0; j < steps; j++) {
+
231 for (size_t i = 0; i < this->particles.size(); i++) {
+
232 res[i][j] = this->particles[i].r_vec;
+
233 }
+
234 (this->*func)(dt, particle_interaction);
+
235 }
+
236
+
237 return res;
+
238}
+
239
+
240void PenningTrap::write_simulation_to_dir(std::string path, double time,
+
241 int steps, std::string method,
+
242 bool particle_interaction)
+
243{
+
244 if (path.back() != '/') {
+
245 path += '/';
+
246 }
+
247 if (mkpath(path, 0777) != 0) {
+
248 std::cout << "Hello" << std::endl;
+
249 return;
+
250 }
+
251
+
252 sim_arr res = this->simulate(time, steps, method, particle_interaction);
+
253
+
254 std::ofstream ofile;
+
255
+
256#pragma omp parallel for private(ofile)
+
257 for (size_t i = 0; i < this->particles.size(); i++) {
+
258 ofile.open(path + "particle_" + std::to_string(i) + ".txt");
+
259 for (vec_3d &vec : res[i]) {
+
260 ofile << vec(0) << "," << vec(1) << "," << vec(2) << "\n";
+
261 }
+
262 ofile.close();
+
263 }
+
264}
+
265
+
266double PenningTrap::fraction_of_particles_left(double time, unsigned int steps, std::string method, bool particle_interaction)
+
267{
+
268 sim_arr res = this->simulate(time, steps, method, particle_interaction);
+
269
+
270 int particles_left = 0;
+
271
+
272 for (Particle p : this->particles) {
+
273 if (arma::norm(p.r_vec) < this->d) {
+
274 particles_left++;
+
275 }
+
276 }
+
277
+
278 return (double) particles_left / (double) this->particles.size();
+
279}
+
280
A class for simulating a Penning trap.
-
A class that holds attributes of a particle.
Definition: Particle.hpp:19
-
arma::vec total_force_external(int i)
Calculate the total external force on a particle.
Definition: PenningTrap.cpp:51
-
arma::vec total_force_particles(int i)
Calculate the total force on a particle from other particles.
Definition: PenningTrap.cpp:56
-
arma::vec external_B_field(arma::vec r)
Calculate B at point r.
Definition: PenningTrap.cpp:41
-
arma::vec force_on_particle(int i, int j)
Calculate the force between 2 particles.
Definition: PenningTrap.cpp:46
-
void evolve_forward_euler(double dt)
Go forward one timestep using the forward Euler method.
Definition: PenningTrap.cpp:71
-
void add_particle(Particle particle)
Add a particle to the system.
Definition: PenningTrap.cpp:31
-
PenningTrap(double B_0=T, double V_0=25.*V/1000., double d=500.)
Set B_0, V_0 and d.
Definition: PenningTrap.cpp:26
-
arma::vec total_force(int i)
calculate the total force on a particle.
Definition: PenningTrap.cpp:61
-
arma::vec external_E_field(arma::vec r)
Calculate E at point r.
Definition: PenningTrap.cpp:36
-
void evolve_RK4(double dt)
Go forward one timestep using the RK4 method.
Definition: PenningTrap.cpp:66
+
A class that holds attributes of a particle.
Definition: Particle.hpp:21
+
double q
Charge.
Definition: Particle.hpp:23
+
vec_3d v_vec
velocity
Definition: Particle.hpp:26
+
double m
Mass.
Definition: Particle.hpp:24
+
vec_3d r_vec
position
Definition: Particle.hpp:25
+
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:30
+
std::vector< Particle > particles
The particles in the Penning trap.
Definition: PenningTrap.hpp:36
+
double fraction_of_particles_left(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate and calculate what fraction of particles are still left inside the Penning trap after the si...
+
double B_0
Magnetic field strength.
Definition: PenningTrap.hpp:32
+
vec_3d external_E_field(vec_3d r)
Calculate E at point r.
Definition: PenningTrap.cpp:87
+
vec_3d total_force(unsigned int i)
calculate the total force on a particle p_i.
+
sim_arr k_r
Definition: PenningTrap.hpp:39
+
void evolve_RK4(double dt, bool particle_interaction=true)
Go forward one timestep using the RK4 method.
+
vec_3d r_func(unsigned int i, unsigned int j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:64
+
vec_3d total_force_particles(unsigned int i)
Calculate the total force on a particle p_i from other particles.
+
sim_arr simulate(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate the particle system inside the Penning trap over a certain amount of time.
+
double d
Characteristic dimension.
Definition: PenningTrap.hpp:34
+
void add_particle(Particle particle)
Add a particle to the system.
Definition: PenningTrap.cpp:82
+
double t
Current time.
Definition: PenningTrap.hpp:35
+
vec_3d force_on_particle(unsigned int i, unsigned int j)
Calculate the force between 2 particles.
+
std::function< double(double)> V_0
Applied potential.
Definition: PenningTrap.hpp:33
+
void evolve_forward_euler(double dt, bool particle_interaction=true)
Go forward one timestep using the forward Euler method.
+
void write_simulation_to_dir(std::string path, double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate and write the displacement of all particles to files.
+
vec_3d external_B_field(vec_3d r)
Calculate B at point r.
Definition: PenningTrap.cpp:95
+
PenningTrap(double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)
Constructor for the PenningTrap class.
Definition: PenningTrap.cpp:18
+
vec_3d total_force_external(unsigned int i)
Calculate the total external force on a particle.
+
sim_arr k_v
Definition: PenningTrap.hpp:37
+
vec_3d v_func(unsigned int i, unsigned int j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:46
+
Library of constants.
+
#define K_E
Coulomb constant. unit: .
Definition: constants.hpp:15
+
Useful typedefs for cleaner code.
+
std::vector< arma::vec::fixed< 3 > > sim_cols
Typedef for the column of the result vector from simulating particles.
Definition: typedefs.hpp:24
+
arma::vec::fixed< 3 > vec_3d
Typedef for a fixed 3d arma vector.
Definition: typedefs.hpp:36
+
std::vector< sim_cols > sim_arr
Typedef for the result of the simulate method.
Definition: typedefs.hpp:32
+
Function prototypes and macros that are useful.
+
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:76
diff --git a/docs/PenningTrap_8hpp.html b/docs/PenningTrap_8hpp.html index 8e1232f..5f6ee45 100644 --- a/docs/PenningTrap_8hpp.html +++ b/docs/PenningTrap_8hpp.html @@ -107,8 +107,10 @@ $(document).ready(function(){initNavTree('PenningTrap_8hpp.html',''); initResiza

A class for simulating a Penning trap. More...

#include <armadillo>
-#include "constants.hpp"
+#include <omp.h>
#include "Particle.hpp"
+#include "constants.hpp"
+#include "typedefs.hpp"

Go to the source code of this file.

diff --git a/docs/PenningTrap_8hpp_source.html b/docs/PenningTrap_8hpp_source.html index 6ed7402..dfdddbe 100644 --- a/docs/PenningTrap_8hpp_source.html +++ b/docs/PenningTrap_8hpp_source.html @@ -106,59 +106,110 @@ $(document).ready(function(){initNavTree('PenningTrap_8hpp_source.html',''); ini
13#define __PENNING_TRAP__
14
15#include <armadillo>
-
16
-
17#include "constants.hpp"
+
16#include <omp.h>
+
17
18#include "Particle.hpp"
-
19
-
25class PenningTrap {
-
26private:
-
27 double B_0;
-
28 double V_0;
-
29 double d;
-
30 std::vector<Particle> particles;
-
31
-
32public:
-
35 PenningTrap(double B_0 = T, double V_0 = 25.*V/1000., double d = 500.);
-
36
-
39 void add_particle(Particle particle);
-
40
-
43 arma::vec external_E_field(arma::vec r);
-
44
-
47 arma::vec external_B_field(arma::vec r);
-
48
-
54 arma::vec force_on_particle(int i, int j);
-
55
-
61 arma::vec total_force_external(int i);
-
62
-
65 arma::vec total_force_particles(int i);
-
66
-
69 arma::vec total_force(int i);
-
70
-
73 void evolve_RK4(double dt);
-
74
-
77 void evolve_forward_euler(double dt);
-
78};
+
19#include "constants.hpp"
+
20#include "typedefs.hpp"
+
21
+
22#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \
+
23 initializer(omp_priv = omp_orig)
+
24
+
30class PenningTrap {
+
31private:
+
32 double B_0;
+
33 std::function<double(double)> V_0;
+
34 double d;
+
35 double t;
+
36 std::vector<Particle> particles;
+
37 sim_arr k_v;
+
39 sim_arr k_r;
+
41
+
52 vec_3d v_func(unsigned int i, unsigned int j, double dt);
+
53
+
64 vec_3d r_func(unsigned int i, unsigned int j, double dt);
+
65
+
66public:
+
74 PenningTrap(
+
75 double B_0 = T,
+
76 std::function<double(double)> V_0 =
+
77 [](double t) { return 25. * V / 1000.; },
+
78 double d = 500., double t = 0.);
79
-
80#endif
+
88 PenningTrap(
+
89 unsigned int i, double B_0 = T,
+
90 std::function<double(double)> V_0 =
+
91 [](double t) { return 25. * V / 1000.; },
+
92 double d = 500., double t = 0.);
+
93
+
102 PenningTrap(
+
103 std::vector<Particle> particles, double B_0 = T,
+
104 std::function<double(double)> V_0 =
+
105 [](double t) { return 25. * V / 1000.; },
+
106 double d = 500., double t = 0.);
+
107
+
112 void add_particle(Particle particle);
+
113
+
120 vec_3d external_E_field(vec_3d r);
+
121
+
128 vec_3d external_B_field(vec_3d r);
+
129
+
140 vec_3d force_on_particle(unsigned int i, unsigned int j);
+
141
+
151 vec_3d total_force_external(unsigned int i);
+
152
+
159 vec_3d total_force_particles(unsigned int i);
+
160
+
167 vec_3d total_force(unsigned int i);
+
168
+
174 void evolve_RK4(double dt, bool particle_interaction = true);
+
175
+
181 void evolve_forward_euler(double dt, bool particle_interaction = true);
+
182
+
191 sim_arr simulate(double time, unsigned int steps,
+
192 std::string method = "rk4",
+
193 bool particle_interaction = true);
+
194
+
203 void write_simulation_to_dir(std::string path, double time,
+
204 unsigned int steps, std::string method = "rk4",
+
205 bool particle_interaction = true);
+
206
+
217 double fraction_of_particles_left(double time, unsigned int steps,
+
218 std::string method = "rk4",
+
219 bool particle_interaction = true);
+
220};
+
221
+
222#endif
Particle.hpp
A class that holds the properties of a particle.
-
Particle
A class that holds attributes of a particle.
Definition: Particle.hpp:19
-
PenningTrap
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:25
-
PenningTrap::particles
std::vector< Particle > particles
The particles in the Penning trap.
Definition: PenningTrap.hpp:30
-
PenningTrap::total_force_external
arma::vec total_force_external(int i)
Calculate the total external force on a particle.
Definition: PenningTrap.cpp:51
-
PenningTrap::B_0
double B_0
Magnetic field strength.
Definition: PenningTrap.hpp:27
-
PenningTrap::total_force_particles
arma::vec total_force_particles(int i)
Calculate the total force on a particle from other particles.
Definition: PenningTrap.cpp:56
-
PenningTrap::external_B_field
arma::vec external_B_field(arma::vec r)
Calculate B at point r.
Definition: PenningTrap.cpp:41
-
PenningTrap::force_on_particle
arma::vec force_on_particle(int i, int j)
Calculate the force between 2 particles.
Definition: PenningTrap.cpp:46
-
PenningTrap::evolve_forward_euler
void evolve_forward_euler(double dt)
Go forward one timestep using the forward Euler method.
Definition: PenningTrap.cpp:71
-
PenningTrap::d
double d
Characteristic dimension.
Definition: PenningTrap.hpp:29
-
PenningTrap::add_particle
void add_particle(Particle particle)
Add a particle to the system.
Definition: PenningTrap.cpp:31
-
PenningTrap::V_0
double V_0
Applied potential.
Definition: PenningTrap.hpp:28
-
PenningTrap::total_force
arma::vec total_force(int i)
calculate the total force on a particle.
Definition: PenningTrap.cpp:61
-
PenningTrap::external_E_field
arma::vec external_E_field(arma::vec r)
Calculate E at point r.
Definition: PenningTrap.cpp:36
-
PenningTrap::evolve_RK4
void evolve_RK4(double dt)
Go forward one timestep using the RK4 method.
Definition: PenningTrap.cpp:66
+
Particle
A class that holds attributes of a particle.
Definition: Particle.hpp:21
+
PenningTrap
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:30
+
PenningTrap::particles
std::vector< Particle > particles
The particles in the Penning trap.
Definition: PenningTrap.hpp:36
+
PenningTrap::fraction_of_particles_left
double fraction_of_particles_left(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate and calculate what fraction of particles are still left inside the Penning trap after the si...
Definition: PenningTrap.cpp:266
+
PenningTrap::B_0
double B_0
Magnetic field strength.
Definition: PenningTrap.hpp:32
+
PenningTrap::external_E_field
vec_3d external_E_field(vec_3d r)
Calculate E at point r.
Definition: PenningTrap.cpp:87
+
PenningTrap::total_force
vec_3d total_force(unsigned int i)
calculate the total force on a particle p_i.
Definition: PenningTrap.cpp:146
+
PenningTrap::k_r
sim_arr k_r
Definition: PenningTrap.hpp:39
+
PenningTrap::evolve_RK4
void evolve_RK4(double dt, bool particle_interaction=true)
Go forward one timestep using the RK4 method.
Definition: PenningTrap.cpp:151
+
PenningTrap::r_func
vec_3d r_func(unsigned int i, unsigned int j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:64
+
PenningTrap::total_force_particles
vec_3d total_force_particles(unsigned int i)
Calculate the total force on a particle p_i from other particles.
Definition: PenningTrap.cpp:129
+
PenningTrap::simulate
sim_arr simulate(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate the particle system inside the Penning trap over a certain amount of time.
Definition: PenningTrap.cpp:211
+
PenningTrap::d
double d
Characteristic dimension.
Definition: PenningTrap.hpp:34
+
PenningTrap::add_particle
void add_particle(Particle particle)
Add a particle to the system.
Definition: PenningTrap.cpp:82
+
PenningTrap::t
double t
Current time.
Definition: PenningTrap.hpp:35
+
PenningTrap::force_on_particle
vec_3d force_on_particle(unsigned int i, unsigned int j)
Calculate the force between 2 particles.
Definition: PenningTrap.cpp:100
+
PenningTrap::V_0
std::function< double(double)> V_0
Applied potential.
Definition: PenningTrap.hpp:33
+
PenningTrap::evolve_forward_euler
void evolve_forward_euler(double dt, bool particle_interaction=true)
Go forward one timestep using the forward Euler method.
Definition: PenningTrap.cpp:186
+
PenningTrap::write_simulation_to_dir
void write_simulation_to_dir(std::string path, double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate and write the displacement of all particles to files.
Definition: PenningTrap.cpp:240
+
PenningTrap::external_B_field
vec_3d external_B_field(vec_3d r)
Calculate B at point r.
Definition: PenningTrap.cpp:95
+
PenningTrap::total_force_external
vec_3d total_force_external(unsigned int i)
Calculate the total external force on a particle.
Definition: PenningTrap.cpp:114
+
PenningTrap::k_v
sim_arr k_v
Definition: PenningTrap.hpp:37
+
PenningTrap::v_func
vec_3d v_func(unsigned int i, unsigned int j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:46
constants.hpp
Library of constants.
T
#define T
1 Tesla. unit:
Definition: constants.hpp:17
V
#define V
1 Volt. unit:
Definition: constants.hpp:19
+
typedefs.hpp
Useful typedefs for cleaner code.
+
vec_3d
arma::vec::fixed< 3 > vec_3d
Typedef for a fixed 3d arma vector.
Definition: typedefs.hpp:36
+
sim_arr
std::vector< sim_cols > sim_arr
Typedef for the result of the simulate method.
Definition: typedefs.hpp:32
diff --git a/docs/animate__100__particles_8py_source.html b/docs/animate__100__particles_8py_source.html new file mode 100644 index 0000000..af734ca --- /dev/null +++ b/docs/animate__100__particles_8py_source.html @@ -0,0 +1,185 @@ + + + + + + + +Penning Trap Simulation: src/animate_100_particles.py Source File + + + + + + + + + + + + + + + + +
+
+
+ + + + + +
+
Penning Trap Simulation +
+
Simulate particle behavior inside a Penning Trap
+
+ + + + + + + + + +
+ +
+
+
+ +
+ +
+
+ + +
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+ +
+
animate_100_particles.py
+
+
+
1import matplotlib.pyplot as plt
+
2import numpy as np
+
3from matplotlib import animation
+
4from mpl_toolkits.mplot3d import Axes3D
+
5
+
6
+
7def get_data(files):
+
8 res = []
+
9 for file in files:
+
10 arr = [[], [], []]
+
11 with open(file, encoding="utf8") as f:
+
12 lines = f.readlines()
+
13
+
14 for line in lines:
+
15 xi, yi, zi = map(float, line.strip().split(","))
+
16 arr[0].append(xi)
+
17 arr[1].append(yi)
+
18 arr[2].append(zi)
+
19 res.append(arr)
+
20
+
21 return np.array(res)
+
22
+
23
+
24def update(num, lines, arr):
+
25 for line, a in zip(lines, arr):
+
26 line.set_data(a[:2, num - 1 : num])
+
27 line.set_3d_properties(a[2, num])
+
28
+
29
+
30def animate():
+
31 plt.style.use("dark_background")
+
32 fig = plt.figure()
+
33 ax = fig.add_subplot(projection="3d")
+
34
+
35 arr = get_data([f"output/simulate_100_particles/particle_{i}.txt" for i in range(100)])
+
36
+
37 arr = arr[:, :, ::10]
+
38
+
39 N = len(arr[0][0])
+
40
+
41 lines = [ax.plot(*a[:, 1], "o")[0] for a in arr]
+
42
+
43 ax.set_title("100 particles inside a Penning trap")
+
44 plt.figtext(
+
45 0.5,
+
46 0.01,
+
47 "100 randomly generated particles "
+
48 "evolving over a time of 50 microseconds.",
+
49 fontsize=12,
+
50 horizontalalignment="center",
+
51 )
+
52
+
53 ax.set_xlim3d([-500.0, 500.0])
+
54 ax.set_xlabel("X (micrometers)")
+
55
+
56 ax.set_ylim3d([-500.0, 500.0])
+
57 ax.set_ylabel("Y (micrometers)")
+
58
+
59 ax.set_zlim3d([-500.0, 500.0])
+
60 ax.set_zlabel("Z (micrometers)")
+
61
+
62 ani = animation.FuncAnimation(
+
63 fig, update, N, fargs=(lines, arr), interval=1, blit=False
+
64 )
+
65
+
66 # ani.save("../images/100_particles.gif", writer=animation.FFMpegFileWriter(fps=50))
+
67 plt.show()
+
68
+
69
+
70if __name__ == "__main__":
+
71 animate()
+
+
+ + + + diff --git a/docs/annotated.html b/docs/annotated.html index 7f9374f..fdee9b2 100644 --- a/docs/annotated.html +++ b/docs/annotated.html @@ -105,6 +105,7 @@ $(document).ready(function(){initNavTree('annotated.html',''); initResizable(); +
 CParticleA class that holds attributes of a particle
 CPenningTrapA class that simulates a Penning trap
 CPenningTrapTest
diff --git a/docs/annotated_dup.js b/docs/annotated_dup.js index 1f9034f..574cc6b 100644 --- a/docs/annotated_dup.js +++ b/docs/annotated_dup.js @@ -1,5 +1,6 @@ var annotated_dup = [ [ "Particle", "classParticle.html", "classParticle" ], - [ "PenningTrap", "classPenningTrap.html", "classPenningTrap" ] + [ "PenningTrap", "classPenningTrap.html", "classPenningTrap" ], + [ "PenningTrapTest", "classPenningTrapTest.html", null ] ]; \ No newline at end of file diff --git a/docs/bug.html b/docs/bug.html index bbcbbea..8ed5241 100644 --- a/docs/bug.html +++ b/docs/bug.html @@ -105,21 +105,23 @@ $(document).ready(function(){initNavTree('bug.html',''); initResizable(); });
File constants.hpp
No known bugs
File main.cpp
-
No known bugs
+
No known bugs
File Particle.cpp
-
No known bugs
+
No known bugs
File Particle.hpp
No known bugs
File PenningTrap.cpp
-
No known bugs
+
No known bugs
File PenningTrap.hpp
No known bugs
File test_suite.cpp
-
No known bugs
-
File utils.cpp
No known bugs
+
File typedefs.hpp
+
No known bugs
+
File utils.cpp
+
No known bugs
File utils.hpp
-
No known bugs
+
No known bugs
diff --git a/docs/classParticle-members.html b/docs/classParticle-members.html index 02f2b23..b3fc92b 100644 --- a/docs/classParticle-members.html +++ b/docs/classParticle-members.html @@ -105,11 +105,11 @@ $(document).ready(function(){initNavTree('classParticle.html',''); initResizable

This is the complete list of members for Particle, including all inherited members.

- + - - + +
mParticleprivate
Particle(double q, double m, arma::vec::fixed< 3 > r_vec, arma::vec::fixed< 3 > v_vec)Particle
Particle(double q, double m, vec_3d r_vec, vec_3d v_vec)Particle
PenningTrapParticlefriend
qParticleprivate
r_vecParticleprivate
v_vecParticleprivate
r_vecParticleprivate
v_vecParticleprivate
diff --git a/docs/classParticle.html b/docs/classParticle.html index 0fcbb7a..271a213 100644 --- a/docs/classParticle.html +++ b/docs/classParticle.html @@ -114,9 +114,9 @@ $(document).ready(function(){initNavTree('classParticle.html',''); initResizable - - - + + +

Public Member Functions

 Particle (double q, double m, arma::vec::fixed< 3 > r_vec, arma::vec::fixed< 3 > v_vec)
 Initialize the particle.
 
 Particle (double q, double m, vec_3d r_vec, vec_3d v_vec)
 Initialize the particle.
 
@@ -126,12 +126,12 @@ Private Attributes - - - - - - + + + + + +

Private Attributes

double m
 Mass.
 
arma::vec::fixed< 3 > r_vec
 position
 
arma::vec::fixed< 3 > v_vec
 velocity
 
vec_3d r_vec
 position
 
vec_3d v_vec
 velocity
 
@@ -142,10 +142,10 @@ Friends

Detailed Description

A class that holds attributes of a particle.

-

Definition at line 19 of file Particle.hpp.

+

Definition at line 21 of file Particle.hpp.

Constructor & Destructor Documentation

- -

◆ Particle()

+ +

◆ Particle()

@@ -165,13 +165,13 @@ Friends
- + - + @@ -183,9 +183,18 @@ Friends

Initialize the particle.

-

Initialize the particle with a charge, mass, position and velocity.

+

Initialize the particle with a charge, mass, position and velocity.

+
Parameters
+

Friends

arma::vec::fixed< 3 > vec_3d  r_vec,
arma::vec::fixed< 3 > vec_3d  v_vec 
+ + + + +
qThe charge of the particle
mThe mass of the particle
r_vecThe initial position of the particle
v_vecThe initial velocity of the particle
+ + -

Definition at line 17 of file Particle.cpp.

+

Definition at line 15 of file Particle.cpp.

@@ -212,7 +221,7 @@ Friends

Make private attributes available for PenningTrap.

-

Definition at line 38 of file Particle.hpp.

+

Definition at line 43 of file Particle.hpp.

@@ -239,7 +248,7 @@ Friends

Mass.

-

Definition at line 22 of file Particle.hpp.

+

Definition at line 24 of file Particle.hpp.

@@ -265,12 +274,12 @@ Friends

Charge.

-

Definition at line 21 of file Particle.hpp.

+

Definition at line 23 of file Particle.hpp.

- -

◆ r_vec

+ +

◆ r_vec

@@ -279,7 +288,7 @@ Friends - +
arma::vec::fixed<3> Particle::r_vecvec_3d Particle::r_vec
@@ -291,12 +300,12 @@ Friends

position

-

Definition at line 23 of file Particle.hpp.

+

Definition at line 25 of file Particle.hpp.

- -

◆ v_vec

+ +

◆ v_vec

@@ -305,7 +314,7 @@ Friends - +
arma::vec::fixed<3> Particle::v_vecvec_3d Particle::v_vec
@@ -317,7 +326,7 @@ Friends

velocity

-

Definition at line 24 of file Particle.hpp.

+

Definition at line 26 of file Particle.hpp.

diff --git a/docs/classParticle.js b/docs/classParticle.js index 113132c..71255c1 100644 --- a/docs/classParticle.js +++ b/docs/classParticle.js @@ -1,9 +1,9 @@ var classParticle = [ - [ "Particle", "classParticle.html#a00e108823877a25513ccae7cac011b4c", null ], + [ "Particle", "classParticle.html#a7af9f8d1fef63dd7643b06629ac7bef4", null ], [ "PenningTrap", "classParticle.html#aa797d319549dc2a0beb06cdbfd430232", null ], [ "m", "classParticle.html#aedcc7e1bc53b0e2b1a4a07c9a1b47563", null ], [ "q", "classParticle.html#a566dcc1de4bdc01251776948798ea8e1", null ], - [ "r_vec", "classParticle.html#acf1a0f3c978b06d76df5bb4279594467", null ], - [ "v_vec", "classParticle.html#a4a5d22c7aeca66f67d083f270cba25df", null ] + [ "r_vec", "classParticle.html#af9497cd8f2dcad0fad54f571ddb383e6", null ], + [ "v_vec", "classParticle.html#a879692772803d6ab65fa4993b54aea6e", null ] ]; \ No newline at end of file diff --git a/docs/classPenningTrap-members.html b/docs/classPenningTrap-members.html index dd46fd6..859c052 100644 --- a/docs/classPenningTrap-members.html +++ b/docs/classPenningTrap-members.html @@ -107,17 +107,27 @@ $(document).ready(function(){initNavTree('classPenningTrap.html',''); initResiza add_particle(Particle particle)PenningTrap B_0PenningTrapprivate dPenningTrapprivate - evolve_forward_euler(double dt)PenningTrap - evolve_RK4(double dt)PenningTrap - external_B_field(arma::vec r)PenningTrap - external_E_field(arma::vec r)PenningTrap - force_on_particle(int i, int j)PenningTrap - particlesPenningTrapprivate - PenningTrap(double B_0=T, double V_0=25.*V/1000., double d=500.)PenningTrap - total_force(int i)PenningTrap - total_force_external(int i)PenningTrap - total_force_particles(int i)PenningTrap - V_0PenningTrapprivate + evolve_forward_euler(double dt, bool particle_interaction=true)PenningTrap + evolve_RK4(double dt, bool particle_interaction=true)PenningTrap + external_B_field(vec_3d r)PenningTrap + external_E_field(vec_3d r)PenningTrap + force_on_particle(unsigned int i, unsigned int j)PenningTrap + fraction_of_particles_left(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)PenningTrap + k_rPenningTrapprivate + k_vPenningTrapprivate + particlesPenningTrapprivate + PenningTrap(double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)PenningTrap + PenningTrap(unsigned int i, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)PenningTrap + PenningTrap(std::vector< Particle > particles, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)PenningTrap + r_func(unsigned int i, unsigned int j, double dt)PenningTrapprivate + simulate(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)PenningTrap + tPenningTrapprivate + total_force(unsigned int i)PenningTrap + total_force_external(unsigned int i)PenningTrap + total_force_particles(unsigned int i)PenningTrap + V_0PenningTrapprivate + v_func(unsigned int i, unsigned int j, double dt)PenningTrapprivate + write_simulation_to_dir(std::string path, double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)PenningTrap diff --git a/docs/classPenningTrap.html b/docs/classPenningTrap.html index fcbbf79..9afb617 100644 --- a/docs/classPenningTrap.html +++ b/docs/classPenningTrap.html @@ -100,6 +100,7 @@ $(document).ready(function(){initNavTree('classPenningTrap.html',''); initResiza
Public Member Functions | +Private Member Functions | Private Attributes | List of all members
PenningTrap Class Reference
@@ -113,60 +114,91 @@ $(document).ready(function(){initNavTree('classPenningTrap.html',''); initResiza - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

 PenningTrap (double B_0=T, double V_0=25.*V/1000., double d=500.)
 Set B_0, V_0 and d.
 
 PenningTrap (double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)
 Constructor for the PenningTrap class.
 
 PenningTrap (unsigned int i, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)
 Constructor for the PenningTrap class.
 
 PenningTrap (std::vector< Particle > particles, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)
 Constructor for the PenningTrap class.
 
void add_particle (Particle particle)
 Add a particle to the system.
 
arma::vec external_E_field (arma::vec r)
 Calculate E at point r.
 
arma::vec external_B_field (arma::vec r)
 Calculate B at point r.
 
arma::vec force_on_particle (int i, int j)
 Calculate the force between 2 particles.
 
arma::vec total_force_external (int i)
 Calculate the total external force on a particle.
 
arma::vec total_force_particles (int i)
 Calculate the total force on a particle from other particles.
 
arma::vec total_force (int i)
 calculate the total force on a particle.
 
void evolve_RK4 (double dt)
 Go forward one timestep using the RK4 method.
 
void evolve_forward_euler (double dt)
 Go forward one timestep using the forward Euler method.
 
vec_3d external_E_field (vec_3d r)
 Calculate E at point r.
 
vec_3d external_B_field (vec_3d r)
 Calculate B at point r.
 
vec_3d force_on_particle (unsigned int i, unsigned int j)
 Calculate the force between 2 particles.
 
vec_3d total_force_external (unsigned int i)
 Calculate the total external force on a particle.
 
vec_3d total_force_particles (unsigned int i)
 Calculate the total force on a particle p_i from other particles.
 
vec_3d total_force (unsigned int i)
 calculate the total force on a particle p_i.
 
void evolve_RK4 (double dt, bool particle_interaction=true)
 Go forward one timestep using the RK4 method.
 
void evolve_forward_euler (double dt, bool particle_interaction=true)
 Go forward one timestep using the forward Euler method.
 
sim_arr simulate (double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
 Simulate the particle system inside the Penning trap over a certain amount of time.
 
void write_simulation_to_dir (std::string path, double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
 Simulate and write the displacement of all particles to files.
 
double fraction_of_particles_left (double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
 Simulate and calculate what fraction of particles are still left inside the Penning trap after the simulation.
 
+ + + + + + +

+Private Member Functions

vec_3d v_func (unsigned int i, unsigned int j, double dt)
 Helper for evolve_RK4 when calculating \(k_{v,i,j}\) values.
 
vec_3d r_func (unsigned int i, unsigned int j, double dt)
 Helper for evolve_RK4 when calculating \(k_{r,i,j}\) values.
 
- - - + + + + + + + + + +

Private Attributes

double B_0
 Magnetic field strength.
 
double V_0
 Applied potential.
 
std::function< double(double)> V_0
 Applied potential.
 
double d
 Characteristic dimension.
 
double t
 Current time.
 
std::vector< Particleparticles
 The particles in the Penning trap.
 
sim_arr k_v
 
sim_arr k_r
 

Detailed Description

A class that simulates a Penning trap.

This class simulates a Penning trap. It can take in a number of particles and simulate how they would behave inside a Penning trap.

-

Definition at line 25 of file PenningTrap.hpp.

+

Definition at line 30 of file PenningTrap.hpp.

Constructor & Destructor Documentation

- -

◆ PenningTrap()

+ +

◆ PenningTrap() [1/3]

@@ -180,14 +212,20 @@ Private Attributes - double  - V_0 = 25.*V/1000., + std::function< double(double)>  + V_0 = [](double t) { return 25. * V / 1000.; }, double  - d = 500.  + d = 500., + + + + + double  + t = 0.  @@ -197,9 +235,138 @@ Private Attributes
-

Set B_0, V_0 and d.

+

Constructor for the PenningTrap class.

+
Parameters
+ + + + + +
B_0The magnetic field strength
V_0The time dependent applied potential
dThe characteristic dimension
tThe starting time
+
+
-

Definition at line 26 of file PenningTrap.cpp.

+

Definition at line 18 of file PenningTrap.cpp.

+ +
+
+ +

◆ PenningTrap() [2/3]

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PenningTrap::PenningTrap (unsigned int i,
double B_0 = T,
std::function< double(double)> V_0 = [](double t) { return 25. * V / 1000.; },
double d = 500.,
double t = 0. 
)
+
+ +

Constructor for the PenningTrap class.

+
Parameters
+ + + + + + +
iThe number of particles to generate
B_0The magnetic field strength
V_0The time dependent applied potential
dThe characteristic dimension
tThe starting time
+
+
+ +

Definition at line 27 of file PenningTrap.cpp.

+ +
+
+ +

◆ PenningTrap() [3/3]

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PenningTrap::PenningTrap (std::vector< Particleparticles,
double B_0 = T,
std::function< double(double)> V_0 = [](double t) { return 25. * V / 1000.; },
double d = 500.,
double t = 0. 
)
+
+ +

Constructor for the PenningTrap class.

+
Parameters
+ + + + + + +
particlesThe starting particles
B_0The magnetic field strength
V_0The time dependent applied potential
dThe characteristic dimension
tThe starting time
+
+
+ +

Definition at line 39 of file PenningTrap.cpp.

@@ -221,13 +388,19 @@ Private Attributes

Add a particle to the system.

+
Parameters
+ + +
particleThe particle to add to the Penning trap
+
+
-

Definition at line 31 of file PenningTrap.cpp.

+

Definition at line 82 of file PenningTrap.cpp.

- -

◆ evolve_forward_euler()

+ +

◆ evolve_forward_euler()

@@ -236,20 +409,37 @@ Private Attributes void PenningTrap::evolve_forward_euler ( double  - dt) + dt, + + + + bool  + particle_interaction = true  + + + + ) +

Go forward one timestep using the forward Euler method.

+
Parameters
+ + + +
dtThe step length
particle_interactionTurn particle interactions on/off
+
+
-

Definition at line 71 of file PenningTrap.cpp.

+

Definition at line 186 of file PenningTrap.cpp.

- -

◆ evolve_RK4()

+ +

◆ evolve_RK4()

@@ -258,28 +448,45 @@ Private Attributes void PenningTrap::evolve_RK4 ( double  - dt) + dt, + + + + bool  + particle_interaction = true  + + + + ) +

Go forward one timestep using the RK4 method.

+
Parameters
+ + + +
dtThe step length
particle_interactionTurn particle interactions on/off
+
+
-

Definition at line 66 of file PenningTrap.cpp.

+

Definition at line 151 of file PenningTrap.cpp.

- -

◆ external_B_field()

+ +

◆ external_B_field()

- + - + @@ -287,21 +494,28 @@ Private Attributes

Calculate B at point r.

+
Parameters
+
arma::vec PenningTrap::external_B_field vec_3d PenningTrap::external_B_field (arma::vec vec_3d  r)
+ +
rThe position where we want to calculate the B field
+ + +
Returns
vec_3d
-

Definition at line 41 of file PenningTrap.cpp.

+

Definition at line 95 of file PenningTrap.cpp.

- -

◆ external_E_field()

+ +

◆ external_E_field()

- + - + @@ -309,27 +523,34 @@ Private Attributes

Calculate E at point r.

+
Parameters
+
arma::vec PenningTrap::external_E_field vec_3d PenningTrap::external_E_field (arma::vec vec_3d  r)
+ +
rThe position where we want to calculate the E field
+ + +
Returns
vec_3d
-

Definition at line 36 of file PenningTrap.cpp.

+

Definition at line 87 of file PenningTrap.cpp.

- -

◆ force_on_particle()

+ +

◆ force_on_particle()

- + - + - + @@ -341,44 +562,222 @@ Private Attributes

Calculate the force between 2 particles.

-

Calculate the force exhibited on particle p_i from particle p_j.

+

Calculate the force exhibited on particle p_i from particle p_j.

+
Parameters
+
arma::vec PenningTrap::force_on_particle vec_3d PenningTrap::force_on_particle (int unsigned int  i,
int unsigned int  j 
+ + +
iThe index of particle p_i
jThe index of particle p_j
+ + +
Returns
vec_3d
-

Definition at line 46 of file PenningTrap.cpp.

+

Definition at line 100 of file PenningTrap.cpp.

- -

◆ total_force()

+ +

◆ fraction_of_particles_left()

- + - + + + + + + + + + + + + + + + + + + + + + + + + + + +
arma::vec PenningTrap::total_force double PenningTrap::fraction_of_particles_left (int double time,
unsigned int steps,
std::string method = "rk4",
bool particle_interaction = true 
)
+
+ +

Simulate and calculate what fraction of particles are still left inside the Penning trap after the simulation.

+
Parameters
+ + + + + +
timeThe time to simulate in microseconds
stepsThe amount of steps for the whole simulation
methodThe method to use when moving forward a timestep
particle_interactionTurn particle interactions on/off
+
+
+
Returns
double
+ +

Definition at line 266 of file PenningTrap.cpp.

+ +
+
+ +

◆ r_func()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
vec_3d PenningTrap::r_func (unsigned int i,
unsigned int j,
double dt 
)
+
+private
+
+ +

Helper for evolve_RK4 when calculating \(k_{r,i,j}\) values.

+

Something

+
Parameters
+ + + + +
iIndex i for \(k_{r,i,j}\)
jIndex j for \(k_{r,i,j}\)
dtthe step length (delta time)
+
+
+
Returns
vec_3d
+ +

Definition at line 64 of file PenningTrap.cpp.

+ +
+
+ +

◆ simulate()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
sim_arr PenningTrap::simulate (double time,
unsigned int steps,
std::string method = "rk4",
bool particle_interaction = true 
)
+
+ +

Simulate the particle system inside the Penning trap over a certain amount of time.

+
Parameters
+ + + + + +
timeThe time to simulate in microseconds
stepsThe amount of steps for the whole simulation
methodThe method to use when moving forward a timestep
particle_interactionTurn particle interactions on/off
+
+
+ +

Definition at line 211 of file PenningTrap.cpp.

+ +
+
+ +

◆ total_force()

+ +
+
+ + + + +
vec_3d PenningTrap::total_force (unsigned int  i)
-

calculate the total force on a particle.

+

calculate the total force on a particle p_i.

+
Parameters
+ + +
iThe index of particle p_i
+
+
+
Returns
vec_3d
-

Definition at line 61 of file PenningTrap.cpp.

+

Definition at line 146 of file PenningTrap.cpp.

- -

◆ total_force_external()

+ +

◆ total_force_external()

- + - + @@ -386,31 +785,161 @@ Private Attributes

Calculate the total external force on a particle.

-

Calculate the total amount of force that E and B exhibits on particle p_i.

+

Calculate the total amount of force that E and B exhibits on particle p_i.

+
Parameters
+
arma::vec PenningTrap::total_force_external vec_3d PenningTrap::total_force_external (int unsigned int  i)
+ +
iThe index of particle p_i
+ + +
Returns
vec_3d
-

Definition at line 51 of file PenningTrap.cpp.

+

Definition at line 114 of file PenningTrap.cpp.

- -

◆ total_force_particles()

+ +

◆ total_force_particles()

- + - +
arma::vec PenningTrap::total_force_particles vec_3d PenningTrap::total_force_particles (int unsigned int  i)
-

Calculate the total force on a particle from other particles.

+

Calculate the total force on a particle p_i from other particles.

+
Parameters
+ + +
iThe index of particle p_i
+
+
+
Returns
vec_3d
-

Definition at line 56 of file PenningTrap.cpp.

+

Definition at line 129 of file PenningTrap.cpp.

+ +
+
+ +

◆ v_func()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
vec_3d PenningTrap::v_func (unsigned int i,
unsigned int j,
double dt 
)
+
+private
+
+ +

Helper for evolve_RK4 when calculating \(k_{v,i,j}\) values.

+

Something

+
Parameters
+ + + + +
iIndex i for \(k_{v,i,j}\)
jIndex j for \(k_{v,i,j}\)
dtthe step length (delta time)
+
+
+
Returns
vec_3d
+ +

Definition at line 46 of file PenningTrap.cpp.

+ +
+
+ +

◆ write_simulation_to_dir()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void PenningTrap::write_simulation_to_dir (std::string path,
double time,
unsigned int steps,
std::string method = "rk4",
bool particle_interaction = true 
)
+
+ +

Simulate and write the displacement of all particles to files.

+
Parameters
+ + + + + + +
pathThe directory to save the data
timeThe time to simulate in microseconds
stepsThe amount of steps for the whole simulation
methodThe method to use when moving forward a timestep
particle_interactionTurn particle interactions on/off
+
+
+ +

Definition at line 240 of file PenningTrap.cpp.

@@ -437,7 +966,7 @@ Private Attributes

Magnetic field strength.

-

Definition at line 27 of file PenningTrap.hpp.

+

Definition at line 32 of file PenningTrap.hpp.

@@ -463,7 +992,57 @@ Private Attributes

Characteristic dimension.

-

Definition at line 29 of file PenningTrap.hpp.

+

Definition at line 34 of file PenningTrap.hpp.

+ + + + +

◆ k_r

+ +
+
+ + + + + +
+ + + + +
sim_arr PenningTrap::k_r
+
+private
+
+

A 2D vector containing all \(k_{i,j}\) where \(j\) is the index of a particle

+ +

Definition at line 39 of file PenningTrap.hpp.

+ +
+
+ +

◆ k_v

+ +
+
+ + + + + +
+ + + + +
sim_arr PenningTrap::k_v
+
+private
+
+

A 2D vector containing all \(k_{i,j}\) where \(j\) is the index of a particle

+ +

Definition at line 37 of file PenningTrap.hpp.

@@ -489,12 +1068,12 @@ Private Attributes

The particles in the Penning trap.

-

Definition at line 30 of file PenningTrap.hpp.

+

Definition at line 36 of file PenningTrap.hpp.

- -

◆ V_0

+ +

◆ t

@@ -503,7 +1082,33 @@ Private Attributes - + + +
double PenningTrap::V_0double PenningTrap::t
+ + +private + + +
+ +

Current time.

+ +

Definition at line 35 of file PenningTrap.hpp.

+ +
+
+ +

◆ V_0

+ +
+
+ + + @@ -515,7 +1120,7 @@ Private Attributes

Applied potential.

-

Definition at line 28 of file PenningTrap.hpp.

+

Definition at line 33 of file PenningTrap.hpp.

diff --git a/docs/classPenningTrap.js b/docs/classPenningTrap.js index 743d3ea..0fd7f36 100644 --- a/docs/classPenningTrap.js +++ b/docs/classPenningTrap.js @@ -1,17 +1,27 @@ var classPenningTrap = [ - [ "PenningTrap", "classPenningTrap.html#a81add5063bd5f29d77f0b5c299c6c560", null ], + [ "PenningTrap", "classPenningTrap.html#ae670d7de621acdb343b01af098086f63", null ], + [ "PenningTrap", "classPenningTrap.html#a763700316b502d5900e587c1f61e6bf1", null ], + [ "PenningTrap", "classPenningTrap.html#a67139e04ef69c0bcffde8f30f67cbf73", null ], [ "add_particle", "classPenningTrap.html#a6e9776ff5b149f01080800716455d7c8", null ], - [ "evolve_forward_euler", "classPenningTrap.html#a56544b6f4befb42984e9650cf2a40965", null ], - [ "evolve_RK4", "classPenningTrap.html#ab891b839c40eeb38d8a2a636c70090a9", null ], - [ "external_B_field", "classPenningTrap.html#a2a3e7f480ba52e9f24d4c50c3981a784", null ], - [ "external_E_field", "classPenningTrap.html#a978a2e2026a4b5308d5184712f81704b", null ], - [ "force_on_particle", "classPenningTrap.html#a4790f41e4fbc6ede4991aa7bbda92182", null ], - [ "total_force", "classPenningTrap.html#a83cc7a04dae009ed8e75453c38fdf8be", null ], - [ "total_force_external", "classPenningTrap.html#a045adb85e97a8e0c38fb36d2fd74eeee", null ], - [ "total_force_particles", "classPenningTrap.html#a135db7d991d9b88b00fde4edee71f78d", null ], + [ "evolve_forward_euler", "classPenningTrap.html#ab9ea97a406534bbe621a95215144875e", null ], + [ "evolve_RK4", "classPenningTrap.html#a36946152fd951b1f7c346c51ff900d8e", null ], + [ "external_B_field", "classPenningTrap.html#acbf065c9c125682329ad82a8d166554c", null ], + [ "external_E_field", "classPenningTrap.html#a1d58feaa2c9e34cbf26b1c5ed75ca9d9", null ], + [ "force_on_particle", "classPenningTrap.html#a9ae34ad740a230e667e96bc6ee8730ce", null ], + [ "fraction_of_particles_left", "classPenningTrap.html#a0194be61c956a9259c747c23e4163c5b", null ], + [ "r_func", "classPenningTrap.html#a43e74792ab4b3f9299f35cb64bdb2648", null ], + [ "simulate", "classPenningTrap.html#a5331837e6dd7bce807a99edd2ba7e854", null ], + [ "total_force", "classPenningTrap.html#a1f668c4433421136ad51741741aa1bc8", null ], + [ "total_force_external", "classPenningTrap.html#ae72d203b0bfa1b9e72bea28cb2863c56", null ], + [ "total_force_particles", "classPenningTrap.html#a46a954a0946def199e30fb300ba1c47b", null ], + [ "v_func", "classPenningTrap.html#af98a720da60b0e1a62aefa5f5cb37c1e", null ], + [ "write_simulation_to_dir", "classPenningTrap.html#abbb832a85139b1a56ebde57d7b8f9a57", null ], [ "B_0", "classPenningTrap.html#a0cac3509aa96e71a26d3b2c902e27716", null ], [ "d", "classPenningTrap.html#a66dfe89c68716b9502927b97f59c27d2", null ], + [ "k_r", "classPenningTrap.html#a2f168622587709b9e3c49077f0b9a640", null ], + [ "k_v", "classPenningTrap.html#ae9b5afdaa5cd366e94bd294452a1eed4", null ], [ "particles", "classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f", null ], - [ "V_0", "classPenningTrap.html#a715329844d75ec4c04f8391421fb4e89", null ] + [ "t", "classPenningTrap.html#a8ca4e21291f60fde619c14099d8c4e8e", null ], + [ "V_0", "classPenningTrap.html#aaf105828121c4a33cc2b217453c20317", null ] ]; \ No newline at end of file diff --git a/docs/classPenningTrapTest-members.html b/docs/classPenningTrapTest-members.html new file mode 100644 index 0000000..1b1f2e1 --- /dev/null +++ b/docs/classPenningTrapTest-members.html @@ -0,0 +1,121 @@ + + + + + + + +Penning Trap Simulation: Member List + + + + + + + + + + + + + + + + +
+
+
+ + +
std::function<double(double)> PenningTrap::V_0
+ + + + + +
+
Penning Trap Simulation +
+
Simulate particle behavior inside a Penning Trap
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+ +
+
PenningTrapTest Member List
+
+
+ +

This is the complete list of members for PenningTrapTest, including all inherited members.

+ + + + + + +
test_external_B_field() (defined in PenningTrapTest)PenningTrapTestinlinestatic
test_external_E_field() (defined in PenningTrapTest)PenningTrapTestinlinestatic
test_force_on_particle() (defined in PenningTrapTest)PenningTrapTestinlinestatic
test_total_force_external() (defined in PenningTrapTest)PenningTrapTestinlinestatic
test_total_force_particles() (defined in PenningTrapTest)PenningTrapTestinlinestatic
+
+ + + + diff --git a/docs/classPenningTrapTest.html b/docs/classPenningTrapTest.html new file mode 100644 index 0000000..8eda947 --- /dev/null +++ b/docs/classPenningTrapTest.html @@ -0,0 +1,273 @@ + + + + + + + +Penning Trap Simulation: PenningTrapTest Class Reference + + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Penning Trap Simulation +
+
Simulate particle behavior inside a Penning Trap
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+ +
+ +
PenningTrapTest Class Reference
+
+
+ + + + + + + + + + + + +

+Static Public Member Functions

static void test_external_E_field ()
 
static void test_external_B_field ()
 
static void test_force_on_particle ()
 
static void test_total_force_external ()
 
static void test_total_force_particles ()
 
+

Detailed Description

+
+

Definition at line 20 of file test_suite.cpp.

+

Member Function Documentation

+ +

◆ test_external_B_field()

+ +
+
+ + + + + +
+ + + + + + + +
static void PenningTrapTest::test_external_B_field ()
+
+inlinestatic
+
+ +

Definition at line 59 of file test_suite.cpp.

+ +
+
+ +

◆ test_external_E_field()

+ +
+
+ + + + + +
+ + + + + + + +
static void PenningTrapTest::test_external_E_field ()
+
+inlinestatic
+
+ +

Definition at line 22 of file test_suite.cpp.

+ +
+
+ +

◆ test_force_on_particle()

+ +
+
+ + + + + +
+ + + + + + + +
static void PenningTrapTest::test_force_on_particle ()
+
+inlinestatic
+
+ +

Definition at line 70 of file test_suite.cpp.

+ +
+
+ +

◆ test_total_force_external()

+ +
+
+ + + + + +
+ + + + + + + +
static void PenningTrapTest::test_total_force_external ()
+
+inlinestatic
+
+ +

Definition at line 95 of file test_suite.cpp.

+ +
+
+ +

◆ test_total_force_particles()

+ +
+
+ + + + + +
+ + + + + + + +
static void PenningTrapTest::test_total_force_particles ()
+
+inlinestatic
+
+ +

Definition at line 108 of file test_suite.cpp.

+ +
+
+
The documentation for this class was generated from the following file: +
+
+ + + + diff --git a/docs/classes.html b/docs/classes.html index 77925d2..7b8f02e 100644 --- a/docs/classes.html +++ b/docs/classes.html @@ -105,7 +105,7 @@ $(document).ready(function(){initNavTree('classes.html',''); initResizable(); })
P
-
Particle
PenningTrap
+
Particle
PenningTrap
PenningTrapTest
diff --git a/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html b/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html index fe23dd4..4313bbd 100644 --- a/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html +++ b/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html @@ -104,6 +104,8 @@ $(document).ready(function(){initNavTree('dir_68267d1309a1af8e8297ef4c3efbcdba.h + + @@ -113,6 +115,8 @@ Files + + diff --git a/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.js b/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.js index 17c90f6..64ce7a5 100644 --- a/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.js +++ b/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.js @@ -1,8 +1,10 @@ var dir_68267d1309a1af8e8297ef4c3efbcdba = [ + [ "animate_100_particles.py", "animate__100__particles_8py_source.html", null ], [ "main.cpp", "main_8cpp.html", null ], [ "Particle.cpp", "Particle_8cpp.html", null ], [ "PenningTrap.cpp", "PenningTrap_8cpp.html", null ], - [ "test_suite.cpp", "test__suite_8cpp.html", null ], + [ "plot_particles_left.py", "plot__particles__left_8py_source.html", null ], + [ "test_suite.cpp", "test__suite_8cpp.html", "test__suite_8cpp" ], [ "utils.cpp", "utils_8cpp.html", "utils_8cpp" ] ]; \ No newline at end of file diff --git a/docs/dir_d44c64559bbebec7f509842c48db8b23.html b/docs/dir_d44c64559bbebec7f509842c48db8b23.html index 21e883c..289eee3 100644 --- a/docs/dir_d44c64559bbebec7f509842c48db8b23.html +++ b/docs/dir_d44c64559bbebec7f509842c48db8b23.html @@ -113,6 +113,9 @@ Files + + + diff --git a/docs/dir_d44c64559bbebec7f509842c48db8b23.js b/docs/dir_d44c64559bbebec7f509842c48db8b23.js index 48feb88..192eaa8 100644 --- a/docs/dir_d44c64559bbebec7f509842c48db8b23.js +++ b/docs/dir_d44c64559bbebec7f509842c48db8b23.js @@ -3,5 +3,6 @@ var dir_d44c64559bbebec7f509842c48db8b23 = [ "constants.hpp", "constants_8hpp.html", "constants_8hpp" ], [ "Particle.hpp", "Particle_8hpp.html", "Particle_8hpp" ], [ "PenningTrap.hpp", "PenningTrap_8hpp.html", "PenningTrap_8hpp" ], + [ "typedefs.hpp", "typedefs_8hpp.html", "typedefs_8hpp" ], [ "utils.hpp", "utils_8hpp.html", "utils_8hpp" ] ]; \ No newline at end of file diff --git a/docs/files.html b/docs/files.html index a998ae5..e842a47 100644 --- a/docs/files.html +++ b/docs/files.html @@ -107,13 +107,16 @@ $(document).ready(function(){initNavTree('files.html',''); initResizable(); }); - - - - - - - + + + + + + + + + +

Files

file  animate_100_particles.py [code]
 
file  main.cpp [code]
 The main program for this project.
 
file  PenningTrap.cpp [code]
 The implementation of the PenningTrap class.
 
file  plot_particles_left.py [code]
 
file  test_suite.cpp [code]
 The test suite for the project.
 
file  PenningTrap.hpp [code]
 A class for simulating a Penning trap.
 
file  typedefs.hpp [code]
 Useful typedefs for cleaner code.
 
file  utils.hpp [code]
 Function prototypes and macros that are useful.
 
 constants.hppLibrary of constants
 Particle.hppA class that holds the properties of a particle
 PenningTrap.hppA class for simulating a Penning trap
 utils.hppFunction prototypes and macros that are useful
  src
 main.cppThe main program for this project
 Particle.cppThe implementation of the Particle class
 PenningTrap.cppThe implementation of the PenningTrap class
 test_suite.cppThe test suite for the project
 utils.cppImplementation of the utils
 typedefs.hppUseful typedefs for cleaner code
 utils.hppFunction prototypes and macros that are useful
  src
 animate_100_particles.py
 main.cppThe main program for this project
 Particle.cppThe implementation of the Particle class
 PenningTrap.cppThe implementation of the PenningTrap class
 plot_particles_left.py
 test_suite.cppThe test suite for the project
 utils.cppImplementation of the utils
diff --git a/docs/functions.html b/docs/functions.html index eb473bb..a2f04ea 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -102,22 +102,30 @@ $(document).ready(function(){initNavTree('functions.html',''); initResizable();
  • add_particle() : PenningTrap
  • B_0 : PenningTrap
  • d : PenningTrap
  • -
  • evolve_forward_euler() : PenningTrap
  • -
  • evolve_RK4() : PenningTrap
  • -
  • external_B_field() : PenningTrap
  • -
  • external_E_field() : PenningTrap
  • -
  • force_on_particle() : PenningTrap
  • +
  • evolve_forward_euler() : PenningTrap
  • +
  • evolve_RK4() : PenningTrap
  • +
  • external_B_field() : PenningTrap
  • +
  • external_E_field() : PenningTrap
  • +
  • force_on_particle() : PenningTrap
  • +
  • fraction_of_particles_left() : PenningTrap
  • +
  • k_r : PenningTrap
  • +
  • k_v : PenningTrap
  • m : Particle
  • -
  • Particle() : Particle
  • +
  • Particle() : Particle
  • particles : PenningTrap
  • -
  • PenningTrap : Particle, PenningTrap
  • +
  • PenningTrap : Particle, PenningTrap
  • q : Particle
  • -
  • r_vec : Particle
  • -
  • total_force() : PenningTrap
  • -
  • total_force_external() : PenningTrap
  • -
  • total_force_particles() : PenningTrap
  • -
  • V_0 : PenningTrap
  • -
  • v_vec : Particle
  • +
  • r_func() : PenningTrap
  • +
  • r_vec : Particle
  • +
  • simulate() : PenningTrap
  • +
  • t : PenningTrap
  • +
  • total_force() : PenningTrap
  • +
  • total_force_external() : PenningTrap
  • +
  • total_force_particles() : PenningTrap
  • +
  • V_0 : PenningTrap
  • +
  • v_func() : PenningTrap
  • +
  • v_vec : Particle
  • +
  • write_simulation_to_dir() : PenningTrap
  • diff --git a/docs/functions_func.html b/docs/functions_func.html index 4a36dd3..1182b1d 100644 --- a/docs/functions_func.html +++ b/docs/functions_func.html @@ -100,16 +100,21 @@ $(document).ready(function(){initNavTree('functions_func.html',''); initResizabl
     
    diff --git a/docs/functions_vars.html b/docs/functions_vars.html index 8c0729a..3ca2e5b 100644 --- a/docs/functions_vars.html +++ b/docs/functions_vars.html @@ -101,12 +101,15 @@ $(document).ready(function(){initNavTree('functions_vars.html',''); initResizabl   diff --git a/docs/globals.html b/docs/globals.html index 78504e0..19a9638 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -99,11 +99,20 @@ $(document).ready(function(){initNavTree('globals.html',''); initResizable(); })
    Here is a list of all documented file members with links to the documentation:
    diff --git a/docs/globals_defs.html b/docs/globals_defs.html index d88a7ee..c7eb483 100644 --- a/docs/globals_defs.html +++ b/docs/globals_defs.html @@ -99,6 +99,8 @@ $(document).ready(function(){initNavTree('globals_defs.html',''); initResizable(
     
    -

    -

    +

    + +
    +

    Credits

    The Doxygen theme used here is doxygen-awesome-css.

    diff --git a/docs/main_8cpp.html b/docs/main_8cpp.html index cf16990..b83f224 100644 --- a/docs/main_8cpp.html +++ b/docs/main_8cpp.html @@ -99,20 +99,60 @@ $(document).ready(function(){initNavTree('main_8cpp.html',''); initResizable();
    +Macros | +Functions | +Variables
    main.cpp File Reference

    The main program for this project. More...

    - +
    #include <cmath>
    +#include <fstream>
    +#include <omp.h>
    +#include <string>
    +#include <sys/stat.h>
    +#include <vector>
    +#include "PenningTrap.hpp"
    +#include "utils.hpp"
    +

    Go to the source code of this file.

    + + + + + + + + + +

    +Macros

    #define PARTICLES   100
     
    #define N   10000
     
    #define CHARGE   1.
     
    #define MASS   40.
     
    + + + + + + + + + + +

    Functions

    void simulate_single_particle ()
     
    void simulate_two_particles ()
     
    void simulate_single_particle_with_different_steps ()
     
    void simulate_100_particles ()
     
    void simulate_100_particles_with_time_potential ()
     
    int main ()
     
    + + + + +

    +Variables

    +Particle p1 (CHARGE, MASS, vec_3d{20., 0., 20.}, vec_3d{0., 25., 0.})
     
    +Particle p2 (CHARGE, MASS, vec_3d{25., 25., 0.}, vec_3d{0., 40., 5.})
     

    Detailed Description

    The main program for this project.

    @@ -120,10 +160,75 @@ Functions
    Janita Ovidie Sandtrøen Willumsen (janitaws)
    Version
    0.1
    -
    Bug:
    No known bugs
    +
    Bug:
    No known bugs

    Definition in file main.cpp.

    -

    Function Documentation

    +

    Macro Definition Documentation

    + +

    ◆ CHARGE

    + +
    +
    + + + + +
    #define CHARGE   1.
    +
    + +

    Definition at line 25 of file main.cpp.

    + +
    +
    + +

    ◆ MASS

    + +
    +
    + + + + +
    #define MASS   40.
    +
    + +

    Definition at line 26 of file main.cpp.

    + +
    +
    + +

    ◆ N

    + +
    +
    + + + + +
    #define N   10000
    +
    + +

    Definition at line 24 of file main.cpp.

    + +
    +
    + +

    ◆ PARTICLES

    + +
    +
    + + + + +
    #define PARTICLES   100
    +
    + +

    Definition at line 23 of file main.cpp.

    + +
    +
    +

    Function Documentation

    ◆ main()

    @@ -139,7 +244,102 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    -

    Definition at line 13 of file main.cpp.

    +

    Definition at line 124 of file main.cpp.

    + +
    + + +

    ◆ simulate_100_particles()

    + +
    +
    + + + + + + + +
    void simulate_100_particles ()
    +
    + +

    Definition at line 77 of file main.cpp.

    + +
    +
    + +

    ◆ simulate_100_particles_with_time_potential()

    + +
    +
    + + + + + + + +
    void simulate_100_particles_with_time_potential ()
    +
    + +

    Definition at line 91 of file main.cpp.

    + +
    +
    + +

    ◆ simulate_single_particle()

    + +
    +
    + + + + + + + +
    void simulate_single_particle ()
    +
    + +

    Definition at line 31 of file main.cpp.

    + +
    +
    + +

    ◆ simulate_single_particle_with_different_steps()

    + +
    +
    + + + + + + + +
    void simulate_single_particle_with_different_steps ()
    +
    + +

    Definition at line 55 of file main.cpp.

    + +
    +
    + +

    ◆ simulate_two_particles()

    + +
    +
    + + + + + + + +
    void simulate_two_particles ()
    +
    + +

    Definition at line 42 of file main.cpp.

    diff --git a/docs/main_8cpp_source.html b/docs/main_8cpp_source.html index bf66ff8..d437689 100644 --- a/docs/main_8cpp_source.html +++ b/docs/main_8cpp_source.html @@ -102,10 +102,149 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
    Go to the documentation of this file.
    1
    -
    13int main()
    -
    14{
    -
    15 return 0;
    -
    16}
    +
    13#include <cmath>
    +
    14#include <fstream>
    +
    15#include <omp.h>
    +
    16#include <string>
    +
    17#include <sys/stat.h>
    +
    18#include <vector>
    +
    19
    +
    20#include "PenningTrap.hpp"
    +
    21#include "utils.hpp"
    +
    22
    +
    23#define PARTICLES 100
    +
    24#define N 10000
    +
    25#define CHARGE 1.
    +
    26#define MASS 40. // unit: amu
    +
    27
    +
    28Particle p1(CHARGE, MASS, vec_3d{20., 0., 20.}, vec_3d{0., 25., 0.});
    +
    29Particle p2(CHARGE, MASS, vec_3d{25., 25., 0.}, vec_3d{0., 40., 5.});
    +
    30
    +
    31void simulate_single_particle()
    +
    32{
    +
    33 DEBUG("Inside single particle sim");
    +
    34 PenningTrap trap(std::vector<Particle>{p1});
    +
    35
    +
    36 double time = 50.; // microseconds
    +
    37
    +
    38 DEBUG("Write to dir");
    +
    39 trap.write_simulation_to_dir("output/simulate_single_particle", time, N);
    +
    40}
    +
    41
    +
    42void simulate_two_particles()
    +
    43{
    +
    44 PenningTrap trap_no_interaction(std::vector<Particle>{p1, p2});
    +
    45 PenningTrap trap_with_interaction(std::vector<Particle>{p1, p2});
    +
    46
    +
    47 double time = 50.; // microseconds
    +
    48
    +
    49 trap_no_interaction.write_simulation_to_dir(
    +
    50 "output/simulate_2_particles/no_interaction", time, N, "rk4", false);
    +
    51 trap_with_interaction.write_simulation_to_dir(
    +
    52 "output/simulate_2_particles/with_interaction", time, N);
    +
    53}
    +
    54
    +
    55void simulate_single_particle_with_different_steps()
    +
    56{
    +
    57
    +
    58 double time = 50; // microseconds
    +
    59
    +
    60 for (int i = 0; i < 4; i++) {
    +
    61 int steps = 4000 * (i + 1);
    +
    62 PenningTrap trap(std::vector<Particle>{p1});
    +
    63 trap.write_simulation_to_dir("output/N_steps/RK4/" +
    +
    64 std::to_string(steps) + "_steps",
    +
    65 time, steps, "rk4", false);
    +
    66 }
    +
    67
    +
    68 for (int i = 0; i < 4; i++) {
    +
    69 int steps = 4000 * (i + 1);
    +
    70 PenningTrap trap(std::vector<Particle>{p1});
    +
    71 trap.write_simulation_to_dir("output/N_steps/euler/" +
    +
    72 std::to_string(steps) + "_steps",
    +
    73 time, steps, "euler", false);
    +
    74 }
    +
    75}
    +
    76
    +
    77void simulate_100_particles()
    +
    78{
    +
    79 PenningTrap trap((unsigned)100, T,
    +
    80 [](double t) {
    +
    81 return 25. * V / 1000. *
    +
    82 (1. + .4 * std::cos(1.5 * t));
    +
    83 },
    +
    84 500., 0);
    +
    85
    +
    86 double time = 500.; // microseconds
    +
    87
    +
    88 trap.write_simulation_to_dir("output/simulate_100_particles", time, N*5);
    +
    89}
    +
    90
    +
    91void simulate_100_particles_with_time_potential()
    +
    92{
    +
    93 double amplitudes[]{.1, .4, .7};
    +
    94
    +
    95 double freq_start = .2;
    +
    96 double freq_end = 2.5;
    +
    97 double freq_increment = .02;
    +
    98 size_t freq_iterations = (size_t) ((freq_end - freq_start) / freq_increment);
    +
    99
    +
    100 std::string path = "output/time_dependent_potential/";
    +
    101 mkpath(path);
    +
    102
    +
    103 std::ofstream ofile;
    +
    104
    +
    105 for (double f : amplitudes) {
    +
    106 ofile.open(path + "f_" + std::to_string(f) + ".txt");
    +
    107 #pragma omp parallel for ordered schedule(static, 1)
    +
    108 for (size_t i=0; i < freq_iterations; i++) {
    +
    109 double freq = freq_start + i*freq_increment;
    +
    110 PenningTrap trap((unsigned)100, T,
    +
    111 [f, freq](double t) {
    +
    112 return (25. * V / 1000.) *
    +
    113 (1. + f * std::cos(freq * t));
    +
    114 },
    +
    115 500., 0.);
    +
    116 double res = trap.fraction_of_particles_left(500., 40000, "rk4", true);
    +
    117 #pragma omp ordered
    +
    118 ofile << freq << "," << res << "\n";
    +
    119 }
    +
    120 ofile.close();
    +
    121 }
    +
    122}
    +
    123
    +
    124int main()
    +
    125{
    +
    126
    +
    127 simulate_single_particle();
    +
    128
    +
    129 simulate_two_particles();
    +
    130
    +
    131 simulate_single_particle_with_different_steps();
    +
    132
    +
    133 double start = omp_get_wtime();
    +
    134
    +
    135 //simulate_100_particles();
    +
    136
    +
    137 simulate_100_particles_with_time_potential();
    +
    138
    +
    139 double end = omp_get_wtime();
    +
    140
    +
    141 std::cout << "Time: " << end - start << " seconds" << std::endl;
    +
    142
    +
    143 return 0;
    +
    144}
    +
    A class for simulating a Penning trap.
    +
    A class that holds attributes of a particle.
    Definition: Particle.hpp:21
    +
    A class that simulates a Penning trap.
    Definition: PenningTrap.hpp:30
    +
    double fraction_of_particles_left(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
    Simulate and calculate what fraction of particles are still left inside the Penning trap after the si...
    +
    void write_simulation_to_dir(std::string path, double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
    Simulate and write the displacement of all particles to files.
    +
    #define T
    1 Tesla. unit:
    Definition: constants.hpp:17
    +
    #define V
    1 Volt. unit:
    Definition: constants.hpp:19
    +
    arma::vec::fixed< 3 > vec_3d
    Typedef for a fixed 3d arma vector.
    Definition: typedefs.hpp:36
    +
    Function prototypes and macros that are useful.
    +
    bool mkpath(std::string path, int mode=0777)
    Make path given.
    Definition: utils.cpp:76
    +
    #define DEBUG(msg)
    Writes a debug message.
    Definition: utils.hpp:36
    diff --git a/docs/menudata.js b/docs/menudata.js index 88ec31f..74c1d7b 100644 --- a/docs/menudata.js +++ b/docs/menudata.js @@ -38,4 +38,5 @@ var menudata={children:[ {text:"File Members",url:"globals.html",children:[ {text:"All",url:"globals.html"}, {text:"Functions",url:"globals_func.html"}, +{text:"Typedefs",url:"globals_type.html"}, {text:"Macros",url:"globals_defs.html"}]}]}]} diff --git a/docs/navtreedata.js b/docs/navtreedata.js index 10ee5ad..9640812 100644 --- a/docs/navtreedata.js +++ b/docs/navtreedata.js @@ -27,7 +27,6 @@ var NAVTREE = [ "Penning Trap Simulation", "index.html", [ [ "Credits", "index.html#autotoc_md1", null ], [ "Bug List", "bug.html", null ], - [ "Todo List", "todo.html", null ], [ "Classes", "annotated.html", [ [ "Class List", "annotated.html", "annotated_dup" ], [ "Class Index", "classes.html", null ], @@ -43,6 +42,7 @@ var NAVTREE = [ "File Members", "globals.html", [ [ "All", "globals.html", null ], [ "Functions", "globals_func.html", null ], + [ "Typedefs", "globals_type.html", null ], [ "Macros", "globals_defs.html", null ] ] ] ] ] diff --git a/docs/navtreeindex0.js b/docs/navtreeindex0.js index 6d8de5d..16caa0e 100644 --- a/docs/navtreeindex0.js +++ b/docs/navtreeindex0.js @@ -1,68 +1,95 @@ var NAVTREEINDEX0 = { -"Particle_8cpp.html":[4,0,1,1], -"Particle_8cpp_source.html":[4,0,1,1], -"Particle_8hpp.html":[4,0,0,1], -"Particle_8hpp_source.html":[4,0,0,1], -"PenningTrap_8cpp.html":[4,0,1,2], -"PenningTrap_8cpp_source.html":[4,0,1,2], -"PenningTrap_8hpp.html":[4,0,0,2], -"PenningTrap_8hpp_source.html":[4,0,0,2], -"annotated.html":[3,0], +"Particle_8cpp.html":[3,0,1,2], +"Particle_8cpp_source.html":[3,0,1,2], +"Particle_8hpp.html":[3,0,0,1], +"Particle_8hpp_source.html":[3,0,0,1], +"PenningTrap_8cpp.html":[3,0,1,3], +"PenningTrap_8cpp_source.html":[3,0,1,3], +"PenningTrap_8hpp.html":[3,0,0,2], +"PenningTrap_8hpp_source.html":[3,0,0,2], +"animate__100__particles_8py_source.html":[3,0,1,0], +"annotated.html":[2,0], "bug.html":[1], -"classParticle.html":[3,0,0], -"classParticle.html#a00e108823877a25513ccae7cac011b4c":[3,0,0,0], -"classParticle.html#a4a5d22c7aeca66f67d083f270cba25df":[3,0,0,5], -"classParticle.html#a566dcc1de4bdc01251776948798ea8e1":[3,0,0,3], -"classParticle.html#aa797d319549dc2a0beb06cdbfd430232":[3,0,0,1], -"classParticle.html#acf1a0f3c978b06d76df5bb4279594467":[3,0,0,4], -"classParticle.html#aedcc7e1bc53b0e2b1a4a07c9a1b47563":[3,0,0,2], -"classPenningTrap.html":[3,0,1], -"classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f":[3,0,1,12], -"classPenningTrap.html#a045adb85e97a8e0c38fb36d2fd74eeee":[3,0,1,8], -"classPenningTrap.html#a0cac3509aa96e71a26d3b2c902e27716":[3,0,1,10], -"classPenningTrap.html#a135db7d991d9b88b00fde4edee71f78d":[3,0,1,9], -"classPenningTrap.html#a2a3e7f480ba52e9f24d4c50c3981a784":[3,0,1,4], -"classPenningTrap.html#a4790f41e4fbc6ede4991aa7bbda92182":[3,0,1,6], -"classPenningTrap.html#a56544b6f4befb42984e9650cf2a40965":[3,0,1,2], -"classPenningTrap.html#a66dfe89c68716b9502927b97f59c27d2":[3,0,1,11], -"classPenningTrap.html#a6e9776ff5b149f01080800716455d7c8":[3,0,1,1], -"classPenningTrap.html#a715329844d75ec4c04f8391421fb4e89":[3,0,1,13], -"classPenningTrap.html#a81add5063bd5f29d77f0b5c299c6c560":[3,0,1,0], -"classPenningTrap.html#a83cc7a04dae009ed8e75453c38fdf8be":[3,0,1,7], -"classPenningTrap.html#a978a2e2026a4b5308d5184712f81704b":[3,0,1,5], -"classPenningTrap.html#ab891b839c40eeb38d8a2a636c70090a9":[3,0,1,3], -"classes.html":[3,1], -"constants_8hpp.html":[4,0,0,0], -"constants_8hpp.html#a0acb682b8260ab1c60b918599864e2e5":[4,0,0,0,1], -"constants_8hpp.html#a4e451456ad7e9276ed0afa42826e7ccb":[4,0,0,0,0], -"constants_8hpp.html#af40a326b23c68a27cebe60f16634a2cb":[4,0,0,0,2], -"constants_8hpp_source.html":[4,0,0,0], -"dir_68267d1309a1af8e8297ef4c3efbcdba.html":[4,0,1], -"dir_d44c64559bbebec7f509842c48db8b23.html":[4,0,0], -"files.html":[4,0], -"functions.html":[3,2,0], -"functions_func.html":[3,2,1], -"functions_rela.html":[3,2,3], -"functions_vars.html":[3,2,2], -"globals.html":[4,1,0], -"globals_defs.html":[4,1,2], -"globals_func.html":[4,1,1], +"classParticle.html":[2,0,0], +"classParticle.html#a566dcc1de4bdc01251776948798ea8e1":[2,0,0,3], +"classParticle.html#a7af9f8d1fef63dd7643b06629ac7bef4":[2,0,0,0], +"classParticle.html#a879692772803d6ab65fa4993b54aea6e":[2,0,0,5], +"classParticle.html#aa797d319549dc2a0beb06cdbfd430232":[2,0,0,1], +"classParticle.html#aedcc7e1bc53b0e2b1a4a07c9a1b47563":[2,0,0,2], +"classParticle.html#af9497cd8f2dcad0fad54f571ddb383e6":[2,0,0,4], +"classPenningTrap.html":[2,0,1], +"classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f":[2,0,1,21], +"classPenningTrap.html#a0194be61c956a9259c747c23e4163c5b":[2,0,1,9], +"classPenningTrap.html#a0cac3509aa96e71a26d3b2c902e27716":[2,0,1,17], +"classPenningTrap.html#a1d58feaa2c9e34cbf26b1c5ed75ca9d9":[2,0,1,7], +"classPenningTrap.html#a1f668c4433421136ad51741741aa1bc8":[2,0,1,12], +"classPenningTrap.html#a2f168622587709b9e3c49077f0b9a640":[2,0,1,19], +"classPenningTrap.html#a36946152fd951b1f7c346c51ff900d8e":[2,0,1,5], +"classPenningTrap.html#a43e74792ab4b3f9299f35cb64bdb2648":[2,0,1,10], +"classPenningTrap.html#a46a954a0946def199e30fb300ba1c47b":[2,0,1,14], +"classPenningTrap.html#a5331837e6dd7bce807a99edd2ba7e854":[2,0,1,11], +"classPenningTrap.html#a66dfe89c68716b9502927b97f59c27d2":[2,0,1,18], +"classPenningTrap.html#a67139e04ef69c0bcffde8f30f67cbf73":[2,0,1,2], +"classPenningTrap.html#a6e9776ff5b149f01080800716455d7c8":[2,0,1,3], +"classPenningTrap.html#a763700316b502d5900e587c1f61e6bf1":[2,0,1,1], +"classPenningTrap.html#a8ca4e21291f60fde619c14099d8c4e8e":[2,0,1,22], +"classPenningTrap.html#a9ae34ad740a230e667e96bc6ee8730ce":[2,0,1,8], +"classPenningTrap.html#aaf105828121c4a33cc2b217453c20317":[2,0,1,23], +"classPenningTrap.html#ab9ea97a406534bbe621a95215144875e":[2,0,1,4], +"classPenningTrap.html#abbb832a85139b1a56ebde57d7b8f9a57":[2,0,1,16], +"classPenningTrap.html#acbf065c9c125682329ad82a8d166554c":[2,0,1,6], +"classPenningTrap.html#ae670d7de621acdb343b01af098086f63":[2,0,1,0], +"classPenningTrap.html#ae72d203b0bfa1b9e72bea28cb2863c56":[2,0,1,13], +"classPenningTrap.html#ae9b5afdaa5cd366e94bd294452a1eed4":[2,0,1,20], +"classPenningTrap.html#af98a720da60b0e1a62aefa5f5cb37c1e":[2,0,1,15], +"classPenningTrapTest.html":[2,0,2], +"classes.html":[2,1], +"constants_8hpp.html":[3,0,0,0], +"constants_8hpp.html#a0acb682b8260ab1c60b918599864e2e5":[3,0,0,0,1], +"constants_8hpp.html#a4e451456ad7e9276ed0afa42826e7ccb":[3,0,0,0,0], +"constants_8hpp.html#af40a326b23c68a27cebe60f16634a2cb":[3,0,0,0,2], +"constants_8hpp_source.html":[3,0,0,0], +"dir_68267d1309a1af8e8297ef4c3efbcdba.html":[3,0,1], +"dir_d44c64559bbebec7f509842c48db8b23.html":[3,0,0], +"files.html":[3,0], +"functions.html":[2,2,0], +"functions_func.html":[2,2,1], +"functions_rela.html":[2,2,3], +"functions_vars.html":[2,2,2], +"globals.html":[3,1,0], +"globals_defs.html":[3,1,3], +"globals_func.html":[3,1,1], +"globals_type.html":[3,1,2], "index.html":[], "index.html#autotoc_md1":[0], -"main_8cpp.html":[4,0,1,0], -"main_8cpp_source.html":[4,0,1,0], +"main_8cpp.html":[3,0,1,1], +"main_8cpp_source.html":[3,0,1,1], "pages.html":[], -"test__suite_8cpp.html":[4,0,1,3], -"test__suite_8cpp_source.html":[4,0,1,3], -"todo.html":[2], -"utils_8cpp.html":[4,0,1,4], -"utils_8cpp.html#a58565270b643b24e3132f38c653e0199":[4,0,1,4,0], -"utils_8cpp.html#acd2a9c7a7d5a7fe9163be8c4cc110746":[4,0,1,4,1], -"utils_8cpp_source.html":[4,0,1,4], -"utils_8hpp.html":[4,0,0,3], -"utils_8hpp.html#ad54b96a1074f9df4dc892a41d115b72d":[4,0,0,3,1], -"utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384":[4,0,0,3,2], -"utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b":[4,0,0,3,0], -"utils_8hpp_source.html":[4,0,0,3] +"plot__particles__left_8py_source.html":[3,0,1,4], +"test__suite_8cpp.html":[3,0,1,5], +"test__suite_8cpp_source.html":[3,0,1,5], +"typedefs_8hpp.html":[3,0,0,3], +"typedefs_8hpp.html#a7c2dfa854274262c4e00e4ef0ab2ce23":[3,0,0,3,1], +"typedefs_8hpp.html#a8502989b1b361725834fc185bd575f66":[3,0,0,3,2], +"typedefs_8hpp.html#a9f33f4962c8fb62cc5ccd0e4e039a8df":[3,0,0,3,3], +"typedefs_8hpp.html#aec69d34220fff45de238b9e01f2686af":[3,0,0,3,0], +"typedefs_8hpp_source.html":[3,0,0,3], +"utils_8cpp.html":[3,0,1,6], +"utils_8cpp.html#a58565270b643b24e3132f38c653e0199":[3,0,1,6,3], +"utils_8cpp.html#a5d2e1e032fd19614f2fbb58149a7b02a":[3,0,1,6,0], +"utils_8cpp.html#acd2a9c7a7d5a7fe9163be8c4cc110746":[3,0,1,6,4], +"utils_8cpp.html#acf13f4e492199cb7231bfa646dbd08de":[3,0,1,6,2], +"utils_8cpp.html#aff5e07c3c1d321709b0cc38e999f427b":[3,0,1,6,1], +"utils_8cpp_source.html":[3,0,1,6], +"utils_8hpp.html":[3,0,0,4], +"utils_8hpp.html#a0c95c4791692b06f8811905a76dbd772":[3,0,0,4,3], +"utils_8hpp.html#a2cc3a2cdb635bac3c8b02e89d4d6af38":[3,0,0,4,4], +"utils_8hpp.html#a60dca3177fb9cb5256609adc7af55168":[3,0,0,4,0], +"utils_8hpp.html#a6fdd7217b750aff5b6295ece7cbdeffa":[3,0,0,4,5], +"utils_8hpp.html#a73d4f21ad937dbc50a0c0538c78fd4f9":[3,0,0,4,1], +"utils_8hpp.html#ad54b96a1074f9df4dc892a41d115b72d":[3,0,0,4,6], +"utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384":[3,0,0,4,7], +"utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b":[3,0,0,4,2], +"utils_8hpp_source.html":[3,0,0,4] }; diff --git a/docs/pages.html b/docs/pages.html index eb4abe8..a84d908 100644 --- a/docs/pages.html +++ b/docs/pages.html @@ -104,7 +104,6 @@ $(document).ready(function(){initNavTree('pages.html',''); initResizable(); });
    Here is a list of all related documentation pages:
    -
     Bug List
     Todo List
    diff --git a/docs/plot__particles__left_8py_source.html b/docs/plot__particles__left_8py_source.html new file mode 100644 index 0000000..c9ab258 --- /dev/null +++ b/docs/plot__particles__left_8py_source.html @@ -0,0 +1,147 @@ + + + + + + + +Penning Trap Simulation: src/plot_particles_left.py Source File + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    plot_particles_left.py
    +
    +
    +
    1import matplotlib.pyplot as plt
    +
    2
    +
    3def main():
    +
    4 files = [
    +
    5 "output/time_dependent_potential/f_0.100000.txt",
    +
    6 "output/time_dependent_potential/f_0.400000.txt",
    +
    7 "output/time_dependent_potential/f_0.700000.txt",
    +
    8 ]
    +
    9 vals = [
    +
    10 .1,
    +
    11 .4,
    +
    12 .7
    +
    13 ]
    +
    14 for i in range(3):
    +
    15 with open(files[i]) as f:
    +
    16 lines = f.readlines()
    +
    17 x = []
    +
    18 y = []
    +
    19 for line in lines:
    +
    20 a,b = line.strip().split(",")
    +
    21 x.append(float(a))
    +
    22 y.append(float(b))
    +
    23 plt.plot(x,y,label=f"amplitude: {vals[i]}")
    +
    24
    +
    25 plt.xlabel(r"$\omega_V$")
    +
    26 plt.ylabel(r"Fraction of particles left")
    +
    27 plt.title(r"The fraction of particles left in the Penning trap "
    +
    28 "after 500 microseconds for different amplitudes and frequencies")
    +
    29 plt.legend()
    +
    30 plt.show()
    +
    31
    +
    32if __name__ == "__main__":
    +
    33 main()
    +
    +
    + + + + diff --git a/docs/search/all_0.js b/docs/search/all_0.js index 8003164..1e5c227 100644 --- a/docs/search/all_0.js +++ b/docs/search/all_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['add_5fparticle_0',['add_particle',['../classPenningTrap.html#a6e9776ff5b149f01080800716455d7c8',1,'PenningTrap']]] + ['_5f_5fmethod_5fname_5f_5f_0',['__METHOD_NAME__',['../utils_8hpp.html#a60dca3177fb9cb5256609adc7af55168',1,'utils.hpp']]] ]; diff --git a/docs/search/all_1.js b/docs/search/all_1.js index 80ed042..4fc815a 100644 --- a/docs/search/all_1.js +++ b/docs/search/all_1.js @@ -1,5 +1,6 @@ var searchData= [ - ['b_5f0_0',['B_0',['../classPenningTrap.html#a0cac3509aa96e71a26d3b2c902e27716',1,'PenningTrap']]], - ['bug_20list_1',['Bug List',['../bug.html',1,'']]] + ['add_5fparticle_0',['add_particle',['../classPenningTrap.html#a6e9776ff5b149f01080800716455d7c8',1,'PenningTrap']]], + ['arma_5fvector_5fclose_5fto_1',['arma_vector_close_to',['../utils_8hpp.html#a0c95c4791692b06f8811905a76dbd772',1,'arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8): utils.cpp'],['../utils_8cpp.html#a5d2e1e032fd19614f2fbb58149a7b02a',1,'arma_vector_close_to(arma::vec &a, arma::vec &b, double tol): utils.cpp']]], + ['assert_2',['ASSERT',['../utils_8hpp.html#a73d4f21ad937dbc50a0c0538c78fd4f9',1,'utils.hpp']]] ]; diff --git a/docs/search/all_10.js b/docs/search/all_10.js new file mode 100644 index 0000000..1b9fc74 --- /dev/null +++ b/docs/search/all_10.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['write_5fsimulation_5fto_5fdir_0',['write_simulation_to_dir',['../classPenningTrap.html#abbb832a85139b1a56ebde57d7b8f9a57',1,'PenningTrap']]] +]; diff --git a/docs/search/all_2.js b/docs/search/all_2.js index 0648f09..80ed042 100644 --- a/docs/search/all_2.js +++ b/docs/search/all_2.js @@ -1,4 +1,5 @@ var searchData= [ - ['constants_2ehpp_0',['constants.hpp',['../constants_8hpp.html',1,'']]] + ['b_5f0_0',['B_0',['../classPenningTrap.html#a0cac3509aa96e71a26d3b2c902e27716',1,'PenningTrap']]], + ['bug_20list_1',['Bug List',['../bug.html',1,'']]] ]; diff --git a/docs/search/all_3.js b/docs/search/all_3.js index e50dce3..0648f09 100644 --- a/docs/search/all_3.js +++ b/docs/search/all_3.js @@ -1,5 +1,4 @@ var searchData= [ - ['d_0',['d',['../classPenningTrap.html#a66dfe89c68716b9502927b97f59c27d2',1,'PenningTrap']]], - ['debug_1',['DEBUG',['../utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b',1,'utils.hpp']]] + ['constants_2ehpp_0',['constants.hpp',['../constants_8hpp.html',1,'']]] ]; diff --git a/docs/search/all_4.js b/docs/search/all_4.js index c031fe4..e50dce3 100644 --- a/docs/search/all_4.js +++ b/docs/search/all_4.js @@ -1,7 +1,5 @@ var searchData= [ - ['evolve_5fforward_5feuler_0',['evolve_forward_euler',['../classPenningTrap.html#a56544b6f4befb42984e9650cf2a40965',1,'PenningTrap']]], - ['evolve_5frk4_1',['evolve_RK4',['../classPenningTrap.html#ab891b839c40eeb38d8a2a636c70090a9',1,'PenningTrap']]], - ['external_5fb_5ffield_2',['external_B_field',['../classPenningTrap.html#a2a3e7f480ba52e9f24d4c50c3981a784',1,'PenningTrap']]], - ['external_5fe_5ffield_3',['external_E_field',['../classPenningTrap.html#a978a2e2026a4b5308d5184712f81704b',1,'PenningTrap']]] + ['d_0',['d',['../classPenningTrap.html#a66dfe89c68716b9502927b97f59c27d2',1,'PenningTrap']]], + ['debug_1',['DEBUG',['../utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b',1,'utils.hpp']]] ]; diff --git a/docs/search/all_5.js b/docs/search/all_5.js index ccf47d2..c4c479f 100644 --- a/docs/search/all_5.js +++ b/docs/search/all_5.js @@ -1,4 +1,7 @@ var searchData= [ - ['force_5fon_5fparticle_0',['force_on_particle',['../classPenningTrap.html#a4790f41e4fbc6ede4991aa7bbda92182',1,'PenningTrap']]] + ['evolve_5fforward_5feuler_0',['evolve_forward_euler',['../classPenningTrap.html#ab9ea97a406534bbe621a95215144875e',1,'PenningTrap']]], + ['evolve_5frk4_1',['evolve_RK4',['../classPenningTrap.html#a36946152fd951b1f7c346c51ff900d8e',1,'PenningTrap']]], + ['external_5fb_5ffield_2',['external_B_field',['../classPenningTrap.html#acbf065c9c125682329ad82a8d166554c',1,'PenningTrap']]], + ['external_5fe_5ffield_3',['external_E_field',['../classPenningTrap.html#a1d58feaa2c9e34cbf26b1c5ed75ca9d9',1,'PenningTrap']]] ]; diff --git a/docs/search/all_6.js b/docs/search/all_6.js index cb8673f..d1d9acc 100644 --- a/docs/search/all_6.js +++ b/docs/search/all_6.js @@ -1,4 +1,5 @@ var searchData= [ - ['k_5fe_0',['K_E',['../constants_8hpp.html#a4e451456ad7e9276ed0afa42826e7ccb',1,'constants.hpp']]] + ['force_5fon_5fparticle_0',['force_on_particle',['../classPenningTrap.html#a9ae34ad740a230e667e96bc6ee8730ce',1,'PenningTrap']]], + ['fraction_5fof_5fparticles_5fleft_1',['fraction_of_particles_left',['../classPenningTrap.html#a0194be61c956a9259c747c23e4163c5b',1,'PenningTrap']]] ]; diff --git a/docs/search/all_7.js b/docs/search/all_7.js index a26e115..6af262e 100644 --- a/docs/search/all_7.js +++ b/docs/search/all_7.js @@ -1,5 +1,6 @@ var searchData= [ - ['m_0',['m',['../classParticle.html#aedcc7e1bc53b0e2b1a4a07c9a1b47563',1,'Particle']]], - ['main_2ecpp_1',['main.cpp',['../main_8cpp.html',1,'']]] + ['k_5fe_0',['K_E',['../constants_8hpp.html#a4e451456ad7e9276ed0afa42826e7ccb',1,'constants.hpp']]], + ['k_5fr_1',['k_r',['../classPenningTrap.html#a2f168622587709b9e3c49077f0b9a640',1,'PenningTrap']]], + ['k_5fv_2',['k_v',['../classPenningTrap.html#ae9b5afdaa5cd366e94bd294452a1eed4',1,'PenningTrap']]] ]; diff --git a/docs/search/all_8.js b/docs/search/all_8.js index c435adb..d86b301 100644 --- a/docs/search/all_8.js +++ b/docs/search/all_8.js @@ -1,11 +1,7 @@ var searchData= [ - ['particle_0',['Particle',['../classParticle.html',1,'Particle'],['../classParticle.html#a00e108823877a25513ccae7cac011b4c',1,'Particle::Particle()']]], - ['particle_2ecpp_1',['Particle.cpp',['../Particle_8cpp.html',1,'']]], - ['particle_2ehpp_2',['Particle.hpp',['../Particle_8hpp.html',1,'']]], - ['particles_3',['particles',['../classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f',1,'PenningTrap']]], - ['penning_20trap_20simulation_4',['Penning trap simulation',['../index.html',1,'']]], - ['penningtrap_5',['PenningTrap',['../classPenningTrap.html',1,'PenningTrap'],['../classParticle.html#aa797d319549dc2a0beb06cdbfd430232',1,'Particle::PenningTrap()'],['../classPenningTrap.html#a81add5063bd5f29d77f0b5c299c6c560',1,'PenningTrap::PenningTrap()']]], - ['penningtrap_2ecpp_6',['PenningTrap.cpp',['../PenningTrap_8cpp.html',1,'']]], - ['penningtrap_2ehpp_7',['PenningTrap.hpp',['../PenningTrap_8hpp.html',1,'']]] + ['m_0',['m',['../classParticle.html#aedcc7e1bc53b0e2b1a4a07c9a1b47563',1,'Particle']]], + ['m_5fassert_1',['m_assert',['../utils_8hpp.html#a2cc3a2cdb635bac3c8b02e89d4d6af38',1,'m_assert(bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg): utils.cpp'],['../utils_8cpp.html#aff5e07c3c1d321709b0cc38e999f427b',1,'m_assert(bool expr, std::string expr_str, std::string f, std::string file, int line, std::string msg): utils.cpp']]], + ['main_2ecpp_2',['main.cpp',['../main_8cpp.html',1,'']]], + ['mkpath_3',['mkpath',['../utils_8hpp.html#a6fdd7217b750aff5b6295ece7cbdeffa',1,'mkpath(std::string path, int mode=0777): utils.cpp'],['../utils_8cpp.html#acf13f4e492199cb7231bfa646dbd08de',1,'mkpath(std::string path, int mode): utils.cpp']]] ]; diff --git a/docs/search/all_9.js b/docs/search/all_9.js index a43f9bc..962dfef 100644 --- a/docs/search/all_9.js +++ b/docs/search/all_9.js @@ -1,4 +1,12 @@ var searchData= [ - ['q_0',['q',['../classParticle.html#a566dcc1de4bdc01251776948798ea8e1',1,'Particle']]] + ['particle_0',['Particle',['../classParticle.html',1,'Particle'],['../classParticle.html#a7af9f8d1fef63dd7643b06629ac7bef4',1,'Particle::Particle()']]], + ['particle_2ecpp_1',['Particle.cpp',['../Particle_8cpp.html',1,'']]], + ['particle_2ehpp_2',['Particle.hpp',['../Particle_8hpp.html',1,'']]], + ['particles_3',['particles',['../classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f',1,'PenningTrap']]], + ['penning_20trap_20simulation_4',['Penning trap simulation',['../index.html',1,'']]], + ['penningtrap_5',['PenningTrap',['../classPenningTrap.html',1,'PenningTrap'],['../classParticle.html#aa797d319549dc2a0beb06cdbfd430232',1,'Particle::PenningTrap()'],['../classPenningTrap.html#ae670d7de621acdb343b01af098086f63',1,'PenningTrap::PenningTrap(double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)'],['../classPenningTrap.html#a763700316b502d5900e587c1f61e6bf1',1,'PenningTrap::PenningTrap(unsigned int i, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)'],['../classPenningTrap.html#a67139e04ef69c0bcffde8f30f67cbf73',1,'PenningTrap::PenningTrap(std::vector< Particle > particles, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)']]], + ['penningtrap_2ecpp_6',['PenningTrap.cpp',['../PenningTrap_8cpp.html',1,'']]], + ['penningtrap_2ehpp_7',['PenningTrap.hpp',['../PenningTrap_8hpp.html',1,'']]], + ['penningtraptest_8',['PenningTrapTest',['../classPenningTrapTest.html',1,'']]] ]; diff --git a/docs/search/all_a.js b/docs/search/all_a.js index b78ca6a..a43f9bc 100644 --- a/docs/search/all_a.js +++ b/docs/search/all_a.js @@ -1,4 +1,4 @@ var searchData= [ - ['r_5fvec_0',['r_vec',['../classParticle.html#acf1a0f3c978b06d76df5bb4279594467',1,'Particle']]] + ['q_0',['q',['../classParticle.html#a566dcc1de4bdc01251776948798ea8e1',1,'Particle']]] ]; diff --git a/docs/search/all_b.js b/docs/search/all_b.js index bf61385..fb8b113 100644 --- a/docs/search/all_b.js +++ b/docs/search/all_b.js @@ -1,4 +1,5 @@ var searchData= [ - ['scientific_5fformat_0',['scientific_format',['../utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384',1,'scientific_format(double d, int width=20, int prec=10): utils.cpp'],['../utils_8hpp.html#ad54b96a1074f9df4dc892a41d115b72d',1,'scientific_format(const std::vector< double > &v, int width=20, int prec=10): utils.cpp'],['../utils_8cpp.html#acd2a9c7a7d5a7fe9163be8c4cc110746',1,'scientific_format(double d, int width, int prec): utils.cpp'],['../utils_8cpp.html#a58565270b643b24e3132f38c653e0199',1,'scientific_format(const std::vector< double > &v, int width, int prec): utils.cpp']]] + ['r_5ffunc_0',['r_func',['../classPenningTrap.html#a43e74792ab4b3f9299f35cb64bdb2648',1,'PenningTrap']]], + ['r_5fvec_1',['r_vec',['../classParticle.html#af9497cd8f2dcad0fad54f571ddb383e6',1,'Particle']]] ]; diff --git a/docs/search/all_c.js b/docs/search/all_c.js index 89cf6c6..f0c09d2 100644 --- a/docs/search/all_c.js +++ b/docs/search/all_c.js @@ -1,9 +1,8 @@ var searchData= [ - ['t_0',['T',['../constants_8hpp.html#a0acb682b8260ab1c60b918599864e2e5',1,'constants.hpp']]], - ['test_5fsuite_2ecpp_1',['test_suite.cpp',['../test__suite_8cpp.html',1,'']]], - ['todo_20list_2',['Todo List',['../todo.html',1,'']]], - ['total_5fforce_3',['total_force',['../classPenningTrap.html#a83cc7a04dae009ed8e75453c38fdf8be',1,'PenningTrap']]], - ['total_5fforce_5fexternal_4',['total_force_external',['../classPenningTrap.html#a045adb85e97a8e0c38fb36d2fd74eeee',1,'PenningTrap']]], - ['total_5fforce_5fparticles_5',['total_force_particles',['../classPenningTrap.html#a135db7d991d9b88b00fde4edee71f78d',1,'PenningTrap']]] + ['scientific_5fformat_0',['scientific_format',['../utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384',1,'scientific_format(double d, int width=20, int prec=10): utils.cpp'],['../utils_8hpp.html#ad54b96a1074f9df4dc892a41d115b72d',1,'scientific_format(const std::vector< double > &v, int width=20, int prec=10): utils.cpp'],['../utils_8cpp.html#acd2a9c7a7d5a7fe9163be8c4cc110746',1,'scientific_format(double d, int width, int prec): utils.cpp'],['../utils_8cpp.html#a58565270b643b24e3132f38c653e0199',1,'scientific_format(const std::vector< double > &v, int width, int prec): utils.cpp']]], + ['sim_5farr_1',['sim_arr',['../typedefs_8hpp.html#aec69d34220fff45de238b9e01f2686af',1,'typedefs.hpp']]], + ['sim_5fcols_2',['sim_cols',['../typedefs_8hpp.html#a7c2dfa854274262c4e00e4ef0ab2ce23',1,'typedefs.hpp']]], + ['sim_5frows_3',['sim_rows',['../typedefs_8hpp.html#a8502989b1b361725834fc185bd575f66',1,'typedefs.hpp']]], + ['simulate_4',['simulate',['../classPenningTrap.html#a5331837e6dd7bce807a99edd2ba7e854',1,'PenningTrap']]] ]; diff --git a/docs/search/all_d.js b/docs/search/all_d.js index cd921db..c04457d 100644 --- a/docs/search/all_d.js +++ b/docs/search/all_d.js @@ -1,5 +1,10 @@ var searchData= [ - ['utils_2ecpp_0',['utils.cpp',['../utils_8cpp.html',1,'']]], - ['utils_2ehpp_1',['utils.hpp',['../utils_8hpp.html',1,'']]] + ['t_0',['t',['../classPenningTrap.html#a8ca4e21291f60fde619c14099d8c4e8e',1,'PenningTrap']]], + ['t_1',['T',['../constants_8hpp.html#a0acb682b8260ab1c60b918599864e2e5',1,'constants.hpp']]], + ['test_5fsuite_2ecpp_2',['test_suite.cpp',['../test__suite_8cpp.html',1,'']]], + ['total_5fforce_3',['total_force',['../classPenningTrap.html#a1f668c4433421136ad51741741aa1bc8',1,'PenningTrap']]], + ['total_5fforce_5fexternal_4',['total_force_external',['../classPenningTrap.html#ae72d203b0bfa1b9e72bea28cb2863c56',1,'PenningTrap']]], + ['total_5fforce_5fparticles_5',['total_force_particles',['../classPenningTrap.html#a46a954a0946def199e30fb300ba1c47b',1,'PenningTrap']]], + ['typedefs_2ehpp_6',['typedefs.hpp',['../typedefs_8hpp.html',1,'']]] ]; diff --git a/docs/search/all_e.js b/docs/search/all_e.js index b447fa7..cd921db 100644 --- a/docs/search/all_e.js +++ b/docs/search/all_e.js @@ -1,6 +1,5 @@ var searchData= [ - ['v_0',['V',['../constants_8hpp.html#af40a326b23c68a27cebe60f16634a2cb',1,'constants.hpp']]], - ['v_5f0_1',['V_0',['../classPenningTrap.html#a715329844d75ec4c04f8391421fb4e89',1,'PenningTrap']]], - ['v_5fvec_2',['v_vec',['../classParticle.html#a4a5d22c7aeca66f67d083f270cba25df',1,'Particle']]] + ['utils_2ecpp_0',['utils.cpp',['../utils_8cpp.html',1,'']]], + ['utils_2ehpp_1',['utils.hpp',['../utils_8hpp.html',1,'']]] ]; diff --git a/docs/search/all_f.js b/docs/search/all_f.js new file mode 100644 index 0000000..bb9c0eb --- /dev/null +++ b/docs/search/all_f.js @@ -0,0 +1,8 @@ +var searchData= +[ + ['v_0',['V',['../constants_8hpp.html#af40a326b23c68a27cebe60f16634a2cb',1,'constants.hpp']]], + ['v_5f0_1',['V_0',['../classPenningTrap.html#aaf105828121c4a33cc2b217453c20317',1,'PenningTrap']]], + ['v_5ffunc_2',['v_func',['../classPenningTrap.html#af98a720da60b0e1a62aefa5f5cb37c1e',1,'PenningTrap']]], + ['v_5fvec_3',['v_vec',['../classParticle.html#a879692772803d6ab65fa4993b54aea6e',1,'Particle']]], + ['vec_5f3d_4',['vec_3d',['../typedefs_8hpp.html#a9f33f4962c8fb62cc5ccd0e4e039a8df',1,'typedefs.hpp']]] +]; diff --git a/docs/search/classes_0.js b/docs/search/classes_0.js index c907a03..463bbc3 100644 --- a/docs/search/classes_0.js +++ b/docs/search/classes_0.js @@ -1,5 +1,6 @@ var searchData= [ ['particle_0',['Particle',['../classParticle.html',1,'']]], - ['penningtrap_1',['PenningTrap',['../classPenningTrap.html',1,'']]] + ['penningtrap_1',['PenningTrap',['../classPenningTrap.html',1,'']]], + ['penningtraptest_2',['PenningTrapTest',['../classPenningTrapTest.html',1,'']]] ]; diff --git a/docs/search/defines_0.js b/docs/search/defines_0.js index c6466cb..1e5c227 100644 --- a/docs/search/defines_0.js +++ b/docs/search/defines_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['debug_0',['DEBUG',['../utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b',1,'utils.hpp']]] + ['_5f_5fmethod_5fname_5f_5f_0',['__METHOD_NAME__',['../utils_8hpp.html#a60dca3177fb9cb5256609adc7af55168',1,'utils.hpp']]] ]; diff --git a/docs/search/defines_1.js b/docs/search/defines_1.js index cb8673f..97ce9d9 100644 --- a/docs/search/defines_1.js +++ b/docs/search/defines_1.js @@ -1,4 +1,4 @@ var searchData= [ - ['k_5fe_0',['K_E',['../constants_8hpp.html#a4e451456ad7e9276ed0afa42826e7ccb',1,'constants.hpp']]] + ['assert_0',['ASSERT',['../utils_8hpp.html#a73d4f21ad937dbc50a0c0538c78fd4f9',1,'utils.hpp']]] ]; diff --git a/docs/search/defines_2.js b/docs/search/defines_2.js index 6eef01f..c6466cb 100644 --- a/docs/search/defines_2.js +++ b/docs/search/defines_2.js @@ -1,4 +1,4 @@ var searchData= [ - ['t_0',['T',['../constants_8hpp.html#a0acb682b8260ab1c60b918599864e2e5',1,'constants.hpp']]] + ['debug_0',['DEBUG',['../utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b',1,'utils.hpp']]] ]; diff --git a/docs/search/defines_3.js b/docs/search/defines_3.js index 06f433f..cb8673f 100644 --- a/docs/search/defines_3.js +++ b/docs/search/defines_3.js @@ -1,4 +1,4 @@ var searchData= [ - ['v_0',['V',['../constants_8hpp.html#af40a326b23c68a27cebe60f16634a2cb',1,'constants.hpp']]] + ['k_5fe_0',['K_E',['../constants_8hpp.html#a4e451456ad7e9276ed0afa42826e7ccb',1,'constants.hpp']]] ]; diff --git a/docs/search/defines_4.js b/docs/search/defines_4.js new file mode 100644 index 0000000..6eef01f --- /dev/null +++ b/docs/search/defines_4.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['t_0',['T',['../constants_8hpp.html#a0acb682b8260ab1c60b918599864e2e5',1,'constants.hpp']]] +]; diff --git a/docs/search/defines_5.js b/docs/search/defines_5.js new file mode 100644 index 0000000..06f433f --- /dev/null +++ b/docs/search/defines_5.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['v_0',['V',['../constants_8hpp.html#af40a326b23c68a27cebe60f16634a2cb',1,'constants.hpp']]] +]; diff --git a/docs/search/files_3.js b/docs/search/files_3.js index 1ca9264..5e3fea9 100644 --- a/docs/search/files_3.js +++ b/docs/search/files_3.js @@ -1,4 +1,5 @@ var searchData= [ - ['test_5fsuite_2ecpp_0',['test_suite.cpp',['../test__suite_8cpp.html',1,'']]] + ['test_5fsuite_2ecpp_0',['test_suite.cpp',['../test__suite_8cpp.html',1,'']]], + ['typedefs_2ehpp_1',['typedefs.hpp',['../typedefs_8hpp.html',1,'']]] ]; diff --git a/docs/search/functions_0.js b/docs/search/functions_0.js index 8003164..72dba03 100644 --- a/docs/search/functions_0.js +++ b/docs/search/functions_0.js @@ -1,4 +1,5 @@ var searchData= [ - ['add_5fparticle_0',['add_particle',['../classPenningTrap.html#a6e9776ff5b149f01080800716455d7c8',1,'PenningTrap']]] + ['add_5fparticle_0',['add_particle',['../classPenningTrap.html#a6e9776ff5b149f01080800716455d7c8',1,'PenningTrap']]], + ['arma_5fvector_5fclose_5fto_1',['arma_vector_close_to',['../utils_8hpp.html#a0c95c4791692b06f8811905a76dbd772',1,'arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8): utils.cpp'],['../utils_8cpp.html#a5d2e1e032fd19614f2fbb58149a7b02a',1,'arma_vector_close_to(arma::vec &a, arma::vec &b, double tol): utils.cpp']]] ]; diff --git a/docs/search/functions_1.js b/docs/search/functions_1.js index c031fe4..c4c479f 100644 --- a/docs/search/functions_1.js +++ b/docs/search/functions_1.js @@ -1,7 +1,7 @@ var searchData= [ - ['evolve_5fforward_5feuler_0',['evolve_forward_euler',['../classPenningTrap.html#a56544b6f4befb42984e9650cf2a40965',1,'PenningTrap']]], - ['evolve_5frk4_1',['evolve_RK4',['../classPenningTrap.html#ab891b839c40eeb38d8a2a636c70090a9',1,'PenningTrap']]], - ['external_5fb_5ffield_2',['external_B_field',['../classPenningTrap.html#a2a3e7f480ba52e9f24d4c50c3981a784',1,'PenningTrap']]], - ['external_5fe_5ffield_3',['external_E_field',['../classPenningTrap.html#a978a2e2026a4b5308d5184712f81704b',1,'PenningTrap']]] + ['evolve_5fforward_5feuler_0',['evolve_forward_euler',['../classPenningTrap.html#ab9ea97a406534bbe621a95215144875e',1,'PenningTrap']]], + ['evolve_5frk4_1',['evolve_RK4',['../classPenningTrap.html#a36946152fd951b1f7c346c51ff900d8e',1,'PenningTrap']]], + ['external_5fb_5ffield_2',['external_B_field',['../classPenningTrap.html#acbf065c9c125682329ad82a8d166554c',1,'PenningTrap']]], + ['external_5fe_5ffield_3',['external_E_field',['../classPenningTrap.html#a1d58feaa2c9e34cbf26b1c5ed75ca9d9',1,'PenningTrap']]] ]; diff --git a/docs/search/functions_2.js b/docs/search/functions_2.js index ccf47d2..d1d9acc 100644 --- a/docs/search/functions_2.js +++ b/docs/search/functions_2.js @@ -1,4 +1,5 @@ var searchData= [ - ['force_5fon_5fparticle_0',['force_on_particle',['../classPenningTrap.html#a4790f41e4fbc6ede4991aa7bbda92182',1,'PenningTrap']]] + ['force_5fon_5fparticle_0',['force_on_particle',['../classPenningTrap.html#a9ae34ad740a230e667e96bc6ee8730ce',1,'PenningTrap']]], + ['fraction_5fof_5fparticles_5fleft_1',['fraction_of_particles_left',['../classPenningTrap.html#a0194be61c956a9259c747c23e4163c5b',1,'PenningTrap']]] ]; diff --git a/docs/search/functions_3.js b/docs/search/functions_3.js index 2dc79c5..ffb26d6 100644 --- a/docs/search/functions_3.js +++ b/docs/search/functions_3.js @@ -1,5 +1,5 @@ var searchData= [ - ['particle_0',['Particle',['../classParticle.html#a00e108823877a25513ccae7cac011b4c',1,'Particle']]], - ['penningtrap_1',['PenningTrap',['../classPenningTrap.html#a81add5063bd5f29d77f0b5c299c6c560',1,'PenningTrap']]] + ['m_5fassert_0',['m_assert',['../utils_8hpp.html#a2cc3a2cdb635bac3c8b02e89d4d6af38',1,'m_assert(bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg): utils.cpp'],['../utils_8cpp.html#aff5e07c3c1d321709b0cc38e999f427b',1,'m_assert(bool expr, std::string expr_str, std::string f, std::string file, int line, std::string msg): utils.cpp']]], + ['mkpath_1',['mkpath',['../utils_8hpp.html#a6fdd7217b750aff5b6295ece7cbdeffa',1,'mkpath(std::string path, int mode=0777): utils.cpp'],['../utils_8cpp.html#acf13f4e492199cb7231bfa646dbd08de',1,'mkpath(std::string path, int mode): utils.cpp']]] ]; diff --git a/docs/search/functions_4.js b/docs/search/functions_4.js index bf61385..852716e 100644 --- a/docs/search/functions_4.js +++ b/docs/search/functions_4.js @@ -1,4 +1,5 @@ var searchData= [ - ['scientific_5fformat_0',['scientific_format',['../utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384',1,'scientific_format(double d, int width=20, int prec=10): utils.cpp'],['../utils_8hpp.html#ad54b96a1074f9df4dc892a41d115b72d',1,'scientific_format(const std::vector< double > &v, int width=20, int prec=10): utils.cpp'],['../utils_8cpp.html#acd2a9c7a7d5a7fe9163be8c4cc110746',1,'scientific_format(double d, int width, int prec): utils.cpp'],['../utils_8cpp.html#a58565270b643b24e3132f38c653e0199',1,'scientific_format(const std::vector< double > &v, int width, int prec): utils.cpp']]] + ['particle_0',['Particle',['../classParticle.html#a7af9f8d1fef63dd7643b06629ac7bef4',1,'Particle']]], + ['penningtrap_1',['PenningTrap',['../classPenningTrap.html#ae670d7de621acdb343b01af098086f63',1,'PenningTrap::PenningTrap(double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)'],['../classPenningTrap.html#a763700316b502d5900e587c1f61e6bf1',1,'PenningTrap::PenningTrap(unsigned int i, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)'],['../classPenningTrap.html#a67139e04ef69c0bcffde8f30f67cbf73',1,'PenningTrap::PenningTrap(std::vector< Particle > particles, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)']]] ]; diff --git a/docs/search/functions_5.js b/docs/search/functions_5.js index 83f26c2..07b3041 100644 --- a/docs/search/functions_5.js +++ b/docs/search/functions_5.js @@ -1,6 +1,4 @@ var searchData= [ - ['total_5fforce_0',['total_force',['../classPenningTrap.html#a83cc7a04dae009ed8e75453c38fdf8be',1,'PenningTrap']]], - ['total_5fforce_5fexternal_1',['total_force_external',['../classPenningTrap.html#a045adb85e97a8e0c38fb36d2fd74eeee',1,'PenningTrap']]], - ['total_5fforce_5fparticles_2',['total_force_particles',['../classPenningTrap.html#a135db7d991d9b88b00fde4edee71f78d',1,'PenningTrap']]] + ['r_5ffunc_0',['r_func',['../classPenningTrap.html#a43e74792ab4b3f9299f35cb64bdb2648',1,'PenningTrap']]] ]; diff --git a/docs/search/functions_6.js b/docs/search/functions_6.js new file mode 100644 index 0000000..a7b65b4 --- /dev/null +++ b/docs/search/functions_6.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['scientific_5fformat_0',['scientific_format',['../utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384',1,'scientific_format(double d, int width=20, int prec=10): utils.cpp'],['../utils_8hpp.html#ad54b96a1074f9df4dc892a41d115b72d',1,'scientific_format(const std::vector< double > &v, int width=20, int prec=10): utils.cpp'],['../utils_8cpp.html#acd2a9c7a7d5a7fe9163be8c4cc110746',1,'scientific_format(double d, int width, int prec): utils.cpp'],['../utils_8cpp.html#a58565270b643b24e3132f38c653e0199',1,'scientific_format(const std::vector< double > &v, int width, int prec): utils.cpp']]], + ['simulate_1',['simulate',['../classPenningTrap.html#a5331837e6dd7bce807a99edd2ba7e854',1,'PenningTrap']]] +]; diff --git a/docs/search/functions_7.js b/docs/search/functions_7.js new file mode 100644 index 0000000..73e1881 --- /dev/null +++ b/docs/search/functions_7.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['total_5fforce_0',['total_force',['../classPenningTrap.html#a1f668c4433421136ad51741741aa1bc8',1,'PenningTrap']]], + ['total_5fforce_5fexternal_1',['total_force_external',['../classPenningTrap.html#ae72d203b0bfa1b9e72bea28cb2863c56',1,'PenningTrap']]], + ['total_5fforce_5fparticles_2',['total_force_particles',['../classPenningTrap.html#a46a954a0946def199e30fb300ba1c47b',1,'PenningTrap']]] +]; diff --git a/docs/search/functions_8.js b/docs/search/functions_8.js new file mode 100644 index 0000000..8d7b6ff --- /dev/null +++ b/docs/search/functions_8.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['v_5ffunc_0',['v_func',['../classPenningTrap.html#af98a720da60b0e1a62aefa5f5cb37c1e',1,'PenningTrap']]] +]; diff --git a/docs/search/functions_9.js b/docs/search/functions_9.js new file mode 100644 index 0000000..1b9fc74 --- /dev/null +++ b/docs/search/functions_9.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['write_5fsimulation_5fto_5fdir_0',['write_simulation_to_dir',['../classPenningTrap.html#abbb832a85139b1a56ebde57d7b8f9a57',1,'PenningTrap']]] +]; diff --git a/docs/search/searchdata.js b/docs/search/searchdata.js index ca77c16..4d47bbf 100644 --- a/docs/search/searchdata.js +++ b/docs/search/searchdata.js @@ -1,13 +1,14 @@ var indexSectionsWithContent = { - 0: "abcdefkmpqrstuv", + 0: "_abcdefkmpqrstuvw", 1: "p", 2: "cmptu", - 3: "aefpst", - 4: "bdmpqrv", - 5: "p", - 6: "dktv", - 7: "bpt" + 3: "aefmprstvw", + 4: "bdkmpqrtv", + 5: "sv", + 6: "p", + 7: "_adktv", + 8: "bp" }; var indexSectionNames = @@ -17,9 +18,10 @@ var indexSectionNames = 2: "files", 3: "functions", 4: "variables", - 5: "related", - 6: "defines", - 7: "pages" + 5: "typedefs", + 6: "related", + 7: "defines", + 8: "pages" }; var indexSectionLabels = @@ -29,8 +31,9 @@ var indexSectionLabels = 2: "Files", 3: "Functions", 4: "Variables", - 5: "Friends", - 6: "Macros", - 7: "Pages" + 5: "Typedefs", + 6: "Friends", + 7: "Macros", + 8: "Pages" }; diff --git a/docs/search/typedefs_0.js b/docs/search/typedefs_0.js new file mode 100644 index 0000000..e79ff95 --- /dev/null +++ b/docs/search/typedefs_0.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['sim_5farr_0',['sim_arr',['../typedefs_8hpp.html#aec69d34220fff45de238b9e01f2686af',1,'typedefs.hpp']]], + ['sim_5fcols_1',['sim_cols',['../typedefs_8hpp.html#a7c2dfa854274262c4e00e4ef0ab2ce23',1,'typedefs.hpp']]], + ['sim_5frows_2',['sim_rows',['../typedefs_8hpp.html#a8502989b1b361725834fc185bd575f66',1,'typedefs.hpp']]] +]; diff --git a/docs/search/typedefs_1.js b/docs/search/typedefs_1.js new file mode 100644 index 0000000..fe88abf --- /dev/null +++ b/docs/search/typedefs_1.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['vec_5f3d_0',['vec_3d',['../typedefs_8hpp.html#a9f33f4962c8fb62cc5ccd0e4e039a8df',1,'typedefs.hpp']]] +]; diff --git a/docs/search/variables_2.js b/docs/search/variables_2.js index 8411aec..7ff6c24 100644 --- a/docs/search/variables_2.js +++ b/docs/search/variables_2.js @@ -1,4 +1,5 @@ var searchData= [ - ['m_0',['m',['../classParticle.html#aedcc7e1bc53b0e2b1a4a07c9a1b47563',1,'Particle']]] + ['k_5fr_0',['k_r',['../classPenningTrap.html#a2f168622587709b9e3c49077f0b9a640',1,'PenningTrap']]], + ['k_5fv_1',['k_v',['../classPenningTrap.html#ae9b5afdaa5cd366e94bd294452a1eed4',1,'PenningTrap']]] ]; diff --git a/docs/search/variables_3.js b/docs/search/variables_3.js index c9f603d..8411aec 100644 --- a/docs/search/variables_3.js +++ b/docs/search/variables_3.js @@ -1,4 +1,4 @@ var searchData= [ - ['particles_0',['particles',['../classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f',1,'PenningTrap']]] + ['m_0',['m',['../classParticle.html#aedcc7e1bc53b0e2b1a4a07c9a1b47563',1,'Particle']]] ]; diff --git a/docs/search/variables_4.js b/docs/search/variables_4.js index a43f9bc..c9f603d 100644 --- a/docs/search/variables_4.js +++ b/docs/search/variables_4.js @@ -1,4 +1,4 @@ var searchData= [ - ['q_0',['q',['../classParticle.html#a566dcc1de4bdc01251776948798ea8e1',1,'Particle']]] + ['particles_0',['particles',['../classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f',1,'PenningTrap']]] ]; diff --git a/docs/search/variables_5.js b/docs/search/variables_5.js index b78ca6a..a43f9bc 100644 --- a/docs/search/variables_5.js +++ b/docs/search/variables_5.js @@ -1,4 +1,4 @@ var searchData= [ - ['r_5fvec_0',['r_vec',['../classParticle.html#acf1a0f3c978b06d76df5bb4279594467',1,'Particle']]] + ['q_0',['q',['../classParticle.html#a566dcc1de4bdc01251776948798ea8e1',1,'Particle']]] ]; diff --git a/docs/search/variables_6.js b/docs/search/variables_6.js index 01f3a29..fa44d82 100644 --- a/docs/search/variables_6.js +++ b/docs/search/variables_6.js @@ -1,5 +1,4 @@ var searchData= [ - ['v_5f0_0',['V_0',['../classPenningTrap.html#a715329844d75ec4c04f8391421fb4e89',1,'PenningTrap']]], - ['v_5fvec_1',['v_vec',['../classParticle.html#a4a5d22c7aeca66f67d083f270cba25df',1,'Particle']]] + ['r_5fvec_0',['r_vec',['../classParticle.html#af9497cd8f2dcad0fad54f571ddb383e6',1,'Particle']]] ]; diff --git a/docs/search/variables_7.js b/docs/search/variables_7.js new file mode 100644 index 0000000..c7c5d99 --- /dev/null +++ b/docs/search/variables_7.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['t_0',['t',['../classPenningTrap.html#a8ca4e21291f60fde619c14099d8c4e8e',1,'PenningTrap']]] +]; diff --git a/docs/search/variables_8.js b/docs/search/variables_8.js new file mode 100644 index 0000000..601b41d --- /dev/null +++ b/docs/search/variables_8.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['v_5f0_0',['V_0',['../classPenningTrap.html#aaf105828121c4a33cc2b217453c20317',1,'PenningTrap']]], + ['v_5fvec_1',['v_vec',['../classParticle.html#a879692772803d6ab65fa4993b54aea6e',1,'Particle']]] +]; diff --git a/docs/test_8py_source.html b/docs/test_8py_source.html new file mode 100644 index 0000000..17942db --- /dev/null +++ b/docs/test_8py_source.html @@ -0,0 +1,177 @@ + + + + + + + +Penning Trap Simulation: src/test.py Source File + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    test.py
    +
    +
    +
    1import matplotlib.pyplot as plt
    +
    2import numpy as np
    +
    3from mpl_toolkits.mplot3d import Axes3D
    +
    4from matplotlib import animation
    +
    5
    +
    6def get_data(files):
    +
    7 res = []
    +
    8 for file in files:
    +
    9 arr = [[], [], []]
    +
    10 with open(file) as f:
    +
    11 lines = f.readlines()
    +
    12
    +
    13 for line in lines:
    +
    14 xi,yi,zi = map(lambda x: float(x), line.strip().split(","))
    +
    15 arr[0].append(xi)
    +
    16 arr[1].append(yi)
    +
    17 arr[2].append(zi)
    +
    18 res.append(arr)
    +
    19
    +
    20 return np.array(res)
    +
    21
    +
    22def update(num, lines, arr):
    +
    23 for line, a in zip(lines, arr):
    +
    24 line.set_data(a[:2, num])
    +
    25 line.set_3d_properties(a[2, num])
    +
    26
    +
    27
    +
    28
    +
    29def animate():
    +
    30 fig = plt.figure()
    +
    31 ax = fig.add_subplot(projection="3d")
    +
    32
    +
    33
    +
    34 arr = get_data([f"output/p{i}.txt" for i in range(100)])
    +
    35
    +
    36 arr = arr[:,:,::10]
    +
    37
    +
    38 N = len(arr[0][0])
    +
    39
    +
    40 lines = [ax.plot(*a[:,1], "o")[0] for a in arr]
    +
    41
    +
    42 ax.set_xlim3d([-500.0, 500.0])
    +
    43 ax.set_xlabel('X')
    +
    44
    +
    45 ax.set_ylim3d([-500.0, 500.0])
    +
    46 ax.set_ylabel('Y')
    +
    47
    +
    48 ax.set_zlim3d([-500.0, 500.0])
    +
    49 ax.set_zlabel('Z')
    +
    50
    +
    51 ani = animation.FuncAnimation(fig, update, N, fargs=(lines, arr),
    +
    52 interval=1,
    +
    53 blit=False)
    +
    54
    +
    55
    +
    56 # ani.save("100_particles.gif", writer=animation.FFMpegFileWriter(fps=30))
    +
    57 plt.show()
    +
    58
    +
    59
    +
    60if __name__ == "__main__":
    +
    61 animate()
    +
    62
    +
    63
    +
    +
    + + + + diff --git a/docs/test__suite_8cpp.html b/docs/test__suite_8cpp.html index 2bab26f..7c69921 100644 --- a/docs/test__suite_8cpp.html +++ b/docs/test__suite_8cpp.html @@ -99,6 +99,7 @@ $(document).ready(function(){initNavTree('test__suite_8cpp.html',''); initResiza
    +Classes | Functions
    test_suite.cpp File Reference
    @@ -106,9 +107,19 @@ $(document).ready(function(){initNavTree('test__suite_8cpp.html',''); initResiza

    The test suite for the project. More...

    - +
    #include "PenningTrap.hpp"
    +#include "utils.hpp"
    +#include <iomanip>
    +#include <sstream>
    +#include <string>
    +

    Go to the source code of this file.

    + + + +

    +Classes

    class  PenningTrapTest
     
    @@ -120,7 +131,7 @@ Functions
    Janita Ovidie Sandtrøen Willumsen (janitaws)
    Version
    0.1
    -
    Bug:
    No known bugs
    +
    Bug:
    No known bugs

    Definition in file test_suite.cpp.

    Function Documentation

    @@ -139,7 +150,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    Functions

    int main ()
    -

    Definition at line 12 of file test_suite.cpp.

    +

    Definition at line 135 of file test_suite.cpp.

    diff --git a/docs/test__suite_8cpp.js b/docs/test__suite_8cpp.js new file mode 100644 index 0000000..5bace7d --- /dev/null +++ b/docs/test__suite_8cpp.js @@ -0,0 +1,4 @@ +var test__suite_8cpp = +[ + [ "PenningTrapTest", "classPenningTrapTest.html", null ] +]; \ No newline at end of file diff --git a/docs/test__suite_8cpp_source.html b/docs/test__suite_8cpp_source.html index 056e5c3..b317c82 100644 --- a/docs/test__suite_8cpp_source.html +++ b/docs/test__suite_8cpp_source.html @@ -102,10 +102,151 @@ $(document).ready(function(){initNavTree('test__suite_8cpp_source.html',''); ini
    Go to the documentation of this file.
    1
    -
    12int main()
    -
    13{
    -
    14 return 0;
    -
    15}
    +
    13#include "PenningTrap.hpp"
    +
    14#include "utils.hpp"
    +
    15
    +
    16#include <iomanip>
    +
    17#include <sstream>
    +
    18#include <string>
    +
    19
    + +
    21public:
    +
    22 static void test_external_E_field()
    +
    23 {
    +
    24 PenningTrap trap;
    +
    25
    +
    26 // Vector containing inputs and expected results
    +
    27 std::vector<std::pair<arma::vec, arma::vec>> tests;
    +
    28
    +
    29 tests.push_back(
    +
    30 std::make_pair(arma::vec{0., 0., 0.}, arma::vec{0., 0., 0.}));
    +
    31
    +
    32 tests.push_back(std::make_pair(arma::vec{10., 0., 0.},
    +
    33 arma::vec{96.4852558, 0., 0.}));
    +
    34
    +
    35 tests.push_back(std::make_pair(arma::vec{10., 0., 0.},
    +
    36 arma::vec{96.4852558, 0., 0.}));
    +
    37
    +
    38 tests.push_back(std::make_pair(arma::vec{0., 10., 0.},
    +
    39 arma::vec{0., 96.4852558, 0.}));
    +
    40
    +
    41 tests.push_back(std::make_pair(arma::vec{0., 0., 10.},
    +
    42 arma::vec{0., 0., -192.9705116}));
    +
    43
    +
    44 arma::vec result;
    +
    45 arma::vec v;
    +
    46 std::stringstream msg;
    +
    47 for (size_t i = 0; i < tests.size(); i++) {
    +
    48 v = tests.at(i).first;
    +
    49 result = trap.external_E_field(v);
    +
    50
    +
    51 msg.str("");
    +
    52 msg << "Testing the external E field at (" << std::setprecision(2)
    +
    53 << v(0) << "," << v(1) << "," << v(2) << ").";
    +
    54
    +
    55 ASSERT(arma_vector_close_to(result, tests.at(i).second), msg.str());
    +
    56 }
    +
    57 }
    +
    58
    +
    59 static void test_external_B_field()
    +
    60 {
    +
    61 // No point in testing at different points since it's not dependent
    +
    62 // on position.
    +
    63 PenningTrap trap;
    +
    64 arma::vec expected{0., 0., T};
    +
    65 arma::vec result = trap.external_B_field(arma::vec{0., 0., 0.});
    +
    66 ASSERT(arma_vector_close_to(expected, result),
    +
    67 "Testing the external B field at (0,0,0)");
    +
    68 }
    +
    69
    +
    70 static void test_force_on_particle()
    +
    71 {
    +
    72 PenningTrap trap;
    +
    73 arma::vec v{0., 0., 0.};
    +
    74
    +
    75 // Add particles to test
    +
    76 trap.add_particle(Particle(1., 40., arma::vec{0., 0., 0.}, v));
    +
    77 trap.add_particle(Particle(1., 40., arma::vec{1., 0., 0.}, v));
    +
    78 trap.add_particle(Particle(1., 40., arma::vec{0., 3., 4.}, v));
    +
    79
    +
    80 // Test p0 and p1
    +
    81 arma::vec expected{-1., 0., 0.};
    +
    82 arma::vec result = trap.force_on_particle(0, 1);
    +
    83 ASSERT(arma_vector_close_to(expected, result),
    +
    84 "Testing the force on a particle at (0,0,0) from a "
    +
    85 "particle at (1,0,0).");
    +
    86
    +
    87 // Test p0 and p2
    +
    88 expected = arma::vec{0, -.024, -.032};
    +
    89 result = trap.force_on_particle(0, 2);
    +
    90 ASSERT(arma_vector_close_to(expected, result),
    +
    91 "Testing the force on a particle at (0,0,0) from a "
    +
    92 "particle at (0,3,4).");
    +
    93 }
    +
    94
    +
    95 static void test_total_force_external()
    +
    96 {
    +
    97 PenningTrap trap;
    +
    98 trap.add_particle(
    +
    99 Particle(1., 40., arma::vec{1., 2., 3.}, arma::vec{3., 4., 5.}));
    +
    100
    +
    101 arma::vec expected{395.58954878, -270.15871624, -57.89115348};
    +
    102 arma::vec result = trap.total_force_external(0);
    +
    103 ASSERT(arma_vector_close_to(expected, result),
    +
    104 "Testing the total external force on a particle at "
    +
    105 "(1,2,3) with velocity (3,4,5)");
    +
    106 }
    +
    107
    +
    108 static void test_total_force_particles()
    +
    109 {
    +
    110 PenningTrap trap;
    +
    111 trap.add_particle(
    +
    112 Particle(1., 40., arma::vec{0., 0., 0.}, arma::vec{0., 0., 0.}));
    +
    113
    +
    114 arma::vec expected{0., 0., 0.};
    +
    115 arma::vec result = trap.total_force_particles(0);
    +
    116 ASSERT(arma_vector_close_to(expected, result),
    +
    117 "Testing the total force of all particles on particle 0 "
    +
    118 "with only a single particle");
    +
    119
    +
    120 trap.add_particle(
    +
    121 Particle(1., 40., arma::vec{1., 0., 0.}, arma::vec{0., 0., 0.}));
    +
    122 trap.add_particle(
    +
    123 Particle(1., 40., arma::vec{0., 1., 0.}, arma::vec{0., 0., 0.}));
    +
    124 trap.add_particle(
    +
    125 Particle(1., 40., arma::vec{0., 0., 1.}, arma::vec{0., 0., 0.}));
    +
    126
    +
    127 expected = arma::vec(3, arma::fill::value(-3473.383325));
    +
    128 result = trap.total_force_particles(0);
    +
    129 ASSERT(arma_vector_close_to(expected, result),
    +
    130 "Testing the total force of all particles on particle 0 "
    +
    131 "with 3 other particles.");
    +
    132 }
    +
    133};
    +
    134
    +
    135int main()
    +
    136{
    +
    137 PenningTrapTest::test_external_E_field();
    +
    138 PenningTrapTest::test_external_B_field();
    +
    139 PenningTrapTest::test_force_on_particle();
    +
    140 PenningTrapTest::test_total_force_external();
    +
    141 PenningTrapTest::test_total_force_particles();
    +
    142 return 0;
    +
    143}
    +
    A class for simulating a Penning trap.
    +
    A class that holds attributes of a particle.
    Definition: Particle.hpp:21
    + +
    A class that simulates a Penning trap.
    Definition: PenningTrap.hpp:30
    +
    vec_3d external_E_field(vec_3d r)
    Calculate E at point r.
    Definition: PenningTrap.cpp:87
    +
    vec_3d total_force_particles(unsigned int i)
    Calculate the total force on a particle p_i from other particles.
    +
    void add_particle(Particle particle)
    Add a particle to the system.
    Definition: PenningTrap.cpp:82
    +
    vec_3d force_on_particle(unsigned int i, unsigned int j)
    Calculate the force between 2 particles.
    +
    vec_3d external_B_field(vec_3d r)
    Calculate B at point r.
    Definition: PenningTrap.cpp:95
    +
    vec_3d total_force_external(unsigned int i)
    Calculate the total external force on a particle.
    +
    #define T
    1 Tesla. unit:
    Definition: constants.hpp:17
    +
    Function prototypes and macros that are useful.
    +
    bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8)
    Test if two armadillo vectors are close to each other.
    Definition: utils.cpp:62
    +
    #define ASSERT(expr, msg)
    A prettier assertion function.
    Definition: utils.hpp:45
    diff --git a/docs/todo.html b/docs/todo.html index 8c5247d..b6363dc 100644 --- a/docs/todo.html +++ b/docs/todo.html @@ -102,26 +102,8 @@ $(document).ready(function(){initNavTree('todo.html',''); initResizable(); });
    -
    File Particle.cpp
    -
    Implement constructor
    File PenningTrap.cpp
    -

    Implement constructor

    -

    -

    Implement add_particle

    -

    -

    Implement external_E_field

    -

    -

    Implement external_B_field

    -

    -

    Implement force_on_particle

    -

    -

    Implement total_force_external

    -

    -

    Implement total_force_particles

    -

    -

    Implement total_force

    -

    -

    Implement evolve_RK4

    +

    Implement evolve_RK4

    Implement evolve_forward_euler

    diff --git a/docs/typedefs_8hpp.html b/docs/typedefs_8hpp.html new file mode 100644 index 0000000..1f2eedb --- /dev/null +++ b/docs/typedefs_8hpp.html @@ -0,0 +1,222 @@ + + + + + + + +Penning Trap Simulation: include/typedefs.hpp File Reference + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    + +
    typedefs.hpp File Reference
    +
    +
    + +

    Useful typedefs for cleaner code. +More...

    +
    #include <vector>
    +#include <armadillo>
    +
    +

    Go to the source code of this file.

    + + + + + + + + + + + + + + +

    +Typedefs

    typedef std::vector< arma::vec::fixed< 3 > > sim_cols
     Typedef for the column of the result vector from simulating particles.
     
    typedef std::vector< arma::vec::fixed< 3 > > sim_rows
     Typedef for the row of the result vector from simulating particles.
     
    typedef std::vector< sim_colssim_arr
     Typedef for the result of the simulate method.
     
    typedef arma::vec::fixed< 3 > vec_3d
     Typedef for a fixed 3d arma vector.
     
    +

    Detailed Description

    +

    Useful typedefs for cleaner code.

    +
    Author
    Cory Alexander Balaton (coryab)
    +
    +Janita Ovidie Sandtrøen Willumsen (janitaws)
    +
    Version
    1.0
    +

    These typedefs make the code more readable and easy to follow along.

    +
    Bug:
    No known bugs
    + +

    Definition in file typedefs.hpp.

    +

    Typedef Documentation

    + +

    ◆ sim_arr

    + +
    +
    + + + + +
    typedef std::vector<sim_cols> sim_arr
    +
    + +

    Typedef for the result of the simulate method.

    + +

    Definition at line 32 of file typedefs.hpp.

    + +
    +
    + +

    ◆ sim_cols

    + +
    +
    + + + + +
    typedef std::vector<arma::vec::fixed<3> > sim_cols
    +
    + +

    Typedef for the column of the result vector from simulating particles.

    + +

    Definition at line 24 of file typedefs.hpp.

    + +
    +
    + +

    ◆ sim_rows

    + +
    +
    + + + + +
    typedef std::vector<arma::vec::fixed<3> > sim_rows
    +
    + +

    Typedef for the row of the result vector from simulating particles.

    + +

    Definition at line 28 of file typedefs.hpp.

    + +
    +
    + +

    ◆ vec_3d

    + +
    +
    + + + + +
    typedef arma::vec::fixed<3> vec_3d
    +
    + +

    Typedef for a fixed 3d arma vector.

    + +

    Definition at line 36 of file typedefs.hpp.

    + +
    +
    +
    +
    + + + + diff --git a/docs/typedefs_8hpp.js b/docs/typedefs_8hpp.js new file mode 100644 index 0000000..d014844 --- /dev/null +++ b/docs/typedefs_8hpp.js @@ -0,0 +1,7 @@ +var typedefs_8hpp = +[ + [ "sim_arr", "typedefs_8hpp.html#aec69d34220fff45de238b9e01f2686af", null ], + [ "sim_cols", "typedefs_8hpp.html#a7c2dfa854274262c4e00e4ef0ab2ce23", null ], + [ "sim_rows", "typedefs_8hpp.html#a8502989b1b361725834fc185bd575f66", null ], + [ "vec_3d", "typedefs_8hpp.html#a9f33f4962c8fb62cc5ccd0e4e039a8df", null ] +]; \ No newline at end of file diff --git a/docs/typedefs_8hpp_source.html b/docs/typedefs_8hpp_source.html new file mode 100644 index 0000000..475ff07 --- /dev/null +++ b/docs/typedefs_8hpp_source.html @@ -0,0 +1,134 @@ + + + + + + + +Penning Trap Simulation: include/typedefs.hpp Source File + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    typedefs.hpp
    +
    +
    +Go to the documentation of this file.
    1
    +
    15#ifndef __TYPEDEFS__
    +
    16#define __TYPEDEFS__
    +
    17
    +
    18#include <vector>
    +
    19#include <armadillo>
    +
    20
    +
    24typedef std::vector<arma::vec::fixed<3>> sim_cols;
    +
    25
    +
    28typedef std::vector<arma::vec::fixed<3>> sim_rows;
    +
    29
    +
    32typedef std::vector<sim_cols> sim_arr;
    +
    33
    +
    36typedef arma::vec::fixed<3> vec_3d;
    +
    37
    +
    38#endif
    +
    std::vector< arma::vec::fixed< 3 > > sim_cols
    Typedef for the column of the result vector from simulating particles.
    Definition: typedefs.hpp:24
    +
    std::vector< arma::vec::fixed< 3 > > sim_rows
    Typedef for the row of the result vector from simulating particles.
    Definition: typedefs.hpp:28
    +
    arma::vec::fixed< 3 > vec_3d
    Typedef for a fixed 3d arma vector.
    Definition: typedefs.hpp:36
    +
    std::vector< sim_cols > sim_arr
    Typedef for the result of the simulate method.
    Definition: typedefs.hpp:32
    +
    +
    + + + + diff --git a/docs/utils_8cpp.html b/docs/utils_8cpp.html index 74ad93f..9401b51 100644 --- a/docs/utils_8cpp.html +++ b/docs/utils_8cpp.html @@ -106,7 +106,8 @@ $(document).ready(function(){initNavTree('utils_8cpp.html',''); initResizable();

    Implementation of the utils. More...

    -
    #include "utils.hpp"
    +
    #include <sys/stat.h>
    +#include "utils.hpp"

    Go to the source code of this file.

    @@ -118,6 +119,15 @@ Functions + + + + + + + + +
    std::string scientific_format (const std::vector< double > &v, int width, int prec)
     Turns a vector of doubles into a string written in scientific format.
     
    void m_assert (bool expr, std::string expr_str, std::string f, std::string file, int line, std::string msg)
     Test an expression, confirm that test is ok, or abort execution.
     
    bool arma_vector_close_to (arma::vec &a, arma::vec &b, double tol)
     Test if two armadillo vectors are close to each other.
     
    bool mkpath (std::string path, int mode)
     Make path given.
     

    Detailed Description

    Implementation of the utils.

    @@ -125,10 +135,167 @@ Functions
    Janita Ovidie Sandtrøen Willumsen (janitaws)
    Version
    1.0
    -
    Bug:
    No known bugs
    +
    Bug:
    No known bugs

    Definition in file utils.cpp.

    Function Documentation

    + +

    ◆ arma_vector_close_to()

    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    bool arma_vector_close_to (arma::vec & a,
    arma::vec & b,
    double tol = 1e-8 
    )
    +
    + +

    Test if two armadillo vectors are close to each other.

    +

    This function takes in 2 vectors and checks if they are approximately equal to each other given a tolerance.

    +
    Parameters
    + + + + +
    aVector a
    bVector b
    tolThe tolerance
    +
    +
    +
    Returns
    bool
    + +

    Definition at line 62 of file utils.cpp.

    + +
    +
    + +

    ◆ m_assert()

    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    void m_assert (bool expr,
    std::string expr_str,
    std::string func,
    std::string file,
    int line,
    std::string msg 
    )
    +
    + +

    Test an expression, confirm that test is ok, or abort execution.

    +

    This function takes in an expression and prints an OK message if it's true, or it prints a fail message and aborts execution if it fails.

    +
    Parameters
    + + + + + + + +
    exprThe expression to be evaluated
    expr_strThe stringified version of the expression
    funcThe function name of the caller
    fileThe file of the caller
    lineThe line number where this function is called from
    msgThe message to be displayed
    +
    +
    + +

    Definition at line 43 of file utils.cpp.

    + +
    +
    + +

    ◆ mkpath()

    + +
    +
    + + + + + + + + + + + + + + + + + + +
    bool mkpath (std::string path,
    int mode = 0777 
    )
    +
    + +

    Make path given.

    +

    This tries to be the equivalent to "mkdir -p" and creates a new directory whenever it needs to.

    +
    Parameters
    + + + +
    pathThe path to be created
    modeThe mode/permissions for all the new directories
    +
    +
    +
    Returns
    bool
    + +

    Definition at line 76 of file utils.cpp.

    + +
    +

    ◆ scientific_format() [1/2]

    @@ -162,6 +329,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    Turns a vector of doubles into a string written in scientific format.

    +

    The code is stolen from https://github.com/anderkve/FYS3150.

    Parameters
    @@ -170,9 +338,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    vThe vector to stringify
    -
    Returns
    String
    +
    Returns
    std::string
    -

    Definition at line 21 of file utils.cpp.

    +

    Definition at line 24 of file utils.cpp.

    @@ -209,7 +377,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    Turns a double into a string written in scientific format.

    -

    Code stolen from https://github.com/anderkve/FYS3150 Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp

    +

    The code is stolen from https://github.com/anderkve/FYS3150.

    Parameters
    @@ -218,9 +386,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    dThe number to stringify
    -
    Returns
    String
    +
    Returns
    std::string
    -

    Definition at line 14 of file utils.cpp.

    +

    Definition at line 17 of file utils.cpp.

    diff --git a/docs/utils_8cpp.js b/docs/utils_8cpp.js index f2eda7a..362b36a 100644 --- a/docs/utils_8cpp.js +++ b/docs/utils_8cpp.js @@ -1,5 +1,8 @@ var utils_8cpp = [ + [ "arma_vector_close_to", "utils_8cpp.html#a5d2e1e032fd19614f2fbb58149a7b02a", null ], + [ "m_assert", "utils_8cpp.html#aff5e07c3c1d321709b0cc38e999f427b", null ], + [ "mkpath", "utils_8cpp.html#acf13f4e492199cb7231bfa646dbd08de", null ], [ "scientific_format", "utils_8cpp.html#a58565270b643b24e3132f38c653e0199", null ], [ "scientific_format", "utils_8cpp.html#acd2a9c7a7d5a7fe9163be8c4cc110746", null ] ]; \ No newline at end of file diff --git a/docs/utils_8cpp_source.html b/docs/utils_8cpp_source.html index 11f53d7..5ed9571 100644 --- a/docs/utils_8cpp_source.html +++ b/docs/utils_8cpp_source.html @@ -102,24 +102,97 @@ $(document).ready(function(){initNavTree('utils_8cpp_source.html',''); initResiz
    Go to the documentation of this file.
    1
    -
    12#include "utils.hpp"
    -
    13
    -
    14std::string scientific_format(double d, int width, int prec)
    -
    15{
    -
    16 std::stringstream ss;
    -
    17 ss << std::setw(width) << std::setprecision(prec) << std::scientific << d;
    -
    18 return ss.str();
    -
    19}
    -
    20
    -
    21std::string scientific_format(const std::vector<double>& v, int width, int prec)
    -
    22{
    -
    23 std::stringstream ss;
    -
    24 for(double elem : v) {
    -
    25 ss << scientific_format(elem, width, prec);
    -
    26 }
    -
    27 return ss.str();
    -
    28}
    -
    std::string scientific_format(double d, int width, int prec)
    Turns a double into a string written in scientific format.
    Definition: utils.cpp:14
    +
    13#include <sys/stat.h>
    +
    14
    +
    15#include "utils.hpp"
    +
    16
    +
    17std::string scientific_format(double d, int width, int prec)
    +
    18{
    +
    19 std::stringstream ss;
    +
    20 ss << std::setw(width) << std::setprecision(prec) << std::scientific << d;
    +
    21 return ss.str();
    +
    22}
    +
    23
    +
    24std::string scientific_format(const std::vector<double> &v, int width, int prec)
    +
    25{
    +
    26 std::stringstream ss;
    +
    27 for (double elem : v) {
    +
    28 ss << scientific_format(elem, width, prec);
    +
    29 }
    +
    30 return ss.str();
    +
    31}
    +
    32
    +
    33static void print_message(std::string msg)
    +
    34{
    +
    35 if (msg.size() > 0) {
    +
    36 std::cout << "message: " << msg << "\n\n";
    +
    37 }
    +
    38 else {
    +
    39 std::cout << "\n";
    +
    40 }
    +
    41}
    +
    42
    +
    43void m_assert(bool expr, std::string expr_str, std::string f, std::string file,
    +
    44 int line, std::string msg)
    +
    45{
    +
    46 std::string new_assert(f.size() + (expr ? 4 : 6), '-');
    +
    47 std::cout << "\x1B[36m" << new_assert << "\033[0m\n";
    +
    48 std::cout << f << ": ";
    +
    49 if (expr) {
    +
    50 std::cout << "\x1B[32mOK\033[0m\n";
    +
    51 print_message(msg);
    +
    52 }
    +
    53 else {
    +
    54 std::cout << "\x1B[31mFAIL\033[0m\n";
    +
    55 print_message(msg);
    +
    56 std::cout << file << " " << line << ": Assertion \"" << expr_str
    +
    57 << "\" Failed\n\n";
    +
    58 abort();
    +
    59 }
    +
    60}
    +
    61
    +
    62bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol)
    +
    63{
    +
    64 if (a.n_elem != b.n_elem) {
    +
    65 return false;
    +
    66 }
    +
    67
    +
    68 for (size_t i = 0; i < a.n_elem; i++) {
    +
    69 if (std::abs(a(i) - b(i)) >= tol) {
    +
    70 return false;
    +
    71 }
    +
    72 }
    +
    73 return true;
    +
    74}
    +
    75
    +
    76bool mkpath(std::string path, int mode)
    +
    77{
    +
    78 std::string cur_dir;
    +
    79 std::string::size_type pos = -1;
    +
    80 struct stat buf;
    +
    81
    +
    82 if (path.back() != '/') {
    +
    83 path += '/';
    +
    84 }
    +
    85 while (true) {
    +
    86 pos++;
    +
    87 pos = path.find('/', pos);
    +
    88 if (pos != std::string::npos) {
    +
    89 cur_dir = path.substr(0, pos);
    +
    90 if (mkdir(cur_dir.c_str(), mode) != 0 && stat(cur_dir.c_str(), &buf) != 0) {
    +
    91 return -1;
    +
    92 }
    +
    93 }
    +
    94 else {
    +
    95 break;
    +
    96 }
    +
    97 }
    +
    98 return 0;
    +
    99}
    +
    bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol)
    Test if two armadillo vectors are close to each other.
    Definition: utils.cpp:62
    +
    std::string scientific_format(double d, int width, int prec)
    Turns a double into a string written in scientific format.
    Definition: utils.cpp:17
    +
    bool mkpath(std::string path, int mode)
    Make path given.
    Definition: utils.cpp:76
    +
    void m_assert(bool expr, std::string expr_str, std::string f, std::string file, int line, std::string msg)
    Test an expression, confirm that test is ok, or abort execution.
    Definition: utils.cpp:43
    Function prototypes and macros that are useful.
    diff --git a/docs/utils_8hpp.html b/docs/utils_8hpp.html index 0789c66..2866ae0 100644 --- a/docs/utils_8hpp.html +++ b/docs/utils_8hpp.html @@ -107,10 +107,11 @@ $(document).ready(function(){initNavTree('utils_8hpp.html',''); initResizable();

    Function prototypes and macros that are useful. More...

    -
    #include <string>
    -#include <vector>
    +
    #include <armadillo>
    #include <iomanip>
    #include <sstream>
    +#include <string>
    +#include <vector>

    Go to the source code of this file.

    @@ -119,6 +120,12 @@ Macros + + + + + +
    #define DEBUG(msg)
     Writes a debug message.
     
    #define ASSERT(expr, msg)
     A prettier assertion function.
     
    #define __METHOD_NAME__   methodName(__PRETTY_FUNCTION__)
     Get the name of the current method/function.
     
    @@ -128,6 +135,15 @@ Functions + + + + + + + + +

    Functions

    std::string scientific_format (const std::vector< double > &v, int width=20, int prec=10)
     Turns a vector of doubles into a string written in scientific format.
     
    void m_assert (bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)
     Test an expression, confirm that test is ok, or abort execution.
     
    bool arma_vector_close_to (arma::vec &a, arma::vec &b, double tol=1e-8)
     Test if two armadillo vectors are close to each other.
     
    bool mkpath (std::string path, int mode=0777)
     Make path given.
     

    Detailed Description

    Function prototypes and macros that are useful.

    @@ -136,10 +152,65 @@ Functions Janita Ovidie Sandtrøen Willumsen (janitaws)
    Version
    1.0

    These utility function are mainly for convenience and aren't directly related to the project.

    -
    Bug:
    No known bugs
    +
    Bug:
    No known bugs

    Definition in file utils.hpp.

    Macro Definition Documentation

    + +

    ◆ __METHOD_NAME__

    + +
    +
    + + + + +
    #define __METHOD_NAME__   methodName(__PRETTY_FUNCTION__)
    +
    + +

    Get the name of the current method/function.

    + +

    Definition at line 51 of file utils.hpp.

    + +
    +
    + +

    ◆ ASSERT

    + +
    +
    + + + + + + + + + + + + + + + + + + +
    #define ASSERT( expr,
     msg 
    )
    +
    +Value:
    m_assert(expr, #expr, __METHOD_NAME__, __FILE__, \
    +
    __LINE__, msg)
    +
    void m_assert(bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)
    Test an expression, confirm that test is ok, or abort execution.
    Definition: utils.cpp:43
    +
    #define __METHOD_NAME__
    Get the name of the current method/function.
    Definition: utils.hpp:51
    +
    +

    A prettier assertion function.

    +

    This macro calls the m_assert function which is a more informative assertion function than the regular assert function from cassert.

    + +

    Definition at line 45 of file utils.hpp.

    + +
    +

    ◆ DEBUG

    @@ -157,13 +228,170 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    Writes a debug message.

    -

    This function writes a debug message that includes the filename, line number, and a custom message. The function is wrapped in an ifdef that checks if DBG is defined, so one can choose to display the debug messages by adding the -DDBG flag when compiling.

    +

    This macro writes a debug message that includes the filename, line number, and a custom message. The function is wrapped in an ifdef that checks if DBG is defined, so one can choose to display the debug messages by adding the -DDBG flag when compiling.

    -

    Definition at line 35 of file utils.hpp.

    +

    Definition at line 36 of file utils.hpp.

    Function Documentation

    + +

    ◆ arma_vector_close_to()

    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    bool arma_vector_close_to (arma::vec & a,
    arma::vec & b,
    double tol = 1e-8 
    )
    +
    + +

    Test if two armadillo vectors are close to each other.

    +

    This function takes in 2 vectors and checks if they are approximately equal to each other given a tolerance.

    +
    Parameters
    + + + + +
    aVector a
    bVector b
    tolThe tolerance
    +
    +
    +
    Returns
    bool
    + +

    Definition at line 62 of file utils.cpp.

    + +
    +
    + +

    ◆ m_assert()

    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    void m_assert (bool expr,
    std::string expr_str,
    std::string func,
    std::string file,
    int line,
    std::string msg 
    )
    +
    + +

    Test an expression, confirm that test is ok, or abort execution.

    +

    This function takes in an expression and prints an OK message if it's true, or it prints a fail message and aborts execution if it fails.

    +
    Parameters
    + + + + + + + +
    exprThe expression to be evaluated
    expr_strThe stringified version of the expression
    funcThe function name of the caller
    fileThe file of the caller
    lineThe line number where this function is called from
    msgThe message to be displayed
    +
    +
    + +

    Definition at line 43 of file utils.cpp.

    + +
    +
    + +

    ◆ mkpath()

    + +
    +
    + + + + + + + + + + + + + + + + + + +
    bool mkpath (std::string path,
    int mode = 0777 
    )
    +
    + +

    Make path given.

    +

    This tries to be the equivalent to "mkdir -p" and creates a new directory whenever it needs to.

    +
    Parameters
    + + + +
    pathThe path to be created
    modeThe mode/permissions for all the new directories
    +
    +
    +
    Returns
    bool
    + +

    Definition at line 76 of file utils.cpp.

    + +
    +

    ◆ scientific_format() [1/2]

    @@ -197,6 +425,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    Turns a vector of doubles into a string written in scientific format.

    +

    The code is stolen from https://github.com/anderkve/FYS3150.

    Parameters
    @@ -205,9 +434,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    vThe vector to stringify
    -
    Returns
    String
    +
    Returns
    std::string
    -

    Definition at line 21 of file utils.cpp.

    +

    Definition at line 24 of file utils.cpp.

    @@ -244,7 +473,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    Turns a double into a string written in scientific format.

    -

    Code stolen from https://github.com/anderkve/FYS3150 Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp

    +

    The code is stolen from https://github.com/anderkve/FYS3150.

    Parameters
    @@ -253,9 +482,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    dThe number to stringify
    -
    Returns
    String
    +
    Returns
    std::string
    -

    Definition at line 14 of file utils.cpp.

    +

    Definition at line 17 of file utils.cpp.

    diff --git a/docs/utils_8hpp.js b/docs/utils_8hpp.js index 7b91aee..68951df 100644 --- a/docs/utils_8hpp.js +++ b/docs/utils_8hpp.js @@ -1,6 +1,11 @@ var utils_8hpp = [ + [ "__METHOD_NAME__", "utils_8hpp.html#a60dca3177fb9cb5256609adc7af55168", null ], + [ "ASSERT", "utils_8hpp.html#a73d4f21ad937dbc50a0c0538c78fd4f9", null ], [ "DEBUG", "utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b", null ], + [ "arma_vector_close_to", "utils_8hpp.html#a0c95c4791692b06f8811905a76dbd772", null ], + [ "m_assert", "utils_8hpp.html#a2cc3a2cdb635bac3c8b02e89d4d6af38", null ], + [ "mkpath", "utils_8hpp.html#a6fdd7217b750aff5b6295ece7cbdeffa", null ], [ "scientific_format", "utils_8hpp.html#ad54b96a1074f9df4dc892a41d115b72d", null ], [ "scientific_format", "utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384", null ] ]; \ No newline at end of file diff --git a/docs/utils_8hpp_source.html b/docs/utils_8hpp_source.html index 5959341..1c7052d 100644 --- a/docs/utils_8hpp_source.html +++ b/docs/utils_8hpp_source.html @@ -105,26 +105,61 @@ $(document).ready(function(){initNavTree('utils_8hpp_source.html',''); initResiz
    15#ifndef __UTILS__
    16#define __UTILS__
    17
    -
    18#include <string>
    -
    19#include <vector>
    -
    20#include <iomanip>
    -
    21#include <sstream>
    -
    22
    -
    31#ifdef DBG
    -
    32 #define DEBUG(msg) std::cout << __FILE__ << " " << __LINE__ << ": " \
    -
    33 << msg << std::endl
    -
    34#else
    -
    35 #define DEBUG(msg)
    -
    36#endif
    -
    37
    -
    51std::string scientific_format(double d, int width=20, int prec=10);
    +
    18#include <armadillo>
    +
    19#include <iomanip>
    +
    20#include <sstream>
    +
    21#include <string>
    +
    22#include <vector>
    +
    23
    +
    32#ifdef DBG
    +
    33 #define DEBUG(msg) std::cout << __FILE__ << " " << __LINE__ << ": " \
    +
    34 << msg << std::endl
    +
    35#else
    +
    36 #define DEBUG(msg)
    +
    37#endif
    +
    38
    +
    45#define ASSERT(expr, msg) m_assert(expr, #expr, __METHOD_NAME__, __FILE__, \
    +
    46 __LINE__, msg)
    +
    47
    +
    51#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
    52
    -
    61std::string scientific_format(const std::vector<double>& v,
    -
    62 int width=20,
    -
    63 int prec=10);
    -
    64
    -
    65#endif
    -
    scientific_format
    std::string scientific_format(double d, int width=20, int prec=10)
    Turns a double into a string written in scientific format.
    Definition: utils.cpp:14
    +
    53
    +
    64std::string scientific_format(double d, int width=20, int prec=10);
    +
    65
    +
    66
    +
    77std::string scientific_format(const std::vector<double>& v,
    +
    78 int width=20,
    +
    79 int prec=10);
    +
    80
    +
    81
    +
    94void m_assert(bool expr,
    +
    95 std::string expr_str,
    +
    96 std::string func,
    +
    97 std::string file,
    +
    98 int line,
    +
    99 std::string msg);
    +
    100
    +
    101
    +
    113bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8);
    +
    114
    +
    115
    +
    126static inline std::string methodName(const std::string& pretty_function)
    +
    127{
    +
    128 size_t colons = pretty_function.find("::");
    +
    129 size_t begin = pretty_function.substr(0,colons).rfind(" ") + 1;
    +
    130 size_t end = pretty_function.rfind("(") - begin;
    +
    131
    +
    132 return pretty_function.substr(begin,end) + "()";
    +
    133}
    +
    134
    +
    135
    +
    146bool mkpath(std::string path, int mode = 0777);
    +
    147
    +
    148#endif
    +
    arma_vector_close_to
    bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8)
    Test if two armadillo vectors are close to each other.
    Definition: utils.cpp:62
    +
    m_assert
    void m_assert(bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)
    Test an expression, confirm that test is ok, or abort execution.
    Definition: utils.cpp:43
    +
    mkpath
    bool mkpath(std::string path, int mode=0777)
    Make path given.
    Definition: utils.cpp:76
    +
    scientific_format
    std::string scientific_format(double d, int width=20, int prec=10)
    Turns a double into a string written in scientific format.
    Definition: utils.cpp:17
    diff --git a/images/100_particles.gif b/images/100_particles.gif new file mode 100644 index 0000000..53eb275 Binary files /dev/null and b/images/100_particles.gif differ diff --git a/include/Particle.hpp b/include/Particle.hpp index 29b4ccb..4b5e716 100644 --- a/include/Particle.hpp +++ b/include/Particle.hpp @@ -14,24 +14,29 @@ #include +#include "typedefs.hpp" + /** @brief A class that holds attributes of a particle * */ class Particle { private: - double q; ///< Charge - double m; ///< Mass - arma::vec::fixed<3> r_vec; ///< position - arma::vec::fixed<3> v_vec; ///< velocity + double q; ///< Charge + double m; ///< Mass + vec_3d r_vec; ///< position + vec_3d v_vec; ///< velocity public: /** @brief Initialize the particle. * * @details Initialize the particle with a charge, mass, position and * velocity. + * + * @param q The charge of the particle + * @param m The mass of the particle + * @param r_vec The initial position of the particle + * @param v_vec The initial velocity of the particle * */ - Particle(double q, double m, - arma::vec::fixed<3> r_vec, - arma::vec::fixed<3> v_vec); + Particle(double q, double m, vec_3d r_vec, vec_3d v_vec); /** @brief Make private attributes available for PenningTrap. * */ diff --git a/include/PenningTrap.hpp b/include/PenningTrap.hpp index b0dbd86..f6cf2c0 100644 --- a/include/PenningTrap.hpp +++ b/include/PenningTrap.hpp @@ -13,9 +13,14 @@ #define __PENNING_TRAP__ #include +#include -#include "constants.hpp" #include "Particle.hpp" +#include "constants.hpp" +#include "typedefs.hpp" + +#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \ + initializer(omp_priv = omp_orig) /** @brief A class that simulates a Penning trap. * @@ -24,57 +29,194 @@ * */ class PenningTrap { private: - double B_0; ///< Magnetic field strength - double V_0; ///< Applied potential - double d; ///< Characteristic dimension - std::vector particles; ///< The particles in the Penning trap + double B_0; ///< Magnetic field strength + std::function V_0; ///< Applied potential + double d; ///< Characteristic dimension + double t; ///< Current time + std::vector particles; ///< The particles in the Penning trap + sim_arr k_v; ///< A 2D vector containing all \f$k_{i,j}\f$ where \f$j\f$ is + ///< the index of a particle + sim_arr k_r; ///< A 2D vector containing all \f$k_{i,j}\f$ where \f$j\f$ is + ///< the index of a particle + + /** @brief Helper for evolve_RK4 when calculating \f$k_{v,i,j}\f$ values + * + * @details Something + * + * @param i Index i for \f$k_{v,i,j}\f$ + * @param j Index j for \f$k_{v,i,j}\f$ + * @param dt the step length (delta time) + * + * @return vec_3d + * */ + vec_3d v_func(unsigned int i, unsigned int j, double dt); + + /** @brief Helper for evolve_RK4 when calculating \f$k_{r,i,j}\f$ values + * + * @details Something + * + * @param i Index i for \f$k_{r,i,j}\f$ + * @param j Index j for \f$k_{r,i,j}\f$ + * @param dt the step length (delta time) + * + * @return vec_3d + * */ + vec_3d r_func(unsigned int i, unsigned int j, double dt); public: - /** @brief Set B_0, V_0 and d. + /** @brief Constructor for the PenningTrap class + * + * @param B_0 The magnetic field strength + * @param V_0 The time dependent applied potential + * @param d The characteristic dimension + * @param t The starting time * */ - PenningTrap(double B_0 = T, double V_0 = 25.*V/1000., double d = 500.); + PenningTrap( + double B_0 = T, + std::function V_0 = + [](double t) { return 25. * V / 1000.; }, + double d = 500., double t = 0.); + + /** @brief Constructor for the PenningTrap class + * + * @param i The number of particles to generate + * @param B_0 The magnetic field strength + * @param V_0 The time dependent applied potential + * @param d The characteristic dimension + * @param t The starting time + * */ + PenningTrap( + unsigned int i, double B_0 = T, + std::function V_0 = + [](double t) { return 25. * V / 1000.; }, + double d = 500., double t = 0.); + + /** @brief Constructor for the PenningTrap class + * + * @param particles The starting particles + * @param B_0 The magnetic field strength + * @param V_0 The time dependent applied potential + * @param d The characteristic dimension + * @param t The starting time + * */ + PenningTrap( + std::vector particles, double B_0 = T, + std::function V_0 = + [](double t) { return 25. * V / 1000.; }, + double d = 500., double t = 0.); /** @brief Add a particle to the system + * + * @param particle The particle to add to the Penning trap * */ void add_particle(Particle particle); /** @brief Calculate E at point r + * + * @param r The position where we want to calculate the E field + * + * @return vec_3d * */ - arma::vec external_E_field(arma::vec r); + vec_3d external_E_field(vec_3d r); /** @brief Calculate B at point r + * + * @param r The position where we want to calculate the B field + * + * @return vec_3d * */ - arma::vec external_B_field(arma::vec r); + vec_3d external_B_field(vec_3d r); /** @brief Calculate the force between 2 particles. * - * @details Calculate the force exhibited on particle p_i from + * @details Calculate the force exhibited on particle p_i from * particle p_j. + * + * @param i The index of particle p_i + * @param j The index of particle p_j + * + * @return vec_3d * */ - arma::vec force_on_particle(int i, int j); + vec_3d force_on_particle(unsigned int i, unsigned int j); /** @brief Calculate the total external force on a particle. * * @details Calculate the total amount of force that E and B exhibits * on particle p_i. + * + * @param i The index of particle p_i + * + * @return vec_3d * */ - arma::vec total_force_external(int i); + vec_3d total_force_external(unsigned int i); - /** @brief Calculate the total force on a particle from other particles. + /** @brief Calculate the total force on a particle p_i from other particles. + * + * @param i The index of particle p_i + * + * @return vec_3d * */ - arma::vec total_force_particles(int i); + vec_3d total_force_particles(unsigned int i); - /** @brief calculate the total force on a particle. - * */ - arma::vec total_force(int i); + /** @brief calculate the total force on a particle p_i. + * + * @param i The index of particle p_i + * + * @return vec_3d + * */ + vec_3d total_force(unsigned int i); /** @brief Go forward one timestep using the RK4 method + * + * @param dt The step length + * @param particle_interaction Turn particle interactions on/off * */ - void evolve_RK4(double dt); + void evolve_RK4(double dt, bool particle_interaction = true); /** @brief Go forward one timestep using the forward Euler method + * + * @param dt The step length + * @param particle_interaction Turn particle interactions on/off * */ - void evolve_forward_euler(double dt); + void evolve_forward_euler(double dt, bool particle_interaction = true); + + /** @brief Simulate the particle system inside the Penning trap over + * a certain amount of time. + * + * @param time The time to simulate in microseconds + * @param steps The amount of steps for the whole simulation + * @param method The method to use when moving forward a timestep + * @param particle_interaction Turn particle interactions on/off + * */ + sim_arr simulate(double time, unsigned int steps, + std::string method = "rk4", + bool particle_interaction = true); + + /** @brief Simulate and write the displacement of all particles to files. + * + * @param path The directory to save the data + * @param time The time to simulate in microseconds + * @param steps The amount of steps for the whole simulation + * @param method The method to use when moving forward a timestep + * @param particle_interaction Turn particle interactions on/off + * */ + void write_simulation_to_dir(std::string path, double time, + unsigned int steps, std::string method = "rk4", + bool particle_interaction = true); + + /** @brief Simulate and calculate what fraction of particles are still + * left inside the Penning trap after the simulation. + * + * @param time The time to simulate in microseconds + * @param steps The amount of steps for the whole simulation + * @param method The method to use when moving forward a timestep + * @param particle_interaction Turn particle interactions on/off + * + * @return double + * */ + double fraction_of_particles_left(double time, unsigned int steps, + std::string method = "rk4", + bool particle_interaction = true); }; #endif diff --git a/include/typedefs.hpp b/include/typedefs.hpp new file mode 100644 index 0000000..f0ceca2 --- /dev/null +++ b/include/typedefs.hpp @@ -0,0 +1,38 @@ +/** @file typedefs.hpp + * + * @author Cory Alexander Balaton (coryab) + * @author Janita Ovidie Sandtrøen Willumsen (janitaws) + * + * @version 1.0 + * + * @brief Useful typedefs for cleaner code. + * + * @details These typedefs make the code more readable and easy to follow + * along. + * + * @bug No known bugs + * */ +#ifndef __TYPEDEFS__ +#define __TYPEDEFS__ + +#include +#include + +/** @brief Typedef for the column of the result vector from simulating + * particles. + * */ +typedef std::vector> sim_cols; + +/** @brief Typedef for the row of the result vector from simulating particles. + * */ +typedef std::vector> sim_rows; + +/** @brief Typedef for the result of the simulate method. + * */ +typedef std::vector sim_arr; + +/** @brief Typedef for a fixed 3d arma vector. + * */ +typedef arma::vec::fixed<3> vec_3d; + +#endif diff --git a/include/utils.hpp b/include/utils.hpp index c8d3e4a..c9c9485 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -15,15 +15,16 @@ #ifndef __UTILS__ #define __UTILS__ -#include -#include +#include #include #include +#include +#include /** @def DEBUG(msg) * @brief Writes a debug message * - * This function writes a debug message that includes the filename, + * This macro writes a debug message that includes the filename, * line number, and a custom message. The function is wrapped in an ifdef * that checks if DBG is defined, so one can choose to display the debug * messages by adding the -DDBG flag when compiling. @@ -35,31 +36,113 @@ #define DEBUG(msg) #endif -/** Code stolen from https://github.com/anderkve/FYS3150 - * Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp - * Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp +/** @def ASSERT(expr) + * @brief A prettier assertion function. + * + * This macro calls the m_assert function which is a more informative + * assertion function than the regular assert function from cassert. * */ +#define ASSERT(expr, msg) m_assert(expr, #expr, __METHOD_NAME__, __FILE__, \ + __LINE__, msg) + +/** @def __METHOD_NAME__ + * @brief Get the name of the current method/function. + * */ +#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__) + /** @brief Turns a double into a string written in scientific format. + * + * @details The code is stolen from https://github.com/anderkve/FYS3150. * * @param d The number to stringify * @param width The reserved width of the string * @param prec The precision of the stringified number * - * @return String + * @return std::string * */ std::string scientific_format(double d, int width=20, int prec=10); + /** @brief Turns a vector of doubles into a string written in scientific format. + * + * @details The code is stolen from https://github.com/anderkve/FYS3150. * * @param v The vector to stringify * @param width The reserved width of the string * @param prec The precision of the stringified number * - * @return String + * @return std::string * */ std::string scientific_format(const std::vector& v, int width=20, int prec=10); + +/** @brief Test an expression, confirm that test is ok, or abort execution. + * + * @details This function takes in an expression and prints an OK message if + * it's true, or it prints a fail message and aborts execution if it fails. + * + * @param expr The expression to be evaluated + * @param expr_str The stringified version of the expression + * @param func The function name of the caller + * @param file The file of the caller + * @param line The line number where this function is called from + * @param msg The message to be displayed + * */ +void m_assert(bool expr, + std::string expr_str, + std::string func, + std::string file, + int line, + std::string msg); + + +/** @brief Test if two armadillo vectors are close to each other. + * + * @details This function takes in 2 vectors and checks if they are + * approximately equal to each other given a tolerance. + * + * @param a Vector a + * @param b Vector b + * @param tol The tolerance + * + * @return bool + * */ +bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8); + + +/** @brief Takes in the __PRETTY_FUNCTION__ string and removes the return type. + * + * @details This function should only be used for the __METHOD_NAME__ macro, + * since it takes the output from __PRETTY_FUNCTION__ and strips the return + * type. + * + * @param pretty_function The string from __PRETTY_FUNCTION__ + * + * @return std::string + * */ +static inline std::string methodName(const std::string& pretty_function) +{ + size_t colons = pretty_function.find("::"); + size_t begin = pretty_function.substr(0,colons).rfind(" ") + 1; + size_t end = pretty_function.rfind("(") - begin; + + return pretty_function.substr(begin,end) + "()"; +} + + +/** @brief Make path given. + * + * @details This tries to be the equivalent to "mkdir -p" and creates a new + * directory whenever it needs to. + * + * @param path The path to be created + * @param mode The mode/permissions for all the new directories + * + * @return bool + * */ +bool mkpath(std::string path, int mode = 0777); + #endif diff --git a/man_pages/man3/Particle.3 b/man_pages/man3/Particle.3 index 466ecc4..ebff781 100644 --- a/man_pages/man3/Particle.3 +++ b/man_pages/man3/Particle.3 @@ -1,4 +1,4 @@ -.TH "Particle" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "Particle" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -13,7 +13,7 @@ Particle \- A class that holds attributes of a particle\&. .in +1c .ti -1c -.RI "\fBParticle\fP (double \fBq\fP, double \fBm\fP, arma::vec::fixed< 3 > \fBr_vec\fP, arma::vec::fixed< 3 > \fBv_vec\fP)" +.RI "\fBParticle\fP (double \fBq\fP, double \fBm\fP, \fBvec_3d\fP \fBr_vec\fP, \fBvec_3d\fP \fBv_vec\fP)" .br .RI "Initialize the particle\&. " .in -1c @@ -29,11 +29,11 @@ Particle \- A class that holds attributes of a particle\&. .br .RI "Mass\&. " .ti -1c -.RI "arma::vec::fixed< 3 > \fBr_vec\fP" +.RI "\fBvec_3d\fP \fBr_vec\fP" .br .RI "position " .ti -1c -.RI "arma::vec::fixed< 3 > \fBv_vec\fP" +.RI "\fBvec_3d\fP \fBv_vec\fP" .br .RI "velocity " .in -1c @@ -49,15 +49,28 @@ Particle \- A class that holds attributes of a particle\&. .PP A class that holds attributes of a particle\&. .PP -Definition at line \fB19\fP of file \fBParticle\&.hpp\fP\&. +Definition at line \fB21\fP of file \fBParticle\&.hpp\fP\&. .SH "Constructor & Destructor Documentation" .PP -.SS "Particle::Particle (double q, double m, arma::vec::fixed< 3 > r_vec, arma::vec::fixed< 3 > v_vec)" +.SS "Particle::Particle (double q, double m, \fBvec_3d\fP r_vec, \fBvec_3d\fP v_vec)" .PP -Initialize the particle\&. Initialize the particle with a charge, mass, position and velocity\&. +Initialize the particle\&. Initialize the particle with a charge, mass, position and velocity\&. .PP -Definition at line \fB17\fP of file \fBParticle\&.cpp\fP\&. +\fBParameters\fP +.RS 4 +\fIq\fP The charge of the particle +.br +\fIm\fP The mass of the particle +.br +\fIr_vec\fP The initial position of the particle +.br +\fIv_vec\fP The initial velocity of the particle +.RE +.PP + +.PP +Definition at line \fB15\fP of file \fBParticle\&.cpp\fP\&. .SH "Friends And Related Function Documentation" .PP .SS "friend class \fBPenningTrap\fP\fC [friend]\fP" @@ -65,7 +78,7 @@ Definition at line \fB17\fP of file \fBParticle\&.cpp\fP\&. .PP Make private attributes available for \fBPenningTrap\fP\&. .PP -Definition at line \fB38\fP of file \fBParticle\&.hpp\fP\&. +Definition at line \fB43\fP of file \fBParticle\&.hpp\fP\&. .SH "Member Data Documentation" .PP .SS "double Particle::m\fC [private]\fP" @@ -73,25 +86,25 @@ Definition at line \fB38\fP of file \fBParticle\&.hpp\fP\&. .PP Mass\&. .PP -Definition at line \fB22\fP of file \fBParticle\&.hpp\fP\&. +Definition at line \fB24\fP of file \fBParticle\&.hpp\fP\&. .SS "double Particle::q\fC [private]\fP" .PP Charge\&. .PP -Definition at line \fB21\fP of file \fBParticle\&.hpp\fP\&. -.SS "arma::vec::fixed<3> Particle::r_vec\fC [private]\fP" +Definition at line \fB23\fP of file \fBParticle\&.hpp\fP\&. +.SS "\fBvec_3d\fP Particle::r_vec\fC [private]\fP" .PP position .PP -Definition at line \fB23\fP of file \fBParticle\&.hpp\fP\&. -.SS "arma::vec::fixed<3> Particle::v_vec\fC [private]\fP" +Definition at line \fB25\fP of file \fBParticle\&.hpp\fP\&. +.SS "\fBvec_3d\fP Particle::v_vec\fC [private]\fP" .PP velocity .PP -Definition at line \fB24\fP of file \fBParticle\&.hpp\fP\&. +Definition at line \fB26\fP of file \fBParticle\&.hpp\fP\&. .SH "Author" .PP diff --git a/man_pages/man3/Particle.cpp.3 b/man_pages/man3/Particle.cpp.3 index 1d94e76..904c7a4 100644 --- a/man_pages/man3/Particle.cpp.3 +++ b/man_pages/man3/Particle.cpp.3 @@ -1,4 +1,4 @@ -.TH "src/Particle.cpp" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "src/Particle.cpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -31,13 +31,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) .PP \fBBug\fP .RS 4 -No known bugs -.RE -.PP -.PP -\fBTodo\fP -.RS 4 -Implement constructor +No known bugs .RE .PP diff --git a/man_pages/man3/Particle.hpp.3 b/man_pages/man3/Particle.hpp.3 index 7cec015..2033d14 100644 --- a/man_pages/man3/Particle.hpp.3 +++ b/man_pages/man3/Particle.hpp.3 @@ -1,4 +1,4 @@ -.TH "include/Particle.hpp" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "include/Particle.hpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -9,6 +9,8 @@ include/Particle.hpp \- A class that holds the properties of a particle\&. .PP \fC#include \fP .br +\fC#include 'typedefs\&.hpp'\fP +.br .SS "Classes" diff --git a/man_pages/man3/PenningTrap.3 b/man_pages/man3/PenningTrap.3 index 503511e..51cca93 100644 --- a/man_pages/man3/PenningTrap.3 +++ b/man_pages/man3/PenningTrap.3 @@ -1,4 +1,4 @@ -.TH "PenningTrap" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "PenningTrap" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -13,45 +13,77 @@ PenningTrap \- A class that simulates a Penning trap\&. .in +1c .ti -1c -.RI "\fBPenningTrap\fP (double \fBB_0\fP=\fBT\fP, double \fBV_0\fP=25\&.*\fBV\fP/1000\&., double \fBd\fP=500\&.)" +.RI "\fBPenningTrap\fP (double \fBB_0\fP=\fBT\fP, std::function< double(double)> \fBV_0\fP=[](double \fBt\fP) { return 25\&. *\fBV\fP/1000\&.;}, double \fBd\fP=500\&., double \fBt\fP=0\&.)" .br -.RI "Set B_0, V_0 and d\&. " +.RI "Constructor for the \fBPenningTrap\fP class\&. " +.ti -1c +.RI "\fBPenningTrap\fP (unsigned int i, double \fBB_0\fP=\fBT\fP, std::function< double(double)> \fBV_0\fP=[](double \fBt\fP) { return 25\&. *\fBV\fP/1000\&.;}, double \fBd\fP=500\&., double \fBt\fP=0\&.)" +.br +.RI "Constructor for the \fBPenningTrap\fP class\&. " +.ti -1c +.RI "\fBPenningTrap\fP (std::vector< \fBParticle\fP > \fBparticles\fP, double \fBB_0\fP=\fBT\fP, std::function< double(double)> \fBV_0\fP=[](double \fBt\fP) { return 25\&. *\fBV\fP/1000\&.;}, double \fBd\fP=500\&., double \fBt\fP=0\&.)" +.br +.RI "Constructor for the \fBPenningTrap\fP class\&. " .ti -1c .RI "void \fBadd_particle\fP (\fBParticle\fP particle)" .br .RI "Add a particle to the system\&. " .ti -1c -.RI "arma::vec \fBexternal_E_field\fP (arma::vec r)" +.RI "\fBvec_3d\fP \fBexternal_E_field\fP (\fBvec_3d\fP r)" .br .RI "Calculate E at point r\&. " .ti -1c -.RI "arma::vec \fBexternal_B_field\fP (arma::vec r)" +.RI "\fBvec_3d\fP \fBexternal_B_field\fP (\fBvec_3d\fP r)" .br .RI "Calculate B at point r\&. " .ti -1c -.RI "arma::vec \fBforce_on_particle\fP (int i, int j)" +.RI "\fBvec_3d\fP \fBforce_on_particle\fP (unsigned int i, unsigned int j)" .br .RI "Calculate the force between 2 particles\&. " .ti -1c -.RI "arma::vec \fBtotal_force_external\fP (int i)" +.RI "\fBvec_3d\fP \fBtotal_force_external\fP (unsigned int i)" .br .RI "Calculate the total external force on a particle\&. " .ti -1c -.RI "arma::vec \fBtotal_force_particles\fP (int i)" +.RI "\fBvec_3d\fP \fBtotal_force_particles\fP (unsigned int i)" .br -.RI "Calculate the total force on a particle from other particles\&. " +.RI "Calculate the total force on a particle p_i from other particles\&. " .ti -1c -.RI "arma::vec \fBtotal_force\fP (int i)" +.RI "\fBvec_3d\fP \fBtotal_force\fP (unsigned int i)" .br -.RI "calculate the total force on a particle\&. " +.RI "calculate the total force on a particle p_i\&. " .ti -1c -.RI "void \fBevolve_RK4\fP (double dt)" +.RI "void \fBevolve_RK4\fP (double dt, bool particle_interaction=true)" .br .RI "Go forward one timestep using the RK4 method\&. " .ti -1c -.RI "void \fBevolve_forward_euler\fP (double dt)" +.RI "void \fBevolve_forward_euler\fP (double dt, bool particle_interaction=true)" .br .RI "Go forward one timestep using the forward Euler method\&. " +.ti -1c +.RI "\fBsim_arr\fP \fBsimulate\fP (double time, unsigned int steps, std::string method='rk4', bool particle_interaction=true)" +.br +.RI "Simulate the particle system inside the Penning trap over a certain amount of time\&. " +.ti -1c +.RI "void \fBwrite_simulation_to_dir\fP (std::string path, double time, unsigned int steps, std::string method='rk4', bool particle_interaction=true)" +.br +.RI "Simulate and write the displacement of all particles to files\&. " +.ti -1c +.RI "double \fBfraction_of_particles_left\fP (double time, unsigned int steps, std::string method='rk4', bool particle_interaction=true)" +.br +.RI "Simulate and calculate what fraction of particles are still left inside the Penning trap after the simulation\&. " +.in -1c +.SS "Private Member Functions" + +.in +1c +.ti -1c +.RI "\fBvec_3d\fP \fBv_func\fP (unsigned int i, unsigned int j, double dt)" +.br +.RI "Helper for evolve_RK4 when calculating $k_{v,i,j}$ values\&. " +.ti -1c +.RI "\fBvec_3d\fP \fBr_func\fP (unsigned int i, unsigned int j, double dt)" +.br +.RI "Helper for evolve_RK4 when calculating $k_{r,i,j}$ values\&. " .in -1c .SS "Private Attributes" @@ -61,7 +93,7 @@ PenningTrap \- A class that simulates a Penning trap\&. .br .RI "Magnetic field strength\&. " .ti -1c -.RI "double \fBV_0\fP" +.RI "std::function< double(double)> \fBV_0\fP" .br .RI "Applied potential\&. " .ti -1c @@ -69,9 +101,19 @@ PenningTrap \- A class that simulates a Penning trap\&. .br .RI "Characteristic dimension\&. " .ti -1c +.RI "double \fBt\fP" +.br +.RI "Current time\&. " +.ti -1c .RI "std::vector< \fBParticle\fP > \fBparticles\fP" .br .RI "The particles in the Penning trap\&. " +.ti -1c +.RI "\fBsim_arr\fP \fBk_v\fP" +.br +.ti -1c +.RI "\fBsim_arr\fP \fBk_r\fP" +.br .in -1c .SH "Detailed Description" .PP @@ -79,15 +121,70 @@ A class that simulates a Penning trap\&. This class simulates a Penning trap\&. It can take in a number of particles and simulate how they would behave inside a Penning trap\&. .PP -Definition at line \fB25\fP of file \fBPenningTrap\&.hpp\fP\&. +Definition at line \fB30\fP of file \fBPenningTrap\&.hpp\fP\&. .SH "Constructor & Destructor Documentation" .PP -.SS "PenningTrap::PenningTrap (double B_0 = \fC\fBT\fP\fP, double V_0 = \fC25\&.*\fBV\fP/1000\&.\fP, double d = \fC500\&.\fP)" +.SS "PenningTrap::PenningTrap (double B_0 = \fC\fBT\fP\fP, std::function< double(double)> V_0 = \fC[](double \fBt\fP) { return 25\&. * \fBV\fP / 1000\&.; }\fP, double d = \fC500\&.\fP, double t = \fC0\&.\fP)" .PP -Set B_0, V_0 and d\&. +Constructor for the \fBPenningTrap\fP class\&. .PP -Definition at line \fB26\fP of file \fBPenningTrap\&.cpp\fP\&. +\fBParameters\fP +.RS 4 +\fIB_0\fP The magnetic field strength +.br +\fIV_0\fP The time dependent applied potential +.br +\fId\fP The characteristic dimension +.br +\fIt\fP The starting time +.RE +.PP + +.PP +Definition at line \fB18\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "PenningTrap::PenningTrap (unsigned int i, double B_0 = \fC\fBT\fP\fP, std::function< double(double)> V_0 = \fC[](double \fBt\fP) { return 25\&. * \fBV\fP / 1000\&.; }\fP, double d = \fC500\&.\fP, double t = \fC0\&.\fP)" + +.PP +Constructor for the \fBPenningTrap\fP class\&. +.PP +\fBParameters\fP +.RS 4 +\fIi\fP The number of particles to generate +.br +\fIB_0\fP The magnetic field strength +.br +\fIV_0\fP The time dependent applied potential +.br +\fId\fP The characteristic dimension +.br +\fIt\fP The starting time +.RE +.PP + +.PP +Definition at line \fB27\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "PenningTrap::PenningTrap (std::vector< \fBParticle\fP > particles, double B_0 = \fC\fBT\fP\fP, std::function< double(double)> V_0 = \fC[](double \fBt\fP) { return 25\&. * \fBV\fP / 1000\&.; }\fP, double d = \fC500\&.\fP, double t = \fC0\&.\fP)" + +.PP +Constructor for the \fBPenningTrap\fP class\&. +.PP +\fBParameters\fP +.RS 4 +\fIparticles\fP The starting particles +.br +\fIB_0\fP The magnetic field strength +.br +\fIV_0\fP The time dependent applied potential +.br +\fId\fP The characteristic dimension +.br +\fIt\fP The starting time +.RE +.PP + +.PP +Definition at line \fB39\fP of file \fBPenningTrap\&.cpp\fP\&. .SH "Member Function Documentation" .PP .SS "void PenningTrap::add_particle (\fBParticle\fP particle)" @@ -95,55 +192,262 @@ Definition at line \fB26\fP of file \fBPenningTrap\&.cpp\fP\&. .PP Add a particle to the system\&. .PP -Definition at line \fB31\fP of file \fBPenningTrap\&.cpp\fP\&. -.SS "void PenningTrap::evolve_forward_euler (double dt)" +\fBParameters\fP +.RS 4 +\fIparticle\fP The particle to add to the Penning trap +.RE +.PP + +.PP +Definition at line \fB82\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "void PenningTrap::evolve_forward_euler (double dt, bool particle_interaction = \fCtrue\fP)" .PP Go forward one timestep using the forward Euler method\&. .PP -Definition at line \fB71\fP of file \fBPenningTrap\&.cpp\fP\&. -.SS "void PenningTrap::evolve_RK4 (double dt)" +\fBParameters\fP +.RS 4 +\fIdt\fP The step length +.br +\fIparticle_interaction\fP Turn particle interactions on/off +.RE +.PP + +.PP +Definition at line \fB186\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "void PenningTrap::evolve_RK4 (double dt, bool particle_interaction = \fCtrue\fP)" .PP Go forward one timestep using the RK4 method\&. .PP -Definition at line \fB66\fP of file \fBPenningTrap\&.cpp\fP\&. -.SS "arma::vec PenningTrap::external_B_field (arma::vec r)" +\fBParameters\fP +.RS 4 +\fIdt\fP The step length +.br +\fIparticle_interaction\fP Turn particle interactions on/off +.RE +.PP + +.PP +Definition at line \fB151\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "\fBvec_3d\fP PenningTrap::external_B_field (\fBvec_3d\fP r)" .PP Calculate B at point r\&. .PP -Definition at line \fB41\fP of file \fBPenningTrap\&.cpp\fP\&. -.SS "arma::vec PenningTrap::external_E_field (arma::vec r)" +\fBParameters\fP +.RS 4 +\fIr\fP The position where we want to calculate the B field +.RE +.PP +\fBReturns\fP +.RS 4 +vec_3d +.RE +.PP + +.PP +Definition at line \fB95\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "\fBvec_3d\fP PenningTrap::external_E_field (\fBvec_3d\fP r)" .PP Calculate E at point r\&. .PP -Definition at line \fB36\fP of file \fBPenningTrap\&.cpp\fP\&. -.SS "arma::vec PenningTrap::force_on_particle (int i, int j)" +\fBParameters\fP +.RS 4 +\fIr\fP The position where we want to calculate the E field +.RE +.PP +\fBReturns\fP +.RS 4 +vec_3d +.RE +.PP .PP -Calculate the force between 2 particles\&. Calculate the force exhibited on particle p_i from particle p_j\&. +Definition at line \fB87\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "\fBvec_3d\fP PenningTrap::force_on_particle (unsigned int i, unsigned int j)" + +.PP +Calculate the force between 2 particles\&. Calculate the force exhibited on particle p_i from particle p_j\&. +.PP +\fBParameters\fP +.RS 4 +\fIi\fP The index of particle p_i +.br +\fIj\fP The index of particle p_j +.RE +.PP +\fBReturns\fP +.RS 4 +vec_3d +.RE +.PP + +.PP +Definition at line \fB100\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "double PenningTrap::fraction_of_particles_left (double time, unsigned int steps, std::string method = \fC'rk4'\fP, bool particle_interaction = \fCtrue\fP)" + +.PP +Simulate and calculate what fraction of particles are still left inside the Penning trap after the simulation\&. +.PP +\fBParameters\fP +.RS 4 +\fItime\fP The time to simulate in microseconds +.br +\fIsteps\fP The amount of steps for the whole simulation +.br +\fImethod\fP The method to use when moving forward a timestep +.br +\fIparticle_interaction\fP Turn particle interactions on/off +.RE +.PP +\fBReturns\fP +.RS 4 +double +.RE +.PP + +.PP +Definition at line \fB266\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "\fBvec_3d\fP PenningTrap::r_func (unsigned int i, unsigned int j, double dt)\fC [private]\fP" + +.PP +Helper for evolve_RK4 when calculating $k_{r,i,j}$ values\&. Something +.PP +\fBParameters\fP +.RS 4 +\fIi\fP Index i for $k_{r,i,j}$ +.br +\fIj\fP Index j for $k_{r,i,j}$ +.br +\fIdt\fP the step length (delta time) +.RE +.PP +\fBReturns\fP +.RS 4 +vec_3d +.RE +.PP + +.PP +Definition at line \fB64\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "\fBsim_arr\fP PenningTrap::simulate (double time, unsigned int steps, std::string method = \fC'rk4'\fP, bool particle_interaction = \fCtrue\fP)" + +.PP +Simulate the particle system inside the Penning trap over a certain amount of time\&. +.PP +\fBParameters\fP +.RS 4 +\fItime\fP The time to simulate in microseconds +.br +\fIsteps\fP The amount of steps for the whole simulation +.br +\fImethod\fP The method to use when moving forward a timestep +.br +\fIparticle_interaction\fP Turn particle interactions on/off +.RE +.PP + +.PP +Definition at line \fB211\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "\fBvec_3d\fP PenningTrap::total_force (unsigned int i)" + +.PP +calculate the total force on a particle p_i\&. +.PP +\fBParameters\fP +.RS 4 +\fIi\fP The index of particle p_i +.RE +.PP +\fBReturns\fP +.RS 4 +vec_3d +.RE +.PP + +.PP +Definition at line \fB146\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "\fBvec_3d\fP PenningTrap::total_force_external (unsigned int i)" + +.PP +Calculate the total external force on a particle\&. Calculate the total amount of force that E and B exhibits on particle p_i\&. +.PP +\fBParameters\fP +.RS 4 +\fIi\fP The index of particle p_i +.RE +.PP +\fBReturns\fP +.RS 4 +vec_3d +.RE +.PP + +.PP +Definition at line \fB114\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "\fBvec_3d\fP PenningTrap::total_force_particles (unsigned int i)" + +.PP +Calculate the total force on a particle p_i from other particles\&. +.PP +\fBParameters\fP +.RS 4 +\fIi\fP The index of particle p_i +.RE +.PP +\fBReturns\fP +.RS 4 +vec_3d +.RE +.PP + +.PP +Definition at line \fB129\fP of file \fBPenningTrap\&.cpp\fP\&. +.SS "\fBvec_3d\fP PenningTrap::v_func (unsigned int i, unsigned int j, double dt)\fC [private]\fP" + +.PP +Helper for evolve_RK4 when calculating $k_{v,i,j}$ values\&. Something +.PP +\fBParameters\fP +.RS 4 +\fIi\fP Index i for $k_{v,i,j}$ +.br +\fIj\fP Index j for $k_{v,i,j}$ +.br +\fIdt\fP the step length (delta time) +.RE +.PP +\fBReturns\fP +.RS 4 +vec_3d +.RE +.PP + .PP Definition at line \fB46\fP of file \fBPenningTrap\&.cpp\fP\&. -.SS "arma::vec PenningTrap::total_force (int i)" +.SS "void PenningTrap::write_simulation_to_dir (std::string path, double time, unsigned int steps, std::string method = \fC'rk4'\fP, bool particle_interaction = \fCtrue\fP)" .PP -calculate the total force on a particle\&. +Simulate and write the displacement of all particles to files\&. +.PP +\fBParameters\fP +.RS 4 +\fIpath\fP The directory to save the data +.br +\fItime\fP The time to simulate in microseconds +.br +\fIsteps\fP The amount of steps for the whole simulation +.br +\fImethod\fP The method to use when moving forward a timestep +.br +\fIparticle_interaction\fP Turn particle interactions on/off +.RE .PP -Definition at line \fB61\fP of file \fBPenningTrap\&.cpp\fP\&. -.SS "arma::vec PenningTrap::total_force_external (int i)" .PP -Calculate the total external force on a particle\&. Calculate the total amount of force that E and B exhibits on particle p_i\&. -.PP -Definition at line \fB51\fP of file \fBPenningTrap\&.cpp\fP\&. -.SS "arma::vec PenningTrap::total_force_particles (int i)" - -.PP -Calculate the total force on a particle from other particles\&. -.PP -Definition at line \fB56\fP of file \fBPenningTrap\&.cpp\fP\&. +Definition at line \fB240\fP of file \fBPenningTrap\&.cpp\fP\&. .SH "Member Data Documentation" .PP .SS "double PenningTrap::B_0\fC [private]\fP" @@ -151,25 +455,39 @@ Definition at line \fB56\fP of file \fBPenningTrap\&.cpp\fP\&. .PP Magnetic field strength\&. .PP -Definition at line \fB27\fP of file \fBPenningTrap\&.hpp\fP\&. +Definition at line \fB32\fP of file \fBPenningTrap\&.hpp\fP\&. .SS "double PenningTrap::d\fC [private]\fP" .PP Characteristic dimension\&. .PP -Definition at line \fB29\fP of file \fBPenningTrap\&.hpp\fP\&. +Definition at line \fB34\fP of file \fBPenningTrap\&.hpp\fP\&. +.SS "\fBsim_arr\fP PenningTrap::k_r\fC [private]\fP" +A 2D vector containing all $k_{i,j}$ where $j$ is the index of a particle +.PP +Definition at line \fB39\fP of file \fBPenningTrap\&.hpp\fP\&. +.SS "\fBsim_arr\fP PenningTrap::k_v\fC [private]\fP" +A 2D vector containing all $k_{i,j}$ where $j$ is the index of a particle +.PP +Definition at line \fB37\fP of file \fBPenningTrap\&.hpp\fP\&. .SS "std::vector<\fBParticle\fP> PenningTrap::particles\fC [private]\fP" .PP The particles in the Penning trap\&. .PP -Definition at line \fB30\fP of file \fBPenningTrap\&.hpp\fP\&. -.SS "double PenningTrap::V_0\fC [private]\fP" +Definition at line \fB36\fP of file \fBPenningTrap\&.hpp\fP\&. +.SS "double PenningTrap::t\fC [private]\fP" + +.PP +Current time\&. +.PP +Definition at line \fB35\fP of file \fBPenningTrap\&.hpp\fP\&. +.SS "std::function PenningTrap::V_0\fC [private]\fP" .PP Applied potential\&. .PP -Definition at line \fB28\fP of file \fBPenningTrap\&.hpp\fP\&. +Definition at line \fB33\fP of file \fBPenningTrap\&.hpp\fP\&. .SH "Author" .PP diff --git a/man_pages/man3/PenningTrap.cpp.3 b/man_pages/man3/PenningTrap.cpp.3 index 68aaa57..d080d97 100644 --- a/man_pages/man3/PenningTrap.cpp.3 +++ b/man_pages/man3/PenningTrap.cpp.3 @@ -1,4 +1,4 @@ -.TH "src/PenningTrap.cpp" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "src/PenningTrap.cpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -9,6 +9,12 @@ src/PenningTrap.cpp \- The implementation of the \fBPenningTrap\fP class\&. .PP \fC#include 'PenningTrap\&.hpp'\fP .br +\fC#include 'constants\&.hpp'\fP +.br +\fC#include 'typedefs\&.hpp'\fP +.br +\fC#include 'utils\&.hpp'\fP +.br .SH "Detailed Description" .PP @@ -31,31 +37,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) .PP \fBBug\fP .RS 4 -No known bugs -.RE -.PP -.PP -\fBTodo\fP -.RS 4 -Implement constructor -.PP -Implement add_particle -.PP -Implement external_E_field -.PP -Implement external_B_field -.PP -Implement force_on_particle -.PP -Implement total_force_external -.PP -Implement total_force_particles -.PP -Implement total_force -.PP -Implement evolve_RK4 -.PP -Implement evolve_forward_euler +No known bugs .RE .PP diff --git a/man_pages/man3/PenningTrap.hpp.3 b/man_pages/man3/PenningTrap.hpp.3 index 2857a95..15d155f 100644 --- a/man_pages/man3/PenningTrap.hpp.3 +++ b/man_pages/man3/PenningTrap.hpp.3 @@ -1,4 +1,4 @@ -.TH "include/PenningTrap.hpp" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "include/PenningTrap.hpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -9,10 +9,14 @@ include/PenningTrap.hpp \- A class for simulating a Penning trap\&. .PP \fC#include \fP .br -\fC#include 'constants\&.hpp'\fP +\fC#include \fP .br \fC#include 'Particle\&.hpp'\fP .br +\fC#include 'constants\&.hpp'\fP +.br +\fC#include 'typedefs\&.hpp'\fP +.br .SS "Classes" diff --git a/man_pages/man3/PenningTrapTest.3 b/man_pages/man3/PenningTrapTest.3 new file mode 100644 index 0000000..3bbe27c --- /dev/null +++ b/man_pages/man3/PenningTrapTest.3 @@ -0,0 +1,56 @@ +.TH "PenningTrapTest" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- +.ad l +.nh +.SH NAME +PenningTrapTest +.SH SYNOPSIS +.br +.PP +.SS "Static Public Member Functions" + +.in +1c +.ti -1c +.RI "static void \fBtest_external_E_field\fP ()" +.br +.ti -1c +.RI "static void \fBtest_external_B_field\fP ()" +.br +.ti -1c +.RI "static void \fBtest_force_on_particle\fP ()" +.br +.ti -1c +.RI "static void \fBtest_total_force_external\fP ()" +.br +.ti -1c +.RI "static void \fBtest_total_force_particles\fP ()" +.br +.in -1c +.SH "Detailed Description" +.PP +Definition at line \fB20\fP of file \fBtest_suite\&.cpp\fP\&. +.SH "Member Function Documentation" +.PP +.SS "static void PenningTrapTest::test_external_B_field ()\fC [inline]\fP, \fC [static]\fP" + +.PP +Definition at line \fB59\fP of file \fBtest_suite\&.cpp\fP\&. +.SS "static void PenningTrapTest::test_external_E_field ()\fC [inline]\fP, \fC [static]\fP" + +.PP +Definition at line \fB22\fP of file \fBtest_suite\&.cpp\fP\&. +.SS "static void PenningTrapTest::test_force_on_particle ()\fC [inline]\fP, \fC [static]\fP" + +.PP +Definition at line \fB70\fP of file \fBtest_suite\&.cpp\fP\&. +.SS "static void PenningTrapTest::test_total_force_external ()\fC [inline]\fP, \fC [static]\fP" + +.PP +Definition at line \fB95\fP of file \fBtest_suite\&.cpp\fP\&. +.SS "static void PenningTrapTest::test_total_force_particles ()\fC [inline]\fP, \fC [static]\fP" + +.PP +Definition at line \fB108\fP of file \fBtest_suite\&.cpp\fP\&. + +.SH "Author" +.PP +Generated automatically by Doxygen for Penning Trap Simulation from the source code\&. diff --git a/man_pages/man3/bug.3 b/man_pages/man3/bug.3 index 670c28b..d21bde1 100644 --- a/man_pages/man3/bug.3 +++ b/man_pages/man3/bug.3 @@ -1,4 +1,4 @@ -.TH "bug" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "bug" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -10,15 +10,17 @@ No known bugs .IP "\fBFile \fBmain\&.cpp\fP \fP" 1c No known bugs .IP "\fBFile \fBParticle\&.cpp\fP \fP" 1c -No known bugs +No known bugs .IP "\fBFile \fBParticle\&.hpp\fP \fP" 1c No known bugs .IP "\fBFile \fBPenningTrap\&.cpp\fP \fP" 1c -No known bugs +No known bugs .IP "\fBFile \fBPenningTrap\&.hpp\fP \fP" 1c No known bugs .IP "\fBFile \fBtest_suite\&.cpp\fP \fP" 1c No known bugs +.IP "\fBFile \fBtypedefs\&.hpp\fP \fP" 1c +No known bugs .IP "\fBFile \fButils\&.cpp\fP \fP" 1c No known bugs .IP "\fBFile \fButils\&.hpp\fP \fP" 1c diff --git a/man_pages/man3/constants.hpp.3 b/man_pages/man3/constants.hpp.3 index 56030e6..b1d978f 100644 --- a/man_pages/man3/constants.hpp.3 +++ b/man_pages/man3/constants.hpp.3 @@ -1,4 +1,4 @@ -.TH "include/constants.hpp" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "include/constants.hpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME diff --git a/man_pages/man3/main.cpp.3 b/man_pages/man3/main.cpp.3 index 294b2fa..23983a7 100644 --- a/man_pages/man3/main.cpp.3 +++ b/man_pages/man3/main.cpp.3 @@ -1,4 +1,4 @@ -.TH "src/main.cpp" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "src/main.cpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -7,13 +7,71 @@ src/main.cpp \- The main program for this project\&. .SH SYNOPSIS .br .PP +\fC#include \fP +.br +\fC#include \fP +.br +\fC#include \fP +.br +\fC#include \fP +.br +\fC#include \fP +.br +\fC#include \fP +.br +\fC#include 'PenningTrap\&.hpp'\fP +.br +\fC#include 'utils\&.hpp'\fP +.br + +.SS "Macros" + +.in +1c +.ti -1c +.RI "#define \fBPARTICLES\fP 100" +.br +.ti -1c +.RI "#define \fBN\fP 10000" +.br +.ti -1c +.RI "#define \fBCHARGE\fP 1\&." +.br +.ti -1c +.RI "#define \fBMASS\fP 40\&." +.br +.in -1c .SS "Functions" .in +1c .ti -1c +.RI "void \fBsimulate_single_particle\fP ()" +.br +.ti -1c +.RI "void \fBsimulate_two_particles\fP ()" +.br +.ti -1c +.RI "void \fBsimulate_single_particle_with_different_steps\fP ()" +.br +.ti -1c +.RI "void \fBsimulate_100_particles\fP ()" +.br +.ti -1c +.RI "void \fBsimulate_100_particles_with_time_potential\fP ()" +.br +.ti -1c .RI "int \fBmain\fP ()" .br .in -1c +.SS "Variables" + +.in +1c +.ti -1c +.RI "\fBParticle\fP \fBp1\fP (CHARGE, MASS, \fBvec_3d\fP{20\&., 0\&., 20\&.}, \fBvec_3d\fP{0\&., 25\&., 0\&.})" +.br +.ti -1c +.RI "\fBParticle\fP \fBp2\fP (CHARGE, MASS, \fBvec_3d\fP{25\&., 25\&., 0\&.}, \fBvec_3d\fP{0\&., 40\&., 5\&.})" +.br +.in -1c .SH "Detailed Description" .PP The main program for this project\&. @@ -41,12 +99,50 @@ No known bugs .PP Definition in file \fBmain\&.cpp\fP\&. +.SH "Macro Definition Documentation" +.PP +.SS "#define CHARGE 1\&." + +.PP +Definition at line \fB25\fP of file \fBmain\&.cpp\fP\&. +.SS "#define MASS 40\&." + +.PP +Definition at line \fB26\fP of file \fBmain\&.cpp\fP\&. +.SS "#define N 10000" + +.PP +Definition at line \fB24\fP of file \fBmain\&.cpp\fP\&. +.SS "#define PARTICLES 100" + +.PP +Definition at line \fB23\fP of file \fBmain\&.cpp\fP\&. .SH "Function Documentation" .PP .SS "int main ()" .PP -Definition at line \fB13\fP of file \fBmain\&.cpp\fP\&. +Definition at line \fB124\fP of file \fBmain\&.cpp\fP\&. +.SS "void simulate_100_particles ()" + +.PP +Definition at line \fB77\fP of file \fBmain\&.cpp\fP\&. +.SS "void simulate_100_particles_with_time_potential ()" + +.PP +Definition at line \fB91\fP of file \fBmain\&.cpp\fP\&. +.SS "void simulate_single_particle ()" + +.PP +Definition at line \fB31\fP of file \fBmain\&.cpp\fP\&. +.SS "void simulate_single_particle_with_different_steps ()" + +.PP +Definition at line \fB55\fP of file \fBmain\&.cpp\fP\&. +.SS "void simulate_two_particles ()" + +.PP +Definition at line \fB42\fP of file \fBmain\&.cpp\fP\&. .SH "Author" .PP Generated automatically by Doxygen for Penning Trap Simulation from the source code\&. diff --git a/man_pages/man3/test_suite.cpp.3 b/man_pages/man3/test_suite.cpp.3 index c7bdeea..c185469 100644 --- a/man_pages/man3/test_suite.cpp.3 +++ b/man_pages/man3/test_suite.cpp.3 @@ -1,4 +1,4 @@ -.TH "src/test_suite.cpp" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "src/test_suite.cpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -7,6 +7,24 @@ src/test_suite.cpp \- The test suite for the project\&. .SH SYNOPSIS .br .PP +\fC#include 'PenningTrap\&.hpp'\fP +.br +\fC#include 'utils\&.hpp'\fP +.br +\fC#include \fP +.br +\fC#include \fP +.br +\fC#include \fP +.br + +.SS "Classes" + +.in +1c +.ti -1c +.RI "class \fBPenningTrapTest\fP" +.br +.in -1c .SS "Functions" .in +1c @@ -46,7 +64,7 @@ Definition in file \fBtest_suite\&.cpp\fP\&. .SS "int main ()" .PP -Definition at line \fB12\fP of file \fBtest_suite\&.cpp\fP\&. +Definition at line \fB135\fP of file \fBtest_suite\&.cpp\fP\&. .SH "Author" .PP Generated automatically by Doxygen for Penning Trap Simulation from the source code\&. diff --git a/man_pages/man3/todo.3 b/man_pages/man3/todo.3 index e48ea02..ef888e2 100644 --- a/man_pages/man3/todo.3 +++ b/man_pages/man3/todo.3 @@ -1,37 +1,11 @@ -.TH "todo" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "todo" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME todo \- Todo List .PP -.IP "\fBFile \fBParticle\&.cpp\fP \fP" 1c -Implement constructor .IP "\fBFile \fBPenningTrap\&.cpp\fP \fP" 1c -Implement constructor -.PP -.PP -Implement add_particle -.PP -.PP -Implement external_E_field -.PP -.PP -Implement external_B_field -.PP -.PP -Implement force_on_particle -.PP -.PP -Implement total_force_external -.PP -.PP -Implement total_force_particles -.PP -.PP -Implement total_force -.PP -.PP Implement evolve_RK4 .PP .PP diff --git a/man_pages/man3/typedefs.hpp.3 b/man_pages/man3/typedefs.hpp.3 new file mode 100644 index 0000000..1933ad3 --- /dev/null +++ b/man_pages/man3/typedefs.hpp.3 @@ -0,0 +1,92 @@ +.TH "include/typedefs.hpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- +.ad l +.nh +.SH NAME +include/typedefs.hpp \- Useful typedefs for cleaner code\&. + +.SH SYNOPSIS +.br +.PP +\fC#include \fP +.br +\fC#include \fP +.br + +.SS "Typedefs" + +.in +1c +.ti -1c +.RI "typedef std::vector< arma::vec::fixed< 3 > > \fBsim_cols\fP" +.br +.RI "Typedef for the column of the result vector from simulating particles\&. " +.ti -1c +.RI "typedef std::vector< arma::vec::fixed< 3 > > \fBsim_rows\fP" +.br +.RI "Typedef for the row of the result vector from simulating particles\&. " +.ti -1c +.RI "typedef std::vector< \fBsim_cols\fP > \fBsim_arr\fP" +.br +.RI "Typedef for the result of the simulate method\&. " +.ti -1c +.RI "typedef arma::vec::fixed< 3 > \fBvec_3d\fP" +.br +.RI "Typedef for a fixed 3d arma vector\&. " +.in -1c +.SH "Detailed Description" +.PP +Useful typedefs for cleaner code\&. + + +.PP +\fBAuthor\fP +.RS 4 +Cory Alexander Balaton (coryab) +.PP +Janita Ovidie Sandtrøen Willumsen (janitaws) +.RE +.PP +\fBVersion\fP +.RS 4 +1\&.0 +.RE +.PP +.PP +These typedefs make the code more readable and easy to follow along\&. +.PP +\fBBug\fP +.RS 4 +No known bugs +.RE +.PP + +.PP +Definition in file \fBtypedefs\&.hpp\fP\&. +.SH "Typedef Documentation" +.PP +.SS "typedef std::vector<\fBsim_cols\fP> \fBsim_arr\fP" + +.PP +Typedef for the result of the simulate method\&. +.PP +Definition at line \fB32\fP of file \fBtypedefs\&.hpp\fP\&. +.SS "typedef std::vector > \fBsim_cols\fP" + +.PP +Typedef for the column of the result vector from simulating particles\&. +.PP +Definition at line \fB24\fP of file \fBtypedefs\&.hpp\fP\&. +.SS "typedef std::vector > \fBsim_rows\fP" + +.PP +Typedef for the row of the result vector from simulating particles\&. +.PP +Definition at line \fB28\fP of file \fBtypedefs\&.hpp\fP\&. +.SS "typedef arma::vec::fixed<3> \fBvec_3d\fP" + +.PP +Typedef for a fixed 3d arma vector\&. +.PP +Definition at line \fB36\fP of file \fBtypedefs\&.hpp\fP\&. +.SH "Author" +.PP +Generated automatically by Doxygen for Penning Trap Simulation from the source code\&. diff --git a/man_pages/man3/utils.cpp.3 b/man_pages/man3/utils.cpp.3 index 1660e32..335b5f5 100644 --- a/man_pages/man3/utils.cpp.3 +++ b/man_pages/man3/utils.cpp.3 @@ -1,4 +1,4 @@ -.TH "src/utils.cpp" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "src/utils.cpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -7,6 +7,8 @@ src/utils.cpp \- Implementation of the utils\&. .SH SYNOPSIS .br .PP +\fC#include \fP +.br \fC#include 'utils\&.hpp'\fP .br @@ -21,6 +23,18 @@ src/utils.cpp \- Implementation of the utils\&. .RI "std::string \fBscientific_format\fP (const std::vector< double > &v, int width, int prec)" .br .RI "Turns a vector of doubles into a string written in scientific format\&. " +.ti -1c +.RI "void \fBm_assert\fP (bool expr, std::string expr_str, std::string f, std::string file, int line, std::string msg)" +.br +.RI "Test an expression, confirm that test is ok, or abort execution\&. " +.ti -1c +.RI "bool \fBarma_vector_close_to\fP (arma::vec &a, arma::vec &b, double tol)" +.br +.RI "Test if two armadillo vectors are close to each other\&. " +.ti -1c +.RI "bool \fBmkpath\fP (std::string path, int mode)" +.br +.RI "Make path given\&. " .in -1c .SH "Detailed Description" .PP @@ -51,10 +65,75 @@ No known bugs Definition in file \fButils\&.cpp\fP\&. .SH "Function Documentation" .PP +.SS "bool arma_vector_close_to (arma::vec & a, arma::vec & b, double tol = \fC1e\-8\fP)" + +.PP +Test if two armadillo vectors are close to each other\&. This function takes in 2 vectors and checks if they are approximately equal to each other given a tolerance\&. +.PP +\fBParameters\fP +.RS 4 +\fIa\fP Vector a +.br +\fIb\fP Vector b +.br +\fItol\fP The tolerance +.RE +.PP +\fBReturns\fP +.RS 4 +bool +.RE +.PP + +.PP +Definition at line \fB62\fP of file \fButils\&.cpp\fP\&. +.SS "void m_assert (bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)" + +.PP +Test an expression, confirm that test is ok, or abort execution\&. This function takes in an expression and prints an OK message if it's true, or it prints a fail message and aborts execution if it fails\&. +.PP +\fBParameters\fP +.RS 4 +\fIexpr\fP The expression to be evaluated +.br +\fIexpr_str\fP The stringified version of the expression +.br +\fIfunc\fP The function name of the caller +.br +\fIfile\fP The file of the caller +.br +\fIline\fP The line number where this function is called from +.br +\fImsg\fP The message to be displayed +.RE +.PP + +.PP +Definition at line \fB43\fP of file \fButils\&.cpp\fP\&. +.SS "bool mkpath (std::string path, int mode = \fC0777\fP)" + +.PP +Make path given\&. This tries to be the equivalent to 'mkdir -p' and creates a new directory whenever it needs to\&. +.PP +\fBParameters\fP +.RS 4 +\fIpath\fP The path to be created +.br +\fImode\fP The mode/permissions for all the new directories +.RE +.PP +\fBReturns\fP +.RS 4 +bool +.RE +.PP + +.PP +Definition at line \fB76\fP of file \fButils\&.cpp\fP\&. .SS "std::string scientific_format (const std::vector< double > & v, int width = \fC20\fP, int prec = \fC10\fP)" .PP -Turns a vector of doubles into a string written in scientific format\&. +Turns a vector of doubles into a string written in scientific format\&. The code is stolen from https://github.com/anderkve/FYS3150\&. .PP \fBParameters\fP .RS 4 @@ -67,16 +146,16 @@ Turns a vector of doubles into a string written in scientific format\&. .PP \fBReturns\fP .RS 4 -String +std::string .RE .PP .PP -Definition at line \fB21\fP of file \fButils\&.cpp\fP\&. +Definition at line \fB24\fP of file \fButils\&.cpp\fP\&. .SS "std::string scientific_format (double d, int width = \fC20\fP, int prec = \fC10\fP)" .PP -Turns a double into a string written in scientific format\&. Code stolen from https://github.com/anderkve/FYS3150 Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp +Turns a double into a string written in scientific format\&. The code is stolen from https://github.com/anderkve/FYS3150\&. .PP \fBParameters\fP .RS 4 @@ -89,12 +168,12 @@ Turns a double into a string written in scientific format\&. Code stolen from ht .PP \fBReturns\fP .RS 4 -String +std::string .RE .PP .PP -Definition at line \fB14\fP of file \fButils\&.cpp\fP\&. +Definition at line \fB17\fP of file \fButils\&.cpp\fP\&. .SH "Author" .PP Generated automatically by Doxygen for Penning Trap Simulation from the source code\&. diff --git a/man_pages/man3/utils.hpp.3 b/man_pages/man3/utils.hpp.3 index 3aba776..3f934d0 100644 --- a/man_pages/man3/utils.hpp.3 +++ b/man_pages/man3/utils.hpp.3 @@ -1,4 +1,4 @@ -.TH "include/utils.hpp" 3 "Thu Sep 28 2023" "Penning Trap Simulation" \" -*- nroff -*- +.TH "include/utils.hpp" 3 "Sat Oct 14 2023" "Penning Trap Simulation" \" -*- nroff -*- .ad l .nh .SH NAME @@ -7,14 +7,16 @@ include/utils.hpp \- Function prototypes and macros that are useful\&. .SH SYNOPSIS .br .PP -\fC#include \fP -.br -\fC#include \fP +\fC#include \fP .br \fC#include \fP .br \fC#include \fP .br +\fC#include \fP +.br +\fC#include \fP +.br .SS "Macros" @@ -23,6 +25,14 @@ include/utils.hpp \- Function prototypes and macros that are useful\&. .RI "#define \fBDEBUG\fP(msg)" .br .RI "Writes a debug message\&. " +.ti -1c +.RI "#define \fBASSERT\fP(expr, msg)" +.br +.RI "A prettier assertion function\&. " +.ti -1c +.RI "#define \fB__METHOD_NAME__\fP methodName(__PRETTY_FUNCTION__)" +.br +.RI "Get the name of the current method/function\&. " .in -1c .SS "Functions" @@ -35,6 +45,18 @@ include/utils.hpp \- Function prototypes and macros that are useful\&. .RI "std::string \fBscientific_format\fP (const std::vector< double > &v, int width=20, int prec=10)" .br .RI "Turns a vector of doubles into a string written in scientific format\&. " +.ti -1c +.RI "void \fBm_assert\fP (bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)" +.br +.RI "Test an expression, confirm that test is ok, or abort execution\&. " +.ti -1c +.RI "bool \fBarma_vector_close_to\fP (arma::vec &a, arma::vec &b, double tol=1e\-8)" +.br +.RI "Test if two armadillo vectors are close to each other\&. " +.ti -1c +.RI "bool \fBmkpath\fP (std::string path, int mode=0777)" +.br +.RI "Make path given\&. " .in -1c .SH "Detailed Description" .PP @@ -67,18 +89,100 @@ No known bugs Definition in file \fButils\&.hpp\fP\&. .SH "Macro Definition Documentation" .PP +.SS "#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)" + +.PP +Get the name of the current method/function\&. +.PP +Definition at line \fB51\fP of file \fButils\&.hpp\fP\&. +.SS "#define ASSERT(expr, msg)" +\fBValue:\fP.PP +.nf + m_assert(expr, #expr, __METHOD_NAME__, __FILE__, \\ + __LINE__, msg) +.fi + +.PP +A prettier assertion function\&. This macro calls the m_assert function which is a more informative assertion function than the regular assert function from cassert\&. +.PP +Definition at line \fB45\fP of file \fButils\&.hpp\fP\&. .SS "#define DEBUG(msg)" .PP -Writes a debug message\&. This function writes a debug message that includes the filename, line number, and a custom message\&. The function is wrapped in an ifdef that checks if DBG is defined, so one can choose to display the debug messages by adding the -DDBG flag when compiling\&. +Writes a debug message\&. This macro writes a debug message that includes the filename, line number, and a custom message\&. The function is wrapped in an ifdef that checks if DBG is defined, so one can choose to display the debug messages by adding the -DDBG flag when compiling\&. .PP -Definition at line \fB35\fP of file \fButils\&.hpp\fP\&. +Definition at line \fB36\fP of file \fButils\&.hpp\fP\&. .SH "Function Documentation" .PP +.SS "bool arma_vector_close_to (arma::vec & a, arma::vec & b, double tol = \fC1e\-8\fP)" + +.PP +Test if two armadillo vectors are close to each other\&. This function takes in 2 vectors and checks if they are approximately equal to each other given a tolerance\&. +.PP +\fBParameters\fP +.RS 4 +\fIa\fP Vector a +.br +\fIb\fP Vector b +.br +\fItol\fP The tolerance +.RE +.PP +\fBReturns\fP +.RS 4 +bool +.RE +.PP + +.PP +Definition at line \fB62\fP of file \fButils\&.cpp\fP\&. +.SS "void m_assert (bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)" + +.PP +Test an expression, confirm that test is ok, or abort execution\&. This function takes in an expression and prints an OK message if it's true, or it prints a fail message and aborts execution if it fails\&. +.PP +\fBParameters\fP +.RS 4 +\fIexpr\fP The expression to be evaluated +.br +\fIexpr_str\fP The stringified version of the expression +.br +\fIfunc\fP The function name of the caller +.br +\fIfile\fP The file of the caller +.br +\fIline\fP The line number where this function is called from +.br +\fImsg\fP The message to be displayed +.RE +.PP + +.PP +Definition at line \fB43\fP of file \fButils\&.cpp\fP\&. +.SS "bool mkpath (std::string path, int mode = \fC0777\fP)" + +.PP +Make path given\&. This tries to be the equivalent to 'mkdir -p' and creates a new directory whenever it needs to\&. +.PP +\fBParameters\fP +.RS 4 +\fIpath\fP The path to be created +.br +\fImode\fP The mode/permissions for all the new directories +.RE +.PP +\fBReturns\fP +.RS 4 +bool +.RE +.PP + +.PP +Definition at line \fB76\fP of file \fButils\&.cpp\fP\&. .SS "std::string scientific_format (const std::vector< double > & v, int width = \fC20\fP, int prec = \fC10\fP)" .PP -Turns a vector of doubles into a string written in scientific format\&. +Turns a vector of doubles into a string written in scientific format\&. The code is stolen from https://github.com/anderkve/FYS3150\&. .PP \fBParameters\fP .RS 4 @@ -91,16 +195,16 @@ Turns a vector of doubles into a string written in scientific format\&. .PP \fBReturns\fP .RS 4 -String +std::string .RE .PP .PP -Definition at line \fB21\fP of file \fButils\&.cpp\fP\&. +Definition at line \fB24\fP of file \fButils\&.cpp\fP\&. .SS "std::string scientific_format (double d, int width = \fC20\fP, int prec = \fC10\fP)" .PP -Turns a double into a string written in scientific format\&. Code stolen from https://github.com/anderkve/FYS3150 Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp +Turns a double into a string written in scientific format\&. The code is stolen from https://github.com/anderkve/FYS3150\&. .PP \fBParameters\fP .RS 4 @@ -113,12 +217,12 @@ Turns a double into a string written in scientific format\&. Code stolen from ht .PP \fBReturns\fP .RS 4 -String +std::string .RE .PP .PP -Definition at line \fB14\fP of file \fButils\&.cpp\fP\&. +Definition at line \fB17\fP of file \fButils\&.cpp\fP\&. .SH "Author" .PP Generated automatically by Doxygen for Penning Trap Simulation from the source code\&. diff --git a/src/Makefile b/src/Makefile index fd101c7..f678e43 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ CLASSOBJS=$(CLASSSRCS:.cpp=.o) INCLUDE=../include -CFLAGS=-larmadillo -llapack -std=c++11 +CFLAGS=-Wall -larmadillo -lblas -llapack -std=c++11 -O3 OPENMP=-fopenmp # Add a debug flag when compiling (For the DEBUG macro in utils.hpp) @@ -19,20 +19,27 @@ else DBGFLAG= endif +PROFILE ?= 0 +ifeq ($(PROFILE), 1) + PROFFLAG=-pg +else + PROFFLAG= +endif + .PHONY: clean all: test_suite main # Rules for executables -main: main.o $(LIBOBJS) - $(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) -I$(INCLUDE) $(OPENMP) +main: main.o $(LIBOBJS) $(CLASSOBJS) + $(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP) -test_suite: test_suite.o $(LIBOBJS) - $(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) -I$(INCLUDE) $(OPENMP) +test_suite: test_suite.o $(LIBOBJS) $(CLASSOBJS) + $(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP) # Rule for object files %.o: %.cpp - $(CC) -c $^ -o $@ $(DBGFLAG) -I$(INCLUDE) $(OPENMP) + $(CC) -c $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP) clean: rm *.o diff --git a/src/Particle.cpp b/src/Particle.cpp index 1bcdb15..2caad68 100644 --- a/src/Particle.cpp +++ b/src/Particle.cpp @@ -8,8 +8,6 @@ * @brief The implementation of the Particle class. * * @bug No known bugs - * - * @todo Implement constructor * */ #include "Particle.hpp" @@ -18,5 +16,9 @@ Particle::Particle(double q, double m, arma::vec::fixed<3> r_vec, arma::vec::fixed<3> v_vec) { - + // Giving the particle its properties + this->q = q; + this->m = m; + this->r_vec = r_vec; + this->v_vec = v_vec; } diff --git a/src/PenningTrap.cpp b/src/PenningTrap.cpp index 7a4ff2b..d0478ec 100644 --- a/src/PenningTrap.cpp +++ b/src/PenningTrap.cpp @@ -8,67 +8,273 @@ * @brief The implementation of the PenningTrap class. * * @bug No known bugs - * - * @todo Implement constructor - * @todo Implement add_particle - * @todo Implement external_E_field - * @todo Implement external_B_field - * @todo Implement force_on_particle - * @todo Implement total_force_external - * @todo Implement total_force_particles - * @todo Implement total_force - * @todo Implement evolve_RK4 - * @todo Implement evolve_forward_euler * */ #include "PenningTrap.hpp" +#include "constants.hpp" +#include "typedefs.hpp" +#include "utils.hpp" -PenningTrap::PenningTrap(double B_0, double V_0, double d) +PenningTrap::PenningTrap(double B_0, std::function V_0, + double d, double t) { + this->B_0 = B_0; + this->V_0 = V_0; + this->d = d; + this->t = t; +} +PenningTrap::PenningTrap(unsigned int i, double B_0, + std::function V_0, double d, double t) + : PenningTrap::PenningTrap(B_0, V_0, d) +{ + vec_3d r, v; + for (size_t j = 0; j < i; j++) { + r = vec_3d().randn() * .1 * this->d; + v = vec_3d().randn() * .1 * this->d; + this->add_particle(Particle(1., 40., r, v)); + } +} + +PenningTrap::PenningTrap(std::vector particles, double B_0, + std::function V_0, double d, double t) + : PenningTrap::PenningTrap(B_0, V_0, d) +{ + this->particles = particles; +} + +vec_3d PenningTrap::v_func(unsigned int i, unsigned int j, double dt) +{ + switch (i) { + case 0: + return .5 * dt * this->k_v[0][j]; + case 1: + return .5 * dt * this->k_v[1][j]; + case 2: + return dt * this->k_v[2][j]; + case 3: + return (dt / 6.) * (this->k_v[0][j].eval() + this->k_v[1][j].eval() + + this->k_v[2][j].eval() + this->k_v[3][j].eval()); + default: + std::cout << "Not valid!" << std::endl; + abort(); + } +} + +vec_3d PenningTrap::r_func(unsigned int i, unsigned int j, double dt) +{ + switch (i) { + case 0: + return .5 * dt * this->k_r[0][j]; + case 1: + return .5 * dt * this->k_r[1][j]; + case 2: + return dt * this->k_r[2][j]; + case 3: + return (dt / 6.) * (this->k_r[0][j].eval() + this->k_r[1][j].eval() + + this->k_r[2][j].eval() + this->k_r[3][j].eval()); + default: + std::cout << "Not valid!" << std::endl; + abort(); + } } void PenningTrap::add_particle(Particle particle) { - + this->particles.push_back(particle); } -arma::vec PenningTrap::external_E_field(arma::vec r) +vec_3d PenningTrap::external_E_field(vec_3d r) +{ + r(2) *= -2.; + double f = this->V_0(this->t) / (this->d * this->d); + + return f * r; +} + +vec_3d PenningTrap::external_B_field(vec_3d r) +{ + return vec_3d{0., 0., this->B_0}; +} + +vec_3d PenningTrap::force_on_particle(unsigned int i, unsigned int j) +{ + Particle p_j = this->particles[j]; + // Calculate the difference between the particles' position + vec_3d res = this->particles[i].r_vec - p_j.r_vec; + + // Get the distance between the particles + double norm = arma::norm(res, 2); + + // Multiply res with p_j's charge divided by the norm cubed + + return vec_3d(res * p_j.q / (norm * norm * norm)); +} + +vec_3d PenningTrap::total_force_external(unsigned int i) +{ + Particle p = this->particles[i]; + + if (arma::norm(p.r_vec) > this->d) { + return vec_3d{0., 0., 0.}; + } + + vec_3d force = + p.q * (this->external_E_field(p.r_vec) + + arma::cross(p.v_vec, this->external_B_field(p.r_vec))); + + return force; +} + +vec_3d PenningTrap::total_force_particles(unsigned int i) +{ + Particle p = this->particles[i]; + + vec_3d res; + + for (size_t j = 0; j < this->particles.size(); j++) { + if (i == j) { + continue; + } + + res += this->force_on_particle(i, j); + } + + return vec_3d(res * K_E * (p.q / p.m)); +} + +vec_3d PenningTrap::total_force(unsigned int i) +{ + return this->total_force_external(i) - this->total_force_particles(i); +} + +void PenningTrap::evolve_RK4(double dt, bool particle_interaction) { + std::vector original_particles = this->particles; + std::vector tmp_particles = this->particles; + + vec_3d (PenningTrap::*force)(unsigned int); + if (particle_interaction) { + force = &PenningTrap::total_force; + } + else { + force = &PenningTrap::total_force_external; + } + + size_t size = this->particles.size(); + + this->k_v = sim_arr(4, sim_cols(size)); + this->k_r = sim_arr(4, sim_cols(size)); + + for (size_t i = 0; i < 4; i++) { +#pragma omp parallel for + for (size_t j = 0; j < this->particles.size(); j++) { + this->k_v[i][j] = (this->*force)(j) / this->particles[j].m; + this->k_r[i][j] = this->particles[j].v_vec; + + Particle *p = &tmp_particles[j]; + + p->v_vec = original_particles[j].v_vec + this->v_func(i, j, dt); + p->r_vec = original_particles[j].r_vec + this->r_func(i, j, dt); + } + this->particles = tmp_particles; + } + this->t += dt; } -arma::vec PenningTrap::external_B_field(arma::vec r) +void PenningTrap::evolve_forward_euler(double dt, bool particle_interaction) { + std::vector new_state = this->particles; + Particle *p; + + vec_3d (PenningTrap::*force)(unsigned int); + if (particle_interaction) { + force = &PenningTrap::total_force; + } + else { + force = &PenningTrap::total_force_external; + } + +#pragma omp parallel for private(p) + for (size_t i = 0; i < this->particles.size(); i++) { + p = &new_state[i]; + p->v_vec += dt * (this->*force)(i) / p->m; + p->r_vec += dt * this->particles[i].v_vec; + } + + this->particles = new_state; + this->t += dt; } -arma::vec PenningTrap::force_on_particle(int i, int j) +sim_arr PenningTrap::simulate(double time, unsigned int steps, + std::string method, bool particle_interaction) { + double dt = time / (double)steps; + sim_arr res(this->particles.size(), sim_cols(steps)); + + void (PenningTrap::*func)(double, bool); + if (method == "rk4") { + func = &PenningTrap::evolve_RK4; + } + else if (method == "euler") { + func = &PenningTrap::evolve_forward_euler; + } + else { + std::cout << "Not a valid method!" << std::endl; + abort(); + } + + for (size_t j = 0; j < steps; j++) { + for (size_t i = 0; i < this->particles.size(); i++) { + res[i][j] = this->particles[i].r_vec; + } + (this->*func)(dt, particle_interaction); + } + + return res; } -arma::vec PenningTrap::total_force_external(int i) +void PenningTrap::write_simulation_to_dir(std::string path, double time, + int steps, std::string method, + bool particle_interaction) { + if (path.back() != '/') { + path += '/'; + } + if (mkpath(path, 0777) != 0) { + std::cout << "Hello" << std::endl; + return; + } + sim_arr res = this->simulate(time, steps, method, particle_interaction); + + std::ofstream ofile; + +#pragma omp parallel for private(ofile) + for (size_t i = 0; i < this->particles.size(); i++) { + ofile.open(path + "particle_" + std::to_string(i) + ".txt"); + for (vec_3d &vec : res[i]) { + ofile << vec(0) << "," << vec(1) << "," << vec(2) << "\n"; + } + ofile.close(); + } } -arma::vec PenningTrap::total_force_particles(int i) +double PenningTrap::fraction_of_particles_left(double time, unsigned int steps, std::string method, bool particle_interaction) { + sim_arr res = this->simulate(time, steps, method, particle_interaction); + int particles_left = 0; + + for (Particle p : this->particles) { + if (arma::norm(p.r_vec) < this->d) { + particles_left++; + } + } + + return (double) particles_left / (double) this->particles.size(); } -arma::vec PenningTrap::total_force(int i) -{ - -} - -void PenningTrap::evolve_RK4(double dt) -{ - -} - -void PenningTrap::evolve_forward_euler(double dt) -{ - -} diff --git a/src/animate_100_particles.py b/src/animate_100_particles.py new file mode 100644 index 0000000..0fc0083 --- /dev/null +++ b/src/animate_100_particles.py @@ -0,0 +1,71 @@ +import matplotlib.pyplot as plt +import numpy as np +from matplotlib import animation +from mpl_toolkits.mplot3d import Axes3D + + +def get_data(files): + res = [] + for file in files: + arr = [[], [], []] + with open(file, encoding="utf8") as f: + lines = f.readlines() + + for line in lines: + xi, yi, zi = map(float, line.strip().split(",")) + arr[0].append(xi) + arr[1].append(yi) + arr[2].append(zi) + res.append(arr) + + return np.array(res) + + +def update(num, lines, arr): + for line, a in zip(lines, arr): + line.set_data(a[:2, num - 1 : num]) + line.set_3d_properties(a[2, num]) + + +def animate(): + plt.style.use("dark_background") + fig = plt.figure() + ax = fig.add_subplot(projection="3d") + + arr = get_data([f"output/simulate_100_particles/particle_{i}.txt" for i in range(100)]) + + arr = arr[:, :, ::10] + + N = len(arr[0][0]) + + lines = [ax.plot(*a[:, 1], "o")[0] for a in arr] + + ax.set_title("100 particles inside a Penning trap") + plt.figtext( + 0.5, + 0.01, + "100 randomly generated particles " + "evolving over a time of 50 microseconds.", + fontsize=12, + horizontalalignment="center", + ) + + ax.set_xlim3d([-500.0, 500.0]) + ax.set_xlabel("X (micrometers)") + + ax.set_ylim3d([-500.0, 500.0]) + ax.set_ylabel("Y (micrometers)") + + ax.set_zlim3d([-500.0, 500.0]) + ax.set_zlabel("Z (micrometers)") + + ani = animation.FuncAnimation( + fig, update, N, fargs=(lines, arr), interval=1, blit=False + ) + + # ani.save("../images/100_particles.gif", writer=animation.FFMpegFileWriter(fps=50)) + plt.show() + + +if __name__ == "__main__": + animate() diff --git a/src/main.cpp b/src/main.cpp index 4c46902..b07ed93 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,135 @@ * @bug No known bugs * */ -int main() +#include +#include +#include +#include +#include +#include + +#include "PenningTrap.hpp" +#include "utils.hpp" + +#define PARTICLES 100 +#define N 10000 +#define CHARGE 1. +#define MASS 40. // unit: amu + +Particle p1(CHARGE, MASS, vec_3d{20., 0., 20.}, vec_3d{0., 25., 0.}); +Particle p2(CHARGE, MASS, vec_3d{25., 25., 0.}, vec_3d{0., 40., 5.}); + +void simulate_single_particle() { + DEBUG("Inside single particle sim"); + PenningTrap trap(std::vector{p1}); + + double time = 50.; // microseconds + + DEBUG("Write to dir"); + trap.write_simulation_to_dir("output/simulate_single_particle", time, N); +} + +void simulate_two_particles() +{ + PenningTrap trap_no_interaction(std::vector{p1, p2}); + PenningTrap trap_with_interaction(std::vector{p1, p2}); + + double time = 50.; // microseconds + + trap_no_interaction.write_simulation_to_dir( + "output/simulate_2_particles/no_interaction", time, N, "rk4", false); + trap_with_interaction.write_simulation_to_dir( + "output/simulate_2_particles/with_interaction", time, N); +} + +void simulate_single_particle_with_different_steps() +{ + + double time = 50; // microseconds + + for (int i = 0; i < 4; i++) { + int steps = 4000 * (i + 1); + PenningTrap trap(std::vector{p1}); + trap.write_simulation_to_dir("output/N_steps/RK4/" + + std::to_string(steps) + "_steps", + time, steps, "rk4", false); + } + + for (int i = 0; i < 4; i++) { + int steps = 4000 * (i + 1); + PenningTrap trap(std::vector{p1}); + trap.write_simulation_to_dir("output/N_steps/euler/" + + std::to_string(steps) + "_steps", + time, steps, "euler", false); + } +} + +void simulate_100_particles() +{ + PenningTrap trap((unsigned)100, T, + [](double t) { + return 25. * V / 1000. * + (1. + .4 * std::cos(1.5 * t)); + }, + 500., 0); + + double time = 500.; // microseconds + + trap.write_simulation_to_dir("output/simulate_100_particles", time, N*5); +} + +void simulate_100_particles_with_time_potential() +{ + double amplitudes[]{.1, .4, .7}; + + double freq_start = .2; + double freq_end = 2.5; + double freq_increment = .02; + size_t freq_iterations = (size_t) ((freq_end - freq_start) / freq_increment); + + std::string path = "output/time_dependent_potential/"; + mkpath(path); + + std::ofstream ofile; + + for (double f : amplitudes) { + ofile.open(path + "f_" + std::to_string(f) + ".txt"); + #pragma omp parallel for ordered schedule(static, 1) + for (size_t i=0; i < freq_iterations; i++) { + double freq = freq_start + i*freq_increment; + PenningTrap trap((unsigned)100, T, + [f, freq](double t) { + return (25. * V / 1000.) * + (1. + f * std::cos(freq * t)); + }, + 500., 0.); + double res = trap.fraction_of_particles_left(500., 40000, "rk4", true); + #pragma omp ordered + ofile << freq << "," << res << "\n"; + } + ofile.close(); + } +} + +int main() +{ + + simulate_single_particle(); + + simulate_two_particles(); + + simulate_single_particle_with_different_steps(); + + double start = omp_get_wtime(); + + //simulate_100_particles(); + + simulate_100_particles_with_time_potential(); + + double end = omp_get_wtime(); + + std::cout << "Time: " << end - start << " seconds" << std::endl; + return 0; } diff --git a/src/plot_particles_left.py b/src/plot_particles_left.py new file mode 100644 index 0000000..1d9a45c --- /dev/null +++ b/src/plot_particles_left.py @@ -0,0 +1,33 @@ +import matplotlib.pyplot as plt + +def main(): + files = [ + "output/time_dependent_potential/f_0.100000.txt", + "output/time_dependent_potential/f_0.400000.txt", + "output/time_dependent_potential/f_0.700000.txt", + ] + vals = [ + .1, + .4, + .7 + ] + for i in range(3): + with open(files[i]) as f: + lines = f.readlines() + x = [] + y = [] + for line in lines: + a,b = line.strip().split(",") + x.append(float(a)) + y.append(float(b)) + plt.plot(x,y,label=f"amplitude: {vals[i]}") + + plt.xlabel(r"$\omega_V$") + plt.ylabel(r"Fraction of particles left") + plt.title(r"The fraction of particles left in the Penning trap " + "after 500 microseconds for different amplitudes and frequencies") + plt.legend() + plt.show() + +if __name__ == "__main__": + main() diff --git a/src/test_suite.cpp b/src/test_suite.cpp index 41f8b9c..cd422c5 100644 --- a/src/test_suite.cpp +++ b/src/test_suite.cpp @@ -9,7 +9,135 @@ * * @bug No known bugs * */ -int main() + +#include "PenningTrap.hpp" +#include "utils.hpp" + +#include +#include +#include + +class PenningTrapTest { +public: + static void test_external_E_field() + { + PenningTrap trap; + + // Vector containing inputs and expected results + std::vector> tests; + + tests.push_back( + std::make_pair(arma::vec{0., 0., 0.}, arma::vec{0., 0., 0.})); + + tests.push_back(std::make_pair(arma::vec{10., 0., 0.}, + arma::vec{96.4852558, 0., 0.})); + + tests.push_back(std::make_pair(arma::vec{10., 0., 0.}, + arma::vec{96.4852558, 0., 0.})); + + tests.push_back(std::make_pair(arma::vec{0., 10., 0.}, + arma::vec{0., 96.4852558, 0.})); + + tests.push_back(std::make_pair(arma::vec{0., 0., 10.}, + arma::vec{0., 0., -192.9705116})); + + arma::vec result; + arma::vec v; + std::stringstream msg; + for (size_t i = 0; i < tests.size(); i++) { + v = tests.at(i).first; + result = trap.external_E_field(v); + + msg.str(""); + msg << "Testing the external E field at (" << std::setprecision(2) + << v(0) << "," << v(1) << "," << v(2) << ")."; + + ASSERT(arma_vector_close_to(result, tests.at(i).second), msg.str()); + } + } + + static void test_external_B_field() + { + // No point in testing at different points since it's not dependent + // on position. + PenningTrap trap; + arma::vec expected{0., 0., T}; + arma::vec result = trap.external_B_field(arma::vec{0., 0., 0.}); + ASSERT(arma_vector_close_to(expected, result), + "Testing the external B field at (0,0,0)"); + } + + static void test_force_on_particle() + { + PenningTrap trap; + arma::vec v{0., 0., 0.}; + + // Add particles to test + trap.add_particle(Particle(1., 40., arma::vec{0., 0., 0.}, v)); + trap.add_particle(Particle(1., 40., arma::vec{1., 0., 0.}, v)); + trap.add_particle(Particle(1., 40., arma::vec{0., 3., 4.}, v)); + + // Test p0 and p1 + arma::vec expected{-1., 0., 0.}; + arma::vec result = trap.force_on_particle(0, 1); + ASSERT(arma_vector_close_to(expected, result), + "Testing the force on a particle at (0,0,0) from a " + "particle at (1,0,0)."); + + // Test p0 and p2 + expected = arma::vec{0, -.024, -.032}; + result = trap.force_on_particle(0, 2); + ASSERT(arma_vector_close_to(expected, result), + "Testing the force on a particle at (0,0,0) from a " + "particle at (0,3,4)."); + } + + static void test_total_force_external() + { + PenningTrap trap; + trap.add_particle( + Particle(1., 40., arma::vec{1., 2., 3.}, arma::vec{3., 4., 5.})); + + arma::vec expected{395.58954878, -270.15871624, -57.89115348}; + arma::vec result = trap.total_force_external(0); + ASSERT(arma_vector_close_to(expected, result), + "Testing the total external force on a particle at " + "(1,2,3) with velocity (3,4,5)"); + } + + static void test_total_force_particles() + { + PenningTrap trap; + trap.add_particle( + Particle(1., 40., arma::vec{0., 0., 0.}, arma::vec{0., 0., 0.})); + + arma::vec expected{0., 0., 0.}; + arma::vec result = trap.total_force_particles(0); + ASSERT(arma_vector_close_to(expected, result), + "Testing the total force of all particles on particle 0 " + "with only a single particle"); + + trap.add_particle( + Particle(1., 40., arma::vec{1., 0., 0.}, arma::vec{0., 0., 0.})); + trap.add_particle( + Particle(1., 40., arma::vec{0., 1., 0.}, arma::vec{0., 0., 0.})); + trap.add_particle( + Particle(1., 40., arma::vec{0., 0., 1.}, arma::vec{0., 0., 0.})); + + expected = arma::vec(3, arma::fill::value(-3473.383325)); + result = trap.total_force_particles(0); + ASSERT(arma_vector_close_to(expected, result), + "Testing the total force of all particles on particle 0 " + "with 3 other particles."); + } +}; + +int main() { + PenningTrapTest::test_external_E_field(); + PenningTrapTest::test_external_B_field(); + PenningTrapTest::test_force_on_particle(); + PenningTrapTest::test_total_force_external(); + PenningTrapTest::test_total_force_particles(); return 0; } diff --git a/src/utils.cpp b/src/utils.cpp index 0e93a31..14670f0 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -9,6 +9,9 @@ * * @bug No known bugs * */ + +#include + #include "utils.hpp" std::string scientific_format(double d, int width, int prec) @@ -18,11 +21,79 @@ std::string scientific_format(double d, int width, int prec) return ss.str(); } -std::string scientific_format(const std::vector& v, int width, int prec) +std::string scientific_format(const std::vector &v, int width, int prec) { std::stringstream ss; - for(double elem : v) { + for (double elem : v) { ss << scientific_format(elem, width, prec); } return ss.str(); } + +static void print_message(std::string msg) +{ + if (msg.size() > 0) { + std::cout << "message: " << msg << "\n\n"; + } + else { + std::cout << "\n"; + } +} + +void m_assert(bool expr, std::string expr_str, std::string f, std::string file, + int line, std::string msg) +{ + std::string new_assert(f.size() + (expr ? 4 : 6), '-'); + std::cout << "\x1B[36m" << new_assert << "\033[0m\n"; + std::cout << f << ": "; + if (expr) { + std::cout << "\x1B[32mOK\033[0m\n"; + print_message(msg); + } + else { + std::cout << "\x1B[31mFAIL\033[0m\n"; + print_message(msg); + std::cout << file << " " << line << ": Assertion \"" << expr_str + << "\" Failed\n\n"; + abort(); + } +} + +bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol) +{ + if (a.n_elem != b.n_elem) { + return false; + } + + for (size_t i = 0; i < a.n_elem; i++) { + if (std::abs(a(i) - b(i)) >= tol) { + return false; + } + } + return true; +} + +bool mkpath(std::string path, int mode) +{ + std::string cur_dir; + std::string::size_type pos = -1; + struct stat buf; + + if (path.back() != '/') { + path += '/'; + } + while (true) { + pos++; + pos = path.find('/', pos); + if (pos != std::string::npos) { + cur_dir = path.substr(0, pos); + if (mkdir(cur_dir.c_str(), mode) != 0 && stat(cur_dir.c_str(), &buf) != 0) { + return -1; + } + } + else { + break; + } + } + return 0; +}