commit
4ee5d397e6
3
.gitignore
vendored
3
.gitignore
vendored
@ -48,3 +48,6 @@ src/*
|
|||||||
!src/*.py
|
!src/*.py
|
||||||
!src/Doxyfile
|
!src/Doxyfile
|
||||||
!src/scripts
|
!src/scripts
|
||||||
|
|
||||||
|
# Job
|
||||||
|
!src/job.script
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.8 MiB After Width: | Height: | Size: 2.0 MiB |
Binary file not shown.
BIN
latex/images/particles_left_narrow_sweep_fine.pdf
Normal file
BIN
latex/images/particles_left_narrow_sweep_fine.pdf
Normal file
Binary file not shown.
Binary file not shown.
BIN
latex/images/particles_left_narrow_sweep_interactions_fine.pdf
Normal file
BIN
latex/images/particles_left_narrow_sweep_interactions_fine.pdf
Normal file
Binary file not shown.
Binary file not shown.
@ -8,7 +8,8 @@ CLASSOBJS=$(CLASSSRCS:.cpp=.o)
|
|||||||
|
|
||||||
INCLUDE=../include
|
INCLUDE=../include
|
||||||
|
|
||||||
CFLAGS=-Wall -larmadillo -lblas -llapack -std=c++11 -O3 -fomit-frame-pointer
|
CFLAGS=-Wall -larmadillo -std=c++11 -O3 -fomit-frame-pointer
|
||||||
|
#CFLAGS=-Wall -larmadillo -lblas -llapack -std=c++11 -O3 -fomit-frame-pointer
|
||||||
OPENMP=-fopenmp
|
OPENMP=-fopenmp
|
||||||
|
|
||||||
# Add a debug flag when compiling (For the DEBUG macro in utils.hpp)
|
# Add a debug flag when compiling (For the DEBUG macro in utils.hpp)
|
||||||
@ -46,6 +47,10 @@ instrument:
|
|||||||
main: main.o $(LIBOBJS) $(CLASSOBJS)
|
main: main.o $(LIBOBJS) $(CLASSOBJS)
|
||||||
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||||
|
|
||||||
|
frequency_narrow_sweeps_long: frequency_narrow_sweeps_long.o $(LIBOBJS) $(CLASSOBJS)
|
||||||
|
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||||
|
|
||||||
|
|
||||||
test_suite: test_suite.o $(LIBOBJS) $(CLASSOBJS)
|
test_suite: test_suite.o $(LIBOBJS) $(CLASSOBJS)
|
||||||
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||||
|
|
||||||
|
|||||||
@ -158,7 +158,7 @@ void PenningTrap::reinitialize(double f, double omega_V, double t)
|
|||||||
|
|
||||||
for (size_t i = 0; i < this->particles.size(); i++) {
|
for (size_t i = 0; i < this->particles.size(); i++) {
|
||||||
p = &this->particles[i];
|
p = &this->particles[i];
|
||||||
p->v_vec = vec3().randn() * .1 * this->d;
|
p->r_vec = vec3().randn() * .1 * this->d;
|
||||||
p->v_vec = vec3().randn() * .1 * this->d;
|
p->v_vec = vec3().randn() * .1 * this->d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,6 +172,7 @@ void PenningTrap::evolve_RK4(double dt, bool particle_interaction)
|
|||||||
{
|
{
|
||||||
Particle *p;
|
Particle *p;
|
||||||
|
|
||||||
|
// Keep original particles
|
||||||
std::vector<Particle> original_particles = this->particles;
|
std::vector<Particle> original_particles = this->particles;
|
||||||
std::vector<Particle> tmp_particles = this->particles;
|
std::vector<Particle> tmp_particles = this->particles;
|
||||||
|
|
||||||
|
|||||||
154
src/frequency_narrow_sweeps_long.cpp
Normal file
154
src/frequency_narrow_sweeps_long.cpp
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
/** @file main.cpp
|
||||||
|
*
|
||||||
|
* @author Cory Alexander Balaton (coryab)
|
||||||
|
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||||
|
*
|
||||||
|
* @version 1.0
|
||||||
|
*
|
||||||
|
* @brief The main program for this project
|
||||||
|
*
|
||||||
|
* @bug No known bugs
|
||||||
|
* */
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <complex>
|
||||||
|
#include <fstream>
|
||||||
|
#include <omp.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "PenningTrap.hpp"
|
||||||
|
#include "constants.hpp"
|
||||||
|
#include "utils.hpp"
|
||||||
|
|
||||||
|
#define PARTICLES 100
|
||||||
|
#define N 40000
|
||||||
|
|
||||||
|
/** @brief Simulate 100 particles over 500 \f$ \mu s \f$ using a time
|
||||||
|
* dependent potential.
|
||||||
|
*
|
||||||
|
* @details The simulation sweeps over different frequencies in [1., 1.7]
|
||||||
|
* MHz.
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
void potential_resonance_narrow_sweep()
|
||||||
|
{
|
||||||
|
double time = 500.;
|
||||||
|
|
||||||
|
double amplitudes[]{.1, .4, .7};
|
||||||
|
|
||||||
|
double freq_start = 1.1;
|
||||||
|
double freq_end = 1.7;
|
||||||
|
double freq_increment = .0005;
|
||||||
|
size_t freq_iterations =
|
||||||
|
(size_t)((freq_end - freq_start) / freq_increment) + 1;
|
||||||
|
|
||||||
|
double res[4][freq_iterations];
|
||||||
|
|
||||||
|
std::string path = "output/time_dependent_potential/";
|
||||||
|
mkpath(path);
|
||||||
|
|
||||||
|
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((uint)PARTICLES);
|
||||||
|
#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(amplitudes[i], res[0][j]);
|
||||||
|
res[i + 1][j] =
|
||||||
|
trap.fraction_of_particles_left(time, N, "rk4", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write results to file
|
||||||
|
ofile.open(path + "narrow_sweep_fine.txt");
|
||||||
|
for (size_t i = 0; i < freq_iterations; i++) {
|
||||||
|
ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ','
|
||||||
|
<< res[3][i] << '\n';
|
||||||
|
}
|
||||||
|
ofile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Simulate 100 particles over 500 \f$ \mu s \f$ using a time
|
||||||
|
* dependent potential.
|
||||||
|
*
|
||||||
|
* @details The simulation sweeps over different frequencies in [1., 1.7]
|
||||||
|
* MHz.
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
void potential_resonance_narrow_sweep_interaction()
|
||||||
|
{
|
||||||
|
double time = 500.;
|
||||||
|
|
||||||
|
double amplitudes[]{.1, .4, .7};
|
||||||
|
|
||||||
|
double freq_start = 1.1;
|
||||||
|
double freq_end = 1.7;
|
||||||
|
double freq_increment = .0005;
|
||||||
|
size_t freq_iterations =
|
||||||
|
(size_t)((freq_end - freq_start) / freq_increment) + 1;
|
||||||
|
|
||||||
|
double res[4][freq_iterations];
|
||||||
|
|
||||||
|
std::string path = "output/time_dependent_potential/";
|
||||||
|
mkpath(path);
|
||||||
|
|
||||||
|
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((uint)PARTICLES);
|
||||||
|
#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(amplitudes[i], res[0][j]);
|
||||||
|
res[i + 1][j] = trap.fraction_of_particles_left(time, N);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write results to file
|
||||||
|
ofile.open(path + "narrow_sweep_interactions_fine.txt");
|
||||||
|
for (size_t i = 0; i < freq_iterations; i++) {
|
||||||
|
ofile << res[0][i] << ',' << res[1][i] << ',' << res[2][i] << ','
|
||||||
|
<< res[3][i] << '\n';
|
||||||
|
}
|
||||||
|
ofile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
double start, end;
|
||||||
|
|
||||||
|
start = omp_get_wtime();
|
||||||
|
|
||||||
|
potential_resonance_narrow_sweep();
|
||||||
|
|
||||||
|
potential_resonance_narrow_sweep_interaction();
|
||||||
|
|
||||||
|
end = omp_get_wtime();
|
||||||
|
|
||||||
|
std::cout << "Time: " << end - start << " seconds" << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
15
src/job.script
Normal file
15
src/job.script
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#SBATCH --account=ec54
|
||||||
|
#SBATCH --job-name=particle-sim
|
||||||
|
#SBATCH --time=0-01:30:00
|
||||||
|
#SBATCH --mem-per-cpu=2G
|
||||||
|
#SBATCH --cpus-per-task=16
|
||||||
|
|
||||||
|
set -o errexit # Exit the script on any error
|
||||||
|
set -o nounset # Treat any unset variables as an error
|
||||||
|
|
||||||
|
module --quiet purge # Reset the modules to the system default
|
||||||
|
module load Armadillo/11.4.3-foss-2022b
|
||||||
|
|
||||||
|
srun ./frequency_narrow_sweeps_long
|
||||||
@ -42,6 +42,7 @@ vec3 analytical_solution_particle_1(double t)
|
|||||||
double w_n = (w_0 - std::sqrt(w_0 * w_0 - 2. * w_z2)) / 2.;
|
double w_n = (w_0 - std::sqrt(w_0 * w_0 - 2. * w_z2)) / 2.;
|
||||||
double A_p = (25. + w_n * 20.) / (w_n - w_p);
|
double A_p = (25. + w_n * 20.) / (w_n - w_p);
|
||||||
double A_n = -(25. + w_p * 20.) / (w_n - w_p);
|
double A_n = -(25. + w_p * 20.) / (w_n - w_p);
|
||||||
|
std::cout << A_p << "," << A_n << std::endl;
|
||||||
std::complex<double> f =
|
std::complex<double> f =
|
||||||
A_p * std::exp(std::complex<double>(0., -w_p * t))
|
A_p * std::exp(std::complex<double>(0., -w_p * t))
|
||||||
+ A_n * std::exp(std::complex<double>(0., -w_n * t));
|
+ A_n * std::exp(std::complex<double>(0., -w_n * t));
|
||||||
@ -211,7 +212,7 @@ void potential_resonance_narrow_sweep()
|
|||||||
|
|
||||||
double amplitudes[]{.1, .4, .7};
|
double amplitudes[]{.1, .4, .7};
|
||||||
|
|
||||||
double freq_start = 1.;
|
double freq_start = 1.1;
|
||||||
double freq_end = 1.7;
|
double freq_end = 1.7;
|
||||||
double freq_increment = .002;
|
double freq_increment = .002;
|
||||||
size_t freq_iterations =
|
size_t freq_iterations =
|
||||||
@ -268,7 +269,7 @@ void potential_resonance_narrow_sweep_interaction()
|
|||||||
|
|
||||||
double amplitudes[]{.1, .4, .7};
|
double amplitudes[]{.1, .4, .7};
|
||||||
|
|
||||||
double freq_start = 1.;
|
double freq_start = 1.1;
|
||||||
double freq_end = 1.7;
|
double freq_end = 1.7;
|
||||||
double freq_increment = .002;
|
double freq_increment = .002;
|
||||||
size_t freq_iterations =
|
size_t freq_iterations =
|
||||||
|
|||||||
@ -34,7 +34,7 @@ def animate():
|
|||||||
|
|
||||||
arr = get_data([f"output/simulate_100_particles/particle_{i}_r.txt" for i in range(100)])
|
arr = get_data([f"output/simulate_100_particles/particle_{i}_r.txt" for i in range(100)])
|
||||||
|
|
||||||
arr = arr[:, :, ::10]
|
arr = arr[:, :, ::40]
|
||||||
|
|
||||||
N = len(arr[0][0])
|
N = len(arr[0][0])
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,16 @@ def main():
|
|||||||
files = [
|
files = [
|
||||||
"output/time_dependent_potential/wide_sweep.txt",
|
"output/time_dependent_potential/wide_sweep.txt",
|
||||||
"output/time_dependent_potential/narrow_sweep.txt",
|
"output/time_dependent_potential/narrow_sweep.txt",
|
||||||
|
"output/time_dependent_potential/narrow_sweep_fine.txt",
|
||||||
"output/time_dependent_potential/narrow_sweep_interactions.txt",
|
"output/time_dependent_potential/narrow_sweep_interactions.txt",
|
||||||
|
"output/time_dependent_potential/narrow_sweep_interactions_fine.txt",
|
||||||
]
|
]
|
||||||
outputs = [
|
outputs = [
|
||||||
"../latex/images/particles_left_wide_sweep.pdf",
|
"../latex/images/particles_left_wide_sweep.pdf",
|
||||||
"../latex/images/particles_left_narrow_sweep.pdf",
|
"../latex/images/particles_left_narrow_sweep.pdf",
|
||||||
|
"../latex/images/particles_left_narrow_sweep_fine.pdf",
|
||||||
"../latex/images/particles_left_narrow_sweep_interactions.pdf",
|
"../latex/images/particles_left_narrow_sweep_interactions.pdf",
|
||||||
|
"../latex/images/particles_left_narrow_sweep_interactions_fine.pdf",
|
||||||
]
|
]
|
||||||
for file, output in zip(files, outputs):
|
for file, output in zip(files, outputs):
|
||||||
with open(file) as f:
|
with open(file) as f:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user