Bug fixes and formatting
This commit is contained in:
@@ -174,17 +174,15 @@ bool DynamicDensityField::changedPositionBin(
|
||||
(old_bin(2) == new_bin(2)));
|
||||
}
|
||||
|
||||
bool DynamicDensityField::changedEnergyBin(
|
||||
double old_energy_eV,
|
||||
double new_energy_eV) const {
|
||||
bool DynamicDensityField::changedEnergyBin(double old_energy_eV,
|
||||
double new_energy_eV) const {
|
||||
const int old_bin = energy_binning_.bin(old_energy_eV);
|
||||
const int new_bin = energy_binning_.bin(new_energy_eV);
|
||||
return !(old_bin == new_bin);
|
||||
}
|
||||
|
||||
bool DynamicDensityField::changedPitchAngleBin(
|
||||
double old_mu,
|
||||
double new_mu) const {
|
||||
bool DynamicDensityField::changedPitchAngleBin(double old_mu,
|
||||
double new_mu) const {
|
||||
const int old_bin = pitch_angle_binning_.bin(old_mu);
|
||||
const int new_bin = pitch_angle_binning_.bin(new_mu);
|
||||
|
||||
@@ -198,11 +196,10 @@ bool DynamicDensityField::changedPitchAngleBin(
|
||||
return !(old_bin == new_bin);
|
||||
}
|
||||
|
||||
void DynamicDensityField::logMovement(
|
||||
const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle,
|
||||
double time_in_bin_s) {
|
||||
void DynamicDensityField::logMovement(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle,
|
||||
double time_in_bin_s) {
|
||||
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
@@ -213,10 +210,9 @@ void DynamicDensityField::logMovement(
|
||||
pitch_angle_bin, energy_bin) += time_in_bin_s;
|
||||
}
|
||||
|
||||
void DynamicDensityField::logDeletion(
|
||||
const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle) {
|
||||
void DynamicDensityField::logDeletion(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle) {
|
||||
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
@@ -317,7 +313,8 @@ blitz::Array<double, 1> DynamicDensityField::
|
||||
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();
|
||||
blitz::Range(energy_binning_.binIndexMin(),
|
||||
energy_binning_.binIndexMax()-1)).copy();
|
||||
}
|
||||
|
||||
blitz::Array<double, 1> DynamicDensityField::
|
||||
|
||||
@@ -84,5 +84,6 @@ CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* e
|
||||
} while (random_n*maximum_density_ >= density_->density(CylinderCoordinate(
|
||||
blitz::TinyVector<double,3>(random_r, random_phi, random_z))));
|
||||
|
||||
return CylinderCoordinate(blitz::TinyVector<double, 3>(random_r, random_phi, random_z));
|
||||
return CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3>(random_r, random_phi, random_z));
|
||||
}
|
||||
@@ -31,6 +31,14 @@ void BorisMover::move(particle::Particle* particle,
|
||||
// keep hard coded for now; has to be decided to be either kept (new field for Boris
|
||||
// mover in json file) or removed again
|
||||
const double max_distance = 1e-4;
|
||||
const double delta_timeresolution = particle->specie()->
|
||||
dynamicDensityField()->timeResolution();
|
||||
// in order to try to minimize the overshoot in the time domain (i.e. if particle
|
||||
// can only life a time dt < min(distance/v, maximal_timestep), which might even be
|
||||
// a lot larger than dt, which would increase the influence of the particle on the
|
||||
// density)
|
||||
double max_time_alive = particle->specie()->dynamicDensityField()->physicalTime() -
|
||||
particle->timeAlive();
|
||||
double leftover_distance = mfp_m;
|
||||
|
||||
auto old_position = particle->position();
|
||||
@@ -54,12 +62,12 @@ void BorisMover::move(particle::Particle* particle,
|
||||
|
||||
double timestep = 0;
|
||||
|
||||
if (old_kinetic_energy < 1E-9) {
|
||||
// Guard against small enegies taking up much time without contributing to
|
||||
// density
|
||||
SIM_INFO("particle skipped due to energy.");
|
||||
return;
|
||||
}
|
||||
// if (old_kinetic_energy < 1E-9) {
|
||||
// // Guard against small enegies taking up much time without contributing to
|
||||
// // density
|
||||
// SIM_INFO("particle skipped due to energy.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
bool changed_position_bin = false;
|
||||
bool changed_energy_bin = false;
|
||||
@@ -77,6 +85,7 @@ void BorisMover::move(particle::Particle* particle,
|
||||
timestep = std::min(maximal_time_step_s_,
|
||||
(leftover_distance + SimConstants::random_lower_limit) / old_velocity);
|
||||
timestep = std::min(timestep, max_distance / old_velocity);
|
||||
timestep = std::min(timestep, max_time_alive);
|
||||
|
||||
double moved_distance = 0.;
|
||||
|
||||
@@ -127,6 +136,14 @@ void BorisMover::move(particle::Particle* particle,
|
||||
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||
|
||||
leftover_distance -= moved_distance;
|
||||
|
||||
// if max_time_alive == 0 but the difference between the time alive and
|
||||
// the endtime > 0 (think can happen due to numerical accuracy)
|
||||
// an infinite loop is created. Therefore catch that case and
|
||||
// allow for a small overshoot in the timedomain (see comment in drift mover)
|
||||
max_time_alive = ((max_time_alive - timestep) <= 0)
|
||||
? delta_timeresolution*SimConstants::compare_epsilon
|
||||
: (max_time_alive - timestep);
|
||||
}
|
||||
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
@@ -386,7 +403,7 @@ void DriftMover::move(particle::Particle* particle,
|
||||
particle->increaseTimeAlive(timestep);
|
||||
particle->increaseTimeInBin(timestep);
|
||||
// if instead of eps*deltaT 0.0 is used the integral would be conserved
|
||||
// if no particles were lost. however in that case the terminator does not
|
||||
// if no particles are lost at a boundary. however in that case the terminator does not
|
||||
// return the correct value if the time the particle is alive is identical
|
||||
// to the physical time... -> increases computation time alot
|
||||
// The version below means that each timestep the density can grow by
|
||||
|
||||
@@ -138,9 +138,8 @@ void Simulation::start() {
|
||||
|
||||
// calculate a 'stride' for the density events s.t. the same number of syncs
|
||||
// would be performed
|
||||
const int density_stride = std::ceil(static_cast<double>(
|
||||
density_events * event_stride)/beta_decay_events);
|
||||
|
||||
const int density_stride = std::ceil(density_events *
|
||||
(static_cast<double>(event_stride)/beta_decay_events));
|
||||
// calculate the scaling factor for the particle weight for particles
|
||||
// drawn from the density
|
||||
const double density_weight_factor =
|
||||
|
||||
@@ -35,7 +35,10 @@ VelocityDistributionFromDensityField::VelocityDistributionFromDensityField(
|
||||
energyBinBorders_(density_field->energyBinning()->binBorders()),
|
||||
pitchAngleBinBorders_(density_field->pitchAngleBinning()->binBorders()),
|
||||
theta_distribution_(std::uniform_real_distribution<double>(0.,1.)),
|
||||
mass_kg_(mass_kg) {}
|
||||
mass_kg_(mass_kg) {
|
||||
// necessary to include the underflow bin in the energy domain
|
||||
energyBinBorders_.insert(energyBinBorders_.begin(), 0);
|
||||
}
|
||||
|
||||
// not important as of now since it's meant for drawing a velocity from the
|
||||
// pitch angle distribution and not to be used in an interaction context in which
|
||||
|
||||
Reference in New Issue
Block a user