From 0b52008d4d71577a4dbeb71deea5aefdbf439159 Mon Sep 17 00:00:00 2001 From: Cory Date: Sun, 8 Oct 2023 17:25:43 +0200 Subject: [PATCH] Overload constructor and format --- include/PenningTrap.hpp | 6 ++++++ src/PenningTrap.cpp | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/PenningTrap.hpp b/include/PenningTrap.hpp index 1c7d56c..50874f8 100644 --- a/include/PenningTrap.hpp +++ b/include/PenningTrap.hpp @@ -42,6 +42,12 @@ public: * */ 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 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); diff --git a/src/PenningTrap.cpp b/src/PenningTrap.cpp index c4fea93..6dce7b0 100644 --- a/src/PenningTrap.cpp +++ b/src/PenningTrap.cpp @@ -17,6 +17,7 @@ #include "constants.hpp" #include "utils.hpp" #include +#include PenningTrap::PenningTrap(double B_0, double V_0, double d) { @@ -25,6 +26,29 @@ PenningTrap::PenningTrap(double B_0, double V_0, double d) this->d = d; } +PenningTrap::PenningTrap(int i, double B_0, double V_0, double d) +{ + this->B_0 = B_0; + this->V_0 = V_0; + this->d = d; + + arma::vec r, v; + for (int j = 0; j < i; j++) { + r = arma::vec(3).randn() * .1 * this->d; + v = arma::vec(3).randn() * .1 * this->d; + this->add_particle(Particle(1., 40., r, v)); + } +} + +PenningTrap::PenningTrap(std::vector particles, double B_0, + double V_0, double d) +{ + this->B_0 = B_0; + this->V_0 = V_0; + this->d = d; + this->particles = particles; +} + void PenningTrap::add_particle(Particle particle) { this->particles.push_back(particle); @@ -196,14 +220,10 @@ sim_arr PenningTrap::simulate(double time, int steps, std::string method) std::function func; if (method == "rk4") { - func = [this](double dt) { - this->evolve_RK4(dt); - }; + func = [this](double dt) { this->evolve_RK4(dt); }; } - else if(method == "euler") { - func = [this](double dt) { - this->evolve_forward_euler(dt); - }; + else if (method == "euler") { + func = [this](double dt) { this->evolve_forward_euler(dt); }; } else { std::cout << "Not a valid method!" << std::endl; @@ -212,11 +232,11 @@ sim_arr PenningTrap::simulate(double time, int steps, std::string method) int size = this->particles.size(); - for (int j=0; jparticles[i].r_vec; } - func(dt); + func(dt); } return res;