Reference documentation for deal.II version GIT relicensing-437-g81ec864850 2024-04-19 07:30:02+00:00
\(\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// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2017 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_particles_particle_h
16#define dealii_particles_particle_h
17
18#include <deal.II/base/config.h>
19
21#include <deal.II/base/point.h>
22#include <deal.II/base/types.h>
23
25
26#include <boost/serialization/array.hpp>
27
28#include <cstdint>
29
31
36namespace Particles
37{
38 namespace internal
39 {
43 using LevelInd = std::pair<int, int>;
44 } // namespace internal
45
94 template <int dim, int spacedim = dim>
96 {
97 public:
102 Particle();
103
117 Particle(const Point<spacedim> &location,
118 const Point<dim> &reference_location,
119 const types::particle_index id);
120
128 Particle(const Particle<dim, spacedim> &particle);
129
154 Particle(const void *&begin_data,
156
161 Particle(Particle<dim, spacedim> &&particle) noexcept;
162
167 operator=(const Particle<dim, spacedim> &particle);
168
173 operator=(Particle<dim, spacedim> &&particle) noexcept;
174
181 ~Particle();
182
197 void *
198 write_particle_data_to_memory(void *data) const;
199
200
218 const void *
219 read_particle_data_from_memory(const void *data);
220
241 void
242 set_location(const Point<spacedim> &new_location);
243
249 const Point<spacedim> &
250 get_location() const;
251
274 get_location();
275
296 void
297 set_reference_location(const Point<dim> &new_reference_location);
298
302 const Point<dim> &
304
314 get_id() const;
315
344 void
345 set_id(const types::particle_index &new_id);
346
359 void
361
366 bool
367 has_properties() const;
368
389 void
390 set_properties(const ArrayView<const double> &new_properties);
391
404
412 get_properties() const;
413
419 std::size_t
421
427 template <class Archive>
428 void
429 save(Archive &ar, const unsigned int version) const;
430
440 template <class Archive>
441 void
442 load(Archive &ar, const unsigned int version);
443
447 void
449
450#ifdef DOXYGEN
456 template <class Archive>
457 void
458 serialize(Archive &archive, const unsigned int version);
459#else
460 // This macro defines the serialize() method that is compatible with
461 // the templated save() and load() method that have been implemented.
462 BOOST_SERIALIZATION_SPLIT_MEMBER()
463#endif
464
465 private:
471
477
482 };
483
484
485
486 /* ---------------------- inline and template functions ------------------ */
487
488 template <int dim, int spacedim>
489 template <class Archive>
490 inline void
491 Particle<dim, spacedim>::load(Archive &ar, const unsigned int)
492 {
493 unsigned int n_properties = 0;
494
495 Point<spacedim> location;
496 Point<dim> reference_location;
498 ar &location &reference_location &id &n_properties;
499
500 set_location(location);
501 set_reference_location(reference_location);
502 set_id(id);
503
504 if (n_properties > 0)
505 {
506 ArrayView<double> properties(get_properties());
507 Assert(
508 properties.size() == n_properties,
510 "This particle was serialized with " +
511 std::to_string(n_properties) +
512 " properties, but the new property handler provides space for " +
513 std::to_string(properties.size()) +
514 " properties. Deserializing a particle only works for matching property sizes."));
515
516 ar &boost::serialization::make_array(properties.data(), n_properties);
517 }
518 }
519
520
521
522 template <int dim, int spacedim>
523 template <class Archive>
524 inline void
525 Particle<dim, spacedim>::save(Archive &ar, const unsigned int) const
526 {
527 unsigned int n_properties = 0;
528 if ((property_pool != nullptr) &&
529 (property_pool_handle != PropertyPool<dim, spacedim>::invalid_handle))
530 n_properties = get_properties().size();
531
532 Point<spacedim> location = get_location();
533 Point<dim> reference_location = get_reference_location();
534 types::particle_index id = get_id();
535
536 ar &location &reference_location &id &n_properties;
537
538 if (n_properties > 0)
539 ar &boost::serialization::make_array(get_properties().data(),
540 n_properties);
541 }
542
543
544
545 template <int dim, int spacedim>
546 inline void
548 {
549 property_pool->set_location(property_pool_handle, new_loc);
550 }
551
552
553
554 template <int dim, int spacedim>
555 inline const Point<spacedim> &
557 {
558 return property_pool->get_location(property_pool_handle);
559 }
560
561
562
563 template <int dim, int spacedim>
564 inline Point<spacedim> &
566 {
567 return property_pool->get_location(property_pool_handle);
568 }
569
570
571
572 template <int dim, int spacedim>
573 inline void
575 {
576 property_pool->set_reference_location(property_pool_handle, new_loc);
577 }
578
579
580
581 template <int dim, int spacedim>
582 inline const Point<dim> &
584 {
585 return property_pool->get_reference_location(property_pool_handle);
586 }
587
588
589
590 template <int dim, int spacedim>
593 {
594 return property_pool->get_id(property_pool_handle);
595 }
596
597
598
599 template <int dim, int spacedim>
600 inline void
602 {
603 property_pool->set_id(property_pool_handle, new_id);
604 }
605
606
607
608 template <int dim, int spacedim>
609 inline void
611 PropertyPool<dim, spacedim> &new_property_pool)
612 {
613 // First, we do want to save any properties that may
614 // have previously been set, and copy them over to the memory allocated
615 // on the new pool.
616 //
617 // It is possible that a particle currently has no properties -- for
618 // example if it has been created without an associated property
619 // pool (i.e., uses the default global pool which does not store any
620 // properties) but that the new pool has properties. In that case,
621 // there is simply nothing to transfer -- but the register_particle()
622 // call here will make sure that the newly allocated properties are
623 // zero-initialized.
624 const typename PropertyPool<dim, spacedim>::Handle new_handle =
625 new_property_pool.register_particle();
626
627 const Point<spacedim> location = get_location();
628 const Point<dim> reference_location = get_reference_location();
629 const types::particle_index id = get_id();
630
631 if (/* old pool */ has_properties())
632 {
633 ArrayView<const double> old_properties = this->get_properties();
634 ArrayView<double> new_properties =
635 new_property_pool.get_properties(new_handle);
636 std::copy(old_properties.cbegin(),
637 old_properties.cend(),
638 new_properties.begin());
639 }
640
641 // Now release the old memory handle
642 property_pool->deregister_particle(property_pool_handle);
643
644
645 // Then set the pointer to the property pool we want to use. Also set the
646 // handle to any properties.
647 property_pool = &new_property_pool;
648 property_pool_handle = new_handle;
649
650 // Now also store the saved locations
651 set_location(location);
652 set_reference_location(reference_location);
653 set_id(id);
654 }
655
656
657
658 template <int dim, int spacedim>
661 {
662 if (has_properties() == false)
663 return {};
664 else
665 return property_pool->get_properties(property_pool_handle);
666 }
667
668
669
670 template <int dim, int spacedim>
671 inline bool
673 {
674 // Particles always have a property pool associated with them,
675 // but we can access properties only if there is a valid handle.
676 // The only way a particle can have no valid handle if it has
677 // been moved-from -- but that leaves an object in an invalid
678 // state, and so we can just assert that that can't be the case.
679 Assert((property_pool_handle !=
682 return (property_pool->n_properties_per_slot() > 0);
683 }
684
685} // namespace Particles
686
688
689
690namespace boost
691{
692 namespace geometry
693 {
694 namespace index
695 {
696 // Forward declaration of bgi::indexable
697 template <class T>
698 struct indexable;
699
703 template <int dim, int spacedim>
704 struct indexable<::Particles::Particle<dim, spacedim>>
705 {
710 using result_type = const ::Point<spacedim> &;
711
714 const ::Particles::Particle<dim, spacedim> &particle) const
715 {
716 return particle.get_location();
717 }
718 };
719
720 } // namespace index
721 } // namespace geometry
722} // namespace boost
723
724#endif
iterator begin() const
Definition array_view.h:702
const_iterator cend() const
Definition array_view.h:729
const_iterator cbegin() const
Definition array_view.h:720
value_type * data() const noexcept
Definition array_view.h:661
std::size_t size() const
Definition array_view.h:684
PropertyPool< dim, spacedim > * property_pool
Definition particle.h:476
void set_property_pool(PropertyPool< dim, spacedim > &property_pool)
Definition particle.h:610
const Point< dim > & get_reference_location() const
Definition particle.h:583
const Point< spacedim > & get_location() const
Definition particle.h:556
bool has_properties() const
Definition particle.h:672
static PropertyPool< dim, spacedim > global_property_pool
Definition particle.h:470
void set_reference_location(const Point< dim > &new_reference_location)
Definition particle.h:574
std::size_t serialized_size_in_bytes() const
Definition particle.cc:286
void save(Archive &ar, const unsigned int version) const
Definition particle.h:525
Particle< dim, spacedim > & operator=(const Particle< dim, spacedim > &particle)
Definition particle.cc:129
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:251
void * write_particle_data_to_memory(void *data) const
Definition particle.cc:218
types::particle_index get_id() const
Definition particle.h:592
ArrayView< double > get_properties()
Definition particle.cc:330
PropertyPool< dim, spacedim >::Handle property_pool_handle
Definition particle.h:481
void load(Archive &ar, const unsigned int version)
Definition particle.h:491
void set_id(const types::particle_index &new_id)
Definition particle.h:601
void serialize(Archive &archive, const unsigned int version)
void set_location(const Point< spacedim > &new_location)
Definition particle.h:547
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:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
std::pair< int, int > LevelInd
Definition particle.h:43
result_type operator()(const ::Particles::Particle< dim, spacedim > &particle) const
Definition particle.h:713