From 944c52d22fa28b95b02afe6ab61b47913d68f281 Mon Sep 17 00:00:00 2001 From: Cory Date: Sun, 22 Oct 2023 14:11:15 +0200 Subject: [PATCH] Add commments --- src/main.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bdc967f..08fd84e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -170,16 +170,20 @@ void potential_resonance_wide_sweep() std::ofstream ofile; #pragma omp parallel for + // Insert frequencies for (size_t i = 0; i < freq_iterations; i++) { res[0][i] = freq_start + freq_increment * i; } #pragma omp parallel { + // Each thread creates a PenningTrap instance and reuses it throughout + // the sweep. PenningTrap trap((unsigned int)100); #pragma omp for collapse(2) for (size_t i = 0; i < 3; i++) { for (size_t j = 0; j < freq_iterations; j++) { + // Reset particles and give new time dependent potential. trap.reinitialize(std::bind( [](double f, double r, double t) { return (25. * V / 1000.) * (1. + f * std::cos(r * t)); @@ -191,6 +195,7 @@ void potential_resonance_wide_sweep() } } + // Write results to file ofile.open(path + "wide_sweep.txt"); for (size_t i = 0; i < freq_iterations; i++) { ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ',' @@ -225,17 +230,15 @@ void potential_resonance_no_interaction_narrow_sweep() std::ofstream ofile; -#pragma omp parallel for - for (size_t i = 0; i < freq_iterations; i++) { - res[0][i] = freq_start + freq_increment * i; - } - #pragma omp parallel { + // Each thread creates a PenningTrap instance and reuses it throughout + // the sweep. PenningTrap trap((unsigned int)100); #pragma omp for collapse(2) for (size_t i = 0; i < 3; i++) { for (size_t j = 0; j < freq_iterations; j++) { + // Reset particles and give new time dependent potential. trap.reinitialize(std::bind( [](double f, double r, double t) { return (25. * V / 1000.) * (1. + f * std::cos(r * t)); @@ -247,6 +250,7 @@ void potential_resonance_no_interaction_narrow_sweep() } } + // Write results to file ofile.open(path + "narrow_sweep.txt"); for (size_t i = 0; i < freq_iterations; i++) { ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ',' @@ -288,10 +292,13 @@ void potential_resonance_with_interaction_narrow_sweep() #pragma omp parallel { + // Each thread creates a PenningTrap instance and reuses it throughout + // the sweep. PenningTrap trap((unsigned int)100); #pragma omp for collapse(2) for (size_t i = 0; i < 3; i++) { for (size_t j = 0; j < freq_iterations; j++) { + // Reset particles and give new time dependent potential. trap.reinitialize(std::bind( [](double f, double r, double t) { return (25. * V / 1000.) * (1. + f * std::cos(r * t)); @@ -302,6 +309,7 @@ void potential_resonance_with_interaction_narrow_sweep() } } + // Write results to file ofile.open(path + "narrow_sweep_interactions.txt"); for (size_t i = 0; i < freq_iterations; i++) { ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ',' @@ -312,7 +320,7 @@ void potential_resonance_with_interaction_narrow_sweep() int main() { - double start,end,t1,t2; + double start, end, t1, t2; start = omp_get_wtime(); simulate_single_particle(); @@ -361,7 +369,7 @@ int main() std::cout << "Time narrow sweep with interaction: " << (t2 - t1) << " seconds" << std::endl; - + end = omp_get_wtime(); std::cout << "Time : " << (end - start)