Update documentation
This commit is contained in:
@@ -30,6 +30,11 @@ public:
|
||||
*
|
||||
* @details Initialize the particle with a charge, mass, position and
|
||||
* velocity.
|
||||
*
|
||||
* @param q The charge of the particle
|
||||
* @param m The mass of the particle
|
||||
* @param r_vec The initial position of the particle
|
||||
* @param v_vec The initial velocity of the particle
|
||||
* */
|
||||
Particle(double q, double m, vec_3d r_vec, vec_3d v_vec);
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
#include "constants.hpp"
|
||||
#include "typedefs.hpp"
|
||||
|
||||
|
||||
#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \
|
||||
#pragma omp declare reduction(+ : vec_3d : omp_out += omp_in) \
|
||||
initializer(omp_priv = omp_orig)
|
||||
|
||||
/** @brief A class that simulates a Penning trap.
|
||||
@@ -30,36 +29,101 @@
|
||||
* */
|
||||
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;
|
||||
double B_0; ///< Magnetic field strength
|
||||
std::function<double(double)> V_0; ///< Applied potential
|
||||
double d; ///< Characteristic dimension
|
||||
double t; ///< Current time
|
||||
std::vector<Particle> particles; ///< The particles in the Penning trap
|
||||
sim_arr k_v; ///< A 2D vector containing all \f$k_{i,j}\f$ where \f$j\f$ is
|
||||
///< the index of a particle
|
||||
sim_arr k_r; ///< A 2D vector containing all \f$k_{i,j}\f$ where \f$j\f$ is
|
||||
///< the index of a particle
|
||||
|
||||
vec_3d v_func(int, int, double);
|
||||
vec_3d r_func(int, int, double);
|
||||
/** @brief Helper for evolve_RK4 when calculating \f$k_{v,i,j}\f$ values
|
||||
*
|
||||
* @details Something
|
||||
*
|
||||
* @param i Index i for \f$k_{v,i,j}\f$
|
||||
* @param j Index j for \f$k_{v,i,j}\f$
|
||||
* @param dt the step length (delta time)
|
||||
*
|
||||
* @return vec_3d
|
||||
* */
|
||||
vec_3d v_func(unsigned int i, unsigned int j, double dt);
|
||||
|
||||
/** @brief Helper for evolve_RK4 when calculating \f$k_{r,i,j}\f$ values
|
||||
*
|
||||
* @details Something
|
||||
*
|
||||
* @param i Index i for \f$k_{r,i,j}\f$
|
||||
* @param j Index j for \f$k_{r,i,j}\f$
|
||||
* @param dt the step length (delta time)
|
||||
*
|
||||
* @return vec_3d
|
||||
* */
|
||||
vec_3d r_func(unsigned int i, unsigned int j, double dt);
|
||||
|
||||
public:
|
||||
/** @brief Set B_0, V_0 and d.
|
||||
/** @brief Constructor for the PenningTrap class
|
||||
*
|
||||
* @param B_0 The magnetic field strength
|
||||
* @param V_0 The time dependent applied potential
|
||||
* @param d The characteristic dimension
|
||||
* @param t The starting time
|
||||
* */
|
||||
PenningTrap(double B_0 = T, double V_0 = 25. * V / 1000., double d = 500.);
|
||||
PenningTrap(
|
||||
double B_0 = T,
|
||||
std::function<double(double)> V_0 =
|
||||
[](double t) { return 25. * V / 1000.; },
|
||||
double d = 500., double t = 0.);
|
||||
|
||||
PenningTrap(int i, double B_0 = T, double V_0 = 25. * V / 1000.,
|
||||
double d = 500.);
|
||||
/** @brief Constructor for the PenningTrap class
|
||||
*
|
||||
* @param i The number of particles to generate
|
||||
* @param B_0 The magnetic field strength
|
||||
* @param V_0 The time dependent applied potential
|
||||
* @param d The characteristic dimension
|
||||
* @param t The starting time
|
||||
* */
|
||||
PenningTrap(
|
||||
unsigned int i, double B_0 = T,
|
||||
std::function<double(double)> V_0 =
|
||||
[](double t) { return 25. * V / 1000.; },
|
||||
double d = 500., double t = 0.);
|
||||
|
||||
PenningTrap(std::vector<Particle> particles, double B_0 = T,
|
||||
double V_0 = 25. * V / 1000., double d = 500.);
|
||||
/** @brief Constructor for the PenningTrap class
|
||||
*
|
||||
* @param particles The starting particles
|
||||
* @param B_0 The magnetic field strength
|
||||
* @param V_0 The time dependent applied potential
|
||||
* @param d The characteristic dimension
|
||||
* @param t The starting time
|
||||
* */
|
||||
PenningTrap(
|
||||
std::vector<Particle> particles, double B_0 = T,
|
||||
std::function<double(double)> V_0 =
|
||||
[](double t) { return 25. * V / 1000.; },
|
||||
double d = 500., double t = 0.);
|
||||
|
||||
/** @brief Add a particle to the system
|
||||
*
|
||||
* @param particle The particle to add to the Penning trap
|
||||
* */
|
||||
void add_particle(Particle particle);
|
||||
|
||||
/** @brief Calculate E at point r
|
||||
*
|
||||
* @param r The position where we want to calculate the E field
|
||||
*
|
||||
* @return vec_3d
|
||||
* */
|
||||
vec_3d external_E_field(vec_3d r);
|
||||
|
||||
/** @brief Calculate B at point r
|
||||
*
|
||||
* @param r The position where we want to calculate the B field
|
||||
*
|
||||
* @return vec_3d
|
||||
* */
|
||||
vec_3d external_B_field(vec_3d r);
|
||||
|
||||
@@ -67,39 +131,92 @@ public:
|
||||
*
|
||||
* @details Calculate the force exhibited on particle p_i from
|
||||
* particle p_j.
|
||||
*
|
||||
* @param i The index of particle p_i
|
||||
* @param j The index of particle p_j
|
||||
*
|
||||
* @return vec_3d
|
||||
* */
|
||||
vec_3d force_on_particle(int i, int j);
|
||||
vec_3d force_on_particle(unsigned int i, unsigned 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.
|
||||
*
|
||||
* @param i The index of particle p_i
|
||||
*
|
||||
* @return vec_3d
|
||||
* */
|
||||
vec_3d total_force_external(int i);
|
||||
vec_3d total_force_external(unsigned int i);
|
||||
|
||||
/** @brief Calculate the total force on a particle from other particles.
|
||||
/** @brief Calculate the total force on a particle p_i from other particles.
|
||||
*
|
||||
* @param i The index of particle p_i
|
||||
*
|
||||
* @return vec_3d
|
||||
* */
|
||||
vec_3d total_force_particles(unsigned int i);
|
||||
|
||||
/** @brief calculate the total force on a particle.
|
||||
/** @brief calculate the total force on a particle p_i.
|
||||
*
|
||||
* @param i The index of particle p_i
|
||||
*
|
||||
* @return vec_3d
|
||||
* */
|
||||
vec_3d total_force(int i);
|
||||
vec_3d total_force(unsigned int i);
|
||||
|
||||
/** @brief Go forward one timestep using the RK4 method
|
||||
*
|
||||
* @param dt The step length
|
||||
* @param particle_interaction Turn particle interactions on/off
|
||||
* */
|
||||
void evolve_RK4(double dt, bool particle_interaction = true);
|
||||
|
||||
/** @brief Go forward one timestep using the forward Euler method
|
||||
*
|
||||
* @param dt The step length
|
||||
* @param particle_interaction Turn particle interactions on/off
|
||||
* */
|
||||
void evolve_forward_euler(double dt, bool particle_interaction = true);
|
||||
|
||||
/** @brief Simulate the particle system inside the Penning trap over
|
||||
* a certain amount of time.
|
||||
*
|
||||
* @param time The time to simulate in microseconds
|
||||
* @param steps The amount of steps for the whole simulation
|
||||
* @param method The method to use when moving forward a timestep
|
||||
* @param particle_interaction Turn particle interactions on/off
|
||||
* */
|
||||
sim_arr simulate(double time, unsigned int steps,
|
||||
std::string method = "rk4",
|
||||
bool particle_interaction = true);
|
||||
std::string method = "rk4",
|
||||
bool particle_interaction = true);
|
||||
|
||||
void write_simulation_to_dir(std::string path, double time, int steps,
|
||||
std::string method = "rk4",
|
||||
/** @brief Simulate and write the displacement of all particles to files.
|
||||
*
|
||||
* @param path The directory to save the data
|
||||
* @param time The time to simulate in microseconds
|
||||
* @param steps The amount of steps for the whole simulation
|
||||
* @param method The method to use when moving forward a timestep
|
||||
* @param particle_interaction Turn particle interactions on/off
|
||||
* */
|
||||
void write_simulation_to_dir(std::string path, double time,
|
||||
unsigned int steps, std::string method = "rk4",
|
||||
bool particle_interaction = true);
|
||||
|
||||
/** @brief Simulate and calculate what fraction of particles are still
|
||||
* left inside the Penning trap after the simulation.
|
||||
*
|
||||
* @param time The time to simulate in microseconds
|
||||
* @param steps The amount of steps for the whole simulation
|
||||
* @param method The method to use when moving forward a timestep
|
||||
* @param particle_interaction Turn particle interactions on/off
|
||||
*
|
||||
* @return double
|
||||
* */
|
||||
double fraction_of_particles_left(double time, unsigned int steps,
|
||||
std::string method = "rk4",
|
||||
bool particle_interaction = true);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,38 @@
|
||||
/** @file typedefs.hpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief Useful typedefs for cleaner code.
|
||||
*
|
||||
* @details These typedefs make the code more readable and easy to follow
|
||||
* along.
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#ifndef __TYPEDEFS__
|
||||
#define __TYPEDEFS__
|
||||
|
||||
#include <vector>
|
||||
#include <armadillo>
|
||||
|
||||
/** @brief Typedef for the column of the result vector from simulating
|
||||
* particles.
|
||||
* */
|
||||
typedef std::vector<arma::vec::fixed<3>> sim_cols;
|
||||
|
||||
/** @brief Typedef for the row of the result vector from simulating particles.
|
||||
* */
|
||||
typedef std::vector<arma::vec::fixed<3>> sim_rows;
|
||||
|
||||
/** @brief Typedef for the result of the simulate method.
|
||||
* */
|
||||
typedef std::vector<sim_cols> sim_arr;
|
||||
|
||||
/** @brief Typedef for a fixed 3d arma vector.
|
||||
* */
|
||||
typedef arma::vec::fixed<3> vec_3d;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -45,40 +45,44 @@
|
||||
#define ASSERT(expr, msg) m_assert(expr, #expr, __METHOD_NAME__, __FILE__, \
|
||||
__LINE__, msg)
|
||||
|
||||
/** @def __METHOD_NAME__
|
||||
* @brief Get the name of the current method/function.
|
||||
* */
|
||||
#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
|
||||
|
||||
|
||||
/** Code stolen from https://github.com/anderkve/FYS3150
|
||||
* Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp
|
||||
* Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp
|
||||
* */
|
||||
|
||||
/** @brief Turns a double into a string written in scientific format.
|
||||
*
|
||||
* @details The code is stolen from https://github.com/anderkve/FYS3150.
|
||||
*
|
||||
* @param d The number to stringify
|
||||
* @param width The reserved width of the string
|
||||
* @param prec The precision of the stringified number
|
||||
*
|
||||
* @return String
|
||||
* @return std::string
|
||||
* */
|
||||
std::string scientific_format(double d, int width=20, int prec=10);
|
||||
|
||||
|
||||
/** @brief Turns a vector of doubles into a string written in scientific format.
|
||||
*
|
||||
* @details The code is stolen from https://github.com/anderkve/FYS3150.
|
||||
*
|
||||
* @param v The vector to stringify
|
||||
* @param width The reserved width of the string
|
||||
* @param prec The precision of the stringified number
|
||||
*
|
||||
* @return String
|
||||
* @return std::string
|
||||
* */
|
||||
std::string scientific_format(const std::vector<double>& v,
|
||||
int width=20,
|
||||
int prec=10);
|
||||
|
||||
|
||||
/** @brief Test an expression, confirm that test is ok, or abort execution.
|
||||
*
|
||||
* This function takes in an expression and prints an OK message if it's
|
||||
* true, or it prints a fail message and aborts execution if it fails.
|
||||
* @details This function takes in an expression and prints an OK message if
|
||||
* it's true, or it prints a fail message and aborts execution if it fails.
|
||||
*
|
||||
* @param expr The expression to be evaluated
|
||||
* @param expr_str The stringified version of the expression
|
||||
@@ -97,27 +101,48 @@ void m_assert(bool expr,
|
||||
|
||||
/** @brief Test if two armadillo vectors are close to each other.
|
||||
*
|
||||
* This function takes in 2 vectors and checks if they are approximately
|
||||
* equal to each other given a tolerance.
|
||||
* @details This function takes in 2 vectors and checks if they are
|
||||
* approximately equal to each other given a tolerance.
|
||||
*
|
||||
* @param a Vector a
|
||||
* @param b Vector b
|
||||
* @param tol The tolerance
|
||||
*
|
||||
* @return Boolean
|
||||
* @return bool
|
||||
* */
|
||||
bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8);
|
||||
|
||||
|
||||
static inline std::string methodName(const std::string& prettyFunction)
|
||||
/** @brief Takes in the __PRETTY_FUNCTION__ string and removes the return type.
|
||||
*
|
||||
* @details This function should only be used for the __METHOD_NAME__ macro,
|
||||
* since it takes the output from __PRETTY_FUNCTION__ and strips the return
|
||||
* type.
|
||||
*
|
||||
* @param pretty_function The string from __PRETTY_FUNCTION__
|
||||
*
|
||||
* @return std::string
|
||||
* */
|
||||
static inline std::string methodName(const std::string& pretty_function)
|
||||
{
|
||||
size_t colons = prettyFunction.find("::");
|
||||
size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
|
||||
size_t end = prettyFunction.rfind("(") - begin;
|
||||
size_t colons = pretty_function.find("::");
|
||||
size_t begin = pretty_function.substr(0,colons).rfind(" ") + 1;
|
||||
size_t end = pretty_function.rfind("(") - begin;
|
||||
|
||||
return prettyFunction.substr(begin,end) + "()";
|
||||
return pretty_function.substr(begin,end) + "()";
|
||||
}
|
||||
|
||||
|
||||
/** @brief Make path given.
|
||||
*
|
||||
* @details This tries to be the equivalent to "mkdir -p" and creates a new
|
||||
* directory whenever it needs to.
|
||||
*
|
||||
* @param path The path to be created
|
||||
* @param mode The mode/permissions for all the new directories
|
||||
*
|
||||
* @return bool
|
||||
* */
|
||||
bool mkpath(std::string path, int mode = 0777);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user