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
+40 -3
View File
@@ -213,6 +213,7 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
// double energy_eV = energyBinBorders_[index(4) + 1]
// + theta_distribution_(*engine)*energy_step;
double energy_eV;
double alpha = 1;
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]*
@@ -229,16 +230,21 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
double nr = density_field_->particleNumber(index +
blitz::TinyVector<int, 5>(0,0,0,0,1));
double alpha = std::log(nr/nl)/std::log(energyBinBorders_[index(4) + 2]/
energyBinBorders_[index(4) + 1]);
// no reason for specific values, just to avoid these cases
// double alpha;
// no reason for specific values, just to avoid these cases
if(nl == 0) {
alpha = 1;
} else if (nr == 0) {
alpha = -1;
} else if (nr == 0 && nl == 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) {
energy_eV = std::pow(energyBinBorders_[index(4) + 2]
/ energyBinBorders_[index(4) + 1], theta_distribution_(*engine)) *
@@ -258,6 +264,15 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
energy_eV = std::pow((xr_alphap1 - xl_alphap1)*
theta_distribution_(*engine) + xl_alphap1, 1/(alpha + 1));
// #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;
// out << "alpha = "<< alpha << "\n\tdrawn energy: " << energy_eV;
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
@@ -285,6 +300,28 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
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
#ifdef debug_level2