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
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  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 P8EST_H
38 #define P8EST_H
39 
40 /* p8est_connectivity.h includes p4est_base.h sc_containers.h */
41 #include <p8est_connectivity.h>
42 
43 SC_EXTERN_C_BEGIN;
44 
46 #define P8EST_OLD_MAXLEVEL 19 /* old means prior to mid-2020 */
47 
49 #define P8EST_MAXLEVEL 30
50 
52 #define P8EST_OLD_QMAXLEVEL 18 /* old means prior to mid-2020 */
53 
55 #define P8EST_QMAXLEVEL 29
56 
58 #define P8EST_ROOT_LEN ((p4est_qcoord_t) 1 << P8EST_MAXLEVEL)
59 
61 #define P8EST_QUADRANT_LEN(l) ((p4est_qcoord_t) 1 << (P8EST_MAXLEVEL - (l)))
62 
64 #define P8EST_QUADRANT_MASK(l) (~(P8EST_QUADRANT_LEN (l) - 1))
65 
68 #define P8EST_LAST_OFFSET(l) (P8EST_ROOT_LEN - P8EST_QUADRANT_LEN (l))
69 
71 typedef struct p8est_quadrant
72 {
74  p4est_qcoord_t x, y, z;
76  int8_t level,
77  pad8;
78  int16_t pad16;
89  {
90  void *user_data;
91  long user_long;
92  int user_int;
97  struct
98  {
100  int owner_rank;
101  }
102  piggy1;
104  struct
105  {
107  p4est_topidx_t from_tree;
108  }
109  piggy2;
111  struct
112  {
114  p4est_locidx_t local_num;
115  }
116  piggy3;
118  }
119  p;
120 }
122 
124 typedef struct p8est_tree
125 {
126  sc_array_t quadrants;
134  int8_t maxlevel;
135 }
137 
142 typedef struct p8est_inspect p8est_inspect_t;
143 
145 typedef struct p8est
146 {
147  sc_MPI_Comm mpicomm;
148  int mpisize,
151  size_t data_size;
153  void *user_pointer;
156  long revision;
174  sc_array_t *trees;
176  sc_mempool_t *user_data_pool;
177  /* WARNING: This is NULL if data size
178  equals zero. */
179  sc_mempool_t *quadrant_pool;
182 }
184 
193 
203 
213 typedef void (*p8est_init_t) (p8est_t * p8est,
214  p4est_topidx_t which_tree,
215  p8est_quadrant_t * quadrant);
216 
223 typedef int (*p8est_refine_t) (p8est_t * p8est,
224  p4est_topidx_t which_tree,
225  p8est_quadrant_t * quadrant);
226 
233 typedef int (*p8est_coarsen_t) (p8est_t * p8est,
234  p4est_topidx_t which_tree,
235  p8est_quadrant_t * quadrants[]);
236 
243 typedef int (*p8est_weight_t) (p8est_t * p8est,
244  p4est_topidx_t which_tree,
245  p8est_quadrant_t * quadrant);
246 
247 extern void *P8EST_DATA_UNINITIALIZED;
248 
250 #define P8EST_QUADRANT_INIT(q) \
251  ((void) memset ((q), -1, sizeof (p8est_quadrant_t)))
252 
260  connectivity,
261  p4est_topidx_t treeid,
262  p4est_qcoord_t x,
263  p4est_qcoord_t y,
264  p4est_qcoord_t z, double vxyz[3]);
265 
286 p8est_t *p8est_new (sc_MPI_Comm mpicomm,
287  p8est_connectivity_t * connectivity,
288  size_t data_size,
289  p8est_init_t init_fn, void *user_pointer);
290 
296 
310 p8est_t *p8est_copy (p8est_t * input, int copy_data);
311 
325 void p8est_reset_data (p8est_t * p8est, size_t data_size,
326  p8est_init_t init_fn,
327  void *user_pointer);
328 
346  int refine_recursive,
347  p8est_refine_t refine_fn,
348  p8est_init_t init_fn);
349 
359  int coarsen_recursive,
360  p8est_coarsen_t coarsen_fn,
361  p8est_init_t init_fn);
362 
375  p8est_connect_type_t btype,
376  p8est_init_t init_fn);
377 
402  int allow_for_coarsening,
403  p8est_weight_t weight_fn);
404 
410 
415 
439 void p8est_save (const char *filename, p8est_t * p8est,
440  int save_data);
441 
470 p8est_t *p8est_load (const char *filename, sc_MPI_Comm mpicomm,
471  size_t data_size, int load_data,
472  void *user_pointer,
473  p8est_connectivity_t ** connectivity);
474 
478 /*@unused@*/
479 static inline p8est_tree_t *
480 p8est_tree_array_index (sc_array_t * array, p4est_topidx_t it)
481 {
482  P4EST_ASSERT (array->elem_size == sizeof (p8est_tree_t));
483  P4EST_ASSERT (it >= 0 && (size_t) it < array->elem_count);
484 
485  return (p8est_tree_t *) (array->array +
486  sizeof (p8est_tree_t) * (size_t) it);
487 }
488 
490 /*@unused@*/
491 static inline p8est_quadrant_t *
492 p8est_quadrant_array_index (sc_array_t * array, size_t it)
493 {
494  P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
495  P4EST_ASSERT (it < array->elem_count);
496 
497  return (p8est_quadrant_t *) (array->array + sizeof (p8est_quadrant_t) * it);
498 }
499 
508 static inline p8est_quadrant_t *
509 p8est_quadrant_array_push_copy (sc_array_t * array,
510  const p8est_quadrant_t *qsrc)
511 {
512  p8est_quadrant_t *q;
513 
514  P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
515 
516  q = (p8est_quadrant_t *) sc_array_push (array);
517  *q = *qsrc;
518  return q;
519 }
520 
527 /*@unused@*/
528 static inline p8est_quadrant_t *
529 p8est_quadrant_array_push (sc_array_t * array)
530 {
531  p8est_quadrant_t *q;
532 
533  P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
534 
535  q = (p8est_quadrant_t *) sc_array_push (array);
537  return q;
538 }
539 
541 /*@unused@*/
542 static inline p8est_quadrant_t *
543 p8est_quadrant_mempool_alloc (sc_mempool_t * mempool)
544 {
545  P4EST_ASSERT (mempool->elem_size == sizeof (p8est_quadrant_t));
546 
547  return (p8est_quadrant_t *) sc_mempool_alloc (mempool);
548 }
549 
551 /*@unused@*/
552 static inline p8est_quadrant_t *
553 p8est_quadrant_list_pop (sc_list_t * list)
554 {
555  return (p8est_quadrant_t *) sc_list_pop (list);
556 }
557 
558 SC_EXTERN_C_END;
559 
560 #endif /* !P8EST_H */
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
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 with an initial coarse mesh.
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:243
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:233
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:223
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.
#define P8EST_MAXLEVEL
The finest level for representing quadrant midpoint coordinates.
Definition: p8est.h:49
long p8est_revision(p8est_t *p8est)
Return the revision counter of the forest.
void p8est_refine(p8est_t *p8est, int refine_recursive, p8est_refine_t refine_fn, p8est_init_t init_fn)
Refine a forest.
void p8est_partition(p8est_t *p8est, int allow_for_coarsening, p8est_weight_t weight_fn)
Equally partition the forest.
unsigned p8est_checksum_partition(p8est_t *p8est)
Compute a partition-dependent checksum for a forest.
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_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.
struct p8est p8est_t
The p8est forest datatype.
#define P8EST_QUADRANT_INIT(q)
set statically allocated quadrant to defined values
Definition: p8est.h:250
p8est_t * p8est_copy(p8est_t *input, int copy_data)
Make a deep copy of a p8est.
struct p8est_tree p8est_tree_t
The p8est tree datatype.
void p8est_destroy(p8est_t *p8est)
Destroy a p8est.
void p8est_save(const char *filename, p8est_t *p8est, int save_data)
Save the complete connectivity/p8est data to disk.
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_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.
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:213
size_t p8est_memory_used(p8est_t *p8est)
Calculate local memory usage of a forest structure.
unsigned p8est_checksum(p8est_t *p8est)
Compute the checksum for a forest.
struct p8est_quadrant p8est_quadrant_t
The 3D quadrant (i.e., octant) datatype.
The connectivity defines the coarse topology of the forest.
p8est_connect_type_t
Characterize a type of adjacency.
Definition: p8est_connectivity.h:120
This structure holds the 3D inter-tree connectivity information.
Definition: p8est_connectivity.h:216
Definition: p8est_extended.h:67
The 3D quadrant (i.e., octant) datatype.
Definition: p8est.h:72
int8_t level
level of refinement
Definition: p8est.h:76
union p8est_quadrant::p8est_quadrant_data p
a union of additional data attached to a quadrant
int16_t pad16
padding
Definition: p8est.h:78
p4est_qcoord_t z
coordinates
Definition: p8est.h:74
int8_t pad8
padding
Definition: p8est.h:77
The p8est tree datatype.
Definition: p8est.h:125
p8est_quadrant_t first_desc
first local descendant
Definition: p8est.h:127
int8_t maxlevel
highest local quadrant level
Definition: p8est.h:134
p4est_locidx_t quadrants_per_level[P8EST_MAXLEVEL+1]
locals only
Definition: p8est.h:132
sc_array_t quadrants
locally stored quadrants
Definition: p8est.h:126
p8est_quadrant_t last_desc
last local descendant
Definition: p8est.h:128
p4est_locidx_t quadrants_offset
cumulative sum over earlier trees on this processor (locals only)
Definition: p8est.h:129
The p8est forest datatype.
Definition: p8est.h:146
p4est_gloidx_t global_num_quadrants
number of quadrants on all trees on all processors
Definition: p8est.h:165
size_t data_size
size of per-quadrant p.user_data (see p8est_quadrant_t::p8est_quadrant_data::user_data)
Definition: p8est.h:151
p4est_topidx_t last_local_tree
0-based index of last local tree, must be -2 for an empty processor
Definition: p8est.h:160
sc_array_t * trees
array of all trees
Definition: p8est.h:174
p4est_gloidx_t * global_first_quadrant
first global quadrant index for each process and 1 beyond
Definition: p8est.h:167
p4est_topidx_t first_local_tree
0-based index of first local tree, must be -1 for an empty processor
Definition: p8est.h:157
sc_MPI_Comm mpicomm
MPI communicator.
Definition: p8est.h:147
p4est_locidx_t local_num_quadrants
number of quadrants on all trees on this processor
Definition: p8est.h:163
p8est_inspect_t * inspect
algorithmic switches
Definition: p8est.h:181
sc_mempool_t * quadrant_pool
memory allocator for temporary quadrants
Definition: p8est.h:179
sc_mempool_t * user_data_pool
memory allocator for user data
Definition: p8est.h:176
int mpicomm_owned
flag if communicator is owned
Definition: p8est.h:150
int mpisize
number of MPI processes
Definition: p8est.h:148
void * user_pointer
convenience pointer for users, never touched by p4est
Definition: p8est.h:153
p8est_quadrant_t * global_first_position
first smallest possible quad for each process and 1 beyond
Definition: p8est.h:170
int mpirank
this process's MPI rank
Definition: p8est.h:149
long revision
Gets bumped on mesh change.
Definition: p8est.h:156
p8est_connectivity_t * connectivity
connectivity structure, not owned
Definition: p8est.h:173
Union for quadrant data.
Definition: p8est.h:89
int user_int
never changed by p4est
Definition: p8est.h:92
void * user_data
never changed by p4est
Definition: p8est.h:90
struct p8est_quadrant::p8est_quadrant_data::@13 piggy1
of ghost octants, store the tree and owner rank; not part of the API
long user_long
never changed by p4est
Definition: p8est.h:91
struct p8est_quadrant::p8est_quadrant_data::@15 piggy3
of ghost octants, store the tree and index in the owner's numbering; only part of the API in p8est_gh...
struct p8est_quadrant::p8est_quadrant_data::@14 piggy2
of transformed octants, store the original tree and the target tree; not part of the API
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:93