From: Wolfgang Bangerth Date: Fri, 9 Aug 2019 16:57:54 +0000 (-0600) Subject: Make particle iterators const references. X-Git-Tag: v9.2.0-rc1~1271^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bdfebd2e205b9812b6f862225e8738081d61995;p=dealii.git Make particle iterators const references. --- diff --git a/tests/particles/particle_handler_01.cc b/tests/particles/particle_handler_01.cc index e201a525b1..e99efe8d3c 100644 --- a/tests/particles/particle_handler_01.cc +++ b/tests/particles/particle_handler_01.cc @@ -76,14 +76,12 @@ test() deallog << "Particle number: " << particle_handler.n_global_particles() << std::endl; - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) + for (const auto &particle : particle_handler) { - deallog << "Particle location: " << particle->get_location() + deallog << "Particle location: " << particle.get_location() << std::endl; deallog << "Particle reference location: " - << particle->get_reference_location() << std::endl; + << particle.get_reference_location() << std::endl; } } diff --git a/tests/particles/particle_handler_02.cc b/tests/particles/particle_handler_02.cc index b1de99be3b..d691ca0f5d 100644 --- a/tests/particles/particle_handler_02.cc +++ b/tests/particles/particle_handler_02.cc @@ -94,14 +94,12 @@ test() deallog << "Max particles per cell: " << particle_handler.n_global_max_particles_per_cell() << std::endl; - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) + for (const auto &particle : particle_handler) { - deallog << "Particle location: " << particle->get_location() + deallog << "Particle location: " << particle.get_location() << std::endl; deallog << "Particle reference location: " - << particle->get_reference_location() << std::endl; + << particle.get_reference_location() << std::endl; } } diff --git a/tests/particles/particle_handler_03.cc b/tests/particles/particle_handler_03.cc index 4ff11ba9cb..9f0f67e0b0 100644 --- a/tests/particles/particle_handler_03.cc +++ b/tests/particles/particle_handler_03.cc @@ -67,20 +67,16 @@ test() particle_handler.insert_particle(particle1, cell1); particle_handler.insert_particle(particle2, cell2); - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - deallog << "Before sort particle id " << particle->get_id() - << " is in cell " << particle->get_surrounding_cell(tr) + for (const auto &particle : particle_handler) + deallog << "Before sort particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tr) << std::endl; particle_handler.sort_particles_into_subdomains_and_cells(); - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - deallog << "After sort particle id " << particle->get_id() - << " is in cell " << particle->get_surrounding_cell(tr) + for (const auto &particle : particle_handler) + deallog << "After sort particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tr) << std::endl; // Move all points up by 0.5. This will change cell for particle 1, and will @@ -88,17 +84,13 @@ test() // coordinate dim-1 despite having a spacedim point. Point shift; shift(dim - 1) = 0.5; - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - particle->set_location(particle->get_location() + shift); + for (auto &particle : particle_handler) + particle.set_location(particle.get_location() + shift); particle_handler.sort_particles_into_subdomains_and_cells(); - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - deallog << "After shift particle id " << particle->get_id() - << " is in cell " << particle->get_surrounding_cell(tr) + for (const auto &particle : particle_handler) + deallog << "After shift particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tr) << std::endl; } diff --git a/tests/particles/particle_handler_04.cc b/tests/particles/particle_handler_04.cc index 5839a45ceb..95a5cec8e8 100644 --- a/tests/particles/particle_handler_04.cc +++ b/tests/particles/particle_handler_04.cc @@ -72,11 +72,9 @@ test() particle_handler.insert_particle(particle1, cell1); particle_handler.insert_particle(particle2, cell2); - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - deallog << "Before sort particle id " << particle->get_id() - << " is in cell " << particle->get_surrounding_cell(tr) + for (const auto &particle : particle_handler) + deallog << "Before sort particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tr) << " on process " << Utilities::MPI::this_mpi_process(tr.get_communicator()) << std::flush << std::endl; @@ -86,11 +84,9 @@ test() particle_handler.sort_particles_into_subdomains_and_cells(); - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - deallog << "After sort particle id " << particle->get_id() - << " is in cell " << particle->get_surrounding_cell(tr) + for (const auto &particle : particle_handler) + deallog << "After sort particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tr) << " on process " << Utilities::MPI::this_mpi_process(tr.get_communicator()) << std::flush << std::endl; @@ -100,17 +96,13 @@ test() // coordinate dim-1 despite having a spacedim point. Point shift; shift(dim - 1) = 0.5; - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - particle->set_location(particle->get_location() + shift); + for (auto &particle : particle_handler) + particle.set_location(particle.get_location() + shift); particle_handler.sort_particles_into_subdomains_and_cells(); - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - deallog << "After shift particle id " << particle->get_id() - << " is in cell " << particle->get_surrounding_cell(tr) + for (const auto &particle : particle_handler) + deallog << "After shift particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tr) << " on process " << Utilities::MPI::this_mpi_process(tr.get_communicator()) << std::flush << std::endl; diff --git a/tests/particles/particle_handler_05.cc b/tests/particles/particle_handler_05.cc index 11f46fbab4..b6251951ce 100644 --- a/tests/particles/particle_handler_05.cc +++ b/tests/particles/particle_handler_05.cc @@ -116,21 +116,17 @@ test() create_regular_particle_distribution(particle_handler, tr); - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - deallog << "Before refinement particle id " << particle->get_id() - << " is in cell " << particle->get_surrounding_cell(tr) + for (const auto &particle : particle_handler) + deallog << "Before refinement particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tr) << std::endl; // Check that all particles are moved to children tr.refine_global(1); - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - deallog << "After refinement particle id " << particle->get_id() - << " is in cell " << particle->get_surrounding_cell(tr) + for (const auto &particle : particle_handler) + deallog << "After refinement particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tr) << std::endl; // Reverse the refinement and check again @@ -139,11 +135,9 @@ test() tr.execute_coarsening_and_refinement(); - for (auto particle = particle_handler.begin(); - particle != particle_handler.end(); - ++particle) - deallog << "After coarsening particle id " << particle->get_id() - << " is in cell " << particle->get_surrounding_cell(tr) + for (const auto &particle : particle_handler) + deallog << "After coarsening particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tr) << std::endl; }