#include <deal.II/base/config.h>
+#include <deal.II/distributed/repartitioning_policy_tools.h>
#include <deal.II/distributed/tria_base.h>
#include <deal.II/grid/grid_tools.h>
template <typename CellIterator>
struct PeriodicFacePair;
}
-
-namespace RepartitioningPolicyTools
-{
- template <int dim, int spacedim>
- class Base;
-}
#endif
namespace parallel
const TriangulationDescription::Settings & settings);
/**
- * TODO
+ * Register a partitioner, which is used within the method
+ * repartition().
*/
void
set_partitioner(
const TriangulationDescription::Settings & settings);
/**
- * TODO
+ * Execute repartitioning and use the partitioner attached by the
+ * method set_partitioner();
*/
void
repartition();
partitioner;
/**
- * TODO
+ * Partitioner used during repartition().
*/
SmartPointer<const RepartitioningPolicyTools::Base<dim, spacedim>>
partitioner_distributed;
void
Triangulation<dim, spacedim>::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();
}
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;
return false;
};
- std::map<Point<spacedim>, unsigned int, decltype(comp)> map(comp);
- std::map<unsigned int, unsigned int> map_i;
+ // map point to local vertex index
+ std::map<Point<spacedim>, 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<unsigned int, unsigned int>
+ 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(),