Reference documentation for deal.II version GIT relicensing-822-gf1642d4ea5 2024-06-12 14:10:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
tria.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2010 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
18#include <deal.II/base/point.h>
20
23
25#include <deal.II/grid/tria.h>
28
29#include <algorithm>
30#include <fstream>
31#include <iostream>
32#include <limits>
33#include <numeric>
34
35
37
38
39namespace internal
40{
41 namespace parallel
42 {
43 namespace distributed
44 {
45 namespace TriangulationImplementation
46 {
54 template <int dim, int spacedim>
55 void
58 {
59 auto pack =
61 &cell) -> std::uint8_t {
62 if (cell->refine_flag_set())
63 return 1;
64 if (cell->coarsen_flag_set())
65 return 2;
66 return 0;
67 };
68
69 auto unpack =
71 &cell,
72 const std::uint8_t &flag) -> void {
73 cell->clear_coarsen_flag();
74 cell->clear_refine_flag();
75 if (flag == 1)
76 cell->set_refine_flag();
77 else if (flag == 2)
78 cell->set_coarsen_flag();
79 };
80
81 GridTools::exchange_cell_data_to_ghosts<std::uint8_t>(tria,
82 pack,
83 unpack);
84 }
85 } // namespace TriangulationImplementation
86 } // namespace distributed
87 } // namespace parallel
88} // namespace internal
89
90
91
92#ifdef DEAL_II_WITH_P4EST
93
94namespace
95{
96 template <int dim, int spacedim>
97 void
100 std::vector<unsigned int> &vertex_touch_count,
101 std::vector<std::list<
103 unsigned int>>> &vertex_to_cell)
104 {
105 vertex_touch_count.resize(triangulation.n_vertices());
106 vertex_to_cell.resize(triangulation.n_vertices());
107
108 for (const auto &cell : triangulation.active_cell_iterators())
109 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
110 {
111 ++vertex_touch_count[cell->vertex_index(v)];
112 vertex_to_cell[cell->vertex_index(v)].emplace_back(cell, v);
113 }
114 }
115
116
117
118 template <int dim, int spacedim>
119 void
122 std::vector<unsigned int> &edge_touch_count,
123 std::vector<std::list<
125 unsigned int>>> &edge_to_cell)
126 {
127 Assert(triangulation.n_levels() == 1, ExcInternalError());
128
129 edge_touch_count.resize(triangulation.n_active_lines());
130 edge_to_cell.resize(triangulation.n_active_lines());
131
132 for (const auto &cell : triangulation.active_cell_iterators())
134 {
135 ++edge_touch_count[cell->line(l)->index()];
136 edge_to_cell[cell->line(l)->index()].emplace_back(cell, l);
137 }
138 }
139
140
141
146 template <int dim, int spacedim>
147 void
150 const std::vector<unsigned int> &vertex_touch_count,
151 const std::vector<std::list<
153 unsigned int>>> &vertex_to_cell,
154 const std::vector<types::global_dof_index>
155 &coarse_cell_to_p4est_tree_permutation,
156 const bool set_vertex_info,
157 typename internal::p4est::types<dim>::connectivity *connectivity)
158 {
159 // copy the vertices into the connectivity structure. the triangulation
160 // exports the array of vertices, but some of the entries are sometimes
161 // unused; this shouldn't be the case for a newly created triangulation,
162 // but make sure
163 //
164 // note that p4est stores coordinates as a triplet of values even in 2d
165 Assert(triangulation.get_used_vertices().size() ==
166 triangulation.get_vertices().size(),
168 Assert(std::find(triangulation.get_used_vertices().begin(),
169 triangulation.get_used_vertices().end(),
170 false) == triangulation.get_used_vertices().end(),
172 if (set_vertex_info == true)
173 for (unsigned int v = 0; v < triangulation.n_vertices(); ++v)
174 {
175 connectivity->vertices[3 * v] = triangulation.get_vertices()[v][0];
176 connectivity->vertices[3 * v + 1] =
177 triangulation.get_vertices()[v][1];
178 connectivity->vertices[3 * v + 2] =
179 (spacedim == 2 ? 0 : triangulation.get_vertices()[v][2]);
180 }
181
182 // next store the tree_to_vertex indices (each tree is here only a single
183 // cell in the coarse mesh). p4est requires vertex numbering in clockwise
184 // orientation
185 //
186 // while we're at it, also copy the neighborship information between cells
188 cell = triangulation.begin_active(),
189 endc = triangulation.end();
190 for (; cell != endc; ++cell)
191 {
192 const unsigned int index =
193 coarse_cell_to_p4est_tree_permutation[cell->index()];
194
195 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
196 {
197 if (set_vertex_info == true)
198 connectivity
200 v] = cell->vertex_index(v);
201 connectivity
203 v] = cell->vertex_index(v);
204 }
205
206 // neighborship information. if a cell is at a boundary, then enter
207 // the index of the cell itself here
208 for (auto f : GeometryInfo<dim>::face_indices())
209 if (cell->face(f)->at_boundary() == false)
210 connectivity
211 ->tree_to_tree[index * GeometryInfo<dim>::faces_per_cell + f] =
212 coarse_cell_to_p4est_tree_permutation[cell->neighbor(f)->index()];
213 else
214 connectivity
215 ->tree_to_tree[index * GeometryInfo<dim>::faces_per_cell + f] =
216 coarse_cell_to_p4est_tree_permutation[cell->index()];
217
218 // fill tree_to_face, which is essentially neighbor_to_neighbor;
219 // however, we have to remap the resulting face number as well
220 for (auto f : GeometryInfo<dim>::face_indices())
221 if (cell->face(f)->at_boundary() == false)
222 {
223 switch (dim)
224 {
225 case 2:
226 {
227 connectivity->tree_to_face
229 cell->neighbor_of_neighbor(f);
230 break;
231 }
232
233 case 3:
234 {
235 /*
236 * The values for tree_to_face are in 0..23 where ttf % 6
237 * gives the face number and ttf / 4 the face orientation
238 * code. The orientation is determined as follows. Let
239 * my_face and other_face be the two face numbers of the
240 * connecting trees in 0..5. Then the first face vertex
241 * of the lower of my_face and other_face connects to a
242 * face vertex numbered 0..3 in the higher of my_face and
243 * other_face. The face orientation is defined as this
244 * number. If my_face == other_face, treating either of
245 * both faces as the lower one leads to the same result.
246 */
247
248 connectivity->tree_to_face[index * 6 + f] =
249 cell->neighbor_of_neighbor(f);
250
251 unsigned int face_idx_list[2] = {
252 f, cell->neighbor_of_neighbor(f)};
254 cell_list[2] = {cell, cell->neighbor(f)};
255 unsigned int smaller_idx = 0;
256
257 if (f > cell->neighbor_of_neighbor(f))
258 smaller_idx = 1;
259
260 unsigned int larger_idx = (smaller_idx + 1) % 2;
261 // smaller = *_list[smaller_idx]
262 // larger = *_list[larger_idx]
263
264 unsigned int v = 0;
265
266 // global vertex index of vertex 0 on face of cell with
267 // smaller local face index
268 unsigned int g_idx = cell_list[smaller_idx]->vertex_index(
271 0,
272 cell_list[smaller_idx]->face_orientation(
274 cell_list[smaller_idx]->face_flip(
276 cell_list[smaller_idx]->face_rotation(
278
279 // loop over vertices on face from other cell and compare
280 // global vertex numbers
281 for (unsigned int i = 0;
283 ++i)
284 {
285 unsigned int idx =
286 cell_list[larger_idx]->vertex_index(
289
290 if (idx == g_idx)
291 {
292 v = i;
293 break;
294 }
295 }
296
297 connectivity->tree_to_face[index * 6 + f] += 6 * v;
298 break;
299 }
300
301 default:
303 }
304 }
305 else
306 connectivity
307 ->tree_to_face[index * GeometryInfo<dim>::faces_per_cell + f] = f;
308 }
309
310 // now fill the vertex information
311 connectivity->ctt_offset[0] = 0;
312 std::partial_sum(vertex_touch_count.begin(),
313 vertex_touch_count.end(),
314 &connectivity->ctt_offset[1]);
315
317 std::accumulate(vertex_touch_count.begin(), vertex_touch_count.end(), 0u);
318 (void)num_vtt;
319 Assert(connectivity->ctt_offset[triangulation.n_vertices()] == num_vtt,
321
322 for (unsigned int v = 0; v < triangulation.n_vertices(); ++v)
323 {
326
327 typename std::list<
328 std::pair<typename Triangulation<dim, spacedim>::active_cell_iterator,
329 unsigned int>>::const_iterator p =
330 vertex_to_cell[v].begin();
331 for (unsigned int c = 0; c < vertex_touch_count[v]; ++c, ++p)
332 {
333 connectivity->corner_to_tree[connectivity->ctt_offset[v] + c] =
334 coarse_cell_to_p4est_tree_permutation[p->first->index()];
335 connectivity->corner_to_corner[connectivity->ctt_offset[v] + c] =
336 p->second;
337 }
338 }
339 }
340
341
342
343 template <int dim, int spacedim>
344 bool
346 const typename internal::p4est::types<dim>::forest *parallel_forest,
348 {
349 Assert(coarse_grid_cell < parallel_forest->connectivity->num_trees,
351 return ((coarse_grid_cell >= parallel_forest->first_local_tree) &&
353 }
354
355
356 template <int dim, int spacedim>
357 void
360 {
361 if (cell->has_children())
362 for (unsigned int c = 0; c < cell->n_children(); ++c)
364 else
365 cell->set_coarsen_flag();
366 }
367
368
369
370 template <int dim, int spacedim>
371 void
374 {
375 if (cell->has_children())
376 for (unsigned int c = 0; c < cell->n_children(); ++c)
378 }
379
380
381 template <int dim, int spacedim>
382 void
384 const typename internal::p4est::types<dim>::tree &tree,
389 const types::subdomain_id my_subdomain,
390 const std::vector<std::vector<bool>> &marked_vertices)
391 {
392 if (dealii_cell->level_subdomain_id() == numbers::artificial_subdomain_id)
393 {
394 // important: only assign the level_subdomain_id if it is a ghost cell
395 // even though we could fill in all.
396 bool used = false;
397 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
398 {
399 if (marked_vertices[dealii_cell->level()]
400 [dealii_cell->vertex_index(v)])
401 {
402 used = true;
403 break;
404 }
405 }
406
407 // Special case: if this cell is active we might be a ghost neighbor
408 // to a locally owned cell across a vertex that is finer.
409 // Example (M= my, O=dealii_cell, owned by somebody else):
410 // *------*
411 // | |
412 // | O |
413 // | |
414 // *---*---*------*
415 // | M | M |
416 // *---*---*
417 // | | M |
418 // *---*---*
419 if (!used && dealii_cell->is_active() &&
420 dealii_cell->is_artificial() == false &&
421 dealii_cell->level() + 1 < static_cast<int>(marked_vertices.size()))
422 {
423 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
424 {
425 if (marked_vertices[dealii_cell->level() + 1]
426 [dealii_cell->vertex_index(v)])
427 {
428 used = true;
429 break;
430 }
431 }
432 }
433
434 // Like above, but now the other way around
435 if (!used && dealii_cell->is_active() &&
436 dealii_cell->is_artificial() == false && dealii_cell->level() > 0)
437 {
438 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
439 {
440 if (marked_vertices[dealii_cell->level() - 1]
441 [dealii_cell->vertex_index(v)])
442 {
443 used = true;
444 break;
445 }
446 }
447 }
448
449 if (used)
450 {
452 &forest, tree_index, &p4est_cell, my_subdomain);
453 Assert((owner != -2) && (owner != -1),
454 ExcMessage("p4est should know the owner."));
455 dealii_cell->set_level_subdomain_id(owner);
456 }
457 }
458
459 if (dealii_cell->has_children())
460 {
463 for (unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
464 ++c)
465 switch (dim)
466 {
467 case 2:
469 break;
470 case 3:
472 break;
473 default:
475 }
476
477
480
481 for (unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
482 ++c)
483 {
485 tree,
487 dealii_cell->child(c),
488 p4est_child[c],
489 forest,
490 my_subdomain,
491 marked_vertices);
492 }
493 }
494 }
495
496
497 template <int dim, int spacedim>
498 void
500 const typename internal::p4est::types<dim>::tree &tree,
503 const typename internal::p4est::types<dim>::forest &forest,
504 const types::subdomain_id my_subdomain)
505 {
506 // check if this cell exists in the local p4est cell
507 if (sc_array_bsearch(const_cast<sc_array_t *>(&tree.quadrants),
508 &p4est_cell,
510 -1)
511 {
512 // yes, cell found in local part of p4est
514 if (dealii_cell->is_active())
515 dealii_cell->set_subdomain_id(my_subdomain);
516 }
517 else
518 {
519 // no, cell not found in local part of p4est. this means that the
520 // local part is more refined than the current cell. if this cell has
521 // no children of its own, we need to refine it, and if it does
522 // already have children then loop over all children and see if they
523 // are locally available as well
524 if (dealii_cell->is_active())
525 dealii_cell->set_refine_flag();
526 else
527 {
530 for (unsigned int c = 0;
532 ++c)
533 switch (dim)
534 {
535 case 2:
537 break;
538 case 3:
540 break;
541 default:
543 }
544
545
548
549 for (unsigned int c = 0;
551 ++c)
554 &tree),
555 &p4est_child[c]) == false)
556 {
557 // no, this child is locally not available in the p4est.
558 // delete all its children but, because this may not be
559 // successful, make sure to mark all children recursively
560 // as not local.
562 dealii_cell->child(c)->recursively_set_subdomain_id(
564 }
565 else
566 {
567 // at least some part of the tree rooted in this child is
568 // locally available
570 dealii_cell->child(c),
571 p4est_child[c],
572 forest,
573 my_subdomain);
574 }
575 }
576 }
577 }
578
579
580 template <int dim, int spacedim>
581 void
583 const ::Triangulation<dim, spacedim> *tria,
584 unsigned int dealii_index,
587 {
588 const int l = ghost_quadrant.level;
589
590 for (int i = 0; i < l; ++i)
591 {
593 i,
595 if (cell->is_active())
596 {
597 cell->clear_coarsen_flag();
598 cell->set_refine_flag();
599 return;
600 }
601
602 const int child_id =
604 i + 1);
605 dealii_index = cell->child_index(child_id);
606 }
607
609 l,
611 if (cell->has_children())
613 else
614 {
615 cell->clear_coarsen_flag();
616 cell->set_subdomain_id(ghost_owner);
617 }
618 }
619
620# ifdef P4EST_SEARCH_LOCAL
621 template <int dim>
622 class PartitionSearch
623 {
624 public:
626 {
627 Assert(dim > 1, ExcNotImplemented());
628 }
629
631
633 operator=(const PartitionSearch<dim> &other) = delete;
634
635 public:
645 static int
648 typename internal::p4est::types<dim>::quadrant *quadrant,
649 int rank_begin,
650 int rank_end,
651 void *point);
652
665 static int
668 typename internal::p4est::types<dim>::quadrant *quadrant,
669 int rank_begin,
670 int rank_end,
671 void *point);
672
673 private:
678 class QuadrantData
679 {
680 public:
681 QuadrantData();
682
683 void
687 typename internal::p4est::types<dim>::quadrant *quadrant,
690
691 void
692 initialize_mapping();
693
695 map_real_to_unit_cell(const Point<dim> &p) const;
696
697 bool
698 is_in_this_quadrant(const Point<dim> &p) const;
699
700 private:
701 std::vector<Point<dim>> cell_vertices;
702
708
710
712 };
713
718 }; // class PartitionSearch
719
720
721
722 template <int dim>
723 int
727 typename internal::p4est::types<dim>::quadrant *quadrant,
728 int /* rank_begin */,
729 int /* rank_end */,
730 void * /* this is always nullptr */ point)
731 {
732 // point must be nullptr here
733 (void)point;
734 Assert(point == nullptr, ::ExcInternalError());
735
736 // we need the user pointer
737 // note that this is not available since function is static
739 reinterpret_cast<PartitionSearch<dim> *>(forest->user_pointer);
740
741 // Avoid p4est macros, instead do bitshifts manually with fixed size types
745 (dim == 2 ? P4EST_MAXLEVEL : P8EST_MAXLEVEL)) -
747 quadrant->level));
748
749 this_object->quadrant_data.set_cell_vertices(forest,
751 quadrant,
753
754 // from cell vertices we can initialize the mapping
755 this_object->quadrant_data.initialize_mapping();
756
757 // always return true since we must decide by point
758 return /* true */ 1;
759 }
760
761
762
763 template <int dim>
764 int
767 typename internal::p4est::types<dim>::topidx /* which_tree */,
768 typename internal::p4est::types<dim>::quadrant * /* quadrant */,
769 int rank_begin,
770 int rank_end,
771 void *point)
772 {
773 // point must NOT be be nullptr here
774 Assert(point != nullptr, ::ExcInternalError());
775
776 // we need the user pointer
777 // note that this is not available since function is static
779 reinterpret_cast<PartitionSearch<dim> *>(forest->user_pointer);
780
781 // point with rank as double pointer
782 double *this_point_dptr = static_cast<double *>(point);
783
785 (dim == 2 ? Point<dim>(this_point_dptr[0], this_point_dptr[1]) :
786 Point<dim>(this_point_dptr[0],
788 this_point_dptr[2]));
789
790 // use reference mapping to decide whether this point is in this quadrant
791 const bool is_in_this_quadrant =
792 this_object->quadrant_data.is_in_this_quadrant(this_point);
793
794
795
797 {
798 // no need to search further, stop recursion
799 return /* false */ 0;
800 }
801
802
803
804 // From here we have a candidate
805 if (rank_begin < rank_end)
806 {
807 // continue recursion
808 return /* true */ 1;
809 }
810
811 // Now, we know that the point is found (rank_begin==rank_end) and we have
812 // the MPI rank, so no need to search further.
813 this_point_dptr[dim] = static_cast<double>(rank_begin);
814
815 // stop recursion.
816 return /* false */ 0;
817 }
818
819
820
821 template <int dim>
822 bool
824 const Point<dim> &p) const
825 {
827
829 }
830
831
832
833 template <int dim>
836 const Point<dim> &p) const
837 {
840 "Cell vertices and mapping coefficients must be fully "
841 "initialized before transforming a point to the unit cell."));
842
844
845 if (dim == 2)
846 {
847 for (unsigned int alpha = 0;
849 ++alpha)
850 {
851 const Point<dim> &p_ref =
853
857 quadrant_mapping_matrix(alpha, 3) * p(0) * p(1)) *
858 p_ref;
859 }
860 }
861 else
862 {
863 for (unsigned int alpha = 0;
865 ++alpha)
866 {
867 const Point<dim> &p_ref =
869
874 quadrant_mapping_matrix(alpha, 4) * p(0) * p(1) +
875 quadrant_mapping_matrix(alpha, 5) * p(1) * p(2) +
876 quadrant_mapping_matrix(alpha, 6) * p(0) * p(2) +
877 quadrant_mapping_matrix(alpha, 7) * p(0) * p(1) * p(2)) *
878 p_ref;
879 }
880 }
881
882 return p_out;
883 }
884
885
886 template <int dim>
888 : cell_vertices(GeometryInfo<dim>::vertices_per_cell)
889 , quadrant_mapping_matrix(GeometryInfo<dim>::vertices_per_cell,
890 GeometryInfo<dim>::vertices_per_cell)
893 {}
894
895
896
897 template <int dim>
898 void
900 {
901 Assert(
904 "Cell vertices must be initialized before the cell mapping can be filled."));
905
908
909 if (dim == 2)
910 {
911 for (unsigned int alpha = 0;
913 ++alpha)
914 {
915 // point matrix to be inverted
916 point_matrix(0, alpha) = 1;
919 point_matrix(3, alpha) =
921 }
922
923 /*
924 * Rows of quadrant_mapping_matrix are the coefficients of the basis
925 * on the physical cell
926 */
928 }
929 else
930 {
931 for (unsigned int alpha = 0;
933 ++alpha)
934 {
935 // point matrix to be inverted
936 point_matrix(0, alpha) = 1;
940 point_matrix(4, alpha) =
942 point_matrix(5, alpha) =
944 point_matrix(6, alpha) =
947 cell_vertices[alpha](1) *
949 }
950
951 /*
952 * Rows of quadrant_mapping_matrix are the coefficients of the basis
953 * on the physical cell
954 */
956 }
957
959 }
960
961
962
963 template <>
964 void
966 typename internal::p4est::types<2>::forest *forest,
968 typename internal::p4est::types<2>::quadrant *quadrant,
971 {
972 constexpr unsigned int dim = 2;
973
974 // p4est for some reason always needs double vxyz[3] as last argument to
975 // quadrant_coord_to_vertex
976 double corner_point[dim + 1] = {0};
977
978 // A lambda to avoid code duplication.
979 const auto copy_vertex = [&](unsigned int vertex_index) -> void {
980 // copy into local struct
981 for (unsigned int d = 0; d < dim; ++d)
982 {
983 cell_vertices[vertex_index](d) = corner_point[d];
984 // reset
985 corner_point[d] = 0;
986 }
987 };
988
989 // Fill points of QuadrantData in lexicographic order
990 /*
991 * Corner #0
992 */
993 unsigned int vertex_index = 0;
995 forest->connectivity, which_tree, quadrant->x, quadrant->y, corner_point);
996
997 // copy into local struct
998 copy_vertex(vertex_index);
999
1000 /*
1001 * Corner #1
1002 */
1003 vertex_index = 1;
1005 forest->connectivity,
1006 which_tree,
1007 quadrant->x + quad_length_on_level,
1008 quadrant->y,
1009 corner_point);
1010
1011 // copy into local struct
1012 copy_vertex(vertex_index);
1013
1014 /*
1015 * Corner #2
1016 */
1017 vertex_index = 2;
1019 forest->connectivity,
1020 which_tree,
1021 quadrant->x,
1022 quadrant->y + quad_length_on_level,
1023 corner_point);
1024
1025 // copy into local struct
1026 copy_vertex(vertex_index);
1027
1028 /*
1029 * Corner #3
1030 */
1031 vertex_index = 3;
1033 forest->connectivity,
1034 which_tree,
1035 quadrant->x + quad_length_on_level,
1036 quadrant->y + quad_length_on_level,
1037 corner_point);
1038
1039 // copy into local struct
1040 copy_vertex(vertex_index);
1041
1043 }
1044
1045
1046
1047 template <>
1048 void
1050 typename internal::p4est::types<3>::forest *forest,
1052 typename internal::p4est::types<3>::quadrant *quadrant,
1055 {
1056 constexpr unsigned int dim = 3;
1057
1058 double corner_point[dim] = {0};
1059
1060 // A lambda to avoid code duplication.
1061 auto copy_vertex = [&](unsigned int vertex_index) -> void {
1062 // copy into local struct
1063 for (unsigned int d = 0; d < dim; ++d)
1064 {
1065 cell_vertices[vertex_index](d) = corner_point[d];
1066 // reset
1067 corner_point[d] = 0;
1068 }
1069 };
1070
1071 // Fill points of QuadrantData in lexicographic order
1072 /*
1073 * Corner #0
1074 */
1075 unsigned int vertex_index = 0;
1077 forest->connectivity,
1078 which_tree,
1079 quadrant->x,
1080 quadrant->y,
1081 quadrant->z,
1082 corner_point);
1083
1084 // copy into local struct
1085 copy_vertex(vertex_index);
1086
1087
1088 /*
1089 * Corner #1
1090 */
1091 vertex_index = 1;
1093 forest->connectivity,
1094 which_tree,
1095 quadrant->x + quad_length_on_level,
1096 quadrant->y,
1097 quadrant->z,
1098 corner_point);
1099
1100 // copy into local struct
1101 copy_vertex(vertex_index);
1102
1103 /*
1104 * Corner #2
1105 */
1106 vertex_index = 2;
1108 forest->connectivity,
1109 which_tree,
1110 quadrant->x,
1111 quadrant->y + quad_length_on_level,
1112 quadrant->z,
1113 corner_point);
1114
1115 // copy into local struct
1116 copy_vertex(vertex_index);
1117
1118 /*
1119 * Corner #3
1120 */
1121 vertex_index = 3;
1123 forest->connectivity,
1124 which_tree,
1125 quadrant->x + quad_length_on_level,
1126 quadrant->y + quad_length_on_level,
1127 quadrant->z,
1128 corner_point);
1129
1130 // copy into local struct
1131 copy_vertex(vertex_index);
1132
1133 /*
1134 * Corner #4
1135 */
1136 vertex_index = 4;
1138 forest->connectivity,
1139 which_tree,
1140 quadrant->x,
1141 quadrant->y,
1142 quadrant->z + quad_length_on_level,
1143 corner_point);
1144
1145 // copy into local struct
1146 copy_vertex(vertex_index);
1147
1148 /*
1149 * Corner #5
1150 */
1151 vertex_index = 5;
1153 forest->connectivity,
1154 which_tree,
1155 quadrant->x + quad_length_on_level,
1156 quadrant->y,
1157 quadrant->z + quad_length_on_level,
1158 corner_point);
1159
1160 // copy into local struct
1161 copy_vertex(vertex_index);
1162
1163 /*
1164 * Corner #6
1165 */
1166 vertex_index = 6;
1168 forest->connectivity,
1169 which_tree,
1170 quadrant->x,
1171 quadrant->y + quad_length_on_level,
1172 quadrant->z + quad_length_on_level,
1173 corner_point);
1174
1175 // copy into local struct
1176 copy_vertex(vertex_index);
1177
1178 /*
1179 * Corner #7
1180 */
1181 vertex_index = 7;
1183 forest->connectivity,
1184 which_tree,
1185 quadrant->x + quad_length_on_level,
1186 quadrant->y + quad_length_on_level,
1187 quadrant->z + quad_length_on_level,
1188 corner_point);
1189
1190 // copy into local struct
1191 copy_vertex(vertex_index);
1192
1193
1195 }
1196# endif // P4EST_SEARCH_LOCAL defined
1197
1198
1204 template <int dim, int spacedim>
1205 class RefineAndCoarsenList
1206 {
1207 public:
1208 RefineAndCoarsenList(const Triangulation<dim, spacedim> &triangulation,
1209 const std::vector<types::global_dof_index>
1210 &p4est_tree_to_coarse_cell_permutation,
1211 const types::subdomain_id my_subdomain);
1212
1221 static int
1223 typename internal::p4est::types<dim>::forest *forest,
1225 typename internal::p4est::types<dim>::quadrant *quadrant);
1226
1231 static int
1233 typename internal::p4est::types<dim>::forest *forest,
1235 typename internal::p4est::types<dim>::quadrant *children[]);
1236
1237 bool
1238 pointers_are_at_end() const;
1239
1240 private:
1241 std::vector<typename internal::p4est::types<dim>::quadrant> refine_list;
1242 typename std::vector<typename internal::p4est::types<dim>::quadrant>::
1243 const_iterator current_refine_pointer;
1244
1245 std::vector<typename internal::p4est::types<dim>::quadrant> coarsen_list;
1246 typename std::vector<typename internal::p4est::types<dim>::quadrant>::
1247 const_iterator current_coarsen_pointer;
1248
1249 void
1254 };
1255
1256
1257
1258 template <int dim, int spacedim>
1259 bool
1260 RefineAndCoarsenList<dim, spacedim>::pointers_are_at_end() const
1261 {
1262 return ((current_refine_pointer == refine_list.end()) &&
1263 (current_coarsen_pointer == coarsen_list.end()));
1264 }
1265
1266
1267
1268 template <int dim, int spacedim>
1269 RefineAndCoarsenList<dim, spacedim>::RefineAndCoarsenList(
1271 const std::vector<types::global_dof_index>
1272 &p4est_tree_to_coarse_cell_permutation,
1273 const types::subdomain_id my_subdomain)
1274 {
1275 // count how many flags are set and allocate that much memory
1276 unsigned int n_refine_flags = 0, n_coarsen_flags = 0;
1277 for (const auto &cell : triangulation.active_cell_iterators())
1278 {
1279 // skip cells that are not local
1280 if (cell->subdomain_id() != my_subdomain)
1281 continue;
1282
1283 if (cell->refine_flag_set())
1285 else if (cell->coarsen_flag_set())
1287 }
1288
1289 refine_list.reserve(n_refine_flags);
1290 coarsen_list.reserve(n_coarsen_flags);
1291
1292
1293 // now build the lists of cells that are flagged. note that p4est will
1294 // traverse its cells in the order in which trees appear in the
1295 // forest. this order is not the same as the order of coarse cells in the
1296 // deal.II Triangulation because we have translated everything by the
1297 // coarse_cell_to_p4est_tree_permutation permutation. in order to make
1298 // sure that the output array is already in the correct order, traverse
1299 // our coarse cells in the same order in which p4est will:
1300 for (unsigned int c = 0; c < triangulation.n_cells(0); ++c)
1301 {
1302 unsigned int coarse_cell_index =
1303 p4est_tree_to_coarse_cell_permutation[c];
1304
1307
1310 /*level=*/0,
1311 /*index=*/0);
1312 p4est_cell.p.which_tree = c;
1313 build_lists(cell, p4est_cell, my_subdomain);
1314 }
1315
1316
1317 Assert(refine_list.size() == n_refine_flags, ExcInternalError());
1318 Assert(coarsen_list.size() == n_coarsen_flags, ExcInternalError());
1319
1320 // make sure that our ordering in fact worked
1321 for (unsigned int i = 1; i < refine_list.size(); ++i)
1322 Assert(refine_list[i].p.which_tree >= refine_list[i - 1].p.which_tree,
1324 for (unsigned int i = 1; i < coarsen_list.size(); ++i)
1325 Assert(coarsen_list[i].p.which_tree >= coarsen_list[i - 1].p.which_tree,
1327
1328 current_refine_pointer = refine_list.begin();
1329 current_coarsen_pointer = coarsen_list.begin();
1330 }
1331
1332
1333
1334 template <int dim, int spacedim>
1335 void
1336 RefineAndCoarsenList<dim, spacedim>::build_lists(
1339 const types::subdomain_id my_subdomain)
1340 {
1341 if (cell->is_active())
1342 {
1343 if (cell->subdomain_id() == my_subdomain)
1344 {
1345 if (cell->refine_flag_set())
1346 refine_list.push_back(p4est_cell);
1347 else if (cell->coarsen_flag_set())
1348 coarsen_list.push_back(p4est_cell);
1349 }
1350 }
1351 else
1352 {
1355 for (unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
1356 ++c)
1357 switch (dim)
1358 {
1359 case 2:
1361 break;
1362 case 3:
1364 break;
1365 default:
1367 }
1369 p4est_child);
1370 for (unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
1371 ++c)
1372 {
1373 p4est_child[c].p.which_tree = p4est_cell.p.which_tree;
1374 build_lists(cell->child(c), p4est_child[c], my_subdomain);
1375 }
1376 }
1377 }
1378
1379
1380 template <int dim, int spacedim>
1381 int
1382 RefineAndCoarsenList<dim, spacedim>::refine_callback(
1383 typename internal::p4est::types<dim>::forest *forest,
1385 typename internal::p4est::types<dim>::quadrant *quadrant)
1386 {
1388 reinterpret_cast<RefineAndCoarsenList<dim, spacedim> *>(
1389 forest->user_pointer);
1390
1391 // if there are no more cells in our list the current cell can't be
1392 // flagged for refinement
1393 if (this_object->current_refine_pointer == this_object->refine_list.end())
1394 return 0;
1395
1397 this_object->current_refine_pointer->p.which_tree,
1399
1400 // if p4est hasn't yet reached the tree of the next flagged cell the
1401 // current cell can't be flagged for refinement
1402 if (coarse_cell_index < this_object->current_refine_pointer->p.which_tree)
1403 return 0;
1404
1405 // now we're in the right tree in the forest
1407 this_object->current_refine_pointer->p.which_tree,
1409
1410 // make sure that the p4est loop over cells hasn't gotten ahead of our own
1411 // pointer
1413 quadrant, &*this_object->current_refine_pointer) <= 0,
1415
1416 // now, if the p4est cell is one in the list, it is supposed to be refined
1418 quadrant, &*this_object->current_refine_pointer))
1419 {
1420 ++this_object->current_refine_pointer;
1421 return 1;
1422 }
1423
1424 // p4est cell is not in list
1425 return 0;
1426 }
1427
1428
1429
1430 template <int dim, int spacedim>
1431 int
1432 RefineAndCoarsenList<dim, spacedim>::coarsen_callback(
1433 typename internal::p4est::types<dim>::forest *forest,
1435 typename internal::p4est::types<dim>::quadrant *children[])
1436 {
1438 reinterpret_cast<RefineAndCoarsenList<dim, spacedim> *>(
1439 forest->user_pointer);
1440
1441 // if there are no more cells in our list the current cell can't be
1442 // flagged for coarsening
1443 if (this_object->current_coarsen_pointer == this_object->coarsen_list.end())
1444 return 0;
1445
1447 this_object->current_coarsen_pointer->p.which_tree,
1449
1450 // if p4est hasn't yet reached the tree of the next flagged cell the
1451 // current cell can't be flagged for coarsening
1452 if (coarse_cell_index < this_object->current_coarsen_pointer->p.which_tree)
1453 return 0;
1454
1455 // now we're in the right tree in the forest
1457 this_object->current_coarsen_pointer->p.which_tree,
1459
1460 // make sure that the p4est loop over cells hasn't gotten ahead of our own
1461 // pointer
1463 children[0], &*this_object->current_coarsen_pointer) <= 0,
1465
1466 // now, if the p4est cell is one in the list, it is supposed to be
1467 // coarsened
1469 children[0], &*this_object->current_coarsen_pointer))
1470 {
1471 // move current pointer one up
1472 ++this_object->current_coarsen_pointer;
1473
1474 // note that the next 3 cells in our list need to correspond to the
1475 // other siblings of the cell we have just found
1476 for (unsigned int c = 1; c < GeometryInfo<dim>::max_children_per_cell;
1477 ++c)
1478 {
1480 children[c], &*this_object->current_coarsen_pointer),
1482 ++this_object->current_coarsen_pointer;
1483 }
1484
1485 return 1;
1486 }
1487
1488 // p4est cell is not in list
1489 return 0;
1490 }
1491
1492
1493
1500 template <int dim, int spacedim>
1501 class PartitionWeights
1502 {
1503 public:
1509 explicit PartitionWeights(const std::vector<unsigned int> &cell_weights);
1510
1518 static int
1521 typename internal::p4est::types<dim>::quadrant *quadrant);
1522
1523 private:
1524 std::vector<unsigned int> cell_weights_list;
1525 std::vector<unsigned int>::const_iterator current_pointer;
1526 };
1527
1528
1529 template <int dim, int spacedim>
1530 PartitionWeights<dim, spacedim>::PartitionWeights(
1531 const std::vector<unsigned int> &cell_weights)
1532 : cell_weights_list(cell_weights)
1533 {
1534 // set the current pointer to the first element of the list, given that
1535 // we will walk through it sequentially
1536 current_pointer = cell_weights_list.begin();
1537 }
1538
1539
1540 template <int dim, int spacedim>
1541 int
1542 PartitionWeights<dim, spacedim>::cell_weight(
1543 typename internal::p4est::types<dim>::forest *forest,
1546 {
1547 // the function gets two additional arguments, but we don't need them
1548 // since we know in which order p4est will walk through the cells
1549 // and have already built our weight lists in this order
1550
1552 reinterpret_cast<PartitionWeights<dim, spacedim> *>(forest->user_pointer);
1553
1554 Assert(this_object->current_pointer >=
1555 this_object->cell_weights_list.begin(),
1557 Assert(this_object->current_pointer < this_object->cell_weights_list.end(),
1559
1560 // Get the weight, increment the pointer, and return the weight. Also
1561 // make sure that we don't exceed the 'int' data type that p4est uses
1562 // to represent weights
1563 const unsigned int weight = *this_object->current_pointer;
1564 ++this_object->current_pointer;
1565
1566 Assert(weight < static_cast<unsigned int>(std::numeric_limits<int>::max()),
1567 ExcMessage("p4est uses 'signed int' to represent the partition "
1568 "weights for cells. The weight provided here exceeds "
1569 "the maximum value represented as a 'signed int'."));
1570 return static_cast<int>(weight);
1571 }
1572
1573 template <int dim, int spacedim>
1574 using cell_relation_t = typename std::pair<
1575 typename ::Triangulation<dim, spacedim>::cell_iterator,
1576 CellStatus>;
1577
1587 template <int dim, int spacedim>
1588 inline void
1591 const typename ::internal::p4est::types<dim>::tree &tree,
1592 const unsigned int idx,
1594 const CellStatus status)
1595 {
1596 const unsigned int local_quadrant_index = tree.quadrants_offset + idx;
1597
1598 // check if we will be writing into valid memory
1600
1601 // store relation
1602 cell_rel[local_quadrant_index] = std::make_pair(dealii_cell, status);
1603 }
1604
1605
1606
1616 template <int dim, int spacedim>
1617 void
1620 const typename ::internal::p4est::types<dim>::tree &tree,
1622 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell)
1623 {
1624 // find index of p4est_cell in the quadrants array of the corresponding tree
1625 const int idx = sc_array_bsearch(
1626 const_cast<sc_array_t *>(&tree.quadrants),
1627 &p4est_cell,
1629 if (idx == -1 &&
1631 const_cast<typename ::internal::p4est::types<dim>::tree *>(
1632 &tree),
1633 &p4est_cell) == false))
1634 // this quadrant and none of its children belong to us.
1635 return;
1636
1637 // recurse further if both p4est and dealii still have children
1638 const bool p4est_has_children = (idx == -1);
1639 if (p4est_has_children && dealii_cell->has_children())
1640 {
1641 // recurse further
1642 typename ::internal::p4est::types<dim>::quadrant
1644
1645 for (unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
1646 ++c)
1647 switch (dim)
1648 {
1649 case 2:
1651 break;
1652 case 3:
1654 break;
1655 default:
1657 }
1658
1661
1662 for (unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
1663 ++c)
1664 {
1666 cell_rel, tree, dealii_cell->child(c), p4est_child[c]);
1667 }
1668 }
1669 else if (!p4est_has_children && !dealii_cell->has_children())
1670 {
1671 // this active cell didn't change
1672 // save pair into corresponding position
1675 }
1676 else if (p4est_has_children) // based on the conditions above, we know that
1677 // dealii_cell has no children
1678 {
1679 // this cell got refined in p4est, but the dealii_cell has not yet been
1680 // refined
1681
1682 // this quadrant is not active
1683 // generate its children, and store information in those
1684 typename ::internal::p4est::types<dim>::quadrant
1686 for (unsigned int c = 0; c < GeometryInfo<dim>::max_children_per_cell;
1687 ++c)
1688 switch (dim)
1689 {
1690 case 2:
1692 break;
1693 case 3:
1695 break;
1696 default:
1698 }
1699
1702
1703 // mark first child with CellStatus::cell_will_be_refined and the
1704 // remaining children with CellStatus::cell_invalid, but associate them
1705 // all with the parent cell unpack algorithm will be called only on
1706 // CellStatus::cell_will_be_refined flagged quadrant
1707 int child_idx;
1709 for (unsigned int i = 0; i < GeometryInfo<dim>::max_children_per_cell;
1710 ++i)
1711 {
1713 const_cast<sc_array_t *>(&tree.quadrants),
1714 &p4est_child[i],
1716
1719
1722 }
1723 }
1724 else // based on the conditions above, we know that p4est_cell has no
1725 // children, and the dealii_cell does
1726 {
1727 // its children got coarsened into this cell in p4est,
1728 // but the dealii_cell still has its children
1730 cell_rel,
1731 tree,
1732 idx,
1735 }
1736 }
1737} // namespace
1738
1739
1740
1741namespace parallel
1742{
1743 namespace distributed
1744 {
1745 /*----------------- class Triangulation<dim,spacedim> ---------------*/
1746 template <int dim, int spacedim>
1749 const MPI_Comm mpi_communicator,
1750 const typename ::Triangulation<dim, spacedim>::MeshSmoothing
1751 smooth_grid,
1752 const Settings settings)
1753 : // Do not check for distorted cells.
1754 // For multigrid, we need limit_level_difference_at_vertices
1755 // to make sure the transfer operators only need to consider two levels.
1756 ::parallel::DistributedTriangulationBase<dim, spacedim>(
1757 mpi_communicator,
1758 (settings & construct_multigrid_hierarchy) ?
1760 typename ::Triangulation<dim, spacedim>::MeshSmoothing>(
1761 smooth_grid |
1762 Triangulation<dim, spacedim>::limit_level_difference_at_vertices) :
1763 smooth_grid,
1764 false)
1765 , settings(settings)
1766 , triangulation_has_content(false)
1767 , connectivity(nullptr)
1768 , parallel_forest(nullptr)
1769 {
1770 parallel_ghost = nullptr;
1771 }
1772
1773
1774
1775 template <int dim, int spacedim>
1777 Triangulation<dim, spacedim>::~Triangulation()
1778 {
1779 // virtual functions called in constructors and destructors never use the
1780 // override in a derived class
1781 // for clarity be explicit on which function is called
1782 try
1783 {
1785 }
1786 catch (...)
1787 {}
1788
1789 AssertNothrow(triangulation_has_content == false, ExcInternalError());
1790 AssertNothrow(connectivity == nullptr, ExcInternalError());
1791 AssertNothrow(parallel_forest == nullptr, ExcInternalError());
1792 }
1793
1794
1795
1796 template <int dim, int spacedim>
1798 void Triangulation<dim, spacedim>::create_triangulation(
1799 const std::vector<Point<spacedim>> &vertices,
1800 const std::vector<CellData<dim>> &cells,
1801 const SubCellData &subcelldata)
1802 {
1803 try
1804 {
1806 vertices, cells, subcelldata);
1807 }
1808 catch (
1809 const typename ::Triangulation<dim, spacedim>::DistortedCellList
1810 &)
1811 {
1812 // the underlying triangulation should not be checking for distorted
1813 // cells
1815 }
1816
1817 Assert(
1818 this->all_reference_cells_are_hyper_cube(),
1819 ExcMessage(
1820 "The class parallel::distributed::Triangulation only supports meshes "
1821 "consisting only of hypercube-like cells."));
1822
1823 // note that now we have some content in the p4est objects and call the
1824 // functions that do the actual work (which are dimension dependent, so
1825 // separate)
1826 triangulation_has_content = true;
1827
1828 setup_coarse_cell_to_p4est_tree_permutation();
1829
1830 copy_new_triangulation_to_p4est(std::integral_constant<int, dim>());
1831
1832 try
1833 {
1834 copy_local_forest_to_triangulation();
1835 }
1836 catch (const typename Triangulation<dim>::DistortedCellList &)
1837 {
1838 // the underlying triangulation should not be checking for distorted
1839 // cells
1841 }
1842
1843 this->update_periodic_face_map();
1844 this->update_number_cache();
1845 }
1846
1847
1848
1849 template <int dim, int spacedim>
1851 void Triangulation<dim, spacedim>::create_triangulation(
1852 const TriangulationDescription::Description<dim, spacedim>
1854 {
1855 (void)construction_data;
1856
1858 }
1859
1860
1861
1862 template <int dim, int spacedim>
1864 void Triangulation<dim, spacedim>::clear()
1865 {
1866 triangulation_has_content = false;
1867
1868 if (parallel_ghost != nullptr)
1869 {
1871 parallel_ghost);
1872 parallel_ghost = nullptr;
1873 }
1874
1875 if (parallel_forest != nullptr)
1876 {
1878 parallel_forest = nullptr;
1879 }
1880
1881 if (connectivity != nullptr)
1882 {
1884 connectivity);
1885 connectivity = nullptr;
1886 }
1887
1888 coarse_cell_to_p4est_tree_permutation.resize(0);
1889 p4est_tree_to_coarse_cell_permutation.resize(0);
1890
1892
1893 this->update_number_cache();
1894 }
1895
1896
1897
1898 template <int dim, int spacedim>
1900 bool Triangulation<dim, spacedim>::is_multilevel_hierarchy_constructed()
1901 const
1902 {
1903 return settings &
1905 }
1906
1907
1908
1909 template <int dim, int spacedim>
1911 bool Triangulation<dim, spacedim>::are_vertices_communicated_to_p4est()
1912 const
1913 {
1914 return settings &
1916 }
1917
1918
1919
1920 template <int dim, int spacedim>
1922 void Triangulation<dim, spacedim>::execute_transfer(
1923 const typename ::internal::p4est::types<dim>::forest
1924 *parallel_forest,
1925 const typename ::internal::p4est::types<dim>::gloidx
1927 {
1928 Assert(this->data_serializer.sizes_fixed_cumulative.size() > 0,
1929 ExcMessage("No data has been packed!"));
1930
1931 // Resize memory according to the data that we will receive.
1932 this->data_serializer.dest_data_fixed.resize(
1933 parallel_forest->local_num_quadrants *
1934 this->data_serializer.sizes_fixed_cumulative.back());
1935
1936 // Execute non-blocking fixed size transfer.
1937 typename ::internal::p4est::types<dim>::transfer_context
1938 *tf_context;
1939 tf_context =
1941 parallel_forest->global_first_quadrant,
1943 parallel_forest->mpicomm,
1944 0,
1945 this->data_serializer.dest_data_fixed.data(),
1946 this->data_serializer.src_data_fixed.data(),
1947 this->data_serializer.sizes_fixed_cumulative.back());
1948
1949 if (this->data_serializer.variable_size_data_stored)
1950 {
1951 // Resize memory according to the data that we will receive.
1952 this->data_serializer.dest_sizes_variable.resize(
1953 parallel_forest->local_num_quadrants);
1954
1955 // Execute fixed size transfer of data sizes for variable size
1956 // transfer.
1958 parallel_forest->global_first_quadrant,
1960 parallel_forest->mpicomm,
1961 1,
1962 this->data_serializer.dest_sizes_variable.data(),
1963 this->data_serializer.src_sizes_variable.data(),
1964 sizeof(unsigned int));
1965 }
1966
1968
1969 // Release memory of previously packed data.
1970 this->data_serializer.src_data_fixed.clear();
1971 this->data_serializer.src_data_fixed.shrink_to_fit();
1972
1973 if (this->data_serializer.variable_size_data_stored)
1974 {
1975 // Resize memory according to the data that we will receive.
1976 this->data_serializer.dest_data_variable.resize(
1977 std::accumulate(this->data_serializer.dest_sizes_variable.begin(),
1978 this->data_serializer.dest_sizes_variable.end(),
1979 std::vector<int>::size_type(0)));
1980
1981# if DEAL_II_P4EST_VERSION_GTE(2, 0, 65, 0)
1982# else
1983 // ----- WORKAROUND -----
1984 // An assertion in p4est prevents us from sending/receiving no data
1985 // at all, which is mandatory if one of our processes does not own
1986 // any quadrant. This bypasses the assertion from being triggered.
1987 // - see: https://github.com/cburstedde/p4est/issues/48
1988 if (this->data_serializer.src_sizes_variable.empty())
1989 this->data_serializer.src_sizes_variable.resize(1);
1990 if (this->data_serializer.dest_sizes_variable.empty())
1991 this->data_serializer.dest_sizes_variable.resize(1);
1992# endif
1993
1994 // Execute variable size transfer.
1996 parallel_forest->global_first_quadrant,
1998 parallel_forest->mpicomm,
1999 1,
2000 this->data_serializer.dest_data_variable.data(),
2001 this->data_serializer.dest_sizes_variable.data(),
2002 this->data_serializer.src_data_variable.data(),
2003 this->data_serializer.src_sizes_variable.data());
2004
2005 // Release memory of previously packed data.
2006 this->data_serializer.src_sizes_variable.clear();
2007 this->data_serializer.src_sizes_variable.shrink_to_fit();
2008 this->data_serializer.src_data_variable.clear();
2009 this->data_serializer.src_data_variable.shrink_to_fit();
2010 }
2011 }
2012
2013
2014
2015 template <int dim, int spacedim>
2017 void Triangulation<dim,
2018 spacedim>::setup_coarse_cell_to_p4est_tree_permutation()
2019 {
2023 coarse_cell_to_p4est_tree_permutation.resize(this->n_cells(0));
2025 cell_connectivity, coarse_cell_to_p4est_tree_permutation);
2026
2027 p4est_tree_to_coarse_cell_permutation =
2028 Utilities::invert_permutation(coarse_cell_to_p4est_tree_permutation);
2029 }
2030
2031
2032
2033 template <int dim, int spacedim>
2035 void Triangulation<dim, spacedim>::write_mesh_vtk(
2036 const std::string &file_basename) const
2037 {
2038 Assert(parallel_forest != nullptr,
2039 ExcMessage("Can't produce output when no forest is created yet."));
2040
2041 AssertThrow(are_vertices_communicated_to_p4est(),
2042 ExcMessage(
2043 "To use this function the triangulation's flag "
2044 "Settings::communicate_vertices_to_p4est must be set."));
2045
2047 parallel_forest, nullptr, file_basename.c_str());
2048 }
2049
2050
2051
2052 template <int dim, int spacedim>
2054 void Triangulation<dim, spacedim>::save(const std::string &filename) const
2055 {
2056 Assert(
2057 this->cell_attached_data.n_attached_deserialize == 0,
2058 ExcMessage(
2059 "Not all SolutionTransfer objects have been deserialized after the last call to load()."));
2060 Assert(this->n_cells() > 0,
2061 ExcMessage("Can not save() an empty Triangulation."));
2062
2063 const int myrank =
2064 Utilities::MPI::this_mpi_process(this->mpi_communicator);
2065
2066 // signal that serialization is going to happen
2067 this->signals.pre_distributed_save();
2068
2069 if (this->my_subdomain == 0)
2070 {
2071 std::string fname = std::string(filename) + ".info";
2072 std::ofstream f(fname);
2073 f << "version nproc n_attached_fixed_size_objs n_attached_variable_size_objs n_coarse_cells"
2074 << std::endl
2075 << 5 << " "
2076 << Utilities::MPI::n_mpi_processes(this->mpi_communicator) << " "
2077 << this->cell_attached_data.pack_callbacks_fixed.size() << " "
2078 << this->cell_attached_data.pack_callbacks_variable.size() << " "
2079 << this->n_cells(0) << std::endl;
2080 }
2081
2082 // each cell should have been flagged `CellStatus::cell_will_persist`
2083 for (const auto &cell_rel : this->local_cell_relations)
2084 {
2085 (void)cell_rel;
2086 Assert((cell_rel.second == // cell_status
2089 }
2090
2091 // Save cell attached data.
2092 this->save_attached_data(parallel_forest->global_first_quadrant[myrank],
2093 parallel_forest->global_num_quadrants,
2094 filename);
2095
2097 parallel_forest,
2098 false);
2099
2100 // signal that serialization has finished
2101 this->signals.post_distributed_save();
2102 }
2103
2104
2105
2106 template <int dim, int spacedim>
2108 void Triangulation<dim, spacedim>::load(const std::string &filename)
2109 {
2110 Assert(
2111 this->n_cells() > 0,
2112 ExcMessage(
2113 "load() only works if the Triangulation already contains a coarse mesh!"));
2114 Assert(
2115 this->n_levels() == 1,
2116 ExcMessage(
2117 "Triangulation may only contain coarse cells when calling load()."));
2118
2119 const int myrank =
2120 Utilities::MPI::this_mpi_process(this->mpi_communicator);
2121
2122 // signal that de-serialization is going to happen
2123 this->signals.pre_distributed_load();
2124
2125 if (parallel_ghost != nullptr)
2126 {
2128 parallel_ghost);
2129 parallel_ghost = nullptr;
2130 }
2132 parallel_forest = nullptr;
2134 connectivity);
2135 connectivity = nullptr;
2136
2137 unsigned int version, numcpus, attached_count_fixed,
2138 attached_count_variable, n_coarse_cells;
2139 {
2140 std::string fname = std::string(filename) + ".info";
2141 std::ifstream f(fname);
2142 AssertThrow(f.fail() == false, ExcIO());
2143 std::string firstline;
2144 getline(f, firstline); // skip first line
2145 f >> version >> numcpus >> attached_count_fixed >>
2146 attached_count_variable >> n_coarse_cells;
2147 }
2148
2149 AssertThrow(version == 5,
2150 ExcMessage("Incompatible version found in .info file."));
2151 Assert(this->n_cells(0) == n_coarse_cells,
2152 ExcMessage("Number of coarse cells differ!"));
2153
2154 // clear all of the callback data, as explained in the documentation of
2155 // register_data_attach()
2156 this->cell_attached_data.n_attached_data_sets = 0;
2157 this->cell_attached_data.n_attached_deserialize =
2159
2161 filename.c_str(),
2162 this->mpi_communicator,
2163 0,
2164 0,
2165 1,
2166 0,
2167 this,
2168 &connectivity);
2169
2170 // We partition the p4est mesh that it conforms to the requirements of the
2171 // deal.II mesh, i.e., partition for coarsening.
2172 // This function call is optional.
2174 parallel_forest,
2175 /* prepare coarsening */ 1,
2176 /* weight_callback */ nullptr);
2177
2178 try
2179 {
2180 copy_local_forest_to_triangulation();
2181 }
2182 catch (const typename Triangulation<dim>::DistortedCellList &)
2183 {
2184 // the underlying triangulation should not be checking for distorted
2185 // cells
2187 }
2188
2189 // Load attached cell data, if any was stored.
2190 this->load_attached_data(parallel_forest->global_first_quadrant[myrank],
2191 parallel_forest->global_num_quadrants,
2192 parallel_forest->local_num_quadrants,
2193 filename,
2196
2197 // signal that de-serialization is finished
2198 this->signals.post_distributed_load();
2199
2200 this->update_periodic_face_map();
2201 this->update_number_cache();
2202 }
2203
2204
2205
2206 template <int dim, int spacedim>
2208 void Triangulation<dim, spacedim>::load(const std::string &filename,
2209 const bool autopartition)
2210 {
2211 (void)autopartition;
2212 load(filename);
2213 }
2214
2215
2216
2217 template <int dim, int spacedim>
2219 void Triangulation<dim, spacedim>::load(
2220 const typename ::internal::p4est::types<dim>::forest *forest)
2221 {
2222 Assert(this->n_cells() > 0,
2223 ExcMessage(
2224 "load() only works if the Triangulation already contains "
2225 "a coarse mesh!"));
2226 Assert(this->n_cells() == forest->trees->elem_count,
2227 ExcMessage(
2228 "Coarse mesh of the Triangulation does not match the one "
2229 "of the provided forest!"));
2230
2231 // clear the old forest
2232 if (parallel_ghost != nullptr)
2233 {
2235 parallel_ghost);
2236 parallel_ghost = nullptr;
2237 }
2239 parallel_forest = nullptr;
2240
2241 // note: we can keep the connectivity, since the coarse grid does not
2242 // change
2243
2244 // create deep copy of the new forest
2245 typename ::internal::p4est::types<dim>::forest *temp =
2246 const_cast<typename ::internal::p4est::types<dim>::forest *>(
2247 forest);
2248 parallel_forest =
2250 parallel_forest->connectivity = connectivity;
2251 parallel_forest->user_pointer = this;
2252
2253 try
2254 {
2255 copy_local_forest_to_triangulation();
2256 }
2257 catch (const typename Triangulation<dim>::DistortedCellList &)
2258 {
2259 // the underlying triangulation should not be checking for distorted
2260 // cells
2262 }
2263
2264 this->update_periodic_face_map();
2265 this->update_number_cache();
2266 }
2267
2268
2269
2270 template <int dim, int spacedim>
2272 unsigned int Triangulation<dim, spacedim>::get_checksum() const
2273 {
2274 Assert(parallel_forest != nullptr,
2275 ExcMessage(
2276 "Can't produce a check sum when no forest is created yet."));
2277 return ::internal::p4est::functions<dim>::checksum(parallel_forest);
2278 }
2279
2280
2281
2282 template <int dim, int spacedim>
2284 const typename ::internal::p4est::types<dim>::forest
2286 {
2287 Assert(parallel_forest != nullptr,
2288 ExcMessage("The forest has not been allocated yet."));
2289 return parallel_forest;
2290 }
2291
2292
2293
2294 template <int dim, int spacedim>
2296 typename ::internal::p4est::types<dim>::tree
2298 const int dealii_coarse_cell_index) const
2299 {
2300 const unsigned int tree_index =
2301 coarse_cell_to_p4est_tree_permutation[dealii_coarse_cell_index];
2302 typename ::internal::p4est::types<dim>::tree *tree =
2303 static_cast<typename ::internal::p4est::types<dim>::tree *>(
2304 sc_array_index(parallel_forest->trees, tree_index));
2305
2306 return tree;
2307 }
2308
2309
2310
2311 // Note: this has been added here to prevent that these functions
2312 // appear in the Doxygen documentation of ::Triangulation
2313# ifndef DOXYGEN
2314
2315 template <>
2316 void
2318 std::integral_constant<int, 2>)
2319 {
2320 const unsigned int dim = 2, spacedim = 2;
2321 Assert(this->n_cells(0) > 0, ExcInternalError());
2322 Assert(this->n_levels() == 1, ExcInternalError());
2323
2324 // data structures that counts how many cells touch each vertex
2325 // (vertex_touch_count), and which cells touch a given vertex (together
2326 // with the local numbering of that vertex within the cells that touch
2327 // it)
2328 std::vector<unsigned int> vertex_touch_count;
2329 std::vector<
2330 std::list<std::pair<Triangulation<dim, spacedim>::active_cell_iterator,
2331 unsigned int>>>
2334 const ::internal::p4est::types<2>::locidx num_vtt =
2335 std::accumulate(vertex_touch_count.begin(),
2336 vertex_touch_count.end(),
2337 0u);
2338
2339 // now create a connectivity object with the right sizes for all
2340 // arrays. set vertex information only in debug mode (saves a few bytes
2341 // in optimized mode)
2342 const bool set_vertex_info = this->are_vertices_communicated_to_p4est();
2343
2345 (set_vertex_info == true ? this->n_vertices() : 0),
2346 this->n_cells(0),
2347 this->n_vertices(),
2348 num_vtt);
2349
2353 coarse_cell_to_p4est_tree_permutation,
2355 connectivity);
2356
2357 Assert(p4est_connectivity_is_valid(connectivity) == 1,
2359
2360 // now create a forest out of the connectivity data structure
2362 this->mpi_communicator,
2363 connectivity,
2364 /* minimum initial number of quadrants per tree */ 0,
2365 /* minimum level of upfront refinement */ 0,
2366 /* use uniform upfront refinement */ 1,
2367 /* user_data_size = */ 0,
2368 /* user_data_constructor = */ nullptr,
2369 /* user_pointer */ this);
2370 }
2371
2372
2373
2374 // TODO: This is a verbatim copy of the 2,2 case. However, we can't just
2375 // specialize the dim template argument, but let spacedim open
2376 template <>
2377 void
2379 std::integral_constant<int, 2>)
2380 {
2381 const unsigned int dim = 2, spacedim = 3;
2382 Assert(this->n_cells(0) > 0, ExcInternalError());
2383 Assert(this->n_levels() == 1, ExcInternalError());
2384
2385 // data structures that counts how many cells touch each vertex
2386 // (vertex_touch_count), and which cells touch a given vertex (together
2387 // with the local numbering of that vertex within the cells that touch
2388 // it)
2389 std::vector<unsigned int> vertex_touch_count;
2390 std::vector<
2391 std::list<std::pair<Triangulation<dim, spacedim>::active_cell_iterator,
2392 unsigned int>>>
2395 const ::internal::p4est::types<2>::locidx num_vtt =
2396 std::accumulate(vertex_touch_count.begin(),
2397 vertex_touch_count.end(),
2398 0u);
2399
2400 // now create a connectivity object with the right sizes for all
2401 // arrays. set vertex information only in debug mode (saves a few bytes
2402 // in optimized mode)
2403 const bool set_vertex_info = this->are_vertices_communicated_to_p4est();
2404
2406 (set_vertex_info == true ? this->n_vertices() : 0),
2407 this->n_cells(0),
2408 this->n_vertices(),
2409 num_vtt);
2410
2414 coarse_cell_to_p4est_tree_permutation,
2416 connectivity);
2417
2418 Assert(p4est_connectivity_is_valid(connectivity) == 1,
2420
2421 // now create a forest out of the connectivity data structure
2423 this->mpi_communicator,
2424 connectivity,
2425 /* minimum initial number of quadrants per tree */ 0,
2426 /* minimum level of upfront refinement */ 0,
2427 /* use uniform upfront refinement */ 1,
2428 /* user_data_size = */ 0,
2429 /* user_data_constructor = */ nullptr,
2430 /* user_pointer */ this);
2431 }
2432
2433
2434
2435 template <>
2436 void
2438 std::integral_constant<int, 3>)
2439 {
2440 const int dim = 3, spacedim = 3;
2441 Assert(this->n_cells(0) > 0, ExcInternalError());
2442 Assert(this->n_levels() == 1, ExcInternalError());
2443
2444 // data structures that counts how many cells touch each vertex
2445 // (vertex_touch_count), and which cells touch a given vertex (together
2446 // with the local numbering of that vertex within the cells that touch
2447 // it)
2448 std::vector<unsigned int> vertex_touch_count;
2449 std::vector<std::list<
2450 std::pair<Triangulation<3>::active_cell_iterator, unsigned int>>>
2453 const ::internal::p4est::types<2>::locidx num_vtt =
2454 std::accumulate(vertex_touch_count.begin(),
2455 vertex_touch_count.end(),
2456 0u);
2457
2458 std::vector<unsigned int> edge_touch_count;
2459 std::vector<std::list<
2460 std::pair<Triangulation<3>::active_cell_iterator, unsigned int>>>
2463 const ::internal::p4est::types<2>::locidx num_ett =
2464 std::accumulate(edge_touch_count.begin(), edge_touch_count.end(), 0u);
2465
2466 // now create a connectivity object with the right sizes for all arrays
2467 const bool set_vertex_info = this->are_vertices_communicated_to_p4est();
2468
2470 (set_vertex_info == true ? this->n_vertices() : 0),
2471 this->n_cells(0),
2472 this->n_active_lines(),
2473 num_ett,
2474 this->n_vertices(),
2475 num_vtt);
2476
2480 coarse_cell_to_p4est_tree_permutation,
2482 connectivity);
2483
2484 // next to tree-to-edge
2485 // data. note that in p4est lines
2486 // are ordered as follows
2487 // *---3---* *---3---*
2488 // /| | / /|
2489 // 6 | 11 6 7 11
2490 // / 10 | / / |
2491 // * | | *---2---* |
2492 // | *---1---* | | *
2493 // | / / | 9 /
2494 // 8 4 5 8 | 5
2495 // |/ / | |/
2496 // *---0---* *---0---*
2497 // whereas in deal.II they are like this:
2498 // *---7---* *---7---*
2499 // /| | / /|
2500 // 4 | 11 4 5 11
2501 // / 10 | / / |
2502 // * | | *---6---* |
2503 // | *---3---* | | *
2504 // | / / | 9 /
2505 // 8 0 1 8 | 1
2506 // |/ / | |/
2507 // *---2---* *---2---*
2508
2509 const unsigned int deal_to_p4est_line_index[12] = {
2510 4, 5, 0, 1, 6, 7, 2, 3, 8, 9, 10, 11};
2511
2513 this->begin_active();
2514 cell != this->end();
2515 ++cell)
2516 {
2517 const unsigned int index =
2518 coarse_cell_to_p4est_tree_permutation[cell->index()];
2519 for (unsigned int e = 0; e < GeometryInfo<3>::lines_per_cell; ++e)
2520 connectivity->tree_to_edge[index * GeometryInfo<3>::lines_per_cell +
2522 cell->line(e)->index();
2523 }
2524
2525 // now also set edge-to-tree
2526 // information
2527 connectivity->ett_offset[0] = 0;
2528 std::partial_sum(edge_touch_count.begin(),
2529 edge_touch_count.end(),
2530 &connectivity->ett_offset[1]);
2531
2532 Assert(connectivity->ett_offset[this->n_active_lines()] == num_ett,
2534
2535 for (unsigned int v = 0; v < this->n_active_lines(); ++v)
2536 {
2537 Assert(edge_to_cell[v].size() == edge_touch_count[v],
2539
2540 std::list<
2541 std::pair<Triangulation<dim, spacedim>::active_cell_iterator,
2542 unsigned int>>::const_iterator p =
2543 edge_to_cell[v].begin();
2544 for (unsigned int c = 0; c < edge_touch_count[v]; ++c, ++p)
2545 {
2546 connectivity->edge_to_tree[connectivity->ett_offset[v] + c] =
2547 coarse_cell_to_p4est_tree_permutation[p->first->index()];
2548 connectivity->edge_to_edge[connectivity->ett_offset[v] + c] =
2549 deal_to_p4est_line_index[p->second];
2550 }
2551 }
2552
2553 Assert(p8est_connectivity_is_valid(connectivity) == 1,
2555
2556 // now create a forest out of the connectivity data structure
2558 this->mpi_communicator,
2559 connectivity,
2560 /* minimum initial number of quadrants per tree */ 0,
2561 /* minimum level of upfront refinement */ 0,
2562 /* use uniform upfront refinement */ 1,
2563 /* user_data_size = */ 0,
2564 /* user_data_constructor = */ nullptr,
2565 /* user_pointer */ this);
2566 }
2567# endif
2568
2569
2570
2571 namespace
2572 {
2573 // ensures the 2:1 mesh balance for periodic boundary conditions in the
2574 // artificial cell layer (the active cells are taken care of by p4est)
2575 template <int dim, int spacedim>
2576 bool
2579 {
2580 if (tria.get_periodic_face_map().empty())
2581 return false;
2582
2583 std::vector<bool> flags_before[2];
2586
2587 std::vector<unsigned int> topological_vertex_numbering(
2588 tria.n_vertices());
2589 for (unsigned int i = 0; i < topological_vertex_numbering.size(); ++i)
2591 // combine vertices that have different locations (and thus, different
2592 // vertex_index) but represent the same topological entity over
2593 // periodic boundaries. The vector topological_vertex_numbering
2594 // contains a linear map from 0 to n_vertices at input and at output
2595 // relates periodic vertices with only one vertex index. The output is
2596 // used to always identify the same vertex according to the
2597 // periodicity, e.g. when finding the maximum cell level around a
2598 // vertex.
2599 //
2600 // Example: On a 3d cell with vertices numbered from 0 to 7 and
2601 // periodic boundary conditions in x direction, the vector
2602 // topological_vertex_numbering will contain the numbers
2603 // {0,0,2,2,4,4,6,6} (because the vertex pairs {0,1}, {2,3}, {4,5},
2604 // {6,7} belong together, respectively). If periodicity is set in x
2605 // and z direction, the output is {0,0,2,2,0,0,2,2}, and if
2606 // periodicity is in all directions, the output is simply
2607 // {0,0,0,0,0,0,0,0}.
2608 using cell_iterator =
2610 typename std::map<std::pair<cell_iterator, unsigned int>,
2611 std::pair<std::pair<cell_iterator, unsigned int>,
2612 unsigned char>>::const_iterator it;
2613 for (it = tria.get_periodic_face_map().begin();
2614 it != tria.get_periodic_face_map().end();
2615 ++it)
2616 {
2617 const cell_iterator &cell_1 = it->first.first;
2618 const unsigned int face_no_1 = it->first.second;
2619 const cell_iterator &cell_2 = it->second.first.first;
2620 const unsigned int face_no_2 = it->second.first.second;
2621 const unsigned char combined_orientation = it->second.second;
2622 const auto [orientation, rotation, flip] =
2624
2625 if (cell_1->level() == cell_2->level())
2626 {
2627 for (unsigned int v = 0;
2628 v < GeometryInfo<dim - 1>::vertices_per_cell;
2629 ++v)
2630 {
2631 // take possible non-standard orientation of face on
2632 // cell[0] into account
2633 const unsigned int vface0 =
2635 v, orientation, flip, rotation);
2636 const unsigned int vi0 =
2638 ->vertex_index(vface0)];
2639 const unsigned int vi1 =
2641 ->vertex_index(v)];
2642 const unsigned int min_index = std::min(vi0, vi1);
2644 ->vertex_index(vface0)] =
2646 ->vertex_index(v)] =
2647 min_index;
2648 }
2649 }
2650 }
2651
2652 // There must not be any chains!
2653 for (unsigned int i = 0; i < topological_vertex_numbering.size(); ++i)
2654 {
2655 const unsigned int j = topological_vertex_numbering[i];
2656 if (j != i)
2658 }
2659
2660
2661 // this code is replicated from grid/tria.cc but using an indirection
2662 // for periodic boundary conditions
2663 bool continue_iterating = true;
2664 std::vector<int> vertex_level(tria.n_vertices());
2665 while (continue_iterating)
2666 {
2667 // store highest level one of the cells adjacent to a vertex
2668 // belongs to
2669 std::fill(vertex_level.begin(), vertex_level.end(), 0);
2671 cell = tria.begin_active(),
2672 endc = tria.end();
2673 for (; cell != endc; ++cell)
2674 {
2675 if (cell->refine_flag_set())
2676 for (const unsigned int vertex :
2679 [cell->vertex_index(vertex)]] =
2681 [cell->vertex_index(vertex)]],
2682 cell->level() + 1);
2683 else if (!cell->coarsen_flag_set())
2684 for (const unsigned int vertex :
2687 [cell->vertex_index(vertex)]] =
2689 [cell->vertex_index(vertex)]],
2690 cell->level());
2691 else
2692 {
2693 // if coarsen flag is set then tentatively assume
2694 // that the cell will be coarsened. this isn't
2695 // always true (the coarsen flag could be removed
2696 // again) and so we may make an error here. we try
2697 // to correct this by iterating over the entire
2698 // process until we are converged
2699 Assert(cell->coarsen_flag_set(), ExcInternalError());
2700 for (const unsigned int vertex :
2703 [cell->vertex_index(vertex)]] =
2705 [cell->vertex_index(vertex)]],
2706 cell->level() - 1);
2707 }
2708 }
2709
2710 continue_iterating = false;
2711
2712 // loop over all cells in reverse order. do so because we
2713 // can then update the vertex levels on the adjacent
2714 // vertices and maybe already flag additional cells in this
2715 // loop
2716 //
2717 // note that not only may we have to add additional
2718 // refinement flags, but we will also have to remove
2719 // coarsening flags on cells adjacent to vertices that will
2720 // see refinement
2721 for (cell = tria.last_active(); cell != endc; --cell)
2722 if (cell->refine_flag_set() == false)
2723 {
2724 for (const unsigned int vertex :
2727 [cell->vertex_index(vertex)]] >=
2728 cell->level() + 1)
2729 {
2730 // remove coarsen flag...
2731 cell->clear_coarsen_flag();
2732
2733 // ...and if necessary also refine the current
2734 // cell, at the same time updating the level
2735 // information about vertices
2737 [cell->vertex_index(vertex)]] >
2738 cell->level() + 1)
2739 {
2740 cell->set_refine_flag();
2741 continue_iterating = true;
2742
2743 for (const unsigned int v :
2746 [cell->vertex_index(v)]] =
2747 std::max(
2749 [cell->vertex_index(v)]],
2750 cell->level() + 1);
2751 }
2752
2753 // continue and see whether we may, for example,
2754 // go into the inner 'if' above based on a
2755 // different vertex
2756 }
2757 }
2758
2759 // clear coarsen flag if not all children were marked
2760 for (const auto &cell : tria.cell_iterators())
2761 {
2762 // nothing to do if we are already on the finest level
2763 if (cell->is_active())
2764 continue;
2765
2766 const unsigned int n_children = cell->n_children();
2767 unsigned int flagged_children = 0;
2768 for (unsigned int child = 0; child < n_children; ++child)
2769 if (cell->child(child)->is_active() &&
2770 cell->child(child)->coarsen_flag_set())
2772
2773 // if not all children were flagged for coarsening, remove
2774 // coarsen flags
2775 if (flagged_children < n_children)
2776 for (unsigned int child = 0; child < n_children; ++child)
2777 if (cell->child(child)->is_active())
2778 cell->child(child)->clear_coarsen_flag();
2779 }
2780 }
2781 std::vector<bool> flags_after[2];
2784 return ((flags_before[0] != flags_after[0]) ||
2785 (flags_before[1] != flags_after[1]));
2786 }
2787 } // namespace
2788
2789
2790
2791 template <int dim, int spacedim>
2793 bool Triangulation<dim, spacedim>::prepare_coarsening_and_refinement()
2794 {
2795 // First exchange coarsen/refinement flags on ghost cells. After this
2796 // collective communication call all flags on ghost cells match the
2797 // flags set by the user on the owning rank.
2800
2801 // Now we can call the sequential version to apply mesh smoothing and
2802 // other modifications:
2805 return any_changes;
2806 }
2807
2808
2809
2810 template <int dim, int spacedim>
2812 void Triangulation<dim, spacedim>::copy_local_forest_to_triangulation()
2813 {
2814 // Disable mesh smoothing for recreating the deal.II triangulation,
2815 // otherwise we might not be able to reproduce the p4est mesh
2816 // exactly. We restore the original smoothing at the end of this
2817 // function. Note that the smoothing flag is used in the normal
2818 // refinement process.
2820 this->smooth_grid;
2821
2822 // We will refine manually to match the p4est further down, which
2823 // obeys a level difference of 2 at each vertex (see the balance call
2824 // to p4est). We can disable this here so we store fewer artificial
2825 // cells (in some cases).
2826 // For geometric multigrid it turns out that
2827 // we will miss level cells at shared vertices if we ignore this.
2828 // See tests/mpi/mg_06. In particular, the flag is still necessary
2829 // even though we force it for the original smooth_grid in the
2830 // constructor.
2831 if (settings & construct_multigrid_hierarchy)
2832 this->smooth_grid =
2833 ::Triangulation<dim,
2834 spacedim>::limit_level_difference_at_vertices;
2835 else
2836 this->smooth_grid = ::Triangulation<dim, spacedim>::none;
2837
2838 bool mesh_changed = false;
2839
2840 // Remove all deal.II refinements. Note that we could skip this and
2841 // start from our current state, because the algorithm later coarsens as
2842 // necessary. This has the advantage of being faster when large parts
2843 // of the local partition changes (likely) and gives a deterministic
2844 // ordering of the cells (useful for snapshot/resume).
2845 // TODO: is there a more efficient way to do this?
2846 if (settings & mesh_reconstruction_after_repartitioning)
2847 while (this->n_levels() > 1)
2848 {
2849 // Instead of marking all active cells, we slice off the finest
2850 // level, one level at a time. This takes the same number of
2851 // iterations but solves an issue where not all cells on a
2852 // periodic boundary are indeed coarsened and we run into an
2853 // irrelevant Assert() in update_periodic_face_map().
2854 for (const auto &cell :
2855 this->active_cell_iterators_on_level(this->n_levels() - 1))
2856 {
2857 cell->set_coarsen_flag();
2858 }
2859 try
2860 {
2863 }
2864 catch (
2866 {
2867 // the underlying triangulation should not be checking for
2868 // distorted cells
2870 }
2871 }
2872
2873
2874 // query p4est for the ghost cells
2875 if (parallel_ghost != nullptr)
2876 {
2878 parallel_ghost);
2879 parallel_ghost = nullptr;
2880 }
2882 parallel_forest,
2883 (dim == 2 ? typename ::internal::p4est::types<dim>::balance_type(
2885 typename ::internal::p4est::types<dim>::balance_type(
2887
2888 Assert(parallel_ghost, ExcInternalError());
2889
2890
2891 // set all cells to artificial. we will later set it to the correct
2892 // subdomain in match_tree_recursively
2893 for (const auto &cell : this->cell_iterators_on_level(0))
2894 cell->recursively_set_subdomain_id(numbers::artificial_subdomain_id);
2895
2896 do
2897 {
2898 for (const auto &cell : this->cell_iterators_on_level(0))
2899 {
2900 // if this processor stores no part of the forest that comes out
2901 // of this coarse grid cell, then we need to delete all children
2902 // of this cell (the coarse grid cell remains)
2904 parallel_forest,
2905 coarse_cell_to_p4est_tree_permutation[cell->index()]) ==
2906 false)
2907 {
2909 if (cell->is_active())
2910 cell->set_subdomain_id(numbers::artificial_subdomain_id);
2911 }
2912
2913 else
2914 {
2915 // this processor stores at least a part of the tree that
2916 // comes out of this cell.
2917
2918 typename ::internal::p4est::types<dim>::quadrant
2920 typename ::internal::p4est::types<dim>::tree *tree =
2921 init_tree(cell->index());
2922
2923 ::internal::p4est::init_coarse_quadrant<dim>(
2925
2927 cell,
2929 *parallel_forest,
2930 this->my_subdomain);
2931 }
2932 }
2933
2934 // check mesh for ghost cells, refine as necessary. iterate over
2935 // every ghostquadrant, find corresponding deal coarsecell and
2936 // recurse.
2937 typename ::internal::p4est::types<dim>::quadrant *quadr;
2939 typename ::internal::p4est::types<dim>::topidx ghost_tree = 0;
2940
2941 for (unsigned int g_idx = 0;
2942 g_idx < parallel_ghost->ghosts.elem_count;
2943 ++g_idx)
2944 {
2945 while (g_idx >= static_cast<unsigned int>(
2946 parallel_ghost->proc_offsets[ghost_owner + 1]))
2947 ++ghost_owner;
2948 while (g_idx >= static_cast<unsigned int>(
2949 parallel_ghost->tree_offsets[ghost_tree + 1]))
2950 ++ghost_tree;
2951
2952 quadr = static_cast<
2953 typename ::internal::p4est::types<dim>::quadrant *>(
2954 sc_array_index(&parallel_ghost->ghosts, g_idx));
2955
2956 unsigned int coarse_cell_index =
2957 p4est_tree_to_coarse_cell_permutation[ghost_tree];
2958
2961 *quadr,
2962 ghost_owner);
2963 }
2964
2965 // Fix all the flags to make sure we have a consistent local
2966 // mesh. For some reason periodic boundaries involving artificial
2967 // cells are not obeying the 2:1 ratio that we require (and that is
2968 // enforced by p4est between active cells). So, here we will loop
2969 // refining across periodic boundaries until 2:1 is satisfied. Note
2970 // that we are using the base class (sequential) prepare and execute
2971 // calls here, not involving communication, because we are only
2972 // trying to recreate a local triangulation from the p4est data.
2973 {
2974 bool mesh_changed = true;
2975 unsigned int loop_counter = 0;
2976
2977 do
2978 {
2981
2982 this->update_periodic_face_map();
2983
2984 mesh_changed =
2986
2987 // We can't be sure that we won't run into a situation where we
2988 // can not reconcile mesh smoothing and balancing of periodic
2989 // faces. As we don't know what else to do, at least abort with
2990 // an error message.
2991 ++loop_counter;
2992
2994 loop_counter < 32,
2995 ExcMessage(
2996 "Infinite loop in "
2997 "parallel::distributed::Triangulation::copy_local_forest_to_triangulation() "
2998 "for periodic boundaries detected. Aborting."));
2999 }
3000 while (mesh_changed);
3001 }
3002
3003 // see if any flags are still set
3004 mesh_changed =
3005 std::any_of(this->begin_active(),
3006 active_cell_iterator{this->end()},
3007 [](const CellAccessor<dim, spacedim> &cell) {
3008 return cell.refine_flag_set() ||
3009 cell.coarsen_flag_set();
3010 });
3011
3012 // actually do the refinement to change the local mesh by
3013 // calling the base class refinement function directly
3014 try
3015 {
3018 }
3019 catch (
3021 {
3022 // the underlying triangulation should not be checking for
3023 // distorted cells
3025 }
3026 }
3027 while (mesh_changed);
3028
3029# ifdef DEBUG
3030 // check if correct number of ghosts is created
3031 unsigned int num_ghosts = 0;
3032
3033 for (const auto &cell : this->active_cell_iterators())
3034 {
3035 if (cell->subdomain_id() != this->my_subdomain &&
3036 cell->subdomain_id() != numbers::artificial_subdomain_id)
3037 ++num_ghosts;
3038 }
3039
3040 Assert(num_ghosts == parallel_ghost->ghosts.elem_count,
3042# endif
3043
3044
3045
3046 // fill level_subdomain_ids for geometric multigrid
3047 // the level ownership of a cell is defined as the owner if the cell is
3048 // active or as the owner of child(0) we need this information for all
3049 // our ancestors and the same-level neighbors of our own cells (=level
3050 // ghosts)
3051 if (settings & construct_multigrid_hierarchy)
3052 {
3053 // step 1: We set our own ids all the way down and all the others to
3054 // -1. Note that we do not fill other cells we could figure out the
3055 // same way, because we might accidentally set an id for a cell that
3056 // is not a ghost cell.
3057 for (unsigned int lvl = this->n_levels(); lvl > 0;)
3058 {
3059 --lvl;
3060 for (const auto &cell : this->cell_iterators_on_level(lvl))
3061 {
3062 if ((cell->is_active() &&
3063 cell->subdomain_id() ==
3064 this->locally_owned_subdomain()) ||
3065 (cell->has_children() &&
3066 cell->child(0)->level_subdomain_id() ==
3067 this->locally_owned_subdomain()))
3068 cell->set_level_subdomain_id(
3069 this->locally_owned_subdomain());
3070 else
3071 {
3072 // not our cell
3073 cell->set_level_subdomain_id(
3075 }
3076 }
3077 }
3078
3079 // step 2: make sure all the neighbors to our level_cells exist.
3080 // Need to look up in p4est...
3081 std::vector<std::vector<bool>> marked_vertices(this->n_levels());
3082 for (unsigned int lvl = 0; lvl < this->n_levels(); ++lvl)
3083 marked_vertices[lvl] = mark_locally_active_vertices_on_level(lvl);
3084
3085 for (const auto &cell : this->cell_iterators_on_level(0))
3086 {
3087 typename ::internal::p4est::types<dim>::quadrant
3089 const unsigned int tree_index =
3090 coarse_cell_to_p4est_tree_permutation[cell->index()];
3091 typename ::internal::p4est::types<dim>::tree *tree =
3092 init_tree(cell->index());
3093
3094 ::internal::p4est::init_coarse_quadrant<dim>(
3096
3098 *tree,
3099 tree_index,
3100 cell,
3102 *parallel_forest,
3103 this->my_subdomain,
3104 marked_vertices);
3105 }
3106
3107 // step 3: make sure we have the parent of our level cells
3108 for (unsigned int lvl = this->n_levels(); lvl > 0;)
3109 {
3110 --lvl;
3111 for (const auto &cell : this->cell_iterators_on_level(lvl))
3112 {
3113 if (cell->has_children())
3114 for (unsigned int c = 0;
3116 ++c)
3117 {
3118 if (cell->child(c)->level_subdomain_id() ==
3119 this->locally_owned_subdomain())
3120 {
3121 // at least one of the children belongs to us, so
3122 // make sure we set the level subdomain id
3124 cell->child(0)->level_subdomain_id();
3126 ExcInternalError()); // we should know the
3127 // child(0)
3128 cell->set_level_subdomain_id(mark);
3129 break;
3130 }
3131 }
3132 }
3133 }
3134 }
3135
3136
3137
3138 // check that our local copy has exactly as many cells as the p4est
3139 // original (at least if we are on only one processor); for parallel
3140 // computations, we want to check that we have at least as many as p4est
3141 // stores locally (in the future we should check that we have exactly as
3142 // many non-artificial cells as parallel_forest->local_num_quadrants)
3143 {
3144 const unsigned int total_local_cells = this->n_active_cells();
3145 (void)total_local_cells;
3146
3147 if (Utilities::MPI::n_mpi_processes(this->mpi_communicator) == 1)
3148 {
3149 Assert(static_cast<unsigned int>(
3150 parallel_forest->local_num_quadrants) == total_local_cells,
3152 }
3153 else
3154 {
3155 Assert(static_cast<unsigned int>(
3156 parallel_forest->local_num_quadrants) <= total_local_cells,
3158 }
3159
3160# ifdef DEBUG
3161 // count the number of owned, active cells and compare with p4est.
3162 unsigned int n_owned = 0;
3163 for (const auto &cell : this->active_cell_iterators())
3164 {
3165 if (cell->subdomain_id() == this->my_subdomain)
3166 ++n_owned;
3167 }
3168
3169 Assert(static_cast<unsigned int>(
3170 parallel_forest->local_num_quadrants) == n_owned,
3172# endif
3173 }
3174
3175 this->smooth_grid = save_smooth;
3176
3177 // finally, after syncing the parallel_forest with the triangulation,
3178 // also update the cell_relations, which will be used for
3179 // repartitioning, further refinement/coarsening, and unpacking
3180 // of stored or transferred data.
3181 update_cell_relations();
3182 }
3183
3184
3185
3186 template <int dim, int spacedim>
3190 {
3191 // Call the other function
3192 std::vector<Point<dim>> point{p};
3193 std::vector<types::subdomain_id> owner = find_point_owner_rank(point);
3194
3195 return owner[0];
3196 }
3197
3198
3199
3200 template <int dim, int spacedim>
3202 std::vector<types::subdomain_id> Triangulation<dim, spacedim>::
3203 find_point_owner_rank(const std::vector<Point<dim>> &points)
3204 {
3205# ifndef P4EST_SEARCH_LOCAL
3206 (void)points;
3208 false,
3209 ExcMessage(
3210 "This function is only available if p4est is version 2.2 and higher."));
3211 // Just return to satisfy compiler
3212 return std::vector<unsigned int>(1,
3214# else
3215 // We can only use this function if vertices are communicated to p4est
3216 AssertThrow(this->are_vertices_communicated_to_p4est(),
3217 ExcMessage(
3218 "Vertices need to be communicated to p4est to use this "
3219 "function. This must explicitly be turned on in the "
3220 "settings of the triangulation's constructor."));
3221
3222 // We can only use this function if all manifolds are flat
3223 for (const auto &manifold_id : this->get_manifold_ids())
3224 {
3226 manifold_id == numbers::flat_manifold_id,
3227 ExcMessage(
3228 "This function can only be used if the triangulation "
3229 "has no other manifold than a Cartesian (flat) manifold attached."));
3230 }
3231
3232 // Create object for callback
3234
3235 // Pointer should be this triangulation before we set it to something else
3236 Assert(parallel_forest->user_pointer == this, ExcInternalError());
3237
3238 // re-assign p4est's user pointer
3239 parallel_forest->user_pointer = &partition_search;
3240
3241 //
3242 // Copy points into p4est internal array data struct
3243 //
3244 // pointer to an array of points.
3246 // allocate memory for a number of dim-dimensional points including their
3247 // MPI rank, i.e., dim + 1 fields
3249 sc_array_new_count(sizeof(double[dim + 1]), points.size());
3250
3251 // now assign the actual value
3252 for (size_t i = 0; i < points.size(); ++i)
3253 {
3254 // alias
3255 const Point<dim> &p = points[i];
3256 // get a non-const view of the array
3257 double *this_sc_point =
3258 static_cast<double *>(sc_array_index_ssize_t(point_sc_array, i));
3259 // fill this with the point data
3260 for (unsigned int d = 0; d < dim; ++d)
3261 {
3262 this_sc_point[d] = p(d);
3263 }
3264 this_sc_point[dim] = -1.0; // owner rank
3265 }
3266
3268 parallel_forest,
3269 /* execute quadrant function when leaving quadrant */
3270 static_cast<int>(false),
3274
3275 // copy the points found to an std::array
3276 std::vector<types::subdomain_id> owner_rank(
3277 points.size(), numbers::invalid_subdomain_id);
3278
3279 // fill the array
3280 for (size_t i = 0; i < points.size(); ++i)
3281 {
3282 // get a non-const view of the array
3283 double *this_sc_point =
3284 static_cast<double *>(sc_array_index_ssize_t(point_sc_array, i));
3285 Assert(this_sc_point[dim] >= 0. || this_sc_point[dim] == -1.,
3287 if (this_sc_point[dim] < 0.)
3289 else
3290 owner_rank[i] =
3291 static_cast<types::subdomain_id>(this_sc_point[dim]);
3292 }
3293
3294 // reset the internal pointer to this triangulation
3295 parallel_forest->user_pointer = this;
3296
3297 // release the memory (otherwise p4est will complain)
3299
3300 return owner_rank;
3301# endif // P4EST_SEARCH_LOCAL defined
3302 }
3303
3304
3305
3306 template <int dim, int spacedim>
3308 void Triangulation<dim, spacedim>::execute_coarsening_and_refinement()
3309 {
3310 // do not allow anisotropic refinement
3311# ifdef DEBUG
3312 for (const auto &cell : this->active_cell_iterators())
3313 if (cell->is_locally_owned() && cell->refine_flag_set())
3314 Assert(cell->refine_flag_set() ==
3316 ExcMessage(
3317 "This class does not support anisotropic refinement"));
3318# endif
3319
3320
3321 // safety check: p4est has an upper limit on the level of a cell
3322 if (this->n_levels() ==
3324 {
3326 cell = this->begin_active(
3328 cell !=
3330 1);
3331 ++cell)
3332 {
3334 !(cell->refine_flag_set()),
3335 ExcMessage(
3336 "Fatal Error: maximum refinement level of p4est reached."));
3337 }
3338 }
3339
3340 this->prepare_coarsening_and_refinement();
3341
3342 // signal that refinement is going to happen
3343 this->signals.pre_distributed_refinement();
3344
3345 // now do the work we're supposed to do when we are in charge
3346 // make sure all flags are cleared on cells we don't own, since nothing
3347 // good can come of that if they are still around
3348 for (const auto &cell : this->active_cell_iterators())
3349 if (cell->is_ghost() || cell->is_artificial())
3350 {
3351 cell->clear_refine_flag();
3352 cell->clear_coarsen_flag();
3353 }
3354
3355
3356 // count how many cells will be refined and coarsened, and allocate that
3357 // much memory
3359 *this, p4est_tree_to_coarse_cell_permutation, this->my_subdomain);
3360
3361 // copy refine and coarsen flags into p4est and execute the refinement
3362 // and coarsening. this uses the refine_and_coarsen_list just built,
3363 // which is communicated to the callback functions through
3364 // p4est's user_pointer object
3365 Assert(parallel_forest->user_pointer == this, ExcInternalError());
3366 parallel_forest->user_pointer = &refine_and_coarsen_list;
3367
3368 if (parallel_ghost != nullptr)
3369 {
3371 parallel_ghost);
3372 parallel_ghost = nullptr;
3373 }
3375 parallel_forest,
3376 /* refine_recursive */ false,
3377 &RefineAndCoarsenList<dim, spacedim>::refine_callback,
3378 /*init_callback=*/nullptr);
3380 parallel_forest,
3381 /* coarsen_recursive */ false,
3382 &RefineAndCoarsenList<dim, spacedim>::coarsen_callback,
3383 /*init_callback=*/nullptr);
3384
3385 // make sure all cells in the lists have been consumed
3386 Assert(refine_and_coarsen_list.pointers_are_at_end(), ExcInternalError());
3387
3388 // reset the pointer
3389 parallel_forest->user_pointer = this;
3390
3391 // enforce 2:1 hanging node condition
3393 parallel_forest,
3394 /* face and corner balance */
3395 (dim == 2 ? typename ::internal::p4est::types<dim>::balance_type(
3397 typename ::internal::p4est::types<dim>::balance_type(
3399 /*init_callback=*/nullptr);
3400
3401 // since refinement and/or coarsening on the parallel forest
3402 // has happened, we need to update the quadrant cell relations
3403 update_cell_relations();
3404
3405 // signals that parallel_forest has been refined and cell relations have
3406 // been updated
3407 this->signals.post_p4est_refinement();
3408
3409 // before repartitioning the mesh, save a copy of the current positions
3410 // of quadrants only if data needs to be transferred later
3411 std::vector<typename ::internal::p4est::types<dim>::gloidx>
3413
3414 if (this->cell_attached_data.n_attached_data_sets > 0)
3415 {
3416 previous_global_first_quadrant.resize(parallel_forest->mpisize + 1);
3417 std::memcpy(previous_global_first_quadrant.data(),
3418 parallel_forest->global_first_quadrant,
3419 sizeof(
3420 typename ::internal::p4est::types<dim>::gloidx) *
3421 (parallel_forest->mpisize + 1));
3422 }
3423
3424 if (!(settings & no_automatic_repartitioning))
3425 {
3426 // partition the new mesh between all processors. If cell weights
3427 // have not been given balance the number of cells.
3428 if (this->signals.weight.empty())
3430 parallel_forest,
3431 /* prepare coarsening */ 1,
3432 /* weight_callback */ nullptr);
3433 else
3434 {
3435 // get cell weights for a weighted repartitioning.
3436 const std::vector<unsigned int> cell_weights = get_cell_weights();
3437
3438 // verify that the global sum of weights is larger than 0
3439 Assert(Utilities::MPI::sum(std::accumulate(cell_weights.begin(),
3440 cell_weights.end(),
3441 std::uint64_t(0)),
3442 this->mpi_communicator) > 0,
3443 ExcMessage(
3444 "The global sum of weights over all active cells "
3445 "is zero. Please verify how you generate weights."));
3446
3448
3449 // attach (temporarily) a pointer to the cell weights through
3450 // p4est's user_pointer object
3451 Assert(parallel_forest->user_pointer == this, ExcInternalError());
3452 parallel_forest->user_pointer = &partition_weights;
3453
3455 parallel_forest,
3456 /* prepare coarsening */ 1,
3457 /* weight_callback */
3458 &PartitionWeights<dim, spacedim>::cell_weight);
3459
3460 // release data
3462 parallel_forest, 0, nullptr, nullptr);
3463 // reset the user pointer to its previous state
3464 parallel_forest->user_pointer = this;
3465 }
3466 }
3467
3468 // pack data before triangulation gets updated
3469 if (this->cell_attached_data.n_attached_data_sets > 0)
3470 {
3471 this->data_serializer.pack_data(
3472 this->local_cell_relations,
3473 this->cell_attached_data.pack_callbacks_fixed,
3474 this->cell_attached_data.pack_callbacks_variable,
3475 this->get_communicator());
3476 }
3477
3478 // finally copy back from local part of tree to deal.II
3479 // triangulation. before doing so, make sure there are no refine or
3480 // coarsen flags pending
3481 for (const auto &cell : this->active_cell_iterators())
3482 {
3483 cell->clear_refine_flag();
3484 cell->clear_coarsen_flag();
3485 }
3486
3487 try
3488 {
3489 copy_local_forest_to_triangulation();
3490 }
3491 catch (const typename Triangulation<dim>::DistortedCellList &)
3492 {
3493 // the underlying triangulation should not be checking for distorted
3494 // cells
3496 }
3497
3498 // transfer data after triangulation got updated
3499 if (this->cell_attached_data.n_attached_data_sets > 0)
3500 {
3501 this->execute_transfer(parallel_forest,
3503
3504 // also update the CellStatus information on the new mesh
3505 this->data_serializer.unpack_cell_status(this->local_cell_relations);
3506 }
3507
3508# ifdef DEBUG
3509 // Check that we know the level subdomain ids of all our neighbors. This
3510 // also involves coarser cells that share a vertex if they are active.
3511 //
3512 // Example (M= my, O=other):
3513 // *------*
3514 // | |
3515 // | O |
3516 // | |
3517 // *---*---*------*
3518 // | M | M |
3519 // *---*---*
3520 // | | M |
3521 // *---*---*
3522 // ^- the parent can be owned by somebody else, so O is not a neighbor
3523 // one level coarser
3524 if (settings & construct_multigrid_hierarchy)
3525 {
3526 for (unsigned int lvl = 0; lvl < this->n_global_levels(); ++lvl)
3527 {
3528 std::vector<bool> active_verts =
3529 this->mark_locally_active_vertices_on_level(lvl);
3530
3531 const unsigned int maybe_coarser_lvl =
3532 (lvl > 0) ? (lvl - 1) : lvl;
3534 cell = this->begin(maybe_coarser_lvl),
3535 endc = this->end(lvl);
3536 for (; cell != endc; ++cell)
3537 if (cell->level() == static_cast<int>(lvl) || cell->is_active())
3538 {
3539 const bool is_level_artificial =
3540 (cell->level_subdomain_id() ==
3542 bool need_to_know = false;
3543 for (const unsigned int vertex :
3545 if (active_verts[cell->vertex_index(vertex)])
3546 {
3547 need_to_know = true;
3548 break;
3549 }
3550
3551 Assert(
3553 ExcMessage(
3554 "Internal error: the owner of cell" +
3555 cell->id().to_string() +
3556 " is unknown even though it is needed for geometric multigrid."));
3557 }
3558 }
3559 }
3560# endif
3561
3562 this->update_periodic_face_map();
3563 this->update_number_cache();
3564
3565 // signal that refinement is finished
3566 this->signals.post_distributed_refinement();
3567 }
3568
3569
3570
3571 template <int dim, int spacedim>
3573 void Triangulation<dim, spacedim>::repartition()
3574 {
3575# ifdef DEBUG
3576 for (const auto &cell : this->active_cell_iterators())
3577 if (cell->is_locally_owned())
3578 Assert(
3579 !cell->refine_flag_set() && !cell->coarsen_flag_set(),
3580 ExcMessage(
3581 "Error: There shouldn't be any cells flagged for coarsening/refinement when calling repartition()."));
3582# endif
3583
3584 // signal that repartitioning is going to happen
3585 this->signals.pre_distributed_repartition();
3586
3587 // before repartitioning the mesh, save a copy of the current positions
3588 // of quadrants only if data needs to be transferred later
3589 std::vector<typename ::internal::p4est::types<dim>::gloidx>
3591
3592 if (this->cell_attached_data.n_attached_data_sets > 0)
3593 {
3594 previous_global_first_quadrant.resize(parallel_forest->mpisize + 1);
3595 std::memcpy(previous_global_first_quadrant.data(),
3596 parallel_forest->global_first_quadrant,
3597 sizeof(
3598 typename ::internal::p4est::types<dim>::gloidx) *
3599 (parallel_forest->mpisize + 1));
3600 }
3601
3602 if (this->signals.weight.empty())
3603 {
3604 // no cell weights given -- call p4est's 'partition' without a
3605 // callback for cell weights
3607 parallel_forest,
3608 /* prepare coarsening */ 1,
3609 /* weight_callback */ nullptr);
3610 }
3611 else
3612 {
3613 // get cell weights for a weighted repartitioning.
3614 const std::vector<unsigned int> cell_weights = get_cell_weights();
3615
3616 // verify that the global sum of weights is larger than 0
3617 Assert(Utilities::MPI::sum(std::accumulate(cell_weights.begin(),
3618 cell_weights.end(),
3619 std::uint64_t(0)),
3620 this->mpi_communicator) > 0,
3621 ExcMessage(
3622 "The global sum of weights over all active cells "
3623 "is zero. Please verify how you generate weights."));
3624
3626
3627 // attach (temporarily) a pointer to the cell weights through
3628 // p4est's user_pointer object
3629 Assert(parallel_forest->user_pointer == this, ExcInternalError());
3630 parallel_forest->user_pointer = &partition_weights;
3631
3633 parallel_forest,
3634 /* prepare coarsening */ 1,
3635 /* weight_callback */
3636 &PartitionWeights<dim, spacedim>::cell_weight);
3637
3638 // reset the user pointer to its previous state
3639 parallel_forest->user_pointer = this;
3640 }
3641
3642 // pack data before triangulation gets updated
3643 if (this->cell_attached_data.n_attached_data_sets > 0)
3644 {
3645 this->data_serializer.pack_data(
3646 this->local_cell_relations,
3647 this->cell_attached_data.pack_callbacks_fixed,
3648 this->cell_attached_data.pack_callbacks_variable,
3649 this->get_communicator());
3650 }
3651
3652 try
3653 {
3654 copy_local_forest_to_triangulation();
3655 }
3656 catch (const typename Triangulation<dim>::DistortedCellList &)
3657 {
3658 // the underlying triangulation should not be checking for distorted
3659 // cells
3661 }
3662
3663 // transfer data after triangulation got updated
3664 if (this->cell_attached_data.n_attached_data_sets > 0)
3665 {
3666 this->execute_transfer(parallel_forest,
3668 }
3669
3670 this->update_periodic_face_map();
3671
3672 // update how many cells, edges, etc, we store locally
3673 this->update_number_cache();
3674
3675 // signal that repartitioning is finished
3676 this->signals.post_distributed_repartition();
3677 }
3678
3679
3680
3681 template <int dim, int spacedim>
3683 const std::vector<types::global_dof_index>
3685 const
3686 {
3687 return p4est_tree_to_coarse_cell_permutation;
3688 }
3689
3690
3691
3692 template <int dim, int spacedim>
3694 const std::vector<types::global_dof_index>
3696 const
3697 {
3698 return coarse_cell_to_p4est_tree_permutation;
3699 }
3700
3701
3702
3703 template <int dim, int spacedim>
3705 std::vector<bool> Triangulation<dim, spacedim>::
3706 mark_locally_active_vertices_on_level(const int level) const
3707 {
3708 Assert(dim > 1, ExcNotImplemented());
3709
3710 std::vector<bool> marked_vertices(this->n_vertices(), false);
3711 for (const auto &cell : this->cell_iterators_on_level(level))
3712 if (cell->level_subdomain_id() == this->locally_owned_subdomain())
3713 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
3714 marked_vertices[cell->vertex_index(v)] = true;
3715
3721 // When a connectivity in the code below is detected, the assignment
3722 // 'marked_vertices[v1] = marked_vertices[v2] = true' makes sure that
3723 // the information about the periodicity propagates back to vertices on
3724 // cells that are not owned locally. However, in the worst case we want
3725 // to connect to a vertex that is 'dim' hops away from the locally owned
3726 // cell. Depending on the order of the periodic face map, we might
3727 // connect to that point by chance or miss it. However, after looping
3728 // through all the periodic directions (which are at most as many as
3729 // the number of space dimensions) we can be sure that all connections
3730 // to vertices have been created.
3731 for (unsigned int repetition = 0; repetition < dim; ++repetition)
3732 for (const auto &it : this->get_periodic_face_map())
3733 {
3734 const cell_iterator &cell_1 = it.first.first;
3735 const unsigned int face_no_1 = it.first.second;
3736 const cell_iterator &cell_2 = it.second.first.first;
3737 const unsigned int face_no_2 = it.second.first.second;
3738 const unsigned char combined_orientation = it.second.second;
3739 const auto [orientation, rotation, flip] =
3741
3742 if (cell_1->level() == level && cell_2->level() == level)
3743 {
3744 for (unsigned int v = 0;
3745 v < GeometryInfo<dim - 1>::vertices_per_cell;
3746 ++v)
3747 {
3748 // take possible non-standard orientation of faces into
3749 // account
3750 const unsigned int vface0 =
3752 v, orientation, flip, rotation);
3753 if (marked_vertices[cell_1->face(face_no_1)->vertex_index(
3754 vface0)] ||
3755 marked_vertices[cell_2->face(face_no_2)->vertex_index(
3756 v)])
3757 marked_vertices[cell_1->face(face_no_1)->vertex_index(
3758 vface0)] =
3759 marked_vertices[cell_2->face(face_no_2)->vertex_index(
3760 v)] = true;
3761 }
3762 }
3763 }
3764
3765 return marked_vertices;
3766 }
3767
3768
3769
3770 template <int dim, int spacedim>
3772 unsigned int Triangulation<dim, spacedim>::
3773 coarse_cell_id_to_coarse_cell_index(
3774 const types::coarse_cell_id coarse_cell_id) const
3775 {
3776 return p4est_tree_to_coarse_cell_permutation[coarse_cell_id];
3777 }
3778
3779
3780
3781 template <int dim, int spacedim>
3785 const unsigned int coarse_cell_index) const
3786 {
3787 return coarse_cell_to_p4est_tree_permutation[coarse_cell_index];
3788 }
3789
3790
3791
3792 template <int dim, int spacedim>
3794 void Triangulation<dim, spacedim>::add_periodicity(
3795 const std::vector<::GridTools::PeriodicFacePair<cell_iterator>>
3797 {
3798 Assert(triangulation_has_content == true,
3799 ExcMessage("The triangulation is empty!"));
3800 Assert(this->n_levels() == 1,
3801 ExcMessage("The triangulation is refined!"));
3802
3803 // call the base class for storing the periodicity information; we must
3804 // do this before going to p4est and rebuilding the triangulation to get
3805 // the level subdomain ids correct in the multigrid case
3807
3808 const auto reference_cell = ReferenceCells::get_hypercube<dim>();
3809 const auto face_reference_cell = ReferenceCells::get_hypercube<dim - 1>();
3810 for (const auto &face_pair : periodicity_vector)
3811 {
3812 const cell_iterator first_cell = face_pair.cell[0];
3813 const cell_iterator second_cell = face_pair.cell[1];
3814 const unsigned int face_left = face_pair.face_idx[0];
3815 const unsigned int face_right = face_pair.face_idx[1];
3816
3817 // respective cells of the matching faces in p4est
3818 const unsigned int tree_left =
3819 coarse_cell_to_p4est_tree_permutation[first_cell->index()];
3820 const unsigned int tree_right =
3821 coarse_cell_to_p4est_tree_permutation[second_cell->index()];
3822
3823 // p4est wants to know which corner the first corner on the face with
3824 // the lower id is mapped to on the face with with the higher id. For
3825 // d==2 there are only two possibilities: i.e., face_pair.orientation
3826 // must be 0 or 1. For d==3 we have to use a lookup table. The result
3827 // is given below.
3828
3829 unsigned int p4est_orientation = 0;
3830 if (dim == 2)
3831 {
3832 AssertIndexRange(face_pair.orientation, 2);
3834 face_pair.orientation ==
3836 0u :
3837 1u;
3838 }
3839 else
3840 {
3841 const unsigned int face_idx_list[] = {face_left, face_right};
3842 const cell_iterator cell_list[] = {first_cell, second_cell};
3843 unsigned int lower_idx, higher_idx;
3844 unsigned char orientation;
3845 if (face_left <= face_right)
3846 {
3847 higher_idx = 1;
3848 lower_idx = 0;
3849 orientation =
3850 face_reference_cell.get_inverse_combined_orientation(
3851 face_pair.orientation);
3852 }
3853 else
3854 {
3855 higher_idx = 0;
3856 lower_idx = 1;
3857 orientation = face_pair.orientation;
3858 }
3859
3860 // get the cell index of the first index on the face with the
3861 // lower id
3862 unsigned int first_p4est_idx_on_cell =
3864 unsigned int first_dealii_idx_on_face =
3866 for (unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_face;
3867 ++i)
3868 {
3869 const unsigned int first_dealii_idx_on_cell =
3872 i,
3873 cell_list[lower_idx]->face_orientation(
3875 cell_list[lower_idx]->face_flip(face_idx_list[lower_idx]),
3876 cell_list[lower_idx]->face_rotation(
3879 {
3881 break;
3882 }
3883 }
3886
3887 // Now map dealii_idx_on_face according to the orientation.
3888 const unsigned int second_dealii_idx_on_face =
3889 reference_cell.standard_to_real_face_vertex(
3892 orientation);
3893 const unsigned int second_dealii_idx_on_cell =
3894 reference_cell.face_to_cell_vertices(
3897 cell_list[higher_idx]->combined_face_orientation(
3899 // map back to p4est
3900 const unsigned int second_p4est_idx_on_face =
3904 }
3905
3907 connectivity,
3908 tree_left,
3909 tree_right,
3910 face_left,
3911 face_right,
3913 }
3914
3915
3917 connectivity) == 1,
3919
3920 // now create a forest out of the connectivity data structure
3923 this->mpi_communicator,
3924 connectivity,
3925 /* minimum initial number of quadrants per tree */ 0,
3926 /* minimum level of upfront refinement */ 0,
3927 /* use uniform upfront refinement */ 1,
3928 /* user_data_size = */ 0,
3929 /* user_data_constructor = */ nullptr,
3930 /* user_pointer */ this);
3931
3932 try
3933 {
3934 copy_local_forest_to_triangulation();
3935 }
3936 catch (const typename Triangulation<dim>::DistortedCellList &)
3937 {
3938 // the underlying triangulation should not be checking for distorted
3939 // cells
3941 }
3942
3943 // The range of ghost_owners might have changed so update that
3944 // information
3945 this->update_number_cache();
3946 }
3947
3948
3949
3950 template <int dim, int spacedim>
3952 std::size_t Triangulation<dim, spacedim>::memory_consumption() const
3953 {
3954 std::size_t mem =
3957 MemoryConsumption::memory_consumption(triangulation_has_content) +
3959 MemoryConsumption::memory_consumption(parallel_forest) +
3961 this->cell_attached_data.n_attached_data_sets) +
3962 // MemoryConsumption::memory_consumption(cell_attached_data.pack_callbacks_fixed)
3963 // +
3964 // MemoryConsumption::memory_consumption(cell_attached_data.pack_callbacks_variable)
3965 // +
3966 // TODO[TH]: how?
3968 coarse_cell_to_p4est_tree_permutation) +
3970 p4est_tree_to_coarse_cell_permutation) +
3971 memory_consumption_p4est();
3972
3973 return mem;
3974 }
3975
3976
3977
3978 template <int dim, int spacedim>
3980 std::size_t Triangulation<dim, spacedim>::memory_consumption_p4est() const
3981 {
3982 return ::internal::p4est::functions<dim>::forest_memory_used(
3983 parallel_forest) +
3985 connectivity);
3986 }
3987
3988
3989
3990 template <int dim, int spacedim>
3992 void Triangulation<dim, spacedim>::copy_triangulation(
3993 const ::Triangulation<dim, spacedim> &other_tria)
3994 {
3995 Assert(
3996 (dynamic_cast<
3997 const ::parallel::distributed::Triangulation<dim, spacedim> *>(
3998 &other_tria)) ||
3999 (other_tria.n_global_levels() == 1),
4001
4003
4004 try
4005 {
4008 }
4009 catch (
4010 const typename ::Triangulation<dim, spacedim>::DistortedCellList
4011 &)
4012 {
4013 // the underlying triangulation should not be checking for distorted
4014 // cells
4016 }
4017
4018 if (const ::parallel::distributed::Triangulation<dim, spacedim>
4020 dynamic_cast<const ::parallel::distributed::
4021 Triangulation<dim, spacedim> *>(&other_tria))
4022 {
4023 // copy parallel distributed specifics
4024 settings = other_distributed->settings;
4025 triangulation_has_content =
4026 other_distributed->triangulation_has_content;
4027 coarse_cell_to_p4est_tree_permutation =
4028 other_distributed->coarse_cell_to_p4est_tree_permutation;
4029 p4est_tree_to_coarse_cell_permutation =
4030 other_distributed->p4est_tree_to_coarse_cell_permutation;
4031
4032 // create deep copy of connectivity graph
4033 typename ::internal::p4est::types<dim>::connectivity
4034 *temp_connectivity = const_cast<
4035 typename ::internal::p4est::types<dim>::connectivity *>(
4036 other_distributed->connectivity);
4037 connectivity =
4038 ::internal::p4est::copy_connectivity<dim>(temp_connectivity);
4039
4040 // create deep copy of parallel forest
4041 typename ::internal::p4est::types<dim>::forest *temp_forest =
4042 const_cast<typename ::internal::p4est::types<dim>::forest *>(
4043 other_distributed->parallel_forest);
4044 parallel_forest =
4046 false);
4047 parallel_forest->connectivity = connectivity;
4048 parallel_forest->user_pointer = this;
4049 }
4050 else
4051 {
4052 triangulation_has_content = true;
4053 setup_coarse_cell_to_p4est_tree_permutation();
4054 copy_new_triangulation_to_p4est(std::integral_constant<int, dim>());
4055 }
4056
4057 try
4058 {
4059 copy_local_forest_to_triangulation();
4060 }
4061 catch (const typename Triangulation<dim>::DistortedCellList &)
4062 {
4063 // the underlying triangulation should not be checking for distorted
4064 // cells
4066 }
4067
4068 this->update_periodic_face_map();
4069 this->update_number_cache();
4070 }
4071
4072
4073
4074 template <int dim, int spacedim>
4076 void Triangulation<dim, spacedim>::update_cell_relations()
4077 {
4078 // reorganize memory for local_cell_relations
4079 this->local_cell_relations.resize(parallel_forest->local_num_quadrants);
4080 this->local_cell_relations.shrink_to_fit();
4081
4082 // recurse over p4est
4083 for (const auto &cell : this->cell_iterators_on_level(0))
4084 {
4085 // skip coarse cells that are not ours
4087 parallel_forest,
4088 coarse_cell_to_p4est_tree_permutation[cell->index()]) == false)
4089 continue;
4090
4091 // initialize auxiliary top level p4est quadrant
4092 typename ::internal::p4est::types<dim>::quadrant
4094 ::internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
4095
4096 // determine tree to start recursion on
4097 typename ::internal::p4est::types<dim>::tree *tree =
4098 init_tree(cell->index());
4099
4101 this->local_cell_relations, *tree, cell, p4est_coarse_cell);
4102 }
4103 }
4104
4105
4106
4107 template <int dim, int spacedim>
4109 std::vector<unsigned int> Triangulation<dim, spacedim>::get_cell_weights()
4110 const
4111 {
4112 // check if local_cell_relations have been previously gathered
4113 // correctly
4114 Assert(this->local_cell_relations.size() ==
4115 static_cast<unsigned int>(parallel_forest->local_num_quadrants),
4117
4118 // Allocate the space for the weights. We reserve an integer for each
4119 // locally owned quadrant on the already refined p4est object.
4120 std::vector<unsigned int> weights;
4121 weights.reserve(this->local_cell_relations.size());
4122
4123 // Iterate over p4est and Triangulation relations
4124 // to find refined/coarsened/kept
4125 // cells. Then append weight.
4126 // Note that we need to follow the p4est ordering
4127 // instead of the deal.II ordering to get the weights
4128 // in the same order p4est will encounter them during repartitioning.
4129 for (const auto &cell_rel : this->local_cell_relations)
4130 {
4131 const auto &cell_it = cell_rel.first;
4132 const auto &cell_status = cell_rel.second;
4133
4134 weights.push_back(this->signals.weight(cell_it, cell_status));
4135 }
4136
4137 return weights;
4138 }
4139
4140
4141
4142 template <int spacedim>
4145 const MPI_Comm mpi_communicator,
4146 const typename ::Triangulation<1, spacedim>::MeshSmoothing
4147 smooth_grid,
4148 const Settings /*settings*/)
4149 : ::parallel::DistributedTriangulationBase<1, spacedim>(
4150 mpi_communicator,
4151 smooth_grid,
4152 false)
4153 {
4155 }
4156
4157
4158 template <int spacedim>
4161 {
4163 }
4164
4165
4166
4167 template <int spacedim>
4169 const std::vector<types::global_dof_index>
4171 const
4172 {
4173 static std::vector<types::global_dof_index> a;
4174 return a;
4175 }
4176
4177
4178
4179 template <int spacedim>
4181 std::map<unsigned int,
4182 std::set<::types::subdomain_id>> Triangulation<1, spacedim>::
4184 const unsigned int /*level*/) const
4185 {
4187
4188 return std::map<unsigned int, std::set<::types::subdomain_id>>();
4189 }
4190
4191
4192
4193 template <int spacedim>
4195 std::vector<bool> Triangulation<1, spacedim>::
4196 mark_locally_active_vertices_on_level(const unsigned int) const
4197 {
4199 return std::vector<bool>();
4200 }
4201
4202
4203
4204 template <int spacedim>
4206 unsigned int Triangulation<1, spacedim>::
4207 coarse_cell_id_to_coarse_cell_index(const types::coarse_cell_id) const
4208 {
4210 return 0;
4211 }
4212
4213
4214
4215 template <int spacedim>
4219 const unsigned int) const
4220 {
4222 return 0;
4223 }
4224
4225
4226
4227 template <int spacedim>
4229 void Triangulation<1, spacedim>::load(const std::string &)
4230 {
4232 }
4233
4234
4235
4236 template <int spacedim>
4238 void Triangulation<1, spacedim>::load(const std::string &, const bool)
4239 {
4241 }
4242
4243
4244
4245 template <int spacedim>
4247 void Triangulation<1, spacedim>::save(const std::string &) const
4248 {
4250 }
4251
4252
4253
4254 template <int spacedim>
4256 bool Triangulation<1, spacedim>::is_multilevel_hierarchy_constructed() const
4257 {
4259 return false;
4260 }
4261
4262
4263
4264 template <int spacedim>
4266 bool Triangulation<1, spacedim>::are_vertices_communicated_to_p4est() const
4267 {
4269 return false;
4270 }
4271
4272
4273
4274 template <int spacedim>
4276 void Triangulation<1, spacedim>::update_cell_relations()
4277 {
4279 }
4280
4281 } // namespace distributed
4282} // namespace parallel
4283
4284
4285#endif // DEAL_II_WITH_P4EST
4286
4287
4288
4289namespace parallel
4290{
4291 namespace distributed
4292 {
4293 template <int dim, int spacedim>
4296 : distributed_tria(
4298 ::parallel::distributed::Triangulation<dim, spacedim> *>(
4299 &tria))
4300 {
4301#ifdef DEAL_II_WITH_P4EST
4302 if (distributed_tria != nullptr)
4303 {
4304 // Save the current set of refinement flags, and adjust the
4305 // refinement flags to be consistent with the p4est oracle.
4306 distributed_tria->save_coarsen_flags(saved_coarsen_flags);
4307 distributed_tria->save_refine_flags(saved_refine_flags);
4308
4309 for (const auto &pair : distributed_tria->local_cell_relations)
4310 {
4311 const auto &cell = pair.first;
4312 const auto &status = pair.second;
4313
4314 switch (status)
4315 {
4317 // cell remains unchanged
4318 cell->clear_refine_flag();
4319 cell->clear_coarsen_flag();
4320 break;
4321
4323 // cell will be refined
4324 cell->clear_coarsen_flag();
4325 cell->set_refine_flag();
4326 break;
4327
4329 // children of this cell will be coarsened
4330 for (const auto &child : cell->child_iterators())
4331 {
4332 child->clear_refine_flag();
4333 child->set_coarsen_flag();
4334 }
4335 break;
4336
4338 // do nothing as cell does not exist yet
4339 break;
4340
4341 default:
4343 break;
4344 }
4345 }
4346 }
4347#endif
4348 }
4349
4350
4351
4352 template <int dim, int spacedim>
4354 {
4355#ifdef DEAL_II_WITH_P4EST
4356 if (distributed_tria)
4357 {
4358 // Undo the refinement flags modification.
4359 distributed_tria->load_coarsen_flags(saved_coarsen_flags);
4360 distributed_tria->load_refine_flags(saved_refine_flags);
4361 }
4362#else
4363 // pretend that this destructor does something to silence clang-tidy
4364 (void)distributed_tria;
4365#endif
4366 }
4367 } // namespace distributed
4368} // namespace parallel
4369
4370
4371
4372/*-------------- Explicit Instantiations -------------------------------*/
4373#include "tria.inst"
4374
4375
CellStatus
Definition cell_status.h:31
@ cell_will_be_refined
@ children_will_be_coarsened
Definition point.h:111
static constexpr unsigned char default_combined_face_orientation()
friend class Tensor
Definition tensor.h:882
constexpr Tensor & operator=(const Tensor< rank_, dim, OtherNumber > &rhs)
virtual void add_periodicity(const std::vector< GridTools::PeriodicFacePair< cell_iterator > > &)
virtual void clear()
const std::map< std::pair< cell_iterator, unsigned int >, std::pair< std::pair< cell_iterator, unsigned int >, unsigned char > > & get_periodic_face_map() const
active_cell_iterator last_active() const
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
cell_iterator end() const
virtual types::coarse_cell_id coarse_cell_index_to_coarse_cell_id(const unsigned int coarse_cell_index) const
virtual void execute_coarsening_and_refinement()
virtual bool prepare_coarsening_and_refinement()
void save_refine_flags(std::ostream &out) const
unsigned int n_vertices() const
void save_coarsen_flags(std::ostream &out) const
active_cell_iterator begin_active(const unsigned int level=0) const
virtual std::size_t memory_consumption() const override
Definition tria_base.cc:92
virtual void clear() override
Definition tria_base.cc:687
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria) override
Definition tria_base.cc:67
const SmartPointer< ::parallel::distributed::Triangulation< dim, spacedim > > distributed_tria
Definition tria.h:1169
virtual void clear() override
Definition tria.cc:1864
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:177
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
Point< 3 > vertices[4]
unsigned int level
Definition grid_out.cc:4626
unsigned int vertex_indices[2]
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertNothrow(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
Definition tria.h:288
typename ::Triangulation< dim, spacedim >::active_cell_iterator active_cell_iterator
Definition tria.h:309
#define DEAL_II_ASSERT_UNREACHABLE()
#define DEAL_II_NOT_IMPLEMENTED()
spacedim const Point< spacedim > & p
Definition grid_tools.h:990
const std::vector< bool > & used
const Triangulation< dim, spacedim > & tria
void get_vertex_connectivity_of_cells(const Triangulation< dim, spacedim > &triangulation, DynamicSparsityPattern &connectivity)
spacedim const Point< spacedim > const std::vector< bool > & marked_vertices
Definition grid_tools.h:991
if(marked_vertices.size() !=0) for(auto it
for(unsigned int j=best_vertex+1;j< vertices.size();++j) if(vertices_to_use[j])
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:191
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
constexpr const ReferenceCell & get_hypercube()
void reorder_hierarchical(const DynamicSparsityPattern &sparsity, std::vector< DynamicSparsityPattern::size_type > &new_indices)
T sum(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
Definition mpi.cc:92
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
Definition mpi.cc:107
std::vector< Integer > invert_permutation(const std::vector< Integer > &permutation)
Definition utilities.h:1699
bool tree_exists_locally(const typename types< dim >::forest *parallel_forest, const typename types< dim >::topidx coarse_grid_cell)
void exchange_refinement_flags(::parallel::distributed::Triangulation< dim, spacedim > &tria)
Definition tria.cc:56
std::tuple< bool, bool, bool > split_face_orientation(const unsigned char combined_face_orientation)
const types::subdomain_id artificial_subdomain_id
Definition types.h:362
const types::subdomain_id invalid_subdomain_id
Definition types.h:341
static const unsigned int invalid_unsigned_int
Definition types.h:220
const types::manifold_id flat_manifold_id
Definition types.h:325
const Iterator const std_cxx20::type_identity_t< Iterator > & end
Definition parallel.h:610
const Iterator & begin
Definition parallel.h:609
STL namespace.
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
Definition types.h:32
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
static unsigned int standard_to_real_face_vertex(const unsigned int vertex, const bool face_orientation=true, const bool face_flip=false, const bool face_rotation=false)
static unsigned int face_to_cell_vertices(const unsigned int face, const unsigned int vertex, const bool face_orientation=true, const bool face_flip=false, const bool face_rotation=false)
static std_cxx20::ranges::iota_view< unsigned int, unsigned int > vertex_indices()
static bool is_inside_unit_cell(const Point< dim > &p)
static Point< dim > unit_cell_vertex(const unsigned int vertex)