From aef45a3e1ef7a56d1d2d52b7b195124c792d3492 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Thu, 10 Jun 2021 16:20:25 +0200 Subject: [PATCH] More use cases of new iterator --- source/particles/particle_handler.cc | 33 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 8b1d941d40..3ce4213b6d 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -348,7 +348,7 @@ namespace Particles if (container.size() > 1) { container[particle->particle_index_within_cell] = - std::move(particles[particle->cell->active_cell_index()].back()); + std::move(container.back()); container.resize(particles.size() - 1); } else @@ -369,26 +369,27 @@ namespace Particles { unsigned int n_particles_removed = 0; - for (unsigned int cell_index = 0; cell_index < particles.size(); - ++cell_index) + for (auto particles_on_cell = particles.begin(); + particles_on_cell != particles.end(); + ++particles_on_cell) { // If there is nothing left to remove, break and return if (n_particles_removed == particles_to_remove.size()) break; // Skip cells where there is nothing to remove - if (particles_to_remove[n_particles_removed] - ->cell->active_cell_index() != cell_index) + if (particles_to_remove[n_particles_removed]->particles_on_cell != + particles_on_cell) continue; - const unsigned int n_particles_in_cell = particles[cell_index].size(); + const unsigned int n_particles_in_cell = particles_on_cell->size(); unsigned int move_to = 0; for (unsigned int move_from = 0; move_from < n_particles_in_cell; ++move_from) { if (n_particles_removed != particles_to_remove.size() && - particles_to_remove[n_particles_removed] - ->cell->active_cell_index() == cell_index && + particles_to_remove[n_particles_removed]->particles_on_cell == + particles_on_cell && particles_to_remove[n_particles_removed] ->particle_index_within_cell == move_from) { @@ -405,12 +406,12 @@ namespace Particles } else { - particles[cell_index][move_to] = - std::move(particles[cell_index][move_from]); + (*particles_on_cell)[move_to] = + std::move((*particles_on_cell)[move_from]); ++move_to; } } - particles[cell_index].resize(move_to); + particles_on_cell->resize(move_to); } update_cached_numbers(); @@ -1251,13 +1252,13 @@ namespace Particles current_cell->active_cell_index(); particles[active_cell_index].push_back( - particles[out_particle->cell->active_cell_index()] - [out_particle->particle_index_within_cell]); + (*out_particle->particles_on_cell) + [out_particle->particle_index_within_cell]); // Avoid deallocating the memory of this particle - particles[out_particle->cell->active_cell_index()] - [out_particle->particle_index_within_cell] = - PropertyPool::invalid_handle; + (*out_particle->particles_on_cell) + [out_particle->particle_index_within_cell] = + PropertyPool::invalid_handle; } else { -- 2.39.5