diff --git a/.clang-format b/.clang-format index d4d13ad..aa36097 100644 --- a/.clang-format +++ b/.clang-format @@ -8,3 +8,5 @@ BreakBeforeBraces: Custom BraceWrapping: AfterFunction: true BeforeElse: true +BreakBeforeBinaryOperators: All +ColumnLimit: 79 diff --git a/Doxyfile b/Doxyfile index 7b951c6..61d59dd 100644 --- a/Doxyfile +++ b/Doxyfile @@ -917,7 +917,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = include src README.md +INPUT = include src src/scripts README.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/README.md b/README.md index 254c153..f404967 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,78 @@ ![](./images/100_particles.gif) +[Repo](https://github.uio.no/FYS3150-G2-2023/Project-3) + +[Documentation](https://pages.github.uio.no/FYS3150-G2-2023/Project-3/) + +## Requirements + +### Operating systems + +- Linux + - Has been tested on [Fedora 38](https://fedoraproject.org/) + - Will most likely work on other Linux distributions +- MacOS + - Might work, but hasn't been tested +- Windows + - Will most likely not work + +### Libraries + +- Python + - [matplotlib](https://matplotlib.org/) + - [numpy](https://numpy.org/) + +- C++ + - [openmp](https://www.openmp.org/) + - [armadillo](https://arma.sourceforge.net/) + + +## Compiling + +Compiling is as easy as running this command while being inside the src directory: + +```shell + make +``` + +## Running programs + +### C++ binaries + +To run **main** or **test_suite**, just run this command while being inside src: + +```shell + ./ +``` + +### Python scripts + +#### Install libraries + +Before running the scripts, make sure that all libraries are installed. +Using pip, you can install all requirements like this: + +```shell + pip install -r requirements.txt +``` + +This recursively install all the packages that are listed in **requirements.txt**. + +#### Running scripts + +For the Python scripts, run them from the src directory like this: + +```shell + python scripts/ +``` + +If you have any problems running the scripts, you might have to run this instead: + +```shell + python3 scripts/ +``` + ## Credits diff --git a/docs/100_particles.gif b/docs/100_particles.gif index 337c6e5..53eb275 100644 Binary files a/docs/100_particles.gif and b/docs/100_particles.gif differ diff --git a/docs/Particle_8cpp_source.html b/docs/Particle_8cpp_source.html index 13c1950..cac8cb5 100644 --- a/docs/Particle_8cpp_source.html +++ b/docs/Particle_8cpp_source.html @@ -105,8 +105,8 @@ $(document).ready(function(){initNavTree('Particle_8cpp_source.html',''); initRe
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)
+
16 vec_3d r_vec,
+
17 vec_3d v_vec)
18{
19 // Giving the particle its properties
20 this->q = q;
@@ -120,6 +120,7 @@ $(document).ready(function(){initNavTree('Particle_8cpp_source.html',''); initRe
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
+
arma::vec::fixed< 3 > vec_3d
Typedef for a fixed 3d arma vector.
Definition: typedefs.hpp:36
diff --git a/docs/Particle_8hpp_source.html b/docs/Particle_8hpp_source.html index f3339f5..98ff655 100644 --- a/docs/Particle_8hpp_source.html +++ b/docs/Particle_8hpp_source.html @@ -128,7 +128,7 @@ $(document).ready(function(){initNavTree('Particle_8hpp_source.html',''); initRe
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
+
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:31
Useful typedefs for cleaner code.
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 5817ff6..81ea9db 100644 --- a/docs/PenningTrap_8cpp.html +++ b/docs/PenningTrap_8cpp.html @@ -105,9 +105,6 @@ $(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

diff --git a/docs/PenningTrap_8cpp_source.html b/docs/PenningTrap_8cpp_source.html index 282e5c2..fab32cb 100644 --- a/docs/PenningTrap_8cpp_source.html +++ b/docs/PenningTrap_8cpp_source.html @@ -103,310 +103,336 @@ $(document).ready(function(){initNavTree('PenningTrap_8cpp_source.html',''); ini
Go to the documentation of this file.
1
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
-
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 this->particles = particles;
-
44}
-
45
-
46vec_3d PenningTrap::v_func(unsigned int i, unsigned int j, double dt)
-
47{
-
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
-
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);
+
14
+
15PenningTrap::PenningTrap(double B_0, std::function<double(double)> V_0,
+
16 double d, double t)
+
17{
+
18 this->B_0 = B_0;
+
19 this->V_0 = V_0;
+
20 this->d = d;
+
21 this->t = t;
+
22}
+
23
+
24PenningTrap::PenningTrap(unsigned int i, double B_0,
+
25 std::function<double(double)> V_0, double d, double t)
+
26 : PenningTrap::PenningTrap(B_0, V_0, d)
+
27{
+
28 vec_3d r, v;
+
29 for (size_t j = 0; j < i; j++) {
+
30 r = vec_3d().randn() * .1 * this->d;
+
31 v = vec_3d().randn() * .1 * this->d;
+
32 this->add_particle(Particle(1., 40., r, v));
+
33 }
+
34}
+
35
+
36PenningTrap::PenningTrap(std::vector<Particle> particles, double B_0,
+
37 std::function<double(double)> V_0, double d, double t)
+
38 : PenningTrap::PenningTrap(B_0, V_0, d)
+
39{
+
40 this->particles = particles;
+
41}
+
42
+
43vec_3d PenningTrap::v_func(unsigned int i, unsigned int j, double dt)
+
44{
+
45 switch (i) {
+
46 case 0:
+
47 return .5 * dt * this->k_v[0][j];
+
48 case 1:
+
49 return .5 * dt * this->k_v[1][j];
+
50 case 2:
+
51 return dt * this->k_v[2][j];
+
52 case 3:
+
53 return (dt / 6.) * (this->k_v[0][j] + 2. * this->k_v[1][j] +
+
54 2. * this->k_v[2][j] + this->k_v[3][j]);
+
55 default:
+
56 std::cout << "Not valid!" << std::endl;
+
57 abort();
+
58 }
+
59}
+
60
+
61vec_3d PenningTrap::r_func(unsigned int i, unsigned int j, double dt)
+
62{
+
63 switch (i) {
+
64 case 0:
+
65 return .5 * dt * this->k_r[0][j];
+
66 case 1:
+
67 return .5 * dt * this->k_r[1][j];
+
68 case 2:
+
69 return dt * this->k_r[2][j];
+
70 case 3:
+
71 return (dt / 6.) * (this->k_r[0][j] + 2. * this->k_r[1][j] +
+
72 2. * this->k_r[2][j] + this->k_r[3][j]);
+
73 default:
+
74 std::cout << "Not valid!" << std::endl;
+
75 abort();
+
76 }
+
77}
+
78
+ +
80{
+
81 this->particles.push_back(particle);
+
82}
+
83
+ +
85{
+
86 r(2) *= -2.;
+
87 double f = this->V_0(this->t) / (this->d * this->d);
+
88
+
89 return f * r;
+
90}
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}
+ +
93{
+
94 return vec_3d{0., 0., this->B_0};
+
95}
+
96
+
97vec_3d PenningTrap::force_on_particle(unsigned int i, unsigned int j)
+
98{
+
99 // Calculate the difference between the particles' position
+
100 vec_3d res = this->particles[i].r_vec - this->particles[j].r_vec;
+
101
+
102 // Get the distance between the particles
+
103 double norm = arma::norm(res, 2);
+
104
+
105 return vec_3d(res * this->particles[j].q / (norm * norm * norm));
+
106}
+
107
+ +
109{
+
110 Particle p = this->particles[i];
+
111
+
112 if (arma::norm(p.r_vec) > this->d) {
+
113 return vec_3d{0., 0., 0.};
+
114 }
+
115
+
116 vec_3d force =
+
117 p.q * (this->external_E_field(p.r_vec) +
+
118 arma::cross(p.v_vec, this->external_B_field(p.r_vec)));
+
119
+
120 return force;
+
121}
+
122
+ +
124{
+
125 Particle p = this->particles[i];
+
126
+
127 vec_3d res;
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 }
+
129 for (size_t j = 0; j < this->particles.size(); j++) {
+
130 if (i == j) {
+
131 continue;
+
132 }
+
133
+
134 res += this->force_on_particle(i, j);
+
135 }
+
136
+
137 return vec_3d(res * K_E * (p.q / p.m));
+
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}
+ +
141{
+
142 if (arma::norm(this->particles[i].r_vec) > this->d) {
+
143 return vec_3d{0., 0., 0.};
+
144 }
+
145 return this->total_force_external(i) - this->total_force_particles(i);
+
146}
+
147
+
148void PenningTrap::evolve_RK4(double dt, bool particle_interaction)
+
149{
150
-
151void PenningTrap::evolve_RK4(double dt, bool particle_interaction)
-
152{
+
151 std::vector<Particle> original_particles = this->particles;
+
152 std::vector<Particle> tmp_particles = this->particles;
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) {
- +
154 vec_3d (PenningTrap::*force)(unsigned int);
+
155 if (particle_interaction) {
+ +
157 }
+
158 else {
+
160 }
-
161 else {
- -
163 }
-
164
-
165 size_t size = this->particles.size();
+
161
+
162 size_t size = this->particles.size();
+
163
+
164 this->k_v = sim_arr(4, sim_cols(size));
+
165 this->k_r = sim_arr(4, sim_cols(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) {
- +
167 for (size_t i = 0; i < 4; i++) {
+
168#pragma omp parallel for
+
169 for (size_t j = 0; j < this->particles.size(); j++) {
+
170 this->k_v[i][j] = (this->*force)(j) / this->particles[j].m;
+
171 this->k_r[i][j] = this->particles[j].v_vec;
+
172
+
173 Particle *p = &tmp_particles[j];
+
174
+
175 p->v_vec = original_particles[j].v_vec + this->v_func(i, j, dt);
+
176 p->r_vec = original_particles[j].r_vec + this->r_func(i, j, dt);
+
177 }
+
178 this->particles.swap(tmp_particles);
+
179 }
+
180 this->t += dt;
+
181}
+
182
+
183void PenningTrap::evolve_forward_euler(double dt, bool particle_interaction)
+
184{
+
185 size_t size = this->particles.size();
+
186 vec_3d force_res[size];
+
187 Particle *p;
+
188
+
189 vec_3d (PenningTrap::*force)(unsigned int);
+
190 if (particle_interaction) {
+ +
192 }
+
193 else {
+
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));
+
196
+
197#pragma omp parallel for
+
198 for (size_t i = 0; i < size; i++) {
+
199 force_res[i] = (this->*force)(i);
+
200 }
+
201
+
202#pragma omp parallel for private(p)
+
203 for (size_t i = 0; i < size; i++) {
+
204 p = &this->particles[i];
+
205 p->r_vec += dt * p->v_vec;
+
206 p->v_vec += dt * force_res[i] / p->m;
+
207 }
+
208
+
209 this->t += dt;
+
210}
+
211
+
212simulation_t PenningTrap::simulate(double time, unsigned int steps,
+
213 std::string method,
+
214 bool particle_interaction)
+
215{
+
216 double dt = time / (double)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();
+
218 unsigned int size = this->particles.size();
+
219
+
220 simulation_t res{sim_arr(size, sim_cols(steps)),
+
221 sim_arr(size, sim_cols(steps))};
+
222
+
223 void (PenningTrap::*func)(double, bool);
+
224 if (method == "rk4") {
+ +
226 }
+
227 else if (method == "euler") {
+ +
229 }
+
230 else {
+
231 std::cout << "Not a valid method!" << std::endl;
+
232 abort();
+
233 }
+
234
+
235 for (size_t j = 0; j < steps; j++) {
+
236 for (size_t i = 0; i < size; i++) {
+
237 res.r_vecs[i][j] = this->particles[i].r_vec;
+
238 res.v_vecs[i][j] = this->particles[i].v_vec;
+
239 }
+
240 (this->*func)(dt, particle_interaction);
+
241 }
+
242
+
243 return res;
+
244}
+
245
+
246void PenningTrap::write_simulation_to_dir(std::string path, double time,
+
247 unsigned int steps,
+
248 std::string method,
+
249 bool particle_interaction)
+
250{
+
251 if (path.back() != '/') {
+
252 path += '/';
+
253 }
+
254 if (mkpath(path, 0777) != 0) {
+
255 std::cout << "Hello" << std::endl;
+
256 return;
+
257 }
+
258
+
259 simulation_t res =
+
260 this->simulate(time, steps, method, particle_interaction);
+
261
+
262 std::ofstream ofile;
+
263
+
264#pragma omp parallel for private(ofile)
+
265 for (size_t i = 0; i < this->particles.size(); i++) {
+
266 ofile.open(path + "particle_" + std::to_string(i) + "_r.txt");
+
267 for (vec_3d &vec : res.r_vecs[i]) {
+
268 ofile << vec(0) << "," << vec(1) << "," << vec(2) << "\n";
+
269 }
+
270 ofile.close();
+
271 ofile.open(path + "particle_" + std::to_string(i) + "_v.txt");
+
272 for (vec_3d &vec : res.v_vecs[i]) {
+
273 ofile << scientific_format(vec(0), 10, 8) << ","
+
274 << scientific_format(vec(1), 8, 10) << ","
+
275 << scientific_format(vec(2), 8, 10) << "\n";
+
276 }
+
277 ofile.close();
+
278 }
279}
280
+
281double PenningTrap::fraction_of_particles_left(double time, unsigned int steps,
+
282 std::string method,
+
283 bool particle_interaction)
+
284{
+
285 simulation_t res =
+
286 this->simulate(time, steps, method, particle_interaction);
+
287
+
288 int particles_left = 0;
+
289
+
290 for (Particle p : this->particles) {
+
291 if (arma::norm(p.r_vec) < this->d) {
+
292 particles_left++;
+
293 }
+
294 }
+
295
+
296 return (double)particles_left / (double)this->particles.size();
+
297}
+
298
+
299vec_3d PenningTrap::get_r(int i)
+
300{
+
301 return this->particles[i].r_vec;
+
302}
+
303
+
304double PenningTrap::get_t()
+
305{
+
306 return this->t;
+
307}
A class for simulating a Penning trap.
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.
+
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:31
+
std::vector< Particle > particles
The particles in the Penning trap.
Definition: PenningTrap.hpp:37
+
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:33
+
vec_3d external_E_field(vec_3d r)
Calculate E at point r.
Definition: PenningTrap.cpp:84
+
vec_3d total_force(unsigned int i)
calculate the total force on a particle p_i.
+
sim_arr k_r
Definition: PenningTrap.hpp:40
+
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:61
+
vec_3d total_force_particles(unsigned int i)
Calculate the total force on a particle p_i from other particles.
+
double d
Characteristic dimension.
Definition: PenningTrap.hpp:35
+
void add_particle(Particle particle)
Add a particle to the system.
Definition: PenningTrap.cpp:79
+
double t
Current time.
Definition: PenningTrap.hpp:36
+
vec_3d force_on_particle(unsigned int i, unsigned int j)
Calculate the force between 2 particles.
Definition: PenningTrap.cpp:97
+
std::function< double(double)> V_0
Applied potential.
Definition: PenningTrap.hpp:34
+
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:92
+
simulation_t 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.
+
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:15
+
vec_3d total_force_external(unsigned int i)
Calculate the total external force on a particle.
+
sim_arr k_v
Definition: PenningTrap.hpp:38
+
vec_3d v_func(unsigned int i, unsigned int j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:43
#define K_E
Coulomb constant. unit: .
Definition: constants.hpp:15
-
Useful typedefs for cleaner code.
+
Typedef for PenningTrap::simulation return value.
Definition: typedefs.hpp:40
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
+
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:74
+
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:15
diff --git a/docs/PenningTrap_8hpp.html b/docs/PenningTrap_8hpp.html index 5f6ee45..7632939 100644 --- a/docs/PenningTrap_8hpp.html +++ b/docs/PenningTrap_8hpp.html @@ -111,6 +111,7 @@ $(document).ready(function(){initNavTree('PenningTrap_8hpp.html',''); initResiza #include "Particle.hpp"
#include "constants.hpp"
#include "typedefs.hpp"
+#include "utils.hpp"

Go to the source code of this file.

diff --git a/docs/PenningTrap_8hpp_source.html b/docs/PenningTrap_8hpp_source.html index dfdddbe..cc866c3 100644 --- a/docs/PenningTrap_8hpp_source.html +++ b/docs/PenningTrap_8hpp_source.html @@ -111,105 +111,111 @@ $(document).ready(function(){initNavTree('PenningTrap_8hpp_source.html',''); ini
18#include "Particle.hpp"
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
- -
31private:
-
32 double B_0;
-
33 std::function<double(double)> V_0;
-
34 double d;
-
35 double t;
-
36 std::vector<Particle> particles;
- - -
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:
- -
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
- -
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
- -
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
- -
121
- -
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
+
21#include "utils.hpp"
+
22
+
23#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \
+
24 initializer(omp_priv = omp_orig)
+
25
+ +
32private:
+
33 double B_0;
+
34 std::function<double(double)> V_0;
+
35 double d;
+
36 double t;
+
37 std::vector<Particle> particles;
+ + +
42
+
53 vec_3d v_func(unsigned int i, unsigned int j, double dt);
+
54
+
65 vec_3d r_func(unsigned int i, unsigned int j, double dt);
+
66
+
67public:
+ +
76 double B_0 = T,
+
77 std::function<double(double)> V_0 =
+
78 [](double t) { return 25. * V / 1000.; },
+
79 double d = 500., double t = 0.);
+
80
+ +
90 unsigned int i, double B_0 = T,
+
91 std::function<double(double)> V_0 =
+
92 [](double t) { return 25. * V / 1000.; },
+
93 double d = 500., double t = 0.);
+
94
+ +
104 std::vector<Particle> particles, double B_0 = T,
+
105 std::function<double(double)> V_0 =
+
106 [](double t) { return 25. * V / 1000.; },
+
107 double d = 500., double t = 0.);
+
108
+
113 void add_particle(Particle particle);
+
114
+ +
122
+ +
130
+
141 vec_3d force_on_particle(unsigned int i, unsigned int j);
+
142
+
152 vec_3d total_force_external(unsigned int i);
+
153
+
160 vec_3d total_force_particles(unsigned int i);
+
161
+
168 vec_3d total_force(unsigned int i);
+
169
+
175 void evolve_RK4(double dt, bool particle_interaction = true);
+
176
+
182 void evolve_forward_euler(double dt, bool particle_interaction = true);
+
183
+
194 simulation_t simulate(double time, unsigned int steps,
+
195 std::string method = "rk4",
+
196 bool particle_interaction = true);
+
197
+
206 void write_simulation_to_dir(std::string path, double time,
+
207 unsigned int steps, std::string method = "rk4",
+
208 bool particle_interaction = true);
+
209
+
220 double fraction_of_particles_left(double time, unsigned int steps,
+
221 std::string method = "rk4",
+
222 bool particle_interaction = true);
+
223
+
224 vec_3d get_r(int i);
+
225 double get_t();
+
226};
+
227
+
228#endif
A class that holds the properties of a particle.
A class that holds attributes of a particle.
Definition: Particle.hpp:21
-
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
-
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
+
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:31
+
std::vector< Particle > particles
The particles in the Penning trap.
Definition: PenningTrap.hpp:37
+
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:33
+
vec_3d external_E_field(vec_3d r)
Calculate E at point r.
Definition: PenningTrap.cpp:84
+
vec_3d total_force(unsigned int i)
calculate the total force on a particle p_i.
+
sim_arr k_r
Definition: PenningTrap.hpp:40
+
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:61
+
vec_3d total_force_particles(unsigned int i)
Calculate the total force on a particle p_i from other particles.
+
double d
Characteristic dimension.
Definition: PenningTrap.hpp:35
+
void add_particle(Particle particle)
Add a particle to the system.
Definition: PenningTrap.cpp:79
+
double t
Current time.
Definition: PenningTrap.hpp:36
+
vec_3d force_on_particle(unsigned int i, unsigned int j)
Calculate the force between 2 particles.
Definition: PenningTrap.cpp:97
+
std::function< double(double)> V_0
Applied potential.
Definition: PenningTrap.hpp:34
+
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:92
+
simulation_t 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.
+
vec_3d total_force_external(unsigned int i)
Calculate the total external force on a particle.
+
sim_arr k_v
Definition: PenningTrap.hpp:38
+
vec_3d v_func(unsigned int i, unsigned int j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:43
Library of constants.
#define T
1 Tesla. unit:
Definition: constants.hpp:17
#define V
1 Volt. unit:
Definition: constants.hpp:19
+
Typedef for PenningTrap::simulation return value.
Definition: typedefs.hpp:40
Useful typedefs for cleaner code.
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.
diff --git a/docs/animate__100__particles_8py_source.html b/docs/animate__100__particles_8py_source.html index af734ca..0475106 100644 --- a/docs/animate__100__particles_8py_source.html +++ b/docs/animate__100__particles_8py_source.html @@ -5,7 +5,7 @@ -Penning Trap Simulation: src/animate_100_particles.py Source File +Penning Trap Simulation: src/scripts/animate_100_particles.py Source File @@ -177,7 +177,7 @@ $(document).ready(function(){initNavTree('animate__100__particles_8py_source.htm diff --git a/docs/annotated.html b/docs/annotated.html index fdee9b2..323b2f9 100644 --- a/docs/annotated.html +++ b/docs/annotated.html @@ -105,7 +105,8 @@ $(document).ready(function(){initNavTree('annotated.html',''); initResizable();
- + +
 CParticleA class that holds attributes of a particle
 CPenningTrapA class that simulates a Penning trap
 CPenningTrapTest
 CPenningTrapTestTest class for the Penning trap
 CsimulationTypedef for PenningTrap::simulation return value
diff --git a/docs/annotated_dup.js b/docs/annotated_dup.js index 574cc6b..c52b935 100644 --- a/docs/annotated_dup.js +++ b/docs/annotated_dup.js @@ -2,5 +2,6 @@ var annotated_dup = [ [ "Particle", "classParticle.html", "classParticle" ], [ "PenningTrap", "classPenningTrap.html", "classPenningTrap" ], - [ "PenningTrapTest", "classPenningTrapTest.html", null ] + [ "PenningTrapTest", "classPenningTrapTest.html", null ], + [ "simulation", "structsimulation.html", null ] ]; \ No newline at end of file diff --git a/docs/classPenningTrap-members.html b/docs/classPenningTrap-members.html index 859c052..973ffb0 100644 --- a/docs/classPenningTrap-members.html +++ b/docs/classPenningTrap-members.html @@ -113,6 +113,8 @@ $(document).ready(function(){initNavTree('classPenningTrap.html',''); initResiza 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 + get_r(int i) (defined in PenningTrap)PenningTrap + get_t() (defined in PenningTrap)PenningTrap k_rPenningTrapprivate k_vPenningTrapprivate particlesPenningTrapprivate @@ -120,7 +122,7 @@ $(document).ready(function(){initNavTree('classPenningTrap.html',''); initResiza 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 + 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 diff --git a/docs/classPenningTrap.html b/docs/classPenningTrap.html index 9afb617..f5952a9 100644 --- a/docs/classPenningTrap.html +++ b/docs/classPenningTrap.html @@ -150,15 +150,19 @@ Public Member Functions 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.
-  +simulation_t 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.
  +vec_3d get_r (int i) +  +double get_t () +  @@ -195,7 +199,7 @@ Private Attributes

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 30 of file PenningTrap.hpp.

+

Definition at line 31 of file PenningTrap.hpp.

Constructor & Destructor Documentation

◆ PenningTrap() [1/3]

@@ -246,7 +250,7 @@ Private Attributes -

Definition at line 18 of file PenningTrap.cpp.

+

Definition at line 15 of file PenningTrap.cpp.

@@ -306,7 +310,7 @@ Private Attributes -

Definition at line 27 of file PenningTrap.cpp.

+

Definition at line 24 of file PenningTrap.cpp.

@@ -366,7 +370,7 @@ Private Attributes -

Definition at line 39 of file PenningTrap.cpp.

+

Definition at line 36 of file PenningTrap.cpp.

@@ -395,7 +399,7 @@ Private Attributes -

Definition at line 82 of file PenningTrap.cpp.

+

Definition at line 79 of file PenningTrap.cpp.

@@ -434,7 +438,7 @@ Private Attributes -

Definition at line 186 of file PenningTrap.cpp.

+

Definition at line 183 of file PenningTrap.cpp.

@@ -473,7 +477,7 @@ Private Attributes -

Definition at line 151 of file PenningTrap.cpp.

+

Definition at line 148 of file PenningTrap.cpp.

@@ -502,7 +506,7 @@ Private Attributes
Returns
vec_3d
-

Definition at line 95 of file PenningTrap.cpp.

+

Definition at line 92 of file PenningTrap.cpp.

@@ -531,7 +535,7 @@ Private Attributes
Returns
vec_3d
-

Definition at line 87 of file PenningTrap.cpp.

+

Definition at line 84 of file PenningTrap.cpp.

@@ -572,7 +576,7 @@ Private Attributes
Returns
vec_3d
-

Definition at line 100 of file PenningTrap.cpp.

+

Definition at line 97 of file PenningTrap.cpp.

@@ -626,7 +630,46 @@ Private Attributes
Returns
double
-

Definition at line 266 of file PenningTrap.cpp.

+

Definition at line 281 of file PenningTrap.cpp.

+ + + + +

◆ get_r()

+ +
+
+

Private Member Functions

+ + + + + + + +
vec_3d PenningTrap::get_r (int i)
+
+ +

Definition at line 299 of file PenningTrap.cpp.

+ +
+ + +

◆ get_t()

+ +
+
+ + + + + + + +
double PenningTrap::get_t ()
+
+ +

Definition at line 304 of file PenningTrap.cpp.

@@ -676,24 +719,24 @@ Private Attributes - +
iIndex i for \(k_{r,i,j}\)
jIndex j for \(k_{r,i,j}\)
dtthe step length (delta time)
dtThe step length (delta time)
Returns
vec_3d
-

Definition at line 64 of file PenningTrap.cpp.

+

Definition at line 61 of file PenningTrap.cpp.

- -

◆ simulate()

+ +

◆ simulate()

- + @@ -730,12 +773,13 @@ Private Attributes - +
sim_arr PenningTrap::simulate simulation_t PenningTrap::simulate ( double  time,
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
particle_interactionTurn particle interactions on/off
+
Returns
simulation_t
-

Definition at line 211 of file PenningTrap.cpp.

+

Definition at line 212 of file PenningTrap.cpp.

@@ -764,7 +808,7 @@ Private Attributes
Returns
vec_3d
-

Definition at line 146 of file PenningTrap.cpp.

+

Definition at line 140 of file PenningTrap.cpp.

@@ -794,7 +838,7 @@ Private Attributes
Returns
vec_3d
-

Definition at line 114 of file PenningTrap.cpp.

+

Definition at line 108 of file PenningTrap.cpp.

@@ -823,7 +867,7 @@ Private Attributes
Returns
vec_3d
-

Definition at line 129 of file PenningTrap.cpp.

+

Definition at line 123 of file PenningTrap.cpp.

@@ -879,7 +923,7 @@ Private Attributes
Returns
vec_3d
-

Definition at line 46 of file PenningTrap.cpp.

+

Definition at line 43 of file PenningTrap.cpp.

@@ -939,7 +983,7 @@ Private Attributes -

Definition at line 240 of file PenningTrap.cpp.

+

Definition at line 246 of file PenningTrap.cpp.

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

Magnetic field strength.

-

Definition at line 32 of file PenningTrap.hpp.

+

Definition at line 33 of file PenningTrap.hpp.

@@ -992,7 +1036,7 @@ Private Attributes

Characteristic dimension.

-

Definition at line 34 of file PenningTrap.hpp.

+

Definition at line 35 of file PenningTrap.hpp.

@@ -1017,7 +1061,7 @@ Private Attributes

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

-

Definition at line 39 of file PenningTrap.hpp.

+

Definition at line 40 of file PenningTrap.hpp.

@@ -1042,7 +1086,7 @@ Private Attributes

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

-

Definition at line 37 of file PenningTrap.hpp.

+

Definition at line 38 of file PenningTrap.hpp.

@@ -1068,7 +1112,7 @@ Private Attributes

The particles in the Penning trap.

-

Definition at line 36 of file PenningTrap.hpp.

+

Definition at line 37 of file PenningTrap.hpp.

@@ -1094,7 +1138,7 @@ Private Attributes

Current time.

-

Definition at line 35 of file PenningTrap.hpp.

+

Definition at line 36 of file PenningTrap.hpp.

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

Applied potential.

-

Definition at line 33 of file PenningTrap.hpp.

+

Definition at line 34 of file PenningTrap.hpp.

diff --git a/docs/classPenningTrap.js b/docs/classPenningTrap.js index 0fd7f36..c3edebd 100644 --- a/docs/classPenningTrap.js +++ b/docs/classPenningTrap.js @@ -11,7 +11,7 @@ var classPenningTrap = [ "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 ], + [ "simulate", "classPenningTrap.html#ae09ef9cfa7e4ed1c108c8576405b3599", null ], [ "total_force", "classPenningTrap.html#a1f668c4433421136ad51741741aa1bc8", null ], [ "total_force_external", "classPenningTrap.html#ae72d203b0bfa1b9e72bea28cb2863c56", null ], [ "total_force_particles", "classPenningTrap.html#a46a954a0946def199e30fb300ba1c47b", null ], diff --git a/docs/classPenningTrapTest-members.html b/docs/classPenningTrapTest-members.html index 1b1f2e1..6a01a89 100644 --- a/docs/classPenningTrapTest-members.html +++ b/docs/classPenningTrapTest-members.html @@ -104,11 +104,11 @@ $(document).ready(function(){initNavTree('classPenningTrapTest.html',''); initRe

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
test_external_B_field()PenningTrapTestinlinestatic
test_external_E_field()PenningTrapTestinlinestatic
test_force_on_particle()PenningTrapTestinlinestatic
test_total_force_external()PenningTrapTestinlinestatic
test_total_force_particles()PenningTrapTestinlinestatic
diff --git a/docs/classPenningTrapTest.html b/docs/classPenningTrapTest.html index 8eda947..b058407 100644 --- a/docs/classPenningTrapTest.html +++ b/docs/classPenningTrapTest.html @@ -104,23 +104,32 @@ $(document).ready(function(){initNavTree('classPenningTrapTest.html',''); initRe
PenningTrapTest Class Reference
+ +

Test class for the Penning trap. + More...

+ + + + +

Static Public Member Functions

static void test_external_E_field ()
 Test that the external E field gives correct values.
 
static void test_external_B_field ()
 Test that the external B field gives correct values.
 
static void test_force_on_particle ()
 Test that the force between particles gives expected results.
 
static void test_total_force_external ()
 Test that the total external force returns expected results.
 
static void test_total_force_particles ()
 Test that the total force of all particles on a single particle returns expected results.
 

Detailed Description

-
-

Definition at line 20 of file test_suite.cpp.

+

Test class for the Penning trap.

+ +

Definition at line 22 of file test_suite.cpp.

Member Function Documentation

◆ test_external_B_field()

@@ -145,7 +154,9 @@ Static Public Member Functions
-

Definition at line 59 of file test_suite.cpp.

+

Test that the external B field gives correct values.

+ +

Definition at line 65 of file test_suite.cpp.

@@ -172,7 +183,9 @@ Static Public Member Functions
-

Definition at line 22 of file test_suite.cpp.

+

Test that the external E field gives correct values.

+ +

Definition at line 26 of file test_suite.cpp.

@@ -199,7 +212,9 @@ Static Public Member Functions
-

Definition at line 70 of file test_suite.cpp.

+

Test that the force between particles gives expected results.

+ +

Definition at line 78 of file test_suite.cpp.

@@ -226,7 +241,9 @@ Static Public Member Functions
-

Definition at line 95 of file test_suite.cpp.

+

Test that the total external force returns expected results.

+ +

Definition at line 105 of file test_suite.cpp.

@@ -253,7 +270,9 @@ Static Public Member Functions
-

Definition at line 108 of file test_suite.cpp.

+

Test that the total force of all particles on a single particle returns expected results.

+ +

Definition at line 121 of file test_suite.cpp.

diff --git a/docs/classes.html b/docs/classes.html index 7b8f02e..11e3ca3 100644 --- a/docs/classes.html +++ b/docs/classes.html @@ -101,11 +101,14 @@ $(document).ready(function(){initNavTree('classes.html',''); initResizable(); })
Class Index
diff --git a/docs/dir_634e799a3947388232110823971192a8.html b/docs/dir_634e799a3947388232110823971192a8.html new file mode 100644 index 0000000..95b55e3 --- /dev/null +++ b/docs/dir_634e799a3947388232110823971192a8.html @@ -0,0 +1,132 @@ + + + + + + + +Penning Trap Simulation: src/scripts Directory Reference + + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Penning Trap Simulation +
+
Simulate particle behavior inside a Penning Trap
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+ +
+
scripts Directory Reference
+
+
+ + + + + + + + + + + + + + + + +

+Files

file  animate_100_particles.py [code]
 
file  plot_2_particles.py [code]
 
file  plot_3d.py [code]
 
file  plot_particles_left.py [code]
 
file  plot_phase_space.py [code]
 
file  plot_relative_error.py [code]
 
file  plot_single_particle.py [code]
 
+
+
+ + + + diff --git a/docs/dir_634e799a3947388232110823971192a8.js b/docs/dir_634e799a3947388232110823971192a8.js new file mode 100644 index 0000000..f6030ae --- /dev/null +++ b/docs/dir_634e799a3947388232110823971192a8.js @@ -0,0 +1,10 @@ +var dir_634e799a3947388232110823971192a8 = +[ + [ "animate_100_particles.py", "animate__100__particles_8py_source.html", null ], + [ "plot_2_particles.py", "plot__2__particles_8py_source.html", null ], + [ "plot_3d.py", "plot__3d_8py_source.html", null ], + [ "plot_particles_left.py", "plot__particles__left_8py_source.html", null ], + [ "plot_phase_space.py", "plot__phase__space_8py_source.html", null ], + [ "plot_relative_error.py", "plot__relative__error_8py_source.html", null ], + [ "plot_single_particle.py", "plot__single__particle_8py_source.html", null ] +]; \ No newline at end of file diff --git a/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html b/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html index 4313bbd..a595b88 100644 --- a/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html +++ b/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html @@ -102,10 +102,13 @@ $(document).ready(function(){initNavTree('dir_68267d1309a1af8e8297ef4c3efbcdba.h
+ + + +

+Directories

directory  scripts
 
- - @@ -115,8 +118,6 @@ Files - - diff --git a/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.js b/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.js index 64ce7a5..b85a8c3 100644 --- a/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.js +++ b/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.js @@ -1,10 +1,9 @@ var dir_68267d1309a1af8e8297ef4c3efbcdba = [ - [ "animate_100_particles.py", "animate__100__particles_8py_source.html", null ], - [ "main.cpp", "main_8cpp.html", null ], + [ "scripts", "dir_634e799a3947388232110823971192a8.html", "dir_634e799a3947388232110823971192a8" ], + [ "main.cpp", "main_8cpp.html", "main_8cpp" ], [ "Particle.cpp", "Particle_8cpp.html", null ], [ "PenningTrap.cpp", "PenningTrap_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/files.html b/docs/files.html index e842a47..0176ee4 100644 --- a/docs/files.html +++ b/docs/files.html @@ -102,7 +102,7 @@ $(document).ready(function(){initNavTree('files.html',''); initResizable(); });
Here is a list of all documented files with brief descriptions:
-
[detail level 12]

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.
 
+
[detail level 123]
@@ -110,13 +110,19 @@ $(document).ready(function(){initNavTree('files.html',''); initResizable(); }); - - - - - - - + + + + + + + + + + + + +
  include
 constants.hppLibrary of constants
 Particle.hppA class that holds the properties of a particle
 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
  scripts
 animate_100_particles.py
 plot_2_particles.py
 plot_3d.py
 plot_particles_left.py
 plot_phase_space.py
 plot_relative_error.py
 plot_single_particle.py
 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
diff --git a/docs/functions.html b/docs/functions.html index a2f04ea..cc1a7e4 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -98,33 +98,92 @@ $(document).ready(function(){initNavTree('functions.html',''); initResizable();
-
Here is a list of all documented class members with links to the class documentation for each member:
diff --git a/docs/functions_func.html b/docs/functions_func.html index 1182b1d..5d4f949 100644 --- a/docs/functions_func.html +++ b/docs/functions_func.html @@ -109,7 +109,12 @@ $(document).ready(function(){initNavTree('functions_func.html',''); initResizabl
  • Particle() : Particle
  • PenningTrap() : PenningTrap
  • r_func() : PenningTrap
  • -
  • simulate() : PenningTrap
  • +
  • simulate() : PenningTrap
  • +
  • test_external_B_field() : PenningTrapTest
  • +
  • test_external_E_field() : PenningTrapTest
  • +
  • test_force_on_particle() : PenningTrapTest
  • +
  • test_total_force_external() : PenningTrapTest
  • +
  • test_total_force_particles() : PenningTrapTest
  • total_force() : PenningTrap
  • total_force_external() : PenningTrap
  • total_force_particles() : PenningTrap
  • diff --git a/docs/globals.html b/docs/globals.html index 19a9638..66911fb 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -100,16 +100,25 @@ $(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_type.html b/docs/globals_type.html index b7735cc..775a687 100644 --- a/docs/globals_type.html +++ b/docs/globals_type.html @@ -102,6 +102,7 @@ $(document).ready(function(){initNavTree('globals_type.html',''); initResizable(
  • sim_arr : typedefs.hpp
  • sim_cols : typedefs.hpp
  • sim_rows : typedefs.hpp
  • +
  • simulation_t : typedefs.hpp
  • vec_3d : typedefs.hpp
  • diff --git a/docs/globals_vars.html b/docs/globals_vars.html new file mode 100644 index 0000000..2c80e49 --- /dev/null +++ b/docs/globals_vars.html @@ -0,0 +1,114 @@ + + + + + + + +Penning Trap Simulation: File Members + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    +
    + + + + diff --git a/docs/index.html b/docs/index.html index 29ac7fb..b9d7673 100644 --- a/docs/index.html +++ b/docs/index.html @@ -104,7 +104,65 @@ $(document).ready(function(){initNavTree('index.html',''); initResizable(); });

    -

    +

    Repo

    +

    Documentation

    +

    +Requirements

    +

    +Operating systems

    +
      +
    • Linux
        +
      • Has been tested on Fedora 38
      • +
      • Will most likely work on other Linux distributions
      • +
      +
    • +
    • MacOS
        +
      • Might work, but hasn't been tested
      • +
      +
    • +
    • Windows
        +
      • Will most likely not work
      • +
      +
    • +
    +

    +Libraries

    + +

    +Compiling

    +

    Compiling is as easy as running this command while being inside the src directory:

    +
    make
    +

    +Running programs

    +

    +C++ binaries

    +

    To run main or test_suite, just run this command while being inside src:

    +
    ./<program-name>
    +

    +Python scripts

    +

    +Install libraries

    +

    Before running the scripts, make sure that all libraries are installed. Using pip, you can install all requirements like this:

    +
    pip install -r requirements.txt
    +

    This recursively install all the packages that are listed in requirements.txt.

    +

    +Running scripts

    +

    For the Python scripts, run them from the src directory like this:

    +
    python scripts/<script-name>
    +

    If you have any problems running the scripts, you might have to run this instead:

    +
    python3 scripts/<script-name>
    +

    Credits

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

    diff --git a/docs/main_8cpp.html b/docs/main_8cpp.html index b83f224..c7ad43a 100644 --- a/docs/main_8cpp.html +++ b/docs/main_8cpp.html @@ -109,10 +109,10 @@ $(document).ready(function(){initNavTree('main_8cpp.html',''); initResizable();

    The main program for this project. More...

    #include <cmath>
    +#include <complex>
    #include <fstream>
    #include <omp.h>
    #include <string>
    -#include <sys/stat.h>
    #include <vector>
    #include "PenningTrap.hpp"
    #include "utils.hpp"
    @@ -123,7 +123,7 @@ $(document).ready(function(){initNavTree('main_8cpp.html',''); initResizable(); Macros #define PARTICLES   100   -#define N   10000 +#define N   40000   #define CHARGE   1.   @@ -132,15 +132,23 @@ Macros + + + + + + + + @@ -149,9 +157,11 @@ Functions Variables + +

    Functions

    vec_3d analytical_solution_particle_1 (double t)
     The analytical solution for particle p1.
     
    void simulate_single_particle ()
     Simulate a single particle over the period of 50 \( \mu s \).
     
    void simulate_two_particles ()
     Simulate 2 particles over the period of 50 \( \mu s \) with and without particle interactions.
     
    void simulate_single_particle_with_different_steps ()
     Simulate a single particle over 50 \( \mu s \) using different amount of steps and different methods.
     
    void simulate_100_particles ()
     Simulate 100 particles over 50 \( \mu s \).
     
    void simulate_100_particles_with_time_potential ()
     Simulate 100 particles over 500 \( \mu s \) using a time dependent potential.
     
    int main ()
     
    Particle p1 (CHARGE, MASS, vec_3d{20., 0., 20.}, vec_3d{0., 25., 0.})
     Particle 1.
     
    Particle p2 (CHARGE, MASS, vec_3d{25., 25., 0.}, vec_3d{0., 40., 5.})
     Particle 2.
     

    Detailed Description

    @@ -203,7 +213,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    - +
    #define N   10000#define N   40000
    @@ -229,6 +239,35 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    Function Documentation

    + +

    ◆ analytical_solution_particle_1()

    + +
    +
    + + + + + + + + +
    vec_3d analytical_solution_particle_1 (double t)
    +
    + +

    The analytical solution for particle p1.

    +
    Parameters
    + + +
    tTime
    +
    +
    +
    Returns
    vec_3d
    + +

    Definition at line 38 of file main.cpp.

    + +
    +

    ◆ main()

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

    Definition at line 124 of file main.cpp.

    +

    Definition at line 194 of file main.cpp.

    @@ -263,7 +302,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    -

    Definition at line 77 of file main.cpp.

    +

    Simulate 100 particles over 50 \( \mu s \).

    + +

    Definition at line 131 of file main.cpp.

    @@ -282,7 +323,10 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    -

    Definition at line 91 of file main.cpp.

    +

    Simulate 100 particles over 500 \( \mu s \) using a time dependent potential.

    +

    The simulation sweeps over different frequencies in [0.2, 2.5] MHz.

    + +

    Definition at line 146 of file main.cpp.

    @@ -301,7 +345,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    -

    Definition at line 31 of file main.cpp.

    +

    Simulate a single particle over the period of 50 \( \mu s \).

    + +

    Definition at line 55 of file main.cpp.

    @@ -320,7 +366,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    -

    Definition at line 55 of file main.cpp.

    +

    Simulate a single particle over 50 \( \mu s \) using different amount of steps and different methods.

    + +

    Definition at line 88 of file main.cpp.

    @@ -339,7 +387,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    -

    Definition at line 42 of file main.cpp.

    +

    Simulate 2 particles over the period of 50 \( \mu s \) with and without particle interactions.

    + +

    Definition at line 70 of file main.cpp.

    diff --git a/docs/main_8cpp.js b/docs/main_8cpp.js new file mode 100644 index 0000000..8b2b87e --- /dev/null +++ b/docs/main_8cpp.js @@ -0,0 +1,11 @@ +var main_8cpp = +[ + [ "analytical_solution_particle_1", "main_8cpp.html#a6451833d72816ef393087956c766125b", null ], + [ "simulate_100_particles", "main_8cpp.html#a213713d6ecc02a32b588ffd179dc7513", null ], + [ "simulate_100_particles_with_time_potential", "main_8cpp.html#a330668384dc073980ba11116309bacc5", null ], + [ "simulate_single_particle", "main_8cpp.html#a8fdbe2d5a872e50ef5ec1263243589d6", null ], + [ "simulate_single_particle_with_different_steps", "main_8cpp.html#ac67e0d59227856c4d42e7d01c75e0ad2", null ], + [ "simulate_two_particles", "main_8cpp.html#a783789519f97c6430081171cacb0ffb1", null ], + [ "p1", "main_8cpp.html#a87da4ef9f2cd753579484824310467b8", null ], + [ "p2", "main_8cpp.html#a90f661586eb3c318fdca6f95ebc4fc46", null ] +]; \ No newline at end of file diff --git a/docs/main_8cpp_source.html b/docs/main_8cpp_source.html index d437689..276eed1 100644 --- a/docs/main_8cpp_source.html +++ b/docs/main_8cpp_source.html @@ -103,148 +103,205 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
    Go to the documentation of this file.
    1
    13#include <cmath>
    -
    14#include <fstream>
    -
    15#include <omp.h>
    -
    16#include <string>
    -
    17#include <sys/stat.h>
    +
    14#include <complex>
    +
    15#include <fstream>
    +
    16#include <omp.h>
    +
    17#include <string>
    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
    +
    24#define N 40000
    +
    25#define CHARGE 1. // unit: e
    +
    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()
    +
    28// Particles used for testing
    +
    29Particle p1(CHARGE, MASS, vec_3d{20., 0., 20.}, vec_3d{0., 25., 0.});
    +
    30Particle p2(CHARGE, MASS, vec_3d{25., 25., 0.}, vec_3d{0., 40., 5.});
    +
    31
    + +
    39{
    +
    40 double w_0 = T / MASS;
    +
    41 double w_z2 = (50. * V / 1000.) / (MASS * 500. * 500.);
    +
    42 double w_p = (w_0 + std::sqrt(w_0 * w_0 - 2. * w_z2)) / 2.;
    +
    43 double w_n = (w_0 - std::sqrt(w_0 * w_0 - 2. * w_z2)) / 2.;
    +
    44 double A_p = (25. + w_n * 20.) / (w_n - w_p);
    +
    45 double A_n = -(25. + w_p * 20.) / (w_n - w_p);
    +
    46 std::complex<double> f =
    +
    47 A_p * std::exp(std::complex<double>(0., -w_p * t)) +
    +
    48 A_n * std::exp(std::complex<double>(0., -w_n * t));
    +
    49 vec_3d res{std::real(f), std::imag(f), 20. * std::cos(std::sqrt(w_z2) * t)};
    +
    50 return res;
    +
    51}
    +
    52
    +
    56{
    -
    57
    -
    58 double time = 50; // microseconds
    +
    57 // Initialize trap with particle 1
    +
    58 PenningTrap trap(std::vector<Particle>{p1});
    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();
    +
    60 double time = 50.; // microseconds
    +
    61
    +
    62 // Simulate and write results to file
    +
    63 trap.write_simulation_to_dir("output/simulate_single_particle", time, N,
    +
    64 "rk4", false);
    +
    65}
    +
    66
    + +
    71{
    +
    72 // Initialize traps with particles
    +
    73 PenningTrap trap_no_interaction(std::vector<Particle>{p1, p2});
    +
    74 PenningTrap trap_with_interaction(std::vector<Particle>{p1, p2});
    +
    75
    +
    76 double time = 50.; // microseconds
    +
    77
    +
    78 // Simulate and write results to files
    +
    79 trap_no_interaction.write_simulation_to_dir(
    +
    80 "output/simulate_2_particles/no_interaction", time, N, "rk4", false);
    +
    81 trap_with_interaction.write_simulation_to_dir(
    +
    82 "output/simulate_2_particles/with_interaction", time, N);
    +
    83}
    +
    84
    + +
    89{
    +
    90 double time = 50.; // microseconds
    +
    91
    +
    92 std::ofstream ofile;
    +
    93
    +
    94 // Calculate relative error for RK4
    +
    95 std::string path = "output/relative_error/RK4/";
    +
    96 mkpath(path);
    +
    97 for (int i = 0; i < 4; i++) {
    +
    98 int steps = 4000 * std::pow(2, i);
    +
    99 double dt = time / (double)steps;
    +
    100 ofile.open(path + std::to_string(steps) + "_steps.txt");
    +
    101 PenningTrap trap(std::vector<Particle>{p1});
    +
    102 simulation_t res = trap.simulate(time, steps, "rk4", false);
    +
    103 for (int i = 0; i < steps; i++) {
    +
    104 ofile << arma::norm(res.r_vecs[0][i] -
    + +
    106 << "\n";
    +
    107 }
    +
    108 ofile.close();
    +
    109 }
    +
    110
    +
    111 // Calculate relative error for forward Euler
    +
    112 path = "output/relative_error/euler/";
    +
    113 mkpath(path);
    +
    114 for (int i = 0; i < 4; i++) {
    +
    115 int steps = 4000 * std::pow(2, i);
    +
    116 double dt = time / (double)steps;
    +
    117 ofile.open(path + std::to_string(steps) + "_steps.txt");
    +
    118 PenningTrap trap(std::vector<Particle>{p1});
    +
    119 simulation_t res = trap.simulate(time, steps, "euler", false);
    +
    120 for (int i = 0; i < steps; i++) {
    +
    121 ofile << arma::norm(res.r_vecs[0][i] -
    + +
    123 << "\n";
    +
    124 }
    +
    125 ofile.close();
    +
    126 }
    +
    127}
    128
    -
    129 simulate_two_particles();
    -
    130
    -
    131 simulate_single_particle_with_different_steps();
    -
    132
    -
    133 double start = omp_get_wtime();
    + +
    132{
    +
    133 PenningTrap trap((unsigned)100);
    134
    -
    135 //simulate_100_particles();
    +
    135 double time = 50.; // microseconds
    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}
    +
    137 trap.write_simulation_to_dir("output/simulate_100_particles", time, N);
    +
    138}
    +
    139
    + +
    147{
    +
    148 double time = 500.;
    +
    149
    +
    150 double amplitudes[]{.1, .4, .7};
    +
    151
    +
    152 double freq_start = .2;
    +
    153 double freq_end = 2.5;
    +
    154 double freq_increment = .02;
    +
    155 size_t freq_iterations = (size_t)((freq_end - freq_start) / freq_increment);
    +
    156
    +
    157 double res[4][freq_iterations];
    +
    158
    +
    159 std::string path = "output/time_dependent_potential/";
    +
    160 mkpath(path);
    +
    161
    +
    162 std::ofstream ofile;
    +
    163
    +
    164 double freq = freq_start;
    +
    165 for (size_t i = 0; i < freq_iterations; i++) {
    +
    166 res[0][i] = freq;
    +
    167 freq += freq_increment;
    +
    168 }
    +
    169
    +
    170#pragma omp parallel for collapse(2) num_threads(4)
    +
    171 for (size_t i = 0; i < 3; i++) {
    +
    172 for (size_t j = 0; j < freq_iterations; j++) {
    +
    173 PenningTrap trap(
    +
    174 (unsigned)100, T,
    +
    175 std::bind(
    +
    176 [](double f, double r, double t) {
    +
    177 return (25. * V / 1000.) * (1. + f * std::cos(r * t));
    +
    178 },
    +
    179 amplitudes[i], res[0][j], std::placeholders::_1),
    +
    180 500., 0.);
    +
    181 res[i + 1][j] =
    +
    182 trap.fraction_of_particles_left(time, N, "rk4", false);
    +
    183 }
    +
    184 }
    +
    185
    +
    186 ofile.open(path + "res.txt");
    +
    187 for (size_t i = 0; i < freq_iterations; i++) {
    +
    188 ofile << res[0][i] << "," << res[1][i] << "," << res[2][i] << ","
    +
    189 << res[3][i] << "\n";
    +
    190 }
    +
    191 ofile.close();
    +
    192}
    +
    193
    +
    194int main()
    +
    195{
    +
    196 double t0 = omp_get_wtime();
    +
    197
    +
    198 // simulate_single_particle();
    +
    199
    +
    200 // simulate_two_particles();
    +
    201
    + +
    203
    +
    204 double t1 = omp_get_wtime();
    +
    205
    + +
    207
    +
    208 //simulate_100_particles_with_time_potential();
    +
    209
    +
    210 double end = omp_get_wtime();
    +
    211
    +
    212 std::cout << "Time: " << (end - t1) << " seconds" << std::endl;
    +
    213
    +
    214 return 0;
    +
    215}
    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.
    +
    A class that simulates a Penning trap.
    Definition: PenningTrap.hpp:31
    +
    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
    +
    void simulate_100_particles()
    Simulate 100 particles over 50 .
    Definition: main.cpp:131
    +
    void simulate_100_particles_with_time_potential()
    Simulate 100 particles over 500 using a time dependent potential.
    Definition: main.cpp:146
    +
    vec_3d analytical_solution_particle_1(double t)
    The analytical solution for particle p1.
    Definition: main.cpp:38
    +
    void simulate_two_particles()
    Simulate 2 particles over the period of 50 with and without particle interactions.
    Definition: main.cpp:70
    +
    Particle p1(CHARGE, MASS, vec_3d{20., 0., 20.}, vec_3d{0., 25., 0.})
    Particle 1.
    +
    void simulate_single_particle()
    Simulate a single particle over the period of 50 .
    Definition: main.cpp:55
    +
    Particle p2(CHARGE, MASS, vec_3d{25., 25., 0.}, vec_3d{0., 40., 5.})
    Particle 2.
    +
    void simulate_single_particle_with_different_steps()
    Simulate a single particle over 50 using different amount of steps and different methods.
    Definition: main.cpp:88
    +
    Typedef for PenningTrap::simulation return value.
    Definition: typedefs.hpp:40
    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
    +
    bool mkpath(std::string path, int mode=0777)
    Make path given.
    Definition: utils.cpp:74
    diff --git a/docs/menudata.js b/docs/menudata.js index 74c1d7b..84356c6 100644 --- a/docs/menudata.js +++ b/docs/menudata.js @@ -29,7 +29,21 @@ var menudata={children:[ {text:"Class List",url:"annotated.html"}, {text:"Class Index",url:"classes.html"}, {text:"Class Members",url:"functions.html",children:[ -{text:"All",url:"functions.html"}, +{text:"All",url:"functions.html",children:[ +{text:"a",url:"functions.html#index_a"}, +{text:"b",url:"functions.html#index_b"}, +{text:"d",url:"functions.html#index_d"}, +{text:"e",url:"functions.html#index_e"}, +{text:"f",url:"functions.html#index_f"}, +{text:"k",url:"functions.html#index_k"}, +{text:"m",url:"functions.html#index_m"}, +{text:"p",url:"functions.html#index_p"}, +{text:"q",url:"functions.html#index_q"}, +{text:"r",url:"functions.html#index_r"}, +{text:"s",url:"functions.html#index_s"}, +{text:"t",url:"functions.html#index_t"}, +{text:"v",url:"functions.html#index_v"}, +{text:"w",url:"functions.html#index_w"}]}, {text:"Functions",url:"functions_func.html"}, {text:"Variables",url:"functions_vars.html"}, {text:"Related Functions",url:"functions_rela.html"}]}]}, @@ -38,5 +52,6 @@ var menudata={children:[ {text:"File Members",url:"globals.html",children:[ {text:"All",url:"globals.html"}, {text:"Functions",url:"globals_func.html"}, +{text:"Variables",url:"globals_vars.html"}, {text:"Typedefs",url:"globals_type.html"}, {text:"Macros",url:"globals_defs.html"}]}]}]} diff --git a/docs/navtreedata.js b/docs/navtreedata.js index 9640812..6156c4d 100644 --- a/docs/navtreedata.js +++ b/docs/navtreedata.js @@ -25,7 +25,19 @@ var NAVTREE = [ [ "Penning Trap Simulation", "index.html", [ - [ "Credits", "index.html#autotoc_md1", null ], + [ "Requirements", "index.html#autotoc_md1", [ + [ "Operating systems", "index.html#autotoc_md2", null ], + [ "Libraries", "index.html#autotoc_md3", null ] + ] ], + [ "Compiling", "index.html#autotoc_md4", null ], + [ "Running programs", "index.html#autotoc_md5", [ + [ "C++ binaries", "index.html#autotoc_md6", null ], + [ "Python scripts", "index.html#autotoc_md7", [ + [ "Install libraries", "index.html#autotoc_md8", null ], + [ "Running scripts", "index.html#autotoc_md9", null ] + ] ] + ] ], + [ "Credits", "index.html#autotoc_md10", null ], [ "Bug List", "bug.html", null ], [ "Classes", "annotated.html", [ [ "Class List", "annotated.html", "annotated_dup" ], @@ -42,6 +54,7 @@ var NAVTREE = [ "File Members", "globals.html", [ [ "All", "globals.html", null ], [ "Functions", "globals_func.html", null ], + [ "Variables", "globals_vars.html", null ], [ "Typedefs", "globals_type.html", null ], [ "Macros", "globals_defs.html", null ] ] ] diff --git a/docs/navtreeindex0.js b/docs/navtreeindex0.js index 16caa0e..d727fc6 100644 --- a/docs/navtreeindex0.js +++ b/docs/navtreeindex0.js @@ -1,95 +1,121 @@ var NAVTREEINDEX0 = { -"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":[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], +"Particle_8cpp.html":[6,0,1,2], +"Particle_8cpp_source.html":[6,0,1,2], +"Particle_8hpp.html":[6,0,0,1], +"Particle_8hpp_source.html":[6,0,0,1], +"PenningTrap_8cpp.html":[6,0,1,3], +"PenningTrap_8cpp_source.html":[6,0,1,3], +"PenningTrap_8hpp.html":[6,0,0,2], +"PenningTrap_8hpp_source.html":[6,0,0,2], +"animate__100__particles_8py_source.html":[6,0,1,0,0], +"annotated.html":[5,0], +"bug.html":[4], +"classParticle.html":[5,0,0], +"classParticle.html#a566dcc1de4bdc01251776948798ea8e1":[5,0,0,3], +"classParticle.html#a7af9f8d1fef63dd7643b06629ac7bef4":[5,0,0,0], +"classParticle.html#a879692772803d6ab65fa4993b54aea6e":[5,0,0,5], +"classParticle.html#aa797d319549dc2a0beb06cdbfd430232":[5,0,0,1], +"classParticle.html#aedcc7e1bc53b0e2b1a4a07c9a1b47563":[5,0,0,2], +"classParticle.html#af9497cd8f2dcad0fad54f571ddb383e6":[5,0,0,4], +"classPenningTrap.html":[5,0,1], +"classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f":[5,0,1,21], +"classPenningTrap.html#a0194be61c956a9259c747c23e4163c5b":[5,0,1,9], +"classPenningTrap.html#a0cac3509aa96e71a26d3b2c902e27716":[5,0,1,17], +"classPenningTrap.html#a1d58feaa2c9e34cbf26b1c5ed75ca9d9":[5,0,1,7], +"classPenningTrap.html#a1f668c4433421136ad51741741aa1bc8":[5,0,1,12], +"classPenningTrap.html#a2f168622587709b9e3c49077f0b9a640":[5,0,1,19], +"classPenningTrap.html#a36946152fd951b1f7c346c51ff900d8e":[5,0,1,5], +"classPenningTrap.html#a43e74792ab4b3f9299f35cb64bdb2648":[5,0,1,10], +"classPenningTrap.html#a46a954a0946def199e30fb300ba1c47b":[5,0,1,14], +"classPenningTrap.html#a66dfe89c68716b9502927b97f59c27d2":[5,0,1,18], +"classPenningTrap.html#a67139e04ef69c0bcffde8f30f67cbf73":[5,0,1,2], +"classPenningTrap.html#a6e9776ff5b149f01080800716455d7c8":[5,0,1,3], +"classPenningTrap.html#a763700316b502d5900e587c1f61e6bf1":[5,0,1,1], +"classPenningTrap.html#a8ca4e21291f60fde619c14099d8c4e8e":[5,0,1,22], +"classPenningTrap.html#a9ae34ad740a230e667e96bc6ee8730ce":[5,0,1,8], +"classPenningTrap.html#aaf105828121c4a33cc2b217453c20317":[5,0,1,23], +"classPenningTrap.html#ab9ea97a406534bbe621a95215144875e":[5,0,1,4], +"classPenningTrap.html#abbb832a85139b1a56ebde57d7b8f9a57":[5,0,1,16], +"classPenningTrap.html#acbf065c9c125682329ad82a8d166554c":[5,0,1,6], +"classPenningTrap.html#ae09ef9cfa7e4ed1c108c8576405b3599":[5,0,1,11], +"classPenningTrap.html#ae670d7de621acdb343b01af098086f63":[5,0,1,0], +"classPenningTrap.html#ae72d203b0bfa1b9e72bea28cb2863c56":[5,0,1,13], +"classPenningTrap.html#ae9b5afdaa5cd366e94bd294452a1eed4":[5,0,1,20], +"classPenningTrap.html#af98a720da60b0e1a62aefa5f5cb37c1e":[5,0,1,15], +"classPenningTrapTest.html":[5,0,2], +"classes.html":[5,1], +"constants_8hpp.html":[6,0,0,0], +"constants_8hpp.html#a0acb682b8260ab1c60b918599864e2e5":[6,0,0,0,1], +"constants_8hpp.html#a4e451456ad7e9276ed0afa42826e7ccb":[6,0,0,0,0], +"constants_8hpp.html#af40a326b23c68a27cebe60f16634a2cb":[6,0,0,0,2], +"constants_8hpp_source.html":[6,0,0,0], +"dir_634e799a3947388232110823971192a8.html":[6,0,1,0], +"dir_68267d1309a1af8e8297ef4c3efbcdba.html":[6,0,1], +"dir_d44c64559bbebec7f509842c48db8b23.html":[6,0,0], +"files.html":[6,0], +"functions.html":[5,2,0], +"functions_func.html":[5,2,1], +"functions_rela.html":[5,2,3], +"functions_vars.html":[5,2,2], +"globals.html":[6,1,0], +"globals_defs.html":[6,1,4], +"globals_func.html":[6,1,1], +"globals_type.html":[6,1,3], +"globals_vars.html":[6,1,2], "index.html":[], "index.html#autotoc_md1":[0], -"main_8cpp.html":[3,0,1,1], -"main_8cpp_source.html":[3,0,1,1], +"index.html#autotoc_md10":[3], +"index.html#autotoc_md2":[0,0], +"index.html#autotoc_md3":[0,1], +"index.html#autotoc_md4":[1], +"index.html#autotoc_md5":[2], +"index.html#autotoc_md6":[2,0], +"index.html#autotoc_md7":[2,1], +"index.html#autotoc_md8":[2,1,0], +"index.html#autotoc_md9":[2,1,1], +"main_8cpp.html":[6,0,1,1], +"main_8cpp.html#a213713d6ecc02a32b588ffd179dc7513":[6,0,1,1,1], +"main_8cpp.html#a330668384dc073980ba11116309bacc5":[6,0,1,1,2], +"main_8cpp.html#a6451833d72816ef393087956c766125b":[6,0,1,1,0], +"main_8cpp.html#a783789519f97c6430081171cacb0ffb1":[6,0,1,1,5], +"main_8cpp.html#a87da4ef9f2cd753579484824310467b8":[6,0,1,1,6], +"main_8cpp.html#a8fdbe2d5a872e50ef5ec1263243589d6":[6,0,1,1,3], +"main_8cpp.html#a90f661586eb3c318fdca6f95ebc4fc46":[6,0,1,1,7], +"main_8cpp.html#ac67e0d59227856c4d42e7d01c75e0ad2":[6,0,1,1,4], +"main_8cpp_source.html":[6,0,1,1], "pages.html":[], -"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] +"plot__2__particles_8py_source.html":[6,0,1,0,1], +"plot__3d_8py_source.html":[6,0,1,0,2], +"plot__particles__left_8py_source.html":[6,0,1,0,3], +"plot__phase__space_8py_source.html":[6,0,1,0,4], +"plot__relative__error_8py_source.html":[6,0,1,0,5], +"plot__single__particle_8py_source.html":[6,0,1,0,6], +"structsimulation.html":[5,0,3], +"test__suite_8cpp.html":[6,0,1,4], +"test__suite_8cpp_source.html":[6,0,1,4], +"typedefs_8hpp.html":[6,0,0,3], +"typedefs_8hpp.html#a784799c37b5e4fb8bf4f6368e004dec6":[6,0,0,3,4], +"typedefs_8hpp.html#a7c2dfa854274262c4e00e4ef0ab2ce23":[6,0,0,3,2], +"typedefs_8hpp.html#a8502989b1b361725834fc185bd575f66":[6,0,0,3,3], +"typedefs_8hpp.html#a9f33f4962c8fb62cc5ccd0e4e039a8df":[6,0,0,3,5], +"typedefs_8hpp.html#aec69d34220fff45de238b9e01f2686af":[6,0,0,3,1], +"typedefs_8hpp_source.html":[6,0,0,3], +"utils_8cpp.html":[6,0,1,5], +"utils_8cpp.html#a58565270b643b24e3132f38c653e0199":[6,0,1,5,3], +"utils_8cpp.html#a6be6f938bcbb235ebb6a2ed9d08411b2":[6,0,1,5,0], +"utils_8cpp.html#acd2a9c7a7d5a7fe9163be8c4cc110746":[6,0,1,5,4], +"utils_8cpp.html#acf13f4e492199cb7231bfa646dbd08de":[6,0,1,5,2], +"utils_8cpp.html#aff5e07c3c1d321709b0cc38e999f427b":[6,0,1,5,1], +"utils_8cpp_source.html":[6,0,1,5], +"utils_8hpp.html":[6,0,0,4], +"utils_8hpp.html#a2cc3a2cdb635bac3c8b02e89d4d6af38":[6,0,0,4,4], +"utils_8hpp.html#a60dca3177fb9cb5256609adc7af55168":[6,0,0,4,0], +"utils_8hpp.html#a6fdd7217b750aff5b6295ece7cbdeffa":[6,0,0,4,5], +"utils_8hpp.html#a73d4f21ad937dbc50a0c0538c78fd4f9":[6,0,0,4,1], +"utils_8hpp.html#ab3e0cf669bddc59bd53998490ffb68b9":[6,0,0,4,3], +"utils_8hpp.html#ad54b96a1074f9df4dc892a41d115b72d":[6,0,0,4,6], +"utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384":[6,0,0,4,7], +"utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b":[6,0,0,4,2], +"utils_8hpp_source.html":[6,0,0,4] }; diff --git a/docs/plot__2__particles_8py_source.html b/docs/plot__2__particles_8py_source.html new file mode 100644 index 0000000..648387a --- /dev/null +++ b/docs/plot__2__particles_8py_source.html @@ -0,0 +1,153 @@ + + + + + + + +Penning Trap Simulation: src/scripts/plot_2_particles.py Source File + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    plot_2_particles.py
    +
    +
    +
    1import matplotlib.pyplot as plt
    +
    2import numpy as np
    +
    3
    +
    4def main():
    +
    5 files = [
    +
    6 "output/simulate_2_particles/no_interaction/particle_0_r.txt",
    +
    7 "output/simulate_2_particles/no_interaction/particle_1_r.txt",
    +
    8 "output/simulate_2_particles/with_interaction/particle_0_r.txt",
    +
    9 "output/simulate_2_particles/with_interaction/particle_1_r.txt"
    +
    10 ]
    +
    11 labels = [
    +
    12 "particle 1 no interaction",
    +
    13 "particle 2 no interaction",
    +
    14 "particle 1 with interaction",
    +
    15 "particle 2 with interaction",
    +
    16 ]
    +
    17 colors = [
    +
    18 "lightskyblue",
    +
    19 "lightskyblue",
    +
    20 "salmon",
    +
    21 "salmon"
    +
    22 ]
    +
    23 for label, color, file in zip(labels, colors, files):
    +
    24 with open(file) as f:
    +
    25 lines = f.readlines()
    +
    26 t = np.linspace(0, 50, len(lines))
    +
    27 r = np.array([list(map(float, line.strip().split(","))) for line in lines])
    +
    28 plt.plot(r[:,0], r[:,1], label=label, color=color)
    +
    29
    +
    30 plt.xlabel(r"x $(\mu m)$")
    +
    31 plt.ylabel(r"y $(\mu m)$")
    +
    32 plt.title(r"2 particles with and without interactions.")
    +
    33 # plt.legend()
    +
    34 # plt.show()
    +
    35 plt.savefig("../latex/images/plot_2_particles_xy.pdf")
    +
    36
    +
    37
    +
    38if __name__ == "__main__":
    +
    39 main()
    +
    +
    + + + + diff --git a/docs/plot__3d_8py_source.html b/docs/plot__3d_8py_source.html new file mode 100644 index 0000000..d297968 --- /dev/null +++ b/docs/plot__3d_8py_source.html @@ -0,0 +1,154 @@ + + + + + + + +Penning Trap Simulation: src/scripts/plot_3d.py Source File + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    plot_3d.py
    +
    +
    +
    1import matplotlib.pyplot as plt
    +
    2import numpy as np
    +
    3
    +
    4def main():
    +
    5 files = [
    +
    6 "output/simulate_2_particles/no_interaction/particle_0_r.txt",
    +
    7 "output/simulate_2_particles/no_interaction/particle_1_r.txt",
    +
    8 "output/simulate_2_particles/with_interaction/particle_0_r.txt",
    +
    9 "output/simulate_2_particles/with_interaction/particle_1_r.txt"
    +
    10 ]
    +
    11 labels = [
    +
    12 "particle 1 no interaction",
    +
    13 "particle 2 no interaction",
    +
    14 "particle 1 with interaction",
    +
    15 "particle 2 with interaction",
    +
    16 ]
    +
    17 colors = [
    +
    18 "lightskyblue",
    +
    19 "deepskyblue",
    +
    20 "salmon",
    +
    21 "darkred"
    +
    22 ]
    +
    23 ax = plt.figure().add_subplot(projection="3d")
    +
    24 for label, color, file in zip(labels, colors, files):
    +
    25 with open(file) as f:
    +
    26 lines = f.readlines()
    +
    27 t = np.linspace(0, 50, len(lines))
    +
    28 r = np.array([list(map(float, line.strip().split(","))) for line in lines])
    +
    29 ax.plot(r[:,0], r[:,1], r[:,2], label=label, color=color)
    +
    30
    +
    31 ax.set_xlabel(r"x $(\mu m)$")
    +
    32 ax.set_ylabel(r"y $(\mu m)$")
    +
    33 ax.set_zlabel(r"z $(\mu m)$")
    +
    34 plt.title(r"2 particles with and without interactions.")
    +
    35 plt.legend()
    +
    36 plt.savefig("../latex/images/3d_plot.pdf")
    +
    37
    +
    38
    +
    39if __name__ == "__main__":
    +
    40 main()
    +
    +
    + + + + diff --git a/docs/plot__particles__left_8py_source.html b/docs/plot__particles__left_8py_source.html index c9ab258..33e15f0 100644 --- a/docs/plot__particles__left_8py_source.html +++ b/docs/plot__particles__left_8py_source.html @@ -5,7 +5,7 @@ -Penning Trap Simulation: src/plot_particles_left.py Source File +Penning Trap Simulation: src/scripts/plot_particles_left.py Source File @@ -104,42 +104,39 @@ $(document).ready(function(){initNavTree('plot__particles__left_8py_source.html'
    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()
    +
    4 with open("output/time_dependent_potential/res.txt") as f:
    +
    5 lines = f.readlines()
    +
    6 x = []
    +
    7 y1 = []
    +
    8 y2 = []
    +
    9 y3 = []
    +
    10 for line in lines:
    +
    11 l = line.strip().split(",")
    +
    12 x.append(float(l[0]))
    +
    13 y1.append(float(l[1]))
    +
    14 y2.append(float(l[2]))
    +
    15 y3.append(float(l[3]))
    +
    16
    +
    17 plt.plot(x,y1,label=f"amplitude: 0.1")
    +
    18 plt.plot(x,y2,label=f"amplitude: 0.4")
    +
    19 plt.plot(x,y3,label=f"amplitude: 0.7")
    +
    20
    +
    21 plt.xlabel(r"$\omega_V$ (MHz)")
    +
    22 plt.ylabel(r"Fraction of particles left")
    +
    23 plt.title(r"The fraction of particles left in the Penning trap "
    +
    24 "after 500 microseconds for different amplitudes and frequencies")
    +
    25 plt.legend()
    +
    26 # plt.show()
    +
    27 plt.savefig("../latex/images/particles_left.pdf")
    +
    28
    +
    29if __name__ == "__main__":
    +
    30 main()
    diff --git a/docs/plot__phase__space_8py_source.html b/docs/plot__phase__space_8py_source.html new file mode 100644 index 0000000..c746ef7 --- /dev/null +++ b/docs/plot__phase__space_8py_source.html @@ -0,0 +1,167 @@ + + + + + + + +Penning Trap Simulation: src/scripts/plot_phase_space.py Source File + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    plot_phase_space.py
    +
    +
    +
    1import matplotlib.pyplot as plt
    +
    2import numpy as np
    +
    3
    +
    4def main():
    +
    5 directories = {
    +
    6 "output/simulate_2_particles/no_interaction/",
    +
    7 "output/simulate_2_particles/with_interaction/",
    +
    8 }
    +
    9 titles = {
    +
    10 "particles without interaction",
    +
    11 "particles with interaction"
    +
    12 }
    +
    13 files = [
    +
    14 "particle_0_r.txt",
    +
    15 "particle_0_v.txt",
    +
    16 "particle_1_r.txt",
    +
    17 "particle_1_v.txt",
    +
    18 ]
    +
    19 labels = [
    +
    20 r"particle 1 r",
    +
    21 r"particle 1 v",
    +
    22 r"particle 2 r",
    +
    23 r"particle 2 v",
    +
    24 ]
    +
    25 colors = [
    +
    26 "lightskyblue",
    +
    27 "deepskyblue",
    +
    28 "salmon",
    +
    29 "tomato",
    +
    30 ]
    +
    31 fig1, axs1 = plt.subplots(2,1)
    +
    32 fig2, axs2 = plt.subplots(2,1)
    +
    33 for i, (dir, title) in enumerate(zip(directories, titles)):
    +
    34 for label, color, file in zip(labels, colors, files):
    +
    35 with open(dir+file) as f:
    +
    36 lines = f.readlines()
    +
    37 t = np.linspace(0, 50, len(lines))
    +
    38 r = np.array([list(map(float, line.strip().split(","))) for line in lines])
    +
    39 axs1[i].plot(t, r[:,0], label=label, color=color)
    +
    40 axs2[i].plot(t, r[:,2], label=label, color=color)
    +
    41
    +
    42 axs1[i].set(xlabel=r"t $(\mu s)$", ylabel = r"z $(\mu m)$")
    +
    43
    +
    44 axs1[i].legend()
    +
    45 axs1[i].set_title(title)
    +
    46
    +
    47 # plt.show()
    +
    48 fig1.savefig("../latex/images/phase_space_2_particles_x.pdf")
    +
    49 fig2.savefig("../latex/images/phase_space_2_particles_z.pdf")
    +
    50
    +
    51
    +
    52if __name__ == "__main__":
    +
    53 main()
    +
    +
    + + + + diff --git a/docs/plot__relative__error_8py_source.html b/docs/plot__relative__error_8py_source.html new file mode 100644 index 0000000..8628d31 --- /dev/null +++ b/docs/plot__relative__error_8py_source.html @@ -0,0 +1,165 @@ + + + + + + + +Penning Trap Simulation: src/scripts/plot_relative_error.py Source File + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    plot_relative_error.py
    +
    +
    +
    1import matplotlib.pyplot as plt
    +
    2import numpy as np
    +
    3
    +
    4def main():
    +
    5 directories = [
    +
    6 "output/relative_error/RK4/",
    +
    7 "output/relative_error/euler/",
    +
    8 ]
    +
    9 files = [
    +
    10 "4000_steps.txt",
    +
    11 "8000_steps.txt",
    +
    12 "16000_steps.txt",
    +
    13 "32000_steps.txt",
    +
    14 ]
    +
    15 labels = [
    +
    16 r"4000 steps",
    +
    17 r"8000 steps",
    +
    18 r"16000 steps",
    +
    19 r"32000 steps",
    +
    20 ]
    +
    21 titles = [
    +
    22 "Relative error for the RK4 method",
    +
    23 "Relative error for the forward Euler method"
    +
    24 ]
    +
    25 methods = [
    +
    26 "rk4",
    +
    27 "euler"
    +
    28 ]
    +
    29 fig1, axs1 = plt.subplots(2,1)
    +
    30 for i, (dir, title) in enumerate(list(zip(directories, titles))):
    +
    31 max_err = []
    +
    32 for label, file in zip(labels, files):
    +
    33 with open(dir+file) as f:
    +
    34 lines = f.readlines()
    +
    35 t = np.linspace(0, 50, len(lines))
    +
    36 r = np.array([float(line.strip()) for line in lines])
    +
    37 max_err.append(max(r))
    +
    38 axs1[i].plot(t, r, label=label)
    +
    39
    +
    40 axs1[i].set(xlabel=r"t $(\mu s)$", ylabel = r"relative_error $(\mu m)$")
    +
    41 axs1[i].legend()
    +
    42 axs1[i].set_title(title)
    +
    43
    +
    44 conv_rate = 1/3 * sum([np.log2(max_err[i+1]/max_err[i])/np.log2(.5) for i in range(3)])
    +
    45 print(f"{methods[i]}: {conv_rate}")
    +
    46
    +
    47 fig1.savefig("../latex/images/phase_space_2_particles_x.pdf")
    +
    48
    +
    49
    +
    50if __name__ == "__main__":
    +
    51 main()
    +
    +
    + + + + diff --git a/docs/plot__single__particle_8py_source.html b/docs/plot__single__particle_8py_source.html new file mode 100644 index 0000000..d5eff34 --- /dev/null +++ b/docs/plot__single__particle_8py_source.html @@ -0,0 +1,144 @@ + + + + + + + +Penning Trap Simulation: src/scripts/plot_single_particle.py Source File + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    plot_single_particle.py
    +
    +
    +
    1import matplotlib.pyplot as plt
    +
    2import numpy as np
    +
    3
    +
    4def z(t):
    +
    5 V_0 = 25.*9.64852558 * 10**4
    +
    6 m = 40.
    +
    7 d = 500.
    +
    8 w_z = np.sqrt((2.*V_0)/(m*d*d))
    +
    9 return 20.*np.cos(w_z*t)
    +
    10
    +
    11def main():
    +
    12 filename = "output/simulate_single_particle/particle_0_r.txt"
    +
    13 r = t = []
    +
    14 with open(filename) as f:
    +
    15 lines = f.readlines()
    +
    16 t = np.linspace(0, 50, len(lines))
    +
    17 r = np.array([list(map(float, line.strip().split(","))) for line in lines])
    +
    18
    +
    19 plt.plot(t, r[:, 2], label="approximation")
    +
    20 plt.plot(t, z(t), label="analytical")
    +
    21 plt.xlabel(r"time $(\mu s)$")
    +
    22 plt.ylabel(r"z $(\mu m)$")
    +
    23 plt.title(r"Movement of a single particle in the x direction")
    +
    24 plt.legend()
    +
    25 # plt.savefig("../latex/images/single_particle.pdf")
    +
    26 plt.show()
    +
    27
    +
    28
    +
    29if __name__ == "__main__":
    +
    30 main()
    +
    +
    + + + + diff --git a/docs/search/all_1.js b/docs/search/all_1.js index 4fc815a..027119f 100644 --- a/docs/search/all_1.js +++ b/docs/search/all_1.js @@ -1,6 +1,6 @@ var searchData= [ ['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']]], + ['analytical_5fsolution_5fparticle_5f1_1',['analytical_solution_particle_1',['../main_8cpp.html#a6451833d72816ef393087956c766125b',1,'main.cpp']]], ['assert_2',['ASSERT',['../utils_8hpp.html#a73d4f21ad937dbc50a0c0538c78fd4f9',1,'utils.hpp']]] ]; diff --git a/docs/search/all_3.js b/docs/search/all_3.js index 0648f09..f292435 100644 --- a/docs/search/all_3.js +++ b/docs/search/all_3.js @@ -1,4 +1,5 @@ var searchData= [ - ['constants_2ehpp_0',['constants.hpp',['../constants_8hpp.html',1,'']]] + ['close_5fto_0',['close_to',['../utils_8hpp.html#ab3e0cf669bddc59bd53998490ffb68b9',1,'close_to(arma::vec &a, arma::vec &b, double tol=1e-8): utils.cpp'],['../utils_8cpp.html#a6be6f938bcbb235ebb6a2ed9d08411b2',1,'close_to(arma::vec &a, arma::vec &b, double tol): utils.cpp']]], + ['constants_2ehpp_1',['constants.hpp',['../constants_8hpp.html',1,'']]] ]; diff --git a/docs/search/all_9.js b/docs/search/all_9.js index 962dfef..a9cb3b3 100644 --- a/docs/search/all_9.js +++ b/docs/search/all_9.js @@ -1,12 +1,14 @@ var searchData= [ - ['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,'']]] + ['p1_0',['p1',['../main_8cpp.html#a87da4ef9f2cd753579484824310467b8',1,'main.cpp']]], + ['p2_1',['p2',['../main_8cpp.html#a90f661586eb3c318fdca6f95ebc4fc46',1,'main.cpp']]], + ['particle_2',['Particle',['../classParticle.html',1,'Particle'],['../classParticle.html#a7af9f8d1fef63dd7643b06629ac7bef4',1,'Particle::Particle()']]], + ['particle_2ecpp_3',['Particle.cpp',['../Particle_8cpp.html',1,'']]], + ['particle_2ehpp_4',['Particle.hpp',['../Particle_8hpp.html',1,'']]], + ['particles_5',['particles',['../classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f',1,'PenningTrap']]], + ['penning_20trap_20simulation_6',['Penning trap simulation',['../index.html',1,'']]], + ['penningtrap_7',['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_8',['PenningTrap.cpp',['../PenningTrap_8cpp.html',1,'']]], + ['penningtrap_2ehpp_9',['PenningTrap.hpp',['../PenningTrap_8hpp.html',1,'']]], + ['penningtraptest_10',['PenningTrapTest',['../classPenningTrapTest.html',1,'']]] ]; diff --git a/docs/search/all_c.js b/docs/search/all_c.js index f0c09d2..86b3940 100644 --- a/docs/search/all_c.js +++ b/docs/search/all_c.js @@ -4,5 +4,12 @@ var searchData= ['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']]] + ['simulate_4',['simulate',['../classPenningTrap.html#ae09ef9cfa7e4ed1c108c8576405b3599',1,'PenningTrap']]], + ['simulate_5f100_5fparticles_5',['simulate_100_particles',['../main_8cpp.html#a213713d6ecc02a32b588ffd179dc7513',1,'main.cpp']]], + ['simulate_5f100_5fparticles_5fwith_5ftime_5fpotential_6',['simulate_100_particles_with_time_potential',['../main_8cpp.html#a330668384dc073980ba11116309bacc5',1,'main.cpp']]], + ['simulate_5fsingle_5fparticle_7',['simulate_single_particle',['../main_8cpp.html#a8fdbe2d5a872e50ef5ec1263243589d6',1,'main.cpp']]], + ['simulate_5fsingle_5fparticle_5fwith_5fdifferent_5fsteps_8',['simulate_single_particle_with_different_steps',['../main_8cpp.html#ac67e0d59227856c4d42e7d01c75e0ad2',1,'main.cpp']]], + ['simulate_5ftwo_5fparticles_9',['simulate_two_particles',['../main_8cpp.html#a783789519f97c6430081171cacb0ffb1',1,'main.cpp']]], + ['simulation_10',['simulation',['../structsimulation.html',1,'']]], + ['simulation_5ft_11',['simulation_t',['../typedefs_8hpp.html#a784799c37b5e4fb8bf4f6368e004dec6',1,'typedefs.hpp']]] ]; diff --git a/docs/search/all_d.js b/docs/search/all_d.js index c04457d..d8c5a50 100644 --- a/docs/search/all_d.js +++ b/docs/search/all_d.js @@ -2,9 +2,14 @@ var searchData= [ ['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,'']]] + ['test_5fexternal_5fb_5ffield_2',['test_external_B_field',['../classPenningTrapTest.html#acb806e49a688424588e0c501bc57a230',1,'PenningTrapTest']]], + ['test_5fexternal_5fe_5ffield_3',['test_external_E_field',['../classPenningTrapTest.html#a542996d72c713636b95e0aa9118f7901',1,'PenningTrapTest']]], + ['test_5fforce_5fon_5fparticle_4',['test_force_on_particle',['../classPenningTrapTest.html#addf81fa5692d8146cce5571ccdc5999b',1,'PenningTrapTest']]], + ['test_5fsuite_2ecpp_5',['test_suite.cpp',['../test__suite_8cpp.html',1,'']]], + ['test_5ftotal_5fforce_5fexternal_6',['test_total_force_external',['../classPenningTrapTest.html#ae104e04dcd21ac63281c908132fdf255',1,'PenningTrapTest']]], + ['test_5ftotal_5fforce_5fparticles_7',['test_total_force_particles',['../classPenningTrapTest.html#a0ee2bbf5e26c115164208b89c5a29e3d',1,'PenningTrapTest']]], + ['total_5fforce_8',['total_force',['../classPenningTrap.html#a1f668c4433421136ad51741741aa1bc8',1,'PenningTrap']]], + ['total_5fforce_5fexternal_9',['total_force_external',['../classPenningTrap.html#ae72d203b0bfa1b9e72bea28cb2863c56',1,'PenningTrap']]], + ['total_5fforce_5fparticles_10',['total_force_particles',['../classPenningTrap.html#a46a954a0946def199e30fb300ba1c47b',1,'PenningTrap']]], + ['typedefs_2ehpp_11',['typedefs.hpp',['../typedefs_8hpp.html',1,'']]] ]; diff --git a/docs/search/classes_1.js b/docs/search/classes_1.js new file mode 100644 index 0000000..0a5cda5 --- /dev/null +++ b/docs/search/classes_1.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['simulation_0',['simulation',['../structsimulation.html',1,'']]] +]; diff --git a/docs/search/functions_0.js b/docs/search/functions_0.js index 72dba03..2162ba3 100644 --- a/docs/search/functions_0.js +++ b/docs/search/functions_0.js @@ -1,5 +1,5 @@ var searchData= [ ['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']]] + ['analytical_5fsolution_5fparticle_5f1_1',['analytical_solution_particle_1',['../main_8cpp.html#a6451833d72816ef393087956c766125b',1,'main.cpp']]] ]; diff --git a/docs/search/functions_1.js b/docs/search/functions_1.js index c4c479f..ff2dfc6 100644 --- a/docs/search/functions_1.js +++ b/docs/search/functions_1.js @@ -1,7 +1,4 @@ var searchData= [ - ['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']]] + ['close_5fto_0',['close_to',['../utils_8hpp.html#ab3e0cf669bddc59bd53998490ffb68b9',1,'close_to(arma::vec &a, arma::vec &b, double tol=1e-8): utils.cpp'],['../utils_8cpp.html#a6be6f938bcbb235ebb6a2ed9d08411b2',1,'close_to(arma::vec &a, arma::vec &b, double tol): utils.cpp']]] ]; diff --git a/docs/search/functions_2.js b/docs/search/functions_2.js index d1d9acc..c4c479f 100644 --- a/docs/search/functions_2.js +++ b/docs/search/functions_2.js @@ -1,5 +1,7 @@ var searchData= [ - ['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']]] + ['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_3.js b/docs/search/functions_3.js index ffb26d6..d1d9acc 100644 --- a/docs/search/functions_3.js +++ b/docs/search/functions_3.js @@ -1,5 +1,5 @@ var searchData= [ - ['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']]] + ['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_4.js b/docs/search/functions_4.js index 852716e..ffb26d6 100644 --- a/docs/search/functions_4.js +++ b/docs/search/functions_4.js @@ -1,5 +1,5 @@ var searchData= [ - ['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.)']]] + ['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_5.js b/docs/search/functions_5.js index 07b3041..852716e 100644 --- a/docs/search/functions_5.js +++ b/docs/search/functions_5.js @@ -1,4 +1,5 @@ var searchData= [ - ['r_5ffunc_0',['r_func',['../classPenningTrap.html#a43e74792ab4b3f9299f35cb64bdb2648',1,'PenningTrap']]] + ['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_6.js b/docs/search/functions_6.js index a7b65b4..07b3041 100644 --- a/docs/search/functions_6.js +++ b/docs/search/functions_6.js @@ -1,5 +1,4 @@ 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']]] + ['r_5ffunc_0',['r_func',['../classPenningTrap.html#a43e74792ab4b3f9299f35cb64bdb2648',1,'PenningTrap']]] ]; diff --git a/docs/search/functions_7.js b/docs/search/functions_7.js index 73e1881..d253bda 100644 --- a/docs/search/functions_7.js +++ b/docs/search/functions_7.js @@ -1,6 +1,10 @@ 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']]] + ['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#ae09ef9cfa7e4ed1c108c8576405b3599',1,'PenningTrap']]], + ['simulate_5f100_5fparticles_2',['simulate_100_particles',['../main_8cpp.html#a213713d6ecc02a32b588ffd179dc7513',1,'main.cpp']]], + ['simulate_5f100_5fparticles_5fwith_5ftime_5fpotential_3',['simulate_100_particles_with_time_potential',['../main_8cpp.html#a330668384dc073980ba11116309bacc5',1,'main.cpp']]], + ['simulate_5fsingle_5fparticle_4',['simulate_single_particle',['../main_8cpp.html#a8fdbe2d5a872e50ef5ec1263243589d6',1,'main.cpp']]], + ['simulate_5fsingle_5fparticle_5fwith_5fdifferent_5fsteps_5',['simulate_single_particle_with_different_steps',['../main_8cpp.html#ac67e0d59227856c4d42e7d01c75e0ad2',1,'main.cpp']]], + ['simulate_5ftwo_5fparticles_6',['simulate_two_particles',['../main_8cpp.html#a783789519f97c6430081171cacb0ffb1',1,'main.cpp']]] ]; diff --git a/docs/search/functions_8.js b/docs/search/functions_8.js index 8d7b6ff..d230e8d 100644 --- a/docs/search/functions_8.js +++ b/docs/search/functions_8.js @@ -1,4 +1,11 @@ var searchData= [ - ['v_5ffunc_0',['v_func',['../classPenningTrap.html#af98a720da60b0e1a62aefa5f5cb37c1e',1,'PenningTrap']]] + ['test_5fexternal_5fb_5ffield_0',['test_external_B_field',['../classPenningTrapTest.html#acb806e49a688424588e0c501bc57a230',1,'PenningTrapTest']]], + ['test_5fexternal_5fe_5ffield_1',['test_external_E_field',['../classPenningTrapTest.html#a542996d72c713636b95e0aa9118f7901',1,'PenningTrapTest']]], + ['test_5fforce_5fon_5fparticle_2',['test_force_on_particle',['../classPenningTrapTest.html#addf81fa5692d8146cce5571ccdc5999b',1,'PenningTrapTest']]], + ['test_5ftotal_5fforce_5fexternal_3',['test_total_force_external',['../classPenningTrapTest.html#ae104e04dcd21ac63281c908132fdf255',1,'PenningTrapTest']]], + ['test_5ftotal_5fforce_5fparticles_4',['test_total_force_particles',['../classPenningTrapTest.html#a0ee2bbf5e26c115164208b89c5a29e3d',1,'PenningTrapTest']]], + ['total_5fforce_5',['total_force',['../classPenningTrap.html#a1f668c4433421136ad51741741aa1bc8',1,'PenningTrap']]], + ['total_5fforce_5fexternal_6',['total_force_external',['../classPenningTrap.html#ae72d203b0bfa1b9e72bea28cb2863c56',1,'PenningTrap']]], + ['total_5fforce_5fparticles_7',['total_force_particles',['../classPenningTrap.html#a46a954a0946def199e30fb300ba1c47b',1,'PenningTrap']]] ]; diff --git a/docs/search/functions_9.js b/docs/search/functions_9.js index 1b9fc74..8d7b6ff 100644 --- a/docs/search/functions_9.js +++ b/docs/search/functions_9.js @@ -1,4 +1,4 @@ var searchData= [ - ['write_5fsimulation_5fto_5fdir_0',['write_simulation_to_dir',['../classPenningTrap.html#abbb832a85139b1a56ebde57d7b8f9a57',1,'PenningTrap']]] + ['v_5ffunc_0',['v_func',['../classPenningTrap.html#af98a720da60b0e1a62aefa5f5cb37c1e',1,'PenningTrap']]] ]; diff --git a/docs/search/functions_a.js b/docs/search/functions_a.js new file mode 100644 index 0000000..1b9fc74 --- /dev/null +++ b/docs/search/functions_a.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 4d47bbf..a67f3d1 100644 --- a/docs/search/searchdata.js +++ b/docs/search/searchdata.js @@ -1,9 +1,9 @@ var indexSectionsWithContent = { 0: "_abcdefkmpqrstuvw", - 1: "p", + 1: "ps", 2: "cmptu", - 3: "aefmprstvw", + 3: "acefmprstvw", 4: "bdkmpqrtv", 5: "sv", 6: "p", diff --git a/docs/search/typedefs_0.js b/docs/search/typedefs_0.js index e79ff95..75b98c8 100644 --- a/docs/search/typedefs_0.js +++ b/docs/search/typedefs_0.js @@ -2,5 +2,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']]] + ['sim_5frows_2',['sim_rows',['../typedefs_8hpp.html#a8502989b1b361725834fc185bd575f66',1,'typedefs.hpp']]], + ['simulation_5ft_3',['simulation_t',['../typedefs_8hpp.html#a784799c37b5e4fb8bf4f6368e004dec6',1,'typedefs.hpp']]] ]; diff --git a/docs/search/variables_4.js b/docs/search/variables_4.js index c9f603d..89df031 100644 --- a/docs/search/variables_4.js +++ b/docs/search/variables_4.js @@ -1,4 +1,6 @@ var searchData= [ - ['particles_0',['particles',['../classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f',1,'PenningTrap']]] + ['p1_0',['p1',['../main_8cpp.html#a87da4ef9f2cd753579484824310467b8',1,'main.cpp']]], + ['p2_1',['p2',['../main_8cpp.html#a90f661586eb3c318fdca6f95ebc4fc46',1,'main.cpp']]], + ['particles_2',['particles',['../classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f',1,'PenningTrap']]] ]; diff --git a/docs/structsimulation-members.html b/docs/structsimulation-members.html new file mode 100644 index 0000000..e81bad3 --- /dev/null +++ b/docs/structsimulation-members.html @@ -0,0 +1,118 @@ + + + + + + + +Penning Trap Simulation: Member List + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    +
    simulation Member List
    +
    +
    + +

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

    + + + +
    r_vecs (defined in simulation)simulation
    v_vecs (defined in simulation)simulation
    +
    + + + + diff --git a/docs/structsimulation.html b/docs/structsimulation.html new file mode 100644 index 0000000..ea17361 --- /dev/null +++ b/docs/structsimulation.html @@ -0,0 +1,170 @@ + + + + + + + +Penning Trap Simulation: simulation Struct Reference + + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Penning Trap Simulation +
    +
    Simulate particle behavior inside a Penning Trap
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    + +
    simulation Struct Reference
    +
    +
    + +

    Typedef for PenningTrap::simulation return value. + More...

    + +

    #include <typedefs.hpp>

    + + + + + + +

    +Public Attributes

    sim_arr r_vecs
     
    sim_arr v_vecs
     
    +

    Detailed Description

    +

    Typedef for PenningTrap::simulation return value.

    + +

    Definition at line 40 of file typedefs.hpp.

    +

    Member Data Documentation

    + +

    ◆ r_vecs

    + +
    +
    + + + + +
    sim_arr simulation::r_vecs
    +
    + +

    Definition at line 41 of file typedefs.hpp.

    + +
    +
    + +

    ◆ v_vecs

    + +
    +
    + + + + +
    sim_arr simulation::v_vecs
    +
    + +

    Definition at line 42 of file typedefs.hpp.

    + +
    +
    +
    The documentation for this struct was generated from the following file: +
    +
    + + + + diff --git a/docs/test__suite_8cpp.html b/docs/test__suite_8cpp.html index 7c69921..ccc234d 100644 --- a/docs/test__suite_8cpp.html +++ b/docs/test__suite_8cpp.html @@ -107,17 +107,18 @@ $(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 <iomanip>
    #include <sstream>
    #include <string>
    +#include "PenningTrap.hpp"
    +#include "utils.hpp"

    Go to the source code of this file.

    +

    Classes

    class  PenningTrapTest
     Test class for the Penning trap. More...
     

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

    -

    Definition at line 135 of file test_suite.cpp.

    +

    Definition at line 148 of file test_suite.cpp.

    diff --git a/docs/test__suite_8cpp_source.html b/docs/test__suite_8cpp_source.html index b317c82..5341d26 100644 --- a/docs/test__suite_8cpp_source.html +++ b/docs/test__suite_8cpp_source.html @@ -102,151 +102,157 @@ $(document).ready(function(){initNavTree('test__suite_8cpp_source.html',''); ini
    Go to the documentation of this file.
    1
    -
    13#include "PenningTrap.hpp"
    -
    14#include "utils.hpp"
    -
    15
    -
    16#include <iomanip>
    -
    17#include <sstream>
    -
    18#include <string>
    +
    13#include <iomanip>
    +
    14#include <sstream>
    +
    15#include <string>
    +
    16
    +
    17#include "PenningTrap.hpp"
    +
    18#include "utils.hpp"
    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) << ").";
    + +
    23public:
    + +
    27 {
    +
    28 PenningTrap trap;
    +
    29
    +
    30 // Vector containing inputs and expected results
    +
    31 std::vector<std::pair<vec_3d, vec_3d>> tests;
    +
    32
    +
    33 tests.push_back(
    +
    34 std::make_pair(vec_3d{0., 0., 0.}, vec_3d{0., 0., 0.}));
    +
    35
    +
    36 tests.push_back(std::make_pair(vec_3d{10., 0., 0.},
    +
    37 vec_3d{96.4852558, 0., 0.}));
    +
    38
    +
    39 tests.push_back(std::make_pair(vec_3d{10., 0., 0.},
    +
    40 vec_3d{96.4852558, 0., 0.}));
    +
    41
    +
    42 tests.push_back(std::make_pair(vec_3d{0., 10., 0.},
    +
    43 vec_3d{0., 96.4852558, 0.}));
    +
    44
    +
    45 tests.push_back(std::make_pair(vec_3d{0., 0., 10.},
    +
    46 vec_3d{0., 0., -192.9705116}));
    +
    47
    +
    48 vec_3d result;
    +
    49 vec_3d v;
    +
    50 std::stringstream msg;
    +
    51 for (size_t i = 0; i < tests.size(); i++) {
    +
    52 v = tests.at(i).first;
    +
    53 result = trap.external_E_field(v);
    54
    -
    55 ASSERT(arma_vector_close_to(result, tests.at(i).second), msg.str());
    -
    56 }
    -
    57 }
    +
    55 msg.str("");
    +
    56 msg << "Testing the external E field at (" << std::setprecision(2)
    +
    57 << v(0) << "," << v(1) << "," << v(2) << ").";
    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 }
    +
    59 ASSERT(close_to(result, tests.at(i).second), msg.str());
    +
    60 }
    +
    61 }
    +
    62
    + +
    66 {
    +
    67 // No point in testing at different points since it's not dependent
    +
    68 // on position.
    +
    69 PenningTrap trap;
    +
    70 vec_3d expected{0., 0., T};
    +
    71 vec_3d result = trap.external_B_field(vec_3d{0., 0., 0.});
    +
    72 ASSERT(close_to(expected, result),
    +
    73 "Testing the external B field at (0,0,0)");
    +
    74 }
    +
    75
    + +
    79 {
    +
    80 PenningTrap trap;
    +
    81 vec_3d v{0., 0., 0.};
    +
    82
    +
    83 // Add particles to test
    +
    84 trap.add_particle(Particle(1., 40., vec_3d{0., 0., 0.}, v));
    +
    85 trap.add_particle(Particle(1., 40., vec_3d{1., 0., 0.}, v));
    +
    86 trap.add_particle(Particle(1., 40., vec_3d{0., 3., 4.}, v));
    +
    87
    +
    88 // Test p0 and p1
    +
    89 vec_3d expected{-1., 0., 0.};
    +
    90 vec_3d result = trap.force_on_particle(0, 1);
    +
    91 ASSERT(close_to(expected, result),
    +
    92 "Testing the force on a particle at (0,0,0) from a "
    +
    93 "particle at (1,0,0).");
    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.}));
    +
    95 // Test p0 and p2
    +
    96 expected = vec_3d{0, -.024, -.032};
    +
    97 result = trap.force_on_particle(0, 2);
    +
    98 ASSERT(close_to(expected, result),
    +
    99 "Testing the force on a particle at (0,0,0) from a "
    +
    100 "particle at (0,3,4).");
    +
    101 }
    +
    102
    + +
    106 {
    +
    107 PenningTrap trap;
    +
    108 trap.add_particle(
    +
    109 Particle(1., 40., vec_3d{1., 2., 3.}, vec_3d{3., 4., 5.}));
    +
    110
    +
    111 vec_3d expected{395.58954878, -270.15871624, -57.89115348};
    +
    112 vec_3d result = trap.total_force_external(0);
    +
    113 ASSERT(close_to(expected, result),
    +
    114 "Testing the total external force on a particle at "
    +
    115 "(1,2,3) with velocity (3,4,5)");
    +
    116 }
    +
    117
    + +
    122 {
    +
    123 PenningTrap trap;
    124 trap.add_particle(
    -
    125 Particle(1., 40., arma::vec{0., 0., 1.}, arma::vec{0., 0., 0.}));
    +
    125 Particle(1., 40., vec_3d{0., 0., 0.}, vec_3d{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),
    +
    127 vec_3d expected{0., 0., 0.};
    +
    128 vec_3d result = trap.total_force_particles(0);
    +
    129 ASSERT(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}
    +
    131 "with only a single particle");
    +
    132
    +
    133 trap.add_particle(
    +
    134 Particle(1., 40., vec_3d{1., 0., 0.}, vec_3d{0., 0., 0.}));
    +
    135 trap.add_particle(
    +
    136 Particle(1., 40., vec_3d{0., 1., 0.}, vec_3d{0., 0., 0.}));
    +
    137 trap.add_particle(
    +
    138 Particle(1., 40., vec_3d{0., 0., 1.}, vec_3d{0., 0., 0.}));
    +
    139
    +
    140 expected = vec_3d().fill(-3473.383325);
    +
    141 result = trap.total_force_particles(0);
    +
    142 ASSERT(close_to(expected, result),
    +
    143 "Testing the total force of all particles on particle 0 "
    +
    144 "with 3 other particles.");
    +
    145 }
    +
    146};
    +
    147
    +
    148int main()
    +
    149{
    + + + + + +
    155 return 0;
    +
    156}
    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.
    +
    Test class for the Penning trap.
    Definition: test_suite.cpp:22
    +
    static void test_total_force_particles()
    Test that the total force of all particles on a single particle returns expected results.
    Definition: test_suite.cpp:121
    +
    static void test_external_E_field()
    Test that the external E field gives correct values.
    Definition: test_suite.cpp:26
    +
    static void test_external_B_field()
    Test that the external B field gives correct values.
    Definition: test_suite.cpp:65
    +
    static void test_force_on_particle()
    Test that the force between particles gives expected results.
    Definition: test_suite.cpp:78
    +
    static void test_total_force_external()
    Test that the total external force returns expected results.
    Definition: test_suite.cpp:105
    +
    A class that simulates a Penning trap.
    Definition: PenningTrap.hpp:31
    +
    vec_3d external_E_field(vec_3d r)
    Calculate E at point r.
    Definition: PenningTrap.cpp:84
    +
    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:79
    +
    vec_3d force_on_particle(unsigned int i, unsigned int j)
    Calculate the force between 2 particles.
    Definition: PenningTrap.cpp:97
    +
    vec_3d external_B_field(vec_3d r)
    Calculate B at point r.
    Definition: PenningTrap.cpp:92
    +
    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
    +
    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 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
    +
    #define ASSERT(expr, msg)
    A prettier assertion function.
    Definition: utils.hpp:46
    +
    bool 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:60
    diff --git a/docs/typedefs_8hpp.html b/docs/typedefs_8hpp.html index 1f2eedb..1225a91 100644 --- a/docs/typedefs_8hpp.html +++ b/docs/typedefs_8hpp.html @@ -99,6 +99,7 @@ $(document).ready(function(){initNavTree('typedefs_8hpp.html',''); initResizable
    typedefs.hpp File Reference
    @@ -106,11 +107,17 @@ $(document).ready(function(){initNavTree('typedefs_8hpp.html',''); initResizable

    Useful typedefs for cleaner code. More...

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

    Go to the source code of this file.

    + + + + +

    +Classes

    struct  simulation
     Typedef for PenningTrap::simulation return value. More...
     
    @@ -125,6 +132,10 @@ Typedefs + + +

    Typedefs

    typedef std::vector< arma::vec::fixed< 3 > > sim_cols
    typedef arma::vec::fixed< 3 > vec_3d
     Typedef for a fixed 3d arma vector.
     
    +typedef struct simulation simulation_t
     Typedef for PenningTrap::simulation return value.
     

    Detailed Description

    Useful typedefs for cleaner code.

    diff --git a/docs/typedefs_8hpp.js b/docs/typedefs_8hpp.js index d014844..ddf845a 100644 --- a/docs/typedefs_8hpp.js +++ b/docs/typedefs_8hpp.js @@ -1,7 +1,9 @@ var typedefs_8hpp = [ + [ "simulation", "structsimulation.html", null ], [ "sim_arr", "typedefs_8hpp.html#aec69d34220fff45de238b9e01f2686af", null ], [ "sim_cols", "typedefs_8hpp.html#a7c2dfa854274262c4e00e4ef0ab2ce23", null ], [ "sim_rows", "typedefs_8hpp.html#a8502989b1b361725834fc185bd575f66", null ], + [ "simulation_t", "typedefs_8hpp.html#a784799c37b5e4fb8bf4f6368e004dec6", 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 index 475ff07..b7cf904 100644 --- a/docs/typedefs_8hpp_source.html +++ b/docs/typedefs_8hpp_source.html @@ -105,8 +105,8 @@ $(document).ready(function(){initNavTree('typedefs_8hpp_source.html',''); initRe
    15#ifndef __TYPEDEFS__
    16#define __TYPEDEFS__
    17
    -
    18#include <vector>
    -
    19#include <armadillo>
    +
    18#include <armadillo>
    +
    19#include <vector>
    20
    24typedef std::vector<arma::vec::fixed<3>> sim_cols;
    25
    @@ -116,7 +116,14 @@ $(document).ready(function(){initNavTree('typedefs_8hpp_source.html',''); initRe
    33
    36typedef arma::vec::fixed<3> vec_3d;
    37
    -
    38#endif
    +
    40typedef struct simulation {
    +
    41 sim_arr r_vecs;
    +
    42 sim_arr v_vecs;
    + +
    44
    +
    45#endif
    +
    Typedef for PenningTrap::simulation return value.
    Definition: typedefs.hpp:40
    +
    struct simulation simulation_t
    Typedef for PenningTrap::simulation return value.
    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
    diff --git a/docs/utils_8cpp.html b/docs/utils_8cpp.html index 9401b51..f76d7e7 100644 --- a/docs/utils_8cpp.html +++ b/docs/utils_8cpp.html @@ -106,8 +106,7 @@ $(document).ready(function(){initNavTree('utils_8cpp.html',''); initResizable();

    Implementation of the utils. More...

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

    Go to the source code of this file.

    @@ -122,9 +121,9 @@ Functions - - - + + + @@ -139,14 +138,14 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    Definition in file utils.cpp.

    Function Documentation

    - -

    ◆ arma_vector_close_to()

    + +

    ◆ close_to()

    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 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.
     
    - + @@ -183,7 +182,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    Returns
    bool
    -

    Definition at line 62 of file utils.cpp.

    +

    Definition at line 60 of file utils.cpp.

    @@ -251,7 +250,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) -

    Definition at line 43 of file utils.cpp.

    +

    Definition at line 41 of file utils.cpp.

    @@ -290,9 +289,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    bool arma_vector_close_to bool close_to ( arma::vec &  a,
    -
    Returns
    bool
    +
    Returns
    bool Success/Fail
    -

    Definition at line 76 of file utils.cpp.

    +

    Definition at line 74 of file utils.cpp.

    @@ -340,7 +339,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    Returns
    std::string
    -

    Definition at line 24 of file utils.cpp.

    +

    Definition at line 22 of file utils.cpp.

    @@ -388,7 +387,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    Returns
    std::string
    -

    Definition at line 17 of file utils.cpp.

    +

    Definition at line 15 of file utils.cpp.

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

    Go to the source code of this file.

    @@ -124,7 +125,7 @@ Macros  A prettier assertion function.
      #define __METHOD_NAME__   methodName(__PRETTY_FUNCTION__) - Get the name of the current method/function.
    + Get the name of the current method/function without the return type.
      - - - + + + @@ -168,9 +169,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    @@ -138,9 +139,9 @@ Functions

    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 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.
     
    -

    Get the name of the current method/function.

    +

    Get the name of the current method/function without the return type.

    -

    Definition at line 51 of file utils.hpp.

    +

    Definition at line 52 of file utils.hpp.

    @@ -201,13 +202,13 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    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
    +
    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:41
    +
    #define __METHOD_NAME__
    Get the name of the current method/function without the return type.
    Definition: utils.hpp:52

    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.

    +

    Definition at line 46 of file utils.hpp.

    @@ -230,19 +231,19 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

    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.

    -

    Definition at line 36 of file utils.hpp.

    +

    Definition at line 37 of file utils.hpp.

    Function Documentation

    - -

    ◆ arma_vector_close_to()

    + +

    ◆ close_to()

    - + @@ -279,7 +280,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    Returns
    bool
    -

    Definition at line 62 of file utils.cpp.

    +

    Definition at line 60 of file utils.cpp.

    @@ -347,7 +348,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) -

    Definition at line 43 of file utils.cpp.

    +

    Definition at line 41 of file utils.cpp.

    @@ -386,9 +387,9 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    bool arma_vector_close_to bool close_to ( arma::vec &  a,
    -
    Returns
    bool
    +
    Returns
    bool Success/Fail
    -

    Definition at line 76 of file utils.cpp.

    +

    Definition at line 74 of file utils.cpp.

    @@ -436,7 +437,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    Returns
    std::string
    -

    Definition at line 24 of file utils.cpp.

    +

    Definition at line 22 of file utils.cpp.

    @@ -484,7 +485,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
    Returns
    std::string
    -

    Definition at line 17 of file utils.cpp.

    +

    Definition at line 15 of file utils.cpp.

    diff --git a/docs/utils_8hpp.js b/docs/utils_8hpp.js index 68951df..35bac4e 100644 --- a/docs/utils_8hpp.js +++ b/docs/utils_8hpp.js @@ -3,7 +3,7 @@ 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 ], + [ "close_to", "utils_8hpp.html#ab3e0cf669bddc59bd53998490ffb68b9", null ], [ "m_assert", "utils_8hpp.html#a2cc3a2cdb635bac3c8b02e89d4d6af38", null ], [ "mkpath", "utils_8hpp.html#a6fdd7217b750aff5b6295ece7cbdeffa", null ], [ "scientific_format", "utils_8hpp.html#ad54b96a1074f9df4dc892a41d115b72d", null ], diff --git a/docs/utils_8hpp_source.html b/docs/utils_8hpp_source.html index 1c7052d..23a5d44 100644 --- a/docs/utils_8hpp_source.html +++ b/docs/utils_8hpp_source.html @@ -109,57 +109,58 @@ $(document).ready(function(){initNavTree('utils_8hpp_source.html',''); initResiz
    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
    +
    22#include <sys/stat.h>
    +
    23#include <vector>
    +
    24
    +
    33#ifdef DBG
    +
    34 #define DEBUG(msg) std::cout << __FILE__ << " " << __LINE__ << ": " \
    +
    35 << msg << std::endl
    +
    36#else
    +
    37 #define DEBUG(msg)
    +
    38#endif
    +
    39
    +
    46#define ASSERT(expr, msg) m_assert(expr, #expr, __METHOD_NAME__, __FILE__, \
    +
    47 __LINE__, msg)
    +
    48
    +
    52#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
    53
    -
    64std::string scientific_format(double d, int width=20, int prec=10);
    -
    65
    +
    54
    +
    65std::string scientific_format(double d, int width=20, int prec=10);
    66
    -
    77std::string scientific_format(const std::vector<double>& v,
    -
    78 int width=20,
    -
    79 int prec=10);
    -
    80
    +
    67
    +
    78std::string scientific_format(const std::vector<double>& v,
    +
    79 int width=20,
    +
    80 int prec=10);
    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
    +
    82
    +
    95void m_assert(bool expr,
    +
    96 std::string expr_str,
    +
    97 std::string func,
    +
    98 std::string file,
    +
    99 int line,
    +
    100 std::string msg);
    101
    -
    113bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8);
    -
    114
    +
    102
    +
    114bool close_to(arma::vec &a, arma::vec &b, double tol=1e-8);
    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
    +
    116
    +
    127static inline std::string methodName(const std::string& pretty_function)
    +
    128{
    +
    129 size_t colons = pretty_function.find("::");
    +
    130 size_t begin = pretty_function.substr(0,colons).rfind(" ") + 1;
    +
    131 size_t end = pretty_function.rfind("(") - begin;
    +
    132
    +
    133 return pretty_function.substr(begin,end) + "()";
    +
    134}
    135
    -
    146bool mkpath(std::string path, int mode = 0777);
    -
    147
    -
    148#endif
    -
    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
    -
    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
    -
    bool mkpath(std::string path, int mode=0777)
    Make path given.
    Definition: utils.cpp:76
    -
    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
    +
    136
    +
    147bool mkpath(std::string path, int mode = 0777);
    +
    148
    +
    149#endif
    +
    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:41
    +
    bool mkpath(std::string path, int mode=0777)
    Make path given.
    Definition: utils.cpp:74
    +
    bool 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:60
    +
    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:15
    diff --git a/include/PenningTrap.hpp b/include/PenningTrap.hpp index 9a78784..411b3cc 100644 --- a/include/PenningTrap.hpp +++ b/include/PenningTrap.hpp @@ -18,15 +18,11 @@ #include "Particle.hpp" #include "constants.hpp" #include "typedefs.hpp" +#include "utils.hpp" -#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \ +#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \ initializer(omp_priv = omp_orig) -typedef struct simulation { - sim_arr r_vecs; - sim_arr v_vecs; -} simulation_t; - /** @brief A class that simulates a Penning trap. * * This class simulates a Penning trap. It can take in a number of particles @@ -62,7 +58,7 @@ private: * * @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) + * @param dt The step length (delta time) * * @return vec_3d * */ @@ -78,8 +74,8 @@ public: * */ PenningTrap( double B_0 = T, - std::function V_0 = - [](double t) { return 25. * V / 1000.; }, + std::function V_0 + = [](double t) { return (25. * V) / 1000.; }, double d = 500., double t = 0.); /** @brief Constructor for the PenningTrap class @@ -92,8 +88,8 @@ public: * */ PenningTrap( unsigned int i, double B_0 = T, - std::function V_0 = - [](double t) { return 25. * V / 1000.; }, + std::function V_0 + = [](double t) { return 25. * V / 1000.; }, double d = 500., double t = 0.); /** @brief Constructor for the PenningTrap class @@ -106,10 +102,21 @@ public: * */ PenningTrap( std::vector particles, double B_0 = T, - std::function V_0 = - [](double t) { return 25. * V / 1000.; }, + std::function V_0 + = [](double t) { return 25. * V / 1000.; }, double d = 500., double t = 0.); + /** @brief Give all particles new positions and velocities, and change t + * and V_0. + * + * @param V_0 The tiome dependent applied potential + * @param t The starting time + * */ + void reinitialize( + std::function V_0 + = [](double t) { return 25. * V / 1000.; }, + double t = 0.); + /** @brief Add a particle to the system * * @param particle The particle to add to the Penning trap @@ -155,7 +162,8 @@ public: * */ vec_3d total_force_external(unsigned int i); - /** @brief Calculate the total force on a particle p_i from other particles. + /** @brief Calculate the total force on a particle p_i from other + * particles. * * @param i The index of particle p_i * @@ -192,6 +200,8 @@ public: * @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 simulation_t * */ simulation_t simulate(double time, unsigned int steps, std::string method = "rk4", @@ -206,7 +216,8 @@ public: * @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", + unsigned int steps, + std::string method = "rk4", bool particle_interaction = true); /** @brief Simulate and calculate what fraction of particles are still diff --git a/include/constants.hpp b/include/constants.hpp index 592b48a..06942ee 100644 --- a/include/constants.hpp +++ b/include/constants.hpp @@ -12,10 +12,10 @@ #ifndef __CONST__ #define __CONST__ -#define K_E 138935.333 ///< Coulomb constant. unit: \f$\frac{u(\mu m)^3}{(\mu s)^2 e^2}\f$ +#define K_E 1.38935333*1e5 ///< Coulomb constant. unit: \f$\frac{u(\mu m)^3}{(\mu s)^2 e^2}\f$ -#define T 96.4852558 ///< 1 Tesla. unit: \f$ \frac{u}{(\mu s) e} \f$ +#define T 9.64852558*1e1 ///< 1 Tesla. unit: \f$ \frac{u}{(\mu s) e} \f$ -#define V 96485255.8 ///< 1 Volt. unit: \f$ \frac{u (\mu m)^2}{(\mu s)^2 e} \f$ +#define V 9.64852558*1e7 ///< 1 Volt. unit: \f$ \frac{u (\mu m)^2}{(\mu s)^2 e} \f$ #endif diff --git a/include/typedefs.hpp b/include/typedefs.hpp index f0ceca2..a5154b8 100644 --- a/include/typedefs.hpp +++ b/include/typedefs.hpp @@ -15,8 +15,8 @@ #ifndef __TYPEDEFS__ #define __TYPEDEFS__ -#include #include +#include /** @brief Typedef for the column of the result vector from simulating * particles. @@ -35,4 +35,11 @@ typedef std::vector sim_arr; * */ typedef arma::vec::fixed<3> vec_3d; +/** @brief Typedef for PenningTrap::simulation return value. + * */ +typedef struct simulation { + sim_arr r_vecs; + sim_arr v_vecs; +} simulation_t; + #endif diff --git a/include/utils.hpp b/include/utils.hpp index c9c9485..c8469c9 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include /** @def DEBUG(msg) @@ -46,7 +47,7 @@ __LINE__, msg) /** @def __METHOD_NAME__ - * @brief Get the name of the current method/function. + * @brief Get the name of the current method/function without the return type. * */ #define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__) @@ -110,7 +111,7 @@ void m_assert(bool expr, * * @return bool * */ -bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8); +bool close_to(arma::vec &a, arma::vec &b, double tol=1e-8); /** @brief Takes in the __PRETTY_FUNCTION__ string and removes the return type. @@ -141,7 +142,7 @@ static inline std::string methodName(const std::string& pretty_function) * @param path The path to be created * @param mode The mode/permissions for all the new directories * - * @return bool + * @return bool Success/Fail * */ bool mkpath(std::string path, int mode = 0777); diff --git a/latex/appendix/appendix.tex b/latex/appendix/appendix.tex deleted file mode 100644 index eac7190..0000000 --- a/latex/appendix/appendix.tex +++ /dev/null @@ -1,44 +0,0 @@ -\documentclass[../main.tex]{subfiles} -\graphicspath{{\subfix{../images/}}} - -\begin{document} -\appendix -\section*{Appendix A}\label{sec:appendix_a} -Equations given -\begin{equation}\label{eq:newton_second} - m \ddot{\mathbf{r}} = \sum_{i} \mathbf{F}_{i} -\end{equation} -% - -% -\begin{equation}\label{eq:e_field_point} - \mathbf{E} = k_{e} \sum_{j=1}^{n} q_j \frac{\mathbf{r} - \mathbf{r}_{j}}{|\mathbf{r} - \mathbf{r}_{j}|^{3}} -\end{equation} -% -\begin{equation}\label{eq:e_field_potential} - \mathbf{E} = - \nabla V -\end{equation} - -\section*{Appendix B}\label{sec:appendix_b} -Sum of all forces -\begin{align*} - sum -\end{align*} - -We find the physical coordinates from $x(t) = \text{Re} f(t)$ and $y(t) = \text{Im} f(t)$, where $f(t)$ is given by equation \eqref{eq:general_solution}. - -We can rewrite $f(t)$ using the definition as -\begin{align*} - % f(t) =& A_{+}e^{-i(\omega_{+} t + \phi_{+})} + A_{-}e^{-i(\omega_{-} t + \phi_{-})} \\ - f(t) =& A_{+}(\cos{\omega_{+} t + \phi_{+}} - i \sin{\omega_{+} t + \phi_{+}}) \\ - \numberthis \label{eq:general_solution_trig} - &+ A_{-}(\cos{\omega_{-} t + \phi_{-}} - i \sin{\omega_{-} t + \phi_{-}}) -\end{align*} -% -If we rearrange the right side of equation \eqref{eq:general_solution_trig}, we find the physical coordinates -\begin{align}\label{eq:physical_coord} - x(t) &= A_{+}(\cos{\omega_{+} t + \phi_{+}}) + A_{-}(\cos{\omega_{-} t + \phi_{-}}) \\ - y(t) &= - A_{+}(i \sin{\omega_{+} t + \phi_{+}}) - A_{-}(i \sin{\omega_{-} t + \phi_{-}}) -\end{align} - -\end{document} \ No newline at end of file diff --git a/latex/appendix/appendix_a.tex b/latex/appendix/appendix_a.tex new file mode 100644 index 0000000..ccc0a85 --- /dev/null +++ b/latex/appendix/appendix_a.tex @@ -0,0 +1,29 @@ +\documentclass[../main.tex]{subfiles} +\graphicspath{{\subfix{../images/}}} + +\begin{document} + +\section{Equations of electrodynamics and classical mechanics}\label{sec:appendix_a} +Newton's second law +\begin{equation}\label{eq:newton_second} + m \ddot{\mathbf{r}} = \sum_{i} \mathbf{F}_{i} +\end{equation}% +% +Lorentz force +\begin{equation}\label{eq:lorentz_force} + \mathbf{F} = q \mathbf{E} + q \mathbf{v} \times \mathbf{B}, +\end{equation}% +% +Electric field +\begin{equation}\label{eq:e_field_potential} + \mathbf{E} = - \nabla V +\end{equation} % +% +Electric field at a point $\mathbf{r}$ +\begin{equation}\label{eq:e_field_point} + \mathbf{E} = k_{e} \sum_{j=1}^{n} q_j \frac{\mathbf{r} - \mathbf{r}_{j}}{|\mathbf{r} - \mathbf{r}_{j}|^{3}} +\end{equation} + + + +\end{document} \ No newline at end of file diff --git a/latex/appendix/appendix_b.tex b/latex/appendix/appendix_b.tex new file mode 100644 index 0000000..772f73e --- /dev/null +++ b/latex/appendix/appendix_b.tex @@ -0,0 +1,145 @@ +\documentclass[../main.tex]{subfiles} +\graphicspath{{\subfix{../images/}}} + +\begin{document} +\section{Derivation of equations}\label{sec:appendix_b} +% Problem 1 +\subsection{Equations of motion}\label{sec:eq_motion} % +First, we need to define the velocity of the particle +\begin{align*} + \mathbf{v} \equiv \frac{d \mathbf{r}}{dt} &= \bigg( \frac{dx}{dt}, \frac{dy}{dt}, \frac{dz}{dt} \bigg). +\end{align*} % +We can rewrite the velocity as $\dot{r} = (\dot{x}, \dot{y}, \dot{z})$, and find the cross product +\begin{align*} + q \mathbf{v} \cross \mathbf{B} &= + q \begin{vmatrix} + \hat{e}_{x} & \hat{e}_{y} & \hat{e}_{z} \\ + \dot{x} & \dot{y} & \dot{z} \\ + 0 & 0 & B_{0} + \end{vmatrix} + = q \big( B_{0} \dot{y}, -B_{0} \dot{x}, 0 \big). +\end{align*} % +We are considering an ideal Penning traps, where we define the electric potential as +\begin{align*} + V(x, y, z) &= \frac{V_{0}}{2 d^{2}}(2z^{2} - x^{2} - y^{2}). +\end{align*} % +The relationship between the electric field $\mathbf{E}$ and the electric potential of the field is given by +\begin{align*} + \mathbf{E} &= - \nabla V \\ + &= - \bigg( \frac{dV}{dx}, \frac{dV}{dy} \frac{dV}{dz} \bigg) \\ + &= \frac{V_{0}}{d^{2}} \big( x, y, -2z \big). +\end{align*} % +We can now express the Lorentz force as +\begin{align*} + \mathbf{F} &= q \mathbf{E} + q \mathbf{v} \cross \mathbf{B} \\ + &= \frac{q V_{0}}{d^{2}} \big( x, y, -2z \big) + \big(q B_{0} \dot{y}, -q B_{0} \dot{x}, 0 \big), +\end{align*} % +and insert it into Newtons equation \eqref{eq:newton_second}. We get +\begin{align*} + \ddot{\mathbf{r}} &= \bigg( \frac{q V_{0}}{m d^{2}} x, \frac{q V_{0}}{m d^{2}} y, -\frac{2 q V_{0}}{m d^{2}} z \bigg) + \bigg(\frac{q B_{0}}{m} \dot{y}, -\frac{q B_{0}}{m} \dot{x}, 0 \bigg), +\end{align*} % +which can be written as +\begin{align*} + \ddot{x} &= \frac{q V_{0}}{m d^{2}} x + \frac{q B_{0}}{m} \dot{y}, \\ + \ddot{y} &= \frac{q V_{0}}{m d^{2}} y - \frac{q B_{0}}{m} \dot{x}, \\ + \ddot{z} &= -\frac{2 q V_{0}}{m d^{2}} z. +\end{align*} +If we define +\begin{equation*} + \omega_{0} \equiv \frac{q B_{0}}{m}, \quad \omega_{z}^{2} \equiv \frac{2 q V_{0}}{m d^{2}}, +\end{equation*} +the equations of motion can be written as +\begin{align*} + \ddot{x} &= \frac{1}{2} \omega_{z}^{2} x + \omega_{0} \dot{y}, \\ + \ddot{y} &= \frac{1}{2} \omega_{z}^{2} y - \omega_{0} \dot{x}, \\ + \ddot{z} &= -\omega_{z}^{2} z. \\ +\end{align*} + +\subsection{General solution}\label{sec:eq_general} +We consider the characteristic equation of a second order differential equation \cite{lindstrom:2016:ch10:5}, +\begin{align*} + r^{2} + \omega_{z}^{2} &= 0 \\ + r &= \pm \sqrt{- \omega_{z}^{2}}. +\end{align*} % +The characteristic equation has two complex roots +\begin{equation*} + r_{1} = - i \omega_{z}, \quad r_{2} = i \omega_{z}, +\end{equation*} +which give us solutions in the general form +\begin{equation*} + z = c_{1} e^{i \omega_{z} t} + c_{2} e^{-i \omega_{z} t}. +\end{equation*} +In addition, for a complex number $z = a + ib$, we can define $e^{z} \equiv e^{a} (\cos{b} + i \sin{b})$ \cite{lindstrom:2016:ch3}. We can rewrite the general solution as +\begin{align*} + c_{1} e^{i \omega_{z} t} + c_{2} e^{-i \omega_{z} t} &= c_{1} (\cos{\omega_{z} t} + i \sin{\omega_{z} t}) \\ + & \quad + c_{2} (\cos{\omega_{z} t} - i \sin{\omega_{z} t} \\ + &= E \cos{\omega_{z} t} + i F \sin{\omega_{z} t}. +\end{align*} % +% +\subsection{Complex function}\label{sec:eq_complex} % +In sec. \ref{sec:eq_motion} we found the differential equations for $\ddot{x}$ and $\ddot{y}$. To derive a single differential equation, we introduce the complex function $f(t) = x(t) + iy(t)$, which gives us +\begin{align*} + 0 &= \Big(\ddot{x} - \omega_{0} \dot{y} - \frac{1}{2} \omega_{z}^{2} x \Big) + i \Big(\ddot{y} + \omega_{0} \dot{x} - \frac{1}{2} \omega_{z}^{2} y \Big) \\ + &= \ddot{x} - \omega_{0} \dot{y} - \frac{1}{2} \omega_{z}^{2} x + i\ddot{y} + i\omega_{0} \dot{x} - i \frac{1}{2} \omega_{z}^{2} y \\ + &= \ddot{x} + i\ddot{y} + i\omega_{0} \dot{x} - \omega_{0} \dot{y} - \frac{1}{2} \omega_{z}^{2} x - i \frac{1}{2} \omega_{z}^{2} y. \\ +\end{align*} +Using the definition $i = \sqrt{-1}$, we can rewrite +\begin{equation*} + i \omega_{0} \dot{x} + (-1) \omega_{0} \dot{y} = i \omega_{0} \dot{x} + i^{2} \omega_{0} \dot{y}. +\end{equation*} +This gives us a single differential equation +\begin{align*} + 0 &= \ddot{x} + i\ddot{y} + i\omega_{0} (\dot{x} + i \dot{y}) - \frac{1}{2} \omega_{z}^{2} x - i \frac{1}{2} \omega_{z}^{2} y \\ + &= \ddot{f} + i \omega_{0} \dot{f} - \frac{1}{2} \omega_{z}^{2} f. +\end{align*} +% +\subsection{Physical coordinates}\label{sec:eq_coord} +We can rewrite eq. \eqref{eq:general_solution}, as +\begin{align*} + f(t) &= A_{+}e^{-i(\omega_{+} t + \phi_{+})} + A_{-}e^{-i(\omega_{-} t + \phi_{-})} \\ + &= A_{+}(\cos{(\omega_{+} t + \phi_{+})} - i \sin{(\omega_{+} t + \phi_{+})}) \\ + % \numberthis \label{eq:general_solution_trig} + & \quad + A_{-}(\cos{(\omega_{-} t + \phi_{-})} - i \sin{(\omega_{-} t + \phi_{-})}). +\end{align*} % +% +\subsection{Upper and lower bounds}\label{sec:upper_lower_bound} +To obtain the upper and lower bounds of the particle's distance from the origin, we first find an expression for the second norm (?) defined as $|f(t)| = \sqrt{(x(t))^{2} + (y(t))^{2}}$. +\begin{align*} + (x(t))^{2} &= \big( A_{+}\cos(\omega_{+} t + \phi_{+}) + A_{-}\cos(\omega_{-} t + \phi_{-}) \big)^{2} \\ + &= A_{+}^{2} \cos^{2}(\omega_{+} t + \phi_{+}) \\ + & \quad + 2 A_{+}A_{-} \cos(\omega_{+} t + \phi_{+})\cos(\omega_{-} t + \phi_{-}) \\ + & \quad + A_{-}^{2}\cos^{2}(\omega_{-} t + \phi_{-}), \\ +\end{align*} % +\begin{align*} + (y(t))^{2} &= \big( - A_{+} \sin(\omega_{+} t + \phi_{+}) - A_{-} \sin(\omega_{-} t + \phi_{-}) \big)^{2} \\ + &= A_{+}^{2} \sin^{2}(\omega_{+} t + \phi_{+}) \\ + & \quad + 2 A_{+}A_{-} \sin(\omega_{+} t + \phi_{+})\sin(\omega_{-} t + \phi_{-}) \\ + & \quad + A_{-}^{2} \sin^{2}(\omega_{-} t + \phi_{-}). +\end{align*} % +We insert these expressions, and find +\begin{align*} + |f(t)| &= \sqrt{(x(t))^{2} + (y(t))^{2}} \\ + &= \sqrt{A_{+}^{2} + 2 A_{+} A_{-} \cos^{2}(\alpha) + A_{-}^{2}}, +\end{align*} % +where $\alpha = (\omega_{+} - \omega_{-}) t +( \phi_{+} - \phi_{-})$. If we set $\alpha = 0$ we get $\cos(0) = 1$, and obtain the upper bound +\begin{align*} + R_{+} &= \sqrt{A_{+}^{2} + 2 A_{+} A_{-} + A_{-}^{2}} \\ + &= \sqrt{(A_{+} + A_{-})^{2}} \\ + &= A_{+} + A_{-}. +\end{align*} +If $\alpha = \pi$ we get $\cos(\pi) = -1$, and find the lower bound +\begin{align*} + R_{-} &= \sqrt{A_{+}^{2} - 2 A_{+} A_{-} + A_{-}^{2}} \\ + &= \sqrt{(A_{+} - A_{-})^{2}} \\ + &= |A_{+} - A_{-}|. +\end{align*} % +% +\subsection{Bounded solution}\label{sec:bounded_solution} + + +\end{document} + +% \begin{align*} +% \omega_{+} - \omega_{-} &= \frac{\omega_{0} + \sqrt{\omega_{0}^{2} - 2 \omega_{z}^{2}}}{2} - \frac{\omega_{0} - \sqrt{\omega_{0}^{2} - 2 \omega_{z}^{2}}}{2} \\ +% &= +% \end{align*} \ No newline at end of file diff --git a/latex/appendix/appendix_c.tex b/latex/appendix/appendix_c.tex new file mode 100644 index 0000000..0a3edd7 --- /dev/null +++ b/latex/appendix/appendix_c.tex @@ -0,0 +1,21 @@ +\documentclass[../main.tex]{subfiles} +\graphicspath{{\subfix{../images/}}} + +\begin{document} + +\section{Numbers and units}\label{sec:appendix_c} +\begin{table}[H] + \centering + \begin{tabular}[c]{lll} + Constant & Value & Unit \\ + \hline + $k_{e}$ (Coulomb) & $1.38935333 \cross 10^{5}$ & $\frac{u (\mu m)^{3}}{(\mu s)^{2} e^{2}}$ \\ + T (Tesla) & $9.64852558 \cross 10^{1}$ & $\frac{u}{(\mu s) e}$ \\ + V (Volt) & $9.64852558 \cross 10^{7}$ & $\frac{u (\mu m)^{2}}{(\mu s)^{2} e}$ \\ + \hline + \end{tabular} + \caption{Value of the Coulomb constant ($k_{e}$), and the SI units for magnetic field strength ($T$) and electric potential ($V$). The base units are given by length in micrometre ($\mu m$), time in microseconds ($\mu s$), mass in ($u$), and charge in elementary charge ($e$).} + \label{tab:constants} +\end{table} + +\end{document} \ No newline at end of file diff --git a/latex/images/3d_plot.pdf b/latex/images/3d_plot.pdf index 98a1825..4a25654 100644 Binary files a/latex/images/3d_plot.pdf and b/latex/images/3d_plot.pdf differ diff --git a/latex/images/particles_left.pdf b/latex/images/particles_left.pdf index b158c7e..ec3ef72 100644 Binary files a/latex/images/particles_left.pdf and b/latex/images/particles_left.pdf differ diff --git a/latex/images/phase_space_2_particles_x.pdf b/latex/images/phase_space_2_particles_x.pdf index a344069..97da31f 100644 Binary files a/latex/images/phase_space_2_particles_x.pdf and b/latex/images/phase_space_2_particles_x.pdf differ diff --git a/latex/images/phase_space_2_particles_z.pdf b/latex/images/phase_space_2_particles_z.pdf index daf1f69..e4e9421 100644 Binary files a/latex/images/phase_space_2_particles_z.pdf and b/latex/images/phase_space_2_particles_z.pdf differ diff --git a/latex/images/plot_2_particles_xy.pdf b/latex/images/plot_2_particles_xy.pdf index 5203fbc..632664e 100644 Binary files a/latex/images/plot_2_particles_xy.pdf and b/latex/images/plot_2_particles_xy.pdf differ diff --git a/latex/images/relative_error.pdf b/latex/images/relative_error.pdf new file mode 100644 index 0000000..0c66768 Binary files /dev/null and b/latex/images/relative_error.pdf differ diff --git a/latex/main.pdf b/latex/main.pdf new file mode 100644 index 0000000..4174abc Binary files /dev/null and b/latex/main.pdf differ diff --git a/latex/main.tex b/latex/main.tex index f9c63f7..e7ab021 100644 --- a/latex/main.tex +++ b/latex/main.tex @@ -10,6 +10,7 @@ % Allows special characters (including æøå) \usepackage[utf8]{inputenc} \usepackage{fontawesome} +% \usepackage{tabularx} % \usepackage[english]{babel} %% Note that you may need to download some of these packages manually, it depends on your setup. @@ -24,12 +25,12 @@ \usepackage{listings} % display code \usepackage{subfigure} % imports a lot of cool and useful figure commands % \usepackage{float} -% \usepackage[section]{placeins} +%\usepackage[section]{placeins} \usepackage{algorithm} \usepackage[noend]{algpseudocode} \usepackage{subfigure} \usepackage{tikz} -% \usetikzlibrary{quantikz2} +\usetikzlibrary{quantikz2} % defines the color of hyperref objects % Blending two colors: blue!80!black = 80% blue and 20% black \hypersetup{ % this is just my personal choice, feel free to change things @@ -63,9 +64,6 @@ % Introduction \subfile{sections/introduction} -% Theory -\subfile{sections/theory} - % Methods \subfile{sections/methods} @@ -76,7 +74,10 @@ \subfile{sections/conclusion} -\subfile{appendix/appendix} +\appendix +\subfile{appendix/appendix_a} +\subfile{appendix/appendix_b} +\subfile{appendix/appendix_c} \onecolumngrid diff --git a/latex/references/references.bib b/latex/references/references.bib index 6a49b46..1ada635 100644 --- a/latex/references/references.bib +++ b/latex/references/references.bib @@ -1,87 +1,104 @@ @book{vogel:2018, - author = {Manuel Vogel}, - title = {Particle Confinement in Penning Traps}, - subtitle = {An Introduction}, - publisher = {Springer Cham}, - year = {2018}, - edition = {1}, - abstract = {An introduction to the field of Penning traps and related experimental techniques. The book is motivated by the observation that often a vast number of different resources have to be explored to gain a good overview of Penning trap principles. This is especially true for students who experience additional difficulty due to the different styles of presentation and notation.} + author = {Manuel Vogel}, + title = {Particle Confinement in Penning Traps}, + subtitle = {An Introduction}, + publisher = {Springer Cham}, + year = {2018}, + edition = {1}, + abstract = {An introduction to the field of Penning traps and related experimental techniques. The book is motivated by the observation that often a vast number of different resources have to be explored to gain a good overview of Penning trap principles. This is especially true for students who experience additional difficulty due to the different styles of presentation and notation.} } @inbook{vogel:2018:ch5, - author = {Manuel Vogel}, - title = {Particle Confinement in Penning Traps}, - subtitle = {An Introduction}, - publisher = {Springer Cham}, - year = {2018}, - edition = {1}, - pages = {45--50} + author = {Manuel Vogel}, + title = {Particle Confinement in Penning Traps}, + subtitle = {An Introduction}, + publisher = {Springer Cham}, + year = {2018}, + edition = {1}, + pages = {45--50} } @inbook{vogel:2018:ch1, - author = {Manuel Vogel}, - title = {Particle Confinement in Penning Traps}, - subtitle = {An Introduction}, - publisher = {Springer Cham}, - year = {2018}, - edition = {1--6} + author = {Manuel Vogel}, + title = {Particle Confinement in Penning Traps}, + subtitle = {An Introduction}, + publisher = {Springer Cham}, + year = {2018}, + edition ={1--6} } -@article{hunter:2007, - author = {Hunter, J. D.}, - title = {Matplotlib: A 2D graphics environment}, - journal = {Computing in Science \& Engineering}, - volume = {9}, - number = {3}, - pages = {90--95}, - abstract = {Matplotlib is a 2D graphics package used for Python for - application development, interactive scripting, and publication-quality - image generation across user interfaces and operating systems.}, +@article{hunter:2007:matplotlib, + author = {Hunter, J. D.}, + title = {Matplotlib: A 2D graphics environment}, + journal = {Computing in Science \& Engineering}, + volume = {9}, + number = {3}, + pages = {90--95}, + abstract = {Matplotlib is a 2D graphics package used for Python for + application development, interactive scripting, and publication-quality + image generation across user interfaces and operating systems.}, publisher = {IEEE COMPUTER SOC}, - doi = {10.1109/MCSE.2007.55}, - year = 2007 + doi = {10.1109/MCSE.2007.55}, + year = 2007 } @inbook{lindstrom:2016:ch3, - author = {Tom Lindstrøm}, - title = {Kalkulus}, - publisher = {Universitetsforlaget}, - year = {2016}, - edition = {4}, - pages = {133--137} + author = {Tom Lindstrøm}, + title = {Kalkulus}, + publisher = {Universitetsforlaget}, + year = {2016}, + edition = {4}, + pages = {133--137} } @inbook{lindstrom:2016:ch10:5, - author = {Tom Lindstrøm}, - title = {Kalkulus}, - publisher = {Universitetsforlaget}, - year = {2016}, - edition = {4}, - pages = {589--606} + author = {Tom Lindstrøm}, + title = {Kalkulus}, + publisher = {Universitetsforlaget}, + year = {2016}, + edition = {4}, + pages = {589--606} } -@article{britannica:2023:matter, - author = {The Editors of Encyclopaedia Britannica}, - title = {matter}, - year = {2023}, - url = {https://www.britannica.com/science/matter}, - urldate = {2023-10-17} +@online{britannica:2023:matter, + author = {The Editors of Encyclopaedia Britannica}, + title = {matter}, + year = {2023}, + url = {https://www.britannica.com/science/matter}, + urldate = {2023-10-17} } @inbook{gjevik:2014:appendix, - author = {Bjørn Gjevik and Morten Wang Fagerland}, - title = {Feltteori og vektoranalyse}, - publisher = {Farleia Forlag}, - year = {2018}, - pages = {162--163} + author = {Bjørn Gjevik and Morten Wang Fagerland}, + title = {Feltteori og vektoranalyse}, + publisher = {Farleia Forlag}, + year = {2018}, + pages = {162--163} } +@article{waskom:2021:seaborn, + author = {Michael L. Waskom}, + title = {seaborn: statistical data visualization}, + journal = {Journal of Open Source Software}, + volume = {6}, + number = {60}, + publisher = {The Open Journal}, + year = {2021}, + doi = {10.21105/joss.03021}, + url = {https://doi.org/10.21105/joss.03021}, + pages = {3021} + } -@article{rk4_method, - author = "Morten Hjorth-Jensen", - title = "Computational Physics, Lecture Notes Fall 2015", - journal = "Department of Physics, University of Oslo", - year = "2015", - chapter = "8.4", - pages = "250--252", +@online{openmp:2018, + author = {OpenMP}, + title = {OpenMP Application Programming Interface}, + year = {2018}, + url = {https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf}, + urldate = {2023-10-22} } + +@misc{penning:fig, + key = , + url = {https://www.med.physik.uni-muenchen.de/research/nuclear-science/nuclear-masses/mlltrap/layout/traps/index.html} + note = {Configuration figure a} +} \ No newline at end of file diff --git a/latex/sections/introduction.tex b/latex/sections/introduction.tex index 567af9f..0ef8ecb 100644 --- a/latex/sections/introduction.tex +++ b/latex/sections/introduction.tex @@ -2,12 +2,12 @@ \graphicspath{{\subfix{../images/}}} \begin{document} - +% \section{Introduction} We are surrounded by matter, which are made up of elementary particles. In the field of physics we want to understand the properties of these particles, measure their physical quantities, not to mention explain the origin of mass \cite{britannica:2023:matter}. However, to study a particle, it is necessary isolate and contain it over time. The Penning trap is a device, able to confine charged particles for a period of time. This concept was evolved from F. M. Penning's implementation of magnetic fiels to a vaccum gauge, and J. R. Pierce's work with electron beams, and put into practice by Hans Dehmelt. In 1973 Dehmelt and his group of researchers were able to confine a particle and store it over several months \cite{vogel:2018:ch1}. In practice, a Penning trap is not easy to obtain, and an experiment is both time consuming and expensive. A numerical approach, allow us to study the effects of the Penning trap on a charged particle, without the cost. We can use ordinary differential equations to model the particle's movement, confined within an Penning trap. Our focus will be on an ideal Penning trap, where an electrostatic field confines the particle in z-direction, and a magnetic field confines it in the radial direction. We will use numerical methods to model a single particle, and study the particle motion in radial direction. In addition, we will model a system of particles, and study their motion both with and without particle interaction. - +% \end{document} \ No newline at end of file diff --git a/latex/sections/methods.pdf b/latex/sections/methods.pdf new file mode 100644 index 0000000..abf8b57 Binary files /dev/null and b/latex/sections/methods.pdf differ diff --git a/latex/sections/methods.tex b/latex/sections/methods.tex index 125bd37..ad8c06f 100644 --- a/latex/sections/methods.tex +++ b/latex/sections/methods.tex @@ -3,39 +3,100 @@ \begin{document} \section{Methods} +% Problem 1 +When we study the Penning traps effect on a particle with a charge $q$, we need to consider the forces acting on the particle. We can use Newton's second law \eqref{eq:newton_second} to determine the position of a particle as a function of time. In addition, we introduce the Lorentz force \eqref{eq:lorentz_force}, which describes the force on the particle. The position can be described by % +% +\begin{equation}\label{eq:newton_lorentz} + m \ddot{\mathbf{r}} = (q \mathbf{E} + q \mathbf{v} \times \mathbf{B}). +\end{equation} +% +Using eq. \eqref{eq:newton_lorentz} we derive the differential equations in sec. \ref{sec:eq_motion}, and can rewrite them as +\begin{align} + \label{eq:motion_x} + \ddot{x} - \omega_{0} \dot{y} - \frac{1}{2} \omega_{z}^{2} x &= 0, \\ + \label{eq:motion_y} + \ddot{y} - \omega_{0} \dot{x} - \frac{1}{2} \omega_{z}^{2} y &= 0, \\ + \label{eq:motion_z} + \ddot{z} + \omega_{z}^{2} z &= 0, +\end{align} % +% +We find the general solution for eq. \eqref{eq:motion_z} +\begin{equation}\label{eq:eq_general} + z(t) = c_{1} e^{i \omega_{z} t} + c_{2} e^{-i \omega_{z} t}, +\end{equation} % +derived in sec. \ref{sec:eq_general}. Continuing, we will use a Calcium ion with a single positive charge. That is, we assume the charge of the particle is $q > 0$. + +% Problem 2 +Since eq. \eqref{eq:motion_x} and eq. \eqref{eq:motion_y} are coupled, we want to rewrite them as a single differential equation. We derive this in sec. \ref{sec:eq_complex}, and the resulting equation is given by +\begin{equation}\label{eq:single_differential} + \ddot{f} + i \omega_{0} \dot{f} - \frac{1}{2} \omega_{z}^{2} f = 0. +\end{equation} + +% Problem 3 +Eq. \eqref{eq:single_differential} has a general solution given by +\begin{equation}\label{eq:general_solution} + f(t) = A_{+}e^{-i(\omega_{+} t + \phi_{+})} + A_{-}e^{-i(\omega_{-} t + \phi_{-})}. +\end{equation} % +The amplitude $A_{+}$ and $A_{-}$ are positive, the phases $\phi_{+}$ and $\phi_{-}$ are constant, and the rate is given by +\begin{equation*} + \omega_{\pm} = \frac{\omega_{0} \pm \sqrt{\omega_{0}^{2} - 2 \omega_{z}^{2}}}{2}. +\end{equation*} +We find the physical coordinates at a given time $t$ using +\begin{equation*} + x(t) = \text{Re}f(t), \quad y(t) = \text{Im}f(t), +\end{equation*} % +and eq. \eqref{eq:general_solution}. We can rearrange the right hand side of the derived expression in \ref{sec:eq_coord}, and find the physical coordinates +\begin{align}\label{eq:physical_coord} + x(t) &= A_{+} \cos(\omega_{+} t + \phi_{+}) + A_{-} \cos(\omega_{-} t + \phi_{-}) \\ + y(t) &= - A_{+} \sin(\omega_{+} t + \phi_{+}) - A_{-} \sin(\omega_{-} t + \phi_{-}) +\end{align} % +% Problem 4 +However, to obtain a bound on the particle's movement in the radial direction, we have to ensure that +\begin{align*} + |f(t)| &= \sqrt{(x(t))^{2} + (y(t))^{2}}. \\ +\end{align*} % +When $t \rightarrow \infty$, the upper and lower limits are +\begin{align} + R_{+} &= A_{+} + A_{-} \\ + R_{-} &= |A_{+} - A_{-}|, +\end{align} +derived in sec. \ref{sec:bounded_solution}. + +% Problem 3 +To obtain the bounded solution, we need to consider the expression +\begin{equation*} + \alpha = (\omega_{+} - \omega_{-}) t +( \phi_{+} - \phi_{-}). +\end{equation*} +When $t \rightarrow \infty$ the constant phases will not affect the expression, we obtain a bounded solution if we consider the rate such that $|f(t)| < \infty$. That is, we need $\omega_{0}^{2} - 2 \omega_{z}^{2}$ in eq. \eqref{eq:angular_rate} to be real. +\begin{align*} + \omega_{0}^{2} - 2 \omega_{z}^{2} = 0, \quad \omega_{0} > 2 \omega_{z} +\end{align*} +\begin{equation}\label{eq:angular_rate} + \omega_{\pm} = \frac{\omega_{0} \pm \sqrt{\omega_{0}^{2} - 2 \omega_{z}^{2}}}{2} +\end{equation} + +We find the solution +Physical properties given by newtons second law \eqref{eq:newton_second} + +The particle moves and its position can be determined using newton. where the electric field + + + -\subsection{Units and constants} -Before continuing, we need to define the units we'll be working with. -Since we are working with particles, we need small units to work with so the -numbers we are working with aren't so small that they could potentially lead -to large round-off errors in our simulation. The units that we will use are listed in Table~\ref{tab:units}. \begin{table}[H] - \begin{center} + \centering \begin{tabular}[c]{lll} - Dimension & Unit & Symbol \\ + Constant & Value & \\ \hline - Length & micrometer & $\mu m$ \\ - Time & microseconds & $\mu s$ \\ - Mass & atomic mass unit & $u$ \\ - Charge & the elementary charge & $e$ \\ + $B_{0}$ & $1.00 T$ & $9.65 \cross 10^{1} \frac{u}{(\mu s) e}$ \\ + $V_{0}$ & $25.0 mV$ & $2.41 \cross 10^{6} \frac{u (\mu m)^{2}}{(\mu s)^{2} e}$ \\ + $d$ & $500 \ \mu m$ & \\ \hline \end{tabular} - \end{center} - \caption{The set of units we'll be working with.}\label{tab:units} + \caption{Default configuration of the Penning trap, where the value of T and V can be found in table \ref{tab:constants}.} + \label{tab:penning_config} \end{table} -With these base units, we get -\begin{equation} - k_e = 1.3893533 \cdot 10^5 \frac{u(\mu m)^3}{(\mu s)^2 e}, -\end{equation} -and we get that the unit for magnetic field strength (Tesla, $T$) and electric potential (Volt, $V$) are -\begin{equation} - \begin{split} - T &= 9.64852558 \cdot 10^1 \frac{u}{(\mu s) e} \\ - V &= 9.64852558 \cdot 10^7 \frac{u (\mu m)^2}{(\mu s)^2 e}. \\ - \end{split} - \label{eq:} -\end{equation} \subsection{Dealing with a multi--particle system} @@ -230,7 +291,6 @@ and would reduce the required amount of loops down to 4. \subsection{Relative error and error convergance rate} \subsection{Tools} -We used matplotlib +The numerical methods implemented in C++, are parallelized using OpenMP \cite{openmp:2018}. We used the Python library matplotlib \cite{hunter:2007:matplotlib} to produce all the plots, and seaborn \cite{waskom:2021:seaborn} to set the theme in the figures. -%\biblio \end{document} diff --git a/latex/sections/results.tex b/latex/sections/results.tex index c48a6b3..9437367 100644 --- a/latex/sections/results.tex +++ b/latex/sections/results.tex @@ -4,7 +4,86 @@ \begin{document} \section{Results and Discussion} -From equation \eqref{eq:general_solution} we can find +% Single particle +We simulated the movement of particles confined in a Penning trap. All simulations used the initial conditions for particle 1 and 2 given in table \ref{tab:initial_condition_particles}. -Problem 9: we have to deal with $|\mathbf{r}| = d$ +First we simulated a single particle for $50 \mu s$, approximating the particle's motion using the RK4 method. In addition we compared the motion of particle 1 with the analytical solution in figure \ref{fig:single_particle}. What we see is a complete overlap of the analytical solution completely overlap the approximated, suggest that the simulation result is good. +% Add something about why the simulated result is good, cos(wt) when w is +% +\begin{table}[H] + \centering + \begin{tabular}[c]{lll} + Particle & Position & Velocity \\ + \hline + $p_{1}$ & $(20, 0, 20) \mu m$ & $(0, 25, 0) \mu m/ \mu s$ \\ + $p_{2}$ & $(25, 25, 0) \mu m$ & $(0, 40, 5) \mu m/ \mu s$ \\ + \hline + \end{tabular} + \caption{Initial position and velocity of particle 1 ($p_{1}$) particle 2 ($p_{2}$), where the analytical solution is given by $z(t) = z_{0} \cos (\omega_{z} t)$} + \label{tab:initial_condition_particles} +\end{table} +\begin{figure}[H] + \centering + \includegraphics[width=\linewidth]{images/single_particle.pdf} + \caption{A single particle in the Penning trap, approximated and analytical motion in z-direction.} + \label{fig:single_particle} +\end{figure} +% Add equations of motion for particle with interaction eq. (18, 19, 20) +% Multiple particles +% Add initial condition of Penning trap +We will now consider the Penning trap with initial conditions given in table \ref{tab:initial_condition_penning}, and simulate using one or two particles. In addition, we simulate two particles both with and without interactions, the result is found in figure \ref{fig:two_particles}. When we add interaction between the particles, they both still follow the same inherent path. However, we observe a small shift in both particle's movement. +\begin{table}[H] + \centering + \begin{tabular}{lll} + $B_0$ & $V_{0}$ & $d$ \\ + \hline + \end{tabular} + \caption{Caption} + \label{tab:initial_condition_penning} +\end{table} +% +\begin{figure} + \centering + \includegraphics[width=\linewidth]{images/plot_2_particles_xy.pdf} + \caption{Movement of two particles in the xy-plane. $\hat{p}_{1}$ and $\hat{p}_{2}$ include particle interaction, whereas $p_{1}$ and $p_{2}$ does not include particle interaction.} + \label{fig:two_particles} +\end{figure} +% Phase space plot +When we simulate two particles, we can see the effect of interaction between the particles in the xy-plane in fig. \ref{fig:phase_space_2x} and in the z-direction in fig. \ref{fig:phase_space_2z}. What we observe is a very small shift in position for particle 1 in x-direction, whereas particle 2 does not have a visible shift. In the z-direction, however, the oscillation of particle 2 experience a greater shift. Particle 2 experience the force of particle 1 such that particle 2 moves larger distance. +% +\begin{figure} + \centering + \includegraphics[width=\linewidth]{images/phase_space_2_particles_x.pdf} + \caption{Phase space plot of two particles in x-direction.} + \label{fig:phase_space_2x} +\end{figure} +% +\begin{figure} + \centering + \includegraphics[width=\linewidth]{images/phase_space_2_particles_z.pdf} + \caption{Phase space plot of two particles in z-direction.} + \label{fig:phase_space_2z} +\end{figure} + +\begin{figure} + \centering + \includegraphics[width=\linewidth]{images/3d_plot.pdf} + \caption{3D plot of particles-} + \label{fig:3d_particles} +\end{figure} + +\begin{figure} + \centering + \includegraphics[width=\linewidth]{images/phase_space_2_particles.pdf} + \caption{Phase space plot of two particles.} + \label{fig:phase_space_2} +\end{figure} + + +\begin{figure} + \centering + \includegraphics[width=\linewidth]{images/particles_left.pdf} + \caption{Fraction of particles left in the Penning trap, with a given amplitude $f$.} + \label{fig:particles_left} +\end{figure} \end{document} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..db5d81e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +matplotlib +numpy diff --git a/src/Makefile b/src/Makefile index f678e43..3718e50 100644 --- a/src/Makefile +++ b/src/Makefile @@ -21,7 +21,7 @@ endif PROFILE ?= 0 ifeq ($(PROFILE), 1) - PROFFLAG=-pg + PROFFLAG=-pg -fno-inline-functions else PROFFLAG= endif @@ -30,6 +30,16 @@ endif all: test_suite main +instrument: + scorep $(CC) -c PenningTrap.cpp -o PenningTrap.o $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP) + scorep $(CC) -c Particle.cpp -o Particle.o $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP) + scorep $(CC) -c utils.cpp -o utils.o $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP) + scorep $(CC) -c main.cpp -o main.o $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP) + scorep $(CC) $(LIBOBJS) $(CLASSOBJS) main.o -o main $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP) + + + + # Rules for executables main: main.o $(LIBOBJS) $(CLASSOBJS) $(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP) diff --git a/src/Particle.cpp b/src/Particle.cpp index 2caad68..374812f 100644 --- a/src/Particle.cpp +++ b/src/Particle.cpp @@ -13,8 +13,8 @@ #include "Particle.hpp" Particle::Particle(double q, double m, - arma::vec::fixed<3> r_vec, - arma::vec::fixed<3> v_vec) + vec_3d r_vec, + vec_3d v_vec) { // Giving the particle its properties this->q = q; diff --git a/src/PenningTrap.cpp b/src/PenningTrap.cpp index d5a3b16..af4b19e 100644 --- a/src/PenningTrap.cpp +++ b/src/PenningTrap.cpp @@ -11,9 +11,10 @@ * */ #include "PenningTrap.hpp" -#include "constants.hpp" #include "typedefs.hpp" -#include "utils.hpp" +#include +#include +#include PenningTrap::PenningTrap(double B_0, std::function V_0, double d, double t) @@ -28,11 +29,9 @@ 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)); + this->particles.push_back(Particle(1., 40., vec_3d(vec_3d().randn() * .1 * this->d), + vec_3d(vec_3d().randn() * .1 * this->d))); } } @@ -43,6 +42,16 @@ PenningTrap::PenningTrap(std::vector particles, double B_0, this->particles = particles; } +void PenningTrap::reinitialize(std::function V_0, double t) +{ + this->V_0 = V_0; + this->t = t; + + for (size_t i = 0; i < this->particles.size(); i++) { + this->particles[i].r_vec = vec_3d().randn() * .1 * this->d; + } +} + vec_3d PenningTrap::v_func(unsigned int i, unsigned int j, double dt) { switch (i) { @@ -53,8 +62,9 @@ vec_3d PenningTrap::v_func(unsigned int i, unsigned int j, double dt) case 2: return dt * this->k_v[2][j]; case 3: - return (dt / 6.) * (this->k_v[0][j] + 2. * this->k_v[1][j] + - 2. * this->k_v[2][j] + this->k_v[3][j]); + return vec_3d((dt / 6.) + * (this->k_v[0][j] + 2. * this->k_v[1][j] + + 2. * this->k_v[2][j] + this->k_v[3][j])); default: std::cout << "Not valid!" << std::endl; abort(); @@ -71,8 +81,9 @@ vec_3d PenningTrap::r_func(unsigned int i, unsigned int j, double dt) case 2: return dt * this->k_r[2][j]; case 3: - return (dt / 6.) * (this->k_r[0][j] + 2. * this->k_r[1][j] + - 2. * this->k_r[2][j] + this->k_r[3][j]); + return vec_3d((dt / 6.) + * (this->k_r[0][j] + 2. * this->k_r[1][j] + + 2. * this->k_r[2][j] + this->k_r[3][j])); default: std::cout << "Not valid!" << std::endl; abort(); @@ -87,9 +98,8 @@ void PenningTrap::add_particle(Particle particle) 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; + return vec_3d((this->V_0(this->t) / (this->d * this->d)) * r); } vec_3d PenningTrap::external_B_field(vec_3d r) @@ -99,51 +109,48 @@ vec_3d PenningTrap::external_B_field(vec_3d r) 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; + vec_3d res = this->particles[i].r_vec - this->particles[j].r_vec; // Get the distance between the particles double norm = arma::norm(res, 2); - return vec_3d(res * p_j.q / (norm * norm * norm)); + return vec_3d((this->particles[j].q / (norm * norm * norm)) * res); } vec_3d PenningTrap::total_force_external(unsigned int i) { - Particle p = this->particles[i]; + Particle *p = &this->particles[i]; - if (arma::norm(p.r_vec) > this->d) { + 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; + return vec_3d( + p->q + * (this->external_E_field(p->r_vec) + + arma::cross(p->v_vec, this->external_B_field(p->r_vec)))); } 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); + if (i != j) + res += this->force_on_particle(i, j); } - return vec_3d(res * K_E * (p.q / p.m)); + return vec_3d(res * K_E * (this->particles[i].q)); } vec_3d PenningTrap::total_force(unsigned int i) { - return this->total_force_external(i) - this->total_force_particles(i); + if (arma::norm(this->particles[i].r_vec) > this->d) { + return vec_3d{0., 0., 0.}; + } + return vec_3d(this->total_force_external(i) + - this->total_force_particles(i)); } void PenningTrap::evolve_RK4(double dt, bool particle_interaction) @@ -152,32 +159,35 @@ 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; - } + vec_3d (PenningTrap::*force)(unsigned int) + = particle_interaction ? &PenningTrap::total_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)); + // Allocating takes a long time, so reuse sim_arr if possible + if (this->k_v.size() != 4 || this->k_r.size() != 4 + || this->k_v[0].size() != size || this->k_r[0].size() != size) { + this->k_v = sim_arr(4, sim_cols(size)); + this->k_r = sim_arr(4, sim_cols(size)); + } + // Each k_{i+1} is dependent on k_i, so outer loop is not parallelizable for (size_t i = 0; i < 4; i++) { + // Inner loop is able to be parallelized #pragma omp parallel for - for (size_t j = 0; j < this->particles.size(); j++) { + for (size_t j = 0; j < 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); + tmp_particles[j].v_vec + = original_particles[j].v_vec + this->v_func(i, j, dt); + tmp_particles[j].r_vec + = original_particles[j].r_vec + this->r_func(i, j, dt); } - this->particles.swap(tmp_particles); + this->particles = tmp_particles; } + this->t += dt; } @@ -187,19 +197,19 @@ void PenningTrap::evolve_forward_euler(double dt, bool particle_interaction) vec_3d force_res[size]; Particle *p; - vec_3d (PenningTrap::*force)(unsigned int); - if (particle_interaction) { - force = &PenningTrap::total_force; - } - else { - force = &PenningTrap::total_force_external; - } + vec_3d (PenningTrap::*force)(unsigned int) + = particle_interaction ? &PenningTrap::total_force + : &PenningTrap::total_force_external; + // Calculating the force for each particle is independent and therefore + // a good candidate for parallel execution #pragma omp parallel for for (size_t i = 0; i < size; i++) { force_res[i] = (this->*force)(i); } + // Updating the particles is also independent, so we can parallelize + // this as well #pragma omp parallel for private(p) for (size_t i = 0; i < size; i++) { p = &this->particles[i]; @@ -217,7 +227,7 @@ simulation_t PenningTrap::simulate(double time, unsigned int steps, double dt = time / (double)steps; unsigned int size = this->particles.size(); - // sim_arr res(this->particles.size(), sim_cols(steps)); + simulation_t res{sim_arr(size, sim_cols(steps)), sim_arr(size, sim_cols(steps))}; @@ -253,27 +263,31 @@ void PenningTrap::write_simulation_to_dir(std::string path, double time, path += '/'; } if (mkpath(path, 0777) != 0) { - std::cout << "Hello" << std::endl; - return; + std::cout << "Failed to make path" << std::endl; + abort(); } - simulation_t res = - this->simulate(time, steps, method, particle_interaction); + simulation_t res + = this->simulate(time, steps, method, particle_interaction); std::ofstream ofile; + // Writing each particle to its own file is independent and can be run in + // parallel. #pragma omp parallel for private(ofile) for (size_t i = 0; i < this->particles.size(); i++) { ofile.open(path + "particle_" + std::to_string(i) + "_r.txt"); for (vec_3d &vec : res.r_vecs[i]) { - ofile << vec(0) << "," << vec(1) << "," << vec(2) << "\n"; + ofile << scientific_format(vec(0), 10, 8) << ',' + << scientific_format(vec(1), 10, 8) << ',' + << scientific_format(vec(2), 10, 8) << '\n'; } ofile.close(); ofile.open(path + "particle_" + std::to_string(i) + "_v.txt"); for (vec_3d &vec : res.v_vecs[i]) { - ofile << scientific_format(vec(0), 10, 8) << "," - << scientific_format(vec(1), 8, 10) << "," - << scientific_format(vec(2), 8, 10) << "\n"; + ofile << scientific_format(vec(0), 10, 8) << ',' + << scientific_format(vec(1), 10, 8) << ',' + << scientific_format(vec(2), 10, 8) << '\n'; } ofile.close(); } @@ -283,26 +297,33 @@ double PenningTrap::fraction_of_particles_left(double time, unsigned int steps, std::string method, bool particle_interaction) { - simulation_t res = - this->simulate(time, steps, method, particle_interaction); + double dt = time / (double)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++) { + (this->*func)(dt, particle_interaction); + } int particles_left = 0; - for (Particle p : this->particles) { - if (arma::norm(p.r_vec) < this->d) { + // A reduction is perfect here + #pragma omp parallel for reduction(+:particles_left) + for (size_t i=0; i < this->particles.size(); i++) { + if (arma::norm(this->particles[i].r_vec) < this->d) { particles_left++; } } return (double)particles_left / (double)this->particles.size(); } - -vec_3d PenningTrap::get_r(int i) -{ - return this->particles[i].r_vec; -} - -double PenningTrap::get_t() -{ - return this->t; -} diff --git a/src/main.cpp b/src/main.cpp index 19ef8fd..641c66a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,10 +13,8 @@ #include #include #include -#include #include #include -#include #include #include "PenningTrap.hpp" @@ -24,12 +22,21 @@ #define PARTICLES 100 #define N 40000 -#define CHARGE 1. -#define MASS 40. // unit: amu +#define CHARGE 1. // unit: e +#define MASS 40.078 // 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.}); +// Particles used for testing +Particle p1(CHARGE, MASS, vec_3d{20., 0., 20.}, + vec_3d{0., 25., 0.}); ///< Particle 1 +Particle p2(CHARGE, MASS, vec_3d{25., 25., 0.}, + vec_3d{0., 40., 5.}); ///< Particle 2 +/** @brief The analytical solution for particle p1 + * + * @param t Time + * + * @return vec_3d + * */ vec_3d analytical_solution_particle_1(double t) { double w_0 = T / MASS; @@ -38,98 +45,122 @@ vec_3d analytical_solution_particle_1(double t) double w_n = (w_0 - std::sqrt(w_0 * w_0 - 2. * w_z2)) / 2.; double A_p = (25. + w_n * 20.) / (w_n - w_p); double A_n = -(25. + w_p * 20.) / (w_n - w_p); - std::complex f = A_p * std::exp(std::complex(0., -w_p * t)) + - A_n * std::exp(std::complex(0., -w_n * t)); - vec_3d res{std::real(f), std::imag(f), 20. * std::cos(std::sqrt(w_z2) * t)}; + std::complex f + = A_p * std::exp(std::complex(0., -w_p * t)) + + A_n * std::exp(std::complex(0., -w_n * t)); + vec_3d res{std::real(f), std::imag(f), + 20. * std::cos(std::sqrt(w_z2) * t)}; return res; } +/** @brief Simulate a single particle over the period of 50 \f$ \mu s \f$. + * */ void simulate_single_particle() { - DEBUG("Inside single particle sim"); + // Initialize trap with particle 1 PenningTrap trap(std::vector{p1}); double time = 50.; // microseconds - DEBUG("Write to dir"); + // Simulate and write results to file trap.write_simulation_to_dir("output/simulate_single_particle", time, N, "rk4", false); } +/** @brief Simulate 2 particles over the period of 50 \f$ \mu s \f$ with and + * without particle interactions. + * */ void simulate_two_particles() { + // Initialize traps with particles PenningTrap trap_no_interaction(std::vector{p1, p2}); PenningTrap trap_with_interaction(std::vector{p1, p2}); double time = 50.; // microseconds + // Simulate and write results to files 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); } +/** @brief Simulate a single particle over 50 \f$ \mu s \f$ using different + * amount of steps and different methods. + * */ void simulate_single_particle_with_different_steps() { - double time = 50.; // microseconds std::ofstream ofile; + // Calculate relative error for RK4 + std::string path = "output/relative_error/RK4/"; + mkpath(path); +#pragma omp parallel for for (int i = 0; i < 4; i++) { int steps = 4000 * std::pow(2, i); double dt = time / (double)steps; - std::string path = "output/relative_error/RK4/"; - mkpath(path); ofile.open(path + std::to_string(steps) + "_steps.txt"); PenningTrap trap(std::vector{p1}); + simulation_t res = trap.simulate(time, steps, "rk4", false); for (int i = 0; i < steps; i++) { - trap.evolve_RK4(dt); - ofile << arma::norm(trap.get_r(0) - - analytical_solution_particle_1(trap.get_t())) - << "\n"; + ofile << arma::norm(res.r_vecs[0][i] + - analytical_solution_particle_1(dt * i)) + << '\n'; } ofile.close(); } + // Calculate relative error for forward Euler + path = "output/relative_error/euler/"; + mkpath(path); +#pragma omp parallel for for (int i = 0; i < 4; i++) { int steps = 4000 * std::pow(2, i); double dt = time / (double)steps; - std::string path = "output/relative_error/euler/"; - mkpath(path); ofile.open(path + std::to_string(steps) + "_steps.txt"); PenningTrap trap(std::vector{p1}); + simulation_t res = trap.simulate(time, steps, "euler", false); for (int i = 0; i < steps; i++) { - trap.evolve_forward_euler(dt); - ofile << arma::norm(trap.get_r(0) - - analytical_solution_particle_1(trap.get_t())) - << "\n"; + ofile << arma::norm(res.r_vecs[0][i] + - analytical_solution_particle_1(dt * i)) + << '\n'; } ofile.close(); } } +/** @brief Simulate 100 particles over 50 \f$ \mu s \f$. + * */ void simulate_100_particles() { - PenningTrap trap((unsigned)100, T, - [](double t) { - return 25. * V / 1000. * (1. + .4 * std::cos(1.5 * t)); - }, - 500., 0); + PenningTrap trap((unsigned)100); - double time = 500.; // microseconds + double time = 50.; // microseconds - trap.write_simulation_to_dir("output/simulate_100_particles", time, N * 4); + trap.write_simulation_to_dir("output/simulate_100_particles", time, N, + "rk4", false); } -void simulate_100_particles_with_time_potential() +/** @brief Simulate 100 particles over 500 \f$ \mu s \f$ using a time + * dependent potential. + * + * @details The simulation sweeps over different frequencies in [0.2, 2.5] + * MHz. + * + * */ +void potential_resonance_wide_sweep() { + double time = 500.; + 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); + size_t freq_iterations + = (size_t)((freq_end - freq_start) / freq_increment) + 1; double res[4][freq_iterations]; @@ -138,53 +169,211 @@ void simulate_100_particles_with_time_potential() std::ofstream ofile; - double freq = freq_start; +#pragma omp parallel for + // Insert frequencies for (size_t i = 0; i < freq_iterations; i++) { - res[0][i] = freq; - freq += freq_increment; + res[0][i] = freq_start + freq_increment * i; } -#pragma omp parallel for collapse(2) num_threads(4) - for (size_t i = 0; i < 3; i++) { - for (size_t j = 0; j < freq_iterations; j++) { - PenningTrap trap( - (unsigned)100, T, - std::bind( +#pragma omp parallel + { + // Each thread creates a PenningTrap instance and reuses it throughout + // the sweep. + PenningTrap trap((unsigned int)100); +#pragma omp for collapse(2) + for (size_t i = 0; i < 3; i++) { + for (size_t j = 0; j < freq_iterations; j++) { + // Reset particles and give new time dependent potential. + trap.reinitialize(std::bind( [](double f, double r, double t) { return (25. * V / 1000.) * (1. + f * std::cos(r * t)); }, - amplitudes[i], res[0][j], std::placeholders::_1), - 500., 0.); - res[i + 1][j] = - trap.fraction_of_particles_left(500., 40000, "rk4", false); + amplitudes[i], res[0][j], std::placeholders::_1)); + res[i + 1][j] + = trap.fraction_of_particles_left(time, N, "rk4", false); + } } } - ofile.open(path + "res.txt"); + // Write results to file + ofile.open(path + "wide_sweep.txt"); for (size_t i = 0; i < freq_iterations; i++) { - ofile << res[0][i] << "," << res[1][i] << "," << res[2][i] << "," - << res[3][i] << "\n"; + ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ',' + << res[3][i] << '\n'; + } + ofile.close(); +} + +/** @brief Simulate 100 particles over 500 \f$ \mu s \f$ using a time + * dependent potential. + * + * @details The simulation sweeps over different frequencies in [1., 1.7] + * MHz. + * + * */ +void potential_resonance_no_interaction_narrow_sweep() +{ + double time = 500.; + + double amplitudes[]{.1, .4, .7}; + + double freq_start = 1.; + double freq_end = 1.7; + double freq_increment = .002; + size_t freq_iterations + = (size_t)((freq_end - freq_start) / freq_increment); + + double res[4][freq_iterations]; + + std::string path = "output/time_dependent_potential/"; + mkpath(path); + + std::ofstream ofile; + +#pragma omp parallel + { + // Each thread creates a PenningTrap instance and reuses it throughout + // the sweep. + PenningTrap trap((unsigned int)100); +#pragma omp for collapse(2) + for (size_t i = 0; i < 3; i++) { + for (size_t j = 0; j < freq_iterations; j++) { + // Reset particles and give new time dependent potential. + trap.reinitialize(std::bind( + [](double f, double r, double t) { + return (25. * V / 1000.) * (1. + f * std::cos(r * t)); + }, + amplitudes[i], res[0][j], std::placeholders::_1)); + res[i + 1][j] + = trap.fraction_of_particles_left(time, N, "rk4", false); + } + } + } + + // Write results to file + ofile.open(path + "narrow_sweep.txt"); + for (size_t i = 0; i < freq_iterations; i++) { + ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ',' + << res[3][i] << '\n'; + } + ofile.close(); +} + +/** @brief Simulate 100 particles over 500 \f$ \mu s \f$ using a time + * dependent potential. + * + * @details The simulation sweeps over different frequencies in [1., 1.7] + * MHz. + * + * */ +void potential_resonance_with_interaction_narrow_sweep() +{ + double time = 500.; + + double amplitudes[]{.1, .4, .7}; + + double freq_start = 1.; + double freq_end = 1.7; + double freq_increment = .002; + size_t freq_iterations + = (size_t)((freq_end - freq_start) / freq_increment); + + double res[4][freq_iterations]; + + std::string path = "output/time_dependent_potential/"; + mkpath(path); + + std::ofstream ofile; + +#pragma omp parallel for + for (size_t i = 0; i < freq_iterations; i++) { + res[0][i] = freq_start + freq_increment * i; + } + +#pragma omp parallel + { + // Each thread creates a PenningTrap instance and reuses it throughout + // the sweep. + PenningTrap trap((unsigned int)100); +#pragma omp for collapse(2) + for (size_t i = 0; i < 3; i++) { + for (size_t j = 0; j < freq_iterations; j++) { + // Reset particles and give new time dependent potential. + trap.reinitialize(std::bind( + [](double f, double r, double t) { + return (25. * V / 1000.) * (1. + f * std::cos(r * t)); + }, + amplitudes[i], res[0][j], std::placeholders::_1)); + res[i + 1][j] = trap.fraction_of_particles_left(time, N); + } + } + } + + // Write results to file + ofile.open(path + "narrow_sweep_interactions.txt"); + for (size_t i = 0; i < freq_iterations; i++) { + ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ',' + << res[3][i] << '\n'; } ofile.close(); } int main() { - double start = omp_get_wtime(); + double start, end, t1, t2; + start = omp_get_wtime(); simulate_single_particle(); simulate_two_particles(); - simulate_single_particle_with_different_steps(); + simulate_single_particle_with_different_steps(); - // simulate_100_particles(); + t2 = omp_get_wtime(); - // simulate_100_particles_with_time_potential(); + std::cout << "Time single and double : " << (t2 - start) + << " seconds" << std::endl; - double end = omp_get_wtime(); + t1 = omp_get_wtime(); - std::cout << "Time: " << (end - start) << " seconds" << std::endl; + simulate_100_particles(); + + t2 = omp_get_wtime(); + + std::cout << "Time 100 particles : " << (t2 - t1) + << " seconds" << std::endl; + + t1 = omp_get_wtime(); + + potential_resonance_wide_sweep(); + + t2 = omp_get_wtime(); + + std::cout << "Time wide sweep : " << (t2 - t1) + << " seconds" << std::endl; + + t1 = omp_get_wtime(); + + potential_resonance_no_interaction_narrow_sweep(); + + t2 = omp_get_wtime(); + + std::cout << "Time narrow sweep no interaction : " << (t2 - t1) + << " seconds" << std::endl; + + t1 = omp_get_wtime(); + + potential_resonance_with_interaction_narrow_sweep(); + + t2 = omp_get_wtime(); + + std::cout << "Time narrow sweep with interaction: " << (t2 - t1) + << " seconds" << std::endl; + + end = omp_get_wtime(); + + std::cout << "Time : " << (end - start) + << " seconds" << std::endl; return 0; } diff --git a/src/scripts/plot_phase_space.py b/src/scripts/plot_phase_space.py index af17c7c..d293fb7 100644 --- a/src/scripts/plot_phase_space.py +++ b/src/scripts/plot_phase_space.py @@ -62,9 +62,9 @@ def main(): axs2[1].set(xlabel=r"t $(\mu s)$", ylabel = r"z $(\mu m)$") axs2[0].set(ylabel = r"z $(\mu m)$") - axs1[i].legend() + axs1[i].legend(loc="upper right") # axs1[i].set_title(title) - axs2[i].legend() + axs2[i].legend(loc="upper right") # axs2[i].set_title(title) fig1.savefig("../latex/images/phase_space_2_particles_x.pdf", bbox_inches="tight") diff --git a/src/scripts/plot_relative_error.py b/src/scripts/plot_relative_error.py index 10106af..9399e67 100644 --- a/src/scripts/plot_relative_error.py +++ b/src/scripts/plot_relative_error.py @@ -16,10 +16,10 @@ params = { plt.rcParams.update(params) def main(): - directories = { + directories = [ "output/relative_error/RK4/", "output/relative_error/euler/", - } + ] files = [ "4000_steps.txt", "8000_steps.txt", @@ -27,17 +27,21 @@ def main(): "32000_steps.txt", ] labels = [ - r"4000 steps", - r"8000 steps", - r"16000 steps", - r"32000 steps", + r"$n_1$", + r"$n_2$", + r"$n_3$", + r"$n_4$", ] titles = [ "Relative error for the RK4 method", "Relative error for the forward Euler method" ] - fig1, axs1 = plt.subplots(2,1, sharex=True) - for i, (dir, title) in enumerate(zip(directories, titles)): + methods = [ + "rk4", + "euler" + ] + fig1, axs1 = plt.subplots(2,1) + for i, (dir, title) in enumerate(list(zip(directories, titles))): max_err = [] for label, file in zip(labels, files): with open(dir+file) as f: @@ -47,17 +51,14 @@ def main(): max_err.append(max(r)) axs1[i].plot(t, r, label=label) - axs1[i].set(ylabel = r"relative_error $(\mu m)$") # xlabel=r"t $(\mu s)$", - - axs1[1].set_xlabel(r"t $(\mu s)$") + axs1[i].set(xlabel=r"t $(\mu s)$", ylabel = r"relative_error $(\mu m)$") axs1[i].legend() - # axs1[i].set_title(title) + axs1[i].set_title(title) - conv_rate = 1/3 * sum([np.log10(max_err[i+1]/max_err[i])/np.log10(.5) for i in range(3)]) - print(conv_rate) + conv_rate = 1/3 * sum([np.log2(max_err[i+1]/max_err[i])/np.log2(.5) for i in range(3)]) + print(f"{methods[i]}: {conv_rate}") - # fig1.savefig("../latex/images/phase_space_2_particles_x.pdf") - plt.show() + fig1.savefig("../latex/images/phase_space_2_particles_x.pdf") if __name__ == "__main__": diff --git a/src/test_suite.cpp b/src/test_suite.cpp index cd422c5..a2a0639 100644 --- a/src/test_suite.cpp +++ b/src/test_suite.cpp @@ -10,39 +10,43 @@ * @bug No known bugs * */ -#include "PenningTrap.hpp" -#include "utils.hpp" - #include #include #include +#include "PenningTrap.hpp" +#include "utils.hpp" + +/** @brief Test class for the Penning trap. + * */ class PenningTrapTest { public: + /** @brief Test that the external E field gives correct values. + * */ static void test_external_E_field() { PenningTrap trap; // Vector containing inputs and expected results - std::vector> tests; + std::vector> tests; tests.push_back( - std::make_pair(arma::vec{0., 0., 0.}, arma::vec{0., 0., 0.})); + std::make_pair(vec_3d{0., 0., 0.}, vec_3d{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(vec_3d{10., 0., 0.}, + vec_3d{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(vec_3d{10., 0., 0.}, + vec_3d{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(vec_3d{0., 10., 0.}, + vec_3d{0., 96.4852558, 0.})); - tests.push_back(std::make_pair(arma::vec{0., 0., 10.}, - arma::vec{0., 0., -192.9705116})); + tests.push_back(std::make_pair(vec_3d{0., 0., 10.}, + vec_3d{0., 0., -192.9705116})); - arma::vec result; - arma::vec v; + vec_3d result; + vec_3d v; std::stringstream msg; for (size_t i = 0; i < tests.size(); i++) { v = tests.at(i).first; @@ -52,81 +56,90 @@ public: 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()); + ASSERT(close_to(result, tests.at(i).second), msg.str()); } } + /** @brief Test that the external B field gives correct values. + * */ 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), + vec_3d expected{0., 0., T}; + vec_3d result = trap.external_B_field(vec_3d{0., 0., 0.}); + ASSERT(close_to(expected, result), "Testing the external B field at (0,0,0)"); } + /** @brief Test that the force between particles gives expected results. + * */ static void test_force_on_particle() { PenningTrap trap; - arma::vec v{0., 0., 0.}; + vec_3d 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)); + trap.add_particle(Particle(1., 40., vec_3d{0., 0., 0.}, v)); + trap.add_particle(Particle(1., 40., vec_3d{1., 0., 0.}, v)); + trap.add_particle(Particle(1., 40., vec_3d{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), + vec_3d expected{-1., 0., 0.}; + vec_3d result = trap.force_on_particle(0, 1); + ASSERT(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}; + expected = vec_3d{0, -.024, -.032}; result = trap.force_on_particle(0, 2); - ASSERT(arma_vector_close_to(expected, result), + ASSERT(close_to(expected, result), "Testing the force on a particle at (0,0,0) from a " "particle at (0,3,4)."); } + /** @brief Test that the total external force returns expected results + * */ static void test_total_force_external() { PenningTrap trap; trap.add_particle( - Particle(1., 40., arma::vec{1., 2., 3.}, arma::vec{3., 4., 5.})); + Particle(1., 40., vec_3d{1., 2., 3.}, vec_3d{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), + vec_3d expected{395.58954878, -270.15871624, -57.89115348}; + vec_3d result = trap.total_force_external(0); + ASSERT(close_to(expected, result), "Testing the total external force on a particle at " "(1,2,3) with velocity (3,4,5)"); } + /** @brief Test that the total force of all particles on a single particle + * returns expected results. + * */ static void test_total_force_particles() { PenningTrap trap; trap.add_particle( - Particle(1., 40., arma::vec{0., 0., 0.}, arma::vec{0., 0., 0.})); + Particle(1., 40., vec_3d{0., 0., 0.}, vec_3d{0., 0., 0.})); - arma::vec expected{0., 0., 0.}; - arma::vec result = trap.total_force_particles(0); - ASSERT(arma_vector_close_to(expected, result), + vec_3d expected{0., 0., 0.}; + vec_3d result = trap.total_force_particles(0); + ASSERT(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.})); + Particle(1., 40., vec_3d{1., 0., 0.}, vec_3d{0., 0., 0.})); trap.add_particle( - Particle(1., 40., arma::vec{0., 1., 0.}, arma::vec{0., 0., 0.})); + Particle(1., 40., vec_3d{0., 1., 0.}, vec_3d{0., 0., 0.})); trap.add_particle( - Particle(1., 40., arma::vec{0., 0., 1.}, arma::vec{0., 0., 0.})); + Particle(1., 40., vec_3d{0., 0., 1.}, vec_3d{0., 0., 0.})); - expected = arma::vec(3, arma::fill::value(-3473.383325)); + expected = vec_3d().fill(-3473.383325); result = trap.total_force_particles(0); - ASSERT(arma_vector_close_to(expected, result), + ASSERT(close_to(expected, result), "Testing the total force of all particles on particle 0 " "with 3 other particles."); } diff --git a/src/utils.cpp b/src/utils.cpp index 14670f0..83e67a8 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -10,8 +10,6 @@ * @bug No known bugs * */ -#include - #include "utils.hpp" std::string scientific_format(double d, int width, int prec) @@ -59,7 +57,7 @@ void m_assert(bool expr, std::string expr_str, std::string f, std::string file, } } -bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol) +bool close_to(arma::vec &a, arma::vec &b, double tol) { if (a.n_elem != b.n_elem) { return false;