Basic neccessities to draw from a density field;
does not yet work correctly since the neccessary density field is reset after a time resolution step
This commit is contained in:
@@ -83,6 +83,7 @@ DynamicDensityField::DynamicDensityField(
|
||||
if (!timer) {
|
||||
ERROR("Timer is necessary for calculation of density field");
|
||||
}
|
||||
initPositionDistributions();
|
||||
}
|
||||
|
||||
bool DynamicDensityField::changedPositionBin(
|
||||
@@ -166,6 +167,88 @@ blitz::Array<double, 3> DynamicDensityField::densityArray() {
|
||||
return density.copy();
|
||||
}
|
||||
|
||||
double DynamicDensityField::particleNumber() {
|
||||
blitz::Array<double, 3> density = densityArray();
|
||||
double particleNumber = blitz::sum(density * bin_volume_m3_);
|
||||
DEBUG_LEVEL_3("particle number: " + std::to_string(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.begin());
|
||||
rmax = *(rbins.end());
|
||||
|
||||
zmin = *(zbins.begin());
|
||||
zmax = *(zbins.end());
|
||||
|
||||
phimin = *(phibins.begin());
|
||||
phimax = *(phibins.end());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void DynamicDensityField::setDensityDistribution() {
|
||||
density_dist_ =
|
||||
std::uniform_real_distribution<double>(0., blitz::max(densityArray()));
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 4> DynamicDensityField::drawPositionAndEnergy(
|
||||
std::mt19937* engine) {
|
||||
// if the density is empty, then return a TinyVector filled with 0s as
|
||||
// an indiction of that (probably not the best solution)
|
||||
if (isEqual(blitz::max(density_per_m3_), 0.)) {
|
||||
DEBUG_LEVEL_3("Density is empty");
|
||||
return blitz::TinyVector<double, 4> (0,0,0,0);
|
||||
}
|
||||
double random_r, random_z, random_phi, random_E, random_n;
|
||||
double density_in_random_cell;
|
||||
|
||||
// random_r = 0.01;
|
||||
// random_phi = 0.;
|
||||
// random_z = 1.;
|
||||
// draw random position (independent of the Energy)
|
||||
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);
|
||||
|
||||
density_in_random_cell = density(CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3> (random_r, random_phi, random_z)));
|
||||
} while (random_n >= density_in_random_cell);
|
||||
|
||||
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());
|
||||
|
||||
E_dist_ = std::piecewise_constant_distribution<double>(energyBins.begin(),
|
||||
energyBins.end(),
|
||||
densityAtPosition.begin());
|
||||
|
||||
random_E = E_dist_(*engine);
|
||||
|
||||
return blitz::TinyVector<double, 4> (random_r, random_phi, random_z, random_E);
|
||||
}
|
||||
|
||||
blitz::Array<double, 4> DynamicDensityField::spectrumArray() {
|
||||
recalculateDensityArray();
|
||||
return density_per_m3_;
|
||||
|
||||
Reference in New Issue
Block a user