From 6250574834b95b15b7a90025b1ffee8948bb4d04 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 22 Mar 2022 12:20:00 -0600 Subject: [PATCH] Minor particle cleanups. --- include/deal.II/particles/particle_handler.h | 2 +- source/particles/generators.cc | 22 ++++++++++++-------- source/particles/particle_handler.cc | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/deal.II/particles/particle_handler.h b/include/deal.II/particles/particle_handler.h index ba6a23d947..63949a1d23 100644 --- a/include/deal.II/particles/particle_handler.h +++ b/include/deal.II/particles/particle_handler.h @@ -166,7 +166,7 @@ namespace Particles * particles to be newly inserted. */ void - reserve(std::size_t n_particles); + reserve(const std::size_t n_particles); /** * Update all internally cached numbers. Note that all functions that diff --git a/source/particles/generators.cc b/source/particles/generators.cc index 1be90a7290..bf82f2e63d 100644 --- a/source/particles/generators.cc +++ b/source/particles/generators.cc @@ -110,8 +110,8 @@ namespace Particles // This function generates a random position in the given cell and - // returns the position and its coordinates in the unit cell. It first - // tries to generate a random and uniformly distributed point in the + // returns the position and its coordinates in the reference cell. It + // first tries to generate a random and uniformly distributed point in // real space, but if that fails (e.g. because the cell has a bad aspect // ratio) it reverts to generating a random point in the unit cell. template @@ -135,10 +135,9 @@ namespace Particles // Generate random points in these bounds until one is within the cell // or we exceed the maximum number of attempts. const unsigned int n_attempts = 100; - Point position; - Point position_unit; for (unsigned int i = 0; i < n_attempts; ++i) { + Point position; for (unsigned int d = 0; d < spacedim; ++d) { position[d] = uniform_distribution_01(random_number_generator) * @@ -148,11 +147,11 @@ namespace Particles try { - position_unit = + const Point position_unit = mapping.transform_real_to_unit_cell(cell, position); if (cell->reference_cell().contains_point(position_unit)) - return std::make_pair(position, position_unit); + return {position, position_unit}; } catch (typename Mapping::ExcTransformationFailed &) { @@ -162,17 +161,22 @@ namespace Particles // If the above algorithm has not worked (e.g. because of badly // deformed cells), retry generating particles - // randomly within the reference cell. This is not generating a + // randomly within the reference cell and then mapping it to to + // real space. This is not generating a // uniform distribution in real space, but will always succeed. + Point position_unit; for (unsigned int d = 0; d < dim; ++d) position_unit[d] = uniform_distribution_01(random_number_generator); - position = mapping.transform_unit_to_real_cell(cell, position_unit); + const Point position = + mapping.transform_unit_to_real_cell(cell, position_unit); - return std::make_pair(position, position_unit); + return {position, position_unit}; } } // namespace + + template void regular_reference_locations( diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 1d7a9b703d..e699ac108b 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -223,7 +223,7 @@ namespace Particles template void - ParticleHandler::reserve(std::size_t n_particles) + ParticleHandler::reserve(const std::size_t n_particles) { property_pool->reserve(n_particles); } -- 2.39.5