]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Fri, 11 Jun 2021 14:18:16 +0000 (10:18 -0400)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Sat, 12 Jun 2021 03:28:18 +0000 (23:28 -0400)
tests/particles/property_pool_03.cc [new file with mode: 0644]
tests/particles/property_pool_03.output [new file with mode: 0644]

diff --git a/tests/particles/property_pool_03.cc b/tests/particles/property_pool_03.cc
new file mode 100644 (file)
index 0000000..64ada7b
--- /dev/null
@@ -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 <deal.II/particles/property_pool.h>
+
+#include <fstream>
+#include <iomanip>
+
+#include "../tests.h"
+
+
+void
+test()
+{
+  {
+    const int dim      = 2;
+    const int spacedim = 2;
+
+    const unsigned int                     n_properties = 3;
+    Particles::PropertyPool<dim, spacedim> pool(n_properties);
+
+    std::vector<
+      std::vector<typename Particles::PropertyPool<dim, spacedim>::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 (file)
index 0000000..1ec4c0b
--- /dev/null
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.