31void simulate_single_particle()
33 DEBUG(
"Inside single particle sim");
38 DEBUG(
"Write to dir");
39 trap.write_simulation_to_dir(
"output/simulate_single_particle", time, N);
42void simulate_two_particles()
44 PenningTrap trap_no_interaction(std::vector<Particle>{p1, p2});
45 PenningTrap trap_with_interaction(std::vector<Particle>{p1, p2});
50 "output/simulate_2_particles/no_interaction", time, N,
"rk4",
false);
51 trap_with_interaction.write_simulation_to_dir(
52 "output/simulate_2_particles/with_interaction", time, N);
55void simulate_single_particle_with_different_steps()
60 for (
int i = 0; i < 4; i++) {
61 int steps = 4000 * (i + 1);
64 std::to_string(steps) +
"_steps",
65 time, steps,
"rk4",
false);
68 for (
int i = 0; i < 4; i++) {
69 int steps = 4000 * (i + 1);
72 std::to_string(steps) +
"_steps",
73 time, steps,
"euler",
false);
77void simulate_100_particles()
81 return 25. *
V / 1000. *
82 (1. + .4 * std::cos(1.5 * t));
91void simulate_100_particles_with_time_potential()
93 double amplitudes[]{.1, .4, .7};
95 double freq_start = .2;
96 double freq_end = 2.5;
97 double freq_increment = .02;
98 size_t freq_iterations = (size_t) ((freq_end - freq_start) / freq_increment);
100 std::string path =
"output/time_dependent_potential/";
105 for (
double f : amplitudes) {
106 ofile.open(path +
"f_" + std::to_string(f) +
".txt");
107 #pragma omp parallel for ordered schedule(static, 1)
108 for (
size_t i=0; i < freq_iterations; i++) {
109 double freq = freq_start + i*freq_increment;
111 [f, freq](
double t) {
112 return (25. *
V / 1000.) *
113 (1. + f * std::cos(freq * t));
118 ofile << freq <<
"," << res <<
"\n";
127 simulate_single_particle();
129 simulate_two_particles();
131 simulate_single_particle_with_different_steps();
133 double start = omp_get_wtime();
137 simulate_100_particles_with_time_potential();
139 double end = omp_get_wtime();
141 std::cout <<
"Time: " << end - start <<
" seconds" << std::endl;
A class for simulating a Penning trap.
A class that holds attributes of a particle.
A class that simulates a Penning trap.
double fraction_of_particles_left(double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate and calculate what fraction of particles are still left inside the Penning trap after the si...
void write_simulation_to_dir(std::string path, double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true)
Simulate and write the displacement of all particles to files.
arma::vec::fixed< 3 > vec_3d
Typedef for a fixed 3d arma vector.
Function prototypes and macros that are useful.
bool mkpath(std::string path, int mode=0777)
Make path given.
#define DEBUG(msg)
Writes a debug message.