p4est  2.8.7
p4est is a software library for parallel adaptive mesh refinement.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
p4est.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  Additional copyright (C) 2011 individual authors
8  Written by Carsten Burstedde, Lucas C. Wilcox, and Tobin Isaac
9 
10  p4est is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  p4est is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with p4est; if not, write to the Free Software Foundation, Inc.,
22  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24 
37 #ifndef P4EST_H
38 #define P4EST_H
39 
40 #ifdef P4EST_TO_P8EST_H
41 #error "The include files p4est.h and p4est_to_p8est.h cannot be combined"
42 #endif
43 
44 /* p4est_connectivity.h includes p4est_base.h sc_containers.h */
45 #include <p4est_connectivity.h>
46 
47 SC_EXTERN_C_BEGIN;
48 
50 #define P4EST_OLD_MAXLEVEL 30 /* in 2D, the maxlevel has always been 30 */
51 
53 #define P4EST_MAXLEVEL 30
54 
56 #define P4EST_OLD_QMAXLEVEL 29 /* in 2D, the qmaxlevel has always been 29 */
57 
59 #define P4EST_QMAXLEVEL 29
60 
62 #define P4EST_ROOT_LEN ((p4est_qcoord_t) 1 << P4EST_MAXLEVEL)
63 
65 #define P4EST_QUADRANT_LEN(l) ((p4est_qcoord_t) 1 << (P4EST_MAXLEVEL - (l)))
66 
68 #define P4EST_QUADRANT_MASK(l) (~(P4EST_QUADRANT_LEN (l) - 1))
69 
72 #define P4EST_LAST_OFFSET(l) (P4EST_ROOT_LEN - P4EST_QUADRANT_LEN (l))
73 
75 typedef struct p4est_quadrant
76 {
80  int8_t level,
81  pad8;
82  int16_t pad16;
93  {
94  void *user_data;
95  long user_long;
96  int user_int;
101  struct
102  {
104  int owner_rank;
105  }
106  piggy1;
108  struct
109  {
111  p4est_topidx_t from_tree;
112  }
113  piggy2;
115  struct
116  {
118  p4est_locidx_t local_num;
119  }
120  piggy3;
122  }
123  p;
124 }
126 
128 typedef struct p4est_tree
129 {
130  sc_array_t quadrants;
138  int8_t maxlevel;
139 }
141 
146 typedef struct p4est_inspect p4est_inspect_t;
147 
149 typedef struct p4est
150 {
151  sc_MPI_Comm mpicomm;
152  int mpisize,
155  size_t data_size;
157  void *user_pointer;
160  long revision;
178  sc_array_t *trees;
180  sc_mempool_t *user_data_pool;
181  /* WARNING: This is NULL if data size
182  equals zero. */
183  sc_mempool_t *quadrant_pool;
186 }
188 
197 
207 
217 typedef void (*p4est_init_t) (p4est_t * p4est,
218  p4est_topidx_t which_tree,
219  p4est_quadrant_t * quadrant);
220 
227 typedef int (*p4est_refine_t) (p4est_t * p4est,
228  p4est_topidx_t which_tree,
229  p4est_quadrant_t * quadrant);
230 
237 typedef int (*p4est_coarsen_t) (p4est_t * p4est,
238  p4est_topidx_t which_tree,
239  p4est_quadrant_t * quadrants[]);
240 
247 typedef int (*p4est_weight_t) (p4est_t * p4est,
248  p4est_topidx_t which_tree,
249  p4est_quadrant_t * quadrant);
250 
251 extern void *P4EST_DATA_UNINITIALIZED;
252 
254 #define P4EST_QUADRANT_INIT(q) \
255  ((void) memset ((q), -1, sizeof (p4est_quadrant_t)))
256 
264  connectivity,
265  p4est_topidx_t treeid,
266  p4est_qcoord_t x,
267  p4est_qcoord_t y, double vxyz[3]);
268 
289 p4est_t *p4est_new (sc_MPI_Comm mpicomm,
290  p4est_connectivity_t * connectivity,
291  size_t data_size,
292  p4est_init_t init_fn, void *user_pointer);
293 
299 
313 p4est_t *p4est_copy (p4est_t * input, int copy_data);
314 
328 void p4est_reset_data (p4est_t * p4est, size_t data_size,
329  p4est_init_t init_fn,
330  void *user_pointer);
331 
349  int refine_recursive,
350  p4est_refine_t refine_fn,
351  p4est_init_t init_fn);
352 
362  int coarsen_recursive,
363  p4est_coarsen_t coarsen_fn,
364  p4est_init_t init_fn);
365 
375  p4est_connect_type_t btype,
376  p4est_init_t init_fn);
377 
402  int allow_for_coarsening,
403  p4est_weight_t weight_fn);
404 
410 
415 
439 void p4est_save (const char *filename, p4est_t * p4est,
440  int save_data);
441 
470 p4est_t *p4est_load (const char *filename, sc_MPI_Comm mpicomm,
471  size_t data_size, int load_data,
472  void *user_pointer,
473  p4est_connectivity_t ** connectivity);
474 
478 /*@unused@*/
479 static inline p4est_tree_t *
480 p4est_tree_array_index (sc_array_t * array, p4est_topidx_t it)
481 {
482  P4EST_ASSERT (array->elem_size == sizeof (p4est_tree_t));
483  P4EST_ASSERT (it >= 0 && (size_t) it < array->elem_count);
484 
485  return (p4est_tree_t *) (array->array +
486  sizeof (p4est_tree_t) * (size_t) it);
487 }
488 
490 /*@unused@*/
491 static inline p4est_quadrant_t *
492 p4est_quadrant_array_index (sc_array_t * array, size_t it)
493 {
494  P4EST_ASSERT (array->elem_size == sizeof (p4est_quadrant_t));
495  P4EST_ASSERT (it < array->elem_count);
496 
497  return (p4est_quadrant_t *) (array->array + sizeof (p4est_quadrant_t) * it);
498 }
499 
508 static inline p4est_quadrant_t *
509 p4est_quadrant_array_push_copy (sc_array_t * array,
510  const p4est_quadrant_t *qsrc)
511 {
512  p4est_quadrant_t *q;
513 
514  P4EST_ASSERT (array->elem_size == sizeof (p4est_quadrant_t));
515 
516  q = (p4est_quadrant_t *) sc_array_push (array);
517  *q = *qsrc;
518  return q;
519 }
520 
527 /*@unused@*/
528 static inline p4est_quadrant_t *
529 p4est_quadrant_array_push (sc_array_t * array)
530 {
531  p4est_quadrant_t *q;
532 
533  P4EST_ASSERT (array->elem_size == sizeof (p4est_quadrant_t));
534 
535  q = (p4est_quadrant_t *) sc_array_push (array);
537  return q;
538 }
539 
541 /*@unused@*/
542 static inline p4est_quadrant_t *
543 p4est_quadrant_mempool_alloc (sc_mempool_t * mempool)
544 {
545  P4EST_ASSERT (mempool->elem_size == sizeof (p4est_quadrant_t));
546 
547  return (p4est_quadrant_t *) sc_mempool_alloc (mempool);
548 }
549 
551 /*@unused@*/
552 static inline p4est_quadrant_t *
553 p4est_quadrant_list_pop (sc_list_t * list)
554 {
555  return (p4est_quadrant_t *) sc_list_pop (list);
556 }
557 
558 SC_EXTERN_C_END;
559 
560 #endif /* !P4EST_H */
int(* p4est_coarsen_t)(p4est_t *p4est, p4est_topidx_t which_tree, p4est_quadrant_t *quadrants[])
Callback function prototype to decide for coarsening.
Definition: p4est.h:237
struct p4est_tree p4est_tree_t
The p4est tree datatype.
void p4est_refine(p4est_t *p4est, int refine_recursive, p4est_refine_t refine_fn, p4est_init_t init_fn)
Refine a forest.
void p4est_destroy(p4est_t *p4est)
Destroy a p4est.
void(* p4est_init_t)(p4est_t *p4est, p4est_topidx_t which_tree, p4est_quadrant_t *quadrant)
Callback function prototype to initialize the quadrant's user data.
Definition: p4est.h:217
void p4est_save(const char *filename, p4est_t *p4est, int save_data)
Save the complete connectivity/p4est data to disk.
size_t p4est_memory_used(p4est_t *p4est)
Calculate local memory usage of a forest structure.
void p4est_partition(p4est_t *p4est, int allow_for_coarsening, p4est_weight_t weight_fn)
Equally partition the forest.
unsigned p4est_checksum_partition(p4est_t *p4est)
Compute a partition-dependent checksum for a forest.
void p4est_balance(p4est_t *p4est, p4est_connect_type_t btype, p4est_init_t init_fn)
2:1 balance the size differences of neighboring elements in a forest.
#define P4EST_QUADRANT_INIT(q)
set statically allocated quadrant to defined values
Definition: p4est.h:254
p4est_t * p4est_copy(p4est_t *input, int copy_data)
Make a deep copy of a p4est.
void p4est_qcoord_to_vertex(p4est_connectivity_t *connectivity, p4est_topidx_t treeid, p4est_qcoord_t x, p4est_qcoord_t y, double vxyz[3])
Transform a quadrant coordinate into the space spanned by tree vertices.
#define P4EST_MAXLEVEL
The finest level for representing quadrant midpoint coordinates.
Definition: p4est.h:53
p4est_t * p4est_load(const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, void *user_pointer, p4est_connectivity_t **connectivity)
Load the complete connectivity/p4est structure from disk.
long p4est_revision(p4est_t *p4est)
Return the revision counter of the forest.
int(* p4est_weight_t)(p4est_t *p4est, p4est_topidx_t which_tree, p4est_quadrant_t *quadrant)
Callback function prototype to calculate weights for partitioning.
Definition: p4est.h:247
struct p4est p4est_t
The p4est forest datatype.
p4est_t * p4est_new(sc_MPI_Comm mpicomm, p4est_connectivity_t *connectivity, size_t data_size, p4est_init_t init_fn, void *user_pointer)
Create a new forest with an initial coarse mesh.
unsigned p4est_checksum(p4est_t *p4est)
Compute the checksum for a forest.
void p4est_coarsen(p4est_t *p4est, int coarsen_recursive, p4est_coarsen_t coarsen_fn, p4est_init_t init_fn)
Coarsen a forest.
int(* p4est_refine_t)(p4est_t *p4est, p4est_topidx_t which_tree, p4est_quadrant_t *quadrant)
Callback function prototype to decide for refinement.
Definition: p4est.h:227
struct p4est_quadrant p4est_quadrant_t
The 2D quadrant datatype.
void p4est_reset_data(p4est_t *p4est, size_t data_size, p4est_init_t init_fn, void *user_pointer)
Reset user pointer and element data.
int32_t p4est_qcoord_t
Typedef for quadrant coordinates.
Definition: p4est_base.h:81
int32_t p4est_topidx_t
Typedef for counting topological entities (trees, tree vertices).
Definition: p4est_base.h:93
int32_t p4est_locidx_t
Typedef for processor-local indexing of quadrants and nodes.
Definition: p4est_base.h:106
int64_t p4est_gloidx_t
Typedef for globally unique indexing of quadrants.
Definition: p4est_base.h:118
The connectivity defines the coarse topology of the forest.
p4est_connect_type_t
Characterize a type of adjacency.
Definition: p4est_connectivity.h:113
This structure holds the 2D inter-tree connectivity information.
Definition: p4est_connectivity.h:190
Data pertaining to selecting, inspecting, and profiling algorithms.
Definition: p4est_extended.h:62
The 2D quadrant datatype.
Definition: p4est.h:76
int8_t level
level of refinement
Definition: p4est.h:80
int16_t pad16
padding
Definition: p4est.h:82
union p4est_quadrant::p4est_quadrant_data p
a union of additional data attached to a quadrant
p4est_qcoord_t y
coordinates
Definition: p4est.h:78
int8_t pad8
padding
Definition: p4est.h:81
The p4est tree datatype.
Definition: p4est.h:129
p4est_quadrant_t last_desc
last local descendant
Definition: p4est.h:132
p4est_quadrant_t first_desc
first local descendant
Definition: p4est.h:131
int8_t maxlevel
highest local quadrant level
Definition: p4est.h:138
sc_array_t quadrants
locally stored quadrants
Definition: p4est.h:130
p4est_locidx_t quadrants_offset
cumulative sum over earlier trees on this processor (locals only)
Definition: p4est.h:133
p4est_locidx_t quadrants_per_level[P4EST_MAXLEVEL+1]
locals only
Definition: p4est.h:136
The p4est forest datatype.
Definition: p4est.h:150
p4est_topidx_t first_local_tree
0-based index of first local tree, must be -1 for an empty processor
Definition: p4est.h:161
p4est_connectivity_t * connectivity
connectivity structure, not owned
Definition: p4est.h:177
p4est_locidx_t local_num_quadrants
number of quadrants on all trees on this processor
Definition: p4est.h:167
void * user_pointer
convenience pointer for users, never touched by p4est
Definition: p4est.h:157
int mpisize
number of MPI processes
Definition: p4est.h:152
int mpirank
this process's MPI rank
Definition: p4est.h:153
sc_array_t * trees
array of all trees
Definition: p4est.h:178
size_t data_size
size of per-quadrant p.user_data (see p4est_quadrant_t::p4est_quadrant_data::user_data)
Definition: p4est.h:155
long revision
Gets bumped on mesh change.
Definition: p4est.h:160
p4est_inspect_t * inspect
algorithmic switches
Definition: p4est.h:185
sc_MPI_Comm mpicomm
MPI communicator.
Definition: p4est.h:151
p4est_gloidx_t global_num_quadrants
number of quadrants on all trees on all processors
Definition: p4est.h:169
p4est_quadrant_t * global_first_position
first smallest possible quad for each process and 1 beyond
Definition: p4est.h:174
int mpicomm_owned
flag if communicator is owned
Definition: p4est.h:154
sc_mempool_t * quadrant_pool
memory allocator for temporary quadrants
Definition: p4est.h:183
p4est_topidx_t last_local_tree
0-based index of last local tree, must be -2 for an empty processor
Definition: p4est.h:164
sc_mempool_t * user_data_pool
memory allocator for user data
Definition: p4est.h:180
p4est_gloidx_t * global_first_quadrant
first global quadrant index for each process and 1 beyond
Definition: p4est.h:171
Union for quadrant data.
Definition: p4est.h:93
struct p4est_quadrant::p4est_quadrant_data::@0 piggy1
of ghost octants, store the tree and owner rank; not part of the API
long user_long
never changed by p4est
Definition: p4est.h:95
struct p4est_quadrant::p4est_quadrant_data::@1 piggy2
of transformed octants, store the original tree and the target tree; not part of the API
int user_int
never changed by p4est
Definition: p4est.h:96
p4est_topidx_t which_tree
the tree containing the quadrant (used in auxiliary octants such as the ghost octants in p4est_ghost_...
Definition: p4est.h:97
struct p4est_quadrant::p4est_quadrant_data::@2 piggy3
of ghost octants, store the tree and index in the owner's numbering; only part of the API in p4est_gh...
void * user_data
never changed by p4est
Definition: p4est.h:94