* class then de-serializes its data from this memory location and
* advance the pointer accordingly.
*
- * @param[in,out] new_property_pool A property pool that is used to
- * allocate the property data used by this particle.
+ * @param[in,out] property_pool An optional pointer to a property pool
+ * that is used to manage the property data used by this particle. Note that
+ * if a non-null pointer is handed over this constructor assumes @p begin_data
+ * contains serialized data of the same length and type that is allocated
+ * by @p property_pool.
*/
Particle (const void *&begin_data,
- PropertyPool<PropertyType> &new_property_pool);
+ PropertyPool<PropertyType> *property_pool = NULL);
/**
* Move constructor for Particle, creates a particle from an existing
* point to the first element in which the data should be written. This
* function is meant for serializing all particle properties and
* afterwards de-serializing the properties by calling the appropriate
- * constructor Particle(void *&data, const unsigned int data_size);
+ * constructor Particle(void *&data, PropertyPool<PropertyType> *property_pool = NULL);
*
* @param [in,out] data The memory location to write particle data
* into. This pointer points to the begin of the memory, in which the
void
write_data(void *&data) const;
+ /**
+ * Returns the size in bytes this particle occupies if all of its data is
+ * serialized (i.e. the number of bytes that is written by the write_data
+ * function of this class).
+ */
+ std::size_t
+ size() const;
+
/**
* Set the location of this particle. Note that this does not check
* whether this is a valid location in the simulation domain.
template <int dim, int spacedim, typename PropertyType>
Particle<dim,spacedim,PropertyType>::Particle (const void *&data,
- PropertyPool<PropertyType> &new_property_pool)
+ PropertyPool<PropertyType> *new_property_pool)
{
const types::particle_index *id_data = static_cast<const types::particle_index *> (data);
id = *id_data++;
for (unsigned int i = 0; i < dim; ++i)
reference_location(i) = *pdata++;
- property_pool = &new_property_pool;
- properties = property_pool->allocate_properties_array();
+ data = static_cast<const void *> (pdata);
- // TODO reinterpret cast pdata to PropertyType
// See if there are properties to load
- const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
- for (unsigned int i = 0; i < particle_properties.size(); ++i)
- particle_properties[i] = *pdata++;
+ if (new_property_pool != NULL)
+ {
+ property_pool = new_property_pool;
+ properties = property_pool->allocate_properties_array();
- data = static_cast<const void *> (pdata);
+ const PropertyType *property_data = static_cast<const PropertyType *> (data);
+
+ const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
+ for (unsigned int i = 0; i < particle_properties.size(); ++i)
+ particle_properties[i] = *property_data++;
+
+ data = static_cast<const void *> (property_data);
+ }
}
for (unsigned int i = 0; i < dim; ++i,++pdata)
*pdata = reference_location(i);
- // TODO reinterpret cast pdata to PropertyType
+ data = static_cast<void *> (pdata);
+
// Write property data
- const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
- for (unsigned int i = 0; i < particle_properties.size(); ++i,++pdata)
- *pdata = particle_properties[i];
+ if (has_properties())
+ {
+ PropertyType *property_data = reinterpret_cast<PropertyType *> (data);
- data = static_cast<void *> (pdata);
+ const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
+ for (unsigned int i = 0; i < particle_properties.size(); ++i,++property_data)
+ *property_data = particle_properties[i];
+
+ data = static_cast<void *> (pdata);
+ }
+ }
+
+
+
+ template <int dim, int spacedim, typename PropertyType>
+ std::size_t
+ Particle<dim,spacedim,PropertyType>::size () const
+ {
+ std::size_t size = sizeof(types::particle_index)
+ + sizeof(location)
+ + sizeof(reference_location);
+
+ if (has_properties())
+ {
+ const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
+ size += sizeof(PropertyType) * particle_properties.size();
+ }
+ return size;
}
void
Particle<dim,spacedim,PropertyType>::set_properties (const ArrayView<const PropertyType> &new_properties)
{
+ Assert(property_pool != NULL,
+ ExcMessage("A particle was asked to set its properties without an "
+ "associated PropertyPool."))
+
if (properties == PropertyPool<PropertyType>::invalid_handle)
properties = property_pool->allocate_properties_array();
const ArrayView<const PropertyType>
Particle<dim,spacedim,PropertyType>::get_properties () const
{
- Assert(property_pool != NULL,
- ExcInternalError());
+ Assert(has_properties(),
+ ExcMessage("A particle without additional properties was asked for "
+ "its properties."));
return property_pool->get_properties(properties);
}
const ArrayView<PropertyType>
Particle<dim,spacedim,PropertyType>::get_properties ()
{
- Assert(property_pool != NULL,
- ExcInternalError());
+ Assert(has_properties(),
+ ExcMessage("A particle without additional properties was asked for "
+ "its properties."));
return property_pool->get_properties(properties);
}