diff --git a/src/h5core/h5_hdf5.c b/src/h5core/h5_hdf5.c index ec62a93..b423fe2 100644 --- a/src/h5core/h5_hdf5.c +++ b/src/h5core/h5_hdf5.c @@ -1247,7 +1247,7 @@ _iter_op_get_obj_type ( if ( info->type == H5L_TYPE_EXTERNAL ) { char *buf; - TRY( buf = h5_alloc(f, NULL, info->u.val_size) ); + TRY( buf = h5_calloc(f, 1, info->u.val_size) ); herr = H5Lget_val(g_id, name, buf, info->u.val_size, H5P_DEFAULT); @@ -1271,7 +1271,7 @@ _iter_op_get_obj_type ( "Followed external link to file '%s' / object '%s'.", filename, objname); - free(buf); + h5_free(f, buf); hid_t obj_id = H5Oopen(g_id, name, H5P_DEFAULT); if ( obj_id < 0 ) diff --git a/src/h5core/h5_lustre.c b/src/h5core/h5_lustre.c index 917ae94..b10031a 100644 --- a/src/h5core/h5_lustre.c +++ b/src/h5core/h5_lustre.c @@ -33,7 +33,7 @@ _get_lustre_stripe_size(h5_file_t *const f, const char *path ) size_t nbytes = sizeof(struct lov_user_md) + INIT_ALLOC_NUM_OSTS * sizeof(struct lov_user_ost_data); struct lov_user_md *lum; - TRY( lum = h5_alloc(f, NULL, nbytes) ); + TRY( lum = h5_calloc(f, 1, nbytes) ); lum->lmm_magic = LOV_USER_MAGIC; int fd = open64(path, O_RDONLY); @@ -84,7 +84,7 @@ _get_lustre_stripe_size(h5_file_t *const f, const char *path ) _print_stripe_info(lum); ssize_t stripe_size = (ssize_t)lum->lmm_stripe_size; - free(lum); + h5_free(f, lum); return stripe_size; } @@ -98,7 +98,7 @@ h5_optimize_for_lustre ( ssize_t stripe_size; if ( f->myproc == 0 ) { - char *path = malloc(strlen(filename)+4); + char *path = h5_calloc(f, 1, strlen(filename)+4); strcpy(path, filename); /* check for existing file */ FILE *test = fopen(path, "r"); @@ -116,7 +116,7 @@ h5_optimize_for_lustre ( stripe_size = _get_lustre_stripe_size(f, path); - free(path); + h5_free(f, path); } TRY( h5priv_mpi_bcast(f, &stripe_size, 1, MPI_LONG_LONG, 0, f->comm) ); diff --git a/src/h5core/h5_maps.c b/src/h5core/h5_maps.c index 47394ba..d025fa5 100644 --- a/src/h5core/h5_maps.c +++ b/src/h5core/h5_maps.c @@ -89,7 +89,7 @@ h5_loc_id_t h5priv_find_idlist ( h5_file_t* const f, h5_idlist_t* list, - h5_loc_id_t item + const h5_loc_id_t item ) { UNUSED_ARGUMENT (f); if (!list) { @@ -97,9 +97,17 @@ h5priv_find_idlist ( } register h5_loc_idx_t low = 0; register h5_loc_idx_t high = list->num_items - 1; + register h5_loc_id_t diff; + register h5_loc_id_t mid; + const h5_loc_id_t face_idx = h5tpriv_get_face_idx(item); + const h5_loc_id_t elem_idx = h5tpriv_get_elem_idx(item); while (low <= high) { - register h5_loc_idx_t mid = (low + high) / 2; - register h5_loc_id_t diff = list->items[mid] - item; + mid = (low + high) / 2; + diff = h5tpriv_get_elem_idx(list->items[mid]) - elem_idx; + // if element indices are equal, we decide on the face indices + if (diff == 0) { + diff = h5tpriv_get_face_idx(list->items[mid]) - face_idx; + } if ( diff > 0 ) high = mid - 1; else if ( diff < 0 ) diff --git a/src/h5core/h5_openclose.c b/src/h5core/h5_openclose.c index 8bb5488..6fd71c7 100644 --- a/src/h5core/h5_openclose.c +++ b/src/h5core/h5_openclose.c @@ -302,7 +302,7 @@ h5upriv_close_file ( TRY( h5priv_close_hdf5_dataspace (f, u->diskshape) ); TRY( h5priv_close_hdf5_dataspace (f, u->memshape) ); TRY( h5priv_close_hdf5_property (f, u->dcreate_prop) ); - free (f->u); + h5_free (f, f->u); f->u = NULL; return f->__errno; @@ -333,7 +333,7 @@ h5bpriv_close_file ( #if defined(PARALLEL_IO) TRY( h5priv_mpi_type_free (f, &b->partition_mpi_t) ); #endif - free (f->b); + h5_free (f, f->b); f->b = NULL; return H5_SUCCESS; @@ -368,9 +368,9 @@ h5_close_file ( TRY( h5priv_close_hdf5_property (f, f->create_prop) ); TRY( h5priv_close_hdf5_group (f, f->root_gid) ); TRY( h5priv_close_hdf5_file (f, f->file) ); - - free (f); h5_debug (f, "%s (): done", __func__); + + h5_free (f, f); return H5_SUCCESS; } diff --git a/src/h5core/h5b_model.c b/src/h5core/h5b_model.c index 93af6ba..72a7c5f 100644 --- a/src/h5core/h5b_model.c +++ b/src/h5core/h5b_model.c @@ -371,7 +371,7 @@ _dissolve_ghostzones ( _dissolve_ghostzone ( f, p_max->p, p_max->q ); - free ( p_max ); + h5_free (f, p_max); p_el = p_max = p_begin->next; while ( p_el ) { @@ -385,13 +385,13 @@ _dissolve_ghostzones ( p_el->next->prev = p_el->prev; p_el->prev->next = p_el->next; p_save = p_el->next; - free ( p_el ); + h5_free (f, p_el); p_el = p_save; } } } - free ( p_begin ); + h5_free (f, p_begin); return H5_SUCCESS; } @@ -581,8 +581,8 @@ h5b_3d_set_view ( - free(user_layout); - free(write_layout); + h5_free(f, user_layout); + h5_free(f, write_layout); TRY( h5bpriv_release_hyperslab(f) ); #endif diff --git a/src/h5core/h5t_adjacencies_tetm.c b/src/h5core/h5t_adjacencies_tetm.c index 7a36f37..4df0ed8 100644 --- a/src/h5core/h5t_adjacencies_tetm.c +++ b/src/h5core/h5t_adjacencies_tetm.c @@ -18,6 +18,9 @@ #include "h5core/h5_core.h" #include "h5_core_private.h" +/* + Allocate structure keeping the upward adjacent elements for each vertex. + */ static inline h5_err_t alloc_tv ( h5_file_t* const f, @@ -36,6 +39,9 @@ alloc_tv ( return H5_SUCCESS; } +/* + Release structure keeping the upward adjacent elements for each vertex. + */ static inline h5_err_t release_tv ( h5_file_t* const f @@ -44,10 +50,10 @@ release_tv ( h5t_adjacencies_t* adj = &t->adjacencies; if (adj->tv.v == NULL) return H5_SUCCESS; - h5_loc_idx_t idx = 0; + h5_loc_idx_t vertex_idx = 0; h5_loc_idx_t last = t->num_vertices[t->num_leaf_levels-1]; - for (; idx < last; idx++) { - TRY( h5priv_free_idlist (f, &adj->tv.v[idx]) ); + for (; vertex_idx < last; vertex_idx++) { + TRY( h5priv_free_idlist (f, &adj->tv.v[vertex_idx]) ); } TRY( h5_free (f, adj->tv.v) ); adj->tv.v = NULL; @@ -55,7 +61,7 @@ release_tv ( } /* - compute T(V) from current level up to highest levels. + Compute upward adjacent elements for each vertex. */ static inline h5_err_t compute_elems_of_vertices ( @@ -67,48 +73,43 @@ compute_elems_of_vertices ( /* loop over all elements in current level */ h5t_fdata_t* t = f->t; - h5_loc_idx_t idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; - h5_loc_idx_t last = t->num_elems[t->num_leaf_levels-1]; - h5_loc_tet_t *el = &t->loc_elems.tets[idx]; - for (;idx < last; idx++, el++) { + h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0:t->num_elems[from_lvl-1]; + h5_loc_idx_t last = (t->num_leaf_levels < 0) ? 0:t->num_elems[t->num_leaf_levels-1]; + for (;elem_idx < last; elem_idx++) { int face_idx; int num_faces = h5tpriv_ref_elem_get_num_vertices(t); for (face_idx = 0; face_idx < num_faces; face_idx++) { - h5_loc_idx_t vidx = el->vertex_indices[face_idx]; - TRY( h5priv_insert_idlist ( - f, - &t->adjacencies.tv.v[vidx], - h5tpriv_build_vertex_id (face_idx, idx), - -1) ); + TRY( h5tpriv_search_tv2 (f, face_idx, elem_idx, NULL) ); } } return H5_SUCCESS; } /* - Compute T(E) from current level up to highest levels. + Compute upward adjacent elements for each edge. */ static inline h5_err_t compute_elems_of_edges ( h5_file_t* const f, const h5t_lvl_idx_t from_lvl ) { - h5t_fdata_t *t = f->t; + h5t_fdata_t* t = f->t; h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - h5_idlist_t *retval = NULL; TRY( h5tpriv_resize_te_htab (f, 4*(num_elems-elem_idx)) ); for (;elem_idx < num_elems; elem_idx++) { int face_idx; int num_faces = h5tpriv_ref_elem_get_num_edges(t); for (face_idx = 0; face_idx < num_faces; face_idx++) { - TRY( h5tpriv_search_te2 ( - f, face_idx, elem_idx, &retval) ); + TRY( h5tpriv_search_te2 (f, face_idx, elem_idx, NULL) ); } } return H5_SUCCESS; } +/* + Compute upward adjacent elements for each triangle. + */ static inline h5_err_t compute_elems_of_triangles ( h5_file_t* const f, @@ -117,53 +118,47 @@ compute_elems_of_triangles ( h5t_fdata_t* t = f->t; h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - h5_idlist_t *retval = NULL; TRY( h5tpriv_resize_td_htab (f, 4*(num_elems-elem_idx)) ); for (;elem_idx < num_elems; elem_idx++) { int face_idx; int num_faces = h5tpriv_ref_elem_get_num_edges (t); for (face_idx = 0; face_idx < num_faces; face_idx++) { - TRY( h5tpriv_search_td2 ( - f, face_idx, elem_idx, &retval) ); + TRY( h5tpriv_search_td2 (f, face_idx, elem_idx, NULL) ); } } return H5_SUCCESS; } +/* + Compute the children o an edge + */ static inline h5_err_t compute_children_of_edge ( h5_file_t* const f, - h5_loc_id_t kid, - h5_idlist_t* children + h5_loc_id_t entity_id, + h5_idlist_t** children ) { - h5t_fdata_t* t = f->t; h5_idlist_t* te; - - TRY( h5tpriv_find_te2 ( - f, - h5tpriv_get_face_idx (kid), - h5tpriv_get_elem_idx (kid), - &te ) - ); - h5_loc_id_t* edge = te->items; + TRY( h5tpriv_find_te (f, entity_id, &te ) ); + h5_loc_id_t* edge_idp = te->items; h5_loc_id_t* end = te->items+te->num_items; - for (; edge < end; edge++) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge); - h5_loc_tet_t* tet = &t->loc_elems.tets[elem_idx]; - if (h5tpriv_is_leaf_elem (f, (h5_generic_loc_elem_t*)tet) == H5_OK ) { - TRY( h5priv_insert_idlist (f, &children, *edge, -1) ); + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); + h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; + if (h5tpriv_is_leaf_elem (f, elem)) { + TRY( h5priv_insert_idlist (f, children, *edge_idp, -1) ); } else { - h5_loc_id_t kids[2]; + h5_loc_id_t edge_ids[2]; TRY( h5tpriv_get_direct_children_of_edge ( f, face_idx, - tet->child_idx, - kids) ); - TRY( compute_children_of_edge (f, kids[0], children) ); - TRY( compute_children_of_edge (f, kids[1], children) ); + elem->child_idx, + edge_ids) ); + TRY( compute_children_of_edge (f, edge_ids[0], children) ); + TRY( compute_children_of_edge (f, edge_ids[1], children) ); } - } + } while (++edge_idp < end); return H5_SUCCESS; } @@ -173,38 +168,32 @@ compute_children_of_edge ( static inline h5_err_t compute_sections_of_edge ( h5_file_t* const f, - h5_loc_id_t kid, - h5_idlist_t* children + h5_loc_id_t entity_id, + h5_idlist_t** children ) { - h5t_fdata_t* t = f->t; h5_idlist_t* te; - - TRY( h5tpriv_find_te2 ( - f, - h5tpriv_get_face_idx (kid), - h5tpriv_get_elem_idx (kid), - &te ) ); - h5_loc_id_t* edge = te->items; + TRY( h5tpriv_find_te (f, entity_id, &te) ); + h5_loc_id_t* edge_idp = te->items; h5_loc_id_t* end = te->items+te->num_items; int refined = 0; - for (; edge < end; edge++) { - h5_loc_idx_t eid = h5tpriv_get_elem_idx (*edge); - h5_loc_idx_t face_id = h5tpriv_get_face_idx (*edge); - h5_generic_loc_elem_t* tet = (h5_generic_loc_elem_t*)&t->loc_elems.tets[eid]; - if (! h5tpriv_is_leaf_elem (f, tet) == H5_OK) { + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); + h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; + if (!h5tpriv_is_leaf_elem (f, elem)) { refined = 1; - h5_loc_id_t kids[2]; + h5_loc_id_t edge_ids[2]; TRY( h5tpriv_get_direct_children_of_edge ( f, - face_id, - tet->child_idx, - kids) ); - TRY( compute_sections_of_edge (f, kids[0], children) ); - TRY( compute_sections_of_edge (f, kids[1], children) ); + face_idx, + elem->child_idx, + edge_ids) ); + TRY( compute_sections_of_edge (f, edge_ids[0], children) ); + TRY( compute_sections_of_edge (f, edge_ids[1], children) ); } - } - if (! refined) { - TRY( h5priv_insert_idlist (f, &children, te->items[0], -1) ); + } while (++edge_idp < end); + if (!refined) { + TRY( h5priv_insert_idlist (f, children, te->items[0], -1) ); } return H5_SUCCESS; } @@ -243,9 +232,9 @@ compute_sections_of_edge ( static inline h5_err_t compute_direct_children_of_triangle ( h5_file_t* const f, - h5_loc_idx_t face_idx, - h5_loc_idx_t elem_idx, - h5_loc_id_t* children + h5_loc_idx_t face_idx, // in + h5_loc_idx_t elem_idx, // in + h5_loc_id_t* children // out ) { h5_loc_idx_t map[4][4][2] = { {{0,0},{0,1},{0,2},{0,5}}, @@ -257,13 +246,13 @@ compute_direct_children_of_triangle ( if ((face_idx < 0) || (face_idx >= num_faces)) { return h5_error_internal (f, __FILE__, __func__, __LINE__); } - children[0] = h5tpriv_build_edge_id ( + children[0] = h5tpriv_build_triangle_id ( map[face_idx][0][0], elem_idx+map[face_idx][0][1]); - children[1] = h5tpriv_build_edge_id ( + children[1] = h5tpriv_build_triangle_id ( map[face_idx][1][0], elem_idx+map[face_idx][1][1]); - children[2] = h5tpriv_build_edge_id ( + children[2] = h5tpriv_build_triangle_id ( map[face_idx][2][0], elem_idx+map[face_idx][2][1]); - children[3] = h5tpriv_build_edge_id ( + children[3] = h5tpriv_build_triangle_id ( map[face_idx][3][0], elem_idx+map[face_idx][3][1]); return H5_SUCCESS; } @@ -271,95 +260,153 @@ compute_direct_children_of_triangle ( static inline h5_err_t compute_children_of_triangle ( h5_file_t* const f, - h5_loc_id_t did, - h5_idlist_t* children + h5_loc_id_t entity_id, + h5_idlist_t** children ) { - - h5t_fdata_t* t = f->t; h5_idlist_t* td; - - TRY( h5tpriv_find_td2 ( - f, - h5tpriv_get_face_idx (did), - h5tpriv_get_elem_idx (did), - &td) ); - h5_loc_id_t* tri = td->items; + TRY( h5tpriv_find_td (f, entity_id, &td) ); + h5_loc_id_t* triangle_idp = td->items; h5_loc_id_t* end = td->items+td->num_items; - for (; tri < end; tri++) { - h5_loc_idx_t eid = h5tpriv_get_elem_idx (*tri); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*tri); - h5_generic_loc_elem_t* tet = (h5_generic_loc_elem_t*)&t->loc_elems.tets[eid]; - if (h5tpriv_is_leaf_elem (f, tet) == H5_OK) { - TRY( h5priv_insert_idlist (f, &children, *tri, -1) ); + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*triangle_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*triangle_idp); + h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; + if (h5tpriv_is_leaf_elem (f, elem)) { + TRY( h5priv_insert_idlist (f, children, *triangle_idp, -1) ); } else { - h5_loc_id_t dids[4] = {-1,-1,-1,-1}; + h5_loc_id_t triangle_ids[4] = {-1,-1,-1,-1}; TRY( compute_direct_children_of_triangle ( f, face_idx, - tet->child_idx, - dids) ); - TRY( compute_children_of_triangle (f, dids[0], children) ); - TRY( compute_children_of_triangle (f, dids[1], children) ); - TRY( compute_children_of_triangle (f, dids[2], children) ); - TRY( compute_children_of_triangle (f, dids[3], children) ); + elem->child_idx, + triangle_ids) ); + TRY( compute_children_of_triangle (f, triangle_ids[0], children) ); + TRY( compute_children_of_triangle (f, triangle_ids[1], children) ); + TRY( compute_children_of_triangle (f, triangle_ids[2], children) ); + TRY( compute_children_of_triangle (f, triangle_ids[3], children) ); } - } + } while (++triangle_idp < end); return H5_SUCCESS; } static inline h5_err_t compute_sections_of_triangle ( h5_file_t* const f, - h5_loc_id_t did, - h5_idlist_t* children + h5_loc_id_t entity_id, + h5_idlist_t** children ) { - h5t_fdata_t* t = f->t; h5_idlist_t* td; - - TRY( h5tpriv_find_td2 ( - f, - h5tpriv_get_face_idx (did), - h5tpriv_get_elem_idx (did), &td) ); - h5_loc_id_t* tri = td->items; + TRY( h5tpriv_find_td (f, entity_id, &td) ); + h5_loc_id_t* triangle_idp = td->items; h5_loc_id_t* end = td->items+td->num_items; int refined = 0; - for (; tri < end; tri++) { - h5_loc_idx_t eid = h5tpriv_get_elem_idx (*tri); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*tri); - h5_generic_loc_elem_t* tet = (h5_generic_loc_elem_t*)&t->loc_elems.tets[eid]; - if (! h5tpriv_is_leaf_elem (f, tet) == H5_OK) { + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*triangle_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*triangle_idp); + h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; + if (!h5tpriv_is_leaf_elem (f, elem)) { refined = 1; - h5_loc_id_t dids[4] = {-1,-1,-1,-1}; + h5_loc_id_t triangle_ids[4] = {-1,-1,-1,-1}; TRY( compute_direct_children_of_triangle ( f, face_idx, - tet->child_idx, - dids) ); - TRY( compute_sections_of_triangle (f, dids[0], children) ); - TRY( compute_sections_of_triangle (f, dids[1], children) ); - TRY( compute_sections_of_triangle (f, dids[2], children) ); - TRY( compute_sections_of_triangle (f, dids[3], children) ); + elem->child_idx, + triangle_ids) ); + TRY( compute_sections_of_triangle (f, triangle_ids[0], children) ); + TRY( compute_sections_of_triangle (f, triangle_ids[1], children) ); + TRY( compute_sections_of_triangle (f, triangle_ids[2], children) ); + TRY( compute_sections_of_triangle (f, triangle_ids[3], children) ); } - } + } while (++triangle_idp < end); if (! refined) { - TRY( h5priv_insert_idlist (f, &children, td->items[0], -1) ); + TRY( h5priv_insert_idlist (f, children, td->items[0], -1) ); } return H5_SUCCESS; } + /* - map edge ID to unique ID - if unique ID not in list: add + Add unique ID of vertex given by face and element index to list. +*/ +static inline h5_err_t +add_vertex2 ( + h5_file_t* const f, // in + h5_idlist_t** list, // out + h5_loc_idx_t face_idx, // in + h5_loc_idx_t elem_idx // in + ) { + h5_idlist_t* tv; + TRY( h5tpriv_find_tv2 (f, face_idx, elem_idx, &tv) ); + TRY( h5priv_search_idlist (f, list, tv->items[0]) ); + return H5_SUCCESS; +} + +/* + Add unique ID of edge given by ID or face and element index. */ static inline h5_err_t add_edge ( - h5_file_t* const f, - h5_idlist_t* list, - h5_loc_idx_t face_idx, - h5_loc_idx_t elem_idx + h5_file_t* const f, // in + h5_idlist_t** list, // out + h5_loc_id_t entity_id // in + ) { + h5_idlist_t* te; + TRY( h5tpriv_find_te (f, entity_id, &te) ); + TRY( h5priv_search_idlist (f, list, te->items[0]) ); + return H5_SUCCESS; +} + +static inline h5_err_t +add_edge2 ( + h5_file_t* const f, // in + h5_idlist_t** list, // out + h5_loc_idx_t face_idx, // in + h5_loc_idx_t elem_idx // in ) { h5_idlist_t* te; TRY( h5tpriv_find_te2 (f, face_idx, elem_idx, &te) ); - TRY( h5priv_search_idlist (f, &list, te->items[0]) ); + TRY( h5priv_search_idlist (f, list, te->items[0]) ); + return H5_SUCCESS; +} + +/* + Add unique ID of triangle given by ID or face and element index. +*/ +static inline h5_err_t +add_triangle ( + h5_file_t* const f, // in + h5_idlist_t** list, // out + h5_loc_idx_t entity_id // in + ) { + h5_idlist_t* td; + TRY( h5tpriv_find_td (f, entity_id, &td) ); + TRY( h5priv_search_idlist (f, list, td->items[0]) ); + + return H5_SUCCESS; +} + +static inline h5_err_t +add_triangle2 ( + h5_file_t* const f, // in + h5_idlist_t** list, // out + h5_loc_idx_t face_idx, // in + h5_loc_idx_t elem_idx // in + ) { + h5_idlist_t* td; + TRY( h5tpriv_find_td2 (f, face_idx, elem_idx, &td) ); + TRY( h5priv_search_idlist (f, list, td->items[0]) ); + + return H5_SUCCESS; +} + +static inline h5_err_t +add_elem2 ( + h5_file_t* const f, // in + h5_idlist_t** list, // out + h5_loc_idx_t elem_idx // in + ) { + h5_loc_id_t elem_id = h5tpriv_build_tet_id (0, elem_idx); + TRY( h5priv_search_idlist (f, list, elem_id) ); + return H5_SUCCESS; } @@ -369,137 +416,128 @@ add_edge ( static inline h5_err_t get_edges_uadj_to_vertex ( h5_file_t* const f, - const h5_loc_id_t id, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { + h5_loc_idx_t vertex_idx; + TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); + h5_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; + TRY( h5priv_alloc_idlist (f, list, 8) ); - - h5t_fdata_t* const t = f->t; - h5_loc_idx_t idx; - TRY( h5t_get_vertex_index_of_vertex (f, id, &idx) ); - h5_idlist_t** tv = &t->adjacencies.tv.v[idx]; - h5_size_t i; + h5_loc_id_t* vertex_idp = tv->items; + h5_loc_id_t* end = vertex_idp + tv->num_items; + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*vertex_idp); + h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; - h5_loc_id_t* vidp = (*tv)->items; // ptr to upward adjacent elements - for (i = 0; i < (*tv)->num_items; i++, vidp++) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vidp); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*vidp); - h5_generic_loc_elem_t* tet = (h5_generic_loc_elem_t*)&t->loc_elems.tets[elem_idx]; - - if (h5tpriv_is_leaf_elem (f, tet) == H5_NOK ) { + if (!h5tpriv_is_leaf_elem (f, elem)) { continue; } - h5_loc_idx_t edge_idx; - edge_idx = h5tpriv_get_edge_connected_to_vertex (t->ref_elem, face_idx, 0); - TRY( add_edge (f, *list, edge_idx, elem_idx) ); - edge_idx = h5tpriv_get_edge_connected_to_vertex (t->ref_elem, face_idx, 1); - TRY( add_edge (f, *list, edge_idx, elem_idx) ); - edge_idx = h5tpriv_get_edge_connected_to_vertex (t->ref_elem, face_idx, 2); - TRY( add_edge (f, *list, edge_idx, elem_idx) ); - } - return H5_SUCCESS; -} - -static inline h5_err_t -add_triangle ( - h5_file_t* const f, - h5_idlist_t* list, - h5_loc_idx_t face_idx, - h5_loc_idx_t elem_idx - ) { - h5_idlist_t* td; - TRY( h5tpriv_find_td2 (f, face_idx, elem_idx, &td) ); - TRY( h5priv_search_idlist (f, &list, td->items[0]) ); - + TRY( add_edge2 (f, list, + h5tpriv_ref_elem_get_edge_idx ( + f->t, 0, face_idx, 0), + elem_idx) ); + TRY( add_edge2 (f, list, + h5tpriv_ref_elem_get_edge_idx ( + f->t, 0, face_idx, 1), + elem_idx) ); + TRY( add_edge2 (f, list, + h5tpriv_ref_elem_get_edge_idx ( + f->t, 0, face_idx, 2), + elem_idx) ); + } while (++vertex_idp < end); return H5_SUCCESS; } static inline h5_err_t get_triangles_uadj_to_vertex ( - h5_file_t * const f, - const h5_loc_id_t id, - h5_idlist_t **list + h5_file_t* const f, + const h5_loc_id_t entity_id, + h5_idlist_t** list ) { - /* - Pre-allocate a list with 8 items. Why 8? Why not? - ;-) - We should change it when we have something better. - */ - TRY ( h5priv_alloc_idlist ( f, list, 8 ) ); + /* get list of all tetrahedra connected to given vertex + Note: this list may include tetrahedra which are not in + the (current) leaf grid */ + h5_loc_idx_t vertex_idx; + TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); + h5_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; - h5t_fdata_t* t = f->t; - h5_loc_idx_t idx; - TRY( h5t_get_vertex_index_of_vertex (f, id, &idx) ); - h5_idlist_t** tv = &t->adjacencies.tv.v[idx]; - - h5_size_t i; - h5_loc_id_t* vidp = (*tv)->items; - for (i = 0; i < (*tv)->num_items; i++, vidp++) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vidp); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*vidp); - h5_generic_loc_elem_t* tet = (h5_generic_loc_elem_t*)&t->loc_elems.tets[elem_idx]; - - if (h5tpriv_is_leaf_elem (f, tet) == H5_NOK) { + // build list of upward adjacent triangles + TRY( h5priv_alloc_idlist (f, list, 8) ); + h5_loc_id_t* vertex_idp = tv->items; + h5_loc_id_t* end = vertex_idp + tv->num_items; + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*vertex_idp); + h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; + if (!h5tpriv_is_leaf_elem (f, elem)) { continue; } - h5_loc_idx_t facet_idx; - facet_idx = h5tpriv_get_triangles_connected_to_vertex (t->ref_elem, face_idx, 0); - TRY( add_triangle (f, *list, facet_idx, elem_idx) ); - facet_idx = h5tpriv_get_triangles_connected_to_vertex (t->ref_elem, face_idx, 1); - TRY( add_triangle (f, *list, facet_idx, elem_idx) ); - facet_idx = h5tpriv_get_triangles_connected_to_vertex (t->ref_elem, face_idx, 2); - TRY( add_triangle (f, *list, facet_idx, elem_idx) ); - } + TRY( add_triangle2 (f, list, + h5tpriv_ref_elem_get_triangle_idx ( + f->t, 0, face_idx, 0), + elem_idx) ); + TRY( add_triangle2 (f, list, + h5tpriv_ref_elem_get_triangle_idx ( + f->t, 0, face_idx, 1), + elem_idx) ); + TRY( add_triangle2 (f, list, + h5tpriv_ref_elem_get_triangle_idx ( + f->t, 0, face_idx, 2), + elem_idx) ); + } while (++vertex_idp < end); return H5_SUCCESS; } static inline h5_err_t get_tets_uadj_to_vertex ( h5_file_t* const f, - const h5_loc_id_t id, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { + h5_loc_idx_t vertex_idx; + TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); + h5_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; + TRY( h5priv_alloc_idlist (f, list, 8) ); - - h5t_fdata_t* t = f->t; - h5_loc_idx_t idx; - TRY( h5t_get_vertex_index_of_vertex (f, id, &idx) ); - h5_idlist_t** tv = &t->adjacencies.tv.v[idx]; - h5_size_t i; - - h5_loc_id_t* vidp = (*tv)->items; - for (i = 0; i < (*tv)->num_items; i++, vidp++) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vidp); - h5_generic_loc_elem_t* tet = (h5_generic_loc_elem_t*)&t->loc_elems.tets[elem_idx]; - - if (h5tpriv_is_leaf_elem (f, tet) == H5_NOK) { + h5_loc_id_t* vertex_idp = tv->items; + h5_loc_id_t* end = vertex_idp + tv->num_items; + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); + h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; + if (!h5tpriv_is_leaf_elem (f, elem)) { continue; } - // add to result - TRY( h5priv_search_idlist (f, list, elem_idx) ); - } + TRY( add_elem2 (f, list, elem_idx) ); + } while (++vertex_idp < end); return H5_SUCCESS; } static inline h5_err_t get_triangles_uadj_to_edge ( h5_file_t* const f, - const h5_loc_id_t kid, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { h5_idlist_t* children; TRY( h5priv_alloc_idlist (f, &children, 8) ); - TRY( compute_children_of_edge (f, kid, children) ); + TRY( compute_children_of_edge (f, entity_id, &children) ); TRY( h5priv_alloc_idlist (f, list, 8) ); - h5_loc_id_t* edge = children->items; + h5_loc_id_t* edge_idp = children->items; h5_loc_id_t* end = children->items+children->num_items; - int map[6][2] = { {2,3}, {0,3}, {1,3}, {1,2}, {0,2}, {0,1} }; - for (; edge < end; edge++) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge); - TRY( add_triangle (f, *list, map[face_idx][0], elem_idx) ); - TRY( add_triangle (f, *list, map[face_idx][1], elem_idx) ); - } + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); + TRY( add_triangle2 (f, list, + h5tpriv_ref_elem_get_triangle_idx ( + f->t, 1, face_idx, 0), + elem_idx) ); + TRY( add_triangle2 (f, list, + h5tpriv_ref_elem_get_triangle_idx ( + f->t, 1, face_idx, 1), + elem_idx) ); + } while (++edge_idp < end); TRY( h5priv_free_idlist ( f, &children) ); return H5_SUCCESS; @@ -508,19 +546,18 @@ get_triangles_uadj_to_edge ( static inline h5_err_t get_tets_uadj_to_edge ( h5_file_t* const f, - const h5_loc_id_t kid, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { h5_idlist_t* children; TRY( h5priv_alloc_idlist (f, &children, 8) ); - TRY( compute_children_of_edge (f, kid, children) ); + TRY( compute_children_of_edge (f, entity_id, &children) ); TRY( h5priv_alloc_idlist (f, list, 8) ); - int i; - h5_loc_id_t* kidp = children->items; - for (i = 0; i < children->num_items; i++, kidp++) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*kidp); - TRY( h5priv_search_idlist (f, list, elem_idx) ); - } + h5_loc_id_t* edge_idp = children->items; + h5_loc_id_t* end = children->items+children->num_items; + do { + TRY( add_elem2 (f, list, h5tpriv_get_elem_idx (*edge_idp)) ); + } while (++edge_idp < end); TRY( h5priv_free_idlist (f, &children) ); return H5_SUCCESS; } @@ -528,19 +565,18 @@ get_tets_uadj_to_edge ( static inline h5_err_t get_tets_uadj_to_triangle ( h5_file_t* const f, - const h5_loc_id_t did, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { h5_idlist_t* children; TRY( h5priv_alloc_idlist (f, &children, 8) ); - TRY( compute_children_of_triangle (f, did, children) ); + TRY( compute_children_of_triangle (f, entity_id, &children) ); TRY( h5priv_alloc_idlist (f, list, 8) ); - int i; - h5_loc_id_t *didp = children->items; - for (i = 0; i < children->num_items; i++ , didp++) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*didp); - TRY( h5priv_search_idlist (f, list, elem_idx) ); - } + h5_loc_id_t* triangle_idp = children->items; + h5_loc_id_t* end = triangle_idp + children->num_items; + do { + TRY( add_elem2 (f, list, h5tpriv_get_elem_idx (*triangle_idp)) ); + } while (++triangle_idp < end); TRY( h5priv_free_idlist (f, &children) ); return H5_SUCCESS; } @@ -548,21 +584,29 @@ get_tets_uadj_to_triangle ( static inline h5_err_t get_vertices_dadj_to_edge ( h5_file_t* const f, - const h5_loc_id_t kid, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { h5_idlist_t* children; TRY( h5priv_alloc_idlist (f, &children, 8) ); - TRY( compute_sections_of_edge (f, kid, children) ); + TRY( compute_sections_of_edge (f, entity_id, &children) ); + // build list of unique vertex IDs TRY( h5priv_alloc_idlist (f, list, 8) ); - int i; - h5_loc_id_t* kidp = children->items; - for (i = 0; i < children->num_items; i++, kidp++) { - h5_loc_idx_t vertex_indices[2]; - TRY( h5t_get_vertex_indices_of_edge (f, *kidp, vertex_indices) ); - TRY( h5priv_search_idlist (f, list, vertex_indices[0]) ); - TRY( h5priv_search_idlist (f, list, vertex_indices[1]) ); - } + h5_loc_id_t* edge_idp = children->items; + h5_loc_id_t* end = edge_idp + children->num_items; + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); + + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, face_idx, 0), + elem_idx) ); + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, face_idx, 1), + elem_idx) ); + } while (++edge_idp < end); TRY( h5priv_free_idlist(f, &children) ); return H5_SUCCESS; } @@ -573,31 +617,40 @@ get_vertices_dadj_to_edge ( static inline h5_err_t get_vertices_dadj_to_triangle ( h5_file_t* const f, - const h5_loc_id_t did, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { h5_idlist_t* children; TRY( h5priv_alloc_idlist (f, &children, 8) ); - - int map[4][3] = { {1,4,5}, {2,3,5}, {0,3,4}, {0,1,2} }; - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (did); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (did); - + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); + h5_loc_idx_t edge_idx; int i; + // loop over all vertices of given triangle for (i = 0; i < 3; i++) { + edge_idx = h5tpriv_ref_elem_get_edge_idx (f->t, 2, face_idx, i); TRY( compute_sections_of_edge ( f, - h5tpriv_build_edge_id (map[face_idx][i], elem_idx), - children) ); + h5tpriv_build_edge_id (edge_idx, elem_idx), + &children) ); } + // build list of unique vertex IDs TRY( h5priv_alloc_idlist (f, list, 8) ); - h5_loc_id_t* kid = children->items; - for (i = 0; i < children->num_items; i++, kid++) { - h5_loc_idx_t vertex_indices[2]; - TRY( h5t_get_vertex_indices_of_edge (f, *kid, vertex_indices) ); - TRY( h5priv_search_idlist (f, list, vertex_indices[0]) ); - TRY( h5priv_search_idlist (f, list, vertex_indices[1]) ); - } + h5_loc_id_t* edge_idp = children->items; + h5_loc_id_t* end = edge_idp + children->num_items; + do { + elem_idx = h5tpriv_get_elem_idx (*edge_idp); + edge_idx = h5tpriv_get_face_idx (*edge_idp); + + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, edge_idx, 0), + elem_idx) ); + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, edge_idx, 1), + elem_idx) ); + } while (++edge_idp < end ); TRY( h5priv_free_idlist(f, &children) ); return H5_SUCCESS; } @@ -608,28 +661,37 @@ get_vertices_dadj_to_triangle ( static inline h5_err_t get_vertices_dadj_to_tet ( h5_file_t* const f, - const h5_loc_id_t eid, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { h5_idlist_t* children; - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (eid); + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); TRY( h5priv_alloc_idlist (f, &children, 8) ); - - int i; - for (i = 0; i < 6; i++) { + // loop over all edges of tetrahedron + h5_loc_idx_t edge_idx = h5tpriv_ref_elem_get_num_edges(f->t); + while (--edge_idx >= 0) { TRY( compute_sections_of_edge ( f, - h5tpriv_build_edge_id ( i, elem_idx ), - children) ); + h5tpriv_build_edge_id ( edge_idx, elem_idx ), + &children) ); } + // build list of unique vertex IDs TRY( h5priv_alloc_idlist (f, list, 8) ); - h5_loc_id_t *kid = children->items; - for (i = 0; i < children->num_items; i++, kid++) { - h5_loc_idx_t vertex_indices[2]; - TRY( h5t_get_vertex_indices_of_edge (f, *kid, vertex_indices) ); - TRY( h5priv_search_idlist (f, list, vertex_indices[0]) ); - TRY( h5priv_search_idlist (f, list, vertex_indices[1]) ); - } + h5_loc_id_t* edge_idp = children->items; + h5_loc_id_t* end = edge_idp + children->num_items; + do { + elem_idx = h5tpriv_get_elem_idx (*edge_idp); + edge_idx = h5tpriv_get_face_idx (*edge_idp); + + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, edge_idx, 0), + elem_idx) ); + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, edge_idx, 1), + elem_idx) ); + } while (++edge_idp < end); TRY( h5priv_free_idlist(f, &children) ); return H5_SUCCESS; } @@ -637,28 +699,31 @@ get_vertices_dadj_to_tet ( static inline h5_err_t get_edges_dadj_to_triangle ( h5_file_t* const f, - const h5_loc_id_t did, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { h5_idlist_t* children; TRY( h5priv_alloc_idlist (f, &children, 8) ); - - int map[4][3] = { {1,4,5}, {2,3,5}, {0,3,4}, {0,1,2} }; - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (did); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (did); - - int i; + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); + // loop over all three edges of triangle + h5_loc_idx_t i; for (i = 0; i < 3; i++) { TRY( compute_sections_of_edge ( f, - h5tpriv_build_edge_id ( map[face_idx][i], elem_idx ), - children) ); + h5tpriv_build_edge_id ( + h5tpriv_ref_elem_get_edge_idx ( + f->t, 2, face_idx, i), + elem_idx ), + &children) ); } + // build list of unique edge IDs TRY( h5priv_alloc_idlist (f, list, 8) ); - h5_loc_id_t *kid = children->items; - for (i = 0; i < children->num_items; i++, kid++) { - TRY( h5priv_search_idlist (f, list, *kid) ); - } + h5_loc_id_t* edge_idp = children->items; + h5_loc_id_t* end = edge_idp + children->num_items; + do { + TRY( add_edge (f, list, *edge_idp) ); + } while (++edge_idp < end); TRY( h5priv_free_idlist (f, &children) ); return H5_SUCCESS; } @@ -666,25 +731,28 @@ get_edges_dadj_to_triangle ( static inline h5_err_t get_edges_dadj_to_tet ( h5_file_t* const f, - const h5_loc_id_t eid, + const h5_loc_id_t elem_id, h5_idlist_t** list ) { h5_idlist_t* children; TRY( h5priv_alloc_idlist (f, &children, 8) ); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (eid); + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (elem_id); - int i; - for (i = 0; i < 6; i++) { + // loop over all edges of tet + h5_loc_idx_t edge_idx = h5tpriv_ref_elem_get_num_edges(f->t); + while (--edge_idx >= 0) { TRY( compute_sections_of_edge ( f, - h5tpriv_build_edge_id ( i, elem_idx ), - children) ); + h5tpriv_build_edge_id (edge_idx, elem_idx), + &children) ); } + // build list of unique edge IDs TRY( h5priv_alloc_idlist (f, list, 8) ); - h5_loc_id_t* kid = children->items; - for (i = 0; i < children->num_items; i++, kid++) { - TRY( h5priv_search_idlist (f, list, *kid) ); - } + h5_loc_id_t* edge_idp = children->items; + h5_loc_id_t* end = edge_idp + children->num_items; + do { + TRY( add_edge (f, list, *edge_idp) ); + } while (++edge_idp < end); TRY( h5priv_free_idlist (f, &children) ); return H5_SUCCESS; } @@ -692,25 +760,26 @@ get_edges_dadj_to_tet ( static inline h5_err_t get_triangles_dadj_to_tet ( h5_file_t* const f, - const h5_loc_id_t eid, + const h5_loc_id_t entity_id, h5_idlist_t** list ) { h5_idlist_t* children; TRY( h5priv_alloc_idlist (f, &children, 8) ); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (eid); - - int i; - for (i = 0; i < 4; i++) { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); + // loop over all triangle of element + h5_loc_idx_t triangle_idx = h5tpriv_ref_elem_get_num_facets(f->t); + while (--triangle_idx >= 0) { TRY( compute_sections_of_triangle ( f, - h5tpriv_build_edge_id ( i, elem_idx ), - children) ); + h5tpriv_build_edge_id (triangle_idx, elem_idx), + &children) ); } TRY( h5priv_alloc_idlist (f, list, 8) ); - h5_loc_id_t* did = children->items; - for (i = 0; i < children->num_items; i++, did++) { - TRY( h5priv_search_idlist (f, list, *did) ); - } + h5_loc_id_t* triangle_idp = children->items; + h5_loc_id_t* end = triangle_idp + children->num_items; + do { + TRY( add_triangle (f, list, *triangle_idp) ); + } while (++triangle_idp < end); TRY( h5priv_free_idlist (f, &children) ); return H5_SUCCESS; } diff --git a/src/h5core/h5t_adjacencies_trim.c b/src/h5core/h5t_adjacencies_trim.c index 627828e..276ca7b 100644 --- a/src/h5core/h5t_adjacencies_trim.c +++ b/src/h5core/h5t_adjacencies_trim.c @@ -43,10 +43,10 @@ release_tv ( h5t_adjacencies_t* adj = &t->adjacencies; if (adj->tv.v == NULL) return H5_SUCCESS; - h5_loc_idx_t idx = 0; + h5_loc_idx_t vertex_idx = 0; h5_loc_idx_t last = t->num_vertices[t->num_leaf_levels-1]; - for (; idx < last; idx++) { - TRY( h5priv_free_idlist (f, &adj->tv.v[idx]) ); + for (; vertex_idx < last; vertex_idx++) { + TRY( h5priv_free_idlist (f, &adj->tv.v[vertex_idx]) ); } TRY( h5_free (f, adj->tv.v) ); adj->tv.v = NULL; @@ -66,19 +66,13 @@ compute_elems_of_vertices ( /* loop over all elements in current level */ h5t_fdata_t *t = f->t; - h5_loc_idx_t idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; - h5_loc_idx_t last = t->num_elems[t->num_leaf_levels-1]; - h5_loc_triangle_t *el = &t->loc_elems.tris[idx]; - for (;idx < last; idx++, el++) { + h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; + h5_loc_idx_t last = (t->num_leaf_levels < 0) ? 0 : t->num_elems[t->num_leaf_levels-1]; + for (;elem_idx < last; elem_idx++) { int face_idx; int num_faces = h5tpriv_ref_elem_get_num_vertices (t); for (face_idx = 0; face_idx < num_faces; face_idx++) { - h5_loc_idx_t vidx = el->vertex_indices[face_idx]; - TRY( h5priv_insert_idlist ( - f, - &t->adjacencies.tv.v[vidx], - h5tpriv_build_vertex_id (face_idx, idx), - -1) ); + TRY( h5tpriv_search_tv2 (f, face_idx, elem_idx, NULL) ); } } return H5_SUCCESS; @@ -92,60 +86,51 @@ compute_elems_of_edges ( h5_file_t* const f, const h5t_lvl_idx_t from_lvl ) { - h5_debug (f, "%s (%lld)", __func__, (long long)from_lvl); h5t_fdata_t *t = f->t; h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - h5_idlist_t *retval = NULL; TRY( h5tpriv_resize_te_htab (f, 4*(num_elems-elem_idx)) ); for (;elem_idx < num_elems; elem_idx++) { h5_loc_idx_t face_idx; h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (t); for (face_idx = 0; face_idx < num_faces; face_idx++) { - TRY ( h5tpriv_search_te2 ( - f, face_idx, elem_idx, &retval ) ); + TRY ( h5tpriv_search_te2 (f, face_idx, elem_idx, NULL ) ); } } - h5_debug (f, "%s (): done", __func__); return H5_SUCCESS; } +/* + Compute the children o an edge + */ static inline h5_err_t compute_children_of_edge ( - h5_file_t * const f, - h5_loc_id_t kid, - h5_idlist_t *children + h5_file_t* const f, + h5_loc_id_t entity_id, + h5_idlist_t** children ) { - h5t_fdata_t *t = f->t; - h5_idlist_t *te; - - TRY ( h5tpriv_find_te2 ( - f, - h5tpriv_get_face_idx ( kid ), - h5tpriv_get_elem_idx ( kid ), - &te ) - ); - h5_loc_id_t *edge = te->items; - h5_loc_id_t *end = te->items+te->num_items; - for ( ; edge < end; edge++ ) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx ( *edge ); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx ( *edge ); - h5_generic_loc_elem_t *el = (h5_generic_loc_elem_t*)&t->loc_elems.tris[elem_idx]; - if ( h5tpriv_is_leaf_elem ( f, el ) == H5_OK ) { - TRY( h5priv_insert_idlist (f, &children, *edge, -1) ); + h5_idlist_t* te; + TRY( h5tpriv_find_te (f, entity_id, &te ) ); + h5_loc_id_t* edge_idp = te->items; + h5_loc_id_t* end = te->items + te->num_items; + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); + h5_loc_triangle_t *elem = &f->t->loc_elems.tris[elem_idx]; + if (h5tpriv_is_leaf_elem (f, elem)) { + TRY( h5priv_insert_idlist (f, children, *edge_idp, -1) ); } else { - h5_loc_id_t kids[2]; - TRY ( h5tpriv_get_direct_children_of_edge ( + h5_loc_id_t edge_ids[2]; + TRY( h5tpriv_get_direct_children_of_edge ( f, face_idx, - el->child_idx, - kids ) ); - TRY ( compute_children_of_edge ( - f, kids[0], children ) ); - TRY ( compute_children_of_edge ( - f, kids[1], children ) ); + elem->child_idx, + edge_ids ) ); + TRY( compute_children_of_edge (f, edge_ids[0], children) ); + TRY( compute_children_of_edge (f, edge_ids[1], children) ); } - } + } while (++edge_idp < end); + return H5_SUCCESS; } @@ -155,192 +140,220 @@ compute_children_of_edge ( static inline h5_err_t compute_sections_of_edge ( h5_file_t * const f, - h5_loc_id_t kid, - h5_idlist_t *children + h5_loc_id_t entity_id, + h5_idlist_t** children ) { - h5t_fdata_t *t = f->t; - h5_idlist_t *te; - - TRY ( h5tpriv_find_te2 ( - f, - h5tpriv_get_face_idx ( kid ), - h5tpriv_get_elem_idx ( kid ), - &te ) - ); - h5_loc_id_t *edge = te->items; + h5_idlist_t* te; + TRY( h5tpriv_find_te (f, entity_id, &te) ); + h5_loc_id_t* edge_idp = te->items; h5_loc_id_t *end = te->items+te->num_items; int refined = 0; - for ( ; edge < end; edge++ ) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx ( *edge ); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx ( *edge ); - h5_generic_loc_elem_t *el = (h5_generic_loc_elem_t*)&t->loc_elems.tris[elem_idx]; - if ( ! h5tpriv_is_leaf_elem ( f, el ) == H5_OK ) { + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx ( *edge_idp ); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx ( *edge_idp ); + h5_loc_triangle_t* elem = &f->t->loc_elems.tris[elem_idx]; + if (!h5tpriv_is_leaf_elem (f, elem)) { refined = 1; - h5_loc_id_t kids[2]; - TRY ( h5tpriv_get_direct_children_of_edge ( + h5_loc_id_t edge_ids[2]; + TRY( h5tpriv_get_direct_children_of_edge ( f, face_idx, - el->child_idx, - kids ) ); - TRY ( compute_sections_of_edge ( - f, kids[0], children ) ); - TRY ( compute_sections_of_edge ( - f, kids[1], children ) ); + elem->child_idx, + edge_ids) ); + TRY( compute_sections_of_edge (f, edge_ids[0], children) ); + TRY( compute_sections_of_edge (f, edge_ids[1], children) ); } - } - if ( ! refined ) { - TRY( h5priv_insert_idlist (f, &children, te->items[0], -1) ); + } while (++edge_idp < end); + if (!refined) { + TRY( h5priv_insert_idlist (f, children, te->items[0], -1) ); } return H5_SUCCESS; } +/* + Add unique ID of vertex given by face and element index to list. +*/ +static inline h5_err_t +add_vertex2 ( + h5_file_t* const f, // in + h5_idlist_t** list, // out + h5_loc_idx_t face_idx, // in + h5_loc_idx_t elem_idx // in + ) { + h5_idlist_t* tv; + TRY( h5tpriv_find_tv2 (f, face_idx, elem_idx, &tv) ); + TRY( h5priv_search_idlist (f, list, tv->items[0]) ); + return H5_SUCCESS; +} /* - map edge ID to unique ID - if unique ID not in list: add + Add unique ID of edge given by ID or face and element index. */ static inline h5_err_t add_edge ( - h5_file_t * const f, - h5_idlist_t *list, + h5_file_t* const f, // in + h5_idlist_t** list, // out + h5_loc_id_t entity_id // in + ) { + h5_idlist_t* te; + TRY( h5tpriv_find_te (f, entity_id, &te) ); + TRY( h5priv_search_idlist (f, list, te->items[0]) ); + return H5_SUCCESS; +} + +static inline h5_err_t +add_edge2 ( + h5_file_t* const f, + h5_idlist_t** list, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx ) { h5_idlist_t *te; - TRY ( h5tpriv_find_te2 ( f, face_idx, elem_idx, &te ) ); - TRY ( h5priv_search_idlist ( f, &list, te->items[0] ) ); + TRY( h5tpriv_find_te2 (f, face_idx, elem_idx, &te) ); + TRY( h5priv_search_idlist (f, list, te->items[0]) ); return H5_SUCCESS; } +static inline h5_err_t +add_elem2 ( + h5_file_t* const f, // in + h5_idlist_t** list, // out + h5_loc_idx_t elem_idx // in + ) { + h5_loc_id_t elem_id = h5tpriv_build_triangle_id (0, elem_idx); + TRY( h5priv_search_idlist (f, list, elem_id) ); + return H5_SUCCESS; +} + +/* + Get upward adjacent edges to vertex given by ID +*/ static inline h5_err_t get_edges_uadj_to_vertex ( - h5_file_t * const f, + h5_file_t* const f, const h5_loc_id_t entity_id, - h5_idlist_t **list + h5_idlist_t** list ) { - TRY ( h5priv_alloc_idlist ( f, list, 8 ) ); - - h5t_fdata_t* t = f->t; - h5_loc_idx_t idx; - TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &idx) ); - h5_idlist_t* tv = t->adjacencies.tv.v[idx]; + h5_loc_idx_t vertex_idx; + TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); + h5_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; - h5_size_t i; + TRY( h5priv_alloc_idlist (f, list, 8) ); h5_loc_id_t* vertex_idp = tv->items; - for ( i = 0; i < tv->num_items; i++, vertex_idp++ ) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx ( *vertex_idp ); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx ( *vertex_idp ); - h5_generic_loc_elem_t* el = (h5_generic_loc_elem_t*)&t->loc_elems.tris[elem_idx]; + h5_loc_id_t* end = vertex_idp + tv->num_items; + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*vertex_idp); + h5_loc_triangle_t* elem= &f->t->loc_elems.tris[elem_idx]; - if ( h5tpriv_is_leaf_elem ( f, el ) == H5_NOK ) { + if (!h5tpriv_is_leaf_elem (f, elem)) { continue; } - h5_loc_idx_t edge_idx; - edge_idx = h5tpriv_get_edge_connected_to_vertex (t->ref_elem, face_idx, 0); - TRY ( add_edge ( f, *list, edge_idx, elem_idx ) ); - edge_idx = h5tpriv_get_edge_connected_to_vertex (t->ref_elem, face_idx, 1); - TRY ( add_edge ( f, *list, edge_idx, elem_idx ) ); - } + TRY( add_edge2 (f, list, + h5tpriv_ref_elem_get_edge_idx ( + f->t, 0, face_idx, 0), + elem_idx) ); + TRY( add_edge2 (f, list, + h5tpriv_ref_elem_get_edge_idx ( + f->t, 0, face_idx, 1), + elem_idx) ); + } while (++vertex_idp < end); return H5_SUCCESS; } static inline h5_err_t get_triangles_uadj_to_vertex ( - h5_file_t * const f, + h5_file_t* const f, const h5_loc_id_t entity_id, - h5_idlist_t **list + h5_idlist_t** list ) { + h5_loc_idx_t vertex_idx; + TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); + h5_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; + TRY ( h5priv_alloc_idlist ( f, list, 8 ) ); - - h5t_fdata_t *t = f->t; - h5_loc_idx_t idx; - TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &idx) ); - h5_idlist_t* tv = t->adjacencies.tv.v[idx]; - - h5_size_t i; h5_loc_id_t *vertex_idp = tv->items; - for ( i = 0; i < tv->num_items; i++, vertex_idp++ ) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx ( *vertex_idp ); - h5_generic_loc_elem_t* el = (h5_generic_loc_elem_t*)&t->loc_elems.tris[elem_idx]; + h5_loc_id_t* end = vertex_idp + tv->num_items; + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); + h5_loc_triangle_t* elem = &f->t->loc_elems.tris[elem_idx]; - if ( h5tpriv_is_leaf_elem ( f, el ) == H5_NOK ) { + if (!h5tpriv_is_leaf_elem (f, elem)) { continue; } - TRY( h5priv_search_idlist (f, list, - h5tpriv_build_entity_id ( - H5T_TYPE_TRIANGLE, 0, elem_idx)) ); - } + TRY( add_elem2 (f, list, elem_idx) ); + } while (++vertex_idp < end); return H5_SUCCESS; } static inline h5_err_t get_triangles_uadj_to_edge ( - h5_file_t * const f, + h5_file_t* const f, const h5_loc_id_t entity_id, - h5_idlist_t **list + h5_idlist_t** list ) { - h5_idlist_t *children; - TRY ( h5priv_alloc_idlist ( f, &children, 8 ) ); - TRY ( compute_children_of_edge ( f, entity_id, children ) ); - TRY ( h5priv_alloc_idlist ( f, list, 8 ) ); - h5_loc_id_t *edge_id = children->items; + h5_idlist_t* children; + TRY( h5priv_alloc_idlist (f, &children, 8) ); + TRY( compute_children_of_edge (f, entity_id, &children) ); + TRY( h5priv_alloc_idlist (f, list, 8) ); + h5_loc_id_t *edge_idp = children->items; h5_loc_id_t *end = children->items+children->num_items; - for ( ; edge_id < end; edge_id++ ) { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx ( *edge_id ); - TRY( h5priv_search_idlist (f, list, - h5tpriv_build_entity_id( - H5T_TYPE_TRIANGLE, 0, elem_idx)) ); - } - TRY ( h5priv_free_idlist( f, &children ) ); + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); + TRY( add_elem2 (f, list, elem_idx) ); + } while (++edge_idp < end); + TRY( h5priv_free_idlist (f, &children) ); return H5_SUCCESS; } static inline h5_err_t get_edges_adj_to_edge ( - h5_file_t * const f, + h5_file_t* const f, const h5_loc_id_t entity_id, - h5_idlist_t **list + h5_idlist_t** list ) { TRY( h5priv_alloc_idlist (f, list, 8) ); - h5_idlist_t *children; + h5_idlist_t* children; TRY( h5priv_alloc_idlist (f, &children, 8) ); - TRY( compute_sections_of_edge ( f, entity_id, children ) ); + TRY( compute_sections_of_edge (f, entity_id, &children) ); TRY( h5priv_alloc_idlist (f, list, 8) ); - h5_loc_id_t* edge_id = children->items; + h5_loc_id_t* edge_idp = children->items; h5_loc_id_t* end = children->items+children->num_items; - h5_idlist_t* te; - for (; edge_id < end; edge_id++) { - h5_loc_idx_t face_idx = h5tpriv_get_face_idx(*edge_id); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx(*edge_id); - TRY( h5tpriv_find_te2 (f, face_idx, elem_idx, &te) ); - TRY( h5priv_search_idlist (f, list, te->items[0]) ); - } - + do { + TRY( add_edge (f, list, *edge_idp) ); + } while (++edge_idp < end); TRY( h5priv_free_idlist(f, &children) ); return H5_SUCCESS; } static inline h5_err_t get_vertices_dadj_to_edge ( - h5_file_t * const f, + h5_file_t* const f, const h5_loc_id_t entity_id, - h5_idlist_t **list + h5_idlist_t** list ) { - h5_idlist_t *children; - TRY ( h5priv_alloc_idlist ( f, &children, 8 ) ); - TRY( compute_sections_of_edge ( f, entity_id, children ) ); - TRY ( h5priv_alloc_idlist ( f, list, 8 ) ); - int i; - h5_loc_id_t *edge_id = children->items; - for ( i = 0; i < children->num_items; i++, edge_id++ ) { - h5_loc_idx_t vertex_indices[2]; - TRY ( h5t_get_vertex_indices_of_edge ( f, *edge_id, vertex_indices ) ); - TRY ( h5priv_search_idlist ( f, list, vertex_indices[0] ) ); - TRY ( h5priv_search_idlist ( f, list, vertex_indices[1] ) ); - } - TRY ( h5priv_free_idlist( f, &children ) ); + h5_idlist_t* children; + TRY( h5priv_alloc_idlist (f, &children, 8) ); + TRY( compute_sections_of_edge (f, entity_id, &children) ); + TRY( h5priv_alloc_idlist (f, list, 8) ); + h5_loc_id_t* edge_idp = children->items; + h5_loc_id_t* end = edge_idp + children->num_items; + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); + + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, face_idx, 0), + elem_idx) ); + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, face_idx, 1), + elem_idx) ); + } while (++edge_idp < end); + TRY( h5priv_free_idlist (f, &children) ); return H5_SUCCESS; } @@ -364,17 +377,24 @@ get_vertices_dadj_to_triangle ( TRY( compute_sections_of_edge ( f, h5tpriv_build_edge_id (face_idx, elem_idx), - children) ); + &children) ); } TRY ( h5priv_alloc_idlist (f, list, 8) ); h5_loc_id_t *edge_idp = children->items; - int i; - for ( i = 0; i < children->num_items; i++, edge_idp++ ) { - h5_loc_idx_t vertex_indices[2]; - TRY ( h5t_get_vertex_indices_of_edge ( f, *edge_idp, vertex_indices ) ); - TRY ( h5priv_search_idlist ( f, list, vertex_indices[0] ) ); - TRY ( h5priv_search_idlist ( f, list, vertex_indices[1] ) ); - } + h5_loc_id_t *end = edge_idp + children->num_items; + do { + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); + + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, face_idx, 0), + elem_idx) ); + TRY( add_vertex2 (f, list, + h5tpriv_ref_elem_get_vertex_idx ( + f->t, 1, face_idx, 1), + elem_idx) ); + } while (++edge_idp < end); TRY ( h5priv_free_idlist(f, &children) ); return H5_SUCCESS; } @@ -387,23 +407,21 @@ get_edges_dadj_to_triangle ( ) { h5_idlist_t* children; TRY ( h5priv_alloc_idlist (f, &children, 8) ); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); // loop over all edges of triangle - h5_loc_idx_t face_idx; - h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (f->t); - for ( face_idx = 0; face_idx < num_faces; face_idx++ ) { + h5_loc_idx_t edge_idx = h5tpriv_ref_elem_get_num_edges (f->t); + while (--edge_idx >= 0) { TRY( compute_sections_of_edge ( f, - h5tpriv_build_edge_id (face_idx, elem_idx), - children) ); + h5tpriv_build_edge_id (edge_idx, elem_idx), + &children) ); } TRY ( h5priv_alloc_idlist (f, list, 8) ); - h5_loc_id_t *edge_idp = children->items; - int i; - for (i = 0; i < children->num_items; i++, edge_idp++) { - TRY ( h5priv_search_idlist (f, list, *edge_idp) ); - } + h5_loc_id_t* edge_idp = children->items; + h5_loc_id_t* end = edge_idp + children->num_items; + do { + TRY( add_edge (f, list, *edge_idp) ); + } while (++edge_idp < end); TRY ( h5priv_free_idlist(f, &children) ); return H5_SUCCESS; } diff --git a/src/h5core/h5t_core_private.h b/src/h5core/h5t_core_private.h index 617835b..de2f813 100644 --- a/src/h5core/h5t_core_private.h +++ b/src/h5core/h5t_core_private.h @@ -88,6 +88,8 @@ #define h5tpriv_build_triangle_id( face_idx, elem_idx ) \ ( h5tpriv_build_entity_id ( H5T_TYPE_TRIANGLE, face_idx, elem_idx ) ) +#define h5tpriv_build_tet_id( face_idx, elem_idx ) \ + ( h5tpriv_build_entity_id ( H5T_TYPE_TET, face_idx, elem_idx ) ) #define h5tpriv_get_face_idx( entity_id ) \ diff --git a/src/h5core/h5t_hsearch.c b/src/h5core/h5t_hsearch.c index 3696232..ea435cb 100644 --- a/src/h5core/h5t_hsearch.c +++ b/src/h5core/h5t_hsearch.c @@ -3,6 +3,32 @@ #include "h5core/h5_core.h" #include "h5_core_private.h" + +h5_err_t +h5tpriv_search_tv2 ( + h5_file_t* const f, + h5_loc_idx_t face_idx, + h5_loc_idx_t elem_idx, + h5_idlist_t** idlist + ) { + H5_CORE_API_ENTER; + h5_err_t ret_value = H5_SUCCESS; + h5t_fdata_t* t = f->t; + + h5_loc_idx_t vertex_idx; + TRY2( ret_value = h5t_get_vertex_index_of_vertex2 ( + f, + face_idx, elem_idx, + &vertex_idx) ); + + TRY2( ret_value = h5priv_search_idlist ( + f, + &t->adjacencies.tv.v[vertex_idx], + h5tpriv_build_vertex_id (face_idx, elem_idx)) ); + + H5_CORE_API_RETURN (ret_value); +} + static int cmp_te_entries ( const void* __a, @@ -18,14 +44,15 @@ compute_te_hashval ( const void* __item ) { h5t_te_entry_t* item = (h5t_te_entry_t*)__item; - char* key = (char*)item->key.vids; - unsigned int count = 2 * sizeof (item->key.vids[0]); + uint16_t* key = (uint16_t*)item->key.vids; + unsigned int count = 2*sizeof (item->key.vids[0]) / sizeof (uint16_t); unsigned int hval = count; - while (count-- > 0) { - if (key[count]) { - hval <<= 4; - hval += key[count]; + while (count--) { + if (*key) { + hval <<= 6; + hval += *key; } + key++; } return hval; } @@ -123,8 +150,8 @@ h5tpriv_search_te2 ( Passing item with type entry type. */ -h5_err_t -h5tpriv_find_te ( +static inline h5_err_t +find_te ( h5_file_t* const f, h5t_te_entry_t* item, // in: item to find h5_idlist_t** idlist // out: @@ -151,6 +178,20 @@ h5tpriv_find_te ( Passing item with face and local element ID. */ +h5_err_t +h5tpriv_find_te ( + h5_file_t* const f, + h5_loc_idx_t edge_id, // in + h5_idlist_t** idlist // out + ) { + h5t_te_entry_t item; + TRY( h5t_get_vertex_indices_of_edge ( + f, + edge_id, + item.key.vids) ); + return find_te (f, &item, idlist); +} + h5_err_t h5tpriv_find_te2 ( h5_file_t* const f, @@ -164,7 +205,7 @@ h5tpriv_find_te2 ( face_idx, elem_idx, item.key.vids) ); - return h5tpriv_find_te (f, &item, idlist); + return find_te (f, &item, idlist); } static int @@ -177,12 +218,13 @@ cmp_td_entries ( return memcmp (a->key.vids, b->key.vids, sizeof(a->key.vids)); } +#if 0 static unsigned int compute_td_hashval ( const void* __item ) { h5t_te_entry_t* item = (h5t_te_entry_t*)__item; - char* key = (char*)item->key.vids; + unsigned char* key = (unsigned char*)item->key.vids; unsigned int count = sizeof (h5_3id_t); unsigned int hval = count; while (count-- > 0) { @@ -193,6 +235,25 @@ compute_td_hashval ( } return hval; } +#endif + +static unsigned int +compute_td_hashval ( + const void* __item + ) { + h5t_td_entry_t* item = (h5t_td_entry_t*)__item; + uint16_t* key = (uint16_t*)item->key.vids; + unsigned int count = 3 * sizeof (item->key.vids[0]) / sizeof (uint16_t); + unsigned int hval = count; + while (count--) { + if (*key) { + hval <<= 6; + hval += *key; + } + key++; + } + return hval; +} static h5_err_t release_td_entry ( @@ -276,8 +337,8 @@ h5tpriv_search_td2 ( return H5_SUCCESS; } -h5_err_t -h5tpriv_find_td ( +static inline h5_err_t +find_td ( h5_file_t* const f, h5t_td_entry_t* item, h5_idlist_t** idlist // out @@ -297,6 +358,20 @@ h5tpriv_find_td ( return H5_SUCCESS; } +h5_err_t +h5tpriv_find_td ( + h5_file_t* const f, + h5_loc_idx_t triangle_id, + h5_idlist_t** idlist + ) { + h5t_td_entry_t item; + TRY( h5t_get_vertex_indices_of_triangle ( + f, + triangle_id, + item.key.vids) ); + return find_td (f, &item, idlist); +} + h5_err_t h5tpriv_find_td2 ( h5_file_t* const f, @@ -310,7 +385,7 @@ h5tpriv_find_td2 ( face_idx, elem_idx, item.key.vids) ); - return h5tpriv_find_td (f, &item, idlist); + return find_td (f, &item, idlist); } /* diff --git a/src/h5core/h5t_hsearch_private.h b/src/h5core/h5t_hsearch_private.h index d9636c7..67aa8ce 100644 --- a/src/h5core/h5t_hsearch_private.h +++ b/src/h5core/h5t_hsearch_private.h @@ -9,28 +9,19 @@ typedef struct h5t_td_entry_key { h5_loc_idx_t vids[3]; } h5t_td_entry_key_t; -typedef struct h5t_idlisthash_key { - h5_loc_id_t ids[1]; -} h5t_idlisthash_key_t; - /* List of all upward adjacent elements of same coarsness of a specific face. The face is specified by its local vertex IDs. */ typedef struct h5_te_entry { - h5_idlist_t* value; h5t_te_entry_key_t key; + h5_idlist_t* value; } h5t_te_entry_t; typedef struct h5_td_entry { - h5_idlist_t* value; h5t_td_entry_key_t key; -} h5t_td_entry_t; - -typedef struct h5t_idlisthash_entry { h5_idlist_t* value; - h5t_idlisthash_key_t key; -} h5t_idlisthash_entry_t; +} h5t_td_entry_t; h5_err_t h5tpriv_resize_te_htab ( @@ -38,6 +29,14 @@ h5tpriv_resize_te_htab ( size_t nel ); +h5_err_t +h5tpriv_search_tv2 ( + h5_file_t * const f, + h5_loc_idx_t face_idx, + h5_loc_idx_t elem_idx, + h5_idlist_t **entry + ); + h5_err_t h5tpriv_search_te2 ( h5_file_t * const f, @@ -49,7 +48,7 @@ h5tpriv_search_te2 ( h5_err_t h5tpriv_find_te ( h5_file_t * const f, - h5t_te_entry_t *item, + h5_loc_idx_t edge_id, h5_idlist_t **retval ); @@ -78,7 +77,7 @@ h5tpriv_search_td2 ( h5_err_t h5tpriv_find_td ( h5_file_t * const f, - h5t_td_entry_t *item, + h5_loc_idx_t triangle_id, h5_idlist_t **retval ); diff --git a/src/h5core/h5t_map.c b/src/h5core/h5t_map.c index e3cbd6f..8f02612 100644 --- a/src/h5core/h5t_map.c +++ b/src/h5core/h5t_map.c @@ -176,7 +176,9 @@ h5tpriv_rebuild_elem_indices_mapping ( return H5_SUCCESS; } - +/* + Get local vertex indices of entity given by it's local ID. + */ h5_err_t h5t_get_vertex_indices_of_entity ( h5_file_t* const f, // in @@ -195,10 +197,13 @@ h5t_get_vertex_indices_of_entity ( h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); int dim = map_entity_type_to_dimension[entity_type]; - + assert (dim >= 0); return h5t_get_vertex_indices_of_entity2 (f, dim, face_idx, elem_idx, vertex_indices); } +/* + Get local vertex indices of entity given by it's face and local element index. + */ h5_err_t h5t_get_vertex_indices_of_entity2 ( h5_file_t* const f, // [in] @@ -212,7 +217,7 @@ h5t_get_vertex_indices_of_entity2 ( int num_vertices = ref_elem->num_vertices_of_face[dim][face_idx]; int i; for (i = 0; i < num_vertices; i++) { - int idx = ref_elem->map[dim][face_idx][i]; + int idx = h5tpriv_ref_elem_get_vertex_idx(f->t, dim, face_idx, i); vertex_indices[i] = indices[idx]; } return H5_SUCCESS; @@ -271,10 +276,12 @@ h5t_get_vertex_indices_of_edge2 ( h5_loc_idx_t* vertex_indices // OUT: vertex indices ) { const h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices (f, elem_idx); - const h5t_ref_elem_t* ref_elem = f->t->ref_elem; - vertex_indices[0] = indices[ ref_elem->map[1][face_idx][0] ]; - vertex_indices[1] = indices[ ref_elem->map[1][face_idx][1] ]; + h5_loc_idx_t idx; + idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 1, face_idx, 0); + vertex_indices[0] = indices[idx]; + idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 1, face_idx, 1); + vertex_indices[1] = indices[idx]; return H5_SUCCESS; } @@ -297,13 +304,15 @@ h5t_get_vertex_indices_of_triangle2 ( const h5_loc_idx_t elem_idx, h5_loc_idx_t* vertex_indices ) { - const h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices ( - f, elem_idx); - const h5t_ref_elem_t* ref_elem = f->t->ref_elem; + const h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices (f, elem_idx); - vertex_indices[0] = indices[ ref_elem->map[2][face_idx][0] ]; - vertex_indices[1] = indices[ ref_elem->map[2][face_idx][1] ]; - vertex_indices[2] = indices[ ref_elem->map[2][face_idx][2] ]; + h5_loc_idx_t idx; + idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 2, face_idx, 0); + vertex_indices[0] = indices[idx]; + idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 2, face_idx, 1); + vertex_indices[1] = indices[idx]; + idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 2, face_idx, 2); + vertex_indices[2] = indices[idx]; return H5_SUCCESS; } @@ -317,12 +326,16 @@ h5t_get_vertex_indices_of_tet ( const h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); const h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices ( f, elem_idx); - const h5t_ref_elem_t* ref_elem = f->t->ref_elem; - vertex_indices[0] = indices[ ref_elem->map[3][0][0] ]; - vertex_indices[1] = indices[ ref_elem->map[3][0][1] ]; - vertex_indices[2] = indices[ ref_elem->map[3][0][2] ]; - vertex_indices[3] = indices[ ref_elem->map[3][0][3] ]; + h5_loc_idx_t idx; + idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 3, 0, 0); + vertex_indices[0] = indices[idx]; + idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 3, 0, 1); + vertex_indices[1] = indices[idx]; + idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 3, 0, 2); + vertex_indices[2] = indices[idx]; + idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 3, 0, 3); + vertex_indices[3] = indices[idx]; return H5_SUCCESS; } diff --git a/src/h5core/h5t_readwrite_tetm.c b/src/h5core/h5t_readwrite_tetm.c index 061bc97..07e76cd 100644 --- a/src/h5core/h5t_readwrite_tetm.c +++ b/src/h5core/h5t_readwrite_tetm.c @@ -14,7 +14,7 @@ init_loc_elems_struct ( const h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; h5t_lvl_idx_t level_idx = 0; int num_vertices = h5tpriv_ref_elem_get_num_vertices (t); - int num_facets = h5tpriv_ref_elem_get_num_faces (t, 2); + int num_facets = h5tpriv_ref_elem_get_num_facets (t); h5_loc_tet_t* loc_elem = t->loc_elems.tets; h5_glb_tet_t* glb_elem = t->glb_elems.tets; @@ -69,7 +69,7 @@ init_geom_boundary_info ( h5t_fdata_t* const t = f->t; h5_loc_idx_t elem_idx = 0; const h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - int num_facets = h5tpriv_ref_elem_get_num_faces (t, 2); + int num_facets = h5tpriv_ref_elem_get_num_facets (t); h5_loc_tet_t* loc_elem = t->loc_elems.tets; h5_glb_tet_t* glb_elem = t->glb_elems.tets; @@ -86,52 +86,6 @@ init_geom_boundary_info ( if (i == num_facets) { continue; // no facet on boundary } - -#if 0 - // mark elements which are edge- or vertex- adjacent to the boundary - // are there more facets on the boundary? - int j; - for (j = i+1; j < num_facets; j++) { - if (loc_elem->neighbor_indices[j] == -1) { - break; // found another boundary facet - } - } - // get vertex ID's of vertices on boundary - h5_loc_idx_t vertex_indices[4]; - if (j < num_facets) { - // all vertices on boundary - vertex_indices[0] = h5tpriv_build_vertex_id (0, elem_idx); - vertex_indices[1] = h5tpriv_build_vertex_id (1, elem_idx); - vertex_indices[2] = h5tpriv_build_vertex_id (2, elem_idx); - vertex_indices[3] = h5tpriv_build_vertex_id (3, elem_idx); - num_vertices = 4; - } else { - // three vertices on boundary - // get vertices of edge i - h5_loc_idx_t face_idx; - face_idx = t->ref_elem->map[2][i][0]; - vertex_indices[0] = h5tpriv_get_loc_elem_vertex_idx ( - f, elem_idx, face_idx); - face_idx = t->ref_elem->map[2][i][1]; - vertex_indices[1] = h5tpriv_get_loc_elem_vertex_idx ( - f, elem_idx, face_idx); - face_idx = t->ref_elem->map[2][i][2]; - vertex_indices[2] = h5tpriv_get_loc_elem_vertex_idx ( - f, elem_idx, face_idx); - num_vertices = 3; - } - // mark elements - - for (i = 0; i < num_vertices; i++) { - const h5_loc_idx_t vertex_idx = vertex_indices[i]; - h5_idlist_t* list = &t->adjacencies.tv.v[vertex_idx]; - // set flag - for (j=0; j < list->num_items; j++) { - h5_loc_idx_t idx = h5tpriv_get_elem_idx (list->items[j]); - t->loc_elems.tris[idx].flags |= H5T_BOUNDARY_ELEM_FLAG; - } - } -#endif } return H5_SUCCESS; } diff --git a/src/h5core/h5t_readwrite_trim.c b/src/h5core/h5t_readwrite_trim.c index dd7ed18..cb45fe4 100644 --- a/src/h5core/h5t_readwrite_trim.c +++ b/src/h5core/h5t_readwrite_trim.c @@ -14,7 +14,7 @@ init_loc_elems_struct ( const h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; h5t_lvl_idx_t level_idx = 0; int num_vertices = h5tpriv_ref_elem_get_num_vertices (t); - int num_facets = h5tpriv_ref_elem_get_num_faces (t,1); + int num_facets = h5tpriv_ref_elem_get_num_facets (t); h5_loc_triangle_t* loc_elem = t->loc_elems.tris; h5_glb_triangle_t* glb_elem = t->glb_elems.tris; @@ -70,7 +70,7 @@ init_geom_boundary_info ( h5t_fdata_t* const t = f->t; h5_loc_idx_t elem_idx = 0; const h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - int num_facets = h5tpriv_ref_elem_get_num_faces (t, 1); + int num_facets = h5tpriv_ref_elem_get_num_facets (t); h5_loc_triangle_t* loc_elem = t->loc_elems.tris; h5_glb_triangle_t* glb_elem = t->glb_elems.tris; @@ -87,46 +87,6 @@ init_geom_boundary_info ( if (i == num_facets) { continue; // no facet on boundary } - -#if 0 - // mark elements which are edge- or vertex- adjacent to the boundary - // are there more facets on the boundary? - int j; - for (j = i+1; j < num_facets; j++) { - if (loc_elem->neighbor_indices[j] == -1) { - break; // found another boundary facet - } - } - // get vertex ID's of vertices on boundary - h5_loc_idx_t vertex_indices[4]; - if (j < num_facets) { - // all vertices on boundary - vertex_indices[0] = h5tpriv_get_loc_elem_vertex_idx (f, elem_idx, 0); - vertex_indices[1] = h5tpriv_get_loc_elem_vertex_idx (f, elem_idx, 1); - vertex_indices[2] = h5tpriv_get_loc_elem_vertex_idx (f, elem_idx, 2); - num_vertices = 3; - } else { - // two vertices on boundary - // get vertices of edge i - h5_loc_idx_t face_idx; - face_idx = t->ref_elem->map[1][i][0]; - vertex_indices[0] = h5tpriv_get_loc_elem_vertex_idx (f, elem_idx, face_idx); - face_idx = t->ref_elem->map[1][i][1]; - vertex_indices[1] = h5tpriv_get_loc_elem_vertex_idx (f, elem_idx, face_idx); - num_vertices = 2; - } - // mark elements - for (i = 0; i < num_vertices; i++) { - // get upward adjacent elements - const h5_loc_idx_t vertex_idx = vertex_indices[i]; - h5_idlist_t* list = &t->adjacencies.tv.v[vertex_idx]; - // set flag - for (j=0; j < list->num_items; j++) { - h5_loc_idx_t idx = h5tpriv_get_elem_idx (list->items[j]); - t->loc_elems.tris[idx].flags |= H5T_BOUNDARY_ELEM_FLAG; - } - } -#endif } return H5_SUCCESS; } diff --git a/src/h5core/h5t_ref_elements.c b/src/h5core/h5t_ref_elements.c index 63e4837..8bf1890 100644 --- a/src/h5core/h5t_ref_elements.c +++ b/src/h5core/h5t_ref_elements.c @@ -2,6 +2,40 @@ #include "h5_core_private.h" /* + information we can retrieve from the reference element: + - number of vertices per sub-entity (1) + - vertex indices of all sub-elements + - upward connectivity + - which co-dim 1 entities are connected to a given vertex + - which co-dim 2 entities are connected to a given vertex + - which co-dim 1 entities are connected to a given co-dim 2 entity + - downward connectivity + - vertex coordinates + +get_conn(face, dim, dim) -> list + +for dim 3 reference elements: +get_conn(0, 3, 0) -> 0, 1, 2, 3 (all vertices) +get_conn(0, 3, 1) -> 0, 1, 2, 3, 4, 5 (all edges) +get_conn(0, 3, 2) -> 0, 1, 2, 3 (all facets) +get_conn(0, 3, 3) -> 0 +get_conn(i, 2, 0) -> vertices of facet i +get_conn(i, 2, 1) -> edges of facet i +get_conn(i, 2, 2) -> facets connected to facet i +get_conn(i, 2, 3) -> 0 +get_conn(i, 1, 0) -> vertices of edge i +get_conn(i, 1, 1) -> edges connected to edge i +get_conn(i, 1, 2) -> facets connected to edge i +get_conn(i, 1, 3) -> 0 +get_conn(i, 0, 0) -> i +get_conn(i, 0, 1) -> edges connected to vertex i +get_conn(i, 0, 2) -> facets connected to vertex i +get_conn(i, 0, 3) -> 0 + +(1) For triangle and tetrahedral meshes the number of vertices is +identical for all sub-entities within the same dimension. This is not +true for other grids (like prismen) + face: All kinds of sub-elements: vertices, edges, triangles ... facet: co-dim 1 face @@ -46,20 +80,21 @@ const h5t_ref_elem_t h5t_tri_ref_elem = { [1] = {2, 2, 2}, // #vertices of edges [2] = {3} // #vertices of trinagles }, - { // map sub-elements to vertices - [0] = {{0}, {1}, {2}}, // 3 vertices - [1] = {{0,1}, {0,2}, {1,2}}, // 3 edges - [2] = {{0,1,2}} // 1 triangles - }, - { // edges connected to vertex - [0] = {0,1}, - [1] = {0,2}, - [2] = {1,2} - }, - { // triangles connected to vertex - [0] = {0}, - [1] = {0}, - [2] = {0} + { // connectivity + // vertices to vertices + [0][0] = {{0}, {1}, {2}}, + // vertices to edges + [0][1] = {{0,1}, {0,2}, {1,2}}, + // vertices to triangles + [0][2] = {{0}, {0}, {0}}, + // edges to vertices + [1][0] = {{0,1}, {0,2}, {1,2}}, + // edges to edges + [1][1] = {{0,1,2}, {0,1,2}, {0,1,2}}, + // edges to triangle + [1][2] = {{0}, {0}, {0}}, + // triangle to vertices + [2][0] = {{0,1,2}} }, { // coordinates {0.0, 0.0}, @@ -68,7 +103,6 @@ const h5t_ref_elem_t h5t_tri_ref_elem = { } }; - /* 3 ** @@ -111,23 +145,40 @@ const h5t_ref_elem_t h5t_tet_ref_elem = { [2] = {3,3,3,3}, // #vertices of trinagles [3] = {4} // #vertices of tets }, - { // map faces to vertices - [0] = {{0}, {1}, {2}, {3}}, // 4 vertices - [1] = {{0,1}, {0,2}, {1,2}, {0,3}, {1,3}, {2,3}}, // 6 edges - [2] = {{0,1,2}, {0,1,3}, {0,2,3}, {1,2,3}}, // 4 triangles - [3] = {{0,1,2,3}} // 1 tets - }, - { // edges connected to vertex - [0] = {0,1,3}, - [1] = {0,2,4}, - [2] = {1,2,5}, - [3] = {3,4,5} - }, - { // triangles connected to vertex - [0] = {0,1,2}, - [1] = {0,1,3}, - [2] = {0,2,3}, - [3] = {1,2,3} + { // connectivity + // vertex to vertices + [0][0] = {{0}, {1}, {2}, {3}}, + // vertex to edges + [0][1] = {{0,1,3}, {0,2,4}, {1,2,5}, {3,4,5}}, + // vertex to triangles + [0][2] = {{0,1,2}, {0,1,3}, {0,2,3}, {1,2,3}}, + // vertex to tetrahedron + [0][3] = {{0}, {0}, {0}, {0}}, + // edge to vertices + [1][0] = {{0,1}, {0,2}, {1,2}, {0,3}, {1,3}, {2,3}}, + // edge to edges + [1][1] = {{0,1,2,3,4}, {0,1,2,3,5}, {0,1,2,4,5}, + {0,1,3,4,5}, {0,2,3,4,5}, {1,2,3,4,5}}, + // edge to triangle + [1][2] = {{0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3}}, + // edge to tetrahedra + [1][3] = {{0}, {0}, {0}, {0}, {0}, {0}}, + // triangle to vertices + [2][0] = {{0,1,2}, {0,1,3}, {0,2,3}, {1,2,3}}, + // triangle to edges + [2][1] = {{0,1,2}, {0,3,4}, {1,3,5}, {2,4,5}}, + // triangle to triangle + [2][2] = {{0,1,2,3}, {0,1,2,3}, {0,1,2,3}, {0,1,2,3}}, + // tetrahedron to tetrahedron + [2][3] = {{0}}, + // tetrahedron to vertices + [3][0] = {{0,1,2,3}}, + // tetrahedron to edges + [3][1] = {{0,1,2,3,4,5}}, + // tetrahedron to triangles + [3][2] = {{0,1,2,3}}, + // tetrahedron to tetrahedron + [3][2] = {{0}} }, { // coordinates {0.0, 0.0, 0.0}, diff --git a/src/h5core/h5t_ref_elements_private.h b/src/h5core/h5t_ref_elements_private.h index c28b667..5eb00b7 100644 --- a/src/h5core/h5t_ref_elements_private.h +++ b/src/h5core/h5t_ref_elements_private.h @@ -2,22 +2,26 @@ #define __H5T_REF_ELEMENTS_PRIVATE_H #define h5tpriv_ref_elem_get_num_vertices(this) (this->ref_elem->num_faces[0]) + #define h5tpriv_ref_elem_get_num_edges(this) (this->ref_elem->num_faces[1]) -#define h5tpriv_ref_elem_get_num_facets(this) \ +#define h5tpriv_ref_elem_get_num_facets(this) \ (this->ref_elem->num_faces[this->ref_elem->dim - 1]) #define h5tpriv_ref_elem_get_num_faces(this, dim) (this->ref_elem->num_faces[dim]) #define h5tpriv_ref_elem_get_dim(this) (this->ref_elem->dim) -#define h5tpriv_get_edge_connected_to_vertex(this,face_idx, i) \ - (this->edges_connected_to_vertex[face_idx][i]) +#define h5tpriv_ref_elem_get_entity_type(this,dim) \ + (this->ref_elem->entity_types[dim]) -#define h5tpriv_get_triangles_connected_to_vertex(this,face_idx, i) \ - (this->triangles_connected_to_vertex[face_idx][i]) +#define h5tpriv_ref_elem_get_vertex_idx(this, dim, face_idx, i) \ + (this->ref_elem->connect[dim][0][face_idx][i]) -#define h5tpriv_ref_elem_get_entity_type(this,dim) \ - (this->entity_types[dim]) +#define h5tpriv_ref_elem_get_edge_idx(this, dim, face_idx, i) \ + (this->ref_elem->connect[dim][1][face_idx][i]) + +#define h5tpriv_ref_elem_get_triangle_idx(this, dim, face_idx, i) \ + (this->ref_elem->connect[dim][2][face_idx][i]) #endif diff --git a/src/h5core/h5t_retrieve.c b/src/h5core/h5t_retrieve.c index 8150fd7..0b488b0 100644 --- a/src/h5core/h5t_retrieve.c +++ b/src/h5core/h5t_retrieve.c @@ -15,10 +15,10 @@ iter_leaf_elem_idx ( do { iter->elem_idx++; if (iter->elem_idx >= f->t->num_elems[iter->leaf_level]) { - return H5_NOK; + return H5_NOK; // done } el = h5tpriv_get_loc_elem (f, iter->elem_idx); - } while (h5tpriv_elem_is_on_level (f, el, iter->leaf_level) == H5_NOK); + } while (!h5tpriv_is_leaf_elem (f, el)); return H5_SUCCESS; } @@ -32,8 +32,8 @@ iterate_leaf_elems ( h5_debug ( f, "Traversing done!" ); return H5_NOK; } - int dim = it->ref_elem->dim; - h5_loc_id_t type_id = it->ref_elem->entity_types[dim]; + int dim = h5tpriv_ref_elem_get_dim (it); + h5_loc_id_t type_id = h5tpriv_ref_elem_get_entity_type (it, dim); return h5tpriv_build_entity_id (type_id, 0, it->elem_idx ); } @@ -49,8 +49,8 @@ iterate_boundary_elems ( return H5_NOK; } } while (!h5tpriv_is_boundary_elem (f, it->elem_idx)); - int dim = it->ref_elem->dim; - h5_loc_id_t type_id = it->ref_elem->entity_types[dim]; + int dim = h5tpriv_ref_elem_get_dim (it); + h5_loc_id_t type_id = h5tpriv_ref_elem_get_entity_type (it, dim); return h5tpriv_build_entity_id (type_id, 0, it->elem_idx ); } @@ -80,7 +80,7 @@ iterate_boundary_facets ( it->face_idx++; } } while (! h5tpriv_is_boundary_facet (f, it->elem_idx, it->face_idx)); - int type = h5tpriv_ref_elem_get_entity_type (it->ref_elem, dim); + int type = h5tpriv_ref_elem_get_entity_type (it, dim); return h5tpriv_build_entity_id (type, it->face_idx, it->elem_idx ); } @@ -120,7 +120,7 @@ iterate_leaf_faces ( i++; h5_loc_idx_t idx = h5tpriv_get_elem_idx (entry->items[i]); el = h5tpriv_get_loc_elem (f, idx); - } while (h5tpriv_elem_is_on_level (f, el, it->leaf_level) == H5_NOK); + } while (!h5tpriv_is_leaf_elem (f, el)); // 3. Face already visited if } while (it->elem_idx > h5tpriv_get_elem_idx(entry->items[i])); @@ -130,7 +130,7 @@ iterate_leaf_faces ( current level and the element index of entry->items[i] is the smallest element index with the given face on the current level. */ - return entry->items[0]; + return entry->items[i]; } /* diff --git a/src/h5core/h5t_retrieve_private.h b/src/h5core/h5t_retrieve_private.h index a520d74..6267174 100644 --- a/src/h5core/h5t_retrieve_private.h +++ b/src/h5core/h5t_retrieve_private.h @@ -16,32 +16,9 @@ extern struct h5t_retrieve_methods h5tpriv_tetm_retrieve_methods; - the level_id of the element is <= the current level - and, if any, the direct children is on a level > the current level */ -static inline h5_err_t -h5tpriv_is_leaf_elem ( - h5_file_t* const f, - h5_generic_loc_elem_t *el // ptr to local element - ) { - h5t_fdata_t* t = f->t; - if ( (el->level_idx > t->leaf_level) || - (el->child_idx >= 0 && el->child_idx < f->t->num_elems[f->t->leaf_level]) ) { - return H5_NOK; - } - return H5_SUCCESS; -} - -static inline h5_err_t -h5tpriv_elem_is_on_level ( - h5_file_t* const f, - h5_generic_loc_elem_t *el, // ptr to local element - const h5t_lvl_idx_t level_idx - ) { - assert ( level_idx < f->t->num_leaf_levels ); - if ( (el->level_idx > level_idx) || - (el->child_idx >= 0 && el->child_idx < f->t->num_elems[level_idx]) ) { - return H5_NOK; - } - return H5_SUCCESS; -} +#define h5tpriv_is_leaf_elem(f, el) \ + ( (el->level_idx <= f->t->leaf_level) && \ + (el->child_idx < 0 || el->child_idx >= f->t->num_elems[f->t->leaf_level]) ) static inline h5_err_t h5tpriv_init_entity_iterator ( diff --git a/src/h5core/h5t_store_tetm.c b/src/h5core/h5t_store_tetm.c index 86fe0d8..ae21705 100644 --- a/src/h5core/h5t_store_tetm.c +++ b/src/h5core/h5t_store_tetm.c @@ -37,7 +37,12 @@ alloc_tets ( return H5_SUCCESS; } - +/* + Return the two direct children of the edge given by face and + element index of first child. + Note: the semantic of elem_idx is a bit confusing. + + */ static h5_err_t get_direct_children_of_edge ( h5_file_t* const f, diff --git a/src/include/h5core/h5t_ref_elements.h b/src/include/h5core/h5t_ref_elements.h index 5a7443a..74b7075 100644 --- a/src/include/h5core/h5t_ref_elements.h +++ b/src/include/h5core/h5t_ref_elements.h @@ -10,12 +10,11 @@ typedef struct { int entity_types[H5T_MAX_DIM+1]; int num_faces[H5T_MAX_DIM+1]; int num_vertices_of_face[H5T_MAX_DIM+1][H5T_MAX_FACES]; - int map[H5T_MAX_DIM+1][H5T_MAX_FACES][H5T_MAX_VERTICES]; - int edges_connected_to_vertex[H5T_MAX_VERTICES][H5T_MAX_FACES]; - int triangles_connected_to_vertex[H5T_MAX_VERTICES][H5T_MAX_FACES]; + int connect[H5T_MAX_DIM+1][H5T_MAX_DIM+1][H5T_MAX_FACES][H5T_MAX_FACES]; h5_float64_t coords[H5T_MAX_VERTICES][H5T_MAX_DIM]; } h5t_ref_elem_t; + extern const h5t_ref_elem_t h5t_tet_ref_elem; extern const h5t_ref_elem_t h5t_tri_ref_elem;