221 lines
6.2 KiB
C++
Executable File
221 lines
6.2 KiB
C++
Executable File
#include "simulation/particle.h"
|
|
#include "constants/physical_constants.h"
|
|
#include "simulation/species.h"
|
|
|
|
namespace particle {
|
|
/*
|
|
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
|
Coordinate* position,
|
|
Vector* velocity)
|
|
: specie_(specie),
|
|
position_(CylinderCoordinate(*position)),
|
|
velocity_(CartesianVector(*velocity, *position)),
|
|
id_(this->last_id_),
|
|
time_alive_s_(0.),
|
|
time_in_bin_s_(0.),
|
|
interaction_counter_(0) {
|
|
last_id_++;
|
|
}
|
|
*/
|
|
|
|
// requires the name of a species "spec_name" to be smaller than 16 characters
|
|
// this is not! checked here and will lead to undefined behaviour if this
|
|
// requirement is not fulfilled
|
|
SerializedParticle::SerializedParticle(double weight,
|
|
blitz::TinyVector<double, 3> cartPos,
|
|
blitz::TinyVector<double, 3> cartVel,
|
|
std::string spec_name,
|
|
int idx_nxt_interaction,
|
|
double time_until_collision) :
|
|
weight_(weight),
|
|
cartesian_position_(cartPos),
|
|
cartesian_velocity_(cartVel),
|
|
idx_nxt_interaction_(idx_nxt_interaction),
|
|
time_until_interaction_(time_until_collision) {
|
|
std::copy(spec_name.begin(), spec_name.end(), specie_name_.data());
|
|
specie_name_[spec_name.length()] = '\0';
|
|
}
|
|
|
|
double SerializedParticle::weight() {
|
|
return weight_;
|
|
}
|
|
|
|
blitz::TinyVector<double, 3> SerializedParticle::cartesianPosition() {
|
|
return cartesian_position_;
|
|
}
|
|
|
|
blitz::TinyVector<double, 3> SerializedParticle::cartesianVelocity() {
|
|
return cartesian_velocity_;
|
|
}
|
|
|
|
std::string SerializedParticle::specieName() {
|
|
return std::string (specie_name_.data());
|
|
}
|
|
|
|
double SerializedParticle::timeUntilCollision() {
|
|
return time_until_interaction_;
|
|
}
|
|
|
|
int SerializedParticle::indexNextInteraction() {
|
|
return idx_nxt_interaction_;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
|
const Coordinate& position,
|
|
const Vector& velocity,
|
|
const double time_birth,
|
|
const double weight)
|
|
: specie_(specie),
|
|
position_cart_(position),
|
|
position_cyl_(position),
|
|
velocity_(velocity, position),
|
|
id_(this->last_id_),
|
|
time_alive_s_(time_birth),
|
|
interaction_counter_(0),
|
|
weight_(weight) {
|
|
last_id_++;
|
|
}
|
|
|
|
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
|
const Coordinate& position,
|
|
const Vector& velocity,
|
|
const double weight)
|
|
: specie_(specie),
|
|
position_cart_(position),
|
|
position_cyl_(position),
|
|
velocity_(velocity, position),
|
|
id_(this->last_id_),
|
|
time_alive_s_(0.),
|
|
interaction_counter_(0),
|
|
weight_(weight) {
|
|
last_id_++;
|
|
}
|
|
|
|
Particle::Particle(particle::SerializedParticle sparticle, std::map<std::string,
|
|
std::shared_ptr<species::TrackedSpecie>>& tracked_species) :
|
|
specie_(tracked_species[sparticle.specieName()]),
|
|
position_cart_(sparticle.cartesianPosition()),
|
|
position_cyl_(blitz::TinyVector<double, 3>(0,0,0)),
|
|
velocity_(sparticle.cartesianVelocity()),
|
|
id_(this->last_id_),
|
|
time_alive_s_(0.),
|
|
interaction_counter_(0),
|
|
weight_(sparticle.weight()),
|
|
index_next_interaction_(sparticle.indexNextInteraction()),
|
|
time_until_collision_(sparticle.timeUntilCollision()) {
|
|
last_id_++;
|
|
position_cyl_ = CylinderCoordinate(position_cart_);
|
|
}
|
|
|
|
long int Particle::last_id_ = 0;
|
|
|
|
double Particle::mass_kg() const {
|
|
return specie_->mass_kg();
|
|
}
|
|
double Particle::charge_C() const {
|
|
return specie_->charge_C();
|
|
}
|
|
|
|
void Particle::lastId(long int id) {
|
|
last_id_ = id;
|
|
}
|
|
|
|
long int Particle::lastId() {
|
|
return last_id_;
|
|
}
|
|
|
|
void Particle::velocity(const CartesianVector& new_velocity) {
|
|
velocity_ = new_velocity;
|
|
}
|
|
|
|
CartesianVector Particle::velocity() const {
|
|
return velocity_;
|
|
}
|
|
|
|
species::TrackedSpecie* Particle::specie() const {
|
|
return specie_.get();
|
|
}
|
|
|
|
void Particle::position(const Coordinate& new_position) {
|
|
position_cart_ = CartesianCoordinate(new_position);
|
|
position_cyl_ = CylinderCoordinate(new_position);
|
|
}
|
|
|
|
CartesianCoordinate Particle::cartesianPosition() const {
|
|
return position_cart_;
|
|
}
|
|
|
|
CylinderCoordinate Particle::cylinderPosition() const {
|
|
return position_cyl_;
|
|
}
|
|
|
|
void Particle::move(const Coordinate& distance) {
|
|
position_cart_.add(distance);
|
|
position_cyl_ = CylinderCoordinate(position_cart_);
|
|
}
|
|
|
|
double Particle::kineticEnergy_eV() const {
|
|
return mass_kg() * absoluteVelocitySquared() * UnitConversion::JouleToeV / 2.;
|
|
}
|
|
|
|
double Particle::absoluteVelocity() const {
|
|
return std::sqrt(absoluteVelocitySquared());
|
|
}
|
|
|
|
double Particle::absoluteVelocitySquared() const {
|
|
return blitz::dot(velocity_.cartesianEntries(), velocity_.cartesianEntries());
|
|
}
|
|
|
|
void Particle::increaseInteractionCounter() {
|
|
interaction_counter_++;
|
|
}
|
|
long int Particle::interactionCounter() const {
|
|
return interaction_counter_;
|
|
}
|
|
|
|
void Particle::increaseTimeAlive(double time_s) {
|
|
time_alive_s_ += time_s;
|
|
}
|
|
double Particle::timeAlive() const {
|
|
return time_alive_s_;
|
|
}
|
|
|
|
long int Particle::ID() const {
|
|
return id_;
|
|
}
|
|
|
|
double Particle::weight() const {
|
|
return weight_;
|
|
}
|
|
|
|
void Particle::deposited(bool truthValue) {
|
|
deposited_ = truthValue;
|
|
}
|
|
|
|
bool Particle::wasDeposited() {
|
|
return deposited_;
|
|
}
|
|
|
|
void Particle::timeUntilCollision(const double time_until_collision) {
|
|
time_until_collision_ = time_until_collision;
|
|
}
|
|
|
|
double Particle::timeUntilCollision() const {
|
|
return time_until_collision_;
|
|
}
|
|
|
|
void Particle::reduceTimeUntilCollision(double delta) {
|
|
time_until_collision_ -= delta;
|
|
}
|
|
|
|
particle::SerializedParticle Particle::serialize() {
|
|
return particle::SerializedParticle(weight_,
|
|
position_cart_.cartesianEntries(), velocity_.cartesianEntries(),
|
|
specie_->name(), index_next_interaction_, time_until_collision_);
|
|
}
|
|
|
|
} // namespace particle
|