From: Rene Gassmoeller Date: Wed, 9 Jun 2021 20:28:40 +0000 (-0400) Subject: Unify particle creation X-Git-Tag: v9.4.0-rc1~1240^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c006e8a287f34e946bd26e389676fbb5764827b;p=dealii.git Unify particle creation --- diff --git a/include/deal.II/particles/particle_handler.h b/include/deal.II/particles/particle_handler.h index 5002a67994..d4c5af7155 100644 --- a/include/deal.II/particles/particle_handler.h +++ b/include/deal.II/particles/particle_handler.h @@ -795,6 +795,20 @@ namespace Particles const void *& data, const typename Triangulation::active_cell_iterator &cell); + /** + * Insert a particle into the collection of particles given all the + * properties necessary for a particle. This function is used internally to + * efficiently generate particles without the detour through a Particle + * object. + */ + particle_iterator + insert_particle( + const Point & position, + const Point & reference_position, + const types::particle_index particle_index, + const typename Triangulation::active_cell_iterator &cell, + const ArrayView &properties = {}); + /** * Address of the triangulation to work on. */ diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index b76330f305..4dd410bc66 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -426,6 +426,21 @@ namespace Particles ParticleHandler::insert_particle( const Particle & particle, const typename Triangulation::active_cell_iterator &cell) + { + return insert_particle(particle.get_location(), + particle.get_reference_location(), + particle.get_id(), + cell, + particle.get_properties()); + } + + + + template + typename ParticleHandler::particle_iterator + ParticleHandler::insert_particle( + const void *& data, + const typename Triangulation::active_cell_iterator &cell) { Assert(triangulation != nullptr, ExcInternalError()); Assert(cell.state() == IteratorState::valid, ExcInternalError()); @@ -444,13 +459,7 @@ namespace Particles cell, particles[active_cell_index].size() - 1); - particle_it->set_reference_location(particle.get_reference_location()); - particle_it->set_location(particle.get_location()); - particle_it->set_id(particle.get_id()); - - if (particle.has_properties()) - particle_it->set_properties(particle.get_properties()); - + data = particle_it->read_particle_data_from_memory(data); ++local_number_of_particles; @@ -462,11 +471,18 @@ namespace Particles template typename ParticleHandler::particle_iterator ParticleHandler::insert_particle( - const void *& data, - const typename Triangulation::active_cell_iterator &cell) + const Point & position, + const Point & reference_position, + const types::particle_index particle_index, + const typename Triangulation::active_cell_iterator &cell, + const ArrayView &properties) { Assert(triangulation != nullptr, ExcInternalError()); Assert(cell.state() == IteratorState::valid, ExcInternalError()); + Assert( + cell->is_locally_owned(), + ExcMessage( + "You tried to insert a particle into a cell that is not locally owned. This is not supported.")); if (particles.size() == 0) particles.resize(triangulation->n_active_cells()); @@ -478,7 +494,12 @@ namespace Particles cell, particles[active_cell_index].size() - 1); - data = particle_it->read_particle_data_from_memory(data); + particle_it->set_location(position); + particle_it->set_reference_location(reference_position); + particle_it->set_id(particle_index); + + if (properties.size() != 0) + particle_it->set_properties(properties); ++local_number_of_particles; @@ -563,26 +584,11 @@ namespace Particles return; for (unsigned int i = 0; i < cells.size(); ++i) - { - const unsigned int active_cell_index = cells[i]->active_cell_index(); - - for (unsigned int p = 0; p < local_positions[i].size(); ++p) - { - particles[active_cell_index].push_back( - property_pool->register_particle()); - ++local_number_of_particles; - - particle_iterator particle_it(particles, - *property_pool, - cells[i], - particles[active_cell_index].size() - - 1); - - particle_it->set_location(positions[index_map[i][p]]); - particle_it->set_reference_location(local_positions[i][p]); - particle_it->set_id(local_start_index + index_map[i][p]); - } - } + for (unsigned int p = 0; p < local_positions[i].size(); ++p) + insert_particle(positions[index_map[i][p]], + local_positions[i][p], + local_start_index + index_map[i][p], + cells[i]); update_cached_numbers(); } @@ -774,9 +780,6 @@ namespace Particles i_cell < local_cells_containing_particles.size(); ++i_cell) { - const unsigned int active_cell_index = - local_cells_containing_particles[i_cell]->active_cell_index(); - for (unsigned int i_particle = 0; i_particle < local_positions[i_cell].size(); ++i_particle) @@ -798,28 +801,17 @@ namespace Particles locally_owned_ids_from_other_processes[calling_process] [index_within_set]; - particles[active_cell_index].push_back( - property_pool->register_particle()); - ++local_number_of_particles; - - particle_iterator particle_it( - particles, - *property_pool, - local_cells_containing_particles[i_cell], - particles[active_cell_index].size() - 1); - - particle_it->set_location(local_positions[i_cell][i_particle]); - particle_it->set_reference_location( - local_reference_positions[i_cell][i_particle]); - particle_it->set_id(particle_id); + auto particle_it = + insert_particle(local_positions[i_cell][i_particle], + local_reference_positions[i_cell][i_particle], + particle_id, + local_cells_containing_particles[i_cell]); if (n_global_properties > 0) { - const auto &this_particle_properties = + particle_it->set_properties( locally_owned_properties_from_other_processes - [calling_process][index_within_set]; - - particle_it->set_properties(this_particle_properties); + [calling_process][index_within_set]); } } }