Fixed to state that drawing from density works.

Some debugging elements not removed.
This commit is contained in:
2024-08-12 14:20:45 +02:00
parent b57f6ff201
commit 9dda12b60a
13 changed files with 100 additions and 31 deletions
+18 -9
View File
@@ -104,6 +104,7 @@ void Simulation::start() {
total_simulated_events);
const int density_events =
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("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);
SIM_INFO("Leftover events on first cpu: " +
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));
leftover_events -= events_of_cylcle;
@@ -142,7 +143,7 @@ void Simulation::start() {
SIM_INFO("Cpu sync.");
SimulationTimer::eventStartPoint(std::string("CpuSync"));
cpu_synchronizer_->synchronize(tracked_species_);
cpu_synchronizer_->synchronize(tracked_species_, reset);
num_cpu_syncs += 1;
SimulationTimer::eventStopPoint(std::string("CpuSync"));
@@ -185,7 +186,7 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
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.");
int current_event = 0;
int current_density_event = 0;
@@ -195,6 +196,10 @@ void Simulation::processEvents(int events, int density_events) {
if (queue_.empty()) {
std::vector<particle::Particle> new_particles;
if(current_density_event == density_events) {
// if(cpu_syncs > 0) {
// DEBUG_LEVEL_3("Break while loop.");
// break;
// }
current_event += 1;
DEBUG_LEVEL_2("Inject particles to queue.");
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
@@ -213,13 +218,13 @@ void Simulation::processEvents(int events, int density_events) {
DEBUG_LEVEL_2("Injected particles to queue.");
} else {
current_density_event += 1;
DEBUG_LEVEL_2("Current density event: " +
std::to_string(current_density_event));
//maybe use a different event name?
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"));
current_density_event += 1;
}
if(new_particles.empty())
continue;
@@ -385,24 +390,28 @@ std::vector<particle::Particle> Simulation::determineInjectedParticles(
}
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{};
if(!new_particles.empty()) {
ERROR("In drawing particles from the density: the new particles vector is not empty at initialization");
}
const double injection_time = timer_->time() - timer_->getDeltaT();
for(auto& pair: tracked_species_) {
// particle number of the denstiy, i.e. the integral over the density
const double particleNumberDensity =
pair.second->dynamicDensityField()->particleNumber();
pair.second->densityForDrawing()->particleNumber();
if (particleNumberDensity == 0) {
DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name());
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(),
pair.second,
new_particles,
numberParticlesToDraw/particleNumberDensity,
particleNumberDensity/numberParticlesToDraw/MpiCommunication::mpiSize(),
injection_time);
}
return new_particles;