Reference documentation for deal.II version Git 840703ecf3 2019-10-14 17:15:20 -0400
\(\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 // Forward declaration
42 # ifndef DOXYGEN
43 namespace parallel
44 {
45  namespace distributed
46  {
47  template <int dim, int spacedim>
48  class Triangulation;
49  }
50 } // namespace parallel
51 # endif
52 
53 namespace internal
54 {
55  namespace p4est
56  {
64  template <int>
65  struct types;
66 
67  // these struct mimics p4est for 1D
68  template <>
69  struct types<1>
70  {
71  // id of a quadrant is an integeger
72  using quadrant = int;
73 
74  // maximum number of children
75  static const int max_n_child_indices_bits = 27;
76 
77  // number of bits the data type of id has
78  static const int n_bits = std::numeric_limits<quadrant>::digits;
79  };
80 
81  template <>
82  struct types<2>
83  {
84  using connectivity = p4est_connectivity_t;
85  using forest = p4est_t;
86  using tree = p4est_tree_t;
87  using quadrant = p4est_quadrant_t;
88  using topidx = p4est_topidx_t;
89  using locidx = p4est_locidx_t;
90  using gloidx = p4est_gloidx_t;
91  using balance_type = p4est_connect_type_t;
92  using ghost = p4est_ghost_t;
93  using transfer_context = p4est_transfer_context_t;
94  };
95 
96  template <>
97  struct types<3>
98  {
99  using connectivity = p8est_connectivity_t;
100  using forest = p8est_t;
101  using tree = p8est_tree_t;
102  using quadrant = p8est_quadrant_t;
103  using topidx = p4est_topidx_t;
104  using locidx = p4est_locidx_t;
105  using gloidx = p4est_gloidx_t;
106  using balance_type = p8est_connect_type_t;
107  using ghost = p8est_ghost_t;
108  using transfer_context = p8est_transfer_context_t;
109  };
110 
111 
112 
120  template <int dim>
121  struct functions;
122 
123  template <>
124  struct functions<2>
125  {
126  static int (&quadrant_compare)(const void *v1, const void *v2);
127 
128  static void (&quadrant_childrenv)(const types<2>::quadrant *q,
129  types<2>::quadrant c[]);
130 
131  static int (&quadrant_overlaps_tree)(types<2>::tree * tree,
132  const types<2>::quadrant *q);
133 
134  static void (&quadrant_set_morton)(types<2>::quadrant *quadrant,
135  int level,
136  uint64_t id);
137 
138  static int (&quadrant_is_equal)(const types<2>::quadrant *q1,
139  const types<2>::quadrant *q2);
140 
141  static int (&quadrant_is_sibling)(const types<2>::quadrant *q1,
142  const types<2>::quadrant *q2);
143 
144  static int (&quadrant_is_ancestor)(const types<2>::quadrant *q1,
145  const types<2>::quadrant *q2);
146 
147  static int (&quadrant_ancestor_id)(const types<2>::quadrant *q,
148  int level);
149 
150  static int (&comm_find_owner)(types<2>::forest * p4est,
151  const types<2>::locidx which_tree,
152  const types<2>::quadrant *q,
153  const int guess);
154 
155  static types<2>::connectivity *(&connectivity_new)(
156  types<2>::topidx num_vertices,
157  types<2>::topidx num_trees,
158  types<2>::topidx num_corners,
159  types<2>::topidx num_vtt);
160  static void (&connectivity_join_faces)(types<2>::connectivity *conn,
161  types<2>::topidx tree_left,
162  types<2>::topidx tree_right,
163  int face_left,
164  int face_right,
165  int orientation);
166 
167 
168 
169  static void (&connectivity_destroy)(p4est_connectivity_t *connectivity);
170 
171  static types<2>::forest *(&new_forest)(
172  MPI_Comm mpicomm,
173  types<2>::connectivity *connectivity,
174  types<2>::locidx min_quadrants,
175  int min_level,
176  int fill_uniform,
177  std::size_t data_size,
178  p4est_init_t init_fn,
179  void * user_pointer);
180 
181  static void (&destroy)(types<2>::forest *p4est);
182 
183  static void (&refine)(types<2>::forest *p4est,
184  int refine_recursive,
185  p4est_refine_t refine_fn,
186  p4est_init_t init_fn);
187 
188  static void (&coarsen)(types<2>::forest *p4est,
189  int coarsen_recursive,
190  p4est_coarsen_t coarsen_fn,
191  p4est_init_t init_fn);
192 
193  static void (&balance)(types<2>::forest * p4est,
195  p4est_init_t init_fn);
196 
197  static types<2>::gloidx (&partition)(types<2>::forest *p4est,
198  int partition_for_coarsening,
199  p4est_weight_t weight_fn);
200 
201  static void (&save)(const char * filename,
202  types<2>::forest *p4est,
203  int save_data);
204 
205  static types<2>::forest *(&load_ext)(const char *filename,
206  MPI_Comm mpicomm,
207  std::size_t data_size,
208  int load_data,
209  int autopartition,
210  int broadcasthead,
211  void * user_pointer,
212  types<2>::connectivity **p4est);
213 
214  static int (&connectivity_save)(const char * filename,
215  types<2>::connectivity *connectivity);
216 
217  static int (&connectivity_is_valid)(types<2>::connectivity *connectivity);
218 
219  static types<2>::connectivity *(&connectivity_load)(const char * filename,
220  std::size_t *length);
221 
222  static unsigned int (&checksum)(types<2>::forest *p4est);
223 
224  static void (&vtk_write_file)(types<2>::forest *p4est,
225  p4est_geometry_t *,
226  const char *baseName);
227 
228  static types<2>::ghost *(&ghost_new)(types<2>::forest * p4est,
229  types<2>::balance_type btype);
230 
231  static void (&ghost_destroy)(types<2>::ghost *ghost);
232 
233  static void (&reset_data)(types<2>::forest *p4est,
234  std::size_t data_size,
235  p4est_init_t init_fn,
236  void * user_pointer);
237 
238  static std::size_t (&forest_memory_used)(types<2>::forest *p4est);
239 
240  static std::size_t (&connectivity_memory_used)(
241  types<2>::connectivity *p4est);
242 
243  template <int spacedim>
244  static void
245  iterate(::internal::p4est::types<2>::forest *parallel_forest,
246  ::internal::p4est::types<2>::ghost * parallel_ghost,
247  void * user_data);
248 
249  static constexpr unsigned int max_level = P4EST_MAXLEVEL;
250 
251  static void (&transfer_fixed)(const types<2>::gloidx *dest_gfq,
252  const types<2>::gloidx *src_gfq,
253  MPI_Comm mpicomm,
254  int tag,
255  void * dest_data,
256  const void * src_data,
257  std::size_t data_size);
258 
259  static types<2>::transfer_context *(&transfer_fixed_begin)(
260  const types<2>::gloidx *dest_gfq,
261  const types<2>::gloidx *src_gfq,
262  MPI_Comm mpicomm,
263  int tag,
264  void * dest_data,
265  const void * src_data,
266  std::size_t data_size);
267 
268  static void (&transfer_fixed_end)(types<2>::transfer_context *tc);
269 
270  static void (&transfer_custom)(const types<2>::gloidx *dest_gfq,
271  const types<2>::gloidx *src_gfq,
272  MPI_Comm mpicomm,
273  int tag,
274  void * dest_data,
275  const int * dest_sizes,
276  const void * src_data,
277  const int * src_sizes);
278 
279  static types<2>::transfer_context *(&transfer_custom_begin)(
280  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 int * dest_sizes,
286  const void * src_data,
287  const int * src_sizes);
288 
289  static void (&transfer_custom_end)(types<2>::transfer_context *tc);
290  };
291 
292 
293  template <>
294  struct functions<3>
295  {
296  static int (&quadrant_compare)(const void *v1, const void *v2);
297 
298  static void (&quadrant_childrenv)(const types<3>::quadrant *q,
299  types<3>::quadrant c[]);
300 
301  static int (&quadrant_overlaps_tree)(types<3>::tree * tree,
302  const types<3>::quadrant *q);
303 
304  static void (&quadrant_set_morton)(types<3>::quadrant *quadrant,
305  int level,
306  uint64_t id);
307 
308  static int (&quadrant_is_equal)(const types<3>::quadrant *q1,
309  const types<3>::quadrant *q2);
310 
311  static int (&quadrant_is_sibling)(const types<3>::quadrant *q1,
312  const types<3>::quadrant *q2);
313 
314  static int (&quadrant_is_ancestor)(const types<3>::quadrant *q1,
315  const types<3>::quadrant *q2);
316  static int (&quadrant_ancestor_id)(const types<3>::quadrant *q,
317  int level);
318 
319  static int (&comm_find_owner)(types<3>::forest * p4est,
320  const types<3>::locidx which_tree,
321  const types<3>::quadrant *q,
322  const int guess);
323 
324  static types<3>::connectivity *(&connectivity_new)(
325  types<3>::topidx num_vertices,
326  types<3>::topidx num_trees,
327  types<3>::topidx num_edges,
328  types<3>::topidx num_ett,
329  types<3>::topidx num_corners,
330  types<3>::topidx num_ctt);
331 
332  static void (&connectivity_join_faces)(types<3>::connectivity *conn,
333  types<3>::topidx tree_left,
334  types<3>::topidx tree_right,
335  int face_left,
336  int face_right,
337  int orientation);
338 
339  static void (&connectivity_destroy)(p8est_connectivity_t *connectivity);
340 
341  static types<3>::forest *(&new_forest)(
342  MPI_Comm mpicomm,
343  types<3>::connectivity *connectivity,
344  types<3>::locidx min_quadrants,
345  int min_level,
346  int fill_uniform,
347  std::size_t data_size,
348  p8est_init_t init_fn,
349  void * user_pointer);
350 
351  static void (&destroy)(types<3>::forest *p8est);
352 
353  static void (&refine)(types<3>::forest *p8est,
354  int refine_recursive,
355  p8est_refine_t refine_fn,
356  p8est_init_t init_fn);
357 
358  static void (&coarsen)(types<3>::forest *p8est,
359  int coarsen_recursive,
360  p8est_coarsen_t coarsen_fn,
361  p8est_init_t init_fn);
362 
363  static void (&balance)(types<3>::forest * p8est,
365  p8est_init_t init_fn);
366 
367  static types<3>::gloidx (&partition)(types<3>::forest *p8est,
368  int partition_for_coarsening,
369  p8est_weight_t weight_fn);
370 
371  static void (&save)(const char * filename,
372  types<3>::forest *p4est,
373  int save_data);
374 
375  static types<3>::forest *(&load_ext)(const char *filename,
376  MPI_Comm mpicomm,
377  std::size_t data_size,
378  int load_data,
379  int autopartition,
380  int broadcasthead,
381  void * user_pointer,
382  types<3>::connectivity **p4est);
383 
384  static int (&connectivity_save)(const char * filename,
385  types<3>::connectivity *connectivity);
386 
387  static int (&connectivity_is_valid)(types<3>::connectivity *connectivity);
388 
389  static types<3>::connectivity *(&connectivity_load)(const char * filename,
390  std::size_t *length);
391 
392  static unsigned int (&checksum)(types<3>::forest *p8est);
393 
394  static void (&vtk_write_file)(types<3>::forest *p8est,
395  p8est_geometry_t *,
396  const char *baseName);
397  static types<3>::ghost *(&ghost_new)(types<3>::forest * p4est,
398  types<3>::balance_type btype);
399 
400  static void (&ghost_destroy)(types<3>::ghost *ghost);
401 
402  static void (&reset_data)(types<3>::forest *p4est,
403  std::size_t data_size,
404  p8est_init_t init_fn,
405  void * user_pointer);
406 
407  static std::size_t (&forest_memory_used)(types<3>::forest *p4est);
408 
409  static std::size_t (&connectivity_memory_used)(
410  types<3>::connectivity *p4est);
411 
412  static constexpr unsigned int max_level = P8EST_MAXLEVEL;
413 
414  static void (&transfer_fixed)(const types<3>::gloidx *dest_gfq,
415  const types<3>::gloidx *src_gfq,
416  MPI_Comm mpicomm,
417  int tag,
418  void * dest_data,
419  const void * src_data,
420  std::size_t data_size);
421 
422  static types<3>::transfer_context *(&transfer_fixed_begin)(
423  const types<3>::gloidx *dest_gfq,
424  const types<3>::gloidx *src_gfq,
425  MPI_Comm mpicomm,
426  int tag,
427  void * dest_data,
428  const void * src_data,
429  std::size_t data_size);
430 
431  static void (&transfer_fixed_end)(types<3>::transfer_context *tc);
432 
433  static void (&transfer_custom)(const types<3>::gloidx *dest_gfq,
434  const types<3>::gloidx *src_gfq,
435  MPI_Comm mpicomm,
436  int tag,
437  void * dest_data,
438  const int * dest_sizes,
439  const void * src_data,
440  const int * src_sizes);
441 
442  static types<3>::transfer_context *(&transfer_custom_begin)(
443  const types<3>::gloidx *dest_gfq,
444  const types<3>::gloidx *src_gfq,
445  MPI_Comm mpicomm,
446  int tag,
447  void * dest_data,
448  const int * dest_sizes,
449  const void * src_data,
450  const int * src_sizes);
451 
452  static void (&transfer_custom_end)(types<3>::transfer_context *tc);
453  };
454 
455 
456 
463  template <int dim>
464  struct iter;
465 
466  template <>
467  struct iter<2>
468  {
469  using corner_info = p4est_iter_corner_info_t;
470  using corner_side = p4est_iter_corner_side_t;
471  using corner_iter = p4est_iter_corner_t;
472  using face_info = p4est_iter_face_info_t;
473  using face_side = p4est_iter_face_side_t;
474  using face_iter = p4est_iter_face_t;
475  };
476 
477  template <>
478  struct iter<3>
479  {
480  using corner_info = p8est_iter_corner_info_t;
481  using corner_side = p8est_iter_corner_side_t;
482  using corner_iter = p8est_iter_corner_t;
483  using edge_info = p8est_iter_edge_info_t;
484  using edge_side = p8est_iter_edge_side_t;
485  using edge_iter = p8est_iter_edge_t;
486  using face_info = p8est_iter_face_info_t;
487  using face_side = p8est_iter_face_side_t;
488  using face_iter = p8est_iter_face_t;
489  };
490 
491 
492 
497  template <int dim>
498  void
499  init_quadrant_children(
500  const typename types<dim>::quadrant &p4est_cell,
501  typename types<dim>::quadrant (
502  &p4est_children)[::GeometryInfo<dim>::max_children_per_cell]);
503 
504 
505 
509  template <int dim>
510  void
511  init_coarse_quadrant(typename types<dim>::quadrant &quad);
512 
513 
514 
518  template <int dim>
519  bool
520  quadrant_is_equal(const typename types<dim>::quadrant &q1,
521  const typename types<dim>::quadrant &q2);
522 
523 
524 
528  template <int dim>
529  bool
530  quadrant_is_ancestor(const typename types<dim>::quadrant &q1,
531  const typename types<dim>::quadrant &q2);
532 
533 
534 
538  template <int dim>
539  bool
540  tree_exists_locally(const typename types<dim>::forest *parallel_forest,
541  const typename types<dim>::topidx coarse_grid_cell);
542 
543 
544 
548  template <int dim, int spacedim>
549  std::map<unsigned int, std::set<::types::subdomain_id>>
550  compute_vertices_with_ghost_neighbors(
551  const ::parallel::distributed::Triangulation<dim, spacedim> &tria,
552  typename ::internal::p4est::types<dim>::forest *parallel_forest,
553  typename ::internal::p4est::types<dim>::ghost * parallel_ghost);
554 
555  } // namespace p4est
556 } // namespace internal
557 
558 DEAL_II_NAMESPACE_CLOSE
559 
560 #endif // DEAL_II_WITH_P4EST
561 
562 #endif // dealii_p4est_wrappers_h
Definition: types.h:31