Initial source
This commit is contained in:
41
include/Particle.hpp
Normal file
41
include/Particle.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/** @file Particle.hpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 0.1
|
||||
*
|
||||
* @brief A class that holds the properties of a particle.
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#ifndef __PARTICLE__
|
||||
#define __PARTICLE__
|
||||
|
||||
#include <armadillo>
|
||||
|
||||
/** @brief A class that holds attributes of a particle
|
||||
* */
|
||||
class Particle {
|
||||
private:
|
||||
double q; ///< Charge
|
||||
double m; ///< Mass
|
||||
arma::vec::fixed<3> r_vec; ///< position
|
||||
arma::vec::fixed<3> v_vec; ///< velocity
|
||||
|
||||
public:
|
||||
/** @brief Initialize the particle.
|
||||
*
|
||||
* @details Initialize the particle with a charge, mass, position and
|
||||
* velocity.
|
||||
* */
|
||||
Particle(double q, double m,
|
||||
arma::vec::fixed<3> r_vec,
|
||||
arma::vec::fixed<3> v_vec);
|
||||
|
||||
/** @brief Make private attributes available for PenningTrap.
|
||||
* */
|
||||
friend class PenningTrap;
|
||||
};
|
||||
|
||||
#endif
|
||||
80
include/PenningTrap.hpp
Normal file
80
include/PenningTrap.hpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/** @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 "constants.hpp"
|
||||
#include "Particle.hpp"
|
||||
|
||||
/** @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
|
||||
|
||||
public:
|
||||
/** @brief Set B_0, V_0 and d.
|
||||
* */
|
||||
PenningTrap(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
|
||||
* */
|
||||
arma::vec external_E_field(arma::vec r);
|
||||
|
||||
/** @brief Calculate B at point r
|
||||
* */
|
||||
arma::vec external_B_field(arma::vec r);
|
||||
|
||||
/** @brief Calculate the force between 2 particles.
|
||||
*
|
||||
* @details Calculate the force exhibited on particle p_i from
|
||||
* particle p_j.
|
||||
* */
|
||||
arma::vec 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.
|
||||
* */
|
||||
arma::vec total_force_external(int i);
|
||||
|
||||
/** @brief Calculate the total force on a particle from other particles.
|
||||
* */
|
||||
arma::vec total_force_particles(int i);
|
||||
|
||||
/** @brief calculate the total force on a particle.
|
||||
* */
|
||||
arma::vec total_force(int i);
|
||||
|
||||
/** @brief Go forward one timestep using the RK4 method
|
||||
* */
|
||||
void evolve_RK4(double dt);
|
||||
|
||||
/** @brief Go forward one timestep using the forward Euler method
|
||||
* */
|
||||
void evolve_forward_euler(double dt);
|
||||
};
|
||||
|
||||
#endif
|
||||
21
include/constants.hpp
Normal file
21
include/constants.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/** @file constants.hpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 0.1
|
||||
*
|
||||
* @brief Library of constants
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#ifndef __CONST__
|
||||
#define __CONST__
|
||||
|
||||
#define K_E 138935.333 ///< Coulomb constant. unit: \f$\frac{u(\mu m)^3}{(\mu s)^2 e^2}\f$
|
||||
|
||||
#define T 96.4852558 ///< 1 Tesla. unit: \f$ \frac{u}{(\mu s) e} \f$
|
||||
|
||||
#define V 96485255.8 ///< 1 Volt. unit: \f$ \frac{u (\mu m)^2}{(\mu s)^2 e} \f$
|
||||
|
||||
#endif
|
||||
65
include/utils.hpp
Normal file
65
include/utils.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/** @file utils.hpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief Function prototypes and macros that are useful.
|
||||
*
|
||||
* These utility function are mainly for convenience and aren't directly
|
||||
* related to the project.
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#ifndef __UTILS__
|
||||
#define __UTILS__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
/** @def DEBUG(msg)
|
||||
* @brief Writes a debug message
|
||||
*
|
||||
* This function writes a debug message that includes the filename,
|
||||
* line number, and a custom message. The function is wrapped in an ifdef
|
||||
* that checks if DBG is defined, so one can choose to display the debug
|
||||
* messages by adding the -DDBG flag when compiling.
|
||||
* */
|
||||
#ifdef DBG
|
||||
#define DEBUG(msg) std::cout << __FILE__ << " " << __LINE__ << ": " \
|
||||
<< msg << std::endl
|
||||
#else
|
||||
#define DEBUG(msg)
|
||||
#endif
|
||||
|
||||
/** 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.
|
||||
*
|
||||
* @param d The number to stringify
|
||||
* @param width The reserved width of the string
|
||||
* @param prec The precision of the stringified number
|
||||
*
|
||||
* @return 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.
|
||||
*
|
||||
* @param v The vector to stringify
|
||||
* @param width The reserved width of the string
|
||||
* @param prec The precision of the stringified number
|
||||
*
|
||||
* @return String
|
||||
* */
|
||||
std::string scientific_format(const std::vector<double>& v,
|
||||
int width=20,
|
||||
int prec=10);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user