From: Luca Heltai Date: Thu, 11 Jun 2020 07:59:04 +0000 (+0200) Subject: New insert_global_particles X-Git-Tag: v9.3.0-rc1~1390^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47bd20ff2e02f04d0b0f726d6f3018ff1f4fd691;p=dealii.git New insert_global_particles --- diff --git a/include/deal.II/particles/particle_handler.h b/include/deal.II/particles/particle_handler.h index 82b5b0f4f9..3ea665d83c 100644 --- a/include/deal.II/particles/particle_handler.h +++ b/include/deal.II/particles/particle_handler.h @@ -307,6 +307,42 @@ namespace Particles const std::vector> & properties = {}, const std::vector &ids = {}); + /** + * Insert a number of particles into the collection of particles. This + * function takes a list of particles for which we don't know the associated + * cell iterator, and distributes them to the correct local particle + * collection of a procesor, by unpacking the locations, figuring out where + * to send the particles by calling + * GridTools::distributed_compute_point_locations(), and sending the + * particles to the corresponding process. + * + * In order to keep track of what mpi process received what particles, a map + * from mpi process to IndexSet is returned by the function. This IndexSet + * contains the local indices of the particles that were passed to this + * function on the calling mpi process, and that falls within the part of + * the triangulation owned by this mpi process. + * + * @param[in] particles A vector of particles that do not need to be on the + * local processor + * + * @param[in] global_bounding_boxes A vector of vectors of bounding boxes. + * The bounding boxes `global_bboxes[rk]` describe which part of the mesh is + * locally owned by the mpi process with rank `rk`. The local description + * can be obtained from GridTools::compute_mesh_predicate_bounding_box(), + * and the global one can be obtained by passing the local ones to + * Utilities::MPI::all_gather(). + * + * @return A map from owner to IndexSet, that contains the local indices + * of the points that were passed to this function on the calling mpi + * process, and that falls within the part of triangulation owned by this + * mpi process. + */ + std::map + insert_global_particles( + const std::vector> &particles, + const std::vector>> + &global_bounding_boxes); + /** * Set the position of the particles by using the values contained in the * vector @p input_vector. diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index f740e56d03..ad1313d228 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -724,6 +724,43 @@ namespace Particles + template + std::map + ParticleHandler::insert_global_particles( + const std::vector> &particles, + const std::vector>> + &global_bounding_boxes) + { + // Store the positions in a vector of points, the ids in a vector of ids, + // and the properties, if any, in a vector of vector of properties. + std::vector> positions; + std::vector> properties; + std::vector ids; + positions.resize(particles.size()); + ids.resize(particles.size()); + if (n_properties_per_particle() > 0) + properties.resize(properties.size(), + std::vector(n_properties_per_particle())); + + unsigned int i = 0; + for (const auto &p : particles) + { + positions[i] = p.get_location(); + ids[i] = p.get_id(); + if (p.has_properties()) + properties[i] = {p.get_properties().begin(), + p.get_properties().end()}; + ++i; + } + + return insert_global_particles(positions, + global_bounding_boxes, + properties, + ids); + } + + + template types::particle_index ParticleHandler::n_global_particles() const