]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Update ParticleHandler::n_particles_in_cell(). 10320/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 22 May 2020 21:50:52 +0000 (15:50 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 22 May 2020 22:07:40 +0000 (16:07 -0600)
include/deal.II/particles/particle_handler.h
source/particles/particle_handler.cc

index 9d41fda592b162a382e05e9cee14bfae7eb599af..a6d008367f88eb286f2a8b4b15471e35de7210de 100644 (file)
@@ -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<dim, spacedim>::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<dim, spacedim>::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<dim, spacedim>::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
index 5a75bb99cd4922997c2f8d72e127039be6f4a2c1..5769885c821a69efdca61a962f23d5f063951f23 100644 (file)
@@ -296,6 +296,30 @@ namespace Particles
 
 
 
+  template <int dim, int spacedim>
+  unsigned int
+  ParticleHandler<dim, spacedim>::n_particles_in_cell(
+    const typename Triangulation<dim, spacedim>::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 <int dim, int spacedim>
   typename ParticleHandler<dim, spacedim>::particle_iterator_range
   ParticleHandler<dim, spacedim>::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 <int dim, int spacedim>
-  unsigned int
-  ParticleHandler<dim, spacedim>::n_particles_in_cell(
-    const typename Triangulation<dim, spacedim>::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 <int dim, int spacedim>
   types::particle_index
   ParticleHandler<dim, spacedim>::get_next_free_particle_index() const

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.