17 #include <deal.II/base/logstream.h> 18 #include <deal.II/base/memory_consumption.h> 19 #include <deal.II/base/utilities.h> 21 #include <deal.II/distributed/p4est_wrappers.h> 22 #include <deal.II/distributed/tria.h> 24 #include <deal.II/grid/grid_tools.h> 25 #include <deal.II/grid/tria.h> 26 #include <deal.II/grid/tria_accessor.h> 27 #include <deal.II/grid/tria_iterator.h> 29 #include <deal.II/lac/dynamic_sparsity_pattern.h> 30 #include <deal.II/lac/sparsity_tools.h> 38 DEAL_II_NAMESPACE_OPEN
41 #ifdef DEAL_II_WITH_P4EST 45 template <
int dim,
int spacedim>
47 get_vertex_to_cell_mappings(
49 std::vector<unsigned int> & vertex_touch_count,
50 std::vector<std::list<
52 unsigned int>>> & vertex_to_cell)
54 vertex_touch_count.resize(triangulation.
n_vertices());
55 vertex_to_cell.resize(triangulation.
n_vertices());
59 cell != triangulation.
end();
61 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; ++v)
63 ++vertex_touch_count[cell->vertex_index(v)];
64 vertex_to_cell[cell->vertex_index(v)].emplace_back(cell, v);
70 template <
int dim,
int spacedim>
72 get_edge_to_cell_mappings(
74 std::vector<unsigned int> & edge_touch_count,
75 std::vector<std::list<
77 unsigned int>>> & edge_to_cell)
86 cell != triangulation.
end();
88 for (
unsigned int l = 0; l < GeometryInfo<dim>::lines_per_cell; ++
l)
90 ++edge_touch_count[cell->line(l)->index()];
91 edge_to_cell[cell->line(l)->index()].emplace_back(cell, l);
101 template <
int dim,
int spacedim>
103 set_vertex_and_cell_info(
105 const std::vector<unsigned int> & vertex_touch_count,
106 const std::vector<std::list<
108 unsigned int>>> & vertex_to_cell,
109 const std::vector<types::global_dof_index>
110 & coarse_cell_to_p4est_tree_permutation,
111 const bool set_vertex_info,
127 if (set_vertex_info ==
true)
128 for (
unsigned int v = 0; v < triangulation.
n_vertices(); ++v)
130 connectivity->vertices[3 * v] = triangulation.
get_vertices()[v][0];
131 connectivity->vertices[3 * v + 1] =
133 connectivity->vertices[3 * v + 2] =
134 (spacedim == 2 ? 0 : triangulation.
get_vertices()[v][2]);
144 endc = triangulation.
end();
145 for (; cell != endc; ++cell)
147 const unsigned int index =
148 coarse_cell_to_p4est_tree_permutation[cell->index()];
150 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; ++v)
152 if (set_vertex_info ==
true)
155 v] = cell->vertex_index(v);
158 v] = cell->vertex_index(v);
163 for (
unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell; ++f)
164 if (cell->face(f)->at_boundary() ==
false)
167 coarse_cell_to_p4est_tree_permutation[cell->neighbor(f)->index()];
171 coarse_cell_to_p4est_tree_permutation[cell->index()];
175 for (
unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell; ++f)
176 if (cell->face(f)->at_boundary() ==
false)
182 connectivity->tree_to_face
184 cell->neighbor_of_neighbor(f);
203 connectivity->tree_to_face[index * 6 + f] =
204 cell->neighbor_of_neighbor(f);
206 unsigned int face_idx_list[2] = {
207 f, cell->neighbor_of_neighbor(f)};
209 cell_list[2] = {cell, cell->neighbor(f)};
210 unsigned int smaller_idx = 0;
212 if (f > cell->neighbor_of_neighbor(f))
215 unsigned int larger_idx = (smaller_idx + 1) % 2;
223 unsigned int g_idx = cell_list[smaller_idx]->vertex_index(
225 face_idx_list[smaller_idx],
227 cell_list[smaller_idx]->face_orientation(
228 face_idx_list[smaller_idx]),
229 cell_list[smaller_idx]->face_flip(
230 face_idx_list[smaller_idx]),
231 cell_list[smaller_idx]->face_rotation(
232 face_idx_list[smaller_idx])));
236 for (
unsigned int i = 0;
237 i < GeometryInfo<dim>::vertices_per_face;
241 cell_list[larger_idx]->vertex_index(
243 face_idx_list[larger_idx], i));
252 connectivity->tree_to_face[index * 6 + f] += 6 * v;
266 connectivity->ctt_offset[0] = 0;
267 std::partial_sum(vertex_touch_count.begin(),
268 vertex_touch_count.end(),
269 &connectivity->ctt_offset[1]);
272 std::accumulate(vertex_touch_count.begin(), vertex_touch_count.end(), 0u);
277 for (
unsigned int v = 0; v < triangulation.
n_vertices(); ++v)
279 Assert(vertex_to_cell[v].size() == vertex_touch_count[v],
283 std::pair<typename Triangulation<dim, spacedim>::active_cell_iterator,
284 unsigned int>>::const_iterator p =
285 vertex_to_cell[v].begin();
286 for (
unsigned int c = 0; c < vertex_touch_count[v]; ++c, ++p)
288 connectivity->corner_to_tree[connectivity->ctt_offset[v] + c] =
289 coarse_cell_to_p4est_tree_permutation[p->first->index()];
290 connectivity->corner_to_corner[connectivity->ctt_offset[v] + c] =
298 template <
int dim,
int spacedim>
304 Assert(coarse_grid_cell < parallel_forest->connectivity->num_trees,
306 return ((coarse_grid_cell >= parallel_forest->first_local_tree) &&
307 (coarse_grid_cell <= parallel_forest->last_local_tree));
311 template <
int dim,
int spacedim>
313 delete_all_children_and_self(
316 if (cell->has_children())
317 for (
unsigned int c = 0; c < cell->n_children(); ++c)
318 delete_all_children_and_self<dim, spacedim>(cell->child(c));
320 cell->set_coarsen_flag();
325 template <
int dim,
int spacedim>
330 if (cell->has_children())
331 for (
unsigned int c = 0; c < cell->n_children(); ++c)
332 delete_all_children_and_self<dim, spacedim>(cell->child(c));
336 template <
int dim,
int spacedim>
338 determine_level_subdomain_id_recursively(
345 const std::vector<std::vector<bool>> & marked_vertices)
352 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; ++v)
354 if (marked_vertices[dealii_cell->level()]
355 [dealii_cell->vertex_index(v)])
374 if (!used && dealii_cell->active() &&
375 dealii_cell->is_artificial() ==
false &&
376 dealii_cell->level() + 1 <
static_cast<int>(marked_vertices.size()))
378 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell;
381 if (marked_vertices[dealii_cell->level() + 1]
382 [dealii_cell->vertex_index(v)])
391 if (!used && dealii_cell->active() &&
392 dealii_cell->is_artificial() ==
false && dealii_cell->level() > 0)
394 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell;
397 if (marked_vertices[dealii_cell->level() - 1]
398 [dealii_cell->vertex_index(v)])
409 &forest, tree_index, &p4est_cell, my_subdomain);
410 Assert((owner != -2) && (owner != -1),
412 dealii_cell->set_level_subdomain_id(owner);
416 if (dealii_cell->has_children())
420 for (
unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
425 P4EST_QUADRANT_INIT(&p4est_child[c]);
428 P8EST_QUADRANT_INIT(&p4est_child[c]);
438 for (
unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
441 determine_level_subdomain_id_recursively<dim, spacedim>(
444 dealii_cell->child(c),
454 template <
int dim,
int spacedim>
456 match_tree_recursively(
464 if (sc_array_bsearch(const_cast<sc_array_t *>(&tree.quadrants),
470 delete_all_children<dim, spacedim>(dealii_cell);
471 if (!dealii_cell->has_children())
472 dealii_cell->set_subdomain_id(my_subdomain);
481 if (dealii_cell->has_children() ==
false)
482 dealii_cell->set_refine_flag();
487 for (
unsigned int c = 0;
488 c < GeometryInfo<dim>::max_children_per_cell;
493 P4EST_QUADRANT_INIT(&p4est_child[c]);
496 P8EST_QUADRANT_INIT(&p4est_child[c]);
506 for (
unsigned int c = 0;
507 c < GeometryInfo<dim>::max_children_per_cell;
512 &p4est_child[c]) ==
false)
518 delete_all_children<dim, spacedim>(dealii_cell->child(c));
519 dealii_cell->child(c)->recursively_set_subdomain_id(
526 match_tree_recursively<dim, spacedim>(tree,
527 dealii_cell->child(c),
537 template <
int dim,
int spacedim>
540 const ::Triangulation<dim, spacedim> * tria,
541 unsigned int dealii_index,
545 const int l = ghost_quadrant.level;
547 for (
int i = 0; i < l; ++i)
552 if (cell->has_children() ==
false)
554 cell->clear_coarsen_flag();
555 cell->set_refine_flag();
562 dealii_index = cell->child_index(child_id);
568 if (cell->has_children())
569 delete_all_children<dim, spacedim>(cell);
572 cell->clear_coarsen_flag();
573 cell->set_subdomain_id(ghost_owner);
584 template <
int dim,
int spacedim>
585 class RefineAndCoarsenList
589 const std::vector<types::global_dof_index>
590 &p4est_tree_to_coarse_cell_permutation,
618 pointers_are_at_end()
const;
621 std::vector<typename internal::p4est::types<dim>::quadrant> refine_list;
622 typename std::vector<typename internal::p4est::types<dim>::quadrant>::
623 const_iterator current_refine_pointer;
625 std::vector<typename internal::p4est::types<dim>::quadrant> coarsen_list;
626 typename std::vector<typename internal::p4est::types<dim>::quadrant>::
627 const_iterator current_coarsen_pointer;
638 template <
int dim,
int spacedim>
640 RefineAndCoarsenList<dim, spacedim>::pointers_are_at_end()
const 642 return ((current_refine_pointer == refine_list.end()) &&
643 (current_coarsen_pointer == coarsen_list.end()));
648 template <
int dim,
int spacedim>
649 RefineAndCoarsenList<dim, spacedim>::RefineAndCoarsenList(
651 const std::vector<types::global_dof_index>
652 & p4est_tree_to_coarse_cell_permutation,
656 unsigned int n_refine_flags = 0, n_coarsen_flags = 0;
659 cell != triangulation.
end();
663 if (cell->subdomain_id() != my_subdomain)
666 if (cell->refine_flag_set())
668 else if (cell->coarsen_flag_set())
672 refine_list.reserve(n_refine_flags);
673 coarsen_list.reserve(n_coarsen_flags);
683 for (
unsigned int c = 0; c < triangulation.
n_cells(0); ++c)
685 unsigned int coarse_cell_index =
686 p4est_tree_to_coarse_cell_permutation[c];
689 &triangulation, 0, coarse_cell_index);
695 p4est_cell.p.which_tree = c;
696 build_lists(cell, p4est_cell, my_subdomain);
704 for (
unsigned int i = 1; i < refine_list.size(); ++i)
705 Assert(refine_list[i].p.which_tree >= refine_list[i - 1].p.which_tree,
707 for (
unsigned int i = 1; i < coarsen_list.size(); ++i)
708 Assert(coarsen_list[i].p.which_tree >= coarsen_list[i - 1].p.which_tree,
711 current_refine_pointer = refine_list.begin();
712 current_coarsen_pointer = coarsen_list.begin();
717 template <
int dim,
int spacedim>
719 RefineAndCoarsenList<dim, spacedim>::build_lists(
724 if (!cell->has_children())
726 if (cell->subdomain_id() == my_subdomain)
728 if (cell->refine_flag_set())
729 refine_list.push_back(p4est_cell);
730 else if (cell->coarsen_flag_set())
731 coarsen_list.push_back(p4est_cell);
738 for (
unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
743 P4EST_QUADRANT_INIT(&p4est_child[c]);
746 P8EST_QUADRANT_INIT(&p4est_child[c]);
753 for (
unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
756 p4est_child[c].p.which_tree = p4est_cell.p.which_tree;
757 build_lists(cell->child(c), p4est_child[c], my_subdomain);
763 template <
int dim,
int spacedim>
765 RefineAndCoarsenList<dim, spacedim>::refine_callback(
770 RefineAndCoarsenList<dim, spacedim> *this_object =
771 reinterpret_cast<RefineAndCoarsenList<dim, spacedim> *
>(
772 forest->user_pointer);
776 if (this_object->current_refine_pointer == this_object->refine_list.end())
779 Assert(coarse_cell_index <=
780 this_object->current_refine_pointer->p.which_tree,
785 if (coarse_cell_index < this_object->current_refine_pointer->p.which_tree)
789 Assert(coarse_cell_index <=
790 this_object->current_refine_pointer->p.which_tree,
796 quadrant, &*this_object->current_refine_pointer) <= 0,
801 quadrant, &*this_object->current_refine_pointer))
803 ++this_object->current_refine_pointer;
813 template <
int dim,
int spacedim>
815 RefineAndCoarsenList<dim, spacedim>::coarsen_callback(
820 RefineAndCoarsenList<dim, spacedim> *this_object =
821 reinterpret_cast<RefineAndCoarsenList<dim, spacedim> *
>(
822 forest->user_pointer);
826 if (this_object->current_coarsen_pointer == this_object->coarsen_list.end())
829 Assert(coarse_cell_index <=
830 this_object->current_coarsen_pointer->p.which_tree,
835 if (coarse_cell_index < this_object->current_coarsen_pointer->p.which_tree)
839 Assert(coarse_cell_index <=
840 this_object->current_coarsen_pointer->p.which_tree,
846 children[0], &*this_object->current_coarsen_pointer) <= 0,
852 children[0], &*this_object->current_coarsen_pointer))
855 ++this_object->current_coarsen_pointer;
859 for (
unsigned int c = 1; c < GeometryInfo<dim>::max_children_per_cell;
863 children[c], &*this_object->current_coarsen_pointer),
865 ++this_object->current_coarsen_pointer;
883 template <
int dim,
int spacedim>
884 class PartitionWeights
892 explicit PartitionWeights(
const std::vector<unsigned int> &cell_weights);
907 std::vector<unsigned int> cell_weights_list;
908 std::vector<unsigned int>::const_iterator current_pointer;
912 template <
int dim,
int spacedim>
913 PartitionWeights<dim, spacedim>::PartitionWeights(
914 const std::vector<unsigned int> &cell_weights)
915 : cell_weights_list(cell_weights)
919 current_pointer = cell_weights_list.begin();
923 template <
int dim,
int spacedim>
925 PartitionWeights<dim, spacedim>::cell_weight(
934 PartitionWeights<dim, spacedim> *this_object =
935 reinterpret_cast<PartitionWeights<dim, spacedim> *
>(forest->user_pointer);
937 Assert(this_object->current_pointer >=
938 this_object->cell_weights_list.begin(),
940 Assert(this_object->current_pointer < this_object->cell_weights_list.end(),
944 return *this_object->current_pointer++;
949 template <
int dim,
int spacedim>
950 using quadrant_cell_relation_t =
typename std::tuple<
951 typename ::internal::p4est::types<dim>::quadrant *,
952 typename ::Triangulation<dim, spacedim>::CellStatus,
953 typename ::Triangulation<dim, spacedim>::cell_iterator>;
966 template <
int dim,
int spacedim>
968 add_single_quadrant_cell_relation(
969 std::vector<quadrant_cell_relation_t<dim, spacedim>> & quad_cell_rel,
970 const typename ::internal::p4est::types<dim>::tree & tree,
971 const unsigned int idx,
975 const unsigned int local_quadrant_index = tree.quadrants_offset + idx;
978 static_cast<typename ::internal::p4est::types<dim>::quadrant *
>(
979 sc_array_index(const_cast<sc_array_t *>(&tree.quadrants), idx));
985 quad_cell_rel[local_quadrant_index] =
986 std::make_tuple(q, status, dealii_cell);
1000 template <
int dim,
int spacedim>
1002 update_quadrant_cell_relations_recursively(
1003 std::vector<quadrant_cell_relation_t<dim, spacedim>> & quad_cell_rel,
1004 const typename ::internal::p4est::types<dim>::tree & tree,
1006 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell)
1009 const int idx = sc_array_bsearch(
1010 const_cast<sc_array_t *>(&tree.quadrants),
1015 const_cast<typename ::internal::p4est::types<dim>::tree *
>(
1017 &p4est_cell) ==
false))
1022 const bool p4est_has_children = (idx == -1);
1023 if (p4est_has_children && dealii_cell->has_children())
1026 typename ::internal::p4est::types<dim>::quadrant
1029 for (
unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
1034 P4EST_QUADRANT_INIT(&p4est_child[c]);
1037 P8EST_QUADRANT_INIT(&p4est_child[c]);
1044 &p4est_cell, p4est_child);
1046 for (
unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
1049 update_quadrant_cell_relations_recursively<dim, spacedim>(
1050 quad_cell_rel, tree, dealii_cell->child(c), p4est_child[c]);
1053 else if (!p4est_has_children && !dealii_cell->has_children())
1057 add_single_quadrant_cell_relation<dim, spacedim>(
1064 else if (p4est_has_children)
1072 typename ::internal::p4est::types<dim>::quadrant
1074 for (
unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
1079 P4EST_QUADRANT_INIT(&p4est_child[c]);
1082 P8EST_QUADRANT_INIT(&p4est_child[c]);
1089 &p4est_cell, p4est_child);
1096 for (
unsigned int i = 0; i < GeometryInfo<dim>::max_children_per_cell;
1099 child_idx = sc_array_bsearch(
1100 const_cast<sc_array_t *>(&tree.quadrants),
1107 add_single_quadrant_cell_relation<dim, spacedim>(
1108 quad_cell_rel, tree, child_idx, dealii_cell, cell_status);
1116 add_single_quadrant_cell_relation<dim, spacedim>(
1130 namespace distributed
1135 template <
int dim,
int spacedim>
1137 MPI_Comm mpi_communicator)
1138 : mpi_communicator(mpi_communicator)
1139 , variable_size_data_stored(false)
1144 template <
int dim,
int spacedim>
1147 const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
1148 const std::vector<typename CellAttachedData::pack_callback_t>
1149 &pack_callbacks_fixed,
1150 const std::vector<typename CellAttachedData::pack_callback_t>
1151 &pack_callbacks_variable)
1153 Assert(src_data_fixed.size() == 0,
1154 ExcMessage(
"Previously packed data has not been released yet!"));
1157 const unsigned int n_callbacks_fixed = pack_callbacks_fixed.size();
1158 const unsigned int n_callbacks_variable = pack_callbacks_variable.size();
1162 variable_size_data_stored = (n_callbacks_variable > 0);
1168 std::vector<unsigned int> cell_sizes_variable_cumulative(
1169 n_callbacks_variable);
1183 std::vector<std::vector<std::vector<char>>> packed_fixed_size_data(
1184 quad_cell_relations.size());
1185 std::vector<std::vector<std::vector<char>>> packed_variable_size_data(
1186 variable_size_data_stored ? quad_cell_relations.size() : 0);
1194 auto quad_cell_rel_it = quad_cell_relations.cbegin();
1195 auto data_cell_fixed_it = packed_fixed_size_data.begin();
1196 auto data_cell_variable_it = packed_variable_size_data.begin();
1197 for (; quad_cell_rel_it != quad_cell_relations.cend();
1198 ++quad_cell_rel_it, ++data_cell_fixed_it)
1200 const auto &cell_status = std::get<1>(*quad_cell_rel_it);
1201 const auto &dealii_cell = std::get<2>(*quad_cell_rel_it);
1204 switch (cell_status)
1222 for (
unsigned int c = 0;
1223 c < GeometryInfo<dim>::max_children_per_cell;
1246 const unsigned int n_fixed_size_data_sets_on_cell =
1250 spacedim>::CELL_INVALID) ?
1252 ((variable_size_data_stored ? 1 : 0) + n_callbacks_fixed));
1253 data_cell_fixed_it->resize(n_fixed_size_data_sets_on_cell);
1256 auto data_fixed_it = data_cell_fixed_it->begin();
1269 spacedim>::CELL_INVALID)
1272 for (
auto callback_it = pack_callbacks_fixed.cbegin();
1273 callback_it != pack_callbacks_fixed.cend();
1274 ++callback_it, ++data_fixed_it)
1276 *data_fixed_it = (*callback_it)(dealii_cell, cell_status);
1283 if (variable_size_data_stored)
1285 const unsigned int n_variable_size_data_sets_on_cell =
1290 n_callbacks_variable);
1291 data_cell_variable_it->resize(
1292 n_variable_size_data_sets_on_cell);
1294 auto callback_it = pack_callbacks_variable.cbegin();
1295 auto data_variable_it = data_cell_variable_it->begin();
1296 auto sizes_variable_it =
1297 cell_sizes_variable_cumulative.begin();
1298 for (; callback_it != pack_callbacks_variable.cend();
1299 ++callback_it, ++data_variable_it, ++sizes_variable_it)
1302 (*callback_it)(dealii_cell, cell_status);
1306 *sizes_variable_it = data_variable_it->size();
1310 std::partial_sum(cell_sizes_variable_cumulative.begin(),
1311 cell_sizes_variable_cumulative.end(),
1312 cell_sizes_variable_cumulative.begin());
1318 data_fixed_it->resize(n_callbacks_variable *
1319 sizeof(
unsigned int));
1320 for (
unsigned int i = 0; i < n_callbacks_variable; ++i)
1321 std::memcpy(&(data_fixed_it->at(i *
1322 sizeof(
unsigned int))),
1323 &(cell_sizes_variable_cumulative.at(i)),
1324 sizeof(
unsigned int));
1331 Assert(data_fixed_it == data_cell_fixed_it->end(),
1338 if (variable_size_data_stored)
1339 ++data_cell_variable_it;
1356 std::vector<unsigned int> local_sizes_fixed(
1357 1 + n_callbacks_fixed + (variable_size_data_stored ? 1 : 0));
1358 for (
auto data_cell_fixed_it = packed_fixed_size_data.cbegin();
1359 data_cell_fixed_it != packed_fixed_size_data.cend();
1360 ++data_cell_fixed_it)
1362 if (data_cell_fixed_it->size() == local_sizes_fixed.size())
1364 auto sizes_fixed_it = local_sizes_fixed.begin();
1365 auto data_fixed_it = data_cell_fixed_it->cbegin();
1366 for (; data_fixed_it != data_cell_fixed_it->cend();
1367 ++data_fixed_it, ++sizes_fixed_it)
1369 *sizes_fixed_it = data_fixed_it->size();
1377 for (
auto data_cell_fixed_it = packed_fixed_size_data.cbegin();
1378 data_cell_fixed_it != packed_fixed_size_data.cend();
1379 ++data_cell_fixed_it)
1381 Assert((data_cell_fixed_it->size() == 1) ||
1382 (data_cell_fixed_it->size() == local_sizes_fixed.size()),
1389 std::vector<unsigned int> global_sizes_fixed(local_sizes_fixed.size());
1391 this->mpi_communicator,
1392 global_sizes_fixed);
1396 sizes_fixed_cumulative.resize(global_sizes_fixed.size());
1397 std::partial_sum(global_sizes_fixed.begin(),
1398 global_sizes_fixed.end(),
1399 sizes_fixed_cumulative.begin());
1404 if (variable_size_data_stored)
1406 src_sizes_variable.reserve(packed_variable_size_data.size());
1407 for (
auto data_cell_variable_it = packed_variable_size_data.cbegin();
1408 data_cell_variable_it != packed_variable_size_data.cend();
1409 ++data_cell_variable_it)
1411 int variable_data_size_on_cell = 0;
1413 for (
auto data_variable_it = data_cell_variable_it->cbegin();
1414 data_variable_it != data_cell_variable_it->cend();
1416 variable_data_size_on_cell += data_variable_it->size();
1418 src_sizes_variable.push_back(variable_data_size_on_cell);
1425 const unsigned int expected_size_fixed =
1426 quad_cell_relations.size() * sizes_fixed_cumulative.back();
1427 const unsigned int expected_size_variable =
1428 std::accumulate(src_sizes_variable.begin(),
1429 src_sizes_variable.end(),
1430 std::vector<int>::size_type(0));
1433 src_data_fixed.reserve(expected_size_fixed);
1434 for (
auto data_cell_fixed_it = packed_fixed_size_data.begin();
1435 data_cell_fixed_it != packed_fixed_size_data.end();
1436 ++data_cell_fixed_it)
1440 for (
auto data_fixed_it = data_cell_fixed_it->begin();
1441 data_fixed_it != data_cell_fixed_it->end();
1443 std::move(data_fixed_it->begin(),
1444 data_fixed_it->end(),
1445 std::back_inserter(src_data_fixed));
1451 if ((data_cell_fixed_it->size() == 1) &&
1452 (sizes_fixed_cumulative.size() > 1))
1454 const std::size_t bytes_skipped =
1455 sizes_fixed_cumulative.back() - sizes_fixed_cumulative.front();
1457 src_data_fixed.insert(src_data_fixed.end(),
1459 static_cast<char>(-1));
1465 if (variable_size_data_stored)
1467 src_data_variable.reserve(expected_size_variable);
1468 for (
auto data_cell_variable_it = packed_variable_size_data.begin();
1469 data_cell_variable_it != packed_variable_size_data.end();
1470 ++data_cell_variable_it)
1474 for (
auto data_variable_it = data_cell_variable_it->begin();
1475 data_variable_it != data_cell_variable_it->end();
1477 std::move(data_variable_it->begin(),
1478 data_variable_it->end(),
1479 std::back_inserter(src_data_variable));
1485 Assert(src_data_variable.size() == expected_size_variable,
1491 template <
int dim,
int spacedim>
1494 const typename ::internal::p4est::types<dim>::forest
1496 const typename ::internal::p4est::types<dim>::gloidx
1497 *previous_global_first_quadrant)
1499 Assert(sizes_fixed_cumulative.size() > 0,
1503 dest_data_fixed.resize(parallel_forest->local_num_quadrants *
1504 sizes_fixed_cumulative.back());
1507 typename ::internal::p4est::types<dim>::transfer_context
1511 parallel_forest->global_first_quadrant,
1512 previous_global_first_quadrant,
1513 parallel_forest->mpicomm,
1515 dest_data_fixed.data(),
1516 src_data_fixed.data(),
1517 sizes_fixed_cumulative.back());
1519 if (variable_size_data_stored)
1522 dest_sizes_variable.resize(parallel_forest->local_num_quadrants);
1527 parallel_forest->global_first_quadrant,
1528 previous_global_first_quadrant,
1529 parallel_forest->mpicomm,
1531 dest_sizes_variable.data(),
1532 src_sizes_variable.data(),
1539 src_data_fixed.clear();
1540 src_data_fixed.shrink_to_fit();
1542 if (variable_size_data_stored)
1545 dest_data_variable.resize(
1546 std::accumulate(dest_sizes_variable.begin(),
1547 dest_sizes_variable.end(),
1548 std::vector<int>::size_type(0)));
1555 if (src_sizes_variable.size() == 0)
1556 src_sizes_variable.resize(1);
1557 if (dest_sizes_variable.size() == 0)
1558 dest_sizes_variable.resize(1);
1562 parallel_forest->global_first_quadrant,
1563 previous_global_first_quadrant,
1564 parallel_forest->mpicomm,
1566 dest_data_variable.data(),
1567 dest_sizes_variable.data(),
1568 src_data_variable.data(),
1569 src_sizes_variable.data());
1572 src_sizes_variable.clear();
1573 src_sizes_variable.shrink_to_fit();
1574 src_data_variable.clear();
1575 src_data_variable.shrink_to_fit();
1581 template <
int dim,
int spacedim>
1584 std::vector<quadrant_cell_relation_t> &quad_cell_relations)
const 1586 Assert(sizes_fixed_cumulative.size() > 0,
1588 if (quad_cell_relations.size() > 0)
1590 Assert(dest_data_fixed.size() > 0,
1595 const unsigned int size = sizes_fixed_cumulative.front();
1601 auto quad_cell_rel_it = quad_cell_relations.begin();
1602 auto dest_fixed_it = dest_data_fixed.cbegin();
1603 for (; quad_cell_rel_it != quad_cell_relations.end();
1604 ++quad_cell_rel_it, dest_fixed_it += sizes_fixed_cumulative.back())
1606 std::get<1>(*quad_cell_rel_it) =
1608 Triangulation<dim, spacedim>::CellStatus>(
1610 dest_fixed_it + size,
1617 template <
int dim,
int spacedim>
1620 const std::vector<quadrant_cell_relation_t> &quad_cell_relations,
1621 const unsigned int handle,
1622 const std::function<
void(
1623 const typename ::Triangulation<dim, spacedim>::cell_iterator &,
1624 const typename ::Triangulation<dim, spacedim>::CellStatus &,
1625 const boost::iterator_range<std::vector<char>::const_iterator> &)>
1626 &unpack_callback)
const 1632 const bool callback_variable_transfer = (handle % 2 == 0);
1633 const unsigned int callback_index = handle / 2;
1635 Assert(sizes_fixed_cumulative.size() > 0,
1637 if (quad_cell_relations.size() > 0)
1639 Assert(dest_data_fixed.size() > 0,
1642 if (callback_variable_transfer)
1643 Assert(dest_data_variable.size() > 0,
1647 std::vector<char>::const_iterator dest_data_it;
1648 std::vector<char>::const_iterator dest_sizes_cell_it;
1658 if (callback_variable_transfer)
1671 const unsigned int offset_variable_data_sizes =
1672 sizes_fixed_cumulative[sizes_fixed_cumulative.size() - 2];
1679 dest_sizes_cell_it = dest_data_fixed.cbegin() +
1680 offset_variable_data_sizes +
1681 callback_index *
sizeof(
unsigned int);
1684 dest_data_it = dest_data_variable.cbegin();
1691 offset = sizes_fixed_cumulative[callback_index];
1692 size = sizes_fixed_cumulative[callback_index + 1] - offset;
1693 data_increment = sizes_fixed_cumulative.back();
1699 dest_data_it = dest_data_fixed.cbegin() + offset;
1703 auto quad_cell_rel_it = quad_cell_relations.begin();
1704 auto dest_sizes_it = dest_sizes_variable.cbegin();
1705 for (; quad_cell_rel_it != quad_cell_relations.end();
1706 ++quad_cell_rel_it, dest_data_it += data_increment)
1708 const auto &cell_status = std::get<1>(*quad_cell_rel_it);
1709 const auto &dealii_cell = std::get<2>(*quad_cell_rel_it);
1711 if (callback_variable_transfer)
1715 data_increment = *dest_sizes_it;
1719 spacedim>::CELL_INVALID)
1723 if (callback_index == 0)
1726 std::memcpy(&offset,
1727 &(*(dest_sizes_cell_it -
sizeof(
unsigned int))),
1728 sizeof(
unsigned int));
1731 &(*dest_sizes_cell_it),
1732 sizeof(
unsigned int));
1739 dest_data_it += offset;
1740 data_increment -= offset;
1744 dest_sizes_cell_it += sizes_fixed_cumulative.back();
1748 switch (cell_status)
1751 spacedim>::CELL_PERSIST:
1753 spacedim>::CELL_COARSEN:
1754 unpack_callback(dealii_cell,
1756 boost::make_iterator_range(dest_data_it,
1762 spacedim>::CELL_REFINE:
1763 unpack_callback(dealii_cell->parent(),
1765 boost::make_iterator_range(dest_data_it,
1771 spacedim>::CELL_INVALID:
1784 template <
int dim,
int spacedim>
1787 const typename ::internal::p4est::types<dim>::forest
1789 const char *filename)
const 1795 Assert(sizes_fixed_cumulative.size() > 0,
1804 const std::string fname_fixed = std::string(filename) +
"_fixed.data";
1807 int ierr = MPI_Info_create(&info);
1811 ierr = MPI_File_open(mpi_communicator,
1812 fname_fixed.c_str(),
1813 MPI_MODE_CREATE | MPI_MODE_WRONLY,
1818 ierr = MPI_File_set_size(fh, 0);
1822 ierr = MPI_Barrier(mpi_communicator);
1824 ierr = MPI_Info_free(&info);
1836 ierr = MPI_File_write_at(fh,
1838 sizes_fixed_cumulative.data(),
1839 sizes_fixed_cumulative.size(),
1846 const unsigned int offset_fixed =
1847 sizes_fixed_cumulative.size() *
sizeof(
unsigned int);
1849 ierr = MPI_File_write_at(
1852 parallel_forest->global_first_quadrant[myrank] *
1853 sizes_fixed_cumulative.back(),
1854 src_data_fixed.data(),
1855 src_data_fixed.size(),
1860 ierr = MPI_File_close(&fh);
1867 if (variable_size_data_stored)
1869 const std::string fname_variable =
1870 std::string(filename) +
"_variable.data";
1875 int ierr = MPI_Info_create(&info);
1879 ierr = MPI_File_open(mpi_communicator,
1880 fname_variable.c_str(),
1881 MPI_MODE_CREATE | MPI_MODE_WRONLY,
1886 ierr = MPI_File_set_size(fh, 0);
1890 ierr = MPI_Barrier(mpi_communicator);
1892 ierr = MPI_Info_free(&info);
1897 MPI_File_write_at(fh,
1898 parallel_forest->global_first_quadrant[myrank] *
1900 src_sizes_variable.data(),
1901 src_sizes_variable.size(),
1906 const unsigned int offset_variable =
1907 parallel_forest->global_num_quadrants *
sizeof(int);
1910 const unsigned int size_on_proc = src_data_variable.size();
1913 std::vector<unsigned int> sizes_on_all_procs(n_procs);
1914 ierr = MPI_Allgather(&size_on_proc,
1917 sizes_on_all_procs.data(),
1925 std::partial_sum(sizes_on_all_procs.begin(),
1926 sizes_on_all_procs.end(),
1927 sizes_on_all_procs.begin());
1930 ierr = MPI_File_write_at(
1935 sizes_on_all_procs[myrank - 1]),
1936 src_data_variable.data(),
1937 src_data_variable.size(),
1942 ierr = MPI_File_close(&fh);
1949 template <
int dim,
int spacedim>
1952 const typename ::internal::p4est::types<dim>::forest
1954 const char * filename,
1955 const unsigned int n_attached_deserialize_fixed,
1956 const unsigned int n_attached_deserialize_variable)
1962 Assert(dest_data_fixed.size() == 0,
1963 ExcMessage(
"Previously loaded data has not been released yet!"));
1965 variable_size_data_stored = (n_attached_deserialize_variable > 0);
1973 const std::string fname_fixed = std::string(filename) +
"_fixed.data";
1976 int ierr = MPI_Info_create(&info);
1980 ierr = MPI_File_open(
1981 mpi_communicator, fname_fixed.c_str(), MPI_MODE_RDONLY, info, &fh);
1984 ierr = MPI_Info_free(&info);
1994 sizes_fixed_cumulative.resize(1 + n_attached_deserialize_fixed +
1995 (variable_size_data_stored ? 1 : 0));
1996 ierr = MPI_File_read_at(fh,
1998 sizes_fixed_cumulative.data(),
1999 sizes_fixed_cumulative.size(),
2005 dest_data_fixed.resize(parallel_forest->local_num_quadrants *
2006 sizes_fixed_cumulative.back());
2009 const unsigned int offset =
2010 sizes_fixed_cumulative.size() *
sizeof(
unsigned int);
2012 ierr = MPI_File_read_at(
2014 offset + parallel_forest->global_first_quadrant[myrank] *
2015 sizes_fixed_cumulative.back(),
2016 dest_data_fixed.data(),
2017 dest_data_fixed.size(),
2022 ierr = MPI_File_close(&fh);
2029 if (variable_size_data_stored)
2031 const std::string fname_variable =
2032 std::string(filename) +
"_variable.data";
2037 int ierr = MPI_Info_create(&info);
2041 ierr = MPI_File_open(mpi_communicator,
2042 fname_variable.c_str(),
2048 ierr = MPI_Info_free(&info);
2052 dest_sizes_variable.resize(parallel_forest->local_num_quadrants);
2054 MPI_File_read_at(fh,
2055 parallel_forest->global_first_quadrant[myrank] *
2057 dest_sizes_variable.data(),
2058 dest_sizes_variable.size(),
2063 const unsigned int offset =
2064 parallel_forest->global_num_quadrants *
sizeof(int);
2066 const unsigned int size_on_proc =
2067 std::accumulate(dest_sizes_variable.begin(),
2068 dest_sizes_variable.end(),
2072 std::vector<unsigned int> sizes_on_all_procs(n_procs);
2073 ierr = MPI_Allgather(&size_on_proc,
2076 sizes_on_all_procs.data(),
2083 std::partial_sum(sizes_on_all_procs.begin(),
2084 sizes_on_all_procs.end(),
2085 sizes_on_all_procs.begin());
2087 dest_data_variable.resize(size_on_proc);
2088 ierr = MPI_File_read_at(fh,
2089 offset + ((myrank == 0) ?
2091 sizes_on_all_procs[myrank - 1]),
2092 dest_data_variable.data(),
2093 dest_data_variable.size(),
2098 ierr = MPI_File_close(&fh);
2105 template <
int dim,
int spacedim>
2109 variable_size_data_stored =
false;
2112 sizes_fixed_cumulative.
clear();
2113 sizes_fixed_cumulative.shrink_to_fit();
2116 src_data_fixed.clear();
2117 src_data_fixed.shrink_to_fit();
2119 dest_data_fixed.clear();
2120 dest_data_fixed.shrink_to_fit();
2123 src_sizes_variable.clear();
2124 src_sizes_variable.shrink_to_fit();
2126 src_data_variable.clear();
2127 src_data_variable.shrink_to_fit();
2129 dest_sizes_variable.clear();
2130 dest_sizes_variable.shrink_to_fit();
2132 dest_data_variable.clear();
2133 dest_data_variable.shrink_to_fit();
2141 template <
int dim,
int spacedim>
2143 MPI_Comm mpi_communicator,
2144 const typename ::Triangulation<dim, spacedim>::MeshSmoothing
2152 (settings_ & construct_multigrid_hierarchy) ?
2156 Triangulation<dim, spacedim>::limit_level_difference_at_vertices) :
2159 , settings(settings_)
2160 , triangulation_has_content(false)
2161 , connectivity(nullptr)
2162 , parallel_forest(nullptr)
2163 , cell_attached_data({0, 0, {}, {}})
2171 template <
int dim,
int spacedim>
2191 template <
int dim,
int spacedim>
2204 const typename ::Triangulation<dim, spacedim>::DistortedCellList
2239 namespace CommunicateLocallyMovedVertices
2248 template <
int dim,
int spacedim>
2253 std::vector<unsigned int> tree_index;
2256 std::vector<typename ::internal::p4est::types<dim>::quadrant>
2260 std::vector<unsigned int> vertex_indices;
2263 std::vector<::Point<spacedim>>
vertices;
2267 std::vector<unsigned int *> first_vertex_indices;
2268 std::vector<::Point<spacedim> *> first_vertices;
2271 bytes_for_buffer()
const 2273 return sizeof(
unsigned int) +
2274 tree_index.size() *
sizeof(
unsigned int) +
2276 sizeof(typename ::internal::p4est ::types<
2278 vertex_indices.size() *
sizeof(
unsigned int) +
2283 pack_data(std::vector<char> &buffer)
const 2285 buffer.resize(bytes_for_buffer());
2287 char *ptr = buffer.data();
2289 const unsigned int num_cells = tree_index.size();
2290 std::memcpy(ptr, &num_cells,
sizeof(
unsigned int));
2291 ptr +=
sizeof(
unsigned int);
2295 num_cells *
sizeof(
unsigned int));
2296 ptr += num_cells *
sizeof(
unsigned int);
2302 sizeof(typename ::internal::p4est::types<dim>::quadrant));
2305 sizeof(typename ::internal::p4est::types<dim>::quadrant);
2308 vertex_indices.data(),
2309 vertex_indices.size() *
sizeof(
unsigned int));
2310 ptr += vertex_indices.size() *
sizeof(
unsigned int);
2320 unpack_data(
const std::vector<char> &buffer)
2322 const char * ptr = buffer.data();
2324 memcpy(&cells, ptr,
sizeof(
unsigned int));
2325 ptr +=
sizeof(
unsigned int);
2327 tree_index.resize(cells);
2328 memcpy(tree_index.data(), ptr,
sizeof(
unsigned int) * cells);
2329 ptr +=
sizeof(
unsigned int) * cells;
2331 quadrants.resize(cells);
2332 memcpy(quadrants.data(),
2335 typename ::internal::p4est::types<dim>::quadrant) *
2338 sizeof(typename ::internal::p4est::types<dim>::quadrant) *
2341 vertex_indices.clear();
2342 first_vertex_indices.resize(cells);
2343 std::vector<unsigned int> n_vertices_on_cell(cells);
2344 std::vector<unsigned int> first_indices(cells);
2345 for (
unsigned int c = 0; c < cells; ++c)
2350 const unsigned int *
const vertex_index =
2351 reinterpret_cast<const unsigned int *
>(ptr);
2352 first_indices[c] = vertex_indices.size();
2353 vertex_indices.push_back(*vertex_index);
2354 n_vertices_on_cell[c] = *vertex_index;
2355 ptr +=
sizeof(
unsigned int);
2357 vertex_indices.resize(vertex_indices.size() +
2358 n_vertices_on_cell[c]);
2359 memcpy(&vertex_indices[vertex_indices.size() -
2360 n_vertices_on_cell[c]],
2362 n_vertices_on_cell[c] *
sizeof(
unsigned int));
2363 ptr += n_vertices_on_cell[c] *
sizeof(
unsigned int);
2365 for (
unsigned int c = 0; c < cells; ++c)
2366 first_vertex_indices[c] = &vertex_indices[first_indices[c]];
2369 first_vertices.resize(cells);
2370 for (
unsigned int c = 0; c < cells; ++c)
2372 first_indices[c] = vertices.size();
2373 vertices.resize(vertices.size() + n_vertices_on_cell[c]);
2374 memcpy(&vertices[vertices.size() - n_vertices_on_cell[c]],
2379 for (
unsigned int c = 0; c < cells; ++c)
2380 first_vertices[c] = &vertices[first_indices[c]];
2400 template <
int dim,
int spacedim>
2402 fill_vertices_recursively(
2405 const unsigned int tree_index,
2408 const typename ::internal::p4est::types<dim>::quadrant
2410 const std::map<
unsigned int, std::set<::types::subdomain_id>>
2411 & vertices_with_ghost_neighbors,
2412 const std::vector<bool> &vertex_locally_moved,
2418 if (dealii_cell->has_children())
2420 typename ::internal::p4est::types<dim>::quadrant
2422 ::internal::p4est::init_quadrant_children<dim>(p4est_cell,
2426 for (
unsigned int c = 0;
2427 c < GeometryInfo<dim>::max_children_per_cell;
2429 fill_vertices_recursively<dim, spacedim>(
2432 dealii_cell->child(c),
2434 vertices_with_ghost_neighbors,
2435 vertex_locally_moved,
2447 if (dealii_cell->is_locally_owned())
2449 std::set<::types::subdomain_id> send_to;
2450 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell;
2453 const std::map<
unsigned int,
2454 std::set<::types::subdomain_id>>::
2455 const_iterator neighbor_subdomains_of_vertex =
2456 vertices_with_ghost_neighbors.find(
2457 dealii_cell->vertex_index(v));
2459 if (neighbor_subdomains_of_vertex !=
2460 vertices_with_ghost_neighbors.end())
2462 Assert(neighbor_subdomains_of_vertex->second.size() != 0,
2465 neighbor_subdomains_of_vertex->second.begin(),
2466 neighbor_subdomains_of_vertex->second.end());
2470 if (send_to.size() > 0)
2472 std::vector<unsigned int> vertex_indices;
2473 std::vector<::Point<spacedim>> local_vertices;
2474 for (
unsigned int v = 0;
2475 v < GeometryInfo<dim>::vertices_per_cell;
2477 if (vertex_locally_moved[dealii_cell->vertex_index(v)])
2479 vertex_indices.push_back(v);
2480 local_vertices.push_back(dealii_cell->vertex(v));
2483 if (vertex_indices.size() > 0)
2484 for (std::set<::types::subdomain_id>::iterator it =
2486 it != send_to.end();
2489 const ::types::subdomain_id subdomain = *it;
2494 const typename std::map<
2496 CellInfo<dim, spacedim>>::iterator p =
2498 .insert(std::make_pair(subdomain,
2499 CellInfo<dim, spacedim>()))
2502 p->second.tree_index.push_back(tree_index);
2503 p->second.quadrants.push_back(p4est_cell);
2505 p->second.vertex_indices.push_back(
2506 vertex_indices.size());
2507 p->second.vertex_indices.insert(
2508 p->second.vertex_indices.end(),
2509 vertex_indices.begin(),
2510 vertex_indices.end());
2512 p->second.vertices.insert(p->second.vertices.end(),
2513 local_vertices.begin(),
2514 local_vertices.end());
2531 template <
int dim,
int spacedim>
2533 set_vertices_recursively(
2535 const typename ::internal::p4est::types<dim>::quadrant
2539 const typename ::internal::p4est::types<dim>::quadrant
2541 const ::Point<spacedim> *
const vertices,
2542 const unsigned int *
const vertex_indices)
2544 if (::internal::p4est::quadrant_is_equal<dim>(p4est_cell,
2551 const unsigned int n_vertices = vertex_indices[0];
2554 for (
unsigned int i = 0; i <
n_vertices; ++i)
2555 dealii_cell->vertex(vertex_indices[i + 1]) = vertices[i];
2560 if (!dealii_cell->has_children())
2563 if (!::internal::p4est::quadrant_is_ancestor<dim>(p4est_cell,
2567 typename ::internal::p4est::types<dim>::quadrant
2569 ::internal::p4est::init_quadrant_children<dim>(p4est_cell,
2572 for (
unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
2574 set_vertices_recursively<dim, spacedim>(tria,
2576 dealii_cell->child(c),
2586 template <
int dim,
int spacedim>
2592 cell_attached_data = {0, 0, {}, {}};
2593 data_transfer.clear();
2602 if (parallel_forest !=
nullptr)
2605 parallel_forest =
nullptr;
2608 if (connectivity !=
nullptr)
2612 connectivity =
nullptr;
2615 coarse_cell_to_p4est_tree_permutation.resize(0);
2616 p4est_tree_to_coarse_cell_permutation.resize(0);
2625 template <
int dim,
int spacedim>
2638 bool have_coarser_cell =
false;
2643 if (cell->is_locally_owned())
2645 have_coarser_cell =
true;
2656 template <
int dim,
int spacedim>
2661 ::GridTools::get_vertex_connectivity_of_cells(*
this,
2663 coarse_cell_to_p4est_tree_permutation.resize(this->
n_cells(0));
2665 cell_connectivity, coarse_cell_to_p4est_tree_permutation);
2667 p4est_tree_to_coarse_cell_permutation =
2673 template <
int dim,
int spacedim>
2676 const char *file_basename)
const 2678 Assert(parallel_forest !=
nullptr,
2679 ExcMessage(
"Can't produce output when no forest is created yet."));
2687 template <
int dim,
int spacedim>
2692 cell_attached_data.n_attached_deserialize == 0,
2694 "not all SolutionTransfer's got deserialized after the last load()"));
2696 ExcMessage(
"Can not save() an empty Triangulation."));
2701 if (this->my_subdomain == 0)
2703 std::string fname = std::string(filename) +
".info";
2704 std::ofstream f(fname.c_str());
2705 f <<
"version nproc n_attached_fixed_size_objs n_attached_variable_size_objs n_coarse_cells" 2709 << cell_attached_data.pack_callbacks_fixed.size() <<
" " 2710 << cell_attached_data.pack_callbacks_variable.size() <<
" " 2711 << this->
n_cells(0) << std::endl;
2717 (void)quad_cell_rel;
2719 (std::get<1>(quad_cell_rel) ==
2724 if (cell_attached_data.n_attached_data_sets > 0)
2727 auto tria =
const_cast< 2733 local_quadrant_cell_relations,
2734 cell_attached_data.pack_callbacks_fixed,
2735 cell_attached_data.pack_callbacks_variable);
2738 tria->data_transfer.save(parallel_forest, filename);
2741 tria->data_transfer.clear();
2756 tria->cell_attached_data.n_attached_data_sets = 0;
2757 tria->cell_attached_data.pack_callbacks_fixed.clear();
2763 template <
int dim,
int spacedim>
2766 const bool autopartition)
2771 "load() only works if the Triangulation already contains a coarse mesh!"));
2775 "Triangulation may only contain coarse cells when calling load()."));
2785 parallel_forest =
nullptr;
2788 connectivity =
nullptr;
2790 unsigned int version, numcpus, attached_count_fixed,
2791 attached_count_variable, n_coarse_cells;
2793 std::string fname = std::string(filename) +
".info";
2794 std::ifstream f(fname.c_str());
2796 std::string firstline;
2797 getline(f, firstline);
2798 f >> version >> numcpus >> attached_count_fixed >>
2799 attached_count_variable >> n_coarse_cells;
2803 ExcMessage(
"Incompatible version found in .info file."));
2805 ExcMessage(
"Number of coarse cells differ!"));
2809 cell_attached_data.n_attached_data_sets = 0;
2810 cell_attached_data.n_attached_deserialize =
2811 attached_count_fixed + attached_count_variable;
2845 if (cell_attached_data.n_attached_deserialize > 0)
2847 data_transfer.load(parallel_forest,
2849 attached_count_fixed,
2850 attached_count_variable);
2857 (void)quad_cell_rel;
2859 (std::get<1>(quad_cell_rel) ==
2876 template <
int dim,
int spacedim>
2880 Assert(parallel_forest !=
nullptr,
2882 "Can't produce a check sum when no forest is created yet."));
2883 return ::internal::p4est::functions<dim>::checksum(parallel_forest);
2888 template <
int dim,
int spacedim>
2900 template <
int dim,
int spacedim>
2901 typename ::internal::p4est::types<dim>::tree *
2903 const int dealii_coarse_cell_index)
const 2905 const unsigned int tree_index =
2906 coarse_cell_to_p4est_tree_permutation[dealii_coarse_cell_index];
2907 typename ::internal::p4est::types<dim>::tree *tree =
2908 static_cast<typename ::internal::p4est::types<dim>::tree *
>(
2909 sc_array_index(parallel_forest->trees, tree_index));
2919 std::integral_constant<int, 2>)
2921 const unsigned int dim = 2, spacedim = 2;
2929 std::vector<unsigned int> vertex_touch_count;
2931 std::list<std::pair<Triangulation<dim, spacedim>::active_cell_iterator,
2934 get_vertex_to_cell_mappings(*
this, vertex_touch_count, vertex_to_cell);
2935 const ::internal::p4est::types<2>::locidx num_vtt =
2936 std::accumulate(vertex_touch_count.begin(),
2937 vertex_touch_count.end(),
2943 const bool set_vertex_info
2952 (set_vertex_info ==
true ? this->
n_vertices() : 0),
2957 set_vertex_and_cell_info(*
this,
2960 coarse_cell_to_p4est_tree_permutation,
2964 Assert(p4est_connectivity_is_valid(connectivity) == 1,
2986 std::integral_constant<int, 2>)
2988 const unsigned int dim = 2, spacedim = 3;
2996 std::vector<unsigned int> vertex_touch_count;
2998 std::list<std::pair<Triangulation<dim, spacedim>::active_cell_iterator,
3001 get_vertex_to_cell_mappings(*
this, vertex_touch_count, vertex_to_cell);
3002 const ::internal::p4est::types<2>::locidx num_vtt =
3003 std::accumulate(vertex_touch_count.begin(),
3004 vertex_touch_count.end(),
3010 const bool set_vertex_info
3019 (set_vertex_info ==
true ? this->
n_vertices() : 0),
3024 set_vertex_and_cell_info(*
this,
3027 coarse_cell_to_p4est_tree_permutation,
3031 Assert(p4est_connectivity_is_valid(connectivity) == 1,
3051 std::integral_constant<int, 3>)
3053 const int dim = 3, spacedim = 3;
3061 std::vector<unsigned int> vertex_touch_count;
3062 std::vector<std::list<
3063 std::pair<Triangulation<3>::active_cell_iterator,
unsigned int>>>
3065 get_vertex_to_cell_mappings(*
this, vertex_touch_count, vertex_to_cell);
3066 const ::internal::p4est::types<2>::locidx num_vtt =
3067 std::accumulate(vertex_touch_count.begin(),
3068 vertex_touch_count.end(),
3071 std::vector<unsigned int> edge_touch_count;
3072 std::vector<std::list<
3073 std::pair<Triangulation<3>::active_cell_iterator,
unsigned int>>>
3075 get_edge_to_cell_mappings(*
this, edge_touch_count, edge_to_cell);
3076 const ::internal::p4est::types<2>::locidx num_ett =
3077 std::accumulate(edge_touch_count.begin(), edge_touch_count.end(), 0u);
3080 const bool set_vertex_info
3089 (set_vertex_info ==
true ? this->
n_vertices() : 0),
3096 set_vertex_and_cell_info(*
this,
3099 coarse_cell_to_p4est_tree_permutation,
3128 const unsigned int deal_to_p4est_line_index[12] = {
3129 4, 5, 0, 1, 6, 7, 2, 3, 8, 9, 10, 11};
3133 cell != this->
end();
3136 const unsigned int index =
3137 coarse_cell_to_p4est_tree_permutation[cell->index()];
3138 for (
unsigned int e = 0; e < GeometryInfo<3>::lines_per_cell; ++e)
3140 deal_to_p4est_line_index[e]] =
3141 cell->line(e)->index();
3146 connectivity->ett_offset[0] = 0;
3147 std::partial_sum(edge_touch_count.begin(),
3148 edge_touch_count.end(),
3149 &connectivity->ett_offset[1]);
3151 Assert(connectivity->ett_offset[this->n_active_lines()] == num_ett,
3156 Assert(edge_to_cell[v].size() == edge_touch_count[v],
3160 std::pair<Triangulation<dim, spacedim>::active_cell_iterator,
3161 unsigned int>>::const_iterator p =
3162 edge_to_cell[v].begin();
3163 for (
unsigned int c = 0; c < edge_touch_count[v]; ++c, ++p)
3165 connectivity->edge_to_tree[connectivity->ett_offset[v] + c] =
3166 coarse_cell_to_p4est_tree_permutation[p->first->index()];
3167 connectivity->edge_to_edge[connectivity->ett_offset[v] + c] =
3168 deal_to_p4est_line_index[p->second];
3172 Assert(p8est_connectivity_is_valid(connectivity) == 1,
3193 template <
int dim,
int spacedim>
3195 enforce_mesh_balance_over_periodic_boundaries(
3201 std::vector<bool> flags_before[2];
3205 std::vector<unsigned int> topological_vertex_numbering(
3207 for (
unsigned int i = 0; i < topological_vertex_numbering.size(); ++i)
3208 topological_vertex_numbering[i] = i;
3226 typename std::map<std::pair<cell_iterator, unsigned int>,
3227 std::pair<std::pair<cell_iterator, unsigned int>,
3228 std::bitset<3>>>::const_iterator it;
3234 const unsigned int face_no_1 = it->first.second;
3236 const unsigned int face_no_2 = it->second.first.second;
3237 const std::bitset<3> face_orientation = it->second.second;
3239 if (cell_1->level() == cell_2->level())
3241 for (
unsigned int v = 0;
3247 const unsigned int vface0 =
3250 face_orientation[0],
3251 face_orientation[1],
3252 face_orientation[2]);
3253 const unsigned int vi0 =
3254 topological_vertex_numbering[cell_1->face(face_no_1)
3255 ->vertex_index(vface0)];
3256 const unsigned int vi1 =
3257 topological_vertex_numbering[cell_2->face(face_no_2)
3259 const unsigned int min_index = std::min(vi0, vi1);
3260 topological_vertex_numbering[cell_1->face(face_no_1)
3261 ->vertex_index(vface0)] =
3262 topological_vertex_numbering[cell_2->face(face_no_2)
3263 ->vertex_index(v)] =
3270 for (
unsigned int i = 0; i < topological_vertex_numbering.size(); ++i)
3272 const unsigned int j = topological_vertex_numbering[i];
3280 bool continue_iterating =
true;
3281 std::vector<int> vertex_level(tria.
n_vertices());
3282 while (continue_iterating)
3286 std::fill(vertex_level.begin(), vertex_level.end(), 0);
3290 for (; cell != endc; ++cell)
3292 if (cell->refine_flag_set())
3293 for (
unsigned int vertex = 0;
3294 vertex < GeometryInfo<dim>::vertices_per_cell;
3296 vertex_level[topological_vertex_numbering
3297 [cell->vertex_index(vertex)]] =
3298 std::max(vertex_level[topological_vertex_numbering
3299 [cell->vertex_index(vertex)]],
3301 else if (!cell->coarsen_flag_set())
3302 for (
unsigned int vertex = 0;
3303 vertex < GeometryInfo<dim>::vertices_per_cell;
3305 vertex_level[topological_vertex_numbering
3306 [cell->vertex_index(vertex)]] =
3307 std::max(vertex_level[topological_vertex_numbering
3308 [cell->vertex_index(vertex)]],
3319 for (
unsigned int vertex = 0;
3320 vertex < GeometryInfo<dim>::vertices_per_cell;
3322 vertex_level[topological_vertex_numbering
3323 [cell->vertex_index(vertex)]] =
3324 std::max(vertex_level[topological_vertex_numbering
3325 [cell->vertex_index(vertex)]],
3330 continue_iterating =
false;
3341 for (cell = tria.
last_active(); cell != endc; --cell)
3342 if (cell->refine_flag_set() ==
false)
3344 for (
unsigned int vertex = 0;
3345 vertex < GeometryInfo<dim>::vertices_per_cell;
3347 if (vertex_level[topological_vertex_numbering
3348 [cell->vertex_index(vertex)]] >=
3352 cell->clear_coarsen_flag();
3357 if (vertex_level[topological_vertex_numbering
3358 [cell->vertex_index(vertex)]] >
3361 cell->set_refine_flag();
3362 continue_iterating =
true;
3364 for (
unsigned int v = 0;
3365 v < GeometryInfo<dim>::vertices_per_cell;
3367 vertex_level[topological_vertex_numbering
3368 [cell->vertex_index(v)]] =
3370 vertex_level[topological_vertex_numbering
3371 [cell->vertex_index(v)]],
3391 const unsigned int n_children = cell->n_children();
3392 unsigned int flagged_children = 0;
3393 for (
unsigned int child = 0; child < n_children; ++child)
3394 if (cell->child(child)->active() &&
3395 cell->child(child)->coarsen_flag_set())
3400 if (flagged_children < n_children)
3401 for (
unsigned int child = 0; child < n_children; ++child)
3402 if (cell->child(child)->active())
3403 cell->child(child)->clear_coarsen_flag();
3406 std::vector<bool> flags_after[2];
3409 return ((flags_before[0] != flags_after[0]) ||
3410 (flags_before[1] != flags_after[1]));
3416 template <
int dim,
int spacedim>
3420 std::vector<bool> flags_before[2];
3424 bool mesh_changed =
false;
3433 mesh_changed = enforce_mesh_balance_over_periodic_boundaries(*
this);
3435 while (mesh_changed);
3439 std::vector<bool> flags_after[2];
3442 return ((flags_before[0] != flags_after[0]) ||
3443 (flags_before[1] != flags_after[1]));
3448 template <
int dim,
int spacedim>
3476 bool mesh_changed =
false;
3489 cell != this->
end();
3492 cell->set_coarsen_flag();
3520 (dim == 2 ? typename ::internal::p4est::types<dim>::balance_type(
3521 P4EST_CONNECT_CORNER) :
3522 typename ::internal::p4est::types<dim>::balance_type(
3523 P8EST_CONNECT_CORNER)));
3532 cell != this->
end(0);
3540 cell != this->
end(0);
3546 if (tree_exists_locally<dim, spacedim>(
3548 coarse_cell_to_p4est_tree_permutation[cell->index()]) ==
3551 delete_all_children<dim, spacedim>(cell);
3552 if (!cell->has_children())
3561 typename ::internal::p4est::types<dim>::quadrant
3563 typename ::internal::p4est::types<dim>::tree *tree =
3566 ::internal::p4est::init_coarse_quadrant<dim>(
3569 match_tree_recursively<dim, spacedim>(*tree,
3580 typename ::internal::p4est::types<dim>::quadrant *quadr;
3582 typename ::internal::p4est::types<dim>::topidx ghost_tree = 0;
3584 for (
unsigned int g_idx = 0;
3596 quadr =
static_cast< 3597 typename ::internal::p4est::types<dim>::quadrant *
>(
3600 unsigned int coarse_cell_index =
3601 p4est_tree_to_coarse_cell_permutation[ghost_tree];
3603 match_quadrant<dim, spacedim>(
this,
3613 mesh_changed =
false;
3616 cell != this->
end();
3618 if (cell->refine_flag_set() || cell->coarsen_flag_set())
3620 mesh_changed =
true;
3639 while (mesh_changed);
3643 unsigned int num_ghosts = 0;
3647 cell != this->
end();
3650 if (cell->subdomain_id() != this->my_subdomain &&
3665 if (
settings & construct_multigrid_hierarchy)
3671 for (
unsigned int lvl = this->
n_levels(); lvl > 0;)
3675 endc = this->
end(lvl);
3676 for (cell = this->
begin(lvl); cell != endc; ++cell)
3678 if ((!cell->has_children() &&
3679 cell->subdomain_id() ==
3681 (cell->has_children() &&
3682 cell->child(0)->level_subdomain_id() ==
3684 cell->set_level_subdomain_id(
3689 cell->set_level_subdomain_id(
3697 std::vector<std::vector<bool>> marked_vertices(this->
n_levels());
3698 for (
unsigned int lvl = 0; lvl < this->
n_levels(); ++lvl)
3703 cell != this->
end(0);
3706 typename ::internal::p4est::types<dim>::quadrant
3708 const unsigned int tree_index =
3709 coarse_cell_to_p4est_tree_permutation[cell->index()];
3710 typename ::internal::p4est::types<dim>::tree *tree =
3713 ::internal::p4est::init_coarse_quadrant<dim>(
3716 determine_level_subdomain_id_recursively<dim, spacedim>(
3727 for (
unsigned int lvl = this->
n_levels(); lvl > 0;)
3731 endc = this->
end(lvl);
3732 for (cell = this->
begin(lvl); cell != endc; ++cell)
3734 if (cell->has_children())
3735 for (
unsigned int c = 0;
3736 c < GeometryInfo<dim>::max_children_per_cell;
3739 if (cell->child(c)->level_subdomain_id() ==
3745 cell->child(0)->level_subdomain_id();
3749 cell->set_level_subdomain_id(mark);
3766 (void)total_local_cells;
3770 Assert(static_cast<unsigned int>(
3771 parallel_forest->local_num_quadrants) == total_local_cells,
3776 Assert(static_cast<unsigned int>(
3777 parallel_forest->local_num_quadrants) <= total_local_cells,
3782 unsigned int n_owned = 0;
3785 cell != this->
end();
3792 Assert(static_cast<unsigned int>(
3793 parallel_forest->local_num_quadrants) == n_owned,
3808 template <
int dim,
int spacedim>
3816 cell != this->
end();
3818 if (cell->is_locally_owned() && cell->refine_flag_set())
3819 Assert(cell->refine_flag_set() ==
3822 "This class does not support anisotropic refinement"));
3839 !(cell->refine_flag_set()),
3841 "Fatal Error: maximum refinement level of p4est reached."));
3855 cell != this->
end();
3857 if (cell->is_ghost() || cell->is_artificial())
3859 cell->clear_refine_flag();
3860 cell->clear_coarsen_flag();
3866 RefineAndCoarsenList<dim, spacedim> refine_and_coarsen_list(
3867 *
this, p4est_tree_to_coarse_cell_permutation, this->my_subdomain);
3874 parallel_forest->user_pointer = &refine_and_coarsen_list;
3885 &RefineAndCoarsenList<dim, spacedim>::refine_callback,
3890 &RefineAndCoarsenList<dim, spacedim>::coarsen_callback,
3897 parallel_forest->user_pointer =
this;
3903 (dim == 2 ? typename ::internal::p4est::types<dim>::balance_type(
3904 P4EST_CONNECT_FULL) :
3905 typename ::internal::p4est::types<dim>::balance_type(
3906 P8EST_CONNECT_FULL)),
3916 std::vector<typename ::internal::p4est::types<dim>::gloidx>
3917 previous_global_first_quadrant;
3920 if (cell_attached_data.n_attached_data_sets > 0)
3923 cell_attached_data.pack_callbacks_fixed,
3924 cell_attached_data.pack_callbacks_variable);
3928 previous_global_first_quadrant.resize(parallel_forest->mpisize + 1);
3929 std::memcpy(previous_global_first_quadrant.data(),
3930 parallel_forest->global_first_quadrant,
3932 typename ::internal::p4est::types<dim>::gloidx) *
3933 (parallel_forest->mpisize + 1));
3950 PartitionWeights<dim, spacedim> partition_weights(cell_weights);
3955 parallel_forest->user_pointer = &partition_weights;
3961 &PartitionWeights<dim, spacedim>::cell_weight);
3965 parallel_forest, 0,
nullptr,
nullptr);
3967 parallel_forest->user_pointer =
this;
3976 cell != this->
end();
3979 cell->clear_refine_flag();
3980 cell->clear_coarsen_flag();
3996 if (cell_attached_data.n_attached_data_sets > 0)
3999 data_transfer.execute_transfer(parallel_forest,
4000 previous_global_first_quadrant.data());
4026 std::vector<bool> active_verts =
4029 const unsigned int maybe_coarser_lvl =
4030 (lvl > 0) ? (lvl - 1) : lvl;
4032 cell = this->
begin(maybe_coarser_lvl),
4033 endc = this->
end(lvl);
4034 for (; cell != endc; ++cell)
4035 if (cell->level() ==
static_cast<int>(lvl) || cell->active())
4037 const bool is_level_artificial =
4038 (cell->level_subdomain_id() ==
4040 bool need_to_know =
false;
4041 for (
unsigned int vertex = 0;
4042 vertex < GeometryInfo<dim>::vertices_per_cell;
4044 if (active_verts[cell->vertex_index(vertex)])
4046 need_to_know =
true;
4051 !need_to_know || !is_level_artificial,
4053 "Internal error: the owner of cell" +
4054 cell->id().to_string() +
4055 " is unknown even though it is needed for geometric multigrid."));
4073 template <
int dim,
int spacedim>
4080 cell != this->
end();
4082 if (cell->is_locally_owned())
4084 !cell->refine_flag_set() && !cell->coarsen_flag_set(),
4086 "Error: There shouldn't be any cells flagged for coarsening/refinement when calling repartition()."));
4091 std::vector<typename ::internal::p4est::types<dim>::gloidx>
4092 previous_global_first_quadrant;
4095 if (cell_attached_data.n_attached_data_sets > 0)
4098 cell_attached_data.pack_callbacks_fixed,
4099 cell_attached_data.pack_callbacks_variable);
4103 previous_global_first_quadrant.resize(parallel_forest->mpisize + 1);
4104 std::memcpy(previous_global_first_quadrant.data(),
4105 parallel_forest->global_first_quadrant,
4107 typename ::internal::p4est::types<dim>::gloidx) *
4108 (parallel_forest->mpisize + 1));
4125 PartitionWeights<dim, spacedim> partition_weights(cell_weights);
4130 parallel_forest->user_pointer = &partition_weights;
4136 &PartitionWeights<dim, spacedim>::cell_weight);
4139 parallel_forest->user_pointer =
this;
4155 if (cell_attached_data.n_attached_data_sets > 0)
4158 data_transfer.execute_transfer(parallel_forest,
4159 previous_global_first_quadrant.data());
4169 template <
int dim,
int spacedim>
4172 const std::vector<bool> &vertex_locally_moved)
4179 const std::vector<bool> locally_owned_vertices =
4180 ::GridTools::get_locally_owned_vertices(*
this);
4181 for (
unsigned int i = 0; i < locally_owned_vertices.size(); ++i)
4182 Assert((vertex_locally_moved[i] ==
false) ||
4183 (locally_owned_vertices[i] ==
true),
4184 ExcMessage(
"The vertex_locally_moved argument must not " 4185 "contain vertices that are not locally owned"));
4195 const std::map<unsigned int, std::set<::types::subdomain_id>>
4202 CommunicateLocallyMovedVertices::CellInfo<dim, spacedim>>;
4203 cellmap_t needs_to_get_cells;
4207 cell != this->
end(0);
4210 typename ::internal::p4est::types<dim>::quadrant
4212 ::internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
4214 CommunicateLocallyMovedVertices::fill_vertices_recursively<dim,
4220 vertices_with_ghost_neighbors,
4221 vertex_locally_moved,
4222 needs_to_get_cells);
4226 std::vector<std::vector<char>> sendbuffers(needs_to_get_cells.size());
4227 std::vector<std::vector<char>>::iterator buffer = sendbuffers.begin();
4228 std::vector<MPI_Request> requests(needs_to_get_cells.size());
4229 std::vector<unsigned int> destinations;
4231 unsigned int idx = 0;
4233 for (
typename cellmap_t::iterator it = needs_to_get_cells.begin();
4234 it != needs_to_get_cells.end();
4235 ++it, ++buffer, ++idx)
4237 const unsigned int num_cells = it->second.tree_index.size();
4239 destinations.push_back(it->first);
4251 it->second.pack_data(*buffer);
4252 const int ierr = MPI_Isend(&(*buffer)[0],
4262 Assert(destinations.size() == needs_to_get_cells.size(),
4267 const std::vector<unsigned int> senders =
4272 std::vector<char> receive;
4273 CommunicateLocallyMovedVertices::CellInfo<dim, spacedim> cellinfo;
4274 for (
unsigned int i = 0; i < senders.size(); ++i)
4281 ierr = MPI_Get_count(&status, MPI_BYTE, &len);
4283 receive.resize(len);
4285 char *ptr = receive.data();
4286 ierr = MPI_Recv(ptr,
4291 this->get_communicator(),
4295 cellinfo.unpack_data(receive);
4296 const unsigned int cells = cellinfo.tree_index.size();
4297 for (
unsigned int c = 0; c < cells; ++c)
4299 typename ::parallel::distributed::
4300 Triangulation<dim, spacedim>::cell_iterator cell(
4304 [cellinfo.tree_index[c]]);
4306 typename ::internal::p4est::types<dim>::quadrant
4308 ::internal::p4est::init_coarse_quadrant<dim>(
4311 CommunicateLocallyMovedVertices::set_vertices_recursively<
4316 cellinfo.quadrants[c],
4317 cellinfo.first_vertices[c],
4318 cellinfo.first_vertex_indices[c]);
4324 if (requests.size() > 0)
4327 MPI_Waitall(requests.size(), requests.data(), MPI_STATUSES_IGNORE);
4340 template <
int dim,
int spacedim>
4343 const std::function<std::vector<char>(
const cell_iterator &,
4345 const bool returns_variable_size_data)
4351 if (returns_variable_size_data)
4353 handle = 2 * cell_attached_data.pack_callbacks_variable.size();
4354 cell_attached_data.pack_callbacks_variable.push_back(pack_callback);
4358 handle = 2 * cell_attached_data.pack_callbacks_fixed.size() + 1;
4359 cell_attached_data.pack_callbacks_fixed.push_back(pack_callback);
4363 ++cell_attached_data.n_attached_data_sets;
4370 template <
int dim,
int spacedim>
4373 const unsigned int handle,
4374 const std::function<
4377 const boost::iterator_range<std::vector<char>::const_iterator> &)>
4380 Assert(cell_attached_data.n_attached_data_sets > 0,
4381 ExcMessage(
"The notify_ready_to_unpack() has already been called " 4382 "once for each registered callback."));
4387 static_cast<unsigned int>(parallel_forest->local_num_quadrants),
4394 const unsigned int callback_index = handle / 2;
4395 if (handle % 2 == 0)
4398 cell_attached_data.pack_callbacks_variable.size(),
4401 Assert(cell_attached_data.pack_callbacks_variable[callback_index] !=
4404 cell_attached_data.pack_callbacks_variable[callback_index] =
nullptr;
4409 cell_attached_data.pack_callbacks_fixed.size(),
4412 Assert(cell_attached_data.pack_callbacks_fixed[callback_index] !=
4415 cell_attached_data.pack_callbacks_fixed[callback_index] =
nullptr;
4425 --cell_attached_data.n_attached_data_sets;
4426 if (cell_attached_data.n_attached_deserialize > 0)
4427 --cell_attached_data.n_attached_deserialize;
4435 if (cell_attached_data.n_attached_data_sets == 0 &&
4436 cell_attached_data.n_attached_deserialize == 0)
4439 cell_attached_data.pack_callbacks_fixed.clear();
4440 cell_attached_data.pack_callbacks_variable.clear();
4441 data_transfer.clear();
4445 std::get<1>(quad_cell_rel) =
4452 template <
int dim,
int spacedim>
4453 const std::vector<types::global_dof_index> &
4457 return p4est_tree_to_coarse_cell_permutation;
4462 template <
int dim,
int spacedim>
4463 const std::vector<types::global_dof_index> &
4472 template <
int dim,
int spacedim>
4473 std::map<unsigned int, std::set<::types::subdomain_id>>
4478 return ::internal::p4est::compute_vertices_with_ghost_neighbors<
4485 template <
int dim,
int spacedim>
4488 const int level)
const 4492 std::vector<bool> marked_vertices(this->
n_vertices(),
false);
4494 for (; cell != endc; ++cell)
4496 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell;
4498 marked_vertices[cell->vertex_index(v)] =
true;
4505 typename std::map<std::pair<cell_iterator, unsigned int>,
4506 std::pair<std::pair<cell_iterator, unsigned int>,
4507 std::bitset<3>>>::const_iterator it;
4519 for (
unsigned int repetition = 0; repetition < dim; ++repetition)
4525 const unsigned int face_no_1 = it->first.second;
4527 const unsigned int face_no_2 = it->second.first.second;
4528 const std::bitset<3> &face_orientation = it->second.second;
4530 if (cell_1->level() == level && cell_2->level() == level)
4532 for (
unsigned int v = 0;
4538 const unsigned int vface0 =
4541 face_orientation[0],
4542 face_orientation[1],
4543 face_orientation[2]);
4544 if (marked_vertices[cell_1->face(face_no_1)->vertex_index(
4546 marked_vertices[cell_2->face(face_no_2)->vertex_index(
4548 marked_vertices[cell_1->face(face_no_1)->vertex_index(
4550 marked_vertices[cell_2->face(face_no_2)->vertex_index(
4556 return marked_vertices;
4561 template <
int dim,
int spacedim>
4565 &periodicity_vector)
4570 ExcMessage(
"The triangulation is refined!"));
4573 std::vector<::GridTools::PeriodicFacePair<cell_iterator>>;
4574 typename FaceVector::const_iterator it, periodic_end;
4575 it = periodicity_vector.begin();
4576 periodic_end = periodicity_vector.end();
4578 for (; it < periodic_end; ++it)
4582 const unsigned int face_left = it->face_idx[0];
4583 const unsigned int face_right = it->face_idx[1];
4586 const unsigned int tree_left =
4587 coarse_cell_to_p4est_tree_permutation[std::distance(this->
begin(),
4589 const unsigned int tree_right =
4590 coarse_cell_to_p4est_tree_permutation[std::distance(this->
begin(),
4600 unsigned int p4est_orientation = 0;
4602 p4est_orientation = it->orientation[1];
4605 const unsigned int face_idx_list[] = {face_left, face_right};
4606 const cell_iterator cell_list[] = {first_cell, second_cell};
4607 unsigned int lower_idx, higher_idx;
4608 if (face_left <= face_right)
4621 unsigned int first_p4est_idx_on_cell =
4622 p8est_face_corners[face_idx_list[lower_idx]][0];
4623 unsigned int first_dealii_idx_on_face =
4625 for (
unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_face;
4628 const unsigned int first_dealii_idx_on_cell =
4630 face_idx_list[lower_idx],
4632 cell_list[lower_idx]->face_orientation(
4633 face_idx_list[lower_idx]),
4634 cell_list[lower_idx]->face_flip(face_idx_list[lower_idx]),
4635 cell_list[lower_idx]->face_rotation(
4636 face_idx_list[lower_idx]));
4637 if (first_p4est_idx_on_cell == first_dealii_idx_on_cell)
4639 first_dealii_idx_on_face = i;
4646 const unsigned int left_to_right[8][4] = {{0, 2, 1, 3},
4654 const unsigned int right_to_left[8][4] = {{0, 2, 1, 3},
4662 const unsigned int second_dealii_idx_on_face =
4663 lower_idx == 0 ? left_to_right[it->orientation.to_ulong()]
4664 [first_dealii_idx_on_face] :
4665 right_to_left[it->orientation.to_ulong()]
4666 [first_dealii_idx_on_face];
4667 const unsigned int second_dealii_idx_on_cell =
4669 face_idx_list[higher_idx],
4670 second_dealii_idx_on_face,
4671 cell_list[higher_idx]->face_orientation(
4672 face_idx_list[higher_idx]),
4673 cell_list[higher_idx]->face_flip(face_idx_list[higher_idx]),
4674 cell_list[higher_idx]->face_rotation(
4675 face_idx_list[higher_idx]));
4677 const unsigned int second_p4est_idx_on_face =
4678 p8est_corner_face_corners[second_dealii_idx_on_cell]
4679 [face_idx_list[higher_idx]];
4680 p4est_orientation = second_p4est_idx_on_face;
4730 template <
int dim,
int spacedim>
4741 cell_attached_data.n_attached_data_sets) +
4748 coarse_cell_to_p4est_tree_permutation) +
4750 p4est_tree_to_coarse_cell_permutation) +
4758 template <
int dim,
int spacedim>
4762 return ::internal::p4est::functions<dim>::forest_memory_used(
4770 template <
int dim,
int spacedim>
4773 const ::Triangulation<dim, spacedim> &other_tria)
4781 const typename ::Triangulation<dim, spacedim>::DistortedCellList
4794 Assert(other_tria.n_levels() == 1,
4796 "Parallel distributed triangulations can only be copied, " 4797 "if they are not refined!"));
4799 if (const ::parallel::distributed::Triangulation<dim, spacedim>
4801 dynamic_cast<const ::parallel::distributed::
4802 Triangulation<dim, spacedim> *
>(&other_tria))
4804 coarse_cell_to_p4est_tree_permutation =
4805 other_tria_x->coarse_cell_to_p4est_tree_permutation;
4806 p4est_tree_to_coarse_cell_permutation =
4807 other_tria_x->p4est_tree_to_coarse_cell_permutation;
4808 cell_attached_data = other_tria_x->cell_attached_data;
4809 data_transfer = other_tria_x->data_transfer;
4837 template <
int dim,
int spacedim>
4843 parallel_forest->local_num_quadrants);
4849 cell != this->
end(0);
4853 if (tree_exists_locally<dim, spacedim>(
4855 coarse_cell_to_p4est_tree_permutation[cell->index()]) ==
false)
4859 typename ::internal::p4est::types<dim>::quadrant
4861 ::internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
4864 typename ::internal::p4est::types<dim>::tree *tree =
4867 update_quadrant_cell_relations_recursively<dim, spacedim>(
4874 template <
int dim,
int spacedim>
4875 std::vector<unsigned int>
4881 static_cast<unsigned int>(parallel_forest->local_num_quadrants),
4889 std::vector<unsigned int> weights;
4900 const auto &cell_status = std::get<1>(quad_cell_rel);
4901 const auto &cell_it = std::get<2>(quad_cell_rel);
4903 switch (cell_status)
4907 weights.push_back(1000);
4920 unsigned int parent_weight = 1000;
4927 weights.push_back(parent_weight);
4933 weights.push_back(1000);
4951 template <
int spacedim>
4954 const typename ::Triangulation<1, spacedim>::MeshSmoothing
4965 template <
int spacedim>
4973 template <
int spacedim>
4976 const std::vector<bool> & )
4983 template <
int spacedim>
4986 const std::function<std::vector<char>(
4987 const typename ::Triangulation<1, spacedim>::cell_iterator &,
4988 const typename ::Triangulation<1, spacedim>::CellStatus)>
4998 template <
int spacedim>
5001 const unsigned int ,
5002 const std::function<
5003 void(
const typename ::Triangulation<1, spacedim>::cell_iterator &,
5004 const typename ::Triangulation<1, spacedim>::CellStatus,
5005 const boost::iterator_range<std::vector<char>::const_iterator> &)>
5013 template <
int spacedim>
5014 const std::vector<types::global_dof_index> &
5018 static std::vector<types::global_dof_index> a;
5024 template <
int spacedim>
5025 std::map<unsigned int, std::set<::types::subdomain_id>>
5029 return std::map<unsigned int, std::set<::types::subdomain_id>>();
5034 template <
int spacedim>
5035 std::map<unsigned int, std::set<::types::subdomain_id>>
5037 const unsigned int )
const 5041 return std::map<unsigned int, std::set<::types::subdomain_id>>();
5046 template <
int spacedim>
5049 const unsigned int)
const 5052 return std::vector<bool>();
5057 template <
int spacedim>
5066 template <
int spacedim>
5077 #endif // DEAL_II_WITH_P4EST 5082 #include "tria.inst" 5085 DEAL_II_NAMESPACE_CLOSE
void write_mesh_vtk(const char *file_basename) const
unsigned int register_data_attach(const std::function< std::vector< char >(const cell_iterator &, const CellStatus)> &pack_callback, const bool returns_variable_size_data)
static const unsigned int invalid_unsigned_int
#define AssertNothrow(cond, exc)
const std::vector< Point< spacedim > > & get_vertices() const
types::subdomain_id locally_owned_subdomain() const override
cell_iterator end() const
types::subdomain_id my_subdomain
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)
unsigned int n_active_lines() const
static::ExceptionBase & ExcIO()
std::vector< Point< spacedim > > vertices
void update_quadrant_cell_relations()
boost::signals2::signal< void()> pre_distributed_refinement
typename::Triangulation< dim, spacedim >::active_cell_iterator active_cell_iterator
bool triangulation_has_content
void fill_level_ghost_owners()
virtual bool has_hanging_nodes() const override
void pack_data(const std::vector< quadrant_cell_relation_t > &quad_cell_relations, const std::vector< typename CellAttachedData::pack_callback_t > &pack_callbacks_fixed, const std::vector< typename CellAttachedData::pack_callback_t > &pack_callbacks_variable)
const std::vector< bool > & get_used_vertices() const
virtual std::size_t memory_consumption_p4est() const
unsigned int get_checksum() const
#define AssertThrow(cond, exc)
MPI_Comm mpi_communicator
void load(const char *filename, const bool autopartition=true)
Triangulation(MPI_Comm mpi_communicator, const typename::Triangulation< dim, spacedim >::MeshSmoothing smooth_grid=(::Triangulation< dim, spacedim >::none), const Settings settings=default_setting)
virtual std::size_t memory_consumption() const override
cell_iterator begin(const unsigned int level=0) const
unsigned int n_active_cells() const
std::vector< unsigned int > get_cell_weights() const
typename::internal::p4est::types< dim >::ghost * parallel_ghost
unsigned int n_levels() const
typename::internal::p4est::types< dim >::forest * parallel_forest
virtual void add_periodicity(const std::vector< GridTools::PeriodicFacePair< cell_iterator >> &)
virtual void execute_coarsening_and_refinement()
virtual MPI_Comm get_communicator() const
void save_coarsen_flags(std::ostream &out) const
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria) override
const std::map< std::pair< cell_iterator, unsigned int >, std::pair< std::pair< cell_iterator, unsigned int >, std::bitset< 3 > > > & get_periodic_face_map() const
virtual bool prepare_coarsening_and_refinement()
static::ExceptionBase & ExcMessage(std::string arg1)
unsigned int subdomain_id
virtual bool prepare_coarsening_and_refinement() override
Triangulation(const MeshSmoothing smooth_grid=none, const bool check_for_distorted_cells=false)
unsigned int n_cells() const
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)
std::vector< bool > mark_locally_active_vertices_on_level(const int level) const
const std::vector< types::global_dof_index > & get_p4est_tree_to_coarse_cell_permutation() const
#define Assert(cond, exc)
virtual void update_number_cache()
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void copy_new_triangulation_to_p4est(std::integral_constant< int, 2 >)
void notify_ready_to_unpack(const unsigned int handle, const std::function< void(const cell_iterator &, const CellStatus, const boost::iterator_range< std::vector< char >::const_iterator > &)> &unpack_callback)
virtual unsigned int n_global_levels() const override
boost::signals2::signal< void()> pre_distributed_save
void save_refine_flags(std::ostream &out) const
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)
std::vector< unsigned int > invert_permutation(const std::vector< unsigned int > &permutation)
size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
active_cell_iterator last_active() const
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
virtual void update_number_cache() override
std::vector< quadrant_cell_relation_t > local_quadrant_cell_relations
const types::subdomain_id artificial_subdomain_id
void communicate_locally_moved_vertices(const std::vector< bool > &vertex_locally_moved)
#define AssertThrowMPI(error_code)
void update_periodic_face_map()
virtual ~Triangulation() override
MeshSmoothing smooth_grid
boost::signals2::signal< unsigned int(const cell_iterator &, const CellStatus), CellWeightSum< unsigned int > > cell_weight
void setup_coarse_cell_to_p4est_tree_permutation()
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &other_tria) override
T unpack(const std::vector< char > &buffer, const bool allow_compression=true)
unsigned int this_mpi_process(const MPI_Comm &mpi_communicator)
static::ExceptionBase & ExcNotImplemented()
void save(const char *filename) const
active_cell_iterator begin_active(const unsigned int level=0) const
virtual void execute_coarsening_and_refinement() override
std::vector< unsigned int > compute_point_to_point_communication_pattern(const MPI_Comm &mpi_comm, const std::vector< unsigned int > &destinations)
boost::signals2::signal< void()> post_distributed_load
typename::Triangulation< dim, spacedim >::cell_iterator cell_iterator
void copy_local_forest_to_triangulation()
virtual void create_triangulation(const std::vector< Point< spacedim >> &vertices, const std::vector< CellData< dim >> &cells, const SubCellData &subcelldata) override
unsigned int n_vertices() const
typename::internal::p4est::types< dim >::tree * init_tree(const int dealii_coarse_cell_index) const
const std::vector< types::global_dof_index > & get_coarse_cell_to_p4est_tree_permutation() const
T max(const T &t, const MPI_Comm &mpi_communicator)
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
virtual void clear() override
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
static::ExceptionBase & ExcInternalError()
virtual std::map< unsigned int, std::set<::types::subdomain_id > > compute_vertices_with_ghost_neighbors() const override
boost::signals2::signal< void()> post_distributed_refinement
virtual void add_periodicity(const std::vector<::GridTools::PeriodicFacePair< cell_iterator >> &) override