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