From e76985db8ef50f36cd9a0f9fb191edef85d683c9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 22 May 2020 15:50:52 -0600 Subject: [PATCH] Update ParticleHandler::n_particles_in_cell(). --- include/deal.II/particles/particle_handler.h | 23 +++++--- source/particles/particle_handler.cc | 62 ++++++++++++-------- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/include/deal.II/particles/particle_handler.h b/include/deal.II/particles/particle_handler.h index 9d41fda592..a6d008367f 100644 --- a/include/deal.II/particles/particle_handler.h +++ b/include/deal.II/particles/particle_handler.h @@ -175,20 +175,33 @@ namespace Particles particle_iterator end_ghost(); + /** + * Return the number of particles that live on the given cell. + */ + types::particle_index + n_particles_in_cell( + const typename Triangulation::active_cell_iterator &cell) + const; + /** * Return a pair of particle iterators that mark the begin and end of * the particles in a particular cell. The last iterator is the first * particle that is no longer in the cell. + * + * The number of elements in the returned range equals what the + * n_particles_in_cell() function returns. */ particle_iterator_range particles_in_cell( const typename Triangulation::active_cell_iterator &cell); - /** * Return a pair of particle iterators that mark the begin and end of * the particles in a particular cell. The last iterator is the first * particle that is no longer in the cell. + * + * The number of elements in the returned range equals what the + * n_particles_in_cell() function returns. */ particle_iterator_range particles_in_cell( @@ -552,14 +565,6 @@ namespace Particles PropertyPool & get_property_pool() const; - /** - * Return the number of particles in the given cell. - */ - unsigned int - n_particles_in_cell( - const typename Triangulation::active_cell_iterator &cell) - const; - /** * Find and update the cells containing each particle for all locally owned * particles. If particles moved out of the local subdomain diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 5a75bb99cd..5769885c82 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -296,6 +296,30 @@ namespace Particles + template + unsigned int + ParticleHandler::n_particles_in_cell( + const typename Triangulation::active_cell_iterator &cell) + const + { + const internal::LevelInd found_cell = + std::make_pair(cell->level(), cell->index()); + + if (cell->is_locally_owned()) + return particles.count(found_cell); + else if (cell->is_ghost()) + return ghost_particles.count(found_cell); + else + AssertThrow(false, + ExcMessage("You can't ask for the particles on an artificial " + "cell since we don't know what exists on these " + "kinds of cells.")); + + return numbers::invalid_unsigned_int; + } + + + template typename ParticleHandler::particle_iterator_range ParticleHandler::particles_in_cell( @@ -323,11 +347,20 @@ namespace Particles particle_iterator(ghost_particles, particles_in_cell.first), particle_iterator(ghost_particles, particles_in_cell.second)); } + else if (cell->is_locally_owned()) + { + const auto particles_in_cell = particles.equal_range(level_index); + return boost::make_iterator_range( + particle_iterator(particles, particles_in_cell.first), + particle_iterator(particles, particles_in_cell.second)); + } + else + AssertThrow(false, + ExcMessage("You can't ask for the particles on an artificial " + "cell since we don't know what exists on these " + "kinds of cells.")); - const auto particles_in_cell = particles.equal_range(level_index); - return boost::make_iterator_range( - particle_iterator(particles, particles_in_cell.first), - particle_iterator(particles, particles_in_cell.second)); + return {}; } @@ -686,27 +719,6 @@ namespace Particles - template - unsigned int - ParticleHandler::n_particles_in_cell( - const typename Triangulation::active_cell_iterator &cell) - const - { - const internal::LevelInd found_cell = - std::make_pair(cell->level(), cell->index()); - - if (cell->is_locally_owned()) - return particles.count(found_cell); - else if (cell->is_ghost()) - return ghost_particles.count(found_cell); - else if (cell->is_artificial()) - AssertThrow(false, ExcInternalError()); - - return 0; - } - - - template types::particle_index ParticleHandler::get_next_free_particle_index() const -- 2.39.5