Reference documentation for deal.II version Git a0b41b6d0f 2020-02-26 20:08:13 -0600
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
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/config.h>
20 
21 #include <deal.II/base/array_view.h>
22 #include <deal.II/base/bounding_box.h>
23 #include <deal.II/base/function.h>
24 #include <deal.II/base/mpi.h>
25 #include <deal.II/base/smartpointer.h>
26 #include <deal.II/base/subscriptor.h>
27 
28 #include <deal.II/distributed/tria.h>
29 
30 #include <deal.II/fe/mapping.h>
31 
32 #include <deal.II/particles/particle.h>
33 #include <deal.II/particles/particle_iterator.h>
34 #include <deal.II/particles/property_pool.h>
35 
36 #include <boost/range/iterator_range.hpp>
37 #include <boost/serialization/map.hpp>
38 
39 DEAL_II_NAMESPACE_OPEN
40 
41 namespace Particles
42 {
55  template <int dim, int spacedim = dim>
56  class ParticleHandler : public Subscriptor
57  {
58  public:
63 
67  using particle_iterator_range = boost::iterator_range<particle_iterator>;
68 
73 
84  const unsigned int n_properties = 0);
85 
89  virtual ~ParticleHandler() override = default;
90 
96  void
99  const unsigned int n_properties = 0);
100 
104  void
105  clear();
106 
112  void
113  clear_particles();
114 
123  void
125 
130  begin() const;
131 
136  begin();
137 
142  end() const;
143 
148  end();
149 
154  begin_ghost() const;
155 
160  begin_ghost();
161 
166  end_ghost() const;
167 
172  end_ghost();
173 
182 
183 
192  const;
193 
197  void
198  remove_particle(const particle_iterator &particle);
199 
208  const Particle<dim, spacedim> &particle,
210 
217  void
219  const std::multimap<
222 
232  void
233  insert_particles(const std::vector<Point<spacedim>> &positions);
234 
282  std::map<unsigned int, IndexSet>
284  const std::vector<Point<spacedim>> &positions,
285  const std::vector<std::vector<BoundingBox<spacedim>>>
286  & global_bounding_boxes,
287  const std::vector<std::vector<double>> &properties = {});
288 
334  template <class VectorType>
335  void
336  set_particle_positions(const VectorType &input_vector,
337  const bool displace_particles = true);
338 
361  void
362  set_particle_positions(const std::vector<Point<spacedim>> &new_positions,
363  const bool displace_particles = true);
364 
365 
386  void
388  const bool displace_particles = true);
389 
419  template <class VectorType>
420  void
421  get_particle_positions(VectorType &output_vector,
422  const bool add_to_output_vector = false);
423 
441  void
442  get_particle_positions(std::vector<Point<spacedim>> &positions,
443  const bool add_to_output_vector = false);
444 
471  void
473  const std::function<std::size_t()> &size_callback,
474  const std::function<void *(const particle_iterator &, void *)>
476  const std::function<const void *(const particle_iterator &, const void *)>
477  &load_callback);
478 
488  n_global_particles() const;
489 
498 
505 
513 
532  IndexSet
533  locally_relevant_ids() const;
534 
538  unsigned int
540 
545  PropertyPool &
546  get_property_pool() const;
547 
551  unsigned int
554  const;
555 
564  void
566 
572  void
574 
580  void
582 
588  void
589  register_load_callback_function(const bool serialization);
590 
594  template <class Archive>
595  void
596  serialize(Archive &ar, const unsigned int version);
597 
598  private:
605 
611 
616  std::multimap<internal::LevelInd, Particle<dim, spacedim>> particles;
617 
623  std::multimap<internal::LevelInd, Particle<dim, spacedim>> ghost_particles;
624 
630 
640 
646 
651  std::unique_ptr<PropertyPool> property_pool;
652 
664  std::function<std::size_t()> size_callback;
665 
676  std::function<void *(const particle_iterator &, void *)> store_callback;
677 
688  std::function<const void *(const particle_iterator &, const void *)>
690 
697  unsigned int handle;
698 
699 #ifdef DEAL_II_WITH_MPI
700 
721  void
723  const std::map<types::subdomain_id, std::vector<particle_iterator>>
724  &particles_to_send,
725  std::multimap<internal::LevelInd, Particle<dim, spacedim>>
726  &received_particles,
727  const std::map<
729  std::vector<
731  &new_cells_for_particles = std::map<
733  std::vector<
735 #endif
736 
742  std::vector<char>
744  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
745  const typename Triangulation<dim, spacedim>::CellStatus status) const;
746 
751  void
753  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
754  const typename Triangulation<dim, spacedim>::CellStatus status,
755  const boost::iterator_range<std::vector<char>::const_iterator>
756  &data_range);
757  };
758 
759 
760 
761  /* ---------------------- inline and template functions ------------------
762  */
763 
764 
765 
766  template <int dim, int spacedim>
767  template <class Archive>
768  void
769  ParticleHandler<dim, spacedim>::serialize(Archive &ar, const unsigned int)
770  {
771  // Note that we do not serialize the particle data itself. Instead we
772  // use the serialization functionality of the triangulation class, because
773  // this guarantees that data is immediately shipped to new processes if
774  // the domain is distributed differently after resuming from a checkpoint.
775  ar //&particles
776  &global_number_of_particles &global_max_particles_per_cell
778  }
779 
780 
781 
782  template <int dim, int spacedim>
783  template <class VectorType>
784  void
786  const VectorType &input_vector,
787  const bool displace_particles)
788  {
789  AssertDimension(input_vector.size(),
790  get_next_free_particle_index() * spacedim);
791  for (auto &p : *this)
792  {
793  auto new_point(displace_particles ? p.get_location() :
794  Point<spacedim>());
795  const auto id = p.get_id();
796  for (unsigned int i = 0; i < spacedim; ++i)
797  new_point[i] += input_vector[id * spacedim + i];
798  p.set_location(new_point);
799  }
801  }
802 
803 
804 
805  template <int dim, int spacedim>
806  template <class VectorType>
807  void
809  VectorType &output_vector,
810  const bool add_to_output_vector)
811  {
812  AssertDimension(output_vector.size(),
813  get_next_free_particle_index() * spacedim);
814  for (const auto &p : *this)
815  {
816  auto point = p.get_location();
817  const auto id = p.get_id();
818  if (add_to_output_vector)
819  for (unsigned int i = 0; i < spacedim; ++i)
820  output_vector[id * spacedim + i] += point[i];
821  else
822  for (unsigned int i = 0; i < spacedim; ++i)
823  output_vector[id * spacedim + i] = point[i];
824  }
825  if (add_to_output_vector)
826  output_vector.compress(VectorOperation::add);
827  else
828  output_vector.compress(VectorOperation::insert);
829  }
830 
831 } // namespace Particles
832 
833 DEAL_II_NAMESPACE_CLOSE
834 
835 #endif
std::multimap< internal::LevelInd, Particle< dim, spacedim > > ghost_particles
types::particle_index n_global_particles() const
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1571
types::particle_index n_locally_owned_particles() const
void get_particle_positions(VectorType &output_vector, const bool add_to_output_vector=false)
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)
IndexSet locally_relevant_ids() const
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 Triangulation< dim, spacedim >, ParticleHandler< dim, spacedim > > triangulation
unsigned int global_max_particles_per_cell
void initialize(const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping, const unsigned int n_properties=0)
virtual ~ParticleHandler() override=default
unsigned int particle_index
Definition: particle.h:66
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: mapping.h:302
particle_iterator begin() const
void set_particle_positions(const VectorType &input_vector, const bool displace_particles=true)
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
std::map< unsigned int, IndexSet > insert_global_particles(const std::vector< Point< spacedim >> &positions, const std::vector< std::vector< BoundingBox< spacedim >>> &global_bounding_boxes, const std::vector< std::vector< double >> &properties={})
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