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::complex<double> f =
46 A_p * std::exp(std::complex<double>(0., -w_p * t))
47 + A_n * std::exp(std::complex<double>(0., -w_n * t));
48 vec3 res{std::real(f), std::imag(f), 20. * std::cos(std::sqrt(w_z2) * t)};
79 "output/simulate_2_particles/no_interaction", time, N,
"rk4",
false);
80 trap_with_interaction.write_simulation_to_dir(
81 "output/simulate_2_particles/with_interaction", time, N);
94 std::string path =
"output/relative_error/RK4/";
96#pragma omp parallel for
97 for (
int i = 0; i < 4; i++) {
98 int steps = 4000 * std::pow(2, i);
99 double dt = time / (double)steps;
100 ofile.open(path + std::to_string(steps) +
"_steps.txt");
102 simulation_t res = trap.simulate(time, steps,
"rk4",
false);
103 for (
int i = 0; i < steps; i++) {
104 ofile << arma::norm(res.r_vecs[0][i]
112 path =
"output/relative_error/euler/";
114#pragma omp parallel for
115 for (
int i = 0; i < 4; i++) {
116 int steps = 4000 * std::pow(2, i);
117 double dt = time / (double)steps;
118 ofile.open(path + std::to_string(steps) +
"_steps.txt");
120 simulation_t res = trap.simulate(time, steps,
"euler",
false);
121 for (
int i = 0; i < steps; i++) {
122 ofile << arma::norm(res.r_vecs[0][i]
153 double amplitudes[]{.1, .4, .7};
155 double freq_start = .2;
156 double freq_end = 2.5;
157 double freq_increment = .02;
158 size_t freq_iterations =
159 (size_t)((freq_end - freq_start) / freq_increment) + 1;
161 double res[4][freq_iterations];
163 std::string path =
"output/time_dependent_potential/";
168#pragma omp parallel for
170 for (
size_t i = 0; i < freq_iterations; i++) {
171 res[0][i] = freq_start + freq_increment * i;
179#pragma omp for collapse(2)
180 for (
size_t i = 0; i < 3; i++) {
181 for (
size_t j = 0; j < freq_iterations; j++) {
191 ofile.open(path +
"wide_sweep.txt");
192 for (
size_t i = 0; i < freq_iterations; i++) {
193 ofile << res[0][i] <<
',' << res[1][i] <<
',' << res[2][i] <<
','
194 << res[3][i] <<
'\n';
210 double amplitudes[]{.1, .4, .7};
212 double freq_start = 1.;
213 double freq_end = 1.7;
214 double freq_increment = .002;
215 size_t freq_iterations = (size_t)((freq_end - freq_start) / freq_increment);
217 double res[4][freq_iterations];
219 std::string path =
"output/time_dependent_potential/";
224#pragma omp parallel for
226 for (
size_t i = 0; i < freq_iterations; i++) {
227 res[0][i] = freq_start + freq_increment * i;
235#pragma omp for collapse(2)
236 for (
size_t i = 0; i < 3; i++) {
237 for (
size_t j = 0; j < freq_iterations; j++) {
247 ofile.open(path +
"narrow_sweep.txt");
248 for (
size_t i = 0; i < freq_iterations; i++) {
249 ofile << res[0][i] <<
',' << res[1][i] <<
',' << res[2][i] <<
','
250 << res[3][i] <<
'\n';
266 double amplitudes[]{.1, .4, .7};
268 double freq_start = 1.;
269 double freq_end = 1.7;
270 double freq_increment = .002;
271 size_t freq_iterations = (size_t)((freq_end - freq_start) / freq_increment);
273 double res[4][freq_iterations];
275 std::string path =
"output/time_dependent_potential/";
280#pragma omp parallel for
281 for (
size_t i = 0; i < freq_iterations; i++) {
282 res[0][i] = freq_start + freq_increment * i;
290#pragma omp for collapse(2)
291 for (
size_t i = 0; i < 3; i++) {
292 for (
size_t j = 0; j < freq_iterations; j++) {
301 ofile.open(path +
"narrow_sweep_interactions.txt");
302 for (
size_t i = 0; i < freq_iterations; i++) {
303 ofile << res[0][i] <<
',' << res[1][i] <<
',' << res[2][i] <<
','
304 << res[3][i] <<
'\n';
311 double start, end, t1, t2;
312 start = omp_get_wtime();
320 t2 = omp_get_wtime();
322 std::cout <<
"Time single and double : " << (t2 - start)
323 <<
" seconds" << std::endl;
325 t1 = omp_get_wtime();
329 t2 = omp_get_wtime();
331 std::cout <<
"Time 100 particles : " << (t2 - t1)
332 <<
" seconds" << std::endl;
334 t1 = omp_get_wtime();
338 t2 = omp_get_wtime();
340 std::cout <<
"Time wide sweep : " << (t2 - t1)
341 <<
" seconds" << std::endl;
343 t1 = omp_get_wtime();
347 t2 = omp_get_wtime();
349 std::cout <<
"Time narrow sweep no interaction : " << (t2 - t1)
350 <<
" seconds" << std::endl;
352 t1 = omp_get_wtime();
356 t2 = omp_get_wtime();
358 std::cout <<
"Time narrow sweep with interaction: " << (t2 - t1)
359 <<
" seconds" << std::endl;
361 end = omp_get_wtime();
363 std::cout <<
"Time : " << (end - start)
364 <<
" 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.
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.