p4est  1.0
src/p8est.h
Go to the documentation of this file.
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 P8EST_H
00037 #define P8EST_H
00038 
00039 /* p8est_connectivity.h includes p4est_base.h sc_containers.h */
00040 #include <p8est_connectivity.h>
00041 
00042 SC_EXTERN_C_BEGIN;
00043 
00045 #define P8EST_MAXLEVEL 19
00046 
00048 #define P8EST_QMAXLEVEL 18
00049 
00051 #define P8EST_ROOT_LEN ((p4est_qcoord_t) 1 << P8EST_MAXLEVEL)
00052 
00054 #define P8EST_QUADRANT_LEN(l) ((p4est_qcoord_t) 1 << (P8EST_MAXLEVEL - (l)))
00055 
00058 #define P8EST_LAST_OFFSET(l) (P8EST_ROOT_LEN - P8EST_QUADRANT_LEN (l))
00059 
00061 typedef struct p8est_quadrant
00062 {
00064   p4est_qcoord_t      x, y, z;  
00066   int8_t              level,    
00067                       pad8;     
00068   int16_t             pad16;    
00069   union p8est_quadrant_data
00070   {
00071     void               *user_data;      
00072     long                user_long;      
00073     int                 user_int;       
00074     p4est_topidx_t      which_tree;     
00078     struct
00079     {
00080       p4est_topidx_t      which_tree;
00081       int                 owner_rank;
00082     }
00083     piggy1; 
00084     struct
00085     {
00086       p4est_topidx_t      which_tree;
00087       p4est_topidx_t      from_tree;
00088     }
00089     piggy2; 
00091     struct
00092     {
00093       p4est_topidx_t      which_tree;
00094       p4est_locidx_t      local_num;
00095     }
00096     piggy3; 
00098   }
00099   p; 
00100 }
00101 p8est_quadrant_t;
00102 
00104 typedef struct p8est_tree
00105 {
00106   sc_array_t          quadrants;             
00107   p8est_quadrant_t    first_desc,            
00108                       last_desc;             
00109   p4est_locidx_t      quadrants_offset;      
00112   p4est_locidx_t      quadrants_per_level[P8EST_MAXLEVEL + 1];
00114   int8_t              maxlevel;              
00115 }
00116 p8est_tree_t;
00117 
00122 typedef struct p8est_inspect p8est_inspect_t;
00123 
00125 typedef struct p8est
00126 {
00127   sc_MPI_Comm         mpicomm;          
00128   int                 mpisize,          
00129                       mpirank;          
00130   size_t              data_size;        
00132   void               *user_pointer;     
00135   p4est_topidx_t      first_local_tree; 
00138   p4est_topidx_t      last_local_tree;  
00141   p4est_locidx_t      local_num_quadrants;   
00143   p4est_gloidx_t      global_num_quadrants;  
00145   p4est_gloidx_t     *global_first_quadrant; 
00148   p8est_quadrant_t   *global_first_position; 
00151   p8est_connectivity_t *connectivity; 
00152   sc_array_t         *trees;          
00154   sc_mempool_t       *user_data_pool; 
00155                                       /*   WARNING: This is NULL if data size
00156                                                     equals zero. */
00157   sc_mempool_t       *quadrant_pool;  
00159   p8est_inspect_t    *inspect;        
00160 }
00161 p8est_t;
00162 
00169 size_t              p8est_memory_used (p8est_t * p8est);
00170 
00180 typedef void        (*p8est_init_t) (p8est_t * p8est,
00181                                      p4est_topidx_t which_tree,
00182                                      p8est_quadrant_t * quadrant);
00183 
00190 typedef int         (*p8est_refine_t) (p8est_t * p8est,
00191                                        p4est_topidx_t which_tree,
00192                                        p8est_quadrant_t * quadrant);
00193 
00200 typedef int         (*p8est_coarsen_t) (p8est_t * p8est,
00201                                         p4est_topidx_t which_tree,
00202                                         p8est_quadrant_t * quadrants[]);
00203 
00210 typedef int         (*p8est_weight_t) (p8est_t * p8est,
00211                                        p4est_topidx_t which_tree,
00212                                        p8est_quadrant_t * quadrant);
00213 
00214 extern void        *P8EST_DATA_UNINITIALIZED;
00215 extern const int    p8est_num_ranges;
00216 
00218 #define P8EST_QUADRANT_INIT(q) \
00219   ((void) memset ((q), -1, sizeof (p8est_quadrant_t)))
00220 
00227 void                p8est_qcoord_to_vertex (p8est_connectivity_t *
00228                                             connectivity,
00229                                             p4est_topidx_t treeid,
00230                                             p4est_qcoord_t x,
00231                                             p4est_qcoord_t y,
00232                                             p4est_qcoord_t z, double vxyz[3]);
00233 
00254 p8est_t            *p8est_new (sc_MPI_Comm mpicomm,
00255                                p8est_connectivity_t * connectivity,
00256                                size_t data_size,
00257                                p8est_init_t init_fn, void *user_pointer);
00258 
00263 void                p8est_destroy (p8est_t * p8est);
00264 
00275 p8est_t            *p8est_copy (p8est_t * input, int copy_data);
00276 
00290 void                p8est_reset_data (p8est_t * p8est, size_t data_size,
00291                                       p8est_init_t init_fn,
00292                                       void *user_pointer);
00293 
00310 void                p8est_refine (p8est_t * p8est,
00311                                   int refine_recursive,
00312                                   p8est_refine_t refine_fn,
00313                                   p8est_init_t init_fn);
00314 
00323 void                p8est_coarsen (p8est_t * p8est,
00324                                    int coarsen_recursive,
00325                                    p8est_coarsen_t coarsen_fn,
00326                                    p8est_init_t init_fn);
00327 
00339 void                p8est_balance (p8est_t * p8est,
00340                                    p8est_connect_type_t btype,
00341                                    p8est_init_t init_fn);
00342 
00355 void                p8est_partition (p8est_t * p8est,
00356                                      int allow_for_coarsening,
00357                                      p8est_weight_t weight_fn);
00358 
00363 unsigned            p8est_checksum (p8est_t * p8est);
00364 
00385 void                p8est_save (const char *filename, p8est_t * p8est,
00386                                 int save_data);
00387 
00414 p8est_t            *p8est_load (const char *filename, sc_MPI_Comm mpicomm,
00415                                 size_t data_size, int load_data,
00416                                 void *user_pointer,
00417                                 p8est_connectivity_t ** connectivity);
00418 
00422 /*@unused@*/
00423 static inline p8est_tree_t *
00424 p8est_tree_array_index (sc_array_t * array, p4est_topidx_t it)
00425 {
00426   P4EST_ASSERT (array->elem_size == sizeof (p8est_tree_t));
00427   P4EST_ASSERT (it >= 0 && (size_t) it < array->elem_count);
00428 
00429   return (p8est_tree_t *) (array->array +
00430                            sizeof (p8est_tree_t) * (size_t) it);
00431 }
00432 
00434 /*@unused@*/
00435 static inline p8est_quadrant_t *
00436 p8est_quadrant_array_index (sc_array_t * array, size_t it)
00437 {
00438   P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
00439   P4EST_ASSERT (it < array->elem_count);
00440 
00441   return (p8est_quadrant_t *) (array->array + sizeof (p8est_quadrant_t) * it);
00442 }
00443 
00445 /*@unused@*/
00446 static inline p8est_quadrant_t *
00447 p8est_quadrant_array_push (sc_array_t * array)
00448 {
00449   P4EST_ASSERT (array->elem_size == sizeof (p8est_quadrant_t));
00450 
00451   return (p8est_quadrant_t *) sc_array_push (array);
00452 }
00453 
00455 /*@unused@*/
00456 static inline p8est_quadrant_t *
00457 p8est_quadrant_mempool_alloc (sc_mempool_t * mempool)
00458 {
00459   P4EST_ASSERT (mempool->elem_size == sizeof (p8est_quadrant_t));
00460 
00461   return (p8est_quadrant_t *) sc_mempool_alloc (mempool);
00462 }
00463 
00465 /*@unused@*/
00466 static inline p8est_quadrant_t *
00467 p8est_quadrant_list_pop (sc_list_t * list)
00468 {
00469   return (p8est_quadrant_t *) sc_list_pop (list);
00470 }
00471 
00472 SC_EXTERN_C_END;
00473 
00474 #endif /* !P8EST_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines