From b56fb09f9014e9eb55c0dceca524240104fc6ce7 Mon Sep 17 00:00:00 2001 From: Rene Gassmoeller Date: Wed, 2 Aug 2023 16:43:36 -0400 Subject: [PATCH] Avoid memory allocations in step 68 --- examples/step-68/step-68.cc | 3 ++- tests/performance/timing_step_68.cc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/step-68/step-68.cc b/examples/step-68/step-68.cc index 38bd36561b..58d49c5bd7 100644 --- a/examples/step-68/step-68.cc +++ b/examples/step-68/step-68.cc @@ -541,6 +541,7 @@ namespace Step68 Vector local_dof_values(fluid_fe.dofs_per_cell); FEPointEvaluation evaluator(mapping, fluid_fe, update_values); + std::vector> particle_positions; // We loop over all the local particles. Although this could be achieved // directly by looping over all the cells, this would force us @@ -564,7 +565,7 @@ namespace Step68 // This is achieved using FEPointEvaluation object. const auto pic = particle_handler.particles_in_cell(cell); Assert(pic.begin() == particle, ExcInternalError()); - std::vector> particle_positions; + particle_positions.clear(); for (auto &p : pic) particle_positions.push_back(p.get_reference_location()); diff --git a/tests/performance/timing_step_68.cc b/tests/performance/timing_step_68.cc index 632fbf9711..3527985f4f 100644 --- a/tests/performance/timing_step_68.cc +++ b/tests/performance/timing_step_68.cc @@ -324,6 +324,7 @@ namespace Step68 Vector local_dof_values(fluid_fe.dofs_per_cell); FEPointEvaluation evaluator(mapping, fluid_fe, update_values); + std::vector> particle_positions; const double this_mpi_process = static_cast(Utilities::MPI::this_mpi_process(mpi_communicator)); @@ -339,7 +340,7 @@ namespace Step68 const auto pic = particle_handler.particles_in_cell(cell); Assert(pic.begin() == particle, ExcInternalError()); - std::vector> particle_positions; + particle_positions.clear(); for (auto &p : pic) particle_positions.push_back(p.get_reference_location()); -- 2.39.5