40#ifdef DEAL_II_WITH_P4EST
44 template <
int dim,
int spacedim>
49 std::vector<std::list<
56 for (
const auto &cell :
triangulation.active_cell_iterators())
66 template <
int dim,
int spacedim>
71 std::vector<std::list<
80 for (
const auto &cell :
triangulation.active_cell_iterators())
84 edge_to_cell[cell->line(l)->index()].emplace_back(cell, l);
94 template <
int dim,
int spacedim>
99 const std::vector<std::list<
102 const std::vector<types::global_dof_index>
103 & coarse_cell_to_p4est_tree_permutation,
121 for (
unsigned int v = 0; v <
triangulation.n_vertices(); ++v)
123 connectivity->vertices[3 * v] =
triangulation.get_vertices()[v][0];
124 connectivity->vertices[3 * v + 1] =
126 connectivity->vertices[3 * v + 2] =
138 for (; cell !=
endc; ++cell)
140 const unsigned int index =
141 coarse_cell_to_p4est_tree_permutation[cell->index()];
148 v] = cell->vertex_index(v);
151 v] = cell->vertex_index(v);
157 if (cell->face(f)->at_boundary() ==
false)
160 coarse_cell_to_p4est_tree_permutation[cell->neighbor(f)->
index()];
164 coarse_cell_to_p4est_tree_permutation[cell->index()];
169 if (cell->face(f)->at_boundary() ==
false)
175 connectivity->tree_to_face
177 cell->neighbor_of_neighbor(f);
196 connectivity->tree_to_face[
index * 6 + f] =
197 cell->neighbor_of_neighbor(f);
200 f, cell->neighbor_of_neighbor(f)};
202 cell_list[2] = {cell, cell->neighbor(f)};
205 if (f > cell->neighbor_of_neighbor(f))
229 for (
unsigned int i = 0;
245 connectivity->tree_to_face[
index * 6 + f] += 6 * v;
259 connectivity->ctt_offset[0] = 0;
262 &connectivity->ctt_offset[1]);
270 for (
unsigned int v = 0; v <
triangulation.n_vertices(); ++v)
276 std::pair<typename Triangulation<dim, spacedim>::active_cell_iterator,
277 unsigned int>>::const_iterator p =
281 connectivity->corner_to_tree[connectivity->ctt_offset[v] + c] =
282 coarse_cell_to_p4est_tree_permutation[p->first->index()];
283 connectivity->corner_to_corner[connectivity->ctt_offset[v] + c] =
291 template <
int dim,
int spacedim>
304 template <
int dim,
int spacedim>
309 if (cell->has_children())
310 for (
unsigned int c = 0; c < cell->n_children(); ++c)
313 cell->set_coarsen_flag();
318 template <
int dim,
int spacedim>
323 if (cell->has_children())
324 for (
unsigned int c = 0; c < cell->n_children(); ++c)
329 template <
int dim,
int spacedim>
338 const std::vector<std::vector<bool>> & marked_vertices)
369 dealii_cell->level() + 1 <
static_cast<int>(marked_vertices.size()))
445 template <
int dim,
int spacedim>
478 for (
unsigned int c = 0;
497 for (
unsigned int c = 0;
510 dealii_cell->child(c)->recursively_set_subdomain_id(
528 template <
int dim,
int spacedim>
531 const ::Triangulation<dim, spacedim> *
tria,
538 for (
int i = 0; i <
l; ++i)
543 if (cell->is_active())
545 cell->clear_coarsen_flag();
546 cell->set_refine_flag();
559 if (cell->has_children())
563 cell->clear_coarsen_flag();
569# ifdef P4EST_SEARCH_LOCAL
641 initialize_mapping();
698 this_object->quadrant_data.set_cell_vertices(forest,
789 "Cell vertices and mapping coefficients must be fully "
790 "initialized before transforming a point to the unit cell."));
796 for (
unsigned int alpha = 0;
812 for (
unsigned int alpha = 0;
853 "Cell vertices must be initialized before the cell mapping can be filled."));
860 for (
unsigned int alpha = 0;
880 for (
unsigned int alpha = 0;
921 constexpr unsigned int dim = 2;
928 const auto copy_vertex = [&](
unsigned int vertex_index) ->
void {
930 for (
unsigned int d = 0;
d < dim; ++
d)
942 unsigned int vertex_index = 0;
954 forest->connectivity,
968 forest->connectivity,
982 forest->connectivity,
1005 constexpr unsigned int dim = 3;
1010 auto copy_vertex = [&](
unsigned int vertex_index) ->
void {
1012 for (
unsigned int d = 0;
d < dim; ++
d)
1024 unsigned int vertex_index = 0;
1026 forest->connectivity,
1042 forest->connectivity,
1057 forest->connectivity,
1072 forest->connectivity,
1087 forest->connectivity,
1102 forest->connectivity,
1117 forest->connectivity,
1132 forest->connectivity,
1153 template <
int dim,
int spacedim>
1154 class RefineAndCoarsenList
1158 const std::vector<types::global_dof_index>
1159 &p4est_tree_to_coarse_cell_permutation,
1190 std::vector<typename internal::p4est::types<dim>::quadrant> refine_list;
1191 typename std::vector<typename internal::p4est::types<dim>::quadrant>
::
1194 std::vector<typename internal::p4est::types<dim>::quadrant> coarsen_list;
1195 typename std::vector<typename internal::p4est::types<dim>::quadrant>
::
1207 template <
int dim,
int spacedim>
1209 RefineAndCoarsenList<dim, spacedim>::pointers_are_at_end()
const
1211 return ((current_refine_pointer == refine_list.end()) &&
1212 (current_coarsen_pointer == coarsen_list.end()));
1217 template <
int dim,
int spacedim>
1218 RefineAndCoarsenList<dim, spacedim>::RefineAndCoarsenList(
1220 const std::vector<types::global_dof_index>
1221 & p4est_tree_to_coarse_cell_permutation,
1226 for (
const auto &cell :
triangulation.active_cell_iterators())
1229 if (cell->subdomain_id() != my_subdomain)
1232 if (cell->refine_flag_set())
1234 else if (cell->coarsen_flag_set())
1252 p4est_tree_to_coarse_cell_permutation[c];
1270 for (
unsigned int i = 1; i < refine_list.size(); ++i)
1271 Assert(refine_list[i].p.which_tree >= refine_list[i - 1].p.which_tree,
1273 for (
unsigned int i = 1; i < coarsen_list.size(); ++i)
1274 Assert(coarsen_list[i].p.which_tree >= coarsen_list[i - 1].p.which_tree,
1277 current_refine_pointer = refine_list.
begin();
1278 current_coarsen_pointer = coarsen_list.begin();
1283 template <
int dim,
int spacedim>
1285 RefineAndCoarsenList<dim, spacedim>::build_lists(
1290 if (cell->is_active())
1292 if (cell->subdomain_id() == my_subdomain)
1294 if (cell->refine_flag_set())
1296 else if (cell->coarsen_flag_set())
1329 template <
int dim,
int spacedim>
1331 RefineAndCoarsenList<dim, spacedim>::refine_callback(
1338 forest->user_pointer);
1346 this_object->current_refine_pointer->p.which_tree,
1356 this_object->current_refine_pointer->p.which_tree,
1362 quadrant, &*
this_object->current_refine_pointer) <= 0,
1379 template <
int dim,
int spacedim>
1381 RefineAndCoarsenList<dim, spacedim>::coarsen_callback(
1388 forest->user_pointer);
1396 this_object->current_coarsen_pointer->p.which_tree,
1406 this_object->current_coarsen_pointer->p.which_tree,
1412 children[0], &*
this_object->current_coarsen_pointer) <= 0,
1418 children[0], &*
this_object->current_coarsen_pointer))
1429 children[c], &*
this_object->current_coarsen_pointer),
1449 template <
int dim,
int spacedim>
1450 class PartitionWeights
1458 explicit PartitionWeights(
const std::vector<unsigned int> &
cell_weights);
1473 std::vector<unsigned int> cell_weights_list;
1474 std::vector<unsigned int>::const_iterator current_pointer;
1478 template <
int dim,
int spacedim>
1479 PartitionWeights<dim, spacedim>::PartitionWeights(
1485 current_pointer = cell_weights_list.begin();
1489 template <
int dim,
int spacedim>
1491 PartitionWeights<dim, spacedim>::cell_weight(
1512 const unsigned int weight = *
this_object->current_pointer;
1515 Assert(weight <
static_cast<unsigned int>(std::numeric_limits<int>::max()),
1516 ExcMessage(
"p4est uses 'signed int' to represent the partition "
1517 "weights for cells. The weight provided here exceeds "
1518 "the maximum value represented as a 'signed int'."));
1519 return static_cast<int>(weight);
1522 template <
int dim,
int spacedim>
1523 using cell_relation_t =
typename std::pair<
1524 typename ::Triangulation<dim, spacedim>::cell_iterator,
1525 typename ::Triangulation<dim, spacedim>::CellStatus>;
1536 template <
int dim,
int spacedim>
1540 const typename ::internal::p4est::types<dim>::tree & tree,
1541 const unsigned int idx,
1565 template <
int dim,
int spacedim>
1569 const typename ::internal::p4est::types<dim>::tree & tree,
1571 const typename ::internal::p4est::types<dim>::quadrant &
p4est_cell)
1580 const_cast<typename ::internal::p4est::types<dim>::tree *
>(
1591 typename ::internal::p4est::types<dim>::quadrant
1637 typename ::internal::p4est::types<dim>::quadrant
1695 namespace distributed
1698 template <
int dim,
int spacedim>
1710 (
settings & construct_multigrid_hierarchy) ?
1714 Triangulation<dim, spacedim>::limit_level_difference_at_vertices) :
1718 , triangulation_has_content(
false)
1719 , connectivity(
nullptr)
1720 , parallel_forest(
nullptr)
1722 parallel_ghost =
nullptr;
1727 template <
int dim,
int spacedim>
1748 template <
int dim,
int spacedim>
1761 const typename ::Triangulation<dim, spacedim>::DistortedCellList
1770 this->all_reference_cells_are_hyper_cube(),
1772 "The class parallel::distributed::Triangulation only supports meshes "
1773 "consisting only of hypercube-like cells."));
1778 triangulation_has_content =
true;
1780 setup_coarse_cell_to_p4est_tree_permutation();
1782 copy_new_triangulation_to_p4est(std::integral_constant<int, dim>());
1786 copy_local_forest_to_triangulation();
1795 this->update_periodic_face_map();
1796 this->update_number_cache();
1801 template <
int dim,
int spacedim>
1814 template <
int dim,
int spacedim>
1818 triangulation_has_content =
false;
1820 if (parallel_ghost !=
nullptr)
1824 parallel_ghost =
nullptr;
1827 if (parallel_forest !=
nullptr)
1830 parallel_forest =
nullptr;
1833 if (connectivity !=
nullptr)
1837 connectivity =
nullptr;
1840 coarse_cell_to_p4est_tree_permutation.resize(0);
1841 p4est_tree_to_coarse_cell_permutation.resize(0);
1845 this->update_number_cache();
1850 template <
int dim,
int spacedim>
1861 template <
int dim,
int spacedim>
1872 template <
int dim,
int spacedim>
1880 Assert(this->data_transfer.sizes_fixed_cumulative.size() > 0,
1884 this->data_transfer.dest_data_fixed.resize(
1885 parallel_forest->local_num_quadrants *
1886 this->data_transfer.sizes_fixed_cumulative.back());
1889 typename ::internal::p4est::types<dim>::transfer_context
1893 parallel_forest->global_first_quadrant,
1895 parallel_forest->mpicomm,
1897 this->data_transfer.dest_data_fixed.
data(),
1898 this->data_transfer.src_data_fixed.
data(),
1899 this->data_transfer.sizes_fixed_cumulative.back());
1901 if (this->data_transfer.variable_size_data_stored)
1904 this->data_transfer.dest_sizes_variable.resize(
1905 parallel_forest->local_num_quadrants);
1910 parallel_forest->global_first_quadrant,
1912 parallel_forest->mpicomm,
1914 this->data_transfer.dest_sizes_variable.
data(),
1915 this->data_transfer.src_sizes_variable.
data(),
1916 sizeof(
unsigned int));
1922 this->data_transfer.src_data_fixed.clear();
1923 this->data_transfer.src_data_fixed.shrink_to_fit();
1925 if (this->data_transfer.variable_size_data_stored)
1928 this->data_transfer.dest_data_variable.resize(
1929 std::accumulate(this->data_transfer.dest_sizes_variable.begin(),
1930 this->data_transfer.dest_sizes_variable.
end(),
1931 std::vector<int>::size_type(0)));
1933# if DEAL_II_P4EST_VERSION_GTE(2, 0, 65, 0)
1940 if (this->data_transfer.src_sizes_variable.size() == 0)
1941 this->data_transfer.src_sizes_variable.resize(1);
1942 if (this->data_transfer.dest_sizes_variable.size() == 0)
1943 this->data_transfer.dest_sizes_variable.resize(1);
1948 parallel_forest->global_first_quadrant,
1950 parallel_forest->mpicomm,
1952 this->data_transfer.dest_data_variable.
data(),
1953 this->data_transfer.dest_sizes_variable.
data(),
1954 this->data_transfer.src_data_variable.
data(),
1955 this->data_transfer.src_sizes_variable.
data());
1958 this->data_transfer.src_sizes_variable.clear();
1959 this->data_transfer.src_sizes_variable.shrink_to_fit();
1960 this->data_transfer.src_data_variable.clear();
1961 this->data_transfer.src_data_variable.shrink_to_fit();
1967 template <
int dim,
int spacedim>
1970 spacedim>::setup_coarse_cell_to_p4est_tree_permutation()
1975 coarse_cell_to_p4est_tree_permutation.resize(this->n_cells(0));
1979 p4est_tree_to_coarse_cell_permutation =
1985 template <
int dim,
int spacedim>
1990 Assert(parallel_forest !=
nullptr,
1991 ExcMessage(
"Can't produce output when no forest is created yet."));
1995 "To use this function the triangulation's flag "
1996 "Settings::communicate_vertices_to_p4est must be set."));
2004 template <
int dim,
int spacedim>
2009 this->cell_attached_data.n_attached_deserialize == 0,
2011 "Not all SolutionTransfer objects have been deserialized after the last call to load()."));
2012 Assert(this->n_cells() > 0,
2013 ExcMessage(
"Can not save() an empty Triangulation."));
2019 this->signals.pre_distributed_save();
2021 if (this->my_subdomain == 0)
2024 std::ofstream f(
fname.c_str());
2025 f <<
"version nproc n_attached_fixed_size_objs n_attached_variable_size_objs n_coarse_cells"
2029 << this->cell_attached_data.pack_callbacks_fixed.size() <<
" "
2030 << this->cell_attached_data.pack_callbacks_variable.size() <<
" "
2031 << this->n_cells(0) << std::endl;
2035 for (
const auto &
cell_rel : this->local_cell_relations)
2045 this->save_attached_data(parallel_forest->global_first_quadrant[
myrank],
2046 parallel_forest->global_num_quadrants,
2054 this->signals.post_distributed_save();
2059 template <
int dim,
int spacedim>
2064 this->n_cells() > 0,
2066 "load() only works if the Triangulation already contains a coarse mesh!"));
2068 this->n_levels() == 1,
2070 "Triangulation may only contain coarse cells when calling load()."));
2076 this->signals.pre_distributed_load();
2078 if (parallel_ghost !=
nullptr)
2082 parallel_ghost =
nullptr;
2085 parallel_forest =
nullptr;
2088 connectivity =
nullptr;
2094 std::ifstream f(
fname.c_str());
2103 ExcMessage(
"Incompatible version found in .info file."));
2104 Assert(this->n_cells(0) == n_coarse_cells,
2105 ExcMessage(
"Number of coarse cells differ!"));
2109 this->cell_attached_data.n_attached_data_sets = 0;
2110 this->cell_attached_data.n_attached_deserialize =
2115 this->mpi_communicator,
2133 copy_local_forest_to_triangulation();
2143 this->load_attached_data(parallel_forest->global_first_quadrant[
myrank],
2144 parallel_forest->global_num_quadrants,
2145 parallel_forest->local_num_quadrants,
2151 this->signals.post_distributed_load();
2153 this->update_periodic_face_map();
2154 this->update_number_cache();
2159 template <
int dim,
int spacedim>
2170 template <
int dim,
int spacedim>
2175 Assert(this->n_cells() > 0,
2177 "load() only works if the Triangulation already contains "
2179 Assert(this->n_cells() == forest->trees->elem_count,
2181 "Coarse mesh of the Triangulation does not match the one "
2182 "of the provided forest!"));
2185 if (parallel_ghost !=
nullptr)
2189 parallel_ghost =
nullptr;
2192 parallel_forest =
nullptr;
2198 typename ::internal::p4est::types<dim>::forest *
temp =
2199 const_cast<typename ::internal::p4est::types<dim>::forest *
>(
2203 parallel_forest->connectivity = connectivity;
2204 parallel_forest->user_pointer =
this;
2208 copy_local_forest_to_triangulation();
2217 this->update_periodic_face_map();
2218 this->update_number_cache();
2223 template <
int dim,
int spacedim>
2227 Assert(parallel_forest !=
nullptr,
2229 "Can't produce a check sum when no forest is created yet."));
2230 return ::internal::p4est::functions<dim>::checksum(parallel_forest);
2235 template <
int dim,
int spacedim>
2237 const typename ::internal::p4est::types<dim>::forest
2240 Assert(parallel_forest !=
nullptr,
2241 ExcMessage(
"The forest has not been allocated yet."));
2242 return parallel_forest;
2247 template <
int dim,
int spacedim>
2249 typename ::internal::p4est::types<dim>::tree
2255 typename ::internal::p4est::types<dim>::tree *tree =
2256 static_cast<typename ::internal::p4est::types<dim>::tree *
>(
2270 std::integral_constant<int, 2>)
2272 const unsigned int dim = 2, spacedim = 2;
2282 std::list<std::pair<Triangulation<dim, spacedim>::active_cell_iterator,
2286 const ::internal::p4est::types<2>::locidx
num_vtt =
2294 const bool set_vertex_info = this->are_vertices_communicated_to_p4est();
2305 coarse_cell_to_p4est_tree_permutation,
2314 this->mpi_communicator,
2330 std::integral_constant<int, 2>)
2332 const unsigned int dim = 2, spacedim = 3;
2342 std::list<std::pair<Triangulation<dim, spacedim>::active_cell_iterator,
2346 const ::internal::p4est::types<2>::locidx
num_vtt =
2354 const bool set_vertex_info = this->are_vertices_communicated_to_p4est();
2365 coarse_cell_to_p4est_tree_permutation,
2374 this->mpi_communicator,
2388 std::integral_constant<int, 3>)
2390 const int dim = 3, spacedim = 3;
2399 std::vector<std::list<
2400 std::pair<Triangulation<3>::active_cell_iterator,
unsigned int>>>
2403 const ::internal::p4est::types<2>::locidx
num_vtt =
2409 std::vector<std::list<
2410 std::pair<Triangulation<3>::active_cell_iterator,
unsigned int>>>
2413 const ::internal::p4est::types<2>::locidx
num_ett =
2417 const bool set_vertex_info = this->are_vertices_communicated_to_p4est();
2422 this->n_active_lines(),
2430 coarse_cell_to_p4est_tree_permutation,
2460 4, 5, 0, 1, 6, 7, 2, 3, 8, 9, 10, 11};
2463 this->begin_active();
2464 cell != this->
end();
2467 const unsigned int index =
2468 coarse_cell_to_p4est_tree_permutation[cell->index()];
2472 cell->line(e)->index();
2477 connectivity->ett_offset[0] = 0;
2480 &connectivity->ett_offset[1]);
2485 for (
unsigned int v = 0; v < this->n_active_lines(); ++v)
2491 std::pair<Triangulation<dim, spacedim>::active_cell_iterator,
2492 unsigned int>>::const_iterator p =
2496 connectivity->edge_to_tree[connectivity->ett_offset[v] + c] =
2497 coarse_cell_to_p4est_tree_permutation[p->first->index()];
2498 connectivity->edge_to_edge[connectivity->ett_offset[v] + c] =
2508 this->mpi_communicator,
2525 template <
int dim,
int spacedim>
2530 if (
tria.get_periodic_face_map().
size() == 0)
2558 using cell_iterator =
2560 typename std::map<std::pair<cell_iterator, unsigned int>,
2561 std::pair<std::pair<cell_iterator, unsigned int>,
2562 std::bitset<3>>>::const_iterator
it;
2564 it !=
tria.get_periodic_face_map().
end();
2567 const cell_iterator &
cell_1 =
it->first.first;
2569 const cell_iterator &
cell_2 =
it->second.first.first;
2570 const unsigned int face_no_2 =
it->second.first.second;
2571 const std::bitset<3> face_orientation =
it->second.second;
2575 for (
unsigned int v = 0;
2581 const unsigned int vface0 =
2584 face_orientation[0],
2585 face_orientation[1],
2586 face_orientation[2]);
2587 const unsigned int vi0 =
2590 const unsigned int vi1 =
2595 ->vertex_index(
vface0)] =
2597 ->vertex_index(v)] =
2622 cell =
tria.begin_active(),
2624 for (; cell !=
endc; ++cell)
2626 if (cell->refine_flag_set())
2627 for (
const unsigned int vertex :
2630 [cell->vertex_index(vertex)]] =
2632 [cell->vertex_index(vertex)]],
2634 else if (!cell->coarsen_flag_set())
2635 for (
const unsigned int vertex :
2638 [cell->vertex_index(vertex)]] =
2640 [cell->vertex_index(vertex)]],
2651 for (
const unsigned int vertex :
2654 [cell->vertex_index(vertex)]] =
2656 [cell->vertex_index(vertex)]],
2672 for (cell =
tria.last_active(); cell !=
endc; --cell)
2673 if (cell->refine_flag_set() ==
false)
2675 for (
const unsigned int vertex :
2678 [cell->vertex_index(vertex)]] >=
2682 cell->clear_coarsen_flag();
2688 [cell->vertex_index(vertex)]] >
2691 cell->set_refine_flag();
2694 for (
const unsigned int v :
2697 [cell->vertex_index(v)]] =
2700 [cell->vertex_index(v)]],
2711 for (
const auto &cell :
tria.cell_iterators())
2714 if (cell->is_active())
2717 const unsigned int n_children = cell->n_children();
2719 for (
unsigned int child = 0; child < n_children; ++child)
2720 if (cell->child(child)->is_active() &&
2721 cell->child(child)->coarsen_flag_set())
2727 for (
unsigned int child = 0; child < n_children; ++child)
2728 if (cell->child(child)->is_active())
2729 cell->child(child)->clear_coarsen_flag();
2742 template <
int dim,
int spacedim>
2753 this->update_periodic_face_map();
2767 "parallel::distributed::Triangulation::prepare_coarsening_and_refinement() "
2768 "for periodic boundaries detected. Aborting."));
2778 template <
int dim,
int spacedim>
2799 if (
settings & construct_multigrid_hierarchy)
2802 spacedim>::limit_level_difference_at_vertices;
2814 if (
settings & mesh_reconstruction_after_repartitioning)
2815 while (this->n_levels() > 1)
2822 for (
const auto &cell :
2823 this->active_cell_iterators_on_level(this->n_levels() - 1))
2825 cell->set_coarsen_flag();
2843 if (parallel_ghost !=
nullptr)
2847 parallel_ghost =
nullptr;
2851 (dim == 2 ? typename ::internal::p4est::types<dim>::balance_type(
2853 typename ::internal::p4est::types<dim>::balance_type(
2861 for (
const auto &cell : this->cell_iterators_on_level(0))
2866 for (
const auto &cell : this->cell_iterators_on_level(0))
2873 coarse_cell_to_p4est_tree_permutation[cell->index()]) ==
2877 if (cell->is_active())
2886 typename ::internal::p4est::types<dim>::quadrant
2888 typename ::internal::p4est::types<dim>::tree *tree =
2889 init_tree(cell->index());
2891 ::internal::p4est::init_coarse_quadrant<dim>(
2898 this->my_subdomain);
2905 typename ::internal::p4est::types<dim>::quadrant *
quadr;
2907 typename ::internal::p4est::types<dim>::topidx
ghost_tree = 0;
2909 for (
unsigned int g_idx = 0;
2910 g_idx < parallel_ghost->ghosts.elem_count;
2913 while (
g_idx >=
static_cast<unsigned int>(
2916 while (
g_idx >=
static_cast<unsigned int>(
2917 parallel_ghost->tree_offsets[
ghost_tree + 1]))
2920 quadr =
static_cast<
2921 typename ::internal::p4est::types<dim>::quadrant *
>(
2925 p4est_tree_to_coarse_cell_permutation[
ghost_tree];
2934 this->prepare_coarsening_and_refinement();
2938 std::any_of(this->begin_active(),
2941 return cell.refine_flag_set() ||
2942 cell.coarsen_flag_set();
2966 for (
const auto &cell : this->active_cell_iterators())
2968 if (cell->subdomain_id() != this->my_subdomain &&
2984 if (
settings & construct_multigrid_hierarchy)
2990 for (
unsigned int lvl = this->n_levels();
lvl > 0;)
2993 for (
const auto &cell : this->cell_iterators_on_level(
lvl))
2995 if ((cell->is_active() &&
2996 cell->subdomain_id() ==
2997 this->locally_owned_subdomain()) ||
2998 (cell->has_children() &&
2999 cell->child(0)->level_subdomain_id() ==
3000 this->locally_owned_subdomain()))
3001 cell->set_level_subdomain_id(
3002 this->locally_owned_subdomain());
3006 cell->set_level_subdomain_id(
3014 std::vector<std::vector<bool>> marked_vertices(this->n_levels());
3015 for (
unsigned int lvl = 0;
lvl < this->n_levels(); ++
lvl)
3016 marked_vertices[
lvl] = mark_locally_active_vertices_on_level(
lvl);
3018 for (
const auto &cell : this->cell_iterators_on_level(0))
3020 typename ::internal::p4est::types<dim>::quadrant
3023 coarse_cell_to_p4est_tree_permutation[cell->index()];
3024 typename ::internal::p4est::types<dim>::tree *tree =
3025 init_tree(cell->index());
3027 ::internal::p4est::init_coarse_quadrant<dim>(
3041 for (
unsigned int lvl = this->n_levels();
lvl > 0;)
3044 for (
const auto &cell : this->cell_iterators_on_level(
lvl))
3046 if (cell->has_children())
3047 for (
unsigned int c = 0;
3051 if (cell->child(c)->level_subdomain_id() ==
3052 this->locally_owned_subdomain())
3057 cell->child(0)->level_subdomain_id();
3061 cell->set_level_subdomain_id(
mark);
3082 Assert(
static_cast<unsigned int>(
3088 Assert(
static_cast<unsigned int>(
3096 for (
const auto &cell : this->active_cell_iterators())
3098 if (cell->subdomain_id() == this->my_subdomain)
3102 Assert(
static_cast<unsigned int>(
3103 parallel_forest->local_num_quadrants) ==
n_owned,
3114 update_cell_relations();
3119 template <
int dim,
int spacedim>
3125 std::vector<Point<dim>> point{p};
3126 std::vector<types::subdomain_id>
owner = find_point_owner_rank(point);
3133 template <
int dim,
int spacedim>
3136 find_point_owner_rank(
const std::vector<
Point<dim>> &points)
3138# ifndef P4EST_SEARCH_LOCAL
3143 "This function is only available if p4est is version 2.2 and higher."));
3145 return std::vector<unsigned int>(1,
3149 AssertThrow(this->are_vertices_communicated_to_p4est(),
3151 "Vertices need to be communicated to p4est to use this "
3152 "function. This must explicitly be turned on in the "
3153 "settings of the triangulation's constructor."));
3156 for (
const auto &manifold_id : this->get_manifold_ids())
3161 "This function can only be used if the triangulation "
3162 "has no other manifold than a Cartesian (flat) manifold attached."));
3185 for (
size_t i = 0; i < points.
size(); ++i)
3193 for (
unsigned int d = 0; d < dim; ++d)
3203 static_cast<int>(
false),
3213 for (
size_t i = 0; i < points.
size(); ++i)
3222 parallel_forest->user_pointer =
this;
3233 template <
int dim,
int spacedim>
3239 for (
const auto &cell : this->active_cell_iterators())
3240 if (cell->is_locally_owned() && cell->refine_flag_set())
3241 Assert(cell->refine_flag_set() ==
3244 "This class does not support anisotropic refinement"));
3249 if (this->n_levels() ==
3253 cell = this->begin_active(
3261 !(cell->refine_flag_set()),
3263 "Fatal Error: maximum refinement level of p4est reached."));
3267 this->prepare_coarsening_and_refinement();
3270 this->signals.pre_distributed_refinement();
3275 for (
const auto &cell : this->active_cell_iterators())
3276 if (cell->is_ghost() || cell->is_artificial())
3278 cell->clear_refine_flag();
3279 cell->clear_coarsen_flag();
3286 *
this, p4est_tree_to_coarse_cell_permutation, this->my_subdomain);
3295 if (parallel_ghost !=
nullptr)
3299 parallel_ghost =
nullptr;
3304 &RefineAndCoarsenList<dim, spacedim>::refine_callback,
3309 &RefineAndCoarsenList<dim, spacedim>::coarsen_callback,
3316 parallel_forest->user_pointer =
this;
3322 (dim == 2 ? typename ::internal::p4est::types<dim>::balance_type(
3324 typename ::internal::p4est::types<dim>::balance_type(
3330 update_cell_relations();
3334 this->signals.post_p4est_refinement();
3338 std::vector<typename ::internal::p4est::types<dim>::gloidx>
3341 if (this->cell_attached_data.n_attached_data_sets > 0)
3345 parallel_forest->global_first_quadrant,
3347 typename ::internal::p4est::types<dim>::gloidx) *
3348 (parallel_forest->mpisize + 1));
3351 if (!(
settings & no_automatic_repartitioning))
3355 if (this->signals.weight.empty())
3363 const std::vector<unsigned int>
cell_weights = get_cell_weights();
3369 this->mpi_communicator) > 0,
3371 "The global sum of weights over all active cells "
3372 "is zero. Please verify how you generate weights."));
3385 &PartitionWeights<dim, spacedim>::cell_weight);
3389 parallel_forest, 0,
nullptr,
nullptr);
3391 parallel_forest->user_pointer =
this;
3396 if (this->cell_attached_data.n_attached_data_sets > 0)
3398 this->data_transfer.pack_data(
3399 this->local_cell_relations,
3400 this->cell_attached_data.pack_callbacks_fixed,
3401 this->cell_attached_data.pack_callbacks_variable);
3407 for (
const auto &cell : this->active_cell_iterators())
3409 cell->clear_refine_flag();
3410 cell->clear_coarsen_flag();
3415 copy_local_forest_to_triangulation();
3425 if (this->cell_attached_data.n_attached_data_sets > 0)
3427 this->execute_transfer(parallel_forest,
3431 this->data_transfer.unpack_cell_status(this->local_cell_relations);
3450 if (
settings & construct_multigrid_hierarchy)
3452 for (
unsigned int lvl = 0;
lvl < this->n_global_levels(); ++
lvl)
3455 this->mark_locally_active_vertices_on_level(
lvl);
3462 for (; cell !=
endc; ++cell)
3463 if (cell->level() ==
static_cast<int>(
lvl) || cell->is_active())
3466 (cell->level_subdomain_id() ==
3469 for (
const unsigned int vertex :
3480 "Internal error: the owner of cell" +
3481 cell->id().to_string() +
3482 " is unknown even though it is needed for geometric multigrid."));
3488 this->update_periodic_face_map();
3489 this->update_number_cache();
3492 this->signals.post_distributed_refinement();
3497 template <
int dim,
int spacedim>
3502 for (
const auto &cell : this->active_cell_iterators())
3503 if (cell->is_locally_owned())
3505 !cell->refine_flag_set() && !cell->coarsen_flag_set(),
3507 "Error: There shouldn't be any cells flagged for coarsening/refinement when calling repartition()."));
3511 this->signals.pre_distributed_repartition();
3515 std::vector<typename ::internal::p4est::types<dim>::gloidx>
3518 if (this->cell_attached_data.n_attached_data_sets > 0)
3522 parallel_forest->global_first_quadrant,
3524 typename ::internal::p4est::types<dim>::gloidx) *
3525 (parallel_forest->mpisize + 1));
3528 if (this->signals.weight.empty())
3540 const std::vector<unsigned int>
cell_weights = get_cell_weights();
3546 this->mpi_communicator) > 0,
3548 "The global sum of weights over all active cells "
3549 "is zero. Please verify how you generate weights."));
3562 &PartitionWeights<dim, spacedim>::cell_weight);
3565 parallel_forest->user_pointer =
this;
3569 if (this->cell_attached_data.n_attached_data_sets > 0)
3571 this->data_transfer.pack_data(
3572 this->local_cell_relations,
3573 this->cell_attached_data.pack_callbacks_fixed,
3574 this->cell_attached_data.pack_callbacks_variable);
3579 copy_local_forest_to_triangulation();
3589 if (this->cell_attached_data.n_attached_data_sets > 0)
3591 this->execute_transfer(parallel_forest,
3595 this->update_periodic_face_map();
3598 this->update_number_cache();
3601 this->signals.post_distributed_repartition();
3606 template <
int dim,
int spacedim>
3608 const std::vector<types::global_dof_index>
3612 return p4est_tree_to_coarse_cell_permutation;
3617 template <
int dim,
int spacedim>
3619 const std::vector<types::global_dof_index>
3623 return coarse_cell_to_p4est_tree_permutation;
3628 template <
int dim,
int spacedim>
3631 mark_locally_active_vertices_on_level(
const int level)
const
3635 std::vector<bool> marked_vertices(this->n_vertices(),
false);
3636 for (
const auto &cell : this->cell_iterators_on_level(
level))
3637 if (cell->level_subdomain_id() == this->locally_owned_subdomain())
3639 marked_vertices[cell->vertex_index(v)] =
true;
3657 for (
const auto &
it : this->get_periodic_face_map())
3662 const unsigned int face_no_2 =
it.second.first.second;
3663 const std::bitset<3> &face_orientation =
it.second.second;
3667 for (
unsigned int v = 0;
3673 const unsigned int vface0 =
3676 face_orientation[0],
3677 face_orientation[1],
3678 face_orientation[2]);
3691 return marked_vertices;
3696 template <
int dim,
int spacedim>
3699 coarse_cell_id_to_coarse_cell_index(
3700 const types::coarse_cell_id coarse_cell_id)
const
3702 return p4est_tree_to_coarse_cell_permutation[coarse_cell_id];
3707 template <
int dim,
int spacedim>
3718 template <
int dim,
int spacedim>
3724 Assert(triangulation_has_content ==
true,
3726 Assert(this->n_levels() == 1,
3727 ExcMessage(
"The triangulation is refined!"));
3743 coarse_cell_to_p4est_tree_permutation[first_cell->index()];
3745 coarse_cell_to_p4est_tree_permutation[
second_cell->index()];
3854 this->mpi_communicator,
3865 copy_local_forest_to_triangulation();
3876 this->update_number_cache();
3881 template <
int dim,
int spacedim>
3892 this->cell_attached_data.n_attached_data_sets) +
3899 coarse_cell_to_p4est_tree_permutation) +
3901 p4est_tree_to_coarse_cell_permutation) +
3902 memory_consumption_p4est();
3909 template <
int dim,
int spacedim>
3913 return ::internal::p4est::functions<dim>::forest_memory_used(
3921 template <
int dim,
int spacedim>
3928 const ::parallel::distributed::Triangulation<dim, spacedim> *
>(
3941 const typename ::Triangulation<dim, spacedim>::DistortedCellList
3949 if (const ::parallel::distributed::Triangulation<dim, spacedim>
3951 dynamic_cast<const ::parallel::distributed::
3952 Triangulation<dim, spacedim> *
>(&
other_tria))
3956 triangulation_has_content =
3958 coarse_cell_to_p4est_tree_permutation =
3960 p4est_tree_to_coarse_cell_permutation =
3964 typename ::internal::p4est::types<dim>::connectivity
3966 typename ::internal::p4est::types<dim>::connectivity *
>(
3972 typename ::internal::p4est::types<dim>::forest *
temp_forest =
3973 const_cast<typename ::internal::p4est::types<dim>::forest *
>(
3978 parallel_forest->connectivity = connectivity;
3979 parallel_forest->user_pointer =
this;
3983 triangulation_has_content =
true;
3984 setup_coarse_cell_to_p4est_tree_permutation();
3985 copy_new_triangulation_to_p4est(std::integral_constant<int, dim>());
3990 copy_local_forest_to_triangulation();
3999 this->update_periodic_face_map();
4000 this->update_number_cache();
4005 template <
int dim,
int spacedim>
4010 this->local_cell_relations.resize(parallel_forest->local_num_quadrants);
4011 this->local_cell_relations.shrink_to_fit();
4014 for (
const auto &cell : this->cell_iterators_on_level(0))
4019 coarse_cell_to_p4est_tree_permutation[cell->index()]) ==
false)
4023 typename ::internal::p4est::types<dim>::quadrant
4028 typename ::internal::p4est::types<dim>::tree *tree =
4029 init_tree(cell->index());
4038 template <
int dim,
int spacedim>
4045 Assert(this->local_cell_relations.size() ==
4046 static_cast<unsigned int>(parallel_forest->local_num_quadrants),
4051 std::vector<unsigned int> weights;
4052 weights.reserve(this->local_cell_relations.size());
4060 for (
const auto &
cell_rel : this->local_cell_relations)
4073 template <
int spacedim>
4089 template <
int spacedim>
4098 template <
int spacedim>
4100 const std::vector<types::global_dof_index>
4104 static std::vector<types::global_dof_index> a;
4110 template <
int spacedim>
4112 std::map<
unsigned int,
4115 const unsigned int )
const
4119 return std::map<unsigned int, std::set<::types::subdomain_id>>();
4124 template <
int spacedim>
4127 mark_locally_active_vertices_on_level(
const unsigned int)
const
4130 return std::vector<bool>();
4135 template <
int spacedim>
4138 coarse_cell_id_to_coarse_cell_index(
const types::coarse_cell_id)
const
4146 template <
int spacedim>
4150 const unsigned int)
const
4158 template <
int spacedim>
4167 template <
int spacedim>
4176 template <
int spacedim>
4185 template <
int spacedim>
4195 template <
int spacedim>
4205 template <
int spacedim>
4222 namespace distributed
4224 template <
int dim,
int spacedim>
4232#ifdef DEAL_II_WITH_P4EST
4242 const auto &cell =
pair.first;
4243 const auto &status =
pair.second;
4247 case ::Triangulation<dim, spacedim>::CELL_PERSIST:
4249 cell->clear_refine_flag();
4250 cell->clear_coarsen_flag();
4253 case ::Triangulation<dim, spacedim>::CELL_REFINE:
4255 cell->clear_coarsen_flag();
4256 cell->set_refine_flag();
4259 case ::Triangulation<dim, spacedim>::CELL_COARSEN:
4261 for (
const auto &child : cell->child_iterators())
4263 child->clear_refine_flag();
4264 child->set_coarsen_flag();
4268 case ::Triangulation<dim, spacedim>::CELL_INVALID:
4283 template <
int dim,
int spacedim>
4286#ifdef DEAL_II_WITH_P4EST
4287 if (distributed_tria)
4290 distributed_tria->load_coarsen_flags(saved_coarsen_flags);
4291 distributed_tria->load_refine_flags(saved_refine_flags);
4295 (void)distributed_tria;
value_type * data() const noexcept
virtual void clear() override
virtual std::size_t memory_consumption() const override
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria) override
TemporarilyMatchRefineFlags(::Triangulation< dim, spacedim > &tria)
~TemporarilyMatchRefineFlags()
const SmartPointer< ::parallel::distributed::Triangulation< dim, spacedim > > distributed_tria
std::vector< bool > saved_refine_flags
std::vector< bool > saved_coarsen_flags
virtual void execute_coarsening_and_refinement() override
virtual void add_periodicity(const std::vector<::GridTools::PeriodicFacePair< cell_iterator > > &) override
virtual types::coarse_cell_id coarse_cell_index_to_coarse_cell_id(const unsigned int coarse_cell_index) const override
const std::vector< types::global_dof_index > & get_p4est_tree_to_coarse_cell_permutation() const
typename::internal::p4est::types< dim >::tree * init_tree(const int dealii_coarse_cell_index) const
types::subdomain_id find_point_owner_rank(const Point< dim > &p)
virtual bool prepare_coarsening_and_refinement() override
const ::internal::p4est::types< dim >::forest * get_p4est() const
const std::vector< types::global_dof_index > & get_coarse_cell_to_p4est_tree_permutation() const
void copy_new_triangulation_to_p4est(std::integral_constant< int, 2 >)
virtual void clear() override
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_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertNothrow(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
typename ::Triangulation< dim, spacedim >::active_cell_iterator active_cell_iterator
std::enable_if_t< std::is_fundamental< T >::value, std::size_t > memory_consumption(const T &t)
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
VectorType::value_type * end(VectorType &V)
T sum(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
std::vector< Integer > invert_permutation(const std::vector< Integer > &permutation)
bool tree_exists_locally(const typename types< dim >::forest *parallel_forest, const typename types< dim >::topidx coarse_grid_cell)
const types::subdomain_id artificial_subdomain_id
const types::subdomain_id invalid_subdomain_id
static const unsigned int invalid_unsigned_int
const types::manifold_id flat_manifold_id
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
static unsigned int standard_to_real_face_vertex(const unsigned int vertex, const bool face_orientation=true, const bool face_flip=false, const bool face_rotation=false)
static unsigned int face_to_cell_vertices(const unsigned int face, const unsigned int vertex, const bool face_orientation=true, const bool face_flip=false, const bool face_rotation=false)
static std_cxx20::ranges::iota_view< unsigned int, unsigned int > vertex_indices()
static bool is_inside_unit_cell(const Point< dim > &p)
static Point< dim > unit_cell_vertex(const unsigned int vertex)
const TriangulationDescription::Settings settings
const ::Triangulation< dim, spacedim > & tria