From: Bruno Date: Wed, 18 Nov 2020 02:07:02 +0000 (-0500) Subject: Add particle update data function to overwrite particle information without recreatin... X-Git-Tag: v9.3.0-rc1~887^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee615f3cb71767679a2fefa065af6f81bfc14ca3;p=dealii.git Add particle update data function to overwrite particle information without recreating the particle Added documentation and fixed indentation Added out to documentation Co-authored-by: Martin Kronbichler --- diff --git a/include/deal.II/particles/particle.h b/include/deal.II/particles/particle.h index a79617d223..e43dc03b31 100644 --- a/include/deal.II/particles/particle.h +++ b/include/deal.II/particles/particle.h @@ -235,6 +235,25 @@ namespace Particles void write_data(void *&data) const; + + /** + * Update all of the data associated with a particle : id, + * location, reference location and, if any, properties by using a + * data array. The array is expected to be large enough to take the data, + * and the void pointer should point to the first entry of the array to + * which the data should be written. This function is meant for + * de-serializing the particle data without requiring that a new Particle + * class be built. This is used in the ParticleHandler to update the + * ghost particles without de-allocating and re-allocating memory. + * + * @param[in,out] data A pointer to a memory location from which + * to read the information that completely describes a particle. This + * class then de-serializes its data from this memory location and + * advance the pointer accordingly. + */ + void + update_particle_data(const void *&data); + /** * 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 2befeec29c..0a68480dc1 100644 --- a/source/particles/particle.cc +++ b/source/particles/particle.cc @@ -220,6 +220,34 @@ namespace Particles } + template + void + Particle::update_particle_data(const void *&data) + { + const types::particle_index *id_data = + static_cast(data); + id = *id_data++; + const double *pdata = reinterpret_cast(id_data); + + for (unsigned int i = 0; i < spacedim; ++i) + location(i) = *pdata++; + + for (unsigned int i = 0; i < dim; ++i) + reference_location(i) = *pdata++; + + // See if there are properties to load + if (has_properties()) + { + const ArrayView particle_properties = + property_pool->get_properties(properties); + const unsigned int size = particle_properties.size(); + for (unsigned int i = 0; i < size; ++i) + particle_properties[i] = *pdata++; + } + + data = static_cast(pdata); + } + template std::size_t diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 783bd95091..fd3fc03874 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -1649,9 +1649,9 @@ namespace Particles for (auto &recv_particle : ghost_particles_iterators) { - recv_particle->second.free_properties(); - recv_particle->second = - Particle(recv_data_it, property_pool.get()); + // Update particle data using previously allocated memory space + // for efficiency reasons + recv_particle->second.update_particle_data(recv_data_it); if (load_callback) recv_data_it =