15#ifndef dealii_particles_particle_accessor_h
16#define dealii_particles_particle_accessor_h
35 class ParticleIterator;
37 class ParticleHandler;
43 template <
int dim,
int spacedim = dim>
101 std::vector<typename PropertyPool<dim, spacedim>::Handle>
particles;
372 template <
class Archive>
374 save(Archive &ar,
const unsigned int version)
const;
381 template <
class Archive>
383 load(Archive &ar,
const unsigned int version);
391 template <
class Archive>
393 serialize(Archive &archive,
const unsigned int version);
397 BOOST_SERIALIZATION_SPLIT_MEMBER()
487 template <
int dim,
int spacedim>
488 template <
class Archive>
492 unsigned int n_properties = 0;
497 ar &location &reference_location &
id &n_properties;
499 set_location(location);
500 set_reference_location(reference_location);
503 if (n_properties > 0)
507 properties.
size() == n_properties,
509 "This particle was serialized with " +
510 std::to_string(n_properties) +
511 " properties, but the new property handler provides space for " +
512 std::to_string(properties.
size()) +
513 " properties. Deserializing a particle only works for matching property sizes."));
515 ar &boost::serialization::make_array(properties.
data(), n_properties);
521 template <
int dim,
int spacedim>
522 template <
class Archive>
526 unsigned int n_properties = 0;
527 if ((property_pool !=
nullptr) &&
529 n_properties = get_properties().size();
532 Point<dim> reference_location = get_reference_location();
535 ar &location &reference_location &
id &n_properties;
537 if (n_properties > 0)
538 ar &boost::serialization::make_array(get_properties().
data(),
545 template <
int dim,
int spacedim>
548 , property_pool(nullptr)
549 , particle_index_within_cell(
numbers::invalid_unsigned_int)
554 template <
int dim,
int spacedim>
556 const typename particle_container::iterator particles_in_cell,
558 const unsigned int particle_index_within_cell)
559 : particles_in_cell(particles_in_cell)
560 , property_pool(const_cast<
PropertyPool<dim, spacedim> *>(&property_pool))
561 , particle_index_within_cell(particle_index_within_cell)
566 template <
int dim,
int spacedim>
576 const double *pdata =
reinterpret_cast<const double *
>(id_data);
579 for (
unsigned int i = 0; i < spacedim; ++i)
580 location[i] = *pdata++;
581 set_location(location);
584 for (
unsigned int i = 0; i < dim; ++i)
585 reference_location[i] = *pdata++;
586 set_reference_location(reference_location);
589 if (has_properties())
592 property_pool->get_properties(get_handle());
593 const unsigned int size = particle_properties.
size();
594 for (
unsigned int i = 0; i <
size; ++i)
595 particle_properties[i] = *pdata++;
598 return static_cast<const void *
>(pdata);
603 template <
int dim,
int spacedim>
613 double *pdata =
reinterpret_cast<double *
>(id_data);
616 for (
unsigned int i = 0; i < spacedim; ++i, ++pdata)
617 *pdata = get_location()[i];
620 for (
unsigned int i = 0; i < dim; ++i, ++pdata)
621 *pdata = get_reference_location()[i];
624 if (has_properties())
627 property_pool->get_properties(get_handle());
628 for (
unsigned int i = 0; i < particle_properties.
size(); ++i, ++pdata)
629 *pdata = particle_properties[i];
632 return static_cast<void *
>(pdata);
637 template <
int dim,
int spacedim>
643 property_pool->set_location(get_handle(), new_loc);
648 template <
int dim,
int spacedim>
654 return property_pool->get_location(get_handle());
659 template <
int dim,
int spacedim>
665 return property_pool->get_location(get_handle());
670 template <
int dim,
int spacedim>
677 property_pool->set_reference_location(get_handle(), new_loc);
682 template <
int dim,
int spacedim>
688 return property_pool->get_reference_location(get_handle());
693 template <
int dim,
int spacedim>
699 return property_pool->get_id(get_handle());
704 template <
int dim,
int spacedim>
715 template <
int dim,
int spacedim>
721 property_pool->set_id(get_handle(), new_id);
726 template <
int dim,
int spacedim>
739 return (property_pool->n_properties_per_slot() > 0);
744 template <
int dim,
int spacedim>
747 const std::vector<double> &new_properties)
757 template <
int dim,
int spacedim>
765 property_pool->get_properties(get_handle());
769 "You are trying to assign properties with an incompatible length. "
770 "The particle has space to store " +
771 std::to_string(property_values.
size()) +
772 " properties, but you are trying to assign " +
773 std::to_string(new_properties.
size()) +
774 " properties. This is not allowed."));
776 if (property_values.
size() > 0)
777 std::copy(new_properties.
begin(),
778 new_properties.
end(),
779 property_values.
begin());
784 template <
int dim,
int spacedim>
795 for (
unsigned int d = 0; d < dim; ++d)
796 array[d] = new_properties[d];
803 template <
int dim,
int spacedim>
809 return property_pool->get_properties(get_handle());
814 template <
int dim,
int spacedim>
822 return particles_in_cell->cell;
833 template <
int dim,
int spacedim>
839 std::size_t
size =
sizeof(get_id()) +
840 sizeof(
double) * spacedim +
841 sizeof(double) * dim;
843 if (has_properties())
845 size +=
sizeof(double) * get_properties().size();
852 template <
int dim,
int spacedim>
858 ++particle_index_within_cell;
860 if (particle_index_within_cell >= particles_in_cell->particles.size())
862 particle_index_within_cell = 0;
869 template <
int dim,
int spacedim>
875 if (particle_index_within_cell > 0)
876 --particle_index_within_cell;
880 particle_index_within_cell = particles_in_cell->particles.empty() ?
882 particles_in_cell->particles.size() - 1;
888 template <
int dim,
int spacedim>
893 return !(*
this == other);
898 template <
int dim,
int spacedim>
910 template <
int dim,
int spacedim>
914 if (property_pool !=
nullptr &&
916 particle_index_within_cell < particles_in_cell->particles.size())
918 else if (property_pool !=
nullptr &&
920 particle_index_within_cell == 0)
930 template <
int dim,
int spacedim>
934 return particles_in_cell->particles[particle_index_within_cell];
939 template <
int dim,
int spacedim>
943 return particles_in_cell->particles[particle_index_within_cell];
964 template <
int dim,
int spacedim>
974 operator()(const ::Particles::ParticleAccessor<dim, spacedim>
977 return accessor.get_location();
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
value_type * data() const noexcept
particle_container::iterator particles_in_cell
const Point< spacedim > & get_location() const
types::particle_index get_id() const
void save(Archive &ar, const unsigned int version) const
unsigned int particle_index_within_cell
types::particle_index get_local_index() const
std::list< ParticlesInCell > particle_container
const void * read_particle_data_from_memory(const void *data)
void load(Archive &ar, const unsigned int version)
const Triangulation< dim, spacedim >::cell_iterator & get_surrounding_cell() const
IteratorState::IteratorStates state() const
bool operator!=(const ParticleAccessor< dim, spacedim > &other) const
void set_properties(const Tensor< 1, dim > &new_properties)
void set_location(const Point< spacedim > &new_location)
PropertyPool< dim, spacedim >::Handle & get_handle()
void serialize(Archive &archive, const unsigned int version)
ArrayView< double > get_properties()
void set_reference_location(const Point< dim > &new_reference_location)
const Point< dim > & get_reference_location() const
std::size_t serialized_size_in_bytes() const
const PropertyPool< dim, spacedim >::Handle & get_handle() const
void set_properties(const std::vector< double > &new_properties)
Point< spacedim > & get_location()
ParticleAccessor(const typename particle_container::iterator particles_in_cell, const PropertyPool< dim, spacedim > &property_pool, const unsigned int particle_index_within_cell)
bool has_properties() const
PropertyPool< dim, spacedim > * property_pool
void * write_particle_data_to_memory(void *data) const
void set_properties(const ArrayView< const double > &new_properties)
ArrayView< const double > get_properties() const
bool operator==(const ParticleAccessor< dim, spacedim > &other) const
void set_id(const types::particle_index &new_id)
ArrayView< double, ::MemorySpace::Host > get_properties(const Handle handle)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< index_type > data
@ past_the_end
Iterator reached end of container.
@ valid
Iterator points to a valid object.
@ invalid
Iterator is invalid, probably due to an error.
Triangulation< dim, spacedim >::active_cell_iterator cell
ParticlesInCell()=default
ParticlesInCell(const std::vector< typename PropertyPool< dim, spacedim >::Handle > &particles, const typename Triangulation< dim, spacedim >::active_cell_iterator &cell)
std::vector< typename PropertyPool< dim, spacedim >::Handle > particles
result_type operator()(const ::Particles::ParticleAccessor< dim, spacedim > &accessor) const