]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test for new periodic exchange ghost
authorBruno Blais <blais.bruno@gmail.com>
Mon, 21 Nov 2022 01:12:14 +0000 (20:12 -0500)
committerBruno Blais <blais.bruno@gmail.com>
Mon, 21 Nov 2022 01:12:14 +0000 (20:12 -0500)
tests/particles/exchange_ghosts_periodic_01.cc [new file with mode: 0644]
tests/particles/exchange_ghosts_periodic_01.mpirun=2.output [new file with mode: 0644]

diff --git a/tests/particles/exchange_ghosts_periodic_01.cc b/tests/particles/exchange_ghosts_periodic_01.cc
new file mode 100644 (file)
index 0000000..be4bc33
--- /dev/null
@@ -0,0 +1,135 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2021 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// like particle_handler_06, but tests that the particle handlers function
+// n_locally_owned_particles only counts locally owned particles.
+
+#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);
+
+    // Create a subdivided hyper rectangle with divisions along the x axis
+    // Colorize is set to true to enable setting one set of periodic boundary
+    // conditions along id 0 and 1
+    std::vector<unsigned int> repetitions({6, 1});
+    if (dim == 3)
+      repetitions.push_back(1);
+    Point<spacedim> left;
+    Point<spacedim> right;
+    for (int i = 0; i < spacedim; ++i)
+      right[i] = 1;
+
+    GridGenerator::subdivided_hyper_rectangle(
+      tr, repetitions, left, right, true);
+    MappingQ<dim, spacedim> mapping(1);
+
+
+    // Generate periodic boundary conditions
+    std::vector<GridTools::PeriodicFacePair<
+      typename Triangulation<dim, spacedim>::cell_iterator>>
+      periodicity_vector;
+    GridTools::collect_periodic_faces(tr, 0, 1, 0, periodicity_vector);
+    tr.add_periodicity(periodicity_vector);
+
+    // both processes create a particle handler with a particle in a
+    // position that is in a ghost cell to the other process connected by a
+    // periodic boundary
+    Particles::ParticleHandler<dim, spacedim> particle_handler(tr, mapping);
+
+    Point<spacedim> position;
+    Point<dim>      reference_position;
+
+    if (Utilities::MPI::this_mpi_process(tr.get_communicator()) == 0)
+      position(0) = 0.001;
+    else
+      position[0] = 0.999;
+
+    Particles::Particle<dim, spacedim> particle(
+      position,
+      reference_position,
+      Utilities::MPI::this_mpi_process(tr.get_communicator()));
+
+    // We give a local random cell hint to check that sorting and
+    // transferring ghost particles works.
+    typename Triangulation<dim, spacedim>::active_cell_iterator cell =
+      tr.begin_active();
+    while (!cell->is_locally_owned())
+      ++cell;
+
+    particle_handler.insert_particle(particle, cell);
+
+    particle_handler.sort_particles_into_subdomains_and_cells();
+
+
+    unsigned int n_ghost_particles = 0;
+    for (auto ghost_particle = particle_handler.begin_ghost();
+         ghost_particle != particle_handler.end_ghost();
+         ++ghost_particle)
+      {
+        ++n_ghost_particles;
+      }
+
+    deallog << "Number of ghost particles before exchange ghost: "
+            << std::to_string(n_ghost_particles) << std::endl;
+
+    particle_handler.exchange_ghost_particles();
+
+    n_ghost_particles = 0;
+    for (auto ghost_particle = particle_handler.begin_ghost();
+         ghost_particle != particle_handler.end_ghost();
+         ++ghost_particle)
+      {
+        ++n_ghost_particles;
+      }
+
+    deallog << "Number of ghost particles after exchange ghost: "
+            << std::to_string(n_ghost_particles) << 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("3d/3d");
+  test<3, 3>();
+  deallog.pop();
+}
diff --git a/tests/particles/exchange_ghosts_periodic_01.mpirun=2.output b/tests/particles/exchange_ghosts_periodic_01.mpirun=2.output
new file mode 100644 (file)
index 0000000..6d22d58
--- /dev/null
@@ -0,0 +1,15 @@
+
+DEAL:0:2d/2d::Number of ghost particles before exchange ghost: 0
+DEAL:0:2d/2d::Number of ghost particles after exchange ghost: 1
+DEAL:0:2d/2d::OK
+DEAL:0:3d/3d::Number of ghost particles before exchange ghost: 0
+DEAL:0:3d/3d::Number of ghost particles after exchange ghost: 1
+DEAL:0:3d/3d::OK
+
+DEAL:1:2d/2d::Number of ghost particles before exchange ghost: 0
+DEAL:1:2d/2d::Number of ghost particles after exchange ghost: 1
+DEAL:1:2d/2d::OK
+DEAL:1:3d/3d::Number of ghost particles before exchange ghost: 0
+DEAL:1:3d/3d::Number of ghost particles after exchange ghost: 1
+DEAL:1: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.