Reference documentation for deal.II version 9.0.0
p4est_wrappers.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2016 - 2017 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_p4est_wrappers_h
17 #define dealii_p4est_wrappers_h
18 
19 #include <deal.II/base/geometry_info.h>
20 
21 #ifdef DEAL_II_WITH_P4EST
22 # include <p4est_bits.h>
23 # include <p4est_extended.h>
24 # include <p4est_vtk.h>
25 # include <p4est_ghost.h>
26 # include <p4est_communication.h>
27 # include <p4est_iterate.h>
28 
29 # include <p8est_bits.h>
30 # include <p8est_extended.h>
31 # include <p8est_vtk.h>
32 # include <p8est_ghost.h>
33 # include <p8est_communication.h>
34 # include <p8est_iterate.h>
35 
36 #include <map>
37 #include <set>
38 
39 
40 DEAL_II_NAMESPACE_OPEN
41 
42 namespace parallel
43 {
44  namespace distributed
45  {
46  template <int dim, int spacedim> class Triangulation;
47  }
48 }
49 
50 
51 namespace internal
52 {
53  namespace p4est
54  {
62  template <int> struct types;
63 
64  template <>
65  struct types<2>
66  {
67  typedef p4est_connectivity_t connectivity;
68  typedef p4est_t forest;
69  typedef p4est_tree_t tree;
70  typedef p4est_quadrant_t quadrant;
71  typedef p4est_topidx_t topidx;
72  typedef p4est_locidx_t locidx;
73 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
74  typedef p4est_connect_type_t balance_type;
75 #else
76  typedef p4est_balance_type_t balance_type;
77 #endif
78  typedef p4est_ghost_t ghost;
79  };
80 
81  template <>
82  struct types<3>
83  {
84  typedef p8est_connectivity_t connectivity;
85  typedef p8est_t forest;
86  typedef p8est_tree_t tree;
87  typedef p8est_quadrant_t quadrant;
88  typedef p4est_topidx_t topidx;
89  typedef p4est_locidx_t locidx;
90 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
91  typedef p8est_connect_type_t balance_type;
92 #else
93  typedef p8est_balance_type_t balance_type;
94 #endif
95  typedef p8est_ghost_t ghost;
96  };
97 
98 
99 
107  template <int dim> struct functions;
108 
109  template <> struct functions<2>
110  {
111  static
112  int (&quadrant_compare) (const void *v1, const void *v2);
113 
114  static
115  void (&quadrant_childrenv) (const types<2>::quadrant *q,
116  types<2>::quadrant c[]);
117 
118  static
119  int (&quadrant_overlaps_tree) (types<2>::tree *tree,
120  const types<2>::quadrant *q);
121 
122  static
123  void (&quadrant_set_morton) (types<2>::quadrant *quadrant,
124  int level,
125  uint64_t id);
126 
127  static
128  int (&quadrant_is_equal) (const types<2>::quadrant *q1,
129  const types<2>::quadrant *q2);
130 
131  static
132  int (&quadrant_is_sibling) (const types<2>::quadrant *q1,
133  const types<2>::quadrant *q2);
134 
135  static
136  int (&quadrant_is_ancestor) (const types<2>::quadrant *q1,
137  const types<2>::quadrant *q2);
138 
139  static
140  int (&quadrant_ancestor_id) (const types<2>::quadrant *q,
141  int level);
142 
143  static
144  int (&comm_find_owner) (types<2>::forest *p4est,
145  const types<2>::locidx which_tree,
146  const types<2>::quadrant *q,
147  const int guess);
148 
149  static
150  types<2>::connectivity *(&connectivity_new) (types<2>::topidx num_vertices,
151  types<2>::topidx num_trees,
152  types<2>::topidx num_corners,
153  types<2>::topidx num_vtt);
154  static
155  void (&connectivity_join_faces) (types<2>::connectivity *conn,
156  types<2>::topidx tree_left,
157  types<2>::topidx tree_right,
158  int face_left,
159  int face_right,
160  int orientation);
161 
162 
163 
164  static
165  void (&connectivity_destroy) (p4est_connectivity_t *connectivity);
166 
167  static
168  types<2>::forest *(&new_forest) (MPI_Comm mpicomm,
169  types<2>::connectivity *connectivity,
170  types<2>::locidx min_quadrants,
171  int min_level,
172  int fill_uniform,
173  size_t data_size,
174  p4est_init_t init_fn,
175  void *user_pointer);
176 
177  static
178  void (&destroy) (types<2>::forest *p4est);
179 
180  static
181  void (&refine) (types<2>::forest *p4est,
182  int refine_recursive,
183  p4est_refine_t refine_fn,
184  p4est_init_t init_fn);
185 
186  static
187  void (&coarsen) (types<2>::forest *p4est,
188  int coarsen_recursive,
189  p4est_coarsen_t coarsen_fn,
190  p4est_init_t init_fn);
191 
192  static
193  void (&balance) (types<2>::forest *p4est,
195  p4est_init_t init_fn);
196 
197 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
198  static
199  p4est_gloidx_t (&partition) (types<2>::forest *p4est,
200  int partition_for_coarsening,
201  p4est_weight_t weight_fn);
202 #else
203  static
204  void (&partition) (types<2>::forest *p4est,
205  int partition_for_coarsening,
206  p4est_weight_t weight_fn);
207 #endif
208 
209  static
210  void (&save) (const char *filename,
211  types<2>::forest *p4est,
212  int save_data);
213 
214 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
215  static
216  types<2>::forest *(&load_ext) (const char *filename,
217  MPI_Comm mpicomm,
218  size_t data_size,
219  int load_data,
220  int autopartition,
221  int broadcasthead,
222  void *user_pointer,
223  types<2>::connectivity **p4est);
224 #else
225  static
226  types<2>::forest *(&load) (const char *filename,
227  MPI_Comm mpicomm,
228  size_t data_size,
229  int load_data,
230  void *user_pointer,
231  types<2>::connectivity **p4est);
232 #endif
233 
234 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
235  static
236  int (&connectivity_save) (const char *filename,
237  types<2>::connectivity *connectivity);
238 #else
239  static
240  void (&connectivity_save) (const char *filename,
241  types<2>::connectivity *connectivity);
242 #endif
243 
244  static
245  int (&connectivity_is_valid) (types<2>::connectivity *connectivity);
246 
247 #if DEAL_II_P4EST_VERSION_GTE(1,0,0,0)
248  static
249  types<2>::connectivity *(&connectivity_load) (const char *filename,
250  size_t *length);
251 #elif DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
252  static
253  types<2>::connectivity *(&connectivity_load) (const char *filename,
254  long unsigned *length);
255 #else
256  static
257  types<2>::connectivity *(&connectivity_load) (const char *filename,
258  long *length);
259 #endif
260 
261  static
262  unsigned int (&checksum) (types<2>::forest *p4est);
263 
264  static
265  void (&vtk_write_file) (types<2>::forest *p4est,
266  p4est_geometry_t *,
267  const char *baseName);
268 
269  static
270  types<2>::ghost *(&ghost_new) (types<2>::forest *p4est,
271  types<2>::balance_type btype);
272 
273  static
274  void (&ghost_destroy) (types<2>::ghost *ghost);
275 
276  static
277  void (&reset_data) (types<2>::forest *p4est,
278  size_t data_size,
279  p4est_init_t init_fn,
280  void *user_pointer);
281 
282  static
283  size_t (&forest_memory_used) (types<2>::forest *p4est);
284 
285  static
286  size_t (&connectivity_memory_used) (types<2>::connectivity *p4est);
287 
288  template <int spacedim>
289  static void iterate(::internal::p4est::types<2>::forest *parallel_forest,
290  ::internal::p4est::types<2>::ghost *parallel_ghost,
291  void *user_data);
292 
293  static const unsigned int max_level = P4EST_MAXLEVEL;
294  };
295 
296 
297  template <> struct functions<3>
298  {
299  static
300  int (&quadrant_compare) (const void *v1, const void *v2);
301 
302  static
303  void (&quadrant_childrenv) (const types<3>::quadrant *q,
304  types<3>::quadrant c[]);
305 
306  static
307  int (&quadrant_overlaps_tree) (types<3>::tree *tree,
308  const types<3>::quadrant *q);
309 
310  static
311  void (&quadrant_set_morton) (types<3>::quadrant *quadrant,
312  int level,
313  uint64_t id);
314 
315  static
316  int (&quadrant_is_equal) (const types<3>::quadrant *q1,
317  const types<3>::quadrant *q2);
318 
319  static
320  int (&quadrant_is_sibling) (const types<3>::quadrant *q1,
321  const types<3>::quadrant *q2);
322 
323  static
324  int (&quadrant_is_ancestor) (const types<3>::quadrant *q1,
325  const types<3>::quadrant *q2);
326  static
327  int (&quadrant_ancestor_id) (const types<3>::quadrant *q,
328  int level);
329 
330  static
331  int (&comm_find_owner) (types<3>::forest *p4est,
332  const types<3>::locidx which_tree,
333  const types<3>::quadrant *q,
334  const int guess);
335 
336  static
337  types<3>::connectivity *(&connectivity_new) (types<3>::topidx num_vertices,
338  types<3>::topidx num_trees,
339  types<3>::topidx num_edges,
340  types<3>::topidx num_ett,
341  types<3>::topidx num_corners,
342  types<3>::topidx num_ctt);
343 
344  static
345  void (&connectivity_join_faces) (types<3>::connectivity *conn,
346  types<3>::topidx tree_left,
347  types<3>::topidx tree_right,
348  int face_left,
349  int face_right,
350  int orientation);
351 
352  static
353  void (&connectivity_destroy) (p8est_connectivity_t *connectivity);
354 
355  static
356  types<3>::forest *(&new_forest) (MPI_Comm mpicomm,
357  types<3>::connectivity *connectivity,
358  types<3>::locidx min_quadrants,
359  int min_level,
360  int fill_uniform,
361  size_t data_size,
362  p8est_init_t init_fn,
363  void *user_pointer);
364 
365  static
366  void (&destroy) (types<3>::forest *p8est);
367 
368  static
369  void (&refine) (types<3>::forest *p8est,
370  int refine_recursive,
371  p8est_refine_t refine_fn,
372  p8est_init_t init_fn);
373 
374  static
375  void (&coarsen) (types<3>::forest *p8est,
376  int coarsen_recursive,
377  p8est_coarsen_t coarsen_fn,
378  p8est_init_t init_fn);
379 
380  static
381  void (&balance) (types<3>::forest *p8est,
383  p8est_init_t init_fn);
384 
385 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
386  static
387  p4est_gloidx_t (&partition) (types<3>::forest *p8est,
388  int partition_for_coarsening,
389  p8est_weight_t weight_fn);
390 #else
391  static
392  void (&partition) (types<3>::forest *p8est,
393  int partition_for_coarsening,
394  p8est_weight_t weight_fn);
395 #endif
396 
397  static
398  void (&save) (const char *filename,
399  types<3>::forest *p4est,
400  int save_data);
401 
402 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
403  static
404  types<3>::forest *(&load_ext) (const char *filename,
405  MPI_Comm mpicomm,
406  std::size_t data_size,
407  int load_data,
408  int autopartition,
409  int broadcasthead,
410  void *user_pointer,
411  types<3>::connectivity **p4est);
412 #else
413  static
414  types<3>::forest *(&load) (const char *filename,
415  MPI_Comm mpicomm,
416  std::size_t data_size,
417  int load_data,
418  void *user_pointer,
419  types<3>::connectivity **p4est);
420 #endif
421 
422 #if DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
423  static
424  int (&connectivity_save) (const char *filename,
425  types<3>::connectivity *connectivity);
426 #else
427  static
428  void (&connectivity_save) (const char *filename,
429  types<3>::connectivity *connectivity);
430 #endif
431 
432  static
433  int (&connectivity_is_valid) (types<3>::connectivity *connectivity);
434 
435 #if DEAL_II_P4EST_VERSION_GTE(1,0,0,0)
436  static
437  types<3>::connectivity *(&connectivity_load) (const char *filename,
438  size_t *length);
439 #elif DEAL_II_P4EST_VERSION_GTE(0,3,4,3)
440  static
441  types<3>::connectivity *(&connectivity_load) (const char *filename,
442  long unsigned *length);
443 #else
444  static
445  types<3>::connectivity *(&connectivity_load) (const char *filename,
446  long *length);
447 #endif
448 
449  static
450  unsigned int (&checksum) (types<3>::forest *p8est);
451 
452  static
453  void (&vtk_write_file) (types<3>::forest *p8est,
454  p8est_geometry_t *,
455  const char *baseName);
456  static
457  types<3>::ghost *(&ghost_new) (types<3>::forest *p4est,
458  types<3>::balance_type btype);
459 
460  static
461  void (&ghost_destroy) (types<3>::ghost *ghost);
462 
463  static
464  void (&reset_data) (types<3>::forest *p4est,
465  size_t data_size,
466  p8est_init_t init_fn,
467  void *user_pointer);
468 
469  static
470  size_t (&forest_memory_used) (types<3>::forest *p4est);
471 
472  static
473  size_t (&connectivity_memory_used) (types<3>::connectivity *p4est);
474 
475 
476 
477  static const unsigned int max_level = P8EST_MAXLEVEL;
478  };
479 
480 
481 
482 
489  template <int dim> struct iter;
490 
491  template <> struct iter<2>
492  {
493  typedef p4est_iter_corner_info_t corner_info;
494  typedef p4est_iter_corner_side_t corner_side;
495  typedef p4est_iter_corner_t corner_iter;
496  typedef p4est_iter_face_info_t face_info;
497  typedef p4est_iter_face_side_t face_side;
498  typedef p4est_iter_face_t face_iter;
499  };
500 
501  template <> struct iter<3>
502  {
503  typedef p8est_iter_corner_info_t corner_info;
504  typedef p8est_iter_corner_side_t corner_side;
505  typedef p8est_iter_corner_t corner_iter;
506  typedef p8est_iter_edge_info_t edge_info;
507  typedef p8est_iter_edge_side_t edge_side;
508  typedef p8est_iter_edge_t edge_iter;
509  typedef p8est_iter_face_info_t face_info;
510  typedef p8est_iter_face_side_t face_side;
511  typedef p8est_iter_face_t face_iter;
512  };
513 
514 
515 
520  template <int dim>
521  void
522  init_quadrant_children
523  (const typename types<dim>::quadrant &p4est_cell,
524  typename types<dim>::quadrant (&p4est_children)[::GeometryInfo<dim>::max_children_per_cell]);
525 
526 
527 
531  template <int dim>
532  void
533  init_coarse_quadrant(typename types<dim>::quadrant &quad);
534 
535 
536 
540  template <int dim>
541  bool
542  quadrant_is_equal (const typename types<dim>::quadrant &q1,
543  const typename types<dim>::quadrant &q2);
544 
545 
546 
550  template <int dim>
551  bool
552  quadrant_is_ancestor (const typename types<dim>::quadrant &q1,
553  const typename types<dim>::quadrant &q2);
554 
555 
556 
560  template <int dim>
561  bool
562  tree_exists_locally (const typename types<dim>::forest *parallel_forest,
563  const typename types<dim>::topidx coarse_grid_cell);
564 
565 
566 
570  template <int dim, int spacedim>
571  std::map<unsigned int, std::set<::types::subdomain_id> >
572  compute_vertices_with_ghost_neighbors(const ::parallel::distributed::Triangulation<dim,spacedim> &tria,
573  typename ::internal::p4est::types<dim>::forest *parallel_forest,
574  typename ::internal::p4est::types<dim>::ghost *parallel_ghost);
575 
576  }
577 }
578 
579 DEAL_II_NAMESPACE_CLOSE
580 
581 #endif //DEAL_II_WITH_P4EST
582 
583 #endif //dealii_p4est_wrappers_h
Definition: types.h:30