template <int dim, int spacedim>
void
PropertyPool<dim, spacedim>::sort_memory_slots(
- std::vector<std::vector<Handle>> &handles_to_sort)
+ const std::vector<Handle> &handles_to_sort)
{
std::vector<Point<spacedim>> sorted_locations;
std::vector<Point<dim>> sorted_reference_locations;
sorted_ids.reserve(ids.size());
sorted_properties.reserve(properties.size());
- Handle i = 0;
- for (auto &handles_in_cell : handles_to_sort)
- for (auto &handle : handles_in_cell)
- {
- Assert(handle != invalid_handle,
- ExcMessage(
- "Invalid handle detected during sorting particle memory."));
-
- sorted_locations.push_back(locations[handle]);
- sorted_reference_locations.push_back(reference_locations[handle]);
- sorted_ids.push_back(ids[handle]);
+ for (auto &handle : handles_to_sort)
+ {
+ Assert(handle != invalid_handle,
+ ExcMessage(
+ "Invalid handle detected during sorting particle memory."));
- for (unsigned int j = 0; j < n_properties; ++j)
- sorted_properties.push_back(properties[handle * n_properties + j]);
+ sorted_locations.push_back(locations[handle]);
+ sorted_reference_locations.push_back(reference_locations[handle]);
+ sorted_ids.push_back(ids[handle]);
- handle = i;
- ++i;
- }
+ for (unsigned int j = 0; j < n_properties; ++j)
+ sorted_properties.push_back(properties[handle * n_properties + j]);
+ }
Assert(sorted_locations.size() ==
locations.size() - currently_available_handles.size(),
"Number of sorted property handles is not equal to number "
"of currently registered handles."));
- locations.swap(sorted_locations);
- reference_locations.swap(sorted_reference_locations);
- ids.swap(sorted_ids);
- properties.swap(sorted_properties);
+ locations = std::move(sorted_locations);
+ reference_locations = std::move(sorted_reference_locations);
+ ids = std::move(sorted_ids);
+ properties = std::move(sorted_properties);
currently_available_handles.clear();
}
const unsigned int n_properties = 3;
Particles::PropertyPool<dim, spacedim> pool(n_properties);
- std::vector<
- std::vector<typename Particles::PropertyPool<dim, spacedim>::Handle>>
+ std::vector<typename Particles::PropertyPool<dim, spacedim>::Handle>
particle_handles;
- particle_handles.resize(2);
// Allocate some space in non-contigous locations
- particle_handles[1].push_back(pool.register_particle());
- particle_handles[0].push_back(pool.register_particle());
- particle_handles[1].push_back(pool.register_particle());
- particle_handles[0].push_back(pool.register_particle());
- particle_handles[1].push_back(pool.register_particle());
- particle_handles[0].push_back(pool.register_particle());
+ particle_handles.push_back(pool.register_particle());
+ particle_handles.insert(particle_handles.begin(), pool.register_particle());
+ particle_handles.push_back(pool.register_particle());
+ particle_handles.insert(particle_handles.begin(), pool.register_particle());
+ particle_handles.push_back(pool.register_particle());
+ particle_handles.insert(particle_handles.begin(), pool.register_particle());
unsigned int i = 0;
- for (auto &particles_in_cell : particle_handles)
- for (auto &particle : particles_in_cell)
- pool.set_id(particle, i++);
+ for (auto &particle : particle_handles)
+ pool.set_id(particle, i++);
- for (const auto &particles_in_cell : particle_handles)
- for (const auto &particle : particles_in_cell)
- deallog << "Before removal unsorted ID: " << pool.get_id(particle)
- << ". Handle: " << particle << std::endl;
+ for (const auto &particle : particle_handles)
+ deallog << "Before removal unsorted ID: " << pool.get_id(particle)
+ << ". Handle: " << particle << std::endl;
pool.sort_memory_slots(particle_handles);
- for (const auto &particles_in_cell : particle_handles)
- for (const auto &particle : particles_in_cell)
- deallog << "Before removal sorted ID: " << pool.get_id(particle)
- << ". Handle: " << particle << std::endl;
+ typename Particles::PropertyPool<dim, spacedim>::Handle h = 0;
+ for (auto &particle : particle_handles)
+ particle = h++;
+
+ for (const auto &particle : particle_handles)
+ deallog << "Before removal sorted ID: " << pool.get_id(particle)
+ << ". Handle: " << particle << std::endl;
// Deallocate some space in the same way the particle handler would
// remove particles
- pool.deregister_particle(particle_handles[1][1]);
- pool.deregister_particle(particle_handles[0][2]);
+ pool.deregister_particle(particle_handles[2]);
+ pool.deregister_particle(particle_handles[3]);
+
+ particle_handles[2] = particle_handles.back();
+ particle_handles.resize(particle_handles.size() - 1);
- particle_handles[1][1] = particle_handles[1].back();
- particle_handles[1].resize(particle_handles[1].size() - 1);
- particle_handles[0].resize(particle_handles[0].size() - 1);
+ particle_handles[3] = particle_handles.back();
+ particle_handles.resize(particle_handles.size() - 1);
- for (const auto &particles_in_cell : particle_handles)
- for (const auto &particle : particles_in_cell)
- deallog << "After removal unsorted ID: " << pool.get_id(particle)
- << ". Handle: " << particle << std::endl;
+ for (const auto &particle : particle_handles)
+ deallog << "After removal unsorted ID: " << pool.get_id(particle)
+ << ". Handle: " << particle << std::endl;
pool.sort_memory_slots(particle_handles);
- for (const auto &particles_in_cell : particle_handles)
- for (const auto &particle : particles_in_cell)
- deallog << "After removal sorted ID: " << pool.get_id(particle)
- << ". Handle: " << particle << std::endl;
+ h = 0;
+ for (auto &particle : particle_handles)
+ particle = h++;
+
+ for (const auto &particle : particle_handles)
+ deallog << "After removal sorted ID: " << pool.get_id(particle)
+ << ". Handle: " << particle << std::endl;
- for (auto &particles_in_cell : particle_handles)
- for (auto &particle : particles_in_cell)
- pool.deregister_particle(particle);
+ for (auto &particle : particle_handles)
+ pool.deregister_particle(particle);
}
deallog << "OK" << std::endl;