Reference documentation for deal.II version Git a0b41b6d0f 2020-02-26 20:08:13 -0600
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
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/config.h>
20 
21 #include <deal.II/base/geometry_info.h>
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 
41 DEAL_II_NAMESPACE_OPEN
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 
140  static int (&quadrant_is_equal)(const types<2>::quadrant *q1,
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 
146  static int (&quadrant_is_ancestor)(const types<2>::quadrant *q1,
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 
157  static types<2>::connectivity *(&connectivity_new)(
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 
173  static types<2>::forest *(&new_forest)(
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 
183  static void (&destroy)(types<2>::forest *p4est);
184 
185  static void (&refine)(types<2>::forest *p4est,
186  int refine_recursive,
187  p4est_refine_t refine_fn,
188  p4est_init_t init_fn);
189 
190  static void (&coarsen)(types<2>::forest *p4est,
191  int coarsen_recursive,
192  p4est_coarsen_t coarsen_fn,
193  p4est_init_t init_fn);
194 
195  static void (&balance)(types<2>::forest * p4est,
197  p4est_init_t init_fn);
198 
199  static types<2>::gloidx (&partition)(types<2>::forest *p4est,
200  int partition_for_coarsening,
201  p4est_weight_t weight_fn);
202 
203  static void (&save)(const char * filename,
204  types<2>::forest *p4est,
205  int save_data);
206 
207  static types<2>::forest *(&load_ext)(const char *filename,
208  MPI_Comm mpicomm,
209  std::size_t data_size,
210  int load_data,
211  int autopartition,
212  int broadcasthead,
213  void * user_pointer,
214  types<2>::connectivity **p4est);
215 
216  static int (&connectivity_save)(const char * filename,
217  types<2>::connectivity *connectivity);
218 
219  static int (&connectivity_is_valid)(types<2>::connectivity *connectivity);
220 
221  static types<2>::connectivity *(&connectivity_load)(const char * filename,
222  std::size_t *length);
223 
224  static unsigned int (&checksum)(types<2>::forest *p4est);
225 
226  static void (&vtk_write_file)(types<2>::forest *p4est,
227  p4est_geometry_t *,
228  const char *baseName);
229 
230  static types<2>::ghost *(&ghost_new)(types<2>::forest * p4est,
231  types<2>::balance_type btype);
232 
233  static void (&ghost_destroy)(types<2>::ghost *ghost);
234 
235  static void (&reset_data)(types<2>::forest *p4est,
236  std::size_t data_size,
237  p4est_init_t init_fn,
238  void * user_pointer);
239 
240  static std::size_t (&forest_memory_used)(types<2>::forest *p4est);
241 
242  static std::size_t (&connectivity_memory_used)(
243  types<2>::connectivity *p4est);
244 
245  template <int spacedim>
246  static void
247  iterate(::internal::p4est::types<2>::forest *parallel_forest,
248  ::internal::p4est::types<2>::ghost * parallel_ghost,
249  void * user_data);
250 
251  static constexpr unsigned int max_level = P4EST_MAXLEVEL;
252 
253  static void (&transfer_fixed)(const types<2>::gloidx *dest_gfq,
254  const types<2>::gloidx *src_gfq,
255  MPI_Comm mpicomm,
256  int tag,
257  void * dest_data,
258  const void * src_data,
259  std::size_t data_size);
260 
261  static types<2>::transfer_context *(&transfer_fixed_begin)(
262  const types<2>::gloidx *dest_gfq,
263  const types<2>::gloidx *src_gfq,
264  MPI_Comm mpicomm,
265  int tag,
266  void * dest_data,
267  const void * src_data,
268  std::size_t data_size);
269 
270  static void (&transfer_fixed_end)(types<2>::transfer_context *tc);
271 
272  static void (&transfer_custom)(const types<2>::gloidx *dest_gfq,
273  const types<2>::gloidx *src_gfq,
274  MPI_Comm mpicomm,
275  int tag,
276  void * dest_data,
277  const int * dest_sizes,
278  const void * src_data,
279  const int * src_sizes);
280 
281  static types<2>::transfer_context *(&transfer_custom_begin)(
282  const types<2>::gloidx *dest_gfq,
283  const types<2>::gloidx *src_gfq,
284  MPI_Comm mpicomm,
285  int tag,
286  void * dest_data,
287  const int * dest_sizes,
288  const void * src_data,
289  const int * src_sizes);
290 
291  static void (&transfer_custom_end)(types<2>::transfer_context *tc);
292  };
293 
294 
295  template <>
296  struct functions<3>
297  {
298  static int (&quadrant_compare)(const void *v1, const void *v2);
299 
300  static void (&quadrant_childrenv)(const types<3>::quadrant *q,
301  types<3>::quadrant c[]);
302 
303  static int (&quadrant_overlaps_tree)(types<3>::tree * tree,
304  const types<3>::quadrant *q);
305 
306  static void (&quadrant_set_morton)(types<3>::quadrant *quadrant,
307  int level,
308  uint64_t id);
309 
310  static int (&quadrant_is_equal)(const types<3>::quadrant *q1,
311  const types<3>::quadrant *q2);
312 
313  static int (&quadrant_is_sibling)(const types<3>::quadrant *q1,
314  const types<3>::quadrant *q2);
315 
316  static int (&quadrant_is_ancestor)(const types<3>::quadrant *q1,
317  const types<3>::quadrant *q2);
318  static int (&quadrant_ancestor_id)(const types<3>::quadrant *q,
319  int level);
320 
321  static int (&comm_find_owner)(types<3>::forest * p4est,
322  const types<3>::locidx which_tree,
323  const types<3>::quadrant *q,
324  const int guess);
325 
326  static types<3>::connectivity *(&connectivity_new)(
327  types<3>::topidx num_vertices,
328  types<3>::topidx num_trees,
329  types<3>::topidx num_edges,
330  types<3>::topidx num_ett,
331  types<3>::topidx num_corners,
332  types<3>::topidx num_ctt);
333 
334  static void (&connectivity_join_faces)(types<3>::connectivity *conn,
335  types<3>::topidx tree_left,
336  types<3>::topidx tree_right,
337  int face_left,
338  int face_right,
339  int orientation);
340 
341  static void (&connectivity_destroy)(p8est_connectivity_t *connectivity);
342 
343  static types<3>::forest *(&new_forest)(
344  MPI_Comm mpicomm,
345  types<3>::connectivity *connectivity,
346  types<3>::locidx min_quadrants,
347  int min_level,
348  int fill_uniform,
349  std::size_t data_size,
350  p8est_init_t init_fn,
351  void * user_pointer);
352 
353  static void (&destroy)(types<3>::forest *p8est);
354 
355  static void (&refine)(types<3>::forest *p8est,
356  int refine_recursive,
357  p8est_refine_t refine_fn,
358  p8est_init_t init_fn);
359 
360  static void (&coarsen)(types<3>::forest *p8est,
361  int coarsen_recursive,
362  p8est_coarsen_t coarsen_fn,
363  p8est_init_t init_fn);
364 
365  static void (&balance)(types<3>::forest * p8est,
367  p8est_init_t init_fn);
368 
369  static types<3>::gloidx (&partition)(types<3>::forest *p8est,
370  int partition_for_coarsening,
371  p8est_weight_t weight_fn);
372 
373  static void (&save)(const char * filename,
374  types<3>::forest *p4est,
375  int save_data);
376 
377  static types<3>::forest *(&load_ext)(const char *filename,
378  MPI_Comm mpicomm,
379  std::size_t data_size,
380  int load_data,
381  int autopartition,
382  int broadcasthead,
383  void * user_pointer,
384  types<3>::connectivity **p4est);
385 
386  static int (&connectivity_save)(const char * filename,
387  types<3>::connectivity *connectivity);
388 
389  static int (&connectivity_is_valid)(types<3>::connectivity *connectivity);
390 
391  static types<3>::connectivity *(&connectivity_load)(const char * filename,
392  std::size_t *length);
393 
394  static unsigned int (&checksum)(types<3>::forest *p8est);
395 
396  static void (&vtk_write_file)(types<3>::forest *p8est,
397  p8est_geometry_t *,
398  const char *baseName);
399  static types<3>::ghost *(&ghost_new)(types<3>::forest * p4est,
400  types<3>::balance_type btype);
401 
402  static void (&ghost_destroy)(types<3>::ghost *ghost);
403 
404  static void (&reset_data)(types<3>::forest *p4est,
405  std::size_t data_size,
406  p8est_init_t init_fn,
407  void * user_pointer);
408 
409  static std::size_t (&forest_memory_used)(types<3>::forest *p4est);
410 
411  static std::size_t (&connectivity_memory_used)(
412  types<3>::connectivity *p4est);
413 
414  static constexpr unsigned int max_level = P8EST_MAXLEVEL;
415 
416  static void (&transfer_fixed)(const types<3>::gloidx *dest_gfq,
417  const types<3>::gloidx *src_gfq,
418  MPI_Comm mpicomm,
419  int tag,
420  void * dest_data,
421  const void * src_data,
422  std::size_t data_size);
423 
424  static types<3>::transfer_context *(&transfer_fixed_begin)(
425  const types<3>::gloidx *dest_gfq,
426  const types<3>::gloidx *src_gfq,
427  MPI_Comm mpicomm,
428  int tag,
429  void * dest_data,
430  const void * src_data,
431  std::size_t data_size);
432 
433  static void (&transfer_fixed_end)(types<3>::transfer_context *tc);
434 
435  static void (&transfer_custom)(const types<3>::gloidx *dest_gfq,
436  const types<3>::gloidx *src_gfq,
437  MPI_Comm mpicomm,
438  int tag,
439  void * dest_data,
440  const int * dest_sizes,
441  const void * src_data,
442  const int * src_sizes);
443 
444  static types<3>::transfer_context *(&transfer_custom_begin)(
445  const types<3>::gloidx *dest_gfq,
446  const types<3>::gloidx *src_gfq,
447  MPI_Comm mpicomm,
448  int tag,
449  void * dest_data,
450  const int * dest_sizes,
451  const void * src_data,
452  const int * src_sizes);
453 
454  static void (&transfer_custom_end)(types<3>::transfer_context *tc);
455  };
456 
457 
458 
465  template <int dim>
466  struct iter;
467 
468  template <>
469  struct iter<2>
470  {
471  using corner_info = p4est_iter_corner_info_t;
472  using corner_side = p4est_iter_corner_side_t;
473  using corner_iter = p4est_iter_corner_t;
474  using face_info = p4est_iter_face_info_t;
475  using face_side = p4est_iter_face_side_t;
476  using face_iter = p4est_iter_face_t;
477  };
478 
479  template <>
480  struct iter<3>
481  {
482  using corner_info = p8est_iter_corner_info_t;
483  using corner_side = p8est_iter_corner_side_t;
484  using corner_iter = p8est_iter_corner_t;
485  using edge_info = p8est_iter_edge_info_t;
486  using edge_side = p8est_iter_edge_side_t;
487  using edge_iter = p8est_iter_edge_t;
488  using face_info = p8est_iter_face_info_t;
489  using face_side = p8est_iter_face_side_t;
490  using face_iter = p8est_iter_face_t;
491  };
492 
493 
494 
499  template <int dim>
500  void
501  init_quadrant_children(
502  const typename types<dim>::quadrant &p4est_cell,
503  typename types<dim>::quadrant (
504  &p4est_children)[::GeometryInfo<dim>::max_children_per_cell]);
505 
506 
507 
511  template <int dim>
512  void
513  init_coarse_quadrant(typename types<dim>::quadrant &quad);
514 
515 
516 
520  template <int dim>
521  bool
522  quadrant_is_equal(const typename types<dim>::quadrant &q1,
523  const typename types<dim>::quadrant &q2);
524 
525 
526 
530  template <int dim>
531  bool
532  quadrant_is_ancestor(const typename types<dim>::quadrant &q1,
533  const typename types<dim>::quadrant &q2);
534 
535 
536 
540  template <int dim>
541  bool
542  tree_exists_locally(const typename types<dim>::forest *parallel_forest,
543  const typename types<dim>::topidx coarse_grid_cell);
544 
545 
546 
550  template <int dim, int spacedim>
551  std::map<unsigned int, std::set<::types::subdomain_id>>
552  compute_vertices_with_ghost_neighbors(
553  const ::parallel::distributed::Triangulation<dim, spacedim> &tria,
554  typename ::internal::p4est::types<dim>::forest *parallel_forest,
555  typename ::internal::p4est::types<dim>::ghost * parallel_ghost);
556 
557  } // namespace p4est
558 } // namespace internal
559 
560 DEAL_II_NAMESPACE_CLOSE
561 
562 #endif // DEAL_II_WITH_P4EST
563 
564 #endif // dealii_p4est_wrappers_h
Definition: types.h:31