16 #include <deal.II/base/mpi.h> 17 #include <deal.II/base/utilities.h> 19 #include <deal.II/distributed/shared_tria.h> 20 #include <deal.II/distributed/tria.h> 22 #include <deal.II/grid/filtered_iterator.h> 23 #include <deal.II/grid/grid_tools.h> 24 #include <deal.II/grid/tria.h> 25 #include <deal.II/grid/tria_accessor.h> 26 #include <deal.II/grid/tria_iterator.h> 28 #include <deal.II/lac/sparsity_tools.h> 31 DEAL_II_NAMESPACE_OPEN
33 #ifdef DEAL_II_WITH_MPI 38 template <
int dim,
int spacedim>
40 MPI_Comm mpi_communicator,
41 const typename ::Triangulation<dim, spacedim>::MeshSmoothing
43 const bool allow_artificial_cells,
49 , allow_artificial_cells(allow_artificial_cells)
51 const auto partition_settings =
55 (void)partition_settings;
61 ExcMessage(
"Settings must contain exactly one type of the active " 62 "cell partitioning scheme."));
66 ExcMessage(
"construct_multigrid_hierarchy requires " 67 "allow_artificial_cells to be set to true."));
72 template <
int dim,
int spacedim>
79 const unsigned int max_active_cells =
82 max_active_cells == this->n_active_cells(),
84 "A parallel::shared::Triangulation needs to be refined in the same" 85 "way on all processors, but the participating processors don't " 86 "agree on the number of active cells."));
89 auto partition_settings = (partition_zoltan | partition_metis |
90 partition_zorder | partition_custom_signal) &
92 if (partition_settings == partition_auto)
93 # ifdef DEAL_II_TRILINOS_WITH_ZOLTAN 94 partition_settings = partition_zoltan;
95 # elif defined DEAL_II_WITH_METIS 96 partition_settings = partition_metis;
98 partition_settings = partition_zorder;
101 if (partition_settings == partition_zoltan)
103 # ifndef DEAL_II_TRILINOS_WITH_ZOLTAN 106 "Choosing 'partition_zoltan' requires the library " 107 "to be compiled with support for Zoltan! " 108 "Instead, you might use 'partition_auto' to select " 109 "a partitioning algorithm that is supported " 110 "by your current configuration."));
116 else if (partition_settings == partition_metis)
118 # ifndef DEAL_II_WITH_METIS 121 "Choosing 'partition_metis' requires the library " 122 "to be compiled with support for METIS! " 123 "Instead, you might use 'partition_auto' to select " 124 "a partitioning algorithm that is supported " 125 "by your current configuration."));
132 else if (partition_settings == partition_zorder)
136 else if (partition_settings == partition_custom_signal)
147 if ((settings & construct_multigrid_hierarchy) &&
148 !(settings & partition_custom_signal))
149 ::GridTools::partition_multigrid_levels(*
this);
151 true_subdomain_ids_of_cells.resize(this->n_active_cells());
155 spacedim>::active_cell_iterator
156 cell = this->begin_active(),
159 if (allow_artificial_cells)
165 active_cell_iterator &)>
170 spacedim>::active_cell_iterator>
171 active_halo_layer_vector =
172 ::GridTools::compute_active_cell_halo_layer(*
this,
174 std::set<typename parallel::shared::Triangulation<dim, spacedim>::
175 active_cell_iterator>
176 active_halo_layer(active_halo_layer_vector.begin(),
177 active_halo_layer_vector.end());
179 for (
unsigned int index = 0; cell != endc; cell++, index++)
182 true_subdomain_ids_of_cells[index] = cell->subdomain_id();
184 if (cell->is_locally_owned() ==
false &&
185 active_halo_layer.find(cell) == active_halo_layer.end())
190 if (settings & construct_multigrid_hierarchy)
192 true_level_subdomain_ids_of_cells.resize(this->n_levels());
198 for (
unsigned int lvl = 0; lvl < this->n_levels(); ++lvl)
200 true_level_subdomain_ids_of_cells[lvl].resize(
205 spacedim>::cell_iterator>
206 level_halo_layer_vector =
207 ::GridTools::compute_cell_halo_layer_on_level(
208 *
this, predicate, lvl);
209 std::set<
typename parallel::shared::
210 Triangulation<dim, spacedim>::cell_iterator>
211 level_halo_layer(level_halo_layer_vector.begin(),
212 level_halo_layer_vector.end());
215 cell_iterator cell = this->begin(lvl),
216 endc = this->end(lvl);
217 for (
unsigned int index = 0; cell != endc; cell++, index++)
221 true_level_subdomain_ids_of_cells[lvl][index] =
222 cell->level_subdomain_id();
231 if (!cell->has_children() &&
232 cell->subdomain_id() !=
237 if (cell->has_children())
239 bool keep_cell =
false;
240 for (
unsigned int c = 0;
241 c < GeometryInfo<dim>::max_children_per_cell;
243 if (cell->child(c)->level_subdomain_id() ==
255 if (!cell->is_locally_owned_on_level() &&
256 level_halo_layer.find(cell) != level_halo_layer.end())
260 cell->set_level_subdomain_id(
269 for (
unsigned int index = 0; cell != endc; cell++, index++)
270 true_subdomain_ids_of_cells[index] = cell->subdomain_id();
276 unsigned int n_my_cells = 0;
278 spacedim>::active_cell_iterator
279 cell = this->begin_active(),
281 for (; cell != endc; ++cell)
282 if (cell->is_locally_owned())
285 const unsigned int total_cells =
287 Assert(total_cells == this->n_active_cells(),
288 ExcMessage(
"Not all cells are assigned to a processor."));
293 if (settings & construct_multigrid_hierarchy)
295 unsigned int n_my_cells = 0;
296 typename parallel::shared::Triangulation<dim, spacedim>::cell_iterator
297 cell = this->begin(),
299 for (; cell != endc; ++cell)
300 if (cell->is_locally_owned_on_level())
303 const unsigned int total_cells =
305 Assert(total_cells == this->n_cells(),
306 ExcMessage(
"Not all cells are assigned to a processor."));
313 template <
int dim,
int spacedim>
317 return allow_artificial_cells;
322 template <
int dim,
int spacedim>
323 const std::vector<types::subdomain_id> &
326 return true_subdomain_ids_of_cells;
331 template <
int dim,
int spacedim>
332 const std::vector<types::subdomain_id> &
334 const unsigned int level)
const 336 Assert(level < true_level_subdomain_ids_of_cells.size(),
338 Assert(true_level_subdomain_ids_of_cells[level].size() ==
339 this->n_cells(level),
341 return true_level_subdomain_ids_of_cells[level];
346 template <
int dim,
int spacedim>
352 this->update_number_cache();
357 template <
int dim,
int spacedim>
367 vertices, cells, subcelldata);
370 const typename ::Triangulation<dim, spacedim>::DistortedCellList
378 this->update_number_cache();
383 template <
int dim,
int spacedim>
386 const ::Triangulation<dim, spacedim> &other_tria)
390 const ::parallel::distributed::Triangulation<dim, spacedim> *
>(
391 &other_tria) ==
nullptr),
393 "Cannot use this function on parallel::distributed::Triangulation."));
398 this->update_number_cache();
403 template <
int dim,
int spacedim>
409 if (settings & construct_multigrid_hierarchy)
421 template <
int dim,
int spacedim>
431 template <
int dim,
int spacedim>
432 const std::vector<unsigned int> &
436 return true_subdomain_ids_of_cells;
441 template <
int dim,
int spacedim>
442 const std::vector<unsigned int> &
444 const unsigned int)
const 447 return true_level_subdomain_ids_of_cells;
457 #include "shared_tria.inst" 459 DEAL_II_NAMESPACE_CLOSE
const std::vector< types::subdomain_id > & get_true_subdomain_ids_of_cells() const
Triangulation(MPI_Comm mpi_communicator, const typename ::Triangulation< dim, spacedim >::MeshSmoothing=(::Triangulation< dim, spacedim >::none), const bool allow_artificial_cells=false, const Settings settings=partition_auto)
void fill_level_ghost_owners()
virtual void execute_coarsening_and_refinement() override
#define AssertThrow(cond, exc)
const std::vector< types::subdomain_id > & get_true_level_subdomain_ids_of_cells(const unsigned int level) const
virtual void execute_coarsening_and_refinement()
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria) override
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual void update_number_cache() override
T sum(const T &t, const MPI_Comm &mpi_communicator)
virtual void create_triangulation(const std::vector< Point< spacedim >> &vertices, const std::vector< CellData< dim >> &cells, const SubCellData &subcelldata)
#define Assert(cond, exc)
virtual void update_number_cache()
const bool allow_artificial_cells
const types::subdomain_id artificial_subdomain_id
__global__ void set(Number *val, const Number s, const size_type N)
virtual void create_triangulation(const std::vector< Point< spacedim >> &vertices, const std::vector< CellData< dim >> &cells, const SubCellData &subcelldata) override
bool with_artificial_cells() const
static ::ExceptionBase & ExcNotImplemented()
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &other_tria) override
T max(const T &t, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcInternalError()