Removed drawing infrastructure
This commit is contained in:
@@ -37,10 +37,6 @@ VelocityDistributionFromDensityField::VelocityDistributionFromDensityField(
|
||||
pitchAngleBinBorders_(density_field->pitchAngleBinning()->binBorders()),
|
||||
theta_distribution_(std::uniform_real_distribution<double>(0.,1.)),
|
||||
mass_kg_(mass_kg) {
|
||||
double maxAbsExponent = std::max(std::abs(std::log10(energyBinBorders_.front())),
|
||||
std::abs(std::log10(energyBinBorders_.back())));
|
||||
alpha_lower_limit = -300/maxAbsExponent;
|
||||
alpha_upper_limit = 300/maxAbsExponent;
|
||||
// necessary to include the underflow bin in the energy domain
|
||||
energyBinBorders_.insert(energyBinBorders_.begin(), 0);
|
||||
}
|
||||
@@ -154,211 +150,6 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
blitz::TinyVector<double, 3> v_perp =
|
||||
perpendicularNormalVector(cartesianB_values);
|
||||
|
||||
blitz::TinyVector<double, 3> v_direction = pitchAngle
|
||||
* cartesianB_values/Bmagnitude
|
||||
+ std::sqrt(1 - pitchAngle*pitchAngle)
|
||||
* kinematic::rotateVector(v_perp, cartesianB_values, theta);
|
||||
|
||||
return CartesianVector(v_direction * vMagnitude);
|
||||
}
|
||||
|
||||
// if valid is false after function, the number of particles in the cell at the given index
|
||||
// is 0
|
||||
CartesianVector VelocityDistributionFromDensityField::drawVelocity(
|
||||
const blitz::TinyVector<int, 5> index, std::mt19937* engine) {
|
||||
|
||||
// const double number_particles_in_bin = density_field_->particleNumber(index);
|
||||
|
||||
const double energy_step = energyBinBorders_[index(4) + 1]
|
||||
- energyBinBorders_[index(4)];
|
||||
|
||||
const double pitch_angle_step = pitchAngleBinBorders_[index(3) + 1]
|
||||
- pitchAngleBinBorders_[index(3)];
|
||||
|
||||
double energy_eV = energyBinBorders_[index(4)]
|
||||
+ theta_distribution_(*engine)*energy_step;
|
||||
|
||||
double pitchAngle = pitchAngleBinBorders_[index(3)]
|
||||
+ theta_distribution_(*engine)*pitch_angle_step;
|
||||
|
||||
// construct the velocity
|
||||
|
||||
const double theta = theta_distribution_(*engine)*2*M_PI;
|
||||
|
||||
blitz::TinyVector<double, 3> zDirection(0,0,1);
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
// vector perpendicular to e_z
|
||||
blitz::TinyVector<double, 3> v_perp(1,0,0);
|
||||
|
||||
blitz::TinyVector<double, 3> v_direction = pitchAngle * zDirection
|
||||
+ std::sqrt(1 - pitchAngle*pitchAngle)
|
||||
* kinematic::rotateVector(v_perp, zDirection, theta);
|
||||
|
||||
return CartesianVector(v_direction * vMagnitude);
|
||||
}
|
||||
|
||||
CartesianVector VelocityDistributionFromDensityField::drawVelocity(
|
||||
const blitz::TinyVector<int, 5> index, std::mt19937* engine,
|
||||
const Coordinate& position,
|
||||
std::shared_ptr<MagneticField> magnetic_field) {
|
||||
|
||||
// since a 0 is included in the bin borders for the energy
|
||||
const double energy_step = energyBinBorders_[index(4) + 2]
|
||||
- energyBinBorders_[index(4) + 1];
|
||||
|
||||
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;
|
||||
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]*
|
||||
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);
|
||||
double nr = density_field_->particleNumber(index +
|
||||
blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||
|
||||
// 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;
|
||||
alpha = std::min(std::max(alpha, alpha_lower_limit), alpha_upper_limit);
|
||||
|
||||
if(alpha == -1) {
|
||||
energy_eV = std::pow(energyBinBorders_[index(4) + 2]
|
||||
/ energyBinBorders_[index(4) + 1], theta_distribution_(*engine)) *
|
||||
energyBinBorders_[index(4) + 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 {
|
||||
double xl_alphap1 = std::pow(energyBinBorders_[index(4) + 1], alpha + 1);
|
||||
double xr_alphap1 = std::pow(energyBinBorders_[index(4) + 2], alpha + 1);
|
||||
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];
|
||||
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||
// DEBUG(out.str());
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
|
||||
double pitchAngle = pitchAngleBinBorders_[index(3)]
|
||||
+ theta_distribution_(*engine)*pitch_angle_step;
|
||||
|
||||
#ifdef debug
|
||||
if((std::isnan(pitchAngle)) || (std::isnan(energy_eV))) {
|
||||
std::stringstream out;
|
||||
out << "pitchAngle: " << pitchAngle;
|
||||
out << "\nenergy value: " << energy_eV;
|
||||
out << "\nalpha: " << alpha;
|
||||
out << "\ncurrent index: " << index;
|
||||
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 << "\nEl^(alpha+1): " << std::pow(energyBinBorders_[index(4) + 1], alpha + 1);
|
||||
out << "\nEr^(alpha+1): " << std::pow(energyBinBorders_[index(4) + 2], alpha + 1);
|
||||
// out << "\nenergy values: " << energyValues;
|
||||
// out << "\npitch angle values: " << pitchAngleValues;
|
||||
out << "\nenergy bin borders: [ ";
|
||||
for(auto element : energyBinBorders_) {
|
||||
out << element << " ";
|
||||
}
|
||||
out << "]";
|
||||
|
||||
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
|
||||
std::stringstream out;
|
||||
out << "left Pitchangle value: "<< pitchAngleBinBorders_[index(3)];
|
||||
out << "\nright Pitchangle value: " << pitchAngleBinBorders_[index(3)+1];
|
||||
out << "\npitchAngle: " << pitchAngle;
|
||||
out << "\nleft energy value: "<< energyBinBorders_[index(4) + 1];
|
||||
out << "\nright energy value: " << energyBinBorders_[index(4)+2];
|
||||
out << "\nenergy value: " << energy_eV;
|
||||
DEBUG_LEVEL_2(out.str());
|
||||
#endif
|
||||
|
||||
// construct the velocity
|
||||
|
||||
const double theta = theta_distribution_(*engine)*2*M_PI;
|
||||
|
||||
blitz::TinyVector<double, 3> cartesianB_values =
|
||||
magnetic_field->value(position).cartesianEntries(position);
|
||||
const double Bmagnitude = kinematic::norm(cartesianB_values);
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
blitz::TinyVector<double, 3> v_perp =
|
||||
perpendicularNormalVector(cartesianB_values);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user