Added option whether particles should be stored
explicitly
This commit is contained in:
@@ -28,6 +28,7 @@ struct TrackedSpeciesBuilderInfo {
|
|||||||
|
|
||||||
double mass_kg;
|
double mass_kg;
|
||||||
double charge_C;
|
double charge_C;
|
||||||
|
bool explicitly_stored;
|
||||||
species::ImplementedSpecies type;
|
species::ImplementedSpecies type;
|
||||||
std::string name;
|
std::string name;
|
||||||
json_path path_in_json;
|
json_path path_in_json;
|
||||||
@@ -109,6 +110,7 @@ class SpeciesBuilder {
|
|||||||
void fillTerminator(Parameter& parameter);
|
void fillTerminator(Parameter& parameter);
|
||||||
void fillReflector(Parameter& parameter);
|
void fillReflector(Parameter& parameter);
|
||||||
void fillTrackedDensity(Parameter& parameter);
|
void fillTrackedDensity(Parameter& parameter);
|
||||||
|
void fillDensityDrawingType(Parameter& parameter);
|
||||||
|
|
||||||
void initTimer();
|
void initTimer();
|
||||||
void buildSpecies();
|
void buildSpecies();
|
||||||
|
|||||||
@@ -51,14 +51,14 @@ class Simulation {
|
|||||||
std::map<std::string, double>& particleNumbers,
|
std::map<std::string, double>& particleNumbers,
|
||||||
bool& all_bins_done);
|
bool& all_bins_done);
|
||||||
|
|
||||||
double meanFreePath(particle::Particle& particle, RandomNumbers* random,
|
// double meanFreePath(particle::Particle& particle, RandomNumbers* random,
|
||||||
std::vector<double>& macroscopic_cross_sections_m);
|
// std::vector<double>& macroscopic_cross_sections_m);
|
||||||
|
|
||||||
|
|
||||||
// draw the individual collision times of the possible interactions and return the
|
// draw the individual collision times of the possible interactions and return the
|
||||||
// minimum of them. Also sets the "nextInteractionIndex" in the particle to the
|
// minimum of them. Also sets the "nextInteractionIndex" in the particle to the
|
||||||
// interaction of the chosen time.
|
// interaction of the chosen time.
|
||||||
double collisionTime(particle::Particle& particle, RandomNumbers* random);
|
void collisionTime(particle::Particle& particle, RandomNumbers* random);
|
||||||
interaction::InteractionOutput interact(particle::Particle& particle,
|
interaction::InteractionOutput interact(particle::Particle& particle,
|
||||||
RandomNumbers* random);
|
RandomNumbers* random);
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class TrackedSpecie : public Specie {
|
|||||||
std::string name,
|
std::string name,
|
||||||
double mass_kg,
|
double mass_kg,
|
||||||
double charge_C,
|
double charge_C,
|
||||||
|
bool explicitly_stored,
|
||||||
std::shared_ptr<Mover> mover,
|
std::shared_ptr<Mover> mover,
|
||||||
std::shared_ptr<Terminator> terminator,
|
std::shared_ptr<Terminator> terminator,
|
||||||
std::shared_ptr<Reflector> reflector,
|
std::shared_ptr<Reflector> reflector,
|
||||||
@@ -95,6 +96,8 @@ class TrackedSpecie : public Specie {
|
|||||||
// getter for the raw pointer to the RandomIndex object
|
// getter for the raw pointer to the RandomIndex object
|
||||||
RandomIndex* randomIndex();
|
RandomIndex* randomIndex();
|
||||||
|
|
||||||
|
bool explicitlyStored();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DynamicDensityField> density_field_;
|
std::shared_ptr<DynamicDensityField> density_field_;
|
||||||
std::shared_ptr<VelocityDistribution> velocity_distribution_;
|
std::shared_ptr<VelocityDistribution> velocity_distribution_;
|
||||||
@@ -115,6 +118,11 @@ class TrackedSpecie : public Specie {
|
|||||||
velocity_distribution_from_density_;
|
velocity_distribution_from_density_;
|
||||||
|
|
||||||
std::shared_ptr<RandomIndex> random_index_;
|
std::shared_ptr<RandomIndex> random_index_;
|
||||||
|
|
||||||
|
// should work if it changes from true -> false (after a restart)
|
||||||
|
// however, it should not work in the opposite case (in which the
|
||||||
|
// old density would be lost)
|
||||||
|
const bool explicitly_stored_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BackgroundSpecie : public Specie {
|
class BackgroundSpecie : public Specie {
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ SpeciesBuilder::SpeciesBuilder(Parameter& parameter) {
|
|||||||
fillTerminator(parameter);
|
fillTerminator(parameter);
|
||||||
fillReflector(parameter);
|
fillReflector(parameter);
|
||||||
fillTrackedDensity(parameter);
|
fillTrackedDensity(parameter);
|
||||||
|
fillDensityDrawingType(parameter);
|
||||||
|
|
||||||
buildSpecies();
|
buildSpecies();
|
||||||
fillInteractions(parameter);
|
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() {
|
void SpeciesBuilder::buildSpecies() {
|
||||||
#ifdef debug_level2
|
#ifdef debug_level2
|
||||||
DEBUG_LEVEL_2("Build species from info.");
|
DEBUG_LEVEL_2("Build species from info.");
|
||||||
@@ -319,9 +327,15 @@ void SpeciesBuilder::buildSpecies() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto& b : tracked_species_info) {
|
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] =
|
tracked_species[b.first] =
|
||||||
std::shared_ptr<species::TrackedSpecie>(new species::TrackedSpecie(
|
std::shared_ptr<species::TrackedSpecie>(new species::TrackedSpecie(
|
||||||
b.second.type, b.second.name, b.second.mass_kg, b.second.charge_C,
|
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.mover, b.second.terminator, b.second.reflector,
|
||||||
b.second.density_field, b.second.velocity_distribution,
|
b.second.density_field, b.second.velocity_distribution,
|
||||||
b.second.drift_velocity, b.second.density_drawing_field));
|
b.second.drift_velocity, b.second.density_drawing_field));
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ void Simulation::start() {
|
|||||||
|
|
||||||
SimulationTimer::eventStartPoint("Reset");
|
SimulationTimer::eventStartPoint("Reset");
|
||||||
if(reset) {
|
if(reset) {
|
||||||
#if defined(debug_level2)
|
#if defined(debug_level2) || defined(debug_level3)
|
||||||
DEBUG_LEVEL_2("Number of particles in active storage queue: "
|
DEBUG_LEVEL_2("Number of particles in active storage queue: "
|
||||||
+ std::to_string(storage_queue_[active_storage].size()));
|
+ std::to_string(storage_queue_[active_storage].size()));
|
||||||
DEBUG_LEVEL_2("Number of particles in inactive storage queue: "
|
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
|
#endif
|
||||||
// if no new particles could be injected from the density, it is not possible
|
// if no new particles could be injected from the density, it is not possible
|
||||||
// that during another iteration cycle new particles will be injected
|
// 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) {
|
if(all_bins_done) {
|
||||||
current_event += 1;
|
current_event += 1;
|
||||||
for(auto& element : tracked_species_) {
|
for(auto& element : tracked_species_) {
|
||||||
if(element.second->type() == species::ImplementedSpecies::electron) {
|
if(element.second->explicitlyStored()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
element.second->randomIndex()->reshuffle(random_->engine());
|
element.second->randomIndex()->reshuffle(random_->engine());
|
||||||
@@ -496,8 +495,7 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::processUntilTermination(
|
void Simulation::processUntilTermination(particle::Particle& particle) {
|
||||||
particle::Particle& particle) {
|
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Process particle until termination");
|
DEBUG_LEVEL_3("Process particle until termination");
|
||||||
DEBUG_LEVEL_3("Weight of the particle: " + std::to_string(particle.weight()));
|
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();
|
double old_energy = particle.kineticEnergy_eV();
|
||||||
|
|
||||||
if(!particle.isNextInteractionValid()) {
|
if(!particle.isNextInteractionValid()) {
|
||||||
DEBUG_LEVEL_1("Calculate time until collision");
|
// DEBUG_LEVEL_1("Calculate time until collision");
|
||||||
SimulationTimer::eventStartPoint(std::string("MFP calculation"));
|
SimulationTimer::eventStartPoint(std::string("CollTime calculation"));
|
||||||
const double collision_time = collisionTime(particle, random_.get());
|
collisionTime(particle, random_.get());
|
||||||
SimulationTimer::eventStopPoint(std::string("MFP calculation"));
|
SimulationTimer::eventStopPoint(std::string("CollTime calculation"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef debug
|
#ifdef debug_level3
|
||||||
std::stringstream out_;
|
std::stringstream out_;
|
||||||
out_ << "Time until collision: " << particle.timeUntilCollision();
|
out_ << "Time until collision: " << particle.timeUntilCollision();
|
||||||
DEBUG_LEVEL_1(out_.str());
|
DEBUG_LEVEL_1(out_.str());
|
||||||
@@ -559,7 +557,7 @@ void Simulation::processUntilTermination(
|
|||||||
#endif
|
#endif
|
||||||
// particle terminated due to reaching time resolution alone -> needs
|
// particle terminated due to reaching time resolution alone -> needs
|
||||||
// to be stored (if it's an electron)
|
// 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());
|
storage_queue_[inactive_storage].push_back(particle.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,38 +658,38 @@ void Simulation::processUntilTermination(
|
|||||||
particle.cylinderPosition(), DeletionType::max_interactions);
|
particle.cylinderPosition(), DeletionType::max_interactions);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
particle.invalidateNextInteraction();
|
particle.invalidateNextInteraction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double Simulation::meanFreePath(particle::Particle& particle,
|
// double Simulation::meanFreePath(particle::Particle& particle,
|
||||||
RandomNumbers* random,
|
// RandomNumbers* random,
|
||||||
std::vector<double>& macroscopic_cross_sections_m) {
|
// std::vector<double>& macroscopic_cross_sections_m) {
|
||||||
double total_macroscopic_cross_section_m = 0.;
|
// double total_macroscopic_cross_section_m = 0.;
|
||||||
for (auto& interaction : particle.specie()->interactions()) {
|
// for (auto& interaction : particle.specie()->interactions()) {
|
||||||
double cross_section_tmp = interaction->macroscopicCrossSection(particle);
|
// double cross_section_tmp = interaction->macroscopicCrossSection(particle);
|
||||||
total_macroscopic_cross_section_m += cross_section_tmp;
|
// total_macroscopic_cross_section_m += cross_section_tmp;
|
||||||
macroscopic_cross_sections_m.push_back(cross_section_tmp);
|
// macroscopic_cross_sections_m.push_back(cross_section_tmp);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (total_macroscopic_cross_section_m <= 0.) {
|
// if (total_macroscopic_cross_section_m <= 0.) {
|
||||||
return std::numeric_limits<double>::max();
|
// return std::numeric_limits<double>::max();
|
||||||
} else {
|
// } else {
|
||||||
const double rnd_number = random->rollUniform(0., 1.);
|
// const double rnd_number = random->rollUniform(0., 1.);
|
||||||
if (rnd_number <= 0) {
|
// if (rnd_number <= 0) {
|
||||||
return std::numeric_limits<double>::max();
|
// return std::numeric_limits<double>::max();
|
||||||
} else {
|
// } else {
|
||||||
return 1. / total_macroscopic_cross_section_m * log(1. / rnd_number);
|
// 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
|
// maybe rewrite to s.t. the min_element part can be removed (together with the
|
||||||
// algorithm lib)
|
// algorithm lib)
|
||||||
double Simulation::collisionTime(particle::Particle& particle, RandomNumbers* random) {
|
void Simulation::collisionTime(particle::Particle& particle, RandomNumbers* random) {
|
||||||
std::vector<double> collision_times;
|
std::vector<double> collision_times;
|
||||||
double tmp;
|
double tmp;
|
||||||
|
|
||||||
@@ -718,8 +716,6 @@ double Simulation::collisionTime(particle::Particle& particle, RandomNumbers* ra
|
|||||||
|
|
||||||
DEBUG_LEVEL_3(out.str());
|
DEBUG_LEVEL_3(out.str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *min_iterator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interaction::InteractionOutput Simulation::interact(
|
interaction::InteractionOutput Simulation::interact(
|
||||||
@@ -774,10 +770,11 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
|||||||
all_bins_done = true;
|
all_bins_done = true;
|
||||||
|
|
||||||
for(auto& pair: tracked_species_) {
|
for(auto& pair: tracked_species_) {
|
||||||
|
// Note: takes the next particle in the storage queue regardless if
|
||||||
if(pair.second->type() == species::ImplementedSpecies::electron) {
|
// that particle is a member of the current tracked_specie
|
||||||
|
if(pair.second->explicitlyStored()) {
|
||||||
// if the storage queue does not contain any more particles
|
// 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()) {
|
if(storage_queue_[active_storage].empty()) {
|
||||||
all_bins_done = all_bins_done && true;
|
all_bins_done = all_bins_done && true;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ TrackedSpecie::TrackedSpecie(
|
|||||||
std::string name,
|
std::string name,
|
||||||
double mass_kg,
|
double mass_kg,
|
||||||
double charge_C,
|
double charge_C,
|
||||||
|
bool explicitly_stored,
|
||||||
std::shared_ptr<Mover> mover,
|
std::shared_ptr<Mover> mover,
|
||||||
std::shared_ptr<Terminator> terminator,
|
std::shared_ptr<Terminator> terminator,
|
||||||
std::shared_ptr<Reflector> reflector,
|
std::shared_ptr<Reflector> reflector,
|
||||||
@@ -59,7 +60,8 @@ TrackedSpecie::TrackedSpecie(
|
|||||||
std::make_shared<PositionDistributionFromDensity>(density_for_drawing)),
|
std::make_shared<PositionDistributionFromDensity>(density_for_drawing)),
|
||||||
velocity_distribution_from_density_(
|
velocity_distribution_from_density_(
|
||||||
std::make_shared<VelocityDistributionFromDensityField>(
|
std::make_shared<VelocityDistributionFromDensityField>(
|
||||||
density_for_drawing, mass_kg)) {
|
density_for_drawing, mass_kg)),
|
||||||
|
explicitly_stored_(explicitly_stored) {
|
||||||
blitz::TinyVector<int, 5> num_bins;
|
blitz::TinyVector<int, 5> num_bins;
|
||||||
auto tmp = density_field->positionBinning()->numBins();
|
auto tmp = density_field->positionBinning()->numBins();
|
||||||
num_bins(0) = tmp(0); num_bins(1) = tmp(1); num_bins(2) = tmp(2);
|
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;
|
current_collector_ = new_collector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TrackedSpecie::explicitlyStored() {
|
||||||
|
return explicitly_stored_;
|
||||||
|
}
|
||||||
|
|
||||||
BackgroundSpecie::BackgroundSpecie(
|
BackgroundSpecie::BackgroundSpecie(
|
||||||
ImplementedSpecies type,
|
ImplementedSpecies type,
|
||||||
std::string name,
|
std::string name,
|
||||||
|
|||||||
Reference in New Issue
Block a user