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_wrap.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 
25 #ifndef P8EST_WRAP_H
26 #define P8EST_WRAP_H
27 
40 #include <p8est_extended.h>
41 #include <sc_refcount.h>
42 
43 SC_EXTERN_C_BEGIN;
44 
45 /*** COMPLETE INTERNAL STATE OF P8EST ***/
46 
47 typedef enum p8est_wrap_flags
48 {
49  P8EST_WRAP_NONE = 0,
50  P8EST_WRAP_REFINE = 0x01,
51  P8EST_WRAP_COARSEN = 0x02
52 }
53 p8est_wrap_flags_t;
54 
58 typedef struct
59 {
60  int hollow;
88  void *user_pointer;
91 }
93 
96 typedef struct p8est_wrap
97 {
98  /* collection of wrap-related parameters */
99  p8est_wrap_params_t params;
100 
106  sc_refcount_t conn_rc;
107  p8est_connectivity_t *conn;
108  struct p8est_wrap *conn_owner;
109 
110  /* these members are considered public and read-only */
111  int p4est_dim;
112  int p4est_half;
113  int p4est_faces;
114  int p4est_children;
117  /* If \a params.store_adapted is true, these arrays store the indices of the
118  * quadrants refined and coarsened during the most recent call to
119  * \ref p8est_wrap_adapt. The wrap's \a p4est has to be balanced when entering
120  * the adaptation, to avoid multi-level refinement.
121  * The arrays are allocated during the first call of \ref p8est_wrap_adapt.
122  * At every time the arrays index into the local quadrants of the p8est as it
123  * was directly after completion of \ref p8est_wrap_adapt. So, they are not
124  * updated in \ref p8est_wrap_partition. Newly_refined only stores newly
125  * refined quadrants with child id 0. */
126  sc_array_t *newly_refined;
128  sc_array_t *newly_coarsened;
131  /* anything below here is considered private und should not be touched */
132  int weight_exponent;
133  uint8_t *flags, *temp_flags;
134  p4est_locidx_t num_refine_flags, inside_counter, num_replaced;
135  p4est_gloidx_t *old_global_first_quadrant;
136 
137  /* for ghost and mesh use p8est_wrap_get_ghost, _mesh declared below */
138  p8est_ghost_t *ghost;
139  p8est_mesh_t *mesh;
140  p8est_ghost_t *ghost_aux;
141  p8est_mesh_t *mesh_aux;
142  int match_aux;
143 }
145 
149 
160 p8est_wrap_t *p8est_wrap_new_conn (sc_MPI_Comm mpicomm,
161  p8est_connectivity_t * conn,
162  int initial_level);
163 
180  p8est_connect_type_t btype,
181  p8est_replace_t replace_fn,
182  void *user_pointer);
183 
198  p8est_wrap_params_t * params);
199 
217 p8est_wrap_t *p8est_wrap_new_ext (sc_MPI_Comm mpicomm,
218  p8est_connectivity_t * conn,
219  int initial_level, int hollow,
220  p8est_connect_type_t btype,
221  p8est_replace_t replace_fn,
222  void *user_pointer);
223 
236 p8est_wrap_t *p8est_wrap_new_params (sc_MPI_Comm mpicomm,
237  p8est_connectivity_t * conn,
238  int initial_level,
239  p8est_wrap_params_t * params);
240 
254  size_t data_size,
255  p8est_replace_t replace_fn,
256  void *user_pointer);
257 
261 p8est_wrap_t *p8est_wrap_new_unitcube (sc_MPI_Comm mpicomm,
262  int initial_level);
263 p8est_wrap_t *p8est_wrap_new_rotwrap (sc_MPI_Comm mpicomm,
264  int initial_level);
265 p8est_wrap_t *p8est_wrap_new_brick (sc_MPI_Comm mpicomm,
266  int bx, int by, int bz,
267  int px, int py, int pz,
268  int initial_level);
269 
271 p8est_wrap_t *p8est_wrap_new_world (int initial_level);
272 void p8est_wrap_destroy (p8est_wrap_t * pp);
273 
279 void p8est_wrap_set_hollow (p8est_wrap_t * pp, int hollow);
280 
297  int coarsen_delay,
298  int coarsen_affect);
299 
317  int partition_for_coarsening);
318 
325 
332 
340  p4est_topidx_t which_tree,
341  p4est_locidx_t which_quad);
342 
350  p4est_topidx_t which_tree,
351  p4est_locidx_t which_quad);
352 
366 
395  int weight_exponent,
396  p4est_locidx_t * unchanged_first,
397  p4est_locidx_t * unchanged_length,
399  unchanged_old_first);
400 
408 
409 /*** ITERATOR OVER THE FOREST LEAVES ***/
410 
411 typedef struct p8est_wrap_leaf
412 {
415  /* Information about the current quadrant */
420  sc_array_t *tquadrants;
422 #if 0 /* DEPRECATED -- anyone using them? */
423  int level;
424  double lowerleft[3];
425  double upperright[3];
426 #endif
427 
428  /* Information about parallel neighbors */
429  int is_mirror;
430  sc_array_t *mirrors;
433 }
435 
437 #define P8EST_LEAF_IS_FIRST_IN_TREE(wleaf) ((wleaf)->which_quad == 0)
438 
439 /* Create an iterator over the local leaves in the forest.
440  * Returns a newly allocated state containing the first leaf,
441  * or NULL if the local partition of the tree is empty.
442  * \param [in] pp Legal p8est_wrap structure, hollow or not.
443  * \param [in] track_mirrors If true, \a pp must not be hollow and mirror
444  * information from the ghost layer is stored.
445  * \return NULL if processor is empty, otherwise a leaf iterator for
446  * subsequent use with \a p8est_wrap_leaf_next.
447  */
448 p8est_wrap_leaf_t *p8est_wrap_leaf_first (p8est_wrap_t * pp,
449  int track_mirrors);
450 
451 /* Move the forest leaf iterator forward.
452  * \param [in,out] leaf A non-NULL leaf iterator created by
453  * \ref p8est_wrap_leaf_first.
454  * \return The state that was input with updated information for the
455  * next leaf, or NULL and deallocates the input if called with
456  * the last leaf on this processor.
457  */
458 p8est_wrap_leaf_t *p8est_wrap_leaf_next (p8est_wrap_leaf_t * leaf);
459 
460 SC_EXTERN_C_END;
461 
462 #endif /* !P8EST_WRAP_H */
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_connect_type_t
Characterize a type of adjacency.
Definition: p8est_connectivity.h:120
Interface routines with extended capabilities.
void(* p8est_replace_t)(p8est_t *p8est, p4est_topidx_t which_tree, int num_outgoing, p8est_quadrant_t *outgoing[], int num_incoming, p8est_quadrant_t *incoming[])
Callback function prototype to replace one set of quadrants with another.
Definition: p8est_extended.h:116
p8est_mesh_t * p8est_wrap_get_mesh(p8est_wrap_t *pp)
Return the appropriate mesh structure.
void p8est_wrap_complete(p8est_wrap_t *pp)
Free memory for the intermediate mesh.
p8est_wrap_t * p8est_wrap_new_world(int initial_level)
Passes sc_MPI_COMM_WORLD to p8est_wrap_new_unitcube.
void p8est_wrap_set_hollow(p8est_wrap_t *pp, int hollow)
Change hollow status of the wrap.
void p8est_wrap_set_partitioning(p8est_wrap_t *pp, int partition_for_coarsening)
Set a parameter that ensures future partitions allow one level of coarsening.
int p8est_wrap_adapt(p8est_wrap_t *pp)
Call p8est_refine, coarsen, and balance to update pp->p8est.
p8est_wrap_t * p8est_wrap_new_conn(sc_MPI_Comm mpicomm, p8est_connectivity_t *conn, int initial_level)
Create a p8est wrapper from a given connectivity structure.
struct p8est_wrap p8est_wrap_t
Wrapping a p8est object for an alternative API.
void p8est_wrap_mark_coarsen(p8est_wrap_t *pp, p4est_topidx_t which_tree, p4est_locidx_t which_quad)
Mark a local element for coarsening.
void p8est_wrap_mark_refine(p8est_wrap_t *pp, p4est_topidx_t which_tree, p4est_locidx_t which_quad)
Mark a local element for refinement.
p8est_wrap_t * p8est_wrap_new_p8est_params(p8est_t *p8est, p8est_wrap_params_t *params)
Create a wrapper for a given p8est structure.
p8est_ghost_t * p8est_wrap_get_ghost(p8est_wrap_t *pp)
Return the appropriate ghost layer.
p8est_wrap_t * p8est_wrap_new_ext(sc_MPI_Comm mpicomm, p8est_connectivity_t *conn, int initial_level, int hollow, p8est_connect_type_t btype, p8est_replace_t replace_fn, void *user_pointer)
Create a p8est wrapper from a given connectivity structure.
int p8est_wrap_partition(p8est_wrap_t *pp, int weight_exponent, p4est_locidx_t *unchanged_first, p4est_locidx_t *unchanged_length, p4est_locidx_t *unchanged_old_first)
Call p8est_partition for equal leaf distribution.
p8est_wrap_t * p8est_wrap_new_unitcube(sc_MPI_Comm mpicomm, int initial_level)
Create a p8est_wrap and internal helper data structures.
p8est_wrap_t * p8est_wrap_new_p8est(p8est_t *p8est, int hollow, p8est_connect_type_t btype, p8est_replace_t replace_fn, void *user_pointer)
Create a wrapper for a given p8est structure.
void p8est_wrap_params_init(p8est_wrap_params_t *params)
Initialize a default p8est_wrap_params_t structure.
void p8est_wrap_set_coarsen_delay(p8est_wrap_t *pp, int coarsen_delay, int coarsen_affect)
Set a parameter that delays coarsening after adaptation.
p8est_wrap_t * p8est_wrap_new_copy(p8est_wrap_t *source, size_t data_size, p8est_replace_t replace_fn, void *user_pointer)
Create a p8est wrapper from an existing one.
p8est_wrap_t * p8est_wrap_new_params(sc_MPI_Comm mpicomm, p8est_connectivity_t *conn, int initial_level, p8est_wrap_params_t *params)
Create a p8est wrapper from a given connectivity structure.
This structure holds the 3D inter-tree connectivity information.
Definition: p8est_connectivity.h:216
Quadrants that neighbor the local domain.
Definition: p8est_ghost.h:46
This structure contains the different parameters of mesh creation.
Definition: p8est_mesh.h:55
This structure contains complete mesh information on a 2:1 balanced forest.
Definition: p8est_mesh.h:170
The 3D quadrant (i.e., octant) datatype.
Definition: p8est.h:72
The p8est tree datatype.
Definition: p8est.h:125
Definition: p8est_wrap.h:412
p8est_quadrant_t * quad
Current quadrant.
Definition: p8est_wrap.h:421
p8est_wrap_t * pp
Must contain a valid ghost.
Definition: p8est_wrap.h:413
p4est_locidx_t nm
Internal: mirror counter.
Definition: p8est_wrap.h:431
p4est_locidx_t local_quad
Quadrant number relative to proc.
Definition: p8est_wrap.h:418
p4est_locidx_t next_mirror_quadrant
Internal: next.
Definition: p8est_wrap.h:432
p4est_topidx_t which_tree
Current tree number.
Definition: p8est_wrap.h:416
sc_array_t * tquadrants
Current tree's quadrants.
Definition: p8est_wrap.h:420
p4est_locidx_t which_quad
Quadrant number relative to tree.
Definition: p8est_wrap.h:417
p8est_tree_t * tree
Current tree.
Definition: p8est_wrap.h:419
sc_array_t * mirrors
If not NULL, from pp's ghost.
Definition: p8est_wrap.h:430
int is_mirror
Quadrant at parallel boundary?
Definition: p8est_wrap.h:429
This structure contains the different parameters of wrap creation.
Definition: p8est_wrap.h:59
int partition_for_coarsening
If true, the partition is modified to allow one level of coarsening when calling p8est_wrap_partition...
Definition: p8est_wrap.h:79
int coarsen_affect
Boolean: If true, we delay coarsening not only after refinement, but also between subsequent coarseni...
Definition: p8est_wrap.h:75
int store_adapted
Boolean: If true, the indices of most recently adapted quadrants are stored in the newly_refined and ...
Definition: p8est_wrap.h:83
p8est_mesh_params_t mesh_params
Parameters for mesh creation.
Definition: p8est_wrap.h:62
int hollow
Do not allocate flags, ghost, and mesh members.
Definition: p8est_wrap.h:60
p8est_replace_t replace_fn
This member may be removed soon.
Definition: p8est_wrap.h:65
void * user_pointer
Set the user pointer in the p8est_wrap.
Definition: p8est_wrap.h:88
int coarsen_delay
Non-negative integer telling how many adaptations to wait before any given quadrant may be coarsened ...
Definition: p8est_wrap.h:71
Wrapping a p8est object for an alternative API.
Definition: p8est_wrap.h:97
p8est_t * p4est
p4est->user_pointer is used internally
Definition: p8est_wrap.h:115
sc_array_t * newly_coarsened
Indices of quadrants coarsened during most recent p8est_wrap_adapt.
Definition: p8est_wrap.h:128
sc_refcount_t conn_rc
This reference counter is a workaround for internal use only.
Definition: p8est_wrap.h:106
sc_array_t * newly_refined
Indices of quadrants refined during most recent p8est_wrap_adapt.
Definition: p8est_wrap.h:126
The p8est forest datatype.
Definition: p8est.h:146