#include "simulation/interaction.h" #include "constants/physical_constants.h" #include "simulation/coordinates.h" #include "simulation/density_field.h" #include "simulation/drift_velocity.h" #include "simulation/kinematic.h" #include "simulation/velocity_distribution.h" namespace interaction { InteractionOutput::InteractionOutput() : delete_current_particle_(false){}; void InteractionOutput::deleteCurrentParticle(bool new_decider) { delete_current_particle_ = new_decider; } bool InteractionOutput::deleteCurrentParticle() { return delete_current_particle_; } void InteractionOutput::add(const particle::Particle& new_particle) { new_particles_.push_back(new_particle); } std::vector InteractionOutput::newParticles() { return new_particles_; } Interaction::Interaction(std::function cross_section, std::shared_ptr target) : cross_section_(cross_section), target_(target), target_velocity_(blitz::TinyVector (0,0,0)) {}; // assumes that v_particle >> v_target double Interaction::macroscopicCrossSection(particle::Particle& particle) { const auto x_particle = particle.cylinderPosition(); const blitz::TinyVector v_particle = particle.velocity().cartesianEntries(); if(!target_->driftVelocity()) { ERROR(target_->name() + ": does not have a drift velocity!"); } const blitz::TinyVector v_partner = target_->driftVelocity()->driftVelocity(x_particle).cartesianEntries(); const blitz::TinyVector velocity_target_fixed = kinematic::velocityTargetFixed(v_particle, v_partner, particle.mass_kg(), target_->mass_kg()); const double kinetic_energy_eV = kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg()) * UnitConversion::JouleToeV; const double density = target_->densityField()->density(x_particle); const double cross_section = microscopicCrossSection(kinetic_energy_eV, particle.cylinderPosition()); return cross_section * density; }; double Interaction::microscopicCrossSection(double energy_eV, const Coordinate& position) { return cross_section_(energy_eV); } // think i need to include the magnetic field for it to be really correct // also sets the velocity of the interaction partner double Interaction::drawCollisionTime(particle::Particle& particle, RandomNumbers* generator) { CartesianVector particle_velocity = particle.velocity(); // approximation for electrons: v_e >> v_t if(particle.specie()->type() == species::ImplementedSpecies::electron) { target_velocity_ = CartesianVector(blitz::TinyVector(0,0,0)); } else { target_velocity_ = target_->velocityDistribution()-> rollVelocity(particle.cylinderPosition(), generator->engine()); // // if no drift velocity is present, then assume target at rest otherwise // // use the drift velocity if(target_->driftVelocity()) { // auto tmp = target_->driftVelocity()->driftVelocity(particle.position()); target_velocity_.add(target_->driftVelocity()->driftVelocity( particle.cartesianPosition(), particle.cylinderPosition()), particle.cartesianPosition()); } } // target_velocity_ = CartesianVector(blitz::TinyVector(0.,0.,0.)); // masses are irrelevant for the transformation const blitz::TinyVector velocity_target_fixed = kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(), target_velocity_.cartesianEntries(), 0, 0); const double relative_velocity = kinematic::norm(velocity_target_fixed); // check if the relative velocity is smaller than an epsilon compared to the larger // of the two present velocities (to avoid division by 0 if either is 0) probably // a better version possible if(relative_velocity/std::max( kinematic::norm(particle_velocity.cartesianEntries()), kinematic::norm(target_velocity_.cartesianEntries()) ) < SimConstants::compare_epsilon) { return std::numeric_limits::max(); } const double energy_eV = kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())* UnitConversion::JouleToeV; const double crosssection = microscopicCrossSection(energy_eV, particle.cylinderPosition()); const double density = target_->densityField()->density(particle.cylinderPosition()); const double random_number = generator->rollUniform(0.,1.); if (random_number == 0) { return std::numeric_limits::max(); } const double distance_target_fixed = - 1./(crosssection * density) * log(random_number); const double time = distance_target_fixed / relative_velocity; return time; } }; // namespace interaction