p4est
1.0
|
00001 /* 00002 This file is part of p4est. 00003 p4est is a C library to manage a collection (a forest) of multiple 00004 connected adaptive quadtrees or octrees in parallel. 00005 00006 Copyright (C) 2010 The University of Texas System 00007 Written by Carsten Burstedde, Lucas C. Wilcox, and Tobin Isaac 00008 00009 p4est is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 p4est is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with p4est; if not, write to the Free Software Foundation, Inc., 00021 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 */ 00023 00036 #ifndef P4EST_H 00037 #define P4EST_H 00038 00039 #ifdef P4EST_TO_P8EST_H 00040 #error "The include files p4est.h and p4est_to_p8est.h cannot be combined" 00041 #endif 00042 00043 /* p4est_connectivity.h includes p4est_base.h sc_containers.h */ 00044 #include <p4est_connectivity.h> 00045 00046 SC_EXTERN_C_BEGIN; 00047 00049 #define P4EST_MAXLEVEL 30 00050 00052 #define P4EST_QMAXLEVEL 29 00053 00055 #define P4EST_ROOT_LEN ((p4est_qcoord_t) 1 << P4EST_MAXLEVEL) 00056 00058 #define P4EST_QUADRANT_LEN(l) ((p4est_qcoord_t) 1 << (P4EST_MAXLEVEL - (l))) 00059 00062 #define P4EST_LAST_OFFSET(l) (P4EST_ROOT_LEN - P4EST_QUADRANT_LEN (l)) 00063 00065 typedef struct p4est_quadrant 00066 { 00068 p4est_qcoord_t x, y; 00070 int8_t level, 00071 pad8; 00072 int16_t pad16; 00073 union p4est_quadrant_data 00074 { 00075 void *user_data; 00076 long user_long; 00077 int user_int; 00078 p4est_topidx_t which_tree; 00082 struct 00083 { 00084 p4est_topidx_t which_tree; 00085 int owner_rank; 00086 } 00087 piggy1; 00088 struct 00089 { 00090 p4est_topidx_t which_tree; 00091 p4est_topidx_t from_tree; 00092 } 00093 piggy2; 00095 struct 00096 { 00097 p4est_topidx_t which_tree; 00098 p4est_locidx_t local_num; 00099 } 00100 piggy3; 00102 } 00103 p; 00104 } 00105 p4est_quadrant_t; 00106 00108 typedef struct p4est_tree 00109 { 00110 sc_array_t quadrants; 00111 p4est_quadrant_t first_desc, 00112 last_desc; 00113 p4est_locidx_t quadrants_offset; 00116 p4est_locidx_t quadrants_per_level[P4EST_MAXLEVEL + 1]; 00118 int8_t maxlevel; 00119 } 00120 p4est_tree_t; 00121 00126 typedef struct p4est_inspect p4est_inspect_t; 00127 00129 typedef struct p4est 00130 { 00131 sc_MPI_Comm mpicomm; 00132 int mpisize, 00133 mpirank; 00134 size_t data_size; 00136 void *user_pointer; 00139 p4est_topidx_t first_local_tree; 00142 p4est_topidx_t last_local_tree; 00145 p4est_locidx_t local_num_quadrants; 00147 p4est_gloidx_t global_num_quadrants; 00149 p4est_gloidx_t *global_first_quadrant; 00152 p4est_quadrant_t *global_first_position; 00155 p4est_connectivity_t *connectivity; 00156 sc_array_t *trees; 00158 sc_mempool_t *user_data_pool; 00159 /* WARNING: This is NULL if data size 00160 equals zero. */ 00161 sc_mempool_t *quadrant_pool; 00163 p4est_inspect_t *inspect; 00164 } 00165 p4est_t; 00166 00173 size_t p4est_memory_used (p4est_t * p4est); 00174 00184 typedef void (*p4est_init_t) (p4est_t * p4est, 00185 p4est_topidx_t which_tree, 00186 p4est_quadrant_t * quadrant); 00187 00194 typedef int (*p4est_refine_t) (p4est_t * p4est, 00195 p4est_topidx_t which_tree, 00196 p4est_quadrant_t * quadrant); 00197 00204 typedef int (*p4est_coarsen_t) (p4est_t * p4est, 00205 p4est_topidx_t which_tree, 00206 p4est_quadrant_t * quadrants[]); 00207 00214 typedef int (*p4est_weight_t) (p4est_t * p4est, 00215 p4est_topidx_t which_tree, 00216 p4est_quadrant_t * quadrant); 00217 00218 extern void *P4EST_DATA_UNINITIALIZED; 00219 extern const int p4est_num_ranges; 00220 00222 #define P4EST_QUADRANT_INIT(q) \ 00223 ((void) memset ((q), -1, sizeof (p4est_quadrant_t))) 00224 00231 void p4est_qcoord_to_vertex (p4est_connectivity_t * 00232 connectivity, 00233 p4est_topidx_t treeid, 00234 p4est_qcoord_t x, 00235 p4est_qcoord_t y, double vxyz[3]); 00236 00257 p4est_t *p4est_new (sc_MPI_Comm mpicomm, 00258 p4est_connectivity_t * connectivity, 00259 size_t data_size, 00260 p4est_init_t init_fn, void *user_pointer); 00261 00266 void p4est_destroy (p4est_t * p4est); 00267 00278 p4est_t *p4est_copy (p4est_t * input, int copy_data); 00279 00293 void p4est_reset_data (p4est_t * p4est, size_t data_size, 00294 p4est_init_t init_fn, 00295 void *user_pointer); 00296 00313 void p4est_refine (p4est_t * p4est, 00314 int refine_recursive, 00315 p4est_refine_t refine_fn, 00316 p4est_init_t init_fn); 00317 00326 void p4est_coarsen (p4est_t * p4est, 00327 int coarsen_recursive, 00328 p4est_coarsen_t coarsen_fn, 00329 p4est_init_t init_fn); 00330 00339 void p4est_balance (p4est_t * p4est, 00340 p4est_connect_type_t btype, 00341 p4est_init_t init_fn); 00342 00355 void p4est_partition (p4est_t * p4est, 00356 int allow_for_coarsening, 00357 p4est_weight_t weight_fn); 00358 00363 unsigned p4est_checksum (p4est_t * p4est); 00364 00385 void p4est_save (const char *filename, p4est_t * p4est, 00386 int save_data); 00387 00414 p4est_t *p4est_load (const char *filename, sc_MPI_Comm mpicomm, 00415 size_t data_size, int load_data, 00416 void *user_pointer, 00417 p4est_connectivity_t ** connectivity); 00418 00422 /*@unused@*/ 00423 static inline p4est_tree_t * 00424 p4est_tree_array_index (sc_array_t * array, p4est_topidx_t it) 00425 { 00426 P4EST_ASSERT (array->elem_size == sizeof (p4est_tree_t)); 00427 P4EST_ASSERT (it >= 0 && (size_t) it < array->elem_count); 00428 00429 return (p4est_tree_t *) (array->array + 00430 sizeof (p4est_tree_t) * (size_t) it); 00431 } 00432 00434 /*@unused@*/ 00435 static inline p4est_quadrant_t * 00436 p4est_quadrant_array_index (sc_array_t * array, size_t it) 00437 { 00438 P4EST_ASSERT (array->elem_size == sizeof (p4est_quadrant_t)); 00439 P4EST_ASSERT (it < array->elem_count); 00440 00441 return (p4est_quadrant_t *) (array->array + sizeof (p4est_quadrant_t) * it); 00442 } 00443 00445 /*@unused@*/ 00446 static inline p4est_quadrant_t * 00447 p4est_quadrant_array_push (sc_array_t * array) 00448 { 00449 P4EST_ASSERT (array->elem_size == sizeof (p4est_quadrant_t)); 00450 00451 return (p4est_quadrant_t *) sc_array_push (array); 00452 } 00453 00455 /*@unused@*/ 00456 static inline p4est_quadrant_t * 00457 p4est_quadrant_mempool_alloc (sc_mempool_t * mempool) 00458 { 00459 P4EST_ASSERT (mempool->elem_size == sizeof (p4est_quadrant_t)); 00460 00461 return (p4est_quadrant_t *) sc_mempool_alloc (mempool); 00462 } 00463 00465 /*@unused@*/ 00466 static inline p4est_quadrant_t * 00467 p4est_quadrant_list_pop (sc_list_t * list) 00468 { 00469 return (p4est_quadrant_t *) sc_list_pop (list); 00470 } 00471 00472 SC_EXTERN_C_END; 00473 00474 #endif /* !P4EST_H */