Reference documentation for deal.II version Git 71593a1301 2019-07-19 12:10:10 -0400
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
particle_handler.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2019 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_particles_particle_handler_h
17 #define dealii_particles_particle_handler_h
18 
19 #include <deal.II/base/array_view.h>
20 #include <deal.II/base/mpi.h>
21 #include <deal.II/base/smartpointer.h>
22 #include <deal.II/base/subscriptor.h>
23 
24 #include <deal.II/distributed/tria.h>
25 
26 #include <deal.II/fe/mapping.h>
27 
28 #include <deal.II/particles/particle.h>
29 #include <deal.II/particles/particle_iterator.h>
30 #include <deal.II/particles/property_pool.h>
31 
32 #include <boost/range/iterator_range.hpp>
33 #include <boost/serialization/map.hpp>
34 
35 DEAL_II_NAMESPACE_OPEN
36 
37 #ifdef DEAL_II_WITH_P4EST
38 
39 namespace Particles
40 {
53  template <int dim, int spacedim = dim>
54  class ParticleHandler : public Subscriptor
55  {
56  public:
61 
65  using particle_iterator_range = boost::iterator_range<particle_iterator>;
66 
71 
83  const unsigned int n_properties = 0);
84 
88  virtual ~ParticleHandler() override = default;
89 
95  void
98  const unsigned int n_properties = 0);
99 
103  void
104  clear();
105 
111  void
112  clear_particles();
113 
122  void
124 
129  begin() const;
130 
135  begin();
136 
141  end() const;
142 
147  end();
148 
153  begin_ghost() const;
154 
159  begin_ghost();
160 
165  end_ghost() const;
166 
171  end_ghost();
172 
181 
182 
191  const;
192 
196  void
197  remove_particle(const particle_iterator &particle);
198 
207  const Particle<dim, spacedim> &particle,
209 
216  void
218  const std::multimap<
221 
231  void
232  insert_particles(const std::vector<Point<spacedim>> &positions);
233 
260  void
262  const std::function<std::size_t()> &size_callback,
263  const std::function<void *(const particle_iterator &, void *)>
265  const std::function<const void *(const particle_iterator &, const void *)>
266  &load_callback);
267 
277  n_global_particles() const;
278 
287 
294 
302 
306  unsigned int
308 
313  PropertyPool &
314  get_property_pool() const;
315 
319  unsigned int
322  const;
323 
332  void
334 
340  void
342 
348  void
350 
356  void
357  register_load_callback_function(const bool serialization);
358 
362  template <class Archive>
363  void
364  serialize(Archive &ar, const unsigned int version);
365 
366  private:
373 
379 
384  std::multimap<internal::LevelInd, Particle<dim, spacedim>> particles;
385 
391  std::multimap<internal::LevelInd, Particle<dim, spacedim>> ghost_particles;
392 
398 
408 
414 
419  std::unique_ptr<PropertyPool> property_pool;
420 
432  std::function<std::size_t()> size_callback;
433 
444  std::function<void *(const particle_iterator &, void *)> store_callback;
445 
456  std::function<const void *(const particle_iterator &, const void *)>
458 
465  unsigned int handle;
466 
467 # ifdef DEAL_II_WITH_MPI
468 
489  void
491  const std::map<types::subdomain_id, std::vector<particle_iterator>>
492  &particles_to_send,
493  std::multimap<internal::LevelInd, Particle<dim, spacedim>>
494  &received_particles,
495  const std::map<
497  std::vector<
499  &new_cells_for_particles = std::map<
501  std::vector<
503 # endif
504 
510  std::vector<char>
512  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
513  const typename Triangulation<dim, spacedim>::CellStatus status) const;
514 
519  void
521  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
522  const typename Triangulation<dim, spacedim>::CellStatus status,
523  const boost::iterator_range<std::vector<char>::const_iterator>
524  &data_range);
525  };
526 
527  /* ---------------------- inline and template functions ------------------ */
528 
529  template <int dim, int spacedim>
530  template <class Archive>
531  void
532  ParticleHandler<dim, spacedim>::serialize(Archive &ar, const unsigned int)
533  {
534  // Note that we do not serialize the particle data itself. Instead we
535  // use the serialization functionality of the triangulation class, because
536  // this guarantees that data is immediately shipped to new processes if
537  // the domain is distributed differently after resuming from a checkpoint.
538  ar //&particles
539  &global_number_of_particles &global_max_particles_per_cell
541  }
542 } // namespace Particles
543 
544 #endif // DEAL_II_WITH_P4EST
545 
546 DEAL_II_NAMESPACE_CLOSE
547 
548 #endif
std::multimap< internal::LevelInd, Particle< dim, spacedim > > ghost_particles
types::particle_index n_global_particles() const
types::particle_index n_locally_owned_particles() const
std::vector< char > store_particles(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status) const
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)
types::particle_index next_free_particle_index
SmartPointer< const parallel::distributed::Triangulation< dim, spacedim >, ParticleHandler< dim, spacedim > > triangulation
unsigned int global_max_particles_per_cell
virtual ~ParticleHandler() override=default
unsigned int particle_index
Definition: particle.h:64
void register_load_callback_function(const bool serialization)
unsigned int subdomain_id
Definition: types.h:43
void insert_particles(const std::multimap< typename Triangulation< dim, spacedim >::active_cell_iterator, 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)
std::function< std::size_t()> size_callback
Abstract base class for mapping classes.
Definition: dof_tools.h:57
particle_iterator begin() const
std::unique_ptr< PropertyPool > property_pool
types::particle_index get_next_free_particle_index() const
boost::iterator_range< particle_iterator > particle_iterator_range
void serialize(Archive &ar, const unsigned int version)
std::multimap< internal::LevelInd, Particle< dim, spacedim > > particles
std::function< void *(const particle_iterator &, void *)> store_callback
PropertyPool & get_property_pool() const
SmartPointer< const Mapping< dim, spacedim >, ParticleHandler< dim, spacedim > > mapping
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 >>())
void load_particles(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status, const boost::iterator_range< std::vector< char >::const_iterator > &data_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