Moved drawing from density to seperate classes
This commit is contained in:
@@ -125,7 +125,6 @@ DynamicDensityField::DynamicDensityField(
|
||||
if(!timer) {
|
||||
ERROR("Timer is necessary for calculation of density field");
|
||||
}
|
||||
initPositionDistributions();
|
||||
}
|
||||
|
||||
double DynamicDensityField::density(const Coordinate& position) {
|
||||
@@ -210,13 +209,6 @@ void DynamicDensityField::logMovement(
|
||||
const int energy_bin = energy_binning_.bin(energy_eV);
|
||||
const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
|
||||
|
||||
// std::stringstream out;
|
||||
// out << "Energy bin " << energy_bin << "\n";
|
||||
// out << "Pitch angle: " << pitch_angle << "\n";
|
||||
// out << "Pitch angle bin: " << pitch_angle_bin << "\n";
|
||||
// out << "time in bin " << time_in_bin_s;
|
||||
// DEBUG_LEVEL_3(out.str());
|
||||
|
||||
time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
||||
pitch_angle_bin, energy_bin) += time_in_bin_s;
|
||||
}
|
||||
@@ -240,8 +232,6 @@ blitz::Array<double, 3> DynamicDensityField::densityArray() {
|
||||
DEBUG_LEVEL_3("recalc Density array");
|
||||
recalculateDensityArray();
|
||||
|
||||
// blitz::Array<double, 3> density(density_per_m3_(
|
||||
// blitz::Range::all(), blitz::Range::all(), blitz::Range::all(), 0));
|
||||
blitz::TinyVector<int,3> lowerbound(density_per_m3_.lbound(0),
|
||||
density_per_m3_.lbound(1),
|
||||
density_per_m3_.lbound(2));
|
||||
@@ -314,11 +304,6 @@ void DynamicDensityField::recalculateDensityArray() {
|
||||
// SimulationTimer::eventStopPoint("recalcDensityArray");
|
||||
}
|
||||
|
||||
void DynamicDensityField::setDensityDistribution() {
|
||||
density_dist_ =
|
||||
std::uniform_real_distribution<double>(0., blitz::max(densityArray()));
|
||||
}
|
||||
|
||||
double DynamicDensityField::particleNumber() {
|
||||
blitz::Array<double, 3> density = densityArray();
|
||||
double particleNumber = blitz::sum(density * bin_volume_m3_);
|
||||
@@ -326,99 +311,24 @@ double DynamicDensityField::particleNumber() {
|
||||
return particleNumber;
|
||||
}
|
||||
|
||||
void DynamicDensityField::initPositionDistributions() {
|
||||
double rmin, rmax;
|
||||
double phimin, phimax;
|
||||
double zmin, zmax;
|
||||
|
||||
auto rbins = position_binning_.radial_binning.binBorders();
|
||||
auto zbins = position_binning_.longitudinal_binning.binBorders();
|
||||
auto phibins = position_binning_.azimuth_binning.binBorders();
|
||||
|
||||
rmin = rbins.front();
|
||||
rmax = rbins.back();
|
||||
DEBUG_LEVEL_3("rmax: " + std::to_string(rmax));
|
||||
|
||||
zmin = zbins.front();
|
||||
zmax = zbins.back();
|
||||
DEBUG_LEVEL_3("zmax: " + std::to_string(zmax));
|
||||
|
||||
phimin = phibins.front();
|
||||
phimax = phibins.back();
|
||||
DEBUG_LEVEL_3("phimax: " + std::to_string(phimax));
|
||||
|
||||
r_dist_ = std::uniform_real_distribution<double>(rmin*rmin, rmax*rmax);
|
||||
phi_dist_ = std::uniform_real_distribution<double>(phimin, phimax);
|
||||
z_dist_ = std::uniform_real_distribution<double>(zmin, zmax);
|
||||
blitz::Array<double, 1> DynamicDensityField::
|
||||
sliceSpectrumArray(const Coordinate& position) const {
|
||||
blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
return density_per_m3_(position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range(0, energy_binning_.binIndexMax()-1)).copy();
|
||||
}
|
||||
|
||||
// don't know if it's even good to have the drawing stuff in the
|
||||
// density distributions...
|
||||
blitz::TinyVector<double, 5> DynamicDensityField::
|
||||
draw(std::mt19937* engine) {
|
||||
// recalculateDensityArray();
|
||||
if (isEqual(blitz::max(density_per_m3_), 0.)) {
|
||||
DEBUG_LEVEL_3("Density is empty");
|
||||
return blitz::TinyVector<double, 5> (0,0,0,0,0);
|
||||
}
|
||||
// setDensityDistribution();
|
||||
double random_r, random_z, random_phi, random_E, random_n;
|
||||
double density_in_random_cell;
|
||||
// SimulationTimer::eventStartPoint("DenDraw rejection");
|
||||
do {
|
||||
DEBUG_LEVEL_3("Missed.");
|
||||
random_r = std::sqrt(r_dist_(*engine));
|
||||
random_phi = phi_dist_(*engine);
|
||||
random_z = z_dist_(*engine);
|
||||
random_n = density_dist_(*engine);
|
||||
blitz::Array<double, 1> DynamicDensityField::
|
||||
sliceTimeInBinArray(const Coordinate& position, double energy_eV) const {
|
||||
blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
int energy_bin = energy_binning_.bin(energy_eV);
|
||||
|
||||
density_in_random_cell = density(CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3> (random_r, random_phi, random_z)));
|
||||
DEBUG_LEVEL_3("Density in drawn cell: " + std::to_string(density_in_random_cell));
|
||||
DEBUG_LEVEL_3("drawn density: " + std::to_string(random_n));
|
||||
} while (random_n >= density_in_random_cell);
|
||||
|
||||
// SimulationTimer::eventStopPoint("DenDraw rejection");
|
||||
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3> (random_r, random_phi, random_z))
|
||||
.cylinderEntries());
|
||||
|
||||
|
||||
std::vector<double> energyBins = energy_binning_.binBorders();
|
||||
energyBins.insert(energyBins.begin(), 0.);
|
||||
blitz::Array<double, 1> densityAtPosition = density_per_m3_(position_bin(0),
|
||||
position_bin(1),
|
||||
position_bin(2),
|
||||
blitz::Range::all());
|
||||
|
||||
std::piecewise_constant_distribution<double> E_dist_(energyBins.begin(),
|
||||
energyBins.end(),
|
||||
densityAtPosition.begin());
|
||||
|
||||
random_E = E_dist_(*engine);
|
||||
|
||||
DEBUG_LEVEL_3("energy: " + std::to_string(random_E));
|
||||
|
||||
const int energy_bin = energy_binning_.bin(random_E);
|
||||
|
||||
std::vector<double> mu_bins = pitch_angle_binning_.binBorders();
|
||||
DEBUG_LEVEL_3("Size pitchangle binning: " + std::to_string(mu_bins.size()));
|
||||
DEBUG_LEVEL_3("Size timeinbin: " + std::to_string(time_in_bin_s_.extent(3)));
|
||||
|
||||
auto values_mu = time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range(0, pitch_angle_binning_.binIndexMax()-1),
|
||||
energy_bin);
|
||||
|
||||
// remove the under- and overflow bins for the constant distribution
|
||||
// for now use only the time_in_bin_s_ array (should make no difference but might be worse?)
|
||||
std::piecewise_constant_distribution<double> mu_distribution(
|
||||
mu_bins.begin(), mu_bins.end(), values_mu.begin());
|
||||
|
||||
double random_mu = mu_distribution(*engine);
|
||||
|
||||
return blitz::TinyVector<double, 5> (random_r, random_phi, random_z, random_mu, random_E);
|
||||
return time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range(0, pitch_angle_binning_.binIndexMax()-1),
|
||||
energy_bin).copy();
|
||||
}
|
||||
|
||||
void DynamicDensityField::resetDynamicDensityField() {
|
||||
|
||||
Reference in New Issue
Block a user