p4est 2.8.6
p4est is a software library for parallel adaptive mesh refinement.
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
43SC_EXTERN_C_BEGIN;
44
46#define P8EST_OLD_MAXLEVEL 19 /* old means prior to mid-2020 */
47#define P8EST_MAXLEVEL 30
48
50#define P8EST_OLD_QMAXLEVEL 18 /* old means prior to mid-2020 */
51#define P8EST_QMAXLEVEL 29
52
54#define P8EST_ROOT_LEN ((p4est_qcoord_t) 1 << P8EST_MAXLEVEL)
55
57#define P8EST_QUADRANT_LEN(l) ((p4est_qcoord_t) 1 << (P8EST_MAXLEVEL - (l)))
58
60#define P8EST_QUADRANT_MASK(l) (~(P8EST_QUADRANT_LEN (l) - 1))
61
64#define P8EST_LAST_OFFSET(l) (P8EST_ROOT_LEN - P8EST_QUADRANT_LEN (l))
65
67typedef struct p8est_quadrant
68{
72 int8_t level,
74 int16_t pad16;
76 {
77 void *user_data;
78 long user_long;
84 struct
85 {
87 int owner_rank;
88 }
90 struct
91 {
93 p4est_topidx_t from_tree;
94 }
95 piggy2;
97 struct
98 {
100 p4est_locidx_t local_num;
101 }
102 piggy3;
104 }
106}
108
110typedef struct p8est_tree
111{
112 sc_array_t quadrants;
120 int8_t maxlevel;
121}
123
129
131typedef struct p8est
132{
133 sc_MPI_Comm mpicomm;
137 size_t data_size;
142 long revision;
160 sc_array_t *trees;
162 sc_mempool_t *user_data_pool;
163 /* WARNING: This is NULL if data size
164 equals zero. */
165 sc_mempool_t *quadrant_pool;
168}
170
179
189
199typedef void (*p8est_init_t) (p8est_t * p8est,
200 p4est_topidx_t which_tree,
201 p8est_quadrant_t * quadrant);
202
209typedef int (*p8est_refine_t) (p8est_t * p8est,
210 p4est_topidx_t which_tree,
211 p8est_quadrant_t * quadrant);
212
219typedef int (*p8est_coarsen_t) (p8est_t * p8est,
220 p4est_topidx_t which_tree,
221 p8est_quadrant_t * quadrants[]);
222
229typedef int (*p8est_weight_t) (p8est_t * p8est,
230 p4est_topidx_t which_tree,
231 p8est_quadrant_t * quadrant);
232
233extern void *P8EST_DATA_UNINITIALIZED;
234
236#define P8EST_QUADRANT_INIT(q) \
237 ((void) memset ((q), -1, sizeof (p8est_quadrant_t)))
238
246 connectivity,
247 p4est_topidx_t treeid,
250 p4est_qcoord_t z, double vxyz[3]);
251
272p8est_t *p8est_new (sc_MPI_Comm mpicomm,
273 p8est_connectivity_t * connectivity,
274 size_t data_size,
275 p8est_init_t init_fn, void *user_pointer);
276
282
296p8est_t *p8est_copy (p8est_t * input, int copy_data);
297
311void p8est_reset_data (p8est_t * p8est, size_t data_size,
312 p8est_init_t init_fn,
313 void *user_pointer);
314
332 int refine_recursive,
333 p8est_refine_t refine_fn,
334 p8est_init_t init_fn);
335
345 int coarsen_recursive,
346 p8est_coarsen_t coarsen_fn,
347 p8est_init_t init_fn);
348
362 p8est_init_t init_fn);
363
386 int allow_for_coarsening,
387 p8est_weight_t weight_fn);
388
394
399
423void p8est_save (const char *filename, p8est_t * p8est,
424 int save_data);
425
454p8est_t *p8est_load (const char *filename, sc_MPI_Comm mpicomm,
455 size_t data_size, int load_data,
456 void *user_pointer,
457 p8est_connectivity_t ** connectivity);
458
462/*@unused@*/
463static inline p8est_tree_t *
464p8est_tree_array_index (sc_array_t * array, p4est_topidx_t it)
465{
466 P4EST_ASSERT (array->elem_size == sizeof (p8est_tree_t));
467 P4EST_ASSERT (it >= 0 && (size_t) it < array->elem_count);
468
469 return (p8est_tree_t *) (array->array +
470 sizeof (p8est_tree_t) * (size_t) it);
471}
472
474/*@unused@*/
475static inline p8est_quadrant_t *
476p8est_quadrant_array_index (sc_array_t * array, size_t it)
477{
478 P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
479 P4EST_ASSERT (it < array->elem_count);
480
481 return (p8est_quadrant_t *) (array->array + sizeof (p8est_quadrant_t) * it);
482}
483
492static inline p8est_quadrant_t *
493p8est_quadrant_array_push_copy (sc_array_t * array,
494 const p8est_quadrant_t *qsrc)
495{
497
498 P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
499
500 q = (p8est_quadrant_t *) sc_array_push (array);
501 *q = *qsrc;
502 return q;
503}
504
511/*@unused@*/
512static inline p8est_quadrant_t *
513p8est_quadrant_array_push (sc_array_t * array)
514{
516
517 P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
518
519 q = (p8est_quadrant_t *) sc_array_push (array);
521 return q;
522}
523
525/*@unused@*/
526static inline p8est_quadrant_t *
527p8est_quadrant_mempool_alloc (sc_mempool_t * mempool)
528{
529 P4EST_ASSERT (mempool->elem_size == sizeof (p8est_quadrant_t));
530
531 return (p8est_quadrant_t *) sc_mempool_alloc (mempool);
532}
533
535/*@unused@*/
536static inline p8est_quadrant_t *
537p8est_quadrant_list_pop (sc_list_t * list)
538{
539 return (p8est_quadrant_t *) sc_list_pop (list);
540}
541
542SC_EXTERN_C_END;
543
544#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
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:229
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:219
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:209
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.
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.
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.
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.
struct p8est p8est_t
The p8est forest datatype.
#define P8EST_QUADRANT_INIT(q)
set statically allocated quadrant to defined values
Definition: p8est.h:236
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:199
p8est_t * p8est_copy(p8est_t *input, int copy_data)
Make a deep copy of a p8est.
size_t p8est_memory_used(p8est_t *p8est)
Calculate local memory usage of a forest structure.
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.
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:119
This structure holds the 3D inter-tree connectivity information.
Definition: p8est_connectivity.h:215
Definition: p8est_extended.h:67
The 3D quadrant (i.e., octant) datatype.
Definition: p8est.h:68
int8_t level
level of refinement
Definition: p8est.h:72
union p8est_quadrant::p8est_quadrant_data p
a union of additional data attached to a quadrant
int16_t pad16
padding
Definition: p8est.h:74
p4est_qcoord_t z
coordinates
Definition: p8est.h:70
int8_t pad8
padding
Definition: p8est.h:73
The p8est tree datatype.
Definition: p8est.h:111
p8est_quadrant_t first_desc
first local descendant
Definition: p8est.h:113
int8_t maxlevel
highest local quadrant level
Definition: p8est.h:120
p4est_locidx_t quadrants_per_level[P8EST_MAXLEVEL+1]
locals only
Definition: p8est.h:118
sc_array_t quadrants
locally stored quadrants
Definition: p8est.h:112
p8est_quadrant_t last_desc
last local descendant
Definition: p8est.h:114
p4est_locidx_t quadrants_offset
cumulative sum over earlier trees on this processor (locals only)
Definition: p8est.h:115
The p8est forest datatype.
Definition: p8est.h:132
p4est_gloidx_t global_num_quadrants
number of quadrants on all trees on all processors
Definition: p8est.h:151
size_t data_size
size of per-quadrant p.user_data (see p8est_quadrant_t::p8est_quadrant_data::user_data)
Definition: p8est.h:137
p4est_topidx_t last_local_tree
0-based index of last local tree, must be -2 for an empty processor
Definition: p8est.h:146
sc_array_t * trees
array of all trees
Definition: p8est.h:160
p4est_gloidx_t * global_first_quadrant
first global quadrant index for each process and 1 beyond
Definition: p8est.h:153
p4est_topidx_t first_local_tree
0-based index of first local tree, must be -1 for an empty processor
Definition: p8est.h:143
sc_MPI_Comm mpicomm
MPI communicator.
Definition: p8est.h:133
p4est_locidx_t local_num_quadrants
number of quadrants on all trees on this processor
Definition: p8est.h:149
p8est_inspect_t * inspect
algorithmic switches
Definition: p8est.h:167
sc_mempool_t * quadrant_pool
memory allocator for temporary quadrants
Definition: p8est.h:165
sc_mempool_t * user_data_pool
memory allocator for user data
Definition: p8est.h:162
int mpicomm_owned
flag if communicator is owned
Definition: p8est.h:136
int mpisize
number of MPI processes
Definition: p8est.h:134
void * user_pointer
convenience pointer for users, never touched by p4est
Definition: p8est.h:139
p8est_quadrant_t * global_first_position
first smallest possible quad for each process and 1 beyond
Definition: p8est.h:156
int mpirank
this process's MPI rank
Definition: p8est.h:135
long revision
Gets bumped on mesh change.
Definition: p8est.h:142
p8est_connectivity_t * connectivity
connectivity structure, not owned
Definition: p8est.h:159
struct p8est_quadrant::p8est_quadrant_data::@15 piggy1
of ghost octants, store the tree and owner rank
struct p8est_quadrant::p8est_quadrant_data::@16 piggy2
of transformed octants, store the original tree and the target tree
struct p8est_quadrant::p8est_quadrant_data::@17 piggy3
of ghost octants, store the tree and index in the owner's numbering
int user_int
never changed by p4est
Definition: p8est.h:79
void * user_data
never changed by p4est
Definition: p8est.h:77
long user_long
never changed by p4est
Definition: p8est.h:78
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:80