Reference documentation for deal.II version 9.0.0
particle_handler.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_particles_particle_handler_h
17 #define dealii_particles_particle_handler_h
18 
19 #include <deal.II/particles/particle.h>
20 #include <deal.II/particles/particle_iterator.h>
21 #include <deal.II/particles/property_pool.h>
22 
23 #include <deal.II/distributed/tria.h>
24 #include <deal.II/base/subscriptor.h>
25 #include <deal.II/base/mpi.h>
26 #include <deal.II/base/array_view.h>
27 #include <deal.II/base/smartpointer.h>
28 #include <deal.II/fe/mapping.h>
29 
30 #include <boost/serialization/map.hpp>
31 #include <boost/range/iterator_range.hpp>
32 
33 DEAL_II_NAMESPACE_OPEN
34 
35 #ifdef DEAL_II_WITH_P4EST
36 
37 namespace Particles
38 {
51  template <int dim, int spacedim=dim>
52  class ParticleHandler: public Subscriptor
53  {
54  public:
59 
63  typedef boost::iterator_range<particle_iterator> particle_iterator_range;
64 
69 
80  const unsigned int n_properties = 0);
81 
86 
94  const unsigned int n_properties = 0);
95 
99  void clear();
100 
106  void clear_particles();
107 
116  void update_cached_numbers();
117 
121  particle_iterator begin() const;
122 
127 
131  particle_iterator end() const;
132 
137 
142 
147 
152 
157 
165 
166 
174 
178  void
179  remove_particle(const particle_iterator &particle);
180 
188  insert_particle(const Particle<dim,spacedim> &particle,
190 
196  void
199 
209  void
210  insert_particles(const std::vector<Point<spacedim> > &positions);
211 
238  void
239  register_additional_store_load_functions(const std::function<std::size_t ()> &size_callback,
240  const std::function<void *(const particle_iterator &,
241  void *)> &store_callback,
242  const std::function<const void *(const particle_iterator &,
243  const void *)> &load_callback);
244 
254 
262 
268 
275 
279  unsigned int n_properties_per_particle() const;
280 
285  PropertyPool &
286  get_property_pool() const;
287 
291  unsigned int
293 
302  void
304 
310  void
312 
318  void
319  register_store_callback_function(const bool serialization);
320 
326  void
327  register_load_callback_function(const bool serialization);
328 
332  template <class Archive>
333  void serialize (Archive &ar, const unsigned int version);
334 
335  private:
340 
345 
350  std::multimap<internal::LevelInd, Particle<dim,spacedim> > particles;
351 
357  std::multimap<internal::LevelInd, Particle<dim,spacedim> > ghost_particles;
358 
364 
374 
380 
385  std::unique_ptr<PropertyPool> property_pool;
386 
398  std::function<std::size_t ()> size_callback;
399 
410  std::function<void *(const particle_iterator &,
411  void *)> store_callback;
412 
423  std::function<const void *(const particle_iterator &,
424  const void *)> load_callback;
425 
431  unsigned int data_offset;
432 
433 #ifdef DEAL_II_WITH_MPI
434 
455  void
456  send_recv_particles(const std::map<types::subdomain_id, std::vector<particle_iterator> > &particles_to_send,
457  std::multimap<internal::LevelInd,Particle <dim,spacedim> > &received_particles,
458  const std::map<types::subdomain_id, std::vector<typename Triangulation<dim,spacedim>::active_cell_iterator> > &new_cells_for_particles =
459  std::map<types::subdomain_id, std::vector<typename Triangulation<dim,spacedim>::active_cell_iterator> > ());
460 #endif
461 
467  void
469  const typename Triangulation<dim,spacedim>::CellStatus status,
470  void *data) const;
471 
476  void
478  const typename Triangulation<dim,spacedim>::CellStatus status,
479  const void *data);
480  };
481 
482  /* -------------------------- inline and template functions ---------------------- */
483 
484  template <int dim, int spacedim>
485  template <class Archive>
486  void ParticleHandler<dim,spacedim>::serialize (Archive &ar, const unsigned int)
487  {
488  // Note that we do not serialize the particle data itself. Instead we
489  // use the serialization functionality of the triangulation class, because
490  // this guarantees that data is immediately shipped to new processes if
491  // the domain is distributed differently after resuming from a checkpoint.
492  ar //&particles
493  &global_number_of_particles
494  &global_max_particles_per_cell
495  &next_free_particle_index;
496  }
497 }
498 
499 #endif // DEAL_II_WITH_P4EST
500 
501 DEAL_II_NAMESPACE_CLOSE
502 
503 #endif
504 
types::particle_index n_global_particles() const
std::function< std::size_t()> size_callback
types::particle_index n_locally_owned_particles() const
unsigned int particle_index
Definition: particle.h:64
void remove_particle(const particle_iterator &particle)
void initialize(const parallel::distributed::Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping, const unsigned int n_properties=0)
types::particle_index n_global_max_particles_per_cell() const
std::function< const void *(const particle_iterator &, const void *)> load_callback
particle_iterator insert_particle(const Particle< dim, spacedim > &particle, const typename Triangulation< dim, spacedim >::active_cell_iterator &cell)
void send_recv_particles(const std::map< types::subdomain_id, std::vector< particle_iterator > > &particles_to_send, std::multimap< internal::LevelInd, Particle< dim, spacedim > > &received_particles, const std::map< types::subdomain_id, std::vector< typename Triangulation< dim, spacedim >::active_cell_iterator > > &new_cells_for_particles=std::map< types::subdomain_id, std::vector< typename Triangulation< dim, spacedim >::active_cell_iterator > >())
types::particle_index next_free_particle_index
unsigned int global_max_particles_per_cell
void register_load_callback_function(const bool serialization)
void store_particles(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status, void *data) const
std::multimap< internal::LevelInd, Particle< dim, spacedim > > particles
particle_iterator begin_ghost() const
unsigned int n_properties_per_particle() const
types::particle_index global_number_of_particles
particle_iterator_range particles_in_cell(const typename Triangulation< dim, spacedim >::active_cell_iterator &cell)
void insert_particles(const std::multimap< typename Triangulation< dim, spacedim >::active_cell_iterator, Particle< dim, spacedim > > &particles)
Abstract base class for mapping classes.
Definition: dof_tools.h:46
particle_iterator begin() const
unsigned int subdomain_id
Definition: types.h:42
ParticleIterator< dim, spacedim > particle_iterator
std::unique_ptr< PropertyPool > property_pool
SmartPointer< const Mapping< dim, spacedim >, ParticleHandler< dim, spacedim > > mapping
void load_particles(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status, const void *data)
types::particle_index get_next_free_particle_index() const
std::multimap< internal::LevelInd, Particle< dim, spacedim > > ghost_particles
void serialize(Archive &ar, const unsigned int version)
std::function< void *(const particle_iterator &, void *)> store_callback
PropertyPool & get_property_pool() const
void register_store_callback_function(const bool serialization)
SmartPointer< const parallel::distributed::Triangulation< dim, spacedim >, ParticleHandler< dim, spacedim > > triangulation
boost::iterator_range< particle_iterator > particle_iterator_range
particle_iterator end_ghost() const
particle_iterator end() const
void register_additional_store_load_functions(const std::function< std::size_t()> &size_callback, const std::function< void *(const particle_iterator &, void *)> &store_callback, const std::function< const void *(const particle_iterator &, const void *)> &load_callback)
unsigned int n_particles_in_cell(const typename Triangulation< dim, spacedim >::active_cell_iterator &cell) const