/**
* Iterator to the end of the list elements of particle_container which
- * belong to locally owned elements.
+ * belong to locally owned elements. Made const to avoid accidental
+ * modification.
*/
- typename particle_container::iterator owned_particles_end;
+ const typename particle_container::iterator owned_particles_end;
/**
* List from the active cells on the present MPI process to positions in
const typename Triangulation<dim, spacedim>::CellStatus status,
const boost::iterator_range<std::vector<char>::const_iterator>
&data_range);
+
+ /**
+ * Internal function returning an iterator to the begin of the container
+ * for owned particles.
+ */
+ typename particle_container::iterator
+ particle_container_owned_begin() const;
+
+ /**
+ * Internal function returning an iterator to the end of the container for
+ * owned particles.
+ */
+ typename particle_container::iterator
+ particle_container_owned_end() const;
+
+ /**
+ * Internal function returning an iterator to the begin of the container
+ * for ghost particles.
+ */
+ typename particle_container::iterator
+ particle_container_ghost_begin() const;
+
+ /**
+ * Internal function returning an iterator to the end of the container for
+ * ghost particles.
+ */
+ typename particle_container::iterator
+ particle_container_ghost_end() const;
};
inline typename ParticleHandler<dim, spacedim>::particle_iterator
ParticleHandler<dim, spacedim>::begin()
{
- // We should always have at least the three anchor entries in the list of
- // particles
- Assert(!particles.empty(), ExcInternalError());
-
- // jump over the first entry which is used for book-keeping
- return particle_iterator(++particles.begin(), *property_pool, 0);
+ return particle_iterator(particle_container_owned_begin(),
+ *property_pool,
+ 0);
}
inline typename ParticleHandler<dim, spacedim>::particle_iterator
ParticleHandler<dim, spacedim>::end()
{
- return particle_iterator(owned_particles_end, *property_pool, 0);
+ return particle_iterator(particle_container_owned_end(), *property_pool, 0);
}
inline typename ParticleHandler<dim, spacedim>::particle_iterator
ParticleHandler<dim, spacedim>::begin_ghost()
{
- Assert(!particles.empty(), ExcInternalError());
- // find the start of ghost particles as one past the end of owned indices;
- // the index in between is used for book-keeping
- typename particle_container::iterator ghost_particles_begin =
- owned_particles_end;
- ++ghost_particles_begin;
- return particle_iterator(ghost_particles_begin, *property_pool, 0);
+ return particle_iterator(particle_container_ghost_begin(),
+ *property_pool,
+ 0);
}
inline typename ParticleHandler<dim, spacedim>::particle_iterator
ParticleHandler<dim, spacedim>::end_ghost()
{
- // skip the last entry which is used for book-keeping
- return particle_iterator(--particles.end(), *property_pool, 0);
+ return particle_iterator(particle_container_ghost_end(), *property_pool, 0);
+ }
+
+
+
+ template <int dim, int spacedim>
+ inline typename ParticleHandler<dim, spacedim>::particle_container::iterator
+ ParticleHandler<dim, spacedim>::particle_container_owned_begin() const
+ {
+ // We should always have at least the three anchor entries in the list of
+ // particles
+ Assert(!particles.empty(), ExcInternalError());
+ typename particle_container::iterator begin =
+ const_cast<particle_container &>(particles).begin();
+ return ++begin;
+ }
+
+
+
+ template <int dim, int spacedim>
+ inline typename ParticleHandler<dim, spacedim>::particle_container::iterator
+ ParticleHandler<dim, spacedim>::particle_container_owned_end() const
+ {
+ Assert(!particles.empty(), ExcInternalError());
+ return owned_particles_end;
+ }
+
+
+
+ template <int dim, int spacedim>
+ inline typename ParticleHandler<dim, spacedim>::particle_container::iterator
+ ParticleHandler<dim, spacedim>::particle_container_ghost_begin() const
+ {
+ Assert(!particles.empty(), ExcInternalError());
+ typename particle_container::iterator begin = owned_particles_end;
+ return ++begin;
+ }
+
+
+
+ template <int dim, int spacedim>
+ inline typename ParticleHandler<dim, spacedim>::particle_container::iterator
+ ParticleHandler<dim, spacedim>::particle_container_ghost_end() const
+ {
+ Assert(!particles.empty(), ExcInternalError());
+ typename particle_container::iterator end =
+ const_cast<particle_container &>(particles).end();
+ return --end;
}
global_max_particles_per_cell =
particle_handler.global_max_particles_per_cell;
next_free_particle_index = particle_handler.next_free_particle_index;
- particles = particle_handler.particles;
- owned_particles_end = particles.begin();
- for (auto it = particle_handler.particles.begin();
- it != particle_handler.owned_particles_end;
- ++it)
- ++owned_particles_end;
+
+ // Manually copy over the particles because we do not want to touch the
+ // anchor iterators set by initialize()
+ particles.insert(particle_container_owned_end(),
+ particle_handler.particle_container_owned_begin(),
+ particle_handler.particle_container_owned_end());
+ particles.insert(particle_container_ghost_end(),
+ particle_handler.particle_container_ghost_begin(),
+ particle_handler.particle_container_ghost_end());
for (auto it = particles.begin(); it != particles.end(); ++it)
if (!it->particles.empty())
const Triangulation<dim, spacedim> *triangulation,
particle_container & given_particles)
{
- TriaActiveIterator<CellAccessor<dim, spacedim>> past_the_end_iterator(
- triangulation, -1, -1);
given_particles.clear();
for (unsigned int i = 0; i < 3; ++i)
given_particles.emplace_back(
std::vector<typename PropertyPool<dim, spacedim>::Handle>(),
- past_the_end_iterator);
+ triangulation->end());
// Set the end of owned particles to the middle of the three elements
- owned_particles_end = ++given_particles.begin();
+ const_cast<typename particle_container::iterator &>(owned_particles_end) =
+ ++given_particles.begin();
}
+
template <int dim, int spacedim>
void
ParticleHandler<dim, spacedim>::update_cached_numbers()
// first sort the owned particles by the active cell index
bool sort_is_necessary = false;
{
- auto previous = ++particles.begin();
- for (auto next = previous; next != owned_particles_end; ++next)
+ auto previous = particle_container_owned_begin();
+ for (auto next = previous; next != particle_container_owned_end(); ++next)
{
if (previous->cell.state() == IteratorState::valid &&
next->cell.state() == IteratorState::valid &&
if (cells_to_particle_cache[cell->active_cell_index()] !=
particles.end())
{
- // observe that owned_particles_end was already set to point
- // into the new sorted_particles array
typename particle_container::iterator insert_position =
- cell->is_locally_owned() ? owned_particles_end :
- --sorted_particles.end();
+ cell->is_locally_owned() ? particle_container_owned_end() :
+ particle_container_ghost_end();
typename particle_container::iterator new_entry =
sorted_particles.insert(
insert_position, typename particle_container::value_type());
// check that we only have locally owned particles in the first region of
// cells; note that we skip the very first anchor element
- for (auto it = ++particles.begin(); it != owned_particles_end; ++it)
+ for (auto it = particle_container_owned_begin();
+ it != particle_container_owned_end();
+ ++it)
Assert(it->cell->is_locally_owned(), ExcInternalError());
// check that the cache is consistent with the iterators
if (cache == particles.end())
{
const typename particle_container::iterator insert_position =
- cell->is_locally_owned() ? owned_particles_end : --particles.end();
+ cell->is_locally_owned() ? particle_container_owned_end() :
+ particle_container_ghost_end();
cache = particles.emplace(
insert_position,
std::vector<typename PropertyPool<dim, spacedim>::Handle>{handle},