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
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
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
Library of constants.
#define T
1 Tesla. unit:
Definition: constants.hpp:17
#define V
1 Volt. unit:
Definition: constants.hpp:19
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