40 double w_z2 = (50. *
V / 1000.) / (
CA_MASS * 500. * 500.);
41 double w_p = (w_0 + std::sqrt(w_0 * w_0 - 2. * w_z2)) / 2.;
42 double w_n = (w_0 - std::sqrt(w_0 * w_0 - 2. * w_z2)) / 2.;
43 double A_p = (25. + w_n * 20.) / (w_n - w_p);
44 double A_n = -(25. + w_p * 20.) / (w_n - w_p);
45 std::cout << A_p <<
"," << A_n << std::endl;
46 std::complex<double> f =
47 A_p * std::exp(std::complex<double>(0., -w_p * t))
48 + A_n * std::exp(std::complex<double>(0., -w_n * t));
49 vec3 res{std::real(f), std::imag(f), 20. * std::cos(std::sqrt(w_z2) * t)};
80 "output/simulate_2_particles/no_interaction", time, N,
"rk4",
false);
81 trap_with_interaction.write_simulation_to_dir(
82 "output/simulate_2_particles/with_interaction", time, N);
95 std::string path =
"output/relative_error/RK4/";
97#pragma omp parallel for private(ofile)
98 for (
int i = 0; i < 4; i++) {
99 int steps = 4000 * std::pow(2, i);
100 std::cout << steps << std::endl;
101 double dt = time / (double)steps;
102 ofile.open(path + std::to_string(steps) +
"_steps.txt");
104 simulation_t res = trap.simulate(time, steps,
"rk4",
false);
105 for (
int i = 0; i < steps; i++) {
106 ofile << arma::norm(res.r_vecs[0][i]
114 path =
"output/relative_error/euler/";
116#pragma omp parallel for private(ofile)
117 for (
int i = 0; i < 4; i++) {
118 int steps = 4000 * std::pow(2, i);
119 double dt = time / (double)steps;
120 ofile.open(path + std::to_string(steps) +
"_steps.txt");
122 simulation_t res = trap.simulate(time, steps,
"euler",
false);
123 for (
int i = 0; i < steps; i++) {
124 ofile << arma::norm(res.r_vecs[0][i]
142 trap.
simulate(time, N,
"rk4",
true);
156 double amplitudes[]{.1, .4, .7};
158 double freq_start = .2;
159 double freq_end = 2.5;
160 double freq_increment = .02;
161 size_t freq_iterations =
162 (size_t)((freq_end - freq_start) / freq_increment) + 1;
164 double res[4][freq_iterations];
166 std::string path =
"output/time_dependent_potential/";
171#pragma omp parallel for
173 for (
size_t i = 0; i < freq_iterations; i++) {
174 res[0][i] = freq_start + freq_increment * i;
182#pragma omp for collapse(2)
183 for (
size_t i = 0; i < 3; i++) {
184 for (
size_t j = 0; j < freq_iterations; j++) {
194 ofile.open(path +
"wide_sweep.txt");
195 for (
size_t i = 0; i < freq_iterations; i++) {
196 ofile << res[0][i] <<
',' << res[1][i] <<
',' << res[2][i] <<
','
197 << res[3][i] <<
'\n';
213 double amplitudes[]{.1, .4, .7};
215 double freq_start = 1.1;
216 double freq_end = 1.7;
217 double freq_increment = .002;
218 size_t freq_iterations =
219 (size_t)((freq_end - freq_start) / freq_increment) + 1;
221 double res[4][freq_iterations];
223 std::string path =
"output/time_dependent_potential/";
228#pragma omp parallel for
230 for (
size_t i = 0; i < freq_iterations; i++) {
231 res[0][i] = freq_start + freq_increment * i;
239#pragma omp for collapse(2)
240 for (
size_t i = 0; i < 3; i++) {
241 for (
size_t j = 0; j < freq_iterations; j++) {
251 ofile.open(path +
"narrow_sweep.txt");
252 for (
size_t i = 0; i < freq_iterations; i++) {
253 ofile << res[0][i] <<
',' << res[1][i] <<
',' << res[2][i] <<
','
254 << res[3][i] <<
'\n';
270 double amplitudes[]{.1, .4, .7};
272 double freq_start = 1.1;
273 double freq_end = 1.7;
274 double freq_increment = .002;
275 size_t freq_iterations =
276 (size_t)((freq_end - freq_start) / freq_increment) + 1;
278 double res[4][freq_iterations];
280 std::string path =
"output/time_dependent_potential/";
285#pragma omp parallel for
286 for (
size_t i = 0; i < freq_iterations; i++) {
287 res[0][i] = freq_start + freq_increment * i;
295#pragma omp for collapse(2)
296 for (
size_t i = 0; i < 3; i++) {
297 for (
size_t j = 0; j < freq_iterations; j++) {
306 ofile.open(path +
"narrow_sweep_interactions.txt");
307 for (
size_t i = 0; i < freq_iterations; i++) {
308 ofile << res[0][i] <<
',' << res[1][i] <<
',' << res[2][i] <<
','
309 << res[3][i] <<
'\n';
320 std::cout <<
"(1) All (default)\n"
321 <<
"(2) Simulate single particle\n"
322 <<
"(3) simulate 2 particles\n"
323 <<
"(4) Simulate single particle with different time steps\n"
324 <<
"(5) Simulate 100 particles\n"
325 <<
"(6) Potential resonance wide sweep\n"
326 <<
"(7) Potential resonance narrow sweep without particle "
328 <<
"(8) Potential resonance narrow sweep with particle "
330 <<
"Select what to run: ";
331 std::cin >> std::noskipws;
333 if (!(std::cin >> option) || option < 1 || option > 8) {
335 std::cin.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
338 <<
"(1) All (default)\n"
339 <<
"(2) Simulate single particle\n"
340 <<
"(3) simulate 2 particles\n"
341 <<
"(4) Simulate single particle with different time steps\n"
342 <<
"(5) Simulate 100 particles\n"
343 <<
"(6) Potential resonance wide sweep\n"
344 <<
"(7) Potential resonance narrow sweep without particle "
346 <<
"(8) Potential resonance narrow sweep with particle "
348 <<
"Not a valid option, please enter a valid number: ";
358 start = omp_get_wtime();
361 std::cout <<
"Running simulate_single_particle\n";
364 std::cout <<
"Running simulate_two_particles\n";
367 std::cout <<
"Running simulate_single_particle_with_different_steps\n";
370 std::cout <<
"Running simulate_100_particles\n";
373 std::cout <<
"Running potential_resonance_wide_sweep\n";
376 std::cout <<
"Running potential_resonance_narrow_sweep\n";
379 std::cout <<
"Running potential_resonance_narrow_sweep_interaction\n";
383 std::cout <<
"Running simulate_single_particle\n";
387 std::cout <<
"Running simulate_two_particles\n";
391 std::cout <<
"Running simulate_single_particle_with_different_steps\n";
395 std::cout <<
"Running simulate_100_particles\n";
399 std::cout <<
"Running potential_resonance_wide_sweep\n";
403 std::cout <<
"Running potential_resonance_narrow_sweep\n";
407 std::cout <<
"Running potential_resonance_narrow_sweep_interaction\n";
411 end = omp_get_wtime();
413 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.
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 reinitialize(double f, double omega_V, double t=0.)
Give all particles new positions and velocities, and change t and V_0.
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.
#define CA_MASS
Mass of a single calcium ion. unit: amu.
void simulate_100_particles()
Simulate 100 particles over 50 .
Particle p1(vec3{20., 0., 20.}, vec3{0., 25., 0.})
Particle 1.
void potential_resonance_narrow_sweep()
Simulate 100 particles over 500 using a time dependent potential.
void potential_resonance_wide_sweep()
Simulate 100 particles over 500 using a time dependent potential.
void simulate_two_particles()
Simulate 2 particles over the period of 50 with and without particle interactions.
vec3 analytical_solution_particle_1(double t)
The analytical solution for particle p1.
void simulate_single_particle()
Simulate a single particle over the period of 50 .
void potential_resonance_narrow_sweep_interaction()
Simulate 100 particles over 500 using a time dependent potential.
void simulate_single_particle_with_different_steps()
Simulate a single particle over 50 using different amount of steps and different methods.
Particle p2(vec3{25., 25., 0.}, vec3{0., 40., 5.})
Particle 2.
Typedef for PenningTrap::simulation return value.
arma::vec::fixed< 3 > vec3
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.