p4est  1.0
src/p4est_connectivity.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 
00031 #ifndef P4EST_CONNECTIVITY_H
00032 #define P4EST_CONNECTIVITY_H
00033 
00034 #ifdef P4_TO_P8
00035 #error "Including a p4est header with P4_TO_P8 defined"
00036 #endif
00037 
00038 #include <sc_io.h>
00039 #include <p4est_base.h>
00040 
00041 SC_EXTERN_C_BEGIN;
00042 
00044 #define P4EST_DIM 2
00045 
00046 #define P4EST_FACES (2 * P4EST_DIM)
00047 
00050 #define P4EST_CHILDREN 4
00051 
00052 #define P4EST_HALF (P4EST_CHILDREN / 2)
00053 
00054 #define P4EST_INSUL 9
00055 
00056 /* size of face transformation encoding */
00057 #define P4EST_FTRANSFORM 9
00058 
00060 #define P4EST_STRING "p4est"
00061 
00062 /* Increase this number whenever the on-disk format for
00063  * p4est_connectivity, p4est, or any other 2D data structure changes.
00064  * The format for reading and writing must be the same.
00065  */
00066 #define P4EST_ONDISK_FORMAT 0x2000009
00067 
00077 typedef enum
00078 {
00079   /* make sure to have different values 2D and 3D */
00080   P4EST_CONNECT_FACE = 21,
00081   P4EST_CONNECT_CORNER = 22,
00082   P4EST_CONNECT_FULL = P4EST_CONNECT_CORNER
00083 }
00084 p4est_connect_type_t;
00085 
00087 typedef enum
00088 {
00089   P4EST_CONN_ENCODE_NONE = SC_IO_ENCODE_NONE,
00090   P4EST_CONN_ENCODE_LAST        
00091 }
00092 p4est_connectivity_encode_t;
00093 
00098 int                 p4est_connect_type_int (p4est_connect_type_t btype);
00099 
00104 const char         *p4est_connect_type_string (p4est_connect_type_t btype);
00105 
00135 typedef struct p4est_connectivity
00136 {
00137   p4est_topidx_t      num_vertices; 
00140   p4est_topidx_t      num_trees;    
00141   p4est_topidx_t      num_corners;  
00143   double             *vertices;     
00145   p4est_topidx_t     *tree_to_vertex; 
00148   int8_t             *tree_to_attr; 
00150   p4est_topidx_t     *tree_to_tree; 
00152   int8_t             *tree_to_face; 
00155   p4est_topidx_t     *tree_to_corner; 
00157   p4est_topidx_t     *ctt_offset; 
00159   p4est_topidx_t     *corner_to_tree; 
00160   int8_t             *corner_to_corner; 
00162 }
00163 p4est_connectivity_t;
00164 
00169 size_t              p4est_connectivity_memory_used (p4est_connectivity_t *
00170                                                     conn);
00171 
00172 typedef struct
00173 {
00174   p4est_topidx_t      ntree;
00175   int8_t              ncorner;
00176 }
00177 p4est_corner_transform_t;
00178 
00179 typedef struct
00180 {
00181   p4est_topidx_t      icorner;
00182   sc_array_t          corner_transforms;
00183 }
00184 p4est_corner_info_t;
00185 
00187 extern const int    p4est_face_corners[4][2];
00188 
00190 extern const int    p4est_face_dual[4];
00191 
00193 extern const int    p4est_corner_faces[4][2];
00194 
00196 extern const int    p4est_corner_face_corners[4][4];
00197 
00199 extern const int    p4est_child_corner_faces[4][4];
00200 
00209 p4est_connectivity_t *p4est_connectivity_new (p4est_topidx_t num_vertices,
00210                                               p4est_topidx_t num_trees,
00211                                               p4est_topidx_t num_corners,
00212                                               p4est_topidx_t num_ctt);
00213 
00222 p4est_connectivity_t *p4est_connectivity_new_copy (p4est_topidx_t
00223                                                    num_vertices,
00224                                                    p4est_topidx_t num_trees,
00225                                                    p4est_topidx_t num_corners,
00226                                                    const double *vertices,
00227                                                    const p4est_topidx_t * ttv,
00228                                                    const p4est_topidx_t * ttt,
00229                                                    const int8_t * ttf,
00230                                                    const p4est_topidx_t * ttc,
00231                                                    const p4est_topidx_t *
00232                                                    coff,
00233                                                    const p4est_topidx_t * ctt,
00234                                                    const int8_t * ctc);
00235 
00238 void                p4est_connectivity_destroy (p4est_connectivity_t *
00239                                                 connectivity);
00240 
00247 void                p4est_connectivity_set_attr (p4est_connectivity_t * conn,
00248                                                  int enable_tree_attr);
00249 
00253 int                 p4est_connectivity_is_valid (p4est_connectivity_t *
00254                                                  connectivity);
00255 
00259 int                 p4est_connectivity_is_equal (p4est_connectivity_t * conn1,
00260                                                  p4est_connectivity_t *
00261                                                  conn2);
00262 
00268 int                 p4est_connectivity_sink (p4est_connectivity_t * conn,
00269                                              sc_io_sink_t * sink);
00270 
00276 sc_array_t         *p4est_connectivity_deflate (p4est_connectivity_t * conn,
00277                                                 p4est_connectivity_encode_t
00278                                                 code);
00279 
00285 int                 p4est_connectivity_save (const char *filename,
00286                                              p4est_connectivity_t *
00287                                              connectivity);
00288 
00293 p4est_connectivity_t *p4est_connectivity_source (sc_io_source_t * source);
00294 
00299 p4est_connectivity_t *p4est_connectivity_inflate (sc_array_t * buffer);
00300 
00306 p4est_connectivity_t *p4est_connectivity_load (const char *filename,
00307                                                size_t * bytes);
00308 
00311 p4est_connectivity_t *p4est_connectivity_new_unitsquare (void);
00312 
00315 p4est_connectivity_t *p4est_connectivity_new_periodic (void);
00316 
00320 p4est_connectivity_t *p4est_connectivity_new_rotwrap (void);
00321 
00324 p4est_connectivity_t *p4est_connectivity_new_corner (void);
00325 
00328 p4est_connectivity_t *p4est_connectivity_new_pillow (void);
00329 
00332 p4est_connectivity_t *p4est_connectivity_new_moebius (void);
00333 
00336 p4est_connectivity_t *p4est_connectivity_new_star (void);
00337 
00344 p4est_connectivity_t *p4est_connectivity_new_cubed (void);
00345 
00351 p4est_connectivity_t *p4est_connectivity_new_disk (void);
00352 
00356 p4est_connectivity_t *p4est_connectivity_new_brick (int mi, int ni,
00357                                                     int periodic_a,
00358                                                     int periodic_b);
00359 
00374 p4est_connectivity_t *p4est_connectivity_new_byname (const char *name);
00375 
00395 void                p4est_expand_face_transform (int iface, int nface,
00396                                                  int ftransform[]);
00397 
00408 p4est_topidx_t      p4est_find_face_transform (p4est_connectivity_t *
00409                                                connectivity,
00410                                                p4est_topidx_t itree,
00411                                                int iface, int ftransform[]);
00412 
00418 void                p4est_find_corner_transform (p4est_connectivity_t *
00419                                                  connectivity,
00420                                                  p4est_topidx_t itree,
00421                                                  int icorner,
00422                                                  p4est_corner_info_t * ci);
00423 
00433 void                p4est_connectivity_complete (p4est_connectivity_t * conn);
00434 
00449 void                p4est_connectivity_permute (p4est_connectivity_t * conn,
00450                                                 sc_array_t * perm,
00451                                                 int is_current_to_new);
00452 #ifdef P4EST_METIS
00453 
00476 void                p4est_connectivity_reorder (MPI_Comm comm, int k,
00477                                                 p4est_connectivity_t * conn,
00478                                                 p4est_connect_type_t ctype);
00479 
00480 #endif /* P4EST_METIS */
00481 
00497 void                p4est_connectivity_join_faces (p4est_connectivity_t *
00498                                                    conn,
00499                                                    p4est_topidx_t tree_left,
00500                                                    p4est_topidx_t tree_right,
00501                                                    int face_left,
00502                                                    int face_right,
00503                                                    int orientation);
00504 
00515 int                 p4est_connectivity_is_equivalent (p4est_connectivity_t *
00516                                                       conn1,
00517                                                       p4est_connectivity_t *
00518                                                       conn2);
00519 
00521 /*@unused@*/
00522 static inline p4est_corner_transform_t *
00523 p4est_corner_array_index (sc_array_t * array, size_t it)
00524 {
00525   P4EST_ASSERT (array->elem_size == sizeof (p4est_corner_transform_t));
00526   P4EST_ASSERT (it < array->elem_count);
00527 
00528   return
00529     (p4est_corner_transform_t *) (array->array +
00530                                   sizeof (p4est_corner_transform_t) * it);
00531 }
00532 
00611 int                 p4est_connectivity_read_inp_stream (FILE * stream,
00612                                                         p4est_topidx_t *
00613                                                         num_vertices,
00614                                                         p4est_topidx_t *
00615                                                         num_trees,
00616                                                         double *vertices,
00617                                                         p4est_topidx_t *
00618                                                         tree_to_vertex);
00619 
00691 p4est_connectivity_t *p4est_connectivity_read_inp (const char *filename);
00692 
00693 SC_EXTERN_C_END;
00694 
00695 #endif /* !P4EST_CONNECTIVITY_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines