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