- iterators implemented/debugged

- traversal functions with iterators debugged for triangle meshes
This commit is contained in:
2010-05-12 19:51:57 +00:00
parent 1c41ca12ce
commit 538b0989eb
15 changed files with 222 additions and 604 deletions
-2
View File
@@ -46,7 +46,6 @@ include_HEADERS = \
../include/H5.h \
../include/H5Block.h \
../include/H5Fed.h \
../include/H5Fed_map.h \
../include/H5Fed_store.h \
../include/H5Fed_tags.h \
../include/H5Part.h
@@ -62,7 +61,6 @@ libH5_a_SOURCES = \
H5Fed.c \
H5Fed_adjacency.c \
H5Fed_inquiry.c \
H5Fed_map.c \
H5Fed_retrieve.c \
H5Fed_store.c \
H5Fed_tags.c \
+10
View File
@@ -42,6 +42,11 @@ EXTRA_HEADERS = \
h5t_storemesh_private.h \
h5t_tags_private.h \
h5t_tetm_adjacencies_private.h \
h5t_tetm_retrieve_private.h \
h5t_tetm_store_private.h \
h5t_trim_adjacencies_private.h \
h5t_trim_retrieve_private.h \
h5t_trim_store_private.h \
h5u_errorhandling_private.h
# Extra files that I wish to include in the dist tar ball.
@@ -87,6 +92,11 @@ libH5Core_a_SOURCES = \
h5t_storemesh.c \
h5t_tags.c \
h5t_tetm_adjacencies.c \
h5t_tetm_retrieve.c \
h5t_tetm_store.c \
h5t_trim_adjacencies.c \
h5t_trim_retrieve.c \
h5t_trim_store.c \
h5u_readwrite.c \
hdf5_misc.c
+5
View File
@@ -4,6 +4,11 @@
#define H5T_CONTAINER_GRPNAME "Topo"
#include "h5t_tetm_adjacencies_private.h"
#include "h5t_tetm_retrieve_private.h"
#include "h5t_tetm_store_private.h"
#include "h5t_trim_adjacencies_private.h"
#include "h5t_trim_retrieve_private.h"
#include "h5t_trim_store_private.h"
#include "h5t_consts_private.h"
#include "h5t_errorhandling_private.h"
#include "h5t_hsearch_private.h"
+7 -8
View File
@@ -1,5 +1,4 @@
#include <string.h>
#include <hdf5.h>
#include "h5core/h5_core.h"
#include "h5_core_private.h"
@@ -22,7 +21,7 @@ cmp_vertices (
h5_float64_t P1[3]
) {
int i;
for ( i = 2; i >= 0; i++ ) {
for ( i = 0; i < 3; i++ ) {
h5_int64_t diff = h5priv_fcmp ( P0[i], P1[i], 10 );
if ( diff < 0 ) return -1;
else if ( diff > 0 ) return 1;
@@ -424,7 +423,7 @@ h5t_get_vertex_indices_of_entity (
h5_id_t elem_idx = h5tpriv_get_elem_idx (entity_id);
int dim = map_entity_type_to_dimension[entity_type];
h5_elem_ldta_t *el = &f->t->elems_ldta[elem_idx];
h5t_ref_element_t* ref_element = f->t->ref_element;
const h5t_ref_element_t* ref_element = f->t->ref_element;
int num_vertices = ref_element->num_vertices_of_face[dim][face_idx];
int i;
for (i = 0; i < num_vertices; i++) {
@@ -453,10 +452,10 @@ h5t_get_vertex_index_of_vertex2 (
const h5_id_t elem_idx, // local element index
h5_id_t* vertex_indices // OUT: vertex ID's
) {
h5t_ref_element_t* ref_element = f->t->ref_element;
const h5t_ref_element_t* ref_element = f->t->ref_element;
h5_elem_ldta_t *el = &f->t->elems_ldta[elem_idx];
vertex_indices[0] = el->local_vids[ref_element->map[1][face_idx][0]];
vertex_indices[0] = el->local_vids[ref_element->map[0][face_idx][0]];
return H5_SUCCESS;
}
@@ -489,7 +488,7 @@ h5t_get_vertex_indices_of_edge2 (
const h5_id_t elem_idx, // local element index
h5_id_t *vertex_indices // OUT: vertex ID's
) {
h5t_ref_element_t* ref_element = f->t->ref_element;
const h5t_ref_element_t* ref_element = f->t->ref_element;
h5_elem_ldta_t *el = &f->t->elems_ldta[elem_idx];
vertex_indices[0] = el->local_vids[ref_element->map[1][face_idx][0]];
@@ -516,7 +515,7 @@ h5t_get_vertex_indices_of_triangle2 (
const h5_id_t elem_idx,
h5_id_t *vertex_indices
) {
h5t_ref_element_t* ref_element = f->t->ref_element;
const h5t_ref_element_t* ref_element = f->t->ref_element;
h5_elem_ldta_t *el = &f->t->elems_ldta[elem_idx];
vertex_indices[0] = el->local_vids[ref_element->map[2][face_idx][0]];
@@ -533,7 +532,7 @@ h5t_get_vertex_indices_of_tet (
h5_id_t *vertex_indices
) {
h5_id_t elem_idx = h5tpriv_get_elem_idx (entity_id);
h5t_ref_element_t* ref_element = f->t->ref_element;
const h5t_ref_element_t* ref_element = f->t->ref_element;
h5_elem_ldta_t *el = &f->t->elems_ldta[elem_idx];
vertex_indices[0] = el->local_vids[ref_element->map[3][0][0]];
+13 -115
View File
@@ -11,16 +11,15 @@
#include "h5_core_private.h"
static struct h5t_methods tet_funcs = {
h5tpriv_alloc_tets,
h5tpriv_store_tet,
h5tpriv_refine_tet,
&h5tpriv_tetm_store_methods,
&h5tpriv_tetm_retrieve_methods,
&h5tpriv_tetm_adjacency_methods
};
static struct h5t_methods tri_funcs = {
h5tpriv_alloc_tris,
h5tpriv_store_tri,
h5tpriv_refine_tri
&h5tpriv_trim_store_methods,
&h5tpriv_trim_retrieve_methods,
&h5tpriv_trim_adjacency_methods
};
/*
@@ -473,10 +472,12 @@ h5t_open_mesh (
case H5_OID_TETRAHEDRON:
t->dsinfo_elems.type_id = t->dtypes.h5_tet_t;
t->methods = tet_funcs;
t->ref_element = &h5t_tet_ref_element;
break;
case H5_OID_TRIANGLE:
t->dsinfo_elems.type_id = t->dtypes.h5_triangle_t;
t->methods = tri_funcs;
t->ref_element = &h5t_tri_ref_element;
break;
default:
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
@@ -530,10 +531,12 @@ static h5_err_t
_release_memory (
h5_file_t* const f
) {
TRY ( h5tpriv_release_tags (f) );
TRY ( (*f->t->methods.adjacency->release_internal_structs) (f) );
TRY ( _release_elems (f) );
TRY ( _release_vertices (f) );
TRY( h5tpriv_release_tags (f) );
if (f->t->methods.adjacency != NULL) {
TRY( (*f->t->methods.adjacency->release_internal_structs) (f) );
}
TRY( _release_elems (f) );
TRY( _release_vertices (f) );
return H5_SUCCESS;
}
@@ -588,108 +591,3 @@ h5tpriv_alloc_num_vertices (
return H5_SUCCESS;
}
h5_err_t
h5tpriv_alloc_tris (
h5_file_t * const f,
const size_t cur,
const size_t new
) {
h5t_fdata_t *t = f->t;
const size_t nvertices = 3;
/* alloc mem for elements */
TRY ( t->elems.tris = h5priv_alloc (
f,
t->elems.tris,
new * sizeof(t->elems.tris[0]) ) );
memset (
t->elems.tris + cur,
-1,
(new-cur) * sizeof(t->elems.tris[0]) );
/* alloc mem for local data of elements */
TRY ( t->elems_ldta = h5priv_alloc (
f,
t->elems_ldta,
new * sizeof (t->elems_ldta[0]) ) );
memset (
t->elems_ldta + cur,
-1,
(new-cur) * sizeof (t->elems_ldta[0]) );
/* alloc mem for local vertex IDs of elements */
TRY ( t->elems_lvids = h5priv_alloc (
f,
t->elems_lvids,
new * sizeof(t->elems_lvids[0]) * nvertices ) );
memset (
t->elems_lvids + cur * sizeof(t->elems_lvids[0]) * nvertices,
-1,
(new-cur) * sizeof(t->elems_lvids[0]) * nvertices );
/* re-init pointer to local vertex id in local data structure */
h5_id_t *p = t->elems_lvids;
h5_id_t id;
for ( id = 0; id < new; id++, p+=nvertices ) {
t->elems_ldta[id].local_vids = p;
}
/* alloc mem for global to local ID mapping */
TRY ( h5priv_alloc_idmap ( f, &t->map_elem_g2l, new ) );
return H5_SUCCESS;
}
h5_err_t
h5tpriv_alloc_tets (
h5_file_t * const f,
const size_t cur,
const size_t new
) {
h5t_fdata_t *t = f->t;
const size_t nvertices = 4;
/* alloc mem for elements */
TRY ( t->elems.tets = h5priv_alloc (
f,
t->elems.tets,
new * sizeof(t->elems.tets[0]) ) );
memset (
t->elems.tets + cur,
-1,
(new-cur) * sizeof(t->elems.tets[0]) );
/* alloc mem for local data of elements */
TRY ( t->elems_ldta = h5priv_alloc (
f,
t->elems_ldta,
new * sizeof (t->elems_ldta[0]) ) );
memset (
t->elems_ldta + cur,
-1,
(new-cur) * sizeof (t->elems_ldta[0]) );
/* alloc mem for local vertex IDs of elements */
TRY ( t->elems_lvids = h5priv_alloc (
f,
t->elems_lvids,
new * sizeof(t->elems_lvids[0]) * nvertices ) );
memset (
t->elems_lvids + cur * nvertices,
-1,
(new-cur) * sizeof(t->elems_lvids[0]) * nvertices );
/* re-init pointer to local vertex id in local data structure */
h5_id_t *p = t->elems_lvids;
h5_id_t id;
for ( id = 0; id < new; id++, p+=nvertices ) {
t->elems_ldta[id].local_vids = p;
}
/* alloc mem for global to local ID mapping */
TRY ( h5priv_alloc_idmap ( f, &t->map_elem_g2l, new ) );
return H5_SUCCESS;
}
+1 -1
View File
@@ -296,7 +296,7 @@ _read_elems (
) {
h5t_fdata_t *t = f->t;
TRY( (*t->methods._alloc_elems)( f, 0, t->num_elems[t->num_levels-1] ) );
TRY( (*t->methods.store->alloc_elems)( f, 0, t->num_elems[t->num_levels-1] ) );
TRY( h5priv_read_dataset_by_name (
f,
t->mesh_gid,
+38 -59
View File
@@ -8,7 +8,7 @@
Skip elements which have been refined on a level <= the current one.
*/
h5_err_t
skip_to_next_elem_on_level (
h5tpriv_skip_to_next_elem_on_level (
h5_file_t* f,
h5t_entity_iterator_t* iter
) {
@@ -44,11 +44,39 @@ h5tpriv_elem_is_on_cur_level (
return H5_SUCCESS;
}
h5_err_t
h5t_alloc_entity_iterator (
h5_file_t* f,
h5t_entity_iterator_t** iter,
int codim
) {
TRY( *iter = h5priv_alloc (f, NULL, sizeof (h5t_entity_iterator_t)) );
return h5t_begin_iterate_entities (f, *iter, codim);
}
h5_err_t
h5t_release_entity_iterator (
h5_file_t* const f,
h5t_entity_iterator_t* iter
) {
return h5priv_free (f, iter);
}
h5_err_t
h5t_begin_iterate_entities (
h5_file_t* f,
h5t_entity_iterator_t* iter,
const int codim
) {
return (*f->t->methods.retrieve->init_iterator)(f, iter, codim);
}
/*!
Travere entities with co-dim > 0
*/
h5_id_t
h5tpriv_iterate_faces (
static h5_id_t
iterate_faces (
h5_file_t* const f,
h5t_entity_iterator_t* iter
) {
@@ -56,10 +84,10 @@ h5tpriv_iterate_faces (
h5_idlist_t* entry;
h5_size_t i;
int dim = iter->ref_element->dim - iter->codim;
int num_faces = iter->ref_element->num_faces[dim];
int num_faces = iter->ref_element->num_faces[dim] - 1;
do {
if (iter->face_idx >= num_faces) {
if (skip_to_next_elem_on_level (f, iter) == H5_NOK) {
if (h5tpriv_skip_to_next_elem_on_level (f, iter) == H5_NOK) {
h5_debug (f, "Traversing done!");
return H5_NOK;
}
@@ -86,76 +114,27 @@ h5tpriv_iterate_faces (
return entry->items[0];
}
h5_id_t
h5tpriv_iterate_elems (
static h5_id_t
iterate_elems (
h5_file_t* const f,
h5t_entity_iterator_t*iter
) {
if ( skip_to_next_elem_on_level (f, iter) == H5_NOK) {
if ( h5tpriv_skip_to_next_elem_on_level (f, iter) == H5_NOK) {
h5_debug ( f, "Traversing done!" );
return H5_NOK;
}
return h5tpriv_build_elem_id ( iter->elem_idx );
}
h5_err_t
h5t_alloc_entity_iterator (
h5_file_t* f,
h5t_entity_iterator_t** iter,
int codim
) {
TRY( *iter = h5priv_alloc (f, NULL, sizeof (h5t_entity_iterator_t)) );
return h5t_begin_iterate_entities (f, *iter, codim);
}
h5_err_t
h5t_release_entity_iterator (
h5_file_t* const f,
h5t_entity_iterator_t* iter
) {
return h5priv_free (f, iter);
}
h5_err_t
h5t_begin_iterate_entities (
h5_file_t* f,
h5t_entity_iterator_t* iter,
int codim
) {
iter->face_idx = -1;
iter->elem_idx = -1;
iter->codim = codim;
iter->ref_element = f->t->ref_element;
switch (iter->ref_element->dim - codim) {
case 0: // iterate vertices
iter->find = h5tpriv_find_tv2;
break;
case 1: // iterate edges
iter->find = h5tpriv_find_te2;
break;
case 2: // iterate faces
iter->find = h5tpriv_find_td2;
break;
case 3: // iterate elems
iter->find = NULL;
break;
default:
return h5_error_internal (f, __FILE__, __func__, __LINE__);
}
return skip_to_next_elem_on_level (f, iter);
}
h5_id_t
h5t_iterate_entities (
h5_file_t* const f,
h5t_entity_iterator_t* iter
) {
if (iter->codim > 0) {
return h5tpriv_iterate_faces (f, iter);
return iterate_faces (f, iter);
} else if (iter->codim == 0) {
return h5tpriv_iterate_elems (f, iter);
return iterate_elems (f, iter);
} else {
return h5_error_internal (f, __FILE__, __func__, __LINE__);
}
+6
View File
@@ -1,6 +1,12 @@
#ifndef __H5T_RETRIEVE_PRIVATE_H
#define __H5T_RETRIEVE_PRIVATE_H
h5_err_t
h5tpriv_skip_to_next_elem_on_level (
h5_file_t* f,
h5t_entity_iterator_t* iter
);
h5_err_t
h5tpriv_elem_is_on_cur_level (
h5_file_t * const f,
+51 -339
View File
@@ -32,8 +32,8 @@ h5t_add_mesh (
consecutive numbered starting from 0.
* Set the global vertex id's in element definitions.
*/
h5_err_t
h5tpriv_assign_global_vertex_ids (
static h5_err_t
assign_global_vertex_ids (
h5_file_t * const f
) {
h5t_fdata_t *t = f->t;
@@ -57,7 +57,7 @@ h5tpriv_assign_global_vertex_ids (
Assign unique global IDs to new elements.
*/
static h5_err_t
_assign_global_elem_ids (
assign_global_elem_ids (
h5_file_t * const f
) {
h5t_fdata_t *t = f->t;
@@ -197,7 +197,7 @@ h5t_end_store_vertices (
t->storing_data = 0;
t->num_vertices[t->cur_level] = t->last_stored_vid+1;
TRY ( h5tpriv_assign_global_vertex_ids ( f ) );
TRY ( assign_global_vertex_ids ( f ) );
TRY ( h5tpriv_sort_vertices ( f ) );
TRY ( h5tpriv_rebuild_global_2_local_map_of_vertices ( f ) );
return H5_SUCCESS;
@@ -230,19 +230,24 @@ h5t_begin_store_elems (
*/
size_t nel = 2097152 > 5*new ? 2097152 : 5*new;
TRY ( h5tpriv_resize_te_htab ( f, nel ) );
return (*t->methods._alloc_elems) ( f, cur, new );
return (*t->methods.store->alloc_elems) ( f, cur, new );
}
/*!
\param[in] local_parent_eid local parent id of element
if level \c >0 else \c -1
\param[in] local_vids local vertex id's defining the element
Store element. The vertices are given via their local indices.
\param[in] f File handle.
\param[in] elem_idx_of_parent Local indexd of the parent element
or \c -1.
\param[in] vertices Local vertex indices defining the
tetrahedron.
*/
h5_id_t
h5t_store_elem (
h5_file_t * const f,
const h5_id_t local_parent_eid,
const h5_id_t local_vids[]
h5t_store_elem (
h5_file_t* const f,
const h5_id_t elem_idx_of_parent,
const h5_id_t* vertices
) {
h5t_fdata_t *t = f->t;
@@ -258,89 +263,39 @@ h5t_store_elem (
/* check parent id */
if (
( t->cur_level == 0 && local_parent_eid != -1 ) ||
( t->cur_level > 0 && local_parent_eid < 0 ) ||
( t->cur_level == 0 && elem_idx_of_parent != -1 ) ||
( t->cur_level > 0 && elem_idx_of_parent < 0 ) ||
( t->cur_level > 0
&& local_parent_eid >= t->num_elems[t->cur_level-1] )
&& elem_idx_of_parent >= t->num_elems[t->cur_level-1] )
) {
return HANDLE_H5_PARENT_ID_ERR (
f,
h5tpriv_map_oid2str(t->mesh_type),
local_parent_eid );
elem_idx_of_parent );
}
return (*t->methods._store_elem)( f, local_parent_eid, local_vids );
}
/*!
Store tetrahedron. The vertices are given with there *local* id's!
\param[in] f File handle.
\param[in] local_parent_id Local id of the parent element or \c -1.
\param[in] local_vids Local vertex id's defining the tetrahedron.
*/
h5_id_t
h5tpriv_store_tet (
h5_file_t * const f,
const h5_id_t local_parent_eid,
const h5_id_t *local_vids
) {
h5t_fdata_t *t = f->t;
t->level_changed = 1;
h5_id_t local_eid = ++t->last_stored_eid;
h5_elem_ldta_t *elem_ldta = &t->elems_ldta[local_eid];
h5_id_t elem_idx = ++t->last_stored_eid;
h5_elem_ldta_t* elem_ldta = &t->elems_ldta[elem_idx];
elem_ldta->local_parent_eid = local_parent_eid;
elem_ldta->local_parent_eid = elem_idx_of_parent;
elem_ldta->local_child_eid = -1;
elem_ldta->level_id = t->cur_level;
int num_vertices = t->ref_element->num_faces[0];
memcpy ( elem_ldta->local_vids, local_vids,
sizeof (*local_vids) * num_vertices );
h5tpriv_sort_local_vids ( f, elem_ldta->local_vids, num_vertices );
h5_id_t face_id;
h5_idlist_t *retval;
for ( face_id = 0; face_id < 6; face_id++ ) {
memcpy (elem_ldta->local_vids, vertices,
sizeof (*vertices) * num_vertices);
h5tpriv_sort_local_vids (f, elem_ldta->local_vids, num_vertices);
h5_id_t face_idx;
int num_faces = t->ref_element->num_faces[1];
h5_idlist_t* retval;
for (face_idx = 0; face_idx < num_faces; face_idx++) {
// add edges to neighbour struct
TRY ( h5tpriv_search_te2 (
TRY( h5tpriv_search_te2 (
f,
face_id,
local_eid,
&retval ) );
face_idx,
elem_idx,
&retval) );
}
return local_eid;
}
h5_id_t
h5tpriv_store_tri (
h5_file_t * const f,
const h5_id_t local_parent_eid,
const h5_id_t *local_vids
) {
h5t_fdata_t *t = f->t;
t->level_changed = 1;
h5_id_t local_eid = ++t->last_stored_eid;
h5_elem_ldta_t *elem_ldta = &t->elems_ldta[local_eid];
elem_ldta->local_parent_eid = local_parent_eid;
elem_ldta->local_child_eid = -1;
elem_ldta->level_id = t->cur_level;
int num_vertices = t->ref_element->num_faces[0];
memcpy ( elem_ldta->local_vids, local_vids,
sizeof (*local_vids) * num_vertices );
h5tpriv_sort_local_vids ( f, elem_ldta->local_vids, num_vertices );
h5_id_t face_id;
h5_idlist_t *retval;
for ( face_id = 0; face_id < 3; face_id++ ) {
// add edges to neighbour struct
TRY ( h5tpriv_search_te2 (
f,
face_id,
local_eid,
&retval ) );
}
return local_eid;
return elem_idx;
}
h5_err_t
@@ -351,7 +306,7 @@ h5t_end_store_elems (
t->storing_data = 0;
t->num_elems[t->cur_level] = t->last_stored_eid+1;
TRY ( _assign_global_elem_ids ( f ) );
TRY ( assign_global_elem_ids ( f ) );
TRY ( h5tpriv_sort_elems ( f ) );
TRY ( h5tpriv_rebuild_global_2_local_map_of_elems ( f ) );
@@ -393,6 +348,20 @@ h5t_begin_refine_elems (
return H5_SUCCESS;
}
/*!
Refine element \c local_eid
\return local id of first new element or \c -1
*/
h5_id_t
h5t_refine_elem (
h5_file_t * const f,
const h5_id_t local_eid
) {
return (*f->t->methods.store->refine_elem)( f, local_eid );
}
h5_err_t
h5t_end_refine_elems (
h5_file_t * const f
@@ -406,265 +375,8 @@ h5t_end_refine_elems (
return H5_SUCCESS;
}
/*!
Refine edge. Store vertex, if new.
Function can be used with tetrahedral and triangle meshes.
\return local id of vertex
*/
h5_id_t
h5tpriv_bisect_edge (
h5_file_t * const f,
h5_id_t face_id,
h5_id_t elem_id
) {
h5t_fdata_t *t = f->t;
h5_id_t vids[2];
h5_idlist_t *retval;
/*
get all elements sharing the given edge
*/
TRY( h5tpriv_find_te2 (f, face_id, elem_id, &retval) );
/*
check wether one of the found elements has been refined
*/
size_t i;
for ( i = 0; i < retval->num_items; i++ ) {
h5_id_t local_id = h5tpriv_get_elem_idx ( retval->items[i] );
h5_elem_ldta_t *tet = &t->elems_ldta[local_id];
if ( tet->local_child_eid >= 0 ) {
/*
this element has been refined!
return bisecting point
*/
h5_id_t face_id = h5tpriv_get_face_idx (
retval->items[i] );
h5_id_t kids[2], edge0[2], edge1[2];
TRY ( h5tpriv_compute_direct_children_of_edge (
f,
face_id,
tet->local_child_eid,
kids ) );
TRY ( h5t_get_vertex_indices_of_edge ( f, kids[0], edge0 ) );
TRY ( h5t_get_vertex_indices_of_edge ( f, kids[1], edge1 ) );
if ( (edge0[0] == edge1[0]) || (edge0[0] == edge1[1]) )
return edge0[0];
else
return edge0[1];
}
}
/*
None of the elements has been refined -> add new vertex.
*/
h5_float64_t *P0 = t->vertices[vids[0]].P;
h5_float64_t *P1 = t->vertices[vids[1]].P;
h5_float64_t P[3];
P[0] = ( P0[0] + P1[0] ) / 2.0;
P[1] = ( P0[1] + P1[1] ) / 2.0;
P[2] = ( P0[2] + P1[2] ) / 2.0;
return h5t_store_vertex ( f, -1, P );
}
/*!
Refine element \c local_eid
\return local id of first new element or \c -1
*/
h5_id_t
h5t_refine_elem (
h5_file_t * const f,
const h5_id_t local_eid
) {
return (*f->t->methods._refine_elem)( f, local_eid );
}
/*!
Refine triangle \c local_eid
\return Local id of first new triangle or \c -1
*/
h5_id_t
h5tpriv_refine_tri (
h5_file_t * const f,
const h5_id_t local_eid
) {
h5t_fdata_t *t = f->t;
h5_id_t local_vids[6];
h5_id_t local_child_eid;
h5_elem_ldta_t *el = &t->elems_ldta[local_eid];
if ( el->local_child_eid >= 0 )
return h5_error (
f,
H5_ERR_INVAL,
"Tetrahedron %lld already refined.",
local_eid );
local_vids[0] = el->local_vids[0];
local_vids[1] = el->local_vids[1];
local_vids[2] = el->local_vids[2];
local_vids[3] = h5tpriv_bisect_edge( f, 0, local_eid ); /* 1,2 */
local_vids[4] = h5tpriv_bisect_edge( f, 1, local_eid ); /* 0,2 */
local_vids[5] = h5tpriv_bisect_edge( f, 2, local_eid ); /* 0,1 */
h5_id_t new_el[3];
/* 0 */
new_el[0] = local_vids[0];
new_el[1] = local_vids[4];
new_el[2] = local_vids[5];
TRY ( local_child_eid = h5tpriv_store_tri ( f, local_eid, new_el ) );
/* 1 */
new_el[0] = local_vids[1];
new_el[1] = local_vids[3];
new_el[2] = local_vids[5];
TRY ( h5tpriv_store_tri ( f, local_eid, new_el ) );
/* 2 */
new_el[0] = local_vids[2];
new_el[1] = local_vids[3];
new_el[2] = local_vids[4];
TRY ( h5tpriv_store_tri ( f, local_eid, new_el ) );
/* 3 */
new_el[0] = local_vids[3];
new_el[1] = local_vids[4];
new_el[2] = local_vids[5];
TRY ( h5tpriv_store_tri ( f, local_eid, new_el ) );
return local_child_eid;
}
/*!
\param[in] f file handle
\param[in] local_kid local edge ID we search children of
\param[in] local_eid local element ID of first children
\param[out] kids direct children
*/
h5_err_t
h5tpriv_compute_direct_children_of_edge (
h5_file_t * const f,
h5_id_t face_id,
h5_id_t local_eid,
h5_id_t kids[2]
) {
int off[6][2] = { {0,1}, {1,2}, {0,2}, {0,3}, {1,3}, {2,3} };
if ( ( face_id < 0 ) || ( face_id >= 6 ) ) {
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
}
kids[0] = h5tpriv_build_edge_id ( face_id, local_eid+off[face_id][0] );
kids[1] = h5tpriv_build_edge_id ( face_id, local_eid+off[face_id][1] );
return H5_SUCCESS;
}
/*!
Refine tetrahedron \c local_eid
\return Local id of first new tetrahedron or \c -1
*/
h5_id_t
h5tpriv_refine_tet (
h5_file_t * const f,
const h5_id_t local_eid
) {
h5t_fdata_t *t = f->t;
h5_id_t local_vids[10];
h5_id_t local_child_eid;
h5_elem_ldta_t *tet = &t->elems_ldta[local_eid];
if ( tet->local_child_eid >= 0 )
return h5_error (
f,
H5_ERR_INVAL,
"Tetrahedron %lld already refined.",
local_eid );
local_vids[0] = tet->local_vids[0];
local_vids[1] = tet->local_vids[1];
local_vids[2] = tet->local_vids[2];
local_vids[3] = tet->local_vids[3];
local_vids[4] = h5tpriv_bisect_edge( f, 0, local_eid );
local_vids[5] = h5tpriv_bisect_edge( f, 2, local_eid );
local_vids[6] = h5tpriv_bisect_edge( f, 3, local_eid );
local_vids[7] = h5tpriv_bisect_edge( f, 1, local_eid );
local_vids[8] = h5tpriv_bisect_edge( f, 4, local_eid );
local_vids[9] = h5tpriv_bisect_edge( f, 5, local_eid );
/*
add new tets
*/
h5_id_t new_tet_local_vids[4];
/* 0 */
new_tet_local_vids[0] = local_vids[0];
new_tet_local_vids[1] = local_vids[6]; // (03)
new_tet_local_vids[2] = local_vids[5]; // (02)
new_tet_local_vids[3] = local_vids[4]; // (01)
TRY ( local_child_eid = h5tpriv_store_tet (
f, local_eid, new_tet_local_vids ) );
/* 1 */
new_tet_local_vids[0] = local_vids[4]; // (01)
new_tet_local_vids[1] = local_vids[8]; // (13)
new_tet_local_vids[2] = local_vids[7]; // (12)
new_tet_local_vids[3] = local_vids[1];
TRY ( h5tpriv_store_tet ( f, local_eid, new_tet_local_vids ) );
/* 2 */
new_tet_local_vids[0] = local_vids[5]; // (02)
new_tet_local_vids[1] = local_vids[9]; // (23)
new_tet_local_vids[2] = local_vids[2];
new_tet_local_vids[3] = local_vids[7]; // (12)
TRY ( h5tpriv_store_tet ( f, local_eid, new_tet_local_vids ) );
/* 3 */
new_tet_local_vids[0] = local_vids[6]; // (03)
new_tet_local_vids[1] = local_vids[3];
new_tet_local_vids[2] = local_vids[9]; // (23)
new_tet_local_vids[3] = local_vids[8]; // (13)
TRY ( h5tpriv_store_tet ( f, local_eid, new_tet_local_vids ) );
/* 4 */
new_tet_local_vids[0] = local_vids[6]; // (03)
new_tet_local_vids[1] = local_vids[5]; // (02)
new_tet_local_vids[2] = local_vids[4]; // (01)
new_tet_local_vids[3] = local_vids[8]; // (13)
TRY ( h5tpriv_store_tet ( f, local_eid, new_tet_local_vids ) );
/* 5 */
new_tet_local_vids[0] = local_vids[5]; // (02)
new_tet_local_vids[1] = local_vids[4]; // (01)
new_tet_local_vids[2] = local_vids[8]; // (13)
new_tet_local_vids[3] = local_vids[7]; // (12)
TRY ( h5tpriv_store_tet ( f, local_eid, new_tet_local_vids ) );
/* 6 */
new_tet_local_vids[0] = local_vids[6]; // (03)
new_tet_local_vids[1] = local_vids[5]; // (02)
new_tet_local_vids[2] = local_vids[9]; // (23)
new_tet_local_vids[3] = local_vids[8]; // (13)
TRY ( h5tpriv_store_tet ( f, local_eid, new_tet_local_vids ) );
/* 7 */
new_tet_local_vids[0] = local_vids[5]; // (02)
new_tet_local_vids[1] = local_vids[9]; // (23)
new_tet_local_vids[2] = local_vids[8]; // (13)
new_tet_local_vids[3] = local_vids[7]; // (12)
TRY ( h5tpriv_store_tet ( f, local_eid, new_tet_local_vids ) );
t->elems.tets[local_eid].global_child_eid = local_child_eid;
t->elems_ldta[local_eid].local_child_eid = local_child_eid;
t->num_elems_on_level[t->cur_level]--;
return local_child_eid;
}
-34
View File
@@ -1,38 +1,4 @@
#ifndef __H5T_STOREMESH_PRIVATE_H
#define __H5T_STOREMESH_PRIVATE_H
h5_id_t
h5tpriv_store_tri (
h5_file_t * const f,
const h5_id_t local_parent_eid,
const h5_id_t vids[]
);
h5_id_t
h5tpriv_store_tet (
h5_file_t * const f,
const h5_id_t local_parent_eid,
const h5_id_t vids[]
);
h5_err_t
h5tpriv_compute_direct_children_of_edge (
h5_file_t * const f,
h5_id_t face_id,
h5_id_t local_eid,
h5_id_t kids[2]
);
h5_id_t
h5tpriv_refine_tri (
h5_file_t * const f,
const h5_id_t local_eid
);
h5_id_t
h5tpriv_refine_tet (
h5_file_t * const f,
const h5_id_t local_eid
);
#endif
+24 -23
View File
@@ -15,7 +15,7 @@
*/
static h5_err_t
_init_container (
init_container (
h5_file_t * const f,
const size_t ntags,
h5t_tagcontainer_t * ctn
@@ -32,14 +32,14 @@ h5tpriv_init_mtagsets (
h5_file_t * const f,
size_t ntags
) {
return _init_container ( f, ntags, &f->t->mtags );
return init_container ( f, ntags, &f->t->mtags );
}
/*
Release all tag values for a specific element
*/
static h5_err_t
_release_tagvals_of_elem (
release_tagvals_of_elem (
h5_file_t * const f,
h5t_tagsel_t *el_vals
) {
@@ -54,7 +54,7 @@ _release_tagvals_of_elem (
Release a tag-set
*/
static h5_err_t
_release_tagset (
release_tagset (
h5_file_t * const f,
const void *__set
) {
@@ -62,7 +62,7 @@ _release_tagset (
unsigned int i;
for ( i = 0; i < set->num_elems; i++ ) {
if ( set->elems[i] != NULL ) {
TRY ( _release_tagvals_of_elem ( f, set->elems[i] ) );
TRY ( release_tagvals_of_elem ( f, set->elems[i] ) );
}
}
TRY ( h5priv_free ( f, set->name ) );
@@ -74,11 +74,12 @@ _release_tagset (
Release all sets in given container
*/
static h5_err_t
_release_container (
h5_file_t * const f,
h5t_tagcontainer_t * ctn
release_container (
h5_file_t* const f,
h5t_tagcontainer_t* ctn
) {
TRY ( h5priv_hwalk ( f, &ctn->sets, _release_tagset ) );
if (ctn->num_sets == 0) return H5_SUCCESS;
TRY ( h5priv_hwalk ( f, &ctn->sets, release_tagset ) );
TRY ( h5priv_free ( f, ctn->names ) );
return H5_SUCCESS;
@@ -92,7 +93,7 @@ h5tpriv_release_tags (
h5_file_t * const f
) {
h5t_fdata_t *t = f->t;
TRY ( _release_container ( f, &t->mtags ) );
TRY ( release_container ( f, &t->mtags ) );
return H5_SUCCESS;
}
@@ -185,7 +186,7 @@ h5t_add_mtagset (
\return H5_SUCCESS or error code
*/
static h5_err_t
_remove_tagset (
remove_tagset (
h5_file_t *const f,
h5t_tagcontainer_t *ctn,
const char name[]
@@ -249,7 +250,7 @@ h5t_remove_mtagset (
h5t_fdata_t *t = f->t;
TRY ( t->mtags.group_id = h5priv_open_group ( f, t->mesh_gid, "Tags" ) );
TRY ( _remove_tagset ( f, &t->mtags, name ) );
TRY ( remove_tagset ( f, &t->mtags, name ) );
TRY ( h5priv_close_hdf5_group ( f, t->mtags.group_id ) );
return H5_SUCCESS;
}
@@ -585,7 +586,7 @@ h5t_remove_mtag_by_name (
}
static hid_t
_open_space_all (
open_space_all (
h5_file_t * const f,
hid_t dataset_id
) {
@@ -596,7 +597,7 @@ _open_space_all (
Store given tagset.
*/
static h5_err_t
_write_tagset (
write_tagset (
h5_file_t * const f,
hid_t loc_id,
H5T_Tagset *tagset
@@ -721,7 +722,7 @@ _write_tagset (
f,
group_id,
&dsinfo,
_open_space_all, _open_space_all,
open_space_all, open_space_all,
elems ) );
strcpy ( dsinfo.name, "entities" );
@@ -731,7 +732,7 @@ _write_tagset (
f,
group_id,
&dsinfo,
_open_space_all, _open_space_all,
open_space_all, open_space_all,
entities ) );
strcpy ( dsinfo.name, "values" );
@@ -742,7 +743,7 @@ _write_tagset (
f,
group_id,
&dsinfo,
_open_space_all, _open_space_all,
open_space_all, open_space_all,
vals ) );
return H5_SUCCESS;
@@ -766,7 +767,7 @@ _write_container (
&ctn->sets ) );
H5T_Tagset *tagset = (H5T_Tagset*)__retval;
if ( tagset->changed ) {
TRY ( _write_tagset (
TRY ( write_tagset (
f,
ctn->group_id,
tagset ) );
@@ -791,7 +792,7 @@ h5tpriv_write_mtags (
}
static h5_err_t
_read_tagset (
read_tagset (
h5_file_t * const f,
hid_t loc_id,
hsize_t idx
@@ -820,7 +821,7 @@ _read_tagset (
f,
dset_id,
&dsinfo,
_open_space_all, _open_space_all,
open_space_all, open_space_all,
elems ) );
TRY ( h5priv_close_hdf5_dataset ( f, dset_id ) );
num_elems--;
@@ -835,7 +836,7 @@ _read_tagset (
f,
dset_id,
&dsinfo,
_open_space_all, _open_space_all,
open_space_all, open_space_all,
entities ) );
TRY ( h5priv_close_hdf5_dataset ( f, dset_id ) );
num_entities--;
@@ -850,7 +851,7 @@ _read_tagset (
f,
dset_id,
&dsinfo,
_open_space_all, _open_space_all,
open_space_all, open_space_all,
vals ) );
TRY ( h5priv_close_hdf5_dataset ( f, dset_id ) );
type = h5_normalize_h5_type ( f, dsinfo.type_id );
@@ -884,7 +885,7 @@ h5tpriv_read_tag_container (
hsize_t idx;
for ( idx = 0; idx < num_sets; idx++ ) {
TRY ( _read_tagset ( f, ctn->group_id, idx ) );
TRY( read_tagset (f, ctn->group_id, idx) );
}
return H5_SUCCESS;
+53 -17
View File
@@ -1,5 +1,5 @@
/*
Copyright 2006-2009
Copyright 2006-2010
Paul Scherrer Institut, Villigen, Switzerland;
Achim Gsell
All rights reserved.
@@ -11,11 +11,7 @@
This code is under development.
*/
#include <stdlib.h>
#include <string.h>
#include <search.h>
#include <time.h>
#include <hdf5.h>
#include "h5core/h5_core.h"
#include "h5_core_private.h"
@@ -134,7 +130,7 @@ compute_children_of_edge (
);
} else {
h5_id_t kids[2];
TRY ( h5tpriv_compute_direct_children_of_edge (
TRY ( t->methods.store->get_direct_children_of_edge (
f,
face_idx,
tet->local_child_eid,
@@ -176,7 +172,7 @@ compute_sections_of_edge (
if ( ! h5tpriv_elem_is_on_cur_level ( f, tet ) == H5_OK ) {
refined = 1;
h5_id_t kids[2];
TRY ( h5tpriv_compute_direct_children_of_edge (
TRY ( t->methods.store->get_direct_children_of_edge (
f,
face_id,
tet->local_child_eid,
@@ -193,22 +189,62 @@ compute_sections_of_edge (
return H5_SUCCESS;
}
/*
Compute direct children of a triangle.
Face 0 Face 1 Face 2 Face 3
1 1 2 1
+ + + +
|\ |\ |\ |\
| \ | \ | \ | \
| \ | \ | \ | \
| \ | \ | \ | \
4+----+7 4+----+8 5+----+9 7+----+8
|\ |\ |\ |\ |\ |\ |\ |\
| \ | \ | \ | \ | \ | \ | \ | \
| \ | \ | \ | \ | \ | \ | \ | \
| \| \ | \| \ | \| \ | \| \
+----+----+ +----+----+ +----+----+ +----+----+
0 5 2 0 6 3 0 6 3 2 9 3
z ^ z ^ y ^ z ^
| | | |
+--> +--> +--> +-->
y x x x
Triangle: face idx, #child
[0,4,5]: 0, 0 [0,4,6]: 1, 0 [0,5,6]: 2, 0 [1,7,8]: 3, 1
[1,4,7]: 0, 1 [1,4,8]: 1, 1 [2,5,9]: 2, 2 [2,7,9]: 3, 2
[2,5,7]: 0, 2 [3,6,8]: 1, 3 [3,6,9]: 2, 3 [3,8,9]: 3, 3
[4,5,7]: 0, 5 [4,6,8]: 2, 4 [5,6,9]: 1, 7 [7,8,9]: 3, 6
*/
static h5_err_t
compute_direct_children_of_triangle (
h5_file_t * const f,
h5_id_t face_id,
h5_id_t eid,
h5_id_t dids[4]
h5_id_t face_idx,
h5_id_t elem_idx,
h5_id_t children[4]
) {
int off[4][4] = { {1,2,3,7}, {0,2,3,6}, {0,1,3,4}, {0,1,2,5} };
if ( ( face_id < 0 ) || ( face_id >= 4 ) ) {
h5_id_t map[4][4][2] = {
{{0,0},{0,1},{0,2},{0,5}},
{{1,0},{1,1},{1,3},{2,4}},
{{2,0},{2,2},{2,3},{1,7}},
{{3,1},{3,2},{3,3},{3,6}}
};
int num_faces = f->t->ref_element->num_faces[2];
if ( (face_idx < 0) || (face_idx >= num_faces) ) {
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
}
dids[0] = h5tpriv_build_edge_id ( face_id, eid+off[face_id][0] );
dids[1] = h5tpriv_build_edge_id ( face_id, eid+off[face_id][1] );
dids[2] = h5tpriv_build_edge_id ( face_id, eid+off[face_id][2] );
dids[3] = h5tpriv_build_edge_id ( face_id, eid+off[face_id][3] );
children[0] = h5tpriv_build_edge_id (
map[face_idx][0][0], elem_idx+map[face_idx][0][1]);
children[1] = h5tpriv_build_edge_id (
map[face_idx][1][0], elem_idx+map[face_idx][1][1]);
children[2] = h5tpriv_build_edge_id (
map[face_idx][2][0], elem_idx+map[face_idx][2][1]);
children[3] = h5tpriv_build_edge_id (
map[face_idx][3][0], elem_idx+map[face_idx][3][1]);
return H5_SUCCESS;
}
+13 -4
View File
@@ -1,6 +1,16 @@
#ifndef __H5T_TYPES_PRIVATE_H
#define __H5T_TYPES_PRIVATE_H
struct h5t_store_methods {
h5_err_t (*alloc_elems)(h5_file_t* const, const size_t, const size_t);
h5_id_t (*refine_elem)(h5_file_t* const, const h5_id_t);
h5_id_t (*get_direct_children_of_edge)(h5_file_t* const, const h5_id_t, const h5_id_t, h5_id_t*);
};
struct h5t_retrieve_methods {
h5_err_t (*init_iterator)(h5_file_t* const, h5t_entity_iterator_t*, const int);
};
struct h5t_adjacency_methods {
h5_err_t (*rebuild_internal_structs)(h5_file_t * const);
h5_err_t (*release_internal_structs)(h5_file_t * const);
@@ -31,9 +41,8 @@ struct h5t_adjacency_methods {
};
struct h5t_methods {
h5_err_t (*_alloc_elems)(h5_file_t * const, const size_t, const size_t);
h5_id_t (*_store_elem)(h5_file_t * const, const h5_id_t, const h5_id_t*);
h5_id_t (*_refine_elem)(h5_file_t * const, const h5_id_t);
struct h5t_store_methods *store;
struct h5t_retrieve_methods *retrieve;
struct h5t_adjacency_methods *adjacency;
};
@@ -125,7 +134,7 @@ typedef struct h5t_fdata {
char mesh_name[16];
char mesh_label[256];
h5_oid_t mesh_type; /* object id of element type */
h5t_ref_element_t* ref_element;
const h5t_ref_element_t* ref_element;
h5_id_t cur_mesh; /* id of current mesh */
h5_id_t mesh_changed; /* true if new or has been changed */
h5_id_t num_meshes; /* number of meshes */
-1
View File
@@ -22,7 +22,6 @@
#include "H5.h"
#include "H5Fed_adjacency.h"
#include "H5Fed_inquiry.h"
#include "H5Fed_map.h"
#include "H5Fed_retrieve.h"
#include "H5Fed_store.h"
#include "H5Fed_tags.h"
+1 -1
View File
@@ -5,7 +5,7 @@ typedef struct {
h5_id_t elem_idx; // local element id
h5_id_t face_idx; // face id according reference element
int codim; // dimension of entities to traverse
h5t_ref_element_t* ref_element; // pointer to reference element
const h5t_ref_element_t* ref_element; // pointer to reference element
h5_err_t (*find)(h5_file_t *const f,
h5_id_t face_idx,
h5_id_t elem_idx,