From: Rene Gassmoeller Date: Thu, 7 Mar 2024 18:17:16 +0000 (-0500) Subject: Add another test X-Git-Tag: v9.6.0-rc1~500^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16709%2Fhead;p=dealii.git Add another test --- 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 index 0000000000..1d7a708c9b --- /dev/null +++ b/tests/particles/particle_handler_refinement_outside_cell_02.cc @@ -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 + +#include + +#include +#include + +#include + +#include "../tests.h" + +template +void +test() +{ + { + parallel::distributed::Triangulation tr(MPI_COMM_WORLD); + + GridGenerator::hyper_cube(tr); + MappingQ mapping(1); + + Particles::ParticleHandler particle_handler(tr, mapping, 2); + + // Create a particle outside of the domain + Point position; + position[0] = 3; + Point 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 index 0000000000..a82262d565 --- /dev/null +++ b/tests/particles/particle_handler_refinement_outside_cell_02.with_p4est=true.mpirun=1.output @@ -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