p4est  1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
p6est.h
Go to the documentation of this file.
1 /*
2  This file is part of p4est.
3  p4est is a C library to manage a collection (a forest) of multiple
4  connected adaptive quadtrees or octrees in parallel.
5 
6  Copyright (C) 2013 The University of Texas System
7  Written by Carsten Burstedde, Lucas C. Wilcox, and Tobin Isaac
8 
9  p4est is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  p4est is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with p4est; if not, write to the Free Software Foundation, Inc.,
21  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 
49 #ifndef P6EST_H
50 #define P6EST_H
51 
52 /* 2+1D refinement is based on the 2D p4est datatypes */
53 #include <p4est.h>
54 /* We need p8est_connect_type_t typedef from p8est_connectivity */
55 #include <p8est_connectivity.h>
56 
57 SC_EXTERN_C_BEGIN;
58 
63 typedef struct p6est_connectivity
64 {
68  double *top_vertices;
72  double height[3];
75 }
77 
92  double *top_vertices,
93  double height[3]);
94 
97 
105  p4est_topidx_t which_tree,
106  double vertices[24]);
107 
116  connectivity,
117  p4est_topidx_t treeid,
118  p4est_qcoord_t x,
119  p4est_qcoord_t y,
120  p4est_qcoord_t z, double vxyz[3]);
121 
125 typedef struct p2est_quadrant
126 {
128  int8_t level,
129  pad8;
130  int16_t pad16;
132  {
133  void *user_data;
134  long user_long;
135  int user_int;
137  struct
138  {
139  p4est_topidx_t which_tree;
140  int owner_rank;
141  }
142  piggy1;
143  struct
144  {
145  p4est_topidx_t which_tree;
146  p4est_topidx_t from_tree;
147  }
148  piggy2;
150  struct
151  {
152  p4est_topidx_t which_tree;
153  p4est_locidx_t local_num;
154  }
155  piggy3;
157  }
158  p;
159 }
161 
163 typedef struct p6est
164 {
165  sc_MPI_Comm mpicomm;
166  int mpisize,
167  mpirank;
168  size_t data_size;
170  void *user_pointer;
178  /* WARNING: This is NULL if data size
179  * equals zero. */
184 }
185 p6est_t;
186 
195 typedef void (*p6est_init_t) (p6est_t * p6est,
196  p4est_topidx_t which_tree,
197  p4est_quadrant_t * column,
198  p2est_quadrant_t * layer);
199 
228 typedef void (*p6est_replace_t) (p6est_t * p6est,
229  p4est_topidx_t which_tree,
230  int num_outcolumns,
231  int num_outlayers,
232  p4est_quadrant_t * outcolumns[],
233  p2est_quadrant_t * outlayers[],
234  int num_incolumns,
235  int num_inlayers,
236  p4est_quadrant_t * incolumns[],
237  p2est_quadrant_t * inlayers[]);
238 
243 typedef int (*p6est_refine_column_t) (p6est_t * p6est,
244  p4est_topidx_t which_tree,
245  p4est_quadrant_t * column);
246 
251 typedef int (*p6est_refine_layer_t) (p6est_t * p6est,
252  p4est_topidx_t which_tree,
253  p4est_quadrant_t * column,
254  p2est_quadrant_t * layer);
255 
260 typedef int (*p6est_coarsen_column_t) (p6est_t * p6est,
261  p4est_topidx_t which_tree,
262  p4est_quadrant_t * columns[]);
263 
268 typedef int (*p6est_coarsen_layer_t) (p6est_t * p6est,
269  p4est_topidx_t which_tree,
270  p4est_quadrant_t * column,
271  p2est_quadrant_t * layers[]);
272 
277 typedef int (*p6est_weight_t) (p6est_t * p6est,
278  p4est_topidx_t which_tree,
279  p4est_quadrant_t * column,
280  p2est_quadrant_t * layer);
281 
282 extern void *P2EST_DATA_UNINITIALIZED;
283 
285 #define P2EST_QUADRANT_INIT(q) \
286  ((void) memset ((q), -1, sizeof (p2est_quadrant_t)))
287 
309 p6est_t *p6est_new (sc_MPI_Comm mpicomm,
310  p6est_connectivity_t * connectivity,
311  size_t data_size,
312  p6est_init_t init_fn, void *user_pointer);
313 
331  double *top_vertices,
332  double height[3], int min_zlevel,
333  size_t data_size,
334  p6est_init_t init_fn,
335  void *user_pointer);
336 
341 void p6est_destroy (p6est_t * p6est);
342 
352 p6est_t *p6est_copy (p6est_t * input, int copy_data);
353 
366 void p6est_reset_data (p6est_t * p6est, size_t data_size,
367  p6est_init_t init_fn,
368  void *user_pointer);
369 
388 void p6est_refine_columns (p6est_t * p6est,
389  int refine_recursive,
391  p6est_init_t init_fn);
392 
411 void p6est_refine_layers (p6est_t * p6est,
412  int refine_recursive,
414  p6est_init_t init_fn);
415 
425 void p6est_coarsen_columns (p6est_t * p6est,
426  int coarsen_recursive,
427  p6est_coarsen_column_t coarsen_fn,
428  p6est_init_t init_fn);
429 
439 void p6est_coarsen_layers (p6est_t * p6est,
440  int coarsen_recursive,
441  p6est_coarsen_layer_t coarsen_fn,
442  p6est_init_t init_fn);
443 
451 void p6est_balance (p6est_t * p6est,
452  p8est_connect_type_t btype,
453  p6est_init_t init_fn);
454 
455 typedef enum
456 {
457  P6EST_COMM_PARTITION = 1,
458  P6EST_COMM_GHOST,
459  P6EST_COMM_BALANCE
460 }
461 p6est_comm_tag_t;
462 
477  p6est_weight_t weight_fn);
478 
483 unsigned p6est_checksum (p6est_t * p6est);
484 
496 void p6est_save (const char *filename, p6est_t * p6est,
497  int save_data);
498 
517 p6est_t *p6est_load (const char *filename, sc_MPI_Comm mpicomm,
518  size_t data_size, int load_data,
519  void *user_pointer,
520  p6est_connectivity_t ** connectivity);
521 
523 /*@unused@*/
524 static inline p2est_quadrant_t *
526 {
527  P4EST_ASSERT (array->elem_size == sizeof (p2est_quadrant_t));
528  P4EST_ASSERT (it < array->elem_count);
529 
530  return (p2est_quadrant_t *) (array->array + sizeof (p2est_quadrant_t) * it);
531 }
532 
534 /*@unused@*/
535 static inline p2est_quadrant_t *
537 {
538  P4EST_ASSERT (array->elem_size == sizeof (p2est_quadrant_t));
539 
540  return (p2est_quadrant_t *) sc_array_push (array);
541 }
542 
544 /*@unused@*/
545 static inline p2est_quadrant_t *
547 {
548  P4EST_ASSERT (mempool->elem_size == sizeof (p2est_quadrant_t));
549 
550  return (p2est_quadrant_t *) sc_mempool_alloc (mempool);
551 }
552 
554 /*@unused@*/
555 static inline p2est_quadrant_t *
557 {
558  return (p2est_quadrant_t *) sc_list_pop (list);
559 }
560 
561 #define P6EST_COLUMN_GET_RANGE(q,f,l) \
562  do { \
563  *(f) = (size_t) (q)->p.piggy3.local_num; \
564  *(l) = *(f) + (size_t) (q)->p.piggy3.which_tree; \
565  } while (0);
566 
567 #define P6EST_COLUMN_SET_RANGE(q,f,l) \
568  do { \
569  (q)->p.piggy3.local_num = (p4est_locidx_t) (f); \
570  (q)->p.piggy3.which_tree = (p4est_topidx_t) ((l) - (f)); \
571  } while (0);
572 
573 /*@unused@*/
574 static inline void
575 p6est_layer_init_data (p6est_t * p6est, p4est_topidx_t which_tree,
576  p4est_quadrant_t * column,
577  p2est_quadrant_t * layer, p6est_init_t init_fn)
578 {
579  if (p6est->data_size > 0) {
580  layer->p.user_data = sc_mempool_alloc (p6est->user_data_pool);
581  }
582  else {
583  layer->p.user_data = NULL;
584  }
585  if (init_fn != NULL) {
586  init_fn (p6est, which_tree, column, layer);
587  }
588 }
589 
590 /*@unused@*/
591 static inline void
592 p6est_layer_free_data (p6est_t * p6est, p2est_quadrant_t * layer)
593 {
594  if (p6est->data_size > 0) {
595  sc_mempool_free (p6est->user_data_pool, layer->p.user_data);
596  }
597  layer->p.user_data = NULL;
598 }
599 
600 void p6est_compress_columns (p6est_t * p6est);
601 void p6est_update_offsets (p6est_t * p6est);
602 
603 SC_EXTERN_C_END;
604 
605 #endif /* !P6EST_H */
int16_t pad16
padding
Definition: p6est.h:130
void p6est_connectivity_destroy(p6est_connectivity_t *conn)
Destroy a p6est_connectivity structure.
Definition: p6est.c:81
int(* p6est_weight_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column, p2est_quadrant_t *layer)
Callback function prototype to calculate weights for partitioning.
Definition: p6est.h:277
unsigned p6est_checksum(p6est_t *p6est)
Compute the checksum for a forest.
Definition: p6est.c:2317
void(* p6est_replace_t)(p6est_t *p6est, p4est_topidx_t which_tree, int num_outcolumns, int num_outlayers, p4est_quadrant_t *outcolumns[], p2est_quadrant_t *outlayers[], int num_incolumns, int num_inlayers, p4est_quadrant_t *incolumns[], p2est_quadrant_t *inlayers[])
Callback function prototype to transfer information from outgoing layers to incoming layers...
Definition: p6est.h:228
long user_long
never changed by p4est
Definition: p6est.h:134
int32_t p4est_qcoord_t
Typedef for quadrant coordinates.
Definition: p4est_base.h:53
sc_array_t * layers
single array that stores p2est_quadrant_t layers within columns
Definition: p6est.h:175
static p2est_quadrant_t * p2est_quadrant_mempool_alloc(sc_mempool_t *mempool)
Call sc_mempool_alloc for a mempool creating quadrants.
Definition: p6est.h:546
A 1D quadrant datatype: this is used to encode a "layer" of a column in the 2D+1D AMR scheme...
Definition: p6est.h:125
p6est_t * p6est_new_from_p4est(p4est_t *p4est, double *top_vertices, double height[3], int min_zlevel, size_t data_size, p6est_init_t init_fn, void *user_pointer)
Create a new forest from an already created p4est that represents columns.
Definition: p6est.c:459
void p6est_coarsen_columns(p6est_t *p6est, int coarsen_recursive, p6est_coarsen_column_t coarsen_fn, p6est_init_t init_fn)
Coarsen the columns of a sheet.
Definition: p6est.c:1680
The p6est forest datatype.
Definition: p6est.h:163
size_t elem_size
size of a single element
Definition: sc_containers.h:499
sc_MPI_Comm mpicomm
MPI communicator.
Definition: p6est.h:165
p6est_connectivity_t * p6est_connectivity_new(p4est_connectivity_t *conn4, double *top_vertices, double height[3])
Create a p6est_connectivity_t from a p4est_connectivity_t.
Definition: p6est.c:47
char * array
linear array to store elements
Definition: sc_containers.h:104
size_t elem_size
size of a single element
Definition: sc_containers.h:95
p8est_connect_type_t
Characterize a type of adjacency.
Definition: p8est_connectivity.h:79
void * user_data
never changed by p4est
Definition: p6est.h:133
The sc_list object provides a linked list.
Definition: sc_containers.h:587
p4est_qcoord_t z
vertical coordinate
Definition: p6est.h:127
void p6est_refine_columns(p6est_t *p6est, int refine_recursive, p6est_refine_column_t refine_fn, p6est_init_t init_fn)
Refine the columns of a sheet.
Definition: p6est.c:1350
int8_t pad8
padding
Definition: p6est.h:128
size_t data_size
size of per-quadrant p.user_data (see p2est_quadrant_t::p2est_quadrant_data::user_data) ...
Definition: p6est.h:168
int user_int
never changed by p4est
Definition: p6est.h:135
int(* p6est_refine_column_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column)
Callback function prototype to decide whether to horizontally refine a column, i.e., horizontally refine all of the layers in the column.
Definition: p6est.h:243
static int refine_fn(p4est_t *p4est, p4est_topidx_t which_tree, p4est_quadrant_t *quadrant)
Callback function to decide on refinement.
Definition: p4est_step1.c:59
void(* p6est_init_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column, p2est_quadrant_t *layer)
Callback function prototype to initialize the layers's user data.
Definition: p6est.h:195
int64_t p4est_gloidx_t
Typedef for globally unique indexing of quadrants.
Definition: p4est_base.h:84
p4est_gloidx_t * global_first_layer
first global quadrant index for each process and 1 beyond
Definition: p6est.h:182
p4est_t * columns
2D description of column layout built from connectivity
Definition: p6est.h:173
void p6est_reset_data(p6est_t *p6est, size_t data_size, p6est_init_t init_fn, void *user_pointer)
Reset user pointer and element data.
Definition: p6est.c:593
The p4est forest datatype.
Definition: p4est.h:129
The top-level 2D p4est interface.
static void * sc_array_push(sc_array_t *array)
Enlarge an array by one element.
Definition: sc_containers.h:485
void p6est_qcoord_to_vertex(p6est_connectivity_t *connectivity, p4est_topidx_t treeid, p4est_qcoord_t x, p4est_qcoord_t y, p4est_qcoord_t z, double vxyz[3])
Transform a quadrant coordinate into the space spanned by tree vertices.
Definition: p6est.c:127
p4est_gloidx_t p6est_partition(p6est_t *p6est, p6est_weight_t weight_fn)
Equally partition the forest.
Definition: p6est.c:2127
void p6est_tree_get_vertices(p6est_connectivity_t *conn, p4est_topidx_t which_tree, double vertices[24])
Get the vertices of the corners of a tree.
Definition: p6est.c:91
int(* p6est_coarsen_column_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *columns[])
Callback function prototype to decide for horizontal coarsening.
Definition: p6est.h:260
This structure holds the 2D+1D inter-tree connectivity information.
Definition: p6est.h:63
p6est_t * p6est_new(sc_MPI_Comm mpicomm, p6est_connectivity_t *connectivity, size_t data_size, p6est_init_t init_fn, void *user_pointer)
Create a new forest.
Definition: p6est.c:451
This structure holds the 2D inter-tree connectivity information.
Definition: p4est_connectivity.h:139
int(* p6est_refine_layer_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column, p2est_quadrant_t *layer)
Callback function prototype to decide whether to vertically refine a layer.
Definition: p6est.h:251
void p6est_balance(p6est_t *p6est, p8est_connect_type_t btype, p6est_init_t init_fn)
Balance a forest.
Definition: p6est.c:2269
void p6est_destroy(p6est_t *p6est)
Destroy a p6est.
Definition: p6est.c:531
The sc_array object provides a large array of equal-size elements.
Definition: sc_containers.h:92
int(* p6est_coarsen_layer_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column, p2est_quadrant_t *layers[])
Callback function prototype to decide for vertical coarsening.
Definition: p6est.h:268
static p2est_quadrant_t * p2est_quadrant_array_index(sc_array_t *array, size_t it)
Return a pointer to a quadrant array element indexed by a size_t.
Definition: p6est.h:525
static void sc_mempool_free(sc_mempool_t *mempool, void *elem)
Return a previously allocated element to the pool.
Definition: sc_containers.h:561
void p6est_coarsen_layers(p6est_t *p6est, int coarsen_recursive, p6est_coarsen_layer_t coarsen_fn, p6est_init_t init_fn)
Coarsen the layers of a sheet.
Definition: p6est.c:1742
double * top_vertices
if NULL, uniform vertical profile, otherwise the vertices of the top of the sheet: should be the same...
Definition: p6est.h:68
void * sc_list_pop(sc_list_t *list)
Remove an element from the front of the list.
static p2est_quadrant_t * p2est_quadrant_array_push(sc_array_t *array)
Call sc_array_push for a quadrant array.
Definition: p6est.h:536
static p2est_quadrant_t * p2est_quadrant_list_pop(sc_list_t *list)
Call sc_list pop for a quadrant array.
Definition: p6est.h:556
void * user_pointer
convenience pointer for users, never touched by p4est
Definition: p6est.h:170
int32_t p4est_topidx_t
Typedef for counting topological entities (trees, tree vertices).
Definition: p4est_base.h:63
int32_t p4est_locidx_t
Typedef for processor-local indexing of quadrants and nodes.
Definition: p4est_base.h:74
void p6est_save(const char *filename, p6est_t *p6est, int save_data)
Save the complete connectivity/p6est data to disk.
Definition: p6est.c:647
p6est_t * p6est_copy(p6est_t *input, int copy_data)
Make a deep copy of a p6est.
Definition: p6est.c:554
void p6est_refine_layers(p6est_t *p6est, int refine_recursive, p6est_refine_layer_t refine_fn, p6est_init_t init_fn)
Refine the layers within the columns of a sheet.
Definition: p6est.c:1358
The coarse topological description of the forest.
sc_mempool_t * layer_pool
memory allocator for temporary layers
Definition: p6est.h:180
p4est_connectivity_t * conn4
the 2D connecitvity; owned; vertices interpreted as the vertices of the bottom of the sheet ...
Definition: p6est.h:65
union p2est_quadrant_t::p6est_quadrant_data p
a union of additional data attached to a layer
static void * sc_mempool_alloc(sc_mempool_t *mempool)
Allocate a single element.
Definition: sc_containers.h:535
The sc_mempool object provides a large pool of equal-size elements.
Definition: sc_containers.h:496
The 2D quadrant datatype.
Definition: p4est.h:65
int mpisize
number of MPI processes
Definition: p6est.h:166
p6est_t * p6est_load(const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, void *user_pointer, p6est_connectivity_t **connectivity)
Load the complete connectivity/p6est structure from disk.
Definition: p6est.c:880
p6est_connectivity_t * connectivity
topology of sheet, not owned.
Definition: p6est.h:172
sc_mempool_t * user_data_pool
memory allocator for user data
Definition: p6est.h:177
p4est_topidx_t which_tree
the tree containing the quadrant
Definition: p6est.h:136