33#ifdef DEAL_II_WITH_MPI
38 template <
int dim,
int spacedim>
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>
76 return (
settings & construct_multigrid_hierarchy);
81 template <
int dim,
int spacedim>
88 const unsigned int max_active_cells =
91 max_active_cells == this->n_active_cells(),
93 "A parallel::shared::Triangulation needs to be refined in the same "
94 "way on all processors, but the participating processors don't "
95 "agree on the number of active cells."));
98 auto partition_settings = (partition_zoltan | partition_metis |
99 partition_zorder | partition_custom_signal) &
101 if (partition_settings == partition_auto)
102# ifdef DEAL_II_TRILINOS_WITH_ZOLTAN
103 partition_settings = partition_zoltan;
104# elif defined DEAL_II_WITH_METIS
105 partition_settings = partition_metis;
107 partition_settings = partition_zorder;
110 if (partition_settings == partition_zoltan)
112# ifndef DEAL_II_TRILINOS_WITH_ZOLTAN
115 "Choosing 'partition_zoltan' requires the library "
116 "to be compiled with support for Zoltan! "
117 "Instead, you might use 'partition_auto' to select "
118 "a partitioning algorithm that is supported "
119 "by your current configuration."));
125 else if (partition_settings == partition_metis)
127# ifndef DEAL_II_WITH_METIS
130 "Choosing 'partition_metis' requires the library "
131 "to be compiled with support for METIS! "
132 "Instead, you might use 'partition_auto' to select "
133 "a partitioning algorithm that is supported "
134 "by your current configuration."));
141 else if (partition_settings == partition_zorder)
145 else if (partition_settings == partition_custom_signal)
156 if ((
settings & construct_multigrid_hierarchy) &&
157 !(
settings & partition_custom_signal))
160 true_subdomain_ids_of_cells.resize(this->n_active_cells());
164 spacedim>::active_cell_iterator
165 cell = this->begin_active(),
168 if (allow_artificial_cells)
179 spacedim>::active_cell_iterator>
180 active_halo_layer_vector =
183 std::set<typename parallel::shared::Triangulation<dim, spacedim>::
184 active_cell_iterator>
185 active_halo_layer(active_halo_layer_vector.begin(),
186 active_halo_layer_vector.end());
188 for (
unsigned int index = 0; cell != endc; cell++, index++)
191 true_subdomain_ids_of_cells[index] = cell->subdomain_id();
193 if (cell->is_locally_owned() ==
false &&
194 active_halo_layer.find(cell) == active_halo_layer.end())
199 if (
settings & construct_multigrid_hierarchy)
201 true_level_subdomain_ids_of_cells.resize(this->n_levels());
207 for (
unsigned int lvl = 0; lvl < this->n_levels(); ++lvl)
209 true_level_subdomain_ids_of_cells[lvl].resize(
214 spacedim>::cell_iterator>
215 level_halo_layer_vector =
217 *
this, predicate, lvl);
218 std::set<
typename parallel::shared::
219 Triangulation<dim, spacedim>::cell_iterator>
220 level_halo_layer(level_halo_layer_vector.begin(),
221 level_halo_layer_vector.end());
224 cell_iterator cell = this->begin(lvl),
225 endc = this->end(lvl);
226 for (
unsigned int index = 0; cell != endc; cell++, index++)
230 true_level_subdomain_ids_of_cells[lvl][index] =
231 cell->level_subdomain_id();
240 if (cell->is_active() &&
241 cell->subdomain_id() !=
246 if (cell->has_children())
248 bool keep_cell =
false;
249 for (
unsigned int c = 0;
250 c < GeometryInfo<dim>::max_children_per_cell;
252 if (cell->child(c)->level_subdomain_id() ==
264 if (!cell->is_locally_owned_on_level() &&
265 level_halo_layer.find(cell) != level_halo_layer.
end())
269 cell->set_level_subdomain_id(
278 for (
unsigned int index = 0; cell != endc; cell++, index++)
279 true_subdomain_ids_of_cells[index] = cell->subdomain_id();
285 const unsigned int n_my_cells = std::count_if(
286 this->begin_active(),
289 [](
const auto &i) {
return (i.is_locally_owned()); });
291 const unsigned int total_cells =
293 Assert(total_cells == this->n_active_cells(),
294 ExcMessage(
"Not all cells are assigned to a processor."));
299 if (
settings & construct_multigrid_hierarchy)
301 const unsigned int n_my_cells =
302 std::count_if(this->begin(), this->end(), [](
const auto &i) {
303 return (i.is_locally_owned_on_level());
307 const unsigned int total_cells =
309 Assert(total_cells == this->n_cells(),
310 ExcMessage(
"Not all cells are assigned to a processor."));
317 template <
int dim,
int spacedim>
321 return allow_artificial_cells;
326 template <
int dim,
int spacedim>
327 const std::vector<types::subdomain_id> &
330 return true_subdomain_ids_of_cells;
335 template <
int dim,
int spacedim>
336 const std::vector<types::subdomain_id> &
338 const unsigned int level)
const
340 Assert(
level < true_level_subdomain_ids_of_cells.size(),
342 Assert(true_level_subdomain_ids_of_cells[
level].size() ==
343 this->n_cells(
level),
345 return true_level_subdomain_ids_of_cells[
level];
350 template <
int dim,
int spacedim>
356 this->update_number_cache();
361 template <
int dim,
int spacedim>
374 const typename ::Triangulation<dim, spacedim>::DistortedCellList
382 this->update_number_cache();
387 template <
int dim,
int spacedim>
393 (void)construction_data;
400 template <
int dim,
int spacedim>
403 const ::Triangulation<dim, spacedim> &other_tria)
407 const ::parallel::DistributedTriangulationBase<dim, spacedim>
408 *
>(&other_tria) ==
nullptr),
410 "Cannot use this function on parallel::distributed::Triangulation."));
415 this->update_number_cache();
426 template <
int dim,
int spacedim>
434 template <
int dim,
int spacedim>
441 template <
int dim,
int spacedim>
442 const std::vector<unsigned int> &
446 return true_subdomain_ids_of_cells;
451 template <
int dim,
int spacedim>
452 const std::vector<unsigned int> &
454 const unsigned int)
const
457 return true_level_subdomain_ids_of_cells;
473 template <
int dim,
int spacedim>
485 const std::vector<types::subdomain_id> &true_subdomain_ids =
489 for (
const auto &cell :
shared_tria->active_cell_iterators())
491 const unsigned int index = cell->active_cell_index();
493 cell->set_subdomain_id(true_subdomain_ids[
index]);
500 template <
int dim,
int spacedim>
504 if (shared_tria && shared_tria->with_artificial_cells())
507 for (
const auto &cell : shared_tria->active_cell_iterators())
509 const unsigned int index = cell->active_cell_index();
510 cell->set_subdomain_id(saved_subdomain_ids[
index]);
520#include "shared_tria.inst"
cell_iterator end() const
std::vector< unsigned int > saved_subdomain_ids
const SmartPointer< const ::parallel::shared::Triangulation< dim, spacedim > > shared_tria
~TemporarilyRestoreSubdomainIds()
TemporarilyRestoreSubdomainIds(const Triangulation< dim, spacedim > &tria)
types::subdomain_id my_subdomain
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria) override
virtual void execute_coarsening_and_refinement() override
typename ::Triangulation< dim, spacedim >::active_cell_iterator active_cell_iterator
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &other_tria) override
const std::vector< types::subdomain_id > & get_true_subdomain_ids_of_cells() const
Triangulation(const 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)
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
@ partition_custom_signal
@ construct_multigrid_hierarchy
bool with_artificial_cells() const
const std::vector< types::subdomain_id > & get_true_level_subdomain_ids_of_cells(const unsigned int level) const
virtual bool is_multilevel_hierarchy_constructed() const override
const bool allow_artificial_cells
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata) override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
T sum(const T &t, const MPI_Comm &mpi_communicator)
T max(const T &t, const MPI_Comm &mpi_communicator)
const types::subdomain_id artificial_subdomain_id
const TriangulationDescription::Settings settings
const ::Triangulation< dim, spacedim > & tria