From 0c686834609dea37c8bf2cf196ad86a1601114da Mon Sep 17 00:00:00 2001 From: Bruno Blais Date: Sun, 20 Nov 2022 20:12:14 -0500 Subject: [PATCH] Add test for new periodic exchange ghost --- .../particles/exchange_ghosts_periodic_01.cc | 135 ++++++++++++++++++ ...xchange_ghosts_periodic_01.mpirun=2.output | 15 ++ 2 files changed, 150 insertions(+) create mode 100644 tests/particles/exchange_ghosts_periodic_01.cc create mode 100644 tests/particles/exchange_ghosts_periodic_01.mpirun=2.output diff --git a/tests/particles/exchange_ghosts_periodic_01.cc b/tests/particles/exchange_ghosts_periodic_01.cc new file mode 100644 index 0000000000..be4bc3302c --- /dev/null +++ b/tests/particles/exchange_ghosts_periodic_01.cc @@ -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 + +#include + +#include +#include + +#include + +#include "../tests.h" + +template +void +test() +{ + { + parallel::distributed::Triangulation 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 repetitions({6, 1}); + if (dim == 3) + repetitions.push_back(1); + Point left; + Point right; + for (int i = 0; i < spacedim; ++i) + right[i] = 1; + + GridGenerator::subdivided_hyper_rectangle( + tr, repetitions, left, right, true); + MappingQ mapping(1); + + + // Generate periodic boundary conditions + std::vector::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 particle_handler(tr, mapping); + + Point position; + Point reference_position; + + if (Utilities::MPI::this_mpi_process(tr.get_communicator()) == 0) + position(0) = 0.001; + else + position[0] = 0.999; + + Particles::Particle 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::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 index 0000000000..6d22d5849a --- /dev/null +++ b/tests/particles/exchange_ghosts_periodic_01.mpirun=2.output @@ -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 + -- 2.39.5