Coryab/code #10
@ -14,12 +14,13 @@
|
|||||||
|
|
||||||
#include <armadillo>
|
#include <armadillo>
|
||||||
|
|
||||||
#include "typedefs.hpp"
|
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
|
#include "typedefs.hpp"
|
||||||
|
|
||||||
/** @brief A class that holds attributes of a particle
|
/** @brief A class that holds attributes of a particle
|
||||||
* */
|
* */
|
||||||
class Particle {
|
class Particle
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
vec_3d r_vec; ///< position
|
vec_3d r_vec; ///< position
|
||||||
vec_3d v_vec; ///< velocity
|
vec_3d v_vec; ///< velocity
|
||||||
@ -37,7 +38,8 @@ public:
|
|||||||
* @param r_vec The initial position of the particle
|
* @param r_vec The initial position of the particle
|
||||||
* @param v_vec The initial velocity of the particle
|
* @param v_vec The initial velocity of the particle
|
||||||
* */
|
* */
|
||||||
Particle(vec_3d r_vec, vec_3d v_vec, double q = CA_CHARGE, double m = CA_MASS);
|
Particle(vec_3d r_vec, vec_3d v_vec, double q = CA_CHARGE,
|
||||||
|
double m = CA_MASS);
|
||||||
|
|
||||||
/** @brief Make private attributes available for PenningTrap.
|
/** @brief Make private attributes available for PenningTrap.
|
||||||
* */
|
* */
|
||||||
|
|||||||
@ -12,14 +12,24 @@
|
|||||||
#ifndef __CONST__
|
#ifndef __CONST__
|
||||||
#define __CONST__
|
#define __CONST__
|
||||||
|
|
||||||
#define K_E 1.38935333*1e5 ///< Coulomb constant. unit: \f$\frac{u(\mu m)^3}{(\mu s)^2 e^2}\f$
|
/** @brief Coulomb constant. unit: \f$\frac{u(\mu m)^3}{(\mu s)^2 e^2}\f$
|
||||||
|
* */
|
||||||
|
#define K_E 1.38935333 * 1e5
|
||||||
|
|
||||||
#define T 9.64852558*1e1 ///< 1 Tesla. unit: \f$ \frac{u}{(\mu s) e} \f$
|
/** @brief 1 Tesla. unit: \f$ \frac{u}{(\mu s) e} \f$
|
||||||
|
* */
|
||||||
|
#define T 9.64852558 * 1e1
|
||||||
|
|
||||||
#define V 9.64852558*1e7 ///< 1 Volt. unit: \f$ \frac{u (\mu m)^2}{(\mu s)^2 e} \f$
|
/** @brief 1 Volt. unit: \f$ \frac{u (\mu m)^2}{(\mu s)^2 e} \f$
|
||||||
|
* */
|
||||||
|
#define V 9.64852558 * 1e7
|
||||||
|
|
||||||
#define CA_MASS 40.078 ///< Mass of a single calcium ion. unit: amu
|
/** @brief Mass of a single calcium ion. unit: amu
|
||||||
|
* */
|
||||||
|
#define CA_MASS 40.078
|
||||||
|
|
||||||
#define CA_CHARGE 1. ///< Charge of a singly charged calcium ion. unit: e
|
/** @brief Charge of a singly charged calcium ion. unit: e
|
||||||
|
* */
|
||||||
|
#define CA_CHARGE 1.
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -31,8 +31,8 @@
|
|||||||
* messages by adding the -DDBG flag when compiling.
|
* messages by adding the -DDBG flag when compiling.
|
||||||
* */
|
* */
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
#define DEBUG(msg) std::cout << __FILE__ << " " << __LINE__ << ": " \
|
#define DEBUG(msg) \
|
||||||
<< msg << std::endl
|
std::cout << __FILE__ << " " << __LINE__ << ": " << msg << std::endl
|
||||||
#else
|
#else
|
||||||
#define DEBUG(msg)
|
#define DEBUG(msg)
|
||||||
#endif
|
#endif
|
||||||
@ -43,15 +43,14 @@
|
|||||||
* This macro calls the m_assert function which is a more informative
|
* This macro calls the m_assert function which is a more informative
|
||||||
* assertion function than the regular assert function from cassert.
|
* assertion function than the regular assert function from cassert.
|
||||||
* */
|
* */
|
||||||
#define ASSERT(expr, msg) m_assert(expr, #expr, __METHOD_NAME__, __FILE__, \
|
#define ASSERT(expr, msg) \
|
||||||
__LINE__, msg)
|
m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)
|
||||||
|
|
||||||
/** @def __METHOD_NAME__
|
/** @def __METHOD_NAME__
|
||||||
* @brief Get the name of the current method/function without the return type.
|
* @brief Get the name of the current method/function without the return type.
|
||||||
* */
|
* */
|
||||||
#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
|
#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
|
||||||
|
|
||||||
|
|
||||||
/** @brief Turns a double into a string written in scientific format.
|
/** @brief Turns a double into a string written in scientific format.
|
||||||
*
|
*
|
||||||
* @details The code is stolen from https://github.com/anderkve/FYS3150.
|
* @details The code is stolen from https://github.com/anderkve/FYS3150.
|
||||||
@ -64,8 +63,8 @@
|
|||||||
* */
|
* */
|
||||||
std::string scientific_format(double d, int width = 20, int prec = 10);
|
std::string scientific_format(double d, int width = 20, int prec = 10);
|
||||||
|
|
||||||
|
/** @brief Turns a vector of doubles into a string written in scientific
|
||||||
/** @brief Turns a vector of doubles into a string written in scientific format.
|
* format.
|
||||||
*
|
*
|
||||||
* @details The code is stolen from https://github.com/anderkve/FYS3150.
|
* @details The code is stolen from https://github.com/anderkve/FYS3150.
|
||||||
*
|
*
|
||||||
@ -75,11 +74,9 @@ std::string scientific_format(double d, int width=20, int prec=10);
|
|||||||
*
|
*
|
||||||
* @return std::string
|
* @return std::string
|
||||||
* */
|
* */
|
||||||
std::string scientific_format(const std::vector<double>& v,
|
std::string scientific_format(const std::vector<double> &v, int width = 20,
|
||||||
int width=20,
|
|
||||||
int prec = 10);
|
int prec = 10);
|
||||||
|
|
||||||
|
|
||||||
/** @brief Test an expression, confirm that test is ok, or abort execution.
|
/** @brief Test an expression, confirm that test is ok, or abort execution.
|
||||||
*
|
*
|
||||||
* @details This function takes in an expression and prints an OK message if
|
* @details This function takes in an expression and prints an OK message if
|
||||||
@ -92,13 +89,8 @@ std::string scientific_format(const std::vector<double>& v,
|
|||||||
* @param line The line number where this function is called from
|
* @param line The line number where this function is called from
|
||||||
* @param msg The message to be displayed
|
* @param msg The message to be displayed
|
||||||
* */
|
* */
|
||||||
void m_assert(bool expr,
|
void m_assert(bool expr, std::string expr_str, std::string func,
|
||||||
std::string expr_str,
|
std::string file, int line, std::string msg);
|
||||||
std::string func,
|
|
||||||
std::string file,
|
|
||||||
int line,
|
|
||||||
std::string msg);
|
|
||||||
|
|
||||||
|
|
||||||
/** @brief Test if two armadillo vectors are close to each other.
|
/** @brief Test if two armadillo vectors are close to each other.
|
||||||
*
|
*
|
||||||
@ -113,7 +105,6 @@ void m_assert(bool expr,
|
|||||||
* */
|
* */
|
||||||
bool close_to(arma::vec &a, arma::vec &b, double tol = 1e-8);
|
bool close_to(arma::vec &a, arma::vec &b, double tol = 1e-8);
|
||||||
|
|
||||||
|
|
||||||
/** @brief Takes in the __PRETTY_FUNCTION__ string and removes the return type.
|
/** @brief Takes in the __PRETTY_FUNCTION__ string and removes the return type.
|
||||||
*
|
*
|
||||||
* @details This function should only be used for the __METHOD_NAME__ macro,
|
* @details This function should only be used for the __METHOD_NAME__ macro,
|
||||||
@ -133,7 +124,6 @@ static inline std::string methodName(const std::string& pretty_function)
|
|||||||
return pretty_function.substr(begin, end) + "()";
|
return pretty_function.substr(begin, end) + "()";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @brief Make path given.
|
/** @brief Make path given.
|
||||||
*
|
*
|
||||||
* @details This tries to be the equivalent to "mkdir -p" and creates a new
|
* @details This tries to be the equivalent to "mkdir -p" and creates a new
|
||||||
|
|||||||
@ -45,8 +45,9 @@ PenningTrap::PenningTrap(std::vector<Particle> particles, double B_0,
|
|||||||
|
|
||||||
void PenningTrap::set_pertubation(double f, double omega_V)
|
void PenningTrap::set_pertubation(double f, double omega_V)
|
||||||
{
|
{
|
||||||
this->perturbation
|
this->perturbation = [f, omega_V](double t) {
|
||||||
= [f, omega_V](double t) { return f * std::cos(omega_V * t); };
|
return f * std::cos(omega_V * t);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void PenningTrap::reinitialize(double f, double omega_V, double t)
|
void PenningTrap::reinitialize(double f, double omega_V, double t)
|
||||||
@ -167,8 +168,8 @@ void PenningTrap::evolve_RK4(double dt, bool particle_interaction)
|
|||||||
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;
|
||||||
|
|
||||||
vec_3d (PenningTrap::*force)(uint)
|
vec_3d (PenningTrap::*force)(uint) =
|
||||||
= particle_interaction ? &PenningTrap::total_force
|
particle_interaction ? &PenningTrap::total_force
|
||||||
: &PenningTrap::total_force_external;
|
: &PenningTrap::total_force_external;
|
||||||
|
|
||||||
size_t size = this->particles.size();
|
size_t size = this->particles.size();
|
||||||
@ -188,10 +189,10 @@ void PenningTrap::evolve_RK4(double dt, bool particle_interaction)
|
|||||||
this->k_v[i][j] = (this->*force)(j) / this->particles[j].m;
|
this->k_v[i][j] = (this->*force)(j) / this->particles[j].m;
|
||||||
this->k_r[i][j] = this->particles[j].v_vec;
|
this->k_r[i][j] = this->particles[j].v_vec;
|
||||||
|
|
||||||
tmp_particles[j].v_vec
|
tmp_particles[j].v_vec =
|
||||||
= original_particles[j].v_vec + this->v_func(i, j, dt);
|
original_particles[j].v_vec + this->v_func(i, j, dt);
|
||||||
tmp_particles[j].r_vec
|
tmp_particles[j].r_vec =
|
||||||
= original_particles[j].r_vec + this->r_func(i, j, dt);
|
original_particles[j].r_vec + this->r_func(i, j, dt);
|
||||||
}
|
}
|
||||||
this->particles = tmp_particles;
|
this->particles = tmp_particles;
|
||||||
}
|
}
|
||||||
@ -205,8 +206,8 @@ void PenningTrap::evolve_forward_euler(double dt, bool particle_interaction)
|
|||||||
vec_3d force_res[size];
|
vec_3d force_res[size];
|
||||||
Particle *p;
|
Particle *p;
|
||||||
|
|
||||||
vec_3d (PenningTrap::*force)(uint)
|
vec_3d (PenningTrap::*force)(uint) =
|
||||||
= particle_interaction ? &PenningTrap::total_force
|
particle_interaction ? &PenningTrap::total_force
|
||||||
: &PenningTrap::total_force_external;
|
: &PenningTrap::total_force_external;
|
||||||
|
|
||||||
// Calculating the force for each particle is independent and therefore
|
// Calculating the force for each particle is independent and therefore
|
||||||
@ -220,9 +221,8 @@ void PenningTrap::evolve_forward_euler(double dt, bool particle_interaction)
|
|||||||
// this as well
|
// this as well
|
||||||
#pragma omp parallel for private(p)
|
#pragma omp parallel for private(p)
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
p = &this->particles[i];
|
p->r_vec += dt * this->particles[i].v_vec;
|
||||||
p->r_vec += dt * p->v_vec;
|
p->v_vec += dt * force_res[i] / this->particles[i].m;
|
||||||
p->v_vec += dt * force_res[i] / p->m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->t += dt;
|
this->t += dt;
|
||||||
@ -241,11 +241,9 @@ simulation_t PenningTrap::simulate(double time, uint steps, std::string method,
|
|||||||
void (PenningTrap::*func)(double, bool);
|
void (PenningTrap::*func)(double, bool);
|
||||||
if (method == "rk4") {
|
if (method == "rk4") {
|
||||||
func = &PenningTrap::evolve_RK4;
|
func = &PenningTrap::evolve_RK4;
|
||||||
}
|
} else if (method == "euler") {
|
||||||
else if (method == "euler") {
|
|
||||||
func = &PenningTrap::evolve_forward_euler;
|
func = &PenningTrap::evolve_forward_euler;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::cout << "Not a valid method!" << std::endl;
|
std::cout << "Not a valid method!" << std::endl;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -273,8 +271,8 @@ void PenningTrap::write_simulation_to_dir(std::string path, double time,
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
simulation_t res
|
simulation_t res =
|
||||||
= this->simulate(time, steps, method, particle_interaction);
|
this->simulate(time, steps, method, particle_interaction);
|
||||||
|
|
||||||
std::ofstream ofile;
|
std::ofstream ofile;
|
||||||
|
|
||||||
@ -308,11 +306,9 @@ double PenningTrap::fraction_of_particles_left(double time, uint steps,
|
|||||||
void (PenningTrap::*func)(double, bool);
|
void (PenningTrap::*func)(double, bool);
|
||||||
if (method == "rk4") {
|
if (method == "rk4") {
|
||||||
func = &PenningTrap::evolve_RK4;
|
func = &PenningTrap::evolve_RK4;
|
||||||
}
|
} else if (method == "euler") {
|
||||||
else if (method == "euler") {
|
|
||||||
func = &PenningTrap::evolve_forward_euler;
|
func = &PenningTrap::evolve_forward_euler;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::cout << "Not a valid method!" << std::endl;
|
std::cout << "Not a valid method!" << std::endl;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|||||||
30
src/main.cpp
30
src/main.cpp
@ -42,8 +42,8 @@ vec_3d 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::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));
|
||||||
vec_3d res{std::real(f), std::imag(f),
|
vec_3d res{std::real(f), std::imag(f),
|
||||||
20. * std::cos(std::sqrt(w_z2) * t)};
|
20. * std::cos(std::sqrt(w_z2) * t)};
|
||||||
@ -156,8 +156,8 @@ void potential_resonance_wide_sweep()
|
|||||||
double freq_start = .2;
|
double freq_start = .2;
|
||||||
double freq_end = 2.5;
|
double freq_end = 2.5;
|
||||||
double freq_increment = .02;
|
double freq_increment = .02;
|
||||||
size_t freq_iterations
|
size_t freq_iterations =
|
||||||
= (size_t)((freq_end - freq_start) / freq_increment) + 1;
|
(size_t)((freq_end - freq_start) / freq_increment) + 1;
|
||||||
|
|
||||||
double res[4][freq_iterations];
|
double res[4][freq_iterations];
|
||||||
|
|
||||||
@ -176,14 +176,14 @@ void potential_resonance_wide_sweep()
|
|||||||
{
|
{
|
||||||
// Each thread creates a PenningTrap instance and reuses it throughout
|
// Each thread creates a PenningTrap instance and reuses it throughout
|
||||||
// the sweep.
|
// the sweep.
|
||||||
PenningTrap trap((unsigned int)100);
|
PenningTrap trap((uint)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.
|
// Reset particles and give new time dependent potential.
|
||||||
trap.reinitialize(amplitudes[i], res[0][j]);
|
trap.reinitialize(amplitudes[i], res[0][j]);
|
||||||
res[i + 1][j]
|
res[i + 1][j] =
|
||||||
= trap.fraction_of_particles_left(time, N, "rk4", false);
|
trap.fraction_of_particles_left(time, N, "rk4", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,8 +213,8 @@ void potential_resonance_narrow_sweep()
|
|||||||
double freq_start = 1.;
|
double freq_start = 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 =
|
||||||
= (size_t)((freq_end - freq_start) / freq_increment);
|
(size_t)((freq_end - freq_start) / freq_increment);
|
||||||
|
|
||||||
double res[4][freq_iterations];
|
double res[4][freq_iterations];
|
||||||
|
|
||||||
@ -233,14 +233,14 @@ void potential_resonance_narrow_sweep()
|
|||||||
{
|
{
|
||||||
// Each thread creates a PenningTrap instance and reuses it throughout
|
// Each thread creates a PenningTrap instance and reuses it throughout
|
||||||
// the sweep.
|
// the sweep.
|
||||||
PenningTrap trap((unsigned int)100);
|
PenningTrap trap((uint)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.
|
// Reset particles and give new time dependent potential.
|
||||||
trap.reinitialize(amplitudes[i], res[0][j]);
|
trap.reinitialize(amplitudes[i], res[0][j]);
|
||||||
res[i + 1][j]
|
res[i + 1][j] =
|
||||||
= trap.fraction_of_particles_left(time, N, "rk4", false);
|
trap.fraction_of_particles_left(time, N, "rk4", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,8 +270,8 @@ void potential_resonance_narrow_sweep_interaction()
|
|||||||
double freq_start = 1.;
|
double freq_start = 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 =
|
||||||
= (size_t)((freq_end - freq_start) / freq_increment);
|
(size_t)((freq_end - freq_start) / freq_increment);
|
||||||
|
|
||||||
double res[4][freq_iterations];
|
double res[4][freq_iterations];
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ void potential_resonance_narrow_sweep_interaction()
|
|||||||
{
|
{
|
||||||
// Each thread creates a PenningTrap instance and reuses it throughout
|
// Each thread creates a PenningTrap instance and reuses it throughout
|
||||||
// the sweep.
|
// the sweep.
|
||||||
PenningTrap trap((unsigned int)100);
|
PenningTrap trap((uint)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++) {
|
||||||
|
|||||||
@ -20,7 +20,8 @@
|
|||||||
|
|
||||||
/** @brief Test class for the Penning trap.
|
/** @brief Test class for the Penning trap.
|
||||||
* */
|
* */
|
||||||
class PenningTrapTest {
|
class PenningTrapTest
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
/** @brief Test that the external E field gives correct values.
|
/** @brief Test that the external E field gives correct values.
|
||||||
* */
|
* */
|
||||||
@ -34,17 +35,17 @@ public:
|
|||||||
tests.push_back(
|
tests.push_back(
|
||||||
std::make_pair(vec_3d{0., 0., 0.}, vec_3d{0., 0., 0.}));
|
std::make_pair(vec_3d{0., 0., 0.}, vec_3d{0., 0., 0.}));
|
||||||
|
|
||||||
tests.push_back(std::make_pair(vec_3d{10., 0., 0.},
|
tests.push_back(
|
||||||
vec_3d{96.4852558, 0., 0.}));
|
std::make_pair(vec_3d{10., 0., 0.}, vec_3d{96.4852558, 0., 0.}));
|
||||||
|
|
||||||
tests.push_back(std::make_pair(vec_3d{10., 0., 0.},
|
tests.push_back(
|
||||||
vec_3d{96.4852558, 0., 0.}));
|
std::make_pair(vec_3d{10., 0., 0.}, vec_3d{96.4852558, 0., 0.}));
|
||||||
|
|
||||||
tests.push_back(std::make_pair(vec_3d{0., 10., 0.},
|
tests.push_back(
|
||||||
vec_3d{0., 96.4852558, 0.}));
|
std::make_pair(vec_3d{0., 10., 0.}, vec_3d{0., 96.4852558, 0.}));
|
||||||
|
|
||||||
tests.push_back(std::make_pair(vec_3d{0., 0., 10.},
|
tests.push_back(
|
||||||
vec_3d{0., 0., -192.9705116}));
|
std::make_pair(vec_3d{0., 0., 10.}, vec_3d{0., 0., -192.9705116}));
|
||||||
|
|
||||||
vec_3d result;
|
vec_3d result;
|
||||||
vec_3d v;
|
vec_3d v;
|
||||||
@ -106,8 +107,7 @@ public:
|
|||||||
static void test_total_force_external()
|
static void test_total_force_external()
|
||||||
{
|
{
|
||||||
PenningTrap trap;
|
PenningTrap trap;
|
||||||
trap.add_particle(
|
trap.add_particle(Particle(vec_3d{1., 2., 3.}, vec_3d{3., 4., 5.}));
|
||||||
Particle(vec_3d{1., 2., 3.}, vec_3d{3., 4., 5.}));
|
|
||||||
|
|
||||||
vec_3d expected{395.58954878, -270.15871624, -57.89115348};
|
vec_3d expected{395.58954878, -270.15871624, -57.89115348};
|
||||||
vec_3d result = trap.total_force_external(0);
|
vec_3d result = trap.total_force_external(0);
|
||||||
@ -122,8 +122,7 @@ public:
|
|||||||
static void test_total_force_particles()
|
static void test_total_force_particles()
|
||||||
{
|
{
|
||||||
PenningTrap trap;
|
PenningTrap trap;
|
||||||
trap.add_particle(
|
trap.add_particle(Particle(vec_3d{0., 0., 0.}, vec_3d{0., 0., 0.}));
|
||||||
Particle(vec_3d{0., 0., 0.}, vec_3d{0., 0., 0.}));
|
|
||||||
|
|
||||||
vec_3d expected{0., 0., 0.};
|
vec_3d expected{0., 0., 0.};
|
||||||
vec_3d result = trap.total_force_particles(0);
|
vec_3d result = trap.total_force_particles(0);
|
||||||
@ -131,12 +130,9 @@ public:
|
|||||||
"Testing the total force of all particles on particle 0 "
|
"Testing the total force of all particles on particle 0 "
|
||||||
"with only a single particle");
|
"with only a single particle");
|
||||||
|
|
||||||
trap.add_particle(
|
trap.add_particle(Particle(vec_3d{1., 0., 0.}, vec_3d{0., 0., 0.}));
|
||||||
Particle(vec_3d{1., 0., 0.}, vec_3d{0., 0., 0.}));
|
trap.add_particle(Particle(vec_3d{0., 1., 0.}, vec_3d{0., 0., 0.}));
|
||||||
trap.add_particle(
|
trap.add_particle(Particle(vec_3d{0., 0., 1.}, vec_3d{0., 0., 0.}));
|
||||||
Particle(vec_3d{0., 1., 0.}, vec_3d{0., 0., 0.}));
|
|
||||||
trap.add_particle(
|
|
||||||
Particle(vec_3d{0., 0., 1.}, vec_3d{0., 0., 0.}));
|
|
||||||
|
|
||||||
expected = vec_3d().fill(-138935.333);
|
expected = vec_3d().fill(-138935.333);
|
||||||
result = trap.total_force_particles(0);
|
result = trap.total_force_particles(0);
|
||||||
|
|||||||
@ -19,7 +19,8 @@ std::string scientific_format(double d, int width, int prec)
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string scientific_format(const std::vector<double> &v, int width, int prec)
|
std::string scientific_format(const std::vector<double> &v, int width,
|
||||||
|
int prec)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
for (double elem : v) {
|
for (double elem : v) {
|
||||||
@ -32,8 +33,7 @@ static void print_message(std::string msg)
|
|||||||
{
|
{
|
||||||
if (msg.size() > 0) {
|
if (msg.size() > 0) {
|
||||||
std::cout << "message: " << msg << "\n\n";
|
std::cout << "message: " << msg << "\n\n";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,8 +47,7 @@ void m_assert(bool expr, std::string expr_str, std::string f, std::string file,
|
|||||||
if (expr) {
|
if (expr) {
|
||||||
std::cout << "\x1B[32mOK\033[0m\n";
|
std::cout << "\x1B[32mOK\033[0m\n";
|
||||||
print_message(msg);
|
print_message(msg);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::cout << "\x1B[31mFAIL\033[0m\n";
|
std::cout << "\x1B[31mFAIL\033[0m\n";
|
||||||
print_message(msg);
|
print_message(msg);
|
||||||
std::cout << file << " " << line << ": Assertion \"" << expr_str
|
std::cout << file << " " << line << ": Assertion \"" << expr_str
|
||||||
@ -85,11 +84,11 @@ bool mkpath(std::string path, int mode)
|
|||||||
pos = path.find('/', pos);
|
pos = path.find('/', pos);
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
cur_dir = path.substr(0, pos);
|
cur_dir = path.substr(0, pos);
|
||||||
if (mkdir(cur_dir.c_str(), mode) != 0 && stat(cur_dir.c_str(), &buf) != 0) {
|
if (mkdir(cur_dir.c_str(), mode) != 0
|
||||||
|
&& stat(cur_dir.c_str(), &buf) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user