Added limiter to power of powerlaw drawing stuff

This commit is contained in:
2025-07-08 11:06:40 +02:00
parent c4ae430fff
commit f5a4e63627
+39 -2
View File
@@ -213,6 +213,7 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
// double energy_eV = energyBinBorders_[index(4) + 1] // double energy_eV = energyBinBorders_[index(4) + 1]
// + theta_distribution_(*engine)*energy_step; // + theta_distribution_(*engine)*energy_step;
double energy_eV; double energy_eV;
double alpha = 1;
if(index(4) == -1) { if(index(4) == -1) {
// linear drawing inbetween E=0, N(0)=0 to E=Er and N(Er)=Nr // linear drawing inbetween E=0, N(0)=0 to E=Er and N(Er)=Nr
energy_eV = energyBinBorders_[index(4) + 2]* energy_eV = energyBinBorders_[index(4) + 2]*
@@ -229,8 +230,7 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
double nr = density_field_->particleNumber(index + double nr = density_field_->particleNumber(index +
blitz::TinyVector<int, 5>(0,0,0,0,1)); blitz::TinyVector<int, 5>(0,0,0,0,1));
double alpha = std::log(nr/nl)/std::log(energyBinBorders_[index(4) + 2]/ // double alpha;
energyBinBorders_[index(4) + 1]);
// no reason for specific values, just to avoid these cases // no reason for specific values, just to avoid these cases
if(nl == 0) { if(nl == 0) {
alpha = 1; alpha = 1;
@@ -238,7 +238,13 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
alpha = -1; alpha = -1;
} else if (nr == 0 && nl == 0) { } else if (nr == 0 && nl == 0) {
alpha = 0; alpha = 0;
} else {
alpha = std::log(nr/nl)/std::log(energyBinBorders_[index(4) + 2]/
energyBinBorders_[index(4) + 1]);
} }
alpha = std::abs(alpha) > 100 ?(alpha/std::abs(alpha))*100 : alpha;
if(alpha == -1) { if(alpha == -1) {
energy_eV = std::pow(energyBinBorders_[index(4) + 2] energy_eV = std::pow(energyBinBorders_[index(4) + 2]
/ energyBinBorders_[index(4) + 1], theta_distribution_(*engine)) * / energyBinBorders_[index(4) + 1], theta_distribution_(*engine)) *
@@ -258,6 +264,15 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
energy_eV = std::pow((xr_alphap1 - xl_alphap1)* energy_eV = std::pow((xr_alphap1 - xl_alphap1)*
theta_distribution_(*engine) + xl_alphap1, 1/(alpha + 1)); theta_distribution_(*engine) + xl_alphap1, 1/(alpha + 1));
// #ifdef debug // #ifdef debug
// if(std::abs(alpha) > 100) {
// std::stringstream out;
// out << "alpha: " << alpha;
// out << "\nxl_alphap1: " << xl_alphap1;
// out << "\nxr_alphap1: " << xr_alphap1;
// DEBUG(out.str());
// }
// #endif
// #ifdef debug
// std::stringstream out; // std::stringstream out;
// out << "alpha = "<< alpha << "\n\tdrawn energy: " << energy_eV; // out << "alpha = "<< alpha << "\n\tdrawn energy: " << energy_eV;
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1]; // out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
@@ -285,6 +300,28 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
ERROR(out.str()); ERROR(out.str());
} }
// if(std::isinf(energy_eV)) {
// std::stringstream out;
// out << "pitchAngle: " << pitchAngle;
// out << "\nenergy value: " << energy_eV;
// out << "\ncurrent index: " << index;
// out << "\nalpha: " << alpha;
// out << "\nNl: " << density_field_->particleNumber(index);
// out << "\nNl: " << density_field_->particleNumber(index +
// blitz::TinyVector<int, 5>(0,0,0,0,1));
// out << "\nEl: " << energyBinBorders_[index(4) + 1];
// out << "\nEr: " << energyBinBorders_[index(4) + 2];
// // out << "\nenergy values: " << energyValues;
// // out << "\npitch angle values: " << pitchAngleValues;
// out << "\nenergy bin borders: [ ";
// for(auto element : energyBinBorders_) {
// out << element << " ";
// }
// out << "]";
// ERROR(out.str());
// }
#endif #endif
#ifdef debug_level2 #ifdef debug_level2