Basic changes for time resolution.

Input from json still suboptimal.
This commit is contained in:
2024-05-14 09:23:52 +02:00
parent cac5e6ff5d
commit 77fa8d175a
12 changed files with 84 additions and 36 deletions
+37 -15
View File
@@ -99,19 +99,33 @@ void Simulation::start() {
parameter_.intValue(json_path({"Simulation", "EventStride"}), 1);
const int total_simulated_events =
parameter_.intValue(json_path({"Simulation", "SimulatedEvents"}), 1);
const int time_resolution_events =
parameter_.intValue(json_path({"Simulation", "TimeResolutionEvents"}),
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));
const int events_this_cpu = eventsThisCpu(total_simulated_events);
// maybe better as class memeber...
const int time_resolution_this_cpu = eventsThisCpu(time_resolution_events);
SIM_INFO("Events per cpu (approx.): " + std::to_string(events_this_cpu));
int leftover_events = events_this_cpu;
int num_cpu_syncs = 0;
bool reset = false;
std::vector<particle::Particle> backup_queue;
backup_queue.reserve(100); // probably should be a more sensible value
while (leftover_events > 0) {
int events_of_cylcle = eventsOfCycle(event_stride, leftover_events);
timer_->increaseTimestep(time_resolution_events*injector_->timePassed());
std::stringstream out;
out << "Timeinterval: " << timer_->time() << "s.";
out << "\n size of particle: " << sizeof(particle::Particle);
DEBUG_LEVEL_3(out.str());
int events_of_cylcle = eventsOfCycle(event_stride, time_resolution_this_cpu);
SIM_INFO("Leftover events on first cpu: " +
std::to_string(leftover_events));
processEvents(events_of_cylcle);
processEvents(events_of_cylcle, backup_queue, time_resolution_events);
DEBUG_LEVEL_3("Size of backup queue: " + std::to_string(backup_queue.size()));
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
leftover_events -= events_of_cylcle;
@@ -154,10 +168,19 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
return random->rollUniform(0, queue_length);
}
void Simulation::processEvents(int events) {
void Simulation::processEvents(int events,
std::vector<particle::Particle>& backup_queue,
const int time_resolution_events) {
DEBUG_LEVEL_0("Processing events.");
std::vector<particle::Particle> particle_queue;
particle_queue.reserve(100);
DEBUG_LEVEL_3("Move backup to processing queue.");
// highly inefficient in case that #cpu_syncs/time_res >> 1
particle_queue.insert(particle_queue.end(), backup_queue.begin(),
backup_queue.end());
// clean backup_queue after moving the elements to the particle queue
backup_queue.erase(backup_queue.begin(), backup_queue.end());
DEBUG_LEVEL_3("Size processing queue: " + std::to_string(particle_queue.size()));
int current_event = 0;
while ((current_event < events) || (!particle_queue.empty())) {
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
@@ -167,7 +190,7 @@ void Simulation::processEvents(int events) {
DEBUG_LEVEL_2("Inject particles to queue.");
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
std::vector<particle::Particle> new_particles =
determineInjectedParticles(random_.get());
determineInjectedParticles(random_.get(), time_resolution_events);
#if defined debug_level3
for(auto& particle : new_particles) {
std::stringstream output_ss;
@@ -193,13 +216,14 @@ void Simulation::processEvents(int events) {
particle::Particle particle = particle_queue.at(particle_number);
particle_queue.erase(particle_queue.begin() + particle_number);
processUntilTermination(particle, particle_queue);
processUntilTermination(particle, particle_queue, backup_queue);
}
}
void Simulation::processUntilTermination(
particle::Particle& particle,
std::vector<particle::Particle>& particle_queue) {
std::vector<particle::Particle>& particle_queue,
std::vector<particle::Particle>& backup_queue) {
DEBUG_LEVEL_3("Process particle until termination");
while (particle.specie()->terminator()->isAlive(&particle)) {
auto old_position = particle.position();
@@ -226,12 +250,9 @@ void Simulation::processUntilTermination(
if (particle.specie()->terminator()->reachedMaxTimeAlive(
&particle)) {
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
+". Reached max time alive.");
if (particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(
particle.position(), DeletionType::max_time_alive);
}
DEBUG_LEVEL_3("Move particle " + particle.specie()->name()
+" to backup queue.");
backup_queue.push_back(particle);
break;
} else if (particle.specie()->terminator()->leftSimulationDomain(
&particle)) {
@@ -339,9 +360,10 @@ interaction::InteractionOutput Simulation::interact(
}
std::vector<particle::Particle> Simulation::determineInjectedParticles(
RandomNumbers* random) {
timer_->increaseTimestep(injector_->timePassed());
return injector_->rollNewParticles(random->engine());
RandomNumbers* random, const int time_resolution_events) {
// timer_->increaseTimestep(injector_->timePassed());
return injector_->rollNewParticles(random->engine(),
timer_->time(), time_resolution_events);
}
//maybe put that into the poisson solver