From ff5d85837f94fe24b3117540a62c71599940b9ee Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 9 May 2019 10:01:36 -0600 Subject: [PATCH] Apply the same logic in the other place where we call the cell weight signal. --- source/grid/grid_tools.cc | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 0d9d9e862b..905609f536 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -2740,21 +2740,40 @@ namespace GridTools Triangulation &triangulation, const SparsityTools::Partitioner partitioner) { + Assert((dynamic_cast *>( + &triangulation) == nullptr), + ExcMessage("Objects of type parallel::distributed::Triangulation " + "are already partitioned implicitly and can not be " + "partitioned again explicitly.")); + std::vector cell_weights; // Get cell weighting if a signal has been attached to the triangulation if (!triangulation.signals.cell_weight.empty()) { - cell_weights.resize(triangulation.n_active_cells(), - std::numeric_limits::max()); + cell_weights.resize(triangulation.n_active_cells(), 0U); - unsigned int c = 0; - typename Triangulation::active_cell_iterator - cell = triangulation.begin_active(), - endc = triangulation.end(); - for (; cell != endc; ++cell, ++c) - cell_weights[c] = triangulation.signals.cell_weight( - cell, Triangulation::CellStatus::CELL_PERSIST); + // In a first step, obtain the weights of the locally owned + // cells. For all others, the weight remains at the zero the + // vector was initialized with above. + for (const auto &cell : triangulation.active_cell_iterators()) + if (cell->is_locally_owned()) + cell_weights[cell->active_cell_index()] = + triangulation.signals.cell_weight( + cell, Triangulation::CellStatus::CELL_PERSIST); + + // If this is a parallel triangulation, we then need to also + // get the weights for all other cells. We have asserted above + // that this function can't be used for + // parallel::distribute::Triangulation objects, so the only + // ones we have to worry about here are + // parallel::shared::Triangulation + if (const auto shared_tria = + dynamic_cast *>( + &triangulation)) + Utilities::MPI::sum(cell_weights, + shared_tria->get_communicator(), + cell_weights); } // Call the other more general function -- 2.39.5