}
} // namespace
+
+ template <int dim, int spacedim>
+ DefaultPolicy<dim, spacedim>::DefaultPolicy(const bool tighten)
+ : tighten(tighten)
+ {}
+
template <int dim, int spacedim>
LinearAlgebra::distributed::Vector<double>
DefaultPolicy<dim, spacedim>::partition(
- const Triangulation<dim, spacedim> &) const
+ const Triangulation<dim, spacedim> &tria_in) const
{
- return {}; // nothing to do
+ if (tighten == false)
+ return {}; // nothing to do
+
+ const auto tria =
+ dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
+ &tria_in);
+
+ if (tria == nullptr)
+ return {}; // nothing to do, since serial triangulation
+
+#ifndef DEAL_II_WITH_MPI
+ Assert(false, ExcNeedsMPI());
+ return {};
+#else
+
+ const auto comm = tria->get_communicator();
+
+ const unsigned int process_has_active_locally_owned_cells =
+ tria->n_locally_owned_active_cells() > 0;
+ const unsigned int n_processes_with_active_locally_owned_cells =
+ Utilities::MPI::sum(process_has_active_locally_owned_cells, comm);
+
+ if (n_processes_with_active_locally_owned_cells ==
+ Utilities::MPI::n_mpi_processes(comm))
+ return {}; // nothing to do, since all processes have cells
+
+ unsigned int offset = 0;
+
+ const int ierr = MPI_Exscan(&process_has_active_locally_owned_cells,
+ &offset,
+ 1,
+ Utilities::MPI::internal::mpi_type_id(
+ &process_has_active_locally_owned_cells),
+ MPI_SUM,
+ comm);
+ AssertThrowMPI(ierr);
+
+ LinearAlgebra::distributed::Vector<double> partition(
+ tria->global_active_cell_index_partitioner().lock());
+
+ partition = offset;
+
+ return partition;
+#endif
}
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// 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 RepartitioningPolicyTools::DefaultPolicy's tightening functionality.
+
+#include <deal.II/base/mpi_consensus_algorithms.h>
+
+#include <deal.II/distributed/fully_distributed_tria.h>
+#include <deal.II/distributed/repartitioning_policy_tools.h>
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/fe/fe_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_out.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/grid/tria_description.h>
+
+#include <deal.II/lac/la_parallel_vector.h>
+
+#include <deal.II/numerics/data_out.h>
+
+#include "./tests.h"
+
+using namespace dealii;
+
+template <int dim>
+void
+test(const MPI_Comm comm)
+{
+ parallel::shared::Triangulation<dim> tria(
+ comm,
+ Triangulation<dim>::none,
+ true,
+ parallel::shared::Triangulation<dim>::partition_custom_signal);
+
+ tria.signals.create.connect([&tria]() {
+ for (const auto &cell : tria.active_cell_iterators())
+ {
+ switch (cell->active_cell_index())
+ {
+ case 0:
+ cell->set_subdomain_id(0);
+ break;
+ case 1:
+ case 2:
+ cell->set_subdomain_id(2);
+ break;
+ case 3:
+ cell->set_subdomain_id(3);
+ break;
+ }
+ }
+ });
+
+ GridGenerator::subdivided_hyper_cube(tria, 2);
+
+ const auto construction_data =
+ TriangulationDescription::Utilities::create_description_from_triangulation(
+ tria,
+ RepartitioningPolicyTools::DefaultPolicy<dim>(true).partition(tria));
+
+ parallel::fullydistributed::Triangulation<dim> tria_pft(comm);
+ tria_pft.create_triangulation(construction_data);
+
+ deallog << tria.n_locally_owned_active_cells() << " "
+ << tria_pft.n_locally_owned_active_cells() << std::endl;
+}
+
+
+
+int
+main(int argc, char **argv)
+{
+ Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1);
+ MPILogInitAll all;
+
+ MPI_Comm comm = MPI_COMM_WORLD;
+
+ deallog.push("all");
+ test<2>(comm);
+ deallog.pop();
+}