#ifndef PARTICLE_H #define PARTICLE_H #include "blitz/array.h" #include "simulation/coordinates.h" #include "simulation/species.h" #include class MpiParticleReader; namespace particle { class SerializedParticle { public: SerializedParticle(double weight, blitz::TinyVector cart_pos, blitz::TinyVector cart_vel, std::string spec_name, int next_interaction_index, double time_until_interaction); SerializedParticle() {}; double weight(); blitz::TinyVector cartesianPosition(); blitz::TinyVector cartesianVelocity(); std::string specieName(); double timeUntilCollision(); int indexNextInteraction(); private: blitz::TinyVector cartesian_position_; blitz::TinyVector cartesian_velocity_; // has to include null character, s.t. the transformation back // to a string becomes trivial. This requires the actual string // to be 16-1=15 characters long at most // (it can be shorter due to the null character) // Example: "e-" -> ['e', '-', '\0', ...] gets correctly transformed back // into "e-" std::array specie_name_; double weight_; int idx_nxt_interaction_; double time_until_interaction_; }; class Particle { public: Particle(std::shared_ptr specie, const Coordinate& position, const Vector& velocity, const double time_birth, const double weight); Particle(std::shared_ptr specie, const Coordinate& position, const Vector& velocity, const double weight); Particle(particle::SerializedParticle sparticle, std::map>& tracked_species); void position(const Coordinate& new_position); CartesianCoordinate cartesianPosition() const; CylinderCoordinate cylinderPosition() const; void velocity(const CartesianVector& new_velocity); CartesianVector velocity() const; void move(const Coordinate& distance); double kineticEnergy_eV() const; double absoluteVelocity() const; double absoluteVelocitySquared() const; double mass_kg() const; double charge_C() const; species::TrackedSpecie* specie() const; static void lastId(long int id); static long int lastId(); // only local on this cpu void increaseInteractionCounter(); long int interactionCounter() const; void increaseTimeAlive(double time_s); double timeAlive() const; long int ID() const; double weight() const; void indexNextInteration(const int index) { index_next_interaction_ = index; }; int indexNextInteraction() { return index_next_interaction_; }; void invalidateNextInteraction() { index_next_interaction_ = -1; }; bool isNextInteractionValid() { return index_next_interaction_ >= 0; }; void timeUntilCollision(const double time_until_collision); double timeUntilCollision() const; void reduceTimeUntilCollision(const double delta); void deposited(bool truthValue=true); bool wasDeposited(); void setLocalFields(const blitz::TinyVector& E, const blitz::TinyVector& B); blitz::TinyVector getLocalE() const; blitz::TinyVector getLocalB() const; bool areLocalFieldsSet() const; // note: particle id is not being stored! particle::SerializedParticle serialize(); private: double weight_; CartesianVector velocity_; CartesianCoordinate position_cart_; CylinderCoordinate position_cyl_; blitz::TinyVector local_E_cart_ = 0.; blitz::TinyVector local_B_cart_ = 0.; double time_alive_s_; // double time_in_bin_s_; long int interaction_counter_; bool deposited_ = false; bool set_local_fields_ = false; // index of the interaction with the sortest distance (-1 if that's none of them) int index_next_interaction_ = -1; double time_until_collision_; std::shared_ptr specie_; long int id_; static long int last_id_; // only local on this cpu }; }; // namespace particle #endif /* PARTICLE_H */