From: Rene Gassmoeller Date: Mon, 14 Aug 2017 21:33:58 +0000 (-0600) Subject: temp X-Git-Tag: v9.0.0-rc1~1013^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a0e64f83fcf212e9ba5bf953ec4a0982622e09c;p=dealii.git temp --- diff --git a/include/deal.II/particles/particle.h b/include/deal.II/particles/particle.h index cedf7c4055..9a2de57d11 100644 --- a/include/deal.II/particles/particle.h +++ b/include/deal.II/particles/particle.h @@ -133,11 +133,14 @@ namespace Particles * 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 &new_property_pool); + PropertyPool *property_pool = NULL); /** * Move constructor for Particle, creates a particle from an existing @@ -169,7 +172,7 @@ namespace Particles * 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 *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 @@ -179,6 +182,14 @@ namespace Particles 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. diff --git a/source/particles/particle.cc b/source/particles/particle.cc index 9ea08746a3..e2917c5f00 100644 --- a/source/particles/particle.cc +++ b/source/particles/particle.cc @@ -73,7 +73,7 @@ namespace Particles template Particle::Particle (const void *&data, - PropertyPool &new_property_pool) + PropertyPool *new_property_pool) { const types::particle_index *id_data = static_cast (data); id = *id_data++; @@ -85,16 +85,22 @@ namespace Particles 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 (pdata); - // TODO reinterpret cast pdata to PropertyType // See if there are properties to load - const ArrayView 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 (pdata); + const PropertyType *property_data = static_cast (data); + + const ArrayView 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 (property_data); + } } @@ -187,13 +193,37 @@ namespace Particles for (unsigned int i = 0; i < dim; ++i,++pdata) *pdata = reference_location(i); - // TODO reinterpret cast pdata to PropertyType + data = static_cast (pdata); + // Write property data - const ArrayView 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 (data); - data = static_cast (pdata); + const ArrayView 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 (pdata); + } + } + + + + template + std::size_t + Particle::size () const + { + std::size_t size = sizeof(types::particle_index) + + sizeof(location) + + sizeof(reference_location); + + if (has_properties()) + { + const ArrayView particle_properties = property_pool->get_properties(properties); + size += sizeof(PropertyType) * particle_properties.size(); + } + return size; } @@ -266,6 +296,10 @@ namespace Particles void Particle::set_properties (const ArrayView &new_properties) { + Assert(property_pool != NULL, + ExcMessage("A particle was asked to set its properties without an " + "associated PropertyPool.")) + if (properties == PropertyPool::invalid_handle) properties = property_pool->allocate_properties_array(); @@ -280,8 +314,9 @@ namespace Particles const ArrayView Particle::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); } @@ -292,8 +327,9 @@ namespace Particles const ArrayView Particle::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); }