From 1790c475dab991704f502bf8723dee1f3bb365be Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Wed, 2 Jul 2008 14:21:21 +0000 Subject: [PATCH] refactoring and triangle meshes --- src/H5.c | 6 +- src/H5.h | 4 +- src/H5Fed.c | 16 +- src/H5Fed.h | 479 +++++------------------------- src/H5Fed_inquiry.c | 177 +++-------- src/H5Fed_retrieve.c | 57 +++- src/H5Fed_store.c | 41 ++- src/H5_inquiry.c | 6 +- src/h5/errorhandling.c | 28 +- src/h5/errorhandling.h | 18 +- src/h5/general.c | 3 +- src/h5/h5_core.h | 13 + src/h5/h5_private.h | 7 - src/h5/h5_types.h | 37 ++- src/h5/t_openclose.c | 63 +++- src/h5/t_readwrite.c | 656 ++++++++++++++++++++++++++++------------- src/h5/t_readwrite.h | 87 ++++-- 17 files changed, 847 insertions(+), 851 deletions(-) diff --git a/src/H5.c b/src/H5.c index 5700b03..c006d16 100644 --- a/src/H5.c +++ b/src/H5.c @@ -42,7 +42,7 @@ #include #include -#include "h5/h5.h" +#include "h5/h5_core.h" #include "h5/h5_private.h" #include "H5Fed.h" @@ -120,8 +120,8 @@ h5_err_t H5GetStepNameFormat ( h5_file *f, /*!< Handle to file */ char *name, /*!< OUT: Prefix */ - h5_int64_t *l_name, /*!< length of buffer name */ - h5_int64_t *width /*!< OUT: Width of the number */ + const h5_size_t l_name, /*!< length of buffer name */ + h5_size_t *width /*!< OUT: Width of the number */ ) { SET_FNAME ( "H5PartDefineStepNameFormat" ); diff --git a/src/H5.h b/src/H5.h index 29aea70..77cf49f 100644 --- a/src/H5.h +++ b/src/H5.h @@ -38,8 +38,8 @@ h5_err_t H5GetStepNameFormat ( h5_file *f, char *name, - h5_int64_t *l_name, - h5_int64_t *width + const h5_size_t l_name, + h5_size_t *width ); h5_err_t diff --git a/src/H5Fed.c b/src/H5Fed.c index 1002aaa..3cc06cc 100644 --- a/src/H5Fed.c +++ b/src/H5Fed.c @@ -15,32 +15,34 @@ #include #include -#include "h5/h5.h" +#include "h5/h5_core.h" #include "h5/h5_private.h" #include "H5Fed.h" h5_err_t H5FedOpenMesh ( h5_file * f, - const h5_id_t id + const h5_id_t id, + const enum h5_mesh_types type ) { SET_FNAME ( __func__ ); - return H5t_open_mesh ( f, id ); + return h5t_open_mesh ( f, id, type ); } h5_id_t H5FedAddMesh ( - h5_file * f + h5_file * f, + const enum h5_mesh_types type ) { SET_FNAME ( __func__ ); - return H5t_open_mesh ( f, -1 ); + return h5t_open_mesh ( f, -1, type ); } h5_err_t -H5FedSetRefinementLevel ( +H5FedSetLevel ( h5_file * f, const h5_id_t id ) { SET_FNAME ( __func__ ); - return H5t_open_level ( f, id ); + return h5t_open_level ( f, id ); } diff --git a/src/H5Fed.h b/src/H5Fed.h index 8d7f56d..58cc405 100644 --- a/src/H5Fed.h +++ b/src/H5Fed.h @@ -25,123 +25,111 @@ h5_size_t H5FedGetNumMeshes ( - h5_file * f /*!< file handle */ + h5_file * f, + const enum h5_mesh_types type ); h5_err_t H5FedOpenMesh ( h5_file * f, - const h5_id_t id + const h5_id_t id, + const enum h5_mesh_types type ); h5_id_t H5FedAddMesh ( - h5_file * fh + h5_file * f, + const enum h5_mesh_types type ); h5_size_t -H5FedGetNumRefinementLevels ( - h5_file * f /*!< file handle */ +H5FedGetNumLevels ( + h5_file * f ); h5_err_t -H5FedSetRefinementLevel ( +H5FedSetLevel ( h5_file * f, const h5_id_t id ); h5_id_t -H5FedAddRefinementLevel ( - h5_file * fh +H5FedGetLevel ( + h5_file * f ); -h5_size_t -H5FedSetAdditionalNumVerticesToStore ( - h5_file * f, /*!< file handle */ - const h5_size_t num /*!< number of additional vertices */ +h5_id_t +H5FedAddLevel ( + h5_file * f + ); + +h5_err_t +H5FedAddNumVertices ( + h5_file * f, + const h5_size_t num + ); + +h5_err_t +H5FedAddNumEntities ( + h5_file * f, + const h5_size_t num ); /****** INQUIRY routines *****************************************************/ -h5_int_t H5GetNumNodes ( - h5_file * fh +h5_size_t +H5GetNumNodes ( + h5_file * f ); -h5_int_t H5FedGetNumMeshLevels ( - h5_file * fh - ); - -h5_int_t H5FedHasTetrahedralMesh ( - h5_file * fh, - const h5_id_t level - ); - -h5_int_t H5FedHasBoundaryMesh( - h5_file * fh, - const h5_id_t level -); - /****** VERTEX statistics routines *******************************************/ -h5_size_t H5FedGetNumVerticesTotal( - h5_file * fh, - const h5_id_t level +h5_size_t +H5FedGetNumVertices ( + h5_file * f ); -h5_size_t H5FedGetNumVerticesCnode ( - h5_file * fh, - const h5_id_t level, - const h5_id_t cnode +h5_size_t +H5FedGetNumVerticesTotal( + h5_file * f ); -/****** EDGE statistics routines ********************************************/ - -h5_size_t H5FedGetNumEdgesTotal ( - h5_file * fh, - const h5_id_t level - ); - -h5_size_t H5FedGetNumEdgesCnode ( - h5_file * fh, - const h5_id_t level, +h5_size_t +H5FedGetNumVerticesCnode ( + h5_file * f, const h5_id_t cnode ); /****** TRIANGLE statistics routines *****************************************/ - -h5_size_t H5FedGetNumTrianglesTotal ( - h5_file * fh, - const h5_id_t level +h5_size_t +H5FedGetNumTriangles ( + h5_file * f ); -h5_size_t H5FedGetNumTrianglesCnode ( - h5_file * fh, - const h5_id_t level, +h5_size_t +H5FedGetNumTrianglesTotal ( + h5_file * f + ); + +h5_size_t +H5FedGetNumTrianglesCnode ( + h5_file * f, const h5_id_t cnode ); /****** TETRAHEDRON statistics routines **************************************/ - -h5_size_t H5FedGetNumTetrahedraTotal( - h5_file * fh, - const h5_id_t level +h5_size_t +H5FedGetNumTetrahedra ( + h5_file * f ); -h5_size_t H5FedGetNumTetrahedraCnode ( - h5_file * fh, - const h5_id_t level, - const h5_id_t cnode +h5_size_t +H5FedGetNumTetrahedraTotal ( + h5_file * f ); -/****** BOUNDARY statistics routines ****************************************/ - -h5_size_t H5FedGetNumBoundaryTrianglesTotal ( - h5_file * fh, - const h5_id_t level - ); - -h5_size_t H5FedGetNumBoundaryTrianglesCnode ( - h5_file * fh, - const h5_id_t level, +h5_size_t +H5FedGetNumTetrahedraCnode ( + h5_file * f, const h5_id_t cnode ); @@ -149,17 +137,6 @@ h5_size_t H5FedGetNumBoundaryTrianglesCnode ( /* vertices */ -h5_size_t -H5FedSetNumVertices ( - h5_file * f, - const h5_size_t num - ); - -h5_size_t -H5FedGetNumVertices ( - h5_file * f - ); - h5_id_t H5FedStoreVertex ( h5_file * f, @@ -167,110 +144,46 @@ H5FedStoreVertex ( const h5_float64_t P[3] ); +h5_err_t +H5FedStartTraverseVertices ( + h5_file * f + ); + h5_id_t -H5FedGetVertex ( +H5FedTraverseVertices ( h5_file * f, h5_id_t * const id, h5_float64_t P[3] ); -/* edges */ -h5_size_t -H5FedSetNumEdges ( - h5_file * f, - const h5_size_t num - ); - -h5_size_t -H5FedGetNumEdges ( - h5_file * f - ); - -h5_id_t -H5FedStoreEdge ( - h5_file * f, - const h5_id_t id, - const h5_id_t parent_id, - const h5_id_t vertex_ids[2] - ); - -h5_id_t -H5FedGetEdge ( - h5_file * f, - h5_id_t * const id, - h5_id_t * const parent_id, - h5_id_t * const vertex_ids[2] - ); - -/* triangles */ -h5_size_t -H5FedSetNumTriangles ( - h5_file * f, - const h5_size_t num - ); h5_size_t H5FedGetNumTriangles ( h5_file * f ); -h5_int_t +h5_id_t H5FedStoreTriangle ( h5_file * f, const h5_id_t id, const h5_id_t parent_id, - const h5_id_t vertex_ids[3] + h5_id_t vertex_ids[3] ); -h5_id_t -H5FedGetTriangle ( - h5_file * f, - h5_id_t * const id, - h5_id_t * const parent_id, - h5_id_t * const vertex_ids[2] - ); - -/* boundary triangles */ -h5_size_t -H5FedSetNumBoundaryTriangles ( - h5_file * f, - const h5_size_t num - ); - -h5_size_t -H5FedGetNumBoundaryTriangles ( +h5_err_t +H5FedStartTraverseTriangles ( h5_file * f ); - h5_id_t -H5FedStoreBoundaryTriangle ( - h5_file * fh, - const h5_id_t id, - const h5_id_t parent_id, - const h5_id_t vertex_ids[3] - ); - -h5_id_t -H5FedGetBoundaryTriangle ( +H5FedTraverseTriangles ( h5_file * f, h5_id_t * const id, h5_id_t * const parent_id, - h5_id_t * const vertex_ids[3] + h5_id_t vertex_ids[3] ); /* tetrahedra */ -h5_size_t -H5FedSetAdditionalNumTetrahedraToStore ( - h5_file * f, - const h5_size_t num_tet - ); - -h5_size_t -H5FedGetNumTetrahedra ( - h5_file * f - ); - h5_id_t H5FedStoreTetrahedron ( h5_file * f, @@ -279,257 +192,19 @@ H5FedStoreTetrahedron ( const h5_id_t vertex_ids[4] ); +h5_err_t +H5FedStartTraverseTetrahedra ( + h5_file * f + ); + h5_id_t -H5FedGetTetrahedron ( +H5FedTraverseTetrahedra ( h5_file * f, h5_id_t * const id, - h5_id_t * parent_id, + h5_id_t * const parent_id, h5_id_t vertex_ids[4] ); -/****** UPWARD ADJACENCY routines *********************************************/ - -h5_id_t * H5FedGetEdgesUAdjacentToVertex ( - h5_file * fh, - const h5_id_t level, - const h5_id_t vertex_id, - h5_size_t * const num_adj_edges - ); - -h5_id_t * H5FedGetTrianglesUAdjacentToVertex ( - h5_file * fh, - const h5_id_t level, - const h5_id_t vertex_id, - h5_size_t * const num_adj_triangles -); - -h5_id_t * H5FedGetTetrahedrasUAdjacentToVertex ( - h5_file * fh, - const h5_id_t level, - const h5_id_t vertex_id, - h5_size_t * const num_adj_tetrahedra - ); - -h5_id_t * H5FedGetTrianglesUAdjacentToEdge ( - h5_file * fh, - const h5_id_t level, - const h5_id_t edge_id, - h5_size_t * const num_adj_triangles - ); - -h5_id_t * H5FedGetTetrahedraUAdjacentToEdge ( - h5_file * fh, - const h5_id_t level, - const h5_id_t edge_id, - h5_size_t * const num_adj_tets - ); - -h5_id_t * H5FedGetTetrahedraUAdjacentToTriangle ( - h5_file * fh, - const h5_int_t level, - const h5_int_t triangle_id, - h5_size_t * const num_adj_tets - ); - -/****** DOWNWARD ADJACENCY routines *********************************************/ - -h5_id_t * H5FedGetVerticesDAdjacentToEdge ( - h5_file * fh, - const h5_int_t level, - const h5_int_t edge_id, - h5_size_t * const num_adj_vertices - ); - -h5_id_t * H5FedGetEdjesDAdjacentToTriangle ( - h5_file * fh, - const h5_id_t level, - const h5_id_t triangle_id, - h5_size_t * const num_adj_triangles - ); - -h5_id_t * H5FedGetVerticesDAdjacentToTriangle ( - h5_file * fh, - const h5_id_t level, - const h5_id_t triangle_id, - h5_size_t * const num_adj_vertices - ); - -h5_id_t * H5FedGetTrianglesDAdjacentToTetrahedron ( - h5_file * fh, - const h5_id_t level, - const h5_id_t tet_id, - h5_size_t * const num_adj_triangles - ); - -h5_id_t * H5FedGetEdjesDAdjacentToTetrahedron ( - h5_file * fh, - const h5_id_t level, - const h5_id_t tet_id, - h5_size_t * const num_adj_edges - ); - -h5_id_t * H5FedGetVerticesDAdjacentToTetrahedron ( - h5_file * fh, - const h5_id_t level, - const h5_id_t tet_id, - h5_size_t * const num_adj_vertices - ); - -/****** routines for accessing degrees of freedom DoF *************************/ - -/* DoF acces for vertices */ - -h5_int_t H5FedStoreDoFVertexFloat ( - h5_file * fh, - const h5_id_t vertex_id, - const h5_float_t * const dof, - const h5_size_t dof_size - ); - -h5_int_t H5FedStoreDoFVertexComplex ( - h5_file * fh, - const h5_id_t vertex_id, - const h5_complex * const dof, - const h5_size_t dof_size - ); - -h5_float_t * H5FedGetDoFVertexFloat ( - h5_file * fh, - const h5_id_t vertex_id, - h5_size_t * const dof_size - ); - -h5_complex * H5FedGetDoFVertexComplex ( - h5_file * fh, - const h5_id_t vertex_id, - h5_size_t * const dof_size - ); - -h5_size_t H5FedGetNumDoFVertexFloat ( - h5_file * fh, - const h5_id_t vertex_id - ); - -h5_size_t H5FedGetNumDoFVertexComplex ( - h5_file * fh, - const h5_size_t vertex_id - ); - -/* DoF access for edges */ - -h5_int_t H5FedStoreDoFEdgeFloat ( - h5_file * fh, - const h5_id_t edge_id, - const h5_float_t * const dof, - const h5_size_t dof_size - ); - -h5_int_t H5FedStoreDoFEdgeComplex ( - h5_file * fh, - const h5_id_t edge_id, - const h5_complex * const dof, - const h5_size_t dof_size - ); - -h5_float_t * H5FedGetDoFEdgeFloat ( - h5_file * fh, - const h5_id_t edge_id, - h5_size_t * const dof_size - ); - -h5_complex* H5FedGetDoFEdgeComplex ( - h5_file * fh, - const h5_id_t edge_id, - h5_size_t * const dof_size - ); - -h5_size_t H5FedGetNumDoFEdgeFloat ( - h5_file * fh, - const h5_id_t edge_id - ); - -h5_size_t H5FedGetNumDoFEdgeComplex ( - h5_file * fh, - const h5_id_t edge_id - ); - - -/* DoF access for triangles */ - -h5_int_t H5FedStoreDoFTriangleFloat ( - h5_file * fh, - const h5_id_t triangle_id, - const h5_float_t * const dof, - const h5_size_t dof_size - ); - -h5_int_t H5FedStoreDoFTriangleComplex ( - h5_file * fh, - const h5_id_t triangle_id, - const h5_complex * const dof, - const h5_size_t dof_size - ); - -h5_float_t * H5FedGetDoFTriangleFloat ( - h5_file* fh, - const h5_id_t triangle_id, - h5_size_t * const dof_size - ); - -h5_complex * H5FedGetDoFTriangleComplex ( - h5_file * fh, - const h5_id_t triangle_id, - h5_size_t * const dof_size - ); - -h5_size_t H5FedGetNumDoFTriangleFloat ( - h5_file * fh, - const h5_id_t triangle_id - ); - -h5_size_t H5FedGetNumDoFTriangleComplex ( - h5_file * fh, - const h5_id_t triangle_id - ); - -/* DoF access for tetrahedra */ - -h5_int_t H5FedStoreDoFTetrahedronFloat ( - h5_file * fh, - const h5_id_t tet_id, - const h5_float_t * const dof, - const h5_size_t dof_size - ); - -h5_int_t H5FedStoreDoFTetrahedronComplex ( - h5_file * fh, - const h5_id_t tet_id, - const h5_complex * const dof, - const h5_size_t dof_size - ); - -h5_float_t * H5FedGetDoFTetrahedronFloat ( - h5_file * fh, - const h5_id_t tet_id, - h5_size_t * const dof_size - ); - -h5_complex * H5FedGetDoFTetrahedronComplex ( - h5_file * fh, - const h5_id_t tet_id, - h5_size_t * const dof_size - ); - -h5_size_t H5FedGetNumDoFTetrahedronFloat ( - h5_file * fh, - const h5_id_t tet_id - ); - -h5_size_t H5FedGetNumDoFTetrahedronComplex ( - h5_file * fh, - const h5_id_t tet_id - ); - #endif diff --git a/src/H5Fed_inquiry.c b/src/H5Fed_inquiry.c index db92164..8b0d34f 100644 --- a/src/H5Fed_inquiry.c +++ b/src/H5Fed_inquiry.c @@ -19,50 +19,17 @@ #include #include -#include "h5/h5.h" +#include "h5/h5_core.h" #include "h5/h5_private.h" #include "H5Fed.h" -/*! - \ingroup h5fed_mesh_inquiry - - Check whether a tetrahedral mesh hierarchy exists on level \c level - - \return \c 1 tetrahedral mesh hierarchy exists on given level. - \return \c 0 tetrahedral mesh exists, but not on given level. - \return \c -1 tetrahedral mesh doesn't exist - */ -h5_int_t H5FedHasTetrahedralMesh ( - h5_file * fh, /*!< file handle */ - const h5_id_t level /*!< mesh level to check */ - ) { - SET_FNAME ( __func__ ); - return -1; -} - -/*! - \ingroup h5fed_mesh_inquiry - - Check whether a triangle mesh hierarchy exists on level \c level - - \return \c 1 boundary mesh hierarchy exists on given level. - \return \c 0 boundary mesh hierarchy exists, but not on given level. - \return \c -1 boundary mesh doesn't exist. -*/ -h5_int_t H5FedHasTriangleMesh( - h5_file * fh, /*!< file handle */ - const h5_id_t level /*!< mesh level to check */ - ) { - SET_FNAME ( __func__ ); - return -1; -} - h5_size_t H5FedGetNumMeshes ( - h5_file * f /*!< file handle */ + h5_file * f, /*!< file handle */ + const enum h5_mesh_types type ) { SET_FNAME ( __func__ ); - return H5t_get_num_meshes ( f ); + return h5t_get_num_meshes ( f, type ); } /*! @@ -74,11 +41,27 @@ H5FedGetNumMeshes ( \return \c -1 on error */ h5_size_t -H5FedGetNumRefinementLevels ( - h5_file * f /*!< file handle */ +H5FedGetNumLevels ( + h5_file * fh /*!< file handle */ ) { SET_FNAME ( __func__ ); - return H5t_get_num_levels ( f ); + return h5t_get_num_levels ( fh ); +} + +h5_id_t +H5FedGetLevel ( + h5_file * fh /*!< file handle */ + ) { + SET_FNAME ( __func__ ); + return h5t_get_level ( fh ); +} + +h5_size_t +H5FedGetNumVertices ( + h5_file * fh /*!< file handle */ + ) { + SET_FNAME ( __func__ ); + return h5t_get_num_vertices ( fh ); } /*! @@ -90,11 +73,12 @@ H5FedGetNumRefinementLevels ( \return number of vertices \return \c -1 on error. */ -h5_size_t H5FedGetNumVerticesTotal( - h5_file * fh, /*!< file handle */ - const h5_id_t level /*!< mesh level to query */ +h5_size_t +H5FedGetNumVerticesTotal( + h5_file * fh /*!< file handle */ ) { - return -1; + SET_FNAME ( __func__ ); + return h5t_get_num_vertices ( fh ); } /*! @@ -108,60 +92,6 @@ q \return \c -1 on error. */ h5_size_t H5FedGetNumVerticesCnode ( h5_file * fh, /*!< file handle */ - const h5_id_t level, /*!< mesh level to query */ - const h5_id_t cnode /*!< compute node */ - ) { - return -1; -} - -/*! - \ingroup h5fed_c_api - - Get the number of vertices used for defining a submesh - at level \c level for this compute node in current step. - - \return number of vertices - \return \c -1 on error. -*/ -h5_size_t -H5FedGetNumVertices ( - h5_file * f /*!< file handle */ - ) { - SET_FNAME ( __func__ ); - return H5t_get_num_vertices ( f ); -} - -/****** EDGE statistics routines ********************************************/ - - -/*! - \ingroup h5fed_mesh_inquiry - - Returns the number of edges present in the mesh at level \c level, - in current step, summed up over all compute nodes - - \return number of edges - \return \c -1 on error. -*/ -h5_size_t H5FedGetNumEdgesTotal ( - h5_file * fh, /*!< file handle */ - const h5_id_t level /*!< mesh level to query */ - ) { - return -1; -} - -/*! - \ingroup h5fed_mesh_inquiry - - Returns the number of edges present in the mesh at level \c level - on compute node \c cnode - - \return number of edges - \return \c -1 on error. -*/ -h5_size_t H5FedGetNumEdgesCnode ( - h5_file * fh, /*!< file handle */ - const h5_id_t level, /*!< mesh level to query */ const h5_id_t cnode /*!< compute node */ ) { return -1; @@ -169,6 +99,13 @@ h5_size_t H5FedGetNumEdgesCnode ( /****** TRIANGLE statistics routines *****************************************/ +h5_size_t +H5FedGetNumTriangles ( + h5_file * fh /*!< file handle */ + ) { + return h5t_get_num_entities ( fh ); +} + /*! \ingroup h5fed_mesh_inquiry @@ -178,13 +115,14 @@ h5_size_t H5FedGetNumEdgesCnode ( \return Number of triangles \return \c -1 on error. */ -h5_size_t H5FedGetNumTrianglesTotal ( - h5_file * fh, /*!< file handle */ - const h5_id_t level /*!< mesh level to query */ +h5_size_t +H5FedGetNumTrianglesTotal ( + h5_file * fh /*!< file handle */ ) { - return -1; + return h5t_get_num_entities ( fh ); } + /*! \ingroup h5fed_mesh_inquiry @@ -194,10 +132,10 @@ h5_size_t H5FedGetNumTrianglesTotal ( \return Number of triangles \return \c -1 on error. */ -h5_size_t H5FedGetNumTrianglesCnode ( +h5_size_t +H5FedGetNumTrianglesCnode ( h5_file * fh, /*!< file handle */ - const h5_id_t level, /*!< mesh level to query */ - const h5_id_t cnode /*!< compute node */ + const h5_id_t cnode /*!< compute node to query */ ) { return -1; } @@ -213,11 +151,12 @@ h5_size_t H5FedGetNumTrianglesCnode ( \return number of tetrahedra \return \c -1 on error. */ -h5_size_t H5FedGetNumTetrahedraTotal( - h5_file * fh, /*!< file handle */ - const h5_id_t level /*!< mesh level to query */ +h5_size_t +H5FedGetNumTetrahedraTotal( + h5_file * fh /*!< file handle */ ) { - return -1; + SET_FNAME ( __func__ ); + return h5t_get_num_entities ( fh ); } /*! @@ -231,29 +170,11 @@ h5_size_t H5FedGetNumTetrahedraTotal( */ h5_size_t H5FedGetNumTetrahedraCnode ( h5_file * fh, /*!< file handle */ - const h5_id_t level, /*!< mesh level to query */ - const h5_id_t cnode /*!< compute node */ + const h5_id_t level /*!< mesh level to query */ ) { return -1; } -/*! - \ingroup h5fed_c_api - - Returns the number of tetrahedral elements present in the mesh at - level \c level in current step on this compute node. - - \return number of tetrahedra - \return \c -1 on error. -*/ -h5_size_t -H5FedGetNumTetrahedra ( - h5_file * f /*!< file handle */ - ) { - SET_FNAME ( __func__ ); - return H5t_get_num_tets ( f ); -} - /****** BOUNDARY statistics routines ****************************************/ diff --git a/src/H5Fed_retrieve.c b/src/H5Fed_retrieve.c index 6cb0f12..667feff 100644 --- a/src/H5Fed_retrieve.c +++ b/src/H5Fed_retrieve.c @@ -16,10 +16,18 @@ #include #include -#include "h5/h5.h" +#include "h5/h5_core.h" #include "h5/h5_private.h" #include "H5Fed.h" +h5_err_t +H5FedStartTraverseVertices ( + h5_file * f /*!< file handle */ + ) { + SET_FNAME ( __func__ ); + return h5t_start_traverse_vertices ( f ); +} + /*! \ingroup h5fed_c_api @@ -29,16 +37,48 @@ \return error code (H5_ERR_NOENT means no more vertices on this level) */ -h5_id_t -H5FedGetVertex ( +h5_err_t +H5FedTraverseVertices ( h5_file * f, /*!< file handle */ h5_id_t * const id, /*!< OUT: global id */ h5_float64_t P[3] /*!< OUT: coordinates */ ) { SET_FNAME ( __func__ ); - return H5t_get_vertex ( f, id, P ); + return h5t_traverse_vertices ( f, id, P ); } + + +h5_err_t +H5FedStartTraverseTriangles ( + h5_file * f /*!< file handle */ + ) { + SET_FNAME ( __func__ ); + return h5t_start_traverse_triangles ( f ); +} + +h5_err_t +H5FedTraverseTriangles ( + h5_file * f, /*!< file handle */ + h5_id_t * const id, /*!< OUT: global tetrahedron id */ + h5_id_t * const parent_id, /*!< OUT: parent id if level + \c >0 else \c -1 */ + h5_id_t vertex_ids[3] /*!< OUT: vertex id's */ + ) { + SET_FNAME ( __func__ ); + return h5t_traverse_triangles ( f, id, parent_id, vertex_ids ); +} + + +h5_err_t +H5FedStartTraverseTetrahedra ( + h5_file * f /*!< file handle */ + ) { + SET_FNAME ( __func__ ); + return h5t_start_traverse_tets ( f ); +} + + /*! \ingroup h5fed_c_api @@ -49,15 +89,16 @@ H5FedGetVertex ( \return pointer to 4-tuple of vertex id's defining the tetrahedron. \return NULL-pointer on error. */ -h5_id_t -H5FedGetTetrahedron ( +h5_err_t +H5FedTraverseTetrahedra ( h5_file * f, /*!< file handle */ h5_id_t * const id, /*!< OUT: global tetrahedron id */ - h5_id_t * parent_id, /*!< OUT: parent id if level + h5_id_t * const parent_id, /*!< OUT: parent id if level \c >0 else \c -1 */ h5_id_t vertex_ids[4] /*!< OUT: vertex id's */ ) { SET_FNAME ( __func__ ); - return H5t_get_tet ( f, id, parent_id, vertex_ids ); + return h5t_traverse_tets ( f, id, parent_id, vertex_ids ); } + diff --git a/src/H5Fed_store.c b/src/H5Fed_store.c index adfb0ac..cdefb38 100644 --- a/src/H5Fed_store.c +++ b/src/H5Fed_store.c @@ -15,7 +15,7 @@ #include #include -#include "h5/h5.h" +#include "h5/h5_core.h" #include "h5/h5_private.h" #include "H5Fed.h" @@ -32,16 +32,16 @@ \note write new level: H5FedAddLevel( f ); - H5FedSetNumVertices( f, nv ); - H5FedSetNumTetrahedra( f, nt ); + H5FedAddNumVertices( f, nv ); + H5FedAddNumEntities( f, ne ); */ h5_id_t -H5FedAddRefinementLevel ( +H5FedAddLevel ( h5_file * f /*!< file handle */ ) { SET_FNAME ( __func__ ); - return H5t_add_level ( f ); + return h5t_add_level ( f ); } /*! @@ -59,15 +59,14 @@ H5FedAddRefinementLevel ( \return number of vertices \return errno on error */ - -h5_size_t -H5FedSetAdditionalNumVerticesToStore ( +h5_err_t +H5FedAddNumVertices ( h5_file * f, /*!< file handle */ const h5_size_t num /*!< number of additional vertices */ ) { SET_FNAME ( __func__ ); - return H5t_add_num_vertices ( f, num ); + return h5t_add_num_vertices ( f, num ); } /*! @@ -87,20 +86,20 @@ H5FedStoreVertex ( ) { SET_FNAME ( __func__ ); - return H5t_store_vertex ( f, id, P ); + return h5t_store_vertex ( f, id, P ); } /*** T E T R A H E D R A ****************************************************/ -h5_size_t -H5FedSetAdditionalNumTetrahedraToStore ( +h5_err_t +H5FedAddNumEntities ( h5_file * f, /*!< file handle */ const h5_size_t num /*!< number of additional - tetrahedra at level \c level */ + entities on current level */ ) { SET_FNAME ( __func__ ); - return H5t_add_num_tets ( f, num ); + return h5t_add_num_entities ( f, num ); } /*! @@ -126,5 +125,17 @@ H5FedStoreTetrahedron ( const h5_id_t vertex_ids[4] /*!< tuple with vertex id's */ ) { SET_FNAME ( __func__ ); - return H5t_store_tet ( f, id, parent_id, vertex_ids ); + return h5t_store_tet ( f, id, parent_id, vertex_ids ); +} + +h5_id_t +H5FedStoreTriangle ( + h5_file * f, /*!< file handle */ + const h5_id_t id, /*!< global tetrahedron id */ + const h5_id_t parent_id, /*!< global parent id + if level \c >0 else \c -1 */ + h5_id_t vertex_ids[3] /*!< tuple with vertex id's */ + ) { + SET_FNAME ( __func__ ); + return h5t_store_triangle ( f, id, parent_id, vertex_ids ); } diff --git a/src/H5_inquiry.c b/src/H5_inquiry.c index 0c9b8f4..09028a9 100644 --- a/src/H5_inquiry.c +++ b/src/H5_inquiry.c @@ -31,12 +31,12 @@ \return Number of compute notes. \return \c -1 on error. */ -h5_int_t +h5_size_t H5GetNumNodes ( - h5_file * fh /*!< file handle */ + h5_file * f /*!< file handle */ ) { SET_FNAME ( __func__ ); - return (h5_int_t)fh->nprocs; + return (h5_size_t)fh->nprocs; } /*` diff --git a/src/h5/errorhandling.c b/src/h5/errorhandling.c index 2ead321..ed3230d 100644 --- a/src/h5/errorhandling.c +++ b/src/h5/errorhandling.c @@ -11,32 +11,32 @@ #include "H5Part.h" h5_error_handler _err_handler = h5_report_errorhandler; -h5_int64_t _h5part_errno = H5PART_SUCCESS; -h5_int64_t _debug = 0; +h5_err_t _h5part_errno = H5PART_SUCCESS; +h5_id_t _debug = 0; static char *__funcname = "NONE"; -h5part_int64_t +h5_err_t h5_set_debuglevel ( - h5part_int64_t level + h5_id_t level ) { _debug = level; - return H5PART_SUCCESS; + return H5_SUCCESS; } -h5part_int64_t +h5_err_t h5_get_debuglevel ( void ) { return _debug; } -h5part_int64_t +h5_err_t h5_set_errorhandler ( - h5part_error_handler handler + h5_error_handler handler ) { _err_handler = handler; - return H5PART_SUCCESS; + return H5_SUCCESS; } h5part_error_handler @@ -46,7 +46,7 @@ h5_get_errorhandler ( return _err_handler; } -h5part_int64_t +h5_err_t h5_get_errno ( void ) { @@ -62,10 +62,10 @@ h5_get_errno ( \return value given in \c eno */ -h5part_int64_t +h5_err_t h5_report_errorhandler ( const char *funcname, - const h5part_int64_t eno, + const h5_err_t eno, const char *fmt, ... ) { @@ -86,10 +86,10 @@ h5_report_errorhandler ( If an error occures, an error message will be printed and the program exists with the error code given in \c eno. */ -h5part_int64_t +h5_err_t h5_abort_errorhandler ( const char *funcname, - const h5part_int64_t eno, + const h5_err_t eno, const char *fmt, ... ) { diff --git a/src/h5/errorhandling.h b/src/h5/errorhandling.h index c89fcbd..541dbf7 100644 --- a/src/h5/errorhandling.h +++ b/src/h5/errorhandling.h @@ -6,17 +6,17 @@ #define h5_warn h5_print_warn #define h5_error h5_print_error -h5part_int64_t +h5_err_t h5_set_debuglevel ( - h5part_int64_t level + h5_id_t level ); -h5part_int64_t +h5_err_t h5_get_debuglevel ( void ); -h5part_int64_t +h5_err_t h5_set_errorhandler ( h5part_error_handler handler ); @@ -26,23 +26,23 @@ h5_get_errorhandler ( void ); -h5part_int64_t +h5_err_t h5_get_errno ( void ); -h5part_int64_t +h5_err_t h5_report_errorhandler ( const char *funcname, - const h5part_int64_t eno, + const h5_err_t eno, const char *fmt, ... ); -h5part_int64_t +h5_err_t h5_abort_errorhandler ( const char *funcname, - const h5part_int64_t eno, + const h5_err_t eno, const char *fmt, ... ) ; diff --git a/src/h5/general.c b/src/h5/general.c index 38d3d1c..35dc1dc 100644 --- a/src/h5/general.c +++ b/src/h5/general.c @@ -446,7 +446,8 @@ h5_err_t h5_get_stepname_fmt ( h5_file * f, char *name, - h5_int64_t *width + const h5_size_t l_name, + h5_size_t *width ) { return -1; } diff --git a/src/h5/h5_core.h b/src/h5/h5_core.h index 3cbe4bb..2f07e2c 100644 --- a/src/h5/h5_core.h +++ b/src/h5/h5_core.h @@ -27,6 +27,14 @@ h5_define_stepname_fmt ( const h5part_int64_t width ); +h5_err_t +h5_get_stepname_fmt ( + h5_file *f, + char *name, + const h5_size_t l_name, + h5_size_t *width + ); + h5_err_t _h5_close_step ( h5_file *f @@ -38,6 +46,11 @@ h5_has_step ( h5_int64_t step ); +h5_int64_t +h5_get_step ( + h5_file *f + ); + #include "attribs.h" #include "errorhandling.h" #include "readwrite.h" diff --git a/src/h5/h5_private.h b/src/h5/h5_private.h index c59688b..cfda1b1 100644 --- a/src/h5/h5_private.h +++ b/src/h5/h5_private.h @@ -6,13 +6,6 @@ #define H5B_CONTAINER_GRPNAME "Block" #define H5T_CONTAINER_GRPNAME "Topo" -#define H5T_COORD_GRPNAME "COORD" -#define H5T_COORD3D_DSNAME "COORD3D" -#define H5T_COORD3D_NUM_ELEMS_DSNAME "COORD3D_NUM_ELEMS" -#define H5T_VMESH_GRPNAME "VOLUME_MESH" -#define H5T_TETMESH_DSNAME "TETMESH" -#define H5T_TETMESH_NUM_ELEMS_DSNAME "TETMESH_NUM_ELEMS" -#define H5T_TETMESH_NUM_ELEMS_ON_LEVEL_DSNAME "TETMESH_NUM_ELEMS_ON_LEVEL" #define H5BLOCK_GROUPNAME_BLOCK H5B_CONTAINER_GRPNAME diff --git a/src/h5/h5_types.h b/src/h5/h5_types.h index d9d7223..758233a 100644 --- a/src/h5/h5_types.h +++ b/src/h5/h5_types.h @@ -34,6 +34,7 @@ typedef __int64 int64_t; #endif /* WIN32 */ typedef int64_t h5_int64_t; +typedef int32_t h5_int32_t; typedef h5_int64_t h5_int_t; typedef h5_int64_t h5part_int64_t; typedef int32_t h5_id_t; @@ -44,13 +45,16 @@ typedef double h5_float64_t; typedef h5_float64_t h5_float_t; typedef h5_float64_t h5part_float64_t; -typedef h5_err_t h5_int32_t; - struct h5_complex { h5_float64_t r,i; }; typedef struct h5_complex h5_complex; +enum h5_mesh_types { + TETRAHEDRAL_MESH, + TRIANGLE_MESH +}; + struct h5_vertex { /* 32Byte */ h5_id_t id; h5_id_t unused; /* for right alignment */ @@ -85,7 +89,7 @@ typedef struct h5_edge h5_edge; typedef struct h5_triangle h5_triangle; typedef struct h5_tetrahedron h5_tetrahedron; -typedef h5_int64_t (*h5_error_handler)( const char*, const h5_int64_t, const char*,...) +typedef h5_err_t (*h5_error_handler)( const char*, const h5_err_t, const char*,...) #ifdef __GNUC__ __attribute__ ((format (printf, 3, 4))) #endif @@ -146,8 +150,15 @@ struct h5b_fdata { struct h5t_fdata_level { }; +union entities { + h5_tetrahedron *tets; + h5_triangle *tris; + void *data; +}; + struct h5t_fdata { char mesh_name[16]; + enum h5_mesh_types mesh_type; h5_id_t cur_mesh; h5_id_t new_mesh; /* idx of the first new mesh or -1 */ h5_id_t num_meshes; @@ -157,24 +168,25 @@ struct h5t_fdata { h5_size_t num_levels; h5_size_t *num_vertices; - h5_size_t *num_tets; - h5_size_t *num_tets_on_level; - h5_size_t *map_tets_g2l; + h5_size_t *num_entities; + h5_size_t *num_entities_on_level; + h5_size_t *map_entity_g2l;/* map global id to local id */ h5_id_t last_retrieved_vertex_id; h5_id_t last_stored_vertex_id; - h5_vertex * vertices; + h5_vertex *vertices; - h5_id_t last_retrieved_tet_id; - h5_id_t last_stored_tet_id; - h5_tetrahedron * tets; + h5_id_t last_retrieved_entity_id; + h5_id_t last_stored_entity_id; + + hid_t entity_tid; + union entities entities; /* HDF5 objects */ hid_t topo_gid; /* grp id of mesh in current level */ + hid_t meshes_gid; hid_t mesh_gid; - hid_t coord_gid; - hid_t vmesh_gid; /* type ids' for compound types */ hid_t float64_3tuple_tid; @@ -182,6 +194,7 @@ struct h5t_fdata { hid_t int32_3tuple_tid; hid_t int32_4tuple_tid; hid_t vertex_tid; + hid_t triangle_tid; hid_t tet_tid; }; diff --git a/src/h5/t_openclose.c b/src/h5/t_openclose.c index bf73472..2ea66be 100644 --- a/src/h5/t_openclose.c +++ b/src/h5/t_openclose.c @@ -15,7 +15,9 @@ extern h5part_error_handler _err_handler; extern h5part_int64_t _h5part_errno; extern unsigned _debug; - +/* + create several HDF5 types +*/ static h5_err_t _create_array_types ( h5_file * f @@ -95,6 +97,57 @@ _create_vertex_type ( return H5_SUCCESS; } +static h5_err_t +_create_triangle_type ( + h5_file * f + ) { + struct h5t_fdata *t = &f->t; + + hid_t hid = H5Tcreate ( H5T_COMPOUND, sizeof(struct h5_triangle) ); + if ( hid < 0 ) { + return HANDLE_H5T_CREATE_ERR ( "H5T_COMPOUND", "triangle" ); + } + t->triangle_tid = hid; + + herr_t herr = H5Tinsert ( + t->triangle_tid, + "id", + HOFFSET(struct h5_triangle, id), + H5T_NATIVE_INT32 ); + if ( herr < 0 ) { + return HANDLE_H5T_INSERT_ERR ( "id", "triangle" ); + } + + herr = H5Tinsert ( + t->triangle_tid, + "parent_id", + HOFFSET(struct h5_triangle, parent_id), + H5T_NATIVE_INT32 ); + if ( herr < 0 ) { + return HANDLE_H5T_INSERT_ERR ( "parent_id", "triangle" ); + } + + herr = H5Tinsert ( + t->triangle_tid, + "refined_on_level", + HOFFSET(struct h5_triangle, refined_on_level), + H5T_NATIVE_INT32 ); + if ( herr < 0 ) { + return HANDLE_H5T_INSERT_ERR ( "refined_on_level", "triangle" ); + } + + herr = H5Tinsert ( + t->triangle_tid, + "vertex_ids", + HOFFSET(struct h5_triangle, vertex_ids), + t->int32_3tuple_tid ); + if ( herr < 0 ) { + return HANDLE_H5T_INSERT_ERR ( "vertex_ids", "triangle" ); + } + + return H5_SUCCESS; +} + static h5_err_t _create_tet_type ( h5_file * f @@ -168,12 +221,11 @@ _h5t_init_fdata ( t->new_level = -1; t->cur_level = -1; t->last_stored_vertex_id = -1; - t->last_stored_tet_id = -1; + t->last_stored_entity_id = -1; t->topo_gid = -1; + t->meshes_gid = -1; t->mesh_gid = -1; - t->coord_gid = -1; - t->vmesh_gid = -1; - + return H5_SUCCESS; } @@ -198,6 +250,7 @@ _h5t_open_file ( if (( h5err = _create_array_types ( f )) < 0 ) return h5err; if (( h5err = _create_vertex_type ( f )) < 0 ) return h5err; + if (( h5err = _create_triangle_type ( f )) < 0 ) return h5err; if (( h5err = _create_tet_type ( f )) < 0 ) return h5err; return H5_SUCCESS; diff --git a/src/h5/t_readwrite.c b/src/h5/t_readwrite.c index 7d17ed4..a8049ed 100644 --- a/src/h5/t_readwrite.c +++ b/src/h5/t_readwrite.c @@ -62,7 +62,7 @@ _open_topo_group ( } static h5_err_t -_open_mesh_group ( +_open_meshes_group ( h5_file * f ) { struct h5t_fdata *t = &f->t; @@ -71,38 +71,33 @@ _open_mesh_group ( h5_err_t h5err = _open_topo_group ( f ); if ( h5err < 0 ) return h5err; } - t->mesh_gid = _open_group ( f, t->topo_gid, t->mesh_name ); + switch ( t->mesh_type) { + case TETRAHEDRAL_MESH: + t->meshes_gid = _open_group ( f, t->topo_gid, "TetMeshes" ); + break; + case TRIANGLE_MESH: + t->meshes_gid = _open_group ( f, t->topo_gid, "TriangleMeshes" ); + break; + default: + t->meshes_gid = -1; + } + return (h5_err_t)t->meshes_gid; +} + +static h5_err_t +_open_mesh_group ( + h5_file * f + ) { + struct h5t_fdata *t = &f->t; + + if ( t->meshes_gid < 0 ) { + h5_err_t h5err = _open_meshes_group ( f ); + if ( h5err < 0 ) return h5err; + } + t->mesh_gid = _open_group ( f, t->meshes_gid, t->mesh_name ); return (h5_err_t)t->mesh_gid; } -static h5_err_t -_open_coord_group ( - h5_file * f - ) { - struct h5t_fdata *t = &f->t; - - if ( t->mesh_gid < 0 ) { - h5_err_t h5err = _open_mesh_group ( f ); - if ( h5err < 0 ) return h5err; - } - t->coord_gid = _open_group ( f, t->mesh_gid, H5T_COORD_GRPNAME ); - return (h5_err_t) t->coord_gid; -} - -static h5_err_t -_open_vmesh_group ( - h5_file * f - ) { - struct h5t_fdata *t = &f->t; - - if ( t->mesh_gid < 0 ) { - h5_err_t h5err = _open_mesh_group ( f ); - if ( h5err < 0 ) return h5err; - } - t->vmesh_gid = _open_group ( f, t->mesh_gid, H5T_VMESH_GRPNAME ); - return (h5_err_t) t->vmesh_gid; -} - static h5_err_t _write_obj ( h5_file * f, @@ -154,78 +149,78 @@ _write_vertices ( if ( t->num_vertices <= 0 ) return H5_SUCCESS; /* ???? */ - if ( t->coord_gid < 0 ) { - h5err = _open_coord_group ( f ); + if ( t->mesh_gid < 0 ) { + h5err = _open_mesh_group ( f ); if ( h5err < 0 ) return h5err; } hsize_t maxdim = H5S_UNLIMITED; h5err = _write_obj ( f, - t->coord_gid, + t->mesh_gid, t->num_vertices[t->num_levels-1], maxdim, t->vertex_tid, (void*)t->vertices, - H5T_COORD3D_DSNAME + "Vertices" ); if ( h5err < 0 ) return h5err; return _write_obj ( f, - t->coord_gid, + t->mesh_gid, t->num_levels, maxdim, H5T_NATIVE_INT32, (void*)t->num_vertices, - H5T_COORD3D_NUM_ELEMS_DSNAME + "NumVertices" ); } static h5_err_t -_write_tets ( +_write_entities ( h5_file * f ) { struct h5t_fdata *t = &f->t; h5_err_t h5err; - if ( t->num_tets <= 0 ) return H5_SUCCESS; + if ( t->num_entities <= 0 ) return H5_SUCCESS; - if ( t->vmesh_gid < 0 ) { - h5err = _open_vmesh_group ( f ); + if ( t->mesh_gid < 0 ) { + h5err = _open_mesh_group ( f ); if ( h5err < 0 ) return h5err; } hsize_t maxdim = H5S_UNLIMITED; h5err = _write_obj ( f, - t->vmesh_gid, - t->num_tets[t->num_levels-1], + t->mesh_gid, + t->num_entities[t->num_levels-1], maxdim, - t->tet_tid, - (void*)t->tets, - H5T_TETMESH_DSNAME + t->entity_tid, + (void*)t->entities.data, + "Entities" ); if ( h5err < 0 ) return h5err; h5err = _write_obj ( f, - t->vmesh_gid, + t->mesh_gid, t->num_levels, maxdim, H5T_NATIVE_INT32, - (void*)t->num_tets, - H5T_TETMESH_NUM_ELEMS_DSNAME + (void*)t->num_entities, + "NumEntities" ); if ( h5err < 0 ) return h5err; return _write_obj ( f, - t->vmesh_gid, + t->mesh_gid, t->num_levels, maxdim, H5T_NATIVE_INT32, - (void*)t->num_tets_on_level, - H5T_TETMESH_NUM_ELEMS_ON_LEVEL_DSNAME + (void*)t->num_entities_on_level, + "NumEntitiesOnLevel" ); } @@ -247,13 +242,9 @@ _write_data ( if ( t->num_levels <= 0 ) return 0; if ( t->new_mesh < 0 ) return 0; - if ( t->topo_gid < 0 ) { - h5err = _open_topo_group ( f ); - if ( h5err < 0 ) return h5err; - } h5err = _write_vertices( f ); if ( h5err < 0 ) return h5err; - h5err = _write_tets( f ); + h5err = _write_entities( f ); if ( h5err < 0 ) return h5err; return H5_SUCCESS; @@ -279,30 +270,30 @@ _release_memory ( } t->num_vertices = NULL; - if ( t->num_tets ) { - free ( t->num_tets ); + if ( t->num_entities ) { + free ( t->num_entities ); } - t->num_tets = NULL; + t->num_entities = NULL; - if ( t->num_tets_on_level ) { - free ( t->num_tets_on_level ); + if ( t->num_entities_on_level ) { + free ( t->num_entities_on_level ); } - t->num_tets_on_level = NULL; + t->num_entities_on_level = NULL; - if ( t->map_tets_g2l ) { - free ( t->map_tets_g2l ); + if ( t->map_entity_g2l ) { + free ( t->map_entity_g2l ); } - t->map_tets_g2l = NULL; + t->map_entity_g2l = NULL; if ( t->vertices ) { free ( t->vertices ); } t->vertices = NULL; - if ( t->tets ) { - free ( t->tets ); + if ( t->entities.data ) { + free ( t->entities.data ); } - t->tets = NULL; + t->entities.data = NULL; return H5_SUCCESS; } @@ -343,13 +334,30 @@ _h5t_close_mesh ( } h5_size_t -H5t_get_num_meshes ( - h5_file * f +h5t_get_num_meshes ( + h5_file * f, + const enum h5_mesh_types type ) { - return (h5_size_t)h5_get_num_objects ( - f->root_gid, - H5T_CONTAINER_GRPNAME, - H5G_GROUP ); + struct h5t_fdata *t = &f->t; + + if ( t->topo_gid < 0 ) { + h5_err_t h5err = _open_topo_group ( f ); + if ( h5err < 0 ) return h5err; + } + switch ( type ) { + case TETRAHEDRAL_MESH: + return (h5_size_t)h5_get_num_objects ( + f->t.topo_gid, + "TetMeshes", + H5G_GROUP ); + case TRIANGLE_MESH: + return (h5_size_t)h5_get_num_objects ( + f->t.topo_gid, + "TriangleMeshes", + H5G_GROUP ); + default: + return -1; + } } /* @@ -358,9 +366,10 @@ H5t_get_num_meshes ( file structure. */ h5_err_t -H5t_open_mesh ( +h5t_open_mesh ( h5_file * f, - h5_id_t id + h5_id_t id, + const enum h5_mesh_types type ) { struct h5t_fdata *t = &f->t; @@ -368,7 +377,7 @@ H5t_open_mesh ( if ( h5err < 0 ) return h5err; if ( t->num_meshes < 0 ) { - h5_size_t result = H5t_get_num_meshes ( f ); + h5_size_t result = h5t_get_num_meshes ( f, type ); t->num_meshes = ( result > 0 ? result : 0 ); } if ( (id < -1) || (id >= t->num_meshes) ) { @@ -377,7 +386,19 @@ H5t_open_mesh ( if ( id == -1 ) { /* append new mesh */ id = t->num_meshes; } - snprintf ( t->mesh_name, sizeof (t->mesh_name), "Mesh#%d", id ); + t->mesh_type = type; + snprintf ( t->mesh_name, sizeof (t->mesh_name), "%d", id ); + + switch( type ) { + case TETRAHEDRAL_MESH: + t->entity_tid = t->tet_tid; + break; + case TRIANGLE_MESH: + t->entity_tid = t->triangle_tid; + break; + default: + return -1; + } h5err = _open_mesh_group ( f ); if ( h5err < 0 ) return h5err; @@ -385,7 +406,7 @@ H5t_open_mesh ( t->cur_mesh = id; if ( id != t->num_meshes ) { /* open existing */ - t->num_levels = H5t_get_num_levels ( f ); + t->num_levels = h5t_get_num_levels ( f ); if ( t->num_levels < 0 ) return t->num_levels; } else { /* append new */ t->num_meshes++; @@ -401,7 +422,7 @@ H5t_open_mesh ( Number of levels: Number of elements in dataset H5T_COORD3D_NUM_ELEMS_DSNAME */ h5_size_t -H5t_get_num_levels ( +h5t_get_num_levels ( h5_file * f ) { struct h5t_fdata *t = &f->t; @@ -411,13 +432,13 @@ H5t_get_num_levels ( if ( t->cur_mesh < 0 ) { return HANDLE_H5_UNDEF_MESH_ERR; } - if ( t->coord_gid < 0 ) { - h5err = _open_coord_group ( f ); + if ( t->mesh_gid < 0 ) { + h5err = _open_mesh_group ( f ); if ( h5err < 0 ) return h5err; } - hid_t dset_id = H5Dopen ( t->coord_gid, H5T_COORD3D_NUM_ELEMS_DSNAME ); + hid_t dset_id = H5Dopen ( t->mesh_gid, "NumVertices" ); if ( dset_id < 0 ) - return HANDLE_H5D_OPEN_ERR ( H5T_COORD3D_NUM_ELEMS_DSNAME ); + return HANDLE_H5D_OPEN_ERR ( "NumVertices" ); hid_t space_id = H5Dget_space( dset_id ); if ( space_id < 0 ) return HANDLE_H5D_GET_SPACE_ERR; @@ -433,7 +454,7 @@ H5t_get_num_levels ( } h5_err_t -H5t_open_level ( +h5t_open_level ( h5_file * f, const h5_id_t id ) { @@ -443,13 +464,21 @@ H5t_open_level ( return HANDLE_H5_OUT_OF_RANGE_ERR ( "Level", id ); t->cur_level = id; t->last_retrieved_vertex_id = -1; - t->last_retrieved_tet_id = -1; + t->last_retrieved_entity_id = -1; return H5_SUCCESS; } h5_id_t -H5t_add_level ( +h5t_get_level ( + h5_file * f + ) { + struct h5t_fdata *t = &f->t; + return t->cur_level; +} + +h5_id_t +h5t_add_level ( h5_file * f ) { struct h5t_fdata *t = &f->t; @@ -469,22 +498,22 @@ H5t_add_level ( t->num_vertices = realloc ( t->num_vertices, num_bytes ); t->num_vertices[t->cur_level] = -1; - t->num_tets = realloc ( t->num_tets, num_bytes ); - t->num_tets[t->cur_level] = -1; - t->num_tets_on_level = realloc ( t->num_tets_on_level, num_bytes ); - t->num_tets_on_level[t->cur_level] = -1; + t->num_entities = realloc ( t->num_entities, num_bytes ); + t->num_entities[t->cur_level] = -1; + t->num_entities_on_level = realloc ( t->num_entities_on_level, num_bytes ); + t->num_entities_on_level[t->cur_level] = -1; t->new_level = t->cur_level; if ( t->cur_level == 0 ) { /* nothing stored yet */ t->last_stored_vertex_id = -1; - t->last_stored_tet_id = -1; + t->last_stored_entity_id = -1; } return t->cur_level; } -h5_size_t -H5t_add_num_vertices ( +h5_err_t +h5t_add_num_vertices ( h5_file * f, const h5_size_t num ) { @@ -503,7 +532,7 @@ H5t_add_num_vertices ( return HANDLE_H5_NOMEM_ERR; } - return num; + return H5_SUCCESS; } /* @@ -586,8 +615,8 @@ _read_num_vertices ( if ( t->cur_level < 0 ) return HANDLE_H5_UNDEF_LEVEL_ERR; - if ( t->coord_gid < 0 ) { - h5err = _open_coord_group ( f ); + if ( t->mesh_gid < 0 ) { + h5err = _open_mesh_group ( f ); if ( h5err < 0 ) return h5err; } ssize_t num_bytes = t->num_levels*sizeof ( t->num_vertices[0] ); @@ -597,8 +626,8 @@ _read_num_vertices ( return HANDLE_H5_NOMEM_ERR; h5err = _read_dataset ( f, - t->coord_gid, - H5T_COORD3D_NUM_ELEMS_DSNAME, + t->mesh_gid, + "NumVertices", H5T_NATIVE_INT32, _open_space_all, _open_space_all, @@ -618,8 +647,8 @@ _read_vertices ( if ( t->cur_level < 0 ) return HANDLE_H5_UNDEF_LEVEL_ERR; - if ( t->coord_gid < 0 ) { - h5err = _open_coord_group ( f ); + if ( t->mesh_gid < 0 ) { + h5err = _open_mesh_group ( f ); if ( h5err < 0 ) return h5err; } @@ -636,8 +665,8 @@ _read_vertices ( return HANDLE_H5_NOMEM_ERR; h5err = _read_dataset ( f, - t->coord_gid, - H5T_COORD3D_DSNAME, + t->mesh_gid, + "Vertices", t->vertex_tid, _open_mem_space_vertices, _open_file_space_vertices, @@ -648,7 +677,7 @@ _read_vertices ( } h5_size_t -H5t_get_num_vertices ( +h5t_get_num_vertices ( h5_file * f ) { struct h5t_fdata *t = &f->t; @@ -667,7 +696,7 @@ H5t_get_num_vertices ( } h5_id_t -H5t_store_vertex ( +h5t_store_vertex ( h5_file * f, /*!< file handle */ const h5_id_t id, /*!< global vertex id or -1 */ const h5_float64_t P[3] /*!< coordinates */ @@ -707,20 +736,21 @@ H5t_store_vertex ( return t->last_stored_vertex_id; } - -h5_size_t -H5t_get_vertex_ids ( - h5_file * f, - h5_id_t * const ids[] +h5_err_t +h5t_start_traverse_vertices ( + h5_file * f ) { - return -1; + struct h5t_fdata *t = &f->t; + + t->last_retrieved_vertex_id = -1; + return H5_SUCCESS; } h5_id_t -H5t_get_vertex ( +h5t_traverse_vertices ( h5_file * f, /*!< file handle */ - h5_id_t * const id, /*!< global vertex */ - h5_float64_t P[3] /*!< coordinates */ + h5_id_t * const id, /*!< OUT: global vertex id */ + h5_float64_t P[3] /*!< OUT: coordinates */ ) { struct h5t_fdata *t = &f->t; @@ -729,8 +759,8 @@ H5t_get_vertex ( if ( h5err < 0 ) return h5err; } if ( t->last_retrieved_vertex_id+1 >= t->num_vertices[t->cur_level] ) { - h5_warn ( "Trying to read more tets than available!" ); - return -1; + h5_debug ( "Traversing done!" ); + return 0; } h5_vertex *vertex = &t->vertices[++t->last_retrieved_vertex_id]; *id = vertex->id; @@ -739,39 +769,48 @@ H5t_get_vertex ( return t->last_retrieved_vertex_id; } -h5_size_t -H5t_add_num_tets ( +h5_err_t +h5t_add_num_entities ( h5_file * f, const h5_size_t num ) { struct h5t_fdata *t = &f->t; + ssize_t num_bytes = 0; + ssize_t num_entities = t->cur_level > 0 ? + num + t->num_entities[t->cur_level-1] : num; + t->num_entities[t->cur_level] = num_entities; - ssize_t num_tets = t->cur_level > 0 ? - num + t->num_tets[t->cur_level-1] : num; - t->num_tets[t->cur_level] = num_tets; + t->num_entities_on_level[t->cur_level] = t->cur_level > 0 ? + num + t->num_entities_on_level[t->cur_level-1] : num; - t->num_tets_on_level[t->cur_level] = t->cur_level > 0 ? - num + t->num_tets_on_level[t->cur_level-1] : num; - - ssize_t num_bytes = num_tets*sizeof ( t->tets[0] ); + switch ( t->mesh_type ) { + case TETRAHEDRAL_MESH: + num_bytes = num_entities*sizeof ( t->entities.tets[0] ); + break; + case TRIANGLE_MESH: + num_bytes = num_entities*sizeof ( t->entities.tris[0] ); + break; + default: + return -1; + } h5_debug ( "Allocating %ld bytes.", num_bytes ); - t->tets = realloc ( t->tets, num_bytes ); - if ( t->tets == NULL ) { + t->entities.data = realloc ( t->entities.data, num_bytes ); + if ( t->entities.data == NULL ) { return H5_ERR_NOMEM; } - t->map_tets_g2l = realloc ( - t->map_tets_g2l, - num_tets*sizeof ( t->map_tets_g2l[0] ) ); + t->map_entity_g2l = realloc ( + t->map_entity_g2l, + num_entities*sizeof ( t->map_entity_g2l[0] ) ); - return num; + return H5_SUCCESS; } h5_id_t -H5t_store_tet ( +h5t_store_tet ( h5_file * f, - const h5_id_t tet_id, /*!< global tetrahedron id */ + const h5_id_t id, /*!< global tetrahedron id */ const h5_id_t parent_id, /*!< global parent id if level \c >0 else \c -1 */ const h5_id_t vertex_ids[4] /*!< tuple with vertex id's */ @@ -782,8 +821,8 @@ H5t_store_tet ( /* more than allocated */ - if ( t->last_stored_tet_id+1 >= t->num_tets[t->cur_level] ) - return HANDLE_H5_OVERFLOW_ERR( "tet", t->num_tets[t->cur_level] ); + if ( t->last_stored_entity_id+1 >= t->num_entities[t->cur_level] ) + return HANDLE_H5_OVERFLOW_ERR( "tet", t->num_entities[t->cur_level] ); /* missing call to add the first level @@ -795,48 +834,115 @@ H5t_store_tet ( check parent id */ if ( (t->cur_level == 0) && (parent_id != -1) ) { - return HANDLE_H5_PARENT_ID_ERR ( "tet", tet_id, parent_id ); + return HANDLE_H5_PARENT_ID_ERR ( "tet", id, parent_id ); } if ( (t->cur_level > 0) && (parent_id < 0) ) { - return HANDLE_H5_PARENT_ID_ERR ( "tet", tet_id, parent_id ); + return HANDLE_H5_PARENT_ID_ERR ( "tet", id, parent_id ); } - if ( (t->cur_level > 0) && (parent_id >= t->num_tets[t->cur_level-1]) ) { - return HANDLE_H5_PARENT_ID_ERR ( "tet", tet_id, parent_id ); + if ( (t->cur_level > 0) && (parent_id >= t->num_entities[t->cur_level-1]) ) { + return HANDLE_H5_PARENT_ID_ERR ( "tet", id, parent_id ); } /* - check tet_id + check id */ if ( (t->cur_level == 0) && ( - (tet_id < 0) || (tet_id >= t->num_tets[0]) ) ) { - return HANDLE_H5_OUT_OF_RANGE_ERR( "tet", tet_id ); + (id < 0) || (id >= t->num_entities[0]) ) ) { + return HANDLE_H5_OUT_OF_RANGE_ERR( "tet", id ); } if ( (t->cur_level > 0) && ( - (tet_id < t->num_tets[t->cur_level-1]) || - (tet_id >= t->num_tets[t->cur_level]) ) ) { - return HANDLE_H5_OUT_OF_RANGE_ERR( "tet", tet_id ); + (id < t->num_entities[t->cur_level-1]) || + (id >= t->num_entities[t->cur_level]) ) ) { + return HANDLE_H5_OUT_OF_RANGE_ERR( "tet", id ); } - h5_tetrahedron *tet = &t->tets[++t->last_stored_tet_id]; - tet->id = tet_id; + h5_tetrahedron *tet = &t->entities.tets[++t->last_stored_entity_id]; + tet->id = id; tet->parent_id = parent_id; tet->refined_on_level = -1; tet->unused = 0; memcpy ( &tet->vertex_ids, vertex_ids, sizeof ( tet->vertex_ids ) ); - t->map_tets_g2l[tet_id] = t->last_stored_tet_id; + t->map_entity_g2l[id] = t->last_stored_entity_id; if ( parent_id >= 0 ) { - h5_id_t local_parent_id = t->map_tets_g2l[parent_id]; - if ( t->tets[local_parent_id].refined_on_level < 0 ) { - t->tets[local_parent_id].refined_on_level = t->cur_level; - t->num_tets_on_level[t->cur_level]--; + h5_id_t local_parent_id = t->map_entity_g2l[parent_id]; + if ( t->entities.tets[local_parent_id].refined_on_level < 0 ) { + t->entities.tets[local_parent_id].refined_on_level = t->cur_level; + t->num_entities_on_level[t->cur_level]--; } } - return t->last_stored_vertex_id; + return t->last_stored_entity_id; +} + + +h5_id_t +h5t_store_triangle ( + h5_file * f, + const h5_id_t id, /*!< global triangle id */ + const h5_id_t parent_id, /*!< global parent id + if level \c >0 else \c -1 */ + const h5_id_t vertex_ids[3] /*!< tuple with vertex id's */ + ) { + + struct h5t_fdata *t = &f->t; + + /* + more than allocated + */ + if ( t->last_stored_entity_id+1 >= t->num_entities[t->cur_level] ) + return HANDLE_H5_OVERFLOW_ERR( "triangle", t->num_entities[t->cur_level] ); + + /* + missing call to add the first level + */ + if ( t->cur_level < 0 ) + return HANDLE_H5_UNDEF_LEVEL_ERR; + + /* + check parent id + */ + if ( (t->cur_level == 0) && (parent_id != -1) ) { + return HANDLE_H5_PARENT_ID_ERR ( "triangle", id, parent_id ); + } + if ( (t->cur_level > 0) && (parent_id < 0) ) { + return HANDLE_H5_PARENT_ID_ERR ( "triangle", id, parent_id ); + } + if ( (t->cur_level > 0) && (parent_id >= t->num_entities[t->cur_level-1]) ) { + return HANDLE_H5_PARENT_ID_ERR ( "triangle", id, parent_id ); + } + /* + check id + */ + if ( (t->cur_level == 0) && ( + (id < 0) || (id >= t->num_entities[0]) ) ) { + return HANDLE_H5_OUT_OF_RANGE_ERR( "triangle", id ); + } + if ( (t->cur_level > 0) && ( + (id < t->num_entities[t->cur_level-1]) || + (id >= t->num_entities[t->cur_level]) ) ) { + return HANDLE_H5_OUT_OF_RANGE_ERR( "triangle", id ); + } + + + h5_triangle *tri = &t->entities.tris[++t->last_stored_entity_id]; + tri->id = id; + tri->parent_id = parent_id; + tri->refined_on_level = -1; + memcpy ( &tri->vertex_ids, vertex_ids, sizeof ( tri->vertex_ids ) ); + + t->map_entity_g2l[id] = t->last_stored_entity_id; + if ( parent_id >= 0 ) { + h5_id_t local_parent_id = t->map_entity_g2l[parent_id]; + if ( t->entities.tris[local_parent_id].refined_on_level < 0 ) { + t->entities.tris[local_parent_id].refined_on_level = t->cur_level; + t->num_entities_on_level[t->cur_level]--; + } + } + return t->last_stored_entity_id; } static h5_err_t -_read_num_tets ( +_read_num_entities ( h5_file * f ) { @@ -847,30 +953,30 @@ _read_num_tets ( if ( t->cur_level < 0 ) return HANDLE_H5_UNDEF_LEVEL_ERR; - if ( t->vmesh_gid < 0 ) { - h5err = _open_vmesh_group ( f ); + if ( t->mesh_gid < 0 ) { + h5err = _open_mesh_group ( f ); if ( h5err < 0 ) return h5err; } - ssize_t num_bytes = t->num_levels*sizeof ( t->num_tets[0] ); + ssize_t num_bytes = t->num_levels*sizeof ( t->num_entities[0] ); h5_debug ( "Allocating %ld bytes.", num_bytes ); - t->num_tets = realloc ( t->num_tets, num_bytes ); - if ( t->num_tets == NULL ) + t->num_entities = realloc ( t->num_entities, num_bytes ); + if ( t->num_entities == NULL ) return HANDLE_H5_NOMEM_ERR; h5err = _read_dataset ( f, - t->vmesh_gid, - H5T_TETMESH_NUM_ELEMS_DSNAME, + t->mesh_gid, + "NumEntities", H5T_NATIVE_INT32, _open_space_all, _open_space_all, - t->num_tets ); + t->num_entities ); if ( h5err < 0 ) return h5err; return H5_SUCCESS; } static h5_err_t -_read_num_tets_on_level ( +_read_num_entities_on_level ( h5_file * f ) { @@ -880,30 +986,30 @@ _read_num_tets_on_level ( if ( t->cur_level < 0 ) return HANDLE_H5_UNDEF_LEVEL_ERR; - if ( t->vmesh_gid < 0 ) { - h5err = _open_vmesh_group ( f ); + if ( t->mesh_gid < 0 ) { + h5err = _open_mesh_group ( f ); if ( h5err < 0 ) return h5err; } - ssize_t num_bytes = t->num_levels*sizeof ( t->num_tets_on_level[0] ); + ssize_t num_bytes = t->num_levels*sizeof ( t->num_entities_on_level[0] ); h5_debug ( "Allocating %ld bytes.", num_bytes ); - t->num_tets_on_level = realloc ( t->num_tets_on_level, num_bytes ); - if ( t->num_tets_on_level == NULL ) + t->num_entities_on_level = realloc ( t->num_entities_on_level, num_bytes ); + if ( t->num_entities_on_level == NULL ) return HANDLE_H5_NOMEM_ERR; h5err = _read_dataset ( f, - t->vmesh_gid, - H5T_TETMESH_NUM_ELEMS_ON_LEVEL_DSNAME, + t->mesh_gid, + "NumEntitiesOnLevel", H5T_NATIVE_INT32, _open_space_all, _open_space_all, - t->num_tets_on_level ); + t->num_entities_on_level ); if ( h5err < 0 ) return h5err; return H5_SUCCESS; } static hid_t -_open_mem_space_tets ( +_open_mem_space_entities ( h5_file * f, hid_t dataset_id ) { @@ -911,7 +1017,7 @@ _open_mem_space_tets ( } static hid_t -_open_file_space_tets ( +_open_file_space_entities ( h5_file * f, hid_t dataset_id ) { @@ -919,46 +1025,59 @@ _open_file_space_tets ( } static h5_err_t -_read_tets ( +_read_entities ( h5_file * f ) { h5_err_t h5err; + ssize_t num_bytes; struct h5t_fdata *t = &f->t; if ( t->cur_level < 0 ) return HANDLE_H5_UNDEF_LEVEL_ERR; - if ( t->vmesh_gid < 0 ) { - h5err = _open_vmesh_group ( f ); + if ( t->mesh_gid < 0 ) { + h5err = _open_mesh_group ( f ); if ( h5err < 0 ) return h5err; } - if ( t->num_tets == NULL ) { - h5err = _read_num_tets ( f ); + if ( t->num_entities == NULL ) { + h5err = _read_num_entities ( f ); if ( h5err < 0 ) return h5err; } - ssize_t num_elems = t->num_tets[t->num_levels-1]; - ssize_t num_bytes = num_elems*sizeof ( t->tets[0] ); + ssize_t num_elems = t->num_entities[t->num_levels-1]; + + switch ( t->mesh_type ) { + case TETRAHEDRAL_MESH: { + num_bytes = num_elems*sizeof ( t->entities.tets[0] ); + break; + } + case TRIANGLE_MESH: { + num_bytes = num_elems*sizeof ( t->entities.tris[0] ); + break; + } + default: + return -1; + } h5_debug ( "Allocating %ld bytes.", num_bytes ); - t->tets = realloc ( t->tets, num_bytes ); - if ( t->tets == NULL ) + t->entities.data = realloc ( t->entities.data, num_bytes ); + if ( t->entities.data == NULL ) return HANDLE_H5_NOMEM_ERR; h5err = _read_dataset ( f, - t->vmesh_gid, - H5T_TETMESH_DSNAME, - t->tet_tid, - _open_mem_space_tets, - _open_file_space_tets, - t->tets ); + t->mesh_gid, + "Entities", + t->entity_tid, + _open_mem_space_entities, + _open_file_space_entities, + t->entities.data ); if ( h5err < 0 ) return h5err; return H5_SUCCESS; } h5_size_t -H5t_get_num_tets ( +h5t_get_num_entities ( h5_file * f ) { struct h5t_fdata *t = &f->t; @@ -969,38 +1088,57 @@ H5t_get_num_tets ( if ( t->cur_level < 0 ) { return HANDLE_H5_UNDEF_LEVEL_ERR; } - if ( t->num_tets_on_level == NULL ) { - h5_err_t h5err = _read_num_tets_on_level ( f ); + if ( t->num_entities_on_level == NULL ) { + h5_err_t h5err = _read_num_entities_on_level ( f ); if ( h5err < 0 ) return h5err; } - return t->num_tets_on_level[t->cur_level]; + return t->num_entities_on_level[t->cur_level]; } -h5_id_t -H5t_get_tet ( - h5_file * f, - h5_id_t * const id, /*!< global tetrahedron id */ - h5_id_t * const parent_id, /*!< global parent id - if level \c >0 else \c -1 */ - h5_id_t ids[4] /*!< tuple with vertex id's */ +h5_err_t +h5t_start_traverse_tets ( + h5_file * f ) { struct h5t_fdata *t = &f->t; - if ( t->tets == NULL ) { - h5_err_t h5err = _read_tets ( f ); + switch ( t->mesh_type ) { + case TRIANGLE_MESH: { + return H5_ERR_INVAL; + } + case TETRAHEDRAL_MESH: { + t->last_retrieved_entity_id = -1; + return H5_SUCCESS; + } + default: + return H5_ERR_INTERNAL; + } +} + +h5_id_t +_traverse_tets ( + h5_file * f, + h5_id_t * const id, /*!< OUT: global tetrahedron id */ + h5_id_t * const parent_id, /*!< OUT: global parent id + if level \c >0 else \c -1 */ + h5_id_t ids[4] /*!< OUT: tuple with vertex id's */ + ) { + struct h5t_fdata *t = &f->t; + + if ( t->entities.data == NULL ) { + h5_err_t h5err = _read_entities ( f ); if ( h5err < 0 ) return h5err; } - if ( t->last_retrieved_tet_id+1 >= t->num_tets[t->cur_level] ) { - h5_warn ( "Trying to read more tets than available!" ); - return -1; + if ( t->last_retrieved_entity_id+1 >= t->num_entities[t->cur_level] ) { + h5_debug ( "Traversing done!" ); + return 0; } - h5_tetrahedron *tet = &t->tets[++t->last_retrieved_tet_id]; + h5_tetrahedron *tet = &t->entities.tets[++t->last_retrieved_entity_id]; while ( (tet->refined_on_level != -1) && (tet->refined_on_level <= t->cur_level) ){ tet++; - t->last_retrieved_tet_id++; - if ( t->last_retrieved_tet_id >= t->num_tets[t->cur_level] ) { + t->last_retrieved_entity_id++; + if ( t->last_retrieved_entity_id >= t->num_entities[t->cur_level] ) { return HANDLE_H5_INTERNAL_ERR; } } @@ -1009,5 +1147,107 @@ H5t_get_tet ( *parent_id = tet->parent_id; memcpy ( ids, &tet->vertex_ids, sizeof ( tet->vertex_ids ) ); - return t->last_retrieved_tet_id; + return t->last_retrieved_entity_id; +} + +h5_id_t +h5t_traverse_tets ( + h5_file * f, + h5_id_t * const id, /*!< OUT: global tetrahedron id */ + h5_id_t * const parent_id, /*!< OUT: global parent id + if level \c >0 else \c -1 */ + h5_id_t ids[4] /*!< OUT: tuple with vertex id's */ + ) { + struct h5t_fdata *t = &f->t; + + switch ( t->mesh_type ) { + case TRIANGLE_MESH: { + return H5_ERR_INVAL; + } + case TETRAHEDRAL_MESH: { + return _traverse_tets ( f, id, parent_id, ids ); + } + default: + return H5_ERR_INTERNAL; + } +} + + +h5_err_t +h5t_start_traverse_triangles ( + h5_file * f + ) { + struct h5t_fdata *t = &f->t; + + switch ( t->mesh_type ) { + case TRIANGLE_MESH: { + t->last_retrieved_entity_id = -1; + return H5_SUCCESS; + } + case TETRAHEDRAL_MESH: { + return H5_ERR_NOT_IMPLEMENTED; + } + default: + return H5_ERR_INTERNAL; + } +} + + +static h5_id_t +_traverse_triangles ( + h5_file * f, + h5_id_t * const id, /*!< OUT: global triangle id */ + h5_id_t * const parent_id, /*!< OUT: global parent id + if level \c >0 else \c -1 */ + h5_id_t ids[3] /*!< OUT: tuple with vertex id's */ + ) { + struct h5t_fdata *t = &f->t; + + if ( t->entities.data == NULL ) { + h5_err_t h5err = _read_entities ( f ); + if ( h5err < 0 ) return h5err; + } + if ( t->last_retrieved_entity_id+1 >= t->num_entities[t->cur_level] ) { + h5_debug ( "Traversing done!" ); + return 0; + } + h5_triangle *tri = &t->entities.tris[++t->last_retrieved_entity_id]; + + while ( (tri->refined_on_level != -1) && + (tri->refined_on_level <= t->cur_level) ){ + tri++; + t->last_retrieved_entity_id++; + if ( t->last_retrieved_entity_id >= t->num_entities[t->cur_level] ) { + return HANDLE_H5_INTERNAL_ERR; + } + } + + *id = tri->id; + *parent_id = tri->parent_id; + memcpy ( ids, &tri->vertex_ids, sizeof ( tri->vertex_ids ) ); + + return t->last_retrieved_entity_id; +} + +h5_id_t +h5t_traverse_triangles ( + h5_file * f, + h5_id_t * const id, /*!< OUT: global triangle id */ + h5_id_t * const parent_id, /*!< OUT: global parent id + if level \c >0 else \c -1 */ + h5_id_t ids[3] /*!< OUT: tuple with vertex id's */ + ) { + + struct h5t_fdata *t = &f->t; + + switch ( t->mesh_type ) { + case TRIANGLE_MESH: { + return _traverse_triangles ( f, id, parent_id, ids ); + } + case TETRAHEDRAL_MESH: { + return H5_ERR_NOT_IMPLEMENTED; + } + default: + return H5_ERR_INTERNAL; + } } diff --git a/src/h5/t_readwrite.h b/src/h5/t_readwrite.h index 1573927..5199052 100644 --- a/src/h5/t_readwrite.h +++ b/src/h5/t_readwrite.h @@ -11,99 +11,132 @@ _h5t_close_step ( h5_file * f ); -h5_id_t -_h5t_open_mesh ( - h5_file * f - ); - -h5_id_t +h5_err_t _h5t_close_mesh ( h5_file * f ); h5_size_t -H5t_get_num_meshes ( - h5_file * f +h5t_get_num_meshes ( + h5_file * f, + const enum h5_mesh_types type ); h5_err_t -H5t_open_mesh ( +h5t_open_mesh ( h5_file * f, - h5_id_t id + h5_id_t id, + const enum h5_mesh_types type ); h5_id_t -H5t_add_mesh ( +h5t_add_mesh ( h5_file * f ); h5_size_t -H5t_get_num_levels ( +h5t_get_num_levels ( h5_file * f ); h5_err_t -H5t_open_level ( +h5t_open_level ( h5_file * f, const h5_id_t id ); h5_id_t -H5t_add_level ( +h5t_get_level ( + h5_file * f + ); + +h5_id_t +h5t_add_level ( h5_file * f ); h5_size_t -H5t_add_num_vertices ( +h5t_add_num_vertices ( h5_file * f, const h5_size_t num ); h5_id_t -H5t_store_vertex ( +h5t_store_vertex ( h5_file * f, const h5_id_t id, const h5_float64_t P[3] ); -h5_id_t -H5t_get_num_vertices ( +h5_size_t +h5t_get_num_vertices ( + h5_file * f + ); + +h5_err_t +h5t_start_traverse_vertices ( h5_file * f ); h5_id_t -H5t_get_vertex ( +h5t_traverse_vertices ( h5_file * f, h5_id_t * const id, h5_float64_t P[3] ); h5_size_t -H5t_add_num_tets ( +h5t_add_num_entities ( h5_file * f, const h5_size_t num ) ; h5_size_t -H5t_get_num_tets ( +h5t_get_num_entities ( h5_file * f ); h5_id_t -H5t_store_tet ( +h5t_store_tet ( h5_file * f, - const h5_id_t tet_id, /*!< global tetrahedron id */ - const h5_id_t parent_id, /*!< global parent id - if level \c >0 else \c -1 */ - const h5_id_t vertex_ids[4] /*!< tuple with vertex id's */ + const h5_id_t id, + const h5_id_t parent_id, + const h5_id_t vertex_ids[4] ); h5_id_t -H5t_get_tet ( +h5t_store_triangle ( + h5_file * f, + const h5_id_t id, + const h5_id_t parent_id, + const h5_id_t vertex_ids[3] + ); + +h5_err_t +h5t_start_traverse_tets ( + h5_file * f + ); + +h5_id_t +h5t_traverse_tets ( h5_file * f, h5_id_t * const id, h5_id_t * const parent_id, h5_id_t vertex_ids[4] ); + +h5_err_t +h5t_start_traverse_triangles ( + h5_file * f + ); + +h5_id_t +h5t_traverse_triangles ( + h5_file * f, + h5_id_t * const id, + h5_id_t * const parent_id, + h5_id_t vertex_ids[3] + ); + #endif