diff --git a/docs/Particle_8cpp.html b/docs/Particle_8cpp.html index b3fd0e9..e5f553c 100644 --- a/docs/Particle_8cpp.html +++ b/docs/Particle_8cpp.html @@ -112,7 +112,7 @@ $(document).ready(function(){initNavTree('Particle_8cpp.html',''); initResizable
Author
Cory Alexander Balaton (coryab)
Janita Ovidie Sandtrøen Willumsen (janitaws)
-
Version
0.1
+
Version
1.0
Bug:
No known bugs

Definition in file Particle.cpp.

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

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

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

Go to the source code of this file.

@@ -122,7 +123,7 @@ Classes
Author
Cory Alexander Balaton (coryab)
Janita Ovidie Sandtrøen Willumsen (janitaws)
-
Version
0.1
+
Version
1.0
Bug:
No known bugs

Definition in file Particle.hpp.

diff --git a/docs/Particle_8hpp_source.html b/docs/Particle_8hpp_source.html index 98ff655..bf09331 100644 --- a/docs/Particle_8hpp_source.html +++ b/docs/Particle_8hpp_source.html @@ -107,30 +107,35 @@ $(document).ready(function(){initNavTree('Particle_8hpp_source.html',''); initRe
14
15#include <armadillo>
16
-
17#include "typedefs.hpp"
-
18
-
21class Particle {
-
22private:
-
23 double q;
-
24 double m;
-
25 vec_3d r_vec;
-
26 vec_3d v_vec;
-
27
-
28public:
-
39 Particle(double q, double m, vec_3d r_vec, vec_3d v_vec);
-
40
-
43 friend class PenningTrap;
-
44};
-
45
-
46#endif
-
Particle
A class that holds attributes of a particle.
Definition: Particle.hpp:21
-
Particle::q
double q
Charge.
Definition: Particle.hpp:23
-
Particle::v_vec
vec_3d v_vec
velocity
Definition: Particle.hpp:26
-
Particle::m
double m
Mass.
Definition: Particle.hpp:24
-
Particle::r_vec
vec_3d r_vec
position
Definition: Particle.hpp:25
-
PenningTrap
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:31
+
17#include "constants.hpp"
+
18#include "typedefs.hpp"
+
19
+
22class Particle
+
23{
+
24private:
+
25 vec3 r_vec;
+
26 vec3 v_vec;
+
27 double q;
+
28 double m;
+
29
+
30public:
+
41 Particle(vec3 r_vec, vec3 v_vec, double q = CA_CHARGE, double m = CA_MASS);
+
42
+
45 friend class PenningTrap;
+
46};
+
47
+
48#endif
+
Particle
A class that holds attributes of a particle.
Definition: Particle.hpp:23
+
Particle::r_vec
vec3 r_vec
position
Definition: Particle.hpp:25
+
Particle::v_vec
vec3 v_vec
velocity
Definition: Particle.hpp:26
+
Particle::q
double q
Charge.
Definition: Particle.hpp:27
+
Particle::m
double m
Mass.
Definition: Particle.hpp:28
+
PenningTrap
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:32
+
constants.hpp
Library of constants.
+
CA_MASS
#define CA_MASS
Mass of a single calcium ion. unit: amu.
Definition: constants.hpp:29
+
CA_CHARGE
#define CA_CHARGE
Charge of a singly charged calcium ion. unit: e.
Definition: constants.hpp:33
typedefs.hpp
Useful typedefs for cleaner code.
-
vec_3d
arma::vec::fixed< 3 > vec_3d
Typedef for a fixed 3d arma vector.
Definition: typedefs.hpp:36
+
vec3
arma::vec::fixed< 3 > vec3
Typedef for a fixed 3d arma vector.
Definition: typedefs.hpp:23
diff --git a/docs/PenningTrap_8cpp.html b/docs/PenningTrap_8cpp.html index 81ea9db..f90f9c5 100644 --- a/docs/PenningTrap_8cpp.html +++ b/docs/PenningTrap_8cpp.html @@ -105,6 +105,11 @@ $(document).ready(function(){initNavTree('PenningTrap_8cpp.html',''); initResiza

The implementation of the PenningTrap class. More...

#include "PenningTrap.hpp"
+#include "typedefs.hpp"
+#include <algorithm>
+#include <functional>
+#include <sys/types.h>
+#include <vector>

Go to the source code of this file.

Detailed Description

@@ -112,7 +117,7 @@ $(document).ready(function(){initNavTree('PenningTrap_8cpp.html',''); initResiza
Author
Cory Alexander Balaton (coryab)
Janita Ovidie Sandtrøen Willumsen (janitaws)
-
Version
0.1
+
Version
1.0
Bug:
No known bugs

Definition in file PenningTrap.cpp.

diff --git a/docs/PenningTrap_8cpp_source.html b/docs/PenningTrap_8cpp_source.html index fab32cb..e974bfc 100644 --- a/docs/PenningTrap_8cpp_source.html +++ b/docs/PenningTrap_8cpp_source.html @@ -103,335 +103,359 @@ $(document).ready(function(){initNavTree('PenningTrap_8cpp_source.html',''); ini
Go to the documentation of this file.
1
13#include "PenningTrap.hpp"
-
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
- -
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];
+
14#include "typedefs.hpp"
+
15#include <algorithm>
+
16#include <functional>
+
17#include <sys/types.h>
+
18#include <vector>
+
19
+
20PenningTrap::PenningTrap(double B_0, double V_0, double d, double t)
+
21{
+
22 this->B_0 = B_0;
+
23 this->V_0 = V_0;
+
24 this->d = d;
+
25 this->t = t;
+
26 this->perturbation = [](double t) { return 1.; };
+
27}
+
28
+
29PenningTrap::PenningTrap(uint i, double B_0, double V_0, double d, double t)
+
30 : PenningTrap::PenningTrap(B_0, V_0, d)
+
31{
+
32 for (size_t j = 0; j < i; j++) {
+
33 this->particles.push_back(
+
34 Particle(vec3(vec3().randn() * .1 * this->d),
+
35 vec3(vec3().randn() * .1 * this->d)));
+
36 }
+
37}
+
38
+
39PenningTrap::PenningTrap(std::vector<Particle> particles, double B_0,
+
40 double V_0, double d, double t)
+
41 : PenningTrap::PenningTrap(B_0, V_0, d)
+
42{
+
43 this->particles = particles;
+
44}
+
45
+
46void PenningTrap::set_pertubation(double f, double omega_V)
+
47{
+
48 this->perturbation = [f, omega_V](double t) {
+
49 return 1 + f * std::cos(omega_V * t);
+
50 };
+
51}
+
52
+
53void PenningTrap::reinitialize(double f, double omega_V, double t)
+
54{
+
55 this->t = t;
+
56 this->set_pertubation(f, omega_V);
+
57
+
58 for (size_t i = 0; i < this->particles.size(); i++) {
+
59 this->particles[i].r_vec = vec3().randn() * .1 * this->d;
+
60 }
+
61}
+
62
+
63vec3 PenningTrap::v_func(uint i, uint j, double dt)
+
64{
+
65 switch (i) {
+
66 case 0:
+
67 return .5 * dt * this->k_v[0][j];
+
68 case 1:
+
69 return .5 * dt * this->k_v[1][j];
+
70 case 2:
+
71 return dt * this->k_v[2][j];
+
72 case 3:
+
73 return vec3((dt / 6.)
+
74 * (this->k_v[0][j] + 2. * this->k_v[1][j]
+
75 + 2. * this->k_v[2][j] + this->k_v[3][j]));
+
76 default:
+
77 std::cout << "Not valid!" << std::endl;
+
78 abort();
+
79 }
+
80}
+
81
+
82vec3 PenningTrap::r_func(uint i, uint j, double dt)
+
83{
+
84 switch (i) {
+
85 case 0:
+
86 return .5 * dt * this->k_r[0][j];
+
87 case 1:
+
88 return .5 * dt * this->k_r[1][j];
+
89 case 2:
+
90 return dt * this->k_r[2][j];
+
91 case 3:
+
92 return vec3((dt / 6.)
+
93 * (this->k_r[0][j] + 2. * this->k_r[1][j]
+
94 + 2. * this->k_r[2][j] + this->k_r[3][j]));
+
95 default:
+
96 std::cout << "Not valid!" << std::endl;
+
97 abort();
+
98 }
+
99}
+
100
+ +
102{
+
103 this->particles.push_back(particle);
+
104}
+
105
+ +
107{
+
108 r(2) *= -2.;
+
109
+
110 return vec3((this->V_0 * this->perturbation(this->t) / (this->d * this->d))
+
111 * r);
+
112}
+
113
+ +
115{
+
116 return vec3{0., 0., this->B_0};
+
117}
+
118
+ +
120{
+
121 // Calculate the difference between the particles' position
+
122 vec3 res = this->particles[i].r_vec - this->particles[j].r_vec;
+
123
+
124 // Get the distance between the particles
+
125 double norm = arma::norm(res, 2);
126
-
127 vec_3d res;
-
128
-
129 for (size_t j = 0; j < this->particles.size(); j++) {
-
130 if (i == j) {
-
131 continue;
-
132 }
+
127 return vec3((this->particles[j].q / (norm * norm * norm)) * res);
+
128}
+
129
+ +
131{
+
132 Particle *p = &this->particles[i];
133
-
134 res += this->force_on_particle(i, j);
-
135 }
-
136
-
137 return vec_3d(res * K_E * (p.q / p.m));
-
138}
-
139
- -
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
-
151 std::vector<Particle> original_particles = this->particles;
-
152 std::vector<Particle> tmp_particles = this->particles;
-
153
-
154 vec_3d (PenningTrap::*force)(unsigned int);
-
155 if (particle_interaction) {
- -
157 }
-
158 else {
- -
160 }
-
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 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;
+
134 if (arma::norm(p->r_vec) > this->d) {
+
135 return vec3{0., 0., 0.};
+
136 }
+
137
+
138 return vec3(p->q
+
139 * (this->external_E_field(p->r_vec)
+
140 + arma::cross(p->v_vec, this->external_B_field(p->r_vec))));
+
141}
+
142
+ +
144{
+
145 vec3 res;
+
146
+
147 for (size_t j = 0; j < this->particles.size(); j++) {
+
148 if (i != j)
+
149 res += this->force_on_particle(i, j);
+
150 }
+
151
+
152 return vec3(res * (K_E * this->particles[i].q));
+
153}
+
154
+ +
156{
+
157 if (arma::norm(this->particles[i].r_vec) > this->d) {
+
158 return vec3{0., 0., 0.};
+
159 }
+
160 return vec3(this->total_force_external(i) - this->total_force_particles(i));
+
161}
+
162
+
163void PenningTrap::evolve_RK4(double dt, bool particle_interaction)
+
164{
+
165
+
166 std::vector<Particle> original_particles = this->particles;
+
167 std::vector<Particle> tmp_particles = this->particles;
+
168
+
169 vec3 (PenningTrap::*force)(uint) = particle_interaction
+ +
172
-
173 Particle *p = &tmp_particles[j];
+
173 size_t size = this->particles.size();
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
-
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 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 }
+
175 // Allocating takes a long time, so reuse sim_arr if possible
+
176 if (this->k_v.size() != 4 || this->k_r.size() != 4
+
177 || this->k_v[0].size() != size || this->k_r[0].size() != size) {
+
178 this->k_v = sim_arr(4, sim_cols(size));
+
179 this->k_r = sim_arr(4, sim_cols(size));
+
180 }
+
181
+
182 // Each k_{i+1} is dependent on k_i, so outer loop is not parallelizable
+
183 for (size_t i = 0; i < 4; i++) {
+
184 // Inner loop is able to be parallelized
+
185#pragma omp parallel for
+
186 for (size_t j = 0; j < size; j++) {
+
187 this->k_v[i][j] = (this->*force)(j) / this->particles[j].m;
+
188 this->k_r[i][j] = this->particles[j].v_vec;
+
189
+
190 tmp_particles[j].v_vec =
+
191 original_particles[j].v_vec + this->v_func(i, j, dt);
+
192 tmp_particles[j].r_vec =
+
193 original_particles[j].r_vec + this->r_func(i, j, dt);
+
194 }
+
195 this->particles = tmp_particles;
+
196 }
+
197
+
198 this->t += dt;
+
199}
+
200
+
201void PenningTrap::evolve_forward_euler(double dt, bool particle_interaction)
+
202{
+
203 size_t size = this->particles.size();
+
204 vec3 force_res[size];
+
205
+
206 vec3 (PenningTrap::*force)(uint) = particle_interaction
+ + +
209
+
210 // Calculating the force for each particle is independent and therefore
+
211 // a good candidate for parallel execution
+
212#pragma omp parallel for
+
213 for (size_t i = 0; i < size; i++) {
+
214 force_res[i] = (this->*force)(i);
+
215 }
+
216
+
217 // Updating the particles is also independent, so we can parallelize
+
218 // this as well
+
219#pragma omp parallel for
+
220 for (size_t i = 0; i < size; i++) {
+
221 this->particles[i].r_vec += dt * this->particles[i].v_vec;
+
222 this->particles[i].v_vec += dt * force_res[i] / this->particles[i].m;
+
223 }
+
224
+
225 this->t += dt;
+
226}
+
227
+
228simulation_t PenningTrap::simulate(double time, uint steps, std::string method,
+
229 bool particle_interaction)
+
230{
+
231 double dt = time / (double)steps;
+
232
+
233 uint size = this->particles.size();
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 }
+
235 simulation_t res{sim_arr(size, sim_cols(steps)),
+
236 sim_arr(size, sim_cols(steps))};
+
237
+
238 void (PenningTrap::*func)(double, bool);
+
239 if (method == "rk4") {
+ +
241 } else if (method == "euler") {
+ +
243 } else {
+
244 std::cout << "Not a valid method!" << std::endl;
+
245 abort();
+
246 }
+
247
+
248 for (size_t j = 0; j < steps; j++) {
+
249 for (size_t i = 0; i < size; i++) {
+
250 res.r_vecs[i][j] = this->particles[i].r_vec;
+
251 res.v_vecs[i][j] = this->particles[i].v_vec;
+
252 }
+
253 (this->*func)(dt, particle_interaction);
+
254 }
+
255
+
256 return res;
+
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 }
+
259void PenningTrap::write_simulation_to_dir(std::string path, double time,
+
260 uint steps, std::string method,
+
261 bool particle_interaction)
+
262{
+
263 if (path.back() != '/') {
+
264 path += '/';
+
265 }
+
266 if (mkpath(path, 0777) != 0) {
+
267 std::cout << "Failed to make path" << std::endl;
+
268 abort();
+
269 }
+
270
+
271 simulation_t res =
+
272 this->simulate(time, steps, method, particle_interaction);
+
273
+
274 std::ofstream ofile;
+
275
+
276 // Writing each particle to its own file is independent and can be run in
+
277 // parallel.
+
278#pragma omp parallel for private(ofile)
+
279 for (size_t i = 0; i < this->particles.size(); i++) {
+
280 ofile.open(path + "particle_" + std::to_string(i) + "_r.txt");
+
281 for (vec3 &vec : res.r_vecs[i]) {
+
282 ofile << scientific_format(vec(0), 10, 8) << ','
+
283 << scientific_format(vec(1), 10, 8) << ','
+
284 << scientific_format(vec(2), 10, 8) << '\n';
+
285 }
+
286 ofile.close();
+
287 ofile.open(path + "particle_" + std::to_string(i) + "_v.txt");
+
288 for (vec3 &vec : res.v_vecs[i]) {
+
289 ofile << scientific_format(vec(0), 10, 8) << ','
+
290 << scientific_format(vec(1), 10, 8) << ','
+
291 << scientific_format(vec(2), 10, 8) << '\n';
+
292 }
+
293 ofile.close();
294 }
-
295
-
296 return (double)particles_left / (double)this->particles.size();
-
297}
-
298
-
299vec_3d PenningTrap::get_r(int i)
+
295}
+
296
+
297double PenningTrap::fraction_of_particles_left(double time, uint steps,
+
298 std::string method,
+
299 bool particle_interaction)
300{
-
301 return this->particles[i].r_vec;
-
302}
-
303
-
304double PenningTrap::get_t()
-
305{
-
306 return this->t;
-
307}
+
301 double dt = time / (double)steps;
+
302
+
303 void (PenningTrap::*func)(double, bool);
+
304 if (method == "rk4") {
+ +
306 } else if (method == "euler") {
+ +
308 } else {
+
309 std::cout << "Not a valid method!" << std::endl;
+
310 abort();
+
311 }
+
312
+
313 for (size_t j = 0; j < steps; j++) {
+
314 (this->*func)(dt, particle_interaction);
+
315 }
+
316
+
317 int particles_left = 0;
+
318
+
319 // A reduction is perfect here
+
320#pragma omp parallel for reduction(+ : particles_left)
+
321 for (size_t i = 0; i < this->particles.size(); i++) {
+
322 if (arma::norm(this->particles[i].r_vec) < this->d) {
+
323 particles_left++;
+
324 }
+
325 }
+
326
+
327 return (double)particles_left / (double)this->particles.size();
+
328}
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: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
+
A class that holds attributes of a particle.
Definition: Particle.hpp:23
+
vec3 r_vec
position
Definition: Particle.hpp:25
+
vec3 v_vec
velocity
Definition: Particle.hpp:26
+
double q
Charge.
Definition: Particle.hpp:27
+
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:32
+
std::vector< Particle > particles
The particles in the Penning trap.
Definition: PenningTrap.hpp:39
+
double B_0
Magnetic field strength.
Definition: PenningTrap.hpp:34
+
vec3 total_force_external(uint i)
Calculate the total external force on a particle.
+
sim_arr k_r
Definition: PenningTrap.hpp:42
+
vec3 total_force_particles(uint i)
Calculate the total force on a particle p_i from other particles.
+
vec3 external_B_field(vec3 r)
Calculate B at point r.
+
void evolve_RK4(double dt, bool particle_interaction=true)
Go forward one timestep using the RK4 method.
+
vec3 v_func(uint i, uint j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:63
+
vec3 external_E_field(vec3 r)
Calculate E at point r.
+
PenningTrap(double B_0=T, double V_0=(25. *V)/1000., double d=500., double t=0.)
Constructor for the PenningTrap class.
Definition: PenningTrap.cpp:20
+
double d
Characteristic dimension.
Definition: PenningTrap.hpp:37
+
void add_particle(Particle particle)
Add a particle to the system.
+
double V_0
Applied potential.
Definition: PenningTrap.hpp:35
+
simulation_t simulate(double time, uint steps, std::string method="rk4", bool particle_interaction=true)
Simulate the particle system inside the Penning trap over a certain amount of time.
+
vec3 force_on_particle(uint i, uint j)
Calculate the force between 2 particles.
+
vec3 r_func(uint i, uint j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:82
+
double t
Current time.
Definition: PenningTrap.hpp:38
+
vec3 total_force(uint i)
calculate the total force on a particle p_i.
+
void set_pertubation(double f, double omega_V)
Time dependent perturbation to V_0.
Definition: PenningTrap.cpp:46
+
void reinitialize(double f, double omega_V, double t=0.)
Give all particles new positions and velocities, and change t and V_0.
Definition: PenningTrap.cpp:53
+
void evolve_forward_euler(double dt, bool particle_interaction=true)
Go forward one timestep using the forward Euler method.
+
double fraction_of_particles_left(double time, uint 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, uint steps, std::string method="rk4", bool particle_interaction=true)
Simulate and write the displacement of all particles to files.
+
std::function< double(double)> perturbation
Time-dependent perturbation.
Definition: PenningTrap.hpp:36
+
sim_arr k_v
Definition: PenningTrap.hpp:40
+
#define K_E
Coulomb constant. unit: .
Definition: constants.hpp:17
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
-
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:74
+
Useful typedefs for cleaner code.
+
arma::vec::fixed< 3 > vec3
Typedef for a fixed 3d arma vector.
Definition: typedefs.hpp:23
+
std::vector< vec3 > sim_cols
Typedef for the column of the result vector from simulating particles.
Definition: typedefs.hpp:28
+
std::vector< sim_cols > sim_arr
Typedef for the result of the simulate method.
Definition: typedefs.hpp:36
+
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:72
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 7632939..e0d2a31 100644 --- a/docs/PenningTrap_8hpp.html +++ b/docs/PenningTrap_8hpp.html @@ -126,7 +126,7 @@ Classes
Author
Cory Alexander Balaton (coryab)
Janita Ovidie Sandtrøen Willumsen (janitaws)
-
Version
0.1
+
Version
1.0
Bug:
No known bugs

Definition in file PenningTrap.hpp.

diff --git a/docs/PenningTrap_8hpp_source.html b/docs/PenningTrap_8hpp_source.html index cc866c3..fab595d 100644 --- a/docs/PenningTrap_8hpp_source.html +++ b/docs/PenningTrap_8hpp_source.html @@ -113,108 +113,107 @@ $(document).ready(function(){initNavTree('PenningTrap_8hpp_source.html',''); ini
20#include "typedefs.hpp"
21#include "utils.hpp"
22
-
23#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \
+
23#pragma omp declare reduction(+ : vec3 : omp_out += omp_in) \
24 initializer(omp_priv = omp_orig)
25
-
31class PenningTrap {
-
32private:
-
33 double B_0;
-
34 std::function<double(double)> V_0;
-
35 double d;
-
36 double t;
-
37 std::vector<Particle> particles;
-
38 sim_arr k_v;
-
40 sim_arr k_r;
-
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:
-
75 PenningTrap(
-
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
-
89 PenningTrap(
-
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
-
103 PenningTrap(
-
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
-
121 vec_3d external_E_field(vec_3d r);
-
122
-
129 vec_3d external_B_field(vec_3d r);
-
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
+
31class PenningTrap
+
32{
+
33private:
+
34 double B_0;
+
35 double V_0;
+
36 std::function<double(double)> perturbation;
+
37 double d;
+
38 double t;
+
39 std::vector<Particle> particles;
+
40 sim_arr k_v;
+
42 sim_arr k_r;
+
44
+
55 vec3 v_func(uint i, uint j, double dt);
+
56
+
67 vec3 r_func(uint i, uint j, double dt);
+
68
+
75 vec3 external_E_field(vec3 r);
+
76
+
83 vec3 external_B_field(vec3 r);
+
84
+
95 vec3 force_on_particle(uint i, uint j);
+
96
+
106 vec3 total_force_external(uint i);
+
107
+
115 vec3 total_force_particles(uint i);
+
116
+
123 vec3 total_force(uint i);
+
124
+
125public:
+
133 PenningTrap(double B_0 = T, double V_0 = (25. * V) / 1000., double d = 500.,
+
134 double t = 0.);
+
135
+
144 PenningTrap(uint i, double B_0 = T, double V_0 = (25. * V) / 1000.,
+
145 double d = 500., double t = 0.);
+
146
+
155 PenningTrap(std::vector<Particle> particles, double B_0 = T,
+
156 double V_0 = (25. * V) / 1000., double d = 500., double t = 0.);
+
157
+
163 void set_pertubation(double f, double omega_V);
+
164
+
171 void reinitialize(double f, double omega_V, double t = 0.);
+
172
+
177 void add_particle(Particle particle);
+
178
+
184 void evolve_RK4(double dt, bool particle_interaction = true);
+
185
+
191 void evolve_forward_euler(double dt, bool particle_interaction = true);
+
192
+
203 simulation_t simulate(double time, uint steps, std::string method = "rk4",
+
204 bool particle_interaction = true);
+
205
+
214 void write_simulation_to_dir(std::string path, double time, uint steps,
+
215 std::string method = "rk4",
+
216 bool particle_interaction = true);
+
217
+
228 double fraction_of_particles_left(double time, uint steps,
+
229 std::string method = "rk4",
+
230 bool particle_interaction = true);
+
231
+
232 friend class PenningTrapTest;
+
233};
+
234
+
235#endif
Particle.hpp
A class that holds the properties of a particle.
-
Particle
A class that holds attributes of a particle.
Definition: Particle.hpp:21
-
PenningTrap
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:31
-
PenningTrap::particles
std::vector< Particle > particles
The particles in the Penning trap.
Definition: PenningTrap.hpp:37
-
PenningTrap::fraction_of_particles_left
double fraction_of_particles_left(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate and calculate what fraction of particles are still left inside the Penning trap after the si...
Definition: PenningTrap.cpp:281
-
PenningTrap::B_0
double B_0
Magnetic field strength.
Definition: PenningTrap.hpp:33
-
PenningTrap::external_E_field
vec_3d external_E_field(vec_3d r)
Calculate E at point r.
Definition: PenningTrap.cpp:84
-
PenningTrap::total_force
vec_3d total_force(unsigned int i)
calculate the total force on a particle p_i.
Definition: PenningTrap.cpp:140
-
PenningTrap::k_r
sim_arr k_r
Definition: PenningTrap.hpp:40
-
PenningTrap::evolve_RK4
void evolve_RK4(double dt, bool particle_interaction=true)
Go forward one timestep using the RK4 method.
Definition: PenningTrap.cpp:148
-
PenningTrap::r_func
vec_3d r_func(unsigned int i, unsigned int j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:61
-
PenningTrap::total_force_particles
vec_3d total_force_particles(unsigned int i)
Calculate the total force on a particle p_i from other particles.
Definition: PenningTrap.cpp:123
-
PenningTrap::d
double d
Characteristic dimension.
Definition: PenningTrap.hpp:35
-
PenningTrap::add_particle
void add_particle(Particle particle)
Add a particle to the system.
Definition: PenningTrap.cpp:79
-
PenningTrap::t
double t
Current time.
Definition: PenningTrap.hpp:36
-
PenningTrap::force_on_particle
vec_3d force_on_particle(unsigned int i, unsigned int j)
Calculate the force between 2 particles.
Definition: PenningTrap.cpp:97
-
PenningTrap::V_0
std::function< double(double)> V_0
Applied potential.
Definition: PenningTrap.hpp:34
-
PenningTrap::evolve_forward_euler
void evolve_forward_euler(double dt, bool particle_interaction=true)
Go forward one timestep using the forward Euler method.
Definition: PenningTrap.cpp:183
-
PenningTrap::write_simulation_to_dir
void write_simulation_to_dir(std::string path, double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate and write the displacement of all particles to files.
Definition: PenningTrap.cpp:246
-
PenningTrap::external_B_field
vec_3d external_B_field(vec_3d r)
Calculate B at point r.
Definition: PenningTrap.cpp:92
-
PenningTrap::simulate
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.
Definition: PenningTrap.cpp:212
-
PenningTrap::total_force_external
vec_3d total_force_external(unsigned int i)
Calculate the total external force on a particle.
Definition: PenningTrap.cpp:108
-
PenningTrap::k_v
sim_arr k_v
Definition: PenningTrap.hpp:38
-
PenningTrap::v_func
vec_3d v_func(unsigned int i, unsigned int j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:43
+
Particle
A class that holds attributes of a particle.
Definition: Particle.hpp:23
+
PenningTrapTest
Test class for the Penning trap.
Definition: test_suite.cpp:24
+
PenningTrap
A class that simulates a Penning trap.
Definition: PenningTrap.hpp:32
+
PenningTrap::particles
std::vector< Particle > particles
The particles in the Penning trap.
Definition: PenningTrap.hpp:39
+
PenningTrap::B_0
double B_0
Magnetic field strength.
Definition: PenningTrap.hpp:34
+
PenningTrap::total_force_external
vec3 total_force_external(uint i)
Calculate the total external force on a particle.
Definition: PenningTrap.cpp:130
+
PenningTrap::k_r
sim_arr k_r
Definition: PenningTrap.hpp:42
+
PenningTrap::total_force_particles
vec3 total_force_particles(uint i)
Calculate the total force on a particle p_i from other particles.
Definition: PenningTrap.cpp:143
+
PenningTrap::external_B_field
vec3 external_B_field(vec3 r)
Calculate B at point r.
Definition: PenningTrap.cpp:114
+
PenningTrap::evolve_RK4
void evolve_RK4(double dt, bool particle_interaction=true)
Go forward one timestep using the RK4 method.
Definition: PenningTrap.cpp:163
+
PenningTrap::v_func
vec3 v_func(uint i, uint j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:63
+
PenningTrap::external_E_field
vec3 external_E_field(vec3 r)
Calculate E at point r.
Definition: PenningTrap.cpp:106
+
PenningTrap::d
double d
Characteristic dimension.
Definition: PenningTrap.hpp:37
+
PenningTrap::add_particle
void add_particle(Particle particle)
Add a particle to the system.
Definition: PenningTrap.cpp:101
+
PenningTrap::V_0
double V_0
Applied potential.
Definition: PenningTrap.hpp:35
+
PenningTrap::simulate
simulation_t simulate(double time, uint steps, std::string method="rk4", bool particle_interaction=true)
Simulate the particle system inside the Penning trap over a certain amount of time.
Definition: PenningTrap.cpp:228
+
PenningTrap::force_on_particle
vec3 force_on_particle(uint i, uint j)
Calculate the force between 2 particles.
Definition: PenningTrap.cpp:119
+
PenningTrap::r_func
vec3 r_func(uint i, uint j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:82
+
PenningTrap::t
double t
Current time.
Definition: PenningTrap.hpp:38
+
PenningTrap::total_force
vec3 total_force(uint i)
calculate the total force on a particle p_i.
Definition: PenningTrap.cpp:155
+
PenningTrap::set_pertubation
void set_pertubation(double f, double omega_V)
Time dependent perturbation to V_0.
Definition: PenningTrap.cpp:46
+
PenningTrap::reinitialize
void reinitialize(double f, double omega_V, double t=0.)
Give all particles new positions and velocities, and change t and V_0.
Definition: PenningTrap.cpp:53
+
PenningTrap::evolve_forward_euler
void evolve_forward_euler(double dt, bool particle_interaction=true)
Go forward one timestep using the forward Euler method.
Definition: PenningTrap.cpp:201
+
PenningTrap::fraction_of_particles_left
double fraction_of_particles_left(double time, uint steps, std::string method="rk4", bool particle_interaction=true)
Simulate and calculate what fraction of particles are still left inside the Penning trap after the si...
Definition: PenningTrap.cpp:297
+
PenningTrap::write_simulation_to_dir
void write_simulation_to_dir(std::string path, double time, uint steps, std::string method="rk4", bool particle_interaction=true)
Simulate and write the displacement of all particles to files.
Definition: PenningTrap.cpp:259
+
PenningTrap::perturbation
std::function< double(double)> perturbation
Time-dependent perturbation.
Definition: PenningTrap.hpp:36
+
PenningTrap::k_v
sim_arr k_v
Definition: PenningTrap.hpp:40
constants.hpp
Library of constants.
-
T
#define T
1 Tesla. unit:
Definition: constants.hpp:17
-
V
#define V
1 Volt. unit:
Definition: constants.hpp:19
+
T
#define T
1 Tesla. unit:
Definition: constants.hpp:21
+
V
#define V
1 Volt. unit:
Definition: constants.hpp:25
simulation
Typedef for PenningTrap::simulation return value.
Definition: typedefs.hpp:40
typedefs.hpp
Useful typedefs for cleaner code.
-
vec_3d
arma::vec::fixed< 3 > vec_3d
Typedef for a fixed 3d arma vector.
Definition: typedefs.hpp:36
-
sim_arr
std::vector< sim_cols > sim_arr
Typedef for the result of the simulate method.
Definition: typedefs.hpp:32
+
vec3
arma::vec::fixed< 3 > vec3
Typedef for a fixed 3d arma vector.
Definition: typedefs.hpp:23
+
sim_arr
std::vector< sim_cols > sim_arr
Typedef for the result of the simulate method.
Definition: typedefs.hpp:36
utils.hpp
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 0475106..6367e48 100644 --- a/docs/animate__100__particles_8py_source.html +++ b/docs/animate__100__particles_8py_source.html @@ -135,7 +135,7 @@ $(document).ready(function(){initNavTree('animate__100__particles_8py_source.htm
32 fig = plt.figure()
33 ax = fig.add_subplot(projection="3d")
34
-
35 arr = get_data([f"output/simulate_100_particles/particle_{i}.txt" for i in range(100)])
+
35 arr = get_data([f"output/simulate_100_particles/particle_{i}_r.txt" for i in range(100)])
36
37 arr = arr[:, :, ::10]
38
diff --git a/docs/annotated_dup.js b/docs/annotated_dup.js index c52b935..37a2cab 100644 --- a/docs/annotated_dup.js +++ b/docs/annotated_dup.js @@ -2,6 +2,6 @@ var annotated_dup = [ [ "Particle", "classParticle.html", "classParticle" ], [ "PenningTrap", "classPenningTrap.html", "classPenningTrap" ], - [ "PenningTrapTest", "classPenningTrapTest.html", null ], + [ "PenningTrapTest", "classPenningTrapTest.html", "classPenningTrapTest" ], [ "simulation", "structsimulation.html", null ] ]; \ No newline at end of file diff --git a/docs/classParticle-members.html b/docs/classParticle-members.html index b3fc92b..2bb47b5 100644 --- a/docs/classParticle-members.html +++ b/docs/classParticle-members.html @@ -105,11 +105,11 @@ $(document).ready(function(){initNavTree('classParticle.html',''); initResizable

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

- + - - + +
mParticleprivate
Particle(double q, double m, vec_3d r_vec, vec_3d v_vec)Particle
Particle(vec3 r_vec, vec3 v_vec, double q=CA_CHARGE, double m=CA_MASS)Particle
PenningTrapParticlefriend
qParticleprivate
r_vecParticleprivate
v_vecParticleprivate
r_vecParticleprivate
v_vecParticleprivate
diff --git a/docs/classParticle.html b/docs/classParticle.html index 271a213..c413211 100644 --- a/docs/classParticle.html +++ b/docs/classParticle.html @@ -114,24 +114,24 @@ $(document).ready(function(){initNavTree('classParticle.html',''); initResizable - - - + + +

Public Member Functions

 Particle (double q, double m, vec_3d r_vec, vec_3d v_vec)
 Initialize the particle.
 
 Particle (vec3 r_vec, vec3 v_vec, double q=CA_CHARGE, double m=CA_MASS)
 Initialize the particle.
 
+ + + + + + - - - - - -

Private Attributes

vec3 r_vec
 position
 
vec3 v_vec
 velocity
 
double q
 Charge.
 
double m
 Mass.
 
vec_3d r_vec
 position
 
vec_3d v_vec
 velocity
 
@@ -142,10 +142,10 @@ Friends

Detailed Description

A class that holds attributes of a particle.

-

Definition at line 21 of file Particle.hpp.

+

Definition at line 22 of file Particle.hpp.

Constructor & Destructor Documentation

- -

◆ Particle()

+ +

◆ Particle()

@@ -153,26 +153,26 @@ Friends
- - - - - - - - - - - - - + - - + + + + + + + + + + + + + + @@ -221,7 +221,7 @@ Friends

Make private attributes available for PenningTrap.

-

Definition at line 43 of file Particle.hpp.

+

Definition at line 45 of file Particle.hpp.

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

Mass.

-

Definition at line 24 of file Particle.hpp.

+

Definition at line 28 of file Particle.hpp.

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

Charge.

-

Definition at line 23 of file Particle.hpp.

+

Definition at line 27 of file Particle.hpp.

- -

◆ r_vec

+ +

◆ r_vec

@@ -288,7 +288,7 @@ Friends
@@ -304,8 +304,8 @@ Friends - -

◆ v_vec

+ +

◆ v_vec

@@ -314,7 +314,7 @@ Friends
diff --git a/docs/classParticle.js b/docs/classParticle.js index 71255c1..9ffef17 100644 --- a/docs/classParticle.js +++ b/docs/classParticle.js @@ -1,9 +1,9 @@ var classParticle = [ - [ "Particle", "classParticle.html#a7af9f8d1fef63dd7643b06629ac7bef4", null ], + [ "Particle", "classParticle.html#af1d7535fb8311eaa77d2b7b345882ec4", null ], [ "PenningTrap", "classParticle.html#aa797d319549dc2a0beb06cdbfd430232", null ], [ "m", "classParticle.html#aedcc7e1bc53b0e2b1a4a07c9a1b47563", null ], [ "q", "classParticle.html#a566dcc1de4bdc01251776948798ea8e1", null ], - [ "r_vec", "classParticle.html#af9497cd8f2dcad0fad54f571ddb383e6", null ], - [ "v_vec", "classParticle.html#a879692772803d6ab65fa4993b54aea6e", null ] + [ "r_vec", "classParticle.html#a1c59101411db43624828b766f87ad460", null ], + [ "v_vec", "classParticle.html#a3a10400add8dd22b8031330c2aafb6fe", null ] ]; \ No newline at end of file diff --git a/docs/classPenningTrap-members.html b/docs/classPenningTrap-members.html index 973ffb0..d4bca01 100644 --- a/docs/classPenningTrap-members.html +++ b/docs/classPenningTrap-members.html @@ -109,27 +109,29 @@ $(document).ready(function(){initNavTree('classPenningTrap.html',''); initResiza - - - - - - + + + + - - - - - + + + + + + + + + - - - - - - + + + + + +

Friends

Particle::Particle (double q,
double m,
vec_3d vec3  r_vec,
vec_3d v_vec vec3 v_vec,
double q = CA_CHARGE,
double m = CA_MASS 
- +
vec_3d Particle::r_vecvec3 Particle::r_vec
- +
vec_3d Particle::v_vecvec3 Particle::v_vec
dPenningTrapprivate
evolve_forward_euler(double dt, bool particle_interaction=true)PenningTrap
evolve_RK4(double dt, bool particle_interaction=true)PenningTrap
external_B_field(vec_3d r)PenningTrap
external_E_field(vec_3d r)PenningTrap
force_on_particle(unsigned int i, unsigned int j)PenningTrap
fraction_of_particles_left(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)PenningTrap
get_r(int i) (defined in PenningTrap)PenningTrap
get_t() (defined in PenningTrap)PenningTrap
external_B_field(vec3 r)PenningTrapprivate
external_E_field(vec3 r)PenningTrapprivate
force_on_particle(uint i, uint j)PenningTrapprivate
fraction_of_particles_left(double time, uint steps, std::string method="rk4", bool particle_interaction=true)PenningTrap
k_rPenningTrapprivate
k_vPenningTrapprivate
particlesPenningTrapprivate
PenningTrap(double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)PenningTrap
PenningTrap(unsigned int i, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)PenningTrap
PenningTrap(std::vector< Particle > particles, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)PenningTrap
r_func(unsigned int i, unsigned int j, double dt)PenningTrapprivate
simulate(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)PenningTrap
PenningTrap(double B_0=T, double V_0=(25. *V)/1000., double d=500., double t=0.)PenningTrap
PenningTrap(uint i, double B_0=T, double V_0=(25. *V)/1000., double d=500., double t=0.)PenningTrap
PenningTrap(std::vector< Particle > particles, double B_0=T, double V_0=(25. *V)/1000., double d=500., double t=0.)PenningTrap
PenningTrapTest (defined in PenningTrap)PenningTrapfriend
perturbationPenningTrapprivate
r_func(uint i, uint j, double dt)PenningTrapprivate
reinitialize(double f, double omega_V, double t=0.)PenningTrap
set_pertubation(double f, double omega_V)PenningTrap
simulate(double time, uint steps, std::string method="rk4", bool particle_interaction=true)PenningTrap
tPenningTrapprivate
total_force(unsigned int i)PenningTrap
total_force_external(unsigned int i)PenningTrap
total_force_particles(unsigned int i)PenningTrap
V_0PenningTrapprivate
v_func(unsigned int i, unsigned int j, double dt)PenningTrapprivate
write_simulation_to_dir(std::string path, double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)PenningTrap
total_force(uint i)PenningTrapprivate
total_force_external(uint i)PenningTrapprivate
total_force_particles(uint i)PenningTrapprivate
V_0PenningTrapprivate
v_func(uint i, uint j, double dt)PenningTrapprivate
write_simulation_to_dir(std::string path, double time, uint steps, std::string method="rk4", bool particle_interaction=true)PenningTrap
diff --git a/docs/classPenningTrap.html b/docs/classPenningTrap.html index f5952a9..9be2e3b 100644 --- a/docs/classPenningTrap.html +++ b/docs/classPenningTrap.html @@ -102,6 +102,7 @@ $(document).ready(function(){initNavTree('classPenningTrap.html',''); initResiza Public Member Functions | Private Member Functions | Private Attributes | +Friends | List of all members
PenningTrap Class Reference
@@ -114,73 +115,78 @@ $(document).ready(function(){initNavTree('classPenningTrap.html',''); initResiza - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + +

Public Member Functions

 PenningTrap (double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)
 Constructor for the PenningTrap class.
 
 PenningTrap (unsigned int i, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)
 Constructor for the PenningTrap class.
 
 PenningTrap (std::vector< Particle > particles, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.)
 Constructor for the PenningTrap class.
 
 PenningTrap (double B_0=T, double V_0=(25. *V)/1000., double d=500., double t=0.)
 Constructor for the PenningTrap class.
 
 PenningTrap (uint i, double B_0=T, double V_0=(25. *V)/1000., double d=500., double t=0.)
 Constructor for the PenningTrap class.
 
 PenningTrap (std::vector< Particle > particles, double B_0=T, double V_0=(25. *V)/1000., double d=500., double t=0.)
 Constructor for the PenningTrap class.
 
void set_pertubation (double f, double omega_V)
 Time dependent perturbation to V_0.
 
void reinitialize (double f, double omega_V, double t=0.)
 Give all particles new positions and velocities, and change t and V_0.
 
void add_particle (Particle particle)
 Add a particle to the system.
 
vec_3d external_E_field (vec_3d r)
 Calculate E at point r.
 
vec_3d external_B_field (vec_3d r)
 Calculate B at point r.
 
vec_3d force_on_particle (unsigned int i, unsigned int j)
 Calculate the force between 2 particles.
 
vec_3d total_force_external (unsigned int i)
 Calculate the total external force on a particle.
 
vec_3d total_force_particles (unsigned int i)
 Calculate the total force on a particle p_i from other particles.
 
vec_3d total_force (unsigned int i)
 calculate the total force on a particle p_i.
 
void evolve_RK4 (double dt, bool particle_interaction=true)
 Go forward one timestep using the RK4 method.
 
void evolve_forward_euler (double dt, bool particle_interaction=true)
 Go forward one timestep using the forward Euler method.
 
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 ()
 
simulation_t simulate (double time, uint 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, uint 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, uint steps, std::string method="rk4", bool particle_interaction=true)
 Simulate and calculate what fraction of particles are still left inside the Penning trap after the simulation.
 
- - - - - - + + + + + + + + + + + + + + + + + + + + + + + +

Private Member Functions

vec_3d v_func (unsigned int i, unsigned int j, double dt)
 Helper for evolve_RK4 when calculating \(k_{v,i,j}\) values.
 
vec_3d r_func (unsigned int i, unsigned int j, double dt)
 Helper for evolve_RK4 when calculating \(k_{r,i,j}\) values.
 
vec3 v_func (uint i, uint j, double dt)
 Helper for evolve_RK4 when calculating \(k_{v,i,j}\) values.
 
vec3 r_func (uint i, uint j, double dt)
 Helper for evolve_RK4 when calculating \(k_{r,i,j}\) values.
 
vec3 external_E_field (vec3 r)
 Calculate E at point r.
 
vec3 external_B_field (vec3 r)
 Calculate B at point r.
 
vec3 force_on_particle (uint i, uint j)
 Calculate the force between 2 particles.
 
vec3 total_force_external (uint i)
 Calculate the total external force on a particle.
 
vec3 total_force_particles (uint i)
 Calculate the total force on a particle p_i from other particles.
 
vec3 total_force (uint i)
 calculate the total force on a particle p_i.
 
- - - + + + + + + @@ -194,6 +200,11 @@ Private Attributes +

Private Attributes

double B_0
 Magnetic field strength.
 
std::function< double(double)> V_0
 Applied potential.
 
double V_0
 Applied potential.
 
std::function< double(double)> perturbation
 Time-dependent perturbation.
 
double d
 Characteristic dimension.
 
 
sim_arr k_r
 
+ + +

+Friends

class PenningTrapTest
 

Detailed Description

A class that simulates a Penning trap.

@@ -201,8 +212,8 @@ Private Attributes

Definition at line 31 of file PenningTrap.hpp.

Constructor & Destructor Documentation

- -

◆ PenningTrap() [1/3]

+ +

◆ PenningTrap() [1/3]

@@ -216,8 +227,8 @@ Private Attributes - std::function< double(double)>  - V_0 = [](double t) { return 25. * V / 1000.; }, + double  + V_0 = (25. * V) / 1000., @@ -250,12 +261,12 @@ Private Attributes -

Definition at line 15 of file PenningTrap.cpp.

+

Definition at line 20 of file PenningTrap.cpp.

- -

◆ PenningTrap() [2/3]

+ +

◆ PenningTrap() [2/3]

@@ -263,7 +274,7 @@ Private Attributes PenningTrap::PenningTrap ( - unsigned int  + uint  i, @@ -275,8 +286,8 @@ Private Attributes - std::function< double(double)>  - V_0 = [](double t) { return 25. * V / 1000.; }, + double  + V_0 = (25. * V) / 1000., @@ -310,12 +321,12 @@ Private Attributes -

Definition at line 24 of file PenningTrap.cpp.

+

Definition at line 29 of file PenningTrap.cpp.

- -

◆ PenningTrap() [3/3]

+ +

◆ PenningTrap() [3/3]

@@ -335,8 +346,8 @@ Private Attributes - std::function< double(double)>  - V_0 = [](double t) { return 25. * V / 1000.; }, + double  + V_0 = (25. * V) / 1000., @@ -370,7 +381,7 @@ Private Attributes -

Definition at line 36 of file PenningTrap.cpp.

+

Definition at line 39 of file PenningTrap.cpp.

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

Definition at line 79 of file PenningTrap.cpp.

+

Definition at line 101 of file PenningTrap.cpp.

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

Definition at line 183 of file PenningTrap.cpp.

+

Definition at line 201 of file PenningTrap.cpp.

@@ -477,24 +488,32 @@ Private Attributes -

Definition at line 148 of file PenningTrap.cpp.

+

Definition at line 163 of file PenningTrap.cpp.

- -

◆ external_B_field()

+ +

◆ external_B_field()

+ + + + + +
- + - +
vec_3d PenningTrap::external_B_field vec3 PenningTrap::external_B_field (vec_3d vec3  r)
+
+private

Calculate B at point r.

@@ -504,26 +523,34 @@ Private Attributes -
Returns
vec_3d
+
Returns
vec3
-

Definition at line 92 of file PenningTrap.cpp.

+

Definition at line 114 of file PenningTrap.cpp.

- -

◆ external_E_field()

+ +

◆ external_E_field()

+ + + + + +
- + - +
vec_3d PenningTrap::external_E_field vec3 PenningTrap::external_E_field (vec_3d vec3  r)
+
+private

Calculate E at point r.

@@ -533,28 +560,31 @@ Private Attributes -
Returns
vec_3d
+
Returns
vec3
-

Definition at line 84 of file PenningTrap.cpp.

+

Definition at line 106 of file PenningTrap.cpp.

- -

◆ force_on_particle()

+ +

◆ force_on_particle()

+ + + + + +
- + - + - + @@ -563,6 +593,11 @@ Private Attributes
vec_3d PenningTrap::force_on_particle vec3 PenningTrap::force_on_particle (unsigned int uint  i,
unsigned int uint  j 
+
+private

Calculate the force between 2 particles.

@@ -574,14 +609,14 @@ Private Attributes -
Returns
vec_3d
+
Returns
vec3
-

Definition at line 97 of file PenningTrap.cpp.

+

Definition at line 119 of file PenningTrap.cpp.

- -

◆ fraction_of_particles_left()

+ +

◆ fraction_of_particles_left()

@@ -595,7 +630,7 @@ Private Attributes - unsigned int  + uint  steps, @@ -630,51 +665,12 @@ Private Attributes
Returns
double
-

Definition at line 281 of file PenningTrap.cpp.

+

Definition at line 297 of file PenningTrap.cpp.

- -

◆ get_r()

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

- -
-
- -

◆ r_func()

+ +

◆ r_func()

@@ -683,15 +679,15 @@ Private Attributes - + - + - + @@ -723,14 +719,97 @@ Private Attributes
vec_3d PenningTrap::r_func vec3 PenningTrap::r_func (unsigned int uint  i,
unsigned int uint  j,
-
Returns
vec_3d
+
Returns
vec3
-

Definition at line 61 of file PenningTrap.cpp.

+

Definition at line 82 of file PenningTrap.cpp.

- -

◆ simulate()

+ +

◆ reinitialize()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void PenningTrap::reinitialize (double f,
double omega_V,
double t = 0. 
)
+
+ +

Give all particles new positions and velocities, and change t and V_0.

+
Parameters
+ + + +
V_0The tiome dependent applied potential
tThe starting time
+
+
+ +

Definition at line 53 of file PenningTrap.cpp.

+ +
+
+ +

◆ set_pertubation()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void PenningTrap::set_pertubation (double f,
double omega_V 
)
+
+ +

Time dependent perturbation to V_0.

+
Parameters
+ + +
fThe amplitude of the perturbation @parma omega_V the angular frequency of the perturbation
+
+
+ +

Definition at line 46 of file PenningTrap.cpp.

+ +
+
+ +

◆ simulate()

@@ -744,7 +823,7 @@ Private Attributes - unsigned int  + uint  steps, @@ -779,24 +858,32 @@ Private Attributes
Returns
simulation_t
-

Definition at line 212 of file PenningTrap.cpp.

+

Definition at line 228 of file PenningTrap.cpp.

- -

◆ total_force()

+ +

◆ total_force()

+ + + + + +
- + - +
vec_3d PenningTrap::total_force vec3 PenningTrap::total_force (unsigned int uint  i)
+
+private

calculate the total force on a particle p_i.

@@ -806,26 +893,34 @@ Private Attributes -
Returns
vec_3d
+
Returns
vec3
-

Definition at line 140 of file PenningTrap.cpp.

+

Definition at line 155 of file PenningTrap.cpp.

- -

◆ total_force_external()

+ +

◆ total_force_external()

+ + + + + +
- + - +
vec_3d PenningTrap::total_force_external vec3 PenningTrap::total_force_external (unsigned int uint  i)
+
+private

Calculate the total external force on a particle.

@@ -836,26 +931,34 @@ Private Attributes -
Returns
vec_3d
+
Returns
vec3
-

Definition at line 108 of file PenningTrap.cpp.

+

Definition at line 130 of file PenningTrap.cpp.

- -

◆ total_force_particles()

+ +

◆ total_force_particles()

+ + + + + +
- + - +
vec_3d PenningTrap::total_force_particles vec3 PenningTrap::total_force_particles (unsigned int uint  i)
+
+private

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

@@ -865,14 +968,14 @@ Private Attributes -
Returns
vec_3d
+
Returns
vec3
-

Definition at line 123 of file PenningTrap.cpp.

+

Definition at line 143 of file PenningTrap.cpp.

- -

◆ v_func()

+ +

◆ v_func()

@@ -881,15 +984,15 @@ Private Attributes - + - + - + @@ -921,14 +1024,14 @@ Private Attributes
vec_3d PenningTrap::v_func vec3 PenningTrap::v_func (unsigned int uint  i,
unsigned int uint  j,
-
Returns
vec_3d
+
Returns
vec3
-

Definition at line 43 of file PenningTrap.cpp.

+

Definition at line 63 of file PenningTrap.cpp.

- -

◆ write_simulation_to_dir()

+ +

◆ write_simulation_to_dir()

@@ -948,7 +1051,7 @@ Private Attributes - unsigned int  + uint  steps, @@ -983,7 +1086,32 @@ Private Attributes -

Definition at line 246 of file PenningTrap.cpp.

+

Definition at line 259 of file PenningTrap.cpp.

+ +
+
+

Friends And Related Function Documentation

+ +

◆ PenningTrapTest

+ +
+
+ + + + + +
+ + + + +
friend class PenningTrapTest
+
+friend
+
+ +

Definition at line 232 of file PenningTrap.hpp.

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

Magnetic field strength.

-

Definition at line 33 of file PenningTrap.hpp.

+

Definition at line 34 of file PenningTrap.hpp.

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

Characteristic dimension.

-

Definition at line 35 of file PenningTrap.hpp.

+

Definition at line 37 of file PenningTrap.hpp.

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

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

-

Definition at line 40 of file PenningTrap.hpp.

+

Definition at line 42 of file PenningTrap.hpp.

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

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

-

Definition at line 38 of file PenningTrap.hpp.

+

Definition at line 40 of file PenningTrap.hpp.

@@ -1112,7 +1240,33 @@ Private Attributes

The particles in the Penning trap.

-

Definition at line 37 of file PenningTrap.hpp.

+

Definition at line 39 of file PenningTrap.hpp.

+ + + + +

◆ perturbation

+ +
+
+ + + + + +
+ + + + +
std::function<double(double)> PenningTrap::perturbation
+
+private
+
+ +

Time-dependent perturbation.

+ +

Definition at line 36 of file PenningTrap.hpp.

@@ -1138,12 +1292,12 @@ Private Attributes

Current time.

-

Definition at line 36 of file PenningTrap.hpp.

+

Definition at line 38 of file PenningTrap.hpp.

- -

◆ V_0

+ +

◆ V_0

@@ -1152,7 +1306,7 @@ Private Attributes - +
std::function<double(double)> PenningTrap::V_0double PenningTrap::V_0
@@ -1164,7 +1318,7 @@ Private Attributes

Applied potential.

-

Definition at line 34 of file PenningTrap.hpp.

+

Definition at line 35 of file PenningTrap.hpp.

diff --git a/docs/classPenningTrap.js b/docs/classPenningTrap.js index c3edebd..987c84c 100644 --- a/docs/classPenningTrap.js +++ b/docs/classPenningTrap.js @@ -1,27 +1,30 @@ var classPenningTrap = [ - [ "PenningTrap", "classPenningTrap.html#ae670d7de621acdb343b01af098086f63", null ], - [ "PenningTrap", "classPenningTrap.html#a763700316b502d5900e587c1f61e6bf1", null ], - [ "PenningTrap", "classPenningTrap.html#a67139e04ef69c0bcffde8f30f67cbf73", null ], + [ "PenningTrap", "classPenningTrap.html#a5b6c6d4636f3a6e279ccde59d4a345e8", null ], + [ "PenningTrap", "classPenningTrap.html#a830be1b8cbf59664e060b6edbeaa302f", null ], + [ "PenningTrap", "classPenningTrap.html#addc96789dcfec07b75156e19fee82f4f", null ], [ "add_particle", "classPenningTrap.html#a6e9776ff5b149f01080800716455d7c8", null ], [ "evolve_forward_euler", "classPenningTrap.html#ab9ea97a406534bbe621a95215144875e", null ], [ "evolve_RK4", "classPenningTrap.html#a36946152fd951b1f7c346c51ff900d8e", null ], - [ "external_B_field", "classPenningTrap.html#acbf065c9c125682329ad82a8d166554c", null ], - [ "external_E_field", "classPenningTrap.html#a1d58feaa2c9e34cbf26b1c5ed75ca9d9", null ], - [ "force_on_particle", "classPenningTrap.html#a9ae34ad740a230e667e96bc6ee8730ce", null ], - [ "fraction_of_particles_left", "classPenningTrap.html#a0194be61c956a9259c747c23e4163c5b", null ], - [ "r_func", "classPenningTrap.html#a43e74792ab4b3f9299f35cb64bdb2648", null ], - [ "simulate", "classPenningTrap.html#ae09ef9cfa7e4ed1c108c8576405b3599", null ], - [ "total_force", "classPenningTrap.html#a1f668c4433421136ad51741741aa1bc8", null ], - [ "total_force_external", "classPenningTrap.html#ae72d203b0bfa1b9e72bea28cb2863c56", null ], - [ "total_force_particles", "classPenningTrap.html#a46a954a0946def199e30fb300ba1c47b", null ], - [ "v_func", "classPenningTrap.html#af98a720da60b0e1a62aefa5f5cb37c1e", null ], - [ "write_simulation_to_dir", "classPenningTrap.html#abbb832a85139b1a56ebde57d7b8f9a57", null ], + [ "external_B_field", "classPenningTrap.html#a361f2c4862c90b5e8e2a2f50c6a95655", null ], + [ "external_E_field", "classPenningTrap.html#a5846c8f75cdc543fd9cf0b2185a3ef22", null ], + [ "force_on_particle", "classPenningTrap.html#a7f210bb2768a5d79ced4b0df0df97598", null ], + [ "fraction_of_particles_left", "classPenningTrap.html#ac529aa26c288f34eae184a67e6bac41f", null ], + [ "r_func", "classPenningTrap.html#a826b7fa8e709d481eb1dee7d0c2cdc08", null ], + [ "reinitialize", "classPenningTrap.html#aaee129f177657455348d0c8ae1441dea", null ], + [ "set_pertubation", "classPenningTrap.html#a9d1d8e90ca839b928aee1ad0cd4aff43", null ], + [ "simulate", "classPenningTrap.html#a7a1d9f0528a12308de25bc30718da20a", null ], + [ "total_force", "classPenningTrap.html#a9a301b0540078c36697880ef204afdf3", null ], + [ "total_force_external", "classPenningTrap.html#a2c01108b52c8e2a003cf9170da9e7682", null ], + [ "total_force_particles", "classPenningTrap.html#a2fe1cefbae18fa5808155ee0d2df713c", null ], + [ "v_func", "classPenningTrap.html#a3c0a44e4e0a94366ff609e81fe463fa2", null ], + [ "write_simulation_to_dir", "classPenningTrap.html#ad8bc4df7ab3eed53b16cfdff38e7760b", null ], [ "B_0", "classPenningTrap.html#a0cac3509aa96e71a26d3b2c902e27716", null ], [ "d", "classPenningTrap.html#a66dfe89c68716b9502927b97f59c27d2", null ], [ "k_r", "classPenningTrap.html#a2f168622587709b9e3c49077f0b9a640", null ], [ "k_v", "classPenningTrap.html#ae9b5afdaa5cd366e94bd294452a1eed4", null ], [ "particles", "classPenningTrap.html#a0112525d9e79a472e761f8ef402a339f", null ], + [ "perturbation", "classPenningTrap.html#ae915f6ad0eef1fb46530e836b6e071e5", null ], [ "t", "classPenningTrap.html#a8ca4e21291f60fde619c14099d8c4e8e", null ], - [ "V_0", "classPenningTrap.html#aaf105828121c4a33cc2b217453c20317", null ] + [ "V_0", "classPenningTrap.html#a715329844d75ec4c04f8391421fb4e89", null ] ]; \ No newline at end of file diff --git a/docs/classPenningTrapTest-members.html b/docs/classPenningTrapTest-members.html index 6a01a89..a1728e4 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()PenningTrapTestinlinestatic
test_external_E_field()PenningTrapTestinlinestatic
test_force_on_particle()PenningTrapTestinlinestatic
test_total_force_external()PenningTrapTestinlinestatic
test_total_force_particles()PenningTrapTestinlinestatic
test_external_B_field()PenningTrapTestinline
test_external_E_field()PenningTrapTestinline
test_force_on_particle()PenningTrapTestinline
test_total_force_external()PenningTrapTestinline
test_total_force_particles()PenningTrapTestinline
diff --git a/docs/classPenningTrapTest.html b/docs/classPenningTrapTest.html index b058407..e679696 100644 --- a/docs/classPenningTrapTest.html +++ b/docs/classPenningTrapTest.html @@ -99,7 +99,7 @@ $(document).ready(function(){initNavTree('classPenningTrapTest.html',''); initRe
-Static Public Member Functions | +Public Member Functions | List of all members
PenningTrapTest Class Reference
@@ -108,31 +108,31 @@ $(document).ready(function(){initNavTree('classPenningTrapTest.html',''); initRe

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.
 

+Public Member Functions

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

Detailed Description

Test class for the Penning trap.

-

Definition at line 22 of file test_suite.cpp.

+

Definition at line 23 of file test_suite.cpp.

Member Function Documentation

- -

◆ test_external_B_field()

+ +

◆ test_external_B_field()

@@ -141,7 +141,7 @@ Static Public Member Functions - + @@ -149,19 +149,19 @@ Static Public Member Functions
static void PenningTrapTest::test_external_B_field void PenningTrapTest::test_external_B_field ( )
-inlinestatic +inline

Test that the external B field gives correct values.

-

Definition at line 65 of file test_suite.cpp.

+

Definition at line 66 of file test_suite.cpp.

- -

◆ test_external_E_field()

+ +

◆ test_external_E_field()

@@ -170,7 +170,7 @@ Static Public Member Functions - + @@ -178,19 +178,19 @@ Static Public Member Functions
static void PenningTrapTest::test_external_E_field void PenningTrapTest::test_external_E_field ( )
-inlinestatic +inline

Test that the external E field gives correct values.

-

Definition at line 26 of file test_suite.cpp.

+

Definition at line 28 of file test_suite.cpp.

- -

◆ test_force_on_particle()

+ +

◆ test_force_on_particle()

@@ -199,7 +199,7 @@ Static Public Member Functions - + @@ -207,19 +207,19 @@ Static Public Member Functions
static void PenningTrapTest::test_force_on_particle void PenningTrapTest::test_force_on_particle ( )
-inlinestatic +inline

Test that the force between particles gives expected results.

-

Definition at line 78 of file test_suite.cpp.

+

Definition at line 80 of file test_suite.cpp.

- -

◆ test_total_force_external()

+ +

◆ test_total_force_external()

@@ -228,7 +228,7 @@ Static Public Member Functions - + @@ -236,19 +236,19 @@ Static Public Member Functions
static void PenningTrapTest::test_total_force_external void PenningTrapTest::test_total_force_external ( )
-inlinestatic +inline

Test that the total external force returns expected results.

-

Definition at line 105 of file test_suite.cpp.

+

Definition at line 107 of file test_suite.cpp.

- -

◆ test_total_force_particles()

+ +

◆ test_total_force_particles()

@@ -257,7 +257,7 @@ Static Public Member Functions - + @@ -265,14 +265,14 @@ Static Public Member Functions
static void PenningTrapTest::test_total_force_particles void PenningTrapTest::test_total_force_particles ( )
-inlinestatic +inline

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

-

Definition at line 121 of file test_suite.cpp.

+

Definition at line 122 of file test_suite.cpp.

diff --git a/docs/classPenningTrapTest.js b/docs/classPenningTrapTest.js new file mode 100644 index 0000000..54d09ee --- /dev/null +++ b/docs/classPenningTrapTest.js @@ -0,0 +1,8 @@ +var classPenningTrapTest = +[ + [ "test_external_B_field", "classPenningTrapTest.html#ad668d7d875bdc1909a42426bf9dead9e", null ], + [ "test_external_E_field", "classPenningTrapTest.html#a6a303be62039ca2ecccd8252744d4dc8", null ], + [ "test_force_on_particle", "classPenningTrapTest.html#a5f4f0b150e54ce463bb29f76d49883f9", null ], + [ "test_total_force_external", "classPenningTrapTest.html#ae6d0c8e0d80338fb7c7edefc97331046", null ], + [ "test_total_force_particles", "classPenningTrapTest.html#a68449d508e66205bc8b27fa5f60db508", null ] +]; \ No newline at end of file diff --git a/docs/constants_8hpp.html b/docs/constants_8hpp.html index 8c5aceb..8119c18 100644 --- a/docs/constants_8hpp.html +++ b/docs/constants_8hpp.html @@ -111,26 +111,68 @@ $(document).ready(function(){initNavTree('constants_8hpp.html',''); initResizabl - + - + - + + + + + + +

Macros

#define K_E   138935.333
#define K_E   1.38935333 * 1e5
 Coulomb constant. unit: \(\frac{u(\mu m)^3}{(\mu s)^2 e^2}\).
 
#define T   96.4852558
#define T   9.64852558 * 1e1
 1 Tesla. unit: \( \frac{u}{(\mu s) e} \)
 
#define V   96485255.8
#define V   9.64852558 * 1e7
 1 Volt. unit: \( \frac{u (\mu m)^2}{(\mu s)^2 e} \)
 
#define CA_MASS   40.078
 Mass of a single calcium ion. unit: amu.
 
#define CA_CHARGE   1.
 Charge of a singly charged calcium ion. unit: e.
 

Detailed Description

Library of constants.

Author
Cory Alexander Balaton (coryab)
Janita Ovidie Sandtrøen Willumsen (janitaws)
-
Version
0.1
+
Version
1.0
Bug:
No known bugs

Definition in file constants.hpp.

Macro Definition Documentation

+ +

◆ CA_CHARGE

+ +
+
+ + + + +
#define CA_CHARGE   1.
+
+ +

Charge of a singly charged calcium ion. unit: e.

+ +

Definition at line 33 of file constants.hpp.

+ +
+
+ +

◆ CA_MASS

+ +
+
+ + + + +
#define CA_MASS   40.078
+
+ +

Mass of a single calcium ion. unit: amu.

+ +

Definition at line 29 of file constants.hpp.

+ +
+

◆ K_E

@@ -138,14 +180,14 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
- +
#define K_E   138935.333#define K_E   1.38935333 * 1e5

Coulomb constant. unit: \(\frac{u(\mu m)^3}{(\mu s)^2 e^2}\).

-

Definition at line 15 of file constants.hpp.

+

Definition at line 17 of file constants.hpp.

@@ -156,14 +198,14 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
- +
#define T   96.4852558#define T   9.64852558 * 1e1

1 Tesla. unit: \( \frac{u}{(\mu s) e} \)

-

Definition at line 17 of file constants.hpp.

+

Definition at line 21 of file constants.hpp.

@@ -174,14 +216,14 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
- +
#define V   96485255.8#define V   9.64852558 * 1e7

1 Volt. unit: \( \frac{u (\mu m)^2}{(\mu s)^2 e} \)

-

Definition at line 19 of file constants.hpp.

+

Definition at line 25 of file constants.hpp.

diff --git a/docs/constants_8hpp.js b/docs/constants_8hpp.js index a4eb8d0..10edb33 100644 --- a/docs/constants_8hpp.js +++ b/docs/constants_8hpp.js @@ -1,5 +1,7 @@ var constants_8hpp = [ + [ "CA_CHARGE", "constants_8hpp.html#af7602a3a314957137ad1cd719aa23789", null ], + [ "CA_MASS", "constants_8hpp.html#a2ff491cc7958ffd5e749c518a4a60ec8", null ], [ "K_E", "constants_8hpp.html#a4e451456ad7e9276ed0afa42826e7ccb", null ], [ "T", "constants_8hpp.html#a0acb682b8260ab1c60b918599864e2e5", null ], [ "V", "constants_8hpp.html#af40a326b23c68a27cebe60f16634a2cb", null ] diff --git a/docs/constants_8hpp_source.html b/docs/constants_8hpp_source.html index a9f3f8b..a2f06fc 100644 --- a/docs/constants_8hpp_source.html +++ b/docs/constants_8hpp_source.html @@ -105,13 +105,17 @@ $(document).ready(function(){initNavTree('constants_8hpp_source.html',''); initR
12#ifndef __CONST__
13#define __CONST__
14
-
15#define K_E 138935.333
-
16
-
17#define T 96.4852558
+
17#define K_E 1.38935333 * 1e5
18
-
19#define V 96485255.8
-
20
-
21#endif
+
21#define T 9.64852558 * 1e1
+
22
+
25#define V 9.64852558 * 1e7
+
26
+
29#define CA_MASS 40.078
+
30
+
33#define CA_CHARGE 1.
+
34
+
35#endif
diff --git a/docs/functions.html b/docs/functions.html index cc1a7e4..c2f9801 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -118,14 +118,14 @@ $(document).ready(function(){initNavTree('functions.html',''); initResizable();

- e -

- f -

@@ -141,9 +141,10 @@ $(document).ready(function(){initNavTree('functions.html',''); initResizable();

- p -

@@ -153,38 +154,40 @@ $(document).ready(function(){initNavTree('functions.html',''); initResizable();

- r -

- s -

- t -

- v -

- w -

diff --git a/docs/functions_func.html b/docs/functions_func.html index 5d4f949..1b82d50 100644 --- a/docs/functions_func.html +++ b/docs/functions_func.html @@ -102,24 +102,26 @@ $(document).ready(function(){initNavTree('functions_func.html',''); initResizabl
  • add_particle() : PenningTrap
  • evolve_forward_euler() : PenningTrap
  • evolve_RK4() : PenningTrap
  • -
  • external_B_field() : PenningTrap
  • -
  • external_E_field() : PenningTrap
  • -
  • force_on_particle() : PenningTrap
  • -
  • fraction_of_particles_left() : PenningTrap
  • -
  • Particle() : Particle
  • -
  • PenningTrap() : PenningTrap
  • -
  • r_func() : 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
  • -
  • v_func() : PenningTrap
  • -
  • write_simulation_to_dir() : PenningTrap
  • +
  • external_B_field() : PenningTrap
  • +
  • external_E_field() : PenningTrap
  • +
  • force_on_particle() : PenningTrap
  • +
  • fraction_of_particles_left() : PenningTrap
  • +
  • Particle() : Particle
  • +
  • PenningTrap() : PenningTrap
  • +
  • r_func() : PenningTrap
  • +
  • reinitialize() : PenningTrap
  • +
  • set_pertubation() : 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
  • +
  • v_func() : PenningTrap
  • +
  • write_simulation_to_dir() : PenningTrap
  • diff --git a/docs/functions_vars.html b/docs/functions_vars.html index 3ca2e5b..81cb4af 100644 --- a/docs/functions_vars.html +++ b/docs/functions_vars.html @@ -105,11 +105,12 @@ $(document).ready(function(){initNavTree('functions_vars.html',''); initResizabl
  • k_v : PenningTrap
  • m : Particle
  • particles : PenningTrap
  • +
  • perturbation : PenningTrap
  • q : Particle
  • -
  • r_vec : Particle
  • +
  • r_vec : Particle
  • t : PenningTrap
  • -
  • V_0 : PenningTrap
  • -
  • v_vec : Particle
  • +
  • V_0 : PenningTrap
  • +
  • v_vec : Particle
  • diff --git a/docs/globals.html b/docs/globals.html index 66911fb..23a1b12 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -98,30 +98,72 @@ $(document).ready(function(){initNavTree('globals.html',''); initResizable(); })
    -
    Here is a list of all documented file members with links to the documentation:
    diff --git a/docs/globals_defs.html b/docs/globals_defs.html index c7eb483..b7d9886 100644 --- a/docs/globals_defs.html +++ b/docs/globals_defs.html @@ -101,6 +101,8 @@ $(document).ready(function(){initNavTree('globals_defs.html',''); initResizable(