From: Bruno Blais Date: Thu, 12 Mar 2020 13:03:18 +0000 (-0400) Subject: Completely reworked the pull request. X-Git-Tag: v9.2.0-rc1~424^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6a467e3ee83c46d4248d69fe0352d090bd9ebc3;p=dealii.git Completely reworked the pull request. The particle handler now has a GridTools::Cache that is used to obtain the vertex_to_cell_centers and vertex_to_cells This enables the same feature as before but is a lot cleaner and flexible. However, the cache has to be stored in a unique pointer because the particlehandler has a constructor that enables it to be constructed without a triangulation. This is not the case for the GridTools::Cache. Consequently, I thought that unique an std::unique was a good compromise here. As always, looking forward to your comments :)! --- diff --git a/include/deal.II/particles/particle_handler.h b/include/deal.II/particles/particle_handler.h index 5fec613820..78f9d22f50 100644 --- a/include/deal.II/particles/particle_handler.h +++ b/include/deal.II/particles/particle_handler.h @@ -29,6 +29,8 @@ #include +#include + #include #include #include @@ -86,15 +88,12 @@ namespace Particles /** * Destructor. */ - virtual ~ParticleHandler() override - { - connection.disconnect(); - } + virtual ~ParticleHandler() override = default; /** * Initialize the particle handler. This function does not clear the - * internal data structures, it just sets the triangulation and the mapping - * to be used. + * internal data structures, it just sets the triangulation and the + * mapping to be used. */ void initialize(const Triangulation &tria, @@ -598,16 +597,6 @@ namespace Particles void serialize(Archive &ar, const unsigned int version); - /** - * Updates the structures that were generated to search in which cells the - * particles belong to. The call to this function updates the - * vertex_to_cells and the vertex_to_cell_centers data structure. This - * function is called every time the triangulation is altered. - * - */ - void - update_triangulation_cache(); - private: /** * Address of the triangulation to work on. @@ -709,30 +698,15 @@ namespace Particles */ unsigned int handle; - /** - * A connection to the corresponding any_changes signal of the Triangulation - * which is attached to the particle_handler - */ - boost::signals2::connection connection; - - /** This variable stores a set from vertices to adjacent cells. It is used - * to locate the cells in which the particle reside. This structured is kept - * in memory to prevent its recalculation every time we - * sort_into_subdomain_and_cells(). This structure is updated everytime - * we call update_triangulation_cache. - */ - std::vector< - std::set::active_cell_iterator>> - vertex_to_cells; - - - /** This variable stores a vector of vectors to cell centers. It is used - * to locate the cells in which the particle reside. This structured is kept - * in memory to prevent its recalculation every time we - * sort_into_subdomain_and_cells(). This structure is updated everytime - * we call update_triangulation_cache. + /** The GridTools::Cache is used to store the information about the + * vertex_to_cells set and the vertex_to_cell_centers vectors to prevent + * recomputing them every time we sort_into_subdomain_and_cells() + * This cache is automatically updated when the triangulation has + * changed. This cache is stored within a unique pointer because the + * particle handler has a constructor that enables it to be constructed + * without a triangulation. The cache does not have such a constructor. */ - std::vector>> vertex_to_cell_centers; + std::unique_ptr> triangulation_cache; #ifdef DEAL_II_WITH_MPI /** diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 90b8729b50..880b85b185 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -120,13 +120,9 @@ namespace Particles , load_callback() , handle(numbers::invalid_unsigned_int) { - // Update the triangulation cache to ensure that you can sort the particles - // correctly - update_triangulation_cache(); - - connection = triangulation.signals.any_change.connect( - std::bind(&ParticleHandler::update_triangulation_cache, - std::ref(*this))); + triangulation_cache = + std_cxx14::make_unique>(triangulation, + mapping); } @@ -144,13 +140,11 @@ namespace Particles // Create the memory pool that will store all particle properties property_pool = std_cxx14::make_unique(n_properties); - // Update the triangulation cache to ensure that you can sort the particles - // correctly - update_triangulation_cache(); - - connection = triangulation->signals.any_change.connect( - std::bind(&ParticleHandler::update_triangulation_cache, - std::ref(*this))); + // Create the grid cache to cache the informations about the triangulation + // that is used to locate the particles into subdomains and cells + triangulation_cache = + std_cxx14::make_unique>(new_triangulation, + new_mapping); } @@ -926,7 +920,16 @@ namespace Particles static_cast(particles_out_of_cell.size() * 0.25)); { - // update_triangulation_cache(); + // Create a map from vertices to adjacent cells using grid cache + std::vector< + std::set::active_cell_iterator>> + vertex_to_cells = triangulation_cache->get_vertex_to_cell_map(); + + // Create a corresponding map of vectors from vertex to cell center using + // grid cache + std::vector>> vertex_to_cell_centers = + triangulation_cache->get_vertex_to_cell_centers_directions(); + std::vector neighbor_permutation; // Find the cells that the particles moved to. @@ -1751,21 +1754,6 @@ namespace Particles break; } } - - template - void - ParticleHandler::update_triangulation_cache() - { - // Create a map from vertices to adjacent cells - vertex_to_cells = GridTools::vertex_to_cell_map(*triangulation); - - // Create a corresponding map of vectors from vertex to cell center - vertex_to_cell_centers = - GridTools::vertex_to_cell_centers_directions(*triangulation, - vertex_to_cells); - } - - } // namespace Particles #include "particle_handler.inst"