From: Peter Munch Date: Wed, 19 May 2021 06:41:03 +0000 (+0200) Subject: Fix ParticleHandler::sort_particles_into_subdomains_and_cells() for lost particles X-Git-Tag: v9.3.0-rc1~31^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d48d3c42e429538c210f985a18f2293a1cd96df8;p=dealii.git Fix ParticleHandler::sort_particles_into_subdomains_and_cells() for lost particles --- diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 629c63804a..d7dd259f8d 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -1067,6 +1067,11 @@ namespace Particles cell_centers); }); + // make a copy of the current cell, since we will modify the variable + // current_cell in the following but we need a backup in the case + // the particle is not found + const auto previous_cell_of_particle = current_cell; + // Search all of the cells adjacent to the closest vertex of the // previous cell Most likely we will find the particle in them. for (unsigned int i = 0; i < n_neighbor_cells; ++i) @@ -1112,7 +1117,8 @@ namespace Particles // We can find no cell for this particle. It has left the // domain due to an integration error or an open boundary. // Signal the loss and move on. - signals.particle_lost(out_particle, current_cell); + signals.particle_lost(out_particle, + previous_cell_of_particle); continue; } } diff --git a/tests/particles/lost_01.cc b/tests/particles/lost_01.cc new file mode 100644 index 0000000000..09d17b0c06 --- /dev/null +++ b/tests/particles/lost_01.cc @@ -0,0 +1,54 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + +// Test the signal that is called if a particle is lost. + +#include + +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +int +main() +{ + initlog(); + + const int dim = 2; + + Triangulation tria; + GridGenerator::hyper_cube(tria); + + MappingQ1 mapping; + + Particles::ParticleHandler particle_handler(tria, mapping); + + std::vector> particle_positions; + particle_positions.emplace_back(0.5, 0.5); + particle_handler.insert_particles(particle_positions); + + particle_handler.signals.particle_lost.connect( + [](const auto &particle, const auto &cell) { + deallog << particle->get_id() << " " << cell->id() << std::endl; + }); + + particle_handler.begin()->set_location(Point{2.0, 2.0}); + + particle_handler.sort_particles_into_subdomains_and_cells(); +} diff --git a/tests/particles/lost_01.output b/tests/particles/lost_01.output new file mode 100644 index 0000000000..6cc2f57a7e --- /dev/null +++ b/tests/particles/lost_01.output @@ -0,0 +1,2 @@ + +DEAL::0 0_0: