Reference documentation for deal.II version Git f15f581df6 2020-07-10 15:30:09 -0400
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
particle.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2020 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_h
17 #define dealii_particles_particle_h
18 
19 #include <deal.II/base/config.h>
20 
22 #include <deal.II/base/point.h>
23 #include <deal.II/base/types.h>
24 
26 
27 #include <cstdint>
28 
30 
31 namespace types
32 {
33  /* Type definitions */
34 
35 #ifdef DEAL_II_WITH_64BIT_INDICES
36 
47  using particle_index = uint64_t;
48 
49 # ifdef DEAL_II_WITH_MPI
50 
54 # define DEAL_II_PARTICLE_INDEX_MPI_TYPE MPI_UINT64_T
55 # endif
56 
57 #else
58 
69  using particle_index = unsigned int;
70 
71 # ifdef DEAL_II_WITH_MPI
72 
76 # define DEAL_II_PARTICLE_INDEX_MPI_TYPE MPI_UNSIGNED
77 # endif
78 #endif
79 } // namespace types
80 
85 namespace Particles
86 {
87  namespace internal
88  {
92  using LevelInd = std::pair<int, int>;
93  } // namespace internal
94 
143  template <int dim, int spacedim = dim>
144  class Particle
145  {
146  public:
151  Particle();
152 
164  Particle(const Point<spacedim> & location,
165  const Point<dim> & reference_location,
166  const types::particle_index id);
167 
175  Particle(const Particle<dim, spacedim> &particle);
176 
193  Particle(const void *& begin_data,
194  PropertyPool *const property_pool = nullptr);
195 
200  Particle(Particle<dim, spacedim> &&particle) noexcept;
201 
206  operator=(const Particle<dim, spacedim> &particle);
207 
212  operator=(Particle<dim, spacedim> &&particle) noexcept;
213 
220  ~Particle();
221 
235  void
236  write_data(void *&data) const;
237 
255  void
256  set_location(const Point<spacedim> &new_location);
257 
263  const Point<spacedim> &
264  get_location() const;
265 
283  void
284  set_reference_location(const Point<dim> &new_reference_location);
285 
289  const Point<dim> &
290  get_reference_location() const;
291 
301  get_id() const;
302 
328  void
329  set_id(const types::particle_index &new_id);
330 
338  void
339  set_property_pool(PropertyPool &property_pool);
340 
345  bool
346  has_properties() const;
347 
365  void
366  set_properties(const ArrayView<const double> &new_properties);
367 
378  const ArrayView<double>
379  get_properties();
380 
388  get_properties() const;
389 
395  std::size_t
396  serialized_size_in_bytes() const;
397 
402  template <class Archive>
403  void
404  save(Archive &ar, const unsigned int version) const;
405 
410  template <class Archive>
411  void
412  load(Archive &ar, const unsigned int version);
413 
414 #ifdef DOXYGEN
415 
419  template <class Archive>
420  void
421  serialize(Archive &archive, const unsigned int version);
422 #else
423  // This macro defines the serialize() method that is compatible with
424  // the templated save() and load() method that have been implemented.
425  BOOST_SERIALIZATION_SPLIT_MEMBER()
426 #endif
427 
428  private:
433 
438 
443 
449 
454  };
455 
456  /* ---------------------- inline and template functions ------------------ */
457 
458  template <int dim, int spacedim>
459  template <class Archive>
460  void
461  Particle<dim, spacedim>::load(Archive &ar, const unsigned int)
462  {
463  unsigned int n_properties = 0;
464 
465  ar &location &reference_location &id &n_properties;
466 
467  if (n_properties > 0)
468  {
469  properties = new double[n_properties];
470  ar &boost::serialization::make_array(properties, n_properties);
471  }
472  }
473 
474  template <int dim, int spacedim>
475  template <class Archive>
476  void
477  Particle<dim, spacedim>::save(Archive &ar, const unsigned int) const
478  {
479  unsigned int n_properties = 0;
480  if ((property_pool != nullptr) &&
481  (properties != PropertyPool::invalid_handle))
482  n_properties = get_properties().size();
483 
484  ar &location &reference_location &id &n_properties;
485 
486  if (n_properties > 0)
487  ar &boost::serialization::make_array(properties, n_properties);
488  }
489 } // namespace Particles
490 
492 
493 
494 namespace boost
495 {
496  namespace geometry
497  {
498  namespace index
499  {
500  // Forward declaration of bgi::indexable
501  template <class T>
502  struct indexable;
503 
507  template <int dim, int spacedim>
508  struct indexable<::Particles::Particle<dim, spacedim>>
509  {
514  using result_type = const ::Point<spacedim> &;
515 
518  const ::Particles::Particle<dim, spacedim> &particle) const
519  {
520  return particle.get_location();
521  }
522  };
523 
524  } // namespace index
525  } // namespace geometry
526 } // namespace boost
527 
528 #endif
PropertyPool::Handle properties
Definition: particle.h:453
Point< spacedim > location
Definition: particle.h:432
types::particle_index id
Definition: particle.h:442
result_type operator()(const ::Particles::Particle< dim, spacedim > &particle) const
Definition: particle.h:517
std::pair< int, int > LevelInd
Definition: particle.h:92
unsigned int particle_index
Definition: particle.h:69
void write_data(const std::vector< Patch< dim, spacedim >> &patches, unsigned int n_data_sets, const bool double_precision, StreamType &out)
Definition: types.h:31
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
Point< dim > reference_location
Definition: particle.h:437
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
PropertyPool * property_pool
Definition: particle.h:448