16 #include <deal.II/base/utilities.h> 17 #include <deal.II/base/mpi.h> 18 #include <deal.II/grid/tria.h> 19 #include <deal.II/grid/tria_accessor.h> 20 #include <deal.II/grid/tria_iterator.h> 21 #include <deal.II/grid/grid_tools.h> 22 #include <deal.II/grid/filtered_iterator.h> 23 #include <deal.II/lac/sparsity_tools.h> 24 #include <deal.II/distributed/shared_tria.h> 25 #include <deal.II/distributed/tria.h> 28 DEAL_II_NAMESPACE_OPEN
30 #ifdef DEAL_II_WITH_MPI 36 template <
int dim,
int spacedim>
38 const typename ::Triangulation<dim,spacedim>::MeshSmoothing smooth_grid,
39 const bool allow_artificial_cells,
43 allow_artificial_cells(allow_artificial_cells)
45 const auto partition_settings
48 (void)partition_settings;
54 ExcMessage (
"Settings must contain exactly one type of the active cell partitioning scheme."))
58 ExcMessage (
"construct_multigrid_hierarchy requires allow_artificial_cells to be set to true."))
63 template <
int dim,
int spacedim>
69 const unsigned int max_active_cells
71 Assert(max_active_cells == this->n_active_cells(),
72 ExcMessage(
"A parallel::shared::Triangulation needs to be refined in the same" 73 "way on all processors, but the participating processors don't " 74 "agree on the number of active cells."))
77 auto partition_settings
78 = (partition_zoltan | partition_metis |
79 partition_zorder | partition_custom_signal) & settings;
80 if (partition_settings == partition_auto)
81 #ifdef DEAL_II_TRILINOS_WITH_ZOLTAN 82 partition_settings = partition_zoltan;
83 #elif defined DEAL_II_WITH_METIS 84 partition_settings = partition_metis;
86 partition_settings = partition_zorder;
89 if (partition_settings == partition_zoltan)
91 #ifndef DEAL_II_TRILINOS_WITH_ZOLTAN 93 ExcMessage(
"Choosing 'partition_zoltan' requires the library " 94 "to be compiled with support for Zoltan! " 95 "Instead, you might use 'partition_auto' to select " 96 "a partitioning algorithm that is supported " 97 "by your current configuration."));
103 else if (partition_settings == partition_metis)
105 #ifndef DEAL_II_WITH_METIS 107 ExcMessage(
"Choosing 'partition_metis' requires the library " 108 "to be compiled with support for METIS! " 109 "Instead, you might use 'partition_auto' to select " 110 "a partitioning algorithm that is supported " 111 "by your current configuration."));
117 else if (partition_settings == partition_zorder)
121 else if (partition_settings == partition_custom_signal)
132 if ((settings & construct_multigrid_hierarchy) && !(settings & partition_custom_signal))
133 ::GridTools::partition_multigrid_levels(*
this);
135 true_subdomain_ids_of_cells.resize(this->n_active_cells());
138 typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
139 cell = this->begin_active(),
142 if (allow_artificial_cells)
146 std::function<bool (const typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator &)> predicate
149 const std::vector<typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator>
150 active_halo_layer_vector = ::GridTools::compute_active_cell_halo_layer (*
this, predicate);
151 std::set<typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator>
152 active_halo_layer(active_halo_layer_vector.begin(), active_halo_layer_vector.end());
154 for (
unsigned int index=0; cell != endc; cell++, index++)
157 true_subdomain_ids_of_cells[index] = cell->subdomain_id();
159 if (cell->is_locally_owned() ==
false &&
160 active_halo_layer.find(cell) == active_halo_layer.
end())
165 if (settings & construct_multigrid_hierarchy)
167 true_level_subdomain_ids_of_cells.resize(this->n_levels());
169 std::function<bool (const typename parallel::shared::Triangulation<dim,spacedim>::cell_iterator &)> predicate
171 for (
unsigned int lvl=0; lvl<this->n_levels(); ++lvl)
173 true_level_subdomain_ids_of_cells[lvl].resize(this->n_cells(lvl));
175 const std::vector<typename parallel::shared::Triangulation<dim,spacedim>::cell_iterator>
176 level_halo_layer_vector = ::GridTools::compute_cell_halo_layer_on_level (*
this, predicate, lvl);
177 std::set<typename parallel::shared::Triangulation<dim,spacedim>::cell_iterator>
178 level_halo_layer(level_halo_layer_vector.begin(), level_halo_layer_vector.end());
180 typename parallel::shared::Triangulation<dim,spacedim>::cell_iterator
181 cell = this->begin(lvl),
182 endc = this->end(lvl);
183 for (
unsigned int index=0; cell != endc; cell++, index++)
186 true_level_subdomain_ids_of_cells[lvl][index] = cell->level_subdomain_id();
197 if (cell->has_children())
199 bool keep_cell =
false;
200 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
201 if (cell->child(c)->level_subdomain_id() == this->my_subdomain)
211 if (!cell->is_locally_owned_on_level() &&
212 level_halo_layer.find(cell) != level_halo_layer.end())
224 for (
unsigned int index=0; cell != endc; cell++, index++)
225 true_subdomain_ids_of_cells[index] = cell->subdomain_id();
231 unsigned int n_my_cells = 0;
232 typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
233 cell = this->begin_active(),
235 for (; cell!=endc; ++cell)
236 if (cell->is_locally_owned())
239 const unsigned int total_cells
241 Assert(total_cells == this->n_active_cells(),
242 ExcMessage(
"Not all cells are assigned to a processor."))
247 if (settings & construct_multigrid_hierarchy)
249 unsigned int n_my_cells = 0;
250 typename parallel::shared::Triangulation<dim,spacedim>::cell_iterator
251 cell = this->begin(),
253 for (; cell!=endc; ++cell)
254 if (cell->is_locally_owned_on_level())
257 const unsigned int total_cells
259 Assert(total_cells == this->n_cells(),
260 ExcMessage(
"Not all cells are assigned to a processor."))
267 template <
int dim,
int spacedim>
271 return allow_artificial_cells;
276 template <
int dim,
int spacedim>
277 const std::vector<types::subdomain_id> &
280 return true_subdomain_ids_of_cells;
285 template <
int dim,
int spacedim>
286 const std::vector<types::subdomain_id> &
289 return true_level_subdomain_ids_of_cells[level];
294 template <
int dim,
int spacedim>
300 this->update_number_cache ();
305 template <
int dim,
int spacedim>
316 catch (
const typename ::Triangulation<dim,spacedim>::DistortedCellList &)
323 this->update_number_cache ();
328 template <
int dim,
int spacedim>
333 Assert ((
dynamic_cast<const ::parallel::distributed::Triangulation<dim,spacedim> *
>(&other_tria) ==
nullptr),
334 ExcMessage(
"Cannot use this function on parallel::distributed::Triangulation."));
338 this->update_number_cache ();
343 template <
int dim,
int spacedim>
350 if (settings & construct_multigrid_hierarchy)
362 template <
int dim,
int spacedim>
372 template <
int dim,
int spacedim>
373 const std::vector<unsigned int> &
377 return true_subdomain_ids_of_cells;
382 template <
int dim,
int spacedim>
383 const std::vector<unsigned int> &
387 return true_level_subdomain_ids_of_cells;
397 #include "shared_tria.inst" 399 DEAL_II_NAMESPACE_CLOSE
virtual void execute_coarsening_and_refinement()
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria)
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 create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
#define AssertThrow(cond, exc)
const std::vector< types::subdomain_id > & get_true_level_subdomain_ids_of_cells(const unsigned int level) const
cell_iterator end() const
virtual void execute_coarsening_and_refinement()
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &other_tria)
T sum(const T &t, const MPI_Comm &mpi_communicator)
#define Assert(cond, exc)
virtual void update_number_cache()
const bool allow_artificial_cells
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
const types::subdomain_id artificial_subdomain_id
virtual void update_number_cache()
bool with_artificial_cells() const
static ::ExceptionBase & ExcNotImplemented()
T max(const T &t, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcInternalError()