From 9ef7fcd3ca1af28b87e5abc2e04173663f022414 Mon Sep 17 00:00:00 2001 From: csendlinger Date: Tue, 24 Jun 2025 15:53:26 +0200 Subject: [PATCH] energy drawing via powerlaw --- src/simulation/velocity_distribution.cpp | 45 ++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/simulation/velocity_distribution.cpp b/src/simulation/velocity_distribution.cpp index 1ca06fe..6c1ad2a 100755 --- a/src/simulation/velocity_distribution.cpp +++ b/src/simulation/velocity_distribution.cpp @@ -210,8 +210,49 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity( const double pitch_angle_step = pitchAngleBinBorders_[index(3) + 1] - pitchAngleBinBorders_[index(3)]; - double energy_eV = energyBinBorders_[index(4) + 1] - + theta_distribution_(*engine)*energy_step; + // double energy_eV = energyBinBorders_[index(4) + 1] + // + theta_distribution_(*engine)*energy_step; + double energy_eV; + if(index(4) == -1) { + // linear drawing inbetween E=0, N(0)=0 to E=Er and N(Er)=Nr + energy_eV = energyBinBorders_[index(4) + 2]* + std::sqrt(theta_distribution_(*engine)); +// #ifdef debug +// std::stringstream out; +// out << "underflow bin.\n\tdrawn energy: " << energy_eV; +// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1]; +// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2]; +// DEBUG(out.str()); +// #endif + } else { + double nl = density_field_->particleNumber(index - + blitz::TinyVector(0,0,0,0,1)); + double nr = density_field_->particleNumber(index); + double alpha = std::log(nr/nl)/std::log(energyBinBorders_[index(4) + 2]/ + energyBinBorders_[index(4) + 1]); + if(alpha == -1) { + energy_eV = (std::pow(2, theta_distribution_(*engine)) - 1)*energy_step + + energyBinBorders_[index(4) + 1]; +#ifdef debug + std::stringstream out; + out << "alpha = -1\n\tdrawn energy: " << energy_eV; + out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1]; + out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2]; + DEBUG(out.str()); +#endif + } else { + energy_eV = (std::pow((std::pow(2, alpha+1) - 1)* + theta_distribution_(*engine) + 1, 1/(alpha + 1)) - 1)* + energy_step + energyBinBorders_[index(4) + 1]; +// #ifdef debug +// std::stringstream out; +// out << "alpha = "<< alpha << "\n\tdrawn energy: " << energy_eV; +// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1]; +// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2]; +// DEBUG(out.str()); +// #endif + } + } double pitchAngle = pitchAngleBinBorders_[index(3)] + theta_distribution_(*engine)*pitch_angle_step;