diff --git a/include/interactions/recombination.h b/include/interactions/recombination.h index 99b0a53..63eae34 100755 --- a/include/interactions/recombination.h +++ b/include/interactions/recombination.h @@ -15,6 +15,8 @@ class Recombination : public Interaction { double macroscopicCrossSection(particle::Particle& particle); + double drawCollisionTime(particle::Particle& particle, RandomNumbers* generator); + private: double macroscopicCrossSection(const Coordinate& position, const int bin_index); std::shared_ptr recombination_target_; diff --git a/src/interactions/recombination.cpp b/src/interactions/recombination.cpp index e7e6f25..10cf075 100755 --- a/src/interactions/recombination.cpp +++ b/src/interactions/recombination.cpp @@ -7,6 +7,7 @@ #include "constants/physical_constants.h" #include "simulation/drift_velocity.h" #include "simulation/electromagnetic_field.h" +#include "simulation/velocity_distribution.h" namespace interaction { @@ -165,4 +166,80 @@ double Recombination::macroscopicCrossSection(const Coordinate& position, return differential_density_value * integrated_microscopic_cross_section; } +double Recombination::drawCollisionTime(particle::Particle& particle, + RandomNumbers* generator) { + CartesianVector particle_velocity = particle.velocity(); + + // Assumes that B || z, which is obviously not necessarily the case !!! + target_velocity_ = recombination_target_->velocityDistributionFromDensityField() + ->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()); + } + + // for testing purposes + // 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 = + (recombination_target_->type() == species::ImplementedSpecies::electron) ? + kinematic::kineticEnergy(velocity_target_fixed, recombination_target_->mass_kg())* + UnitConversion::JouleToeV : + 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()); + // Use the density for drawing field, since it contains the density of the earlier + // timestep + const double density = recombination_target_->densityForDrawing() + ->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; + + +#ifdef debug_level2 + std::stringstream out; + out << "particle energy: " << particle.kineticEnergy_eV(); + out << "\ncross section: " << crosssection; + out << "\ndensity: " << density; + out << "\ntime: " << time; + if(density > 0) + DEBUG_LEVEL_2(out.str()); +#endif + + return time; +} + }; // namespace interaction \ No newline at end of file