Overload constructor and format

This commit is contained in:
Cory Balaton 2023-10-08 17:25:43 +02:00
parent 51a381e672
commit 0b52008d4d
No known key found for this signature in database
GPG Key ID: 3E5FCEBFD80F432B
2 changed files with 36 additions and 10 deletions

View File

@ -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<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);

View File

@ -17,6 +17,7 @@
#include "constants.hpp"
#include "utils.hpp"
#include <cstdlib>
#include <vector>
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<Particle> 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<void(double)> 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);
};
func = [this](double dt) { this->evolve_forward_euler(dt); };
}
else {
std::cout << "Not a valid method!" << std::endl;