#include <deal.II/base/mpi.h>
#include <deal.II/distributed/fully_distributed_tria.h>
+#include <deal.II/distributed/repartitioning_policy_tools.h>
#include <deal.II/grid/grid_tools.h>
+ template <int dim, int spacedim>
+ void
+ Triangulation<dim, spacedim>::set_partitioner(
+ const RepartitioningPolicyTools::Base<dim, spacedim> &partitioner,
+ const TriangulationDescription::Settings & settings)
+ {
+ this->partitioner_distributed = &partitioner;
+ this->settings = settings;
+ }
+
+
+
+ template <int dim, int spacedim>
+ void
+ Triangulation<dim, spacedim>::repartition()
+ {
+ this->signals.pre_distributed_repartition();
+
+ const auto construction_data = TriangulationDescription::Utilities::
+ create_description_from_triangulation(
+ *this,
+ this->partitioner_distributed->partition(*this),
+ this->settings);
+
+ this->create_triangulation(construction_data);
+
+ this->signals.post_distributed_repartition();
+ }
+
+
+
template <int dim, int spacedim>
void
Triangulation<dim, spacedim>::execute_coarsening_and_refinement()
#include <deal.II/base/mpi.h>
#include <deal.II/base/mpi_consensus_algorithms.h>
+#include <deal.II/distributed/fully_distributed_tria.h>
#include <deal.II/distributed/tria.h>
#include <deal.II/dofs/dof_accessor.h>
collect(
const std::vector<unsigned int> & relevant_processes,
const std::vector<DescriptionTemp<dim, spacedim>> &description_temp,
- const MPI_Comm & comm)
+ const MPI_Comm & comm,
+ const bool vertices_have_unique_ids)
{
dealii::Utilities::MPI::ConsensusAlgorithms::AnonymousProcess<char,
char>
std::vector<char> &) {
this->merge(
dealii::Utilities::unpack<DescriptionTemp<dim, spacedim>>(
- recv_buffer, false));
+ recv_buffer, false),
+ vertices_have_unique_ids);
});
dealii::Utilities::MPI::ConsensusAlgorithms::Selector<char, char>(
* This done by the reduce() function.
*/
void
- merge(const DescriptionTemp<dim, spacedim> &other)
+ merge(const DescriptionTemp<dim, spacedim> &other,
+ const bool vertices_have_unique_ids)
{
this->cell_infos.resize(
std::max(other.cell_infos.size(), this->cell_infos.size()));
- this->coarse_cells.insert(this->coarse_cells.end(),
- other.coarse_cells.begin(),
- other.coarse_cells.end());
- this->coarse_cell_vertices.insert(this->coarse_cell_vertices.end(),
- other.coarse_cell_vertices.begin(),
- other.coarse_cell_vertices.end());
+ if (vertices_have_unique_ids == false)
+ {
+ const auto comp = [](const auto &a, const auto &b) {
+ const double tolerance = 1e-10;
+
+ if (a.distance(b) < tolerance)
+ return false;
+
+ for (unsigned int i = 0; i < spacedim; ++i)
+ if (std::abs(a[i] - b[i]) > tolerance)
+ return a[i] < b[i];
+
+ return false;
+ };
+
+ std::map<Point<spacedim>, unsigned int, decltype(comp)> map(comp);
+ std::map<unsigned int, unsigned int> map_i;
+
+ for (unsigned int i = 0; i < this->coarse_cell_vertices.size();
+ ++i)
+ map[coarse_cell_vertices[i].second] = i;
+
+ unsigned int counter = coarse_cell_vertices.size();
+
+ for (const auto p : other.coarse_cell_vertices)
+ if (map.find(p.second) == map.end())
+ {
+ this->coarse_cell_vertices.emplace_back(counter, p.second);
+ map[p.second] = map_i[p.first] = counter++;
+ }
+ else
+ map_i[p.first] = map[p.second];
+
+ for (auto cell : other.coarse_cells)
+ {
+ for (auto &v : cell.vertices)
+ v = map_i[v];
+ }
+
+ this->coarse_cells.insert(this->coarse_cells.end(),
+ other.coarse_cells.begin(),
+ other.coarse_cells.end());
+ }
+ else
+ {
+ this->coarse_cells.insert(this->coarse_cells.end(),
+ other.coarse_cells.begin(),
+ other.coarse_cells.end());
+ this->coarse_cell_vertices.insert(
+ this->coarse_cell_vertices.end(),
+ other.coarse_cell_vertices.begin(),
+ other.coarse_cell_vertices.end());
+ }
+
this->coarse_cell_index_to_coarse_cell_id.insert(
this->coarse_cell_index_to_coarse_cell_id.end(),
other.coarse_cell_index_to_coarse_cell_id.begin(),
// collect description from all processes that used to own locally-owned
// active cells of this process in a single description
DescriptionTemp<dim, spacedim> description_merged;
- description_merged.collect(relevant_processes,
- descriptions_per_rank,
- partition.get_mpi_communicator());
+ description_merged.collect(
+ relevant_processes,
+ descriptions_per_rank,
+ partition.get_mpi_communicator(),
+ dynamic_cast<
+ const parallel::fullydistributed::Triangulation<dim, spacedim> *>(
+ &tria) != nullptr);
// remove redundant entries
description_merged.reduce();