p4est 2.8.6
p4est is a software library for parallel adaptive mesh refinement.
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
47SC_EXTERN_C_BEGIN;
48
50#define P4EST_OLD_MAXLEVEL 30 /* in 2D, the maxlevel has always been 30 */
51#define P4EST_MAXLEVEL 30
52
54#define P4EST_OLD_QMAXLEVEL 29 /* in 2D, the qmaxlevel has always been 29 */
55#define P4EST_QMAXLEVEL 29
56
58#define P4EST_ROOT_LEN ((p4est_qcoord_t) 1 << P4EST_MAXLEVEL)
59
61#define P4EST_QUADRANT_LEN(l) ((p4est_qcoord_t) 1 << (P4EST_MAXLEVEL - (l)))
62
64#define P4EST_QUADRANT_MASK(l) (~(P4EST_QUADRANT_LEN (l) - 1))
65
68#define P4EST_LAST_OFFSET(l) (P4EST_ROOT_LEN - P4EST_QUADRANT_LEN (l))
69
71typedef struct p4est_quadrant
72{
76 int8_t level,
78 int16_t pad16;
80 {
81 void *user_data;
82 long user_long;
88 struct
89 {
91 int owner_rank;
92 }
94 struct
95 {
97 p4est_topidx_t from_tree;
98 }
99 piggy2;
101 struct
102 {
104 p4est_locidx_t local_num;
105 }
106 piggy3;
108 }
110}
112
114typedef struct p4est_tree
115{
116 sc_array_t quadrants;
124 int8_t maxlevel;
125}
127
133
135typedef struct p4est
136{
137 sc_MPI_Comm mpicomm;
141 size_t data_size;
146 long revision;
164 sc_array_t *trees;
166 sc_mempool_t *user_data_pool;
167 /* WARNING: This is NULL if data size
168 equals zero. */
169 sc_mempool_t *quadrant_pool;
172}
174
183
193
203typedef void (*p4est_init_t) (p4est_t * p4est,
204 p4est_topidx_t which_tree,
205 p4est_quadrant_t * quadrant);
206
213typedef int (*p4est_refine_t) (p4est_t * p4est,
214 p4est_topidx_t which_tree,
215 p4est_quadrant_t * quadrant);
216
223typedef int (*p4est_coarsen_t) (p4est_t * p4est,
224 p4est_topidx_t which_tree,
225 p4est_quadrant_t * quadrants[]);
226
233typedef int (*p4est_weight_t) (p4est_t * p4est,
234 p4est_topidx_t which_tree,
235 p4est_quadrant_t * quadrant);
236
237extern void *P4EST_DATA_UNINITIALIZED;
238
240#define P4EST_QUADRANT_INIT(q) \
241 ((void) memset ((q), -1, sizeof (p4est_quadrant_t)))
242
250 connectivity,
251 p4est_topidx_t treeid,
253 p4est_qcoord_t y, double vxyz[3]);
254
275p4est_t *p4est_new (sc_MPI_Comm mpicomm,
276 p4est_connectivity_t * connectivity,
277 size_t data_size,
278 p4est_init_t init_fn, void *user_pointer);
279
285
299p4est_t *p4est_copy (p4est_t * input, int copy_data);
300
314void p4est_reset_data (p4est_t * p4est, size_t data_size,
315 p4est_init_t init_fn,
316 void *user_pointer);
317
335 int refine_recursive,
336 p4est_refine_t refine_fn,
337 p4est_init_t init_fn);
338
348 int coarsen_recursive,
349 p4est_coarsen_t coarsen_fn,
350 p4est_init_t init_fn);
351
362 p4est_init_t init_fn);
363
386 int allow_for_coarsening,
387 p4est_weight_t weight_fn);
388
394
399
423void p4est_save (const char *filename, p4est_t * p4est,
424 int save_data);
425
454p4est_t *p4est_load (const char *filename, sc_MPI_Comm mpicomm,
455 size_t data_size, int load_data,
456 void *user_pointer,
457 p4est_connectivity_t ** connectivity);
458
462/*@unused@*/
463static inline p4est_tree_t *
464p4est_tree_array_index (sc_array_t * array, p4est_topidx_t it)
465{
466 P4EST_ASSERT (array->elem_size == sizeof (p4est_tree_t));
467 P4EST_ASSERT (it >= 0 && (size_t) it < array->elem_count);
468
469 return (p4est_tree_t *) (array->array +
470 sizeof (p4est_tree_t) * (size_t) it);
471}
472
474/*@unused@*/
475static inline p4est_quadrant_t *
476p4est_quadrant_array_index (sc_array_t * array, size_t it)
477{
478 P4EST_ASSERT (array->elem_size == sizeof (p4est_quadrant_t));
479 P4EST_ASSERT (it < array->elem_count);
480
481 return (p4est_quadrant_t *) (array->array + sizeof (p4est_quadrant_t) * it);
482}
483
492static inline p4est_quadrant_t *
493p4est_quadrant_array_push_copy (sc_array_t * array,
494 const p4est_quadrant_t *qsrc)
495{
497
498 P4EST_ASSERT (array->elem_size == sizeof (p4est_quadrant_t));
499
500 q = (p4est_quadrant_t *) sc_array_push (array);
501 *q = *qsrc;
502 return q;
503}
504
511/*@unused@*/
512static inline p4est_quadrant_t *
513p4est_quadrant_array_push (sc_array_t * array)
514{
516
517 P4EST_ASSERT (array->elem_size == sizeof (p4est_quadrant_t));
518
519 q = (p4est_quadrant_t *) sc_array_push (array);
521 return q;
522}
523
525/*@unused@*/
526static inline p4est_quadrant_t *
527p4est_quadrant_mempool_alloc (sc_mempool_t * mempool)
528{
529 P4EST_ASSERT (mempool->elem_size == sizeof (p4est_quadrant_t));
530
531 return (p4est_quadrant_t *) sc_mempool_alloc (mempool);
532}
533
535/*@unused@*/
536static inline p4est_quadrant_t *
537p4est_quadrant_list_pop (sc_list_t * list)
538{
539 return (p4est_quadrant_t *) sc_list_pop (list);
540}
541
542SC_EXTERN_C_END;
543
544#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:223
struct p4est_tree p4est_tree_t
The p4est tree datatype.
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.
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.
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.
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:203
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:240
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.
long p4est_revision(p4est_t *p4est)
Return the revision counter of the forest.
p4est_t * p4est_copy(p4est_t *input, int copy_data)
Make a deep copy of a p4est.
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:233
struct p4est p4est_t
The p4est forest datatype.
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:213
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:72
int8_t level
level of refinement
Definition: p4est.h:76
int16_t pad16
padding
Definition: p4est.h:78
union p4est_quadrant::p4est_quadrant_data p
a union of additional data attached to a quadrant
p4est_qcoord_t y
coordinates
Definition: p4est.h:74
int8_t pad8
padding
Definition: p4est.h:77
The p4est tree datatype.
Definition: p4est.h:115
p4est_quadrant_t last_desc
last local descendant
Definition: p4est.h:118
p4est_quadrant_t first_desc
first local descendant
Definition: p4est.h:117
int8_t maxlevel
highest local quadrant level
Definition: p4est.h:124
sc_array_t quadrants
locally stored quadrants
Definition: p4est.h:116
p4est_locidx_t quadrants_offset
cumulative sum over earlier trees on this processor (locals only)
Definition: p4est.h:119
p4est_locidx_t quadrants_per_level[P4EST_MAXLEVEL+1]
locals only
Definition: p4est.h:122
The p4est forest datatype.
Definition: p4est.h:136
p4est_topidx_t first_local_tree
0-based index of first local tree, must be -1 for an empty processor
Definition: p4est.h:147
p4est_connectivity_t * connectivity
connectivity structure, not owned
Definition: p4est.h:163
p4est_locidx_t local_num_quadrants
number of quadrants on all trees on this processor
Definition: p4est.h:153
void * user_pointer
convenience pointer for users, never touched by p4est
Definition: p4est.h:143
int mpisize
number of MPI processes
Definition: p4est.h:138
int mpirank
this process's MPI rank
Definition: p4est.h:139
sc_array_t * trees
array of all trees
Definition: p4est.h:164
size_t data_size
size of per-quadrant p.user_data (see p4est_quadrant_t::p4est_quadrant_data::user_data)
Definition: p4est.h:141
long revision
Gets bumped on mesh change.
Definition: p4est.h:146
p4est_inspect_t * inspect
algorithmic switches
Definition: p4est.h:171
sc_MPI_Comm mpicomm
MPI communicator.
Definition: p4est.h:137
p4est_gloidx_t global_num_quadrants
number of quadrants on all trees on all processors
Definition: p4est.h:155
p4est_quadrant_t * global_first_position
first smallest possible quad for each process and 1 beyond
Definition: p4est.h:160
int mpicomm_owned
flag if communicator is owned
Definition: p4est.h:140
sc_mempool_t * quadrant_pool
memory allocator for temporary quadrants
Definition: p4est.h:169
p4est_topidx_t last_local_tree
0-based index of last local tree, must be -2 for an empty processor
Definition: p4est.h:150
sc_mempool_t * user_data_pool
memory allocator for user data
Definition: p4est.h:166
p4est_gloidx_t * global_first_quadrant
first global quadrant index for each process and 1 beyond
Definition: p4est.h:157
struct p4est_quadrant::p4est_quadrant_data::@0 piggy1
of ghost octants, store the tree and owner rank
long user_long
never changed by p4est
Definition: p4est.h:82
struct p4est_quadrant::p4est_quadrant_data::@1 piggy2
of transformed octants, store the original tree and the target tree
int user_int
never changed by p4est
Definition: p4est.h:83
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:84
struct p4est_quadrant::p4est_quadrant_data::@2 piggy3
of ghost octants, store the tree and index in the owner's numbering
void * user_data
never changed by p4est
Definition: p4est.h:81