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(+ : vec3 : omp_out += omp_in) \
24 initializer(omp_priv = omp_orig)
25
31 class PenningTrap
32{
35 friend class PenningTrapTest;
36 private:
37 double B_0;
38 double V_0;
39 std::function<double(double)> perturbation;
40 double d;
41 double t;
42 std::vector<Particle> particles;
43
47 sim_arr k_v;
48
52 sim_arr k_r;
53
64 vec3 v_func(uint i, uint j, double dt);
65
76 vec3 r_func(uint i, uint j, double dt);
77
84 vec3 external_E_field(vec3 r);
85
92 vec3 external_B_field(vec3 r);
93
104 vec3 force_on_particle(uint i, uint j);
105
115 vec3 total_force_external(uint i);
116
124 vec3 total_force_particles(uint i);
125
132 vec3 total_force(uint i);
133
134 public:
142 PenningTrap(double B_0 = T, double V_0 = (25. * V) / 1000., double d = 500.,
143 double t = 0.);
144
153 PenningTrap(uint i, double B_0 = T, double V_0 = (25. * V) / 1000.,
154 double d = 500., double t = 0.);
155
164 PenningTrap(std::vector<Particle> particles, double B_0 = T,
165 double V_0 = (25. * V) / 1000., double d = 500., double t = 0.);
166
172 void set_pertubation(double f, double omega_V);
173
180 void reinitialize(double f, double omega_V, double t = 0.);
181
186 void add_particle(Particle particle);
187
193 void evolve_RK4(double dt, bool particle_interaction = true);
194
200 void evolve_forward_euler(double dt, bool particle_interaction = true);
201
212 simulation_t simulate(double time, uint steps, std::string method = "rk4",
213 bool particle_interaction = true);
214
223 void write_simulation_to_dir(std::string path, double time, uint steps,
224 std::string method = "rk4",
225 bool particle_interaction = true);
226
237 double fraction_of_particles_left(double time, uint steps,
238 std::string method = "rk4",
239 bool particle_interaction = true);
240
241};
242
243#endif
Particle.hpp
A class that holds the properties of a particle.
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:42
PenningTrap::B_0
double B_0
Magnetic field strength.
Definition: PenningTrap.hpp:37
PenningTrap::total_force_external
vec3 total_force_external(uint i)
Calculate the total external force on a particle.
Definition: PenningTrap.cpp:82
PenningTrap::k_r
sim_arr k_r
A 2D vector containing all where is the index of a particle.
Definition: PenningTrap.hpp:52
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:95
PenningTrap::external_B_field
vec3 external_B_field(vec3 r)
Calculate B at point r.
Definition: PenningTrap.cpp:66
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:20
PenningTrap::external_E_field
vec3 external_E_field(vec3 r)
Calculate E at point r.
Definition: PenningTrap.cpp:58
PenningTrap::d
double d
Characteristic dimension.
Definition: PenningTrap.hpp:40
PenningTrap::add_particle
void add_particle(Particle particle)
Add a particle to the system.
Definition: PenningTrap.cpp:158
PenningTrap::V_0
double V_0
Applied potential.
Definition: PenningTrap.hpp:38
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:71
PenningTrap::r_func
vec3 r_func(uint i, uint j, double dt)
Helper for evolve_RK4 when calculating values.
Definition: PenningTrap.cpp:39
PenningTrap::t
double t
Current time.
Definition: PenningTrap.hpp:41
PenningTrap::total_force
vec3 total_force(uint i)
calculate the total force on a particle p_i.
Definition: PenningTrap.cpp:107
PenningTrap::set_pertubation
void set_pertubation(double f, double omega_V)
Time dependent perturbation to V_0.
Definition: PenningTrap.cpp:141
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:148
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:39
PenningTrap::k_v
sim_arr k_v
A 2D vector containing all where is the index of a particle.
Definition: PenningTrap.hpp:47
constants.hpp
Library of constants.
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.
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.