p4est  1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
p8est.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) 2010 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 
36 #ifndef P8EST_H
37 #define P8EST_H
38 
39 /* p8est_connectivity.h includes p4est_base.h sc_containers.h */
40 #include <p8est_connectivity.h>
41 
42 SC_EXTERN_C_BEGIN;
43 
45 #define P8EST_MAXLEVEL 19
46 
48 #define P8EST_QMAXLEVEL 18
49 
51 #define P8EST_ROOT_LEN ((p4est_qcoord_t) 1 << P8EST_MAXLEVEL)
52 
54 #define P8EST_QUADRANT_LEN(l) ((p4est_qcoord_t) 1 << (P8EST_MAXLEVEL - (l)))
55 
58 #define P8EST_LAST_OFFSET(l) (P8EST_ROOT_LEN - P8EST_QUADRANT_LEN (l))
59 
61 typedef struct p8est_quadrant
62 {
64  p4est_qcoord_t x, y, z;
66  int8_t level,
67  pad8;
68  int16_t pad16;
70  {
71  void *user_data;
72  long user_long;
73  int user_int;
78  struct
79  {
80  p4est_topidx_t which_tree;
81  int owner_rank;
82  }
83  piggy1;
84  struct
85  {
86  p4est_topidx_t which_tree;
87  p4est_topidx_t from_tree;
88  }
89  piggy2;
91  struct
92  {
93  p4est_topidx_t which_tree;
94  p4est_locidx_t local_num;
95  }
96  piggy3;
98  }
99  p;
100 }
102 
104 typedef struct p8est_tree
105 {
107  p8est_quadrant_t first_desc,
108  last_desc;
112  p4est_locidx_t quadrants_per_level[P8EST_MAXLEVEL + 1];
114  int8_t maxlevel;
115 }
117 
122 typedef struct p8est_inspect p8est_inspect_t;
123 
125 typedef struct p8est
126 {
127  sc_MPI_Comm mpicomm;
128  int mpisize,
129  mpirank;
130  size_t data_size;
132  void *user_pointer;
155  /* WARNING: This is NULL if data size
156  equals zero. */
159  p8est_inspect_t *inspect;
160 }
161 p8est_t;
162 
169 size_t p8est_memory_used (p8est_t * p8est);
170 
180 typedef void (*p8est_init_t) (p8est_t * p8est,
181  p4est_topidx_t which_tree,
182  p8est_quadrant_t * quadrant);
183 
190 typedef int (*p8est_refine_t) (p8est_t * p8est,
191  p4est_topidx_t which_tree,
192  p8est_quadrant_t * quadrant);
193 
200 typedef int (*p8est_coarsen_t) (p8est_t * p8est,
201  p4est_topidx_t which_tree,
202  p8est_quadrant_t * quadrants[]);
203 
210 typedef int (*p8est_weight_t) (p8est_t * p8est,
211  p4est_topidx_t which_tree,
212  p8est_quadrant_t * quadrant);
213 
214 extern void *P8EST_DATA_UNINITIALIZED;
215 
217 #define P8EST_QUADRANT_INIT(q) \
218  ((void) memset ((q), -1, sizeof (p8est_quadrant_t)))
219 
227  connectivity,
228  p4est_topidx_t treeid,
229  p4est_qcoord_t x,
230  p4est_qcoord_t y,
231  p4est_qcoord_t z, double vxyz[3]);
232 
253 p8est_t *p8est_new (sc_MPI_Comm mpicomm,
254  p8est_connectivity_t * connectivity,
255  size_t data_size,
256  p8est_init_t init_fn, void *user_pointer);
257 
262 void p8est_destroy (p8est_t * p8est);
263 
274 p8est_t *p8est_copy (p8est_t * input, int copy_data);
275 
289 void p8est_reset_data (p8est_t * p8est, size_t data_size,
290  p8est_init_t init_fn,
291  void *user_pointer);
292 
309 void p8est_refine (p8est_t * p8est,
310  int refine_recursive,
312  p8est_init_t init_fn);
313 
322 void p8est_coarsen (p8est_t * p8est,
323  int coarsen_recursive,
324  p8est_coarsen_t coarsen_fn,
325  p8est_init_t init_fn);
326 
338 void p8est_balance (p8est_t * p8est,
339  p8est_connect_type_t btype,
340  p8est_init_t init_fn);
341 
354 void p8est_partition (p8est_t * p8est,
355  int allow_for_coarsening,
356  p8est_weight_t weight_fn);
357 
362 unsigned p8est_checksum (p8est_t * p8est);
363 
384 void p8est_save (const char *filename, p8est_t * p8est,
385  int save_data);
386 
413 p8est_t *p8est_load (const char *filename, sc_MPI_Comm mpicomm,
414  size_t data_size, int load_data,
415  void *user_pointer,
416  p8est_connectivity_t ** connectivity);
417 
421 /*@unused@*/
422 static inline p8est_tree_t *
424 {
425  P4EST_ASSERT (array->elem_size == sizeof (p8est_tree_t));
426  P4EST_ASSERT (it >= 0 && (size_t) it < array->elem_count);
427 
428  return (p8est_tree_t *) (array->array +
429  sizeof (p8est_tree_t) * (size_t) it);
430 }
431 
433 /*@unused@*/
434 static inline p8est_quadrant_t *
436 {
437  P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
438  P4EST_ASSERT (it < array->elem_count);
439 
440  return (p8est_quadrant_t *) (array->array + sizeof (p8est_quadrant_t) * it);
441 }
442 
444 /*@unused@*/
445 static inline p8est_quadrant_t *
447 {
448  P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
449 
450  return (p8est_quadrant_t *) sc_array_push (array);
451 }
452 
454 /*@unused@*/
455 static inline p8est_quadrant_t *
457 {
458  P4EST_ASSERT (mempool->elem_size == sizeof (p8est_quadrant_t));
459 
460  return (p8est_quadrant_t *) sc_mempool_alloc (mempool);
461 }
462 
464 /*@unused@*/
465 static inline p8est_quadrant_t *
467 {
468  return (p8est_quadrant_t *) sc_list_pop (list);
469 }
470 
471 SC_EXTERN_C_END;
472 
473 #endif /* !P8EST_H */
sc_MPI_Comm mpicomm
MPI communicator.
Definition: p8est.h:127
void p8est_qcoord_to_vertex(p8est_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.
int32_t p4est_qcoord_t
Typedef for quadrant coordinates.
Definition: p4est_base.h:53
sc_array_t quadrants
locally stored quadrants
Definition: p8est.h:106
int8_t maxlevel
highest local quadrant level
Definition: p8est.h:114
int16_t pad16
padding
Definition: p8est.h:68
void p8est_reset_data(p8est_t *p8est, size_t data_size, p8est_init_t init_fn, void *user_pointer)
Reset user pointer and element data.
void p8est_refine(p8est_t *p8est, int refine_recursive, p8est_refine_t refine_fn, p8est_init_t init_fn)
Refine a forest.
size_t p8est_memory_used(p8est_t *p8est)
Calculate memory usage of a forest structure.
size_t elem_size
size of a single element
Definition: sc_containers.h:499
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
size_t data_size
size of per-quadrant p.user_data (see p8est_quadrant_t::p8est_quadrant_data::user_data) ...
Definition: p8est.h:130
#define P8EST_MAXLEVEL
The finest level of the octree for representing nodes.
Definition: p8est.h:45
p8est_t * p8est_load(const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, void *user_pointer, p8est_connectivity_t **connectivity)
Load the complete connectivity/p8est structure from disk.
p4est_topidx_t first_local_tree
0-based index of first local tree, must be -1 for an empty processor
Definition: p8est.h:135
The sc_list object provides a linked list.
Definition: sc_containers.h:587
Data pertaining to selecting, inspecting, and profiling algorithms.
Definition: p8est_extended.h:56
static p8est_tree_t * p8est_tree_array_index(sc_array_t *array, p4est_topidx_t it)
Return a pointer to an array element indexed by a p4est_topidx_t.
Definition: p8est.h:423
p8est_quadrant_t last_desc
last local descendant
Definition: p8est.h:107
p4est_locidx_t quadrants_offset
cumulative sum over earlier trees on this processor (locals only)
Definition: p8est.h:109
void p8est_partition(p8est_t *p8est, int allow_for_coarsening, p8est_weight_t weight_fn)
Equally partition the forest.
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
unsigned p8est_checksum(p8est_t *p8est)
Compute the checksum for a forest.
static p8est_quadrant_t * p8est_quadrant_mempool_alloc(sc_mempool_t *mempool)
Call sc_mempool_alloc for a mempool creating quadrants.
Definition: p8est.h:456
p4est_topidx_t which_tree
the tree containing the quadrant (used in auxiliary octants such as the ghost octants in p4est_ghost_...
Definition: p8est.h:74
p8est_connectivity_t * connectivity
connectivity structure, not owned
Definition: p8est.h:151
int user_int
never changed by p4est
Definition: p8est.h:73
int64_t p4est_gloidx_t
Typedef for globally unique indexing of quadrants.
Definition: p4est_base.h:84
void p8est_destroy(p8est_t *p8est)
Destroy a p8est.
static void * sc_array_push(sc_array_t *array)
Enlarge an array by one element.
Definition: sc_containers.h:485
long user_long
never changed by p4est
Definition: p8est.h:72
int8_t pad8
padding
Definition: p8est.h:66
p8est_quadrant_t * global_first_position
first smallest possible quad for each process and 1 beyond
Definition: p8est.h:148
This structure holds the 3D inter-tree connectivity information.
Definition: p8est_connectivity.h:158
The 3D quadrant (i.e.
Definition: p8est.h:61
int(* p8est_refine_t)(p8est_t *p8est, p4est_topidx_t which_tree, p8est_quadrant_t *quadrant)
Callback function prototype to decide for refinement.
Definition: p8est.h:190
The p8est forest datatype.
Definition: p8est.h:125
sc_mempool_t * user_data_pool
memory allocator for user data
Definition: p8est.h:154
p8est_t * p8est_copy(p8est_t *input, int copy_data)
Make a deep copy of a p8est.
p4est_locidx_t local_num_quadrants
number of quadrants on all trees on this processor
Definition: p8est.h:141
static p8est_quadrant_t * p8est_quadrant_array_push(sc_array_t *array)
Call sc_array_push for a quadrant array.
Definition: p8est.h:446
void(* p8est_init_t)(p8est_t *p8est, p4est_topidx_t which_tree, p8est_quadrant_t *quadrant)
Callback function prototype to initialize the quadrant's user data.
Definition: p8est.h:180
The sc_array object provides a large array of equal-size elements.
Definition: sc_containers.h:92
void p8est_save(const char *filename, p8est_t *p8est, int save_data)
Save the complete connectivity/p8est data to disk.
int(* p8est_weight_t)(p8est_t *p8est, p4est_topidx_t which_tree, p8est_quadrant_t *quadrant)
Callback function prototype to calculate weights for partitioning.
Definition: p8est.h:210
void * sc_list_pop(sc_list_t *list)
Remove an element from the front of the list.
p4est_qcoord_t z
coordinates
Definition: p8est.h:64
int mpisize
number of MPI processes
Definition: p8est.h:128
sc_mempool_t * quadrant_pool
memory allocator for temporary quadrants
Definition: p8est.h:157
int32_t p4est_topidx_t
Typedef for counting topological entities (trees, tree vertices).
Definition: p4est_base.h:63
sc_array_t * trees
array of all trees
Definition: p8est.h:152
int32_t p4est_locidx_t
Typedef for processor-local indexing of quadrants and nodes.
Definition: p4est_base.h:74
p4est_gloidx_t global_num_quadrants
number of quadrants on all trees on all processors
Definition: p8est.h:143
p4est_topidx_t last_local_tree
0-based index of last local tree, must be -2 for an empty processor
Definition: p8est.h:138
void * user_data
never changed by p4est
Definition: p8est.h:71
static p8est_quadrant_t * p8est_quadrant_list_pop(sc_list_t *list)
Call sc_list pop for a quadrant array.
Definition: p8est.h:466
p4est_gloidx_t * global_first_quadrant
first global quadrant index for each process and 1 beyond
Definition: p8est.h:145
The p8est tree datatype.
Definition: p8est.h:104
int(* p8est_coarsen_t)(p8est_t *p8est, p4est_topidx_t which_tree, p8est_quadrant_t *quadrants[])
Callback function prototype to decide for coarsening.
Definition: p8est.h:200
The coarse topological description of the forest.
void p8est_balance(p8est_t *p8est, p8est_connect_type_t btype, p8est_init_t init_fn)
2:1 balance the size differences of neighboring elements in a forest.
p8est_inspect_t * inspect
algorithmic switches
Definition: p8est.h:159
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
void p8est_coarsen(p8est_t *p8est, int coarsen_recursive, p8est_coarsen_t coarsen_fn, p8est_init_t init_fn)
Coarsen a forest.
p8est_t * p8est_new(sc_MPI_Comm mpicomm, p8est_connectivity_t *connectivity, size_t data_size, p8est_init_t init_fn, void *user_pointer)
Create a new forest.
static p8est_quadrant_t * p8est_quadrant_array_index(sc_array_t *array, size_t it)
Return a pointer to a quadrant array element indexed by a size_t.
Definition: p8est.h:435
void * user_pointer
convenience pointer for users, never touched by p4est
Definition: p8est.h:132