Reference documentation for deal.II version Git f15f581df6 2020-07-10 15:30:09 -0400
\(\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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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);
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 
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 
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
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
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  } // namespace p4est
546 } // namespace internal
547 
549 
550 #endif // DEAL_II_WITH_P4EST
551 
552 #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< 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:363
unsigned int level
Definition: grid_out.cc:4331
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 >::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:362
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