Penning Trap Simulation Simulate particle behavior inside a Penning Trap

Loading...
Searching...
No Matches
PenningTrap.hpp
Go to the documentation of this file.
1
12#ifndef __PENNING_TRAP__
13#define __PENNING_TRAP__
14
15#include <armadillo>
16#include <omp.h>
17
18#include "Particle.hpp"
19#include "constants.hpp"
20#include "typedefs.hpp"
21#include "utils.hpp"
22
23#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \
24 initializer(omp_priv = omp_orig)
25
31 class PenningTrap {
32 private:
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
67 public:
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
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
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
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
utils.hpp
Function prototypes and macros that are useful.