Reference documentation for deal.II version 9.5.1
\(\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
p4est_wrappers.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2008 - 2022 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16
19
21
22#ifdef DEAL_II_WITH_P4EST
23
24namespace internal
25{
26 namespace p4est
27 {
28 namespace
29 {
30 template <int dim, int spacedim>
31 typename ::Triangulation<dim, spacedim>::cell_iterator
33 const ::parallel::distributed::Triangulation<dim, spacedim>
35 const typename ::internal::p4est::types<dim>::topidx treeidx,
36 const typename ::internal::p4est::types<dim>::quadrant &quad)
37 {
38 int i, l = quad.level;
40 triangulation->get_p4est_tree_to_coarse_cell_permutation()[treeidx];
41
42 for (i = 0; i < l; ++i)
43 {
44 typename ::Triangulation<dim, spacedim>::cell_iterator cell(
46 const int child_id =
48 &quad, i + 1);
49 Assert(cell->has_children(),
50 ExcMessage("p4est quadrant does not correspond to a cell!"));
51 dealii_index = cell->child_index(child_id);
52 }
53
54 typename ::Triangulation<dim, spacedim>::cell_iterator out_cell(
56
57 return out_cell;
58 }
59
64 template <int dim, int spacedim>
65 struct FindGhosts
66 {
67 const typename ::parallel::distributed::Triangulation<dim,
68 spacedim>
71 std::map<unsigned int, std::set<::types::subdomain_id>>
73 };
74
75
81 template <int dim, int spacedim>
82 void
84 typename ::internal::p4est::iter<dim>::corner_info *info,
85 void * user_data)
86 {
87 int i, j;
88 int nsides = info->sides.elem_count;
89 auto *sides = reinterpret_cast<
90 typename ::internal::p4est::iter<dim>::corner_side *>(
91 info->sides.array);
93 static_cast<FindGhosts<dim, spacedim> *>(user_data);
94 sc_array_t *subids = fg->subids;
95 const ::parallel::distributed::Triangulation<dim, spacedim>
96 * triangulation = fg->triangulation;
97 int nsubs;
98 ::types::subdomain_id *subdomain_ids;
99 std::map<unsigned int, std::set<::types::subdomain_id>>
100 *vertices_with_ghost_neighbors = fg->vertices_with_ghost_neighbors;
101
102 subids->elem_count = 0;
103 for (i = 0; i < nsides; ++i)
104 {
105 if (sides[i].is_ghost)
106 {
107 typename ::parallel::distributed::
108 Triangulation<dim, spacedim>::cell_iterator cell =
110 sides[i].treeid,
111 *(sides[i].quad));
112 Assert(cell->is_ghost(),
113 ExcMessage("ghost quad did not find ghost cell"));
115 static_cast<::types::subdomain_id *>(
117 *subid = cell->subdomain_id();
118 }
119 }
120
121 if (!subids->elem_count)
122 {
123 return;
124 }
125
126 nsubs = static_cast<int>(subids->elem_count);
127 subdomain_ids =
128 reinterpret_cast<::types::subdomain_id *>(subids->array);
129
130 for (i = 0; i < nsides; ++i)
131 {
132 if (!sides[i].is_ghost)
133 {
134 typename ::parallel::distributed::
135 Triangulation<dim, spacedim>::cell_iterator cell =
137 sides[i].treeid,
138 *(sides[i].quad));
139
140 Assert(!cell->is_ghost(),
141 ExcMessage("local quad found ghost cell"));
142
143 for (j = 0; j < nsubs; ++j)
144 {
145 (*vertices_with_ghost_neighbors)[cell->vertex_index(
146 sides[i].corner)]
147 .insert(subdomain_ids[j]);
148 }
149 }
150 }
151
152 subids->elem_count = 0;
153 }
154
158 template <int dim, int spacedim>
159 void
161 typename ::internal::p4est::iter<dim>::edge_info *info,
162 void * user_data)
163 {
164 int i, j, k;
165 int nsides = info->sides.elem_count;
166 auto *sides = reinterpret_cast<
167 typename ::internal::p4est::iter<dim>::edge_side *>(
168 info->sides.array);
169 auto * fg = static_cast<FindGhosts<dim, spacedim> *>(user_data);
170 sc_array_t *subids = fg->subids;
171 const ::parallel::distributed::Triangulation<dim, spacedim>
172 * triangulation = fg->triangulation;
173 int nsubs;
174 ::types::subdomain_id *subdomain_ids;
175 std::map<unsigned int, std::set<::types::subdomain_id>>
176 *vertices_with_ghost_neighbors = fg->vertices_with_ghost_neighbors;
177
178 subids->elem_count = 0;
179 for (i = 0; i < nsides; ++i)
180 {
181 if (sides[i].is_hanging)
182 {
183 for (j = 0; j < 2; ++j)
184 {
185 if (sides[i].is.hanging.is_ghost[j])
186 {
187 typename ::parallel::distributed::
188 Triangulation<dim, spacedim>::cell_iterator cell =
190 sides[i].treeid,
191 *(sides[i].is.hanging.quad[j]));
193 static_cast<::types::subdomain_id *>(
195 *subid = cell->subdomain_id();
196 }
197 }
198 }
199 }
200
201 if (!subids->elem_count)
202 {
203 return;
204 }
205
206 nsubs = static_cast<int>(subids->elem_count);
207 subdomain_ids =
208 reinterpret_cast<::types::subdomain_id *>(subids->array);
209
210 for (i = 0; i < nsides; ++i)
211 {
212 if (sides[i].is_hanging)
213 {
214 for (j = 0; j < 2; ++j)
215 {
216 if (!sides[i].is.hanging.is_ghost[j])
217 {
218 typename ::parallel::distributed::
219 Triangulation<dim, spacedim>::cell_iterator cell =
221 sides[i].treeid,
222 *(sides[i].is.hanging.quad[j]));
223
224 for (k = 0; k < nsubs; ++k)
225 {
226 (*vertices_with_ghost_neighbors)
227 [cell->vertex_index(
228 p8est_edge_corners[sides[i].edge][1 ^ j])]
229 .insert(subdomain_ids[k]);
230 }
231 }
232 }
233 }
234 }
235
236 subids->elem_count = 0;
237 }
238
242 template <int dim, int spacedim>
243 void
245 typename ::internal::p4est::iter<dim>::face_info *info,
246 void * user_data)
247 {
248 int i, j, k;
249 int nsides = info->sides.elem_count;
250 auto *sides = reinterpret_cast<
251 typename ::internal::p4est::iter<dim>::face_side *>(
252 info->sides.array);
254 static_cast<FindGhosts<dim, spacedim> *>(user_data);
255 sc_array_t *subids = fg->subids;
256 const ::parallel::distributed::Triangulation<dim, spacedim>
257 * triangulation = fg->triangulation;
258 int nsubs;
259 ::types::subdomain_id *subdomain_ids;
260 std::map<unsigned int, std::set<::types::subdomain_id>>
261 * vertices_with_ghost_neighbors = fg->vertices_with_ghost_neighbors;
262 int limit = (dim == 2) ? 2 : 4;
263
264 subids->elem_count = 0;
265 for (i = 0; i < nsides; ++i)
266 {
267 if (sides[i].is_hanging)
268 {
269 for (j = 0; j < limit; ++j)
270 {
271 if (sides[i].is.hanging.is_ghost[j])
272 {
273 typename ::parallel::distributed::
274 Triangulation<dim, spacedim>::cell_iterator cell =
276 sides[i].treeid,
277 *(sides[i].is.hanging.quad[j]));
279 static_cast<::types::subdomain_id *>(
281 *subid = cell->subdomain_id();
282 }
283 }
284 }
285 }
286
287 if (!subids->elem_count)
288 {
289 return;
290 }
291
292 nsubs = static_cast<int>(subids->elem_count);
293 subdomain_ids =
294 reinterpret_cast<::types::subdomain_id *>(subids->array);
295
296 for (i = 0; i < nsides; ++i)
297 {
298 if (sides[i].is_hanging)
299 {
300 for (j = 0; j < limit; ++j)
301 {
302 if (!sides[i].is.hanging.is_ghost[j])
303 {
304 typename ::parallel::distributed::
305 Triangulation<dim, spacedim>::cell_iterator cell =
307 sides[i].treeid,
308 *(sides[i].is.hanging.quad[j]));
309
310 for (k = 0; k < nsubs; ++k)
311 {
312 if (dim == 2)
313 {
314 (*vertices_with_ghost_neighbors)
315 [cell->vertex_index(
317 [(limit - 1) ^ j])]
318 .insert(subdomain_ids[k]);
319 }
320 else
321 {
322 (*vertices_with_ghost_neighbors)
323 [cell->vertex_index(
325 [(limit - 1) ^ j])]
326 .insert(subdomain_ids[k]);
327 }
328 }
329 }
330 }
331 }
332 }
333
334 subids->elem_count = 0;
335 }
336 } // namespace
337
338
339 int (&functions<2>::quadrant_compare)(const void *v1, const void *v2) =
341
343 types<2>::quadrant c[]) =
345
347 const types<2>::quadrant *q) =
349
351 int level,
352 std::uint64_t id) =
354
356 const types<2>::quadrant *q2) =
358
360 const types<2>::quadrant *q2) =
362
364 const types<2>::quadrant *q2) =
366
368 int level) =
370
373 const types<2>::quadrant *q,
374 const int guess) =
376
382
387 const double * vertices,
388 const types<2>::topidx *ttv,
389 const types<2>::topidx *ttt,
390 const int8_t * ttf,
391 const types<2>::topidx *ttc,
392 const types<2>::topidx *coff,
393 const types<2>::topidx *ctt,
395
399 int face_left,
400 int face_right,
401 int orientation) =
403
406
409 types<2>::connectivity *connectivity,
411 int min_level,
412 int fill_uniform,
413 std::size_t data_size,
415 void * user_pointer) = p4est_new_ext;
416
418 int copy_data) = p4est_copy;
419
421
426
431
435
440
441 void (&functions<2>::save)(const char * filename,
442 types<2>::forest *p4est,
443 int save_data) = p4est_save;
444
446 const char * filename,
448 std::size_t data_size,
449 int load_data,
450 int autopartition,
451 int broadcasthead,
452 void * user_pointer,
454
456 const char * filename,
458
461
463 const char * filename,
464 std::size_t *length) = p4est_connectivity_load;
465
466 unsigned int (&functions<2>::checksum)(types<2>::forest *p4est) =
468
471 const char *baseName) =
473
477
480
482 std::size_t data_size,
484 void *user_pointer) = p4est_reset_data;
485
488
491
492 constexpr unsigned int functions<2>::max_level;
493
497 int tag,
498 void * dest_data,
499 const void * src_data,
500 std::size_t data_size) =
502
507 int tag,
508 void * dest_data,
509 const void * src_data,
511
514
518 int tag,
519 void * dest_data,
520 const int * dest_sizes,
521 const void * src_data,
522 const int * src_sizes) =
524
529 int tag,
530 void * dest_data,
531 const int * dest_sizes,
532 const void * src_data,
534
537
538# ifdef P4EST_SEARCH_LOCAL
540 types<2>::forest * p4est,
541 int call_post,
545# endif
546
548 types<2>::connectivity * connectivity,
552 double vxyz[3]) = p4est_qcoord_to_vertex;
553
554 int (&functions<3>::quadrant_compare)(const void *v1, const void *v2) =
556
558 types<3>::quadrant c[]) =
560
562 const types<3>::quadrant *q) =
564
566 int level,
567 std::uint64_t id) =
569
571 const types<3>::quadrant *q2) =
573
575 const types<3>::quadrant *q2) =
577
579 const types<3>::quadrant *q2) =
581
583 int level) =
585
588 const types<3>::quadrant *q,
589 const int guess) =
591
599
605 const double * vertices,
606 const types<3>::topidx *ttv,
607 const types<3>::topidx *ttt,
608 const int8_t * ttf,
609 const types<3>::topidx *tte,
610 const types<3>::topidx *eoff,
611 const types<3>::topidx *ett,
612 const int8_t * ete,
613 const types<3>::topidx *ttc,
614 const types<3>::topidx *coff,
615 const types<3>::topidx *ctt,
617
620
624 int face_left,
625 int face_right,
626 int orientation) =
628
631 types<3>::connectivity *connectivity,
633 int min_level,
634 int fill_uniform,
635 std::size_t data_size,
637 void * user_pointer) = p8est_new_ext;
638
640 int copy_data) = p8est_copy;
641
643
648
653
657
662
663 void (&functions<3>::save)(const char * filename,
664 types<3>::forest *p4est,
665 int save_data) = p8est_save;
666
668 const char * filename,
670 std::size_t data_size,
671 int load_data,
672 int autopartition,
673 int broadcasthead,
674 void * user_pointer,
676
678 const char * filename,
680
683
685 const char * filename,
686 std::size_t *length) = p8est_connectivity_load;
687
690
693 const char *baseName) =
695
699
702
704 std::size_t data_size,
706 void *user_pointer) = p8est_reset_data;
707
710
713
714 constexpr unsigned int functions<3>::max_level;
715
719 int tag,
720 void * dest_data,
721 const void * src_data,
722 std::size_t data_size) =
724
729 int tag,
730 void * dest_data,
731 const void * src_data,
733
736
740 int tag,
741 void * dest_data,
742 const int * dest_sizes,
743 const void * src_data,
744 const int * src_sizes) =
746
751 int tag,
752 void * dest_data,
753 const int * dest_sizes,
754 const void * src_data,
756
759
760# ifdef P4EST_SEARCH_LOCAL
762 types<3>::forest * p4est,
763 int call_post,
767# endif
768
770 types<3>::connectivity * connectivity,
775 double vxyz[3]) = p8est_qcoord_to_vertex;
776
777 template <int dim>
778 void
780 const typename types<dim>::quadrant &p4est_cell,
781 typename types<dim>::quadrant (
783 {
784 for (unsigned int c = 0;
786 ++c)
787 switch (dim)
788 {
789 case 2:
791 break;
792 case 3:
794 break;
795 default:
796 Assert(false, ExcNotImplemented());
797 }
798
799
801 }
802
803 template <int dim>
804 void
806 {
807 switch (dim)
808 {
809 case 2:
810 P4EST_QUADRANT_INIT(&quad);
811 break;
812 case 3:
813 P8EST_QUADRANT_INIT(&quad);
814 break;
815 default:
816 Assert(false, ExcNotImplemented());
817 }
819 /*level=*/0,
820 /*index=*/0);
821 }
822
823 template <int dim>
824 bool
826 const typename types<dim>::quadrant &q2)
827 {
829 }
830
831
832
833 template <int dim>
834 bool
836 const typename types<dim>::quadrant &q2)
837 {
839 }
840
841 template <int dim>
842 bool
843 tree_exists_locally(const typename types<dim>::forest *parallel_forest,
845 {
846 Assert(coarse_grid_cell < parallel_forest->connectivity->num_trees,
848 return ((coarse_grid_cell >= parallel_forest->first_local_tree) &&
850 }
851
852
853
854 // template specializations
855
856 template <>
858 copy_connectivity<2>(const typename types<2>::connectivity *connectivity)
859 {
861 connectivity->num_vertices,
862 connectivity->num_trees,
863 connectivity->num_corners,
864 connectivity->vertices,
865 connectivity->tree_to_vertex,
866 connectivity->tree_to_tree,
867 connectivity->tree_to_face,
868 connectivity->tree_to_corner,
869 connectivity->ctt_offset,
870 connectivity->corner_to_tree,
871 connectivity->corner_to_corner);
872 }
873
874 template <>
876 copy_connectivity<3>(const typename types<3>::connectivity *connectivity)
877 {
879 connectivity->num_vertices,
880 connectivity->num_trees,
881 connectivity->num_edges,
882 connectivity->num_corners,
883 connectivity->vertices,
884 connectivity->tree_to_vertex,
885 connectivity->tree_to_tree,
886 connectivity->tree_to_face,
887 connectivity->tree_to_edge,
888 connectivity->ett_offset,
889 connectivity->edge_to_tree,
890 connectivity->edge_to_edge,
891 connectivity->tree_to_corner,
892 connectivity->ctt_offset,
893 connectivity->corner_to_tree,
894 connectivity->corner_to_corner);
895 }
896
897
898
899 template <>
900 bool
902 const typename types<1>::quadrant &q2)
903 {
904 return q1 == q2;
905 }
906
907
908
909 template <>
910 bool
912 types<1>::quadrant const &q2)
913 {
914 // determine level of quadrants
919
920 // q1 can be an ancestor of q2 if q1's level is smaller
921 if (level_1 >= level_2)
922 return false;
923
924 // extract path of quadrants up to level of possible ancestor q1
925 const int truncated_id_1 = (q1 >> (types<1>::n_bits - 1 - level_1))
926 << (types<1>::n_bits - 1 - level_1);
927 const int truncated_id_2 = (q2 >> (types<1>::n_bits - 1 - level_1))
928 << (types<1>::n_bits - 1 - level_1);
929
930 // compare paths
932 }
933
934
935
936 template <>
937 void
939 const typename types<1>::quadrant &q,
940 typename types<1>::quadrant (
942 {
943 // determine the current level of quadrant
946 const int level_child = level_parent + 1;
947
948 // left child: only n_child_indices has to be incremented
949 p4est_children[0] = (q + 1);
950
951 // right child: increment and set a bit to 1 indicating that it is a right
952 // child
953 p4est_children[1] = (q + 1) | (1 << (types<1>::n_bits - 1 - level_child));
954 }
955
956
957
958 template <>
959 void
961 {
962 quad = 0;
963 }
964
965 } // namespace p4est
966} // namespace internal
967
968#endif // DEAL_II_WITH_P4EST
969
970/*-------------- Explicit Instantiations -------------------------------*/
971#include "p4est_wrappers.inst"
972
973
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
Point< 3 > vertices[4]
unsigned int level
Definition grid_out.cc:4618
const unsigned int v1
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
void init_quadrant_children< 1 >(const typename types< 1 >::quadrant &q, typename types< 1 >::quadrant(&p4est_children)[::GeometryInfo< 1 >::max_children_per_cell])
void init_coarse_quadrant(typename types< dim >::quadrant &quad)
bool quadrant_is_equal< 1 >(const typename types< 1 >::quadrant &q1, const typename types< 1 >::quadrant &q2)
types< 2 >::connectivity * copy_connectivity< 2 >(const typename types< 2 >::connectivity *connectivity)
types< 3 >::connectivity * copy_connectivity< 3 >(const typename types< 3 >::connectivity *connectivity)
bool quadrant_is_equal(const typename types< dim >::quadrant &q1, const typename types< dim >::quadrant &q2)
void init_quadrant_children(const typename types< dim >::quadrant &p4est_cell, typename types< dim >::quadrant(&p4est_children)[::GeometryInfo< dim >::max_children_per_cell])
bool quadrant_is_ancestor(const typename types< dim >::quadrant &q1, const typename types< dim >::quadrant &q2)
void init_coarse_quadrant< 1 >(typename types< 1 >::quadrant &quad)
bool quadrant_is_ancestor< 1 >(types< 1 >::quadrant const &q1, types< 1 >::quadrant const &q2)
bool tree_exists_locally(const typename types< dim >::forest *parallel_forest, const typename types< dim >::topidx coarse_grid_cell)
sc_array_t * subids
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
std::map< unsigned int, std::set<::types::subdomain_id > > * vertices_with_ghost_neighbors