From: Rene Gassmoeller Date: Fri, 11 Jun 2021 14:18:16 +0000 (-0400) Subject: Add test X-Git-Tag: v9.4.0-rc1~1222^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90efb544c622606ea005ef98d5d4b6347951935c;p=dealii.git Add test --- diff --git a/tests/particles/property_pool_03.cc b/tests/particles/property_pool_03.cc new file mode 100644 index 0000000000..64ada7b132 --- /dev/null +++ b/tests/particles/property_pool_03.cc @@ -0,0 +1,104 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 2020 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// test the sorting of memory chunks inside the property pool + +#include + +#include +#include + +#include "../tests.h" + + +void +test() +{ + { + const int dim = 2; + const int spacedim = 2; + + const unsigned int n_properties = 3; + Particles::PropertyPool pool(n_properties); + + std::vector< + std::vector::Handle>> + particle_handles; + particle_handles.resize(2); + + // Allocate some space in non-contigous locations + particle_handles[1].push_back(pool.register_particle()); + particle_handles[0].push_back(pool.register_particle()); + particle_handles[1].push_back(pool.register_particle()); + particle_handles[0].push_back(pool.register_particle()); + particle_handles[1].push_back(pool.register_particle()); + particle_handles[0].push_back(pool.register_particle()); + + unsigned int i = 0; + for (auto &particles_in_cell : particle_handles) + for (auto &particle : particles_in_cell) + pool.set_id(particle, i++); + + for (const auto &particles_in_cell : particle_handles) + for (const auto &particle : particles_in_cell) + deallog << "Before removal unsorted ID: " << pool.get_id(particle) + << ". Handle: " << particle << std::endl; + + pool.sort_memory_slots(particle_handles); + + for (const auto &particles_in_cell : particle_handles) + for (const auto &particle : particles_in_cell) + deallog << "Before removal sorted ID: " << pool.get_id(particle) + << ". Handle: " << particle << std::endl; + + // Deallocate some space in the same way the particle handler would + // remove particles + pool.deregister_particle(particle_handles[1][1]); + pool.deregister_particle(particle_handles[0][2]); + + particle_handles[1][1] = particle_handles[1].back(); + particle_handles[1].resize(particle_handles[1].size() - 1); + particle_handles[0].resize(particle_handles[0].size() - 1); + + for (const auto &particles_in_cell : particle_handles) + for (const auto &particle : particles_in_cell) + deallog << "After removal unsorted ID: " << pool.get_id(particle) + << ". Handle: " << particle << std::endl; + + pool.sort_memory_slots(particle_handles); + + for (const auto &particles_in_cell : particle_handles) + for (const auto &particle : particles_in_cell) + deallog << "After removal sorted ID: " << pool.get_id(particle) + << ". Handle: " << particle << std::endl; + + for (auto &particles_in_cell : particle_handles) + for (auto &particle : particles_in_cell) + pool.deregister_particle(particle); + } + + deallog << "OK" << std::endl; +} + + + +int +main() +{ + initlog(); + test(); +} diff --git a/tests/particles/property_pool_03.output b/tests/particles/property_pool_03.output new file mode 100644 index 0000000000..1ec4c0b7e1 --- /dev/null +++ b/tests/particles/property_pool_03.output @@ -0,0 +1,22 @@ + +DEAL::Before removal unsorted ID: 0. Handle: 1 +DEAL::Before removal unsorted ID: 1. Handle: 3 +DEAL::Before removal unsorted ID: 2. Handle: 5 +DEAL::Before removal unsorted ID: 3. Handle: 0 +DEAL::Before removal unsorted ID: 4. Handle: 2 +DEAL::Before removal unsorted ID: 5. Handle: 4 +DEAL::Before removal sorted ID: 0. Handle: 0 +DEAL::Before removal sorted ID: 1. Handle: 1 +DEAL::Before removal sorted ID: 2. Handle: 2 +DEAL::Before removal sorted ID: 3. Handle: 3 +DEAL::Before removal sorted ID: 4. Handle: 4 +DEAL::Before removal sorted ID: 5. Handle: 5 +DEAL::After removal unsorted ID: 0. Handle: 0 +DEAL::After removal unsorted ID: 1. Handle: 1 +DEAL::After removal unsorted ID: 3. Handle: 3 +DEAL::After removal unsorted ID: 5. Handle: 5 +DEAL::After removal sorted ID: 0. Handle: 0 +DEAL::After removal sorted ID: 1. Handle: 1 +DEAL::After removal sorted ID: 3. Handle: 2 +DEAL::After removal sorted ID: 5. Handle: 3 +DEAL::OK