Author SHA1 Message Date
csendlinger d17602e1fa Fixed bug with mu=-1; added nan-check in
drawing velocity from density if DO_DEBUG
is true in the config file
2025-03-15 09:09:21 +01:00
csendlinger 5bc545ac99 hotfix: changed a <= b to !(a > b) 2025-03-13 15:20:56 +01:00
csendlinger d62c49a15d Bugfix drawing from density 2025-02-27 11:32:17 +01:00
4 changed files with 28 additions and 2 deletions
+7
View File
@@ -70,6 +70,13 @@ int PitchAngleBinning::bin(double pitch_angle) const {
auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(), auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(),
pitch_angle_bin_borders_.end(), pitch_angle_bin_borders_.end(),
pitch_angle); pitch_angle);
// otherwise the valid mu-value of -1 is assigned to the underflow
// bin which can lead to a segfault in the drawing of the pitch
// angle in "velocity_distribution.cpp"
if(!(pitch_angle < pitch_angle_bin_borders_.front()) &&
(it == pitch_angle_bin_borders_.begin())) {
return (it - pitch_angle_bin_borders_.begin());
}
return (it - pitch_angle_bin_borders_.begin()) - 1; return (it - pitch_angle_bin_borders_.begin()) - 1;
} }
@@ -80,6 +80,7 @@ CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* e
random_r = std::sqrt(r_values(*engine)); random_r = std::sqrt(r_values(*engine));
random_phi = phi_values(*engine); random_phi = phi_values(*engine);
random_z = z_values(*engine); random_z = z_values(*engine);
random_n = density_values(*engine);
// might be bad that the value gets recalculated for each call of density_->density(...) // might be bad that the value gets recalculated for each call of density_->density(...)
} while (random_n*maximum_density_ >= density_->density(CylinderCoordinate( } while (random_n*maximum_density_ >= density_->density(CylinderCoordinate(
blitz::TinyVector<double,3>(random_r, random_phi, random_z)))); blitz::TinyVector<double,3>(random_r, random_phi, random_z))));
@@ -58,7 +58,7 @@ CompositeAngleDistribution::CompositeAngleDistribution(
double CompositeAngleDistribution::roll(std::mt19937* engine, double CompositeAngleDistribution::roll(std::mt19937* engine,
double energy_eV) { double energy_eV) {
if (energy_eV <= decider_energy_) { if (!(energy_eV > decider_energy_)) {
return lower_distribution_->roll(engine, energy_eV); return lower_distribution_->roll(engine, energy_eV);
} else { } else {
return higher_distribution_->roll(engine, energy_eV); return higher_distribution_->roll(engine, energy_eV);
+18
View File
@@ -5,6 +5,7 @@
#include "simulation/velocity_distribution_function.h" #include "simulation/velocity_distribution_function.h"
#include "simulation/density_field.h" #include "simulation/density_field.h"
#include "simulation/electromagnetic_field.h" #include "simulation/electromagnetic_field.h"
#include "simulation/errors.h"
// utility function returning a unit vector perpendicular to the given // utility function returning a unit vector perpendicular to the given
// (cartesian) TinyVector // (cartesian) TinyVector
@@ -121,6 +122,23 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
double pitchAngle = pitchAngle_dist(*engine); double pitchAngle = pitchAngle_dist(*engine);
#ifdef debug
if((std::isnan(pitchAngle)) || (std::isnan(energy_eV))) {
std::stringstream out;
out << "pitchAngle: " << pitchAngle;
out << "\nenergy value: " << energy_eV;
out << "\nenergy values: " << energyValues;
out << "\npitch angle values: " << pitchAngleValues;
out << "\nenergy bin borders: [ ";
for(auto element : energyBinBorders_) {
out << element << " ";
}
out << "]";
ERROR(out.str());
}
#endif
// construct the velocity // construct the velocity
const double theta = theta_distribution_(*engine)*2*M_PI; const double theta = theta_distribution_(*engine)*2*M_PI;