149 lines
6.4 KiB
C++
Executable File
149 lines
6.4 KiB
C++
Executable File
#include "interactions/recombination.h"
|
||
|
||
#include "simulation/density_field.h"
|
||
#include "simulation/logger.h"
|
||
#include "simulation/species.h"
|
||
#include "simulation/kinematic.h"
|
||
#include "constants/physical_constants.h"
|
||
#include "simulation/drift_velocity.h"
|
||
|
||
namespace interaction {
|
||
|
||
Recombination::Recombination(std::function<double(double)> cross_section,
|
||
std::shared_ptr<species::TrackedSpecie> target)
|
||
: Interaction(cross_section, target), recombination_target_(target) {}
|
||
|
||
InteractionOutput Recombination::performInteraction(
|
||
particle::Particle& particle,
|
||
RandomNumbers* generator) {
|
||
DEBUG_LEVEL_3("Perform recombination.");
|
||
|
||
std::vector<double> macroscopic_bin_cross_sections_m;
|
||
const int number_energy_bins = recombination_target_->dynamicDensityField()
|
||
->energyBinning()->binIndexMax();
|
||
std::vector<double> energyBinBorders = recombination_target_->
|
||
dynamicDensityField()->energyBinning()->binBorders();
|
||
|
||
// calculate the density scaled cross section for each energy bin
|
||
if(recombination_target_->type() == species::ImplementedSpecies::electron) {
|
||
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||
macroscopic_bin_cross_sections_m.push_back(
|
||
macroscopicCrossSection(particle.position(), bin));
|
||
}
|
||
} else {
|
||
const blitz::TinyVector<double, 3> v_particle =
|
||
particle.velocity().cartesianEntries();
|
||
|
||
// ion targets need to have a drift velocity defined in the json file
|
||
// (a determination is not yet part of the simulation itself)
|
||
if(!recombination_target_->driftVelocity()) {
|
||
ERROR(recombination_target_->name() + ": does not have a drift velocity!");
|
||
}
|
||
|
||
// drift velocity of the target particle
|
||
const blitz::TinyVector<double, 3> v_partner =
|
||
recombination_target_->driftVelocity()
|
||
->driftVelocity(particle.position()).cartesianEntries();
|
||
|
||
// velocity of incident particle in the drift frame of the target species
|
||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||
kinematic::velocityTargetFixed(v_particle, v_partner, particle.mass_kg(),
|
||
recombination_target_->mass_kg());
|
||
|
||
const double kinetic_energy_eV =
|
||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg()) *
|
||
UnitConversion::JouleToeV;
|
||
|
||
// velocity distribution in the drift frame assumed to be isotropic -> averages out
|
||
// so that the density scaled cross section only depends on the kinetic energy
|
||
// of the electrons in the drift frame
|
||
double energy_eV_bin_center;
|
||
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||
energy_eV_bin_center = (energyBinBorders[bin] + energyBinBorders[bin+1])/2.;
|
||
macroscopic_bin_cross_sections_m.push_back(
|
||
microscopicCrossSection(kinetic_energy_eV) *
|
||
recombination_target_->dynamicDensityField()
|
||
->density(particle.position(), energy_eV_bin_center));
|
||
}
|
||
}
|
||
|
||
const double total_macroscopic_cross_section_m =
|
||
std::accumulate(macroscopic_bin_cross_sections_m.begin(),
|
||
macroscopic_bin_cross_sections_m.end(), 0.0);
|
||
|
||
if(total_macroscopic_cross_section_m <= 0.) {
|
||
ERROR("Total cross section is " + std::to_string(total_macroscopic_cross_section_m) +
|
||
". But recombination was chosen.");
|
||
}
|
||
|
||
// distribution to choose the energy (bin) of the actual target particle that will
|
||
// perform the interaction
|
||
std::discrete_distribution<int> energy_bin_decider(
|
||
macroscopic_bin_cross_sections_m.begin(),
|
||
macroscopic_bin_cross_sections_m.end());
|
||
|
||
const int energy_bin = energy_bin_decider(*(generator->engine()));
|
||
// calculate the energy of the chosen energy bin
|
||
const double energy_eV = (energyBinBorders[energy_bin] +
|
||
energyBinBorders[energy_bin+1]) / 2.;
|
||
|
||
// log the deletion in the dynamic density field of the target specie
|
||
recombination_target_->dynamicDensityField()->logDeletion(particle.position(),
|
||
energy_eV);
|
||
|
||
InteractionOutput output;
|
||
// incident particle is lost
|
||
output.deleteCurrentParticle(true);
|
||
|
||
if (particle.specie()->deletionLogger()) {
|
||
particle.specie()->deletionLogger()->logDeletion(
|
||
particle.position(), DeletionType::recombination);
|
||
}
|
||
|
||
return output;
|
||
}
|
||
|
||
double Recombination::macroscopicCrossSection(particle::Particle& particle) {
|
||
if(recombination_target_->type() == species::ImplementedSpecies::electron) {
|
||
const int numBins = recombination_target_->dynamicDensityField()->
|
||
energyBinning()->binIndexMax();
|
||
double macroscopic_cross_section = 0.;
|
||
const auto position = particle.position();
|
||
for (int bin = 0; bin < numBins - 1; ++bin) {
|
||
macroscopic_cross_section += macroscopicCrossSection(position, bin);
|
||
}
|
||
return macroscopic_cross_section;
|
||
}
|
||
// if target is not an electron -> cross section independent of energy of
|
||
// the target (electrons are much faster than the ions)
|
||
return Interaction::macroscopicCrossSection(particle);
|
||
}
|
||
// implicitly assumes that the bin index > 0 and < maxBinIndex
|
||
// calculates ∫dE_t σ(E_t) dn_t/dE_t (only applicable if
|
||
// cross section is effectively independent of E_i)
|
||
// over the given energy bin; i: incident, t: target
|
||
double Recombination::macroscopicCrossSection(const Coordinate& position,
|
||
const int energy_bin_index) {
|
||
if (energy_bin_index > recombination_target_->dynamicDensityField()
|
||
->energyBinning()->binIndexMax()) {
|
||
return 0.;
|
||
}
|
||
const double lower_bound = recombination_target_->dynamicDensityField()
|
||
->energyBinning()->binBorders()[energy_bin_index];
|
||
const double upper_bound = recombination_target_->dynamicDensityField()
|
||
->energyBinning()->binBorders()[energy_bin_index + 1];
|
||
const double intermediate_value = (upper_bound + lower_bound)/2.;
|
||
const double differential_density_value = recombination_target_->
|
||
dynamicDensityField()->density(position, intermediate_value) /
|
||
(upper_bound - lower_bound);
|
||
//Simpson's rule
|
||
const double integrated_microscopic_cross_section =
|
||
(upper_bound - lower_bound)/6. *
|
||
(microscopicCrossSection(upper_bound) +
|
||
4*microscopicCrossSection(intermediate_value) +
|
||
microscopicCrossSection(lower_bound));
|
||
// assumption, that the differential density is constant within a cell
|
||
return differential_density_value * integrated_microscopic_cross_section;
|
||
}
|
||
|
||
}; // namespace interaction
|