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 00024 #ifndef P8EST_LNODES_H 00025 #define P8EST_LNODES_H 00026 00027 #include <p8est.h> 00028 #include <p8est_ghost.h> 00029 00030 SC_EXTERN_C_BEGIN; 00031 00032 typedef int16_t p8est_lnodes_code_t; 00033 00091 typedef struct p8est_lnodes 00092 { 00093 sc_MPI_Comm mpicomm; 00094 p4est_locidx_t num_local_nodes; 00095 p4est_locidx_t owned_count; 00096 p4est_gloidx_t global_offset; 00097 p4est_gloidx_t *nonlocal_nodes; 00098 sc_array_t *sharers; 00099 p4est_locidx_t *global_owned_count; 00100 00101 int degree, vnodes; 00102 p4est_locidx_t num_local_elements; 00103 p8est_lnodes_code_t *face_code; 00104 p4est_locidx_t *element_nodes; 00105 } 00106 p8est_lnodes_t; 00107 00119 typedef struct p8est_lnodes_rank 00120 { 00121 int rank; 00122 sc_array_t shared_nodes; 00123 p4est_locidx_t shared_mine_offset, shared_mine_count; 00124 p4est_locidx_t owned_offset, owned_count; 00125 } 00126 p8est_lnodes_rank_t; 00127 00181 /*@unused@*/ 00182 static inline int 00183 p8est_lnodes_decode (p8est_lnodes_code_t face_code, int hanging_face[6], 00184 int hanging_edge[12]) 00185 { 00186 P4EST_ASSERT (face_code >= 0); 00187 00188 if (face_code) { 00189 int i, j; 00190 int16_t c = face_code & 0x0007; 00191 int16_t cwork; 00192 int f; 00193 int e; 00194 int16_t work = face_code >> 3; 00195 00196 memset (hanging_face, -1, 6 * sizeof (int)); 00197 memset (hanging_edge, -1, 12 * sizeof (int)); 00198 00199 cwork = c; 00200 for (i = 0; i < 3; ++i) { 00201 if (work & 0x0001) { 00202 f = p8est_corner_faces[c][i]; 00203 hanging_face[f] = p8est_corner_face_corners[c][f]; 00204 for (j = 0; j < 4; j++) { 00205 e = p8est_face_edges[f][j]; 00206 hanging_edge[e] = 4; 00207 } 00208 } 00209 work >>= 1; 00210 } 00211 for (i = 0; i < 3; ++i) { 00212 if (work & 0x0001) { 00213 e = p8est_corner_edges[c][i]; 00214 hanging_edge[e] = (hanging_edge[e] == -1) ? 0 : 2; 00215 hanging_edge[e] += (int) (cwork & 0x0001); 00216 } 00217 cwork >>= 1; 00218 work >>= 1; 00219 } 00220 return 1; 00221 } 00222 else { 00223 return 0; 00224 } 00225 } 00226 00227 p8est_lnodes_t *p8est_lnodes_new (p8est_t * p8est, 00228 p8est_ghost_t * ghost_layer, 00229 int degree); 00230 00231 void p8est_lnodes_destroy (p8est_lnodes_t *); 00232 00247 typedef struct p8est_lnodes_buffer 00248 { 00249 sc_array_t *requests; /* sc_MPI_Request */ 00250 sc_array_t *send_buffers; 00251 sc_array_t *recv_buffers; 00252 } 00253 p8est_lnodes_buffer_t; 00254 00271 p8est_lnodes_buffer_t *p8est_lnodes_share_owned_begin (sc_array_t * node_data, 00272 p8est_lnodes_t * 00273 lnodes); 00274 00275 void p8est_lnodes_share_owned_end (p8est_lnodes_buffer_t * 00276 buffer); 00277 00282 void p8est_lnodes_share_owned (sc_array_t * node_data, 00283 p8est_lnodes_t * lnodes); 00284 00301 p8est_lnodes_buffer_t *p8est_lnodes_share_all_begin (sc_array_t * node_data, 00302 p8est_lnodes_t * lnodes); 00303 00304 void p8est_lnodes_share_all_end (p8est_lnodes_buffer_t * 00305 buffer); 00306 00314 p8est_lnodes_buffer_t *p8est_lnodes_share_all (sc_array_t * node_data, 00315 p8est_lnodes_t * lnodes); 00316 00317 void p8est_lnodes_buffer_destroy (p8est_lnodes_buffer_t * 00318 buffer); 00319 00322 /*@unused@*/ 00323 static inline p8est_lnodes_rank_t * 00324 p8est_lnodes_rank_array_index_int (sc_array_t * array, int it) 00325 { 00326 P4EST_ASSERT (array->elem_size == sizeof (p8est_lnodes_rank_t)); 00327 P4EST_ASSERT (it >= 0 && (size_t) it < array->elem_count); 00328 00329 return (p8est_lnodes_rank_t *) 00330 (array->array + sizeof (p8est_lnodes_rank_t) * it); 00331 } 00332 00335 /*@unused@*/ 00336 static inline p8est_lnodes_rank_t * 00337 p8est_lnodes_rank_array_index (sc_array_t * array, size_t it) 00338 { 00339 P4EST_ASSERT (array->elem_size == sizeof (p8est_lnodes_rank_t)); 00340 P4EST_ASSERT (it < array->elem_count); 00341 00342 return (p8est_lnodes_rank_t *) 00343 (array->array + sizeof (p8est_lnodes_rank_t) * it); 00344 } 00345 00347 /*@unused@*/ 00348 static inline p4est_gloidx_t 00349 p8est_lnodes_global_index (p8est_lnodes_t * lnodes, p4est_locidx_t lidx) 00350 { 00351 p4est_locidx_t owned = lnodes->owned_count; 00352 P4EST_ASSERT (lidx >= 0 && lidx < lnodes->num_local_nodes); 00353 00354 return (lidx < owned) ? lnodes->global_offset + lidx : 00355 lnodes->nonlocal_nodes[lidx - owned]; 00356 } 00357 00358 SC_EXTERN_C_END; 00359 00360 #endif /* !P8EST_LNODES */