Fixed to state that drawing from density works.
Some debugging elements not removed.
This commit is contained in:
@@ -24,6 +24,7 @@ struct TrackedSpeciesBuilderInfo {
|
|||||||
std::shared_ptr<VelocityDistribution> velocity_distribution;
|
std::shared_ptr<VelocityDistribution> velocity_distribution;
|
||||||
std::shared_ptr<DriftVelocity> drift_velocity;
|
std::shared_ptr<DriftVelocity> drift_velocity;
|
||||||
std::shared_ptr<DynamicDensityField> last_sync_density_field;
|
std::shared_ptr<DynamicDensityField> last_sync_density_field;
|
||||||
|
std::shared_ptr<DynamicDensityField> density_drawing_field;
|
||||||
|
|
||||||
double mass_kg;
|
double mass_kg;
|
||||||
double charge_C;
|
double charge_C;
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ class CpuSynchronizer {
|
|||||||
|
|
||||||
void synchronize(
|
void synchronize(
|
||||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
|
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
|
||||||
tracked_species);
|
tracked_species, bool reset);
|
||||||
|
|
||||||
void synchronize(DynamicDensityField* field,
|
void synchronize(DynamicDensityField* field,
|
||||||
DynamicDensityField* last_sync_field);
|
DynamicDensityField* last_sync_field,
|
||||||
|
DynamicDensityField* density_for_drawing,
|
||||||
|
bool reset);
|
||||||
void synchronize(CurrentCollector* collector,
|
void synchronize(CurrentCollector* collector,
|
||||||
CurrentCollector* last_sync_collector);
|
CurrentCollector* last_sync_collector);
|
||||||
void synchronize(DeletionLogger* logger,
|
void synchronize(DeletionLogger* logger,
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class DynamicDensityField : public DensityField {
|
|||||||
const CylinderBinning* positionBinning() const;
|
const CylinderBinning* positionBinning() const;
|
||||||
|
|
||||||
double physicalTime() const;
|
double physicalTime() const;
|
||||||
|
double timeResolution() const;
|
||||||
|
|
||||||
friend class CpuSynchronizer;
|
friend class CpuSynchronizer;
|
||||||
|
|
||||||
|
|||||||
@@ -34,14 +34,16 @@ class Simulation {
|
|||||||
void init(Parameter& parameter);
|
void init(Parameter& parameter);
|
||||||
void start();
|
void start();
|
||||||
void finalize();
|
void finalize();
|
||||||
void processEvents(int events, int density_events);
|
// cpu_syncs only included for debug purposes, e.g. only drawing decay particles
|
||||||
|
// at the 0th timestep
|
||||||
|
void processEvents(int events, int density_events, int cpu_syncs);
|
||||||
void processUntilTermination(particle::Particle& particle);
|
void processUntilTermination(particle::Particle& particle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<particle::Particle> determineInjectedParticles(RandomNumbers* random);
|
std::vector<particle::Particle> determineInjectedParticles(RandomNumbers* random);
|
||||||
std::vector<particle::Particle>
|
std::vector<particle::Particle>
|
||||||
determineInjectedDensityParticles(RandomNumbers* random,
|
determineInjectedDensityParticles(RandomNumbers* random,
|
||||||
const int numberParticlesToDraw);
|
const int numberParticlesToDraw, const int current);
|
||||||
|
|
||||||
double meanFreePath(particle::Particle& particle, RandomNumbers* random);
|
double meanFreePath(particle::Particle& particle, RandomNumbers* random);
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ class TrackedSpecie : public Specie {
|
|||||||
std::shared_ptr<DynamicDensityField> density_field,
|
std::shared_ptr<DynamicDensityField> density_field,
|
||||||
std::shared_ptr<VelocityDistribution> velocity_distribution,
|
std::shared_ptr<VelocityDistribution> velocity_distribution,
|
||||||
std::shared_ptr<DriftVelocity> drift_velocity,
|
std::shared_ptr<DriftVelocity> drift_velocity,
|
||||||
std::shared_ptr<DynamicDensityField> last_sync_density_field);
|
std::shared_ptr<DynamicDensityField> last_sync_density_field,
|
||||||
|
std::shared_ptr<DynamicDensityField> density_for_drawing);
|
||||||
|
|
||||||
DensityField* densityField();
|
DensityField* densityField();
|
||||||
VelocityDistribution* velocityDistibution();
|
VelocityDistribution* velocityDistibution();
|
||||||
@@ -80,6 +81,8 @@ class TrackedSpecie : public Specie {
|
|||||||
DeletionLogger* lastSyncDeletionLogger();
|
DeletionLogger* lastSyncDeletionLogger();
|
||||||
void lastSyncDeletionLogger(std::shared_ptr<DeletionLogger> new_logger);
|
void lastSyncDeletionLogger(std::shared_ptr<DeletionLogger> new_logger);
|
||||||
|
|
||||||
|
DynamicDensityField* densityForDrawing();
|
||||||
|
|
||||||
CurrentCollector* currentCollector();
|
CurrentCollector* currentCollector();
|
||||||
void currentCollector(std::shared_ptr<CurrentCollector> new_collector);
|
void currentCollector(std::shared_ptr<CurrentCollector> new_collector);
|
||||||
|
|
||||||
@@ -109,6 +112,8 @@ class TrackedSpecie : public Specie {
|
|||||||
std::shared_ptr<DynamicDensityField> last_sync_density_field_;
|
std::shared_ptr<DynamicDensityField> last_sync_density_field_;
|
||||||
std::shared_ptr<DeletionLogger> last_sync_deletion_logger_;
|
std::shared_ptr<DeletionLogger> last_sync_deletion_logger_;
|
||||||
std::shared_ptr<CurrentCollector> last_sync_current_collector_;
|
std::shared_ptr<CurrentCollector> last_sync_current_collector_;
|
||||||
|
|
||||||
|
std::shared_ptr<DynamicDensityField> density_for_drawing_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BackgroundSpecie : public Specie {
|
class BackgroundSpecie : public Specie {
|
||||||
|
|||||||
@@ -259,6 +259,13 @@ void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
|
|||||||
{"DensityField", "DynamicDensityField"}),
|
{"DensityField", "DynamicDensityField"}),
|
||||||
timer_);
|
timer_);
|
||||||
|
|
||||||
|
// not the optimal solution! (has to be optimized)
|
||||||
|
b.second.density_drawing_field = buildDynamicDensityField(
|
||||||
|
parameter,
|
||||||
|
json_path_append(b.second.path_in_json,
|
||||||
|
{"DensityField", "DynamicDensityField"}),
|
||||||
|
timer_);
|
||||||
|
|
||||||
b.second.last_sync_density_field = buildDynamicDensityField(
|
b.second.last_sync_density_field = buildDynamicDensityField(
|
||||||
parameter,
|
parameter,
|
||||||
json_path_append(b.second.path_in_json,
|
json_path_append(b.second.path_in_json,
|
||||||
@@ -283,7 +290,8 @@ void SpeciesBuilder::buildSpecies() {
|
|||||||
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.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.last_sync_density_field));
|
b.second.drift_velocity, b.second.last_sync_density_field,
|
||||||
|
b.second.density_drawing_field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,9 @@ void CpuSynchronizer::synchronize(Timer* timer, Timer* last_sync_timer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CpuSynchronizer::synchronize(DynamicDensityField* field,
|
void CpuSynchronizer::synchronize(DynamicDensityField* field,
|
||||||
DynamicDensityField* last_sync_field) {
|
DynamicDensityField* last_sync_field,
|
||||||
|
DynamicDensityField* density_for_drawing,
|
||||||
|
bool reset) {
|
||||||
if (field && last_sync_field) {
|
if (field && last_sync_field) {
|
||||||
if(field == last_sync_field) {
|
if(field == last_sync_field) {
|
||||||
ERROR("The way last_sync_field is created does not work as intended.");
|
ERROR("The way last_sync_field is created does not work as intended.");
|
||||||
@@ -75,6 +77,11 @@ void CpuSynchronizer::synchronize(DynamicDensityField* field,
|
|||||||
|
|
||||||
sumToAll(field->deleted_particles_, last_sync_field->deleted_particles_);
|
sumToAll(field->deleted_particles_, last_sync_field->deleted_particles_);
|
||||||
field->deleted_particles_ = last_sync_field->deleted_particles_;
|
field->deleted_particles_ = last_sync_field->deleted_particles_;
|
||||||
|
if (reset) {
|
||||||
|
density_for_drawing->time_in_bin_s_ = last_sync_field->time_in_bin_s_;
|
||||||
|
density_for_drawing->deleted_particles_ =
|
||||||
|
last_sync_field->deleted_particles_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +137,7 @@ void CpuSynchronizer::synchronize(DeletionLogger* logger,
|
|||||||
|
|
||||||
void CpuSynchronizer::synchronize(
|
void CpuSynchronizer::synchronize(
|
||||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
|
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
|
||||||
tracked_species) {
|
tracked_species, bool reset) {
|
||||||
MPI_Barrier(MPI_COMM_WORLD);
|
MPI_Barrier(MPI_COMM_WORLD);
|
||||||
auto it = tracked_species.begin();
|
auto it = tracked_species.begin();
|
||||||
// drops due to time being a global variable now
|
// drops due to time being a global variable now
|
||||||
@@ -141,7 +148,8 @@ void CpuSynchronizer::synchronize(
|
|||||||
for (auto& pair : tracked_species) {
|
for (auto& pair : tracked_species) {
|
||||||
// DEBUG_LEVEL_3("dynden Synchronization.");
|
// DEBUG_LEVEL_3("dynden Synchronization.");
|
||||||
synchronize(pair.second->dynamicDensityField(),
|
synchronize(pair.second->dynamicDensityField(),
|
||||||
pair.second->lastSyncDensityField());
|
pair.second->lastSyncDensityField(),
|
||||||
|
pair.second->densityForDrawing(), reset);
|
||||||
// DEBUG_LEVEL_3("cc Synchronization.");
|
// DEBUG_LEVEL_3("cc Synchronization.");
|
||||||
synchronize(pair.second->currentCollector(),
|
synchronize(pair.second->currentCollector(),
|
||||||
pair.second->lastSyncCurrentCollector());
|
pair.second->lastSyncCurrentCollector());
|
||||||
|
|||||||
@@ -183,14 +183,17 @@ void DynamicDensityField::initPositionDistributions() {
|
|||||||
auto zbins = position_binning_.longitudinal_binning.binBorders();
|
auto zbins = position_binning_.longitudinal_binning.binBorders();
|
||||||
auto phibins = position_binning_.azimuth_binning.binBorders();
|
auto phibins = position_binning_.azimuth_binning.binBorders();
|
||||||
|
|
||||||
rmin = *(rbins.begin());
|
rmin = rbins.front();
|
||||||
rmax = *(rbins.end());
|
rmax = rbins.back();
|
||||||
|
DEBUG_LEVEL_3("rmax: " + std::to_string(rmax));
|
||||||
|
|
||||||
zmin = *(zbins.begin());
|
zmin = zbins.front();
|
||||||
zmax = *(zbins.end());
|
zmax = zbins.back();
|
||||||
|
DEBUG_LEVEL_3("zmax: " + std::to_string(zmax));
|
||||||
|
|
||||||
phimin = *(phibins.begin());
|
phimin = phibins.front();
|
||||||
phimax = *(phibins.end());
|
phimax = phibins.back();
|
||||||
|
DEBUG_LEVEL_3("phimax: " + std::to_string(phimax));
|
||||||
|
|
||||||
r_dist_ = std::uniform_real_distribution<double>(rmin*rmin, rmax*rmax);
|
r_dist_ = std::uniform_real_distribution<double>(rmin*rmin, rmax*rmax);
|
||||||
phi_dist_ = std::uniform_real_distribution<double>(phimin, phimax);
|
phi_dist_ = std::uniform_real_distribution<double>(phimin, phimax);
|
||||||
@@ -206,6 +209,7 @@ blitz::TinyVector<double, 4> DynamicDensityField::drawPositionAndEnergy(
|
|||||||
std::mt19937* engine) {
|
std::mt19937* engine) {
|
||||||
// if the density is empty, then return a TinyVector filled with 0s as
|
// if the density is empty, then return a TinyVector filled with 0s as
|
||||||
// an indiction of that (probably not the best solution)
|
// an indiction of that (probably not the best solution)
|
||||||
|
recalculateDensityArray();
|
||||||
if (isEqual(blitz::max(density_per_m3_), 0.)) {
|
if (isEqual(blitz::max(density_per_m3_), 0.)) {
|
||||||
DEBUG_LEVEL_3("Density is empty");
|
DEBUG_LEVEL_3("Density is empty");
|
||||||
return blitz::TinyVector<double, 4> (0,0,0,0);
|
return blitz::TinyVector<double, 4> (0,0,0,0);
|
||||||
@@ -245,6 +249,7 @@ blitz::TinyVector<double, 4> DynamicDensityField::drawPositionAndEnergy(
|
|||||||
densityAtPosition.begin());
|
densityAtPosition.begin());
|
||||||
|
|
||||||
random_E = E_dist_(*engine);
|
random_E = E_dist_(*engine);
|
||||||
|
DEBUG_LEVEL_3("energy: " + std::to_string(random_E));
|
||||||
|
|
||||||
return blitz::TinyVector<double, 4> (random_r, random_phi, random_z, random_E);
|
return blitz::TinyVector<double, 4> (random_r, random_phi, random_z, random_E);
|
||||||
}
|
}
|
||||||
@@ -288,6 +293,10 @@ double DynamicDensityField::physicalTime() const {
|
|||||||
return timer_->time();
|
return timer_->time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double DynamicDensityField::timeResolution() const {
|
||||||
|
return timer_->getDeltaT();
|
||||||
|
}
|
||||||
|
|
||||||
void DynamicDensityField::resetDynamicDensityField() {
|
void DynamicDensityField::resetDynamicDensityField() {
|
||||||
//timer_->resetTime(); // time stays global
|
//timer_->resetTime(); // time stays global
|
||||||
time_in_bin_s_ = 0.;
|
time_in_bin_s_ = 0.;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ void Injector::rollNewParticleFromDensityField(std::mt19937* engine,
|
|||||||
const double weight,
|
const double weight,
|
||||||
const double injection_time) {
|
const double injection_time) {
|
||||||
blitz::TinyVector<double, 4> particle_specs =
|
blitz::TinyVector<double, 4> particle_specs =
|
||||||
specie->dynamicDensityField()->drawPositionAndEnergy(engine);
|
specie->densityForDrawing()->drawPositionAndEnergy(engine);
|
||||||
// blitz::TinyVector<double, 4> particle_specs(0.01, 0, 1, 1);
|
// blitz::TinyVector<double, 4> particle_specs(0.01, 0, 1, 1);
|
||||||
|
|
||||||
// check if density was empty (i.e. Energy component is 0)
|
// check if density was empty (i.e. Energy component is 0)
|
||||||
@@ -89,6 +89,7 @@ void Injector::rollNewParticleFromDensityField(std::mt19937* engine,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_LEVEL_3("Injected z position: " + std::to_string(particle_specs(2)));
|
DEBUG_LEVEL_3("Injected z position: " + std::to_string(particle_specs(2)));
|
||||||
|
DEBUG_LEVEL_3("Injected r position: " + std::to_string(particle_specs(0)));
|
||||||
|
|
||||||
const double v_abs = kinematic::velocity(particle_specs[3], specie->mass_kg());
|
const double v_abs = kinematic::velocity(particle_specs[3], specie->mass_kg());
|
||||||
|
|
||||||
|
|||||||
@@ -186,8 +186,9 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
bool left_simulation_domain = false;
|
bool left_simulation_domain = false;
|
||||||
// if particle too slow -> timestep > maximum time the particle lives
|
// if particle too slow -> timestep > maximum time the particle lives
|
||||||
// -> add maximal timestep to time in bin and stop moving the particle
|
// -> add maximal timestep to time in bin and stop moving the particle
|
||||||
bool died_in_bin = false;
|
bool died_in_bin = false;
|
||||||
const double max_time_alive =
|
// DEBUG_LEVEL_3("Mover: timealive before moving: " + std::to_string(particle->timeAlive()));
|
||||||
|
double max_time_alive =
|
||||||
particle->specie()->dynamicDensityField()->physicalTime() -
|
particle->specie()->dynamicDensityField()->physicalTime() -
|
||||||
particle->timeAlive();
|
particle->timeAlive();
|
||||||
|
|
||||||
@@ -308,6 +309,22 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
|
|
||||||
particle->increaseTimeAlive(timestep);
|
particle->increaseTimeAlive(timestep);
|
||||||
particle->increaseTimeInBin(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 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 (at most) a factor
|
||||||
|
// of (1 + eps) (if no particles are lost)
|
||||||
|
// TODO:
|
||||||
|
// - check if it's not better to change the terminator such that is uses the
|
||||||
|
// compare function from /include/simulation/compare.h
|
||||||
|
max_time_alive = ((max_time_alive - timestep) <= 0)
|
||||||
|
? particle->specie()->dynamicDensityField()
|
||||||
|
->timeResolution()*SimConstants::compare_epsilon
|
||||||
|
: (max_time_alive - timestep);
|
||||||
|
if (max_time_alive == 0) {
|
||||||
|
DEBUG_LEVEL_3("Mover: max_time_alive is 0.");
|
||||||
|
DEBUG_LEVEL_3("Mover: particle time alive: " + std::to_string(particle->timeAlive()));
|
||||||
|
}
|
||||||
|
|
||||||
const auto new_position = particle->position();
|
const auto new_position = particle->position();
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ double Particle::timeAlive() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Particle::increaseTimeInBin(double time_s) {
|
void Particle::increaseTimeInBin(double time_s) {
|
||||||
time_in_bin_s_ += time_s*weight_;
|
time_in_bin_s_ += time_s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Particle::resetTimeInBin() {
|
void Particle::resetTimeInBin() {
|
||||||
@@ -110,7 +110,7 @@ void Particle::resetTimeInBin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double Particle::timeInBin() const {
|
double Particle::timeInBin() const {
|
||||||
return time_in_bin_s_;
|
return time_in_bin_s_*weight_;
|
||||||
}
|
}
|
||||||
|
|
||||||
long int Particle::ID() const {
|
long int Particle::ID() const {
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ void Simulation::start() {
|
|||||||
total_simulated_events);
|
total_simulated_events);
|
||||||
const int density_events =
|
const int density_events =
|
||||||
parameter_.intValue(json_path({"Simulation", "DensityEventsPerCPU"}), 0);
|
parameter_.intValue(json_path({"Simulation", "DensityEventsPerCPU"}), 0);
|
||||||
|
DEBUG_LEVEL_0("Density events per cpu: " + std::to_string(density_events));
|
||||||
|
|
||||||
SIM_INFO("Total simulated events: " + std::to_string(total_simulated_events));
|
SIM_INFO("Total simulated events: " + std::to_string(total_simulated_events));
|
||||||
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
|
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
|
||||||
@@ -132,7 +133,7 @@ void Simulation::start() {
|
|||||||
int events_of_cylcle = eventsOfCycle(event_stride, leftover_events_time_resolution);
|
int events_of_cylcle = eventsOfCycle(event_stride, leftover_events_time_resolution);
|
||||||
SIM_INFO("Leftover events on first cpu: " +
|
SIM_INFO("Leftover events on first cpu: " +
|
||||||
std::to_string(leftover_events));
|
std::to_string(leftover_events));
|
||||||
processEvents(events_of_cylcle, density_events);
|
processEvents(events_of_cylcle, density_events, num_cpu_syncs);
|
||||||
|
|
||||||
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
|
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
|
||||||
leftover_events -= events_of_cylcle;
|
leftover_events -= events_of_cylcle;
|
||||||
@@ -142,7 +143,7 @@ void Simulation::start() {
|
|||||||
|
|
||||||
SIM_INFO("Cpu sync.");
|
SIM_INFO("Cpu sync.");
|
||||||
SimulationTimer::eventStartPoint(std::string("CpuSync"));
|
SimulationTimer::eventStartPoint(std::string("CpuSync"));
|
||||||
cpu_synchronizer_->synchronize(tracked_species_);
|
cpu_synchronizer_->synchronize(tracked_species_, reset);
|
||||||
num_cpu_syncs += 1;
|
num_cpu_syncs += 1;
|
||||||
SimulationTimer::eventStopPoint(std::string("CpuSync"));
|
SimulationTimer::eventStopPoint(std::string("CpuSync"));
|
||||||
|
|
||||||
@@ -185,7 +186,7 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
|
|||||||
return random->rollUniform(0, queue_length);
|
return random->rollUniform(0, queue_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::processEvents(int events, int density_events) {
|
void Simulation::processEvents(int events, int density_events, int cpu_syncs) {
|
||||||
DEBUG_LEVEL_0("Processing events.");
|
DEBUG_LEVEL_0("Processing events.");
|
||||||
int current_event = 0;
|
int current_event = 0;
|
||||||
int current_density_event = 0;
|
int current_density_event = 0;
|
||||||
@@ -195,6 +196,10 @@ void Simulation::processEvents(int events, int density_events) {
|
|||||||
if (queue_.empty()) {
|
if (queue_.empty()) {
|
||||||
std::vector<particle::Particle> new_particles;
|
std::vector<particle::Particle> new_particles;
|
||||||
if(current_density_event == density_events) {
|
if(current_density_event == density_events) {
|
||||||
|
// if(cpu_syncs > 0) {
|
||||||
|
// DEBUG_LEVEL_3("Break while loop.");
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
current_event += 1;
|
current_event += 1;
|
||||||
DEBUG_LEVEL_2("Inject particles to queue.");
|
DEBUG_LEVEL_2("Inject particles to queue.");
|
||||||
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
||||||
@@ -213,13 +218,13 @@ void Simulation::processEvents(int events, int density_events) {
|
|||||||
DEBUG_LEVEL_2("Injected particles to queue.");
|
DEBUG_LEVEL_2("Injected particles to queue.");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
current_density_event += 1;
|
|
||||||
DEBUG_LEVEL_2("Current density event: " +
|
DEBUG_LEVEL_2("Current density event: " +
|
||||||
std::to_string(current_density_event));
|
std::to_string(current_density_event));
|
||||||
//maybe use a different event name?
|
//maybe use a different event name?
|
||||||
SimulationTimer::eventStartPoint(std::string("DensityParticleInjection"));
|
SimulationTimer::eventStartPoint(std::string("DensityParticleInjection"));
|
||||||
new_particles = determineInjectedDensityParticles(random_.get(), density_events);
|
new_particles = determineInjectedDensityParticles(random_.get(), density_events, current_density_event);
|
||||||
SimulationTimer::eventStopPoint(std::string("DensityParticleInjection"));
|
SimulationTimer::eventStopPoint(std::string("DensityParticleInjection"));
|
||||||
|
current_density_event += 1;
|
||||||
}
|
}
|
||||||
if(new_particles.empty())
|
if(new_particles.empty())
|
||||||
continue;
|
continue;
|
||||||
@@ -385,24 +390,28 @@ std::vector<particle::Particle> Simulation::determineInjectedParticles(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||||
RandomNumbers* random, const int numberParticlesToDraw) {
|
RandomNumbers* random, const int numberParticlesToDraw, const int current) {
|
||||||
std::vector<particle::Particle> new_particles{};
|
std::vector<particle::Particle> new_particles{};
|
||||||
if(!new_particles.empty()) {
|
if(!new_particles.empty()) {
|
||||||
ERROR("In drawing particles from the density: the new particles vector is not empty at initialization");
|
ERROR("In drawing particles from the density: the new particles vector is not empty at initialization");
|
||||||
}
|
}
|
||||||
const double injection_time = timer_->time() - timer_->getDeltaT();
|
const double injection_time = timer_->time() - timer_->getDeltaT();
|
||||||
for(auto& pair: tracked_species_) {
|
for(auto& pair: tracked_species_) {
|
||||||
|
// particle number of the denstiy, i.e. the integral over the density
|
||||||
const double particleNumberDensity =
|
const double particleNumberDensity =
|
||||||
pair.second->dynamicDensityField()->particleNumber();
|
pair.second->densityForDrawing()->particleNumber();
|
||||||
if (particleNumberDensity == 0) {
|
if (particleNumberDensity == 0) {
|
||||||
DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name());
|
DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
DEBUG_LEVEL_3("particle number " + pair.second->name() + ": " + std::to_string(particleNumberDensity));
|
if (current == 0) {
|
||||||
|
DEBUG_LEVEL_0("particle number " + pair.second->name() + ": " + std::to_string(particleNumberDensity));
|
||||||
|
// DEBUG_LEVEL_0("weight: " + std::to_string(particleNumberDensity/numberParticlesToDraw));
|
||||||
|
}
|
||||||
injector_->rollNewParticleFromDensityField(random->engine(),
|
injector_->rollNewParticleFromDensityField(random->engine(),
|
||||||
pair.second,
|
pair.second,
|
||||||
new_particles,
|
new_particles,
|
||||||
numberParticlesToDraw/particleNumberDensity,
|
particleNumberDensity/numberParticlesToDraw/MpiCommunication::mpiSize(),
|
||||||
injection_time);
|
injection_time);
|
||||||
}
|
}
|
||||||
return new_particles;
|
return new_particles;
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ TrackedSpecie::TrackedSpecie(
|
|||||||
std::shared_ptr<DynamicDensityField> density_field,
|
std::shared_ptr<DynamicDensityField> density_field,
|
||||||
std::shared_ptr<VelocityDistribution> velocity_distribution,
|
std::shared_ptr<VelocityDistribution> velocity_distribution,
|
||||||
std::shared_ptr<DriftVelocity> drift_velocity,
|
std::shared_ptr<DriftVelocity> drift_velocity,
|
||||||
std::shared_ptr<DynamicDensityField> last_sync_density_field)
|
std::shared_ptr<DynamicDensityField> last_sync_density_field,
|
||||||
|
std::shared_ptr<DynamicDensityField> density_for_drawing)
|
||||||
: Specie(type, name, mass_kg, charge_C),
|
: Specie(type, name, mass_kg, charge_C),
|
||||||
mover_(mover),
|
mover_(mover),
|
||||||
terminator_(terminator),
|
terminator_(terminator),
|
||||||
@@ -54,7 +55,8 @@ TrackedSpecie::TrackedSpecie(
|
|||||||
drift_velocity_(drift_velocity),
|
drift_velocity_(drift_velocity),
|
||||||
last_sync_density_field_(last_sync_density_field),
|
last_sync_density_field_(last_sync_density_field),
|
||||||
last_sync_deletion_logger_(std::shared_ptr<DeletionLogger>(nullptr)),
|
last_sync_deletion_logger_(std::shared_ptr<DeletionLogger>(nullptr)),
|
||||||
last_sync_current_collector_(std::shared_ptr<CurrentCollector>(nullptr)) {}
|
last_sync_current_collector_(std::shared_ptr<CurrentCollector>(nullptr)),
|
||||||
|
density_for_drawing_(density_for_drawing) {}
|
||||||
|
|
||||||
DensityField* TrackedSpecie::densityField() {
|
DensityField* TrackedSpecie::densityField() {
|
||||||
return density_field_.get();
|
return density_field_.get();
|
||||||
@@ -75,6 +77,10 @@ DynamicDensityField* TrackedSpecie::lastSyncDensityField() {
|
|||||||
return last_sync_density_field_.get();
|
return last_sync_density_field_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DynamicDensityField* TrackedSpecie::densityForDrawing() {
|
||||||
|
return density_for_drawing_.get();
|
||||||
|
}
|
||||||
|
|
||||||
Mover* TrackedSpecie::mover() {
|
Mover* TrackedSpecie::mover() {
|
||||||
return mover_.get();
|
return mover_.get();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user