]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add another test 16709/head
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Thu, 7 Mar 2024 18:17:16 +0000 (13:17 -0500)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Thu, 7 Mar 2024 18:17:16 +0000 (13:17 -0500)
tests/particles/particle_handler_refinement_outside_cell_02.cc [new file with mode: 0644]
tests/particles/particle_handler_refinement_outside_cell_02.with_p4est=true.mpirun=1.output [new file with mode: 0644]

diff --git a/tests/particles/particle_handler_refinement_outside_cell_02.cc b/tests/particles/particle_handler_refinement_outside_cell_02.cc
new file mode 100644 (file)
index 0000000..1d7a708
--- /dev/null
@@ -0,0 +1,115 @@
+// ------------------------------------------------------------------------
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (C) 2017 - 2023 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// Part of the source code is dual licensed under Apache-2.0 WITH
+// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
+// governing the source code and code contributions can be found in
+// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
+//
+// ------------------------------------------------------------------------
+
+
+
+// Check that particles are correctly deleted during grid
+// refinement/coarsening.
+// Like particle_handler_refinement_outside_cell.cc, but
+// with particles that carry properties.
+
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/fe/mapping_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+
+#include <deal.II/particles/particle_handler.h>
+
+#include "../tests.h"
+
+template <int dim, int spacedim>
+void
+test()
+{
+  {
+    parallel::distributed::Triangulation<dim, spacedim> tr(MPI_COMM_WORLD);
+
+    GridGenerator::hyper_cube(tr);
+    MappingQ<dim, spacedim> mapping(1);
+
+    Particles::ParticleHandler<dim, spacedim> particle_handler(tr, mapping, 2);
+
+    // Create a particle outside of the domain
+    Point<spacedim> position;
+    position[0] = 3;
+    Point<dim> reference_position;
+    reference_position[0]    = 0.5;
+    types::particle_index id = 0;
+
+    particle_handler.insert_particle(position,
+                                     reference_position,
+                                     id,
+                                     tr.begin_active());
+
+    position[0] = 1.0 + 1e-13;
+    id          = 1;
+
+    particle_handler.insert_particle(position,
+                                     reference_position,
+                                     id,
+                                     tr.begin_active());
+
+    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
+    particle_handler.prepare_for_coarsening_and_refinement();
+    tr.refine_global(1);
+    particle_handler.unpack_after_coarsening_and_refinement();
+
+    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
+    for (auto cell = tr.begin_active(); cell != tr.end(); ++cell)
+      cell->set_coarsen_flag();
+
+    particle_handler.prepare_for_coarsening_and_refinement();
+    tr.execute_coarsening_and_refinement();
+    particle_handler.unpack_after_coarsening_and_refinement();
+
+    for (const auto &particle : particle_handler)
+      deallog << "After coarsening particle id " << particle.get_id()
+              << " is in cell " << particle.get_surrounding_cell(tr)
+              << std::endl;
+  }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+
+  MPILogInitAll all;
+
+  deallog.push("2d/2d");
+  test<2, 2>();
+  deallog.pop();
+  deallog.push("2d/3d");
+  test<2, 3>();
+  deallog.pop();
+  deallog.push("3d/3d");
+  test<3, 3>();
+  deallog.pop();
+}
diff --git a/tests/particles/particle_handler_refinement_outside_cell_02.with_p4est=true.mpirun=1.output b/tests/particles/particle_handler_refinement_outside_cell_02.with_p4est=true.mpirun=1.output
new file mode 100644 (file)
index 0000000..a82262d
--- /dev/null
@@ -0,0 +1,16 @@
+
+DEAL:0:2d/2d::Before refinement particle id 0 is in cell 0.0
+DEAL:0:2d/2d::Before refinement particle id 1 is in cell 0.0
+DEAL:0:2d/2d::After refinement particle id 1 is in cell 1.1
+DEAL:0:2d/2d::After coarsening particle id 1 is in cell 0.0
+DEAL:0:2d/2d::OK
+DEAL:0:2d/3d::Before refinement particle id 0 is in cell 0.0
+DEAL:0:2d/3d::Before refinement particle id 1 is in cell 0.0
+DEAL:0:2d/3d::After refinement particle id 1 is in cell 1.1
+DEAL:0:2d/3d::After coarsening particle id 1 is in cell 0.0
+DEAL:0:2d/3d::OK
+DEAL:0:3d/3d::Before refinement particle id 0 is in cell 0.0
+DEAL:0:3d/3d::Before refinement particle id 1 is in cell 0.0
+DEAL:0:3d/3d::After refinement particle id 1 is in cell 1.1
+DEAL:0:3d/3d::After coarsening particle id 1 is in cell 0.0
+DEAL:0:3d/3d::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.