Reference documentation for deal.II version Git ac854ef673 2021-03-06 10:09:45 +0100
\(\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 - 2020 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_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_vtk.h>
36 
37 # include <map>
38 # include <set>
39 
40 
42 
43 // Forward declaration
44 # ifndef DOXYGEN
45 namespace parallel
46 {
47  namespace distributed
48  {
49  template <int dim, int spacedim>
50  class Triangulation;
51  }
52 } // namespace parallel
53 # endif
54 
55 namespace 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 topidx = p4est_topidx_t;
91  using locidx = p4est_locidx_t;
92  using gloidx = p4est_gloidx_t;
93  using balance_type = p4est_connect_type_t;
94  using ghost = p4est_ghost_t;
95  using transfer_context = p4est_transfer_context_t;
96  };
97 
98  template <>
99  struct types<3>
100  {
101  using connectivity = p8est_connectivity_t;
102  using forest = p8est_t;
103  using tree = p8est_tree_t;
104  using quadrant = p8est_quadrant_t;
105  using topidx = p4est_topidx_t;
106  using locidx = p4est_locidx_t;
107  using gloidx = p4est_gloidx_t;
108  using balance_type = p8est_connect_type_t;
109  using ghost = p8est_ghost_t;
110  using transfer_context = p8est_transfer_context_t;
111  };
112 
113 
114 
122  template <int dim>
123  struct functions;
124 
125  template <>
126  struct functions<2>
127  {
128  static int (&quadrant_compare)(const void *v1, const void *v2);
129 
130  static void (&quadrant_childrenv)(const types<2>::quadrant *q,
131  types<2>::quadrant c[]);
132 
133  static int (&quadrant_overlaps_tree)(types<2>::tree * tree,
134  const types<2>::quadrant *q);
135 
136  static void (&quadrant_set_morton)(types<2>::quadrant *quadrant,
137  int level,
138  uint64_t id);
139 
141  const types<2>::quadrant *q2);
142 
143  static int (&quadrant_is_sibling)(const types<2>::quadrant *q1,
144  const types<2>::quadrant *q2);
145 
147  const types<2>::quadrant *q2);
148 
149  static int (&quadrant_ancestor_id)(const types<2>::quadrant *q,
150  int level);
151 
152  static int (&comm_find_owner)(types<2>::forest * p4est,
153  const types<2>::locidx which_tree,
154  const types<2>::quadrant *q,
155  const int guess);
156 
158  types<2>::topidx num_vertices,
159  types<2>::topidx num_trees,
160  types<2>::topidx num_corners,
161  types<2>::topidx num_vtt);
162  static void (&connectivity_join_faces)(types<2>::connectivity *conn,
163  types<2>::topidx tree_left,
164  types<2>::topidx tree_right,
165  int face_left,
166  int face_right,
167  int orientation);
168 
169 
170 
171  static void (&connectivity_destroy)(p4est_connectivity_t *connectivity);
172 
174  MPI_Comm mpicomm,
175  types<2>::connectivity *connectivity,
176  types<2>::locidx min_quadrants,
177  int min_level,
178  int fill_uniform,
179  std::size_t data_size,
180  p4est_init_t init_fn,
181  void * user_pointer);
182 
184  int copy_data);
185 
186  static void (&destroy)(types<2>::forest *p4est);
187 
188  static void (&refine)(types<2>::forest *p4est,
189  int refine_recursive,
190  p4est_refine_t refine_fn,
191  p4est_init_t init_fn);
192 
193  static void (&coarsen)(types<2>::forest *p4est,
194  int coarsen_recursive,
195  p4est_coarsen_t coarsen_fn,
196  p4est_init_t init_fn);
197 
198  static void (&balance)(types<2>::forest * p4est,
200  p4est_init_t init_fn);
201 
203  int partition_for_coarsening,
204  p4est_weight_t weight_fn);
205 
206  static void (&save)(const char * filename,
207  types<2>::forest *p4est,
208  int save_data);
209 
210  static types<2>::forest *(&load_ext)(const char *filename,
211  MPI_Comm mpicomm,
212  std::size_t data_size,
213  int load_data,
214  int autopartition,
215  int broadcasthead,
216  void * user_pointer,
217  types<2>::connectivity **p4est);
218 
219  static int (&connectivity_save)(const char * filename,
220  types<2>::connectivity *connectivity);
221 
222  static int (&connectivity_is_valid)(types<2>::connectivity *connectivity);
223 
224  static types<2>::connectivity *(&connectivity_load)(const char * filename,
225  std::size_t *length);
226 
227  static unsigned int (&checksum)(types<2>::forest *p4est);
228 
229  static void (&vtk_write_file)(types<2>::forest *p4est,
230  p4est_geometry_t *,
231  const char *baseName);
232 
234  types<2>::balance_type btype);
235 
236  static void (&ghost_destroy)(types<2>::ghost *ghost);
237 
238  static void (&reset_data)(types<2>::forest *p4est,
239  std::size_t data_size,
240  p4est_init_t init_fn,
241  void * user_pointer);
242 
243  static std::size_t (&forest_memory_used)(types<2>::forest *p4est);
244 
245  static std::size_t (&connectivity_memory_used)(
246  types<2>::connectivity *p4est);
247 
248  template <int spacedim>
249  static void
250  iterate(::internal::p4est::types<2>::forest *parallel_forest,
251  ::internal::p4est::types<2>::ghost * parallel_ghost,
252  void * user_data);
253 
254  static constexpr unsigned int max_level = P4EST_MAXLEVEL;
255 
256  static void (&transfer_fixed)(const types<2>::gloidx *dest_gfq,
257  const types<2>::gloidx *src_gfq,
258  MPI_Comm mpicomm,
259  int tag,
260  void * dest_data,
261  const void * src_data,
262  std::size_t data_size);
263 
265  const types<2>::gloidx *dest_gfq,
266  const types<2>::gloidx *src_gfq,
267  MPI_Comm mpicomm,
268  int tag,
269  void * dest_data,
270  const void * src_data,
271  std::size_t data_size);
272 
273  static void (&transfer_fixed_end)(types<2>::transfer_context *tc);
274 
275  static void (&transfer_custom)(const types<2>::gloidx *dest_gfq,
276  const types<2>::gloidx *src_gfq,
277  MPI_Comm mpicomm,
278  int tag,
279  void * dest_data,
280  const int * dest_sizes,
281  const void * src_data,
282  const int * src_sizes);
283 
285  const types<2>::gloidx *dest_gfq,
286  const types<2>::gloidx *src_gfq,
287  MPI_Comm mpicomm,
288  int tag,
289  void * dest_data,
290  const int * dest_sizes,
291  const void * src_data,
292  const int * src_sizes);
293 
294  static void (&transfer_custom_end)(types<2>::transfer_context *tc);
295  };
296 
297 
298  template <>
299  struct functions<3>
300  {
301  static int (&quadrant_compare)(const void *v1, const void *v2);
302 
303  static void (&quadrant_childrenv)(const types<3>::quadrant *q,
304  types<3>::quadrant c[]);
305 
306  static int (&quadrant_overlaps_tree)(types<3>::tree * tree,
307  const types<3>::quadrant *q);
308 
309  static void (&quadrant_set_morton)(types<3>::quadrant *quadrant,
310  int level,
311  uint64_t id);
312 
314  const types<3>::quadrant *q2);
315 
316  static int (&quadrant_is_sibling)(const types<3>::quadrant *q1,
317  const types<3>::quadrant *q2);
318 
320  const types<3>::quadrant *q2);
321  static int (&quadrant_ancestor_id)(const types<3>::quadrant *q,
322  int level);
323 
324  static int (&comm_find_owner)(types<3>::forest * p4est,
325  const types<3>::locidx which_tree,
326  const types<3>::quadrant *q,
327  const int guess);
328 
330  types<3>::topidx num_vertices,
331  types<3>::topidx num_trees,
332  types<3>::topidx num_edges,
333  types<3>::topidx num_ett,
334  types<3>::topidx num_corners,
335  types<3>::topidx num_ctt);
336 
337  static void (&connectivity_join_faces)(types<3>::connectivity *conn,
338  types<3>::topidx tree_left,
339  types<3>::topidx tree_right,
340  int face_left,
341  int face_right,
342  int orientation);
343 
344  static void (&connectivity_destroy)(p8est_connectivity_t *connectivity);
345 
347  MPI_Comm mpicomm,
348  types<3>::connectivity *connectivity,
349  types<3>::locidx min_quadrants,
350  int min_level,
351  int fill_uniform,
352  std::size_t data_size,
353  p8est_init_t init_fn,
354  void * user_pointer);
355 
357  int copy_data);
358 
359  static void (&destroy)(types<3>::forest *p8est);
360 
361  static void (&refine)(types<3>::forest *p8est,
362  int refine_recursive,
363  p8est_refine_t refine_fn,
364  p8est_init_t init_fn);
365 
366  static void (&coarsen)(types<3>::forest *p8est,
367  int coarsen_recursive,
368  p8est_coarsen_t coarsen_fn,
369  p8est_init_t init_fn);
370 
371  static void (&balance)(types<3>::forest * p8est,
373  p8est_init_t init_fn);
374 
376  int partition_for_coarsening,
377  p8est_weight_t weight_fn);
378 
379  static void (&save)(const char * filename,
380  types<3>::forest *p4est,
381  int save_data);
382 
383  static types<3>::forest *(&load_ext)(const char *filename,
384  MPI_Comm mpicomm,
385  std::size_t data_size,
386  int load_data,
387  int autopartition,
388  int broadcasthead,
389  void * user_pointer,
390  types<3>::connectivity **p4est);
391 
392  static int (&connectivity_save)(const char * filename,
393  types<3>::connectivity *connectivity);
394 
395  static int (&connectivity_is_valid)(types<3>::connectivity *connectivity);
396 
397  static types<3>::connectivity *(&connectivity_load)(const char * filename,
398  std::size_t *length);
399 
400  static unsigned int (&checksum)(types<3>::forest *p8est);
401 
402  static void (&vtk_write_file)(types<3>::forest *p8est,
403  p8est_geometry_t *,
404  const char *baseName);
406  types<3>::balance_type btype);
407 
408  static void (&ghost_destroy)(types<3>::ghost *ghost);
409 
410  static void (&reset_data)(types<3>::forest *p4est,
411  std::size_t data_size,
412  p8est_init_t init_fn,
413  void * user_pointer);
414 
415  static std::size_t (&forest_memory_used)(types<3>::forest *p4est);
416 
417  static std::size_t (&connectivity_memory_used)(
418  types<3>::connectivity *p4est);
419 
420  static constexpr unsigned int max_level = P8EST_MAXLEVEL;
421 
422  static void (&transfer_fixed)(const types<3>::gloidx *dest_gfq,
423  const types<3>::gloidx *src_gfq,
424  MPI_Comm mpicomm,
425  int tag,
426  void * dest_data,
427  const void * src_data,
428  std::size_t data_size);
429 
431  const types<3>::gloidx *dest_gfq,
432  const types<3>::gloidx *src_gfq,
433  MPI_Comm mpicomm,
434  int tag,
435  void * dest_data,
436  const void * src_data,
437  std::size_t data_size);
438 
439  static void (&transfer_fixed_end)(types<3>::transfer_context *tc);
440 
441  static void (&transfer_custom)(const types<3>::gloidx *dest_gfq,
442  const types<3>::gloidx *src_gfq,
443  MPI_Comm mpicomm,
444  int tag,
445  void * dest_data,
446  const int * dest_sizes,
447  const void * src_data,
448  const int * src_sizes);
449 
451  const types<3>::gloidx *dest_gfq,
452  const types<3>::gloidx *src_gfq,
453  MPI_Comm mpicomm,
454  int tag,
455  void * dest_data,
456  const int * dest_sizes,
457  const void * src_data,
458  const int * src_sizes);
459 
460  static void (&transfer_custom_end)(types<3>::transfer_context *tc);
461  };
462 
463 
464 
471  template <int dim>
472  struct iter;
473 
474  template <>
475  struct iter<2>
476  {
477  using corner_info = p4est_iter_corner_info_t;
478  using corner_side = p4est_iter_corner_side_t;
479  using corner_iter = p4est_iter_corner_t;
480  using face_info = p4est_iter_face_info_t;
481  using face_side = p4est_iter_face_side_t;
482  using face_iter = p4est_iter_face_t;
483  };
484 
485  template <>
486  struct iter<3>
487  {
488  using corner_info = p8est_iter_corner_info_t;
489  using corner_side = p8est_iter_corner_side_t;
490  using corner_iter = p8est_iter_corner_t;
491  using edge_info = p8est_iter_edge_info_t;
492  using edge_side = p8est_iter_edge_side_t;
493  using edge_iter = p8est_iter_edge_t;
494  using face_info = p8est_iter_face_info_t;
495  using face_side = p8est_iter_face_side_t;
496  using face_iter = p8est_iter_face_t;
497  };
498 
499 
500 
505  template <int dim>
506  void
508  const typename types<dim>::quadrant &p4est_cell,
509  typename types<dim>::quadrant (
510  &p4est_children)[::GeometryInfo<dim>::max_children_per_cell]);
511 
512 
513 
517  template <int dim>
518  void
520 
521 
522 
526  template <int dim>
527  bool
528  quadrant_is_equal(const typename types<dim>::quadrant &q1,
529  const typename types<dim>::quadrant &q2);
530 
531 
532 
536  template <int dim>
537  bool
538  quadrant_is_ancestor(const typename types<dim>::quadrant &q1,
539  const typename types<dim>::quadrant &q2);
540 
541 
542 
546  template <int dim>
547  bool
548  tree_exists_locally(const typename types<dim>::forest *parallel_forest,
549  const typename types<dim>::topidx coarse_grid_cell);
550 
551  } // namespace p4est
552 } // namespace internal
553 
555 
556 #endif // DEAL_II_WITH_P4EST
557 
558 #endif // dealii_p4est_wrappers_h
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)
p8est_transfer_context_t transfer_context
p8est_iter_corner_side_t corner_side
bool tree_exists_locally(const typename types< dim >::forest *parallel_forest, const typename types< dim >::topidx coarse_grid_cell)
p8est_iter_face_t face_iter
p4est_iter_face_info_t face_info
p4est_iter_corner_info_t corner_info
p4est_connect_type_t balance_type
static types< 2 >::forest *(&) copy_forest(types< 2 >::forest *input, int copy_data)
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_face_t face_iter
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)
p8est_iter_face_side_t face_side
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)
p8est_connect_type_t balance_type
p4est_iter_face_side_t face_side
bool quadrant_is_equal(const typename types< dim >::quadrant &q1, const typename types< dim >::quadrant &q2)
p4est_connectivity_t connectivity
void init_quadrant_children(const typename types< dim >::quadrant &p4est_cell, typename types< dim >::quadrant(&p4est_children)[::GeometryInfo< dim >::max_children_per_cell])
void init_coarse_quadrant(typename types< dim >::quadrant &quad)
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)
p8est_connectivity_t connectivity
Definition: types.h:31
void partition(const SparsityPattern &sparsity_pattern, const unsigned int n_partitions, std::vector< unsigned int > &partition_indices, const Partitioner partitioner=Partitioner::metis)
p4est_iter_corner_side_t corner_side
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)
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:394
unsigned int level
Definition: grid_out.cc:4578
bool quadrant_is_ancestor(const typename types< dim >::quadrant &q1, const typename types< dim >::quadrant &q2)
p8est_iter_corner_info_t corner_info
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 >::connectivity *(&) connectivity_load(const char *filename, std::size_t *length)
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)
void coarsen(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold)
p8est_iter_edge_info_t edge_info
static types< 3 >::forest *(&) copy_forest(types< 3 >::forest *input, int copy_data)
static types< 3 >::ghost *(&) ghost_new(types< 3 >::forest *p4est, types< 3 >::balance_type btype)
p8est_iter_corner_t corner_iter
static types< 2 >::ghost *(&) ghost_new(types< 2 >::forest *p4est, types< 2 >::balance_type btype)
p8est_iter_face_info_t face_info
static types< 2 >::connectivity *(&) connectivity_load(const char *filename, std::size_t *length)
p4est_transfer_context_t transfer_context
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:393
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< 2 >::connectivity *(&) connectivity_new(types< 2 >::topidx num_vertices, types< 2 >::topidx num_trees, types< 2 >::topidx num_corners, types< 2 >::topidx num_vtt)
void refine(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold, const unsigned int max_to_mark=numbers::invalid_unsigned_int)
p8est_iter_edge_side_t edge_side
p8est_iter_edge_t edge_iter
p4est_iter_corner_t corner_iter