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 P4EST_LNODES_H 00025 #define P4EST_LNODES_H 00026 00027 #include <p4est.h> 00028 #include <p4est_ghost.h> 00029 00030 SC_EXTERN_C_BEGIN; 00031 00032 typedef int8_t p4est_lnodes_code_t; 00033 00084 typedef struct p4est_lnodes 00085 { 00086 sc_MPI_Comm mpicomm; 00087 p4est_locidx_t num_local_nodes; 00088 p4est_locidx_t owned_count; 00089 p4est_gloidx_t global_offset; 00090 p4est_gloidx_t *nonlocal_nodes; 00091 sc_array_t *sharers; 00092 p4est_locidx_t *global_owned_count; 00093 00094 int degree, vnodes; 00095 p4est_locidx_t num_local_elements; 00096 p4est_lnodes_code_t *face_code; 00097 p4est_locidx_t *element_nodes; 00098 } 00099 p4est_lnodes_t; 00100 00112 typedef struct p4est_lnodes_rank 00113 { 00114 int rank; 00115 sc_array_t shared_nodes; 00116 p4est_locidx_t shared_mine_offset, shared_mine_count; 00117 p4est_locidx_t owned_offset, owned_count; 00118 } 00119 p4est_lnodes_rank_t; 00120 00134 /*@unused@*/ 00135 static inline int 00136 p4est_lnodes_decode (p4est_lnodes_code_t face_code, int hanging_face[4]) 00137 { 00138 P4EST_ASSERT (face_code >= 0); 00139 00140 if (face_code) { 00141 int i; 00142 int8_t c = face_code & 0x03; 00143 int f; 00144 int8_t work = face_code >> 2; 00145 00146 memset (hanging_face, -1, 4 * sizeof (int)); 00147 00148 for (i = 0; i < 2; ++i) { 00149 f = p4est_corner_faces[c][i]; 00150 hanging_face[f] = (work & 0x01) ? p4est_corner_face_corners[c][f] : -1; 00151 work >>= 1; 00152 } 00153 00154 return 1; 00155 } 00156 else { 00157 return 0; 00158 } 00159 } 00160 00161 p4est_lnodes_t *p4est_lnodes_new (p4est_t * p4est, 00162 p4est_ghost_t * ghost_layer, 00163 int degree); 00164 00165 void p4est_lnodes_destroy (p4est_lnodes_t * lnodes); 00166 00181 typedef struct p4est_lnodes_buffer 00182 { 00183 sc_array_t *requests; /* sc_MPI_Request */ 00184 sc_array_t *send_buffers; 00185 sc_array_t *recv_buffers; 00186 } 00187 p4est_lnodes_buffer_t; 00188 00205 p4est_lnodes_buffer_t *p4est_lnodes_share_owned_begin (sc_array_t * node_data, 00206 p4est_lnodes_t * 00207 lnodes); 00208 00209 void p4est_lnodes_share_owned_end (p4est_lnodes_buffer_t * 00210 buffer); 00211 00216 void p4est_lnodes_share_owned (sc_array_t * node_data, 00217 p4est_lnodes_t * lnodes); 00218 00235 p4est_lnodes_buffer_t *p4est_lnodes_share_all_begin (sc_array_t * node_data, 00236 p4est_lnodes_t * lnodes); 00237 00238 void p4est_lnodes_share_all_end (p4est_lnodes_buffer_t * 00239 buffer); 00240 00248 p4est_lnodes_buffer_t *p4est_lnodes_share_all (sc_array_t * node_data, 00249 p4est_lnodes_t * lnodes); 00250 00251 void p4est_lnodes_buffer_destroy (p4est_lnodes_buffer_t * 00252 buffer); 00253 00256 /*@unused@*/ 00257 static inline p4est_lnodes_rank_t * 00258 p4est_lnodes_rank_array_index_int (sc_array_t * array, int it) 00259 { 00260 P4EST_ASSERT (array->elem_size == sizeof (p4est_lnodes_rank_t)); 00261 P4EST_ASSERT (it >= 0 && (size_t) it < array->elem_count); 00262 00263 return (p4est_lnodes_rank_t *) 00264 (array->array + sizeof (p4est_lnodes_rank_t) * it); 00265 } 00266 00269 /*@unused@*/ 00270 static inline p4est_lnodes_rank_t * 00271 p4est_lnodes_rank_array_index (sc_array_t * array, size_t it) 00272 { 00273 P4EST_ASSERT (array->elem_size == sizeof (p4est_lnodes_rank_t)); 00274 P4EST_ASSERT (it < array->elem_count); 00275 00276 return (p4est_lnodes_rank_t *) 00277 (array->array + sizeof (p4est_lnodes_rank_t) * it); 00278 } 00279 00281 /*@unused@*/ 00282 static inline p4est_gloidx_t 00283 p4est_lnodes_global_index (p4est_lnodes_t * lnodes, p4est_locidx_t lidx) 00284 { 00285 p4est_locidx_t owned = lnodes->owned_count; 00286 P4EST_ASSERT (lidx >= 0 && lidx < lnodes->num_local_nodes); 00287 00288 return (lidx < owned) ? lnodes->global_offset + lidx : 00289 lnodes->nonlocal_nodes[lidx - owned]; 00290 } 00291 00292 SC_EXTERN_C_END; 00293 00294 #endif /* !P4EST_LNODES */