17 #include <deal.II/base/utilities.h> 18 #include <deal.II/base/memory_consumption.h> 19 #include <deal.II/base/logstream.h> 20 #include <deal.II/lac/sparsity_tools.h> 21 #include <deal.II/lac/dynamic_sparsity_pattern.h> 22 #include <deal.II/grid/tria.h> 23 #include <deal.II/grid/tria_accessor.h> 24 #include <deal.II/grid/tria_iterator.h> 25 #include <deal.II/grid/grid_tools.h> 26 #include <deal.II/distributed/tria.h> 28 #ifdef DEAL_II_WITH_P4EST 29 # include <p4est_bits.h> 30 # include <p4est_extended.h> 31 # include <p4est_vtk.h> 32 # include <p4est_ghost.h> 33 # include <p4est_communication.h> 34 # include <p4est_iterate.h> 36 # include <p8est_bits.h> 37 # include <p8est_extended.h> 38 # include <p8est_vtk.h> 39 # include <p8est_ghost.h> 40 # include <p8est_communication.h> 41 # include <p8est_iterate.h> 50 DEAL_II_NAMESPACE_OPEN
53 #ifdef DEAL_II_WITH_P4EST 71 int (&quadrant_compare) (
const void *v1,
const void *v2);
125 void (&connectivity_destroy) (p4est_connectivity_t *connectivity);
134 p4est_init_t init_fn,
142 int refine_recursive,
143 p4est_refine_t refine_fn,
144 p4est_init_t init_fn);
148 int coarsen_recursive,
149 p4est_coarsen_t coarsen_fn,
150 p4est_init_t init_fn);
155 p4est_init_t init_fn);
157 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 160 int partition_for_coarsening,
161 p4est_weight_t weight_fn);
165 int partition_for_coarsening,
166 p4est_weight_t weight_fn);
170 void (&save) (
const char *filename,
174 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 194 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 196 int (&connectivity_save) (
const char *filename,
200 void (&connectivity_save) (
const char *filename,
207 #if DEAL_II_P4EST_VERSION_GTE(1,0,0,0) 211 #elif DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 214 long unsigned *length);
227 const char *baseName);
239 p4est_init_t init_fn,
248 static const unsigned max_level;
252 = p4est_quadrant_compare;
256 = p4est_quadrant_childrenv;
260 = p4est_quadrant_overlaps_tree;
265 = p4est_quadrant_set_morton;
269 = p4est_quadrant_is_equal;
273 = p4est_quadrant_is_sibling;
277 = p4est_quadrant_is_ancestor;
281 = p4est_quadrant_ancestor_id;
287 = p4est_comm_find_owner;
293 = p4est_connectivity_new;
295 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,1) 302 = p4est_connectivity_join_faces;
306 = p4est_connectivity_destroy;
314 p4est_init_t init_fn,
322 int refine_recursive,
323 p4est_refine_t refine_fn,
324 p4est_init_t init_fn)
328 int coarsen_recursive,
329 p4est_coarsen_t coarsen_fn,
330 p4est_init_t init_fn)
335 p4est_init_t init_fn)
338 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 340 int partition_for_coarsening,
341 p4est_weight_t weight_fn)
342 = p4est_partition_ext;
345 int partition_for_coarsening,
346 p4est_weight_t weight_fn)
347 = p4est_partition_ext;
355 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 359 std::size_t data_size,
370 std::size_t data_size,
377 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 380 = p4est_connectivity_save;
384 = p4est_connectivity_save;
389 = p4est_connectivity_is_valid;
391 #if DEAL_II_P4EST_VERSION_GTE(1,0,0,0) 395 = p4est_connectivity_load;
396 #elif DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 399 long unsigned *length)
400 = p4est_connectivity_load;
405 = p4est_connectivity_load;
413 const char *baseName)
414 = p4est_vtk_write_file;
421 = p4est_ghost_destroy;
425 p4est_init_t init_fn,
433 = p4est_connectivity_memory_used;
440 int (&quadrant_compare) (
const void *v1,
const void *v2);
494 void (&connectivity_destroy) (p8est_connectivity_t *connectivity);
503 p8est_init_t init_fn,
511 int refine_recursive,
512 p8est_refine_t refine_fn,
513 p8est_init_t init_fn);
517 int coarsen_recursive,
518 p8est_coarsen_t coarsen_fn,
519 p8est_init_t init_fn);
524 p8est_init_t init_fn);
526 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 529 int partition_for_coarsening,
530 p8est_weight_t weight_fn);
534 int partition_for_coarsening,
535 p8est_weight_t weight_fn);
539 void (&save) (
const char *filename,
543 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 547 std::size_t data_size,
557 std::size_t data_size,
563 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 565 int (&connectivity_save) (
const char *filename,
569 void (&connectivity_save) (
const char *filename,
576 #if DEAL_II_P4EST_VERSION_GTE(1,0,0,0) 580 #elif DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 583 long unsigned *length);
596 const char *baseName);
608 p8est_init_t init_fn,
617 static const unsigned max_level;
622 = p8est_quadrant_compare;
626 = p8est_quadrant_childrenv;
630 = p8est_quadrant_overlaps_tree;
635 = p8est_quadrant_set_morton;
639 = p8est_quadrant_is_equal;
643 = p8est_quadrant_is_sibling;
647 = p8est_quadrant_is_ancestor;
651 = p8est_quadrant_ancestor_id;
657 = p8est_comm_find_owner;
665 = p8est_connectivity_new;
668 = p8est_connectivity_destroy;
670 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,1) 677 = p8est_connectivity_join_faces;
686 p8est_init_t init_fn,
694 int refine_recursive,
695 p8est_refine_t refine_fn,
696 p8est_init_t init_fn)
700 int coarsen_recursive,
701 p8est_coarsen_t coarsen_fn,
702 p8est_init_t init_fn)
707 p8est_init_t init_fn)
710 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 712 int partition_for_coarsening,
713 p8est_weight_t weight_fn)
714 = p8est_partition_ext;
717 int partition_for_coarsening,
718 p8est_weight_t weight_fn)
719 = p8est_partition_ext;
727 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 731 std::size_t data_size,
742 std::size_t data_size,
749 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 752 = p8est_connectivity_save;
756 = p8est_connectivity_save;
761 = p8est_connectivity_is_valid;
763 #if DEAL_II_P4EST_VERSION_GTE(1,0,0,0) 767 = p8est_connectivity_load;
768 #elif DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 771 long unsigned *length)
772 = p8est_connectivity_load;
777 = p8est_connectivity_load;
785 const char *baseName)
786 = p8est_vtk_write_file;
793 = p8est_ghost_destroy;
797 p8est_init_t init_fn,
805 = p8est_connectivity_memory_used;
812 init_quadrant_children
817 for (
unsigned int c=0;
818 c<GeometryInfo<dim>::max_children_per_cell; ++c)
822 P4EST_QUADRANT_INIT(&p4est_children[c]);
825 P8EST_QUADRANT_INIT(&p4est_children[c]);
828 Assert (
false, ExcNotImplemented());
845 P4EST_QUADRANT_INIT(&quad);
848 P8EST_QUADRANT_INIT(&quad);
851 Assert (
false, ExcNotImplemented());
882 template <
int dim>
struct iter;
884 template <>
struct iter<2>
886 typedef p4est_iter_corner_info_t corner_info;
887 typedef p4est_iter_corner_side_t corner_side;
888 typedef p4est_iter_corner_t corner_iter;
889 typedef p4est_iter_face_info_t face_info;
890 typedef p4est_iter_face_side_t face_side;
891 typedef p4est_iter_face_t face_iter;
894 template <>
struct iter<3>
896 typedef p8est_iter_corner_info_t corner_info;
897 typedef p8est_iter_corner_side_t corner_side;
898 typedef p8est_iter_corner_t corner_iter;
899 typedef p8est_iter_edge_info_t edge_info;
900 typedef p8est_iter_edge_side_t edge_side;
901 typedef p8est_iter_edge_t edge_iter;
902 typedef p8est_iter_face_info_t face_info;
903 typedef p8est_iter_face_side_t face_side;
904 typedef p8est_iter_face_t face_iter;
913 template <
int dim,
int spacedim>
916 std::vector<unsigned int> &vertex_touch_count,
917 std::vector<std::list<
921 vertex_touch_count.resize (triangulation.
n_vertices());
922 vertex_to_cell.resize (triangulation.
n_vertices());
926 cell != triangulation.
end(); ++cell)
927 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
929 ++vertex_touch_count[cell->vertex_index(v)];
930 vertex_to_cell[cell->vertex_index(v)]
931 .push_back (std::make_pair (cell, v));
937 template <
int dim,
int spacedim>
940 std::vector<unsigned int> &edge_touch_count,
941 std::vector<std::list<
952 cell != triangulation.
end(); ++cell)
953 for (
unsigned int l=0; l<GeometryInfo<dim>::lines_per_cell; ++l)
955 ++edge_touch_count[cell->line(l)->index()];
956 edge_to_cell[cell->line(l)->index()]
957 .push_back (std::make_pair (cell, l));
967 template <
int dim,
int spacedim>
970 const std::vector<unsigned int> &vertex_touch_count,
971 const std::vector<std::list<
974 const std::vector<types::global_dof_index> &coarse_cell_to_p4est_tree_permutation,
975 const bool set_vertex_info,
992 if (set_vertex_info ==
true)
993 for (
unsigned int v=0; v<triangulation.
n_vertices(); ++v)
995 connectivity->vertices[3*v ] = triangulation.
get_vertices()[v][0];
996 connectivity->vertices[3*v+1] = triangulation.
get_vertices()[v][1];
997 connectivity->vertices[3*v+2] = (spacedim == 2 ?
1010 endc = triangulation.
end();
1011 for (; cell != endc; ++cell)
1014 index = coarse_cell_to_p4est_tree_permutation[cell->index()];
1016 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
1018 if (set_vertex_info ==
true)
1025 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
1026 if (cell->face(f)->at_boundary() ==
false)
1028 = coarse_cell_to_p4est_tree_permutation[cell->neighbor(f)->index()];
1031 = coarse_cell_to_p4est_tree_permutation[cell->index()];
1035 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
1036 if (cell->face(f)->at_boundary() ==
false)
1043 = cell->neighbor_of_neighbor (f);
1062 connectivity->tree_to_face[index*6 + f]
1063 = cell->neighbor_of_neighbor (f);
1065 unsigned int face_idx_list[2] =
1066 {f, cell->neighbor_of_neighbor (f)};
1068 cell_list[2] = {cell, cell->neighbor(f)};
1069 unsigned int smaller_idx = 0;
1071 if (f>cell->neighbor_of_neighbor (f))
1074 unsigned int larger_idx = (smaller_idx+1) % 2;
1082 unsigned int g_idx =
1083 cell_list[smaller_idx]->vertex_index(
1085 face_idx_list[smaller_idx],
1087 cell_list[smaller_idx]->face_orientation(face_idx_list[smaller_idx]),
1088 cell_list[smaller_idx]->face_flip(face_idx_list[smaller_idx]),
1089 cell_list[smaller_idx]->face_rotation(face_idx_list[smaller_idx]))
1094 for (
unsigned int i=0; i<GeometryInfo<dim>::vertices_per_face; ++i)
1098 cell_list[larger_idx]->vertex_index(
1100 face_idx_list[larger_idx],
1111 connectivity->tree_to_face[index*6 + f] += 6*v;
1116 Assert (
false, ExcNotImplemented());
1124 connectivity->ctt_offset[0] = 0;
1125 std::partial_sum (vertex_touch_count.begin(),
1126 vertex_touch_count.end(),
1127 &connectivity->ctt_offset[1]);
1130 num_vtt = std::accumulate (vertex_touch_count.begin(),
1131 vertex_touch_count.end(),
1136 ExcInternalError());
1138 for (
unsigned int v=0; v<triangulation.
n_vertices(); ++v)
1140 Assert (vertex_to_cell[v].size() == vertex_touch_count[v],
1141 ExcInternalError());
1143 typename std::list<std::pair
1145 unsigned int> >::const_iterator
1146 p = vertex_to_cell[v].begin();
1147 for (
unsigned int c=0; c<vertex_touch_count[v]; ++c, ++p)
1149 connectivity->corner_to_tree[connectivity->ctt_offset[v]+c]
1150 = coarse_cell_to_p4est_tree_permutation[p->first->index()];
1151 connectivity->corner_to_corner[connectivity->ctt_offset[v]+c]
1159 template <
int dim,
int spacedim>
1164 Assert (coarse_grid_cell < parallel_forest->connectivity->num_trees,
1165 ExcInternalError());
1166 return ((coarse_grid_cell >= parallel_forest->first_local_tree)
1168 (coarse_grid_cell <= parallel_forest->last_local_tree));
1172 template <
int dim,
int spacedim>
1176 if (cell->has_children())
1177 for (
unsigned int c=0; c<cell->n_children(); ++c)
1178 delete_all_children_and_self<dim,spacedim> (cell->child(c));
1180 cell->set_coarsen_flag ();
1185 template <
int dim,
int spacedim>
1189 if (cell->has_children())
1190 for (
unsigned int c=0; c<cell->n_children(); ++c)
1191 delete_all_children_and_self<dim,spacedim> (cell->child(c));
1195 template <
int dim,
int spacedim>
1203 const std::vector<std::vector<bool> > &marked_vertices)
1210 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
1212 if (marked_vertices[dealii_cell->level()][dealii_cell->vertex_index(v)])
1225 Assert((owner!=-2) && (owner!=-1),
ExcMessage(
"p4est should know the owner."));
1226 dealii_cell->set_level_subdomain_id(owner);
1231 if (dealii_cell->has_children ())
1234 p4est_child[GeometryInfo<dim>::max_children_per_cell];
1235 for (
unsigned int c=0;
1236 c<GeometryInfo<dim>::max_children_per_cell; ++c)
1240 P4EST_QUADRANT_INIT(&p4est_child[c]);
1243 P8EST_QUADRANT_INIT(&p4est_child[c]);
1246 Assert (
false, ExcNotImplemented());
1254 for (
unsigned int c=0;
1255 c<GeometryInfo<dim>::max_children_per_cell; ++c)
1257 determine_level_subdomain_id_recursively <dim,spacedim> (tree,tree_index,
1258 dealii_cell->child(c),
1268 template <
int dim,
int spacedim>
1277 if (sc_array_bsearch(const_cast<sc_array_t *>(&tree.quadrants),
1283 delete_all_children<dim,spacedim> (dealii_cell);
1284 if (!dealii_cell->has_children())
1285 dealii_cell->set_subdomain_id(my_subdomain);
1294 if (dealii_cell->has_children () ==
false)
1295 dealii_cell->set_refine_flag ();
1299 p4est_child[GeometryInfo<dim>::max_children_per_cell];
1300 for (
unsigned int c=0;
1301 c<GeometryInfo<dim>::max_children_per_cell; ++c)
1305 P4EST_QUADRANT_INIT(&p4est_child[c]);
1308 P8EST_QUADRANT_INIT(&p4est_child[c]);
1311 Assert (
false, ExcNotImplemented());
1319 for (
unsigned int c=0;
1320 c<GeometryInfo<dim>::max_children_per_cell; ++c)
1330 delete_all_children<dim,spacedim> (dealii_cell->child(c));
1331 dealii_cell->child(c)
1338 match_tree_recursively<dim,spacedim> (tree,
1339 dealii_cell->child(c),
1349 template <
int dim,
int spacedim>
1351 match_quadrant (const ::Triangulation<dim,spacedim> *tria,
1352 unsigned int dealii_index,
1354 unsigned int ghost_owner)
1357 int l = ghost_quadrant.level;
1359 for (i = 0; i < l; i++)
1362 if (cell->has_children () ==
false)
1364 cell->clear_coarsen_flag();
1365 cell->set_refine_flag ();
1370 dealii_index = cell->child_index(child_id);
1374 if (cell->has_children())
1375 delete_all_children<dim,spacedim> (cell);
1378 cell->clear_coarsen_flag();
1379 cell->set_subdomain_id(ghost_owner);
1385 template <
int dim,
int spacedim>
1390 const typename std::list<std::pair<
unsigned int,
typename std_cxx11::function<
1392 typename parallel::distributed::Triangulation<dim,spacedim>::CellStatus,
1394 > > > &attached_data_pack_callbacks)
1396 typedef std::list<std::pair<
unsigned int,
typename std_cxx11::function<
1398 typename parallel::distributed::Triangulation<dim,spacedim>::CellStatus,
1400 > > > callback_list_t;
1402 int idx = sc_array_bsearch(const_cast<sc_array_t *>(&tree.quadrants),
1412 bool p4est_has_children = (idx == -1);
1414 if (p4est_has_children && dealii_cell->has_children())
1418 p4est_child[GeometryInfo<dim>::max_children_per_cell];
1419 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1423 P4EST_QUADRANT_INIT(&p4est_child[c]);
1426 P8EST_QUADRANT_INIT(&p4est_child[c]);
1429 Assert (
false, ExcNotImplemented());
1435 for (
unsigned int c=0;
1436 c<GeometryInfo<dim>::max_children_per_cell; ++c)
1438 attach_mesh_data_recursively<dim,spacedim> (tree,
1439 dealii_cell->child(c),
1441 attached_data_pack_callbacks);
1444 else if (!p4est_has_children && !dealii_cell->has_children())
1449 sc_array_index (const_cast<sc_array_t *>(&tree.quadrants), idx)
1453 for (
typename callback_list_t::const_iterator it = attached_data_pack_callbacks.begin();
1454 it != attached_data_pack_callbacks.end();
1457 void *ptr =
static_cast<char *
>(q->p.user_data) + (*it).first;
1458 ((*it).second)(dealii_cell,
1463 else if (p4est_has_children)
1470 p4est_child[GeometryInfo<dim>::max_children_per_cell];
1471 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1475 P4EST_QUADRANT_INIT(&p4est_child[c]);
1478 P8EST_QUADRANT_INIT(&p4est_child[c]);
1481 Assert (
false, ExcNotImplemented());
1486 int child0_idx = sc_array_bsearch(const_cast<sc_array_t *>(&tree.quadrants),
1489 Assert(child0_idx != -1,
ExcMessage(
"the first child should exist as an active quadrant!"));
1493 sc_array_index (const_cast<sc_array_t *>(&tree.quadrants), child0_idx)
1497 for (
typename callback_list_t::const_iterator it = attached_data_pack_callbacks.begin();
1498 it != attached_data_pack_callbacks.end();
1501 void *ptr =
static_cast<char *
>(q->p.user_data) + (*it).first;
1503 ((*it).second)(dealii_cell,
1509 for (
unsigned int i=1; i<GeometryInfo<dim>::max_children_per_cell; ++i)
1511 int child_idx = sc_array_bsearch(const_cast<sc_array_t *>(&tree.quadrants),
1515 sc_array_index (const_cast<sc_array_t *>(&tree.quadrants), child_idx)
1527 sc_array_index (const_cast<sc_array_t *>(&tree.quadrants), idx)
1531 for (
typename callback_list_t::const_iterator it = attached_data_pack_callbacks.begin();
1532 it != attached_data_pack_callbacks.end();
1535 void *ptr =
static_cast<char *
>(q->p.user_data) + (*it).first;
1536 ((*it).second)(dealii_cell,
1543 template <
int dim,
int spacedim>
1549 std::vector<unsigned int> &weight)
1551 const int idx = sc_array_bsearch(const_cast<sc_array_t *>(&tree.quadrants),
1561 const bool p4est_has_children = (idx == -1);
1563 if (p4est_has_children && dealii_cell->has_children())
1567 p4est_child[GeometryInfo<dim>::max_children_per_cell];
1568 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1572 P4EST_QUADRANT_INIT(&p4est_child[c]);
1575 P8EST_QUADRANT_INIT(&p4est_child[c]);
1578 Assert (
false, ExcNotImplemented());
1584 for (
unsigned int c=0;
1585 c<GeometryInfo<dim>::max_children_per_cell; ++c)
1587 get_cell_weights_recursively<dim,spacedim> (tree,
1588 dealii_cell->child(c),
1594 else if (!p4est_has_children && !dealii_cell->has_children())
1597 weight.push_back(1000);
1601 else if (p4est_has_children)
1604 unsigned int parent_weight(1000);
1608 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1611 weight.push_back(parent_weight);
1617 weight.push_back(1000);
1624 template <
int dim,
int spacedim>
1630 const unsigned int offset,
1631 const typename std_cxx11::function<
1635 int idx = sc_array_bsearch(const_cast<sc_array_t *>(&tree.quadrants),
1646 const bool p4est_has_children = (idx == -1);
1647 if (p4est_has_children)
1649 Assert(dealii_cell->has_children(), ExcInternalError());
1653 p4est_child[GeometryInfo<dim>::max_children_per_cell];
1654 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1658 P4EST_QUADRANT_INIT(&p4est_child[c]);
1661 P8EST_QUADRANT_INIT(&p4est_child[c]);
1664 Assert (
false, ExcNotImplemented());
1670 for (
unsigned int c=0;
1671 c<GeometryInfo<dim>::max_children_per_cell; ++c)
1673 post_mesh_data_recursively<dim,spacedim> (tree,
1674 dealii_cell->child(c),
1683 Assert(! dealii_cell->has_children(), ExcInternalError());
1687 sc_array_index (const_cast<sc_array_t *>(&tree.quadrants), idx)
1690 void *ptr =
static_cast<char *
>(q->p.user_data) + offset;
1691 typename parallel::distributed::Triangulation<dim,spacedim>::CellStatus
1692 status = *
static_cast< 1693 typename parallel::distributed::Triangulation<dim,spacedim>::CellStatus *
1699 unpack_callback(dealii_cell, status, ptr);
1704 unpack_callback(parent_cell, status, ptr);
1709 unpack_callback(dealii_cell, status, ptr);
1729 template <
int dim,
int spacedim>
1730 class RefineAndCoarsenList
1734 const std::vector<types::global_dof_index> &p4est_tree_to_coarse_cell_permutation,
1761 bool pointers_are_at_end ()
const;
1764 std::vector<typename internal::p4est::types<dim>::quadrant> refine_list;
1765 typename std::vector<typename internal::p4est::types<dim>::quadrant>::const_iterator current_refine_pointer;
1767 std::vector<typename internal::p4est::types<dim>::quadrant> coarsen_list;
1768 typename std::vector<typename internal::p4est::types<dim>::quadrant>::const_iterator current_coarsen_pointer;
1772 const unsigned int myid);
1777 template <
int dim,
int spacedim>
1779 RefineAndCoarsenList<dim,spacedim>::
1780 pointers_are_at_end ()
const 1782 return ((current_refine_pointer == refine_list.end())
1784 (current_coarsen_pointer == coarsen_list.end()));
1789 template <
int dim,
int spacedim>
1790 RefineAndCoarsenList<dim,spacedim>::
1792 const std::vector<types::global_dof_index> &p4est_tree_to_coarse_cell_permutation,
1796 unsigned int n_refine_flags = 0,
1797 n_coarsen_flags = 0;
1798 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
1800 cell != triangulation.
end(); ++cell)
1803 if (cell->subdomain_id() != my_subdomain)
1806 if (cell->refine_flag_set())
1808 else if (cell->coarsen_flag_set())
1812 refine_list.reserve (n_refine_flags);
1813 coarsen_list.reserve (n_coarsen_flags);
1823 for (
unsigned int c=0; c<triangulation.
n_cells(0); ++c)
1825 unsigned int coarse_cell_index =
1826 p4est_tree_to_coarse_cell_permutation[c];
1829 cell (&triangulation, 0, coarse_cell_index);
1836 p4est_cell.p.which_tree = c;
1837 build_lists (cell, p4est_cell, my_subdomain);
1841 Assert(refine_list.size() == n_refine_flags,
1842 ExcInternalError());
1843 Assert(coarsen_list.size() == n_coarsen_flags,
1844 ExcInternalError());
1847 for (
unsigned int i=1; i<refine_list.size(); ++i)
1848 Assert (refine_list[i].p.which_tree >=
1849 refine_list[i-1].p.which_tree,
1850 ExcInternalError());
1851 for (
unsigned int i=1; i<coarsen_list.size(); ++i)
1852 Assert (coarsen_list[i].p.which_tree >=
1853 coarsen_list[i-1].p.which_tree,
1854 ExcInternalError());
1856 current_refine_pointer = refine_list.begin();
1857 current_coarsen_pointer = coarsen_list.begin();
1862 template <
int dim,
int spacedim>
1864 RefineAndCoarsenList<dim,spacedim>::
1869 if (!cell->has_children())
1871 if (cell->subdomain_id() == my_subdomain)
1873 if (cell->refine_flag_set())
1874 refine_list.push_back (p4est_cell);
1875 else if (cell->coarsen_flag_set())
1876 coarsen_list.push_back (p4est_cell);
1882 p4est_child[GeometryInfo<dim>::max_children_per_cell];
1883 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1887 P4EST_QUADRANT_INIT(&p4est_child[c]);
1890 P8EST_QUADRANT_INIT(&p4est_child[c]);
1893 Assert (
false, ExcNotImplemented());
1898 for (
unsigned int c=0;
1899 c<GeometryInfo<dim>::max_children_per_cell; ++c)
1901 p4est_child[c].p.which_tree = p4est_cell.p.which_tree;
1902 build_lists (cell->child(c),
1910 template <
int dim,
int spacedim>
1912 RefineAndCoarsenList<dim,spacedim>::
1917 RefineAndCoarsenList<dim,spacedim> *this_object
1918 =
reinterpret_cast<RefineAndCoarsenList<dim,spacedim>*
>(forest->user_pointer);
1922 if (this_object->current_refine_pointer == this_object->refine_list.end())
1925 Assert (coarse_cell_index <=
1926 this_object->current_refine_pointer->p.which_tree,
1927 ExcInternalError());
1931 if (coarse_cell_index <
1932 this_object->current_refine_pointer->p.which_tree)
1936 Assert (coarse_cell_index <=
1937 this_object->current_refine_pointer->p.which_tree,
1938 ExcInternalError());
1943 quadrant_compare (quadrant,
1944 &*this_object->current_refine_pointer) <= 0,
1945 ExcInternalError());
1949 quadrant_is_equal (quadrant, &*this_object->current_refine_pointer))
1951 ++this_object->current_refine_pointer;
1961 template <
int dim,
int spacedim>
1963 RefineAndCoarsenList<dim,spacedim>::
1968 RefineAndCoarsenList<dim,spacedim> *this_object
1969 =
reinterpret_cast<RefineAndCoarsenList<dim,spacedim>*
>(forest->user_pointer);
1973 if (this_object->current_coarsen_pointer ==
1974 this_object->coarsen_list.end())
1977 Assert (coarse_cell_index <=
1978 this_object->current_coarsen_pointer->p.which_tree,
1979 ExcInternalError());
1983 if (coarse_cell_index <
1984 this_object->current_coarsen_pointer->p.which_tree)
1988 Assert (coarse_cell_index <=
1989 this_object->current_coarsen_pointer->p.which_tree,
1990 ExcInternalError());
1995 quadrant_compare (children[0],
1996 &*this_object->current_coarsen_pointer) <= 0,
1997 ExcInternalError());
2002 quadrant_is_equal (children[0],
2003 &*this_object->current_coarsen_pointer))
2006 ++this_object->current_coarsen_pointer;
2010 for (
unsigned int c=1; c<GeometryInfo<dim>::max_children_per_cell; ++c)
2013 quadrant_is_equal (children[c],
2014 &*this_object->current_coarsen_pointer),
2015 ExcInternalError());
2016 ++this_object->current_coarsen_pointer;
2034 template <
int dim,
int spacedim>
2035 class PartitionWeights
2043 PartitionWeights (
const std::vector<unsigned int> &cell_weights);
2059 std::vector<unsigned int> cell_weights_list;
2060 std::vector<unsigned int>::const_iterator current_pointer;
2064 template <
int dim,
int spacedim>
2065 PartitionWeights<dim,spacedim>::
2066 PartitionWeights (
const std::vector<unsigned int> &cell_weights)
2068 cell_weights_list(cell_weights)
2072 current_pointer = cell_weights_list.begin();
2076 template <
int dim,
int spacedim>
2078 PartitionWeights<dim,spacedim>::
2087 PartitionWeights<dim,spacedim> *this_object
2088 =
reinterpret_cast<PartitionWeights<dim,spacedim>*
>(forest->user_pointer);
2090 Assert (this_object->current_pointer >= this_object->cell_weights_list.begin(),
2091 ExcInternalError());
2092 Assert (this_object->current_pointer < this_object->cell_weights_list.end(),
2093 ExcInternalError());
2096 return *this_object->current_pointer++;
2115 static bool initialized =
false;
2117 if (initialized ==
false)
2119 sc_init (MPI_COMM_WORLD,
2120 0, 0, 0, SC_LP_SILENT);
2121 p4est_init (0, SC_LP_SILENT);
2130 static bool deinitialized =
false;
2132 if (deinitialized ==
false)
2137 deinitialized =
true;
2145 static void do_initialize ()
2147 static Singleton singleton;
2156 namespace distributed
2162 template <
int dim,
int spacedim>
2165 const typename ::Triangulation<dim,spacedim>::MeshSmoothing smooth_grid,
2173 settings(settings_),
2174 triangulation_has_content (false),
2176 parallel_forest (0),
2177 refinement_in_progress (false),
2178 attached_data_size(0),
2179 n_attached_datas(0),
2180 n_attached_deserialize(0)
2185 ::internal::p4est::InitFinalize::do_initialize ();
2192 template <
int dim,
int spacedim>
2198 ExcInternalError());
2199 Assert (connectivity == 0, ExcInternalError());
2200 Assert (parallel_forest == 0, ExcInternalError());
2207 template <
int dim,
int spacedim>
2219 catch (
const typename ::Triangulation<dim,spacedim>::DistortedCellList &)
2252 namespace CommunicateLocallyMovedVertices
2261 template <
int dim,
int spacedim>
2265 std::vector<unsigned int> tree_index;
2267 std::vector<typename ::internal::p4est::types<dim>::quadrant> quadrants;
2270 std::vector<unsigned int> vertex_indices;
2273 std::vector<::Point<spacedim> >
vertices;
2277 std::vector<unsigned int * > first_vertex_indices;
2278 std::vector<::Point<spacedim>* > first_vertices;
2280 unsigned int bytes_for_buffer ()
const 2282 return (
sizeof(
unsigned int) +
2283 tree_index.size() *
sizeof(
unsigned int) +
2284 quadrants.size() *
sizeof(typename ::internal::p4est
2285 ::types<dim>::quadrant) +
2287 vertex_indices.size() *
sizeof(
unsigned int);
2290 void pack_data (std::vector<char> &buffer)
const 2292 buffer.resize(bytes_for_buffer());
2294 char *ptr = &buffer[0];
2296 const unsigned int num_cells = tree_index.size();
2297 std::memcpy(ptr, &num_cells,
sizeof(
unsigned int));
2298 ptr +=
sizeof(
unsigned int);
2302 num_cells*
sizeof(
unsigned int));
2303 ptr += num_cells*
sizeof(
unsigned int);
2307 num_cells *
sizeof(typename ::internal::p4est::
2308 types<dim>::quadrant));
2309 ptr += num_cells*
sizeof(typename ::internal::p4est::types<dim>::
2314 vertex_indices.size() *
sizeof(
unsigned int));
2315 ptr += vertex_indices.size() *
sizeof(
unsigned int);
2322 Assert (ptr == &buffer[0]+buffer.size(),
2323 ExcInternalError());
2327 void unpack_data (
const std::vector<char> &buffer)
2329 const char *ptr = &buffer[0];
2331 memcpy(&cells, ptr,
sizeof(
unsigned int));
2332 ptr +=
sizeof(
unsigned int);
2334 tree_index.resize(cells);
2335 memcpy(&tree_index[0],ptr,
sizeof(
unsigned int)*cells);
2336 ptr +=
sizeof(
unsigned int)*cells;
2338 quadrants.resize(cells);
2339 memcpy(&quadrants[0],ptr,
2340 sizeof(typename ::internal::p4est::types<dim>::quadrant)*cells);
2341 ptr +=
sizeof(typename ::internal::p4est::types<dim>::quadrant)*cells;
2343 vertex_indices.clear();
2344 first_vertex_indices.resize(cells);
2345 std::vector<unsigned int> n_vertices_on_cell(cells);
2346 std::vector<unsigned int> first_indices (cells);
2347 for (
unsigned int c=0; c<cells; ++c)
2352 const unsigned int *
const vertex_index
2353 =
reinterpret_cast<const unsigned int *const
>(ptr);
2354 first_indices[c] = vertex_indices.size();
2355 vertex_indices.push_back(*vertex_index);
2356 n_vertices_on_cell[c] = *vertex_index;
2357 ptr +=
sizeof(
unsigned int);
2359 vertex_indices.resize(vertex_indices.size() + n_vertices_on_cell[c]);
2360 memcpy(&vertex_indices[vertex_indices.size() - n_vertices_on_cell[c]],
2361 ptr, n_vertices_on_cell[c]*
sizeof(
unsigned int));
2362 ptr += n_vertices_on_cell[c]*
sizeof(
unsigned int);
2364 for (
unsigned int c=0; c<cells; ++c)
2365 first_vertex_indices[c] = &vertex_indices[first_indices[c]];
2368 first_vertices.resize(cells);
2369 for (
unsigned int c=0; c<cells; ++c)
2372 const ::Point<spacedim> *
const vertex
2373 =
reinterpret_cast<const ::Point<spacedim> * const
>(ptr);
2374 first_indices[c] = vertices.size();
2375 vertices.push_back(*vertex);
2377 vertices.resize(vertices.size() + n_vertices_on_cell[c]-1);
2378 memcpy(&vertices[vertices.size() - (n_vertices_on_cell[c]-1)],
2382 for (
unsigned int c=0; c<cells; ++c)
2383 first_vertices[c] = &vertices[first_indices[c]];
2385 Assert (ptr == &buffer[0]+buffer.size(),
2386 ExcInternalError());
2404 template <
int dim,
int spacedim>
2407 const unsigned int tree_index,
2409 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
2410 const std::map<
unsigned int, std::set<::types::subdomain_id> > &vertices_with_ghost_neighbors,
2411 const std::vector<bool> &vertex_locally_moved,
2416 if (dealii_cell->has_children())
2418 typename ::internal::p4est::types<dim>::quadrant
2419 p4est_child[GeometryInfo<dim>::max_children_per_cell];
2420 ::internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
2423 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
2424 fill_vertices_recursively<dim,spacedim>(tria,
2426 dealii_cell->child(c),
2428 vertices_with_ghost_neighbors,
2429 vertex_locally_moved,
2441 if (dealii_cell->is_locally_owned())
2443 std::set<::types::subdomain_id> send_to;
2444 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
2446 const std::map<unsigned int, std::set<::types::subdomain_id> >::const_iterator
2447 neighbor_subdomains_of_vertex
2448 = vertices_with_ghost_neighbors.find (dealii_cell->vertex_index(v));
2450 if (neighbor_subdomains_of_vertex
2451 != vertices_with_ghost_neighbors.end())
2453 Assert(neighbor_subdomains_of_vertex->second.size()!=0,
2454 ExcInternalError());
2455 send_to.insert(neighbor_subdomains_of_vertex->second.begin(),
2456 neighbor_subdomains_of_vertex->second.end());
2460 if (send_to.size() > 0)
2462 std::vector<unsigned int> vertex_indices;
2463 std::vector<::Point<spacedim> > local_vertices;
2464 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
2465 if (vertex_locally_moved[dealii_cell->vertex_index(v)])
2467 vertex_indices.push_back(v);
2468 local_vertices.push_back(dealii_cell->vertex(v));
2471 if (vertex_indices.size()>0)
2472 for (std::set<::types::subdomain_id>::iterator it=send_to.begin();
2473 it!=send_to.end(); ++it)
2475 const ::types::subdomain_id subdomain = *it;
2479 const typename std::map<::types::subdomain_id, CellInfo<dim, spacedim> >::iterator
2481 = needs_to_get_cell.insert (std::make_pair(subdomain,
2482 CellInfo<dim,spacedim>()))
2485 p->second.tree_index.push_back(tree_index);
2486 p->second.quadrants.push_back(p4est_cell);
2488 p->second.vertex_indices.push_back(vertex_indices.size());
2489 p->second.vertex_indices.insert(p->second.vertex_indices.end(),
2490 vertex_indices.begin(),
2491 vertex_indices.end());
2493 p->second.vertices.insert(p->second.vertices.end(),
2494 local_vertices.begin(),
2495 local_vertices.end());
2512 template <
int dim,
int spacedim>
2514 set_vertices_recursively (
2516 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
2518 const typename ::internal::p4est::types<dim>::quadrant &quadrant,
2519 const ::Point<spacedim> *
const vertices,
2520 const unsigned int *
const vertex_indices)
2522 if (::internal::p4est::quadrant_is_equal<dim>(p4est_cell, quadrant))
2524 Assert(!dealii_cell->is_artificial(), ExcInternalError());
2525 Assert(!dealii_cell->has_children(), ExcInternalError());
2526 Assert(!dealii_cell->is_locally_owned(), ExcInternalError());
2528 const unsigned int n_vertices = vertex_indices[0];
2532 dealii_cell->vertex(vertex_indices[i+1]) = vertices[i];
2537 if (! dealii_cell->has_children())
2540 if (! ::internal::p4est::quadrant_is_ancestor<dim> (p4est_cell, quadrant))
2543 typename ::internal::p4est::types<dim>::quadrant
2544 p4est_child[GeometryInfo<dim>::max_children_per_cell];
2545 ::internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
2547 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
2548 set_vertices_recursively<dim,spacedim> (tria, p4est_child[c],
2549 dealii_cell->child(c),
2558 template <
int dim,
int spacedim>
2570 if (parallel_forest != 0)
2573 parallel_forest = 0;
2576 if (connectivity != 0)
2582 coarse_cell_to_p4est_tree_permutation.resize (0);
2583 p4est_tree_to_coarse_cell_permutation.resize (0);
2592 template <
int dim,
int spacedim>
2605 bool have_coarser_cell =
false;
2609 if (cell->is_locally_owned())
2611 have_coarser_cell =
true;
2621 template <
int dim,
int spacedim>
2627 coarse_cell_to_p4est_tree_permutation.resize (this->
n_cells(0));
2630 coarse_cell_to_p4est_tree_permutation);
2632 p4est_tree_to_coarse_cell_permutation
2638 template <
int dim,
int spacedim>
2642 Assert (parallel_forest != 0,
2643 ExcMessage (
"Can't produce output when no forest is created yet."));
2649 template <
int dim,
int spacedim>
2655 ExcMessage (
"not all SolutionTransfer's got deserialized after the last load()"));
2656 int real_data_size = 0;
2662 if (this->my_subdomain==0)
2664 std::string fname=std::string(filename)+
".info";
2665 std::ofstream f(fname.c_str());
2666 f <<
"version nproc attached_bytes n_attached_objs n_coarse_cells" << std::endl
2669 << real_data_size <<
" " 2691 void *userptr = parallel_forest->user_pointer;
2693 parallel_forest->user_pointer = userptr;
2697 template <
int dim,
int spacedim>
2701 const bool autopartition)
2703 Assert(this->
n_cells()>0,
ExcMessage(
"load() only works if the Triangulation already contains a coarse mesh!"));
2713 parallel_forest = 0;
2717 unsigned int version, numcpus, attached_size, attached_count, n_coarse_cells;
2719 std::string fname=std::string(filename)+
".info";
2720 std::ifstream f(fname.c_str());
2721 std::string firstline;
2722 getline(f, firstline);
2723 f >> version >> numcpus >> attached_size >> attached_count >> n_coarse_cells;
2726 Assert(version == 2,
ExcMessage(
"Incompatible version found in .info file."));
2728 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 2731 ExcMessage(
"parallel::distributed::Triangulation::load() only supports loading " 2732 "saved data with a greater or equal number of processes than were used to " 2733 "save() when using p4est 0.3.4.2."));
2740 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3) 2743 attached_size, attached_size>0,
2748 (void)autopartition;
2751 attached_size, attached_size>0,
2781 template <
int dim,
int spacedim>
2785 Assert (parallel_forest != 0,
2786 ExcMessage (
"Can't produce a check sum when no forest is created yet."));
2787 return ::internal::p4est::functions<dim>::checksum (parallel_forest);
2790 template <
int dim,
int spacedim>
2804 cell = this->
begin();
2805 cell != this->
end();
2809 this->number_cache.level_ghost_owners.insert(cell->level_subdomain_id());
2816 template <
int dim,
int spacedim>
2817 typename ::internal::p4est::types<dim>::tree *
2821 const unsigned int tree_index
2822 = coarse_cell_to_p4est_tree_permutation[dealii_coarse_cell_index];
2823 typename ::internal::p4est::types<dim>::tree *tree
2824 =
static_cast<typename ::internal::p4est::types<dim>::tree *
> 2825 (sc_array_index (parallel_forest->trees,
2837 const unsigned int dim = 2, spacedim = 2;
2845 std::vector<unsigned int> vertex_touch_count;
2848 std::pair<Triangulation<dim,spacedim>::active_cell_iterator,
2851 get_vertex_to_cell_mappings (*
this,
2854 const ::internal::p4est::types<2>::locidx
2855 num_vtt = std::accumulate (vertex_touch_count.begin(),
2856 vertex_touch_count.end(),
2862 const bool set_vertex_info
2877 set_vertex_and_cell_info (*
this,
2880 coarse_cell_to_p4est_tree_permutation,
2884 Assert (p4est_connectivity_is_valid (connectivity) == 1,
2885 ExcInternalError());
2908 const unsigned int dim = 2, spacedim = 3;
2916 std::vector<unsigned int> vertex_touch_count;
2919 std::pair<Triangulation<dim,spacedim>::active_cell_iterator,
2922 get_vertex_to_cell_mappings (*
this,
2925 const ::internal::p4est::types<2>::locidx
2926 num_vtt = std::accumulate (vertex_touch_count.begin(),
2927 vertex_touch_count.end(),
2933 const bool set_vertex_info
2948 set_vertex_and_cell_info (*
this,
2951 coarse_cell_to_p4est_tree_permutation,
2955 Assert (p4est_connectivity_is_valid (connectivity) == 1,
2956 ExcInternalError());
2977 const int dim = 3, spacedim = 3;
2985 std::vector<unsigned int> vertex_touch_count;
2988 std::pair<Triangulation<3>::active_cell_iterator,
2991 get_vertex_to_cell_mappings (*
this,
2994 const ::internal::p4est::types<2>::locidx
2995 num_vtt = std::accumulate (vertex_touch_count.begin(),
2996 vertex_touch_count.end(),
2999 std::vector<unsigned int> edge_touch_count;
3002 std::pair<Triangulation<3>::active_cell_iterator,
3005 get_edge_to_cell_mappings (*
this,
3008 const ::internal::p4est::types<2>::locidx
3009 num_ett = std::accumulate (edge_touch_count.begin(),
3010 edge_touch_count.end(),
3014 const bool set_vertex_info
3031 set_vertex_and_cell_info (*
this,
3034 coarse_cell_to_p4est_tree_permutation,
3063 const unsigned int deal_to_p4est_line_index[12]
3064 = { 4, 5, 0, 1, 6, 7, 2, 3, 8, 9, 10, 11 } ;
3066 for (Triangulation<dim,spacedim>::active_cell_iterator
3068 cell != this->
end(); ++cell)
3071 index = coarse_cell_to_p4est_tree_permutation[cell->index()];
3072 for (
unsigned int e=0; e<GeometryInfo<3>::lines_per_cell; ++e)
3074 deal_to_p4est_line_index[e]]
3075 = cell->line(e)->index();
3080 connectivity->ett_offset[0] = 0;
3081 std::partial_sum (edge_touch_count.begin(),
3082 edge_touch_count.end(),
3083 &connectivity->ett_offset[1]);
3085 Assert (connectivity->ett_offset[this->n_active_lines()] ==
3087 ExcInternalError());
3091 Assert (edge_to_cell[v].size() == edge_touch_count[v],
3092 ExcInternalError());
3095 <Triangulation<dim,spacedim>::active_cell_iterator,
3096 unsigned int> >::const_iterator
3097 p = edge_to_cell[v].begin();
3098 for (
unsigned int c=0; c<edge_touch_count[v]; ++c, ++p)
3100 connectivity->edge_to_tree[connectivity->ett_offset[v]+c]
3101 = coarse_cell_to_p4est_tree_permutation[p->first->index()];
3102 connectivity->edge_to_edge[connectivity->ett_offset[v]+c]
3103 = deal_to_p4est_line_index[p->second];
3107 Assert (p8est_connectivity_is_valid (connectivity) == 1,
3108 ExcInternalError());
3143 template <
typename ITERATOR>
3146 std::vector<unsigned int> &topological_vertex_numbering)
3148 const unsigned int dim = ITERATOR::AccessorType::dimension;
3153 if (periodic.
cell[0]->has_children() &&
3154 periodic.
cell[1]->has_children())
3160 for (
unsigned int cf=0; cf<periodic.
cell[0]->face(periodic.
face_idx[0])->n_children(); ++cf)
3162 const unsigned int child_index_0 =
3168 periodic_child.
cell[0] = periodic.
cell[0]->child(child_index_0);
3173 const unsigned int child_index_1 =
3177 periodic_child.
cell[1] = periodic.
cell[1]->child(child_index_1);
3181 identify_periodic_vertices_recursively (periodic_child,
3182 topological_vertex_numbering);
3186 for (
unsigned int v=0; v<
GeometryInfo<dim-1>::vertices_per_cell; ++v)
3190 const unsigned int vface0 =
3194 const unsigned int vi0 = topological_vertex_numbering[periodic.
cell[0]->face(periodic.
face_idx[0])->vertex_index(vface0)];
3195 const unsigned int vi1 = topological_vertex_numbering[periodic.
cell[1]->face(periodic.
face_idx[1])->vertex_index(v)];
3196 const unsigned int min_index = std::min(vi0, vi1);
3197 topological_vertex_numbering[periodic.
cell[0]->face(periodic.
face_idx[0])->vertex_index(vface0)]
3198 = topological_vertex_numbering[periodic.
cell[1]->face(periodic.
face_idx[1])->vertex_index(v)]
3207 template <
int dim,
int spacedim>
3208 bool enforce_mesh_balance_over_periodic_boundaries
3215 std::vector<bool> flags_before[2];
3219 std::vector<unsigned int> topological_vertex_numbering(tria.
n_vertices());
3220 for (
unsigned int i=0; i<topological_vertex_numbering.size(); ++i)
3221 topological_vertex_numbering[i] = i;
3225 topological_vertex_numbering);
3230 bool continue_iterating =
true;
3231 std::vector<int> vertex_level(tria.
n_vertices());
3232 while (continue_iterating)
3236 std::fill (vertex_level.begin(), vertex_level.end(), 0);
3237 typename Triangulation<dim,spacedim>::active_cell_iterator
3239 for (; cell!=endc; ++cell)
3241 if (cell->refine_flag_set())
3242 for (
unsigned int vertex=0; vertex<GeometryInfo<dim>::vertices_per_cell;
3244 vertex_level[topological_vertex_numbering[cell->vertex_index(vertex)]]
3245 = std::max (vertex_level[topological_vertex_numbering[cell->vertex_index(vertex)]],
3247 else if (!cell->coarsen_flag_set())
3248 for (
unsigned int vertex=0; vertex<GeometryInfo<dim>::vertices_per_cell;
3250 vertex_level[topological_vertex_numbering[cell->vertex_index(vertex)]]
3251 = std::max (vertex_level[topological_vertex_numbering[cell->vertex_index(vertex)]],
3261 Assert (cell->coarsen_flag_set(), ExcInternalError());
3262 for (
unsigned int vertex=0; vertex<GeometryInfo<dim>::vertices_per_cell;
3264 vertex_level[topological_vertex_numbering[cell->vertex_index(vertex)]]
3265 = std::max (vertex_level[topological_vertex_numbering[cell->vertex_index(vertex)]],
3270 continue_iterating =
false;
3281 for (cell=tria.
last_active(); cell != endc; --cell)
3282 if (cell->refine_flag_set() ==
false)
3284 for (
unsigned int vertex=0;
3285 vertex<GeometryInfo<dim>::vertices_per_cell; ++vertex)
3286 if (vertex_level[topological_vertex_numbering[cell->vertex_index(vertex)]] >=
3290 cell->clear_coarsen_flag();
3295 if (vertex_level[topological_vertex_numbering[cell->vertex_index(vertex)]] >
3298 cell->set_refine_flag();
3299 continue_iterating =
true;
3301 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell;
3303 vertex_level[topological_vertex_numbering[cell->vertex_index(v)]]
3304 = std::max (vertex_level[topological_vertex_numbering[cell->vertex_index(v)]],
3316 cell!=tria.
end(); ++cell)
3322 const unsigned int n_children=cell->n_children();
3323 unsigned int flagged_children=0;
3324 for (
unsigned int child=0; child<n_children; ++child)
3325 if (cell->child(child)->active() &&
3326 cell->child(child)->coarsen_flag_set())
3331 if (flagged_children < n_children)
3332 for (
unsigned int child=0; child<n_children; ++child)
3333 if (cell->child(child)->active())
3334 cell->child(child)->clear_coarsen_flag();
3337 std::vector<bool> flags_after[2];
3340 return ((flags_before[0] != flags_after[0]) ||
3341 (flags_before[1] != flags_after[1]));
3347 template <
int dim,
int spacedim>
3351 std::vector<bool> flags_before[2];
3355 bool mesh_changed =
false;
3363 mesh_changed = enforce_mesh_balance_over_periodic_boundaries(*
this,
3366 while (mesh_changed);
3370 std::vector<bool> flags_after[2];
3373 return ((flags_before[0] != flags_after[0]) ||
3374 (flags_before[1] != flags_after[1]));
3379 template <
int dim,
int spacedim>
3402 bool mesh_changed =
false;
3415 cell != this->
end();
3418 cell->set_coarsen_flag();
3449 typename ::internal::p4est::types<dim>::
3450 balance_type(P4EST_CONNECT_CORNER)
3452 typename ::internal::p4est::types<dim>::
3453 balance_type(P8EST_CONNECT_CORNER)));
3461 cell = this->
begin(0);
3462 cell != this->
end(0);
3469 cell = this->
begin(0);
3470 cell != this->
end(0);
3476 if (tree_exists_locally<dim,spacedim>(parallel_forest,
3477 coarse_cell_to_p4est_tree_permutation[cell->index()])
3480 delete_all_children<dim,spacedim> (cell);
3481 if (!cell->has_children())
3490 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
3491 typename ::internal::p4est::types<dim>::tree *tree =
3494 ::internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
3496 match_tree_recursively<dim,spacedim> (*tree, cell,
3506 typename ::internal::p4est::types<dim>::quadrant *quadr;
3507 unsigned int ghost_owner=0;
3508 typename ::internal::p4est::types<dim>::topidx ghost_tree=0;
3510 for (
unsigned int g_idx=0; g_idx<
parallel_ghost->ghosts.elem_count; ++g_idx)
3512 while (g_idx >= (
unsigned int)
parallel_ghost->proc_offsets[ghost_owner+1])
3514 while (g_idx >= (
unsigned int)
parallel_ghost->tree_offsets[ghost_tree+1])
3517 quadr =
static_cast<typename ::internal::p4est::types<dim>::quadrant *
> 3520 unsigned int coarse_cell_index =
3521 p4est_tree_to_coarse_cell_permutation[ghost_tree];
3523 match_quadrant<dim,spacedim> (
this, coarse_cell_index, *quadr, ghost_owner);
3530 mesh_changed =
false;
3531 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
3533 cell != this->
end();
3535 if (cell->refine_flag_set() || cell->coarsen_flag_set())
3537 mesh_changed =
true;
3559 while (mesh_changed);
3563 unsigned int num_ghosts = 0;
3565 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
3567 cell != this->
end();
3570 if (cell->subdomain_id() != this->my_subdomain
3584 if (
settings & construct_multigrid_hierarchy)
3590 for (
unsigned int lvl=this->
n_levels(); lvl>0; )
3608 std::vector<std::vector<bool> > marked_vertices(this->
n_levels());
3609 for (
unsigned int lvl=0; lvl < this->
n_levels(); ++lvl)
3614 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
3615 const unsigned int tree_index
3616 = coarse_cell_to_p4est_tree_permutation[cell->index()];
3617 typename ::internal::p4est::types<dim>::tree *tree =
3620 ::internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
3622 determine_level_subdomain_id_recursively<dim,spacedim> (*tree, tree_index, cell,
3630 for (
unsigned int lvl=this->
n_levels(); lvl>0;)
3635 if (cell->has_children())
3636 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
3643 mark = cell->child(0)->level_subdomain_id();
3645 cell->set_level_subdomain_id(mark);
3664 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
3666 if (cell->face(f)->at_boundary() || cell->neighbor(f)->level() >= cell->level())
3671 if (cell_level_mine && !neighbor_level_mine)
3674 Assert(cell->neighbor(f)->active(), ExcInternalError());
3677 || cell->neighbor(f)->level_subdomain_id() == cell->neighbor(f)->subdomain_id(), ExcInternalError());
3678 cell->neighbor(f)->set_level_subdomain_id(cell->neighbor(f)->subdomain_id());
3680 else if (!cell_level_mine && neighbor_level_mine)
3683 Assert(cell->active(), ExcInternalError());
3686 || cell->level_subdomain_id() == cell->subdomain_id(), ExcInternalError());
3687 cell->set_level_subdomain_id(cell->subdomain_id());
3704 (void)total_local_cells;
3707 Assert (static_cast<unsigned int>(parallel_forest->local_num_quadrants) ==
3711 Assert (static_cast<unsigned int>(parallel_forest->local_num_quadrants) <=
3713 ExcInternalError());
3716 unsigned int n_owned = 0;
3717 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
3719 cell != this->
end(); ++cell)
3725 Assert(static_cast<unsigned int>(parallel_forest->local_num_quadrants) ==
3726 n_owned, ExcInternalError());
3735 template <
int dim,
int spacedim>
3748 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
3750 cell != this->
end(); ++cell)
3751 if (cell->is_locally_owned() && cell->refine_flag_set())
3752 Assert (cell->refine_flag_set() ==
3754 ExcMessage (
"This class does not support anisotropic refinement"));
3761 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
3766 ExcMessage(
"Fatal Error: maximum refinement level of p4est reached."));
3776 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
3778 cell != this->
end(); ++cell)
3779 if (cell->is_ghost() || cell->is_artificial())
3781 cell->clear_refine_flag ();
3782 cell->clear_coarsen_flag ();
3788 RefineAndCoarsenList<dim,spacedim>
3789 refine_and_coarsen_list (*
this,
3790 p4est_tree_to_coarse_cell_permutation,
3791 this->my_subdomain);
3797 Assert (parallel_forest->user_pointer ==
this,
3798 ExcInternalError());
3799 parallel_forest->user_pointer = &refine_and_coarsen_list;
3807 refine (parallel_forest,
false,
3808 &RefineAndCoarsenList<dim,spacedim>::refine_callback,
3811 coarsen (parallel_forest,
false,
3812 &RefineAndCoarsenList<dim,spacedim>::coarsen_callback,
3816 Assert (refine_and_coarsen_list.pointers_are_at_end(),
3817 ExcInternalError());
3820 parallel_forest->user_pointer =
this;
3828 typename ::internal::p4est::types<dim>::
3829 balance_type(P4EST_CONNECT_FULL)
3831 typename ::internal::p4est::types<dim>::
3832 balance_type(P8EST_CONNECT_FULL)),
3845 partition (parallel_forest,
3853 PartitionWeights<dim,spacedim> partition_weights (cell_weights);
3857 Assert (parallel_forest->user_pointer ==
this,
3858 ExcInternalError());
3859 parallel_forest->user_pointer = &partition_weights;
3864 &PartitionWeights<dim,spacedim>::cell_weight);
3867 parallel_forest->user_pointer =
this;
3874 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
3876 cell != this->
end(); ++cell)
3878 cell->clear_refine_flag();
3879 cell->clear_coarsen_flag();
3894 refinement_in_progress =
false;
3899 template <
int dim,
int spacedim>
3905 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
3907 cell != this->
end(); ++cell)
3908 if (cell->is_locally_owned())
3910 !cell->refine_flag_set() && !cell->coarsen_flag_set(),
3911 ExcMessage (
"Error: There shouldn't be any cells flagged for coarsening/refinement when calling repartition()."));
3934 PartitionWeights<dim,spacedim> partition_weights (cell_weights);
3938 Assert (parallel_forest->user_pointer ==
this,
3939 ExcInternalError());
3940 parallel_forest->user_pointer = &partition_weights;
3945 &PartitionWeights<dim,spacedim>::cell_weight);
3948 parallel_forest->user_pointer =
this;
3970 template <
int dim,
int spacedim>
3976 ExcDimensionMismatch(vertex_locally_moved.size(),
3980 const std::vector<bool> locally_owned_vertices
3982 for (
unsigned int i=0; i<locally_owned_vertices.size(); ++i)
3983 Assert ((vertex_locally_moved[i] ==
false)
3985 (locally_owned_vertices[i] ==
true),
3986 ExcMessage (
"The vertex_locally_moved argument must not " 3987 "contain vertices that are not locally owned"));
3991 std::map<unsigned int, std::set<::types::subdomain_id> >
3992 vertices_with_ghost_neighbors;
3997 for (
typename Triangulation<dim,spacedim>::active_cell_iterator
4000 if (cell->is_ghost())
4001 for (
unsigned int vertex_no=0;
4002 vertex_no<GeometryInfo<dim>::vertices_per_cell; ++vertex_no)
4004 const unsigned int process_local_vertex_no = cell->vertex_index(vertex_no);
4005 vertices_with_ghost_neighbors[process_local_vertex_no].insert
4006 (cell->subdomain_id());
4012 std::map<::types::subdomain_id, CommunicateLocallyMovedVertices::CellInfo<dim,spacedim> > cellmap_t;
4013 cellmap_t needs_to_get_cells;
4016 cell = this->
begin(0);
4017 cell != this->
end(0);
4020 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
4021 ::internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
4023 CommunicateLocallyMovedVertices::fill_vertices_recursively<dim,spacedim>
4028 vertices_with_ghost_neighbors,
4029 vertex_locally_moved,
4030 needs_to_get_cells);
4034 std::vector<std::vector<char> > sendbuffers (needs_to_get_cells.size());
4035 std::vector<std::vector<char> >::iterator buffer = sendbuffers.begin();
4036 std::vector<MPI_Request> requests (needs_to_get_cells.size());
4037 std::vector<unsigned int> destinations;
4041 for (
typename cellmap_t::iterator it=needs_to_get_cells.begin();
4042 it!=needs_to_get_cells.end();
4043 ++it, ++buffer, ++idx)
4045 const unsigned int num_cells = it->second.tree_index.size();
4047 destinations.push_back(it->first);
4049 Assert(num_cells==it->second.quadrants.size(), ExcInternalError());
4050 Assert(num_cells>0, ExcInternalError());
4059 it->second.pack_data (*buffer);
4060 MPI_Isend(&(*buffer)[0], buffer->size(),
4061 MPI_BYTE, it->first,
4065 Assert(destinations.size()==needs_to_get_cells.size(), ExcInternalError());
4069 const std::vector<unsigned int> senders
4074 std::vector<char> receive;
4075 CommunicateLocallyMovedVertices::CellInfo<dim,spacedim> cellinfo;
4076 for (
unsigned int i=0; i<senders.size(); ++i)
4081 MPI_Get_count(&status, MPI_BYTE, &len);
4082 receive.resize(len);
4084 char *ptr = &receive[0];
4085 MPI_Recv(ptr, len, MPI_BYTE, status.MPI_SOURCE, status.MPI_TAG,
4086 this->get_communicator(), &status);
4088 cellinfo.unpack_data(receive);
4089 const unsigned int cells = cellinfo.tree_index.size();
4090 for (
unsigned int c=0; c<cells; ++c)
4092 typename ::parallel::distributed::Triangulation<dim,spacedim>::cell_iterator
4097 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
4098 ::internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
4100 CommunicateLocallyMovedVertices::set_vertices_recursively<dim,spacedim> (*
this,
4103 cellinfo.quadrants[c],
4104 cellinfo.first_vertices[c],
4105 cellinfo.first_vertex_indices[c]);
4111 if (requests.size() > 0)
4112 MPI_Waitall(requests.size(), &requests[0], MPI_STATUSES_IGNORE);
4117 ExcInternalError());
4120 template <
int dim,
int spacedim>
4126 void *)> &pack_callback)
4130 ExcMessage(
"register_data_attach(), not all data has been unpacked last time?"));
4136 std::pair<unsigned int, pack_callback_t> (offset, pack_callback)
4143 template <
int dim,
int spacedim>
4149 const void *)> &unpack_callback)
4152 ExcMessage (
"invalid offset in notify_ready_to_unpack()"));
4154 ExcMessage (
"invalid offset in notify_ready_to_unpack()"));
4159 cell = this->
begin (0);
4160 cell != this->
end (0);
4164 if (tree_exists_locally<dim, spacedim> (parallel_forest,
4165 coarse_cell_to_p4est_tree_permutation[cell->index() ])
4169 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
4170 typename ::internal::p4est::types<dim>::tree *tree =
4173 ::internal::p4est::init_coarse_quadrant<dim> (p4est_coarse_cell);
4177 post_mesh_data_recursively<dim, spacedim> (*tree,
4205 void *userptr = parallel_forest->user_pointer;
4207 parallel_forest->user_pointer = userptr;
4212 template <
int dim,
int spacedim>
4213 const std::vector<types::global_dof_index> &
4216 return p4est_tree_to_coarse_cell_permutation;
4221 template <
int dim,
int spacedim>
4222 const std::vector<types::global_dof_index> &
4236 template <
int dim,
int spacedim>
4239 typename ::parallel::distributed::Triangulation<dim,spacedim> *triangulation;
4241 std::map<unsigned int, std::set<::types::subdomain_id> >
4242 *vertices_with_ghost_neighbors;
4250 template <
int dim,
int spacedim>
4253 (typename ::internal::p4est::iter<dim>::corner_info *info,
4257 int nsides = info->sides.elem_count;
4258 typename ::internal::p4est::iter<dim>::corner_side *sides =
4259 (typename ::internal::p4est::iter<dim>::corner_side *)
4260 (info->sides.array);
4261 FindGhosts<dim,spacedim> *fg =
static_cast<FindGhosts<dim,spacedim> *
>(user_data);
4262 sc_array_t *subids = fg->subids;
4263 typename ::parallel::distributed::Triangulation<dim,spacedim> *triangulation = fg->triangulation;
4266 std::map<unsigned int, std::set<::types::subdomain_id> >
4267 *vertices_with_ghost_neighbors = fg->vertices_with_ghost_neighbors;
4269 subids->elem_count = 0;
4270 for (i = 0; i < nsides; i++)
4272 if (sides[i].is_ghost)
4274 typename ::parallel::distributed::Triangulation<dim,spacedim>::cell_iterator cell = cell_from_quad (triangulation, sides[i].treeid, *(sides[i].quad));
4275 Assert (cell->is_ghost(),
ExcMessage (
"ghost quad did not find ghost cell"));
4278 *subid = cell->subdomain_id();
4282 if (!subids->elem_count)
4287 nsubs = (int) subids->elem_count;
4290 for (i = 0; i < nsides; i++)
4292 if (!sides[i].is_ghost)
4294 typename ::parallel::distributed::Triangulation<dim,spacedim>::cell_iterator cell = cell_from_quad (triangulation, sides[i].treeid, *(sides[i].quad));
4298 for (j = 0; j < nsubs; j++)
4300 (*vertices_with_ghost_neighbors)[cell->vertex_index(sides[i].corner)]
4301 .insert (subdomain_ids[j]);
4306 subids->elem_count = 0;
4312 template <
int dim,
int spacedim>
4315 (typename ::internal::p4est::iter<dim>::edge_info *info,
4319 int nsides = info->sides.elem_count;
4320 typename ::internal::p4est::iter<dim>::edge_side *sides =
4321 (typename ::internal::p4est::iter<dim>::edge_side *)
4322 (info->sides.array);
4323 FindGhosts<dim,spacedim> *fg =
static_cast<FindGhosts<dim,spacedim> *
>(user_data);
4324 sc_array_t *subids = fg->subids;
4325 typename ::parallel::distributed::Triangulation<dim,spacedim> *triangulation = fg->triangulation;
4328 std::map<unsigned int, std::set<::types::subdomain_id> >
4329 *vertices_with_ghost_neighbors = fg->vertices_with_ghost_neighbors;
4331 subids->elem_count = 0;
4332 for (i = 0; i < nsides; i++)
4334 if (sides[i].is_hanging)
4336 for (j = 0; j < 2; j++)
4338 if (sides[i].is.hanging.is_ghost[j])
4340 typename ::parallel::distributed::Triangulation<dim,spacedim>::cell_iterator cell = cell_from_quad (triangulation, sides[i].treeid, *(sides[i].is.hanging.quad[j]));
4343 *subid = cell->subdomain_id();
4349 if (!subids->elem_count)
4354 nsubs = (int) subids->elem_count;
4357 for (i = 0; i < nsides; i++)
4359 if (sides[i].is_hanging)
4361 for (j = 0; j < 2; j++)
4363 if (!sides[i].is.hanging.is_ghost[j])
4365 typename ::parallel::distributed::Triangulation<dim,spacedim>::cell_iterator cell = cell_from_quad (triangulation, sides[i].treeid, *(sides[i].is.hanging.quad[j]));
4367 for (k = 0; k < nsubs; k++)
4369 (*vertices_with_ghost_neighbors)[cell->vertex_index(p8est_edge_corners[sides[i].edge][1^j])]
4370 .insert (subdomain_ids[k]);
4377 subids->elem_count = 0;
4383 template <
int dim,
int spacedim>
4386 (typename ::internal::p4est::iter<dim>::face_info *info,
4390 int nsides = info->sides.elem_count;
4391 typename ::internal::p4est::iter<dim>::face_side *sides =
4392 (typename ::internal::p4est::iter<dim>::face_side *)
4393 (info->sides.array);
4394 FindGhosts<dim,spacedim> *fg =
static_cast<FindGhosts<dim,spacedim> *
>(user_data);
4395 sc_array_t *subids = fg->subids;
4396 typename ::parallel::distributed::Triangulation<dim,spacedim> *triangulation = fg->triangulation;
4399 std::map<unsigned int, std::set<::types::subdomain_id> >
4400 *vertices_with_ghost_neighbors = fg->vertices_with_ghost_neighbors;
4401 int limit = (dim == 2) ? 2 : 4;
4403 subids->elem_count = 0;
4404 for (i = 0; i < nsides; i++)
4406 if (sides[i].is_hanging)
4408 for (j = 0; j < limit; j++)
4410 if (sides[i].is.hanging.is_ghost[j])
4412 typename ::parallel::distributed::Triangulation<dim,spacedim>::cell_iterator cell = cell_from_quad (triangulation, sides[i].treeid, *(sides[i].is.hanging.quad[j]));
4415 *subid = cell->subdomain_id();
4421 if (!subids->elem_count)
4426 nsubs = (int) subids->elem_count;
4429 for (i = 0; i < nsides; i++)
4431 if (sides[i].is_hanging)
4433 for (j = 0; j < limit; j++)
4435 if (!sides[i].is.hanging.is_ghost[j])
4437 typename ::parallel::distributed::Triangulation<dim,spacedim>::cell_iterator cell = cell_from_quad (triangulation, sides[i].treeid, *(sides[i].is.hanging.quad[j]));
4439 for (k = 0; k < nsubs; k++)
4443 (*vertices_with_ghost_neighbors)[cell->vertex_index(p4est_face_corners[sides[i].face][(limit - 1)^j])]
4444 .insert (subdomain_ids[k]);
4448 (*vertices_with_ghost_neighbors)[cell->vertex_index(p8est_face_corners[sides[i].face][(limit - 1)^j])]
4449 .insert (subdomain_ids[k]);
4457 subids->elem_count = 0;
4470 template <
typename ITERATOR>
4473 const int target_level,
4474 std::vector<bool> &active_vertices_on_level)
4476 if (periodic.
cell[0]->level() > target_level)
4479 const unsigned int dim = ITERATOR::AccessorType::dimension;
4482 if (periodic.
cell[0]->level() < target_level &&
4483 periodic.
cell[0]->has_children() &&
4484 periodic.
cell[1]->has_children())
4490 for (
unsigned int cf=0; cf<periodic.
cell[0]->face(periodic.
face_idx[0])->n_children(); ++cf)
4492 const unsigned int child_index_0 =
4498 periodic_child.
cell[0] = periodic.
cell[0]->child(child_index_0);
4503 const unsigned int child_index_1 =
4507 periodic_child.
cell[1] = periodic.
cell[1]->child(child_index_1);
4511 mark_periodic_vertices_recursively (periodic_child, target_level,
4512 active_vertices_on_level);
4517 if (periodic.
cell[0]->level() != target_level)
4520 for (
unsigned int v=0; v<
GeometryInfo<dim-1>::vertices_per_cell; ++v)
4524 const unsigned int vface0 =
4528 if (active_vertices_on_level[periodic.
cell[0]->face(periodic.
face_idx[0])->vertex_index(vface0)] ||
4529 active_vertices_on_level[periodic.
cell[1]->face(periodic.
face_idx[1])->vertex_index(v)])
4530 active_vertices_on_level[periodic.
cell[0]->face(periodic.
face_idx[0])->vertex_index(vface0)]
4531 = active_vertices_on_level[periodic.
cell[1]->face(periodic.
face_idx[1])->vertex_index(v)]
4542 template <
typename ITERATOR>
4545 const int target_level,
4546 std::map<
unsigned int, std::set<::types::subdomain_id> > &vertices_with_ghost_neighbors)
4548 if (periodic.
cell[0]->level() > target_level)
4553 if (periodic.
cell[0]->level() < target_level &&
4554 periodic.
cell[0]->has_children() &&
4555 periodic.
cell[1]->has_children())
4561 for (
unsigned int cf=0; cf<periodic.
cell[0]->face(periodic.
face_idx[0])->n_children(); ++cf)
4564 for (; c<periodic.
cell[0]->n_children(); ++c)
4566 if (periodic.
cell[0]->child(c)->face(periodic.
face_idx[0]) ==
4567 periodic.
cell[0]->face(periodic.
face_idx[0])->child(cf))
4572 periodic_child.
cell[0] = periodic.
cell[0]->child(c);
4576 for (; c<periodic.
cell[1]->n_children(); ++c)
4578 if (periodic.
cell[1]->child(c)->face(periodic.
face_idx[1]) ==
4579 periodic.
cell[1]->face(periodic.
face_idx[1])->child(cf))
4584 periodic_child.
cell[1] = periodic.
cell[1]->child(c);
4588 set_periodic_ghost_neighbors_recursively (periodic_child, target_level,
4589 vertices_with_ghost_neighbors);
4594 if (periodic.
cell[0]->level() != target_level)
4601 ExcNotImplemented());
4603 for (
unsigned int v=0; v<
GeometryInfo<ITERATOR::AccessorType::dimension-1>::vertices_per_cell; ++v)
4606 idx0 = periodic.
cell[0]->face(periodic.
face_idx[0])->vertex_index(v),
4607 idx1 = periodic.
cell[1]->face(periodic.
face_idx[1])->vertex_index(v);
4608 if (vertices_with_ghost_neighbors.find(idx0) !=
4609 vertices_with_ghost_neighbors.end())
4610 vertices_with_ghost_neighbors[idx1].
4611 insert(vertices_with_ghost_neighbors[idx0].
begin(),
4612 vertices_with_ghost_neighbors[idx0].end());
4613 if (vertices_with_ghost_neighbors.find(idx1) !=
4614 vertices_with_ghost_neighbors.end())
4615 vertices_with_ghost_neighbors[idx0].
4616 insert(vertices_with_ghost_neighbors[idx1].
begin(),
4617 vertices_with_ghost_neighbors[idx1].end());
4628 template <
int dim,
int spacedim>
4632 (std::map<
unsigned int, std::set<::types::subdomain_id> >
4633 &vertices_with_ghost_neighbors)
4635 Assert (dim>1, ExcNotImplemented());
4637 FindGhosts<dim,spacedim> fg;
4639 fg.triangulation =
this;
4640 fg.vertices_with_ghost_neighbors = &vertices_with_ghost_neighbors;
4650 static_cast<void *>(&fg),
4651 NULL, find_ghosts_face<2,spacedim>, find_ghosts_corner<2,spacedim>);
4657 static_cast<void *>(&fg),
4658 NULL, find_ghosts_face<3,spacedim>, find_ghosts_edge<3,spacedim>, find_ghosts_corner<3,spacedim>);
4662 Assert (
false, ExcNotImplemented());
4665 sc_array_destroy (fg.subids);
4674 template <
int dim,
int spacedim>
4678 (
const unsigned int level,
4679 std::map<
unsigned int, std::set<::types::subdomain_id> >
4680 &vertices_with_ghost_neighbors)
4682 const std::vector<bool> locally_active_vertices =
4685 if (cell->level_subdomain_id() != ::numbers::artificial_subdomain_id
4687 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
4688 if (locally_active_vertices[cell->vertex_index(v)])
4689 vertices_with_ghost_neighbors[cell->vertex_index(v)]
4690 .insert (cell->level_subdomain_id());
4694 level, vertices_with_ghost_neighbors);
4699 template<
int dim,
int spacedim>
4704 Assert (dim>1, ExcNotImplemented());
4706 std::vector<bool> marked_vertices(this->
n_vertices(),
false);
4709 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
4710 marked_vertices[cell->vertex_index(v)] =
true;
4714 level, marked_vertices);
4716 return marked_vertices;
4721 template<
int dim,
int spacedim>
4727 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,1) 4731 ExcMessage (
"The triangulation is refined!"));
4733 typedef std::vector<GridTools::PeriodicFacePair<cell_iterator> >
4735 typename FaceVector::const_iterator it, periodic_end;
4736 it = periodicity_vector.begin();
4737 periodic_end = periodicity_vector.end();
4739 for (; it<periodic_end; ++it)
4743 const unsigned int face_left = it->face_idx[0];
4744 const unsigned int face_right = it->face_idx[1];
4747 const unsigned int tree_left
4748 = coarse_cell_to_p4est_tree_permutation[std::distance(this->
begin(),
4750 const unsigned int tree_right
4751 = coarse_cell_to_p4est_tree_permutation[std::distance(this->
begin(),
4761 unsigned int p4est_orientation = 0;
4763 p4est_orientation = it->orientation[1];
4766 const unsigned int face_idx_list[] = {face_left, face_right};
4767 const cell_iterator cell_list[] = {first_cell, second_cell};
4768 unsigned int lower_idx, higher_idx;
4769 if (face_left<=face_right)
4781 unsigned int first_p4est_idx_on_cell = p8est_face_corners[face_idx_list[lower_idx]][0];
4783 for (
unsigned int i=0; i<GeometryInfo<dim>::vertices_per_face; ++i)
4785 const unsigned int first_dealii_idx_on_cell
4787 (face_idx_list[lower_idx], i,
4788 cell_list[lower_idx]->face_orientation(face_idx_list[lower_idx]),
4789 cell_list[lower_idx]->face_flip(face_idx_list[lower_idx]),
4790 cell_list[lower_idx]->face_rotation(face_idx_list[lower_idx]));
4791 if (first_p4est_idx_on_cell == first_dealii_idx_on_cell)
4793 first_dealii_idx_on_face = i;
4799 const unsigned int left_to_right [8][4] = {{0,2,1,3},{0,1,2,3},{3,1,2,0},{3,2,1,0},
4800 {2,3,0,1},{1,3,0,2},{1,0,3,2},{2,0,3,1}
4802 const unsigned int right_to_left [8][4] = {{0,2,1,3},{0,1,2,3},{3,1,2,0},{3,2,1,0},
4803 {2,3,0,1},{2,0,3,1},{1,0,3,2},{1,3,0,2}
4805 const unsigned int second_dealii_idx_on_face
4806 = lower_idx==0?left_to_right[it->orientation.to_ulong()][first_dealii_idx_on_face]:
4807 right_to_left[it->orientation.to_ulong()][first_dealii_idx_on_face];
4808 const unsigned int second_dealii_idx_on_cell
4810 (face_idx_list[higher_idx], second_dealii_idx_on_face,
4811 cell_list[higher_idx]->face_orientation(face_idx_list[higher_idx]),
4812 cell_list[higher_idx]->face_flip(face_idx_list[higher_idx]),
4813 cell_list[higher_idx]->face_rotation(face_idx_list[higher_idx]));
4815 const unsigned int second_p4est_idx_on_face
4816 = p8est_corner_face_corners[second_dealii_idx_on_cell][face_idx_list[higher_idx]];
4817 p4est_orientation = second_p4est_idx_on_face;
4831 (connectivity) == 1, ExcInternalError());
4859 periodicity_vector.begin(),
4860 periodicity_vector.end());
4869 template <
int dim,
int spacedim>
4891 template <
int dim,
int spacedim>
4895 return ::internal::p4est::functions<dim>::forest_memory_used(parallel_forest)
4901 template <
int dim,
int spacedim>
4911 catch (
const typename ::Triangulation<dim,spacedim>::DistortedCellList &)
4923 Assert (old_tria.n_levels() == 1,
4924 ExcMessage (
"Parallel distributed triangulations can only be copied, " 4925 "if they are not refined!"));
4927 if (const ::parallel::distributed::Triangulation<dim,spacedim> *
4928 old_tria_x =
dynamic_cast<const ::parallel::distributed::Triangulation<dim,spacedim> *
>(&old_tria))
4930 Assert (!old_tria_x->refinement_in_progress,
4931 ExcMessage (
"Parallel distributed triangulations can only " 4932 "be copied, if no refinement is in progress!"));
4937 coarse_cell_to_p4est_tree_permutation = old_tria_x->coarse_cell_to_p4est_tree_permutation;
4938 p4est_tree_to_coarse_cell_permutation = old_tria_x->p4est_tree_to_coarse_cell_permutation;
4966 template <
int dim,
int spacedim>
4982 void *userptr = parallel_forest->user_pointer;
4986 parallel_forest->user_pointer = userptr;
4993 cell = this->
begin(0);
4994 cell != this->
end(0);
4998 if (tree_exists_locally<dim,spacedim>(parallel_forest,
4999 coarse_cell_to_p4est_tree_permutation[cell->index()])
5003 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
5004 typename ::internal::p4est::types<dim>::tree *tree =
5007 ::internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
5009 attach_mesh_data_recursively<dim,spacedim>(*tree,
5016 template <
int dim,
int spacedim>
5017 std::vector<unsigned int>
5026 std::vector<unsigned int> weights;
5035 for (
unsigned int c=0; c<this->
n_cells(0); ++c)
5038 if (tree_exists_locally<dim,spacedim>(parallel_forest,c) ==
false)
5041 const unsigned int coarse_cell_index =
5042 p4est_tree_to_coarse_cell_permutation[c];
5045 dealii_coarse_cell (
this, 0, coarse_cell_index);
5047 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
5052 p4est_coarse_cell.p.which_tree = c;
5054 const typename ::internal::p4est::types<dim>::tree *tree =
5057 get_cell_weights_recursively<dim,spacedim>(*tree,
5067 template <
int dim,
int spacedim>
5068 typename ::Triangulation<dim,spacedim>::cell_iterator
5070 (typename ::parallel::distributed::Triangulation<dim,spacedim> *triangulation,
5071 typename ::internal::p4est::types<dim>::topidx treeidx,
5072 typename ::internal::p4est::types<dim>::quadrant &quad)
5074 int i, l = quad.level;
5077 triangulation->get_p4est_tree_to_coarse_cell_permutation()[treeidx];
5079 for (i = 0; i < l; i++)
5081 typename ::Triangulation<dim,spacedim>::cell_iterator cell (triangulation, i, dealii_index);
5083 Assert (cell->has_children (),
ExcMessage (
"p4est quadrant does not correspond to a cell!"));
5084 dealii_index = cell->child_index(child_id);
5087 typename ::Triangulation<dim,spacedim>::cell_iterator out_cell (triangulation, l, dealii_index);
5094 template <
int spacedim>
5101 Assert (
false, ExcNotImplemented());
5105 template <
int spacedim>
5108 Assert (
false, ExcNotImplemented());
5113 template <
int spacedim>
5116 (
const std::vector<bool> &)
5118 Assert (
false, ExcNotImplemented());
5122 template <
int spacedim>
5123 const std::vector<types::global_dof_index> &
5126 static std::vector<types::global_dof_index> a;
5130 template <
int spacedim>
5134 (std::map<
unsigned int, std::set<::types::subdomain_id> >
5137 Assert (
false, ExcNotImplemented());
5140 template <
int spacedim>
5144 (
const unsigned int ,
5145 std::map<
unsigned int, std::set<::types::subdomain_id> >
5148 Assert (
false, ExcNotImplemented());
5151 template <
int spacedim>
5156 Assert (
false, ExcNotImplemented());
5157 return std::vector<bool>();
5163 #else // DEAL_II_WITH_P4EST 5167 namespace distributed
5169 template <
int dim,
int spacedim>
5174 Assert (
false, ExcNotImplemented());
5179 #endif // DEAL_II_WITH_P4EST 5185 #include "tria.inst" 5188 DEAL_II_NAMESPACE_CLOSE
virtual unsigned int n_global_levels() const
void write_mesh_vtk(const char *file_basename) const
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria)
std::vector< unsigned int > get_cell_weights()
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 const unsigned int invalid_unsigned_int
void fill_vertices_with_ghost_neighbors(std::map< unsigned int, std::set<::types::subdomain_id > > &vertices_with_ghost_neighbors)
const std::vector< Point< spacedim > > & get_vertices() const
cell_iterator end() const
types::subdomain_id my_subdomain
unsigned int register_data_attach(const std::size_t size, const std_cxx11::function< void(const cell_iterator &, const CellStatus, void *)> &pack_callback)
unsigned int n_active_lines() const
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria)
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)
std::vector< Point< spacedim > > vertices
::ExceptionBase & ExcMessage(std::string arg1)
boost::signals2::signal< unsigned int(const cell_iterator &, const CellStatus), CellWeightSum< unsigned int > > cell_weight
bool triangulation_has_content
virtual void copy_triangulation(const Triangulation< dim, spacedim > &old_tria)
unsigned int attached_data_size
void notify_ready_to_unpack(const unsigned int offset, const std_cxx11::function< void(const cell_iterator &, const CellStatus, const void *)> &unpack_callback)
const std::vector< bool > & get_used_vertices() const
virtual std::size_t memory_consumption_p4est() const
void copy_new_triangulation_to_p4est(::internal::int2type< 2 >)
unsigned int get_checksum() const
#define AssertThrow(cond, exc)
void fill_level_vertices_with_ghost_neighbors(const unsigned int level, std::map< unsigned int, std::set<::types::subdomain_id > > &vertices_with_ghost_neighbors)
virtual bool has_hanging_nodes() const
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)
callback_list_t attached_data_pack_callbacks
cell_iterator begin(const unsigned int level=0) const
unsigned int n_active_cells() const
void add_periodicity(const std::vector< GridTools::PeriodicFacePair< cell_iterator > > &)
typename::internal::p4est::types< dim >::ghost * parallel_ghost
unsigned int n_levels() const
typename::internal::p4est::types< dim >::forest * parallel_forest
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
virtual bool prepare_coarsening_and_refinement()
virtual void execute_coarsening_and_refinement()
virtual MPI_Comm get_communicator() const
void save_coarsen_flags(std::ostream &out) const
virtual bool prepare_coarsening_and_refinement()
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)
unsigned int global_dof_index
static unsigned int child_cell_on_face(const RefinementCase< dim > &ref_case, const unsigned int face, const unsigned int subface, const bool face_orientation=true, const bool face_flip=false, const bool face_rotation=false, const RefinementCase< dim-1 > &face_refinement_case=RefinementCase< dim-1 >::isotropic_refinement)
const std::vector< types::global_dof_index > & get_p4est_tree_to_coarse_cell_permutation() const
#define Assert(cond, exc)
virtual void update_number_cache()
std::vector< bool > mark_locally_active_vertices_on_level(const unsigned int level) const
virtual std::size_t memory_consumption() const
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
virtual std::size_t memory_consumption() const
types::subdomain_id locally_owned_subdomain() const
void save_refine_flags(std::ostream &out) const
virtual void execute_coarsening_and_refinement()
std::vector< unsigned int > invert_permutation(const std::vector< unsigned int > &permutation)
unsigned int subdomain_id
active_cell_iterator last_active() const
bool refinement_in_progress
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
::Triangulation< dim, spacedim >::active_cell_iterator active_cell_iterator
const types::subdomain_id artificial_subdomain_id
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
void communicate_locally_moved_vertices(const std::vector< bool > &vertex_locally_moved)
MeshSmoothing smooth_grid
unsigned int n_attached_datas
void setup_coarse_cell_to_p4est_tree_permutation()
::Triangulation< dim, spacedim >::cell_iterator cell_iterator
std::vector< GridTools::PeriodicFacePair< cell_iterator > > periodic_face_pairs_level_0
void save(const char *filename) const
unsigned int n_attached_deserialize
active_cell_iterator begin_active(const unsigned int level=0) const
virtual void update_number_cache()
std::vector< unsigned int > compute_point_to_point_communication_pattern(const MPI_Comm &mpi_comm, const std::vector< unsigned int > &destinations)
void copy_local_forest_to_triangulation()
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::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation