}
+
+ template <int dim, int spacedim>
+ CellWeightPolicy<dim, spacedim>::CellWeightPolicy(
+ const std::function<
+ unsigned int(const typename Triangulation<dim, spacedim>::cell_iterator &,
+ const typename Triangulation<dim, spacedim>::CellStatus)>
+ &weighting_function)
+ : weighting_function(weighting_function)
+ {}
+
+
+
+ template <int dim, int spacedim>
+ LinearAlgebra::distributed::Vector<double>
+ CellWeightPolicy<dim, spacedim>::partition(
+ const Triangulation<dim, spacedim> &tria_in) const
+ {
+#ifndef DEAL_II_WITH_MPI
+ (void)tria_in;
+ return {};
+#else
+
+ const auto tria =
+ dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
+ &tria_in);
+
+ Assert(tria, ExcNotImplemented());
+
+ const auto partitioner =
+ tria->global_active_cell_index_partitioner().lock();
+
+ std::vector<unsigned int> weights(partitioner->local_size());
+
+ const auto mpi_communicator = tria_in.get_communicator();
+ const auto n_subdomains = Utilities::MPI::n_mpi_processes(mpi_communicator);
+
+ // determine weight of each cell
+ for (const auto &cell : tria->active_cell_iterators())
+ if (cell->is_locally_owned())
+ weights[partitioner->global_to_local(
+ cell->global_active_cell_index())] =
+ weighting_function(
+ cell, Triangulation<dim, spacedim>::CellStatus::CELL_PERSIST);
+
+ // determine weight of all the cells locally owned by this process
+ types::global_cell_index process_local_weight = 0;
+ for (const auto &weight : weights)
+ process_local_weight += weight;
+
+ // determine partial sum of weights of this process
+ types::global_cell_index process_local_weight_offset = 0;
+
+ int ierr =
+ MPI_Exscan(&process_local_weight,
+ &process_local_weight_offset,
+ 1,
+ Utilities::MPI::internal::mpi_type_id(&process_local_weight),
+ MPI_SUM,
+ tria->get_communicator());
+ AssertThrowMPI(ierr);
+
+ // total weight of all processes
+ types::global_cell_index total_weight =
+ process_local_weight_offset + process_local_weight;
+
+ ierr = MPI_Bcast(&total_weight,
+ 1,
+ Utilities::MPI::internal::mpi_type_id(&total_weight),
+ n_subdomains - 1,
+ mpi_communicator);
+
+ // setup partition
+ LinearAlgebra::distributed::Vector<double> partition(partitioner);
+
+ for (types::global_cell_index i = 0, weight = process_local_weight_offset;
+ i < partition.locally_owned_size();
+ weight += weights[i], ++i)
+ partition.local_element(i) =
+ static_cast<double>(weight * n_subdomains / total_weight);
+
+ return partition;
+#endif
+ }
+
+
} // namespace RepartitioningPolicyTools
DEAL:0:grid_policy_minimal::n_dofs: 4813
DEAL:0:grid_policy_minimal::n_locally_owned_dofs: 993
DEAL:0:grid_policy_minimal::
+DEAL:0:grid_policy_weight::n_levels: 1
+DEAL:0:grid_policy_weight::n_cells: 1
+DEAL:0:grid_policy_weight::n_active_cells: 1
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_dofs: 9
+DEAL:0:grid_policy_weight::n_locally_owned_dofs: 9
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_levels: 2
+DEAL:0:grid_policy_weight::n_cells: 5
+DEAL:0:grid_policy_weight::n_active_cells: 4
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_dofs: 25
+DEAL:0:grid_policy_weight::n_locally_owned_dofs: 15
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_levels: 3
+DEAL:0:grid_policy_weight::n_cells: 9
+DEAL:0:grid_policy_weight::n_active_cells: 7
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_dofs: 43
+DEAL:0:grid_policy_weight::n_locally_owned_dofs: 21
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_levels: 4
+DEAL:0:grid_policy_weight::n_cells: 33
+DEAL:0:grid_policy_weight::n_active_cells: 25
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_dofs: 141
+DEAL:0:grid_policy_weight::n_locally_owned_dofs: 51
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_levels: 5
+DEAL:0:grid_policy_weight::n_cells: 93
+DEAL:0:grid_policy_weight::n_active_cells: 70
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_dofs: 423
+DEAL:0:grid_policy_weight::n_locally_owned_dofs: 137
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_levels: 6
+DEAL:0:grid_policy_weight::n_cells: 233
+DEAL:0:grid_policy_weight::n_active_cells: 175
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_dofs: 1353
+DEAL:0:grid_policy_weight::n_locally_owned_dofs: 421
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_levels: 7
+DEAL:0:grid_policy_weight::n_cells: 465
+DEAL:0:grid_policy_weight::n_active_cells: 349
+DEAL:0:grid_policy_weight::
+DEAL:0:grid_policy_weight::n_dofs: 4813
+DEAL:0:grid_policy_weight::n_locally_owned_dofs: 993
+DEAL:0:grid_policy_weight::
DEAL:1:grid_policy_default::n_levels: 1
DEAL:1:grid_policy_default::n_cells: 1
DEAL:1:grid_policy_minimal::n_dofs: 4813
DEAL:1:grid_policy_minimal::n_locally_owned_dofs: 944
DEAL:1:grid_policy_minimal::
+DEAL:1:grid_policy_weight::n_levels: 1
+DEAL:1:grid_policy_weight::n_cells: 1
+DEAL:1:grid_policy_weight::n_active_cells: 1
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_dofs: 9
+DEAL:1:grid_policy_weight::n_locally_owned_dofs: 0
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_levels: 2
+DEAL:1:grid_policy_weight::n_cells: 5
+DEAL:1:grid_policy_weight::n_active_cells: 4
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_dofs: 25
+DEAL:1:grid_policy_weight::n_locally_owned_dofs: 6
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_levels: 3
+DEAL:1:grid_policy_weight::n_cells: 9
+DEAL:1:grid_policy_weight::n_active_cells: 7
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_dofs: 43
+DEAL:1:grid_policy_weight::n_locally_owned_dofs: 4
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_levels: 4
+DEAL:1:grid_policy_weight::n_cells: 37
+DEAL:1:grid_policy_weight::n_active_cells: 28
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_dofs: 141
+DEAL:1:grid_policy_weight::n_locally_owned_dofs: 30
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_levels: 5
+DEAL:1:grid_policy_weight::n_cells: 105
+DEAL:1:grid_policy_weight::n_active_cells: 79
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_dofs: 423
+DEAL:1:grid_policy_weight::n_locally_owned_dofs: 96
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_levels: 6
+DEAL:1:grid_policy_weight::n_cells: 289
+DEAL:1:grid_policy_weight::n_active_cells: 217
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_dofs: 1353
+DEAL:1:grid_policy_weight::n_locally_owned_dofs: 328
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_levels: 7
+DEAL:1:grid_policy_weight::n_cells: 577
+DEAL:1:grid_policy_weight::n_active_cells: 433
+DEAL:1:grid_policy_weight::
+DEAL:1:grid_policy_weight::n_dofs: 4813
+DEAL:1:grid_policy_weight::n_locally_owned_dofs: 944
+DEAL:1:grid_policy_weight::
DEAL:2:grid_policy_default::n_levels: 1
DEAL:2:grid_policy_minimal::n_dofs: 4813
DEAL:2:grid_policy_minimal::n_locally_owned_dofs: 960
DEAL:2:grid_policy_minimal::
+DEAL:2:grid_policy_weight::n_levels: 1
+DEAL:2:grid_policy_weight::n_cells: 1
+DEAL:2:grid_policy_weight::n_active_cells: 1
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_dofs: 9
+DEAL:2:grid_policy_weight::n_locally_owned_dofs: 0
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_levels: 1
+DEAL:2:grid_policy_weight::n_cells: 1
+DEAL:2:grid_policy_weight::n_active_cells: 1
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_dofs: 25
+DEAL:2:grid_policy_weight::n_locally_owned_dofs: 0
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_levels: 3
+DEAL:2:grid_policy_weight::n_cells: 9
+DEAL:2:grid_policy_weight::n_active_cells: 7
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_dofs: 43
+DEAL:2:grid_policy_weight::n_locally_owned_dofs: 7
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_levels: 4
+DEAL:2:grid_policy_weight::n_cells: 29
+DEAL:2:grid_policy_weight::n_active_cells: 22
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_dofs: 141
+DEAL:2:grid_policy_weight::n_locally_owned_dofs: 22
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_levels: 5
+DEAL:2:grid_policy_weight::n_cells: 93
+DEAL:2:grid_policy_weight::n_active_cells: 70
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_dofs: 423
+DEAL:2:grid_policy_weight::n_locally_owned_dofs: 70
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_levels: 6
+DEAL:2:grid_policy_weight::n_cells: 241
+DEAL:2:grid_policy_weight::n_active_cells: 181
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_dofs: 1353
+DEAL:2:grid_policy_weight::n_locally_owned_dofs: 203
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_levels: 7
+DEAL:2:grid_policy_weight::n_cells: 665
+DEAL:2:grid_policy_weight::n_active_cells: 499
+DEAL:2:grid_policy_weight::
+DEAL:2:grid_policy_weight::n_dofs: 4813
+DEAL:2:grid_policy_weight::n_locally_owned_dofs: 960
+DEAL:2:grid_policy_weight::
DEAL:3:grid_policy_default::n_levels: 1
DEAL:3:grid_policy_minimal::n_dofs: 4813
DEAL:3:grid_policy_minimal::n_locally_owned_dofs: 912
DEAL:3:grid_policy_minimal::
+DEAL:3:grid_policy_weight::n_levels: 1
+DEAL:3:grid_policy_weight::n_cells: 1
+DEAL:3:grid_policy_weight::n_active_cells: 1
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_dofs: 9
+DEAL:3:grid_policy_weight::n_locally_owned_dofs: 0
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_levels: 2
+DEAL:3:grid_policy_weight::n_cells: 5
+DEAL:3:grid_policy_weight::n_active_cells: 4
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_dofs: 25
+DEAL:3:grid_policy_weight::n_locally_owned_dofs: 4
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_levels: 3
+DEAL:3:grid_policy_weight::n_cells: 9
+DEAL:3:grid_policy_weight::n_active_cells: 7
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_dofs: 43
+DEAL:3:grid_policy_weight::n_locally_owned_dofs: 7
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_levels: 4
+DEAL:3:grid_policy_weight::n_cells: 29
+DEAL:3:grid_policy_weight::n_active_cells: 22
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_dofs: 141
+DEAL:3:grid_policy_weight::n_locally_owned_dofs: 22
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_levels: 5
+DEAL:3:grid_policy_weight::n_cells: 81
+DEAL:3:grid_policy_weight::n_active_cells: 61
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_dofs: 423
+DEAL:3:grid_policy_weight::n_locally_owned_dofs: 64
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_levels: 6
+DEAL:3:grid_policy_weight::n_cells: 229
+DEAL:3:grid_policy_weight::n_active_cells: 172
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_dofs: 1353
+DEAL:3:grid_policy_weight::n_locally_owned_dofs: 201
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_levels: 7
+DEAL:3:grid_policy_weight::n_cells: 657
+DEAL:3:grid_policy_weight::n_active_cells: 493
+DEAL:3:grid_policy_weight::
+DEAL:3:grid_policy_weight::n_dofs: 4813
+DEAL:3:grid_policy_weight::n_locally_owned_dofs: 912
+DEAL:3:grid_policy_weight::
DEAL:4:grid_policy_default::n_levels: 1
DEAL:4:grid_policy_minimal::n_dofs: 4813
DEAL:4:grid_policy_minimal::n_locally_owned_dofs: 1004
DEAL:4:grid_policy_minimal::
+DEAL:4:grid_policy_weight::n_levels: 1
+DEAL:4:grid_policy_weight::n_cells: 1
+DEAL:4:grid_policy_weight::n_active_cells: 1
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_dofs: 9
+DEAL:4:grid_policy_weight::n_locally_owned_dofs: 0
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_levels: 1
+DEAL:4:grid_policy_weight::n_cells: 1
+DEAL:4:grid_policy_weight::n_active_cells: 1
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_dofs: 25
+DEAL:4:grid_policy_weight::n_locally_owned_dofs: 0
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_levels: 3
+DEAL:4:grid_policy_weight::n_cells: 9
+DEAL:4:grid_policy_weight::n_active_cells: 7
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_dofs: 43
+DEAL:4:grid_policy_weight::n_locally_owned_dofs: 4
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_levels: 4
+DEAL:4:grid_policy_weight::n_cells: 25
+DEAL:4:grid_policy_weight::n_active_cells: 19
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_dofs: 141
+DEAL:4:grid_policy_weight::n_locally_owned_dofs: 16
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_levels: 5
+DEAL:4:grid_policy_weight::n_cells: 61
+DEAL:4:grid_policy_weight::n_active_cells: 46
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_dofs: 423
+DEAL:4:grid_policy_weight::n_locally_owned_dofs: 56
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_levels: 6
+DEAL:4:grid_policy_weight::n_cells: 189
+DEAL:4:grid_policy_weight::n_active_cells: 142
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_dofs: 1353
+DEAL:4:grid_policy_weight::n_locally_owned_dofs: 200
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_levels: 7
+DEAL:4:grid_policy_weight::n_cells: 541
+DEAL:4:grid_policy_weight::n_active_cells: 406
+DEAL:4:grid_policy_weight::
+DEAL:4:grid_policy_weight::n_dofs: 4813
+DEAL:4:grid_policy_weight::n_locally_owned_dofs: 1004
+DEAL:4:grid_policy_weight::