From aa3bfcae846dabd6c15f004c68633621c46ee95d Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Wed, 8 Dec 2021 09:11:59 +0100 Subject: [PATCH] Clean up --- .../distributed/fully_distributed_tria.h | 15 ++++---- source/distributed/fully_distributed_tria.cc | 5 +++ source/grid/tria_description.cc | 36 ++++++++++++------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/include/deal.II/distributed/fully_distributed_tria.h b/include/deal.II/distributed/fully_distributed_tria.h index 318e99f84e..b6337f9a92 100644 --- a/include/deal.II/distributed/fully_distributed_tria.h +++ b/include/deal.II/distributed/fully_distributed_tria.h @@ -19,6 +19,7 @@ #include +#include #include #include @@ -39,12 +40,6 @@ namespace GridTools template struct PeriodicFacePair; } - -namespace RepartitioningPolicyTools -{ - template - class Base; -} #endif namespace parallel @@ -203,7 +198,8 @@ namespace parallel const TriangulationDescription::Settings & settings); /** - * TODO + * Register a partitioner, which is used within the method + * repartition(). */ void set_partitioner( @@ -211,7 +207,8 @@ namespace parallel const TriangulationDescription::Settings & settings); /** - * TODO + * Execute repartitioning and use the partitioner attached by the + * method set_partitioner(); */ void repartition(); @@ -322,7 +319,7 @@ namespace parallel partitioner; /** - * TODO + * Partitioner used during repartition(). */ SmartPointer> partitioner_distributed; diff --git a/source/distributed/fully_distributed_tria.cc b/source/distributed/fully_distributed_tria.cc index 7e6df2b815..ed8766a55f 100644 --- a/source/distributed/fully_distributed_tria.cc +++ b/source/distributed/fully_distributed_tria.cc @@ -327,20 +327,25 @@ namespace parallel void Triangulation::repartition() { + // signal that repartitioning has started this->signals.pre_distributed_repartition(); + // create construction_data with the help of the partitioner const auto construction_data = TriangulationDescription::Utilities:: create_description_from_triangulation( *this, this->partitioner_distributed->partition(*this), this->settings); + // clear old content this->clear(); this->coarse_cell_id_to_coarse_cell_index_vector.clear(); this->coarse_cell_index_to_coarse_cell_id_vector.clear(); + // use construction_data to set up new triangulation this->create_triangulation(construction_data); + // signal that repartitioning has completed this->signals.post_distributed_repartition(); } diff --git a/source/grid/tria_description.cc b/source/grid/tria_description.cc index e8c5041c0b..ceccb8d8e6 100644 --- a/source/grid/tria_description.cc +++ b/source/grid/tria_description.cc @@ -158,8 +158,9 @@ namespace TriangulationDescription this->cell_infos.resize( std::max(other.cell_infos.size(), this->cell_infos.size())); - if (vertices_have_unique_ids == false) + if (vertices_have_unique_ids == false) // need to compare points { + // comparator of points const auto comp = [](const auto &a, const auto &b) { const double tolerance = 1e-10; @@ -170,31 +171,40 @@ namespace TriangulationDescription return false; }; - std::map, unsigned int, decltype(comp)> map(comp); - std::map map_i; + // map point to local vertex index + std::map, unsigned int, decltype(comp)> + map_point_to_local_vertex_index(comp); + // ... initialize map with existing points for (unsigned int i = 0; i < this->coarse_cell_vertices.size(); ++i) - map[coarse_cell_vertices[i].second] = i; + map_point_to_local_vertex_index[coarse_cell_vertices[i] + .second] = i; - unsigned int counter = coarse_cell_vertices.size(); + // map local vertex indices within other to the new local indices + std::map + map_old_to_new_local_vertex_index; - for (const auto p : other.coarse_cell_vertices) - if (map.find(p.second) == map.end()) + // 1) renumerate vertices in other and insert into maps + unsigned int counter = coarse_cell_vertices.size(); + for (const auto &p : other.coarse_cell_vertices) + if (map_point_to_local_vertex_index.find(p.second) == + map_point_to_local_vertex_index.end()) { this->coarse_cell_vertices.emplace_back(counter, p.second); - map[p.second] = map_i[p.first] = counter++; + map_point_to_local_vertex_index[p.second] = + map_old_to_new_local_vertex_index[p.first] = counter++; } else - map_i[p.first] = map[p.second]; + map_old_to_new_local_vertex_index[p.first] = + map_point_to_local_vertex_index[p.second]; + // 2) renumerate vertices of cells auto other_coarse_cells_copy = other.coarse_cells; for (auto &cell : other_coarse_cells_copy) - { - for (auto &v : cell.vertices) - v = map_i[v]; - } + for (auto &v : cell.vertices) + v = map_old_to_new_local_vertex_index[v]; this->coarse_cells.insert(this->coarse_cells.end(), other_coarse_cells_copy.begin(), -- 2.39.5