Changed distance drawing procedure;

Changed mover to work with times instead of distance;
Changed how interactions are done (recombination still tbd)
This commit is contained in:
2025-05-08 09:56:25 +02:00
parent 2c79c567d8
commit 60430abcba
16 changed files with 225 additions and 76 deletions
+67 -1
View File
@@ -29,7 +29,8 @@ std::vector<particle::Particle> InteractionOutput::newParticles() {
Interaction::Interaction(std::function<double(double)> cross_section,
std::shared_ptr<species::Specie> target)
: cross_section_(cross_section), target_(target) {}
: cross_section_(cross_section), target_(target),
target_velocity_(blitz::TinyVector<double, 3> (0,0,0)) {};
// assumes that v_particle >> v_target
double Interaction::macroscopicCrossSection(particle::Particle& particle) {
@@ -61,4 +62,69 @@ double Interaction::microscopicCrossSection(double energy_eV) {
return cross_section_(energy_eV);
}
double Interaction::drawCollisionTime(particle::Particle& particle,
RandomNumbers* generator) {
CartesianVector particle_velocity = particle.velocity();
target_velocity_ = target_->velocityDistribution()->
rollVelocity(particle.position(), generator->engine());
// if no drift velocity is present, then assume target at rest otherwise
// use the drift velocity
if(target_->driftVelocity()) {
target_velocity_.add(target_->driftVelocity()->driftVelocity(particle.position()),
particle.position());
}
// masses are irrelevant for the transformation
const blitz::TinyVector<double, 3> velocity_target_fixed =
kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(),
target_velocity_.cartesianEntries(), 0, 0);
const double relative_velocity = kinematic::norm(velocity_target_fixed);
// std::stringstream out;
// out << "particle "<< particle.specie()->name() <<" velocity: "
// << particle_velocity.cartesianEntries();
// out << "\ntarget "<< target_->name() <<" velocity: "
// << target_velocity_.cartesianEntries();
// out << "\nabsolute relative velocity: " << relative_velocity;
// 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<double>::max();
}
const double energy_eV =
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
UnitConversion::JouleToeV;
const double crosssection = microscopicCrossSection(energy_eV);
const double density = target_->densityField()->density(particle.position());
// out << "\ninverse mfp: " << crosssection*density << ", sigma: " << crosssection;
// out << ", density: " << density;
const double random_number = generator->rollUniform(0.,1.);
if (random_number == 0) {
return std::numeric_limits<double>::max();
}
const double distance_target_fixed =
- 1./(crosssection * density) * log(generator->rollUniform(0.,1.));
// out << "\ndistance in target fixed frame: " << distance_target_fixed;
const double time = distance_target_fixed / relative_velocity;
// out << "\ntime before collision: " << time;
// DEBUG_LEVEL_3(out.str());
return time;
}
}; // namespace interaction