Develop #14

Merged
coryab merged 124 commits from develop into main 2023-10-24 20:43:56 +00:00
Showing only changes of commit 944c52d22f - Show all commits

View File

@ -170,16 +170,20 @@ void potential_resonance_wide_sweep()
std::ofstream ofile; std::ofstream ofile;
#pragma omp parallel for #pragma omp parallel for
// Insert frequencies
for (size_t i = 0; i < freq_iterations; i++) { for (size_t i = 0; i < freq_iterations; i++) {
res[0][i] = freq_start + freq_increment * i; res[0][i] = freq_start + freq_increment * i;
} }
#pragma omp parallel #pragma omp parallel
{ {
// Each thread creates a PenningTrap instance and reuses it throughout
// the sweep.
PenningTrap trap((unsigned int)100); PenningTrap trap((unsigned int)100);
#pragma omp for collapse(2) #pragma omp for collapse(2)
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
for (size_t j = 0; j < freq_iterations; j++) { for (size_t j = 0; j < freq_iterations; j++) {
// Reset particles and give new time dependent potential.
trap.reinitialize(std::bind( trap.reinitialize(std::bind(
[](double f, double r, double t) { [](double f, double r, double t) {
return (25. * V / 1000.) * (1. + f * std::cos(r * 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"); ofile.open(path + "wide_sweep.txt");
for (size_t i = 0; i < freq_iterations; i++) { for (size_t i = 0; i < freq_iterations; i++) {
ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][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; 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 #pragma omp parallel
{ {
// Each thread creates a PenningTrap instance and reuses it throughout
// the sweep.
PenningTrap trap((unsigned int)100); PenningTrap trap((unsigned int)100);
#pragma omp for collapse(2) #pragma omp for collapse(2)
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
for (size_t j = 0; j < freq_iterations; j++) { for (size_t j = 0; j < freq_iterations; j++) {
// Reset particles and give new time dependent potential.
trap.reinitialize(std::bind( trap.reinitialize(std::bind(
[](double f, double r, double t) { [](double f, double r, double t) {
return (25. * V / 1000.) * (1. + f * std::cos(r * 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"); ofile.open(path + "narrow_sweep.txt");
for (size_t i = 0; i < freq_iterations; i++) { for (size_t i = 0; i < freq_iterations; i++) {
ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][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 #pragma omp parallel
{ {
// Each thread creates a PenningTrap instance and reuses it throughout
// the sweep.
PenningTrap trap((unsigned int)100); PenningTrap trap((unsigned int)100);
#pragma omp for collapse(2) #pragma omp for collapse(2)
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
for (size_t j = 0; j < freq_iterations; j++) { for (size_t j = 0; j < freq_iterations; j++) {
// Reset particles and give new time dependent potential.
trap.reinitialize(std::bind( trap.reinitialize(std::bind(
[](double f, double r, double t) { [](double f, double r, double t) {
return (25. * V / 1000.) * (1. + f * std::cos(r * 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"); ofile.open(path + "narrow_sweep_interactions.txt");
for (size_t i = 0; i < freq_iterations; i++) { for (size_t i = 0; i < freq_iterations; i++) {
ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ',' ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ','
@ -312,7 +320,7 @@ void potential_resonance_with_interaction_narrow_sweep()
int main() int main()
{ {
double start,end,t1,t2; double start, end, t1, t2;
start = omp_get_wtime(); start = omp_get_wtime();
simulate_single_particle(); simulate_single_particle();
@ -361,7 +369,7 @@ int main()
std::cout << "Time narrow sweep with interaction: " << (t2 - t1) std::cout << "Time narrow sweep with interaction: " << (t2 - t1)
<< " seconds" << std::endl; << " seconds" << std::endl;
end = omp_get_wtime(); end = omp_get_wtime();
std::cout << "Time : " << (end - start) std::cout << "Time : " << (end - start)