Reference documentation for deal.II version 9.4.1
\(\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\}}\)
Loading...
Searching...
No Matches
particle.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2017 - 2022 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 <boost/serialization/array.hpp>
28
29#include <cstdint>
30
32
37namespace Particles
38{
39 namespace internal
40 {
44 using LevelInd = std::pair<int, int>;
45 } // namespace internal
46
95 template <int dim, int spacedim = dim>
97 {
98 public:
103 Particle();
104
118 Particle(const Point<spacedim> & location,
119 const Point<dim> & reference_location,
120 const types::particle_index id);
121
129 Particle(const Particle<dim, spacedim> &particle);
130
155 Particle(const void *& begin_data,
157
162 Particle(Particle<dim, spacedim> &&particle) noexcept;
163
168 operator=(const Particle<dim, spacedim> &particle);
169
174 operator=(Particle<dim, spacedim> &&particle) noexcept;
175
182 ~Particle();
183
198 void *
199 write_particle_data_to_memory(void *data) const;
200
201
219 const void *
220 read_particle_data_from_memory(const void *data);
221
242 void
243 set_location(const Point<spacedim> &new_location);
244
250 const Point<spacedim> &
251 get_location() const;
252
273 void
274 set_reference_location(const Point<dim> &new_reference_location);
275
279 const Point<dim> &
281
291 get_id() const;
292
321 void
322 set_id(const types::particle_index &new_id);
323
336 void
338
343 bool
344 has_properties() const;
345
366 void
367 set_properties(const ArrayView<const double> &new_properties);
368
381
389 get_properties() const;
390
396 std::size_t
398
404 template <class Archive>
405 void
406 save(Archive &ar, const unsigned int version) const;
407
417 template <class Archive>
418 void
419 load(Archive &ar, const unsigned int version);
420
424 void
426
427#ifdef DOXYGEN
433 template <class Archive>
434 void
435 serialize(Archive &archive, const unsigned int version);
436#else
437 // This macro defines the serialize() method that is compatible with
438 // the templated save() and load() method that have been implemented.
439 BOOST_SERIALIZATION_SPLIT_MEMBER()
440#endif
441
442 private:
448
454
459 };
460
461
462
463 /* ---------------------- inline and template functions ------------------ */
464
465 template <int dim, int spacedim>
466 template <class Archive>
467 inline void
468 Particle<dim, spacedim>::load(Archive &ar, const unsigned int)
469 {
470 unsigned int n_properties = 0;
471
472 Point<spacedim> location;
473 Point<dim> reference_location;
475 ar &location &reference_location &id &n_properties;
476
477 set_location(location);
478 set_reference_location(reference_location);
479 set_id(id);
480
481 if (n_properties > 0)
482 {
483 ArrayView<double> properties(get_properties());
484 Assert(
485 properties.size() == n_properties,
487 "This particle was serialized with " +
488 std::to_string(n_properties) +
489 " properties, but the new property handler provides space for " +
490 std::to_string(properties.size()) +
491 " properties. Deserializing a particle only works for matching property sizes."));
492
493 ar &boost::serialization::make_array(properties.data(), n_properties);
494 }
495 }
496
497
498
499 template <int dim, int spacedim>
500 template <class Archive>
501 inline void
502 Particle<dim, spacedim>::save(Archive &ar, const unsigned int) const
503 {
504 unsigned int n_properties = 0;
505 if ((property_pool != nullptr) &&
506 (property_pool_handle != PropertyPool<dim, spacedim>::invalid_handle))
507 n_properties = get_properties().size();
508
509 Point<spacedim> location = get_location();
510 Point<dim> reference_location = get_reference_location();
511 types::particle_index id = get_id();
512
513 ar &location &reference_location &id &n_properties;
514
515 if (n_properties > 0)
516 ar &boost::serialization::make_array(get_properties().data(),
517 n_properties);
518 }
519
520
521
522 template <int dim, int spacedim>
523 inline void
525 {
526 property_pool->set_location(property_pool_handle, new_loc);
527 }
528
529
530
531 template <int dim, int spacedim>
532 inline const Point<spacedim> &
534 {
535 return property_pool->get_location(property_pool_handle);
536 }
537
538
539
540 template <int dim, int spacedim>
541 inline void
543 {
544 property_pool->set_reference_location(property_pool_handle, new_loc);
545 }
546
547
548
549 template <int dim, int spacedim>
550 inline const Point<dim> &
552 {
553 return property_pool->get_reference_location(property_pool_handle);
554 }
555
556
557
558 template <int dim, int spacedim>
561 {
562 return property_pool->get_id(property_pool_handle);
563 }
564
565
566
567 template <int dim, int spacedim>
568 inline void
570 {
571 property_pool->set_id(property_pool_handle, new_id);
572 }
573
574
575
576 template <int dim, int spacedim>
577 inline void
579 PropertyPool<dim, spacedim> &new_property_pool)
580 {
581 // First, we do want to save any properties that may
582 // have previously been set, and copy them over to the memory allocated
583 // on the new pool.
584 //
585 // It is possible that a particle currently has no properties -- for
586 // example if it has been created without an associated property
587 // pool (i.e., uses the default global pool which does not store any
588 // properties) but that the new pool has properties. In that case,
589 // there is simply nothing to transfer -- but the register_particle()
590 // call here will make sure that the newly allocated properties are
591 // zero-initialized.
592 const typename PropertyPool<dim, spacedim>::Handle new_handle =
593 new_property_pool.register_particle();
594
595 const Point<spacedim> location = get_location();
596 const Point<dim> reference_location = get_reference_location();
597 const types::particle_index id = get_id();
598
599 if (/* old pool */ has_properties())
600 {
601 ArrayView<const double> old_properties = this->get_properties();
602 ArrayView<double> new_properties =
603 new_property_pool.get_properties(new_handle);
604 std::copy(old_properties.cbegin(),
605 old_properties.cend(),
606 new_properties.begin());
607 }
608
609 // Now release the old memory handle
610 property_pool->deregister_particle(property_pool_handle);
611
612
613 // Then set the pointer to the property pool we want to use. Also set the
614 // handle to any properties.
615 property_pool = &new_property_pool;
616 property_pool_handle = new_handle;
617
618 // Now also store the saved locations
619 set_location(location);
620 set_reference_location(reference_location);
621 set_id(id);
622 }
623
624
625
626 template <int dim, int spacedim>
627 inline const ArrayView<const double>
629 {
630 if (has_properties() == false)
631 return {};
632 else
633 return property_pool->get_properties(property_pool_handle);
634 }
635
636
637
638 template <int dim, int spacedim>
639 inline bool
641 {
642 // Particles always have a property pool associated with them,
643 // but we can access properties only if there is a valid handle.
644 // The only way a particle can have no valid handle if it has
645 // been moved-from -- but that leaves an object in an invalid
646 // state, and so we can just assert that that can't be the case.
647 Assert((property_pool_handle !=
650 return (property_pool->n_properties_per_slot() > 0);
651 }
652
653} // namespace Particles
654
656
657
658namespace boost
659{
660 namespace geometry
661 {
662 namespace index
663 {
664 // Forward declaration of bgi::indexable
665 template <class T>
666 struct indexable;
667
671 template <int dim, int spacedim>
672 struct indexable<::Particles::Particle<dim, spacedim>>
673 {
678 using result_type = const ::Point<spacedim> &;
679
682 const ::Particles::Particle<dim, spacedim> &particle) const
683 {
684 return particle.get_location();
685 }
686 };
687
688 } // namespace index
689 } // namespace geometry
690} // namespace boost
691
692#endif
iterator begin() const
Definition: array_view.h:585
const_iterator cend() const
Definition: array_view.h:612
const_iterator cbegin() const
Definition: array_view.h:603
value_type * data() const noexcept
Definition: array_view.h:553
std::size_t size() const
Definition: array_view.h:576
PropertyPool< dim, spacedim > * property_pool
Definition: particle.h:453
void set_property_pool(PropertyPool< dim, spacedim > &property_pool)
Definition: particle.h:578
const Point< dim > & get_reference_location() const
Definition: particle.h:551
const Point< spacedim > & get_location() const
Definition: particle.h:533
bool has_properties() const
Definition: particle.h:640
static PropertyPool< dim, spacedim > global_property_pool
Definition: particle.h:447
void set_reference_location(const Point< dim > &new_reference_location)
Definition: particle.h:542
std::size_t serialized_size_in_bytes() const
Definition: particle.cc:287
void save(Archive &ar, const unsigned int version) const
Definition: particle.h:502
Particle< dim, spacedim > & operator=(const Particle< dim, spacedim > &particle)
Definition: particle.cc:130
const ArrayView< double > get_properties()
Definition: particle.cc:330
void set_properties(const ArrayView< const double > &new_properties)
Definition: particle.cc:305
const void * read_particle_data_from_memory(const void *data)
Definition: particle.cc:252
void * write_particle_data_to_memory(void *data) const
Definition: particle.cc:219
types::particle_index get_id() const
Definition: particle.h:560
PropertyPool< dim, spacedim >::Handle property_pool_handle
Definition: particle.h:458
void load(Archive &ar, const unsigned int version)
Definition: particle.h:468
void free_properties()
Definition: particle.cc:204
void set_id(const types::particle_index &new_id)
Definition: particle.h:569
void serialize(Archive &archive, const unsigned int version)
void set_location(const Point< spacedim > &new_location)
Definition: particle.h:524
const Point< spacedim > & get_location(const Handle handle) const
unsigned int n_properties_per_slot() const
ArrayView< double > get_properties(const Handle handle)
void deregister_particle(Handle &handle)
void set_id(const Handle handle, const types::particle_index &new_id)
types::particle_index get_id(const Handle handle) const
void set_reference_location(const Handle handle, const Point< dim > &new_reference_location)
void set_location(const Handle handle, const Point< spacedim > &new_location)
const Point< dim > & get_reference_location(const Handle handle) const
Definition: point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
#define Assert(cond, exc)
Definition: exceptions.h:1473
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
std::pair< int, int > LevelInd
Definition: particle.h:44
result_type operator()(const ::Particles::Particle< dim, spacedim > &particle) const
Definition: particle.h:681