105 lines
3.1 KiB
C++
105 lines
3.1 KiB
C++
/** @file PenningTrap.hpp
|
|
*
|
|
* @author Cory Alexander Balaton (coryab)
|
|
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
|
*
|
|
* @version 0.1
|
|
*
|
|
* @brief A class for simulating a Penning trap.
|
|
*
|
|
* @bug No known bugs
|
|
* */
|
|
#ifndef __PENNING_TRAP__
|
|
#define __PENNING_TRAP__
|
|
|
|
#include <armadillo>
|
|
#include <omp.h>
|
|
|
|
#include "Particle.hpp"
|
|
#include "constants.hpp"
|
|
#include "typedefs.hpp"
|
|
|
|
|
|
#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \
|
|
initializer(omp_priv = omp_orig)
|
|
|
|
/** @brief A class that simulates a Penning trap.
|
|
*
|
|
* This class simulates a Penning trap. It can take in a number of particles
|
|
* and simulate how they would behave inside a Penning trap.
|
|
* */
|
|
class PenningTrap {
|
|
private:
|
|
double B_0; ///< Magnetic field strength
|
|
double V_0; ///< Applied potential
|
|
double d; ///< Characteristic dimension
|
|
std::vector<Particle> particles; ///< The particles in the Penning trap
|
|
sim_arr k_v;
|
|
sim_arr k_r;
|
|
std::function<vec_3d(int, double)>* v_funcs;
|
|
std::function<vec_3d(int, double)>* r_funcs;
|
|
|
|
public:
|
|
/** @brief Set B_0, V_0 and d.
|
|
* */
|
|
PenningTrap(double B_0 = T, double V_0 = 25. * V / 1000., double d = 500.);
|
|
|
|
PenningTrap(int i, double B_0 = T, double V_0 = 25. * V / 1000.,
|
|
double d = 500.);
|
|
|
|
PenningTrap(std::vector<Particle> particles, double B_0 = T,
|
|
double V_0 = 25. * V / 1000., double d = 500.);
|
|
|
|
/** @brief Add a particle to the system
|
|
* */
|
|
void add_particle(Particle particle);
|
|
|
|
/** @brief Calculate E at point r
|
|
* */
|
|
vec_3d external_E_field(vec_3d r);
|
|
|
|
/** @brief Calculate B at point r
|
|
* */
|
|
vec_3d external_B_field(vec_3d r);
|
|
|
|
/** @brief Calculate the force between 2 particles.
|
|
*
|
|
* @details Calculate the force exhibited on particle p_i from
|
|
* particle p_j.
|
|
* */
|
|
vec_3d force_on_particle(int i, int j);
|
|
|
|
/** @brief Calculate the total external force on a particle.
|
|
*
|
|
* @details Calculate the total amount of force that E and B exhibits
|
|
* on particle p_i.
|
|
* */
|
|
vec_3d total_force_external(int i);
|
|
|
|
/** @brief Calculate the total force on a particle from other particles.
|
|
* */
|
|
vec_3d total_force_particles(unsigned int i);
|
|
|
|
/** @brief calculate the total force on a particle.
|
|
* */
|
|
vec_3d total_force(int i);
|
|
|
|
/** @brief Go forward one timestep using the RK4 method
|
|
* */
|
|
void evolve_RK4(double dt, bool particle_interaction = true);
|
|
|
|
/** @brief Go forward one timestep using the forward Euler method
|
|
* */
|
|
void evolve_forward_euler(double dt, bool particle_interaction = true);
|
|
|
|
sim_arr simulate(double time, unsigned int steps,
|
|
std::string method = "rk4",
|
|
bool particle_interaction = true);
|
|
|
|
void write_simulation_to_dir(std::string path, double time, int steps,
|
|
std::string method = "rk4",
|
|
bool particle_interaction = true);
|
|
};
|
|
|
|
#endif
|