Added option whether particles should be stored
explicitly
This commit is contained in:
@@ -82,6 +82,7 @@ SpeciesBuilder::SpeciesBuilder(Parameter& parameter) {
|
||||
fillTerminator(parameter);
|
||||
fillReflector(parameter);
|
||||
fillTrackedDensity(parameter);
|
||||
fillDensityDrawingType(parameter);
|
||||
|
||||
buildSpecies();
|
||||
fillInteractions(parameter);
|
||||
@@ -306,6 +307,13 @@ void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
|
||||
}
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillDensityDrawingType(Parameter& parameter) {
|
||||
for(auto& b : tracked_species_info) {
|
||||
b.second.explicitly_stored = parameter.boolValue(
|
||||
json_path_append(b.second.path_in_json, {"StoreInQueue"}), false);
|
||||
}
|
||||
}
|
||||
|
||||
void SpeciesBuilder::buildSpecies() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Build species from info.");
|
||||
@@ -319,9 +327,15 @@ void SpeciesBuilder::buildSpecies() {
|
||||
}
|
||||
|
||||
for (auto& b : tracked_species_info) {
|
||||
#ifdef debug
|
||||
std::stringstream out;
|
||||
out << b.second.name << ": stored in queue? " << (b.second.explicitly_stored ? "true": "false");
|
||||
DEBUG_LEVEL_1(out.str());
|
||||
#endif
|
||||
tracked_species[b.first] =
|
||||
std::shared_ptr<species::TrackedSpecie>(new species::TrackedSpecie(
|
||||
b.second.type, b.second.name, b.second.mass_kg, b.second.charge_C,
|
||||
b.second.explicitly_stored,
|
||||
b.second.mover, b.second.terminator, b.second.reflector,
|
||||
b.second.density_field, b.second.velocity_distribution,
|
||||
b.second.drift_velocity, b.second.density_drawing_field));
|
||||
|
||||
@@ -318,7 +318,7 @@ void Simulation::start() {
|
||||
|
||||
SimulationTimer::eventStartPoint("Reset");
|
||||
if(reset) {
|
||||
#if defined(debug_level2)
|
||||
#if defined(debug_level2) || defined(debug_level3)
|
||||
DEBUG_LEVEL_2("Number of particles in active storage queue: "
|
||||
+ std::to_string(storage_queue_[active_storage].size()));
|
||||
DEBUG_LEVEL_2("Number of particles in inactive storage queue: "
|
||||
@@ -461,12 +461,11 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
|
||||
#endif
|
||||
// if no new particles could be injected from the density, it is not possible
|
||||
// that during another iteration cycle new particles will be injected
|
||||
// (drawing field only changes after timesteps)
|
||||
|
||||
// (drawing field only changes after timesteps)
|
||||
if(all_bins_done) {
|
||||
current_event += 1;
|
||||
for(auto& element : tracked_species_) {
|
||||
if(element.second->type() == species::ImplementedSpecies::electron) {
|
||||
if(element.second->explicitlyStored()) {
|
||||
continue;
|
||||
}
|
||||
element.second->randomIndex()->reshuffle(random_->engine());
|
||||
@@ -496,8 +495,7 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::processUntilTermination(
|
||||
particle::Particle& particle) {
|
||||
void Simulation::processUntilTermination(particle::Particle& particle) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Process particle until termination");
|
||||
DEBUG_LEVEL_3("Weight of the particle: " + std::to_string(particle.weight()));
|
||||
@@ -507,13 +505,13 @@ void Simulation::processUntilTermination(
|
||||
double old_energy = particle.kineticEnergy_eV();
|
||||
|
||||
if(!particle.isNextInteractionValid()) {
|
||||
DEBUG_LEVEL_1("Calculate time until collision");
|
||||
SimulationTimer::eventStartPoint(std::string("MFP calculation"));
|
||||
const double collision_time = collisionTime(particle, random_.get());
|
||||
SimulationTimer::eventStopPoint(std::string("MFP calculation"));
|
||||
// DEBUG_LEVEL_1("Calculate time until collision");
|
||||
SimulationTimer::eventStartPoint(std::string("CollTime calculation"));
|
||||
collisionTime(particle, random_.get());
|
||||
SimulationTimer::eventStopPoint(std::string("CollTime calculation"));
|
||||
}
|
||||
|
||||
#ifdef debug
|
||||
#ifdef debug_level3
|
||||
std::stringstream out_;
|
||||
out_ << "Time until collision: " << particle.timeUntilCollision();
|
||||
DEBUG_LEVEL_1(out_.str());
|
||||
@@ -559,7 +557,7 @@ void Simulation::processUntilTermination(
|
||||
#endif
|
||||
// particle terminated due to reaching time resolution alone -> needs
|
||||
// to be stored (if it's an electron)
|
||||
if(particle.specie()->type() == species::ImplementedSpecies::electron) {
|
||||
if(particle.specie()->explicitlyStored()) {
|
||||
storage_queue_[inactive_storage].push_back(particle.serialize());
|
||||
}
|
||||
|
||||
@@ -660,38 +658,38 @@ void Simulation::processUntilTermination(
|
||||
particle.cylinderPosition(), DeletionType::max_interactions);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
particle.invalidateNextInteraction();
|
||||
}
|
||||
}
|
||||
|
||||
double Simulation::meanFreePath(particle::Particle& particle,
|
||||
RandomNumbers* random,
|
||||
std::vector<double>& macroscopic_cross_sections_m) {
|
||||
double total_macroscopic_cross_section_m = 0.;
|
||||
for (auto& interaction : particle.specie()->interactions()) {
|
||||
double cross_section_tmp = interaction->macroscopicCrossSection(particle);
|
||||
total_macroscopic_cross_section_m += cross_section_tmp;
|
||||
macroscopic_cross_sections_m.push_back(cross_section_tmp);
|
||||
}
|
||||
// double Simulation::meanFreePath(particle::Particle& particle,
|
||||
// RandomNumbers* random,
|
||||
// std::vector<double>& macroscopic_cross_sections_m) {
|
||||
// double total_macroscopic_cross_section_m = 0.;
|
||||
// for (auto& interaction : particle.specie()->interactions()) {
|
||||
// double cross_section_tmp = interaction->macroscopicCrossSection(particle);
|
||||
// total_macroscopic_cross_section_m += cross_section_tmp;
|
||||
// macroscopic_cross_sections_m.push_back(cross_section_tmp);
|
||||
// }
|
||||
|
||||
if (total_macroscopic_cross_section_m <= 0.) {
|
||||
return std::numeric_limits<double>::max();
|
||||
} else {
|
||||
const double rnd_number = random->rollUniform(0., 1.);
|
||||
if (rnd_number <= 0) {
|
||||
return std::numeric_limits<double>::max();
|
||||
} else {
|
||||
return 1. / total_macroscopic_cross_section_m * log(1. / rnd_number);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (total_macroscopic_cross_section_m <= 0.) {
|
||||
// return std::numeric_limits<double>::max();
|
||||
// } else {
|
||||
// const double rnd_number = random->rollUniform(0., 1.);
|
||||
// if (rnd_number <= 0) {
|
||||
// return std::numeric_limits<double>::max();
|
||||
// } else {
|
||||
// return 1. / total_macroscopic_cross_section_m * log(1. / rnd_number);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// maybe rewrite to s.t. the min_element part can be removed (together with the
|
||||
// algorithm lib)
|
||||
double Simulation::collisionTime(particle::Particle& particle, RandomNumbers* random) {
|
||||
void Simulation::collisionTime(particle::Particle& particle, RandomNumbers* random) {
|
||||
std::vector<double> collision_times;
|
||||
double tmp;
|
||||
|
||||
@@ -718,8 +716,6 @@ double Simulation::collisionTime(particle::Particle& particle, RandomNumbers* ra
|
||||
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
#endif
|
||||
|
||||
return *min_iterator;
|
||||
}
|
||||
|
||||
interaction::InteractionOutput Simulation::interact(
|
||||
@@ -774,10 +770,11 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||
all_bins_done = true;
|
||||
|
||||
for(auto& pair: tracked_species_) {
|
||||
|
||||
if(pair.second->type() == species::ImplementedSpecies::electron) {
|
||||
// Note: takes the next particle in the storage queue regardless if
|
||||
// that particle is a member of the current tracked_specie
|
||||
if(pair.second->explicitlyStored()) {
|
||||
// if the storage queue does not contain any more particles
|
||||
// no new particles can be drawn for the electrons
|
||||
// no new particles can be drawn
|
||||
if(storage_queue_[active_storage].empty()) {
|
||||
all_bins_done = all_bins_done && true;
|
||||
continue;
|
||||
|
||||
@@ -38,6 +38,7 @@ TrackedSpecie::TrackedSpecie(
|
||||
std::string name,
|
||||
double mass_kg,
|
||||
double charge_C,
|
||||
bool explicitly_stored,
|
||||
std::shared_ptr<Mover> mover,
|
||||
std::shared_ptr<Terminator> terminator,
|
||||
std::shared_ptr<Reflector> reflector,
|
||||
@@ -59,7 +60,8 @@ TrackedSpecie::TrackedSpecie(
|
||||
std::make_shared<PositionDistributionFromDensity>(density_for_drawing)),
|
||||
velocity_distribution_from_density_(
|
||||
std::make_shared<VelocityDistributionFromDensityField>(
|
||||
density_for_drawing, mass_kg)) {
|
||||
density_for_drawing, mass_kg)),
|
||||
explicitly_stored_(explicitly_stored) {
|
||||
blitz::TinyVector<int, 5> num_bins;
|
||||
auto tmp = density_field->positionBinning()->numBins();
|
||||
num_bins(0) = tmp(0); num_bins(1) = tmp(1); num_bins(2) = tmp(2);
|
||||
@@ -147,6 +149,10 @@ void TrackedSpecie::currentCollector(
|
||||
current_collector_ = new_collector;
|
||||
}
|
||||
|
||||
bool TrackedSpecie::explicitlyStored() {
|
||||
return explicitly_stored_;
|
||||
}
|
||||
|
||||
BackgroundSpecie::BackgroundSpecie(
|
||||
ImplementedSpecies type,
|
||||
std::string name,
|
||||
|
||||
Reference in New Issue
Block a user