Reference documentation for deal.II version 9.4.0
\(\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\}}\)
p4est_wrappers.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2016 - 2021 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#ifndef dealii_p4est_wrappers_h
17#define dealii_p4est_wrappers_h
18
19#include <deal.II/base/config.h>
20
22
23#ifdef DEAL_II_WITH_P4EST
24# include <p4est_bits.h>
25# include <p4est_communication.h>
26# include <p4est_extended.h>
27# include <p4est_ghost.h>
28# include <p4est_iterate.h>
29# include <p4est_search.h>
30# include <p4est_vtk.h>
31# include <p8est_bits.h>
32# include <p8est_communication.h>
33# include <p8est_extended.h>
34# include <p8est_ghost.h>
35# include <p8est_iterate.h>
36# include <p8est_search.h>
37# include <p8est_vtk.h>
38
39# include <map>
40# include <set>
41
42
44
45// Forward declaration
46# ifndef DOXYGEN
47namespace parallel
48{
49 namespace distributed
50 {
51 template <int dim, int spacedim>
52 class Triangulation;
53 }
54} // namespace parallel
55# endif
56
57namespace internal
58{
59 namespace p4est
60 {
68 template <int>
69 struct types;
70
71 // these struct mimics p4est for 1D
72 template <>
73 struct types<1>
74 {
75 // id of a quadrant is an integeger
76 using quadrant = int;
77
78 // maximum number of children
79 static const int max_n_child_indices_bits = 27;
80
81 // number of bits the data type of id has
82 static const int n_bits = std::numeric_limits<quadrant>::digits;
83 };
84
85 template <>
86 struct types<2>
87 {
88 using connectivity = p4est_connectivity_t;
89 using forest = p4est_t;
90 using tree = p4est_tree_t;
91 using quadrant = p4est_quadrant_t;
92 using quadrant_coord = p4est_qcoord_t;
93 using topidx = p4est_topidx_t;
94 using locidx = p4est_locidx_t;
95 using gloidx = p4est_gloidx_t;
96 using balance_type = p4est_connect_type_t;
97 using ghost = p4est_ghost_t;
98 using transfer_context = p4est_transfer_context_t;
99# ifdef P4EST_SEARCH_LOCAL
100 using search_partition_callback = p4est_search_partition_t;
101# endif
102 };
103
104 template <>
105 struct types<3>
106 {
107 using connectivity = p8est_connectivity_t;
108 using forest = p8est_t;
109 using tree = p8est_tree_t;
110 using quadrant = p8est_quadrant_t;
111 using quadrant_coord = p4est_qcoord_t;
112 using topidx = p4est_topidx_t;
113 using locidx = p4est_locidx_t;
114 using gloidx = p4est_gloidx_t;
115 using balance_type = p8est_connect_type_t;
116 using ghost = p8est_ghost_t;
117 using transfer_context = p8est_transfer_context_t;
118# ifdef P4EST_SEARCH_LOCAL
119 using search_partition_callback = p8est_search_partition_t;
120# endif
121 };
122
123
124
132 template <int dim>
133 struct functions;
134
135 template <>
136 struct functions<2>
137 {
138 static int (&quadrant_compare)(const void *v1, const void *v2);
139
140 static void (&quadrant_childrenv)(const types<2>::quadrant *q,
142
143 static int (&quadrant_overlaps_tree)(types<2>::tree * tree,
144 const types<2>::quadrant *q);
145
146 static void (&quadrant_set_morton)(types<2>::quadrant *quadrant,
147 int level,
148 std::uint64_t id);
149
151 const types<2>::quadrant *q2);
152
153 static int (&quadrant_is_sibling)(const types<2>::quadrant *q1,
154 const types<2>::quadrant *q2);
155
157 const types<2>::quadrant *q2);
158
159 static int (&quadrant_ancestor_id)(const types<2>::quadrant *q,
160 int level);
161
162 static int (&comm_find_owner)(types<2>::forest * p4est,
163 const types<2>::locidx which_tree,
164 const types<2>::quadrant *q,
165 const int guess);
166
168 types<2>::topidx num_vertices,
169 types<2>::topidx num_trees,
170 types<2>::topidx num_corners,
171 types<2>::topidx num_vtt);
172
174 types<2>::topidx num_vertices,
175 types<2>::topidx num_trees,
176 types<2>::topidx num_corners,
177 const double * vertices,
178 const types<2>::topidx *ttv,
179 const types<2>::topidx *ttt,
180 const int8_t * ttf,
181 const types<2>::topidx *ttc,
182 const types<2>::topidx *coff,
183 const types<2>::topidx *ctt,
184 const int8_t * ctc);
185
186 static void (&connectivity_join_faces)(types<2>::connectivity *conn,
187 types<2>::topidx tree_left,
188 types<2>::topidx tree_right,
189 int face_left,
190 int face_right,
191 int orientation);
192
193
194
195 static void (&connectivity_destroy)(p4est_connectivity_t *connectivity);
196
198 MPI_Comm mpicomm,
199 types<2>::connectivity *connectivity,
200 types<2>::locidx min_quadrants,
201 int min_level,
202 int fill_uniform,
203 std::size_t data_size,
204 p4est_init_t init_fn,
205 void * user_pointer);
206
208 int copy_data);
209
210 static void (&destroy)(types<2>::forest *p4est);
211
212 static void (&refine)(types<2>::forest *p4est,
213 int refine_recursive,
214 p4est_refine_t refine_fn,
215 p4est_init_t init_fn);
216
217 static void (&coarsen)(types<2>::forest *p4est,
218 int coarsen_recursive,
219 p4est_coarsen_t coarsen_fn,
220 p4est_init_t init_fn);
221
222 static void (&balance)(types<2>::forest * p4est,
224 p4est_init_t init_fn);
225
227 int partition_for_coarsening,
228 p4est_weight_t weight_fn);
229
230 static void (&save)(const char * filename,
231 types<2>::forest *p4est,
232 int save_data);
233
234 static types<2>::forest *(&load_ext)(const char *filename,
235 MPI_Comm mpicomm,
236 std::size_t data_size,
237 int load_data,
238 int autopartition,
239 int broadcasthead,
240 void * user_pointer,
241 types<2>::connectivity **p4est);
242
243 static int (&connectivity_save)(const char * filename,
244 types<2>::connectivity *connectivity);
245
246 static int (&connectivity_is_valid)(types<2>::connectivity *connectivity);
247
248 static types<2>::connectivity *(&connectivity_load)(const char * filename,
249 std::size_t *length);
250
251 static unsigned int (&checksum)(types<2>::forest *p4est);
252
253 static void (&vtk_write_file)(types<2>::forest *p4est,
254 p4est_geometry_t *,
255 const char *baseName);
256
259
260 static void (&ghost_destroy)(types<2>::ghost *ghost);
261
262 static void (&reset_data)(types<2>::forest *p4est,
263 std::size_t data_size,
264 p4est_init_t init_fn,
265 void * user_pointer);
266
267 static std::size_t (&forest_memory_used)(types<2>::forest *p4est);
268
269 static std::size_t (&connectivity_memory_used)(
271
272 template <int spacedim>
273 static void
275 ::internal::p4est::types<2>::ghost * parallel_ghost,
276 void * user_data);
277
278 static constexpr unsigned int max_level = P4EST_MAXLEVEL;
279
280 static void (&transfer_fixed)(const types<2>::gloidx *dest_gfq,
281 const types<2>::gloidx *src_gfq,
282 MPI_Comm mpicomm,
283 int tag,
284 void * dest_data,
285 const void * src_data,
286 std::size_t data_size);
287
289 const types<2>::gloidx *dest_gfq,
290 const types<2>::gloidx *src_gfq,
291 MPI_Comm mpicomm,
292 int tag,
293 void * dest_data,
294 const void * src_data,
295 std::size_t data_size);
296
297 static void (&transfer_fixed_end)(types<2>::transfer_context *tc);
298
299 static void (&transfer_custom)(const types<2>::gloidx *dest_gfq,
300 const types<2>::gloidx *src_gfq,
301 MPI_Comm mpicomm,
302 int tag,
303 void * dest_data,
304 const int * dest_sizes,
305 const void * src_data,
306 const int * src_sizes);
307
309 const types<2>::gloidx *dest_gfq,
310 const types<2>::gloidx *src_gfq,
311 MPI_Comm mpicomm,
312 int tag,
313 void * dest_data,
314 const int * dest_sizes,
315 const void * src_data,
316 const int * src_sizes);
317
318 static void (&transfer_custom_end)(types<2>::transfer_context *tc);
319
320# ifdef P4EST_SEARCH_LOCAL
321 static void (&search_partition)(
322 types<2>::forest * forest,
323 int call_post,
326 sc_array_t * points);
327# endif
328
329 static void (&quadrant_coord_to_vertex)(
330 types<2>::connectivity * connectivity,
331 types<2>::topidx treeid,
334 double vxyz[3]);
335 };
336
337
338 template <>
339 struct functions<3>
340 {
341 static int (&quadrant_compare)(const void *v1, const void *v2);
342
343 static void (&quadrant_childrenv)(const types<3>::quadrant *q,
345
346 static int (&quadrant_overlaps_tree)(types<3>::tree * tree,
347 const types<3>::quadrant *q);
348
349 static void (&quadrant_set_morton)(types<3>::quadrant *quadrant,
350 int level,
351 std::uint64_t id);
352
354 const types<3>::quadrant *q2);
355
356 static int (&quadrant_is_sibling)(const types<3>::quadrant *q1,
357 const types<3>::quadrant *q2);
358
360 const types<3>::quadrant *q2);
361 static int (&quadrant_ancestor_id)(const types<3>::quadrant *q,
362 int level);
363
364 static int (&comm_find_owner)(types<3>::forest * p4est,
365 const types<3>::locidx which_tree,
366 const types<3>::quadrant *q,
367 const int guess);
368
370 types<3>::topidx num_vertices,
371 types<3>::topidx num_trees,
372 types<3>::topidx num_edges,
373 types<3>::topidx num_ett,
374 types<3>::topidx num_corners,
375 types<3>::topidx num_ctt);
376
378 types<3>::topidx num_vertices,
379 types<3>::topidx num_trees,
380 types<3>::topidx num_edges,
381 types<3>::topidx num_corners,
382 const double * vertices,
383 const types<3>::topidx *ttv,
384 const types<3>::topidx *ttt,
385 const int8_t * ttf,
386 const types<3>::topidx *tte,
387 const types<3>::topidx *eoff,
388 const types<3>::topidx *ett,
389 const int8_t * ete,
390 const types<3>::topidx *ttc,
391 const types<3>::topidx *coff,
392 const types<3>::topidx *ctt,
393 const int8_t * ctc);
394
395 static void (&connectivity_join_faces)(types<3>::connectivity *conn,
396 types<3>::topidx tree_left,
397 types<3>::topidx tree_right,
398 int face_left,
399 int face_right,
400 int orientation);
401
402 static void (&connectivity_destroy)(p8est_connectivity_t *connectivity);
403
405 MPI_Comm mpicomm,
406 types<3>::connectivity *connectivity,
407 types<3>::locidx min_quadrants,
408 int min_level,
409 int fill_uniform,
410 std::size_t data_size,
411 p8est_init_t init_fn,
412 void * user_pointer);
413
415 int copy_data);
416
417 static void (&destroy)(types<3>::forest *p8est);
418
419 static void (&refine)(types<3>::forest *p8est,
420 int refine_recursive,
421 p8est_refine_t refine_fn,
422 p8est_init_t init_fn);
423
424 static void (&coarsen)(types<3>::forest *p8est,
425 int coarsen_recursive,
426 p8est_coarsen_t coarsen_fn,
427 p8est_init_t init_fn);
428
429 static void (&balance)(types<3>::forest * p8est,
431 p8est_init_t init_fn);
432
434 int partition_for_coarsening,
435 p8est_weight_t weight_fn);
436
437 static void (&save)(const char * filename,
438 types<3>::forest *p4est,
439 int save_data);
440
441 static types<3>::forest *(&load_ext)(const char *filename,
442 MPI_Comm mpicomm,
443 std::size_t data_size,
444 int load_data,
445 int autopartition,
446 int broadcasthead,
447 void * user_pointer,
448 types<3>::connectivity **p4est);
449
450 static int (&connectivity_save)(const char * filename,
451 types<3>::connectivity *connectivity);
452
453 static int (&connectivity_is_valid)(types<3>::connectivity *connectivity);
454
455 static types<3>::connectivity *(&connectivity_load)(const char * filename,
456 std::size_t *length);
457
458 static unsigned int (&checksum)(types<3>::forest *p8est);
459
460 static void (&vtk_write_file)(types<3>::forest *p8est,
461 p8est_geometry_t *,
462 const char *baseName);
465
466 static void (&ghost_destroy)(types<3>::ghost *ghost);
467
468 static void (&reset_data)(types<3>::forest *p4est,
469 std::size_t data_size,
470 p8est_init_t init_fn,
471 void * user_pointer);
472
473 static std::size_t (&forest_memory_used)(types<3>::forest *p4est);
474
475 static std::size_t (&connectivity_memory_used)(
477
478 static constexpr unsigned int max_level = P8EST_MAXLEVEL;
479
480 static void (&transfer_fixed)(const types<3>::gloidx *dest_gfq,
481 const types<3>::gloidx *src_gfq,
482 MPI_Comm mpicomm,
483 int tag,
484 void * dest_data,
485 const void * src_data,
486 std::size_t data_size);
487
489 const types<3>::gloidx *dest_gfq,
490 const types<3>::gloidx *src_gfq,
491 MPI_Comm mpicomm,
492 int tag,
493 void * dest_data,
494 const void * src_data,
495 std::size_t data_size);
496
497 static void (&transfer_fixed_end)(types<3>::transfer_context *tc);
498
499 static void (&transfer_custom)(const types<3>::gloidx *dest_gfq,
500 const types<3>::gloidx *src_gfq,
501 MPI_Comm mpicomm,
502 int tag,
503 void * dest_data,
504 const int * dest_sizes,
505 const void * src_data,
506 const int * src_sizes);
507
509 const types<3>::gloidx *dest_gfq,
510 const types<3>::gloidx *src_gfq,
511 MPI_Comm mpicomm,
512 int tag,
513 void * dest_data,
514 const int * dest_sizes,
515 const void * src_data,
516 const int * src_sizes);
517
518 static void (&transfer_custom_end)(types<3>::transfer_context *tc);
519
520# ifdef P4EST_SEARCH_LOCAL
521 static void (&search_partition)(
522 types<3>::forest * forest,
523 int call_post,
526 sc_array_t * points);
527# endif
528
529 static void (&quadrant_coord_to_vertex)(
530 types<3>::connectivity * connectivity,
531 types<3>::topidx treeid,
535 double vxyz[3]);
536 };
537
538
539
546 template <int dim>
547 struct iter;
548
549 template <>
550 struct iter<2>
551 {
552 using corner_info = p4est_iter_corner_info_t;
553 using corner_side = p4est_iter_corner_side_t;
554 using corner_iter = p4est_iter_corner_t;
555 using face_info = p4est_iter_face_info_t;
556 using face_side = p4est_iter_face_side_t;
557 using face_iter = p4est_iter_face_t;
558 };
559
560 template <>
561 struct iter<3>
562 {
563 using corner_info = p8est_iter_corner_info_t;
564 using corner_side = p8est_iter_corner_side_t;
565 using corner_iter = p8est_iter_corner_t;
566 using edge_info = p8est_iter_edge_info_t;
567 using edge_side = p8est_iter_edge_side_t;
568 using edge_iter = p8est_iter_edge_t;
569 using face_info = p8est_iter_face_info_t;
570 using face_side = p8est_iter_face_side_t;
571 using face_iter = p8est_iter_face_t;
572 };
573
574
575
580 template <int dim>
581 void
583 const typename types<dim>::quadrant &p4est_cell,
584 typename types<dim>::quadrant (
586
587
588
592 template <int dim>
593 void
595
596
597
601 template <int dim>
602 bool
603 quadrant_is_equal(const typename types<dim>::quadrant &q1,
604 const typename types<dim>::quadrant &q2);
605
606
607
611 template <int dim>
612 bool
614 const typename types<dim>::quadrant &q2);
615
616
617
621 template <int dim>
622 bool
623 tree_exists_locally(const typename types<dim>::forest *parallel_forest,
624 const typename types<dim>::topidx coarse_grid_cell);
625
626
630 template <int dim>
631 typename types<dim>::connectivity *
632 copy_connectivity(const typename types<dim>::connectivity *connectivity);
633
634# ifndef DOXYGEN
635 template <>
636 typename types<2>::connectivity *
637 copy_connectivity<2>(const typename types<2>::connectivity *connectivity);
638
639 template <>
640 typename types<3>::connectivity *
641 copy_connectivity<3>(const typename types<3>::connectivity *connectivity);
642# endif
643 } // namespace p4est
644} // namespace internal
645
647
648#endif // DEAL_II_WITH_P4EST
649
650#endif // dealii_p4est_wrappers_h
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
Point< 3 > vertices[4]
unsigned int level
Definition: grid_out.cc:4606
const unsigned int v1
Definition: grid_tools.cc:1000
void refine(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold, const unsigned int max_to_mark=numbers::invalid_unsigned_int)
void coarsen(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold)
void partition(const SparsityPattern &sparsity_pattern, const unsigned int n_partitions, std::vector< unsigned int > &partition_indices, const Partitioner partitioner=Partitioner::metis)
void init_coarse_quadrant(typename types< dim >::quadrant &quad)
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)
bool tree_exists_locally(const typename types< dim >::forest *parallel_forest, const typename types< dim >::topidx coarse_grid_cell)
types< dim >::connectivity * copy_connectivity(const typename types< dim >::connectivity *connectivity)
Definition: types.h:32
static types< 2 >::forest *(&) new_forest(MPI_Comm mpicomm, types< 2 >::connectivity *connectivity, types< 2 >::locidx min_quadrants, int min_level, int fill_uniform, std::size_t data_size, p4est_init_t init_fn, void *user_pointer)
static types< 2 >::forest *(&) copy_forest(types< 2 >::forest *input, int copy_data)
static types< 2 >::connectivity *(&) connectivity_new(types< 2 >::topidx num_vertices, types< 2 >::topidx num_trees, types< 2 >::topidx num_corners, types< 2 >::topidx num_vtt)
static types< 2 >::forest *(&) load_ext(const char *filename, MPI_Comm mpicomm, std::size_t data_size, int load_data, int autopartition, int broadcasthead, void *user_pointer, types< 2 >::connectivity **p4est)
static types< 2 >::connectivity *(&) connectivity_load(const char *filename, std::size_t *length)
static types< 2 >::connectivity *(&) connectivity_new_copy(types< 2 >::topidx num_vertices, types< 2 >::topidx num_trees, types< 2 >::topidx num_corners, const double *vertices, const types< 2 >::topidx *ttv, const types< 2 >::topidx *ttt, const int8_t *ttf, const types< 2 >::topidx *ttc, const types< 2 >::topidx *coff, const types< 2 >::topidx *ctt, const int8_t *ctc)
static void iterate(::internal::p4est::types< 2 >::forest *parallel_forest, ::internal::p4est::types< 2 >::ghost *parallel_ghost, void *user_data)
static types< 2 >::transfer_context *(&) transfer_fixed_begin(const types< 2 >::gloidx *dest_gfq, const types< 2 >::gloidx *src_gfq, MPI_Comm mpicomm, int tag, void *dest_data, const void *src_data, std::size_t data_size)
static types< 2 >::ghost *(&) ghost_new(types< 2 >::forest *p4est, types< 2 >::balance_type btype)
static types< 2 >::transfer_context *(&) transfer_custom_begin(const types< 2 >::gloidx *dest_gfq, const types< 2 >::gloidx *src_gfq, MPI_Comm mpicomm, int tag, void *dest_data, const int *dest_sizes, const void *src_data, const int *src_sizes)
static types< 3 >::connectivity *(&) connectivity_new_copy(types< 3 >::topidx num_vertices, types< 3 >::topidx num_trees, types< 3 >::topidx num_edges, types< 3 >::topidx num_corners, const double *vertices, const types< 3 >::topidx *ttv, const types< 3 >::topidx *ttt, const int8_t *ttf, const types< 3 >::topidx *tte, const types< 3 >::topidx *eoff, const types< 3 >::topidx *ett, const int8_t *ete, const types< 3 >::topidx *ttc, const types< 3 >::topidx *coff, const types< 3 >::topidx *ctt, const int8_t *ctc)
static types< 3 >::forest *(&) load_ext(const char *filename, MPI_Comm mpicomm, std::size_t data_size, int load_data, int autopartition, int broadcasthead, void *user_pointer, types< 3 >::connectivity **p4est)
static types< 3 >::transfer_context *(&) transfer_custom_begin(const types< 3 >::gloidx *dest_gfq, const types< 3 >::gloidx *src_gfq, MPI_Comm mpicomm, int tag, void *dest_data, const int *dest_sizes, const void *src_data, const int *src_sizes)
static types< 3 >::ghost *(&) ghost_new(types< 3 >::forest *p4est, types< 3 >::balance_type btype)
static types< 3 >::connectivity *(&) connectivity_new(types< 3 >::topidx num_vertices, types< 3 >::topidx num_trees, types< 3 >::topidx num_edges, types< 3 >::topidx num_ett, types< 3 >::topidx num_corners, types< 3 >::topidx num_ctt)
static types< 3 >::connectivity *(&) connectivity_load(const char *filename, std::size_t *length)
static types< 3 >::forest *(&) copy_forest(types< 3 >::forest *input, int copy_data)
static types< 3 >::transfer_context *(&) transfer_fixed_begin(const types< 3 >::gloidx *dest_gfq, const types< 3 >::gloidx *src_gfq, MPI_Comm mpicomm, int tag, void *dest_data, const void *src_data, std::size_t data_size)
static types< 3 >::forest *(&) new_forest(MPI_Comm mpicomm, types< 3 >::connectivity *connectivity, types< 3 >::locidx min_quadrants, int min_level, int fill_uniform, std::size_t data_size, p8est_init_t init_fn, void *user_pointer)
p4est_iter_corner_t corner_iter
p4est_iter_corner_info_t corner_info
p4est_iter_face_info_t face_info
p4est_iter_face_side_t face_side
p4est_iter_corner_side_t corner_side
p4est_iter_face_t face_iter
p8est_iter_corner_t corner_iter
p8est_iter_corner_info_t corner_info
p8est_iter_face_info_t face_info
p8est_iter_edge_side_t edge_side
p8est_iter_edge_t edge_iter
p8est_iter_edge_info_t edge_info
p8est_iter_face_side_t face_side
p8est_iter_face_t face_iter
p8est_iter_corner_side_t corner_side
p4est_connectivity_t connectivity
p4est_connect_type_t balance_type
p4est_transfer_context_t transfer_context
p8est_connectivity_t connectivity
p8est_transfer_context_t transfer_context
p8est_connect_type_t balance_type