Implement force_on_particle

This commit is contained in:
Cory Balaton 2023-09-29 14:36:53 +02:00
parent f2e9004f96
commit 8e9f3db316
No known key found for this signature in database
GPG Key ID: 3E5FCEBFD80F432B

View File

@ -21,6 +21,8 @@
* */ * */
#include "PenningTrap.hpp" #include "PenningTrap.hpp"
#include <algorithm>
#include <stdexcept>
PenningTrap::PenningTrap(double B_0, double V_0, double d) PenningTrap::PenningTrap(double B_0, double V_0, double d)
{ {
@ -59,7 +61,17 @@ arma::vec PenningTrap::external_B_field(arma::vec r)
arma::vec PenningTrap::force_on_particle(int i, int j) arma::vec PenningTrap::force_on_particle(int i, int j)
{ {
// Calculate the difference between the particles' position
arma::vec::fixed<3> res = this->particles.at(i).r_vec
- this->particles.at(j).r_vec;
// Get the distance between the particles
double norm = arma::norm(res);
// Multiply res with p_j's charge divided by the norm cubed
res *= this->particles.at(j).q/(norm*norm*norm);
return res;
} }
arma::vec PenningTrap::total_force_external(int i) arma::vec PenningTrap::total_force_external(int i)