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;
373 template <
class Archive>
375 save(Archive &ar,
const unsigned int version)
const;
386 template <
class Archive>
388 load(Archive &ar,
const unsigned int version);
396 template <
class Archive>
398 serialize(Archive &archive,
const unsigned int version);
402 BOOST_SERIALIZATION_SPLIT_MEMBER()
492 template <
int dim,
int spacedim>
493 template <
class Archive>
497 unsigned int n_properties = 0;
502 ar &location &reference_location &
id &n_properties;
504 set_location(location);
505 set_reference_location(reference_location);
508 if (n_properties > 0)
512 properties.
size() == n_properties,
514 "This particle was serialized with " +
515 std::to_string(n_properties) +
516 " properties, but the new property handler provides space for " +
517 std::to_string(properties.
size()) +
518 " properties. Deserializing a particle only works for matching property sizes."));
520 ar &boost::serialization::make_array(properties.
data(), n_properties);
526 template <
int dim,
int spacedim>
527 template <
class Archive>
531 unsigned int n_properties = 0;
532 if ((property_pool !=
nullptr) &&
534 n_properties = get_properties().size();
537 Point<dim> reference_location = get_reference_location();
540 ar &location &reference_location &
id &n_properties;
542 if (n_properties > 0)
543 ar &boost::serialization::make_array(get_properties().data(),
550 template <
int dim,
int spacedim>
553 , property_pool(nullptr)
554 , particle_index_within_cell(
numbers::invalid_unsigned_int)
559 template <
int dim,
int spacedim>
561 const typename particle_container::iterator particles_in_cell,
563 const unsigned int particle_index_within_cell)
564 : particles_in_cell(particles_in_cell)
565 , property_pool(const_cast<
PropertyPool<dim, spacedim> *>(&property_pool))
566 , particle_index_within_cell(particle_index_within_cell)
571 template <
int dim,
int spacedim>
581 const double *pdata =
reinterpret_cast<const double *
>(id_data);
584 for (
unsigned int i = 0; i < spacedim; ++i)
585 location[i] = *pdata++;
586 set_location(location);
589 for (
unsigned int i = 0; i < dim; ++i)
590 reference_location[i] = *pdata++;
591 set_reference_location(reference_location);
594 if (has_properties())
597 property_pool->get_properties(get_handle());
598 const unsigned int size = particle_properties.
size();
599 for (
unsigned int i = 0; i < size; ++i)
600 particle_properties[i] = *pdata++;
603 return static_cast<const void *
>(pdata);
608 template <
int dim,
int spacedim>
618 double *pdata =
reinterpret_cast<double *
>(id_data);
621 for (
unsigned int i = 0; i < spacedim; ++i, ++pdata)
622 *pdata = get_location()[i];
625 for (
unsigned int i = 0; i < dim; ++i, ++pdata)
626 *pdata = get_reference_location()[i];
629 if (has_properties())
632 property_pool->get_properties(get_handle());
633 for (
unsigned int i = 0; i < particle_properties.
size(); ++i, ++pdata)
634 *pdata = particle_properties[i];
637 return static_cast<void *
>(pdata);
642 template <
int dim,
int spacedim>
648 property_pool->set_location(get_handle(), new_loc);
653 template <
int dim,
int spacedim>
659 return property_pool->get_location(get_handle());
664 template <
int dim,
int spacedim>
670 return property_pool->get_location(get_handle());
675 template <
int dim,
int spacedim>
682 property_pool->set_reference_location(get_handle(), new_loc);
687 template <
int dim,
int spacedim>
693 return property_pool->get_reference_location(get_handle());
698 template <
int dim,
int spacedim>
704 return property_pool->get_id(get_handle());
709 template <
int dim,
int spacedim>
720 template <
int dim,
int spacedim>
726 property_pool->set_id(get_handle(), new_id);
731 template <
int dim,
int spacedim>
744 return (property_pool->n_properties_per_slot() > 0);
749 template <
int dim,
int spacedim>
752 const std::vector<double> &new_properties)
762 template <
int dim,
int spacedim>
770 property_pool->get_properties(get_handle());
774 "You are trying to assign properties with an incompatible length. "
775 "The particle has space to store " +
776 std::to_string(property_values.
size()) +
777 " properties, but you are trying to assign " +
778 std::to_string(new_properties.
size()) +
779 " properties. This is not allowed."));
781 if (property_values.
size() > 0)
782 std::copy(new_properties.
begin(),
783 new_properties.
end(),
784 property_values.
begin());
789 template <
int dim,
int spacedim>
800 for (
unsigned int d = 0; d < dim; ++d)
801 array[d] = new_properties[d];
808 template <
int dim,
int spacedim>
814 return property_pool->get_properties(get_handle());
819 template <
int dim,
int spacedim>
825 (void)new_property_pool;
830 template <
int dim,
int spacedim>
838 return particles_in_cell->cell;
843 template <
int dim,
int spacedim>
849 return property_pool->get_properties(get_handle());
854 template <
int dim,
int spacedim>
860 std::size_t size =
sizeof(get_id()) +
861 sizeof(
double) * spacedim +
862 sizeof(double) * dim;
864 if (has_properties())
866 size +=
sizeof(double) * get_properties().size();
873 template <
int dim,
int spacedim>
879 ++particle_index_within_cell;
881 if (particle_index_within_cell >= particles_in_cell->particles.size())
883 particle_index_within_cell = 0;
890 template <
int dim,
int spacedim>
896 if (particle_index_within_cell > 0)
897 --particle_index_within_cell;
901 particle_index_within_cell = particles_in_cell->particles.empty() ?
903 particles_in_cell->particles.size() - 1;
909 template <
int dim,
int spacedim>
914 return !(*
this == other);
919 template <
int dim,
int spacedim>
931 template <
int dim,
int spacedim>
935 if (property_pool !=
nullptr &&
937 particle_index_within_cell < particles_in_cell->particles.size())
939 else if (property_pool !=
nullptr &&
941 particle_index_within_cell == 0)
951 template <
int dim,
int spacedim>
955 return particles_in_cell->particles[particle_index_within_cell];
960 template <
int dim,
int spacedim>
964 return particles_in_cell->particles[particle_index_within_cell];
985 template <
int dim,
int spacedim>
995 operator()(const ::Particles::ParticleAccessor<dim, spacedim>
998 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)
void set_property_pool(PropertyPool< dim, spacedim > &property_pool)
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)
#define DEAL_II_DEPRECATED
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
@ 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