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;
385 template <
class Archive>
387 save(Archive &ar,
const unsigned int version)
const;
398 template <
class Archive>
400 load(Archive &ar,
const unsigned int version);
408 template <
class Archive>
410 serialize(Archive &archive,
const unsigned int version);
414 BOOST_SERIALIZATION_SPLIT_MEMBER()
504 template <
int dim,
int spacedim>
505 template <
class Archive>
509 unsigned int n_properties = 0;
514 ar &location &reference_location &
id &n_properties;
516 set_location(location);
517 set_reference_location(reference_location);
520 if (n_properties > 0)
524 properties.
size() == n_properties,
526 "This particle was serialized with " +
527 std::to_string(n_properties) +
528 " properties, but the new property handler provides space for " +
529 std::to_string(properties.
size()) +
530 " properties. Deserializing a particle only works for matching property sizes."));
532 ar &boost::serialization::make_array(properties.
data(), n_properties);
538 template <
int dim,
int spacedim>
539 template <
class Archive>
543 unsigned int n_properties = 0;
544 if ((property_pool !=
nullptr) &&
546 n_properties = get_properties().size();
549 Point<dim> reference_location = get_reference_location();
552 ar &location &reference_location &
id &n_properties;
554 if (n_properties > 0)
555 ar &boost::serialization::make_array(get_properties().data(),
562 template <
int dim,
int spacedim>
565 , property_pool(nullptr)
566 , particle_index_within_cell(
numbers::invalid_unsigned_int)
571 template <
int dim,
int spacedim>
573 const typename particle_container::iterator particles_in_cell,
575 const unsigned int particle_index_within_cell)
576 : particles_in_cell(particles_in_cell)
577 , property_pool(const_cast<
PropertyPool<dim, spacedim> *>(&property_pool))
578 , particle_index_within_cell(particle_index_within_cell)
583 template <
int dim,
int spacedim>
593 const double *pdata =
reinterpret_cast<const double *
>(id_data);
596 for (
unsigned int i = 0; i < spacedim; ++i)
597 location[i] = *pdata++;
598 set_location(location);
601 for (
unsigned int i = 0; i < dim; ++i)
602 reference_location[i] = *pdata++;
603 set_reference_location(reference_location);
606 if (has_properties())
609 property_pool->get_properties(get_handle());
610 const unsigned int size = particle_properties.
size();
611 for (
unsigned int i = 0; i < size; ++i)
612 particle_properties[i] = *pdata++;
615 return static_cast<const void *
>(pdata);
620 template <
int dim,
int spacedim>
630 double *pdata =
reinterpret_cast<double *
>(id_data);
633 for (
unsigned int i = 0; i < spacedim; ++i, ++pdata)
634 *pdata = get_location()[i];
637 for (
unsigned int i = 0; i < dim; ++i, ++pdata)
638 *pdata = get_reference_location()[i];
641 if (has_properties())
644 property_pool->get_properties(get_handle());
645 for (
unsigned int i = 0; i < particle_properties.
size(); ++i, ++pdata)
646 *pdata = particle_properties[i];
649 return static_cast<void *
>(pdata);
654 template <
int dim,
int spacedim>
660 property_pool->set_location(get_handle(), new_loc);
665 template <
int dim,
int spacedim>
671 return property_pool->get_location(get_handle());
676 template <
int dim,
int spacedim>
682 return property_pool->get_location(get_handle());
687 template <
int dim,
int spacedim>
694 property_pool->set_reference_location(get_handle(), new_loc);
699 template <
int dim,
int spacedim>
705 return property_pool->get_reference_location(get_handle());
710 template <
int dim,
int spacedim>
716 return property_pool->get_id(get_handle());
721 template <
int dim,
int spacedim>
732 template <
int dim,
int spacedim>
738 property_pool->set_id(get_handle(), new_id);
743 template <
int dim,
int spacedim>
756 return (property_pool->n_properties_per_slot() > 0);
761 template <
int dim,
int spacedim>
764 const std::vector<double> &new_properties)
774 template <
int dim,
int spacedim>
782 property_pool->get_properties(get_handle());
786 "You are trying to assign properties with an incompatible length. "
787 "The particle has space to store " +
788 std::to_string(property_values.
size()) +
789 " properties, but you are trying to assign " +
790 std::to_string(new_properties.
size()) +
791 " properties. This is not allowed."));
793 if (property_values.
size() > 0)
794 std::copy(new_properties.
begin(),
795 new_properties.
end(),
796 property_values.
begin());
801 template <
int dim,
int spacedim>
812 for (
unsigned int d = 0; d < dim; ++d)
813 array[d] = new_properties[d];
820 template <
int dim,
int spacedim>
826 return property_pool->get_properties(get_handle());
831 template <
int dim,
int spacedim>
837 (void)new_property_pool;
842 template <
int dim,
int spacedim>
850 return particles_in_cell->cell;
855 template <
int dim,
int spacedim>
864 return particles_in_cell->cell;
869 template <
int dim,
int spacedim>
875 return property_pool->get_properties(get_handle());
880 template <
int dim,
int spacedim>
886 std::size_t size =
sizeof(get_id()) +
887 sizeof(
double) * spacedim +
888 sizeof(double) * dim;
890 if (has_properties())
892 size +=
sizeof(double) * get_properties().size();
899 template <
int dim,
int spacedim>
905 ++particle_index_within_cell;
907 if (particle_index_within_cell >= particles_in_cell->particles.size())
909 particle_index_within_cell = 0;
916 template <
int dim,
int spacedim>
922 if (particle_index_within_cell > 0)
923 --particle_index_within_cell;
927 particle_index_within_cell = particles_in_cell->particles.empty() ?
929 particles_in_cell->particles.size() - 1;
935 template <
int dim,
int spacedim>
940 return !(*
this == other);
945 template <
int dim,
int spacedim>
957 template <
int dim,
int spacedim>
961 if (property_pool !=
nullptr &&
963 particle_index_within_cell < particles_in_cell->particles.size())
965 else if (property_pool !=
nullptr &&
967 particle_index_within_cell == 0)
977 template <
int dim,
int spacedim>
981 return particles_in_cell->particles[particle_index_within_cell];
986 template <
int dim,
int spacedim>
990 return particles_in_cell->particles[particle_index_within_cell];
1011 template <
int dim,
int spacedim>
1024 return accessor.get_location();
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
value_type * data() const noexcept
const Triangulation< dim, spacedim >::cell_iterator & get_surrounding_cell(const Triangulation< dim, spacedim > &triangulation) const
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.
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
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