diff --git a/.gitattributes b/.gitattributes index bafe01c..ce5ddf7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -360,7 +360,6 @@ doc/tetrahedron_refinements/6-edges/edge_01-12-20-23-30-31_refined/output_file.j doc/tetrahedron_refinements/README -text doc/tetrahedron_refinements/text2vtk.py -text /license.txt -text -/rules.make -text src/C++/H5Fed.cc -text src/C++/H5Fed.hh -text src/C++/Makefile.am -text @@ -416,6 +415,7 @@ src/h5core/h5_readwrite_private.h -text src/h5core/h5_syscall.c -text src/h5core/h5_syscall_private.h -text src/h5core/h5_types_private.h -text +src/h5core/h5_va_macros.h -text src/h5core/h5b_attribs.c -text src/h5core/h5b_errorhandling_private.h -text src/h5core/h5b_model.c -text @@ -517,6 +517,7 @@ test/H5Fed/tetmesh_adjacencies.c -text test/H5Fed/tetmesh_read.c -text test/H5Fed/tetmesh_read_tags.c -text test/H5Fed/tetmesh_write.c -text +test/H5Fed/tetmesh_write1.c -text test/H5Fed/tetmesh_write2.c -text test/H5Fed/tetmesh_write_tags.c -text test/H5Fed/trimesh_adjacencies.c -text diff --git a/configure.ac b/configure.ac index f8d650e..f6c5c55 100644 --- a/configure.ac +++ b/configure.ac @@ -131,7 +131,6 @@ fi # if one is found in the current PATH. # Otherwise, set INSTALL to `dir/install-sh -c` AC_PROG_INSTALL - AC_PROG_AWK # Disable shared libraries by default: can be enabled with --enable-shared diff --git a/rules.make b/rules.make deleted file mode 100755 index 1ce27fc..0000000 --- a/rules.make +++ /dev/null @@ -1,52 +0,0 @@ -# Makefile Rules (used by both GNUMakefile and Makefile) -# now "all" rule is defined in the main makefile -# all: H5PartTest H5PartTest.o H5Part.o - -vtkhdf.o: vtkhdf.cc - $(CXX) $(CFLAGS) -c vtkhdf.cc - -H5PartTest: H5PartTest.o H5Part.o - $(CXX) -o H5PartTest H5Part.o H5PartTest.o $(LDFLAGS) - -Bench: Bench.c H5Part.o - $(CC) $(CFLAGS) -o Bench Bench.c H5Part.o $(LDFLAGS) - -H5PartTest.o: H5PartTest.cc H5Part.hh - $(CXX) $(CFLAGS) -DREGRESSIONTEST -c H5PartTest.cc - -H5PartTestParallel.o: H5PartTestParallel.cc H5Part.hh - $(CXX) $(CFLAGS) -c H5PartTestParallel.cc - -H5PartTestParallel: H5PartTestParallel.o H5Part.o - $(CXX) -o H5PartTestParallel H5Part.o H5PartTestParallel.o $(LDFLAGS) - -H5PartAndreasTest.o: H5PartAndreasTest.cc H5Part.hh - $(CXX) $(CFLAGS) -c H5PartAndreasTest.cc - -H5PartAndreasTest: H5PartAndreasTest.o H5Part.o - $(CXX) -o H5PartAndreasTest H5Part.o H5PartAndreasTest.o $(LDFLAGS) - -H5Part.o: H5Part.c H5Part.h - $(CC) $(CFLAGS) -c H5Part.c - -H5PartF.o: H5PartF.c Underscore.h H5Part.h - $(CC) $(CFLAGS) -w -c H5PartF.c - -H5testF.o: H5testF.f H5Part.inc - $(F90) $(CFLAGS) -c H5testF.f - -H5testF: H5testF.o H5Part.o H5PartF.o - $(F90) $(CFLAGS) -o H5testF H5testF.o H5PartF.o H5Part.o $(LDFLAGS) -lC - -vtkxml.o: vtkxml.cc - $(CXX) $(CFLAGS) -c vtkxml.cc - -Underscore.h: TestUnderscore.f TestUnderscoreC.c - rm -f TestUnderscore.o TestUnderscoreC.o TestUnderscore - $(CC) -c TestUnderscoreC.c - $(F90) -c TestUnderscore.f - $(F90) -o TestUnderscore TestUnderscore.o TestUnderscoreC.o -lC - ./TestUnderscore >& Underscore.h - -clean: - rm -rf *~ *.o H5PartTest diff --git a/src/C/H5.c b/src/C/H5.c index 0682349..cf34e16 100644 --- a/src/C/H5.c +++ b/src/C/H5.c @@ -60,10 +60,8 @@ H5OpenFile ( h5_int32_t flags, /*!< file open flags */ MPI_Comm comm /*!< MPI communicator */ ) { - H5_API_ENTER2 (h5_file_p, - "filename=\"%s\", flags=%d, ...", - filename, flags); - H5_API_RETURN (h5_open_file (filename, flags, comm)); + H5_API_ENTER (h5_file_p, "filename='%s', flags=%d, ...",filename,flags); + H5_API_RETURN (h5_open_file (filename, flags, comm, 0)); } /*! @@ -77,7 +75,7 @@ h5_err_t H5CloseFile ( h5_file_t* const f /*!< file handle */ ) { - H5_API_ENTER1 (h5_err_t, "f=%p", f); + H5_API_ENTER (h5_err_t, "f=%p", f); H5_API_RETURN (h5_close_file (f)); } @@ -92,7 +90,7 @@ h5_err_t H5CheckFile ( h5_file_t* const f /*!< file handle */ ) { - H5_API_ENTER1 (h5_err_t, "f=%p", f); + H5_API_ENTER (h5_err_t, "f=%p", f); H5_API_RETURN (h5_check_filehandle (f)); } @@ -101,7 +99,7 @@ h5_err_t H5FlushStep ( h5_file_t* const f /*!< file handle */ ) { - H5_API_ENTER1 (h5_err_t, "f=%p", f); + H5_API_ENTER (h5_err_t, "f=%p", f); H5_API_RETURN (h5_flush_step (f)); } @@ -109,7 +107,7 @@ h5_err_t H5FlushFile ( h5_file_t* const f /*!< file handle */ ) { - H5_API_ENTER1 (h5_err_t, "f=%p", f); + H5_API_ENTER (h5_err_t, "f=%p", f); H5_API_RETURN (h5_flush_file (f)); } @@ -129,9 +127,14 @@ H5SetStepNameFormat ( const char* name, /*!< Prefix */ const h5_int64_t width /*!< Width of the number */ ) { +<<<<<<< .working H5_API_ENTER3 (h5_err_t, "f=%p, name=\"%s\", width=%lld", f, name, (long long) width); +======= + H5_API_ENTER (h5_err_t, "f=%p, name='%s', width=%lld", + f, name, (long long) width); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_set_stepname_fmt (f, name, width)); } @@ -150,9 +153,15 @@ H5GetStepNameFormat ( const h5_size_t l_name, /*!< length of buffer name */ int* width /*!< OUT: Width of the number */ ) { +<<<<<<< .working H5_API_ENTER4 (h5_err_t, "f=%p, name=%p, l_name=%llu, width=%p", f, name, (unsigned long long)l_name, width); +======= + H5_API_ENTER (h5_err_t, + "f=%p, name=%p, l_name=%llu, width=%p", + f, name, (unsigned long long)l_name, width); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_get_stepname_fmt (f, name, l_name, width)); } @@ -168,7 +177,11 @@ H5SetStep ( h5_file_t* const f, /*!< [in] Handle to open file */ const h5_id_t step /*!< [in] Step to set. */ ) { +<<<<<<< .working H5_API_ENTER2 (h5_err_t, "f=%p, step=%lld", f, (long long)step); +======= + H5_API_ENTER (h5_err_t, "f=%p, step=%lld", f, (long long)step); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_set_step (f, step)); } @@ -183,7 +196,11 @@ h5_id_t H5GetStep ( h5_file_t* const f /*!< Handle to open file */ ) { +<<<<<<< .working H5_API_ENTER1 (h5_err_t, "f=%p", f); +======= + H5_API_ENTER (h5_err_t, "f=%p", f); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_get_step (f)); } @@ -201,7 +218,11 @@ int H5GetNumProcs ( h5_file_t* const f ) { +<<<<<<< .working H5_API_ENTER1 (h5_err_t, "f=%p", f); +======= + H5_API_ENTER (h5_err_t, "f=%p", f); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_get_num_procs(f)); } @@ -222,7 +243,11 @@ h5_ssize_t H5GetNumSteps ( h5_file_t* const f ) { +<<<<<<< .working H5_API_ENTER1 (h5_err_t, "f=%p", f); +======= + H5_API_ENTER (h5_err_t, "f=%p", f); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_get_num_steps(f)); } @@ -241,10 +266,14 @@ H5HasStep ( h5_file_t* const f, h5_id_t stepno ) { +<<<<<<< .working H5_API_ENTER2 (h5_err_t, "f=%p, stepno=%lld", f, (long long)stepno); +======= + H5_API_ENTER (h5_err_t, "f=%p, stepno=%lld", f, (long long)stepno); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_has_step (f, stepno)); } @@ -259,7 +288,11 @@ h5_err_t H5StartTraverseSteps ( h5_file_t* const f /*!< Handle to open file */ ) { +<<<<<<< .working H5_API_ENTER1 (h5_err_t, "f=%p", f); +======= + H5_API_ENTER (h5_err_t, "f=%p", f); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_start_traverse_steps (f)); } @@ -274,7 +307,11 @@ h5_err_t H5TraverseSteps ( h5_file_t* const f /*!< Handle to open file */ ) { +<<<<<<< .working H5_API_ENTER1 (h5_err_t, "f=%p", f); +======= + H5_API_ENTER (h5_err_t, "f=%p", f); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_traverse_steps (f)); } @@ -300,7 +337,11 @@ H5SetThrottle ( h5_file_t* f, int factor ) { +<<<<<<< .working H5_API_ENTER2 (h5_err_t, "f=%p, factor=%d", f, factor); +======= + H5_API_ENTER (h5_err_t, "f=%p, factor=%d", f, factor); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_set_throttle(f, factor)); } #endif // PARALLEL_IO @@ -316,8 +357,7 @@ h5_err_t H5SetVerbosityLevel ( const h5_id_t level ) { - H5_API_ENTER1 (h5_err_t, "level=%lld", (long long) level); - H5_API_RETURN (h5_set_debuglevel (level)); + return h5_set_debuglevel (level); } /*! @@ -331,7 +371,11 @@ h5_err_t H5SetErrorHandler ( h5_errorhandler_t handler ) { +<<<<<<< .working H5_API_ENTER1 (h5_err_t, "handler=%p", handler); +======= + H5_API_ENTER (h5_err_t, "handler=%p", handler); +>>>>>>> .merge-right.r3679 H5_API_RETURN (h5_set_errorhandler (handler)); } @@ -346,7 +390,7 @@ h5_errorhandler_t H5GetErrorHandler ( void ) { - H5_API_ENTER0 (h5_errorhandler_t); + H5_API_ENTER (h5_errorhandler_t, "%s", "void"); H5_API_RETURN (h5_get_errorhandler()); } diff --git a/src/C/H5Block.c b/src/C/H5Block.c index b1d9954..8d127fa 100644 --- a/src/C/H5Block.c +++ b/src/C/H5Block.c @@ -72,7 +72,7 @@ h5_int64_t H5Block3dHasView ( h5_file_t *const f /*!< IN: File handle */ ) { - H5_API_ENTER1 (h5_int64_t, "f=0x%p", f); + H5_API_ENTER (h5_int64_t, "f=%p", f); H5_API_RETURN (h5b_3d_has_view (f)); } @@ -99,15 +99,15 @@ H5Block3dSetView ( const h5_int64_t k_start, /*!< IN: start index of \c k */ const h5_int64_t k_end /*!< IN: end index of \c k */ ) { - H5_API_ENTER7 (h5_err_t, - "f=0X%p, " - "i_start=%lld, i_end=%lld, " - "j_start=%lld, j_end=%lld, " - "k_start=%lld, k_end=%lld", - f, - (long long)i_start, (long long)i_end, - (long long)j_start, (long long)j_end, - (long long)k_start, (long long)k_end); + H5_API_ENTER (h5_err_t, + "f=%p, " + "i_start=%lld, i_end=%lld, " + "j_start=%lld, j_end=%lld, " + "k_start=%lld, k_end=%lld", + f, + (long long)i_start, (long long)i_end, + (long long)j_start, (long long)j_end, + (long long)k_start, (long long)k_end); H5_API_RETURN (h5b_3d_set_view(f, i_start, i_end, j_start, j_end, k_start, k_end)); } @@ -128,15 +128,15 @@ H5Block3dGetView ( h5_size_t *k_start, /*!< OUT: start index of \c k */ h5_size_t *k_end /*!< OUT: end index of \c k */ ) { - H5_API_ENTER7 (h5_err_t, - "f=0X%p, " - "i_start=0x%p, i_end=0x%p, " - "j_start=0x%p, j_end=0x%p, " - "k_start=0x%p, k_end=0x%p", - f, - i_start, i_end, - j_start, j_end, - k_start, k_end); + H5_API_ENTER (h5_err_t, + "f=%p, " + "i_start=%p, i_end=%p, " + "j_start=%p, j_end=%p, " + "k_start=%p, k_end=%p", + f, + i_start, i_end, + j_start, j_end, + k_start, k_end); H5_API_RETURN (h5b_3d_get_view (f, i_start, i_end, j_start, j_end, k_start, k_end)); } @@ -157,15 +157,15 @@ H5Block3dGetReducedView ( h5_size_t *const k_start, /*!< OUT: start index of \c j */ h5_size_t *const k_end /*!< OUT: end index of \c j */ ) { - H5_API_ENTER7 (h5_err_t, - "f=0X%p, " - "i_start=0x%p, i_end=0x%p, " - "j_start=0x%p, j_end=0x%p, " - "k_start=0x%p, k_end=0x%p", - f, - i_start, i_end, - j_start, j_end, - k_start, k_end); + H5_API_ENTER (h5_err_t, + "f=%p, " + "i_start=%p, i_end=%p, " + "j_start=%p, j_end=%p, " + "k_start=%p, k_end=%p", + f, + i_start, i_end, + j_start, j_end, + k_start, k_end); H5_API_RETURN (h5b_3d_get_reduced_view(f, i_start, i_end, j_start, j_end, k_start, k_end)); } @@ -184,12 +184,12 @@ H5Block3dSetChunk ( const h5_size_t j, /*!< IN: size of \c j */ const h5_size_t k /*!< IN: size of \c k */ ) { - H5_API_ENTER4 (h5_err_t, - "f=0x%p, i=%llu, j=%llu, k=%llu", - f, - (long long unsigned)i, - (long long unsigned)j, - (long long unsigned)k); + H5_API_ENTER (h5_err_t, + "f=%p, i=%llu, j=%llu, k=%llu", + f, + (long long unsigned)i, + (long long unsigned)j, + (long long unsigned)k); H5_API_RETURN (h5b_3d_set_chunk(f, i, j, k)); } @@ -208,9 +208,9 @@ H5Block3dGetChunk ( h5_size_t *const j, /*!< OUT: size of \c j */ h5_size_t *const k /*!< OUT: size of \c k */ ) { - H5_API_ENTER4 (h5_err_t, - "f=0x%p, i=0x%p, j=0x%p, k=0x%p", - f, i, j, k); + H5_API_ENTER (h5_err_t, + "f=%p, i=%p, j=%p, k=%p", + f, i, j, k); H5_API_RETURN (h5b_3d_get_chunk(f, field_name, i, j, k)); } @@ -236,12 +236,12 @@ H5Block3dSetGrid ( const h5_size_t j, /*!< IN: dimension in \c j */ const h5_size_t k /*!< IN: dimension in \c k */ ) { - H5_API_ENTER4 (h5_err_t, - "f=0x%p, i=%llu, j=%llu, k=%llu", - f, - (long long unsigned)i, - (long long unsigned)j, - (long long unsigned)k); + H5_API_ENTER (h5_err_t, + "f=%p, i=%llu, j=%llu, k=%llu", + f, + (long long unsigned)i, + (long long unsigned)j, + (long long unsigned)k); H5_API_RETURN (h5b_3d_set_grid(f, i, j, k)); } @@ -261,9 +261,9 @@ H5Block3dGetGridCoords ( h5_int64_t *j, /*!< OUT: index in \c j */ h5_int64_t *k /*!< OUT: index in \c k */ ) { - H5_API_ENTER5 (h5_err_t, - "f=0x%p, proc=%d, i=0x%p, j=0x%p, k=0x%p", - f, proc, i, j, k); + H5_API_ENTER (h5_err_t, + "f=%p, proc=%d, i=%p, j=%p, k=%p", + f, proc, i, j, k); H5_API_RETURN (h5b_3d_get_grid_coords(f, proc, i, j, k)); } @@ -285,12 +285,12 @@ H5Block3dSetDims ( const h5_size_t j, /*!< IN: dimension in \c j */ const h5_size_t k /*!< IN: dimension in \c k */ ) { - H5_API_ENTER4 (h5_err_t, - "f=0x%p, i=%llu, j=%llu, k=%llu", - f, - (long long unsigned)i, - (long long unsigned)j, - (long long unsigned)k); + H5_API_ENTER (h5_err_t, + "f=%p, i=%llu, j=%llu, k=%llu", + f, + (long long unsigned)i, + (long long unsigned)j, + (long long unsigned)k); H5_API_RETURN (h5b_3d_set_dims(f, i, j, k)); } #endif @@ -314,12 +314,12 @@ H5Block3dSetHalo ( const h5_size_t j, /*!< IN: radius in \c j */ const h5_size_t k /*!< IN: radius in \c k */ ) { - H5_API_ENTER4 (h5_err_t, - "f=0x%p, i=%llu, j=%llu, k=%llu", - f, - (long long unsigned)i, - (long long unsigned)j, - (long long unsigned)k); + H5_API_ENTER (h5_err_t, + "f=%p, i=%llu, j=%llu, k=%llu", + f, + (long long unsigned)i, + (long long unsigned)j, + (long long unsigned)k); H5_API_RETURN (h5b_3d_set_halo(f, i, j, k)); } @@ -334,7 +334,7 @@ h5_ssize_t H5BlockGetNumFields ( h5_file_t *const f /*!< IN: file handle */ ) { - H5_API_ENTER1 (h5_ssize_t, "f=0x%p", f); + H5_API_ENTER (h5_ssize_t, "f=%p", f); H5_API_RETURN (h5b_get_num_fields(f)); } @@ -366,14 +366,14 @@ H5BlockGetFieldInfo ( h5_size_t *elem_rank, /*!< OUT: element rank */ h5_int64_t *type /*!< OUT: datatype */ ) { - H5_API_ENTER8 (h5_err_t, - "f=0x%p, idx=%llu, " - "name=0x%p, len_name=%llu, " - "field_rank=0x%p, field_dims=0x%p, elem_rank=0x%p, type=0x%p", - f, (long long unsigned)idx, - name, (long long unsigned)len_name, - field_rank, field_dims, elem_rank, - type); + H5_API_ENTER (h5_err_t, + "f=%p, idx=%llu, " + "name=%p, len_name=%llu, " + "field_rank=%p, field_dims=%p, elem_rank=%p, type=%p", + f, (long long unsigned)idx, + name, (long long unsigned)len_name, + field_rank, field_dims, elem_rank, + type); H5_API_RETURN ( h5b_get_field_info ( f, @@ -403,10 +403,10 @@ H5BlockGetFieldInfoByName ( h5_size_t *elem_rank, /*!< OUT: element rank */ h5_int64_t *type /*!< OUT: datatype */ ) { - H5_API_ENTER6 (h5_err_t, - "f=0x%p, name=\"%s\", " - "field_rank=0x%p, field_dims=0x%p, elem_rank=0x%p, type=0x%p", - f, name, field_rank, field_dims, elem_rank, type); + H5_API_ENTER (h5_err_t, + "f=%p, name='%s', " + "field_rank=%p, field_dims=%p, elem_rank=%p, type=%p", + f, name, field_rank, field_dims, elem_rank, type); H5_API_RETURN ( h5b_get_field_info_by_name ( f, @@ -434,15 +434,15 @@ H5BlockWriteFieldAttribString ( const char *attrib_name, /*!< IN: attribute name */ const char *buffer /*!< IN: attribute value */ ) { - H5_API_ENTER4 (h5_err_t, - "f=%p, " - "field_name=\"%s\", " - "attrib_name=\"%s\", " - "buffer=\"%s\"", - f, - field_name, - attrib_name, - buffer); + H5_API_ENTER (h5_err_t, + "f=%p, " + "field_name='%s', " + "attrib_name='%s', " + "buffer='%s'", + f, + field_name, + attrib_name, + buffer); H5_API_RETURN ( h5_write_field_attrib ( f, @@ -468,15 +468,15 @@ H5BlockReadFieldAttribString ( const char *attrib_name, /*!< IN: attribute name */ char *buffer /*!< OUT: attribute value */ ) { - H5_API_ENTER4 (h5_err_t, - "f=%p, " - "field_name=\"%s\", " - "attrib_name=\"%s\", " - "buffer=0x%p", - f, - field_name, - attrib_name, - buffer); + H5_API_ENTER (h5_err_t, + "f=%p, " + "field_name='%s', " + "attrib_name='%s', " + "buffer=%p", + f, + field_name, + attrib_name, + buffer); H5_API_RETURN ( h5_read_field_attrib ( f, @@ -498,9 +498,7 @@ H5BlockGetNumFieldAttribs ( h5_file_t *const f, /* #include @@ -14,7 +15,7 @@ h5_add_attachment ( h5_file_t* const f, const char* const fname ) { - H5_CORE_API_ENTER1 (h5_err_t, "fname=\"%s\"", fname); + H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s'", f, fname); // allowed file modes: O_RDWR, O_WRONLY; O_APPEND if (f->mode == H5_O_RDONLY) { H5_PRIV_FUNC_LEAVE ( @@ -26,21 +27,21 @@ h5_add_attachment ( H5_CORE_API_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot stat file \"%s\"", + "Cannot stat file '%s'", fname)); } hsize_t fsize = st.st_size; hsize_t write_length; char* buf = NULL; if (f->myproc == 0) { - buf = malloc (fsize); + TRY (buf = h5_alloc (NULL, fsize)); write_length = fsize; int fd; if ((fd = open (fname, O_RDONLY)) < 0) { H5_CORE_API_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot open file \"%s\" for reading", + "Cannot open file '%s' for reading", fname)); } again: @@ -51,7 +52,7 @@ h5_add_attachment ( H5_CORE_API_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot read file \"%s\"", + "Cannot read file '%s'", fname)); } } @@ -59,17 +60,17 @@ h5_add_attachment ( H5_CORE_API_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot close file \"%s\"", + "Cannot close file '%s'", fname)); } } else { - buf = malloc (1); + TRY (buf = h5_alloc (NULL, 1)); write_length = 0; } hid_t loc_id; - TRY (loc_id = h5priv_open_group (f, f->file, H5_ATTACHMENT)); + TRY (loc_id = h5priv_open_group (1, f->file, H5_ATTACHMENT)); h5_err_t exists; TRY (exists = hdf5_link_exists (loc_id, fname)); if (exists && (f->mode == H5_O_RDWR || f->mode == H5_O_WRONLY)) { @@ -134,7 +135,7 @@ h5_ssize_t h5_get_num_attachments ( h5_file_t* const f ) { - H5_CORE_API_ENTER0 (h5_ssize_t); + H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f); h5_ssize_t num = 0; hid_t group_id; TRY (group_id = open_attachments (f)); @@ -154,7 +155,10 @@ h5_get_attachment_info_by_idx ( h5_size_t len_fname, // IN h5_size_t* const fsize // OUT ) { - H5_CORE_API_ENTER0 (h5_err_t); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, idx=%llu, fname=%s, len_fname=%llu, fsize=%p", + f, (unsigned long long)idx, fname, (unsigned long long)len_fname, + fsize); hid_t loc_id; TRY (loc_id = open_attachments (f)); if (loc_id < 0) { // no attachment group in file @@ -181,7 +185,7 @@ h5_get_attachment_info_by_name ( const char* const fname, // IN h5_size_t* const fsize // OUT ) { - H5_CORE_API_ENTER2 (h5_err_t, "fname=\"%s\", fsize=0x%p", fname, fsize); + H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s', fsize=%p", f, fname, fsize); hid_t loc_id; TRY (loc_id = open_attachments (f)); @@ -203,7 +207,7 @@ h5_get_attachment ( h5_file_t* const f, const char* const fname ) { - H5_CORE_API_ENTER1 (h5_err_t, "fname=\"%s\"", fname); + H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s'", f, fname); // allowed modes: O_RDWR, O_RDONLY; O_APPEND // forbidden modes: O_WRONLY if (f->mode == H5_O_WRONLY) { @@ -212,7 +216,7 @@ h5_get_attachment ( } hid_t loc_id; - TRY (loc_id = h5priv_open_group (f, f->file, H5_ATTACHMENT)); + TRY (loc_id = hdf5_open_group (f->file, H5_ATTACHMENT)); h5_err_t exists; TRY (exists = hdf5_link_exists (loc_id, fname)); if (f->mode == H5_O_WRONLY) { @@ -222,7 +226,7 @@ h5_get_attachment ( H5_PRIV_FUNC_LEAVE ( h5_error ( H5_ERR_H5, - "Attachment \"%s\" doesn't exist", fname)); + "Attachment '%s' doesn't exist", fname)); } // read dataset @@ -274,21 +278,21 @@ h5_get_attachment ( H5_CORE_API_LEAVE ( h5_error ( H5_ERR_H5, - "Error opening file \"%s\": %s", + "Error opening file '%s': %s", fname, strerror(errno))); } if (write (fd, buf, fsize) != fsize) { H5_CORE_API_LEAVE ( h5_error ( H5_ERR_H5, - "Error writing to file \"%s\": %s", + "Error writing to file '%s': %s", fname, strerror(errno))); } if (close (fd) < 0) { H5_CORE_API_LEAVE ( h5_error ( H5_ERR_H5, - "Error closing file \"%s\": %s", + "Error closing file '%s': %s", fname, strerror(errno))); } } @@ -302,7 +306,7 @@ h5_delete_attachment ( h5_file_t* const f, const char* const fname ) { - H5_CORE_API_ENTER1 (h5_err_t, "fname=\"%s\"", fname); + H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s'", f, fname); hid_t group_id; TRY (group_id = open_attachments (f)); if (group_id < 0) { diff --git a/src/h5core/h5_attribs.c b/src/h5core/h5_attribs.c index caa8b93..3bb46b8 100644 --- a/src/h5core/h5_attribs.c +++ b/src/h5core/h5_attribs.c @@ -21,12 +21,12 @@ h5priv_read_attrib ( const hid_t attrib_type, /*!< HDF5 type of attribute */ void* const attrib_value /*!< OUT: attribute value */ ) { - H5_PRIV_API_ENTER4 (h5_err_t, - "id=%d, attrib_name=\"%s\", attrib_type=%d, attrib_value=%p", - id, - attrib_name, - attrib_type, - attrib_value); + H5_PRIV_API_ENTER (h5_err_t, + "id=%d, attrib_name='%s', attrib_type=%d, attrib_value=%p", + id, + attrib_name, + attrib_type, + attrib_value); hid_t attrib_id; hid_t type_id; hid_t space_id; @@ -69,15 +69,15 @@ h5_read_attrib ( const hid_t attrib_type, /*!< HDF5 type of attribute */ void* const attrib_value /*!< OUT: attribute value */ ) { - H5_CORE_API_ENTER5 (h5_err_t, - "f=%p mode=%d, " - "attrib_name=\"%s\", attrib_type=%d, " - "attrib_value=%p", - f, - mode, - attrib_name, - attrib_type, - attrib_value); + H5_CORE_API_ENTER (h5_err_t, + "f=%p mode=%d, " + "attrib_name='%s', attrib_type=%d, " + "attrib_value=%p", + f, + mode, + attrib_name, + attrib_type, + attrib_value); if (mode != H5_ATTRIB_FILE) CHECK_TIMEGROUP( f ); @@ -95,14 +95,14 @@ h5priv_write_attrib ( const void* attrib_value, /*!< value of attribute */ const hsize_t attrib_nelem /*!< number of elements (dimension) */ ) { - H5_PRIV_API_ENTER5 (h5_err_t, - "id=%d, attrib_name=\"%s\", attrib_type=%d, " - "attrib_value=%p, attrib_nelem=%llu", - id, - attrib_name, - attrib_type, - attrib_value, - attrib_nelem); + H5_PRIV_API_ENTER (h5_err_t, + "id=%d, attrib_name='%s', attrib_type=%d, " + "attrib_value=%p, attrib_nelem=%llu", + id, + attrib_name, + attrib_type, + attrib_value, + attrib_nelem); hid_t space_id; hid_t attrib_id; hid_t type_id; @@ -147,16 +147,16 @@ h5_write_attrib ( const void* attrib_value, /*!< value of attribute */ const hsize_t attrib_nelem /*!< number of elements (dimension) */ ) { - H5_CORE_API_ENTER6 (h5_err_t, - "f=%p mode=%d, " - "attrib_name=\"%s\", attrib_type=%d, " - "attrib_value=%p, attrib_nelem=%llu", - f, - mode, - attrib_name, - attrib_type, - attrib_value, - attrib_nelem); + H5_CORE_API_ENTER (h5_err_t, + "f=%p mode=%d, " + "attrib_name='%s', attrib_type=%d, " + "attrib_value=%p, attrib_nelem=%llu", + f, + mode, + attrib_name, + attrib_type, + attrib_value, + attrib_nelem); if (mode != H5_ATTRIB_FILE) CHECK_TIMEGROUP( f ); CHECK_WRITABLE_MODE( f ); @@ -177,17 +177,17 @@ h5priv_get_attrib_info ( h5_int64_t* attrib_type, /*!< OUT: H5 type of attribute */ h5_size_t* attrib_nelem /*!< OUT: number of elements */ ) { - H5_PRIV_API_ENTER6 (h5_err_t, - "id=%d, " - "attrib_idx=%llu, " - "attrib_name=%p, len_attrib_name=%llu, " - "attrib_type=%p, attrib_nelem=%p", - id, - (long long unsigned)attrib_idx, - attrib_name, - (long long unsigned)len_attrib_name, - attrib_type, - attrib_nelem); + H5_PRIV_API_ENTER (h5_err_t, + "id=%d, " + "attrib_idx=%llu, " + "attrib_name=%p, len_attrib_name=%llu, " + "attrib_type=%p, attrib_nelem=%p", + id, + (long long unsigned)attrib_idx, + attrib_name, + (long long unsigned)len_attrib_name, + attrib_type, + attrib_nelem); hid_t attrib_id; hid_t mytype; hid_t space_id; @@ -232,17 +232,17 @@ h5_get_attrib_info ( h5_int64_t* attrib_type, /*!< OUT: H5 type of attribute */ h5_size_t* attrib_nelem /*!< OUT: number of elements */ ) { - H5_PRIV_API_ENTER7 (h5_err_t, - "f=0x%p, mode=%d, " - "attrib_idx=%llu, attrib_name=%p, len_attrib_name=%llu, " - "attrib_type=%p, attrib_nelem=%p", - f, mode, - (long long unsigned)attrib_idx, - attrib_name, - (long long unsigned)len_attrib_name, - attrib_type, - attrib_nelem); - + H5_PRIV_API_ENTER (h5_err_t, + "f=0x%p, mode=%d, " + "attrib_idx=%llu, attrib_name=%p, len_attrib_name=%llu, " + "attrib_type=%p, attrib_nelem=%p", + f, mode, + (long long unsigned)attrib_idx, + attrib_name, + (long long unsigned)len_attrib_name, + attrib_type, + attrib_nelem); + if (mode != H5_ATTRIB_FILE) CHECK_TIMEGROUP( f ); hid_t id = 0; @@ -264,8 +264,7 @@ h5_get_num_attribs ( h5_file_t *const f, /*!< handle to open file */ const char mode /*!< FILE or STEP flag */ ) { - H5_CORE_API_ENTER2 (h5_ssize_t, - "f=%p, mode=%d", f, mode); + H5_CORE_API_ENTER (h5_ssize_t, "f=%p, mode=%d", f, mode); if (mode != H5_ATTRIB_FILE) CHECK_TIMEGROUP( f ); hid_t id = 0; TRY (get_hdf5_obj_id(f, mode, &id)); diff --git a/src/h5core/h5_core_private.h b/src/h5core/h5_core_private.h index e500a32..b804b86 100644 --- a/src/h5core/h5_core_private.h +++ b/src/h5core/h5_core_private.h @@ -1,102 +1,39 @@ #ifndef __H5_CORE_PRIVATE_H #define __H5_CORE_PRIVATE_H -#define H5_CORE_API_ENTER0(type) __FUNC_ENTER(type) -#define H5_CORE_API_ENTER1(type, fmt, a1) \ - __FUNC_ENTER1(type, fmt, a1, H5_DEBUG_CORE_API) -#define H5_CORE_API_ENTER2(type, fmt, a1, a2) \ - __FUNC_ENTER2(type, fmt, a1, a2, H5_DEBUG_CORE_API) -#define H5_CORE_API_ENTER3(type, fmt, a1, a2, a3) \ - __FUNC_ENTER3(type, fmt, a1, a2, a3, H5_DEBUG_CORE_API) -#define H5_CORE_API_ENTER4(type, fmt, a1, a2, a3, a4) \ - __FUNC_ENTER4(type, fmt, a1, a2, a3, a4, H5_DEBUG_CORE_API) -#define H5_CORE_API_ENTER5(type, fmt, a1, a2, a3, a4, a5) \ - __FUNC_ENTER5(type, fmt, a1, a2, a3, a4, a5, H5_DEBUG_CORE_API) -#define H5_CORE_API_ENTER6(type, fmt, a1, a2, a3, a4, a5, a6) \ - __FUNC_ENTER6(type, fmt, a1, a2, a3, a4, a5, a6, H5_DEBUG_CORE_API) -#define H5_CORE_API_ENTER7(type, fmt, a1, a2, a3, a4, a5, a6, a7) \ - __FUNC_ENTER7(type, fmt, a1, a2, a3, a4, a5, a6, a7, H5_DEBUG_CORE_API) -#define H5_CORE_API_ENTER8(type, fmt, a1, a2, a3, a4, a5, a6, a7, a8) \ - __FUNC_ENTER8(type, fmt, a1, a2, a3, a4, a5, a6, a7, a8, H5_DEBUG_CORE_API) +#define H5_CORE_API_ENTER(type, fmt, ...) \ + __FUNC_ENTER(type, H5_DEBUG_CORE_API, fmt, __VA_ARGS__) #define H5_CORE_API_LEAVE(value) __FUNC_LEAVE(value) #define H5_CORE_API_RETURN(value) __FUNC_RETURN(value, H5_DEBUG_CORE_API) -#define H5_PRIV_API_ENTER0(type) \ - __FUNC_ENTER1(type, H5_DEBUG_PRIV_API) -#define H5_PRIV_API_ENTER1(type, fmt, a1) \ - __FUNC_ENTER1(type, fmt, a1, H5_DEBUG_PRIV_API) -#define H5_PRIV_API_ENTER2(type, fmt, a1, a2) \ - __FUNC_ENTER2(type, fmt, a1, a2, H5_DEBUG_PRIV_API) -#define H5_PRIV_API_ENTER3(type, fmt, a1, a2, a3) \ - __FUNC_ENTER3(type, fmt, a1, a2, a3, H5_DEBUG_PRIV_API) -#define H5_PRIV_API_ENTER4(type, fmt, a1, a2, a3, a4) \ - __FUNC_ENTER4(type, fmt, a1, a2, a3, a4, H5_DEBUG_PRIV_API) -#define H5_PRIV_API_ENTER5(type, fmt, a1, a2, a3, a4, a5) \ - __FUNC_ENTER5(type, fmt, a1, a2, a3, a4, a5, H5_DEBUG_PRIV_API) -#define H5_PRIV_API_ENTER6(type, fmt, a1, a2, a3, a4, a5, a6) \ - __FUNC_ENTER6(type, fmt, a1, a2, a3, a4, a5, a6, H5_DEBUG_PRIV_API) -#define H5_PRIV_API_ENTER7(type, fmt, a1, a2, a3, a4, a5, a6, a7) \ - __FUNC_ENTER7(type, fmt, a1, a2, a3, a4, a5, a6, a7, H5_DEBUG_PRIV_API) +#define H5_PRIV_API_ENTER(type, fmt, ...) \ + __FUNC_ENTER(type, H5_DEBUG_PRIV_API, fmt, __VA_ARGS__) #define H5_PRIV_API_LEAVE(value) __FUNC_LEAVE(value) #define H5_PRIV_API_RETURN(value) __FUNC_RETURN(value, H5_DEBUG_PRIV_API) -#define H5_PRIV_FUNC_ENTER(type) __FUNC_ENTER(type) -#define H5_PRIV_FUNC_ENTER1(type, fmt, a1) \ - __FUNC_ENTER1(type, fmt, a1, H5_DEBUG_PRIV_FUNC) -#define H5_PRIV_FUNC_ENTER2(type, fmt, a1, a2) \ - __FUNC_ENTER2(type, fmt, a1, a2, H5_DEBUG_PRIV_FUNC) -#define H5_PRIV_FUNC_ENTER3(type, fmt, a1, a2, a3) \ - __FUNC_ENTER3(type, fmt,a1, a2, a3, H5_DEBUG_PRIV_FUNC) -#define H5_PRIV_FUNC_ENTER4(type, fmt, a1, a2, a3, a4) \ - __FUNC_ENTER4(type, fmt,a1, a2, a3, a4, H5_DEBUG_PRIV_FUNC) -#define H5_PRIV_FUNC_ENTER5(type, fmt, a1, a2, a3, a4, a5) \ - __FUNC_ENTER5(type, fmt,a1, a2, a3, a4, a5, H5_DEBUG_PRIV_FUNC) +#define H5_PRIV_FUNC_ENTER(type, fmt, ...) \ + __FUNC_ENTER(type, H5_DEBUG_PRIV_FUNC, fmt, __VA_ARGS__ ) #define H5_PRIV_FUNC_LEAVE(value) __FUNC_LEAVE(value) #define H5_PRIV_FUNC_RETURN(value) __FUNC_RETURN(value, H5_DEBUG_PRIV_FUNC) -#define HDF5_WRAPPER_ENTER(type) __FUNC_ENTER(type) -#define HDF5_WRAPPER_ENTER0(type) \ - __FUNC_ENTER0(type, H5_DEBUG_HDF5) -#define HDF5_WRAPPER_ENTER1(type, fmt, a1) \ - __FUNC_ENTER1(type, fmt, a1, H5_DEBUG_HDF5) -#define HDF5_WRAPPER_ENTER2(type, fmt, a1, a2) \ - __FUNC_ENTER2(type, fmt, a1, a2, H5_DEBUG_HDF5) -#define HDF5_WRAPPER_ENTER3(type, fmt, a1, a2, a3) \ - __FUNC_ENTER3(type, fmt, a1, a2, a3, H5_DEBUG_HDF5) -#define HDF5_WRAPPER_ENTER4(type, fmt, a1, a2, a3, a4) \ - __FUNC_ENTER4(type, fmt, a1, a2, a3, a4, H5_DEBUG_HDF5) -#define HDF5_WRAPPER_ENTER5(type, fmt, a1, a2, a3, a4, a5) \ - __FUNC_ENTER5(type, fmt, a1, a2, a3, a4, a5, H5_DEBUG_HDF5) + +#define HDF5_WRAPPER_ENTER(type, fmt, ...) \ + __FUNC_ENTER(type, H5_DEBUG_HDF5, fmt, __VA_ARGS__ ) #define HDF5_WRAPPER_LEAVE(value) __FUNC_LEAVE(value) #define HDF5_WRAPPER_RETURN(value) __FUNC_RETURN(value, H5_DEBUG_HDF5) -#define MALLOC_WRAPPER_ENTER1(type, fmt, a1) \ - __FUNC_ENTER1(type, fmt, a1, H5_DEBUG_MALLOC) -#define MALLOC_WRAPPER_ENTER2(type, fmt, a1, a2) \ - __FUNC_ENTER2(type, fmt, a1, a2, H5_DEBUG_MALLOC) -#define MALLOC_WRAPPER_ENTER3(type, fmt, a1, a2, a3) \ - __FUNC_ENTER3(type, fmt, a1, a2, a3, H5_DEBUG_MALLOC) -#define MALLOC_WRAPPER_LEAVE(value) __FUNC_LEAVE(value) -#define MALLOC_WRAPPER_RETURN(value) __FUNC_RETURN(value, H5_DEBUG_MALLOC) -#define MPI_WRAPPER_ENTER(type) __FUNC_ENTER(type) -#define MPI_WRAPPER_ENTER0(type) \ - __FUNC_ENTER0(type, H5_DEBUG_MPI) -#define MPI_WRAPPER_ENTER1(type, fmt, a1) \ - __FUNC_ENTER1(type, fmt, a1, H5_DEBUG_MPI) -#define MPI_WRAPPER_ENTER2(type, fmt, a1, a2) \ - __FUNC_ENTER2(type, fmt, a1, a2, H5_DEBUG_MPI) -#define MPI_WRAPPER_ENTER3(type, fmt, a1, a2, a3) \ - __FUNC_ENTER3(type, fmt, a1, a2, a3, H5_DEBUG_MPI) -#define MPI_WRAPPER_ENTER4(type, fmt, a1, a2, a3, a4) \ - __FUNC_ENTER4(type, fmt, a1, a2, a3, a4, H5_DEBUG_MPI) -#define MPI_WRAPPER_ENTER5(type, fmt, a1, a2, a3, a4, a5) \ - __FUNC_ENTER5(type, fmt, a1, a2, a3, a4, a5, H5_DEBUG_MPI) +#define MPI_WRAPPER_ENTER(type, fmt, ...) \ + __FUNC_ENTER(type, H5_DEBUG_MPI, fmt, __VA_ARGS__ ) #define MPI_WRAPPER_LEAVE(value) __FUNC_LEAVE(value) #define MPI_WRAPPER_RETURN(value) __FUNC_RETURN(value, H5_DEBUG_MPI) +#define H5_INLINE_FUNC_ENTER(type) type ret_value = (type)H5_ERR; +#define H5_INLINE_FUNC_LEAVE(expr) __FUNC_LEAVE(expr) +#define H5_INLINE_FUNC_RETURN(expr) __FUNC_RETURN(expr, 0) + /* WARNING! Changing these values will alter the data model and introduce * file incompatibilities with previous versions. */ #define H5_DATANAME_LEN 64 @@ -109,6 +46,7 @@ #define H5_BLOCKNAME_Z "2" #define H5_ATTACHMENT "Attachment" +#include "h5_va_macros.h" #include "h5_types_private.h" #include "h5_attribs_private.h" diff --git a/src/h5core/h5_errorhandling.c b/src/h5core/h5_errorhandling.c index 34b1c9a..c73278c 100644 --- a/src/h5core/h5_errorhandling.c +++ b/src/h5core/h5_errorhandling.c @@ -16,15 +16,15 @@ char *h5_rfmts[] = { [e_int] "%d", [e_ssize_t] "%ld", [e_char_p] "%s", - [e_void_p] "0x%p", + [e_void_p] "%p", [e_h5_err_t] "%lld", [e_h5_int64_t] "%lld", [e_h5_id_t] "%lld", [e_h5_ssize_t] "%lld", - [e_h5_errorhandler_t] "0x%p", - [e_h5_file_p] "0x%p", + [e_h5_errorhandler_t] "%p", + [e_h5_file_p] "%p", [e_h5t_lvl_idx_t] "%d", - [e_h5t_iterator_p] "0x%p", + [e_h5t_iterator_p] "%p", [e_h5_loc_id_t] "%ld", [e_h5_loc_idx_t] "%ld", [e_hid_t] "%ld", @@ -76,7 +76,7 @@ h5_set_debuglevel ( const h5_id_t level /*!< debug level */ ) { if (level < 0) - h5_debug_level = 0; + h5_debug_level = (1 << 20) - 1; else h5_debug_level = level; return H5_SUCCESS; diff --git a/src/h5core/h5_errorhandling_private.h b/src/h5core/h5_errorhandling_private.h index 1b706cc..089c9a4 100644 --- a/src/h5core/h5_errorhandling_private.h +++ b/src/h5core/h5_errorhandling_private.h @@ -1,54 +1,27 @@ #ifndef __H5_ERRORHANDLING_PRIVATE_H #define __H5_ERRORHANDLING_PRIVATE_H -#define HANDLE_H5_DATASET_RANK_ERR( m, n ) \ - h5_error( \ - H5_ERR_INVAL, \ - "Wrong rank of dataset: Is %d, but should be %d", \ - m, n ); - -#define HANDLE_H5_GROUP_EXISTS_ERR( name ) \ - h5_error( \ - H5_ERR_INVAL, \ - "Group \"%s\" already exists", name ) - -/**************** H5 *********************/ - -#define h5priv_handle_file_mode_error( mode_id ) \ - h5_error( \ - H5_ERR_BADF, \ - "Operation not permitted in mode \"%s\"", \ +#define h5priv_handle_file_mode_error( mode_id ) \ + h5_error( \ + H5_ERR_BADF, \ + "Operation not permitted in mode '%s'", \ H5_O_MODES[mode_id] ); -#define HANDLE_H5_STEP_EXISTS_ERR( step ) \ +#define HANDLE_H5_OVERFLOW_ERR( max ) \ h5_error( \ H5_ERR_INVAL, \ - "Step #%lld already exists, step cannot be set " \ - "to an existing step in write and append mode", \ - (long long)step ); - -#define HANDLE_H5_NOENTRY_ERR( group_name, type, idx ) \ - h5_error( \ - H5_ERR_NOENTRY, \ - "No entry with index %lld and type %d in group %s!", \ - (long long)idx, type, group_name ); - - -#define HANDLE_H5_OVERFLOW_ERR( max ) \ - h5_error( \ - H5_ERR_INVAL, \ "Cannot store more than %lld items", (long long)max ); -#define HANDLE_H5_PARENT_ID_ERR( parent_id ) \ +#define HANDLE_H5_PARENT_ID_ERR( parent_id ) \ h5_error( \ H5_ERR_INVAL, \ - "Wrong parent_id %lld.", \ + "Wrong parent_id %lld.", \ (long long)parent_id ); -#define HANDLE_H5_OUT_OF_RANGE_ERR( otype, oid ) \ - h5_error( \ - H5_ERR_INVAL, \ - "%s id %lld out of range", \ +#define HANDLE_H5_OUT_OF_RANGE_ERR( otype, oid ) \ + h5_error( \ + H5_ERR_INVAL, \ + "%s id %lld out of range", \ otype, (long long)oid ); #endif diff --git a/src/h5core/h5_hdf5.c b/src/h5core/h5_hdf5.c index 0deb9cc..a85c35f 100644 --- a/src/h5core/h5_hdf5.c +++ b/src/h5core/h5_hdf5.c @@ -1,10 +1,81 @@ #include #include #include +#include #include "h5core/h5_core.h" #include "h5_core_private.h" +/* + Test whether given path exists. + */ +h5_err_t +h5priv_link_exists_ ( + const hid_t loc_id, + const char const* path[], + size_t size + ) { + H5_PRIV_FUNC_ENTER (h5_err_t, "loc_id=%d, (%s), path=%s, ...", + loc_id, hdf5_get_objname (loc_id), path[0]); + // for the time being we limit the concatenated path to 1024 bytes + char name[1024]; + char* s = name; + char* end = name+sizeof (name); + name[0] = '\0'; + + for (size_t i = 0; i < size; i++) { + if (i) { // do not *prepend* a slash! + *s++ = '/'; + *s = '\0'; + } + if (s+strlen(path[i])+1 >= end) H5_PRIV_API_LEAVE ( + h5_error ( + H5_ERR_HDF5, + "path %s... to long", name)); + s = stpcpy (s, path[i]); + h5_err_t exists; + TRY (exists = hdf5_link_exists (loc_id, name)); + if (!exists) H5_PRIV_FUNC_LEAVE (0); + } + H5_PRIV_FUNC_RETURN (1); +} + +h5_err_t +h5priv_open_group_ ( + int create_intermediate, + const hid_t loc_id, + const char const* path[], + size_t size + ) { + H5_PRIV_FUNC_ENTER (h5_err_t, + "create_intermediate=%d, loc_id=%d, (%s), path=%s, ...", + create_intermediate, loc_id, hdf5_get_objname (loc_id), + path[0]); + hid_t hid = loc_id; + hid_t hid2 = 0; + h5_err_t exists; + for (size_t i=0; i < size; i++) { + TRY (exists = hdf5_link_exists (hid, path[i])); + if (exists) { + TRY (hid2 = hdf5_open_group (hid, path[i])); + } else if (create_intermediate) { + TRY (hid2 = hdf5_create_group (hid, path[i])); + } else { + H5_PRIV_FUNC_LEAVE ( + h5_error ( + H5_ERR_HDF5, + "No such group '%s/%s'.", + hdf5_get_objname (hid), + path[i])); + + } + if (hid != loc_id) { + TRY (hdf5_close_group (hid)); + } + hid = hid2; + } + H5_PRIV_FUNC_RETURN (hid); +} typedef struct op_data { int queried_idx; @@ -124,9 +195,9 @@ iter_op_count_match ( const H5L_info_t* info, void* _op_data ) { - H5_PRIV_FUNC_ENTER4 (herr_t, - "g_id=%d, name=\"%s\", info=0x%p, _op_data=0x%p", - g_id, name, info, _op_data); + H5_PRIV_FUNC_ENTER (herr_t, + "g_id=%d, name='%s', info=%p, _op_data=%p", + g_id, name, info, _op_data); op_data_t* op_data = (op_data_t*)_op_data; H5O_type_t type; TRY (type = iter_op_get_obj_type (g_id, name, info)); @@ -143,8 +214,7 @@ ssize_t hdf5_get_num_groups ( const hid_t loc_id ) { - HDF5_WRAPPER_ENTER2 (ssize_t, - "loc_id=%d (%s)", loc_id, hdf5_get_objname (loc_id)); + HDF5_WRAPPER_ENTER (ssize_t, "loc_id=%d (%s)", loc_id, hdf5_get_objname (loc_id)); op_data_t op_data; memset (&op_data, 0, sizeof (op_data)); op_data.type = H5O_TYPE_GROUP; @@ -156,7 +226,7 @@ hdf5_get_num_groups ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot get number of groups in \"%s\".", + "Cannot get number of groups in '%s'.", hdf5_get_objname (loc_id))); } HDF5_WRAPPER_RETURN (op_data.cnt); @@ -167,9 +237,9 @@ hdf5_get_num_groups_matching_prefix ( const hid_t loc_id, char* prefix ) { - HDF5_WRAPPER_ENTER3 (ssize_t, - "loc_id=%d (%s), prefix=\"%s\"", - loc_id, hdf5_get_objname (loc_id), prefix); + HDF5_WRAPPER_ENTER (ssize_t, + "loc_id=%d (%s), prefix='%s'", + loc_id, hdf5_get_objname (loc_id), prefix); op_data_t op_data; memset (&op_data, 0, sizeof (op_data)); op_data.type = H5O_TYPE_GROUP; @@ -183,7 +253,7 @@ hdf5_get_num_groups_matching_prefix ( h5_error ( H5_ERR_HDF5, "Cannot get number of groups with prefix" - " \"%s\" in \"%s\".", + " '%s' in '%s'.", prefix, hdf5_get_objname (loc_id))); } HDF5_WRAPPER_RETURN (op_data.cnt); @@ -196,10 +266,10 @@ hdf5_get_name_of_group_by_idx ( char *name, size_t len ) { - HDF5_WRAPPER_ENTER5 (h5_err_t, - "loc_id=%d (%s), idx=%llu, name=0x%p, len=%llu", - loc_id, hdf5_get_objname (loc_id), - idx, name, (unsigned long long)len); + HDF5_WRAPPER_ENTER (h5_err_t, + "loc_id=%d (%s), idx=%llu, name=%p, len=%llu", + loc_id, hdf5_get_objname (loc_id), + idx, name, (unsigned long long)len); op_data_t op_data; memset (&op_data, 0, sizeof (op_data)); op_data.type = H5O_TYPE_GROUP; @@ -216,7 +286,7 @@ hdf5_get_name_of_group_by_idx ( h5_error ( H5_ERR_HDF5, "Cannot get name of group with index" - " \"%lu\" in \"%s\".", + " '%lu' in '%s'.", (long unsigned int)idx, hdf5_get_objname (loc_id))); } @@ -227,8 +297,8 @@ ssize_t hdf5_get_num_datasets ( const hid_t loc_id ) { - HDF5_WRAPPER_ENTER2 (ssize_t, - "loc_id=%d (%s)", loc_id, hdf5_get_objname (loc_id)); + HDF5_WRAPPER_ENTER (ssize_t, + "loc_id=%d (%s)", loc_id, hdf5_get_objname (loc_id)); op_data_t op_data; memset (&op_data, 0, sizeof (op_data)); op_data.type = H5O_TYPE_DATASET; @@ -240,7 +310,7 @@ hdf5_get_num_datasets ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot get number of datasets in \"%s\".", + "Cannot get number of datasets in '%s'.", hdf5_get_objname (loc_id))); } HDF5_WRAPPER_RETURN (op_data.cnt); @@ -256,10 +326,10 @@ hdf5_get_name_of_dataset_by_idx ( char *name, size_t len ) { - HDF5_WRAPPER_ENTER5 (h5_err_t, - "loc_id=%d (%s), idx=%llu, name=0x%p, len=%llu", - loc_id, hdf5_get_objname (loc_id), - idx, name, (unsigned long long)len); + HDF5_WRAPPER_ENTER (h5_err_t, + "loc_id=%d (%s), idx=%llu, name=%p, len=%llu", + loc_id, hdf5_get_objname (loc_id), + idx, name, (unsigned long long)len); op_data_t op_data; memset (&op_data, 0, sizeof (op_data)); op_data.type = H5O_TYPE_DATASET; @@ -276,7 +346,7 @@ hdf5_get_name_of_dataset_by_idx ( h5_error ( H5_ERR_HDF5, "Cannot get name of dataset with index" - " \"%lu\" in \"%s\".", + " '%lu' in '%s'.", (long unsigned int)idx, hdf5_get_objname (loc_id))); } diff --git a/src/h5core/h5_hdf5_private.h b/src/h5core/h5_hdf5_private.h index 0d26972..8f9a894 100644 --- a/src/h5core/h5_hdf5_private.h +++ b/src/h5core/h5_hdf5_private.h @@ -3,14 +3,24 @@ /****** L i n k **************************************************************/ + +/* + Determine whether a link with the specified name exists in a group. + + Result: + 1 if link exists + 0 if link doesn't exist + error else + + */ static inline h5_err_t hdf5_link_exists ( const hid_t loc_id, const char* name ) { - HDF5_WRAPPER_ENTER3 (h5_err_t, - "loc_id=%d (%s), name=\"%s\"", - loc_id, hdf5_get_objname (loc_id), name); + HDF5_WRAPPER_ENTER (h5_err_t, + "loc_id=%d (%s), name='%s'", + loc_id, hdf5_get_objname (loc_id), name); /* Save old error handler */ H5E_auto2_t old_func; void *old_client_data; @@ -41,9 +51,9 @@ hdf5_delete_link ( const char* name, hid_t lapl_id ) { - HDF5_WRAPPER_ENTER4 (h5_err_t, - "loc_id=%d (%s), name=\"%s\", lapl_id=%d", - loc_id, hdf5_get_objname (loc_id), name, lapl_id); + HDF5_WRAPPER_ENTER (h5_err_t, + "loc_id=%d (%s), name='%s', lapl_id=%d", + loc_id, hdf5_get_objname (loc_id), name, lapl_id); if (H5Ldelete (loc_id, name, lapl_id) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -61,17 +71,17 @@ hdf5_open_group ( const hid_t loc_id, const char* const group_name ) { - HDF5_WRAPPER_ENTER3 (hid_t, - "loc_id=%d (%s), group_name=\"%s\"", - loc_id, - hdf5_get_objname (loc_id), - group_name); + HDF5_WRAPPER_ENTER (hid_t, + "loc_id=%d (%s), group_name='%s'", + loc_id, + hdf5_get_objname (loc_id), + group_name); hid_t group_id = H5Gopen (loc_id, group_name, H5P_DEFAULT); if (group_id < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot open group \"%s/%s\".", + "Cannot open group '%s/%s'.", hdf5_get_objname (loc_id), group_name)); HDF5_WRAPPER_RETURN (group_id); @@ -82,8 +92,8 @@ hdf5_create_group ( const hid_t loc_id, const char* const group_name ) { - HDF5_WRAPPER_ENTER3 (hid_t, - "loc_id=%d (%s), group_name=\"%s\"", + HDF5_WRAPPER_ENTER (hid_t, + "loc_id=%d (%s), group_name='%s'", loc_id, hdf5_get_objname (loc_id), group_name); @@ -93,53 +103,30 @@ hdf5_create_group ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot create group \"%s/%s\".", + "Cannot create group '%s/%s'.", hdf5_get_objname (loc_id), group_name)); HDF5_WRAPPER_RETURN (group_id); } -/*! - Open HDF5 group. If group doesn't exist create it. +h5_err_t +h5priv_open_group_ (int, hid_t, const char const*[], size_t); - \param[in] f file handle - \param[in] loc_id location id - \param[in] group_name name of group to open -*/ -static inline hid_t -h5priv_open_group ( - h5_file_t* const f, +#define h5priv_open_group(create_intermediate, loc_id, ...) \ + (h5priv_open_group_ (create_intermediate, \ + loc_id, \ + (const char const*[]) {__VA_ARGS__}, \ + PP_NARG(__VA_ARGS__))) + +h5_err_t +h5priv_link_exists_ ( const hid_t loc_id, - const char* const group_name - ) { - hid_t group_id; + const char const* path[], + size_t size + ); +#define h5priv_link_exists(loc_id, ...) \ + (h5priv_link_exists_ (loc_id, (const char const*[]){__VA_ARGS__}, PP_NARG(__VA_ARGS__))) - H5_PRIV_API_ENTER3 (hid_t, - "loc_id=%d (%s), group_name=\"%s\"", - loc_id, - hdf5_get_objname (loc_id), - group_name); - - /* - check access modes: - Open Create - H5_O_RDWR x x - H5_O_RDONLY x - - H5_O_WRONLY x x (overwrite/append data to existing dataset) - H5_O_APPEND x x (append datasets to an existing group) - */ - - h5_err_t exists; - TRY (exists = hdf5_link_exists(loc_id, group_name)); - if (exists > 0) { - TRY (group_id = hdf5_open_group (loc_id, group_name)); - } else { - CHECK_WRITABLE_MODE (f); - TRY (group_id = hdf5_create_group (loc_id, group_name)); - } - - H5_PRIV_API_RETURN (group_id); -} /*! Close group. @@ -151,10 +138,10 @@ static inline h5_err_t hdf5_close_group ( const hid_t group_id ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, - "group_id=%d (%s)", - group_id, - hdf5_get_objname (group_id)); + HDF5_WRAPPER_ENTER (h5_err_t, + "group_id=%d (%s)", + group_id, + hdf5_get_objname (group_id)); if (group_id == 0 || group_id == -1) HDF5_WRAPPER_LEAVE (H5_SUCCESS); @@ -162,7 +149,7 @@ hdf5_close_group ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot terminate access to group \"%s\").", + "Cannot terminate access to group '%s').", hdf5_get_objname (group_id))); } HDF5_WRAPPER_RETURN (H5_SUCCESS); @@ -172,16 +159,16 @@ static inline h5_ssize_t hdf5_get_num_objs_in_group ( const hid_t group_id ) { - HDF5_WRAPPER_ENTER2 (h5_ssize_t, - "group_id=%d (%s)", - group_id, - hdf5_get_objname (group_id)); + HDF5_WRAPPER_ENTER (h5_ssize_t, + "group_id=%d (%s)", + group_id, + hdf5_get_objname (group_id)); H5G_info_t group_info; if (H5Gget_info (group_id, &group_info) < 0) { HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot get number of objects in group \"%s\".", + "Cannot get number of objects in group '%s'.", hdf5_get_objname(group_id))); } HDF5_WRAPPER_RETURN ((h5_ssize_t)group_info.nlinks); @@ -199,11 +186,11 @@ hdf5_get_objname_by_idx ( char *name, size_t size ) { - HDF5_WRAPPER_ENTER3 (h5_ssize_t, - "loc_id=%d (%s), idx=%lld", - loc_id, - hdf5_get_objname (loc_id), - (long long)idx); + HDF5_WRAPPER_ENTER (h5_ssize_t, + "loc_id=%d (%s), idx=%lld", + loc_id, + hdf5_get_objname (loc_id), + (long long)idx); if (name == NULL) { size = 0; @@ -217,7 +204,7 @@ hdf5_get_objname_by_idx ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot get name of object %llu in group \"%s\".", + "Cannot get name of object %llu in group '%s'.", (unsigned long long)idx, hdf5_get_objname (loc_id))); HDF5_WRAPPER_RETURN (len); @@ -238,9 +225,9 @@ hdf5_create_dataspace ( const hsize_t* dims, const hsize_t* maxdims ) { - HDF5_WRAPPER_ENTER1 (hid_t, + HDF5_WRAPPER_ENTER (hid_t, "rank=%d", - rank); + rank); hid_t dataspace_id = H5Screate_simple (rank, dims, maxdims); if (dataspace_id < 0) HDF5_WRAPPER_LEAVE ( @@ -255,7 +242,7 @@ static inline hid_t hdf5_create_dataspace_scalar ( void ) { - HDF5_WRAPPER_ENTER0 (hid_t); + HDF5_WRAPPER_ENTER (hid_t, "%s", "void"); hid_t dataspace_id = H5Screate (H5S_SCALAR); if (dataspace_id < 0) HDF5_WRAPPER_LEAVE ( @@ -274,9 +261,7 @@ hdf5_select_hyperslab_of_dataspace ( const hsize_t* count, const hsize_t* block ) { - HDF5_WRAPPER_ENTER1 (h5_err_t, - "%d", - space_id); + HDF5_WRAPPER_ENTER (h5_err_t, "%d", space_id); herr_t herr = H5Sselect_hyperslab ( space_id, op, @@ -300,9 +285,7 @@ hdf5_select_elements_of_dataspace ( hsize_t nelems, const hsize_t* indices ) { - HDF5_WRAPPER_ENTER1 (h5_err_t, - "%d", - space_id); + HDF5_WRAPPER_ENTER (h5_err_t, "%d", space_id); herr_t herr; if ( nelems > 0 ) { herr = H5Sselect_elements ( @@ -326,9 +309,9 @@ static inline h5_err_t hdf5_select_none ( hid_t space_id ) { - HDF5_WRAPPER_ENTER1 (h5_err_t, + HDF5_WRAPPER_ENTER (h5_err_t, "%d", - space_id); + space_id); herr_t herr = H5Sselect_none (space_id); if (herr < 0) { HDF5_WRAPPER_LEAVE ( @@ -343,9 +326,7 @@ static inline h5_ssize_t hdf5_get_selected_npoints_of_dataspace ( hid_t space_id ) { - HDF5_WRAPPER_ENTER1 (h5_ssize_t, - "%d", - space_id); + HDF5_WRAPPER_ENTER (h5_ssize_t, "%d", space_id); hssize_t size = H5Sget_select_npoints (space_id); if (size < 0) HDF5_WRAPPER_LEAVE ( @@ -360,9 +341,7 @@ static inline h5_ssize_t hdf5_get_npoints_of_dataspace ( hid_t space_id ) { - HDF5_WRAPPER_ENTER1 (h5_ssize_t, - "%d", - space_id); + HDF5_WRAPPER_ENTER (h5_ssize_t, "%d", space_id); hssize_t size = H5Sget_simple_extent_npoints (space_id); if (size < 0) HDF5_WRAPPER_LEAVE ( @@ -379,9 +358,7 @@ hdf5_get_dims_of_dataspace ( hsize_t* dims, hsize_t* maxdims ) { - HDF5_WRAPPER_ENTER1 (int, - "%d", - space_id); + HDF5_WRAPPER_ENTER (int, "%d", space_id); int rank = H5Sget_simple_extent_dims (space_id, dims, maxdims); if (rank < 0) HDF5_WRAPPER_LEAVE ( @@ -402,9 +379,7 @@ static inline h5_err_t hdf5_close_dataspace ( const hid_t dataspace_id ) { - HDF5_WRAPPER_ENTER1 (h5_err_t, - "dataspace_%d", - dataspace_id); + HDF5_WRAPPER_ENTER (h5_err_t, "dataspace=%d", dataspace_id); if (dataspace_id <= 0 || dataspace_id == H5S_ALL) HDF5_WRAPPER_LEAVE (H5_SUCCESS); @@ -431,11 +406,11 @@ hdf5_open_dataset ( const hid_t loc_id, const char* const dataset_name ) { - HDF5_WRAPPER_ENTER3 (hid_t, - "loc_id=%d (%s), dataset_name=\"%s\"", - loc_id, - hdf5_get_objname (loc_id), - dataset_name); + HDF5_WRAPPER_ENTER (hid_t, + "loc_id=%d (%s), dataset_name='%s'", + loc_id, + hdf5_get_objname (loc_id), + dataset_name); hid_t dataset_id = H5Dopen ( loc_id, dataset_name, @@ -444,7 +419,7 @@ hdf5_open_dataset ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot open dataset \"%s/%s\".", + "Cannot open dataset '%s/%s'.", hdf5_get_objname (loc_id), dataset_name)); HDF5_WRAPPER_RETURN (dataset_id); @@ -469,8 +444,8 @@ hdf5_create_dataset ( const hid_t dataspace_id, const hid_t create_proplist ) { - HDF5_WRAPPER_ENTER3 (hid_t, - "loc_id=%d (%s), dataset_name=\"%s\"", + HDF5_WRAPPER_ENTER (hid_t, + "loc_id=%d (%s), dataset_name='%s'", loc_id, hdf5_get_objname (loc_id), dataset_name); @@ -486,7 +461,7 @@ hdf5_create_dataset ( HDF5_WRAPPER_LEAVE ( h5_error( H5_ERR_HDF5, - "Cannot create dataset \"%s/%s\"", + "Cannot create dataset '%s/%s'", hdf5_get_objname (loc_id), dataset_name)); HDF5_WRAPPER_RETURN (dataset_id); @@ -502,8 +477,8 @@ static inline h5_err_t hdf5_close_dataset ( const hid_t dataset_id ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, - "dataset_id=%d (%s)", + HDF5_WRAPPER_ENTER (h5_err_t, + "dataset_id=%d (%s)", dataset_id, hdf5_get_objname (dataset_id)); if (dataset_id < 0) @@ -513,7 +488,7 @@ hdf5_close_dataset ( HDF5_WRAPPER_LEAVE ( h5_error( H5_ERR_HDF5, - "Close of dataset \"%s\" failed.", + "Close of dataset '%s' failed.", hdf5_get_objname (dataset_id))); } HDF5_WRAPPER_RETURN (H5_SUCCESS); @@ -530,16 +505,16 @@ static inline hid_t hdf5_get_dataset_space ( const hid_t dataset_id ) { - HDF5_WRAPPER_ENTER2 (hid_t, - "dataset_id=%d (%s)", - dataset_id, - hdf5_get_objname(dataset_id)); + HDF5_WRAPPER_ENTER (hid_t, + "dataset_id=%d (%s)", + dataset_id, + hdf5_get_objname(dataset_id)); hid_t dataspace_id = H5Dget_space (dataset_id); if (dataspace_id < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot get dataspace for dataset \"%s\".", + "Cannot get dataspace for dataset '%s'.", hdf5_get_objname (dataset_id))); HDF5_WRAPPER_RETURN (dataspace_id); } @@ -565,12 +540,12 @@ hdf5_write_dataset ( const hid_t xfer_prop, const void* buf ) { - HDF5_WRAPPER_ENTER3 (h5_err_t, - "dataset_id=%d (%s) type_id=%d", - dataset_id, - hdf5_get_objname(dataset_id), - type_id); - + HDF5_WRAPPER_ENTER (h5_err_t, + "dataset_id=%d (%s) type_id=%d", + dataset_id, + hdf5_get_objname(dataset_id), + type_id); + herr_t herr = H5Dwrite ( dataset_id, type_id, @@ -582,7 +557,7 @@ hdf5_write_dataset ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Write to dataset \"%s\" failed.", \ + "Write to dataset '%s' failed.", \ hdf5_get_objname (dataset_id))); HDF5_WRAPPER_RETURN (H5_SUCCESS); @@ -599,11 +574,11 @@ hdf5_read_dataset ( const hid_t diskspace_id, const hid_t xfer_prop, void* const buf ) { - HDF5_WRAPPER_ENTER3 (h5_err_t, - "dataset_id=%d (%s) type_id=%d", - dataset_id, - hdf5_get_objname(dataset_id), - type_id); + HDF5_WRAPPER_ENTER (h5_err_t, + "dataset_id=%d (%s) type_id=%d", + dataset_id, + hdf5_get_objname(dataset_id), + type_id); herr_t herr = H5Dread ( dataset_id, type_id, @@ -615,7 +590,7 @@ hdf5_read_dataset ( HDF5_WRAPPER_LEAVE ( h5_error( H5_ERR_HDF5, - "Error reading dataset \"%s\".", + "Error reading dataset '%s'.", hdf5_get_objname (dataset_id))); HDF5_WRAPPER_RETURN (H5_SUCCESS); @@ -625,10 +600,10 @@ static inline hid_t hdf5_get_dataset_type ( const hid_t dataset_id ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, - "dataset_id=%d (%s)", - dataset_id, - hdf5_get_objname(dataset_id)); + HDF5_WRAPPER_ENTER (h5_err_t, + "dataset_id=%d (%s)", + dataset_id, + hdf5_get_objname(dataset_id)); hid_t datatype_id = H5Dget_type (dataset_id); if (datatype_id < 0) HDF5_WRAPPER_LEAVE ( @@ -644,16 +619,16 @@ hdf5_set_dataset_extent ( hid_t dataset_id, const hsize_t* size ) { - HDF5_WRAPPER_ENTER3 (h5_err_t, - "dataset_id=%d (%s), size=%llu", - dataset_id, - hdf5_get_objname(dataset_id), - *size); + HDF5_WRAPPER_ENTER (h5_err_t, + "dataset_id=%d (%s), size=%llu", + dataset_id, + hdf5_get_objname(dataset_id), + *size); if (H5Dset_extent(dataset_id, size) < 0) { HDF5_WRAPPER_LEAVE ( h5_error( H5_ERR_HDF5, - "Changing size of dataset \"%s\" dimensions failed.", + "Changing size of dataset '%s' dimensions failed.", hdf5_get_objname (dataset_id))); } HDF5_WRAPPER_RETURN (H5_SUCCESS); @@ -663,10 +638,10 @@ static inline h5_ssize_t hdf5_get_npoints_of_dataset ( hid_t dataset_id ) { - HDF5_WRAPPER_ENTER2 (h5_ssize_t, - "dataset_id=%d (%s)", - dataset_id, - hdf5_get_objname(dataset_id)); + HDF5_WRAPPER_ENTER (h5_ssize_t, + "dataset_id=%d (%s)", + dataset_id, + hdf5_get_objname(dataset_id)); hid_t dspace_id; hsize_t size; TRY (dspace_id = hdf5_get_dataset_space (dataset_id)); @@ -680,11 +655,11 @@ hdf5_get_npoints_of_dataset_by_name ( const hid_t loc_id, const char* const name ) { - HDF5_WRAPPER_ENTER3 (h5_ssize_t, - "loc_id=%d (%s), name=\"%s\"", - loc_id, - hdf5_get_objname(loc_id), - name); + HDF5_WRAPPER_ENTER (h5_ssize_t, + "loc_id=%d (%s), name='%s'", + loc_id, + hdf5_get_objname(loc_id), + name); hid_t dset_id; hsize_t size; TRY (dset_id = hdf5_open_dataset (loc_id, name)); @@ -750,11 +725,11 @@ hdf5_create_array_type ( const int rank, const hsize_t* dims ) { - HDF5_WRAPPER_ENTER3 (hid_t, - "base_type_id=%d (%s), rank=%d", - base_type_id, - hdf5_get_type_name (base_type_id), - rank); + HDF5_WRAPPER_ENTER (hid_t, + "base_type_id=%d (%s), rank=%d", + base_type_id, + hdf5_get_type_name (base_type_id), + rank); hid_t type_id = H5Tarray_create (base_type_id, rank, dims); if (type_id < 0) { HDF5_WRAPPER_LEAVE ( @@ -773,10 +748,10 @@ hdf5_create_type ( H5T_class_t class, const size_t size ) { - HDF5_WRAPPER_ENTER2 (hid_t, - "class=%d (%s)", - class, - get_class_type_name (class)); + HDF5_WRAPPER_ENTER (hid_t, + "class=%d (%s)", + class, + get_class_type_name (class)); hid_t type_id = H5Tcreate (class, size); if (type_id < 0) { HDF5_WRAPPER_LEAVE ( @@ -792,8 +767,7 @@ static inline hid_t hdf5_create_string_type( const hsize_t len ) { - HDF5_WRAPPER_ENTER1 (hid_t, - "len = %llu", len); + HDF5_WRAPPER_ENTER (hid_t, "len = %llu", len); hid_t type_id = H5Tcopy ( H5T_C_S1 ); if (type_id < 0) HDF5_WRAPPER_LEAVE ( @@ -817,7 +791,7 @@ hdf5_insert_type ( size_t offset, hid_t field_id ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, "type_id=%d, name=%s", type_id, name); + HDF5_WRAPPER_ENTER (h5_err_t, "type_id=%d, name='%s'", type_id, name); herr_t herr = H5Tinsert (type_id, name, offset, field_id); if (herr < 0) HDF5_WRAPPER_LEAVE ( @@ -832,7 +806,7 @@ static inline h5_err_t hdf5_close_type ( hid_t dtype_id ) { - HDF5_WRAPPER_ENTER1 (h5_err_t, "dtype_id=%d", dtype_id); + HDF5_WRAPPER_ENTER (h5_err_t, "dtype_id=%d", dtype_id); herr_t herr = H5Tclose (dtype_id); if (herr < 0) HDF5_WRAPPER_LEAVE ( @@ -848,7 +822,7 @@ static inline hid_t hdf5_create_property ( hid_t cls_id ) { - HDF5_WRAPPER_ENTER1 (hid_t, "cls_id=%d", cls_id); + HDF5_WRAPPER_ENTER (hid_t, "cls_id=%d", cls_id); hid_t prop_id = H5Pcreate (cls_id); if (prop_id < 0) HDF5_WRAPPER_LEAVE ( @@ -869,7 +843,7 @@ static inline hid_t hdf5_get_dataset_create_plist ( const hid_t dataset_id ) { - HDF5_WRAPPER_ENTER2 (hid_t, "dataset_id=%d (%s)", + HDF5_WRAPPER_ENTER (hid_t, "dataset_id=%d (%s)", dataset_id, hdf5_get_objname (dataset_id)); hid_t plist_id = H5Dget_create_plist (dataset_id); @@ -877,7 +851,7 @@ hdf5_get_dataset_create_plist ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot get create properties for dataset \"%s\".", + "Cannot get create properties for dataset '%s'.", hdf5_get_objname (dataset_id))); HDF5_WRAPPER_RETURN (plist_id); } @@ -888,9 +862,9 @@ hdf5_set_chunk_property ( int rank, hsize_t* dims ) { - HDF5_WRAPPER_ENTER3 (h5_err_t, + HDF5_WRAPPER_ENTER (h5_err_t, "plist=%d, rank=%d, dims[0]=%llu ...", - plist, rank, dims[0]); + plist, rank, dims[0]); if (H5Pset_chunk (plist, rank, dims) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -906,7 +880,7 @@ hdf5_get_chunk_property ( int rank, hsize_t* dims ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, "plist=%d, rank=%d", plist, rank); + HDF5_WRAPPER_ENTER (h5_err_t, "plist=%d, rank=%d", plist, rank); if (H5Pget_chunk (plist, rank, dims) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -921,7 +895,7 @@ hdf5_set_layout_property ( hid_t plist, H5D_layout_t layout ) { - HDF5_WRAPPER_ENTER1 (h5_err_t, "plist=%d", plist); + HDF5_WRAPPER_ENTER (h5_err_t, "plist=%d", plist); if (H5Pset_layout (plist, layout) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -938,9 +912,9 @@ hdf5_set_fapl_mpio_property ( MPI_Comm comm, MPI_Info info ) { - HDF5_WRAPPER_ENTER3 (h5_err_t, - "fapl_id=%d, comm=0x%p, info=0x%p", - fapl_id, (void*)comm, (void*)info); + HDF5_WRAPPER_ENTER (h5_err_t, + "fapl_id=%d, comm=%p, info=%p", + fapl_id, (void*)comm, (void*)info); if (H5Pset_fapl_mpio (fapl_id, comm, info) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -956,9 +930,9 @@ hdf5_set_fapl_mpiposix_property ( MPI_Comm comm, hbool_t use_gpfs ) { - HDF5_WRAPPER_ENTER3 (h5_err_t, - "fapl_id=%d, comm=0x%p, use_gpfs=%d", - fapl_id, (void*)comm, (int)use_gpfs); + HDF5_WRAPPER_ENTER (h5_err_t, + "fapl_id=%d, comm=%p, use_gpfs=%d", + fapl_id, (void*)comm, (int)use_gpfs); if ( H5Pset_fapl_mpiposix (fapl_id, comm, use_gpfs) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -973,9 +947,7 @@ hdf5_set_dxpl_mpio_property ( hid_t dxpl_id, H5FD_mpio_xfer_t mode ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, - "dxpl_id=%d, mode=%d", - dxpl_id, (int)mode); + HDF5_WRAPPER_ENTER (h5_err_t, "dxpl_id=%d, mode=%d",dxpl_id,(int)mode); if (H5Pset_dxpl_mpio (dxpl_id, mode) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -991,9 +963,7 @@ hdf5_set_mdc_property ( hid_t fapl_id, H5AC_cache_config_t *config ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, - "fapl_id=%d, config=0x%p", - fapl_id, config); + HDF5_WRAPPER_ENTER (h5_err_t, "fapl_id=%d, config=%p",fapl_id,config); if (H5Pset_mdc_config (fapl_id, config) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -1008,9 +978,7 @@ hdf5_get_mdc_property ( hid_t fapl_id, H5AC_cache_config_t *config ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, - "fapl_id=%d, config=0x%p", - fapl_id, config); + HDF5_WRAPPER_ENTER (h5_err_t, "fapl_id=%d, config=%p",fapl_id,config); if (H5Pget_mdc_config (fapl_id, config) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -1020,32 +988,14 @@ hdf5_get_mdc_property ( HDF5_WRAPPER_RETURN (H5_SUCCESS); } -static inline h5_err_t -hdf5_set_alignment_property ( - const hid_t fapl_id, - const hsize_t threshold, - const hsize_t alignment - ) { - HDF5_WRAPPER_ENTER3 (h5_err_t, - "fapl_id=%d, threshold=%llu, alignment=%llu", - fapl_id, threshold, alignment); - if (H5Pset_alignment (fapl_id, threshold, alignment) < 0) - HDF5_WRAPPER_LEAVE ( - h5_error ( - H5_ERR_HDF5, - "Cannot set alignment in the " - "file access property list.")); - HDF5_WRAPPER_RETURN (H5_SUCCESS); -} - static inline h5_err_t hdf5_set_btree_ik_property ( const hid_t fcpl_id, const hsize_t btree_ik ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, - "fapl_id=%d, btree_ik=%llu", - fcpl_id, btree_ik); + HDF5_WRAPPER_ENTER (h5_err_t, + "fapl_id=%d, btree_ik=%llu", + fcpl_id, btree_ik); if (H5Pset_istore_k (fcpl_id, btree_ik) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -1055,11 +1005,46 @@ hdf5_set_btree_ik_property ( HDF5_WRAPPER_RETURN (H5_SUCCESS); } +static inline h5_err_t +hdf5_set_alignment_property ( + hid_t plist, + hsize_t threshold, + hsize_t alignment + ) { + HDF5_WRAPPER_ENTER (h5_err_t, + "plist=%d, threshold=%llu, alignment=%llu", + plist, threshold, alignment); + if (H5Pset_alignment (plist, threshold, alignment) < 0) + HDF5_WRAPPER_LEAVE ( + h5_error ( + H5_ERR_HDF5, + "Cannot set alignment property to %llu and threshold %llu", + alignment, threshold)); + HDF5_WRAPPER_RETURN (H5_SUCCESS); +} + +static inline h5_err_t +hdf5_set_meta_block_size ( + hid_t fapl_id, + hsize_t size + ) { + HDF5_WRAPPER_ENTER (h5_err_t, + "fapl_id=%d, size=%llu", + fapl_id, size); + if (H5Pset_meta_block_size (fapl_id, size) < 0) + HDF5_WRAPPER_LEAVE ( + h5_error ( + H5_ERR_HDF5, + "Cannot set meta block size property to %llu", + size)); + HDF5_WRAPPER_RETURN (H5_SUCCESS); +} + static inline h5_err_t hdf5_close_property ( hid_t prop ) { - HDF5_WRAPPER_ENTER1 (h5_err_t, "prop=%d", prop); + HDF5_WRAPPER_ENTER (h5_err_t, "prop=%d", prop); if (H5Pclose (prop) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( @@ -1074,15 +1059,13 @@ static inline h5_err_t hdf5_close_file ( hid_t file_id ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, - "file_id=%d (%s)", - file_id, - hdf5_get_objname (file_id)); + HDF5_WRAPPER_ENTER (h5_err_t, "file_id=%d (%s)", + file_id, hdf5_get_objname (file_id)); if (H5Fclose (file_id) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot close file \"%s\".", + "Cannot close file '%s'.", hdf5_get_objname (file_id))); HDF5_WRAPPER_RETURN (H5_SUCCESS); } @@ -1092,7 +1075,7 @@ hdf5_flush ( hid_t obj_id, H5F_scope_t scope ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, + HDF5_WRAPPER_ENTER (h5_err_t, "obj_id=%d (%s)", obj_id, hdf5_get_objname (obj_id)); @@ -1113,8 +1096,8 @@ hdf5_set_errorhandler ( H5E_auto_t func, void* client_data ) { - HDF5_WRAPPER_ENTER3 (h5_err_t, - "estack_id=%d, func=0x%p, client_data=0x%p", + HDF5_WRAPPER_ENTER (h5_err_t, + "estack_id=%d, func=%p, client_data=%p", estack_id, func, client_data); if (H5Eset_auto (estack_id, func, client_data) < 0) HDF5_WRAPPER_LEAVE ( @@ -1130,15 +1113,15 @@ hdf5_open_attribute ( hid_t loc_id, const char* attrib_name ) { - HDF5_WRAPPER_ENTER3 (hid_t, - "loc_id=%d (%s), attr_name=\"%s\"", - loc_id, hdf5_get_objname (loc_id), attrib_name); + HDF5_WRAPPER_ENTER (hid_t, + "loc_id=%d (%s), attr_name='%s'", + loc_id, hdf5_get_objname (loc_id), attrib_name); hid_t attrib_id = H5Aopen (loc_id, attrib_name, H5P_DEFAULT); if (attrib_id < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot open attribute \"%s\" of \"%s\".", + "Cannot open attribute '%s' of '%s'.", attrib_name, hdf5_get_objname (loc_id))); HDF5_WRAPPER_RETURN (attrib_id); @@ -1149,15 +1132,15 @@ hdf5_open_attribute_idx ( hid_t loc_id, unsigned int idx ) { - HDF5_WRAPPER_ENTER3 (hid_t, - "loc_id=%d (%s), idx=%u", - loc_id, hdf5_get_objname (loc_id), idx); + HDF5_WRAPPER_ENTER (hid_t, + "loc_id=%d (%s), idx=%u", + loc_id, hdf5_get_objname (loc_id), idx); hid_t attr_id = H5Aopen_idx (loc_id, idx); if (attr_id < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot open attribute \"%u\" of \"%s\".", + "Cannot open attribute '%u' of '%s'.", idx, hdf5_get_objname (loc_id))); HDF5_WRAPPER_RETURN (attr_id); @@ -1169,9 +1152,9 @@ hdf5_open_attribute_by_name ( const char* obj_name, const char* attr_name ) { - HDF5_WRAPPER_ENTER4 (hid_t, - "loc_id=%d (%s), obj_name=\"%s\", attr_name=\"%s\"", - loc_id, hdf5_get_objname (loc_id), + HDF5_WRAPPER_ENTER (hid_t, + "loc_id=%d (%s), obj_name='%s', attr_name='%s'", + loc_id, hdf5_get_objname (loc_id), obj_name, attr_name); hid_t attr_id = H5Aopen_by_name ( loc_id, @@ -1183,7 +1166,7 @@ hdf5_open_attribute_by_name ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot open attribute \"%s\" of \"%s\".", + "Cannot open attribute '%s' of '%s'.", attr_name, obj_name)); HDF5_WRAPPER_RETURN (attr_id); @@ -1198,10 +1181,10 @@ hdf5_create_attribute ( hid_t acpl_id, hid_t aapl_id ) { - HDF5_WRAPPER_ENTER4 (hid_t, - "loc_id=%d (%s), attr_name=\"%s\", type_id=%d", - loc_id, hdf5_get_objname (loc_id), - attr_name, type_id); + HDF5_WRAPPER_ENTER (hid_t, + "loc_id=%d (%s), attr_name='%s', type_id=%d", + loc_id, hdf5_get_objname (loc_id), + attr_name, type_id); hid_t attr_id = H5Acreate ( loc_id, attr_name, @@ -1213,7 +1196,7 @@ hdf5_create_attribute ( HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot create attribute \"%s\" for \"%s\".", + "Cannot create attribute '%s' for '%s'.", attr_name, hdf5_get_objname (loc_id))); HDF5_WRAPPER_RETURN (attr_id); @@ -1225,15 +1208,15 @@ hdf5_read_attribute ( hid_t mem_type_id, void* buf ) { - HDF5_WRAPPER_ENTER4 (h5_err_t, - "attr_id=%d (%s), mem_type_id=%d, buf=0x%p", - attr_id, hdf5_get_objname (attr_id), - mem_type_id, buf); + HDF5_WRAPPER_ENTER (h5_err_t, + "attr_id=%d (%s), mem_type_id=%d, buf=%p", + attr_id, hdf5_get_objname (attr_id), + mem_type_id, buf); if (H5Aread (attr_id, mem_type_id, buf) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot read attribute \"%s\".", + "Cannot read attribute '%s'.", hdf5_get_objname (attr_id))); HDF5_WRAPPER_RETURN (H5_SUCCESS); } @@ -1247,15 +1230,15 @@ hdf5_write_attribute ( hid_t mem_type_id, const void* buf ) { - HDF5_WRAPPER_ENTER4 (h5_err_t, - "attr_id=%d (%s), mem_type_id=%d, buf=0x%p", - attr_id, hdf5_get_objname (attr_id), - mem_type_id, buf); + HDF5_WRAPPER_ENTER (h5_err_t, + "attr_id=%d (%s), mem_type_id=%d, buf=%p", + attr_id, hdf5_get_objname (attr_id), + mem_type_id, buf); if (H5Awrite (attr_id, mem_type_id, buf) < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot write attribute \"%s\".", + "Cannot write attribute '%s'.", hdf5_get_objname (attr_id))); HDF5_WRAPPER_RETURN (H5_SUCCESS); @@ -1267,10 +1250,10 @@ hdf5_get_attribute_name ( size_t buf_size, char *buf ) { - HDF5_WRAPPER_ENTER4 (h5_ssize_t, - "attr_id=%d (%s), buf_size=%llu, buf=0x%p", - attr_id, hdf5_get_objname (attr_id), - (unsigned long long)buf_size, buf); + HDF5_WRAPPER_ENTER (h5_ssize_t, + "attr_id=%d (%s), buf_size=%llu, buf=%p", + attr_id, hdf5_get_objname (attr_id), + (unsigned long long)buf_size, buf); ssize_t size = H5Aget_name ( attr_id, buf_size, buf ); if (size < 0) HDF5_WRAPPER_LEAVE ( @@ -1284,15 +1267,15 @@ static inline hid_t hdf5_get_attribute_type ( hid_t attr_id ) { - HDF5_WRAPPER_ENTER2 (hid_t, - "attr_id=%d (%s)", - attr_id, hdf5_get_objname (attr_id)); + HDF5_WRAPPER_ENTER (hid_t, + "attr_id=%d (%s)", + attr_id, hdf5_get_objname (attr_id)); hid_t datatype_id = H5Aget_type (attr_id); if (datatype_id < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot get type of attribute \"%s\".", + "Cannot get type of attribute '%s'.", hdf5_get_objname (attr_id))); HDF5_WRAPPER_RETURN (datatype_id); } @@ -1301,15 +1284,15 @@ static inline hid_t hdf5_get_attribute_dataspace ( hid_t attr_id ) { - HDF5_WRAPPER_ENTER2 (hid_t, - "attr_id=%d (%s)", - attr_id, hdf5_get_objname (attr_id)); + HDF5_WRAPPER_ENTER (hid_t, + "attr_id=%d (%s)", + attr_id, hdf5_get_objname (attr_id)); hid_t space_id = H5Aget_space (attr_id); if (space_id < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot get dataspace of attribute \"%s\".", + "Cannot get dataspace of attribute '%s'.", hdf5_get_objname (attr_id))); HDF5_WRAPPER_RETURN (space_id); } @@ -1318,15 +1301,15 @@ static inline int hdf5_get_num_attribute ( hid_t loc_id ) { - HDF5_WRAPPER_ENTER2 (int, - "loc_id=%d (%s)", - loc_id, hdf5_get_objname (loc_id)); + HDF5_WRAPPER_ENTER (int, + "loc_id=%d (%s)", + loc_id, hdf5_get_objname (loc_id)); int num = H5Aget_num_attrs (loc_id); if (num < 0) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot get number of attributes of \"%s\".", + "Cannot get number of attributes of '%s'.", hdf5_get_objname (loc_id))); HDF5_WRAPPER_RETURN (num); } @@ -1336,14 +1319,14 @@ static inline h5_err_t hdf5_close_attribute ( hid_t attr_id ) { - HDF5_WRAPPER_ENTER2 (h5_err_t, - "attr_id=%d (%s)", - attr_id, hdf5_get_objname (attr_id)); + HDF5_WRAPPER_ENTER (h5_err_t, + "attr_id=%d (%s)", + attr_id, hdf5_get_objname (attr_id)); if (H5Aclose (attr_id)) HDF5_WRAPPER_LEAVE ( h5_error ( H5_ERR_HDF5, - "Cannot close attribute \"%s\".", + "Cannot close attribute '%s'.", hdf5_get_objname (attr_id))); HDF5_WRAPPER_RETURN (H5_SUCCESS); diff --git a/src/h5core/h5_hsearch.c b/src/h5core/h5_hsearch.c index 590eaf3..3e6443a 100644 --- a/src/h5core/h5_hsearch.c +++ b/src/h5core/h5_hsearch.c @@ -67,12 +67,12 @@ h5priv_hcreate ( unsigned int (*compute_hash)(const void*), h5_err_t (*free_entry)(const void*) ) { - H5_PRIV_API_ENTER5 (h5_err_t, - "nel=%llu, htab=0x%p, compare=0x%p, " - "compute_hash=0x%p, free_entry=0x%p", - (long long unsigned)nel, - htab, compare, compute_hash, free_entry); - + H5_PRIV_API_ENTER (h5_err_t, + "nel=%llu, htab=%p, compare=%p, " + "compute_hash=%p, free_entry=%p", + (long long unsigned)nel, + htab, compare, compute_hash, free_entry); + /* Test for correct arguments. */ if (htab == NULL || htab->table != NULL) { H5_PRIV_API_LEAVE (h5_error_internal ()); @@ -104,9 +104,9 @@ h5priv_hresize ( size_t nel, // number of entries to grow h5_hashtable_t* htab // hash table to resize ) { - H5_PRIV_API_ENTER2 (h5_err_t, - "nel=%llu, htab=0x%p", - (long long unsigned)nel, htab); + H5_PRIV_API_ENTER (h5_err_t, + "nel=%llu, htab=%p", + (long long unsigned)nel, htab); if (htab == NULL || htab->table == NULL) { H5_PRIV_API_LEAVE (h5_error_internal ()); } @@ -144,7 +144,7 @@ hwalk ( struct hsearch_data* htab, h5_err_t (*visit)(const void *item) ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, "htab=0x%p, visit=0x%p", htab, visit); + H5_PRIV_FUNC_ENTER (h5_err_t, "htab=%p, visit=%p", htab, visit); unsigned int idx = 1; for (idx = 1; idx < htab->size; idx++) { if (htab->table[idx].used) { @@ -161,7 +161,7 @@ h5_err_t h5priv_hdestroy ( struct hsearch_data* htab ) { - H5_PRIV_API_ENTER1 (h5_err_t, "htab=0x%p", htab); + H5_PRIV_API_ENTER (h5_err_t, "htab=%p", htab); /* Test for correct arguments. */ if (htab == NULL) { H5_PRIV_API_LEAVE (h5_error_internal ()); @@ -199,14 +199,14 @@ h5priv_hsearch ( void** retval, struct hsearch_data* htab ) { - H5_PRIV_API_ENTER4 (h5_err_t, - "item=0x%p, action=%d, retval=0x%p, htab=0x%p", - item, (int)action, retval, htab); + H5_PRIV_API_ENTER (h5_err_t, + "item=%p, action=%d, retval=%p, htab=%p", + item, (int)action, retval, htab); unsigned int hval; unsigned int idx; /* Compute an value for the given key. Perhaps use a better method. */ - hval = (*htab->compute_hash)(item); + hval = htab->compute_hash(item); /* First hash function: simply take the modul but prevent zero. */ idx = hval % htab->size + 1; @@ -215,7 +215,7 @@ h5priv_hsearch ( /* Further action might be required according to the action value. */ if (htab->table[idx].used == hval - && ((*htab->compare) (item, htab->table[idx].entry) == 0) ) { + && (htab->compare (item, htab->table[idx].entry) == 0) ) { if (retval) { *retval = htab->table[idx].entry; } @@ -241,7 +241,7 @@ h5priv_hsearch ( /* If entry is found use it. */ if (htab->table[idx].used == hval - && ((*htab->compare) ( + && (htab->compare ( item, htab->table[idx].entry) == 0) ) { if (retval) { *retval = htab->table[idx].entry; @@ -314,7 +314,7 @@ static h5_err_t free_string_keyed ( const void* __entry ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, "__entry=%p", __entry); h5_hitem_string_keyed_t* entry = (h5_hitem_string_keyed_t*) __entry; TRY (h5_free (entry->key)); TRY (h5_free (entry)); @@ -327,7 +327,7 @@ h5priv_hcreate_string_keyed ( h5_hashtable_t* htab, h5_err_t (*free_entry)(const void*) ) { - H5_PRIV_API_ENTER2 (h5_err_t, "htab=0x%p, free_entry=0x%p", htab, free_entry); + H5_PRIV_API_ENTER (h5_err_t, "htab=%p, free_entry=%p", htab, free_entry); if (free_entry == NULL) { TRY (h5priv_hcreate (nel, htab, cmp_string_keyed, diff --git a/src/h5core/h5_lustre.c b/src/h5core/h5_lustre.c index cea5f26..5d0ba29 100644 --- a/src/h5core/h5_lustre.c +++ b/src/h5core/h5_lustre.c @@ -1,3 +1,6 @@ +#include "h5core/h5_core.h" +#include "h5_core_private.h" + #ifdef H5_USE_LUSTRE #include @@ -11,8 +14,6 @@ #include #include -#include "h5core/h5_core.h" -#include "h5_core_private.h" #define MSG_HEADER "optimize for lustre: " @@ -100,7 +101,7 @@ h5_optimize_for_lustre ( const char *filename ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, filename=\"%s\"", f, filename); + H5_CORE_API_ENTER (h5_err_t, "f=%p, filename='%s'", f, filename); ssize_t stripe_size; if ( f->myproc == 0 ) { diff --git a/src/h5core/h5_maps.c b/src/h5core/h5_maps.c index 46adeae..80b01f8 100644 --- a/src/h5core/h5_maps.c +++ b/src/h5core/h5_maps.c @@ -16,11 +16,9 @@ h5_err_t h5priv_alloc_idlist ( h5_loc_idlist_t** list, - const h5_size_t size + const int32_t size ) { - H5_PRIV_API_ENTER2 (h5_err_t, - "list=0x%p, size=%llu", - list, (long long unsigned)size); + H5_PRIV_API_ENTER (h5_err_t, "list=%p, size=%d", list, size); TRY (*list = h5_calloc ( 1, sizeof (**list)+size*sizeof ((*list)->items[0]))); (*list)->size = size; @@ -31,8 +29,8 @@ h5_err_t h5priv_free_idlist ( h5_loc_idlist_t** list ) { - H5_PRIV_API_ENTER1 (h5_err_t, "list=0x%p", list); - if (*list == NULL) return H5_SUCCESS; + H5_PRIV_API_ENTER (h5_err_t, "list=%p", list); + if (*list == NULL) H5_PRIV_API_LEAVE (H5_SUCCESS); TRY (h5_free (*list)); *list = NULL; H5_PRIV_API_RETURN (H5_SUCCESS); @@ -43,9 +41,7 @@ grow_idlist ( h5_loc_idlist_t** list, size_t new_size ) { - H5_PRIV_API_ENTER2 (h5_err_t, - "list=0x%p, new_size=%llu", - list, (long long unsigned)new_size); + H5_PRIV_API_ENTER (h5_err_t, "list=%p, new_size=%zu", list, new_size); size_t num_bytes = sizeof (**list) + (new_size-1)*sizeof((*list)->items[0]); TRY (*list = h5_alloc (*list, num_bytes)); (*list)->size = new_size; @@ -61,11 +57,11 @@ h5priv_insert_idlist ( h5_loc_id_t id, h5_loc_idx_t idx ) { - H5_PRIV_API_ENTER3 (h5_err_t, - "list=0x%p, id=%llu, idx=%llu", - list, - (long long unsigned)id, - (long long unsigned)idx); + H5_PRIV_API_ENTER (h5_err_t, + "list=%p, id=%llu, idx=%llu", + list, + (long long unsigned)id, + (long long unsigned)idx); if (*list == NULL) { TRY (h5priv_alloc_idlist (list, 2)); } else if ((*list)->num_items == (*list)->size) { @@ -99,9 +95,9 @@ h5priv_find_idlist ( h5_loc_idlist_t* list, const h5_loc_id_t item ) { - H5_PRIV_API_ENTER2 (h5_err_t, - "list=0x%p, item=%llu", - list, (long long unsigned)item); + H5_PRIV_API_ENTER (h5_err_t, + "list=%p, item=%llu", + list, (long long unsigned)item); if (!list) { H5_PRIV_API_LEAVE (-1); } @@ -137,9 +133,9 @@ h5priv_search_idlist ( h5_loc_idlist_t** list, h5_loc_id_t item ) { - H5_PRIV_API_ENTER2 (h5_err_t, - "list=0x%p, item=%llu", - list, (long long unsigned)item); + H5_PRIV_API_ENTER (h5_err_t, + "list=%p, item=%llu", + list, (long long unsigned)item); h5_loc_idx_t idx = h5priv_find_idlist (*list, item); if (idx < 0) { idx = -(idx+1); @@ -148,14 +144,162 @@ h5priv_search_idlist ( H5_PRIV_API_RETURN (idx); } +/////////////////////////////////////////////////////////////////////////////// + +/* + Allocate new/empty string-list + */ +h5_err_t +h5priv_alloc_strlist ( + h5_strlist_t** list, + const h5_size_t size + ) { + H5_PRIV_API_ENTER (h5_err_t, + "list=%p, size=%llu", + list, (long long unsigned)size); + TRY (*list = h5_calloc ( + 1, sizeof (**list)+size*sizeof ((*list)->items[0]))); + (*list)->size = size; + H5_PRIV_API_RETURN (H5_SUCCESS); +} + +h5_err_t +h5priv_free_strlist ( + h5_strlist_t** list + ) { + H5_PRIV_API_ENTER (h5_err_t, "list=%p", list); + if (list == NULL || *list == NULL) H5_PRIV_API_LEAVE (H5_SUCCESS); + h5_strlist_t* l = *list; + for (size_t i = 0; i < l->size; i++) { + TRY (h5_free(l->items[i])); + } + TRY (h5_free (l)); + l = NULL; + H5_PRIV_API_RETURN (H5_SUCCESS); +} + +static inline h5_err_t +grow_strlist ( + h5_strlist_t** list, + size_t new_size + ) { + H5_PRIV_API_ENTER (h5_err_t, "list=%p, new_size=%zu", list, new_size); + size_t num_bytes = sizeof (**list) + (new_size-1)*sizeof((*list)->items[0]); + TRY (*list = h5_alloc (*list, num_bytes)); + (*list)->size = new_size; + H5_PRIV_FUNC_RETURN (H5_SUCCESS); +} + +/* + Add item to list at position given by \c idx. +*/ +ssize_t +h5priv_insert_strlist ( + h5_strlist_t** list, + const char const* item, + size_t idx + ) { + H5_PRIV_API_ENTER (ssize_t, + "list=%p, item=%s, idx=%llu", + list, item, (long long unsigned)idx); + if (*list == NULL) { + TRY (h5priv_alloc_strlist (list, 2)); + } else if ((*list)->num_items == (*list)->size) { + h5_size_t size = (*list)->size; + if (size == 0) { + size = 16; + } else { + size *= 2; + } + TRY (grow_strlist (list, size)); + } + h5_strlist_t* l = *list; + if (idx == -1) { + idx = l->num_items; + } else { + memmove ( + &l->items[idx+1], + &l->items[idx], + (l->num_items - idx) * sizeof (l->items[0])); + } + TRY (l->items[idx] = h5_strdup(item)); + l->num_items++; + H5_PRIV_API_RETURN (idx); +} + +/* + Find ID in sorted list +*/ +ssize_t +h5priv_find_strlist ( + h5_strlist_t* list, + const char* const item + ) { + H5_PRIV_API_ENTER (ssize_t, "list=%p, item=%s", list, item); + if (!list) { + H5_PRIV_API_LEAVE (-1); + } + register h5_loc_idx_t low = 0; + register h5_loc_idx_t high = list->num_items - 1; + register h5_loc_id_t diff; + register h5_loc_id_t mid; + while (low <= high) { + mid = (low + high) / 2; + diff = strcmp (list->items[mid], item); + if ( diff > 0 ) + high = mid - 1; + else if ( diff < 0 ) + low = mid + 1; + else + H5_PRIV_API_LEAVE (mid); // found + } + H5_PRIV_API_RETURN (-(low+1)); // not found +} + +/* + Search in sorted list. If item is not in list, add it. + */ +ssize_t +h5priv_search_strlist ( + h5_strlist_t** list, + const char* const item + ) { + H5_PRIV_API_ENTER (h5_err_t, "list=%p, item=%s", list, item); + h5_loc_idx_t idx = h5priv_find_strlist (*list, item); + if (idx < 0) { + idx = -(idx+1); + TRY (idx = h5priv_insert_strlist (list, item, idx)); + } + H5_PRIV_API_RETURN (idx); +} + +h5_err_t +h5priv_remove_strlist ( + h5_strlist_t* list, + const char* const item + ) { + H5_PRIV_API_ENTER (h5_err_t, "list=%p, item=%s", list, item); + ssize_t idx = h5priv_find_strlist (list, item); + if (idx < 0) H5_PRIV_API_LEAVE (-1); + + list->num_items--; + memmove ( + &list->items[idx], + &list->items[idx+1], + (list->num_items - idx) * sizeof (list->items[0])); + H5_PRIV_API_RETURN (idx); +} + + +/////////////////////////////////////////////////////////////////////////////// h5_err_t h5priv_alloc_idxmap ( h5_idxmap_t* map, const h5_size_t size ) { - H5_PRIV_API_ENTER2 (h5_err_t, - "map=0x%p, size=%llu", + H5_PRIV_API_ENTER (h5_err_t, + "map=%p, size=%llu", map, (long long unsigned)size); int new = (map->items == NULL); size_t size_in_bytes = size * sizeof (map->items[0]); @@ -171,11 +315,11 @@ h5priv_insert_idxmap ( h5_glb_idx_t glb_idx, h5_loc_idx_t loc_idx ) { - H5_PRIV_API_ENTER3 (h5_err_t, - "map=0x%p, glb_idx=%llu, loc_idx=%llu", - map, - (long long unsigned)glb_idx, - (long long unsigned)loc_idx); + H5_PRIV_API_ENTER (h5_err_t, + "map=%p, glb_idx=%llu, loc_idx=%llu", + map, + (long long unsigned)glb_idx, + (long long unsigned)loc_idx); if (map->num_items == map->size) H5_PRIV_API_LEAVE ( HANDLE_H5_OVERFLOW_ERR ( @@ -213,9 +357,9 @@ h5priv_search_idxmap ( h5_idxmap_t* map, h5_glb_idx_t value ) { - H5_PRIV_API_ENTER2 (h5_err_t, - "map=0x%p, value=%lld", - map, (long long)value); + H5_PRIV_API_ENTER (h5_err_t, + "map=%p, value=%lld", + map, (long long)value); register h5_loc_idx_t low = 0; register h5_loc_idx_t high = map->num_items - 1; while (low <= high) { @@ -249,7 +393,7 @@ h5_err_t h5priv_sort_idxmap ( h5_idxmap_t* map ) { - H5_PRIV_API_ENTER1 (h5_err_t, "map=0x%p", map); + H5_PRIV_API_ENTER (h5_err_t, "map=%p", map); qsort ( map->items, map->num_items, sizeof (map->items[0]), cmp_idxmap_items); H5_PRIV_API_RETURN (H5_SUCCESS); diff --git a/src/h5core/h5_maps_private.h b/src/h5core/h5_maps_private.h index 3a720b4..1bd1c6c 100644 --- a/src/h5core/h5_maps_private.h +++ b/src/h5core/h5_maps_private.h @@ -1,10 +1,17 @@ #ifndef __H5_MAPS_PRIVATE_H #define __H5_MAPS_PRIVATE_H +typedef struct { + size_t size; + size_t num_items; + char* items[1]; +} h5_strlist_t; + + h5_err_t h5priv_alloc_idlist ( h5_loc_idlist_t **list, - const h5_size_t size + const int32_t size ); h5_err_t @@ -30,6 +37,25 @@ h5priv_search_idlist ( h5_loc_idlist_t** list, h5_loc_id_t item ); + +h5_err_t +h5priv_alloc_strlist (h5_strlist_t**, const h5_size_t); + +h5_err_t +h5priv_free_strlist (h5_strlist_t**); + +ssize_t +h5priv_insert_strlist (h5_strlist_t**, const char const*, size_t); + +ssize_t +h5priv_find_strlist (h5_strlist_t*, const char* const item); + +ssize_t +h5priv_search_strlist (h5_strlist_t**, const char* const); + +h5_err_t +h5priv_remove_strlist (h5_strlist_t*, const char* const); + h5_err_t h5priv_alloc_idxmap ( h5_idxmap_t *map, diff --git a/src/h5core/h5_mpi.c b/src/h5core/h5_mpi.c index 94fef91..2ba08da 100644 --- a/src/h5core/h5_mpi.c +++ b/src/h5core/h5_mpi.c @@ -12,8 +12,8 @@ h5priv_mpi_recv( const int tag, const MPI_Comm comm ) { - MPI_WRAPPER_ENTER4 (h5_err_t, - "buf=0x%p, count=%d, type=?, from=%d, tag=%d, comm=?", + MPI_WRAPPER_ENTER (h5_err_t, + "buf=%p, count=%d, type=?, from=%d, tag=%d, comm=?", buf, count, from, tag); int err = MPI_Recv( buf, @@ -38,8 +38,8 @@ h5priv_mpi_send( const int tag, const MPI_Comm comm ) { - MPI_WRAPPER_ENTER4 (h5_err_t, - "buf=0x%p, count=%d, type=?, to=%d, tag=%d, comm=?", + MPI_WRAPPER_ENTER (h5_err_t, + "buf=%p, count=%d, type=?, to=%d, tag=%d, comm=?", buf, count, to, tag); int err = MPI_Send( buf, @@ -62,8 +62,8 @@ h5priv_mpi_bcast ( const int root, const MPI_Comm comm ) { - MPI_WRAPPER_ENTER3 (h5_err_t, - "buf=0x%p, count=%d, type=?, root=%d, comm=?", + MPI_WRAPPER_ENTER (h5_err_t, + "buf=%p, count=%d, type=?, root=%d, comm=?", buf, count, root); int err = MPI_Bcast( buf, @@ -87,9 +87,9 @@ h5priv_mpi_sum ( const MPI_Datatype type, const MPI_Comm comm ) { - MPI_WRAPPER_ENTER3 (h5_err_t, - "sendbuf=0x%p, recvbuf=0x%p, count=%d, type=?, comm=?", - sendbuf, recvbuf, count); + MPI_WRAPPER_ENTER (h5_err_t, + "sendbuf=%p, recvbuf=%p, count=%d, type=?, comm=?", + sendbuf, recvbuf, count); int err = MPI_Allreduce( sendbuf, recvbuf, @@ -111,8 +111,8 @@ h5priv_mpi_prefix_sum ( const MPI_Datatype type, const MPI_Comm comm ) { - MPI_WRAPPER_ENTER3 (h5_err_t, - "sendbuf=0x%p, recvbuf=0x%p, count=%d, type=?, comm=?", + MPI_WRAPPER_ENTER (h5_err_t, + "sendbuf=%p, recvbuf=%p, count=%d, type=?, comm=?", sendbuf, recvbuf, count); int err = MPI_Scan( sendbuf, @@ -137,8 +137,9 @@ h5priv_mpi_allgather ( const MPI_Datatype recvtype, const MPI_Comm comm ) { - MPI_WRAPPER_ENTER4 (h5_err_t, - "sendbuf=0x%p, sendcount=%d, sendtype=?, recvbuf=0x%p, recvcount=%d, recvtype=?, comm=?", + MPI_WRAPPER_ENTER (h5_err_t, + "sendbuf=%p, sendcount=%d, sendtype=?, recvbuf=%p, " + "recvcount=%d, recvtype=?, comm=?", sendbuf, sendcount, recvbuf, recvcount); int err = MPI_Allgather ( sendbuf, @@ -158,8 +159,7 @@ h5priv_mpi_comm_size ( MPI_Comm comm, int* size ) { - MPI_WRAPPER_ENTER1 (h5_err_t, - "comm=?, size=0x%p", size); + MPI_WRAPPER_ENTER (h5_err_t, "comm=?, size=%p", size); int err = MPI_Comm_size (comm, size); if (err != MPI_SUCCESS) MPI_WRAPPER_LEAVE (h5_error (H5_ERR_MPI, "Cannot get communicator size")); @@ -172,8 +172,7 @@ h5priv_mpi_comm_rank ( MPI_Comm comm, int* rank ) { - MPI_WRAPPER_ENTER1 (h5_err_t, - "comm=?, rank=0x%p", rank); + MPI_WRAPPER_ENTER (h5_err_t, "comm=?, rank=%p", rank); int err = MPI_Comm_rank (comm, rank); if (err != MPI_SUCCESS) MPI_WRAPPER_LEAVE (h5_error (H5_ERR_MPI, "Cannot get this task's rank")); @@ -186,7 +185,7 @@ h5priv_mpi_type_contiguous ( const MPI_Datatype oldtype, MPI_Datatype *const newtype ) { - MPI_WRAPPER_ENTER1 (h5_err_t, "nelems=%lu, oldtype=?, newtype=?", (long unsigned)nelems); + MPI_WRAPPER_ENTER (h5_err_t, "nelems=%lu, oldtype=?, newtype=?", (long unsigned)nelems); int err; err = MPI_Type_contiguous ( nelems, oldtype, newtype ); if (err != MPI_SUCCESS) @@ -201,7 +200,7 @@ h5_err_t h5priv_mpi_type_free ( MPI_Datatype *type ) { - MPI_WRAPPER_ENTER1 (h5_err_t, "type=0x%p", type); + MPI_WRAPPER_ENTER (h5_err_t, "type=%p", type); int err = MPI_Type_free( type ); if (err != MPI_SUCCESS) MPI_WRAPPER_LEAVE (h5_error(H5_ERR_MPI, "Cannot free MPI type")); @@ -217,8 +216,9 @@ h5priv_mpi_cart_create ( int reorder, MPI_Comm *new_comm ) { - MPI_WRAPPER_ENTER5 (h5_err_t, "old_comm=?, ndims=%d, dims=0x%p, period=0x%p, reorder=%d, new_comm=0x%p", - ndims, dims, period, reorder, new_comm); + MPI_WRAPPER_ENTER (h5_err_t, "old_comm=?, ndims=%d, dims=%p, period=%p, " + "reorder=%d, new_comm=%p", + ndims, dims, period, reorder, new_comm); int err = MPI_Cart_create( old_comm, ndims, dims, period, reorder, new_comm); if (err != MPI_SUCCESS) @@ -233,8 +233,8 @@ h5priv_mpi_cart_coords ( int maxdim, int *coords ) { - MPI_WRAPPER_ENTER3 (h5_err_t, "comm=?, rank=%d, maxdim=%d, coords=0x%p", - rank, maxdim, coords); + MPI_WRAPPER_ENTER (h5_err_t, "comm=?, rank=%d, maxdim=%d, coords=%p", + rank, maxdim, coords); int err = MPI_Cart_coords( comm, rank, maxdim, coords ); if (err != MPI_SUCCESS) MPI_WRAPPER_LEAVE (h5_error(H5_ERR_MPI, "Cannot create cartesian grid")); diff --git a/src/h5core/h5_openclose.c b/src/h5core/h5_openclose.c index 67544e7..059d6c9 100644 --- a/src/h5core/h5_openclose.c +++ b/src/h5core/h5_openclose.c @@ -24,7 +24,7 @@ h5_check_filehandle ( h5_file_t* const f /*!< filehandle to check validity of */ ) { - if (f == NULL || f->file < 0 || f->u == NULL || f->b == NULL || f->t == NULL) { + if (f == NULL || f->file < 0 || f->u == NULL || f->b == NULL) { return h5_error ( H5_ERR_BADFD, "Called with bad filehandle."); @@ -36,7 +36,7 @@ h5_check_filehandle ( Initialize H5Part */ static herr_t -h5priv_error_handler ( +hdf5_error_handler ( hid_t estack_id, void* __f ) { @@ -62,7 +62,7 @@ static h5_err_t h5upriv_open_file ( h5_file_t* const f /*!< IN: file handle */ ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_PRIV_API_ENTER (h5_err_t, "f=%p", f); TRY (f->u = (h5u_fdata_t*)h5_alloc (NULL, sizeof (*f->u))); h5u_fdata_t *u = f->u; @@ -93,7 +93,7 @@ static h5_err_t h5bpriv_open_file ( h5_file_t * const f /*!< IN: file handle */ ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_PRIV_API_ENTER (h5_err_t, "f=%p", f); h5b_fdata_t* b; if (f->b) @@ -123,37 +123,12 @@ h5bpriv_open_file ( H5_PRIV_API_RETURN (H5_SUCCESS); } -/*! - \ingroup h5_core_filehandling - - Open file with name \c filename. This function is available in the paralell - and serial version. In the serial case \c comm may have any value. - - \return File handle. - \return NULL on error. -*/ -h5_file_p -h5_open_file ( - const char* filename, /*!< The name of the data file to open. */ - h5_int32_t flags, /*!< The access mode for the file. */ - MPI_Comm comm /*!< MPI communicator */ +static inline +h5_err_t mpi_init ( + h5_file_t* const f, + MPI_Comm comm ) { - H5_CORE_API_ENTER2 (h5_file_p, - "filename=\"%s\", flags=%d, ...", - filename, flags); - h5_info ("Opening file %s.", filename); - h5_file_p f = NULL; - TRY2 (f = h5_calloc (1, sizeof (h5_file_t))); - - TRY2 (hdf5_set_errorhandler (H5E_DEFAULT, h5priv_error_handler, NULL)); - TRY2 (h5_set_stepname_fmt (f, H5_STEPNAME, H5_STEPWIDTH)); - - f->xfer_prop = f->create_prop = f->access_prop = H5P_DEFAULT; - - f->comm = comm; /* init values for serial case */ - f->nprocs = 1; - f->myproc = 0; - + H5_INLINE_FUNC_ENTER (h5_err_t); #ifdef PARALLEL_IO TRY2 (h5priv_mpi_comm_size (comm, &f->nprocs)); TRY2 (h5priv_mpi_comm_rank (comm, &f->myproc)); @@ -162,38 +137,61 @@ h5_open_file ( rather than the access_prop which is for file creation. */ TRY2 (f->xfer_prop = hdf5_create_property(H5P_DATASET_XFER)); TRY2 (f->access_prop = hdf5_create_property(H5P_FILE_ACCESS)); - TRY2 (f->create_prop = hdf5_create_property(H5P_FILE_CREATE)); /* select the HDF5 VFD */ - if (flags & H5_VFD_MPIPOSIX) { + if (f->flags & H5_VFD_MPIPOSIX) { h5_info("Selecting MPI-POSIX VFD"); hbool_t use_gpfs = 0; // TODO autodetect GPFS? TRY2 (hdf5_set_fapl_mpiposix_property(f->access_prop, comm, use_gpfs)); } else { h5_info("Selecting MPI-IO VFD"); TRY2 (hdf5_set_fapl_mpio_property(f->access_prop, comm, MPI_INFO_NULL)); - if (flags & H5_VFD_INDEPENDENT) { + if (f->flags & H5_VFD_INDEPENDENT) { h5_info("MPI-IO: Using independent mode"); } else { h5_info("MPI-IO: Using collective mode"); TRY2 (hdf5_set_dxpl_mpio_property(f->xfer_prop, H5FD_MPIO_COLLECTIVE) ); } } -#endif /* PARALLEL_IO */ - #ifdef H5_USE_LUSTRE - TRY (h5_optimize_for_lustre(f, filename)); + if (f->flags & H5_FS_LUSTRE) { + TRY (h5_optimize_for_lustre(f, filename)); + } #endif +#endif /* PARALLEL_IO */ + H5_INLINE_FUNC_RETURN (H5_SUCCESS); +} - if (flags & H5_O_RDONLY) { +static inline +h5_err_t set_alignment ( + h5_file_t* const f, + h5_size_t align + ) { + H5_INLINE_FUNC_ENTER (h5_err_t); + if ( align != 0 ) { + h5_info ("Setting HDF5 alignment to %llu bytes", align); + TRY (hdf5_set_alignment_property (f->access_prop, 0, align)); + h5_info ("Setting HDF5 meta block to %llu bytes", align); + TRY (H5Pset_meta_block_size (f->access_prop, align)); + } + H5_INLINE_FUNC_RETURN (H5_SUCCESS); +} + +static inline h5_err_t +open_file ( + h5_file_t* const f, + const char* const filename + ) { + H5_INLINE_FUNC_ENTER (h5_err_t); + if (f->mode & H5_O_RDONLY) { f->file = H5Fopen (filename, H5F_ACC_RDONLY, f->access_prop); } - else if (flags & H5_O_WRONLY){ + else if (f->mode & H5_O_WRONLY){ f->file = H5Fcreate (filename, H5F_ACC_TRUNC, f->create_prop, f->access_prop); f->empty = 1; } - else if (flags & H5_O_APPEND || flags & H5_O_RDWR) { + else if (f->mode & H5_O_APPEND || f->mode & H5_O_RDWR) { int fd = open (filename, O_RDONLY, 0); if ((fd == -1) && (errno == ENOENT)) { f->file = H5Fcreate (filename, H5F_ACC_TRUNC, @@ -208,30 +206,75 @@ h5_open_file ( } else { H5_PRIV_FUNC_LEAVE ( - (h5_file_p)h5_error ( + h5_error ( H5_ERR_INVAL, - "Invalid file access mode \"%d\".", flags)); + "Invalid file access mode '%d'.", f->mode)); } if (f->file < 0) H5_PRIV_FUNC_LEAVE ( - (h5_file_p)h5_error ( + h5_error ( H5_ERR_HDF5, - "Cannot open file \"%s\" with mode \"%d\"", - filename, flags)); - TRY2 (f->root_gid = hdf5_open_group (f->file, "/" )); + "Cannot open file '%s' with mode '%d'", + filename, f->mode)); + H5_INLINE_FUNC_RETURN (H5_SUCCESS); +} + +/*! + \ingroup h5_core_filehandling + + Open file with name \c filename. This function is available in the paralell + and serial version. In the serial case \c comm may have any value. + + \param[in] filename The name of the data file to open. + \param[in] flags The access mode for the file. + \param[in] comm MPI communicator + \param[in] align Number of bytes for setting alignment, + metadata block size, etc. Set to 0 to disable. + + \return File handle. + \return H5_ERR on error. +*/ +h5_file_p +h5_open_file ( + const char* filename, + h5_int32_t flags, + MPI_Comm comm, + h5_size_t align + ) { + H5_CORE_API_ENTER (h5_file_p, + "filename='%s', flags=%d, comm=?, align=%llu", + filename, flags, align); + h5_info ("Opening file %s.", filename); + h5_file_p f = NULL; + TRY2 (f = h5_calloc (1, sizeof (h5_file_t))); + + TRY2 (hdf5_set_errorhandler (H5E_DEFAULT, hdf5_error_handler, NULL)); + TRY2 (h5_set_stepname_fmt (f, H5_STEPNAME, H5_STEPWIDTH)); + + /* init values */ + f->comm = comm; + f->nprocs = 1; // queried later + f->myproc = 0; // queried later f->mode = flags; f->step_gid = -1; f->throttle = 0; - sprintf ( f->step_name, "%s#%0*lld", f->prefix_step_name, f->width_step_idx, (long long)f->step_idx); + f->xfer_prop = f->access_prop = H5P_DEFAULT; + TRY2 (f->create_prop = hdf5_create_property(H5P_FILE_CREATE)); + + TRY2 (mpi_init (f, comm)); + TRY2 (set_alignment (f, align)); + TRY2 (open_file (f, filename)); + + TRY2 (f->root_gid = hdf5_open_group (f->file, "/" )); + TRY2 (h5upriv_open_file (f)); TRY2 (h5bpriv_open_file (f)); - TRY2 (h5tpriv_open_file (f)); H5_CORE_API_RETURN (f); } @@ -249,7 +292,7 @@ static h5_err_t h5upriv_close_file ( h5_file_t* const f /*!< file handle */ ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_PRIV_API_ENTER (h5_err_t, "f=%p", f); struct h5u_fdata* u = f->u; h5_errno = H5_SUCCESS; @@ -277,7 +320,7 @@ static h5_err_t h5bpriv_close_file ( h5_file_t* const f /*!< IN: file handle */ ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_PRIV_API_ENTER (h5_err_t, "f=%p", f); struct h5b_fdata* b = f->b; TRY (hdf5_close_group (b->block_gid)); TRY (hdf5_close_group (b->field_gid)); @@ -307,7 +350,7 @@ h5_err_t h5_close_file ( h5_file_t* const f /*!< file handle */ ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_err_t, "f=%p", f); h5_errno = H5_SUCCESS; CHECK_FILEHANDLE (f); @@ -315,7 +358,6 @@ h5_close_file ( TRY (h5priv_close_step (f)); TRY (h5upriv_close_file (f)); TRY (h5bpriv_close_file (f)); - TRY (h5tpriv_close_file (f)); TRY (hdf5_close_property (f->xfer_prop)); TRY (hdf5_close_property (f->access_prop)); TRY (hdf5_close_property (f->create_prop)); @@ -327,17 +369,17 @@ h5_close_file ( h5_err_t h5_flush_step ( - h5_file_t * const f + h5_file_t* const f ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_err_t, "f=%p", f); H5_CORE_API_RETURN (hdf5_flush (f->step_gid, H5F_SCOPE_LOCAL)); } h5_err_t h5_flush_file ( - h5_file_t * const f + h5_file_t* const f ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_err_t, "f=%p", f); H5_CORE_API_RETURN (hdf5_flush (f->file, H5F_SCOPE_GLOBAL)); } @@ -358,8 +400,7 @@ h5_set_stepname_fmt ( const char* name, int width ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, name=\"%s\", width=%d", f, name, width); + H5_CORE_API_ENTER (h5_err_t, "f=%p, name='%s', width=%d", f, name, width); if (width < 0) width = 0; else if (width > H5_STEPNAME_LEN - 1) width = H5_STEPNAME_LEN - 1; strncpy ( @@ -419,7 +460,7 @@ int h5_get_num_procs ( h5_file_t* const f /*!< file handle */ ) { - H5_CORE_API_ENTER1 (int, "f=0x%p", f); + H5_CORE_API_ENTER (int, "f=%p", f); H5_CORE_API_RETURN (f->nprocs); } @@ -434,7 +475,7 @@ hid_t h5_get_hdf5_file( h5_file_t* const f /*!< file handle */ ) { - H5_CORE_API_ENTER1 (hid_t, "f=0x%p", f); + H5_CORE_API_ENTER (hid_t, "f=%p", f); H5_CORE_API_RETURN (f->file); } diff --git a/src/h5core/h5_readwrite.c b/src/h5core/h5_readwrite.c index d42bbe9..d637402 100644 --- a/src/h5core/h5_readwrite.c +++ b/src/h5core/h5_readwrite.c @@ -21,12 +21,12 @@ h5priv_write_dataset_by_name ( hid_t (*set_diskspace)(h5_file_t*,hid_t), const void* const data ) { - H5_PRIV_API_ENTER7 (h5_err_t, - "f=0x%p, loc_id=%d (%s), dsinfo=0x%p, set_memspace=0x%p, " - "set_diskspace=0x%p, data=0x%p", - f, loc_id, hdf5_get_objname(loc_id), - dsinfo, - set_memspace, set_diskspace, data); + H5_PRIV_API_ENTER (h5_err_t, + "f=%p, loc_id=%d (%s), dsinfo=%p, set_memspace=%p, " + "set_diskspace=%p, data=%p", + f, loc_id, hdf5_get_objname(loc_id), + dsinfo, + set_memspace, set_diskspace, data); h5_info ("Writing dataset %s/%s.", hdf5_get_objname (loc_id), dsinfo->name); @@ -97,12 +97,12 @@ h5priv_read_dataset ( hid_t (*set_dspace)(h5_file_t*,hid_t), void* const data ) { - H5_PRIV_API_ENTER7 (h5_err_t, - "f=0x%p, dset_id=%d (%s), dsinfo=0x%p, set_mspace=0x%p, " - "set_dspace=0x%p, data=0x%p", - f, dset_id, hdf5_get_objname(dset_id), - dsinfo, - set_mspace, set_dspace, data); + H5_PRIV_API_ENTER (h5_err_t, + "f=%p, dset_id=%d (%s), dsinfo=%p, set_mspace=%p, " + "set_dspace=%p, data=%p", + f, dset_id, hdf5_get_objname(dset_id), + dsinfo, + set_mspace, set_dspace, data); hid_t mspace_id; hid_t dspace_id; @@ -137,12 +137,12 @@ h5priv_read_dataset_by_name ( hid_t (*set_dspace)(h5_file_t*,hid_t), void* const data ) { - H5_PRIV_API_ENTER7 (h5_err_t, - "f=0x%p, loc_id=%d (%s), dsinfo=0x%p, " - "set_mpace=0x%p, set_dspace=0x%p, data=0x%p", - f, loc_id, hdf5_get_objname(loc_id), - dsinfo, - set_mspace, set_dspace, data); + H5_PRIV_API_ENTER (h5_err_t, + "f=%p, loc_id=%d (%s), dsinfo=%p, " + "set_mpace=%p, set_dspace=%p, data=%p", + f, loc_id, hdf5_get_objname(loc_id), + dsinfo, + set_mspace, set_dspace, data); hid_t dset_id; TRY (dset_id = hdf5_open_dataset (loc_id, dsinfo->name)); TRY (h5priv_read_dataset (f, dset_id, dsinfo, set_mspace, set_dspace, data)); @@ -155,10 +155,9 @@ h5_err_t h5priv_close_step ( h5_file_t* const f ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_PRIV_API_ENTER (h5_err_t, "f=%p", f); if (f->step_gid <= 0) H5_PRIV_API_LEAVE (H5_SUCCESS); - TRY (h5tpriv_close_step (f)); TRY (hdf5_close_group (f->step_gid)); f->step_gid = -1; @@ -171,7 +170,7 @@ h5_set_step ( h5_file_t* const f, /*!< [in] Handle to open file */ const h5_id_t step_idx /*!< [in] Step to set. */ ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, step_idx=%lld", f, (long long)step_idx); + H5_CORE_API_ENTER (h5_err_t, "f=%p, step_idx=%lld", f, (long long)step_idx); TRY (h5priv_close_step (f)); f->step_idx = step_idx; @@ -184,9 +183,8 @@ h5_set_step ( f->myproc, (long long)f->step_idx, (long long)(size_t) f); - TRY (f->step_gid = h5priv_open_group (f, f->file, f->step_name)); - TRY (h5tpriv_init_step (f)); - + + TRY (f->step_gid = h5priv_open_group (is_writable(f), f->file, f->step_name)); H5_CORE_API_RETURN (H5_SUCCESS); } @@ -197,7 +195,7 @@ h5_int64_t h5_normalize_h5_type ( hid_t type ) { - H5_CORE_API_ENTER1 (h5_int64_t, "type=%d", type); + H5_CORE_API_ENTER (h5_int64_t, "type=%d", type); H5T_class_t tclass; int size; TRY (tclass = H5Tget_class (type)); @@ -207,9 +205,10 @@ h5_normalize_h5_type ( case H5T_INTEGER: if (size==8) { H5_CORE_API_LEAVE (H5_INT64_T); - } - else if (size==4) { + } else if (size==4) { H5_CORE_API_LEAVE (H5_INT32_T); + } else if (size==2) { + H5_CORE_API_LEAVE (H5_INT16_T); } break; case H5T_FLOAT: @@ -233,9 +232,9 @@ h5_get_dataset_type( const hid_t group_id, const char* dset_name ) { - H5_CORE_API_ENTER2 (h5_int64_t, - "group_id=%d, dset_name=\"%s\"", - group_id, dset_name); + H5_CORE_API_ENTER (h5_int64_t, + "group_id=%d, dset_name='%s'", + group_id, dset_name); hid_t dset_id; hid_t hdf5_type; h5_int64_t type; @@ -253,7 +252,7 @@ h5_has_step ( h5_file_t* const f, /*!< [in] Handle to open file */ const h5_id_t step_idx /*!< [in] Step number to query */ ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, step_idx=%lld", f, (long long)step_idx); + H5_CORE_API_ENTER (h5_err_t, "f=%p, step_idx=%lld", f, (long long)step_idx); char name[2*H5_STEPNAME_LEN]; sprintf (name, "%s#%0*lld", @@ -266,9 +265,7 @@ h5_normalize_dataset_name ( const char *name, char *name2 ) { - H5_CORE_API_ENTER2 (h5_err_t, - "name=\"%s\", name2=\"%s\"", - name, name2); + H5_CORE_API_ENTER (h5_err_t, "name='%s', name2='%s'", name, name2); if ( strlen(name) > H5_DATANAME_LEN-1 ) { strncpy ( name2, name, H5_DATANAME_LEN-1 ); name2[H5_DATANAME_LEN-1] = '\0'; @@ -294,7 +291,7 @@ h5_set_throttle ( h5_file_t* const f, const int factor ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, factor=%d", f, factor); + H5_CORE_API_ENTER (h5_err_t, "f=%p, factor=%d", f, factor); if ( (f->mode & H5_VFD_INDEPENDENT) || (f->mode & H5_VFD_MPIPOSIX) ) { f->throttle = factor; h5_info ("Throttling enabled with factor = %d", f->throttle ); @@ -310,7 +307,7 @@ h5_err_t h5_start_throttle ( h5_file_t* const f ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_err_t, "f=%p", f); if (f->throttle > 0) { int token = 1; h5_info ("Throttling with factor = %d", f->throttle); @@ -334,7 +331,7 @@ h5_err_t h5_end_throttle ( h5_file_t* const f ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_err_t, "f=%p", f); if (f->throttle > 0) { int token; if (f->myproc + f->throttle < f->nprocs) { diff --git a/src/h5core/h5_syscall.c b/src/h5core/h5_syscall.c index d6d3fb3..d703235 100644 --- a/src/h5core/h5_syscall.c +++ b/src/h5core/h5_syscall.c @@ -5,61 +5,6 @@ #include "h5core/h5_core.h" #include "h5_core_private.h" -void_p -h5_alloc ( - void* ptr, - const size_t size - ) { - MALLOC_WRAPPER_ENTER2 (void_p, - "ptr=%p, size=%lu", ptr, size); - ptr = realloc (ptr, size); - if (ptr == NULL) { - MALLOC_WRAPPER_LEAVE ( - (void_p)h5_error (H5_ERR_NOMEM, "Out of memory.")); - } - MALLOC_WRAPPER_RETURN (ptr); -} - -void_p -h5_calloc ( - const size_t count, - const size_t size - ) { - MALLOC_WRAPPER_ENTER2 (void_p, - "count=%lu , size=%lu", count, size); - void* ptr = calloc (count, size); - if (ptr == NULL) { - MALLOC_WRAPPER_LEAVE ( - (void_p)h5_error (H5_ERR_NOMEM, "Out of memory.")); - } - MALLOC_WRAPPER_RETURN (ptr); -} - -char_p -h5priv_strdup ( - const char* s1 - ) { - MALLOC_WRAPPER_ENTER1 (char_p, "s=%s", s1); - - char_p s2 = h5_calloc (1, strlen (s1)+1 ); - if (s2 == NULL) { - MALLOC_WRAPPER_LEAVE ( - (char_p)h5_error (H5_ERR_NOMEM, "Out of memory.")); - } - MALLOC_WRAPPER_RETURN (strcpy (s2, s1)); - -} - -h5_err_t -h5_free ( - void* ptr - ) { - MALLOC_WRAPPER_ENTER1 (h5_err_t, "ptr=0x%p", ptr); - if (ptr) { - free (ptr); - } - MALLOC_WRAPPER_RETURN (H5_SUCCESS); -} void* h5priv_tsearch ( diff --git a/src/h5core/h5_syscall_private.h b/src/h5core/h5_syscall_private.h index c1d8490..df3b796 100644 --- a/src/h5core/h5_syscall_private.h +++ b/src/h5core/h5_syscall_private.h @@ -1,10 +1,6 @@ #ifndef __H5_SYSCALL_PRIVATE_H #define __H5_SYSCALL_PRIVATE_H -char* -h5priv_strdup ( - const char* s1 - ); void* h5priv_tsearch ( const void* key, diff --git a/src/h5core/h5_types_private.h b/src/h5core/h5_types_private.h index c1861b4..28c2890 100644 --- a/src/h5core/h5_types_private.h +++ b/src/h5core/h5_types_private.h @@ -38,7 +38,6 @@ struct h5_file { struct h5u_fdata *u; struct h5b_fdata *b; - struct h5t_fdata *t; }; struct h5_idxmap_el { diff --git a/src/h5core/h5_va_macros.h b/src/h5core/h5_va_macros.h new file mode 100644 index 0000000..306c08c --- /dev/null +++ b/src/h5core/h5_va_macros.h @@ -0,0 +1,25 @@ +#ifndef __H5_VA_MACROS_H +#define __H5_VA_MACROS_H + +#define PP_NARG(...) \ + PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) +#define PP_NARG_(...) \ + PP_ARG_N(__VA_ARGS__) +#define PP_ARG_N( \ + _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \ + _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \ + _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \ + _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \ + _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \ + _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \ + _61,_62,_63,N,...) N +#define PP_RSEQ_N() \ + 63,62,61,60, \ + 59,58,57,56,55,54,53,52,51,50, \ + 49,48,47,46,45,44,43,42,41,40, \ + 39,38,37,36,35,34,33,32,31,30, \ + 29,28,27,26,25,24,23,22,21,20, \ + 19,18,17,16,15,14,13,12,11,10, \ + 9,8,7,6,5,4,3,2,1,0 + +#endif diff --git a/src/h5core/h5b_attribs.c b/src/h5core/h5b_attribs.c index 99f3d9e..90a5145 100644 --- a/src/h5core/h5b_attribs.c +++ b/src/h5core/h5b_attribs.c @@ -10,16 +10,16 @@ h5_write_field_attrib ( const void *attrib_value, /*!< IN: attribute value */ const h5_int64_t attrib_nelem /*!< IN: number of elements */ ) { - H5_CORE_API_ENTER6 (h5_err_t, - "f=%p, field_name=\"%s\", " - "attrib_name=\"%s\", attrib_type=%d, " - "attrib_value=%p, attrib_nelem=%lld", - f, - field_name, - attrib_name, - attrib_type, - attrib_value, - (long long)attrib_nelem); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, field_name='%s', " + "attrib_name='%s', attrib_type=%d, " + "attrib_value=%p, attrib_nelem=%lld", + f, + field_name, + attrib_name, + attrib_type, + attrib_value, + (long long)attrib_nelem); TRY( h5bpriv_create_field_group(f, field_name) ); TRY( h5_write_attrib ( @@ -41,15 +41,15 @@ h5_read_field_attrib ( const h5_int64_t attrib_type, /*!< IN: attribute type */ void *buffer /*!< OUT: attribute value */ ) { - H5_CORE_API_ENTER5 (h5_err_t, - "f=%p, field_name=\"%s\", " - "attrib_name=\"%s\", attrib_type=%lld, " - "attrib_value=%p", - f, - field_name, - attrib_name, - (long long)attrib_type, - buffer); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, field_name='%s', " + "attrib_name='%s', attrib_type=%lld, " + "attrib_value=%p", + f, + field_name, + attrib_name, + (long long)attrib_type, + buffer); TRY( h5bpriv_open_field_group(f, field_name) ); @@ -68,10 +68,7 @@ h5b_get_num_field_attribs ( h5_file_t *const f, /*b->shape > 0) { TRY (hdf5_close_dataspace (f->b->shape)); f->b->shape = -1; @@ -420,7 +422,7 @@ h5_err_t h5bpriv_open_block_group ( h5_file_t *const f /*!< IN: file handle */ ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_PRIV_API_ENTER (h5_err_t, "f=%p", f); h5b_fdata_t *b = f->b; TRY (hdf5_close_group (b->block_gid)); @@ -437,7 +439,7 @@ static h5_err_t _create_block_group ( h5_file_t *const f /*!< IN: file handle */ ) { - H5_PRIV_FUNC_ENTER1 (h5_err_t, "f=0x%p", f); + H5_PRIV_FUNC_ENTER (h5_err_t, "f=%p", f); h5_err_t exists; TRY (exists = hdf5_link_exists (f->step_gid, H5_BLOCKNAME)); @@ -456,7 +458,7 @@ h5bpriv_have_field_group ( h5_file_t *const f, /*!< IN: file handle */ const char *name ) { - H5_PRIV_API_ENTER2 (h5_err_t, "f=0x%p, name=\"%s\"", f, name); + H5_PRIV_API_ENTER (h5_err_t, "f=%p, name='%s'", f, name); char name2[H5_DATANAME_LEN]; h5_normalize_dataset_name (name, name2); @@ -469,7 +471,7 @@ h5bpriv_open_field_group ( h5_file_t *const f, /*!< IN: file handle */ const char *name ) { - H5_PRIV_API_ENTER2 (h5_err_t, "f=0x%p, name=\"%s\"", f, name); + H5_PRIV_API_ENTER (h5_err_t, "f=%p, name='%s'", f, name); char name2[H5_DATANAME_LEN]; h5_normalize_dataset_name (name, name2); @@ -489,7 +491,7 @@ h5bpriv_create_field_group ( h5_file_t *const f, /*!< IN: file handle */ const char *name /*!< IN: name of field group to create */ ) { - H5_PRIV_API_ENTER2 (h5_err_t, "f=0x%p, name=\"%s\"", f, name); + H5_PRIV_API_ENTER (h5_err_t, "f=%p, name='%s'", f, name); h5b_fdata_t *b = f->b; TRY( _create_block_group(f) ); @@ -527,15 +529,15 @@ h5b_3d_set_view ( const h5_size_t k_start, /*!< IN: start index of \c k */ const h5_size_t k_end /*!< IN: end index of \c k */ ) { - H5_CORE_API_ENTER7 (h5_err_t, - "f=0X%p, " - "i_start=%llu, i_end=%llu, " - "j_start=%llu, j_end=%llu, " - "k_start=%llu, k_end=%llu", - f, - (long long unsigned)i_start, (long long unsigned)i_end, - (long long unsigned)j_start, (long long unsigned)j_end, - (long long unsigned)k_start, (long long unsigned)k_end); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, " + "i_start=%llu, i_end=%llu, " + "j_start=%llu, j_end=%llu, " + "k_start=%llu, k_end=%llu", + f, + (long long unsigned)i_start, (long long unsigned)i_end, + (long long unsigned)j_start, (long long unsigned)j_end, + (long long unsigned)k_start, (long long unsigned)k_end); h5b_partition_t *p = f->b->user_layout; p->i_start = i_start; p->i_end = i_end; @@ -602,15 +604,15 @@ h5b_3d_get_view ( h5_size_t *const k_start, /*!< OUT: start index of \c k */ h5_size_t *const k_end /*!< OUT: end index of \c k */ ) { - H5_CORE_API_ENTER7 (h5_err_t, - "f=0X%p, " - "i_start=0x%p, i_end=0x%p, " - "j_start=0x%p, j_end=0x%p, " - "k_start=0x%p, k_end=0x%p", - f, - i_start, i_end, - j_start, j_end, - k_start, k_end); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, " + "i_start=%p, i_end=%p, " + "j_start=%p, j_end=%p, " + "k_start=%p, k_end=%p", + f, + i_start, i_end, + j_start, j_end, + k_start, k_end); h5b_partition_t *p = f->b->user_layout; *i_start = p->i_start; @@ -633,15 +635,15 @@ h5b_3d_get_reduced_view ( h5_size_t *const k_start, /*!< OUT: start index of \c k */ h5_size_t *const k_end /*!< OUT: end index of \c k */ ) { - H5_CORE_API_ENTER7 (h5_err_t, - "f=0X%p, " - "i_start=0x%p, i_end=0x%p, " - "j_start=0x%p, j_end=0x%p, " - "k_start=0x%p, k_end=0x%p", - f, - i_start, i_end, - j_start, j_end, - k_start, k_end); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, " + "i_start=%p, i_end=%p, " + "j_start=%p, j_end=%p, " + "k_start=%p, k_end=%p", + f, + i_start, i_end, + j_start, j_end, + k_start, k_end); h5b_partition_t *p = f->b->write_layout; *i_start = p->i_start; @@ -661,12 +663,12 @@ h5b_3d_set_chunk ( const h5_size_t j, /*!< IN: size of \c j */ const h5_size_t k /*!< IN: size of \c k */ ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, i=%llu, j=%llu, k=%llu", - f, - (long long unsigned)i, - (long long unsigned)j, - (long long unsigned)k); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, i=%llu, j=%llu, k=%llu", + f, + (long long unsigned)i, + (long long unsigned)j, + (long long unsigned)k); if ( i == 0 || j == 0 || k == 0 ) { h5_info ("Disabling chunking" ); @@ -690,9 +692,9 @@ h5b_3d_get_chunk ( h5_size_t *const j, /*!< OUT: size of \c j */ h5_size_t *const k /*!< OUT: size of \c k */ ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, i=0x%p, j=0x%p, k=0x%p", - f, i, j, k); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, i=%p, j=%p, k=%p", + f, i, j, k); CHECK_TIMEGROUP ( f ); h5b_fdata_t *b = f->b; @@ -729,12 +731,12 @@ h5b_3d_set_grid ( const h5_size_t j, /*!< IN: dimension in \c j */ const h5_size_t k /*!< IN: dimension in \c k */ ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, i=%llu, j=%llu, k=%llu", - f, - (long long unsigned)i, - (long long unsigned)j, - (long long unsigned)k); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, i=%llu, j=%llu, k=%llu", + f, + (long long unsigned)i, + (long long unsigned)j, + (long long unsigned)k); if (i*j*k != f->nprocs) { H5_CORE_API_LEAVE ( h5_error(H5_ERR_INVAL, @@ -768,9 +770,9 @@ h5b_3d_get_grid_coords ( h5_int64_t *j, /*!< OUT: index in \c j */ h5_int64_t *k /*!< OUT: index in \c k */ ) { - H5_CORE_API_ENTER5 (h5_err_t, - "f=0x%p, proc=%d, i=0x%p, j=0x%p, k=0x%p", - f, proc, i, j, k); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, proc=%d, i=%p, j=%p, k=%p", + f, proc, i, j, k); if ( ! f->b->have_grid ) H5_CORE_API_LEAVE ( h5_error(H5_ERR_INVAL, @@ -791,12 +793,12 @@ h5b_3d_set_dims ( const h5_size_t j, /*!< IN: dimension in \c j */ const h5_size_t k /*!< IN: dimension in \c k */ ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, i=%llu, j=%llu, k=%llu", - f, - (long long unsigned)i, - (long long unsigned)j, - (long long unsigned)k); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, i=%llu, j=%llu, k=%llu", + f, + (long long unsigned)i, + (long long unsigned)j, + (long long unsigned)k); if ( ! f->b->have_grid ) H5_CORE_API_LEAVE ( h5_error(H5_ERR_INVAL, @@ -856,12 +858,12 @@ h5b_3d_set_halo ( const h5_size_t j, /*!< IN: radius in \c j */ const h5_size_t k /*!< IN: radius in \c k */ ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, i=%llu, j=%llu, k=%llu", - f, - (long long unsigned)i, - (long long unsigned)j, - (long long unsigned)k); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, i=%llu, j=%llu, k=%llu", + f, + (long long unsigned)i, + (long long unsigned)j, + (long long unsigned)k); if ( ! f->b->have_grid ) { H5_CORE_API_LEAVE ( @@ -888,7 +890,7 @@ h5_ssize_t h5b_get_num_fields ( h5_file_t *const f /*!< IN: File handle */ ) { - H5_CORE_API_ENTER1 (h5_ssize_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f); CHECK_TIMEGROUP( f ); TRY (h5bpriv_open_block_group(f)); @@ -904,10 +906,10 @@ h5b_get_field_info_by_name ( h5_size_t *elem_rank, /*!< OUT: element rank */ h5_int64_t *type /*!< OUT: datatype */ ) { - H5_CORE_API_ENTER6 (h5_err_t, - "f=0x%p, name=\"%s\", " - "field_rank=0x%p, field_dims=0x%p, elem_rank=0x%p, type=0x%p", - f, name, field_rank, field_dims, elem_rank, type); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, name='%s', " + "field_rank=%p, field_dims=%p, elem_rank=%p, type=%p", + f, name, field_rank, field_dims, elem_rank, type); CHECK_TIMEGROUP( f ); hsize_t dims[16]; /* give it plenty of space even though we don't expect rank > 3 */ @@ -956,14 +958,14 @@ h5b_get_field_info ( h5_size_t *elem_rank, /*!< OUT: element rank */ h5_int64_t *type /*!< OUT: datatype */ ) { - H5_CORE_API_ENTER8 (h5_err_t, - "f=0x%p, idx=%llu, " - "name=0x%p, len_name=%llu, " - "field_rank=0x%p, field_dims=0x%p, elem_rank=0x%p, type=0x%p", - f, - (long long unsigned)idx, - name, (long long unsigned)len_name, - field_rank, field_dims, elem_rank, type); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, idx=%llu, " + "name=%p, len_name=%llu, " + "field_rank=%p, field_dims=%p, elem_rank=%p, type=%p", + f, + (long long unsigned)idx, + name, (long long unsigned)len_name, + field_rank, field_dims, elem_rank, type); CHECK_TIMEGROUP( f ); TRY (h5bpriv_open_block_group(f)); diff --git a/src/h5core/h5b_readwrite.c b/src/h5core/h5b_readwrite.c index 9253248..da7f5eb 100644 --- a/src/h5core/h5b_readwrite.c +++ b/src/h5core/h5b_readwrite.c @@ -5,7 +5,7 @@ static h5_err_t _select_hyperslab_for_writing ( h5_file_t *const f /*!< IN: file handle */ ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, "f=%p", f); /* re-use existing hyperslab */ @@ -107,7 +107,9 @@ _write_data ( const void *data, /*!< IN: data to write */ const hid_t type /*!< IN: data type */ ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, + "f=%p, field_name=%s, data_name=%s, data=%p type=%d", + f, field_name, data_name, data, type); hid_t dataset; h5b_fdata_t *b = f->b; @@ -118,13 +120,13 @@ _write_data ( hid_t type_file; TRY( type_file = hdf5_get_dataset_type (dataset) ); if ( type != type_file ) { - return h5_error( + H5_PRIV_FUNC_LEAVE (h5_error( H5_ERR_HDF5, "Field '%s' already has type '%s' " "but was written as '%s'.", field_name, hdf5_get_type_name (type_file), - hdf5_get_type_name (type)); + hdf5_get_type_name (type))); } } else { TRY (dataset = hdf5_create_dataset( @@ -159,9 +161,9 @@ h5b_write_scalar_data ( const void *data, /*!< IN: data to write */ const hid_t type /*!< IN: data type */ ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, field_name=\"%s\", data=0x%p, type=%d", - f, field_name, data, type); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, field_name='%s', data=%p, type=%d", + f, field_name, data, type); CHECK_TIMEGROUP( f ); CHECK_WRITABLE_MODE( f ); CHECK_LAYOUT( f ); @@ -180,12 +182,12 @@ h5b_write_vector3d_data ( const void *zdata, /*!< IN: z data to write */ const hid_t type /*!< IN: data type */ ) { - H5_CORE_API_ENTER6 (h5_err_t, - "f=0x%p, field_name=\"%s\", " - "xdata=0x%p, " - "ydata=0x%p, " - "zdata=0x%p, " - "type=%d", + H5_CORE_API_ENTER (h5_err_t, + "f=%p, field_name='%s', " + "xdata=%p, " + "ydata=%p, " + "zdata=%p, " + "type=%d", f, field_name, xdata, ydata, zdata, type); CHECK_TIMEGROUP( f ); CHECK_WRITABLE_MODE( f ); @@ -203,7 +205,7 @@ _select_hyperslab_for_reading ( h5_file_t *const f, /*!< IN: file handle */ const hid_t dataset ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, "f=%p, dataset=%d", f, dataset); h5b_fdata_t *b = f->b; h5b_partition_t *p = b->user_layout; int rank; @@ -283,7 +285,9 @@ read_data ( void *data, /*!< OUT: ptr to read buffer */ const hid_t type /*!< IN: data type */ ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, + "f=%p, dataset_name=%s, data=%p, type=%d", + f, dataset_name, data, type); hid_t dataset; h5b_fdata_t *b = f->b; @@ -314,9 +318,9 @@ h5b_read_scalar_data ( void *data, /*!< OUT: read bufer */ const hid_t type /*!< IN: data type */ ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, field_name=\"%s\", data=0x%p, type=%d", - f, field_name, data, type); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, field_name='%s', data=%p, type=%d", + f, field_name, data, type); CHECK_TIMEGROUP( f ); CHECK_LAYOUT( f ); TRY( h5bpriv_open_field_group(f, field_name) ); @@ -333,12 +337,12 @@ h5b_read_vector3d_data ( void *zdata, /*!< IN: z data to write */ const hid_t type /*!< IN: data type */ ) { - H5_CORE_API_ENTER6 (h5_err_t, - "f=0x%p, field_name=\"%s\", " - "xdata=0x%p, " - "ydata=0x%p, " - "zdata=0x%p, " - "type=%d", + H5_CORE_API_ENTER (h5_err_t, + "f=%p, field_name='%s', " + "xdata=%p, " + "ydata=%p, " + "zdata=%p, " + "type=%d", f, field_name, xdata, ydata, zdata, type); CHECK_TIMEGROUP( f ); CHECK_LAYOUT( f ); diff --git a/src/h5core/h5t_access_private.h b/src/h5core/h5t_access_private.h index 77e4e4d..cc621f4 100644 --- a/src/h5core/h5t_access_private.h +++ b/src/h5core/h5t_access_private.h @@ -3,73 +3,72 @@ struct h5t_access_methods { h5_generic_loc_elem_t* (*get_loc_elem)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_glb_idx_t (*get_loc_elem_glb_idx) ( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_glb_idx_t (*set_loc_elem_glb_idx) ( - h5_file_t* const, const h5_loc_idx_t, const h5_glb_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_glb_idx_t); h5_loc_idx_t (*get_loc_elem_parent_idx)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_loc_idx_t (*set_loc_elem_parent_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t); h5_loc_id_t (*get_loc_elem_child_idx)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_loc_id_t (*set_loc_elem_child_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t); h5t_lvl_idx_t (*get_loc_elem_level_idx)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5t_lvl_idx_t (*set_loc_elem_level_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5t_lvl_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5t_lvl_idx_t); h5_loc_idx_t* (*get_loc_elem_vertex_indices)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_loc_idx_t (*get_loc_elem_vertex_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t); h5_loc_idx_t (*set_loc_elem_vertex_idx)( - h5_file_t* const, - const h5_loc_idx_t, const h5_loc_idx_t, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t, const h5_loc_idx_t); h5_loc_idx_t* (*get_loc_elem_neighbor_indices)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_loc_idx_t (*get_loc_elem_neighbor_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t); h5_loc_idx_t (*set_loc_elem_neighbor_idx)( - h5_file_t* const, - const h5_loc_idx_t, const h5_loc_idx_t, const h5_loc_idx_t); - + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t, const h5_loc_idx_t); + h5_loc_id_t (*get_loc_entity_parent)( + h5t_mesh_t* const, h5_loc_id_t); + h5_err_t (*get_loc_entity_children)( + h5t_mesh_t* const, const h5_loc_id_t, h5_loc_id_t*); h5_generic_glb_elem_t* (*get_glb_elem)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_glb_id_t (*get_glb_elem_idx)( - h5_file_t* const, const h5_loc_id_t); + h5t_mesh_t* const, const h5_loc_id_t); h5_glb_id_t (*set_glb_elem_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5_glb_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_glb_idx_t); h5_glb_idx_t (*get_glb_elem_parent_idx)( - h5_file_t* const, const h5_loc_id_t); + h5t_mesh_t* const, const h5_loc_id_t); h5_glb_idx_t (*set_glb_elem_parent_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5_glb_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_glb_idx_t); h5_glb_idx_t (*get_glb_elem_child_idx)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_glb_idx_t (*set_glb_elem_child_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5_glb_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_glb_idx_t); h5_glb_idx_t* (*get_glb_elem_vertex_indices)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_glb_idx_t (*get_glb_elem_vertex_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t); h5_glb_id_t (*set_glb_elem_vertex_idx)( - h5_file_t* const, - const h5_loc_idx_t, const h5_loc_idx_t, const h5_glb_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t, const h5_glb_idx_t); h5_glb_idx_t* (*get_glb_elem_neighbor_indices)( - h5_file_t* const, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t); h5_glb_idx_t (*get_glb_elem_neighbor_idx)( - h5_file_t* const, const h5_loc_idx_t, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t); h5_glb_idx_t (*set_glb_elem_neighbor_idx)( - h5_file_t* const, - const h5_loc_idx_t, const h5_loc_idx_t, const h5_glb_idx_t); - h5_err_t (*set_boundary_elem_flag)(h5_file_t* const, const h5_loc_idx_t); - h5_err_t (*clear_boundary_elem_flag)(h5_file_t* const, const h5_loc_idx_t); - h5_err_t (*set_boundary_facet_flag)(h5_file_t* const, const h5_loc_idx_t); - h5_err_t (*clear_boundary_facet_flag)(h5_file_t* const, const h5_loc_idx_t); - int (*is_boundary_elem)(h5_file_t* const, const h5_loc_idx_t); - int (*is_boundary_facet)(h5_file_t* const, const h5_loc_idx_t, const h5_loc_idx_t); - int (*is_boundary_face)(h5_file_t* const, const int, const h5_loc_idx_t, const h5_loc_idx_t); + h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t, const h5_glb_idx_t); + h5_err_t (*set_boundary_elem_flag)(h5t_mesh_t* const, const h5_loc_idx_t); + h5_err_t (*clear_boundary_elem_flag)(h5t_mesh_t* const, const h5_loc_idx_t); + h5_err_t (*set_boundary_facet_flag)(h5t_mesh_t* const, const h5_loc_idx_t); + h5_err_t (*clear_boundary_facet_flag)(h5t_mesh_t* const, const h5_loc_idx_t); + int (*is_boundary_elem)(h5t_mesh_t* const, const h5_loc_idx_t); + int (*is_boundary_facet)(h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t); + int (*is_boundary_face)(h5t_mesh_t* const, const int, const h5_loc_idx_t, const h5_loc_idx_t); }; extern struct h5t_access_methods h5tpriv_access_trim_methods; @@ -77,311 +76,327 @@ extern struct h5t_access_methods h5tpriv_access_tetm_methods; static inline h5_generic_loc_elem_t* h5tpriv_get_loc_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_loc_elem)(f, elem_idx); + return (*m->methods.access->get_loc_elem)(m, elem_idx); } static inline h5_glb_idx_t h5tpriv_set_loc_elem_glb_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t loc_elem_idx, h5_glb_idx_t glb_elem_idx ) { - return (*f->t->methods.access->set_loc_elem_glb_idx)(f, loc_elem_idx, glb_elem_idx); + return (*m->methods.access->set_loc_elem_glb_idx)(m, loc_elem_idx, glb_elem_idx); } static inline h5_glb_idx_t h5tpriv_get_loc_elem_glb_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t loc_elem_idx ) { - return (*f->t->methods.access->get_loc_elem_glb_idx)(f, loc_elem_idx); + return (*m->methods.access->get_loc_elem_glb_idx)(m, loc_elem_idx); } static inline h5_loc_idx_t h5tpriv_get_loc_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_loc_elem_parent_idx)(f, elem_idx); + return (*m->methods.access->get_loc_elem_parent_idx)(m, elem_idx); } static inline h5_loc_idx_t h5tpriv_set_loc_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t parent_idx ) { - return (*f->t->methods.access->set_loc_elem_parent_idx)( - f, elem_idx, parent_idx); + return (*m->methods.access->set_loc_elem_parent_idx)( + m, elem_idx, parent_idx); } static inline h5_loc_idx_t h5tpriv_get_loc_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_loc_elem_child_idx)( - f, elem_idx); + return (*m->methods.access->get_loc_elem_child_idx)(m, elem_idx); } static inline h5_loc_idx_t h5tpriv_set_loc_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t child_idx) { - return (*f->t->methods.access->set_loc_elem_child_idx)( - f, elem_idx, child_idx); + return (*m->methods.access->set_loc_elem_child_idx)( + m, elem_idx, child_idx); } static inline h5t_lvl_idx_t h5tpriv_get_loc_elem_level_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_loc_elem_level_idx)( - f, elem_idx); + return (*m->methods.access->get_loc_elem_level_idx)( + m, elem_idx); } static inline h5t_lvl_idx_t h5tpriv_set_loc_elem_level_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5t_lvl_idx_t lvl_idx ) { - return (*f->t->methods.access->set_loc_elem_level_idx)( - f, elem_idx, lvl_idx); + return (*m->methods.access->set_loc_elem_level_idx)( + m, elem_idx, lvl_idx); } static inline h5_loc_idx_t* h5tpriv_get_loc_elem_vertex_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_loc_elem_vertex_indices)( - f, elem_idx); + return (*m->methods.access->get_loc_elem_vertex_indices)( + m, elem_idx); } static inline h5_loc_idx_t h5tpriv_get_loc_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t face_idx ) { - return (*f->t->methods.access->get_loc_elem_vertex_idx)( - f, elem_idx, face_idx); + return (*m->methods.access->get_loc_elem_vertex_idx)( + m, elem_idx, face_idx); } static inline h5_loc_idx_t h5tpriv_set_loc_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t face_idx, h5_loc_idx_t vertex_idx ) { - return (*f->t->methods.access->set_loc_elem_vertex_idx)( - f, elem_idx, face_idx, vertex_idx); + return (*m->methods.access->set_loc_elem_vertex_idx)( + m, elem_idx, face_idx, vertex_idx); } static inline h5_loc_idx_t* h5tpriv_get_loc_elem_neighbor_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_loc_elem_neighbor_indices)( - f, elem_idx); + return (*m->methods.access->get_loc_elem_neighbor_indices)( + m, elem_idx); } static inline h5_loc_idx_t h5tpriv_get_loc_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t face_idx ) { - return (*f->t->methods.access->get_loc_elem_neighbor_idx)( - f, elem_idx, face_idx); + return (*m->methods.access->get_loc_elem_neighbor_idx)( + m, elem_idx, face_idx); } static inline h5_loc_idx_t h5tpriv_set_loc_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t face_idx, h5_loc_idx_t idx ) { - return (*f->t->methods.access->set_loc_elem_neighbor_idx)( - f, elem_idx, face_idx, idx); + return (*m->methods.access->set_loc_elem_neighbor_idx)( + m, elem_idx, face_idx, idx); +} + +static inline h5_loc_id_t +h5tpriv_get_loc_entity_parent ( + h5t_mesh_t* const m, + h5_loc_id_t entity_id + ) { + return m->methods.access->get_loc_entity_parent (m, entity_id); +} + +static inline h5_err_t +h5tpriv_get_loc_entity_children ( + h5t_mesh_t* const m, + const h5_loc_id_t elem_id, + h5_loc_id_t* const children + ) { + return (*m->methods.access->get_loc_entity_children) (m, elem_id, children); } static inline h5_generic_glb_elem_t* h5tpriv_get_glb_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_glb_elem)( - f, elem_idx); + return (*m->methods.access->get_glb_elem)( + m, elem_idx); } static inline h5_glb_idx_t h5tpriv_get_glb_elem_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_glb_elem_idx)( - f, elem_idx); + return (*m->methods.access->get_glb_elem_idx)( + m, elem_idx); } static inline h5_glb_idx_t h5tpriv_set_glb_elem_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_glb_idx_t idx ) { - return (*f->t->methods.access->set_glb_elem_idx)( - f, elem_idx, idx); + return (*m->methods.access->set_glb_elem_idx)( + m, elem_idx, idx); } static inline h5_glb_idx_t h5tpriv_get_glb_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_glb_elem_parent_idx)( - f, elem_idx); + return (*m->methods.access->get_glb_elem_parent_idx)( + m, elem_idx); } static inline h5_glb_idx_t h5tpriv_set_glb_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_glb_idx_t idx ) { - return (*f->t->methods.access->set_glb_elem_parent_idx)( - f, elem_idx, idx); + return (*m->methods.access->set_glb_elem_parent_idx)( + m, elem_idx, idx); } static inline h5_glb_idx_t h5tpriv_get_glb_elem_child_idx( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_glb_elem_child_idx)( - f, elem_idx); + return (*m->methods.access->get_glb_elem_child_idx)( + m, elem_idx); } static inline h5_glb_idx_t h5tpriv_set_glb_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_glb_idx_t idx ) { - return (*f->t->methods.access->set_glb_elem_child_idx)( - f, elem_idx, idx); + return (*m->methods.access->set_glb_elem_child_idx)( + m, elem_idx, idx); } static inline h5_glb_idx_t* h5tpriv_get_glb_elem_vertex_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_glb_elem_vertex_indices)( - f, elem_idx); + return (*m->methods.access->get_glb_elem_vertex_indices)( + m, elem_idx); } static inline h5_glb_idx_t h5tpriv_get_glb_elem_vertex_idx( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t face_idx ) { - return (*f->t->methods.access->get_glb_elem_vertex_idx)( - f, elem_idx, face_idx); + return (*m->methods.access->get_glb_elem_vertex_idx)( + m, elem_idx, face_idx); } static inline h5_glb_idx_t h5tpriv_set_glb_elem_vertex_idx( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t face_idx, h5_glb_idx_t idx ) { - return (*f->t->methods.access->set_glb_elem_vertex_idx)( - f, elem_idx, face_idx, idx); + return (*m->methods.access->set_glb_elem_vertex_idx)( + m, elem_idx, face_idx, idx); } static inline h5_glb_idx_t* h5tpriv_get_glb_elem_neighbor_indices( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->get_glb_elem_neighbor_indices)( - f, elem_idx); + return (*m->methods.access->get_glb_elem_neighbor_indices)( + m, elem_idx); } static inline h5_glb_idx_t h5tpriv_get_glb_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t face_idx ) { - return (*f->t->methods.access->get_glb_elem_neighbor_idx)( - f, elem_idx, face_idx); + return (*m->methods.access->get_glb_elem_neighbor_idx)( + m, elem_idx, face_idx); } static inline h5_glb_idx_t h5tpriv_set_glb_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t face_idx, h5_glb_idx_t idx ) { - return (*f->t->methods.access->set_glb_elem_neighbor_idx)( - f, elem_idx, face_idx, idx); + return (*m->methods.access->set_glb_elem_neighbor_idx)( + m, elem_idx, face_idx, idx); } static inline h5_err_t h5tpriv_set_boundary_elem_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->set_boundary_elem_flag)(f, elem_idx); + return (*m->methods.access->set_boundary_elem_flag)(m, elem_idx); } static inline h5_err_t h5tpriv_clear_boundary_elem_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->clear_boundary_elem_flag)(f, elem_idx); + return (*m->methods.access->clear_boundary_elem_flag)(m, elem_idx); } static inline int h5tpriv_is_boundary_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - return (*f->t->methods.access->is_boundary_elem)(f, elem_idx); + return (*m->methods.access->is_boundary_elem)(m, elem_idx); } static inline int h5tpriv_is_boundary_facet ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, h5_loc_idx_t facet_idx ) { - return (*f->t->methods.access->is_boundary_facet)(f, elem_idx, facet_idx); + return (*m->methods.access->is_boundary_facet)(m, elem_idx, facet_idx); } static inline int h5tpriv_is_boundary_face ( - h5_file_t* const f, + h5t_mesh_t* const m, const int dim, const h5_loc_idx_t elem_idx, const h5_loc_idx_t facet_idx ) { - return (*f->t->methods.access->is_boundary_face)(f, dim, elem_idx, facet_idx); + return (*m->methods.access->is_boundary_face)(m, dim, elem_idx, facet_idx); } #endif diff --git a/src/h5core/h5t_access_tetm.c b/src/h5core/h5t_access_tetm.c index ce4df70..21b286b 100644 --- a/src/h5core/h5t_access_tetm.c +++ b/src/h5core/h5t_access_tetm.c @@ -6,138 +6,138 @@ static h5_generic_loc_elem_t* get_loc_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; + h5_loc_tet_t* elem = &m->loc_elems.tets[elem_idx]; return (h5_generic_loc_elem_t*)elem; } static h5_glb_idx_t get_loc_elem_glb_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tets[elem_idx].glb_idx; + return m->loc_elems.tets[elem_idx].glb_idx; } static h5_glb_idx_t set_loc_elem_glb_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_glb_idx_t glb_idx ) { - f->t->loc_elems.tets[elem_idx].glb_idx = glb_idx; + m->loc_elems.tets[elem_idx].glb_idx = glb_idx; return glb_idx; } static h5_loc_idx_t get_loc_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tets[elem_idx].parent_idx; + return m->loc_elems.tets[elem_idx].parent_idx; } static h5_loc_idx_t set_loc_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t parent_idx ) { - f->t->loc_elems.tets[elem_idx].parent_idx = parent_idx; + m->loc_elems.tets[elem_idx].parent_idx = parent_idx; return parent_idx; } static h5_loc_idx_t get_loc_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tets[elem_idx].child_idx; + return m->loc_elems.tets[elem_idx].child_idx; } static h5_loc_idx_t set_loc_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t child_idx ) { - f->t->loc_elems.tets[elem_idx].child_idx = child_idx; + m->loc_elems.tets[elem_idx].child_idx = child_idx; return child_idx; } static h5t_lvl_idx_t get_loc_elem_level_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tets[elem_idx].level_idx; + return m->loc_elems.tets[elem_idx].level_idx; } static h5t_lvl_idx_t set_loc_elem_level_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5t_lvl_idx_t level_idx ) { - f->t->loc_elems.tets[elem_idx].level_idx = level_idx; + m->loc_elems.tets[elem_idx].level_idx = level_idx; return level_idx; } static h5_loc_idx_t* get_loc_elem_vertex_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tets[elem_idx].vertex_indices; + return m->loc_elems.tets[elem_idx].vertex_indices; } static h5_loc_idx_t get_loc_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - return f->t->loc_elems.tets[elem_idx].vertex_indices[face_idx]; + return m->loc_elems.tets[elem_idx].vertex_indices[face_idx]; } static h5_loc_idx_t set_loc_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx, const h5_loc_idx_t vertex_idx ) { - f->t->loc_elems.tets[elem_idx].vertex_indices[face_idx] = vertex_idx; + m->loc_elems.tets[elem_idx].vertex_indices[face_idx] = vertex_idx; return vertex_idx; } static h5_loc_idx_t* get_loc_elem_neighbor_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tets[elem_idx].neighbor_indices; + return m->loc_elems.tets[elem_idx].neighbor_indices; } static h5_loc_idx_t get_loc_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - return f->t->loc_elems.tets[elem_idx].neighbor_indices[face_idx]; + return m->loc_elems.tets[elem_idx].neighbor_indices[face_idx]; } static h5_loc_idx_t set_loc_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx, const h5_loc_idx_t neighbor_idx ) { - f->t->loc_elems.tets[elem_idx].neighbor_indices[face_idx] = neighbor_idx; + m->loc_elems.tets[elem_idx].neighbor_indices[face_idx] = neighbor_idx; return neighbor_idx; } @@ -145,183 +145,183 @@ set_loc_elem_neighbor_idx ( /*** op's on global elements ***/ static h5_generic_glb_elem_t* get_glb_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return (h5_generic_glb_elem_t*)&f->t->glb_elems.tets[elem_idx]; + return (h5_generic_glb_elem_t*)&m->glb_elems.tets[elem_idx]; } static h5_glb_idx_t get_glb_elem_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tets[elem_idx].idx; + return m->glb_elems.tets[elem_idx].idx; } static h5_glb_idx_t set_glb_elem_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_glb_idx_t idx ) { - f->t->glb_elems.tets[elem_idx].idx = idx; + m->glb_elems.tets[elem_idx].idx = idx; return idx; } static h5_glb_idx_t get_glb_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tets[elem_idx].parent_idx; + return m->glb_elems.tets[elem_idx].parent_idx; } static h5_glb_idx_t set_glb_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_glb_idx_t parent_idx ) { - f->t->glb_elems.tets[elem_idx].parent_idx = parent_idx; + m->glb_elems.tets[elem_idx].parent_idx = parent_idx; return parent_idx; } static h5_glb_idx_t get_glb_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tets[elem_idx].child_idx; + return m->glb_elems.tets[elem_idx].child_idx; } static h5_glb_idx_t set_glb_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_glb_idx_t child_idx ) { - f->t->glb_elems.tets[elem_idx].child_idx = child_idx; + m->glb_elems.tets[elem_idx].child_idx = child_idx; return child_idx; } static h5_glb_idx_t* get_glb_elem_vertex_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tets[elem_idx].vertex_indices; + return m->glb_elems.tets[elem_idx].vertex_indices; } static h5_glb_idx_t get_glb_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - return f->t->glb_elems.tets[elem_idx].vertex_indices[face_idx]; + return m->glb_elems.tets[elem_idx].vertex_indices[face_idx]; } static h5_glb_idx_t set_glb_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx, const h5_glb_idx_t vertex_idx ) { - f->t->glb_elems.tets[elem_idx].vertex_indices[face_idx] = vertex_idx; + m->glb_elems.tets[elem_idx].vertex_indices[face_idx] = vertex_idx; return vertex_idx; } static h5_glb_idx_t* get_glb_elem_neighbor_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tets[elem_idx].neighbor_indices; + return m->glb_elems.tets[elem_idx].neighbor_indices; } static h5_glb_idx_t get_glb_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - return f->t->glb_elems.tets[elem_idx].neighbor_indices[face_idx]; + return m->glb_elems.tets[elem_idx].neighbor_indices[face_idx]; } static h5_glb_idx_t set_glb_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx, const h5_glb_idx_t neighbor_idx ) { - f->t->glb_elems.tets[elem_idx].neighbor_indices[face_idx] = neighbor_idx; + m->glb_elems.tets[elem_idx].neighbor_indices[face_idx] = neighbor_idx; return neighbor_idx; } static h5_err_t set_boundary_elem_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - f->t->loc_elems.tets[elem_idx].flags |= H5T_BOUNDARY_ELEM_FLAG; + m->loc_elems.tets[elem_idx].flags |= H5T_BOUNDARY_ELEM_FLAG; return H5_SUCCESS; } static h5_err_t set_boundary_facet_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - f->t->loc_elems.tets[elem_idx].flags |= H5T_BOUNDARY_FACET_FLAG; + m->loc_elems.tets[elem_idx].flags |= H5T_BOUNDARY_FACET_FLAG; return H5_SUCCESS; } static h5_err_t clear_boundary_elem_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - f->t->loc_elems.tets[elem_idx].flags &= ~H5T_BOUNDARY_ELEM_FLAG; + m->loc_elems.tets[elem_idx].flags &= ~H5T_BOUNDARY_ELEM_FLAG; return H5_SUCCESS; } static h5_err_t clear_boundary_facet_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - f->t->loc_elems.tets[elem_idx].flags &= ~H5T_BOUNDARY_FACET_FLAG; + m->loc_elems.tets[elem_idx].flags &= ~H5T_BOUNDARY_FACET_FLAG; return H5_SUCCESS; } static int is_boundary_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return (f->t->loc_elems.tets[elem_idx].flags & H5T_BOUNDARY_ELEM_FLAG) ? 1 : 0; + return (m->loc_elems.tets[elem_idx].flags & H5T_BOUNDARY_ELEM_FLAG) ? 1 : 0; } static int is_boundary_facet ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t facet_idx ) { - return (f->t->loc_elems.tets[elem_idx].neighbor_indices[facet_idx] == -1); + return (m->loc_elems.tets[elem_idx].neighbor_indices[facet_idx] == -1); } static int is_boundary_face ( - h5_file_t* const f, + h5t_mesh_t* const m, const int dim, const h5_loc_idx_t elem_idx, const h5_loc_idx_t facet_idx ) { - UNUSED_ARGUMENT (f); + UNUSED_ARGUMENT (m); UNUSED_ARGUMENT (dim); UNUSED_ARGUMENT (elem_idx); UNUSED_ARGUMENT (facet_idx); @@ -329,6 +329,396 @@ is_boundary_face ( return h5_error_internal (); } +/* + From time to time we need the parent entity of a given entity. This is + simple for cells but requires some knowledge about the mesh refinement + method for all other entities. Of course not all entities have a parent + anyway. + + Just as an reminder: New vertices in a refined tetrahedron P: + + 3 + ** + ** * + * * * + * * * + * * * + * 9 * + * * * + 7 * 8 + * * * + * 2 * + * * * * * + * * * * + * 5 6 * + * * * * + ** ** + 0 * * * * * * * 4 * * * * * * *1 + + The new cells (with n_P: number of children): + + n_P vertices + 0 0,4,5,7 + 1 4,1,6,8 + 2 5,6,2,9 + 3 7,8,9,3 + 4 4,5,6,8 + 5 4,5,7,8 + 6 5,6,8,9 + 7 5,7,8,9 + + Given an entity E we know: + + * C: the cell E belongs to, + * e_C: the id of E in C and E = [e_C,C] + * P: the parent of C, if any + * n_P: the number of child C + +*/ + +/* + Parent of tetrahedron + --------------------- + This is the simplest case: each children knows his parent. + + + Parent of triangle + ------------------ + Given an triangle E, we want to know the parent triangle of E. + + Refining a tetrahedron gives 4*4 new triangles on the surface of the + tetrahedron. We don't care about the inner triangles. + + The new triangles on the surface of P are: + + n_P vertices triangles + 0 0,4,5,7 (0,4,5)* (0,4,7)* (0,5,7)* (4,5,7) + 1 4,1,6,8 (4,1,6)* (4,1,8)* (4,6,8) (1,6,8)* + 2 5,6,2,9 (5,6,2)* (5,6,9) (5,2,9)* (6,2,9)* + 3 7,8,9,3 (7,8,9) (7,8,3)* (7,9,3)* (8,9,3)* + 4 4,5,6,8 (4,5,6)* (4,5,8) (4,6,8) (5,6,8) + 5 4,5,7,8 (4,5,7) (4,5,8) (4,7,8)* (5,7,8) + 6 5,6,8,9 (5,6,8) (5,6,9) (5,8,9) (6,8,9)* + 7 5,7,8,9 (5,7,8) (5,7,9)* (5,8,9) (7,8,9) + + Now let's have a look on triangle id's. We want to map an triangle id e_C + of cell C to the triangle id e_P of its parent P. As we can see in above + table, the triangle (0,4,5) has id 0 and belongs to child 0. The parent + triangle of (0,4,5) is (0,1,2) also with id 0. It is simple to prove, that + the triangle id of child and parent are identical in all cases. + + triangle tetrahedron triangle id parent triangle id + (0,4,5) (0,4,5,7) 0 0 + (0,4,7) (0,4,5,7) 1 1 + (0,5,7) (0,4,5,7) 2 2 + (4,1,6) (4,1,6,8) 0 0 + (4,1,8) (4,1,6,8) 1 1 + (1,6,8) (4,1,6,8) 3 3 + (5,6,2) (5,6,2,9) 0 0 + (5,2,9) (5,6,2,9) 2 2 + (6,2,9) (5,6,2,9) 3 3 + (7,8,3) (7,8,9,3) 1 1 + (7,9,3) (7,8,9,3) 2 2 + (8,9,3) (7,8,9,3) 3 3 + (4,5,6) (4,5,6,8) 0 0 + (4,7,8) (4,5,7,8) 2 1 + (6,8,9) (5,6,8,9) 3 3 + (5,7,9) (5,7,8,9) 1 2 + + This gives us the following matrix: + + t r i a n g l e i d + 0 1 2 3 + + c 0 0 1 2 -1 + h 1 0 1 -1 3 + i 2 0 -1 2 3 + l 3 -1 1 2 3 + d 4 0 -1 -1 -1 + 5 -1 -1 1 -1 + n 6 -1 -1 -1 3 + o 7 -1 2 -1 -1 + +*/ +int map_tri_to_parent_face[8][4] = { + { 0, 1, 2,-1}, // 0 + { 0, 1,-1, 3}, // 1 + { 0,-1, 2, 3}, // 2 + {-1, 1, 2, 3}, // 3 + { 0,-1,-1,-1}, // 4 + {-1,-1, 1,-1}, // 5 + {-1,-1,-1, 3}, // 6 + {-1, 2,-1,-1} // 7 +}; + +/* + Parent of edge + -------------- + Given an edge E, we want to know the parent edge of E. + + Refining P we get 25 new edges. But only 12 edges are intersecting with + edges of P. Only for these 12 edges we have a parent edges in P. So, + we don't have to care about the 13 other edges. It is obvious, that only + the first for children of P have edges intersecting with edges of P. + These edges are marked in the following table. + + Edges of the first four childern of P: + + n_P vertices edges + 0 0,4,5,7 (0,4)* (0,5)* (4,5) (0,7)* (4,7) (5,7) + 1 4,1,6,8 (4,1)* (4,6) (1,6)* (4,8) (1,8)* (6,8) + 2 5,6,2,9 (5,6) (5,2)* (6,2)* (5,9) (6,9) (2,9)* + 3 7,8,9,3 (7,8) (7,9) (8,9) (7,3)* (8,3)* (9,3)* + + Now let's have a look on edge id's. We want to map an edge id e_C of cell + C to the edge id e_P of its parent P. As we can see in above table, the + edge (0,4) has id 0 and belongs to child 0. The parent edge of (0,4) is + (0,1) also with id 0. It is simple to prove, that the edge id in child + and parent are identical in all cases. This gives us the following matrix: + + e d g e i d + 0 1 2 3 4 5 + + c 0 0 1 -1 3 -1 -1 + h 1 0 -1 2 -1 4 -1 + i 2 -1 1 2 -1 -1 5 + l 3 -1 -1 -1 3 4 5 + d 4 -1 -1 -1 -1 -1 -1 + 5 -1 -1 -1 -1 -1 -1 + n 6 -1 -1 -1 -1 -1 -1 + o 7 -1 -1 -1 -1 -1 -1 + + How to read it? Given an entity E, we know the element/cell C + entity E is belonging to and the edge number e_C. We know the parent P of + C and we know which number of child C is, let this be n_P. + + The matrix maps child number and edge id of E to the corresponding edge + id of the parent. + + f (n_P, e_C) -> e_P + + If the result is -1, no parent edge exists. Otherwise the parent edge is + [e_P,P] + +*/ +int map_edge_to_parent_face[8][6] = { + { 0, 1,-1, 3,-1,-1}, + { 0,-1, 2,-1, 4,-1}, + {-1, 1, 2,-1,-1, 5}, + {-1,-1,-1, 3, 4, 5}, + {-1,-1,-1,-1,-1,-1}, + {-1,-1,-1,-1,-1,-1}, + {-1,-1,-1,-1,-1,-1}, + {-1,-1,-1,-1,-1,-1}, +}; +/* + Parent of vertex + ---------------- + This case is trivial. +*/ +int map_vertex_to_parent_face[8][4] = { + { 0,-1,-1,-1}, + {-1, 1,-1,-1}, + {-1,-1, 2,-1}, + {-1,-1,-1, 3}, + {-1,-1,-1,-1}, + {-1,-1,-1,-1}, + {-1,-1,-1,-1}, + {-1,-1,-1,-1}, +}; + +static h5_loc_id_t +get_loc_entity_parent ( + h5t_mesh_t* const m, + h5_loc_id_t entity_id + ) { + // extract type ID and face index + h5_loc_id_t type_id = h5tpriv_get_entity_type (entity_id); + h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); + + // # of children + h5_loc_idx_t parent_idx = get_loc_elem_parent_idx (m, elem_idx); + if (parent_idx < 0) + return H5_NOK; + h5_loc_idx_t firstborn_idx = get_loc_elem_child_idx (m, parent_idx); + h5_loc_idx_t num_child = elem_idx - firstborn_idx; + + switch (type_id) { + case H5T_TYPE_VERTEX: { + face_idx = map_vertex_to_parent_face[num_child][face_idx]; + break; + } + case H5T_TYPE_EDGE: { + face_idx = map_edge_to_parent_face[num_child][face_idx]; + break; + } + case H5T_TYPE_TRIANGLE: { + face_idx = map_edge_to_parent_face[num_child][face_idx]; + break; + } + case H5T_TYPE_TET: { + break; + } + default: + h5_error_internal (); + } + return (face_idx != -1) ? + h5tpriv_build_entity_id (type_id, face_idx, parent_idx) : -1; +} + +static h5_err_t +get_children_of_loc_elem ( + h5t_mesh_t* const m, + h5_loc_idx_t face_idx, // in + h5_loc_idx_t elem_idx, // in + h5_loc_id_t* children // out + ) { + if (face_idx != 0) { + return h5_error_internal (); + } + h5_loc_idx_t idx = m->loc_elems.tets[elem_idx].child_idx; + children[0] = h5tpriv_build_tet_id (0, idx++); + children[1] = h5tpriv_build_tet_id (0, idx++); + children[2] = h5tpriv_build_tet_id (0, idx++); + children[3] = h5tpriv_build_tet_id (0, idx++); + children[4] = h5tpriv_build_tet_id (0, idx++); + children[5] = h5tpriv_build_tet_id (0, idx++); + children[6] = h5tpriv_build_tet_id (0, idx++); + children[7] = h5tpriv_build_tet_id (0, idx); + + return H5_SUCCESS; +} +/* + Compute direct children of a triangle. + + Face 0 Face 1 Face 2 Face 3 + 1 1 2 1 + + + + + + |\ |\ |\ |\ + | \ | \ | \ | \ + | \ | \ | \ | \ + | \ | \ | \ | \ + 4+----+6 4+----+8 5+----+9 6+----+8 + |\ |\ |\ |\ |\ |\ |\ |\ + | \ | \ | \ | \ | \ | \ | \ | \ + | \ | \ | \ | \ | \ | \ | \ | \ + | \| \ | \| \ | \| \ | \| \ + +----+----+ +----+----+ +----+----+ +----+----+ + 0 5 2 0 7 3 0 7 3 2 9 3 + + z ^ z ^ y ^ z ^ + | | | | + +--> +--> +--> +--> + y x x x + + Triangle: face idx, #child + + [0,4,5]: 0, 0 [0,4,7]: 1, 0 [0,5,7]: 2, 0 [1,6,8]: 3, 1 + [1,4,6]: 0, 1 [1,4,8]: 1, 1 [2,5,9]: 2, 2 [2,6,9]: 3, 2 + [2,5,6]: 0, 2 [3,7,8]: 1, 3 [3,7,9]: 2, 3 [3,8,9]: 3, 3 + [4,5,6]: 0, 4 [4,7,8]: 2, 5 [5,7,9]: 1, 7 [6,8,9]: 3, 6 + +*/ +static inline h5_err_t +get_children_of_loc_triangle ( + h5t_mesh_t* const m, + h5_loc_idx_t face_idx, // in + h5_loc_idx_t elem_idx, // in + h5_loc_id_t* children // out + ) { + h5_loc_idx_t map[4][4][2] = { + {{0,0},{0,1},{0,2},{0,4}}, // face 0 + {{1,0},{1,1},{1,3},{2,5}}, // face 1 + {{2,0},{2,2},{2,3},{1,7}}, // face 2 + {{3,1},{3,2},{3,3},{3,6}} // face 3 + }; + int num_faces = h5tpriv_ref_elem_get_num_facets (m); + if ((face_idx < 0) || (face_idx >= num_faces)) { + return h5_error_internal (); + } + h5_loc_idx_t idx = m->loc_elems.tets[elem_idx].child_idx; + children[0] = h5tpriv_build_triangle_id ( + map[face_idx][0][0], idx+map[face_idx][0][1]); + children[1] = h5tpriv_build_triangle_id ( + map[face_idx][1][0], idx+map[face_idx][1][1]); + children[2] = h5tpriv_build_triangle_id ( + map[face_idx][2][0], idx+map[face_idx][2][1]); + children[3] = h5tpriv_build_triangle_id ( + map[face_idx][3][0], idx+map[face_idx][3][1]); + return H5_SUCCESS; +} + +/* + Return the two direct children of the edge given by face and + element index of first child. + */ +static h5_err_t +get_children_of_loc_edge ( + h5t_mesh_t* const m, + h5_loc_idx_t face_idx, + h5_loc_idx_t elem_idx, + h5_loc_id_t* children + ) { + /* + Please read the note about the offsets in the corresponding file + for triangle meshes. + */ + int offs[6][2] = { {0,1}, // edge 0 + {0,2}, // edge 1 + {1,2}, // edge 2 + {0,3}, // edge 3 + {1,3}, // edge 4 + {2,3} // edge 5 + }; + h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (m); + if ((face_idx < 0) || (face_idx >= num_faces)) { + return h5_error_internal (); + } + h5_loc_idx_t idx = m->loc_elems.tets[elem_idx].child_idx; + children[0] = h5tpriv_build_edge_id (face_idx, idx+offs[face_idx][0]); + children[1] = h5tpriv_build_edge_id (face_idx, idx+offs[face_idx][1]); + return H5_SUCCESS; +} + +static h5_err_t +get_loc_entity_children ( + h5t_mesh_t* const m, + const h5_loc_id_t entity_id, + h5_loc_id_t* const children + ) { + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%d, children=%p", + m, entity_id, children); + + const h5_loc_id_t type_id = h5tpriv_get_entity_type (entity_id); + const h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); + const h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); + + if (h5tpriv_is_leaf_elem (m, &m->loc_elems.tets[elem_idx])) { + H5_PRIV_FUNC_LEAVE (H5_NOK); // not refined + } + switch (type_id) { + case H5T_TYPE_TET: { + H5_PRIV_FUNC_LEAVE ( + get_children_of_loc_elem (m, face_idx, elem_idx, children)); + break; + } + case H5T_TYPE_TRIANGLE: { + H5_PRIV_FUNC_LEAVE ( + get_children_of_loc_triangle (m, face_idx, elem_idx, children)); + break; + } + case H5T_TYPE_EDGE: { + H5_PRIV_FUNC_LEAVE ( + get_children_of_loc_edge (m, face_idx, elem_idx, children)); + } + default: + H5_PRIV_FUNC_LEAVE (h5_error_internal ()); + } + H5_PRIV_FUNC_RETURN (H5_SUCCESS); +} + struct h5t_access_methods h5tpriv_access_tetm_methods = { get_loc_elem, get_loc_elem_glb_idx, @@ -345,6 +735,8 @@ struct h5t_access_methods h5tpriv_access_tetm_methods = { get_loc_elem_neighbor_indices, get_loc_elem_neighbor_idx, set_loc_elem_neighbor_idx, + get_loc_entity_parent, + get_loc_entity_children, get_glb_elem, get_glb_elem_idx, set_glb_elem_idx, diff --git a/src/h5core/h5t_access_trim.c b/src/h5core/h5t_access_trim.c index bd93e50..59bc181 100644 --- a/src/h5core/h5t_access_trim.c +++ b/src/h5core/h5t_access_trim.c @@ -4,137 +4,137 @@ /*** op's on local elements ***/ static h5_generic_loc_elem_t* get_loc_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return (h5_generic_loc_elem_t*)&f->t->loc_elems.tris[elem_idx]; + return (h5_generic_loc_elem_t*)&m->loc_elems.tris[elem_idx]; } static h5_glb_idx_t get_loc_elem_glb_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tris[elem_idx].glb_idx; + return m->loc_elems.tris[elem_idx].glb_idx; } static h5_glb_idx_t set_loc_elem_glb_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_glb_idx_t glb_idx ) { - f->t->loc_elems.tris[elem_idx].glb_idx = glb_idx; + m->loc_elems.tris[elem_idx].glb_idx = glb_idx; return glb_idx; } static h5_loc_idx_t get_loc_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tris[elem_idx].parent_idx; + return m->loc_elems.tris[elem_idx].parent_idx; } static h5_loc_idx_t set_loc_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t parent_idx ) { - f->t->loc_elems.tris[elem_idx].parent_idx = parent_idx; + m->loc_elems.tris[elem_idx].parent_idx = parent_idx; return parent_idx; } static h5_loc_idx_t get_loc_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tris[elem_idx].child_idx; + return m->loc_elems.tris[elem_idx].child_idx; } static h5_loc_idx_t set_loc_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t child_idx ) { - f->t->loc_elems.tris[elem_idx].child_idx = child_idx; + m->loc_elems.tris[elem_idx].child_idx = child_idx; return child_idx; } static h5t_lvl_idx_t get_loc_elem_level_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tris[elem_idx].level_idx; + return m->loc_elems.tris[elem_idx].level_idx; } static h5t_lvl_idx_t set_loc_elem_level_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5t_lvl_idx_t level_idx ) { - f->t->loc_elems.tris[elem_idx].level_idx = level_idx; + m->loc_elems.tris[elem_idx].level_idx = level_idx; return level_idx; } static h5_loc_idx_t* get_loc_elem_vertex_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tris[elem_idx].vertex_indices; + return m->loc_elems.tris[elem_idx].vertex_indices; } static h5_loc_idx_t get_loc_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - return f->t->loc_elems.tris[elem_idx].vertex_indices[face_idx]; + return m->loc_elems.tris[elem_idx].vertex_indices[face_idx]; } static h5_loc_idx_t set_loc_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx, const h5_loc_idx_t vertex_idx ) { - f->t->loc_elems.tris[elem_idx].vertex_indices[face_idx] = vertex_idx; + m->loc_elems.tris[elem_idx].vertex_indices[face_idx] = vertex_idx; return vertex_idx; } static h5_loc_idx_t* get_loc_elem_neighbor_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->loc_elems.tris[elem_idx].neighbor_indices; + return m->loc_elems.tris[elem_idx].neighbor_indices; } static h5_loc_idx_t get_loc_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - return f->t->loc_elems.tris[elem_idx].neighbor_indices[face_idx]; + return m->loc_elems.tris[elem_idx].neighbor_indices[face_idx]; } static h5_loc_idx_t set_loc_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx, const h5_loc_idx_t neighbor_idx ) { - f->t->loc_elems.tris[elem_idx].neighbor_indices[face_idx] = neighbor_idx; + m->loc_elems.tris[elem_idx].neighbor_indices[face_idx] = neighbor_idx; return neighbor_idx; } @@ -142,189 +142,280 @@ set_loc_elem_neighbor_idx ( /*** op's on global elements ***/ static h5_generic_glb_elem_t* get_glb_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return (h5_generic_glb_elem_t*)&f->t->glb_elems.tris[elem_idx]; + return (h5_generic_glb_elem_t*)&m->glb_elems.tris[elem_idx]; } static h5_glb_idx_t get_glb_elem_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tris[elem_idx].idx; + return m->glb_elems.tris[elem_idx].idx; } static h5_glb_idx_t set_glb_elem_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_glb_idx_t idx ) { - f->t->glb_elems.tris[elem_idx].idx = idx; + m->glb_elems.tris[elem_idx].idx = idx; return idx; } static h5_glb_idx_t get_glb_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tris[elem_idx].parent_idx; + return m->glb_elems.tris[elem_idx].parent_idx; } static h5_glb_idx_t set_glb_elem_parent_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_glb_id_t parent_idx ) { - f->t->glb_elems.tris[elem_idx].parent_idx = parent_idx; + m->glb_elems.tris[elem_idx].parent_idx = parent_idx; return parent_idx; } static h5_glb_idx_t get_glb_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tris[elem_idx].child_idx; + return m->glb_elems.tris[elem_idx].child_idx; } static h5_glb_idx_t set_glb_elem_child_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_glb_idx_t child_idx ) { - f->t->glb_elems.tris[elem_idx].child_idx = child_idx; + m->glb_elems.tris[elem_idx].child_idx = child_idx; return child_idx; } static h5_glb_idx_t* get_glb_elem_vertex_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tris[elem_idx].vertex_indices; + return m->glb_elems.tris[elem_idx].vertex_indices; } static h5_glb_idx_t get_glb_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - return f->t->glb_elems.tris[elem_idx].vertex_indices[face_idx]; + return m->glb_elems.tris[elem_idx].vertex_indices[face_idx]; } static h5_glb_idx_t set_glb_elem_vertex_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx, const h5_glb_idx_t vertex_idx ) { - f->t->glb_elems.tris[elem_idx].vertex_indices[face_idx] = vertex_idx; + m->glb_elems.tris[elem_idx].vertex_indices[face_idx] = vertex_idx; return vertex_idx; } static h5_glb_idx_t* get_glb_elem_neighbor_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return f->t->glb_elems.tris[elem_idx].neighbor_indices; + return m->glb_elems.tris[elem_idx].neighbor_indices; } static h5_glb_idx_t get_glb_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - return f->t->glb_elems.tris[elem_idx].neighbor_indices[face_idx]; + return m->glb_elems.tris[elem_idx].neighbor_indices[face_idx]; } static h5_glb_idx_t set_glb_elem_neighbor_idx ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx, const h5_glb_idx_t neighbor_idx ) { - f->t->glb_elems.tris[elem_idx].neighbor_indices[face_idx] = neighbor_idx; + m->glb_elems.tris[elem_idx].neighbor_indices[face_idx] = neighbor_idx; return neighbor_idx; } static h5_err_t set_boundary_elem_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - f->t->loc_elems.tris[elem_idx].flags |= H5T_BOUNDARY_ELEM_FLAG; + m->loc_elems.tris[elem_idx].flags |= H5T_BOUNDARY_ELEM_FLAG; return H5_SUCCESS; } static h5_err_t set_boundary_facet_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - f->t->loc_elems.tris[elem_idx].flags |= H5T_BOUNDARY_FACET_FLAG; + m->loc_elems.tris[elem_idx].flags |= H5T_BOUNDARY_FACET_FLAG; return H5_SUCCESS; } static h5_err_t clear_boundary_elem_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - f->t->loc_elems.tris[elem_idx].flags &= ~H5T_BOUNDARY_ELEM_FLAG; + m->loc_elems.tris[elem_idx].flags &= ~H5T_BOUNDARY_ELEM_FLAG; return H5_SUCCESS; } static h5_err_t clear_boundary_facet_flag ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx ) { - f->t->loc_elems.tris[elem_idx].flags &= ~H5T_BOUNDARY_FACET_FLAG; + m->loc_elems.tris[elem_idx].flags &= ~H5T_BOUNDARY_FACET_FLAG; return H5_SUCCESS; } static int is_boundary_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - return (f->t->loc_elems.tris[elem_idx].flags & H5T_BOUNDARY_ELEM_FLAG) ? 1 : 0; + return (m->loc_elems.tris[elem_idx].flags & H5T_BOUNDARY_ELEM_FLAG) ? 1 : 0; } static int is_boundary_facet ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx, const h5_loc_idx_t facet_idx ) { - return (f->t->loc_elems.tris[elem_idx].neighbor_indices[facet_idx] == -1); + return (m->loc_elems.tris[elem_idx].neighbor_indices[facet_idx] == -1); } static int is_boundary_face ( - h5_file_t* const f, + h5t_mesh_t* const m, const int dim, const h5_loc_idx_t elem_idx, const h5_loc_idx_t facet_idx ) { - UNUSED_ARGUMENT (f); + UNUSED_ARGUMENT (m); UNUSED_ARGUMENT (dim); UNUSED_ARGUMENT (elem_idx); UNUSED_ARGUMENT (facet_idx); return h5_error_internal (); } +static h5_loc_id_t +get_loc_entity_parent ( + h5t_mesh_t* const m, + h5_loc_id_t entity_id + ) { + return H5_SUCCESS; +} + +static h5_err_t +get_children_of_loc_elem ( + h5t_mesh_t* const m, + h5_loc_idx_t face_idx, // in + h5_loc_idx_t elem_idx, // in + h5_loc_id_t* children // out + ) { + if (face_idx != 0) { + return h5_error_internal (); + } + h5_loc_idx_t idx = m->loc_elems.tris[elem_idx].child_idx; + children[0] = h5tpriv_build_tet_id (0, idx++); + children[1] = h5tpriv_build_tet_id (0, idx++); + children[2] = h5tpriv_build_tet_id (0, idx++); + children[3] = h5tpriv_build_tet_id (0, idx++); + + return H5_SUCCESS; +} + + +static h5_err_t +get_children_of_loc_edge ( + h5t_mesh_t* const m, + const h5_loc_idx_t face_idx, + const h5_loc_idx_t elem_idx, + h5_loc_id_t* children + ) { + /* + Please note: The face index of the children and the father is + always the same. The only think we have to know, is the offset + to the element index of the first child. This is either 0, 1 or + 2. The third child is an "inner" child which doesn't superpose edges + of the parent. + + The direct children of edge 0 of an element are edge 0 of the + first child and edge 0 of the second child, giving the offset 0 + and 1 for this edge. + */ + int off[3][2] = { {0,1}, // edge 0 + {0,2}, // edge 1 + {1,2} // edge 2 + }; + h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (m); + if ((face_idx < 0) || (face_idx >= num_faces)) { + return h5_error_internal (); + } + h5_loc_idx_t idx = m->loc_elems.tris[elem_idx].child_idx; + children[0] = h5tpriv_build_edge_id (face_idx, idx+off[face_idx][0]); + children[1] = h5tpriv_build_edge_id (face_idx, idx+off[face_idx][1]); + return H5_SUCCESS; +} + +static h5_err_t +get_loc_entity_children ( + h5t_mesh_t* const m, + const h5_loc_id_t entity_id, + h5_loc_id_t* const children + ) { + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%d, children=%p", + m, entity_id, children); + + const h5_loc_id_t type_id = h5tpriv_get_entity_type (entity_id); + const h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); + const h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); + + if (h5tpriv_is_leaf_elem (m, &m->loc_elems.tris[elem_idx])) { + H5_PRIV_FUNC_LEAVE (H5_NOK); // not refined + } + switch (type_id) { + case H5T_TYPE_TRIANGLE: { + H5_PRIV_FUNC_LEAVE ( + get_children_of_loc_elem (m, face_idx, elem_idx, children)); + break; + } + case H5T_TYPE_EDGE: { + H5_PRIV_FUNC_LEAVE ( + get_children_of_loc_edge (m, face_idx, elem_idx, children)); + } + } + H5_PRIV_FUNC_RETURN (h5_error_internal ()); +} + struct h5t_access_methods h5tpriv_access_trim_methods = { get_loc_elem, get_loc_elem_glb_idx, @@ -341,6 +432,8 @@ struct h5t_access_methods h5tpriv_access_trim_methods = { get_loc_elem_neighbor_indices, get_loc_elem_neighbor_idx, set_loc_elem_neighbor_idx, + get_loc_entity_parent, + get_loc_entity_children, get_glb_elem, get_glb_elem_idx, set_glb_elem_idx, diff --git a/src/h5core/h5t_adjacencies.c b/src/h5core/h5t_adjacencies.c index 6b15589..81cc172 100644 --- a/src/h5core/h5t_adjacencies.c +++ b/src/h5core/h5t_adjacencies.c @@ -18,41 +18,39 @@ h5_err_t h5t_get_adjacencies ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, entity_id=%llu, dim=%d, list=0x%p", - f, (long long unsigned)entity_id, dim, list); - H5_CORE_API_RETURN (h5tpriv_get_adjacencies (f, entity_id, dim, list)); + H5_CORE_API_ENTER (h5_err_t, + "m=%p, entity_id=%llu, dim=%d, list=%p", + m, (long long unsigned)entity_id, dim, list); + H5_CORE_API_RETURN (h5tpriv_get_adjacencies (m, entity_id, dim, list)); } h5_err_t h5t_release_list_of_adjacencies ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idlist_t** list ) { - H5_CORE_API_ENTER2 (h5_err_t, - "f=0x%p, list=0x%p", - f, list); - UNUSED_ARGUMENT (f); + H5_CORE_API_ENTER (h5_err_t, "m=%p, list=%p", m, list); + UNUSED_ARGUMENT (m); H5_CORE_API_RETURN (h5priv_free_idlist (list)); } h5_err_t h5t_find_te2 ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t** retval ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%lld, elem_idx=%lld, retval=0x%p", - f, - (long long)face_idx, - (long long)elem_idx, - retval); - H5_CORE_API_RETURN (h5tpriv_find_te2 (f,face_idx,elem_idx,retval)); + H5_CORE_API_ENTER (h5_err_t, + "m=%p, face_idx=%lld, elem_idx=%lld, retval=%p", + m, + (long long)face_idx, + (long long)elem_idx, + retval); + H5_CORE_API_RETURN (h5tpriv_find_te2 (m,face_idx,elem_idx,retval)); } diff --git a/src/h5core/h5t_adjacencies_private.h b/src/h5core/h5t_adjacencies_private.h index af5e1f1..02c708f 100644 --- a/src/h5core/h5t_adjacencies_private.h +++ b/src/h5core/h5t_adjacencies_private.h @@ -2,10 +2,10 @@ #define __H5T_ADJACENCIES_PRIVATE_H struct h5t_adjacency_methods { - h5_err_t (*update_internal_structs)(h5_file_t* const, h5t_lvl_idx_t); - h5_err_t (*release_internal_structs)(h5_file_t* const); + h5_err_t (*update_internal_structs)(h5t_mesh_t* const, h5t_lvl_idx_t); + h5_err_t (*release_internal_structs)(h5t_mesh_t* const); h5_err_t (*get_adjacencies)( - h5_file_t * const, + h5t_mesh_t* const, const h5_loc_id_t, const h5_int32_t, h5_loc_idlist_t**); }; @@ -14,42 +14,42 @@ extern struct h5t_adjacency_methods h5tpriv_tetm_adjacency_methods; static inline h5_err_t h5tpriv_get_adjacencies ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { - H5_PRIV_API_ENTER4 (h5_err_t, - "f=0x%p, entity_id=%lld, dim=%d, list=0x%p", - f, (long long)entity_id, dim, list); - if (f->t->methods.adjacency == NULL) { + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, entity_id=%lld, dim=%d, list=%p", + m, (long long)entity_id, dim, list); + if (m->methods.adjacency == NULL) { H5_PRIV_API_LEAVE (h5_error_internal ()); } - H5_PRIV_API_RETURN (f->t->methods.adjacency->get_adjacencies( - f, entity_id, dim, list)); + H5_PRIV_API_RETURN (m->methods.adjacency->get_adjacencies( + m, entity_id, dim, list)); } static inline h5_err_t h5tpriv_release_adjacency_structs ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); - if (f->t->methods.adjacency == NULL) { + H5_PRIV_API_ENTER (h5_err_t, "m=%p", m); + if (m->methods.adjacency == NULL) { H5_PRIV_API_LEAVE (H5_OK); } - H5_PRIV_API_RETURN (f->t->methods.adjacency->release_internal_structs(f)); + H5_PRIV_API_RETURN (m->methods.adjacency->release_internal_structs(m)); } static inline h5_err_t h5tpriv_update_adjacency_structs ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t level_id ) { - H5_PRIV_API_ENTER2 (h5_err_t, "f=0x%p, level_id=%d", f, level_id); - if (f->t->methods.adjacency == NULL) { + H5_PRIV_API_ENTER (h5_err_t, "m=%p, level_id=%d", m, level_id); + if (m->methods.adjacency == NULL) { H5_PRIV_API_LEAVE (H5_OK); } - H5_PRIV_API_RETURN (f->t->methods.adjacency->update_internal_structs(f, level_id)); + H5_PRIV_API_RETURN (m->methods.adjacency->update_internal_structs(m, level_id)); } #endif diff --git a/src/h5core/h5t_adjacencies_tetm.c b/src/h5core/h5t_adjacencies_tetm.c index d8a7c90..b385ad6 100644 --- a/src/h5core/h5t_adjacencies_tetm.c +++ b/src/h5core/h5t_adjacencies_tetm.c @@ -23,20 +23,19 @@ */ static inline h5_err_t alloc_tv ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, from_lvl=%u", - f, (unsigned)from_lvl); - h5t_fdata_t* t = f->t; - h5_loc_idx_t num_vertices = t->num_vertices[t->num_leaf_levels-1]; + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, from_lvl=%u", + m, (unsigned)from_lvl); + h5_loc_idx_t num_vertices = m->num_vertices[m->num_leaf_levels-1]; - h5t_adjacencies_t* adj = &t->adjacencies; + h5t_adjacencies_t* adj = &m->adjacencies; // allocate ptr to ID-list per vertex TRY( adj->tv.v = h5_alloc (adj->tv.v, num_vertices*sizeof(*adj->tv.v)) ); - size_t i = from_lvl <= 0 ? 0 : t->num_vertices[from_lvl-1]; + size_t i = from_lvl <= 0 ? 0 : m->num_vertices[from_lvl-1]; memset (adj->tv.v+i, 0, (num_vertices-i)*sizeof(*adj->tv.v)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -47,16 +46,15 @@ alloc_tv ( */ static inline h5_err_t release_tv ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - h5t_adjacencies_t* adj = &t->adjacencies; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + h5t_adjacencies_t* adj = &m->adjacencies; if (adj->tv.v == NULL) H5_PRIV_FUNC_LEAVE (H5_SUCCESS); h5_loc_idx_t vertex_idx = 0; - h5_loc_idx_t last = t->num_vertices[t->num_leaf_levels-1]; + h5_loc_idx_t last = m->num_vertices[m->num_leaf_levels-1]; for (; vertex_idx < last; vertex_idx++) { TRY( h5priv_free_idlist (&adj->tv.v[vertex_idx]) ); } @@ -70,24 +68,24 @@ release_tv ( */ static inline h5_err_t compute_elems_of_vertices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, from_lvl=%u", - f, (unsigned)from_lvl); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, from_lvl=%u", + m, (unsigned)from_lvl); /* expand structure */ - TRY( alloc_tv (f, from_lvl) ); + TRY( alloc_tv (m, from_lvl) ); /* loop over all elements in current level */ - h5t_fdata_t* t = f->t; - h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0:t->num_elems[from_lvl-1]; - h5_loc_idx_t last = (t->num_leaf_levels < 0) ? 0:t->num_elems[t->num_leaf_levels-1]; + h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0:m->num_elems[from_lvl-1]; + h5_loc_idx_t last = (m->num_leaf_levels < 0) ? + 0 : m->num_elems[m->num_leaf_levels-1]; for (;elem_idx < last; elem_idx++) { int face_idx; - int num_faces = h5tpriv_ref_elem_get_num_vertices(t); + int num_faces = h5tpriv_ref_elem_get_num_vertices(m); for (face_idx = 0; face_idx < num_faces; face_idx++) { - TRY( h5tpriv_search_tv2 (f, face_idx, elem_idx, NULL) ); + TRY( h5tpriv_search_tv2 (m, face_idx, elem_idx, NULL) ); } } H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -98,21 +96,18 @@ compute_elems_of_vertices ( */ static inline h5_err_t compute_elems_of_edges ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, from_lvl=%u", - f, (unsigned)from_lvl); - h5t_fdata_t* t = f->t; - h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; - h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - TRY( h5tpriv_resize_te_htab (f, 4*(num_elems-elem_idx)) ); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, from_lvl=%d", m, from_lvl); + h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : m->num_elems[from_lvl-1]; + h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; + TRY( h5tpriv_resize_te_htab (m, 4*(num_elems-elem_idx)) ); for (;elem_idx < num_elems; elem_idx++) { int face_idx; - int num_faces = h5tpriv_ref_elem_get_num_edges(t); + int num_faces = h5tpriv_ref_elem_get_num_edges(m); for (face_idx = 0; face_idx < num_faces; face_idx++) { - TRY( h5tpriv_search_te2 (f, face_idx, elem_idx, NULL) ); + TRY( h5tpriv_search_te2 (m, face_idx, elem_idx, NULL) ); } } H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -123,97 +118,99 @@ compute_elems_of_edges ( */ static inline h5_err_t compute_elems_of_triangles ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, from_lvl=%u", - f, (unsigned)from_lvl); - h5t_fdata_t* t = f->t; - h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; - h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - TRY( h5tpriv_resize_td_htab (f, 4*(num_elems-elem_idx)) ); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, from_lvl=%u", m, from_lvl); + h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : m->num_elems[from_lvl-1]; + h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; + TRY( h5tpriv_resize_td_htab (m, 4*(num_elems-elem_idx)) ); for (;elem_idx < num_elems; elem_idx++) { int face_idx; - int num_faces = h5tpriv_ref_elem_get_num_edges (t); + int num_faces = h5tpriv_ref_elem_get_num_edges (m); for (face_idx = 0; face_idx < num_faces; face_idx++) { - TRY( h5tpriv_search_td2 (f, face_idx, elem_idx, NULL) ); + TRY( h5tpriv_search_td2 (m, face_idx, elem_idx, NULL) ); } } H5_PRIV_FUNC_RETURN (H5_SUCCESS); } + /* - Compute the children o an edge + For the computation of some adjacency relations we need to know either + the descendant or the sections of a triangle or an edge. We use the term + "descendant" for the set of all grandchildren and "sections" for the + descendant of the entity which has been refined most. The following + example helps to show the difference: + + We want to know the descendant and sections of the edge (0,1). Let (0,1) + be an edge of the tetrahedra T_i and T_j. Let the edge (0,1) in T_i be + + 0---3---2-------1 + + and in T_j: + + 0---3-4-2-------1 + + We have the following descendants: + (0,3), (3,2), (2,1), (3,4), (4,2) + + and the sections: + (0,3), (3,4), (4,2), (2,1) + + Note: (3,2) is *not* a section of (0,1) */ static inline h5_err_t -compute_children_of_edge ( - h5_file_t* const f, +get_descendant_of_edge ( + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idlist_t** children ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, children=0x%p", - f, - (long long unsigned)entity_id, - children); - h5_loc_idlist_t* te; - TRY( h5tpriv_find_te (f, entity_id, &te ) ); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, children=%p", + m, + (long long unsigned)entity_id, + children); + h5_loc_idlist_t* te = NULL; + TRY( h5tpriv_find_te (m, entity_id, &te ) ); h5_loc_id_t* edge_idp = te->items; h5_loc_id_t* end = te->items+te->num_items; do { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); - h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; - if (h5tpriv_is_leaf_elem (f, elem)) { + h5_loc_id_t edge_ids[2] = {-1,-1}; + TRY (h5tpriv_get_loc_entity_children (m, *edge_idp, edge_ids)); + if (edge_ids[0] == -1) { TRY( h5priv_insert_idlist (children, *edge_idp, -1) ); } else { - h5_loc_id_t edge_ids[2]; - TRY( h5tpriv_get_direct_children_of_edge ( - f, - face_idx, - elem->child_idx, - edge_ids) ); - TRY( compute_children_of_edge (f, edge_ids[0], children) ); - TRY( compute_children_of_edge (f, edge_ids[1], children) ); + TRY( get_descendant_of_edge (m, edge_ids[0], children) ); + TRY( get_descendant_of_edge (m, edge_ids[1], children) ); } } while (++edge_idp < end); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } -/* - Compute all sections of an edge. -*/ static inline h5_err_t -compute_sections_of_edge ( - h5_file_t* const f, +get_sections_of_edge ( + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idlist_t** children ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, children=0x%p", - f, - (long long unsigned)entity_id, - children); - h5_loc_idlist_t* te; - TRY( h5tpriv_find_te (f, entity_id, &te) ); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, children=%p", + m, + (long long unsigned)entity_id, + children); + h5_loc_idlist_t* te = NULL; + TRY( h5tpriv_find_te (m, entity_id, &te) ); h5_loc_id_t* edge_idp = te->items; h5_loc_id_t* end = te->items+te->num_items; int refined = 0; do { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); - h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; - if (!h5tpriv_is_leaf_elem (f, elem)) { + h5_loc_id_t edge_ids[2] = {-1,-1}; + TRY (h5tpriv_get_loc_entity_children (m, *edge_idp, edge_ids)); + if (edge_ids[0] >= 0) { refined = 1; - h5_loc_id_t edge_ids[2]; - TRY( h5tpriv_get_direct_children_of_edge ( - f, - face_idx, - elem->child_idx, - edge_ids) ); - TRY( compute_sections_of_edge (f, edge_ids[0], children) ); - TRY( compute_sections_of_edge (f, edge_ids[1], children) ); + TRY (get_sections_of_edge (m, edge_ids[0], children)); + TRY (get_sections_of_edge (m, edge_ids[1], children)); } } while (++edge_idp < end); if (!refined) { @@ -222,141 +219,62 @@ compute_sections_of_edge ( H5_PRIV_FUNC_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 inline h5_err_t -compute_direct_children_of_triangle ( - h5_file_t* const f, - h5_loc_idx_t face_idx, // in - h5_loc_idx_t elem_idx, // in - h5_loc_id_t* children // out - ) { - H5_PRIV_FUNC_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%llu, elem_idx=%llu, children=0x%p", - f, - (long long unsigned)face_idx, - (long long unsigned)elem_idx, - children); - - h5_loc_idx_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 = h5tpriv_ref_elem_get_num_facets (f->t); - if ((face_idx < 0) || (face_idx >= num_faces)) { - H5_PRIV_FUNC_LEAVE (h5_error_internal ()); - } - children[0] = h5tpriv_build_triangle_id ( - map[face_idx][0][0], elem_idx+map[face_idx][0][1]); - children[1] = h5tpriv_build_triangle_id ( - map[face_idx][1][0], elem_idx+map[face_idx][1][1]); - children[2] = h5tpriv_build_triangle_id ( - map[face_idx][2][0], elem_idx+map[face_idx][2][1]); - children[3] = h5tpriv_build_triangle_id ( - map[face_idx][3][0], elem_idx+map[face_idx][3][1]); - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - -static inline h5_err_t -compute_children_of_triangle ( - h5_file_t* const f, +get_descendant_of_triangle ( + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idlist_t** children ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, children=0x%p", - f, - (long long unsigned)entity_id, - children); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, children=%p", + m, + (long long unsigned)entity_id, + children); h5_loc_idlist_t* td; - TRY( h5tpriv_find_td (f, entity_id, &td) ); + TRY( h5tpriv_find_td (m, entity_id, &td) ); h5_loc_id_t* triangle_idp = td->items; h5_loc_id_t* end = td->items+td->num_items; do { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*triangle_idp); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*triangle_idp); - h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; - if (h5tpriv_is_leaf_elem (f, elem)) { - TRY( h5priv_insert_idlist (children, *triangle_idp, -1) ); + h5_loc_id_t triangle_ids[4] = {-1,-1,-1,-1}; + TRY (h5tpriv_get_loc_entity_children (m, *triangle_idp, triangle_ids)); + + if (triangle_ids[0] == -1) { + TRY (h5priv_insert_idlist (children, *triangle_idp, -1) ); } else { - h5_loc_id_t triangle_ids[4] = {-1,-1,-1,-1}; - TRY( compute_direct_children_of_triangle ( - f, - face_idx, - elem->child_idx, - triangle_ids) ); - TRY( compute_children_of_triangle (f, triangle_ids[0], children) ); - TRY( compute_children_of_triangle (f, triangle_ids[1], children) ); - TRY( compute_children_of_triangle (f, triangle_ids[2], children) ); - TRY( compute_children_of_triangle (f, triangle_ids[3], children) ); + TRY (get_descendant_of_triangle (m, triangle_ids[0], children)); + TRY (get_descendant_of_triangle (m, triangle_ids[1], children)); + TRY (get_descendant_of_triangle (m, triangle_ids[2], children)); + TRY (get_descendant_of_triangle (m, triangle_ids[3], children)); } } while (++triangle_idp < end); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static inline h5_err_t -compute_sections_of_triangle ( - h5_file_t* const f, +get_sections_of_triangle ( + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idlist_t** children ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, children=0x%p", - f, + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, children=%p", + m, (long long unsigned)entity_id, children); h5_loc_idlist_t* td; - TRY( h5tpriv_find_td (f, entity_id, &td) ); + TRY (h5tpriv_find_td (m, entity_id, &td)); h5_loc_id_t* triangle_idp = td->items; h5_loc_id_t* end = td->items+td->num_items; int refined = 0; do { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*triangle_idp); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*triangle_idp); - h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; - if (!h5tpriv_is_leaf_elem (f, elem)) { + h5_loc_id_t triangle_ids[4] = {-1,-1,-1,-1}; + TRY (h5tpriv_get_loc_entity_children (m, *triangle_idp, triangle_ids)); + if (triangle_ids[0] >= 0) { refined = 1; - h5_loc_id_t triangle_ids[4] = {-1,-1,-1,-1}; - TRY( compute_direct_children_of_triangle ( - f, - face_idx, - elem->child_idx, - triangle_ids) ); - TRY( compute_sections_of_triangle (f, triangle_ids[0], children) ); - TRY( compute_sections_of_triangle (f, triangle_ids[1], children) ); - TRY( compute_sections_of_triangle (f, triangle_ids[2], children) ); - TRY( compute_sections_of_triangle (f, triangle_ids[3], children) ); + TRY (get_sections_of_triangle (m, triangle_ids[0], children)); + TRY (get_sections_of_triangle (m, triangle_ids[1], children)); + TRY (get_sections_of_triangle (m, triangle_ids[2], children)); + TRY (get_sections_of_triangle (m, triangle_ids[3], children)); } } while (++triangle_idp < end); if (! refined) { @@ -370,18 +288,18 @@ compute_sections_of_triangle ( */ static inline h5_err_t add_vertex2 ( - h5_file_t* const f, // in + h5t_mesh_t* const m, // in h5_loc_idlist_t** list, // out h5_loc_idx_t face_idx, // in h5_loc_idx_t elem_idx // in ) { - H5_PRIV_FUNC_ENTER4 (h5_err_t, - "f=0x%p, list=0x%p, face_idx=%llu, elem_idx=%llu", - f, list, + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, list=%p, face_idx=%llu, elem_idx=%llu", + m, list, (long long unsigned)face_idx, (long long unsigned)elem_idx); h5_loc_idlist_t* tv; - TRY( h5tpriv_find_tv2 (f, face_idx, elem_idx, &tv) ); + TRY( h5tpriv_find_tv2 (m, face_idx, elem_idx, &tv) ); TRY( h5priv_search_idlist (list, tv->items[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -391,34 +309,34 @@ add_vertex2 ( */ static inline h5_err_t add_edge ( - h5_file_t* const f, // in + h5t_mesh_t* const m, // in h5_loc_idlist_t** list, // out h5_loc_id_t entity_id // in ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, list=0x%p, entity_id=%llu", - f, list, - (long long unsigned)entity_id); - h5_loc_idlist_t* te; - TRY( h5tpriv_find_te (f, entity_id, &te) ); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, list=%p, entity_id=%llu", + m, list, + (long long unsigned)entity_id); + h5_loc_idlist_t* te = NULL; + TRY( h5tpriv_find_te (m, entity_id, &te) ); TRY( h5priv_search_idlist (list, te->items[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static inline h5_err_t add_edge2 ( - h5_file_t* const f, // in + h5t_mesh_t* const m, // in h5_loc_idlist_t** list, // out h5_loc_idx_t face_idx, // in h5_loc_idx_t elem_idx // in ) { - H5_PRIV_FUNC_ENTER4 (h5_err_t, - "f=0x%p, list=0x%p, face_idx=%llu, elem_idx=%llu", - f, list, + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, list=%p, face_idx=%llu, elem_idx=%llu", + m, list, (long long unsigned)face_idx, (long long unsigned)elem_idx); h5_loc_idlist_t* te; - TRY( h5tpriv_find_te2 (f, face_idx, elem_idx, &te) ); + TRY( h5tpriv_find_te2 (m, face_idx, elem_idx, &te) ); TRY( h5priv_search_idlist (list, te->items[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -428,16 +346,16 @@ add_edge2 ( */ static inline h5_err_t add_triangle ( - h5_file_t* const f, // in + h5t_mesh_t* const m, // in h5_loc_idlist_t** list, // out h5_loc_idx_t entity_id // in ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, list=0x%p, entity_id=%llu", - f, list, - (long long unsigned)entity_id); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, list=%p, entity_id=%llu", + m, list, + (long long unsigned)entity_id); h5_loc_idlist_t* td; - TRY( h5tpriv_find_td (f, entity_id, &td) ); + TRY( h5tpriv_find_td (m, entity_id, &td) ); TRY( h5priv_search_idlist (list, td->items[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -445,18 +363,18 @@ add_triangle ( static inline h5_err_t add_triangle2 ( - h5_file_t* const f, // in + h5t_mesh_t* const m, // in h5_loc_idlist_t** list, // out h5_loc_idx_t face_idx, // in h5_loc_idx_t elem_idx // in ) { - H5_PRIV_FUNC_ENTER4 (h5_err_t, - "f=0x%p, list=0x%p, face_idx=%llu, elem_idx=%llu", - f, list, + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, list=%p, face_idx=%llu, elem_idx=%llu", + m, list, (long long unsigned)face_idx, (long long unsigned)elem_idx); h5_loc_idlist_t* td; - TRY( h5tpriv_find_td2 (f, face_idx, elem_idx, &td) ); + TRY( h5tpriv_find_td2 (m, face_idx, elem_idx, &td) ); TRY( h5priv_search_idlist (list, td->items[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -467,8 +385,8 @@ add_elem2 ( h5_loc_idlist_t** list, // out h5_loc_idx_t elem_idx // in ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "list=0x%p, elem_idx=%llu", + H5_PRIV_FUNC_ENTER (h5_err_t, + "list=%p, elem_idx=%llu", list, (long long unsigned)elem_idx); h5_loc_id_t elem_id = h5tpriv_build_tet_id (0, elem_idx); @@ -482,16 +400,16 @@ add_elem2 ( */ static inline h5_err_t get_edges_uadj_to_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idx_t vertex_idx; - TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); - h5_loc_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; + TRY( h5t_get_vertex_index_of_vertex (m, entity_id, &vertex_idx) ); + h5_loc_idlist_t* tv = m->adjacencies.tv.v[vertex_idx]; TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t* vertex_idp = tv->items; @@ -499,22 +417,22 @@ get_edges_uadj_to_vertex ( do { h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*vertex_idp); - h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; + h5_loc_tet_t* elem = &m->loc_elems.tets[elem_idx]; - if (!h5tpriv_is_leaf_elem (f, elem)) { + if (!h5tpriv_is_leaf_elem (m, elem)) { continue; } - TRY( add_edge2 (f, list, + TRY( add_edge2 (m, list, h5tpriv_ref_elem_get_edge_idx ( - f->t, 0, face_idx, 0), + m, 0, face_idx, 0), elem_idx) ); - TRY( add_edge2 (f, list, + TRY( add_edge2 (m, list, h5tpriv_ref_elem_get_edge_idx ( - f->t, 0, face_idx, 1), + m, 0, face_idx, 1), elem_idx) ); - TRY( add_edge2 (f, list, + TRY( add_edge2 (m, list, h5tpriv_ref_elem_get_edge_idx ( - f->t, 0, face_idx, 2), + m, 0, face_idx, 2), elem_idx) ); } while (++vertex_idp < end); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -522,19 +440,19 @@ get_edges_uadj_to_vertex ( static inline h5_err_t get_triangles_uadj_to_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); /* get list of all tetrahedra connected to given vertex Note: this list may include tetrahedra which are not in the (current) leaf grid */ h5_loc_idx_t vertex_idx; - TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); - h5_loc_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; + TRY( h5t_get_vertex_index_of_vertex (m, entity_id, &vertex_idx) ); + h5_loc_idlist_t* tv = m->adjacencies.tv.v[vertex_idx]; // build list of upward adjacent triangles TRY( h5priv_alloc_idlist (list, 8) ); @@ -543,21 +461,21 @@ get_triangles_uadj_to_vertex ( do { h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*vertex_idp); - h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; - if (!h5tpriv_is_leaf_elem (f, elem)) { + h5_loc_tet_t* elem = &m->loc_elems.tets[elem_idx]; + if (!h5tpriv_is_leaf_elem (m, elem)) { continue; } - TRY( add_triangle2 (f, list, + TRY( add_triangle2 (m, list, h5tpriv_ref_elem_get_triangle_idx ( - f->t, 0, face_idx, 0), + m, 0, face_idx, 0), elem_idx) ); - TRY( add_triangle2 (f, list, + TRY( add_triangle2 (m, list, h5tpriv_ref_elem_get_triangle_idx ( - f->t, 0, face_idx, 1), + m, 0, face_idx, 1), elem_idx) ); - TRY( add_triangle2 (f, list, + TRY( add_triangle2 (m, list, h5tpriv_ref_elem_get_triangle_idx ( - f->t, 0, face_idx, 2), + m, 0, face_idx, 2), elem_idx) ); } while (++vertex_idp < end); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -565,24 +483,24 @@ get_triangles_uadj_to_vertex ( static inline h5_err_t get_tets_uadj_to_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idx_t vertex_idx; - TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); - h5_loc_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; + TRY( h5t_get_vertex_index_of_vertex (m, entity_id, &vertex_idx) ); + h5_loc_idlist_t* tv = m->adjacencies.tv.v[vertex_idx]; TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t* vertex_idp = tv->items; h5_loc_id_t* end = vertex_idp + tv->num_items; do { h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); - h5_loc_tet_t* elem = &f->t->loc_elems.tets[elem_idx]; - if (!h5tpriv_is_leaf_elem (f, elem)) { + h5_loc_tet_t* elem = &m->loc_elems.tets[elem_idx]; + if (!h5tpriv_is_leaf_elem (m, elem)) { continue; } TRY( add_elem2 (list, elem_idx) ); @@ -592,29 +510,29 @@ get_tets_uadj_to_vertex ( static inline h5_err_t get_triangles_uadj_to_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); - TRY( compute_children_of_edge (f, entity_id, &children) ); + TRY( get_descendant_of_edge (m, entity_id, &children) ); TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t* edge_idp = children->items; h5_loc_id_t* end = children->items+children->num_items; do { h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); - TRY( add_triangle2 (f, list, + TRY( add_triangle2 (m, list, h5tpriv_ref_elem_get_triangle_idx ( - f->t, 1, face_idx, 0), + m, 1, face_idx, 0), elem_idx) ); - TRY( add_triangle2 (f, list, + TRY( add_triangle2 (m, list, h5tpriv_ref_elem_get_triangle_idx ( - f->t, 1, face_idx, 1), + m, 1, face_idx, 1), elem_idx) ); } while (++edge_idp < end); TRY (h5priv_free_idlist (&children)); @@ -624,16 +542,16 @@ get_triangles_uadj_to_edge ( static inline h5_err_t get_tets_uadj_to_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); - TRY( compute_children_of_edge (f, entity_id, &children) ); + TRY( get_descendant_of_edge (m, entity_id, &children) ); TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t* edge_idp = children->items; h5_loc_id_t* end = children->items+children->num_items; @@ -646,16 +564,16 @@ get_tets_uadj_to_edge ( static inline h5_err_t get_tets_uadj_to_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); - TRY( compute_children_of_triangle (f, entity_id, &children) ); + TRY( get_descendant_of_triangle (m, entity_id, &children) ); TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t* triangle_idp = children->items; h5_loc_id_t* end = triangle_idp + children->num_items; @@ -668,16 +586,16 @@ get_tets_uadj_to_triangle ( static inline h5_err_t get_vertices_dadj_to_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); - TRY( compute_sections_of_edge (f, entity_id, &children) ); + TRY( get_sections_of_edge (m, entity_id, &children) ); // build list of unique vertex IDs TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t* edge_idp = children->items; @@ -686,13 +604,13 @@ get_vertices_dadj_to_edge ( h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, face_idx, 0), + m, 1, face_idx, 0), elem_idx) ); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, face_idx, 1), + m, 1, face_idx, 1), elem_idx) ); } while (++edge_idp < end); TRY( h5priv_free_idlist(&children) ); @@ -704,13 +622,13 @@ get_vertices_dadj_to_edge ( */ static inline h5_err_t get_vertices_dadj_to_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); @@ -719,9 +637,9 @@ get_vertices_dadj_to_triangle ( int i; // loop over all vertices of given triangle for (i = 0; i < 3; i++) { - edge_idx = h5tpriv_ref_elem_get_edge_idx (f->t, 2, face_idx, i); - TRY( compute_sections_of_edge ( - f, + edge_idx = h5tpriv_ref_elem_get_edge_idx (m, 2, face_idx, i); + TRY( get_sections_of_edge ( + m, h5tpriv_build_edge_id (edge_idx, elem_idx), &children) ); } @@ -733,13 +651,13 @@ get_vertices_dadj_to_triangle ( elem_idx = h5tpriv_get_elem_idx (*edge_idp); edge_idx = h5tpriv_get_face_idx (*edge_idp); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, edge_idx, 0), + m, 1, edge_idx, 0), elem_idx) ); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, edge_idx, 1), + m, 1, edge_idx, 1), elem_idx) ); } while (++edge_idp < end ); TRY( h5priv_free_idlist(&children) ); @@ -751,21 +669,21 @@ get_vertices_dadj_to_triangle ( */ static inline h5_err_t get_vertices_dadj_to_tet ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); TRY( h5priv_alloc_idlist (&children, 8) ); // loop over all edges of tetrahedron - h5_loc_idx_t edge_idx = h5tpriv_ref_elem_get_num_edges(f->t); + h5_loc_idx_t edge_idx = h5tpriv_ref_elem_get_num_edges(m); while (--edge_idx >= 0) { - TRY( compute_sections_of_edge ( - f, + TRY( get_sections_of_edge ( + m, h5tpriv_build_edge_id ( edge_idx, elem_idx ), &children) ); } @@ -777,13 +695,13 @@ get_vertices_dadj_to_tet ( elem_idx = h5tpriv_get_elem_idx (*edge_idp); edge_idx = h5tpriv_get_face_idx (*edge_idp); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, edge_idx, 0), + m, 1, edge_idx, 0), elem_idx) ); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, edge_idx, 1), + m, 1, edge_idx, 1), elem_idx) ); } while (++edge_idp < end); TRY( h5priv_free_idlist(&children) ); @@ -792,13 +710,13 @@ get_vertices_dadj_to_tet ( static inline h5_err_t get_edges_dadj_to_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); @@ -806,11 +724,11 @@ get_edges_dadj_to_triangle ( // loop over all three edges of triangle h5_loc_idx_t i; for (i = 0; i < 3; i++) { - TRY( compute_sections_of_edge ( - f, + TRY( get_sections_of_edge ( + m, h5tpriv_build_edge_id ( h5tpriv_ref_elem_get_edge_idx ( - f->t, 2, face_idx, i), + m, 2, face_idx, i), elem_idx ), &children) ); } @@ -819,7 +737,7 @@ get_edges_dadj_to_triangle ( h5_loc_id_t* edge_idp = children->items; h5_loc_id_t* end = edge_idp + children->num_items; do { - TRY( add_edge (f, list, *edge_idp) ); + TRY( add_edge (m, list, *edge_idp) ); } while (++edge_idp < end); TRY( h5priv_free_idlist (&children) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -827,22 +745,22 @@ get_edges_dadj_to_triangle ( static inline h5_err_t get_edges_dadj_to_tet ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t elem_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, elem_id=%llu, list=0x%p", - f, (long long unsigned)elem_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, elem_id=%llu, list=%p", + m, (long long unsigned)elem_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (elem_id); // loop over all edges of tet - h5_loc_idx_t edge_idx = h5tpriv_ref_elem_get_num_edges(f->t); + h5_loc_idx_t edge_idx = h5tpriv_ref_elem_get_num_edges(m); while (--edge_idx >= 0) { - TRY( compute_sections_of_edge ( - f, + TRY( get_sections_of_edge ( + m, h5tpriv_build_edge_id (edge_idx, elem_idx), &children) ); } @@ -851,7 +769,7 @@ get_edges_dadj_to_tet ( h5_loc_id_t* edge_idp = children->items; h5_loc_id_t* end = edge_idp + children->num_items; do { - TRY( add_edge (f, list, *edge_idp) ); + TRY( add_edge (m, list, *edge_idp) ); } while (++edge_idp < end); TRY( h5priv_free_idlist (&children) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -859,21 +777,21 @@ get_edges_dadj_to_tet ( static inline h5_err_t get_triangles_dadj_to_tet ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); // loop over all triangle of element - h5_loc_idx_t triangle_idx = h5tpriv_ref_elem_get_num_facets(f->t); + h5_loc_idx_t triangle_idx = h5tpriv_ref_elem_get_num_facets(m); while (--triangle_idx >= 0) { - TRY( compute_sections_of_triangle ( - f, + TRY( get_sections_of_triangle ( + m, h5tpriv_build_edge_id (triangle_idx, elem_idx), &children) ); } @@ -881,7 +799,7 @@ get_triangles_dadj_to_tet ( h5_loc_id_t* triangle_idp = children->items; h5_loc_id_t* end = triangle_idp + children->num_items; do { - TRY( add_triangle (f, list, *triangle_idp) ); + TRY( add_triangle (m, list, *triangle_idp) ); } while (++triangle_idp < end); TRY( h5priv_free_idlist (&children) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -898,18 +816,18 @@ dim_error( static inline h5_err_t get_adjacencies_to_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { switch (dim) { case 1: - return get_edges_uadj_to_vertex(f, entity_id, list); + return get_edges_uadj_to_vertex(m, entity_id, list); case 2: - return get_triangles_uadj_to_vertex(f, entity_id, list); + return get_triangles_uadj_to_vertex(m, entity_id, list); case 3: - return get_tets_uadj_to_vertex(f, entity_id, list); + return get_tets_uadj_to_vertex(m, entity_id, list); default: return dim_error (dim); } @@ -917,18 +835,18 @@ get_adjacencies_to_vertex ( static inline h5_err_t get_adjacencies_to_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { switch (dim) { case 0: - return get_vertices_dadj_to_edge(f, entity_id, list); + return get_vertices_dadj_to_edge(m, entity_id, list); case 2: - return get_triangles_uadj_to_edge(f, entity_id, list); + return get_triangles_uadj_to_edge(m, entity_id, list); case 3: - return get_tets_uadj_to_edge(f, entity_id, list); + return get_tets_uadj_to_edge(m, entity_id, list); default: return dim_error (dim); } @@ -936,18 +854,18 @@ get_adjacencies_to_edge ( static inline h5_err_t get_adjacencies_to_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { switch (dim) { case 0: - return get_vertices_dadj_to_triangle(f, entity_id, list); + return get_vertices_dadj_to_triangle(m, entity_id, list); case 1: - return get_edges_dadj_to_triangle(f, entity_id, list); + return get_edges_dadj_to_triangle(m, entity_id, list); case 3: - return get_tets_uadj_to_triangle(f, entity_id, list); + return get_tets_uadj_to_triangle(m, entity_id, list); default: return dim_error (dim); } @@ -955,18 +873,18 @@ get_adjacencies_to_triangle ( static inline h5_err_t get_adjacencies_to_tet ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { switch (dim) { case 0: - return get_vertices_dadj_to_tet(f, entity_id, list); + return get_vertices_dadj_to_tet(m, entity_id, list); case 1: - return get_edges_dadj_to_tet(f, entity_id, list); + return get_edges_dadj_to_tet(m, entity_id, list); case 2: - return get_triangles_dadj_to_tet(f, entity_id, list); + return get_triangles_dadj_to_tet(m, entity_id, list); default: return dim_error (dim); } @@ -974,7 +892,7 @@ get_adjacencies_to_tet ( static h5_err_t get_adjacencies ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list @@ -982,13 +900,13 @@ get_adjacencies ( h5_loc_id_t entity_type = h5tpriv_get_entity_type (entity_id); switch (entity_type) { case H5T_TYPE_VERTEX: - return get_adjacencies_to_vertex (f, entity_id, dim, list); + return get_adjacencies_to_vertex (m, entity_id, dim, list); case H5T_TYPE_EDGE: - return get_adjacencies_to_edge (f, entity_id, dim, list); + return get_adjacencies_to_edge (m, entity_id, dim, list); case H5T_TYPE_TRIANGLE: - return get_adjacencies_to_triangle (f, entity_id, dim, list); + return get_adjacencies_to_triangle (m, entity_id, dim, list); case H5T_TYPE_TET: - return get_adjacencies_to_tet (f, entity_id, dim, list); + return get_adjacencies_to_tet (m, entity_id, dim, list); default: break; } @@ -998,41 +916,37 @@ get_adjacencies ( static h5_err_t update_internal_structs ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, from_lvl=%u", - f, (unsigned)from_lvl); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, from_lvl=%u", + m, (unsigned)from_lvl); clock_t t1 = clock(); - TRY( compute_elems_of_vertices (f, from_lvl) ); + TRY( compute_elems_of_vertices (m, from_lvl) ); clock_t t2 = clock(); - fprintf (stderr, "compute_tets_of_vertices(): %f\n", - (float)(t2-t1)/CLOCKS_PER_SEC); + h5_debug ("compute_elems_of_vertices(): %f\n", (float)(t2-t1)/CLOCKS_PER_SEC); t1 = clock(); - TRY( compute_elems_of_edges (f, from_lvl) ); + TRY( compute_elems_of_edges (m, from_lvl) ); t2 = clock(); - fprintf (stderr, "compute_tets_of_edge(): %f\n", - (float)(t2-t1)/CLOCKS_PER_SEC); + h5_debug ("compute_elems_of_edge(): %f\n", (float)(t2-t1)/CLOCKS_PER_SEC); t1 = clock(); - TRY( compute_elems_of_triangles (f, from_lvl) ); + TRY( compute_elems_of_triangles (m, from_lvl) ); t2 = clock(); - fprintf (stderr, "compute_tets_of_triangle(): %f\n", - (float)(t2-t1)/CLOCKS_PER_SEC); + h5_debug ("compute_tets_of_triangle(): %f\n", (float)(t2-t1)/CLOCKS_PER_SEC); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static h5_err_t release_internal_structs ( - h5_file_t * const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - TRY( release_tv (f) ); - TRY( h5priv_hdestroy (&t->adjacencies.te_hash) ); - TRY( h5priv_hdestroy (&t->adjacencies.td_hash) ); - memset (&t->adjacencies, 0, sizeof (t->adjacencies)); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + TRY( release_tv (m) ); + TRY( h5priv_hdestroy (&m->adjacencies.te_hash) ); + TRY( h5priv_hdestroy (&m->adjacencies.td_hash) ); + memset (&m->adjacencies, 0, sizeof (m->adjacencies)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5t_adjacencies_trim.c b/src/h5core/h5t_adjacencies_trim.c index 4fe206a..b99453d 100644 --- a/src/h5core/h5t_adjacencies_trim.c +++ b/src/h5core/h5t_adjacencies_trim.c @@ -19,20 +19,19 @@ static inline h5_err_t alloc_tv ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, from_lvl=%u", - f, (unsigned)from_lvl); - h5t_fdata_t* t = f->t; - h5_loc_idx_t num_vertices = t->num_vertices[t->num_leaf_levels-1]; + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, from_lvl=%u", + m, (unsigned)from_lvl); + h5_loc_idx_t num_vertices = m->num_vertices[m->num_leaf_levels-1]; - h5t_adjacencies_t* adj = &t->adjacencies; + h5t_adjacencies_t* adj = &m->adjacencies; // allocate ptr to ID-list per vertex TRY( adj->tv.v = h5_alloc (adj->tv.v, num_vertices*sizeof(*adj->tv.v)) ); - size_t i = from_lvl <= 0 ? 0 : t->num_vertices[from_lvl-1]; + size_t i = from_lvl <= 0 ? 0 : m->num_vertices[from_lvl-1]; memset (adj->tv.v+i, 0, (num_vertices-i)*sizeof(*adj->tv.v)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -40,16 +39,15 @@ alloc_tv ( static inline h5_err_t release_tv ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - h5t_adjacencies_t* adj = &t->adjacencies; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + h5t_adjacencies_t* adj = &m->adjacencies; if (adj->tv.v == NULL) H5_PRIV_FUNC_LEAVE (H5_SUCCESS); h5_loc_idx_t vertex_idx = 0; - h5_loc_idx_t last = t->num_vertices[t->num_leaf_levels-1]; + h5_loc_idx_t last = m->num_vertices[m->num_leaf_levels-1]; for (; vertex_idx < last; vertex_idx++) { TRY( h5priv_free_idlist (&adj->tv.v[vertex_idx]) ); } @@ -63,25 +61,24 @@ release_tv ( */ static inline h5_err_t compute_elems_of_vertices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, from_lvl=%u", - f, (unsigned)from_lvl); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, from_lvl=%u", + m, (unsigned)from_lvl); /* expand structure */ - TRY( alloc_tv (f, from_lvl) ); + TRY( alloc_tv (m, from_lvl) ); /* loop over all elements in current level */ - h5t_fdata_t *t = f->t; - h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; - h5_loc_idx_t last = (t->num_leaf_levels < 0) ? 0 : t->num_elems[t->num_leaf_levels-1]; + h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : m->num_elems[from_lvl-1]; + h5_loc_idx_t last = (m->num_leaf_levels < 0) ? 0 : m->num_elems[m->num_leaf_levels-1]; for (;elem_idx < last; elem_idx++) { int face_idx; - int num_faces = h5tpriv_ref_elem_get_num_vertices (t); + int num_faces = h5tpriv_ref_elem_get_num_vertices (m); for (face_idx = 0; face_idx < num_faces; face_idx++) { - TRY( h5tpriv_search_tv2 (f, face_idx, elem_idx, NULL) ); + TRY( h5tpriv_search_tv2 (m, face_idx, elem_idx, NULL) ); } } H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -92,102 +89,85 @@ compute_elems_of_vertices ( */ static inline h5_err_t compute_elems_of_edges ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, from_lvl=%u", - f, (unsigned)from_lvl); - h5t_fdata_t *t = f->t; - h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; - h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - TRY( h5tpriv_resize_te_htab (f, 4*(num_elems-elem_idx)) ); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, from_lvl=%u", + m, (unsigned)from_lvl); + h5_loc_idx_t elem_idx = (from_lvl <= 0) ? 0 : m->num_elems[from_lvl-1]; + h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; + TRY( h5tpriv_resize_te_htab (m, 4*(num_elems-elem_idx)) ); for (;elem_idx < num_elems; elem_idx++) { h5_loc_idx_t face_idx; - h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (t); + h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (m); for (face_idx = 0; face_idx < num_faces; face_idx++) { - TRY ( h5tpriv_search_te2 (f, face_idx, elem_idx, NULL ) ); + TRY ( h5tpriv_search_te2 (m, face_idx, elem_idx, NULL ) ); } } H5_PRIV_FUNC_RETURN (H5_SUCCESS); } /* - Compute the children o an edge + Please read the note about "descendants" and "sections" in the + corresponding file for tetrahedral meshes. */ static inline h5_err_t -compute_children_of_edge ( - h5_file_t* const f, +get_descendant_of_edge ( + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idlist_t** children ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, children=0x%p", - f, - (long long unsigned)entity_id, - children); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, children=%p", + m, + (long long unsigned)entity_id, + children); h5_loc_idlist_t* te; - TRY( h5tpriv_find_te (f, entity_id, &te ) ); + TRY( h5tpriv_find_te (m, entity_id, &te ) ); h5_loc_id_t* edge_idp = te->items; h5_loc_id_t* end = te->items + te->num_items; do { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); - h5_loc_triangle_t *elem = &f->t->loc_elems.tris[elem_idx]; - if (h5tpriv_is_leaf_elem (f, elem)) { + h5_loc_id_t edge_ids[2] = {-1,-1}; + TRY (h5tpriv_get_loc_entity_children (m, *edge_idp, edge_ids)); + if (edge_ids[0] == -1) { TRY( h5priv_insert_idlist (children, *edge_idp, -1) ); } else { - h5_loc_id_t edge_ids[2]; - TRY( h5tpriv_get_direct_children_of_edge ( - f, - face_idx, - elem->child_idx, - edge_ids ) ); - TRY( compute_children_of_edge (f, edge_ids[0], children) ); - TRY( compute_children_of_edge (f, edge_ids[1], children) ); + TRY( get_descendant_of_edge (m, edge_ids[0], children) ); + TRY( get_descendant_of_edge (m, edge_ids[1], children) ); } } while (++edge_idp < end); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } -/* - Compute all sections of an edge. -*/ static inline h5_err_t -compute_sections_of_edge ( - h5_file_t * const f, +get_sections_of_edge ( + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idlist_t** children ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, children=0x%p", - f, - (long long unsigned)entity_id, + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, children=%p", + m, + (long long unsigned)entity_id, children); h5_loc_idlist_t* te; - TRY( h5tpriv_find_te (f, entity_id, &te) ); + TRY (h5tpriv_find_te (m, entity_id, &te)); h5_loc_id_t* edge_idp = te->items; h5_loc_id_t *end = te->items+te->num_items; int refined = 0; do { - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx ( *edge_idp ); - h5_loc_idx_t face_idx = h5tpriv_get_face_idx ( *edge_idp ); - h5_loc_triangle_t* elem = &f->t->loc_elems.tris[elem_idx]; - if (!h5tpriv_is_leaf_elem (f, elem)) { + h5_loc_id_t edge_ids[2] = {-1,-1}; + TRY (h5tpriv_get_loc_entity_children (m, *edge_idp, edge_ids)); + if (edge_ids[0] >= 0) { refined = 1; - h5_loc_id_t edge_ids[2]; - TRY( h5tpriv_get_direct_children_of_edge ( - f, - face_idx, - elem->child_idx, - edge_ids) ); - TRY( compute_sections_of_edge (f, edge_ids[0], children) ); - TRY( compute_sections_of_edge (f, edge_ids[1], children) ); + TRY (get_sections_of_edge (m, edge_ids[0], children)); + TRY (get_sections_of_edge (m, edge_ids[1], children)); } } while (++edge_idp < end); if (!refined) { - TRY( h5priv_insert_idlist (children, te->items[0], -1) ); + TRY (h5priv_insert_idlist (children, te->items[0], -1)); } H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -197,18 +177,18 @@ compute_sections_of_edge ( */ static inline h5_err_t add_vertex2 ( - h5_file_t* const f, // in + h5t_mesh_t* const m, // in h5_loc_idlist_t** list, // out h5_loc_idx_t face_idx, // in h5_loc_idx_t elem_idx // in ) { - H5_PRIV_FUNC_ENTER4 (h5_err_t, - "f=0x%p, list=0x%p, face_idx=%llu, elem_idx=%llu", - f, list, + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, list=%p, face_idx=%llu, elem_idx=%llu", + m, list, (long long unsigned)face_idx, (long long unsigned)elem_idx); h5_loc_idlist_t* tv; - TRY( h5tpriv_find_tv2 (f, face_idx, elem_idx, &tv) ); + TRY( h5tpriv_find_tv2 (m, face_idx, elem_idx, &tv) ); TRY( h5priv_search_idlist (list, tv->items[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -218,34 +198,34 @@ add_vertex2 ( */ static inline h5_err_t add_edge ( - h5_file_t* const f, // in + h5t_mesh_t* const m, // in h5_loc_idlist_t** list, // out h5_loc_id_t entity_id // in ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, list=0x%p, entity_id=%llu", - f, list, - (long long unsigned)entity_id); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, list=%p, entity_id=%llu", + m, list, + (long long unsigned)entity_id); h5_loc_idlist_t* te; - TRY( h5tpriv_find_te (f, entity_id, &te) ); + TRY( h5tpriv_find_te (m, entity_id, &te) ); TRY( h5priv_search_idlist (list, te->items[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static inline h5_err_t add_edge2 ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idlist_t** list, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx ) { - H5_PRIV_FUNC_ENTER4 (h5_err_t, - "f=0x%p, list=0x%p, face_idx=%llu, elem_idx=%llu", - f, list, + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, list=%p, face_idx=%llu, elem_idx=%llu", + m, list, (long long unsigned)face_idx, (long long unsigned)elem_idx); h5_loc_idlist_t *te; - TRY( h5tpriv_find_te2 (f, face_idx, elem_idx, &te) ); + TRY( h5tpriv_find_te2 (m, face_idx, elem_idx, &te) ); TRY( h5priv_search_idlist (list, te->items[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -255,8 +235,8 @@ add_elem2 ( h5_loc_idlist_t** list, // out h5_loc_idx_t elem_idx // in ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "list=0x%p, elem_idx=%llu", + H5_PRIV_FUNC_ENTER (h5_err_t, + "list=%p, elem_idx=%llu", list, (long long unsigned)elem_idx); h5_loc_id_t elem_id = h5tpriv_build_triangle_id (0, elem_idx); @@ -270,16 +250,16 @@ add_elem2 ( */ static inline h5_err_t get_edges_uadj_to_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idx_t vertex_idx; - TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); - h5_loc_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; + TRY( h5t_get_vertex_index_of_vertex (m, entity_id, &vertex_idx) ); + h5_loc_idlist_t* tv = m->adjacencies.tv.v[vertex_idx]; TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t* vertex_idp = tv->items; @@ -287,18 +267,18 @@ get_edges_uadj_to_vertex ( do { h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*vertex_idp); - h5_loc_triangle_t* elem= &f->t->loc_elems.tris[elem_idx]; + h5_loc_triangle_t* elem= &m->loc_elems.tris[elem_idx]; - if (!h5tpriv_is_leaf_elem (f, elem)) { + if (!h5tpriv_is_leaf_elem (m, elem)) { continue; } - TRY( add_edge2 (f, list, + TRY( add_edge2 (m, list, h5tpriv_ref_elem_get_edge_idx ( - f->t, 0, face_idx, 0), + m, 0, face_idx, 0), elem_idx) ); - TRY( add_edge2 (f, list, + TRY( add_edge2 (m, list, h5tpriv_ref_elem_get_edge_idx ( - f->t, 0, face_idx, 1), + m, 0, face_idx, 1), elem_idx) ); } while (++vertex_idp < end); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -306,25 +286,25 @@ get_edges_uadj_to_vertex ( static inline h5_err_t get_triangles_uadj_to_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idx_t vertex_idx; - TRY( h5t_get_vertex_index_of_vertex (f, entity_id, &vertex_idx) ); - h5_loc_idlist_t* tv = f->t->adjacencies.tv.v[vertex_idx]; + TRY( h5t_get_vertex_index_of_vertex (m, entity_id, &vertex_idx) ); + h5_loc_idlist_t* tv = m->adjacencies.tv.v[vertex_idx]; TRY ( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t *vertex_idp = tv->items; h5_loc_id_t* end = vertex_idp + tv->num_items; do { h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*vertex_idp); - h5_loc_triangle_t* elem = &f->t->loc_elems.tris[elem_idx]; + h5_loc_triangle_t* elem = &m->loc_elems.tris[elem_idx]; - if (!h5tpriv_is_leaf_elem (f, elem)) { + if (!h5tpriv_is_leaf_elem (m, elem)) { continue; } TRY (add_elem2 (list, elem_idx)); @@ -334,16 +314,16 @@ get_triangles_uadj_to_vertex ( static inline h5_err_t get_triangles_uadj_to_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); - TRY( compute_children_of_edge (f, entity_id, &children) ); + TRY( get_descendant_of_edge (m, entity_id, &children) ); TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t *edge_idp = children->items; h5_loc_id_t *end = children->items+children->num_items; @@ -358,23 +338,23 @@ get_triangles_uadj_to_edge ( static inline h5_err_t get_edges_adj_to_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); - TRY( compute_sections_of_edge (f, entity_id, &children) ); + TRY( get_sections_of_edge (m, entity_id, &children) ); TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t* edge_idp = children->items; h5_loc_id_t* end = children->items+children->num_items; do { - TRY( add_edge (f, list, *edge_idp) ); + TRY( add_edge (m, list, *edge_idp) ); } while (++edge_idp < end); TRY( h5priv_free_idlist(&children) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -382,16 +362,16 @@ get_edges_adj_to_edge ( static inline h5_err_t get_vertices_dadj_to_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY( h5priv_alloc_idlist (&children, 8) ); - TRY( compute_sections_of_edge (f, entity_id, &children) ); + TRY( get_sections_of_edge (m, entity_id, &children) ); TRY( h5priv_alloc_idlist (list, 8) ); h5_loc_id_t* edge_idp = children->items; h5_loc_id_t* end = edge_idp + children->num_items; @@ -399,13 +379,13 @@ get_vertices_dadj_to_edge ( h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (*edge_idp); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (*edge_idp); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, face_idx, 0), + m, 1, face_idx, 0), elem_idx) ); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, face_idx, 1), + m, 1, face_idx, 1), elem_idx) ); } while (++edge_idp < end); TRY( h5priv_free_idlist (&children) ); @@ -417,23 +397,23 @@ get_vertices_dadj_to_edge ( */ static inline h5_err_t get_vertices_dadj_to_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY (h5priv_alloc_idlist (&children, 8)); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx ( entity_id ); // loop over all edges of triangle h5_loc_idx_t face_idx; - h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (f->t); + h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (m); for (face_idx = 0; face_idx < num_faces; face_idx++) { - TRY( compute_sections_of_edge ( - f, + TRY( get_sections_of_edge ( + m, h5tpriv_build_edge_id (face_idx, elem_idx), &children) ); } @@ -444,13 +424,13 @@ get_vertices_dadj_to_triangle ( elem_idx = h5tpriv_get_elem_idx (*edge_idp); face_idx = h5tpriv_get_face_idx (*edge_idp); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, face_idx, 0), + m, 1, face_idx, 0), elem_idx) ); - TRY( add_vertex2 (f, list, + TRY( add_vertex2 (m, list, h5tpriv_ref_elem_get_vertex_idx ( - f->t, 1, face_idx, 1), + m, 1, face_idx, 1), elem_idx) ); } while (++edge_idp < end); TRY (h5priv_free_idlist(&children)); @@ -459,21 +439,21 @@ get_vertices_dadj_to_triangle ( static inline h5_err_t get_edges_dadj_to_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idlist_t** list ) { - H5_PRIV_FUNC_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%llu, list=0x%p", - f, (long long unsigned)entity_id, list); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, entity_id=%llu, list=%p", + m, (long long unsigned)entity_id, list); h5_loc_idlist_t* children; TRY (h5priv_alloc_idlist (&children, 8)); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); // loop over all edges of triangle - h5_loc_idx_t edge_idx = h5tpriv_ref_elem_get_num_edges (f->t); + h5_loc_idx_t edge_idx = h5tpriv_ref_elem_get_num_edges (m); while (--edge_idx >= 0) { - TRY( compute_sections_of_edge ( - f, + TRY( get_sections_of_edge ( + m, h5tpriv_build_edge_id (edge_idx, elem_idx), &children) ); } @@ -481,7 +461,7 @@ get_edges_dadj_to_triangle ( h5_loc_id_t* edge_idp = children->items; h5_loc_id_t* end = edge_idp + children->num_items; do { - TRY( add_edge (f, list, *edge_idp) ); + TRY( add_edge (m, list, *edge_idp) ); } while (++edge_idp < end); TRY (h5priv_free_idlist(&children)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); @@ -498,16 +478,16 @@ dim_error( static inline h5_err_t get_adjacencies_to_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { switch (dim) { case 1: - return get_edges_uadj_to_vertex(f, entity_id, list); + return get_edges_uadj_to_vertex(m, entity_id, list); case 2: - return get_triangles_uadj_to_vertex(f, entity_id, list); + return get_triangles_uadj_to_vertex(m, entity_id, list); default: return dim_error (dim); } @@ -515,18 +495,18 @@ get_adjacencies_to_vertex ( static inline h5_err_t get_adjacencies_to_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { switch (dim) { case 0: - return get_vertices_dadj_to_edge(f, entity_id, list); + return get_vertices_dadj_to_edge(m, entity_id, list); case 1: - return get_edges_adj_to_edge(f, entity_id, list); + return get_edges_adj_to_edge(m, entity_id, list); case 2: - return get_triangles_uadj_to_edge(f, entity_id, list); + return get_triangles_uadj_to_edge(m, entity_id, list); default: return dim_error (dim); } @@ -534,16 +514,16 @@ get_adjacencies_to_edge ( static inline h5_err_t get_adjacencies_to_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { switch (dim) { case 0: - return get_vertices_dadj_to_triangle(f, entity_id, list); + return get_vertices_dadj_to_triangle(m, entity_id, list); case 1: - return get_edges_dadj_to_triangle(f, entity_id, list); + return get_edges_dadj_to_triangle(m, entity_id, list); default: return dim_error (dim); } @@ -551,7 +531,7 @@ get_adjacencies_to_triangle ( static h5_err_t get_adjacencies ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list @@ -559,11 +539,11 @@ get_adjacencies ( h5_loc_id_t entity_type = h5tpriv_get_entity_type (entity_id); switch (entity_type) { case H5T_TYPE_VERTEX: - return get_adjacencies_to_vertex (f, entity_id, dim, list); + return get_adjacencies_to_vertex (m, entity_id, dim, list); case H5T_TYPE_EDGE: - return get_adjacencies_to_edge (f, entity_id, dim, list); + return get_adjacencies_to_edge (m, entity_id, dim, list); case H5T_TYPE_TRIANGLE: - return get_adjacencies_to_triangle (f, entity_id, dim, list); + return get_adjacencies_to_triangle (m, entity_id, dim, list); default: break; } @@ -572,20 +552,20 @@ get_adjacencies ( static inline h5_err_t update_internal_structs ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, from_lvl=%u", - f, (unsigned)from_lvl); + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, from_lvl=%u", + m, (unsigned)from_lvl); h5_debug ("%s (%lld)", __func__, (long long)from_lvl); clock_t t1 = clock(); - TRY( compute_elems_of_vertices (f, from_lvl) ); + TRY( compute_elems_of_vertices (m, from_lvl) ); clock_t t2 = clock(); // fprintf (stderr, "compute_elems_of_vertices(): %f\n", // (float)(t2-t1)/CLOCKS_PER_SEC); t1 = clock(); - TRY( compute_elems_of_edges (f, from_lvl ) ); + TRY( compute_elems_of_edges (m, from_lvl ) ); t2 = clock(); // fprintf (stderr, "compute_elems_of_edge(): %f\n", // (float)(t2-t1)/CLOCKS_PER_SEC); @@ -595,13 +575,12 @@ update_internal_structs ( static inline h5_err_t release_internal_structs ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t *t = f->t; - TRY( release_tv (f) ); - TRY( h5priv_hdestroy (&t->adjacencies.te_hash) ); - memset (&t->adjacencies, 0, sizeof (t->adjacencies)); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + TRY( release_tv (m) ); + TRY( h5priv_hdestroy (&m->adjacencies.te_hash) ); + memset (&m->adjacencies, 0, sizeof (m->adjacencies)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5t_errorhandling_private.h b/src/h5core/h5t_errorhandling_private.h index 0e0cc26..5619c7e 100644 --- a/src/h5core/h5t_errorhandling_private.h +++ b/src/h5core/h5t_errorhandling_private.h @@ -5,16 +5,15 @@ static inline h5_err_t h5tpriv_error_local_elem_nexist ( - h5_file_t * const f, + h5t_mesh_t * const m, h5_loc_idx_t vertex_indices[] ) { - h5t_fdata_t* t = f->t; char s[1024]; int num_chars_printed = snprintf (s, sizeof(s), "%lld,", (long long)vertex_indices[0]); int i; - int num_vertices = h5tpriv_ref_elem_get_num_vertices (t); + int num_vertices = h5tpriv_ref_elem_get_num_vertices (m); for (i = 1; i < num_vertices; i++) { num_chars_printed += snprintf ( s + num_chars_printed, sizeof (s) - num_chars_printed, diff --git a/src/h5core/h5t_hsearch.c b/src/h5core/h5t_hsearch.c index 2706f90..5aa019b 100644 --- a/src/h5core/h5t_hsearch.c +++ b/src/h5core/h5t_hsearch.c @@ -6,27 +6,26 @@ h5_err_t h5tpriv_search_tv2 ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, // in h5_loc_idx_t elem_idx, // in h5_loc_idlist_t** idlist // out ) { - H5_PRIV_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%lld, elem_idx=%lld, idlist=0x%p", - f, (long long)face_idx, (long long)elem_idx, idlist); - h5t_fdata_t* t = f->t; + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, face_idx=%lld, elem_idx=%lld, idlist=%p", + m, (long long)face_idx, (long long)elem_idx, idlist); h5_loc_idx_t vertex_idx; TRY (h5t_get_vertex_index_of_vertex2 ( - f, + m, face_idx, elem_idx, &vertex_idx)); TRY (h5priv_search_idlist ( - &t->adjacencies.tv.v[vertex_idx], + &m->adjacencies.tv.v[vertex_idx], h5tpriv_build_vertex_id (face_idx, elem_idx))); if (idlist) { - *idlist = t->adjacencies.tv.v[vertex_idx]; + *idlist = m->adjacencies.tv.v[vertex_idx]; } H5_PRIV_API_RETURN (H5_SUCCESS); @@ -64,7 +63,7 @@ static h5_err_t release_te_entry ( const void* __entry ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, "__entry=%p", __entry); struct h5_te_entry* entry = *(struct h5_te_entry**)__entry; h5_loc_idlist_t* list = entry->value; TRY (h5priv_free_idlist (&list)); @@ -74,11 +73,11 @@ release_te_entry ( h5_err_t h5tpriv_resize_te_htab ( - h5_file_t* const f, + h5t_mesh_t* const m, size_t nel ) { - H5_PRIV_API_ENTER2 (h5_err_t, "f=0x%p, nel=%lld", f, (long long)nel); - h5t_adjacencies_t* a = &f->t->adjacencies; + H5_PRIV_API_ENTER (h5_err_t, "m=%p, nel=%lld", m, (long long)nel); + h5t_adjacencies_t* a = &m->adjacencies; if ( a->te_hash.size == 0 ) { TRY (h5priv_hcreate ( nel, @@ -94,23 +93,23 @@ h5tpriv_resize_te_htab ( h5_err_t h5tpriv_search_te2 ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t** idlist ) { - H5_PRIV_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%lld, elem_idx=%lld, idlist=0x%p", - f, (long long)face_idx, (long long)elem_idx, idlist); - h5t_fdata_t* t = f->t; - h5t_adjacencies_t* a = &t->adjacencies; + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, face_idx=%lld, elem_idx=%lld, idlist=%p", + m, (long long)face_idx, (long long)elem_idx, idlist); + h5t_adjacencies_t* a = &m->adjacencies; void* __retval; - h5t_te_entry_t* entry; - - TRY (entry = h5_calloc (1, sizeof (*entry))); + static h5t_te_entry_t* entry = NULL; + if (entry == NULL) { + TRY (entry = h5_calloc (1, sizeof (*entry))); + } TRY (h5t_get_vertex_indices_of_edge2 ( - f, face_idx, elem_idx, entry->key.vids)); + m, face_idx, elem_idx, entry->key.vids)); /* resize hash table if more than 3/4 filled */ @@ -124,7 +123,7 @@ h5tpriv_search_te2 ( of remaining elements is a good enough guess for the number of edges we still have to add to the hash table. */ - h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; + h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; TRY (h5priv_hresize ( 3*(num_elems - elem_idx), &a->te_hash)); @@ -135,13 +134,12 @@ h5tpriv_search_te2 ( &__retval, &a->te_hash)); h5t_te_entry_t* te_entry = (h5t_te_entry_t *)__retval; + if (entry == te_entry) { // if used, + entry = NULL; // force allocation of new entry + } TRY (h5priv_search_idlist ( &te_entry->value, h5tpriv_build_edge_id (face_idx, elem_idx))); - if (te_entry->value->num_items > 1) { - /* search returned existing entry */ - TRY (h5_free (entry)); - } if (idlist) { *idlist = te_entry->value; } @@ -155,19 +153,20 @@ h5tpriv_search_te2 ( */ static inline h5_err_t find_te ( - h5_file_t* const f, + h5t_mesh_t* const m, h5t_te_entry_t* item, // in: item to find h5_loc_idlist_t** idlist // out: ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, item=%p, idlist=%p", + m, item, idlist); void* __entry; TRY (h5priv_hsearch ( item, H5_FIND, &__entry, - &f->t->adjacencies.te_hash)); + &m->adjacencies.te_hash)); h5t_te_entry_t* entry = (h5t_te_entry_t*)__entry; - if (entry ==NULL) { + if (entry == NULL) { H5_PRIV_FUNC_LEAVE (H5_NOK); // not found } if (idlist) { @@ -183,39 +182,40 @@ find_te ( */ h5_err_t h5tpriv_find_te ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t edge_id, // in h5_loc_idlist_t** idlist // out ) { - H5_PRIV_API_ENTER3 (h5_err_t, - "f=0x%p, edge_id=%lld, idlist=0x%p", - f, (long long)edge_id, idlist); + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, edge_id=%lld, idlist=%p", + m, (long long)edge_id, idlist); h5t_te_entry_t item; TRY (h5t_get_vertex_indices_of_edge ( - f, + m, edge_id, item.key.vids)); - TRY (find_te (f, &item, idlist)); + + TRY (find_te (m, &item, idlist)); H5_PRIV_API_RETURN (H5_SUCCESS); } h5_err_t h5tpriv_find_te2 ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, // in h5_loc_idx_t elem_idx, // in h5_loc_idlist_t** idlist // out ) { - H5_PRIV_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%lld, elem_idx=%lld, idlist=0x%p", - f, (long long)face_idx, (long long)elem_idx, idlist); + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, face_idx=%lld, elem_idx=%lld, idlist=%p", + m, (long long)face_idx, (long long)elem_idx, idlist); h5t_te_entry_t item; TRY (h5t_get_vertex_indices_of_edge2 ( - f, + m, face_idx, elem_idx, item.key.vids)); - TRY (find_te (f, &item, idlist)); + TRY (find_te (m, &item, idlist)); H5_PRIV_API_RETURN (H5_SUCCESS); } @@ -251,7 +251,7 @@ static h5_err_t release_td_entry ( const void* __entry ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, "__entry=%p", __entry); struct h5_td_entry* entry = *(struct h5_td_entry**)__entry; h5_loc_idlist_t* list = entry->value; TRY (h5priv_free_idlist (&list)); @@ -262,11 +262,11 @@ release_td_entry ( h5_err_t h5tpriv_resize_td_htab ( - h5_file_t* const f, + h5t_mesh_t* const m, size_t nel ) { - H5_PRIV_API_ENTER2 (h5_err_t, "f=0x%p, nel=%lld", f, (long long)nel); - h5t_adjacencies_t* a = &f->t->adjacencies; + H5_PRIV_API_ENTER (h5_err_t, "m=%p, nel=%lld", m, (long long)nel); + h5t_adjacencies_t* a = &m->adjacencies; if (a->td_hash.size == 0) { TRY (h5priv_hcreate ( nel, @@ -282,45 +282,43 @@ h5tpriv_resize_td_htab ( h5_err_t h5tpriv_search_td2 ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t** idlist // out ) { - H5_PRIV_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%lld, elem_idx=%lld, idlist=0x%p", - f, (long long)face_idx, (long long)elem_idx, idlist); - h5t_fdata_t* t = f->t; - h5t_adjacencies_t* a = &f->t->adjacencies; + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, face_idx=%lld, elem_idx=%lld, idlist=%p", + m, (long long)face_idx, (long long)elem_idx, idlist); + h5t_adjacencies_t* a = &m->adjacencies; void* __retval; - h5t_td_entry_t* entry; - - TRY (entry = h5_calloc (1, sizeof(*entry)) ); + static h5t_td_entry_t* entry = NULL; + if (entry == NULL) { + TRY (entry = h5_calloc (1, sizeof(*entry)) ); + } TRY (h5t_get_vertex_indices_of_triangle2 ( - f, face_idx, elem_idx, entry->key.vids) ); - /* - resize hash table if more than 3/4 filled - */ + m, face_idx, elem_idx, entry->key.vids) ); + /* resize hash table if more than 3/4 filled */ if ((a->td_hash.size*6) <= (a->td_hash.filled<<3)) { - h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; + h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; TRY (h5priv_hresize (3*(num_elems-elem_idx), &a->td_hash)); } - /* search in directory, add if entry doesn't already exists */ + /* search in hash, add if entry doesn't already exists */ TRY (h5priv_hsearch ( entry, H5_ENTER, &__retval, &a->td_hash)); + h5t_td_entry_t *td_entry = (h5t_td_entry_t *)__retval; + if (entry == td_entry) { // if used: + entry = NULL; // force allocation of new + } /* search ID in list of IDs for given triangle */ - h5t_td_entry_t *td_entry = (h5t_td_entry_t *)__retval; TRY (h5priv_search_idlist ( &td_entry->value, h5tpriv_build_triangle_id (face_idx, elem_idx))); - if (td_entry->value->num_items > 1) { - TRY (h5_free (entry)); - } if (idlist) { *idlist = td_entry->value; } @@ -329,7 +327,7 @@ h5tpriv_search_td2 ( static inline h5_err_t find_td ( - h5_file_t* const f, + h5t_mesh_t* const m, h5t_td_entry_t* item, h5_loc_idlist_t** idlist // out ) { @@ -338,7 +336,7 @@ find_td ( item, H5_FIND, &__entry, - &f->t->adjacencies.td_hash); + &m->adjacencies.td_hash); if (__entry == NULL) { return h5tpriv_error_local_triangle_nexist (item->key.vids); } @@ -349,39 +347,39 @@ find_td ( h5_err_t h5tpriv_find_td ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t triangle_id, h5_loc_idlist_t** idlist ) { - H5_PRIV_API_ENTER3 (h5_err_t, - "f=0x%p, triangle_id=%lld, idlist=0x%p", - f, (long long)triangle_id, idlist); + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, triangle_id=%lld, idlist=%p", + m, (long long)triangle_id, idlist); h5t_td_entry_t item; TRY (h5t_get_vertex_indices_of_triangle ( - f, + m, triangle_id, item.key.vids)); - TRY (find_td (f, &item, idlist)); + TRY (find_td (m, &item, idlist)); H5_PRIV_API_RETURN (H5_SUCCESS); } h5_err_t h5tpriv_find_td2 ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t** idlist ) { - H5_PRIV_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%lld, elem_idx=%lld, idlist=0x%p", - f, (long long)face_idx, (long long)elem_idx, idlist); + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, face_idx=%lld, elem_idx=%lld, idlist=%p", + m, (long long)face_idx, (long long)elem_idx, idlist); h5t_td_entry_t item; TRY (h5t_get_vertex_indices_of_triangle2 ( - f, + m, face_idx, elem_idx, item.key.vids)); - TRY (find_td (f, &item, idlist)); + TRY (find_td (m, &item, idlist)); H5_PRIV_API_RETURN (H5_SUCCESS); } @@ -390,16 +388,16 @@ h5tpriv_find_td2 ( */ h5_err_t h5tpriv_find_tv2 ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t** idlist ) { - H5_PRIV_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%lld, elem_idx=%lld, idlist=0x%p", - f, (long long)face_idx, (long long)elem_idx, idlist); + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, face_idx=%lld, elem_idx=%lld, idlist=%p", + m, (long long)face_idx, (long long)elem_idx, idlist); h5_loc_idx_t idx; - TRY (idx = h5tpriv_get_loc_elem_vertex_idx (f, elem_idx, face_idx)); - *idlist = f->t->adjacencies.tv.v[idx]; + TRY (idx = h5tpriv_get_loc_elem_vertex_idx (m, elem_idx, face_idx)); + *idlist = m->adjacencies.tv.v[idx]; H5_PRIV_API_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5t_hsearch_private.h b/src/h5core/h5t_hsearch_private.h index 20c25f2..8c66a3b 100644 --- a/src/h5core/h5t_hsearch_private.h +++ b/src/h5core/h5t_hsearch_private.h @@ -25,13 +25,13 @@ typedef struct h5_td_entry { h5_err_t h5tpriv_resize_te_htab ( - h5_file_t * const f, + h5t_mesh_t* const m, size_t nel ); h5_err_t h5tpriv_search_tv2 ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t **entry @@ -39,7 +39,7 @@ h5tpriv_search_tv2 ( h5_err_t h5tpriv_search_te2 ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t **entry @@ -47,28 +47,28 @@ h5tpriv_search_te2 ( h5_err_t h5tpriv_find_te ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idx_t edge_id, - h5_loc_idlist_t **retval + h5_loc_idlist_t** idlist ); h5_err_t h5tpriv_find_te2 ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, - h5_loc_idlist_t **retval + h5_loc_idlist_t** idlist ); h5_err_t h5tpriv_resize_td_htab ( - h5_file_t * const f, + h5t_mesh_t* const m, size_t nel ); h5_err_t h5tpriv_search_td2 ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t **entry @@ -76,14 +76,14 @@ h5tpriv_search_td2 ( h5_err_t h5tpriv_find_td ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idx_t triangle_id, h5_loc_idlist_t **retval ); h5_err_t h5tpriv_find_td2 ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t **rentry @@ -91,7 +91,7 @@ h5tpriv_find_td2 ( h5_err_t h5tpriv_find_tv2 ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t **retval diff --git a/src/h5core/h5t_inquiry.c b/src/h5core/h5t_inquiry.c index b7d9718..94694a7 100644 --- a/src/h5core/h5t_inquiry.c +++ b/src/h5core/h5t_inquiry.c @@ -14,7 +14,7 @@ get_num_meshes ( h5_file_t* const f, const char* grpname ) { - H5_PRIV_FUNC_ENTER (h5_ssize_t); + H5_PRIV_FUNC_ENTER (h5_ssize_t, "f=%p, grpname=%s", f, grpname); hid_t topo_gid = -1; hid_t meshes_gid = -1; @@ -40,7 +40,7 @@ h5_ssize_t h5t_get_num_tetmeshes ( h5_file_t* const f ) { - H5_CORE_API_ENTER1 (h5_ssize_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f); H5_CORE_API_RETURN (get_num_meshes (f, TETRAHEDRAL_MESHES_GRPNAME)); } @@ -48,7 +48,7 @@ h5_ssize_t h5t_get_num_trimeshes ( h5_file_t* const f ) { - H5_CORE_API_ENTER1 (h5_ssize_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f); H5_CORE_API_RETURN (get_num_meshes (f, TRIANGLE_MESHES_GRPNAME)); } @@ -61,13 +61,10 @@ h5t_get_num_trimeshes ( */ h5_ssize_t h5t_get_num_leaf_levels ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_ssize_t, "f=0x%p", f); - if (f->t->cur_mesh < 0) { - H5_CORE_API_LEAVE (h5tpriv_error_undef_mesh ()); - } - H5_CORE_API_RETURN (f->t->num_leaf_levels); + H5_CORE_API_ENTER (h5_ssize_t, "m=%p", m); + H5_CORE_API_RETURN (m->num_leaf_levels); } /*! @@ -79,10 +76,10 @@ h5t_get_num_leaf_levels ( */ h5t_lvl_idx_t h5t_get_level ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5t_lvl_idx_t, "f=0x%p", f); - H5_CORE_API_RETURN (f->t->leaf_level); + H5_CORE_API_ENTER (h5t_lvl_idx_t, "m=%p", m); + H5_CORE_API_RETURN (m->leaf_level); } /*! @@ -100,21 +97,17 @@ h5t_get_level ( */ h5_ssize_t h5t_get_num_elems ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_id_t cnode ) { - H5_CORE_API_ENTER2 (h5_ssize_t, - "f=0x%p, cnode=%llu", - f, (long long unsigned)cnode); + H5_CORE_API_ENTER (h5_ssize_t, "m=%p, cnode=%llu", + m, (long long unsigned)cnode); UNUSED_ARGUMENT (cnode); - if (f->t->cur_mesh < 0) { - H5_CORE_API_LEAVE (h5tpriv_error_undef_mesh ()); - } - if (f->t->leaf_level < 0) { + if (m->leaf_level < 0) { H5_CORE_API_LEAVE (h5tpriv_error_undef_level ()); } - H5_CORE_API_RETURN (f->t->num_elems_on_leaf_level[f->t->leaf_level]); + H5_CORE_API_RETURN (m->num_leaf_elems[m->leaf_level]); } /*! @@ -132,20 +125,17 @@ h5t_get_num_elems ( */ h5_ssize_t h5t_get_num_vertices ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_id_t cnode ) { - H5_CORE_API_ENTER2 (h5_ssize_t, - "f=0x%p, cnode=%llu", - f, (long long unsigned)cnode); + H5_CORE_API_ENTER (h5_ssize_t, + "m=%p, cnode=%llu", + m, (long long unsigned)cnode); UNUSED_ARGUMENT (cnode); - if (f->t->cur_mesh < 0) { - H5_CORE_API_LEAVE (h5tpriv_error_undef_mesh ()); - } - if (f->t->leaf_level < 0) { + if (m->leaf_level < 0) { H5_CORE_API_LEAVE (h5tpriv_error_undef_level ()); } - H5_CORE_API_RETURN (f->t->num_vertices[f->t->leaf_level]); + H5_CORE_API_RETURN (m->num_vertices[m->leaf_level]); } diff --git a/src/h5core/h5t_map.c b/src/h5core/h5t_map.c index 331f2d2..9dc0b00 100644 --- a/src/h5core/h5t_map.c +++ b/src/h5core/h5t_map.c @@ -32,14 +32,13 @@ cmp_vertices ( */ h5_err_t h5tpriv_sort_local_vertex_indices ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t* const indices, /* IN/OUT: local vertex indices */ const h5_size_t size /* size of array */ ) { - H5_PRIV_API_ENTER3 (h5_err_t, - "f=0x%p, indices=0x%p, size=%llu", - f, indices, (long long unsigned)size); - h5t_fdata_t* t = f->t; + H5_PRIV_API_ENTER (h5_err_t, + "m=%p, indices=%p, size=%llu", + m, indices, (long long unsigned)size); h5_size_t i; for (i = 1; i < size; ++i) { @@ -47,8 +46,8 @@ h5tpriv_sort_local_vertex_indices ( h5_size_t j = i; while ((j >= 1 ) && cmp_vertices ( - t->vertices[idx].P, - t->vertices[indices[j-1]].P + m->vertices[idx].P, + m->vertices[indices[j-1]].P ) < 0 ) { indices[j] = indices[j-1]; --j; @@ -63,15 +62,13 @@ h5tpriv_sort_local_vertex_indices ( */ h5_loc_idx_t h5t_map_global_vertex_idx2local ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_glb_idx_t glb_idx ) { - H5_CORE_API_ENTER2 (h5_loc_idx_t, - "f=0x%p, glb_idx=%lld", - f, (long long)glb_idx); + H5_CORE_API_ENTER (h5_loc_idx_t, "m=%p, glb_idx=%lld", m, (long long)glb_idx); if (glb_idx < 0) return -1; - h5_loc_idx_t loc_idx = h5priv_search_idxmap (&f->t->map_vertex_g2l, glb_idx); + h5_loc_idx_t loc_idx = h5priv_search_idxmap (&m->map_vertex_g2l, glb_idx); if (loc_idx < 0) { H5_CORE_API_LEAVE (h5tpriv_error_global_id_nexist ("vertex", glb_idx)); } @@ -80,18 +77,18 @@ h5t_map_global_vertex_idx2local ( h5_err_t h5t_map_global_vertex_indices2local ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_glb_idx_t* const glb_indices, const h5_size_t size, h5_loc_idx_t* const loc_indices ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, glb_indices=0x%p, size=%llu, loc_indices=0x%p", - f, glb_indices, (long long unsigned)size, loc_indices); + H5_CORE_API_ENTER (h5_err_t, + "m=%p, glb_indices=%p, size=%llu, loc_indices=%p", + m, glb_indices, (long long unsigned)size, loc_indices); h5_size_t i; for (i = 0; i < size; i++) { TRY (loc_indices[i] = - h5t_map_global_vertex_idx2local (f, glb_indices[i])); + h5t_map_global_vertex_idx2local (m, glb_indices[i])); } H5_CORE_API_RETURN (H5_SUCCESS); } @@ -106,15 +103,15 @@ h5t_map_global_vertex_indices2local ( */ h5_loc_idx_t h5t_map_glb_elem_idx2loc ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_glb_idx_t glb_idx ) { - H5_CORE_API_ENTER2 (h5_loc_idx_t, - "f=0x%p, glb_idx=%lld", - f, (long long)glb_idx); + H5_CORE_API_ENTER (h5_loc_idx_t, + "m=%p, glb_idx=%lld", + m, (long long)glb_idx); if (glb_idx < 0) H5_CORE_API_LEAVE (-1); - h5_loc_idx_t loc_idx = h5priv_search_idxmap (&f->t->map_elem_g2l, glb_idx); + h5_loc_idx_t loc_idx = h5priv_search_idxmap (&m->map_elem_g2l, glb_idx); if (loc_idx < 0) H5_CORE_API_LEAVE (h5tpriv_error_global_id_nexist ("elem", glb_idx)); H5_CORE_API_RETURN (loc_idx); @@ -122,19 +119,19 @@ h5t_map_glb_elem_idx2loc ( h5_err_t h5t_map_glb_elem_indices2loc ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_glb_idx_t* glb_indices, const h5_size_t size, h5_loc_idx_t* loc_indices ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, glb_indices=0x%p, size=%llu, loc_indices=0x%p", - f, glb_indices, (long long unsigned)size, loc_indices); + H5_CORE_API_ENTER (h5_err_t, + "m=%p, glb_indices=%p, size=%llu, loc_indices=%p", + m, glb_indices, (long long unsigned)size, loc_indices); const h5_glb_idx_t* end = glb_indices+size; while (glb_indices < end) { TRY (*loc_indices = - h5t_map_glb_elem_idx2loc (f, *glb_indices)); + h5t_map_glb_elem_idx2loc (m, *glb_indices)); loc_indices++; glb_indices++; } @@ -147,22 +144,21 @@ h5t_map_glb_elem_indices2loc ( */ h5_err_t h5tpriv_rebuild_vertex_indices_mapping ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_loc_idx_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - if (t->num_leaf_levels <= 0) H5_PRIV_API_LEAVE (H5_SUCCESS); + H5_CORE_API_ENTER (h5_loc_idx_t, "m=%p", m); + if (m->num_leaf_levels <= 0) H5_PRIV_API_LEAVE (H5_SUCCESS); - h5_loc_idx_t loc_idx = t->leaf_level > 0 ? t->num_vertices[t->leaf_level-1] : 0; - h5_loc_idx_t num_loc_vertices = t->num_vertices[t->num_leaf_levels-1]; - h5_idxmap_el_t *item = &t->map_vertex_g2l.items[loc_idx]; + h5_loc_idx_t loc_idx = m->leaf_level > 0 ? m->num_vertices[m->leaf_level-1] : 0; + h5_loc_idx_t num_loc_vertices = m->num_vertices[m->num_leaf_levels-1]; + h5_idxmap_el_t *item = &m->map_vertex_g2l.items[loc_idx]; for (; loc_idx < num_loc_vertices; loc_idx++, item++) { - item->glb_idx = t->vertices[loc_idx].idx; + item->glb_idx = m->vertices[loc_idx].idx; item->loc_idx = loc_idx; - t->map_vertex_g2l.num_items++; + m->map_vertex_g2l.num_items++; } - h5priv_sort_idxmap (&t->map_vertex_g2l); + h5priv_sort_idxmap (&m->map_vertex_g2l); H5_PRIV_API_RETURN (H5_SUCCESS); } @@ -171,22 +167,21 @@ h5tpriv_rebuild_vertex_indices_mapping ( */ h5_err_t h5tpriv_rebuild_elem_indices_mapping ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_loc_idx_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - if (t->num_leaf_levels <= 0) H5_PRIV_API_LEAVE (H5_SUCCESS); + H5_CORE_API_ENTER (h5_loc_idx_t, "m=%p", m); + if (m->num_leaf_levels <= 0) H5_PRIV_API_LEAVE (H5_SUCCESS); - h5_loc_idx_t loc_idx = t->leaf_level > 0 ? t->num_elems[t->leaf_level-1] : 0; - h5_loc_idx_t num_loc_elems = t->num_elems[t->num_leaf_levels-1]; - h5_idxmap_el_t *item = &t->map_elem_g2l.items[loc_idx]; + h5_loc_idx_t loc_idx = m->leaf_level > 0 ? m->num_elems[m->leaf_level-1] : 0; + h5_loc_idx_t num_loc_elems = m->num_elems[m->num_leaf_levels-1]; + h5_idxmap_el_t *item = &m->map_elem_g2l.items[loc_idx]; for (; loc_idx < num_loc_elems; loc_idx++, item++) { - item->glb_idx = h5tpriv_get_loc_elem_glb_idx (f, loc_idx); + item->glb_idx = h5tpriv_get_loc_elem_glb_idx (m, loc_idx); item->loc_idx = loc_idx; - t->map_elem_g2l.num_items++; + m->map_elem_g2l.num_items++; } - h5priv_sort_idxmap (&t->map_elem_g2l); + h5priv_sort_idxmap (&m->map_elem_g2l); H5_PRIV_API_RETURN (H5_SUCCESS); } @@ -195,15 +190,15 @@ h5tpriv_rebuild_elem_indices_mapping ( */ h5_err_t h5t_get_vertex_indices_of_entity ( - h5_file_t* const f, // in + h5t_mesh_t* const m, // in const h5_loc_id_t entity_id, // in h5_loc_idx_t* vertex_indices // out ) { - H5_CORE_API_ENTER3 (h5_loc_idx_t, - "f=0x%p, entity_id=%llu, vertex_indices=0x%p", - f, - (long long unsigned)entity_id, - vertex_indices); + H5_CORE_API_ENTER (h5_loc_idx_t, + "m=%p, entity_id=%llu, vertex_indices=%p", + m, + (long long unsigned)entity_id, + vertex_indices); h5_loc_idx_t type = h5tpriv_get_entity_type (entity_id); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); @@ -216,7 +211,7 @@ h5t_get_vertex_indices_of_entity ( default: H5_CORE_API_LEAVE (h5_error_internal ()); } - H5_CORE_API_RETURN (h5t_get_vertex_indices_of_entity2 (f, dim, face_idx, elem_idx, vertex_indices)); + H5_CORE_API_RETURN (h5t_get_vertex_indices_of_entity2 (m, dim, face_idx, elem_idx, vertex_indices)); } /* @@ -224,24 +219,24 @@ h5t_get_vertex_indices_of_entity ( */ h5_err_t h5t_get_vertex_indices_of_entity2 ( - h5_file_t* const f, // [in] + h5t_mesh_t* const m, // [in] const int dim, // [in] dimension const h5_loc_idx_t face_idx, // [in] vertex index according ref. element const h5_loc_idx_t elem_idx, // [in] local element index h5_loc_idx_t* vertex_indices // [out] ) { - H5_CORE_API_ENTER5 (h5_err_t, - "f=0x%p, dim=%d, face_idx=%llu, elem_idx=%llu, vertex_indices=0x%p", - f, dim, - (long long unsigned)face_idx, - (long long unsigned)elem_idx, - vertex_indices); - h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices (f, elem_idx); - const h5t_ref_elem_t* ref_elem = f->t->ref_elem; + H5_CORE_API_ENTER (h5_err_t, + "m=%p, dim=%d, face_idx=%llu, elem_idx=%llu, vertex_indices=%p", + m, dim, + (long long unsigned)face_idx, + (long long unsigned)elem_idx, + vertex_indices); + h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices (m, elem_idx); + const h5t_ref_elem_t* ref_elem = m->ref_elem; int num_vertices = ref_elem->num_vertices_of_face[dim][face_idx]; int i; for (i = 0; i < num_vertices; i++) { - int idx = h5tpriv_ref_elem_get_vertex_idx(f->t, dim, face_idx, i); + int idx = h5tpriv_ref_elem_get_vertex_idx(m, dim, face_idx, i); vertex_indices[i] = indices[idx]; } H5_CORE_API_RETURN (H5_SUCCESS); @@ -249,35 +244,35 @@ h5t_get_vertex_indices_of_entity2 ( h5_err_t h5t_get_vertex_index_of_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idx_t* vertex_index ) { - H5_CORE_API_ENTER3 (h5_loc_idx_t, - "f=0x%p, entity_id=%llu, vertex_index=%llu", - f, - (long long unsigned)entity_id, - (long long unsigned)*vertex_index); + H5_CORE_API_ENTER (h5_loc_idx_t, + "m=%p, entity_id=%llu, vertex_index=%llu", + m, + (long long unsigned)entity_id, + (long long unsigned)*vertex_index); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); H5_CORE_API_RETURN (h5t_get_vertex_index_of_vertex2 ( - f, face_idx, elem_idx, vertex_index)); + m, face_idx, elem_idx, vertex_index)); } h5_err_t h5t_get_vertex_index_of_vertex2 ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t face_idx, // vertex index according ref. element const h5_loc_idx_t elem_idx, // local element index h5_loc_idx_t* vertex_indices // OUT: vertex ID's ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%llu, elem_idx=%llu, vertex_indices=0x%p", - f, - (long long unsigned)face_idx, - (long long unsigned)elem_idx, - vertex_indices); - vertex_indices[0] = h5tpriv_get_loc_elem_vertex_idx (f, elem_idx, face_idx); + H5_CORE_API_ENTER (h5_err_t, + "m=%p, face_idx=%llu, elem_idx=%llu, vertex_indices=%p", + m, + (long long unsigned)face_idx, + (long long unsigned)elem_idx, + vertex_indices); + vertex_indices[0] = h5tpriv_get_loc_elem_vertex_idx (m, elem_idx, face_idx); H5_CORE_API_RETURN (H5_SUCCESS); } @@ -286,19 +281,19 @@ h5t_get_vertex_index_of_vertex2 ( */ h5_err_t h5t_get_vertex_indices_of_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idx_t* vertex_indices ) { - H5_CORE_API_ENTER3 (h5_loc_idx_t, - "f=0x%p, entity_id=%llu, vertex_indices=0x%p", - f, - (long long unsigned)entity_id, - vertex_indices); + H5_CORE_API_ENTER (h5_loc_idx_t, + "m=%p, entity_id=%llu, vertex_indices=%p", + m, + (long long unsigned)entity_id, + vertex_indices); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); H5_CORE_API_RETURN (h5t_get_vertex_indices_of_edge2 ( - f, face_idx, elem_idx, vertex_indices)); + m, face_idx, elem_idx, vertex_indices)); } /*! @@ -310,93 +305,93 @@ h5t_get_vertex_indices_of_edge ( */ h5_err_t h5t_get_vertex_indices_of_edge2 ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t face_idx, // edge index according ref. element const h5_loc_idx_t elem_idx, // local element index h5_loc_idx_t* vertex_indices // OUT: vertex indices ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%llu, elem_idx=%llu, vertex_indices=0x%p", - f, - (long long unsigned)face_idx, - (long long unsigned)elem_idx, - vertex_indices); - const h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices (f, elem_idx); + H5_CORE_API_ENTER (h5_err_t, + "m=%p, face_idx=%llu, elem_idx=%llu, vertex_indices=%p", + m, + (long long unsigned)face_idx, + (long long unsigned)elem_idx, + vertex_indices); + const h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices (m, elem_idx); h5_loc_idx_t idx; - idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 1, face_idx, 0); + idx = h5tpriv_ref_elem_get_vertex_idx (m, 1, face_idx, 0); vertex_indices[0] = indices[idx]; - idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 1, face_idx, 1); + idx = h5tpriv_ref_elem_get_vertex_idx (m, 1, face_idx, 1); vertex_indices[1] = indices[idx]; H5_CORE_API_RETURN (H5_SUCCESS); } h5_err_t h5t_get_vertex_indices_of_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idx_t* vertex_indices ) { - H5_CORE_API_ENTER3 (h5_loc_idx_t, - "f=0x%p, entity_id=%llu, vertex_indices=0x%p", - f, - (long long unsigned)entity_id, - vertex_indices); + H5_CORE_API_ENTER (h5_loc_idx_t, + "m=%p, entity_id=%llu, vertex_indices=%p", + m, + (long long unsigned)entity_id, + vertex_indices); h5_loc_idx_t face_idx = h5tpriv_get_face_idx (entity_id); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); H5_CORE_API_RETURN (h5t_get_vertex_indices_of_triangle2 ( - f, face_idx, elem_idx, vertex_indices)); + m, face_idx, elem_idx, vertex_indices)); } h5_err_t h5t_get_vertex_indices_of_triangle2 ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t face_idx, const h5_loc_idx_t elem_idx, h5_loc_idx_t* vertex_indices ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, face_idx=%llu, elem_idx=%llu, vertex_indices=0x%p", - f, - (long long unsigned)face_idx, - (long long unsigned)elem_idx, - vertex_indices); - const h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices (f, elem_idx); + H5_CORE_API_ENTER (h5_err_t, + "m=%p, face_idx=%llu, elem_idx=%llu, vertex_indices=%p", + m, + (long long unsigned)face_idx, + (long long unsigned)elem_idx, + vertex_indices); + const h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices (m, elem_idx); h5_loc_idx_t idx; - idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 2, face_idx, 0); + idx = h5tpriv_ref_elem_get_vertex_idx (m, 2, face_idx, 0); vertex_indices[0] = indices[idx]; - idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 2, face_idx, 1); + idx = h5tpriv_ref_elem_get_vertex_idx (m, 2, face_idx, 1); vertex_indices[1] = indices[idx]; - idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 2, face_idx, 2); + idx = h5tpriv_ref_elem_get_vertex_idx (m, 2, face_idx, 2); vertex_indices[2] = indices[idx]; H5_CORE_API_RETURN (H5_SUCCESS); } h5_err_t h5t_get_vertex_indices_of_tet ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idx_t* vertex_indices ) { - H5_CORE_API_ENTER3 (h5_loc_idx_t, - "f=0x%p, entity_id=%llu, vertex_indices=0x%p", - f, - (long long unsigned)entity_id, - vertex_indices); + H5_CORE_API_ENTER (h5_loc_idx_t, + "m=%p, entity_id=%llu, vertex_indices=%p", + m, + (long long unsigned)entity_id, + vertex_indices); const h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); const h5_loc_idx_t* indices = h5tpriv_get_loc_elem_vertex_indices ( - f, elem_idx); + m, elem_idx); h5_loc_idx_t idx; - idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 3, 0, 0); + idx = h5tpriv_ref_elem_get_vertex_idx (m, 3, 0, 0); vertex_indices[0] = indices[idx]; - idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 3, 0, 1); + idx = h5tpriv_ref_elem_get_vertex_idx (m, 3, 0, 1); vertex_indices[1] = indices[idx]; - idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 3, 0, 2); + idx = h5tpriv_ref_elem_get_vertex_idx (m, 3, 0, 2); vertex_indices[2] = indices[idx]; - idx = h5tpriv_ref_elem_get_vertex_idx (f->t, 3, 0, 3); + idx = h5tpriv_ref_elem_get_vertex_idx (m, 3, 0, 3); vertex_indices[3] = indices[idx]; H5_CORE_API_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5t_map_private.h b/src/h5core/h5t_map_private.h index d4b60f0..23230f9 100644 --- a/src/h5core/h5t_map_private.h +++ b/src/h5core/h5t_map_private.h @@ -3,25 +3,25 @@ h5_err_t h5tpriv_sort_local_vertex_indices ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idx_t * const indices, const h5_size_t size ); h5_loc_idx_t h5tpriv_get_local_vid ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_float64_t P[3] ); h5_err_t h5tpriv_rebuild_vertex_indices_mapping ( - h5_file_t * const f + h5t_mesh_t* const m ); h5_err_t h5tpriv_rebuild_elem_indices_mapping ( - h5_file_t * const f + h5t_mesh_t* const m ); #endif diff --git a/src/h5core/h5t_model.c b/src/h5core/h5t_model.c index 4435c6f..c79ee3c 100644 --- a/src/h5core/h5t_model.c +++ b/src/h5core/h5t_model.c @@ -8,11 +8,10 @@ */ static inline h5_err_t create_array_types ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; - h5_dtypes_t* dtypes = &(t->dtypes); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + h5_dtypes_t* dtypes = &(m->dtypes); hsize_t dims[1] = { 3 }; TRY( @@ -40,10 +39,10 @@ create_array_types ( static inline h5_err_t create_vertex_type ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5_dtypes_t* dtypes = &f->t->dtypes; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + h5_dtypes_t* dtypes = &m->dtypes; TRY( dtypes->h5_vertex_t = hdf5_create_type ( @@ -67,10 +66,10 @@ create_vertex_type ( static inline h5_err_t create_triangle_type ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5_dtypes_t* dtypes = &f->t->dtypes; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + h5_dtypes_t* dtypes = &m->dtypes; TRY( dtypes->h5_triangle_t = hdf5_create_type ( @@ -112,10 +111,10 @@ create_triangle_type ( static inline h5_err_t create_tag_types ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5_dtypes_t* dtypes = &f->t->dtypes; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + h5_dtypes_t* dtypes = &m->dtypes; TRY ( dtypes->h5t_glb_tag_idx_t = hdf5_create_type ( @@ -139,10 +138,10 @@ create_tag_types ( static inline h5_err_t create_tet_type ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5_dtypes_t* dtypes = &f->t->dtypes; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + h5_dtypes_t* dtypes = &m->dtypes; TRY( dtypes->h5_tet_t = hdf5_create_type ( @@ -182,115 +181,6 @@ create_tet_type ( H5_PRIV_FUNC_RETURN (H5_SUCCESS); } -static h5_err_t -init_fdata ( - h5_file_t* const f - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; - - memset (t->mesh_name, 0, sizeof (t->mesh_name)); - t->mesh_type = 0; - t->ref_elem = NULL; - t->cur_mesh = -1; - t->mesh_changed = 0; - t->num_meshes = -1; - t->num_leaf_levels = -1; - t->leaf_level = -1; - t->last_stored_vid = -1; - t->last_stored_eid = -1; - t->topo_gid = -1; - t->meshes_gid = -1; - t->mesh_gid = -1; - - /* initialize pointers */ - t->glb_elems.data = NULL; - t->loc_elems.data = NULL; - t->num_elems = NULL; - t->num_elems_on_leaf_level = NULL; - t->map_elem_g2l.items = NULL; - t->vertices = NULL; - t->num_vertices = NULL; - t->map_vertex_g2l.items = NULL; - t->mtags.names = NULL; - - /* vertices */ - strcpy (t->dsinfo_vertices.name, "Vertices"); - t->dsinfo_vertices.rank = 1; - t->dsinfo_vertices.dims[0] = 0; - t->dsinfo_vertices.max_dims[0] = H5S_UNLIMITED; - t->dsinfo_vertices.chunk_dims[0] = 4096; - t->dsinfo_vertices.type_id = t->dtypes.h5_vertex_t; - TRY (t->dsinfo_vertices.create_prop = hdf5_create_property ( - H5P_DATASET_CREATE) ); - TRY (hdf5_set_chunk_property ( - t->dsinfo_vertices.create_prop, - t->dsinfo_vertices.rank, - t->dsinfo_vertices.chunk_dims) ); - t->dsinfo_vertices.access_prop = H5P_DEFAULT; - - /* NumVertices */ - strcpy (t->dsinfo_num_vertices.name, "NumVertices"); - t->dsinfo_num_vertices.rank = 1; - t->dsinfo_num_vertices.dims[0] = 0; - t->dsinfo_num_vertices.max_dims[0] = H5S_UNLIMITED; - t->dsinfo_num_vertices.chunk_dims[0] = 4096; - t->dsinfo_num_vertices.type_id = t->dtypes.h5_glb_idx_t; - TRY (t->dsinfo_num_vertices.create_prop = hdf5_create_property ( - H5P_DATASET_CREATE) ); - TRY (hdf5_set_chunk_property ( - t->dsinfo_num_vertices.create_prop, - t->dsinfo_num_vertices.rank, - t->dsinfo_num_vertices.chunk_dims) ); - t->dsinfo_num_vertices.access_prop = H5P_DEFAULT; - - /* Elems */ - strcpy (t->dsinfo_elems.name, "Elems"); - t->dsinfo_elems.rank = 1; - t->dsinfo_elems.dims[0] = 0; - t->dsinfo_elems.max_dims[0] = H5S_UNLIMITED; - t->dsinfo_elems.chunk_dims[0] = 4096; - TRY (t->dsinfo_elems.create_prop = hdf5_create_property ( - H5P_DATASET_CREATE) ); - TRY (hdf5_set_chunk_property ( - t->dsinfo_elems.create_prop, - t->dsinfo_elems.rank, - t->dsinfo_elems.chunk_dims) ); - t->dsinfo_elems.access_prop = H5P_DEFAULT; - - /* NumElems */ - strcpy (t->dsinfo_num_elems.name, "NumElems"); - t->dsinfo_num_elems.rank = 1; - t->dsinfo_num_elems.dims[0] = 0; - t->dsinfo_num_elems.max_dims[0] = H5S_UNLIMITED; - t->dsinfo_num_elems.chunk_dims[0] = 4096; - t->dsinfo_num_elems.type_id = t->dtypes.h5_glb_idx_t; - TRY (t->dsinfo_num_elems.create_prop = hdf5_create_property ( - H5P_DATASET_CREATE) ); - TRY( hdf5_set_chunk_property ( - t->dsinfo_num_elems.create_prop, - t->dsinfo_num_elems.rank, - t->dsinfo_num_elems.chunk_dims) ); - t->dsinfo_num_elems.access_prop = H5P_DEFAULT; - - /* NumElemsOnLevel */ - strcpy (t->dsinfo_num_elems_on_leaf_level.name, "NumElemsOnLeafLevel"); - t->dsinfo_num_elems_on_leaf_level.rank = 1; - t->dsinfo_num_elems_on_leaf_level.dims[0] = 0; - t->dsinfo_num_elems_on_leaf_level.max_dims[0] = H5S_UNLIMITED; - t->dsinfo_num_elems_on_leaf_level.chunk_dims[0] = 4096; - t->dsinfo_num_elems_on_leaf_level.type_id = t->dtypes.h5_glb_idx_t; - TRY( t->dsinfo_num_elems_on_leaf_level.create_prop = hdf5_create_property ( - H5P_DATASET_CREATE) ); - TRY( hdf5_set_chunk_property ( - t->dsinfo_num_elems_on_leaf_level.create_prop, - t->dsinfo_num_elems_on_leaf_level.rank, - t->dsinfo_num_elems_on_leaf_level.chunk_dims) ); - t->dsinfo_num_elems_on_leaf_level.access_prop = H5P_DEFAULT; - - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - /*! \ingroup h5_private @@ -302,132 +192,164 @@ init_fdata ( \return H5_SUCCESS or error code */ h5_err_t -h5tpriv_open_file ( - h5_file_t* const f /*!< IN: file handle */ +h5tpriv_init_mesh ( + h5t_mesh_t* const m, + h5_file_t* const f, + const char* name, + const hid_t mesh_hid ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); - TRY (f->t = h5_calloc (1, sizeof (*f->t))); - h5t_fdata_t* t = f->t; + H5_PRIV_API_ENTER (h5_err_t, "m=%p", m); - t->dtypes.h5_glb_idx_t = H5_INT64_T; - t->dtypes.h5_int64_t = H5_INT64_T; - t->dtypes.h5_float64_t = H5_FLOAT64_T; + m->f = f; + strncpy (m->mesh_name, name, sizeof (m->mesh_name)-1); + m->mesh_name[sizeof(m->mesh_name)-1] = '\0'; + m->mesh_gid = mesh_hid; - TRY (create_array_types (f)); - TRY (create_vertex_type (f)); - TRY (create_triangle_type (f)); - TRY (create_tet_type (f)); - TRY (create_tag_types (f)); - TRY (init_fdata (f)); - H5_PRIV_API_RETURN (H5_SUCCESS); -} -h5_err_t -h5tpriv_init_step ( - h5_file_t* const f - ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); - UNUSED_ARGUMENT (f); - H5_PRIV_API_RETURN (H5_SUCCESS); -} + m->dtypes.h5_glb_idx_t = H5_INT64_T; + m->dtypes.h5_int64_t = H5_INT64_T; + m->dtypes.h5_float64_t = H5_FLOAT64_T; -/* - - write data - - close HDF5 objects we cannot reuse - - free memory -*/ -h5_err_t -h5tpriv_close_step ( - h5_file_t* const f - ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); - UNUSED_ARGUMENT (f); - H5_PRIV_API_RETURN (H5_SUCCESS); + TRY (create_array_types (m)); + TRY (create_vertex_type (m)); + TRY (create_triangle_type (m)); + TRY (create_tet_type (m)); + TRY (create_tag_types (m)); + + m->ref_elem = NULL; + m->mesh_changed = 0; + m->num_leaf_levels = -1; + m->leaf_level = -1; + m->last_stored_vid = -1; + m->last_stored_eid = -1; + + + /* initialize pointers */ + m->glb_elems.data = NULL; + m->loc_elems.data = NULL; + m->num_elems = NULL; + m->num_leaf_elems = NULL; + m->map_elem_g2l.items = NULL; + m->vertices = NULL; + m->num_vertices = NULL; + m->map_vertex_g2l.items = NULL; + + /* vertices */ + strcpy (m->dsinfo_vertices.name, "Vertices"); + m->dsinfo_vertices.rank = 1; + m->dsinfo_vertices.dims[0] = 0; + m->dsinfo_vertices.max_dims[0] = H5S_UNLIMITED; + m->dsinfo_vertices.chunk_dims[0] = 4096; + m->dsinfo_vertices.type_id = m->dtypes.h5_vertex_t; + TRY (m->dsinfo_vertices.create_prop = hdf5_create_property ( + H5P_DATASET_CREATE) ); + TRY (hdf5_set_chunk_property ( + m->dsinfo_vertices.create_prop, + m->dsinfo_vertices.rank, + m->dsinfo_vertices.chunk_dims) ); + m->dsinfo_vertices.access_prop = H5P_DEFAULT; + + /* Elems */ + strcpy (m->dsinfo_elems.name, "Elems"); + m->dsinfo_elems.rank = 1; + m->dsinfo_elems.dims[0] = 0; + m->dsinfo_elems.max_dims[0] = H5S_UNLIMITED; + m->dsinfo_elems.chunk_dims[0] = 4096; + TRY (m->dsinfo_elems.create_prop = hdf5_create_property ( + H5P_DATASET_CREATE) ); + TRY (hdf5_set_chunk_property ( + m->dsinfo_elems.create_prop, + m->dsinfo_elems.rank, + m->dsinfo_elems.chunk_dims) ); + m->dsinfo_elems.access_prop = H5P_DEFAULT; + + H5_PRIV_FUNC_RETURN (H5_SUCCESS); } /* Open HDF5 group with specific mesh */ - static h5_err_t release_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - TRY( h5_free (t->loc_elems.data) ); - t->loc_elems.data = NULL; - TRY( h5_free (t->num_elems) ); - t->num_elems = NULL; - TRY( h5_free (t->num_elems_on_leaf_level) ); - t->num_elems_on_leaf_level = NULL; - TRY( h5_free (t->map_elem_g2l.items) ); - t->map_elem_g2l.items = NULL; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + TRY( h5_free (m->loc_elems.data) ); + m->loc_elems.data = NULL; + TRY( h5_free (m->num_elems) ); + m->num_elems = NULL; + TRY( h5_free (m->num_leaf_elems) ); + m->num_leaf_elems = NULL; + TRY( h5_free (m->map_elem_g2l.items) ); + m->map_elem_g2l.items = NULL; H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static h5_err_t release_vertices ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - TRY( h5_free (t->vertices) ); - t->vertices = NULL; - TRY( h5_free (t->num_vertices) ); - t->num_vertices = NULL; - TRY( h5_free (t->map_vertex_g2l.items) ); - t->map_vertex_g2l.items = NULL; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + TRY( h5_free (m->vertices) ); + m->vertices = NULL; + TRY( h5_free (m->num_vertices) ); + m->num_vertices = NULL; + TRY( h5_free (m->map_vertex_g2l.items) ); + m->map_vertex_g2l.items = NULL; H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static h5_err_t release_memory ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER1 (h5_err_t, "f=0x%p", f); - TRY( h5tpriv_release_tags (f) ); - TRY( h5tpriv_release_adjacency_structs (f) ); - TRY( release_elems (f) ); - TRY( release_vertices (f) ); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + TRY (h5tpriv_release_adjacency_structs (m)); + TRY (release_elems (m)); + TRY (release_vertices (m)); + TRY (h5_free (m)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } h5_err_t h5t_close_mesh ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - if (!(f->mode & H5_O_RDONLY)) { - TRY (h5tpriv_write_mesh (f)); - } - TRY (hdf5_close_group (f->t->mesh_gid)); - TRY (hdf5_close_group (f->t->meshes_gid)); - TRY (hdf5_close_group (f->t->topo_gid)); + H5_CORE_API_ENTER (h5_err_t, "m=%p", m); - TRY (release_memory (f)); - TRY (init_fdata (f)); + // check if tagsets are still open + if (m->mtagsets && m->mtagsets->num_items > 0) + H5_CORE_API_LEAVE ( + h5_error ( + H5_ERR_H5FED, + "Mesh cannot be closed: Mesh is referenced by open tagsets")); + + if (!(m->f->mode & H5_O_RDONLY)) { + TRY (h5tpriv_write_mesh (m)); + } + TRY (hdf5_close_group (m->mesh_gid)); + + TRY (release_memory (m)); H5_CORE_API_RETURN (H5_SUCCESS); } h5_err_t h5t_set_level ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t level_id ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, level_id=%d", f, level_id); - h5t_fdata_t* t = f->t; + H5_CORE_API_ENTER (h5_err_t, "m=%p, level_id=%d", m, level_id); - if ((level_id < 0) || (level_id >= t->num_leaf_levels)) + if ((level_id < 0) || (level_id >= m->num_leaf_levels)) H5_CORE_API_LEAVE (HANDLE_H5_OUT_OF_RANGE_ERR ("Level", level_id)); - h5t_lvl_idx_t prev_level = t->leaf_level; - t->leaf_level = level_id; + h5t_lvl_idx_t prev_level = m->leaf_level; + m->leaf_level = level_id; - if (level_id >= t->num_loaded_levels) { - TRY (h5tpriv_update_adjacency_structs (f, ++prev_level)); + if (level_id >= m->num_loaded_levels) { + TRY (h5tpriv_update_adjacency_structs (m, ++prev_level)); } H5_CORE_API_RETURN (H5_SUCCESS); } @@ -437,36 +359,15 @@ h5t_set_level ( */ h5_err_t h5tpriv_alloc_num_vertices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_size_t num ) { - H5_PRIV_FUNC_ENTER2 (h5_err_t, - "f=0x%p, num=%llu", - f, + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, num=%llu", + m, (long long unsigned)num); - h5t_fdata_t* t = f->t; - ssize_t size = num * sizeof (t->vertices[0]); - TRY (t->vertices = h5_alloc (t->vertices, size)); - TRY (h5priv_alloc_idxmap (&t->map_vertex_g2l, num)); - H5_PRIV_API_RETURN (H5_SUCCESS); -} - -/*! - \ingroup h5_private - - \internal - - De-initialize topological internal structure. Open HDF5 objects are - closed and allocated memory freed. - - \return H5_SUCCESS or error code -*/ -h5_err_t -h5tpriv_close_file ( - h5_file_t* const f /*!< IN: file handle */ - ) { - H5_PRIV_FUNC_ENTER1 (h5_err_t, "f=0x%p", f); - TRY (h5t_close_mesh (f)); - TRY (hdf5_close_group (f->t->meshes_gid)); + ssize_t size = num * sizeof (m->vertices[0]); + TRY (m->vertices = h5_alloc (m->vertices, size)); + TRY (h5priv_alloc_idxmap (&m->map_vertex_g2l, num)); H5_PRIV_API_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5t_model_private.h b/src/h5core/h5t_model_private.h index e7b2ccb..acea2c5 100644 --- a/src/h5core/h5t_model_private.h +++ b/src/h5core/h5t_model_private.h @@ -1,42 +1,9 @@ #ifndef __H5T_MODEL_PRIVATE_H #define __H5T_MODEL_PRIVATE_H -h5_err_t -h5tpriv_open_file ( - h5_file_t * const f - ); -h5_err_t -h5tpriv_close_file ( - h5_file_t * const f - ); -h5_err_t -h5tpriv_close_step ( - h5_file_t * const f - ); -h5_err_t -h5tpriv_init_fdata ( - h5_file_t * const f - ); -h5_err_t -h5tpriv_init_step ( - h5_file_t * const f - ); -h5_err_t -h5tpriv_alloc_num_vertices ( - h5_file_t * const f, - const h5_size_t num_vertices - ); -h5_err_t -h5tpriv_alloc_tris ( - h5_file_t * const f, - const size_t cur, - const size_t new_size - ); -h5_err_t -h5tpriv_alloc_tets ( - h5_file_t * const f, - const size_t cur, - const size_t new_size - ); +h5_err_t h5tpriv_alloc_num_vertices (h5t_mesh_t* const, const h5_size_t); +h5_err_t h5tpriv_alloc_tris (h5t_mesh_t* const, const size_t, const size_t); +h5_err_t h5tpriv_alloc_tets (h5t_mesh_t* const, const size_t, const size_t); +h5_err_t h5tpriv_init_mesh (h5t_mesh_t* const, h5_file_t* const, const char*, const hid_t); -#endif +#endif \ No newline at end of file diff --git a/src/h5core/h5t_model_tetm.c b/src/h5core/h5t_model_tetm.c index ad563e0..82d4bc2 100644 --- a/src/h5core/h5t_model_tetm.c +++ b/src/h5core/h5t_model_tetm.c @@ -1,3 +1,4 @@ +#include #include "h5core/h5_core.h" #include "h5_core_private.h" @@ -9,83 +10,60 @@ static struct h5t_methods tet_funcs = { &h5tpriv_tetm_adjacency_methods }; -static inline h5_err_t -open_tetmeshes_group ( - h5_file_t* const f - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; - - if (t->topo_gid == 0 || t->topo_gid == -1) { - TRY (t->topo_gid = h5priv_open_group ( - f, f->root_gid, H5T_CONTAINER_GRPNAME)); - } - TRY (t->meshes_gid = h5priv_open_group ( - f, - t->topo_gid, - TETRAHEDRAL_MESHES_GRPNAME)); - t->mesh_type = H5_OID_TETRAHEDRON; - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - -static inline h5_err_t -open_tetmesh_group ( - h5_file_t* const f, - const h5_id_t id - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; - - if (t->meshes_gid < 0) { - TRY (open_tetmeshes_group (f)); - } - snprintf (t->mesh_name, sizeof (t->mesh_name), "%lld", (long long)id); - - TRY (t->mesh_gid = h5priv_open_group ( - f, - t->meshes_gid, - t->mesh_name)); - t->cur_mesh = id; - H5_PRIV_API_RETURN (H5_SUCCESS); -} - /* - If the value of parameter \c id is \c -1, a new mesh will be appended. + open tetrahedral mesh */ +h5_err_t +h5t_open_tetrahedral_mesh_by_idx ( + h5_file_t* const f, + const h5_id_t idx, + h5t_mesh_t** mesh + ) { + H5_CORE_API_ENTER (h5_err_t, "f=%p, idx=%lld, mesh=%p", f, (long long)idx, mesh); + hid_t ctn_hid; + char name[1024]; + + TRY (ctn_hid = h5priv_open_group ( + 0, + f->root_gid, + H5T_CONTAINER_GRPNAME, + TETRAHEDRAL_MESHES_GRPNAME)); + TRY (hdf5_get_name_of_group_by_idx (ctn_hid, idx, name, sizeof (name))); + TRY (hdf5_close_group (ctn_hid)); + + H5_CORE_API_RETURN (h5t_open_tetrahedral_mesh (f, name, mesh)); +} + h5_err_t h5t_open_tetrahedral_mesh ( h5_file_t* const f, - h5_id_t id + const char* name, + h5t_mesh_t** mesh ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, id=%lld", f, (long long)id); - h5t_fdata_t* t = f->t; + H5_CORE_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh); + hid_t mesh_hid; - TRY (h5t_close_mesh (f)); + TRY (mesh_hid = h5priv_open_group ( + 0, // do not create intermediate groups + f->root_gid, + H5T_CONTAINER_GRPNAME, + TETRAHEDRAL_MESHES_GRPNAME, + name)); - if (t->num_meshes < 0) { - h5_size_t result = h5t_get_num_tetmeshes (f); - t->num_meshes = (result > 0 ? result : 0); - } - if ((id < -1) || (id >= t->num_meshes)) { - H5_CORE_API_LEAVE (HANDLE_H5_OUT_OF_RANGE_ERR ("mesh", id)); - } - t->dsinfo_elems.type_id = t->dtypes.h5_tet_t; - t->methods = tet_funcs; - t->ref_elem = &h5t_tet_ref_elem; + TRY (*mesh = h5_alloc (NULL, sizeof(**mesh))); + h5t_mesh_t* m = *mesh; + TRY (h5tpriv_init_mesh ( + m, + f, + name, + mesh_hid)); + + m->dsinfo_elems.type_id = m->dtypes.h5_tet_t; + m->methods = tet_funcs; + m->ref_elem = &h5t_tet_ref_elem; + m->leaf_level = 0; + TRY (h5tpriv_read_mesh (m)); - if (id == -1) { // add new - id = 0; - t->num_meshes = 1; - t->cur_mesh = 0; - t->mesh_changed = 0; - t->leaf_level = 0; - t->num_leaf_levels = 0; - TRY (open_tetmesh_group (f, id)); - } else { // read existing - TRY (open_tetmesh_group (f, id)); - TRY (h5tpriv_read_mesh (f)); - t->leaf_level = 0; - } H5_CORE_API_RETURN (H5_SUCCESS); } @@ -94,14 +72,50 @@ h5t_open_tetrahedral_mesh ( \return mesh id */ -h5_id_t +h5_err_t h5t_add_tetrahedral_mesh ( - h5_file_t* const f + h5_file_t* const f, + const char* name, + h5t_mesh_t** mesh ) { - H5_CORE_API_ENTER1 (h5_id_t, "f=0x%p", f); - h5_id_t mesh_id = 0; - TRY (mesh_id = h5t_open_tetrahedral_mesh (f, -1)); - TRY (h5t_add_level (f)); - f->t->mesh_changed = 1; - H5_CORE_API_RETURN (mesh_id); + H5_CORE_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh); + CHECK_WRITABLE_MODE (f); + h5_err_t exists; + TRY (exists = h5priv_link_exists ( + f->root_gid, + H5T_CONTAINER_GRPNAME, + TETRAHEDRAL_MESHES_GRPNAME, + name)); + if (exists) { + H5_CORE_API_LEAVE ( + h5_error ( + H5_ERR, + "Tetrahedral mesh '%s' already exists!", + name)); + } + hid_t mesh_hid; + TRY (mesh_hid = h5priv_open_group ( + 1, // create intermediate groups in path + f->root_gid, + H5T_CONTAINER_GRPNAME, + TETRAHEDRAL_MESHES_GRPNAME, + name)); + + TRY (*mesh = h5_alloc (NULL, sizeof(**mesh))); + h5t_mesh_t* m = *mesh; + TRY (h5tpriv_init_mesh ( + m, + f, + name, + mesh_hid)); + + m->dsinfo_elems.type_id = m->dtypes.h5_tet_t; + m->methods = tet_funcs; + m->ref_elem = &h5t_tet_ref_elem; + m->leaf_level = 0; + m->num_leaf_levels = 0; + TRY (h5t_add_level (m)); + m->mesh_changed = 1; + + H5_CORE_API_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5t_model_trim.c b/src/h5core/h5t_model_trim.c index 1f2c2c5..e6e3e2b 100644 --- a/src/h5core/h5t_model_trim.c +++ b/src/h5core/h5t_model_trim.c @@ -1,3 +1,4 @@ +#include #include "h5core/h5_core.h" #include "h5_core_private.h" @@ -10,156 +11,111 @@ static struct h5t_methods tri_funcs = { }; /* - Open container of triangle meshes - */ -static inline h5_err_t -open_trimeshes_group ( - h5_file_t* const f - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; - - if (t->topo_gid == 0 || t->topo_gid == -1) { - TRY (t->topo_gid = h5priv_open_group ( - f, f->root_gid, H5T_CONTAINER_GRPNAME)); - } - TRY (t->meshes_gid = h5priv_open_group ( - f, - t->topo_gid, - TRIANGLE_MESHES_GRPNAME)); - t->mesh_type = H5_OID_TRIANGLE; - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - -/* - Open container of triangle mesh with \c id - */ -static inline h5_err_t -open_trimesh_group ( + open tetrahedral mesh +*/ +h5_err_t +h5t_open_triangle_mesh_by_idx ( h5_file_t* const f, - const h5_id_t id + const h5_id_t idx, + h5t_mesh_t** mesh ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; + H5_CORE_API_ENTER (h5_err_t, "f=%p, idx=%lld, mesh=%p", f, (long long)idx, mesh); + hid_t ctn_hid; + char name[1024]; - if (t->meshes_gid < 0) { - TRY (open_trimeshes_group (f)); - } - snprintf (t->mesh_name, sizeof (t->mesh_name), "%lld", (long long)id); + TRY (ctn_hid = h5priv_open_group ( + 0, + f->root_gid, + H5T_CONTAINER_GRPNAME, + TRIANGLE_MESHES_GRPNAME)); + TRY (hdf5_get_name_of_group_by_idx (ctn_hid, idx, name, sizeof (name))); + TRY (hdf5_close_group (ctn_hid)); - TRY (t->mesh_gid = h5priv_open_group ( - f, - t->meshes_gid, - t->mesh_name)); - t->cur_mesh = id; - H5_PRIV_API_RETURN (H5_SUCCESS); + H5_CORE_API_RETURN (h5t_open_triangle_mesh (f, name, mesh)); } h5_err_t h5t_open_triangle_mesh ( h5_file_t* const f, - h5_id_t id + const char* name, + h5t_mesh_t** mesh ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, id=%lld", f, (long long)id); - h5t_fdata_t* t = f->t; + H5_CORE_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh); + hid_t mesh_hid; - TRY (h5t_close_mesh (f)); + TRY (mesh_hid = h5priv_open_group ( + 0, + f->root_gid, + H5T_CONTAINER_GRPNAME, + TRIANGLE_MESHES_GRPNAME, + name)); - if (t->num_meshes < 0) { - h5_size_t result = h5t_get_num_trimeshes (f); - t->num_meshes = (result > 0 ? result : 0); - } - if ((id < -1) || (id >= t->num_meshes)) { - H5_CORE_API_LEAVE (HANDLE_H5_OUT_OF_RANGE_ERR ("mesh", id)); - } - t->dsinfo_elems.type_id = t->dtypes.h5_triangle_t; - t->methods = tri_funcs; - t->ref_elem = &h5t_tri_ref_elem; + TRY (*mesh = h5_alloc (NULL, sizeof(**mesh))); + h5t_mesh_t* m = *mesh; + TRY (h5tpriv_init_mesh ( + m, + f, + name, + mesh_hid)); + + m->dsinfo_elems.type_id = m->dtypes.h5_triangle_t; + m->methods = tri_funcs; + m->ref_elem = &h5t_tri_ref_elem; + m->leaf_level = 0; + TRY (h5tpriv_read_mesh (m)); - if (id == -1) { // add new - id = 0; - t->num_meshes = 1; - t->cur_mesh = 0; - t->mesh_changed = 0; - t->leaf_level = 0; - t->num_leaf_levels = 0; - TRY (open_trimesh_group (f, 0)); - } else { // read existing - TRY (open_trimesh_group (f, 0)); - TRY (h5tpriv_read_mesh (f)); - t->leaf_level = 0; - } H5_CORE_API_RETURN (H5_SUCCESS); } -#if 0 -/* - open HDF5 group with data of specific mesh. - */ -static inline h5_err_t -open_trimesh_group_by_name ( - h5_file_t* const f, - const char* mesh_name - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; - - if (t->meshes_gid < 0) { - TRY (open_trimeshes_group (f)); - } - strncpy (t->mesh_name, mesh_name, sizeof (t->mesh_name)); - - TRY (t->mesh_gid = h5priv_open_group ( - f, - t->meshes_gid, - t->mesh_name)); - t->cur_mesh = id; - H5_PRIV_API_RETURN (H5_SUCCESS); -} - -/* - open existing triangle mesh given by \c name. -*/ -h5_err_t -h5t_open_triangle_mesh_by_name ( - h5_file_t* const f, - const* char name - ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, name=%s", f, name); - h5t_fdata_t* t = f->t; - - TRY (h5t_close_mesh (f)); - - t->dsinfo_elems.type_id = t->dtypes.h5_triangle_t; - t->methods = tri_funcs; - t->ref_elem = &h5t_tri_ref_elem; - TRY (open_trimesh_group (f, id)); - - if (id == -1) { // add new - id = t->num_meshes; - t->num_meshes++; - t->mesh_changed = id; - t->num_leaf_levels = 0; - } else { // read existing - TRY (h5tpriv_read_mesh (f)); - } - H5_CORE_API_RETURN (H5_SUCCESS); -} -#endif - /*! Add new mesh \return mesh id */ -h5_id_t +h5_err_t h5t_add_triangle_mesh ( - h5_file_t* const f + h5_file_t* const f, + const char* name, + h5t_mesh_t** mesh ) { - H5_CORE_API_ENTER1 (h5_id_t, "f=0x%p", f); - h5_id_t mesh_id = 0; - TRY (mesh_id = h5t_open_triangle_mesh (f, -1)); - TRY (h5t_add_level (f)); - f->t->mesh_changed = 1; - H5_CORE_API_RETURN (mesh_id); + H5_CORE_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh); + CHECK_WRITABLE_MODE (f); + h5_err_t exists; + TRY (exists = h5priv_link_exists ( + f->root_gid, + H5T_CONTAINER_GRPNAME, + TRIANGLE_MESHES_GRPNAME, + name)); + if (exists) { + H5_CORE_API_LEAVE ( + h5_error ( + H5_ERR, + "Tetrahedral mesh '%s' already exists!", + name)); + } + hid_t mesh_hid; + TRY (mesh_hid = h5priv_open_group ( + 1, // create intermediate groups in path + f->root_gid, + H5T_CONTAINER_GRPNAME, + TRIANGLE_MESHES_GRPNAME, + name)); + + TRY (*mesh = h5_alloc (NULL, sizeof(**mesh))); + h5t_mesh_t* m = *mesh; + TRY (h5tpriv_init_mesh ( + m, + f, + name, + mesh_hid)); + + m->dsinfo_elems.type_id = m->dtypes.h5_triangle_t; + m->methods = tri_funcs; + m->ref_elem = &h5t_tri_ref_elem; + m->leaf_level = 0; + m->num_leaf_levels = 0; + TRY (h5t_add_level (m)); + m->mesh_changed = 1; + + H5_CORE_API_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5t_readwrite.c b/src/h5core/h5t_readwrite.c index ba4ceb8..bd60da2 100644 --- a/src/h5core/h5t_readwrite.c +++ b/src/h5core/h5t_readwrite.c @@ -21,116 +21,91 @@ open_space_all ( */ static h5_err_t write_vertices ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t *t = f->t; - assert (t->num_leaf_levels > 0); - - t->dsinfo_vertices.dims[0] = t->num_vertices[t->num_leaf_levels-1]; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + assert (m->num_leaf_levels > 0); + + m->dsinfo_vertices.dims[0] = m->num_vertices[m->num_leaf_levels-1]; TRY( h5priv_write_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_vertices, + m->f, + m->mesh_gid, + &m->dsinfo_vertices, open_space_all, open_space_all, - t->vertices) ); - TRY( h5priv_write_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_num_vertices, - open_space_all, - open_space_all, - t->num_vertices) ); + m->vertices) ); + + TRY (h5priv_write_attrib ( + m->mesh_gid, + "__num_vertices__", + H5T_NATIVE_INT64, + m->num_vertices, + m->num_leaf_levels)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static h5_err_t write_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; - assert (t->num_leaf_levels > 0); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + assert (m->num_leaf_levels > 0); - h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; + h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; // alloc and inititalize data in memory - TRY( h5tpriv_alloc_glb_elems_struct (f, num_elems) ); - TRY( h5tpriv_init_glb_elems_struct (f) ); + TRY (h5tpriv_alloc_glb_elems_struct (m, num_elems)); + TRY (h5tpriv_init_glb_elems_struct (m)); - t->dsinfo_elems.dims[0] = num_elems; + m->dsinfo_elems.dims[0] = num_elems; TRY( h5priv_write_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_elems, + m->f, + m->mesh_gid, + &m->dsinfo_elems, open_space_all, open_space_all, - t->glb_elems.data) ); + m->glb_elems.data) ); - TRY( h5priv_write_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_num_elems, - open_space_all, - open_space_all, - t->num_elems) ); + TRY (h5priv_write_attrib ( + m->mesh_gid, + "__num_elems__", + H5T_NATIVE_INT64, + m->num_elems, + m->num_leaf_levels)); + + TRY (h5priv_write_attrib ( + m->mesh_gid, + "__num_leaf_elems__", + H5T_NATIVE_INT64, + m->num_leaf_elems, + m->num_leaf_levels)); + + TRY (h5priv_write_attrib ( + m->mesh_gid, + "__num_leaf_levels__", + H5T_NATIVE_INT16, + &m->num_leaf_levels, + 1)); - TRY( h5priv_write_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_num_elems_on_leaf_level, - open_space_all, - open_space_all, - t->num_elems_on_leaf_level) ); // release mem - TRY( h5_free (t->glb_elems.data) ); - t->glb_elems.tets = NULL; + TRY( h5_free (m->glb_elems.data) ); + m->glb_elems.tets = NULL; H5_PRIV_FUNC_RETURN (H5_SUCCESS); } h5_err_t h5tpriv_write_mesh ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - if (t->mesh_changed) { - TRY (write_vertices (f)); - TRY (write_elems (f)); + H5_PRIV_API_ENTER (h5_err_t, "m=%p", m); + if (m->mesh_changed) { + TRY (write_vertices (m)); + TRY (write_elems (m)); } - if (t->mtags.changed) { - TRY (h5tpriv_write_mtags (f)); - } - H5_PRIV_API_RETURN (H5_SUCCESS); } -static h5_ssize_t -get_num_leaf_levels ( - h5_file_t* const f - ) { - h5t_fdata_t* t = f->t; - hid_t dataset_id; - hid_t diskspace_id; - hssize_t size; - - H5_PRIV_FUNC_ENTER1 (h5_ssize_t, "f=0x%p", f); - if (t->cur_mesh < 0) { - H5_PRIV_FUNC_LEAVE (h5tpriv_error_undef_mesh ()); - } - TRY (dataset_id = hdf5_open_dataset (t->mesh_gid, "NumVertices") ); - TRY (diskspace_id = hdf5_get_dataset_space (dataset_id) ); - TRY (size = hdf5_get_npoints_of_dataspace (diskspace_id) ); - TRY (hdf5_close_dataspace (diskspace_id) ); - TRY (hdf5_close_dataset (dataset_id)); - - t->num_leaf_levels = size; - H5_PRIV_FUNC_RETURN (size); -} - - static hid_t open_mem_space_vertices ( h5_file_t* const f, @@ -153,43 +128,35 @@ open_file_space_vertices ( static inline h5_err_t read_num_vertices ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); - if (t->mesh_gid < 0) { - H5_PRIV_FUNC_LEAVE ( - h5_error_internal ()); - } - ssize_t num_bytes = t->num_leaf_levels*sizeof (t->num_vertices[0]); - TRY( t->num_vertices = h5_alloc (t->num_vertices, num_bytes) ); - TRY( h5priv_read_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_num_vertices, - open_space_all, - open_space_all, - t->num_vertices) ); + ssize_t num_bytes = m->num_leaf_levels*sizeof (m->num_vertices[0]); + TRY (m->num_vertices = h5_alloc (m->num_vertices, num_bytes)); + TRY (h5priv_read_attrib ( + m->mesh_gid, + "__num_vertices__", + H5T_NATIVE_INT64, + m->num_vertices)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static h5_err_t read_vertices ( - h5_file_t * f + h5t_mesh_t* m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); - TRY( h5tpriv_alloc_num_vertices (f, t->num_vertices[t->num_leaf_levels-1]) ); + TRY( h5tpriv_alloc_num_vertices (m, m->num_vertices[m->num_leaf_levels-1]) ); TRY( h5priv_read_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_vertices, + m->f, + m->mesh_gid, + &m->dsinfo_vertices, open_mem_space_vertices, open_file_space_vertices, - t->vertices) ); + m->vertices) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -216,83 +183,64 @@ open_file_space_elems ( static h5_err_t read_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); - size_t size = t->num_leaf_levels * sizeof (t->num_elems[0]); - TRY( t->num_elems = h5_calloc (1, size) ); - TRY( t->num_elems_on_leaf_level = h5_calloc (1, size) ); - TRY( h5priv_read_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_num_elems, - open_space_all, - open_space_all, - t->num_elems) ); + TRY (m->num_elems = h5_calloc (m->num_leaf_levels, sizeof(m->num_elems[0]))); + TRY( m->num_leaf_elems = h5_calloc (m->num_leaf_levels, sizeof(m->num_elems[0]))); - TRY( h5priv_read_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_num_elems_on_leaf_level, - open_space_all, - open_space_all, - t->num_elems_on_leaf_level) ); + TRY (h5priv_read_attrib ( + m->mesh_gid, + "__num_elems__", + H5T_NATIVE_INT64, + m->num_elems)); - h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - TRY( h5tpriv_alloc_elems (f, 0, num_elems) ); - TRY( h5tpriv_alloc_glb_elems_struct (f, num_elems) ); + TRY (h5priv_read_attrib ( + m->mesh_gid, + "__num_leaf_elems__", + H5T_NATIVE_INT64, + m->num_leaf_elems)); + + h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; + TRY( h5tpriv_alloc_elems (m, 0, num_elems) ); + TRY( h5tpriv_alloc_glb_elems_struct (m, num_elems) ); TRY( h5priv_read_dataset_by_name ( - f, - t->mesh_gid, - &t->dsinfo_elems, + m->f, + m->mesh_gid, + &m->dsinfo_elems, open_mem_space_elems, open_file_space_elems, - t->glb_elems.data) ); + m->glb_elems.data) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } -static inline h5_err_t -read_mtags ( - h5_file_t* const f - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; - h5_err_t exists; - TRY (exists = hdf5_link_exists (t->mesh_gid, "Tags")); - if (exists) { - TRY (t->mtags.group_id = h5priv_open_group (f, t->mesh_gid, "Tags") ); - TRY (h5tpriv_read_tag_container (f, &f->t->mtags) ); - } - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - h5_err_t h5tpriv_read_mesh ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - if (t->mesh_gid < 0) { - H5_PRIV_API_LEAVE (h5_error_internal ()); - } - TRY (get_num_leaf_levels (f)); - TRY (read_num_vertices (f)); + H5_PRIV_API_ENTER (h5_err_t, "m=%p", m); - TRY (read_vertices (f)); - TRY (h5tpriv_rebuild_vertex_indices_mapping (f)); + TRY (h5priv_read_attrib ( + m->mesh_gid, + "__num_leaf_levels__", + H5T_NATIVE_INT16, + &m->num_leaf_levels)); - TRY (read_elems (f)); + TRY (read_num_vertices (m)); - TRY (h5tpriv_init_glb2loc_elem_map (f)); - TRY (h5tpriv_init_loc_elems_struct (f, 0)); - TRY (h5_free (t->glb_elems.data)); - TRY (h5tpriv_update_adjacency_structs (f, 0)); - TRY (h5tpriv_init_geom_boundary_info (f, 0)); + TRY (read_vertices (m)); + TRY (h5tpriv_rebuild_vertex_indices_mapping (m)); - TRY (read_mtags (f)); - t->num_loaded_levels = t->num_leaf_levels; + TRY (read_elems (m)); + + TRY (h5tpriv_init_glb2loc_elem_map (m)); + TRY (h5tpriv_init_loc_elems_struct (m, 0)); + TRY (h5_free (m->glb_elems.data)); + TRY (h5tpriv_update_adjacency_structs (m, 0)); + TRY (h5tpriv_init_geom_boundary_info (m, 0)); + + m->num_loaded_levels = m->num_leaf_levels; H5_PRIV_API_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5t_readwrite_private.h b/src/h5core/h5t_readwrite_private.h index c223892..27b206b 100644 --- a/src/h5core/h5t_readwrite_private.h +++ b/src/h5core/h5t_readwrite_private.h @@ -2,11 +2,11 @@ #define __H5T_READWRITE_PRIVATE_H struct h5t_read_methods { - h5_err_t (*init_loc_elems_struct)(h5_file_t* const, h5t_lvl_idx_t); - h5_err_t (*init_geom_boundary_info)(h5_file_t* const, h5t_lvl_idx_t); - h5_err_t (*alloc_glb_elems_struct)(h5_file_t* const, h5_loc_idx_t); - h5_err_t (*init_glb2loc_elem_map)(h5_file_t* const); - h5_err_t (*init_glb_elems_struct)(h5_file_t* const); + h5_err_t (*init_loc_elems_struct)(h5t_mesh_t* const, h5t_lvl_idx_t); + h5_err_t (*init_geom_boundary_info)(h5t_mesh_t* const, h5t_lvl_idx_t); + h5_err_t (*alloc_glb_elems_struct)(h5t_mesh_t* const, h5_loc_idx_t); + h5_err_t (*init_glb2loc_elem_map)(h5t_mesh_t* const); + h5_err_t (*init_glb_elems_struct)(h5t_mesh_t* const); }; extern struct h5t_read_methods h5tpriv_read_trim_methods; @@ -14,61 +14,61 @@ extern struct h5t_read_methods h5tpriv_read_tetm_methods; h5_err_t h5tpriv_write_obj ( - h5_file_t * f, + h5t_mesh_t* m, const hid_t gid, const hsize_t current_dims, const hsize_t max_dims, const hid_t tid, - const void * const object, - const char * const dsname + const void* const object, + const char* const dsname ); h5_err_t h5tpriv_read_mesh ( - h5_file_t * const f + h5t_mesh_t* const m ); h5_err_t h5tpriv_write_mesh ( - h5_file_t * const f + h5t_mesh_t* const m ); static inline h5_err_t h5tpriv_init_loc_elems_struct ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - return (*f->t->methods.read->init_loc_elems_struct) (f, from_lvl); + return (*m->methods.read->init_loc_elems_struct) (m, from_lvl); } static inline h5_err_t h5tpriv_init_geom_boundary_info ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - return (*f->t->methods.read->init_geom_boundary_info) (f, from_lvl); + return (*m->methods.read->init_geom_boundary_info) (m, from_lvl); } static inline h5_err_t h5tpriv_alloc_glb_elems_struct ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t num_elems ) { - return (*f->t->methods.read->alloc_glb_elems_struct) (f, num_elems); + return (*m->methods.read->alloc_glb_elems_struct) (m, num_elems); } static inline h5_err_t h5tpriv_init_glb2loc_elem_map ( - h5_file_t* const f + h5t_mesh_t* const m ) { - return (*f->t->methods.read->init_glb2loc_elem_map) (f); + return (*m->methods.read->init_glb2loc_elem_map) (m); } static inline h5_err_t h5tpriv_init_glb_elems_struct ( - h5_file_t* const f + h5t_mesh_t* const m ) { - return (*f->t->methods.read->init_glb_elems_struct) (f); + return (*m->methods.read->init_glb_elems_struct) (m); } #endif diff --git a/src/h5core/h5t_readwrite_tetm.c b/src/h5core/h5t_readwrite_tetm.c index 87b3d0d..d8fed31 100644 --- a/src/h5core/h5t_readwrite_tetm.c +++ b/src/h5core/h5t_readwrite_tetm.c @@ -7,33 +7,32 @@ */ static h5_err_t init_loc_elems_struct ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* const t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, from_lvl=%d", m, from_lvl); h5_loc_idx_t elem_idx = 0; - const h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; + const h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; h5t_lvl_idx_t level_idx = 0; - int num_vertices = h5tpriv_ref_elem_get_num_vertices (t); - int num_facets = h5tpriv_ref_elem_get_num_facets (t); - h5_loc_tet_t* loc_elem = t->loc_elems.tets; - h5_glb_tet_t* glb_elem = t->glb_elems.tets; + int num_vertices = h5tpriv_ref_elem_get_num_vertices (m); + int num_facets = h5tpriv_ref_elem_get_num_facets (m); + h5_loc_tet_t* loc_elem = m->loc_elems.tets; + h5_glb_tet_t* glb_elem = m->glb_elems.tets; - for (elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; + for (elem_idx = (from_lvl <= 0) ? 0 : m->num_elems[from_lvl-1]; elem_idx < num_elems; elem_idx++, loc_elem++, glb_elem++) { // global element index loc_elem->glb_idx = glb_elem->idx; // local parent index TRY( loc_elem->parent_idx = - h5t_map_glb_elem_idx2loc (f, glb_elem->parent_idx) ); + h5t_map_glb_elem_idx2loc (m, glb_elem->parent_idx) ); // local child index TRY( loc_elem->child_idx = - h5t_map_glb_elem_idx2loc (f, glb_elem->child_idx) ); + h5t_map_glb_elem_idx2loc (m, glb_elem->child_idx) ); // level idx - if (elem_idx >= t->num_elems[level_idx]) { + if (elem_idx >= m->num_elems[level_idx]) { level_idx++; } loc_elem->level_idx = level_idx; @@ -42,20 +41,20 @@ init_loc_elems_struct ( loc_elem->refinement_level = 0; h5_loc_tet_t* elem = loc_elem; while (elem->parent_idx > 0) { - elem = t->loc_elems.tets + elem->parent_idx; + elem = m->loc_elems.tets + elem->parent_idx; loc_elem->refinement_level++; } // vertex indices TRY( h5t_map_global_vertex_indices2local ( - f, + m, glb_elem->vertex_indices, num_vertices, loc_elem->vertex_indices) ); // neighbor indices TRY( h5t_map_glb_elem_indices2loc ( - f, + m, glb_elem->neighbor_indices, num_facets, loc_elem->neighbor_indices) ); @@ -65,18 +64,17 @@ init_loc_elems_struct ( static h5_err_t init_geom_boundary_info ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* const t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, from_lvl=%d", m, from_lvl); h5_loc_idx_t elem_idx = 0; - const h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - int num_facets = h5tpriv_ref_elem_get_num_facets (t); - h5_loc_tet_t* loc_elem = t->loc_elems.tets; - h5_glb_tet_t* glb_elem = t->glb_elems.tets; + const h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; + int num_facets = h5tpriv_ref_elem_get_num_facets (m); + h5_loc_tet_t* loc_elem = m->loc_elems.tets; + h5_glb_tet_t* glb_elem = m->glb_elems.tets; - for (elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; + for (elem_idx = (from_lvl <= 0) ? 0 : m->num_elems[from_lvl-1]; elem_idx < num_elems; elem_idx++, loc_elem++, glb_elem++) { // on boundary? int i; @@ -98,42 +96,40 @@ init_geom_boundary_info ( */ static h5_err_t alloc_glb_elems_struct ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t num_elems ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* const t = f->t; - TRY (t->glb_elems.tets = h5_calloc ( + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, num_elems=%d", m, num_elems); + TRY (m->glb_elems.tets = h5_calloc ( num_elems, - sizeof(t->glb_elems.tets[0]) ) ); + sizeof(m->glb_elems.tets[0]) ) ); memset ( - t->glb_elems.tets, + m->glb_elems.tets, -1, - (num_elems) * sizeof(t->glb_elems.tets[0]) ); + (num_elems) * sizeof(m->glb_elems.tets[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static h5_err_t init_glb2loc_elem_map ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); - if (t->num_leaf_levels <= 0) + if (m->num_leaf_levels <= 0) H5_PRIV_FUNC_LEAVE (H5_SUCCESS); h5_loc_idx_t loc_idx = 0; - h5_loc_idx_t num_loc_elems = t->num_elems[t->num_leaf_levels-1]; - h5_idxmap_el_t* item = &t->map_elem_g2l.items[loc_idx]; - h5_glb_tet_t* elem = t->glb_elems.tets; + h5_loc_idx_t num_loc_elems = m->num_elems[m->num_leaf_levels-1]; + h5_idxmap_el_t* item = &m->map_elem_g2l.items[loc_idx]; + h5_glb_tet_t* elem = m->glb_elems.tets; for (; loc_idx < num_loc_elems; elem++, loc_idx++, item++) { item->glb_idx = elem->idx; item->loc_idx = loc_idx; - t->map_elem_g2l.num_items++; + m->map_elem_g2l.num_items++; } - h5priv_sort_idxmap (&t->map_elem_g2l); + h5priv_sort_idxmap (&m->map_elem_g2l); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -143,15 +139,14 @@ init_glb2loc_elem_map ( */ static h5_err_t init_glb_elems_struct ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* const t = f->t; - h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; // simple in serial runs: global index = local index - h5_loc_tet_t* loc_elem = t->loc_elems.tets; - h5_glb_tet_t* glb_elem = t->glb_elems.tets; + h5_loc_tet_t* loc_elem = m->loc_elems.tets; + h5_glb_tet_t* glb_elem = m->glb_elems.tets; h5_loc_tet_t* end = loc_elem + num_elems; while (loc_elem < end) { diff --git a/src/h5core/h5t_readwrite_trim.c b/src/h5core/h5t_readwrite_trim.c index 119181b..00aed80 100644 --- a/src/h5core/h5t_readwrite_trim.c +++ b/src/h5core/h5t_readwrite_trim.c @@ -7,33 +7,32 @@ */ static h5_err_t init_loc_elems_struct ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* const t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, from_lvl=%d", m, from_lvl); h5_loc_idx_t elem_idx = 0; - const h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; + const h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; h5t_lvl_idx_t level_idx = 0; - int num_vertices = h5tpriv_ref_elem_get_num_vertices (t); - int num_facets = h5tpriv_ref_elem_get_num_facets (t); - h5_loc_triangle_t* loc_elem = t->loc_elems.tris; - h5_glb_triangle_t* glb_elem = t->glb_elems.tris; + int num_vertices = h5tpriv_ref_elem_get_num_vertices (m); + int num_facets = h5tpriv_ref_elem_get_num_facets (m); + h5_loc_triangle_t* loc_elem = m->loc_elems.tris; + h5_glb_triangle_t* glb_elem = m->glb_elems.tris; - for (elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; + for (elem_idx = (from_lvl <= 0) ? 0 : m->num_elems[from_lvl-1]; elem_idx < num_elems; elem_idx++, loc_elem++, glb_elem++) { // global element index loc_elem->glb_idx = glb_elem->idx; // local parent index TRY( loc_elem->parent_idx = - h5t_map_glb_elem_idx2loc (f, glb_elem->parent_idx) ); + h5t_map_glb_elem_idx2loc (m, glb_elem->parent_idx) ); // local child index TRY( loc_elem->child_idx = - h5t_map_glb_elem_idx2loc (f, glb_elem->child_idx) ); + h5t_map_glb_elem_idx2loc (m, glb_elem->child_idx) ); // level idx - if (elem_idx >= t->num_elems[level_idx]) { + if (elem_idx >= m->num_elems[level_idx]) { level_idx++; } loc_elem->level_idx = level_idx; @@ -42,20 +41,20 @@ init_loc_elems_struct ( loc_elem->refinement_level = 0; h5_loc_triangle_t* elem = loc_elem; while (elem->parent_idx > 0) { - elem = t->loc_elems.tris + elem->parent_idx; + elem = m->loc_elems.tris + elem->parent_idx; loc_elem->refinement_level++; } // vertex indices TRY( h5t_map_global_vertex_indices2local ( - f, + m, glb_elem->vertex_indices, num_vertices, loc_elem->vertex_indices) ); // neighbor indices TRY( h5t_map_glb_elem_indices2loc ( - f, + m, glb_elem->neighbor_indices, num_facets, loc_elem->neighbor_indices) ); @@ -66,18 +65,17 @@ init_loc_elems_struct ( static h5_err_t init_geom_boundary_info ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t from_lvl ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* const t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, from_lvl=%d", m, from_lvl); h5_loc_idx_t elem_idx = 0; - const h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; - int num_facets = h5tpriv_ref_elem_get_num_facets (t); - h5_loc_triangle_t* loc_elem = t->loc_elems.tris; - h5_glb_triangle_t* glb_elem = t->glb_elems.tris; + const h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; + int num_facets = h5tpriv_ref_elem_get_num_facets (m); + h5_loc_triangle_t* loc_elem = m->loc_elems.tris; + h5_glb_triangle_t* glb_elem = m->glb_elems.tris; - for (elem_idx = (from_lvl <= 0) ? 0 : t->num_elems[from_lvl-1]; + for (elem_idx = (from_lvl <= 0) ? 0 : m->num_elems[from_lvl-1]; elem_idx < num_elems; elem_idx++, loc_elem++, glb_elem++) { // on boundary? int i; @@ -99,43 +97,41 @@ init_geom_boundary_info ( */ static h5_err_t alloc_glb_elems_struct ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t num_elems ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* const t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, num_elems=%d", m, num_elems); - TRY ( t->glb_elems.tris = h5_calloc ( + TRY ( m->glb_elems.tris = h5_calloc ( num_elems, - sizeof(t->glb_elems.tris[0]) ) ); + sizeof(m->glb_elems.tris[0]) ) ); memset ( - t->glb_elems.tris, + m->glb_elems.tris, -1, - (num_elems) * sizeof(t->glb_elems.tris[0]) ); + (num_elems) * sizeof(m->glb_elems.tris[0]) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } static h5_err_t init_glb2loc_elem_map ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); - if (t->num_leaf_levels <= 0) + if (m->num_leaf_levels <= 0) H5_PRIV_FUNC_LEAVE (H5_SUCCESS); h5_loc_idx_t loc_idx = 0; - h5_loc_idx_t num_loc_elems = t->num_elems[t->num_leaf_levels-1]; - h5_idxmap_el_t* item = &t->map_elem_g2l.items[loc_idx]; - h5_glb_triangle_t* elem = t->glb_elems.tris; + h5_loc_idx_t num_loc_elems = m->num_elems[m->num_leaf_levels-1]; + h5_idxmap_el_t* item = &m->map_elem_g2l.items[loc_idx]; + h5_glb_triangle_t* elem = m->glb_elems.tris; for (; loc_idx < num_loc_elems; elem++, loc_idx++, item++) { item->glb_idx = elem->idx; item->loc_idx = loc_idx; - t->map_elem_g2l.num_items++; + m->map_elem_g2l.num_items++; } - h5priv_sort_idxmap (&t->map_elem_g2l); + h5priv_sort_idxmap (&m->map_elem_g2l); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -145,15 +141,14 @@ init_glb2loc_elem_map ( */ static h5_err_t init_glb_elems_struct ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* const t = f->t; - h5_loc_idx_t num_elems = t->num_elems[t->num_leaf_levels-1]; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + h5_loc_idx_t num_elems = m->num_elems[m->num_leaf_levels-1]; // simple in serial runs: global index = local index - h5_loc_triangle_t* loc_elem = t->loc_elems.tris; - h5_glb_triangle_t* glb_elem = t->glb_elems.tris; + h5_loc_triangle_t* loc_elem = m->loc_elems.tris; + h5_glb_triangle_t* glb_elem = m->glb_elems.tris; h5_loc_triangle_t* end = loc_elem + num_elems; while (loc_elem < end) { diff --git a/src/h5core/h5t_retrieve.c b/src/h5core/h5t_retrieve.c index e12dcda..39c6511 100644 --- a/src/h5core/h5t_retrieve.c +++ b/src/h5core/h5t_retrieve.c @@ -8,28 +8,25 @@ */ static h5_err_t iter_leaf_elem_idx ( - h5_file_t* f, h5t_leaf_iterator_t* iter ) { h5_generic_loc_elem_t* el; do { iter->elem_idx++; - if (iter->elem_idx >= f->t->num_elems[iter->leaf_level]) { + if (iter->elem_idx >= iter->mesh->num_elems[iter->leaf_level]) { return H5_NOK; // done } - el = h5tpriv_get_loc_elem (f, iter->elem_idx); - } while (!h5tpriv_is_leaf_elem (f, el)); + el = h5tpriv_get_loc_elem (iter->mesh, iter->elem_idx); + } while (!h5tpriv_is_leaf_elem (iter->mesh, el)); return H5_SUCCESS; } static h5_loc_id_t iterate_leaf_elems ( - h5_file_t* const f, union h5t_iterator* iter ) { h5t_leaf_iterator_t* it = (h5t_leaf_iterator_t*)&iter->leaf; - if ( iter_leaf_elem_idx (f, it) == H5_NOK) { - h5_debug ("Traversing done!"); + if ( iter_leaf_elem_idx (it) == H5_NOK) { return H5_NOK; } int dim = h5tpriv_ref_elem_get_dim (it); @@ -39,39 +36,34 @@ iterate_leaf_elems ( static h5_loc_id_t iterate_boundary_elems ( - h5_file_t* const f, h5t_iterator_t* iter ) { h5t_leaf_iterator_t* it = (h5t_leaf_iterator_t*)&iter->leaf; do { - if ( iter_leaf_elem_idx (f, it) == H5_NOK) { - h5_debug ("Traversing done!"); + if ( iter_leaf_elem_idx (it) == H5_NOK) { return H5_NOK; } - } while (!h5tpriv_is_boundary_elem (f, it->elem_idx)); + } while (!h5tpriv_is_boundary_elem (it->mesh, it->elem_idx)); int dim = h5tpriv_ref_elem_get_dim (it); h5_loc_id_t type_id = h5tpriv_ref_elem_get_entity_type (it, dim); return h5tpriv_build_entity_id (type_id, 0, it->elem_idx ); } - - /* Iterate boundary facets (co-dim 1 entities). */ static h5_loc_id_t iterate_boundary_facets ( - h5_file_t* const f, h5t_iterator_t* iter ) { - H5_PRIV_FUNC_ENTER (h5_loc_id_t); + H5_PRIV_FUNC_ENTER (h5_loc_id_t, "iter=%p", iter); h5t_leaf_iterator_t* it = (h5t_leaf_iterator_t*)&iter->leaf; int num_facets = h5tpriv_ref_elem_get_num_facets (it) - 1; int dim = h5tpriv_ref_elem_get_dim (it) - it->codim; do { if (it->face_idx >= num_facets) { h5_loc_id_t elem_id; - TRY( elem_id = iterate_boundary_elems (f, iter) ); + TRY( elem_id = iterate_boundary_elems (iter) ); if (elem_id == H5_NOK) { H5_PRIV_FUNC_LEAVE (H5_NOK); // done! } @@ -80,7 +72,7 @@ iterate_boundary_facets ( } else { it->face_idx++; } - } while (! h5tpriv_is_boundary_facet (f, it->elem_idx, it->face_idx)); + } while (! h5tpriv_is_boundary_facet (it->mesh, it->elem_idx, it->face_idx)); int type = h5tpriv_ref_elem_get_entity_type (it, dim); H5_PRIV_FUNC_RETURN (h5tpriv_build_entity_id (type, it->face_idx, it->elem_idx)); } @@ -90,10 +82,9 @@ iterate_boundary_facets ( */ static h5_loc_id_t iterate_leaf_faces ( - h5_file_t* const f, h5t_iterator_t* iter ) { - H5_PRIV_FUNC_ENTER (h5_loc_id_t); + H5_PRIV_FUNC_ENTER (h5_loc_id_t, "iter=%p", iter); h5t_leaf_iterator_t* it = (h5t_leaf_iterator_t*)iter; h5_loc_idlist_t* entry; int dim = h5tpriv_ref_elem_get_dim (it) - it->codim; @@ -101,8 +92,7 @@ iterate_leaf_faces ( int i = -1; do { if (it->face_idx >= num_faces) { - if (iter_leaf_elem_idx (f, it) == H5_NOK) { - h5_debug ("Traversing done!"); + if (iter_leaf_elem_idx (it) == H5_NOK) { H5_PRIV_FUNC_LEAVE (H5_NOK); // done! } it->face_idx = 0; @@ -113,7 +103,7 @@ iterate_leaf_faces ( // 1. Get list of all elements with this face. Actually we // retrieve a list of entities sorted by the element index. - TRY( (it->find)(f, it->face_idx, it->elem_idx, &entry) ); + TRY( (it->find)(it->mesh, it->face_idx, it->elem_idx, &entry) ); // 2. Go to first element in list which is on current level i = -1; @@ -121,8 +111,8 @@ iterate_leaf_faces ( do { i++; h5_loc_idx_t idx = h5tpriv_get_elem_idx (entry->items[i]); - el = h5tpriv_get_loc_elem (f, idx); - } while (!h5tpriv_is_leaf_elem (f, el)); + el = h5tpriv_get_loc_elem (it->mesh, idx); + } while (!h5tpriv_is_leaf_elem (it->mesh, el)); // 3. Face already visited if } while (it->elem_idx > h5tpriv_get_elem_idx(entry->items[i])); @@ -140,10 +130,9 @@ iterate_leaf_faces ( */ static h5_loc_id_t iterate_boundary_faces ( - h5_file_t* const f, h5t_iterator_t* iter ) { - H5_PRIV_FUNC_ENTER (h5_loc_id_t); + H5_PRIV_FUNC_ENTER (h5_loc_id_t, "iter=%p", iter); h5t_leaf_iterator_t* it = (h5t_leaf_iterator_t*)iter; // TODO!!! int dim = h5tpriv_ref_elem_get_dim (it) - it->codim; @@ -155,7 +144,7 @@ iterate_boundary_faces ( // goto next element if (it->face_idx >= num_faces) { h5_loc_id_t elem_id; - TRY( elem_id = iterate_boundary_elems (f, iter) ); + TRY( elem_id = iterate_boundary_elems (iter) ); if (elem_id == H5_NOK) { H5_PRIV_FUNC_LEAVE (H5_NOK); // done! } @@ -164,7 +153,7 @@ iterate_boundary_faces ( it->face_idx++; } } while (! h5tpriv_is_boundary_face ( - f, dim, it->elem_idx, it->face_idx)); + it->mesh, dim, it->elem_idx, it->face_idx)); // Skip already visited faces } while (0); H5_PRIV_FUNC_RETURN (h5_error_internal ()); @@ -172,11 +161,9 @@ iterate_boundary_faces ( static h5_loc_id_t iterate_tags ( - h5_file_t* const f, h5t_iterator_t* iter ) { - H5_PRIV_FUNC_ENTER (h5_loc_id_t); - UNUSED_ARGUMENT (f); + H5_PRIV_FUNC_ENTER (h5_loc_id_t, "iter=%p", iter); UNUSED_ARGUMENT (iter); #if 0 h5t_tagsel_t* tags; @@ -195,44 +182,42 @@ iterate_tags ( h5_err_t h5t_init_leaf_iterator ( - h5_file_t* f, h5t_iterator_t* iter, + h5t_mesh_t* m, int codim ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, iter=0x%p, codim=%d", - f, iter, codim); + H5_CORE_API_ENTER (h5_err_t, "iter=%p, m=%p, codim=%d", iter, m, codim); h5t_leaf_iterator_t* it = (h5t_leaf_iterator_t*)&iter->leaf; + it->mesh = m; it->face_idx = 999; it->elem_idx = -1; it->codim = codim; - it->leaf_level = f->t->leaf_level; - it->ref_elem = f->t->ref_elem; + it->leaf_level = m->leaf_level; + it->ref_elem = m->ref_elem; if (it->codim > 0) { it->iter = iterate_leaf_faces; } else if (it->codim == 0) { it->iter = iterate_leaf_elems; } - TRY (h5tpriv_init_entity_iterator (f, iter, codim)); + TRY (h5tpriv_init_entity_iterator (m, iter, codim)); H5_CORE_API_RETURN (H5_SUCCESS); } h5_err_t h5t_init_boundary_face_iterator ( - h5_file_t* f, h5t_iterator_t* iter, + h5t_mesh_t* m, int codim ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, iter=0x%p, codim=%d", - f, iter, codim); + H5_CORE_API_ENTER (h5_err_t, "iter=%p, m=%p, codim=%d", iter, m, codim); h5t_leaf_iterator_t* it = (h5t_leaf_iterator_t*)iter; + it->mesh = m; it->face_idx = 999; // something > max number of faces it->elem_idx = -1; it->codim = codim; - it->leaf_level = f->t->leaf_level; - it->ref_elem = f->t->ref_elem; + it->leaf_level = m->leaf_level; + it->ref_elem = m->ref_elem; if (it->codim <= 0 || it->codim > it->ref_elem->dim) { H5_CORE_API_LEAVE (h5tpriv_inval_codim (codim, 1, it->ref_elem->dim)); @@ -247,49 +232,43 @@ h5t_init_boundary_face_iterator ( h5_err_t h5t_init_mtag_iterator ( - h5_file_t* f, h5t_iterator_t* iter, + h5t_mesh_t* m, const char* name ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, iter=0x%p, name=\"%s\"", - f, iter, name); + H5_CORE_API_ENTER (h5_err_t, "iter=%p, m=%p, name='%s'", iter, m, name); h5t_tag_iterator_t* it = (h5t_tag_iterator_t*)iter; - TRY (h5t_open_mtagset (f, name, &it->tagset)); + it->mesh = m; + TRY (h5t_open_mtagset (m, name, &it->tagset)); it->elem_idx = -1; it->subentity_idx = 999; - it->level_idx = f->t->leaf_level; + it->level_idx = m->leaf_level; it->iter = iterate_tags; H5_CORE_API_RETURN (H5_SUCCESS); } h5_err_t h5t_release_entity_iterator ( - h5_file_t* const f, h5t_iterator_t* iter ) { - UNUSED_ARGUMENT (f); - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_err_t, "iter=%p", iter); H5_CORE_API_RETURN (h5_free (iter)); } h5_loc_id_t h5t_iterate_entities ( - h5_file_t* const f, h5t_iterator_t* iter ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, iter=0x%p", f, iter); + H5_CORE_API_ENTER (h5_err_t, "iter=%p", iter); h5t_generic_iterator_t* it = (h5t_generic_iterator_t*)iter; - H5_CORE_API_RETURN (it->iter (f, iter)); + H5_CORE_API_RETURN (it->iter (iter)); } h5_err_t h5t_end_iterate_entities ( - h5_file_t* const f, h5t_iterator_t* iter ) { - UNUSED_ARGUMENT (f); - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, iter=0x%p", f, iter); + H5_CORE_API_ENTER (h5_err_t, "iter=%p", iter); memset (iter, 0, sizeof(*iter)); h5t_leaf_iterator_t* it = (h5t_leaf_iterator_t*)iter; it->face_idx = -1; @@ -300,34 +279,34 @@ h5t_end_iterate_entities ( h5_err_t h5t_get_vertex_coords_by_index ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t vertex_index, h5_float64_t P[3] ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, vertex_index=%llu, P=0x%p", - f, - (long long unsigned)vertex_index, - P); - h5_loc_vertex_t *vertex = &f->t->vertices[vertex_index]; + H5_CORE_API_ENTER (h5_err_t, + "m=%p, vertex_index=%llu, P=%p", + m, + (long long unsigned)vertex_index, + P); + h5_loc_vertex_t *vertex = &m->vertices[vertex_index]; memcpy ( P, &vertex->P, sizeof ( vertex->P ) ); H5_CORE_API_RETURN (H5_SUCCESS); } h5_err_t h5t_get_vertex_coords_by_id ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t vertex_id, h5_float64_t P[3] ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, vertex_id=%llu, P=0x%p", - f, - (long long unsigned)vertex_id, - P); + H5_CORE_API_ENTER (h5_err_t, + "m=%p, vertex_id=%llu, P=%p", + m, + (long long unsigned)vertex_id, + P); h5_loc_idx_t vertex_index; - TRY (h5t_get_vertex_index_of_vertex (f, vertex_id, &vertex_index)); - TRY (h5t_get_vertex_coords_by_index (f, vertex_index, P)); + TRY (h5t_get_vertex_index_of_vertex (m, vertex_id, &vertex_index)); + TRY (h5t_get_vertex_coords_by_index (m, vertex_index, P)); H5_CORE_API_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5t_retrieve_private.h b/src/h5core/h5t_retrieve_private.h index 71ba14a..a200a20 100644 --- a/src/h5core/h5t_retrieve_private.h +++ b/src/h5core/h5t_retrieve_private.h @@ -16,17 +16,17 @@ extern struct h5t_retrieve_methods h5tpriv_tetm_retrieve_methods; - the level_id of the element is <= the current level - and, if any, the direct children is on a level > the current level */ -#define h5tpriv_is_leaf_elem(f, el) \ - ( (el->level_idx <= f->t->leaf_level) && \ - (el->child_idx < 0 || el->child_idx >= f->t->num_elems[f->t->leaf_level]) ) +#define h5tpriv_is_leaf_elem(m, el) \ + ( ((el)->level_idx <= m->leaf_level) && \ + ((el)->child_idx < 0 || (el)->child_idx >= m->num_elems[m->leaf_level]) ) static inline h5_err_t h5tpriv_init_entity_iterator ( - h5_file_t* f, + h5t_mesh_t* m, h5t_iterator_t* const iter, const int codim ) { - return (*f->t->methods.retrieve->init_entity_iterator) (iter, codim); + return (*m->methods.retrieve->init_entity_iterator) (iter, codim); } #endif diff --git a/src/h5core/h5t_store.c b/src/h5core/h5t_store.c index e0598ae..9e630a2 100644 --- a/src/h5core/h5t_store.c +++ b/src/h5core/h5t_store.c @@ -8,21 +8,19 @@ */ static h5_err_t assign_global_vertex_indices ( - h5_file_t* const f + h5t_mesh_t* const m ) { - h5t_fdata_t* const t = f->t; - - if (t->leaf_level < 0) return H5_SUCCESS; /* no level defined */ + if (m->leaf_level < 0) return H5_SUCCESS; /* no level defined */ /* simple in serial runs: global_id = local_id */ - h5_loc_idx_t local_idx = (t->leaf_level == 0) ? - 0 : t->num_vertices[t->leaf_level-1]; + h5_loc_idx_t local_idx = (m->leaf_level == 0) ? + 0 : m->num_vertices[m->leaf_level-1]; for (local_idx = 0; - local_idx < t->num_vertices[t->num_leaf_levels-1]; + local_idx < m->num_vertices[m->num_leaf_levels-1]; local_idx++) { - t->vertices[local_idx].idx = local_idx; + m->vertices[local_idx].idx = local_idx; } return H5_SUCCESS; @@ -33,19 +31,17 @@ assign_global_vertex_indices ( */ static h5_err_t assign_glb_elem_indices ( - h5_file_t* const f + h5t_mesh_t* const m ) { - h5t_fdata_t* const t = f->t; - - if (t->leaf_level < 0) return H5_SUCCESS; /* no level defined */ + if (m->leaf_level < 0) return H5_SUCCESS; /* no level defined */ /* simple in serial runs: global index = local index */ - h5_loc_idx_t loc_idx = (t->leaf_level == 0) ? 0 : t->num_elems[t->leaf_level-1]; + h5_loc_idx_t loc_idx = (m->leaf_level == 0) ? 0 : m->num_elems[m->leaf_level-1]; - for (; loc_idx < t->num_elems[t->leaf_level]; loc_idx++) { - h5tpriv_set_loc_elem_glb_idx (f, loc_idx, loc_idx); + for (; loc_idx < m->num_elems[m->leaf_level]; loc_idx++) { + h5tpriv_set_loc_elem_glb_idx (m, loc_idx, loc_idx); } return H5_SUCCESS; @@ -55,42 +51,31 @@ assign_glb_elem_indices ( h5t_lvl_idx_t h5t_add_level ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5t_lvl_idx_t, "f=0x%p", f); - h5t_fdata_t* const t = f->t; + H5_CORE_API_ENTER (h5t_lvl_idx_t, "m=%p", m); + CHECK_WRITABLE_MODE(m->f); - if (f->mode == H5_O_RDONLY) { - H5_CORE_API_LEAVE (h5priv_handle_file_mode_error(f->mode)); - } + m->leaf_level = m->num_leaf_levels++; + m->num_loaded_levels = m->num_leaf_levels; - /* t->num_leaf_levels will be set to zero on file creation(!) */ - if ((t->cur_mesh < 0) || (t->num_leaf_levels == -1)) { - H5_CORE_API_LEAVE (h5tpriv_error_undef_mesh ()); - } - t->leaf_level = t->num_leaf_levels++; - t->num_loaded_levels = t->num_leaf_levels; - t->dsinfo_num_vertices.dims[0] = t->num_leaf_levels; - t->dsinfo_num_elems.dims[0] = t->num_leaf_levels; - t->dsinfo_num_elems_on_leaf_level.dims[0] = t->num_leaf_levels; + ssize_t num_bytes = m->num_leaf_levels*sizeof (h5_size_t); + TRY (m->num_vertices = h5_alloc (m->num_vertices, num_bytes)); + m->num_vertices[m->leaf_level] = -1; - ssize_t num_bytes = t->num_leaf_levels*sizeof (h5_size_t); - TRY (t->num_vertices = h5_alloc (t->num_vertices, num_bytes)); - t->num_vertices[t->leaf_level] = -1; + TRY (m->num_elems = h5_alloc (m->num_elems, num_bytes)); + m->num_elems[m->leaf_level] = -1; + TRY ( m->num_leaf_elems = h5_alloc ( + m->num_leaf_elems, num_bytes)); + m->num_leaf_elems[m->leaf_level] = -1; - TRY (t->num_elems = h5_alloc (t->num_elems, num_bytes)); - t->num_elems[t->leaf_level] = -1; - TRY ( t->num_elems_on_leaf_level = h5_alloc ( - t->num_elems_on_leaf_level, num_bytes)); - t->num_elems_on_leaf_level[t->leaf_level] = -1; - - if (t->leaf_level == 0) { + if (m->leaf_level == 0) { /* nothing stored yet */ - t->last_stored_vid = -1; - t->last_stored_eid = -1; + m->last_stored_vid = -1; + m->last_stored_eid = -1; } - H5_CORE_API_RETURN (t->leaf_level); + H5_CORE_API_RETURN (m->leaf_level); } /*! @@ -98,52 +83,47 @@ h5t_add_level ( */ h5_err_t h5t_begin_store_vertices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_size_t num ) { - H5_CORE_API_ENTER2 (h5_err_t, - "f=0x%p, num=%llu", - f, (long long unsigned)num); - h5t_fdata_t* const t = f->t; - - if (t->leaf_level < 0) { + H5_CORE_API_ENTER (h5_err_t, "m=%p, num=%llu", m, (long long unsigned)num); + if (m->leaf_level < 0) { H5_CORE_API_LEAVE (h5tpriv_error_undef_level()); } - h5_size_t cur_num_vertices = (t->leaf_level > 0 ? - t->num_vertices[t->leaf_level-1] : 0); - t->num_vertices[t->leaf_level] = cur_num_vertices+num; - t->dsinfo_vertices.dims[0] = cur_num_vertices+num; - H5_CORE_API_RETURN (h5tpriv_alloc_num_vertices (f, cur_num_vertices+num)); + h5_size_t cur_num_vertices = (m->leaf_level > 0 ? + m->num_vertices[m->leaf_level-1] : 0); + m->num_vertices[m->leaf_level] = cur_num_vertices+num; + m->dsinfo_vertices.dims[0] = cur_num_vertices+num; + H5_CORE_API_RETURN (h5tpriv_alloc_num_vertices (m, cur_num_vertices+num)); } h5_loc_idx_t h5t_store_vertex ( - h5_file_t* const f, /*!< file handle */ + h5t_mesh_t* const m, /*!< file handle */ const h5_glb_idx_t glb_id, /*!< global vertex id from mesher or -1 */ const h5_float64_t P[3] /*!< coordinates */ ) { - H5_CORE_API_ENTER3 (h5_loc_idx_t, - "f=0x%p, glb=id=%lld, P=0x%p", - f, - (long long)glb_id, - P); - h5t_fdata_t* const t = f->t; + H5_CORE_API_ENTER (h5_loc_idx_t, + "m=%p, glb=id=%lld, P=%p", + m, + (long long)glb_id, + P); /* more than allocated */ - if (t->last_stored_vid+1 >= t->num_vertices[t->leaf_level]) + if (m->last_stored_vid+1 >= m->num_vertices[m->leaf_level]) H5_CORE_API_LEAVE (HANDLE_H5_OVERFLOW_ERR( - t->num_vertices[t->leaf_level])); + m->num_vertices[m->leaf_level])); /* missing call to add the first level */ - if (t->leaf_level < 0) + if (m->leaf_level < 0) H5_CORE_API_LEAVE (h5tpriv_error_undef_level()); - h5_loc_idx_t local_idx = ++t->last_stored_vid; - h5_loc_vertex_t *vertex = &t->vertices[local_idx]; + h5_loc_idx_t local_idx = ++m->last_stored_vid; + h5_loc_vertex_t *vertex = &m->vertices[local_idx]; vertex->idx = glb_id; /* ID from mesher, replaced later!*/ memcpy (&vertex->P, P, sizeof (vertex->P)); H5_CORE_API_RETURN (local_idx); @@ -151,14 +131,13 @@ h5t_store_vertex ( h5_err_t h5t_end_store_vertices ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* const t = f->t; - - t->num_vertices[t->leaf_level] = t->last_stored_vid+1; - TRY (assign_global_vertex_indices (f)); - TRY (h5tpriv_rebuild_vertex_indices_mapping (f)); + H5_CORE_API_ENTER (h5_err_t, "m=%p", m); + + m->num_vertices[m->leaf_level] = m->last_stored_vid+1; + TRY (assign_global_vertex_indices (m)); + TRY (h5tpriv_rebuild_vertex_indices_mapping (m)); H5_CORE_API_RETURN (H5_SUCCESS); } @@ -170,28 +149,27 @@ h5t_end_store_vertices ( */ h5_err_t h5t_begin_store_elems ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_size_t num ) { - H5_CORE_API_ENTER2 (h5_err_t, - "f=0x%p, num=%llu", - f, (long long unsigned)num); - h5t_fdata_t* const t = f->t; + H5_CORE_API_ENTER (h5_err_t, + "m=%p, num=%llu", + m, (long long unsigned)num); - size_t cur = t->leaf_level > 0 ? t->num_elems[t->leaf_level-1] : 0; + size_t cur = m->leaf_level > 0 ? m->num_elems[m->leaf_level-1] : 0; size_t new = num + cur; - t->num_elems[t->leaf_level] = new; - t->dsinfo_elems.dims[0] = new; + m->num_elems[m->leaf_level] = new; + m->dsinfo_elems.dims[0] = new; - t->num_elems_on_leaf_level[t->leaf_level] = t->leaf_level > 0 ? - num + t->num_elems_on_leaf_level[t->leaf_level-1] : num; + m->num_leaf_elems[m->leaf_level] = m->leaf_level > 0 ? + num + m->num_leaf_elems[m->leaf_level-1] : num; /* We allocate a hash table for a minimum of 2^21 edges to avoid resizing. */ size_t nel = 2097152 > 5*new ? 2097152 : 5*new; - TRY (h5tpriv_resize_te_htab (f, nel)); - H5_CORE_API_RETURN (h5tpriv_alloc_elems (f, cur, new)); + TRY (h5tpriv_resize_te_htab (m, nel)); + H5_CORE_API_RETURN (h5tpriv_alloc_elems (m, cur, new)); } @@ -206,78 +184,76 @@ h5t_begin_store_elems ( */ h5_loc_idx_t h5t_store_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t parent_idx, const h5_loc_idx_t* vertex_indices ) { - H5_CORE_API_ENTER3 (h5_loc_idx_t, - "f=0x%p, parent_idx=%lld, vertex_indices=0x%p", - f, - (long long)parent_idx, - vertex_indices); - h5t_fdata_t* t = f->t; + H5_CORE_API_ENTER (h5_loc_idx_t, + "m=%p, parent_idx=%lld, vertex_indices=%p", + m, + (long long)parent_idx, + vertex_indices); /* level set? */ - if (t->leaf_level < 0) + if (m->leaf_level < 0) H5_CORE_API_LEAVE ( h5tpriv_error_undef_level()); /* more than allocated? */ - if ( t->last_stored_eid+1 >= t->num_elems[t->leaf_level] ) + if ( m->last_stored_eid+1 >= m->num_elems[m->leaf_level] ) H5_CORE_API_LEAVE ( - HANDLE_H5_OVERFLOW_ERR (t->num_elems[t->leaf_level])); + HANDLE_H5_OVERFLOW_ERR (m->num_elems[m->leaf_level])); /* check parent id */ - if ((t->leaf_level == 0 && parent_idx != -1) || - (t->leaf_level > 0 && parent_idx < 0) || - (t->leaf_level > 0 - && parent_idx >= t->num_elems[t->leaf_level-1]) + if ((m->leaf_level == 0 && parent_idx != -1) || + (m->leaf_level > 0 && parent_idx < 0) || + (m->leaf_level > 0 + && parent_idx >= m->num_elems[m->leaf_level-1]) ) { H5_CORE_API_LEAVE ( HANDLE_H5_PARENT_ID_ERR (parent_idx)); } /* store elem data (but neighbors) */ - h5_loc_idx_t elem_idx = ++t->last_stored_eid; - h5tpriv_set_loc_elem_parent_idx (f, elem_idx, parent_idx); - h5tpriv_set_loc_elem_child_idx (f, elem_idx, -1); - h5tpriv_set_loc_elem_level_idx (f, elem_idx, t->leaf_level); + h5_loc_idx_t elem_idx = ++m->last_stored_eid; + h5tpriv_set_loc_elem_parent_idx (m, elem_idx, parent_idx); + h5tpriv_set_loc_elem_child_idx (m, elem_idx, -1); + h5tpriv_set_loc_elem_level_idx (m, elem_idx, m->leaf_level); // get ptr to local vertices store h5_loc_idx_t* loc_vertex_indices = h5tpriv_get_loc_elem_vertex_indices ( - f, elem_idx); - int num_vertices = h5tpriv_ref_elem_get_num_vertices (t); + m, elem_idx); + int num_vertices = h5tpriv_ref_elem_get_num_vertices (m); memcpy (loc_vertex_indices, vertex_indices, sizeof (*vertex_indices)*num_vertices); - h5tpriv_sort_local_vertex_indices (f, loc_vertex_indices, num_vertices); + h5tpriv_sort_local_vertex_indices (m, loc_vertex_indices, num_vertices); /* add edges to map edges -> elements */ h5_loc_idx_t face_idx; - int num_faces = h5tpriv_ref_elem_get_num_edges (t); + int num_faces = h5tpriv_ref_elem_get_num_edges (m); for (face_idx = 0; face_idx < num_faces; face_idx++) { // add edges to neighbour struct - TRY (h5tpriv_search_te2 (f, face_idx, elem_idx, NULL)); + TRY (h5tpriv_search_te2 (m, face_idx, elem_idx, NULL)); } H5_CORE_API_RETURN (elem_idx); } h5_err_t h5t_end_store_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* const t = f->t; + H5_CORE_API_ENTER (h5_err_t, "m=%p", m); - t->num_elems[t->leaf_level] = t->last_stored_eid+1; + m->num_elems[m->leaf_level] = m->last_stored_eid+1; /* assign global indices to new indices */ - TRY (assign_glb_elem_indices (f)); + TRY (assign_glb_elem_indices (m)); /* rebuild map: global index -> local_index */ - TRY (h5tpriv_rebuild_elem_indices_mapping (f)); + TRY (h5tpriv_rebuild_elem_indices_mapping (m)); /* mesh specific finalize */ - TRY (t->methods.store->end_store_elems (f)); + TRY (m->methods.store->end_store_elems (m)); H5_CORE_API_RETURN (H5_SUCCESS); } @@ -287,21 +263,20 @@ h5t_end_store_elems ( */ h5_err_t h5t_mark_entity ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id ) { - H5_CORE_API_ENTER2 (h5_err_t, "f=0x%p, entity_id=%llu", - f, (long long unsigned)entity_id); - h5t_fdata_t* const t = f->t; - H5_CORE_API_RETURN (h5priv_insert_idlist (&t->marked_entities, entity_id, -1)); + H5_CORE_API_ENTER (h5_err_t, "m=%p, entity_id=%llu", + m, (long long unsigned)entity_id); + H5_CORE_API_RETURN (h5priv_insert_idlist (&m->marked_entities, entity_id, -1)); } h5_err_t h5t_pre_refine ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - H5_CORE_API_RETURN (f->t->methods.store->pre_refine (f)); + H5_CORE_API_ENTER (h5_err_t, "m=%p", m); + H5_CORE_API_RETURN (m->methods.store->pre_refine (m)); } /* @@ -309,51 +284,48 @@ h5t_pre_refine ( */ h5_err_t h5t_refine_marked_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* const t = f->t; + H5_CORE_API_ENTER (h5_err_t, "m=%p", m); int i; - for (i = 0; i < t->marked_entities->num_items; i++) { - TRY (h5tpriv_refine_elem (f, t->marked_entities->items[i])); + for (i = 0; i < m->marked_entities->num_items; i++) { + TRY (h5tpriv_refine_elem (m, m->marked_entities->items[i])); } H5_CORE_API_RETURN (H5_SUCCESS); } h5_err_t h5t_post_refine ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* const t = f->t; - TRY (h5t_end_store_vertices (f)); - TRY (h5t_end_store_elems (f)); - H5_CORE_API_RETURN (h5priv_free_idlist (&t->marked_entities)); + H5_CORE_API_ENTER (h5_err_t, "m=%p", m); + TRY (h5t_end_store_vertices (m)); + TRY (h5t_end_store_elems (m)); + H5_CORE_API_RETURN (h5priv_free_idlist (&m->marked_entities)); } h5_err_t h5t_begin_refine_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* const t = f->t; + H5_CORE_API_ENTER (h5_err_t, "m=%p", m); /* Pre-allocate space for items to avoid allocating small pieces of memory. */ - TRY (h5priv_alloc_idlist (&t->marked_entities, 2048)); + TRY (h5priv_alloc_idlist (&m->marked_entities, 2048)); H5_CORE_API_RETURN (H5_SUCCESS); } h5_err_t h5t_end_refine_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - TRY (h5t_pre_refine (f)); - TRY (h5t_refine_marked_elems (f)); - TRY (h5t_post_refine (f)); + H5_CORE_API_ENTER (h5_err_t, "m=%p", m); + TRY (h5t_pre_refine (m)); + TRY (h5t_refine_marked_elems (m)); + TRY (h5t_post_refine (m)); H5_CORE_API_RETURN (H5_SUCCESS); } @@ -361,19 +333,19 @@ h5t_end_refine_elems ( // index set for DUNE h5_err_t h5t_create_index_set ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_err_t, "m=%p", m); int codim; - int dim = h5tpriv_ref_elem_get_dim (f->t); + int dim = h5tpriv_ref_elem_get_dim (m); // todo: check tagset already exist - TRY (h5t_add_mtagset (f, "__IndexSet__", H5_INT64_T)); + TRY (h5t_add_mtagset (m, "__IndexSet__", H5_INT64_T)); for (codim = 0; codim <= dim; codim++) { h5_glb_idx_t idx = 0; h5t_leaf_iterator_t it; h5_glb_id_t entity_id; - TRY (h5t_init_leaf_iterator (f, (h5t_iterator_t*)&it, codim)); + TRY (h5t_init_leaf_iterator ((h5t_iterator_t*)&it, m, codim)); while ((entity_id = it.iter(f, (h5t_iterator_t*)&it)) >= 0) { TRY (h5t_set_mtag_by_name (f, "__IndexSet__", entity_id, 1, &idx)); } diff --git a/src/h5core/h5t_store_private.h b/src/h5core/h5t_store_private.h index 785c3f8..3078b29 100644 --- a/src/h5core/h5t_store_private.h +++ b/src/h5core/h5t_store_private.h @@ -2,44 +2,30 @@ #define __H5T_STOREMESH_PRIVATE_H struct h5t_store_methods { - h5_err_t (*alloc_elems)(h5_file_t* const, const size_t, const size_t); - h5_err_t (*pre_refine)(h5_file_t* const); - h5_loc_idx_t (*refine_elem)(h5_file_t* const, const h5_loc_idx_t); - h5_err_t (*end_store_elems)(h5_file_t* const); - h5_err_t (*get_direct_children_of_edge)( - h5_file_t* const, const h5_loc_idx_t, const h5_loc_idx_t, - h5_loc_id_t*); + h5_err_t (*alloc_elems)(h5t_mesh_t* const, const size_t, const size_t); + h5_err_t (*pre_refine)(h5t_mesh_t* const); + h5_loc_idx_t (*refine_elem)(h5t_mesh_t* const, const h5_loc_idx_t); + h5_err_t (*end_store_elems)(h5t_mesh_t* const); }; extern struct h5t_store_methods h5tpriv_trim_store_methods; extern struct h5t_store_methods h5tpriv_tetm_store_methods; -static inline h5_err_t -h5tpriv_get_direct_children_of_edge ( - h5_file_t* const f, - h5_loc_idx_t face_idx, - h5_loc_idx_t elem_idx, - h5_loc_id_t children[2] - ) { - return (*f->t->methods.store->get_direct_children_of_edge) ( - f, face_idx, elem_idx, children); -} - static inline h5_err_t h5tpriv_alloc_elems ( - h5_file_t* const f, + h5t_mesh_t* const m, const size_t cur, const size_t new ) { - return (*f->t->methods.store->alloc_elems) (f, cur, new); + return (*m->methods.store->alloc_elems) (m, cur, new); } static inline h5_loc_idx_t h5tpriv_refine_elem ( - h5_file_t * const f, + h5t_mesh_t * const m, const h5_loc_idx_t elem_idx ) { - return (*f->t->methods.store->refine_elem)(f, elem_idx); + return (*m->methods.store->refine_elem)(m, elem_idx); } #endif diff --git a/src/h5core/h5t_store_tetm.c b/src/h5core/h5t_store_tetm.c index a5b28de..1314443 100644 --- a/src/h5core/h5t_store_tetm.c +++ b/src/h5core/h5t_store_tetm.c @@ -5,61 +5,27 @@ static h5_err_t alloc_tets ( - h5_file_t* const f, + h5t_mesh_t* const m, const size_t cur, const size_t new ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t *t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, cur=%zu, new=%zu", m, cur, new); /* alloc mem for local data of elements */ - TRY ( t->loc_elems.tets = h5_alloc ( - t->loc_elems.tets, - new * sizeof (t->loc_elems.tets[0]) ) ); + TRY ( m->loc_elems.tets = h5_alloc ( + m->loc_elems.tets, + new * sizeof (m->loc_elems.tets[0]) ) ); memset ( - t->loc_elems.tets + cur, + m->loc_elems.tets + cur, -1, - (new-cur) * sizeof (t->loc_elems.tets[0]) ); + (new-cur) * sizeof (m->loc_elems.tets[0]) ); /* alloc mem for global to local ID mapping */ - TRY (h5priv_alloc_idxmap (&t->map_elem_g2l, new)); + TRY (h5priv_alloc_idxmap (&m->map_elem_g2l, new)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } -/* - Return the two direct children of the edge given by face and - element index of first child. - Note: the semantic of elem_idx is a bit confusing. - - */ -static h5_err_t -get_direct_children_of_edge ( - h5_file_t* const f, - h5_loc_idx_t face_idx, - h5_loc_idx_t elem_idx, - h5_loc_id_t children[2] - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - /* - Please read the note about the offsets in the corresponding file - for triangle meshes. - */ - int offs[6][2] = { {0,1}, // edge 0 - {0,2}, // edge 1 - {1,2}, // edge 2 - {0,3}, // edge 3 - {1,3}, // edge 4 - {2,3} // edge 5 - }; - h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (f->t); - if ((face_idx < 0) || (face_idx >= num_faces)) { - H5_PRIV_FUNC_LEAVE (h5_error_internal ()); - } - children[0] = h5tpriv_build_edge_id (face_idx, elem_idx+offs[face_idx][0]); - children[1] = h5tpriv_build_edge_id (face_idx, elem_idx+offs[face_idx][1]); - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} /*! Refine edge. Store vertex, if new. @@ -70,44 +36,34 @@ get_direct_children_of_edge ( */ static h5_loc_idx_t bisect_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t face_idx, const h5_loc_idx_t elem_idx ) { - H5_PRIV_FUNC_ENTER (h5_loc_idx_t); - h5t_fdata_t* t = f->t; - h5_loc_idlist_t* retval; + H5_PRIV_FUNC_ENTER (h5_loc_idx_t, + "m=%p, face_idx=%d, elem_idx=%d", + m, face_idx, elem_idx); + h5_loc_idlist_t* retval; /* get all elements sharing the given edge */ - TRY( h5tpriv_find_te2 (f, face_idx, elem_idx, &retval) ); + TRY (h5tpriv_find_te2 (m, face_idx, elem_idx, &retval)); /* check wether one of the found elements has been refined */ size_t i; for (i = 0; i < retval->num_items; i++) { - h5_loc_idx_t idx = h5tpriv_get_elem_idx (retval->items[i]); - h5_loc_idx_t child_idx = h5tpriv_get_loc_elem_child_idx (f, idx); - if (child_idx >= 0) { - /* - this element has been refined! - return bisecting point - */ - h5_loc_idx_t face_id = h5tpriv_get_face_idx ( - retval->items[i]); - h5_loc_id_t kids[2]; + h5_loc_id_t kids[2] = {-1,-1}; + TRY (h5tpriv_get_loc_entity_children (m, retval->items[i], kids)); + if (kids[0] >= 0) { + // element has been refined, return bisecting point h5_loc_idx_t edge0[2], edge1[2]; - TRY( get_direct_children_of_edge ( - f, - face_id, - child_idx, - kids) ); - TRY( h5t_get_vertex_indices_of_edge (f, kids[0], edge0) ); - TRY( h5t_get_vertex_indices_of_edge (f, kids[1], edge1) ); + TRY( h5t_get_vertex_indices_of_edge (m, kids[0], edge0) ); + TRY( h5t_get_vertex_indices_of_edge (m, kids[1], edge1) ); if ((edge0[0] == edge1[0]) || (edge0[0] == edge1[1])) { - H5_PRIV_FUNC_LEAVE (edge0[0]); // return idx of first vertex of edge + H5_PRIV_FUNC_LEAVE (edge0[0]); // return first vertex } else { - H5_PRIV_FUNC_LEAVE (edge0[1]); // return idx of second vertex of edge + H5_PRIV_FUNC_LEAVE (edge0[1]); // return second vertex } } } @@ -115,16 +71,16 @@ bisect_edge ( None of the elements has been refined -> add new vertex. */ h5_loc_idx_t indices[2]; - TRY( h5t_get_vertex_indices_of_edge2 (f, face_idx, elem_idx, indices) ); - h5_float64_t* P0 = t->vertices[indices[0]].P; - h5_float64_t* P1 = t->vertices[indices[1]].P; + TRY( h5t_get_vertex_indices_of_edge2 (m, face_idx, elem_idx, indices) ); + h5_float64_t* P0 = m->vertices[indices[0]].P; + h5_float64_t* P1 = m->vertices[indices[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; - H5_PRIV_FUNC_RETURN (h5t_store_vertex (f, -1, P)); // return idx of new vertex + H5_PRIV_FUNC_RETURN (h5t_store_vertex (m, -1, P)); // return idx of new vertex } /* @@ -150,30 +106,31 @@ bisect_edge ( */ static h5_err_t pre_refine_tet ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - unsigned int num_elems_to_refine = f->t->marked_entities->num_items; - TRY (h5t_begin_store_vertices (f, num_elems_to_refine*3 + 192)); - TRY (h5t_begin_store_elems (f, num_elems_to_refine*8)); - H5_CORE_API_RETURN (H5_SUCCESS); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + unsigned int num_elems_to_refine = m->marked_entities->num_items; + TRY (h5t_begin_store_vertices (m, num_elems_to_refine*3 + 192)); + TRY (h5t_begin_store_elems (m, num_elems_to_refine*8)); + H5_PRIV_FUNC_RETURN (H5_SUCCESS); } /*! - Refine tetrahedron \c elem_idx + Refine tetrahedron \c elem_idx. This function implements a "red refinement" + as described by J. Bey in "Tetrahedral grid refinement", Computing 55 + (1995), pp. 355-378 \return Local id of first new tetrahedron or \c -1 */ static h5_loc_idx_t refine_tet ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - H5_PRIV_FUNC_ENTER (h5_loc_idx_t); - h5t_fdata_t* t = f->t; + H5_PRIV_FUNC_ENTER (h5_loc_idx_t, "m=%p, elem_idx=%d", m, elem_idx); h5_loc_idx_t vertices[10]; h5_loc_idx_t elem_idx_of_first_child; - h5_loc_tet_t* el = &t->loc_elems.tets[elem_idx]; + h5_loc_tet_t* el = &m->loc_elems.tets[elem_idx]; if ( el->child_idx >= 0 ) H5_PRIV_FUNC_LEAVE ( @@ -186,86 +143,92 @@ refine_tet ( vertices[2] = el->vertex_indices[2]; vertices[3] = el->vertex_indices[3]; - vertices[4] = bisect_edge (f, 0, elem_idx); - vertices[5] = bisect_edge (f, 1, elem_idx); - vertices[6] = bisect_edge (f, 3, elem_idx); - vertices[7] = bisect_edge (f, 2, elem_idx); - vertices[8] = bisect_edge (f, 4, elem_idx); - vertices[9] = bisect_edge (f, 5, elem_idx); + vertices[4] = bisect_edge (m, 0, elem_idx); // edge (0,1) + vertices[5] = bisect_edge (m, 1, elem_idx); // edge (0,2) + vertices[6] = bisect_edge (m, 2, elem_idx); // edge (1,2) + vertices[7] = bisect_edge (m, 3, elem_idx); // edge (0,3) + vertices[8] = bisect_edge (m, 4, elem_idx); // edge (1,3) + vertices[9] = bisect_edge (m, 5, elem_idx); // edge (2,3) - /* - add new tets - */ + // add new tets h5_loc_idx_t new_elem[4]; - new_elem[0] = vertices[0]; // child 0 - new_elem[1] = vertices[4]; - new_elem[2] = vertices[5]; - new_elem[3] = vertices[6]; - TRY( elem_idx_of_first_child = h5t_store_elem (f, elem_idx, new_elem) ); + // child 0 + new_elem[0] = vertices[0]; // vertex 0 + new_elem[1] = vertices[4]; // split point (0,1) + new_elem[2] = vertices[5]; // split point (0,2) + new_elem[3] = vertices[7]; // split point (0,3) + TRY( elem_idx_of_first_child = h5t_store_elem (m, elem_idx, new_elem) ); - new_elem[0] = vertices[4]; // child 1 - new_elem[1] = vertices[1]; - new_elem[2] = vertices[7]; - new_elem[3] = vertices[8]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + // child 1 + new_elem[0] = vertices[4]; // split point (0,1) + new_elem[1] = vertices[1]; // vertex 1 + new_elem[2] = vertices[6]; // split point (1,2) + new_elem[3] = vertices[8]; // split point (1,3) + TRY( h5t_store_elem (m, elem_idx, new_elem) ); - new_elem[0] = vertices[5]; // child 2 - new_elem[1] = vertices[7]; - new_elem[2] = vertices[2]; - new_elem[3] = vertices[9]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + // child 2 + new_elem[0] = vertices[5]; // split point (0,2) + new_elem[1] = vertices[6]; // split point (1,2) + new_elem[2] = vertices[2]; // vertex 2 + new_elem[3] = vertices[9]; // split point (2,3) + TRY( h5t_store_elem (m, elem_idx, new_elem) ); - new_elem[0] = vertices[6]; // child 3 - new_elem[1] = vertices[8]; - new_elem[2] = vertices[9]; - new_elem[3] = vertices[3]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + // child 3 + new_elem[0] = vertices[7]; // split point (0,3) + new_elem[1] = vertices[8]; // split point (1,3) + new_elem[2] = vertices[9]; // split point (2,3) + new_elem[3] = vertices[3]; // vertex 3 + TRY( h5t_store_elem (m, elem_idx, new_elem) ); - new_elem[0] = vertices[4]; // child 4 - new_elem[1] = vertices[5]; - new_elem[2] = vertices[6]; - new_elem[3] = vertices[8]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + // child 4 + new_elem[0] = vertices[4]; // split point (0,1) + new_elem[1] = vertices[5]; // split point (0,2) + new_elem[2] = vertices[6]; // split point (1,2) + new_elem[3] = vertices[8]; // split point (1,3) + TRY( h5t_store_elem (m, elem_idx, new_elem) ); - new_elem[0] = vertices[4]; // child 5 - new_elem[1] = vertices[5]; - new_elem[2] = vertices[7]; - new_elem[3] = vertices[8]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + // child 5 + new_elem[0] = vertices[4]; // split point (0,1) + new_elem[1] = vertices[5]; // split point (0,2) + new_elem[2] = vertices[7]; // split point (0,3) + new_elem[3] = vertices[8]; // split point (1,3) + TRY( h5t_store_elem (m, elem_idx, new_elem) ); - new_elem[0] = vertices[5]; // child 6 - new_elem[1] = vertices[7]; - new_elem[2] = vertices[8]; - new_elem[3] = vertices[9]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + // child 6 + new_elem[0] = vertices[5]; // split point (0,2) + new_elem[1] = vertices[6]; // split point (1,2) + new_elem[2] = vertices[8]; // split point (1,3) + new_elem[3] = vertices[9]; // split point (2,3) + TRY( h5t_store_elem (m, elem_idx, new_elem) ); - new_elem[0] = vertices[5]; // child 7 - new_elem[1] = vertices[6]; - new_elem[2] = vertices[8]; - new_elem[3] = vertices[9]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + // child 7 + new_elem[0] = vertices[5]; // split point (0,2) + new_elem[1] = vertices[7]; // split point (0,3) + new_elem[2] = vertices[8]; // split point (1,3) + new_elem[3] = vertices[9]; // split point (2,3) + TRY( h5t_store_elem (m, elem_idx, new_elem) ); - t->loc_elems.tets[elem_idx].child_idx = elem_idx_of_first_child; - t->num_elems_on_leaf_level[t->leaf_level]--; + m->loc_elems.tets[elem_idx].child_idx = elem_idx_of_first_child; + m->num_leaf_elems[m->leaf_level]--; H5_PRIV_FUNC_RETURN (elem_idx_of_first_child); } static inline h5_loc_idx_t compute_neighbor_of_face ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - H5_PRIV_FUNC_ENTER (h5_loc_idx_t); - h5t_fdata_t * const t = f->t; + H5_PRIV_FUNC_ENTER (h5_loc_idx_t, "m=%p, elem_idx=%d, face_idx=%d", + m, elem_idx, face_idx); h5_loc_idlist_t* td; h5_loc_idx_t neighbor_idx = -2; do { TRY( h5tpriv_find_td2 ( - f, + m, face_idx, elem_idx, &td) ); @@ -274,7 +237,7 @@ compute_neighbor_of_face ( } if (td->num_items == 1) { // neighbor is coarser or face is on the boundary - elem_idx = t->loc_elems.tets[elem_idx].parent_idx; + elem_idx = m->loc_elems.tets[elem_idx].parent_idx; if (elem_idx == -1) { // we are on the level of the macro grid neighbor_idx = -1; @@ -299,28 +262,27 @@ compute_neighbor_of_face ( */ static inline h5_err_t compute_neighbors_of_elems ( - h5_file_t* const f, + h5t_mesh_t* const m, h5t_lvl_idx_t level ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t * const t = f->t; - if (level < 0 || level >= t->num_leaf_levels) { + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, level=%d", m, level); + if (level < 0 || level >= m->num_leaf_levels) { H5_PRIV_FUNC_LEAVE ( h5_error ( H5_ERR_INVAL, "level idx %lld out of bound, must be in [%lld,%lld]", (long long)level, (long long)0, - (long long)t->num_leaf_levels)); + (long long)m->num_leaf_levels)); } - h5_loc_idx_t elem_idx = level == 0 ? 0 : t->num_elems[level-1]; - const h5_loc_idx_t last_idx = t->num_elems[level] - 1; - h5_loc_tet_t *el = &t->loc_elems.tets[elem_idx]; + h5_loc_idx_t elem_idx = level == 0 ? 0 : m->num_elems[level-1]; + const h5_loc_idx_t last_idx = m->num_elems[level] - 1; + h5_loc_tet_t *el = &m->loc_elems.tets[elem_idx]; while (elem_idx <= last_idx) { h5_loc_idx_t face_idx = 0; for (; face_idx < 4; face_idx++) { el->neighbor_indices[face_idx] = - compute_neighbor_of_face (f, elem_idx, face_idx); + compute_neighbor_of_face (m, elem_idx, face_idx); } elem_idx++; el++; @@ -331,13 +293,12 @@ compute_neighbors_of_elems ( static h5_err_t end_store_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* const t = f->t; - TRY( h5tpriv_update_adjacency_structs (f, t->leaf_level) ); - TRY( compute_neighbors_of_elems (f, t->leaf_level) ); - TRY( h5tpriv_init_geom_boundary_info (f, t->leaf_level) ); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + TRY( h5tpriv_update_adjacency_structs (m, m->leaf_level) ); + TRY( compute_neighbors_of_elems (m, m->leaf_level) ); + TRY( h5tpriv_init_geom_boundary_info (m, m->leaf_level) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -346,5 +307,4 @@ struct h5t_store_methods h5tpriv_tetm_store_methods = { pre_refine_tet, refine_tet, end_store_elems, - get_direct_children_of_edge }; diff --git a/src/h5core/h5t_store_trim.c b/src/h5core/h5t_store_trim.c index 62c5ff8..850da24 100644 --- a/src/h5core/h5t_store_trim.c +++ b/src/h5core/h5t_store_trim.c @@ -5,98 +5,51 @@ static h5_err_t alloc_triangles ( - h5_file_t * const f, + h5t_mesh_t* const m, const size_t cur, const size_t new ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t *t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, cur=%zu, new=%zu", m, cur, new); /* alloc mem for local data of elements */ - TRY ( t->loc_elems.tris = h5_alloc ( - t->loc_elems.tris, - new * sizeof (t->loc_elems.tris[0]) ) ); + TRY ( m->loc_elems.tris = h5_alloc ( + m->loc_elems.tris, + new * sizeof (m->loc_elems.tris[0]) ) ); memset ( - t->loc_elems.tris + cur, + m->loc_elems.tris + cur, -1, - (new-cur) * sizeof (t->loc_elems.tris[0]) ); + (new-cur) * sizeof (m->loc_elems.tris[0]) ); /* alloc mem for global to local ID mapping */ - TRY (h5priv_alloc_idxmap (&t->map_elem_g2l, new)); + TRY (h5priv_alloc_idxmap (&m->map_elem_g2l, new)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } -static h5_err_t -get_direct_children_of_edge ( - h5_file_t * const f, - const h5_loc_idx_t face_idx, - const h5_loc_idx_t elem_idx, - h5_loc_id_t children[2] - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - /* - Please note: The face index of the children and the father is - always the same. The only think we have to know, is the offset - to the element index of the first child. This is either 0, 1 or - 2. The third child is an "inner" child which doesn't superpose edges - of the parent. - - The direct children of edge 0 of an element are edge 0 of the - first child and edge 0 of the second child, giving the offset 0 - and 1 for this edge. - */ - int off[3][2] = { {0,1}, // edge 0 - {0,2}, // edge 1 - {1,2} // edge 2 - }; - h5_loc_idx_t num_faces = h5tpriv_ref_elem_get_num_edges (f->t); - if ((face_idx < 0) || (face_idx >= num_faces)) { - H5_PRIV_FUNC_LEAVE (h5_error_internal ()); - } - children[0] = h5tpriv_build_edge_id (face_idx, elem_idx+off[face_idx][0]); - children[1] = h5tpriv_build_edge_id (face_idx, elem_idx+off[face_idx][1]); - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - /* Bisect edge and return local vertex index of the bisecting point. */ static h5_loc_idx_t bisect_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t face_idx, const h5_loc_idx_t elem_idx ) { - H5_PRIV_FUNC_ENTER (h5_loc_idx_t); - h5t_fdata_t* const t = f->t; + H5_PRIV_FUNC_ENTER (h5_loc_idx_t, "m=%p, face_idx=%d, elem_idx=%d", + m, face_idx, elem_idx); h5_loc_idlist_t* retval; - /* - get all elements sharing the given edge - */ - TRY( h5tpriv_find_te2 (f, face_idx, elem_idx, &retval) ); - /* - check wether one of the found elements has been refined - */ + // get all elements sharing the given edge + TRY (h5tpriv_find_te2 (m, face_idx, elem_idx, &retval)); + // check wether one of the found elements has been refined size_t i; for (i = 0; i < retval->num_items; i++) { - h5_loc_idx_t idx = h5tpriv_get_elem_idx (retval->items[i]); - h5_loc_idx_t child_idx = h5tpriv_get_loc_elem_child_idx (f, idx); - if (child_idx >= 0) { - /* - this element has been refined! - return bisecting point - */ - h5_loc_id_t kids[2]; - TRY( get_direct_children_of_edge ( - f, - h5tpriv_get_face_idx (retval->items[i]), - child_idx, - kids ) ); - + h5_loc_id_t kids[2] = {-1,-1}; + TRY (h5tpriv_get_loc_entity_children (m, retval->items[i], kids)); + if (kids[0] >= 0) { + // element has been refined, return bisecting point h5_loc_idx_t edge0[2], edge1[2]; - TRY( h5t_get_vertex_indices_of_edge ( f, kids[0], edge0 ) ); - TRY( h5t_get_vertex_indices_of_edge ( f, kids[1], edge1 ) ); + TRY (h5t_get_vertex_indices_of_edge (m, kids[0], edge0)); + TRY (h5t_get_vertex_indices_of_edge (m, kids[1], edge1)); if ((edge0[0] == edge1[0]) || (edge0[0] == edge1[1])) { H5_PRIV_FUNC_LEAVE (edge0[0]); } else { @@ -108,16 +61,16 @@ bisect_edge ( None of the elements has been refined -> add new vertex. */ h5_loc_idx_t indices[2]; - TRY( h5t_get_vertex_indices_of_edge2 (f, face_idx, elem_idx, indices) ); - h5_float64_t* P0 = t->vertices[indices[0]].P; - h5_float64_t* P1 = t->vertices[indices[1]].P; + TRY( h5t_get_vertex_indices_of_edge2 (m, face_idx, elem_idx, indices) ); + h5_float64_t* P0 = m->vertices[indices[0]].P; + h5_float64_t* P1 = m->vertices[indices[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; - H5_PRIV_FUNC_RETURN (h5t_store_vertex (f, -1, P)); + H5_PRIV_FUNC_RETURN (h5t_store_vertex (m, -1, P)); } /* @@ -126,13 +79,13 @@ bisect_edge ( */ static h5_err_t pre_refine_triangle ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_CORE_API_ENTER1 (h5_err_t, "f=0x%p", f); - unsigned int num_elems_to_refine = f->t->marked_entities->num_items; - TRY (h5t_begin_store_vertices (f, num_elems_to_refine*2 + 64)); - TRY (h5t_begin_store_elems (f, num_elems_to_refine*4)); - H5_CORE_API_RETURN (H5_SUCCESS); + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); + unsigned int num_elems_to_refine = m->marked_entities->num_items; + TRY (h5t_begin_store_vertices (m, num_elems_to_refine*2 + 64)); + TRY (h5t_begin_store_elems (m, num_elems_to_refine*4)); + H5_PRIV_FUNC_RETURN (H5_SUCCESS); } /*! @@ -142,14 +95,13 @@ pre_refine_triangle ( */ static h5_loc_idx_t refine_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t elem_idx ) { - H5_PRIV_FUNC_ENTER (h5_loc_idx_t); - h5t_fdata_t* const t = f->t; + H5_PRIV_FUNC_ENTER (h5_loc_idx_t, "m=%p, elem_idx=%d", m, elem_idx); h5_loc_idx_t vertices[6]; // local vertex indices h5_loc_idx_t elem_idx_of_first_child; - h5_loc_triangle_t* el = &t->loc_elems.tris[elem_idx]; + h5_loc_triangle_t* el = &m->loc_elems.tris[elem_idx]; if (el->child_idx >= 0) H5_PRIV_FUNC_LEAVE ( @@ -162,52 +114,52 @@ refine_triangle ( vertices[1] = el->vertex_indices[1]; vertices[2] = el->vertex_indices[2]; - vertices[3] = bisect_edge (f, 0, elem_idx); - vertices[4] = bisect_edge (f, 1, elem_idx); - vertices[5] = bisect_edge (f, 2, elem_idx); + vertices[3] = bisect_edge (m, 0, elem_idx); + vertices[4] = bisect_edge (m, 1, elem_idx); + vertices[5] = bisect_edge (m, 2, elem_idx); h5_loc_idx_t new_elem[3]; new_elem[0] = vertices[0]; // V[0] < V[3] , V[4] new_elem[1] = vertices[3]; new_elem[2] = vertices[4]; - TRY( elem_idx_of_first_child = h5t_store_elem (f, elem_idx, new_elem) ); + TRY( elem_idx_of_first_child = h5t_store_elem (m, elem_idx, new_elem) ); new_elem[0] = vertices[3]; // V[3] < V[1] , V[5] new_elem[1] = vertices[1]; new_elem[2] = vertices[5]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + TRY( h5t_store_elem (m, elem_idx, new_elem) ); new_elem[0] = vertices[4]; // V[4] < V[5] , V[2] new_elem[1] = vertices[5]; new_elem[2] = vertices[2]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + TRY( h5t_store_elem (m, elem_idx, new_elem) ); new_elem[0] = vertices[3]; // V[3] < V[4] , V[5] new_elem[1] = vertices[4]; new_elem[2] = vertices[5]; - TRY( h5t_store_elem (f, elem_idx, new_elem) ); + TRY( h5t_store_elem (m, elem_idx, new_elem) ); - t->loc_elems.tris[elem_idx].child_idx = elem_idx_of_first_child; - t->num_elems_on_leaf_level[t->leaf_level]--; + m->loc_elems.tris[elem_idx].child_idx = elem_idx_of_first_child; + m->num_leaf_elems[m->leaf_level]--; H5_PRIV_FUNC_RETURN (elem_idx_of_first_child); } static inline h5_loc_idx_t compute_neighbor_of_face ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t elem_idx, const h5_loc_idx_t face_idx ) { - H5_PRIV_FUNC_ENTER (h5_loc_idx_t); - h5t_fdata_t * const t = f->t; + H5_PRIV_FUNC_ENTER (h5_loc_idx_t, "m=%p, elem_idx=%d, face_idx=%d", + m, elem_idx, face_idx); h5_loc_idlist_t* te; h5_loc_idx_t neighbor_idx = -2; do { TRY( h5tpriv_find_te2 ( - f, + m, face_idx, elem_idx, &te) ); @@ -216,7 +168,7 @@ compute_neighbor_of_face ( } if (te->num_items == 1) { // neighbor is coarser or face is on the boundary - elem_idx = t->loc_elems.tris[elem_idx].parent_idx; + elem_idx = m->loc_elems.tris[elem_idx].parent_idx; if (elem_idx == -1) { // we are on the level of the macro grid neighbor_idx = -1; @@ -241,28 +193,27 @@ compute_neighbor_of_face ( */ static inline h5_err_t compute_neighbors_of_elems ( - h5_file_t* const f, + h5t_mesh_t* const m, h5t_lvl_idx_t level ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t * const t = f->t; - if (level < 0 || level >= t->num_leaf_levels) { + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p, level=%d", m, level); + if (level < 0 || level >= m->num_leaf_levels) { H5_PRIV_FUNC_LEAVE ( h5_error ( H5_ERR_INVAL, "level idx %lld out of bound, must be in [%lld,%lld]", (long long)level, (long long)0, - (long long)t->num_leaf_levels)); + (long long)m->num_leaf_levels)); } - h5_loc_idx_t elem_idx = level == 0 ? 0 : t->num_elems[level-1]; - const h5_loc_idx_t last_idx = t->num_elems[level] - 1; - h5_loc_triangle_t *el = &t->loc_elems.tris[elem_idx]; + h5_loc_idx_t elem_idx = level == 0 ? 0 : m->num_elems[level-1]; + const h5_loc_idx_t last_idx = m->num_elems[level] - 1; + h5_loc_triangle_t *el = &m->loc_elems.tris[elem_idx]; while (elem_idx <= last_idx) { h5_loc_idx_t face_idx = 0; for (; face_idx < 3; face_idx++) { el->neighbor_indices[face_idx] = - compute_neighbor_of_face (f, elem_idx, face_idx); + compute_neighbor_of_face (m, elem_idx, face_idx); } elem_idx++; el++; @@ -273,14 +224,13 @@ compute_neighbors_of_elems ( static h5_err_t end_store_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "m=%p", m); - TRY( h5tpriv_update_adjacency_structs (f, t->leaf_level) ); - TRY( compute_neighbors_of_elems (f, t->leaf_level) ); - TRY( h5tpriv_init_geom_boundary_info (f, t->leaf_level) ); + TRY( h5tpriv_update_adjacency_structs (m, m->leaf_level) ); + TRY( compute_neighbors_of_elems (m, m->leaf_level) ); + TRY( h5tpriv_init_geom_boundary_info (m, m->leaf_level) ); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } @@ -289,5 +239,4 @@ struct h5t_store_methods h5tpriv_trim_store_methods = { pre_refine_triangle, refine_triangle, end_store_elems, - get_direct_children_of_edge }; diff --git a/src/h5core/h5t_tags.c b/src/h5core/h5t_tags.c index 2da0f9e..5d4b6fb 100644 --- a/src/h5core/h5t_tags.c +++ b/src/h5core/h5t_tags.c @@ -1,147 +1,149 @@ - #include #include "h5core/h5_core.h" #include "h5_core_private.h" -/* - TODO: - - read tagsets on demand - */ - -/* - Release a tag-set - */ -static inline h5_err_t -release_tagset ( - h5t_tagset_t* tagset - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - unsigned int i; - // release per element structures - for (i = 0; i < tagset->num_elems; i++) { - if (tagset->elems[i] != NULL) { - TRY (h5_free (tagset->elems[i])); - } - } - // release other memory - TRY (h5_free (tagset->name)); - TRY (h5_free (tagset->values)); - TRY (h5_free (tagset)); - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - -/* - Release a tagset. Special version for releasing a container. - */ -static h5_err_t -release_tagset2 ( - const void* __tagset - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_tagset_t* tagset = *(h5t_tagset_t**)__tagset; - H5_PRIV_FUNC_RETURN (release_tagset (tagset)); -} - - -/* - Initialize a tag container - */ -static inline h5_err_t -init_container ( - const size_t ntags, - h5t_tagcontainer_t* ctn - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - TRY (ctn->names = h5_calloc (ntags, sizeof(char*))); - TRY (h5priv_hcreate_string_keyed (ntags, &ctn->sets, - release_tagset2)); - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - -/* - Release all sets in given container - */ -static inline h5_err_t -release_container ( - h5t_tagcontainer_t* ctn - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - if (ctn->num_sets == 0) - H5_PRIV_FUNC_LEAVE (H5_SUCCESS); - TRY (h5priv_hdestroy (&ctn->sets)); - TRY (h5_free (ctn->names)); - memset (ctn, 0, sizeof (*ctn)); - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - -/* - Release all tagsets -*/ -h5_err_t -h5tpriv_release_tags ( - h5_file_t* const f - ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - TRY (release_container (&t->mtags)); - H5_PRIV_API_RETURN (H5_SUCCESS); -} - -static inline h5_err_t -tagset_exists ( - h5t_tagcontainer_t* ctn, - char* name - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_tagset_t tagset; - tagset.name = name; - H5_PRIV_FUNC_RETURN (h5priv_hsearch (&tagset,H5_FIND,NULL,&ctn->sets)); -} - -h5_err_t -h5t_mtagset_exists ( +static hid_t +open_space_all ( h5_file_t* const f, - h5t_tagcontainer_t* ctn, - char* name + const hid_t dataset_id ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, ctn=0x%p, name=\"%s\"", - f, ctn, name); - H5_CORE_API_RETURN (tagset_exists (&f->t->mtags, name)); + UNUSED_ARGUMENT (f); + UNUSED_ARGUMENT (dataset_id); + return H5S_ALL; } /*! - Add tag to current mesh. + Get number of tagsets + */ +h5_ssize_t +h5t_get_num_mtagsets ( + h5t_mesh_t* const m + ) { + H5_CORE_API_ENTER (h5_ssize_t, "m=%p", m); + h5_ssize_t num_mtagsets = 0; + h5_err_t exists = 0; + TRY (exists = h5priv_link_exists (m->mesh_gid, "Tags")); + if (!exists) H5_CORE_API_LEAVE (0); - \param[in] f File handle - \param[in] name name of tag - \param[in] type type - \param[out] tag pointer to tag object if != 0 + hid_t loc_id; + TRY (loc_id = h5priv_open_group (0, m->mesh_gid, "Tags")); + TRY (num_mtagsets = hdf5_get_num_groups (loc_id)); + TRY (hdf5_close_group (loc_id)); + + H5_CORE_API_RETURN (num_mtagsets); + +} - \return H5_SUCCESS or error code -*/ static h5_err_t -add_tagset ( - h5_file_t* const f, - h5t_tagcontainer_t* ctn, - char* name, +get_tagset_info ( + const hid_t loc_id, + const h5_size_t idx, + char name[], + const h5_size_t len_name, + h5_int64_t* const type + ) { + H5_PRIV_FUNC_ENTER (h5_err_t, + "loc_id=%d, idx=%llu, name=%p, len_name=%llu, type=%p", + loc_id, (long long unsigned)idx, name, + (long long unsigned)len_name, type); + + hid_t tags_id, tag_id, dset_id; + // open ctn with all tags + TRY (tags_id = hdf5_open_group (loc_id, "Tags")); + // get name of tag given by idx + TRY (hdf5_get_name_of_group_by_idx (tags_id, idx, name, len_name)); + // open this tag + TRY (tag_id = hdf5_open_group (tags_id, name)); + // determine type of dataset with values + TRY (dset_id = hdf5_open_dataset (tag_id, "values")); + hid_t type_; + TRY (type_ = hdf5_get_dataset_type (dset_id)); + TRY (*type = h5_normalize_h5_type (type_)); + + TRY (hdf5_close_dataset (dset_id)); + TRY (hdf5_close_group (tag_id)); + TRY (hdf5_close_group (tags_id)); + H5_PRIV_FUNC_RETURN (H5_SUCCESS); +} + +/*! + Get information about tagset given by index: + name + type + */ +h5_err_t +h5t_get_mtagset_info ( + h5t_mesh_t* const m, + const h5_size_t idx, + char name[], + const h5_size_t len_name, + h5_int64_t* const type + ) { + H5_CORE_API_ENTER (h5_err_t, + "m=%p, idx=%llu, name=%p, len_name=%llu, type=%p", + m, (long long unsigned)idx, name, + (long long unsigned)len_name, type); + + + H5_CORE_API_RETURN (get_tagset_info(m->mesh_gid, idx, name, len_name, type)); +} + +/*! + Check whether taget exists. + */ +h5_err_t +h5t_mtagset_exists ( + h5t_mesh_t* const m, + const char name[] + ) { + H5_CORE_API_ENTER (h5_err_t, "m=%p, name=%s", m, name); + H5_CORE_API_RETURN (h5priv_link_exists (m->mesh_gid, "Tags", name)); +} + +static h5_err_t +new_tagset ( + h5t_mesh_t* const m, + hid_t parent_gid, + const char name[], h5_id_t type, h5t_tagset_t** rtagset ) { - H5_PRIV_FUNC_ENTER5 (h5_err_t, - "f=0x%p, ctn=0x%p, name=\"%s\", type=%llu, rtagset=0x%p", - f, ctn, name, - (long long unsigned)type, - rtagset); - h5t_fdata_t* t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, + "m=%p, name='%s', type=%llu, rtagset=%p", + m, name, (long long unsigned)type, rtagset); - // Initialize data structure for m-tagsets, if not already done. - if (ctn->names == NULL) { - TRY (init_container (521, ctn)); - } - // TODO: Resize if we have more then 80% of 521 filled! + h5t_tagset_t* tagset = NULL; + size_t size = (m->num_elems[m->num_leaf_levels-1] - 1) * sizeof(*tagset->elems) + + sizeof(*tagset); + TRY (tagset = h5_calloc (1, size)); + TRY (tagset->name = h5_strdup (name)); + tagset->m = m; + tagset->parent_gid = parent_gid; + tagset->type = type; + tagset->num_elems = m->num_elems[m->num_leaf_levels-1]; + tagset->scope.min_level = 32767; + tagset->scope.max_level = -1; + TRY (h5priv_search_strlist (&m->mtagsets, name)); + + *rtagset = tagset; + H5_PRIV_FUNC_RETURN (H5_SUCCESS); +} + +/*! + Create a new tagset + */ +h5_err_t +h5t_create_mtagset ( + h5t_mesh_t* const m, + const char name[], + const h5_id_t type, + h5t_tagset_t** set + ) { + H5_CORE_API_ENTER (h5_err_t, + "m=%p, name='%s', type=%llu, set=%p", + m, name, (long long unsigned)type, set); // validate name if (name == NULL || name[0] == '\0') { H5_PRIV_FUNC_LEAVE ( @@ -155,203 +157,16 @@ add_tagset ( } // check if a tagset with given name already exists - h5_err_t h5err; - TRY (h5err = tagset_exists (ctn, name) ); - if (h5err == H5_SUCCESS) { - H5_PRIV_FUNC_LEAVE ( - h5_error (H5_ERR_INVAL, - "Tagset with name %s already exists!", - name)); - } + h5_err_t exists; + TRY (exists = h5priv_link_exists (m->mesh_gid, "Tags", name)); + if (exists || h5priv_find_strlist (m->mtagsets, name) >= 0) + H5_CORE_API_LEAVE ( + h5_error ( + H5_ERR_H5FED, + "Cannot create tagset '%s': Tagset exists", name)); + - // create new tagset - h5t_tagset_t* tagset = NULL; - size_t size = (t->num_elems[t->num_leaf_levels-1] - 1) * sizeof(*tagset->elems) - + sizeof(*tagset); - TRY (tagset = h5_calloc (1, size)); - - TRY (tagset->name = h5priv_strdup (name)); - tagset->type = type; - tagset->num_elems = t->num_elems[t->num_leaf_levels-1]; - tagset->scope.min_level = 32767; - tagset->scope.max_level = -1; - - // add tagset to hash of tagsets - TRY (h5priv_hsearch (tagset, H5_ENTER, NULL, &ctn->sets)); - - t->mtags.changed = 1; - t->mtags.names[t->mtags.num_sets] = tagset->name; - t->mtags.num_sets++; - - if (rtagset != NULL) *rtagset = tagset; - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - -h5_err_t -h5t_add_mtagset ( - h5_file_t* const f, - char* name, - h5_id_t type - ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, name=\"%s\", type=%llu", - f, name, - (long long unsigned)type); - h5t_fdata_t* t = f->t; - H5_CORE_API_RETURN (add_tagset (f, &t->mtags, name, type, NULL)); -} - - -/*! - Remove a tagset from the current mesh. - - \param[in] f file handle - \param[in] name name of tagset to remove - - \return H5_SUCCESS or error code - */ -static h5_err_t -remove_tagset ( - h5_file_t* const f, - h5t_tagcontainer_t* ctn, - const char name[] - ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - // remove tagset with NAME from m-tagsets dictionary - void* __retval = NULL; - TRY (h5priv_hsearch (&name, H5_REMOVE, &__retval, &ctn->sets)); - h5t_tagset_t* tagset = (h5t_tagset_t*)__retval; - if (tagset == NULL) { - H5_PRIV_FUNC_LEAVE (H5_SUCCESS); - } - TRY (release_tagset (tagset)); - - // remove HDF5 datasets and group for this tagset - hid_t loc_id; - TRY (loc_id = h5priv_open_group (f, ctn->group_id, name)); - TRY (hdf5_delete_link (loc_id, "elems", H5P_DEFAULT)); - TRY (hdf5_delete_link (loc_id, "entities", H5P_DEFAULT)); - TRY (hdf5_delete_link (loc_id, "values", H5P_DEFAULT)); - TRY (hdf5_close_group (loc_id)); - TRY (hdf5_delete_link (ctn->group_id, name, H5P_DEFAULT)); - - H5_PRIV_FUNC_RETURN (H5_SUCCESS); -} - -/*! - Remove a tagset from the current mesh. - - \param[in] f file handle - \param[in] name name of tagset to remove - - \return H5_SUCCESS or error code - */ -h5_err_t -h5t_remove_mtagset ( - h5_file_t* const f, - const char name[] - ) { - H5_CORE_API_ENTER2 (h5_err_t, - "f=0x%p, name=\"%s\"", - f, name); - 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 (hdf5_close_group (t->mtags.group_id)); - H5_CORE_API_RETURN (H5_SUCCESS); -} - -h5_ssize_t -h5t_get_num_mtagsets ( - h5_file_t* const f - ) { - H5_CORE_API_ENTER1 (h5_ssize_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - H5_CORE_API_RETURN (t->mtags.num_sets); -} - -/*! - Get available tagset in current mesh. - - \param[in] f file handle - \param[out] names names of available tagsets - - \return Number of mesh tag-sets - */ -h5_ssize_t -h5t_get_mtagsets ( - h5_file_t* const f, - char** names[] - ) { - H5_CORE_API_ENTER2 (h5_ssize_t, "f=0x%p, names=0x%p", f, names); - h5t_fdata_t* t = f->t; - *names = t->mtags.names; - H5_CORE_API_RETURN (t->mtags.num_sets); -} - -h5_err_t -h5t_open_mtagset ( - h5_file_t* const f, - const char* name, - h5t_tagset_t** retval - ) { - H5_CORE_API_ENTER3 (h5_ssize_t, - "f=0x%p, name=\"%s\", retval=0x%p", - f, name, retval); - h5t_fdata_t* t = f->t; - void* __retval = NULL; - TRY (h5priv_hsearch (&name, H5_FIND, &__retval, &t->mtags.sets)); - *retval = (h5t_tagset_t*)__retval; - H5_CORE_API_RETURN (H5_SUCCESS); -} - -/*! - Get type of tagset in current mesh. - - \param[in] f file handle - \param[in] name name of tagset - - \return type or error code - */ -h5_id_t -h5t_get_mtagset_type_by_name ( - h5_file_t* const f, - char* name - ) { - H5_CORE_API_ENTER2 (h5_ssize_t, - "f=0x%p, name=\"%s\"", - f, name); - h5t_tagset_t* tagset; - TRY (h5t_open_mtagset (f, name, &tagset)); - H5_CORE_API_RETURN (tagset->type); -} - -/*! - Get information about a tagset - - \param[in] f file handle - \param[in] idx index of tagset we want information about - \param[out] name name of tag-set - \param[out] type type of tag-set - */ -h5_ssize_t -h5t_get_mtagset_info ( - h5_file_t* const f, - const h5_id_t idx, - char** name, - h5_id_t* type - ) { - H5_CORE_API_ENTER4 (h5_ssize_t, - "f=0x%p, idx=%lld, name=0x%p, type=0x%p", - f, (long long)idx, name, type); - h5t_fdata_t* t = f->t; - *name = t->mtags.names[idx]; - void* __retval = NULL; - TRY (h5priv_hsearch (t->mtags.names[idx], H5_FIND, &__retval, - &t->mtags.sets)); - h5t_tagset_t* retval = (h5t_tagset_t*)__retval; - *type = retval->type; - H5_CORE_API_RETURN (H5_SUCCESS); + H5_CORE_API_RETURN (new_tagset (m, m->mesh_gid, name, type, set)); } static int @@ -376,18 +191,6 @@ find_face_id ( return -(low+1); } -static inline h5_err_t -tag_nexists_warn ( - const char* name, - const h5_loc_idx_t face_id, - const h5_loc_idx_t elem_idx - ) { - return h5_warn ( - "Tag %s not set for face %llx of element %lld", - name, - (long long)face_id, - (long long)elem_idx); -} static h5_err_t remove_tag ( @@ -395,10 +198,15 @@ remove_tag ( const h5_loc_idx_t face_id, const h5_loc_idx_t elem_idx ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, "tagset=%p, face_id=%d, elem_idx=%d", + tagset, face_id, elem_idx); if (tagset->elems[elem_idx] == NULL) { H5_PRIV_FUNC_LEAVE ( - tag_nexists_warn (tagset->name, face_id, elem_idx)); + h5_warn ( + "Tag %s not set for face %llx of element %lld", + tagset->name, + (long long)face_id, + (long long)elem_idx)); } h5t_tageleminfo_t* eleminfo = tagset->elems[elem_idx]; @@ -406,7 +214,11 @@ remove_tag ( int idx = find_face_id (eleminfo, face_id); if (idx < 0) { H5_PRIV_FUNC_LEAVE ( - tag_nexists_warn (tagset->name, face_id, elem_idx)); + h5_warn ( + "Tag %s not set for face %llx of element %lld", + tagset->name, + (long long)face_id, + (long long)elem_idx)); } h5t_taginfo_t* ti = &eleminfo->ti[idx]; @@ -433,7 +245,9 @@ add_tag ( const size_t dim, void* val ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, + "tagset=%p, idx=%d, face_id=%d, elem_idx=%d, dim=%zu, val=%p", + tagset, idx, face_id, elem_idx, dim, val); // insert new taginfo h5t_tageleminfo_t* eleminfo = tagset->elems[elem_idx]; TRY (eleminfo = tagset->elems[elem_idx] = h5_alloc ( @@ -462,13 +276,11 @@ add_tag ( static inline h5_err_t overwrite_tag ( - h5_file_t* const f, h5t_tagset_t* tagset, const int idx, const h5_loc_idx_t elem_idx, void* val ) { - UNUSED_ARGUMENT (f); h5t_tageleminfo_t* eleminfo = tagset->elems[elem_idx]; h5t_taginfo_t* ti = &eleminfo->ti[idx]; @@ -483,14 +295,15 @@ overwrite_tag ( */ static h5_err_t set_tag ( - h5_file_t* const f, h5t_tagset_t* tagset, const h5_loc_idx_t face_id, const h5_loc_idx_t elem_idx, const size_t dim, void* val ) { - H5_PRIV_FUNC_ENTER (h5_err_t); + H5_PRIV_FUNC_ENTER (h5_err_t, + "tagset=%p, face_id=%d, elem_idx=%d, dim=%zu, val=%p", + tagset, face_id, elem_idx, dim, val); if (tagset->elems[elem_idx] == NULL) { TRY (tagset->elems[elem_idx] = h5_calloc ( 1, sizeof (*tagset->elems))); @@ -500,312 +313,160 @@ set_tag ( h5t_taginfo_t* ti = eleminfo->ti + i; if (i >= 0 && dim != ti->val_dim) { /* - This is a very unusual case! So the processing can be - a bit more expensive ... + Overwrite existing value with new dimension. + This is a very unusual case. */ TRY (remove_tag (tagset, face_id, elem_idx)); TRY (add_tag (tagset, i, face_id, elem_idx, dim, val)); } else if (i >= 0 && dim == ti->val_dim) { - TRY (overwrite_tag (f, tagset, i, elem_idx, val)); + TRY (overwrite_tag (tagset, i, elem_idx, val)); } else { // i < 0 TRY (add_tag (tagset, -i-1, face_id, elem_idx, dim, val)); tagset->num_entities++; } - if (f->t->leaf_level < tagset->scope.min_level) { - tagset->scope.min_level = f->t->leaf_level; + if (tagset->m->leaf_level < tagset->scope.min_level) { + tagset->scope.min_level = tagset->m->leaf_level; } - if (f->t->leaf_level > tagset->scope.max_level) { - tagset->scope.max_level = f->t->leaf_level; + if (tagset->m->leaf_level > tagset->scope.max_level) { + tagset->scope.max_level = tagset->m->leaf_level; } - tagset->changed = 1; H5_PRIV_FUNC_RETURN (H5_SUCCESS); } -/* - Inheritance: - - to coarser level only - - if entity has tagged parrent, tag of parent - - else: not tagged - Parent of entity in tetrahedral grid: - - tetrahedron: parent ID - - triangles: - face child parent face - 0 0 0 - 1 0 1 - 2 0 2 - 3 0 -1 - 0 1 0 - 1 1 1 - 2 1 -1 - 3 1 3 - 0 2 0 - 1 2 -1 - 2 2 2 - 3 2 3 - 0 3 -1 - 1 3 1 - 2 3 2 - 3 3 3 - 0 4 -1 - 1 4 1 - 2 4 -1 - 3 4 -1 - 0 5 0 - 1 5 -1 - 2 5 -1 - 3 5 -1 - 0 6 -1 - 1 6 -1 - 2 6 -1 - 3 6 3 - 0 7 -1 - 1 7 -1 - 2 7 2 - 3 7 -1 -*/ -int map_tri_to_parent_face[8][4] = { - {0,1,2,-1}, - {0,1,-1,3}, - {0,-1,2,3}, - {-1,1,2,3}, - {-1,1,-1,-1}, - {0,-1,-1,-1}, - {-1,-1,-1,3}, - {-1,-1,2,-1}}; -/* - - edges: - 0 0-3 0 - 1 0-3 1 - 2 0-3 2 - 3 0-3 3 - 4 0-3 4 - 5 0-3 5 - 0-5 4-7 -1 -*/ -int map_edge_to_parent_face[8][6] = { - -}; -/* - - vertex: - 0 0 0 - 1-3 0 -1 - 0 1 -1 - 1 1 1 - 2,3 1 -1 - 0,1 2 -1 - 2 2 2 - 3 2 -1 - 0-2 3 -1 - 3 3 3 - 0-3 4 -1 - 0-3 5 -1 - 0-3 6 -1 -*/ - -static inline h5_err_t -get_idx_of_tagval ( - const h5t_tagset_t* tagset, - const h5_loc_idx_t face_id, - const h5_loc_idx_t elem_idx, - int* taginfo_idx, - h5_loc_idx_t* val_idx +static h5_err_t +read_tagset ( + h5t_tagset_t* const tagset ) { - h5t_tageleminfo_t* eleminfo = tagset->elems[elem_idx]; - if (eleminfo == NULL) { - return H5_NOK; - } - *taginfo_idx = find_face_id (eleminfo, face_id); - if (*taginfo_idx < 0) { - return H5_NOK; // not tagged - } - *val_idx = eleminfo->ti[*taginfo_idx].val_idx; - return H5_SUCCESS; -} + H5_PRIV_FUNC_ENTER (h5_err_t, "tagset=%p", tagset); + hid_t loc_id = 0; -static inline h5_ssize_t -get_tag ( - h5_file_t* const f, - const h5t_tagset_t *tagset, - const h5_loc_idx_t face_id, - const h5_loc_idx_t elem_idx, - size_t* const dim, - void* const values - ) { - if (f->t->leaf_level < tagset->scope.min_level) { - return H5_NOK; // entity not tagged + // open HDF5 group + + TRY (loc_id = h5priv_open_group (0, tagset->parent_gid, "Tags", tagset->name)); + + // read datasets: + + // "elems" + h5t_glb_tag_idx_t* elems; + size_t num_elems = 0; + + hid_t dset_id; + TRY (dset_id = hdf5_open_dataset (loc_id, "elems")); + TRY (num_elems = hdf5_get_npoints_of_dataset (dset_id)); + TRY (elems = h5_calloc (num_elems, sizeof(*elems))); + h5_dsinfo_t dsinfo; + memset (&dsinfo, 0, sizeof (dsinfo)); + dsinfo.type_id = tagset->m->dtypes.h5t_glb_tag_idx_t; + TRY (h5priv_read_dataset ( + tagset->m->f, + dset_id, + &dsinfo, + open_space_all, open_space_all, + elems)); + TRY (hdf5_close_dataset (dset_id)); + num_elems--; + + // "entities" + h5t_glb_tag_idx_t* entities; + size_t ent_idx = 0; + size_t num_entities = 0; + TRY (dset_id = hdf5_open_dataset (loc_id, "entities")); + TRY (num_entities = hdf5_get_npoints_of_dataset (dset_id)); + TRY (entities = h5_calloc (num_entities, sizeof(*entities))); + TRY (h5priv_read_dataset ( + tagset->m->f, + dset_id, + &dsinfo, + open_space_all, open_space_all, + entities)); + TRY (hdf5_close_dataset (dset_id)); + num_entities--; + + // "values" + h5_int64_t* vals; + size_t num_vals = 0; + TRY (dset_id = hdf5_open_dataset (loc_id, "values")); + TRY (num_vals = hdf5_get_npoints_of_dataset (dset_id)); + TRY (vals = h5_calloc (num_vals, sizeof (*vals))); + TRY (dsinfo.type_id = hdf5_get_dataset_type (dset_id)); + TRY (h5priv_read_dataset ( + tagset->m->f, + dset_id, + &dsinfo, + open_space_all, open_space_all, + vals)); + TRY (hdf5_close_dataset (dset_id )); + tagset->type = h5_normalize_h5_type (dsinfo.type_id); + + /* + add tagset and set values + */ + + h5_int64_t scope; + TRY (h5priv_read_attrib (loc_id, "__scope_min__", H5_INT64_T, &scope)); + tagset->scope.min_level = scope; + TRY (h5priv_read_attrib (loc_id, "__scope_max__", H5_INT64_T, &scope)); + tagset->scope.max_level = scope; + + for (ent_idx = 0; ent_idx < num_entities; ent_idx++) { + h5t_glb_tag_idx_t *entity = &entities[ent_idx]; + size_t dim = (entity+1)->idx - entity->idx; + // map global face id and global element idx to local + h5_loc_idx_t face_id; + h5_loc_idx_t elem_idx; + h5_glb_idx_t glb_elem_idx = h5tpriv_get_elem_idx (entity->eid); + TRY (elem_idx = h5t_map_glb_elem_idx2loc (tagset->m, glb_elem_idx)); + face_id = h5tpriv_get_face_id (entity->eid); + TRY (set_tag ( + tagset, + face_id, + elem_idx, + dim, + &vals[entity->idx])); } - h5_loc_idx_t val_idx = 0; - int ti_idx = 0; - h5_err_t h5err = get_idx_of_tagval (tagset, face_id, elem_idx, - &ti_idx, &val_idx); - if (h5err < 0) { - return h5err; - } - h5t_taginfo_t* ti = &tagset->elems[elem_idx]->ti[ti_idx]; - h5t_tagval_t* v = tagset->values; - if (*dim > ti->val_dim || values == NULL) { - *dim = ti->val_dim; - } - if (values != NULL) { - memcpy (values, v + val_idx, *dim*sizeof(*v) ); - } - return H5_SUCCESS; + TRY (h5_free (elems)); + TRY (h5_free (entities)); + TRY (h5_free (vals)); + H5_PRIV_FUNC_RETURN (H5_SUCCESS); } /*! - Set tag for entity in current mesh. - - \param[in] f file handle - \param[in] name names of tagset - \param[in] id local id of entity - \param[in] val tag value - \param[in] size size of value - - \return H5_SUCCESS or error code + Open existing tagset given by \c name. */ h5_err_t -h5t_set_mtag_by_name ( - h5_file_t* const f, - char name[], - const h5_loc_id_t entity_id, - const size_t dim, - void* val - ) { - H5_CORE_API_ENTER5 (h5_err_t, - "f=0x%p, name=\"%s\", entity_id=%lld, dim=%llu, val=0x%p", - f, - name, - (long long)entity_id, - (long long unsigned)dim, - val); - h5t_tagset_t* tagset; - TRY (h5t_open_mtagset (f, name, &tagset)); - h5_loc_idx_t face_id = h5tpriv_get_face_id (entity_id); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); - H5_CORE_API_RETURN (set_tag (f, tagset, face_id, elem_idx, dim, val)); -} -/*! - Get tag for entity in given tagset. - - \param[in] f file handle - \param[in] name names of tagset - \param[in] id id of entity - \param[out] size dimension of value - \param[out] val tag value - - \return H5_SUCCESS or error code - */ -h5_ssize_t -h5t_get_tag ( - h5_file_t* const f, - const h5t_tagset_t* tagset, - const h5_loc_id_t entity_id, - size_t* const dim, - void* const vals - ) { - H5_CORE_API_ENTER5 (h5_err_t, - "f=0x%p, tagset=0x%p, entity_id=%lld, dim=0x%p, val=0x%p", - f, - tagset, - (long long)entity_id, - dim, - vals); - h5_loc_idx_t face_id = h5tpriv_get_face_id (entity_id); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); - H5_CORE_API_RETURN (get_tag (f, tagset, face_id, elem_idx, dim, vals)); -} - -/*! - Get tag for entity in current mesh. - - \param[in] f file handle - \param[in] name names of tagset - \param[in] id id of entity - \param[out] size dimension of value - \param[out] val tag value - - \return H5_SUCCESS or error code - */ -h5_ssize_t -h5t_get_mtag_by_name ( - h5_file_t* const f, +h5t_open_mtagset ( + h5t_mesh_t* const m, const char name[], - const h5_loc_id_t entity_id, - size_t* dim, - void* vals + h5t_tagset_t** set ) { - H5_CORE_API_ENTER5 (h5_err_t, - "f=0x%p, name=\"%s\", entity_id=%lld, dim=0x%p, val=0x%p", - f, - name, - (long long)entity_id, - dim, - vals); - h5t_tagset_t* tagset; - TRY (h5t_open_mtagset (f, name, &tagset)); - h5_loc_idx_t face_id = h5tpriv_get_face_id (entity_id); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); - H5_CORE_API_RETURN (get_tag (f, tagset, face_id, elem_idx, dim, vals)); -} + H5_CORE_API_ENTER (h5_err_t, + "m=%p, name='%s', set=%p", + m, name, set); + // validate name + if (name == NULL || name[0] == '\0') { + H5_PRIV_FUNC_LEAVE ( + h5_error (H5_ERR_INVAL, "Invalid name" )); + } -/*! - Remove tag for entity in current mesh. + // check if a tagset with given name exists + h5_err_t exists; + TRY (exists = h5priv_link_exists (m->mesh_gid, "Tags", name)); + if (!exists) H5_CORE_API_LEAVE ( + h5_error ( + H5_ERR_INVAL, + "Cannot open tagset '%s': No such tagset ", name)); - \param[in] f file handle - \param[in] tagset pointer to tagset - \param[in] id id of entity -*/ -h5_err_t -h5t_remove_mtag ( - h5_file_t* const f, - h5t_tagset_t* tagset, - const h5_loc_id_t entity_id - ) { - UNUSED_ARGUMENT (f); - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, tagset=0x%p, entity_id=%lld", - f, - tagset, - (long long)entity_id); - h5_loc_idx_t face_id = h5tpriv_get_face_id (entity_id); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); - H5_CORE_API_RETURN (remove_tag (tagset, face_id, elem_idx)); -} + // check if tagset has already been opened + if (h5priv_find_strlist (m->mtagsets, name) >= 0) H5_CORE_API_LEAVE ( + h5_error ( + H5_ERR_INVAL, + "Cannot open tagset '%s': Already open ", name)); -/*! - Remove tag for entity in current mesh. - \param[in] f file handle - \param[in] name names of tagset - \param[in] id id of entity -*/ -h5_err_t -h5t_remove_mtag_by_name ( - h5_file_t* const f, - const char name[], - const h5_loc_id_t entity_id - ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, name=\"%s\", entity_id=%lld", - f, - name, - (long long)entity_id); - h5t_tagset_t* tagset; - TRY (h5t_open_mtagset (f, name, &tagset)); - h5_loc_idx_t face_id = h5tpriv_get_face_id (entity_id); - h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); - H5_CORE_API_RETURN (remove_tag (tagset, face_id, elem_idx)); -} - -static hid_t -open_space_all ( - h5_file_t* const f, - const hid_t dataset_id - ) { - UNUSED_ARGUMENT (f); - UNUSED_ARGUMENT (dataset_id); - return H5S_ALL; + TRY (new_tagset (m, m->mesh_gid, name, -1, set)); + TRY (read_tagset (*set)); + H5_CORE_API_RETURN (H5_SUCCESS); } /* @@ -813,12 +474,9 @@ open_space_all ( */ static h5_err_t write_tagset ( - h5_file_t* const f, - const hid_t loc_id, h5t_tagset_t* tagset ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; + H5_PRIV_FUNC_ENTER (h5_err_t, "tagset=%p", tagset); h5t_tageleminfo_t** eleminfos = tagset->elems; hid_t group_id; h5t_glb_tag_idx_t* elems = NULL; // in memory dataset @@ -832,10 +490,11 @@ write_tagset ( h5_loc_idx_t entity_idx = 0; h5_loc_idx_t val_idx = 0; - if (t->num_leaf_levels <= 0) { + h5t_mesh_t* m = tagset->m; + if (m->num_leaf_levels <= 0) { H5_PRIV_FUNC_LEAVE (H5_SUCCESS); // nothing to do } - num_elems = t->num_elems[t->num_leaf_levels-1]; + num_elems = m->num_elems[m->num_leaf_levels-1]; if (num_elems == 0 || tagset->num_entities == 0) { H5_PRIV_FUNC_LEAVE (H5_SUCCESS); // nothing to do } @@ -856,11 +515,12 @@ write_tagset ( elem->idx = entity_idx; h5t_tageleminfo_t* eleminfo = *eleminfos; - // loop over tagged faces of this element + // loop over all tagged faces of this element int ti_idx; for (ti_idx = 0; eleminfo && ti_idx < eleminfo->num_tags; ti_idx++) { h5t_taginfo_t* ti = eleminfo->ti+ti_idx; - h5_glb_idx_t glb_elem_idx = h5tpriv_get_loc_elem_glb_idx (f, elem_idx); + h5_glb_idx_t glb_elem_idx = h5tpriv_get_loc_elem_glb_idx ( + m, elem_idx); entity->eid = h5tpriv_build_entity_id ( 0, (h5_glb_id_t)ti->face_id, glb_elem_idx); entity->idx = val_idx; @@ -883,7 +543,11 @@ write_tagset ( tagset->num_values = entity->idx = val_idx; // write data - TRY (group_id = h5priv_open_group (f, loc_id, tagset->name)); + TRY (group_id = h5priv_open_group ( + 1, + tagset->parent_gid, + "Tags", + tagset->name)); h5_dsinfo_t dsinfo; memset (&dsinfo, 0, sizeof(dsinfo)); dsinfo.rank = 1; @@ -893,13 +557,13 @@ write_tagset ( strcpy (dsinfo.name, "elems"); dsinfo.dims[0] = num_elems + 1; - dsinfo.type_id = t->dtypes.h5t_glb_tag_idx_t; + dsinfo.type_id = m->dtypes.h5t_glb_tag_idx_t; TRY (dsinfo.create_prop = hdf5_create_property (H5P_DATASET_CREATE)); TRY (hdf5_set_chunk_property (dsinfo.create_prop, dsinfo.rank, dsinfo.chunk_dims)); TRY (h5priv_write_dataset_by_name ( - f, + m->f, group_id, &dsinfo, open_space_all, open_space_all, @@ -909,7 +573,7 @@ write_tagset ( dsinfo.dims[0] = tagset->num_entities + 1; TRY (h5priv_write_dataset_by_name ( - f, + m->f, group_id, &dsinfo, open_space_all, open_space_all, @@ -917,10 +581,10 @@ write_tagset ( strcpy (dsinfo.name, "values"); dsinfo.dims[0] = tagset->num_values; - dsinfo.type_id = t->dtypes.h5_int64_t; + dsinfo.type_id = m->dtypes.h5_int64_t; TRY (h5priv_write_dataset_by_name ( - f, + m->f, group_id, &dsinfo, open_space_all, open_space_all, @@ -937,236 +601,223 @@ write_tagset ( H5_PRIV_FUNC_RETURN (H5_SUCCESS); } + /* - Store given tag container. Write only changed tag-sets. + Release a tag-set */ -static h5_err_t -write_container ( - h5_file_t* const f, - h5t_tagcontainer_t* ctn +static inline h5_err_t +release_mtagset ( + h5t_tagset_t* tagset ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - size_t idx; - for (idx = 0; idx < ctn->num_sets; idx++) { - void *__retval; - TRY (h5priv_hsearch ( - &ctn->names[idx], - H5_FIND, - &__retval, - &ctn->sets)); - h5t_tagset_t *tagset = (h5t_tagset_t*)__retval; - if (tagset->changed) { - TRY(write_tagset ( - f, - ctn->group_id, - tagset)); + H5_PRIV_FUNC_ENTER (h5_err_t, "tagset=%p", tagset); + unsigned int i; + // release per element structures + for (i = 0; i < tagset->num_elems; i++) { + if (tagset->elems[i] != NULL) { + TRY (h5_free (tagset->elems[i])); } } + // remove from book-keeping list in mesh + TRY (h5priv_remove_strlist(tagset->m->mtagsets, tagset->name)); + + // release other memory + TRY (h5_free (tagset->name)); + TRY (h5_free (tagset->values)); + TRY (h5_free (tagset)); + H5_PRIV_FUNC_RETURN (H5_SUCCESS); } +/*! + Close tagset. -/* - Store mesh tags container - */ + Write data to disk, if something as been changed, and release memory. +*/ h5_err_t -h5tpriv_write_mtags ( - h5_file_t* const f +h5t_close_mtagset ( + h5t_tagset_t* tagset ) { - H5_PRIV_API_ENTER1 (h5_err_t, "f=0x%p", f); - h5t_fdata_t* t = f->t; - TRY (t->mtags.group_id = h5priv_open_group (f, t->mesh_gid, "Tags")); - TRY (write_container (f, &f->t->mtags)); - TRY (hdf5_close_group (t->mtags.group_id)); - H5_PRIV_API_RETURN (H5_SUCCESS); + H5_CORE_API_ENTER (h5_err_t, "tagset=%p", tagset); + if (tagset->changed) { + TRY (write_tagset (tagset)); + } + TRY (release_mtagset (tagset)); + H5_CORE_API_RETURN (H5_SUCCESS); } +/*! + Delete tagset on disk. + + Note: + There may be a copy in memory! This copy is still accessable, even + changes are possible. Since data are written on close, the tagset will + be created again. + We should implement something to avoid this! We have a similiar problem, + if the user opens the dataset more than once. + */ + +/*! + Remove a tagset from the current mesh. + + \param[in] f file handle + \param[in] name name of tagset to remove + + \return H5_SUCCESS or error code + */ static h5_err_t -read_tagset ( - h5_file_t* const f, - h5t_tagcontainer_t* ctn, - hsize_t idx +remove_tagset ( + const hid_t tagsets_id, + const char name[] ) { - H5_PRIV_FUNC_ENTER (h5_err_t); - h5t_fdata_t* t = f->t; - hid_t loc_id = ctn->group_id; - char* name; - h5_id_t type; - hid_t group_id; - hid_t dset_id; - ssize_t ssize; - TRY ((ssize = hdf5_get_objname_by_idx (loc_id, idx, NULL, 0))); - TRY ((name = h5_calloc (1, ++ssize))); - TRY (hdf5_get_objname_by_idx (loc_id, idx, name, ssize)); - TRY (group_id = hdf5_open_group (loc_id, name)); - - // read datasets: "elems", "entities" and "values" - h5t_glb_tag_idx_t* elems; - size_t num_elems = 0; - - TRY (dset_id = hdf5_open_dataset (group_id, "elems")); - TRY (num_elems = hdf5_get_npoints_of_dataset (dset_id)); - TRY (elems = h5_calloc (num_elems, sizeof(*elems))); - h5_dsinfo_t dsinfo; - memset (&dsinfo, 0, sizeof (dsinfo)); - dsinfo.type_id = t->dtypes.h5t_glb_tag_idx_t; - TRY (h5priv_read_dataset ( - f, - dset_id, - &dsinfo, - open_space_all, open_space_all, - elems)); - TRY (hdf5_close_dataset (dset_id)); - num_elems--; - - h5t_glb_tag_idx_t* entities; - size_t ent_idx = 0; - size_t num_entities = 0; - TRY (dset_id = hdf5_open_dataset (group_id, "entities")); - TRY (num_entities = hdf5_get_npoints_of_dataset (dset_id)); - TRY (entities = h5_calloc (num_entities, sizeof(*entities))); - TRY (h5priv_read_dataset ( - f, - dset_id, - &dsinfo, - open_space_all, open_space_all, - entities)); - TRY (hdf5_close_dataset (dset_id)); - num_entities--; - - h5_int64_t* vals; - size_t num_vals = 0; - TRY (dset_id = hdf5_open_dataset (group_id, "values")); - TRY (num_vals = hdf5_get_npoints_of_dataset (dset_id)); - TRY (vals = h5_calloc (num_vals, sizeof (*vals))); - TRY (dsinfo.type_id = hdf5_get_dataset_type (dset_id)); - TRY (h5priv_read_dataset ( - f, - dset_id, - &dsinfo, - open_space_all, open_space_all, - vals)); - TRY (hdf5_close_dataset (dset_id )); - type = h5_normalize_h5_type (dsinfo.type_id); - /* - add tagset and set values - */ - h5t_tagset_t* tagset; - TRY (add_tagset (f, ctn, name, type, &tagset) ); - - h5_int64_t scope; - TRY (h5priv_read_attrib (group_id, "__scope_min__", H5_INT64_T, &scope)); - tagset->scope.min_level = scope; - TRY (h5priv_read_attrib (group_id, "__scope_max__", H5_INT64_T, &scope)); - tagset->scope.max_level = scope; - - for (ent_idx = 0; ent_idx < num_entities; ent_idx++) { - h5t_glb_tag_idx_t *entity = &entities[ent_idx]; - size_t dim = (entity+1)->idx - entity->idx; - // map global face id and global element idx to local - h5_loc_idx_t face_id; - h5_loc_idx_t elem_idx; - h5_glb_idx_t glb_elem_idx = h5tpriv_get_elem_idx (entity->eid); - TRY (elem_idx = h5t_map_glb_elem_idx2loc (f, glb_elem_idx)); - face_id = h5tpriv_get_face_id (entity->eid); - TRY (set_tag ( - f, - tagset, - face_id, - elem_idx, - dim, - &vals[entity->idx])); - } - TRY (h5_free (name)); + H5_PRIV_FUNC_ENTER (h5_err_t, "tagsets_id=%d, name=%s", tagsets_id, name); + hid_t loc_id; + TRY (loc_id = hdf5_open_group (tagsets_id, name)); + TRY (hdf5_delete_link (loc_id, "elems", H5P_DEFAULT)); + TRY (hdf5_delete_link (loc_id, "entities", H5P_DEFAULT)); + TRY (hdf5_delete_link (loc_id, "values", H5P_DEFAULT)); + TRY (hdf5_close_group (loc_id)); + TRY (hdf5_delete_link (tagsets_id, name, H5P_DEFAULT)); H5_PRIV_FUNC_RETURN (H5_SUCCESS); } -h5_err_t -h5tpriv_read_tag_container ( - h5_file_t* const f, - h5t_tagcontainer_t* ctn - ) { - H5_PRIV_API_ENTER2 (h5_err_t, "f=0x%p, ctn=0x%p", f, ctn); - size_t num_sets; - TRY (num_sets = hdf5_get_num_objs_in_group (ctn->group_id)); - hsize_t idx; - - for (idx = 0; idx < num_sets; idx++) { - TRY (read_tagset (f, ctn, idx)); - } +/*! + Remove a tagset from the current mesh. - H5_PRIV_API_RETURN (H5_SUCCESS); + \param[in] f file handle + \param[in] name name of tagset to remove + + \return H5_SUCCESS or error code + */ +h5_err_t +h5t_remove_mtagset ( + h5t_mesh_t* const m, + const char name[] + ) { + H5_CORE_API_ENTER (h5_err_t, "m=%p, name='%s'", m, name); + + // check if tagset has a copy in memory + if (h5priv_find_strlist (m->mtagsets, name) >= 0) H5_CORE_API_LEAVE ( + h5_error ( + H5_ERR_INVAL, + "Cannot remove tagset '%s': Still open ", name)); + + hid_t loc_id; + TRY (loc_id = hdf5_open_group (m->mesh_gid, "Tags")); + TRY (remove_tagset (loc_id, name)); + TRY (hdf5_close_group (loc_id)); + H5_CORE_API_RETURN (H5_SUCCESS); } -/* - Get m-tagset of given entity. Return the number of tagsets as result - of the function and the names in the pointer array \c name. To query the - number of tagsets, use \c NULL as value of \c name. If the actual number - of tagset is greater than \c dim, the first \c dim names found will be - returned. - - \remark - This functions performs with O(n) where n is the number of tagsets. - - \param[in] f file handle - \param[in] entity_id ID of entity we want to know the set tags - \param[out] names Array of ptr to tagset names - \param[in] dim dimension of array - - \return number of tagsets +/*! + Set tag. */ -static h5_ssize_t -get_tagset_names_of_entity ( - h5t_tagcontainer_t* ctn, - h5_loc_id_t entity_id, - char* names[], - h5_size_t dim +h5_err_t +h5t_set_tag ( + h5t_tagset_t* const tagset, + const h5_loc_id_t entity_id, + const h5_size_t size, + void* val ) { - H5_PRIV_FUNC_ENTER (h5_ssize_t); - size_t idx; - size_t _dim = 0; + H5_CORE_API_ENTER (h5_err_t, + "tagset=%p, entity_id=%lld, size=%llu, val=%p", + tagset, + (long long)entity_id, + (long long unsigned)size, + val); h5_loc_idx_t face_id = h5tpriv_get_face_id (entity_id); h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); - - for (idx = 0; idx < ctn->num_sets; idx++) { - void* __retval; - TRY (h5priv_hsearch ( - &ctn->names[idx], - H5_FIND, - &__retval, - &ctn->sets)); - h5t_tagset_t* tagset = (h5t_tagset_t*)__retval; - int tagset_idx = 0; - h5_loc_idx_t val_idx; - if (0 < get_idx_of_tagval (tagset, - face_id, elem_idx, - &tagset_idx, &val_idx) ) { - continue; // not tagged - } - if (names != NULL && _dim <= dim) { - names[_dim] = ctn->names[idx]; - } - _dim++; - } - H5_PRIV_FUNC_RETURN (_dim); + TRY (set_tag (tagset, face_id, elem_idx, size, val)); + tagset->changed = 1; + H5_CORE_API_RETURN (H5_SUCCESS); } -/* - Return tag names for given entity. - */ -h5_ssize_t -h5t_get_mtagset_names_of_entity ( - h5_file_t* const f, +static inline h5_err_t +get_idx_of_tagval ( + const h5t_tagset_t* tagset, const h5_loc_id_t entity_id, - char* names[], - const h5_size_t dim + int* taginfo_idx, + h5_loc_idx_t* val_idx ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, entity_id=%lld, names=0x%p, dim=%llu", - f, - (long long)entity_id, - names, - (long long unsigned)dim); - H5_CORE_API_RETURN ( - get_tagset_names_of_entity (&f->t->mtags, entity_id, names, dim)); + h5_loc_idx_t face_id = h5tpriv_get_face_id (entity_id); + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); + h5t_tageleminfo_t* eleminfo = tagset->elems[elem_idx]; + if (eleminfo == NULL) { + return H5_NOK; // not tagged + } + *taginfo_idx = find_face_id (eleminfo, face_id); + if (*taginfo_idx < 0) { + return H5_NOK; // not tagged + } + *val_idx = eleminfo->ti[*taginfo_idx].val_idx; + return H5_SUCCESS; } + +/*! + Get tag for entity in given tagset. Untagged entities inherit tags from + their closest parent. + + \param[in] tagset tagset + \param[in] entity_id id of entity + \param[out] size size of value + \param[out] vals tag value + + \return H5_SUCCESS or error code + */ +h5_loc_id_t +h5t_get_tag ( + const h5t_tagset_t* tagset, + const h5_loc_id_t entity_id, + h5_size_t* const dim, + void* const values + ) { + H5_CORE_API_ENTER (h5_err_t, + "tagset=%p, entity_id=%lld, dim=%p, values=%p", + tagset, + (long long)entity_id, + dim, + values); + if (tagset->m->leaf_level < tagset->scope.min_level) { + H5_CORE_API_LEAVE (H5_NOK); // entity not tagged + } + h5_loc_id_t id = entity_id; + h5_err_t h5err; + int ti_idx = 0; + h5_loc_idx_t val_idx = 0; + // query entity while not tagged and parent exists + while ((h5err = get_idx_of_tagval (tagset, id, &ti_idx, &val_idx)) < 0 && + (id = h5tpriv_get_loc_entity_parent (tagset->m, id)) >= 0); + + if (h5err < 0) + H5_CORE_API_LEAVE (H5_NOK); // entity not tagged + + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (id); + h5t_taginfo_t* ti = &tagset->elems[elem_idx]->ti[ti_idx]; + h5t_tagval_t* v = tagset->values; + if (*dim > ti->val_dim || values == NULL) { + *dim = ti->val_dim; + } + if (values != NULL) { + memcpy (values, v + val_idx, *dim*sizeof(*v) ); + } + H5_CORE_API_RETURN (id); +} + +/*! + Remove tag from entity + + \param[in] tagset pointer to tagset + \param[in] entity_id local entity id +*/ +h5_err_t +h5t_remove_tag ( + h5t_tagset_t* tagset, + const h5_loc_id_t entity_id + ) { + H5_CORE_API_ENTER (h5_err_t, + "tagset=%p, entity_id=%lld", + tagset, (long long)entity_id); + h5_loc_idx_t face_id = h5tpriv_get_face_id (entity_id); + h5_loc_idx_t elem_idx = h5tpriv_get_elem_idx (entity_id); + H5_CORE_API_RETURN (remove_tag (tagset, face_id, elem_idx)); +} + diff --git a/src/h5core/h5t_tags_private.h b/src/h5core/h5t_tags_private.h index 44a2beb..b7c9144 100644 --- a/src/h5core/h5t_tags_private.h +++ b/src/h5core/h5t_tags_private.h @@ -56,6 +56,9 @@ typedef struct { struct h5t_tagset { char* name; // name of tagset + hid_t parent_gid; + h5t_mesh_t* m; + unsigned int changed; // flag tagset changed, ... struct { h5t_lvl_idx_t min_level; @@ -69,18 +72,6 @@ struct h5t_tagset { h5t_tageleminfo_t* elems[1]; // per element structure }; -/* - Structure for hash table of tagsets - */ -struct h5t_tagcontainer { - unsigned int changed; // flag container changed - hid_t group_id; - hsize_t num_sets; // number of tagsets - char** names; // fast access via index - h5_hashtable_t sets; // hash table -}; - - typedef struct { h5_glb_id_t eid ; // global entity id h5_glb_idx_t idx; // global index @@ -91,8 +82,7 @@ typedef struct { h5_loc_idx_t idx; // local index } h5t_loc_tag_idx_t; -h5_err_t h5tpriv_write_mtags ( h5_file_t *const f ); -h5_err_t h5tpriv_release_tags ( h5_file_t * const f ); -h5_err_t h5tpriv_read_tag_container ( h5_file_t * const f, - h5t_tagcontainer_t *container ); + +h5_err_t h5tpriv_write_mtags (h5t_mesh_t* const); +h5_err_t h5tpriv_read_tag_container ( h5t_mesh_t* const, h5t_tagcontainer_t*); #endif diff --git a/src/h5core/h5t_types_private.h b/src/h5core/h5t_types_private.h index 04e7167..3b275a1 100644 --- a/src/h5core/h5t_types_private.h +++ b/src/h5core/h5t_types_private.h @@ -80,7 +80,6 @@ typedef union h5_loc_elems { /*** type ids' for compound types ***/ typedef struct h5_dtypes { hid_t h5_glb_idx_t; /* ID's */ - hid_t h5_int64_t; /* 64 bit signed integer */ hid_t h5_float64_t; /* 64 bit floating point */ hid_t h5_coord3d_t; /* 3-tuple of 64-bit float */ @@ -116,60 +115,51 @@ typedef struct h5t_methods { } h5t_methods_t; -typedef struct h5t_fdata { +struct h5t_mesh { /*** book-keeping ***/ char mesh_name[256]; - h5_oid_t mesh_type; /* object id of element type */ const h5t_ref_elem_t* ref_elem; - 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 */ h5t_lvl_idx_t leaf_level; /* idx of current level */ h5t_lvl_idx_t num_leaf_levels;/* number of levels */ h5t_lvl_idx_t num_loaded_levels; - /*** HDF5 IDs ***/ - hid_t topo_gid; /* grp id of mesh in current - level */ - hid_t meshes_gid; /* HDF5 id */ - hid_t mesh_gid; + h5_strlist_t* mtagsets; - /*** type ids' for base & compound data types ***/ - h5_dtypes_t dtypes; + /*** HDF5 IDs ***/ + hid_t mesh_gid; /*** functions to handle differnt mesh types ***/ struct h5t_methods methods; + /*** type ids' for base & compound data types ***/ + h5_dtypes_t dtypes; + /*** vertices ***/ h5_loc_vertex_t *vertices; h5_size_t *num_vertices; h5_idxmap_t map_vertex_g2l; /* map global to local idx */ h5_loc_idx_t last_stored_vid; h5_dsinfo_t dsinfo_vertices; - h5_dsinfo_t dsinfo_num_vertices; - /*** Elements ***/ h5_glb_elems_t glb_elems; h5_loc_elems_t loc_elems; h5_size_t *num_elems; - h5_size_t *num_elems_on_leaf_level; + h5_size_t *num_leaf_elems; h5_idxmap_t map_elem_g2l; /* map global id to local id */ h5_loc_idx_t last_stored_eid; h5_dsinfo_t dsinfo_elems; - h5_dsinfo_t dsinfo_num_elems; - h5_dsinfo_t dsinfo_num_elems_on_leaf_level; h5_loc_idlist_t* marked_entities; /*** Adjacencies ***/ h5t_adjacencies_t adjacencies; - /*** Tags ***/ - h5t_tagcontainer_t mtags; - h5t_tagcontainer_t stags; -} h5t_fdata_t; + /*** File ***/ + h5_file_t* f; +}; #endif diff --git a/src/h5core/h5u_model.c b/src/h5core/h5u_model.c index 234ed51..26bc0d3 100644 --- a/src/h5core/h5u_model.c +++ b/src/h5core/h5u_model.c @@ -5,7 +5,7 @@ h5_ssize_t h5u_get_num_particles ( h5_file_t *const f /*!< [in] Handle to open file */ ) { - H5_CORE_API_ENTER1 (h5_ssize_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f); h5_ssize_t nparticles; /* if a view exists, use its size as the number of particles */ @@ -56,10 +56,10 @@ h5u_set_num_particles ( const h5_size_t nparticles, /*!< [in] Number of particles */ const h5_size_t stride /*!< [in] Stride of particles in memory */ ) { - H5_CORE_API_ENTER3 (h5_ssize_t, - "f=0x%p, nparticles=%llu, stride=%llu", - f, (long long unsigned)nparticles, - (long long unsigned)stride); + H5_CORE_API_ENTER (h5_ssize_t, + "f=%p, nparticles=%llu, stride=%llu", + f, (long long unsigned)nparticles, + (long long unsigned)stride); struct h5u_fdata *u = f->u; hsize_t start; hsize_t total; @@ -171,7 +171,7 @@ h5_err_t h5u_has_view ( const h5_file_t *const f ) { - H5_CORE_API_ENTER1 (h5_ssize_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f); H5_CORE_API_RETURN (f->u->viewindexed || (f->u->viewstart >= 0 && f->u->viewend >= 0)); } @@ -179,7 +179,7 @@ h5_err_t h5u_reset_view ( h5_file_t *const f ) { - H5_CORE_API_ENTER1 (h5_ssize_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f); struct h5u_fdata *u = f->u; u->viewstart = -1; @@ -199,9 +199,9 @@ h5u_set_view ( h5_int64_t start, /*!< [in] Start particle */ h5_int64_t end /*!< [in] End particle */ ) { - H5_CORE_API_ENTER3 (h5_ssize_t, - "f=0x%p, start=%lld, end=%lld", - f, (long long)start, (long long)end); + H5_CORE_API_ENTER (h5_ssize_t, + "f=%p, start=%lld, end=%lld", + f, (long long)start, (long long)end); hsize_t total; hsize_t stride = 1; hsize_t dmax = H5S_UNLIMITED; @@ -277,9 +277,9 @@ h5u_set_view_indices ( const h5_size_t *const indices, /*!< [in] List of indices */ h5_size_t nelems /*!< [in] Size of list */ ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, indices=0x%p, nelems=%llu", - f, indices, (long long unsigned)nelems); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, indices=%p, nelems=%llu", + f, indices, (long long unsigned)nelems); hsize_t total; hsize_t dmax = H5S_UNLIMITED; struct h5u_fdata *u = f->u; @@ -306,7 +306,7 @@ h5u_set_view_indices ( H5_CORE_API_LEAVE (H5_SUCCESS); } - if ( total == 0 ) return H5_SUCCESS; + if ( total == 0 ) H5_CORE_API_LEAVE (H5_SUCCESS); u->nparticles = nelems; h5_debug ("This view selected %lld particles.", (long long)u->nparticles ); @@ -336,9 +336,9 @@ h5u_get_view ( h5_int64_t *start, h5_int64_t *end ) { - H5_CORE_API_ENTER3 (h5_err_t, - "f=0x%p, start=0x%p, end=0x%p", - f, start, end); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, start=%p, end=%p", + f, start, end); struct h5u_fdata *u = f->u; if ( u->viewindexed ) { @@ -372,7 +372,7 @@ h5_int64_t h5u_set_canonical_view ( h5_file_t *const f ) { - H5_CORE_API_ENTER1 (h5_int64_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_int64_t, "f=%p", f); TRY( h5u_reset_view ( f ) ); h5_int64_t start = 0; @@ -411,7 +411,7 @@ h5_ssize_t h5u_get_num_datasets ( h5_file_t *const f /*!< [in] Handle to open file */ ) { - H5_CORE_API_ENTER1 (h5_int64_t, "f=0x%p", f); + H5_CORE_API_ENTER (h5_int64_t, "f=%p", f); H5_CORE_API_RETURN (hdf5_get_num_datasets (f->step_gid)); } @@ -428,16 +428,16 @@ h5u_get_dataset_info ( h5_int64_t *type, /*!< [out] Type of data in dataset */ h5_size_t *nelem /*!< [out] Number of elements. */ ) { - H5_CORE_API_ENTER6 (h5_err_t, - "f=0x%p, " - "idx=%lld, " - "dataset_name=\"%s\", len_dataset_name=%llu, " - "type=0x%p, nelem=0x%p", - f, - (long long)idx, - dataset_name, - (long long unsigned)len_dataset_name, - type, nelem); + H5_CORE_API_ENTER (h5_err_t, + "f=%p, " + "idx=%lld, " + "dataset_name='%s', len_dataset_name=%llu, " + "type=%p, nelem=%p", + f, + (long long)idx, + dataset_name, + (long long unsigned)len_dataset_name, + type, nelem); TRY (hdf5_get_name_of_dataset_by_idx ( f->step_gid, idx, @@ -448,13 +448,13 @@ h5u_get_dataset_info ( TRY (nelem_ = hdf5_get_npoints_of_dataset_by_name ( f->step_gid, dataset_name) ); - if ( nelem_ < 0 ) return nelem_; + if ( nelem_ < 0 ) H5_CORE_API_LEAVE (nelem_); *nelem = nelem_; } - if ( type ) { + if (type) { *type = h5_get_dataset_type (f->step_gid, dataset_name); - if ( *type < 0 ) return *type; + if (*type < 0) H5_CORE_API_LEAVE (*type); } H5_CORE_API_RETURN (H5_SUCCESS); @@ -465,7 +465,7 @@ h5u_set_chunk ( h5_file_t *const f, const h5_size_t size ) { - H5_CORE_API_ENTER2 (h5_int64_t, "f=0x%p, size=%llu", f, (long long unsigned)size); + H5_CORE_API_ENTER (h5_int64_t, "f=%p, size=%llu", f, (long long unsigned)size); if ( size == 0 ) { h5_info ("Disabling chunking" ); @@ -486,9 +486,7 @@ h5u_get_chunk ( const char *name, /*!< IN: name of dataset */ h5_size_t *size /*!< OUT: chunk size in particles */ ) { - H5_CORE_API_ENTER3 (h5_int64_t, - "f=0x%p, name=\"%s\", size=0x%p", - f, name, size); + H5_CORE_API_ENTER (h5_int64_t, "f=%p, name='%s', size=%p", f,name,size); hid_t dataset_id; hid_t plist_id; hsize_t hsize; diff --git a/src/h5core/h5u_readwrite.c b/src/h5core/h5u_readwrite.c index 7b72222..580f67d 100644 --- a/src/h5core/h5u_readwrite.c +++ b/src/h5core/h5u_readwrite.c @@ -8,9 +8,8 @@ h5u_read_data ( void *data, /*!< [out] Array of data */ const hid_t type ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, name=\"%s\", data=0x%p, type=%d", - f, name, data, type); + H5_CORE_API_ENTER (h5_err_t, "f=%p, name='%s', data=%p, type=%d", + f, name, data, type); CHECK_TIMEGROUP (f); struct h5u_fdata *u = f->u; @@ -108,9 +107,8 @@ h5u_write_data ( const void *data, /*!< IN: Array to commit to disk */ const hid_t type /*!< IN: Type of data */ ) { - H5_CORE_API_ENTER4 (h5_err_t, - "f=0x%p, name=\"%s\", data=0x%p, type=%d", - f, name, data, type); + H5_CORE_API_ENTER (h5_err_t, "f=%p, name='%s', data=%p, type=%d", + f, name, data, type); CHECK_TIMEGROUP( f ); CHECK_WRITABLE_MODE( f ); @@ -155,12 +153,13 @@ h5u_write_data ( #ifdef PARALLEL_IO TRY (h5_end_throttle (f)); #endif - if (f->mode & H5_O_FLUSHSTEP) + if (f->mode & H5_FLUSH_STEP) TRY (hdf5_flush (f->step_gid, H5F_SCOPE_LOCAL)); TRY (hdf5_close_dataset (dset_id)); f->empty = 0; + TRY (hdf5_flush (f->step_gid, H5F_SCOPE_LOCAL)); H5_CORE_API_RETURN (H5_SUCCESS); } diff --git a/src/include/H5Fed.h b/src/include/H5Fed.h index 52df7ff..8efb4f5 100644 --- a/src/include/H5Fed.h +++ b/src/include/H5Fed.h @@ -34,44 +34,66 @@ extern "C" { static inline h5_err_t H5FedOpenTetrahedralMesh ( h5_file_t* const f, - const h5_id_t mesh_id + const char* name, + h5t_mesh_t** mesh ) { - H5_API_ENTER2 (h5_err_t, "f=0x%p, mesh_id=%lld", f, (long long)mesh_id); - H5_API_RETURN (h5t_open_tetrahedral_mesh (f, mesh_id)); + H5_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh); + H5_API_RETURN (h5t_open_tetrahedral_mesh (f, name, mesh)); +} + +static inline h5_err_t +H5FedOpenTetrahedralMeshByIndex ( + h5_file_t* const f, + const h5_id_t idx, + h5t_mesh_t** mesh + ) { + H5_API_ENTER (h5_err_t, "f=%p, idx=%lld, mesh=%p", f, (long long)idx, mesh); + H5_API_RETURN (h5t_open_tetrahedral_mesh_by_idx (f, idx, mesh)); } static inline h5_err_t H5FedOpenTriangleMesh ( h5_file_t* const f, - const h5_id_t mesh_id + const char* name, + h5t_mesh_t** mesh ) { - H5_API_ENTER2 (h5_err_t, "f=0x%p, mesh_id=%lld", f, (long long)mesh_id); - H5_API_RETURN (h5t_open_triangle_mesh (f, mesh_id)); + H5_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh); + H5_API_RETURN (h5t_open_triangle_mesh (f, name, mesh)); +} + +static inline h5_err_t +H5FedOpenTriangleMeshByIndex ( + h5_file_t* const f, + const h5_id_t idx, + h5t_mesh_t** mesh + ) { + H5_API_ENTER (h5_err_t, "f=%p, idx=%lld, mesh=%p", f, (long long)idx, mesh); + H5_API_RETURN (h5t_open_triangle_mesh_by_idx (f, idx, mesh)); } static inline h5_err_t H5FedCloseMesh ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5_err_t, "f=0x%p", f); - H5_API_RETURN (h5t_close_mesh (f)); + H5_API_ENTER (h5_err_t, "m=%p", m); + H5_API_RETURN (h5t_close_mesh (m)); } static inline h5_err_t H5FedSetLevel ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t level_id ) { - H5_API_ENTER2 (h5_err_t, "f=0x%p, level_id=%d", f, level_id); - H5_API_RETURN (h5t_set_level (f, level_id)); + H5_API_ENTER (h5_err_t, "m=%p, level_id=%d", m, level_id); + H5_API_RETURN (h5t_set_level (m, level_id)); } static inline h5_err_t H5FedLinkMeshToStep ( - h5_file_t* const f, + h5_file_t* const m, const h5_id_t mesh_id ) { - H5_API_ENTER2 (h5_err_t, "f=0x%p, mesh_id=%lld", f, (long long)mesh_id); + H5_API_ENTER (h5_err_t, "m=%p, mesh_id=%lld", m, (long long)mesh_id); H5_API_RETURN (h5_error_not_implemented ()); } diff --git a/src/include/H5Fed_adjacency.h b/src/include/H5Fed_adjacency.h index 994e86a..5c5f891 100644 --- a/src/include/H5Fed_adjacency.h +++ b/src/include/H5Fed_adjacency.h @@ -7,26 +7,24 @@ extern "C" { static inline h5_err_t H5FedGetAdjacencies ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t** list ) { - H5_API_ENTER4 (h5_err_t, - "f=0x%p, entity_id=%lld, dim=%d, list=0x%p", - f, (long long)entity_id, dim, list); - H5_API_RETURN (h5t_get_adjacencies (f, entity_id, dim, list)); + H5_API_ENTER (h5_err_t, + "m=%p, entity_id=%lld, dim=%d, list=%p", + m, (long long)entity_id, dim, list); + H5_API_RETURN (h5t_get_adjacencies (m, entity_id, dim, list)); } static inline h5_err_t H5FedReleaseListOfAdjacencies ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idlist_t** list ) { - H5_API_ENTER2 (h5_err_t, - "f=0x%p, list=0x%p", - f, list); - H5_API_RETURN (h5t_release_list_of_adjacencies (f, list)); + H5_API_ENTER (h5_err_t, "f=%p, list=%p", m, list); + H5_API_RETURN (h5t_release_list_of_adjacencies (m, list)); } #ifdef __cplusplus diff --git a/src/include/H5Fed_inquiry.h b/src/include/H5Fed_inquiry.h index c7ea021..54b8a37 100644 --- a/src/include/H5Fed_inquiry.h +++ b/src/include/H5Fed_inquiry.h @@ -34,7 +34,7 @@ static inline h5_ssize_t H5FedGetNumTetrahedralMeshes ( h5_file_t* const f ) { - H5_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_API_ENTER (h5_err_t, "f=%p", f); H5_API_RETURN (h5t_get_num_tetmeshes (f)); } @@ -42,7 +42,7 @@ static inline h5_ssize_t H5FedGetNumTriangleMeshes ( h5_file_t* const f ) { - H5_API_ENTER1 (h5_err_t, "f=0x%p", f); + H5_API_ENTER (h5_err_t, "f=%p", f); H5_API_RETURN (h5t_get_num_trimeshes (f)); } @@ -55,10 +55,10 @@ H5FedGetNumTriangleMeshes ( */ static inline h5_ssize_t H5FedGetNumLevels ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5_ssize_t, "f=0x%p", f); - H5_API_RETURN (h5t_get_num_leaf_levels (f)); + H5_API_ENTER (h5_ssize_t, "m=%p", m); + H5_API_RETURN (h5t_get_num_leaf_levels (m)); } /*! @@ -70,10 +70,10 @@ H5FedGetNumLevels ( */ static inline h5t_lvl_idx_t H5FedGetLevel ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5t_lvl_idx_t, "f=0x%p", f); - H5_API_RETURN (h5t_get_level (f)); + H5_API_ENTER (h5t_lvl_idx_t, "m=%p", m); + H5_API_RETURN (h5t_get_level (m)); } /*! @@ -86,10 +86,10 @@ H5FedGetLevel ( */ static inline h5_ssize_t H5FedGetNumVertices ( - h5_file_t* const f /*!< file handle */ + h5t_mesh_t* const m /*!< file handle */ ) { - H5_API_ENTER1 (h5_ssize_t, "f=0x%p", f); - H5_API_RETURN (h5t_get_num_vertices (f, -1)); + H5_API_ENTER (h5_ssize_t, "m=%p", m); + H5_API_RETURN (h5t_get_num_vertices (m, -1)); } /*! @@ -103,11 +103,11 @@ H5FedGetNumVertices ( */ static inline h5_ssize_t H5FedGetNumVerticesCnode ( - h5_file_t* const f, + h5t_mesh_t* const m, const int cnode ) { - H5_API_ENTER2 (h5_ssize_t, "f=0x%p, cnode=%d", f, cnode); - H5_API_RETURN (h5t_get_num_vertices (f, cnode)); + H5_API_ENTER (h5_ssize_t, "m=%p, cnode=%d", m, cnode); + H5_API_RETURN (h5t_get_num_vertices (m, cnode)); } /*! @@ -120,10 +120,10 @@ H5FedGetNumVerticesCnode ( */ static inline h5_ssize_t H5FedGetNumVerticesTotal ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5_ssize_t, "f=0x%p", f); - H5_API_RETURN (h5t_get_num_vertices (f, -1)); + H5_API_ENTER (h5_ssize_t, "m=%p", m); + H5_API_RETURN (h5t_get_num_vertices (m, -1)); } /*! @@ -136,12 +136,12 @@ H5FedGetNumVerticesTotal ( */ static inline h5_ssize_t H5FedGetNumElements ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5_ssize_t, "f=0x%p", f); + H5_API_ENTER (h5_ssize_t, "m=%p", m); // MLH: can't use field from opaque h5_file_t! //h5_ssize_t num = h5t_get_num_elems (f, f->myproc); - H5_API_RETURN (h5t_get_num_elems (f, -1)); + H5_API_RETURN (h5t_get_num_elems (m, -1)); } /*! @@ -155,11 +155,11 @@ H5FedGetNumElements ( */ static inline h5_ssize_t H5FedGetNumElementsCnode ( - h5_file_t* const f, + h5t_mesh_t* const m, const int cnode ) { - H5_API_ENTER2 (h5_ssize_t, "f=0x%p, cnode=%d", f, cnode); - H5_API_RETURN (h5t_get_num_elems (f, cnode)); + H5_API_ENTER (h5_ssize_t, "m=%p, cnode=%d", m, cnode); + H5_API_RETURN (h5t_get_num_elems (m, cnode)); } /*! @@ -172,10 +172,10 @@ H5FedGetNumElementsCnode ( */ static inline h5_ssize_t H5FedGetNumElementsTotal ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5_ssize_t, "f=0x%p", f); - H5_API_RETURN (h5t_get_num_elems (f, -1)); + H5_API_ENTER (h5_ssize_t, "m=%p", m); + H5_API_RETURN (h5t_get_num_elems (m, -1)); } #ifdef __cplusplus diff --git a/src/include/H5Fed_retrieve.h b/src/include/H5Fed_retrieve.h index 76542cf..0144c17 100644 --- a/src/include/H5Fed_retrieve.h +++ b/src/include/H5Fed_retrieve.h @@ -36,32 +36,31 @@ extern "C" { static inline h5t_iterator_p H5FedBeginTraverseEntities ( - h5_file_t* const f, + h5t_mesh_t* const m, const int codim ) { - H5_API_ENTER2 (h5t_iterator_p, "f=0x%p, codim=%d", f, codim); + H5_API_ENTER (h5t_iterator_p, "m=%p, codim=%d", m, codim); h5t_iterator_p iter; TRY3 (h5t_iterator_p, iter = (h5t_iterator_p)h5_calloc (1, sizeof (*iter))); - TRY3 (h5t_iterator_p, h5t_init_leaf_iterator (f, iter, codim)); + TRY3 (h5t_iterator_p, h5t_init_leaf_iterator (iter, m, codim)); H5_API_RETURN (iter); } static inline h5t_iterator_p H5FedBeginTraverseBoundaryFaces ( - h5_file_t* const f, + h5t_mesh_t* const m, const int codim ) { - H5_API_ENTER2 (h5t_iterator_p, "f=0x%p, codim=%d", f, codim); + H5_API_ENTER (h5t_iterator_p, "m=%p, codim=%d", m, codim); h5t_iterator_p iter; TRY3 (h5t_iterator_p, iter = (h5t_iterator_p)h5_calloc (1, sizeof (*iter))); - TRY3 (h5t_iterator_p, h5t_init_boundary_face_iterator (f, iter, codim)); + TRY3 (h5t_iterator_p, h5t_init_boundary_face_iterator (iter, m, codim)); H5_API_RETURN (iter); } /*! Get next local entity ID. - \param[in] f file handle \param[in/out] iter iterator \return Local entity ID @@ -70,28 +69,26 @@ H5FedBeginTraverseBoundaryFaces ( */ static inline h5_loc_id_t H5FedTraverseEntities ( - h5_file_t* const f, h5t_iterator_t* iter ) { - H5_API_ENTER2 (h5_loc_id_t, "f=0x%p, iter=0x%p", f, iter); - H5_API_RETURN (h5t_iterate_entities (f, iter)); + H5_API_ENTER (h5_loc_id_t, "iter=%p", iter); + H5_API_RETURN (h5t_iterate_entities (iter)); } /*! End of traversing. Release internal data structures. - \param[in] f File handle + \param[in/out] iter iterator \return H5_SUCCESS or error code */ static inline h5_err_t H5FedEndTraverseEntities ( - h5_file_t* const f, h5t_iterator_t* iter ) { - H5_API_ENTER2 (h5_err_t, "f=0x%p, iter=0x%p", f, iter); - H5_API_RETURN (h5t_release_entity_iterator (f, iter)); + H5_API_ENTER (h5_err_t, "iter=%p", iter); + H5_API_RETURN (h5t_release_entity_iterator (iter)); } @@ -106,74 +103,74 @@ H5FedEndTraverseEntities ( */ static inline h5_err_t H5FedGetVertexCoordsByIndex ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t vertex_index, h5_float64_t P[3] ) { - H5_API_ENTER3 (h5_err_t, - "f=0x%p, vertex_index=%lld, P=0x%p", - f, (long long)vertex_index, P); - H5_API_RETURN (h5t_get_vertex_coords_by_index (f, vertex_index, P)); + H5_API_ENTER (h5_err_t, + "m=%p, vertex_index=%lld, P=%p", + m, (long long)vertex_index, P); + H5_API_RETURN (h5t_get_vertex_coords_by_index (m, vertex_index, P)); } static inline h5_err_t H5FedGetVertexCoordsByID ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t vertex_id, h5_float64_t P[3] ) { - H5_API_ENTER3 (h5_err_t, - "f=0x%p, vertex_id=%lld, P=0x%p", - f, (long long)vertex_id, P); - H5_API_RETURN (h5t_get_vertex_coords_by_id (f, vertex_id, P)); + H5_API_ENTER (h5_err_t, + "m=%p, vertex_id=%lld, P=%p", + m, (long long)vertex_id, P); + H5_API_RETURN (h5t_get_vertex_coords_by_id (m, vertex_id, P)); } static inline h5_err_t H5FedGetVertexIndicesOfEdge ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idx_t* vertex_indices ) { - H5_API_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%lld, vertex_indices=0x%p", - f, (long long)entity_id, vertex_indices); - H5_API_RETURN (h5t_get_vertex_indices_of_edge (f, entity_id, vertex_indices)); + H5_API_ENTER (h5_err_t, + "m=%p, entity_id=%lld, vertex_indices=%p", + m, (long long)entity_id, vertex_indices); + H5_API_RETURN (h5t_get_vertex_indices_of_edge (m, entity_id, vertex_indices)); } static inline h5_err_t H5FedGetVertexIndicesOfTriangle ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idx_t* vertex_indices ) { - H5_API_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%lld, vertex_indices=0x%p", - f, (long long)entity_id, vertex_indices); - H5_API_RETURN (h5t_get_vertex_indices_of_triangle (f, entity_id, vertex_indices)); + H5_API_ENTER (h5_err_t, + "m=%p, entity_id=%lld, vertex_indices=%p", + m, (long long)entity_id, vertex_indices); + H5_API_RETURN (h5t_get_vertex_indices_of_triangle (m, entity_id, vertex_indices)); } static inline h5_err_t H5FedGetVertexIndicesOfTet ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idx_t* vertex_indices ) { - H5_API_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%lld, vertex_indices=0x%p", - f, (long long)entity_id, vertex_indices); - H5_API_RETURN (h5t_get_vertex_indices_of_tet (f, entity_id, vertex_indices)); + H5_API_ENTER (h5_err_t, + "m=%p, entity_id=%lld, vertex_indices=%p", + m, (long long)entity_id, vertex_indices); + H5_API_RETURN (h5t_get_vertex_indices_of_tet (m, entity_id, vertex_indices)); } static inline h5_err_t H5FedGetVertexIndicesOfEntity ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t entity_id, h5_loc_idx_t* vertex_indices ) { - H5_API_ENTER3 (h5_err_t, - "f=0x%p, entity_id=%lld, vertex_indices=0x%p", - f, (long long)entity_id, vertex_indices); - H5_API_RETURN (h5t_get_vertex_indices_of_entity (f, entity_id, vertex_indices)); + H5_API_ENTER (h5_err_t, + "m=%p, entity_id=%lld, vertex_indices=%p", + m, (long long)entity_id, vertex_indices); + H5_API_RETURN (h5t_get_vertex_indices_of_entity (m, entity_id, vertex_indices)); } #ifdef __cplusplus diff --git a/src/include/H5Fed_store.h b/src/include/H5Fed_store.h index b1e423c..8a45768 100644 --- a/src/include/H5Fed_store.h +++ b/src/include/H5Fed_store.h @@ -23,20 +23,24 @@ extern "C" { #endif -static inline h5_id_t +static inline h5_err_t H5FedAddTetrahedralMesh ( - h5_file_t* const f + h5_file_t* const f, + const char* name, + h5t_mesh_t** mesh ) { - H5_API_ENTER1 (h5_id_t, "f=0x%p", f); - H5_API_RETURN (h5t_add_tetrahedral_mesh (f)); + H5_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh); + H5_API_RETURN (h5t_add_tetrahedral_mesh (f, name, mesh)); } -static inline h5_id_t +static inline h5_err_t H5FedAddTriangleMesh ( - h5_file_t* const f + h5_file_t* const f, + const char* name, + h5t_mesh_t** mesh ) { - H5_API_ENTER1 (h5_id_t, "f=0x%p", f); - H5_API_RETURN (h5t_add_triangle_mesh (f)); + H5_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh); + H5_API_RETURN (h5t_add_triangle_mesh (f, name, mesh)); } /*! @@ -61,21 +65,21 @@ H5FedAddTriangleMesh ( */ static inline h5t_lvl_idx_t H5FedAddLevel ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5t_lvl_idx_t, "f=0x%p", f); - H5_API_RETURN (h5t_add_level (f)); + H5_API_ENTER (h5t_lvl_idx_t, "m=%p", m); + H5_API_RETURN (h5t_add_level (m)); } static inline h5_err_t H5FedBeginStoreVertices ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_size_t num ) { - H5_API_ENTER2 (h5_err_t, - "f=0x%p, num=%llu", - f, (long long unsigned)num); - H5_API_RETURN (h5t_begin_store_vertices (f, num)); + H5_API_ENTER (h5_err_t, + "m=%p, num=%llu", + m, (long long unsigned)num); + H5_API_RETURN (h5t_begin_store_vertices (m, num)); } /*! @@ -89,39 +93,39 @@ H5FedBeginStoreVertices ( */ static inline h5_loc_idx_t H5FedStoreVertex ( - h5_file_t* const f, /*!< file handle */ + h5t_mesh_t* const m, /*!< file handle */ const h5_glb_id_t vertex_id, /*!< id from mesher or -1 */ const h5_float64_t P[3] /*!< coordinates */ ) { - H5_API_ENTER3 (h5_loc_idx_t, - "f=0x%p, vertex_id=%lld, P=0x%p", - f, (long long)vertex_id, P); - if (h5t_get_level (f) != 0) { + H5_API_ENTER (h5_loc_idx_t, + "m=%p, vertex_id=%lld, P=%p", + m, (long long)vertex_id, P); + if (h5t_get_level (m) != 0) { H5_API_LEAVE ( h5_error ( H5_ERR_INVAL, "Vertices can be added to level 0 only!")); } - H5_API_RETURN (h5t_store_vertex (f, vertex_id, P)); + H5_API_RETURN (h5t_store_vertex (m, vertex_id, P)); } static inline h5_err_t H5FedEndStoreVertices ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5_err_t, "f=0x%p", f); - H5_API_RETURN (h5t_end_store_vertices (f)); + H5_API_ENTER (h5_err_t, "m=%p", m); + H5_API_RETURN (h5t_end_store_vertices (m)); } static inline h5_err_t H5FedBeginStoreElements ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_size_t num ) { - H5_API_ENTER2 (h5_err_t, - "f=0x%p, num=%llu", - f, (long long unsigned)num); - H5_API_RETURN (h5t_begin_store_elems (f, num)); + H5_API_ENTER (h5_err_t, + "m=%p, num=%llu", + m, (long long unsigned)num); + H5_API_RETURN (h5t_begin_store_elems (m, num)); } /*! @@ -140,52 +144,52 @@ H5FedBeginStoreElements ( */ static inline h5_loc_idx_t H5FedStoreElement ( - h5_file_t* const f, /*!< file handle */ + h5t_mesh_t* const m, /*!< file handle */ const h5_loc_idx_t local_vids[] /*!< tuple with vertex id's */ ) { - H5_API_ENTER2 (h5_loc_idx_t, "f=0x%p, local_vids=0x%p", f, local_vids); - if (h5t_get_level (f) != 0) { + H5_API_ENTER (h5_loc_idx_t, "m=%p, local_vids=%p", m, local_vids); + if (h5t_get_level (m) != 0) { H5_API_LEAVE ( h5_error ( H5_ERR_INVAL, "Elements can be added to level 0 only!")); } - H5_API_RETURN (h5t_store_elem (f, -1, local_vids)); + H5_API_RETURN (h5t_store_elem (m, -1, local_vids)); } static inline h5_err_t H5FedEndStoreElements ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5_err_t, "f=0x%p", f); - H5_API_RETURN (h5t_end_store_elems (f)); + H5_API_ENTER (h5_err_t, "m=%p", m); + H5_API_RETURN (h5t_end_store_elems (m)); } static inline h5_err_t H5FedBeginRefineElements ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5_err_t, "f=0x%p", f); - H5_API_RETURN (h5t_begin_refine_elems (f)); + H5_API_ENTER (h5_err_t, "m=%p", m); + H5_API_RETURN (h5t_begin_refine_elems (m)); } static inline h5_loc_idx_t H5FedRefineElement ( - h5_file_t* const f, /*!< file handle */ + h5t_mesh_t* const m, /*!< file handle */ const h5_loc_id_t local_eid /*!< local element id */ ) { - H5_API_ENTER2 (h5_loc_idx_t, - "f=0x%p, local_eid=%lld", - f, (long long)local_eid); - H5_API_RETURN (h5t_mark_entity (f, local_eid)); + H5_API_ENTER (h5_loc_idx_t, + "m=%p, local_eid=%lld", + m, (long long)local_eid); + H5_API_RETURN (h5t_mark_entity (m, local_eid)); } static inline h5_err_t H5FedEndRefineElements ( - h5_file_t* const f + h5t_mesh_t* const m ) { - H5_API_ENTER1 (h5_err_t, "f=0x%p", f); - H5_API_RETURN (h5t_end_refine_elems (f)); + H5_API_ENTER (h5_err_t, "m=%p", m); + H5_API_RETURN (h5t_end_refine_elems (m)); } #ifdef __cplusplus diff --git a/src/include/H5Fed_tags.h b/src/include/H5Fed_tags.h index e858c09..3c51c54 100644 --- a/src/include/H5Fed_tags.h +++ b/src/include/H5Fed_tags.h @@ -5,143 +5,199 @@ extern "C" { #endif +/*! + Get number of tagsets assocciated with the mesh. + + \param[in] m mesh + */ +static inline h5_ssize_t +H5FedGetNumMTagsets ( + h5t_mesh_t* const m + ) { + H5_API_ENTER (h5_ssize_t, "m=%p", m); + H5_API_RETURN (h5t_get_num_mtagsets(m)); +} + +/*! + Get some information about the tagset \c name. + + \param[in] m mesh + \param[in] idx index of tagset to query + \param[out] name name of tagset + \param[in] len_name len of buffer \c name + \param[out] type type of tagset +*/ +static inline h5_err_t +H5FedGetMTagsetInfo ( + h5t_mesh_t* const m, + const h5_size_t idx, + char name[], + const h5_size_t len_name, + h5_int64_t* const type + ) { + H5_API_ENTER (h5_err_t, + "m=%p, idx=%llu, name=%p, len_name=%llu, type=%p", + m, (long long unsigned)idx, name, + (long long unsigned)len_name, type); + H5_API_RETURN (h5t_get_mtagset_info (m, idx, name, len_name, type)); +} + +/*! + Test whether tagset \c name exists. + + \param[in] m mesh + \param[out] name name of tagset to test existance +*/ +static inline h5_err_t +H5FedMTagsetExists ( + h5t_mesh_t* const m, + const char name[] + ) { + H5_API_ENTER (h5_err_t, "m=%p, name=%s", m, name); + H5_API_RETURN (h5t_mtagset_exists (m, name)); +} + /*! Add a tagset to the current mesh. - \param[in] f file handle - \param[in] name name of tagset - \param[in] type data type of tagset + \param[in] m mesh to add a tagset to + \param[in] name name of tagset + \param[in] type data type of tagset + \param[out] tagset new tagset \return H5_SUCCESS or error code */ static inline h5_err_t H5FedAddMTagset ( - h5_file_t* const f, - char* name, - h5_id_t type + h5t_mesh_t* const m, + const char name[], + const h5_id_t type, + h5t_tagset_t** tagset ) { - H5_API_ENTER3 (h5_err_t, "f=0x%p, name=\"%s\", type=%lld", - f, name, (long long)type); - H5_API_RETURN (h5t_add_mtagset (f, name, type)); + H5_API_ENTER (h5_err_t, + "m=%p, name='%s', type=%lld tagset=%p", + m, name, (long long)type, tagset); + H5_API_RETURN (h5t_create_mtagset (m, name, type, tagset)); } /*! - Remove a tagset from the current mesh. + Open tagset \c name. - \param[in] f file handle + \param[in] m mesh + \param[in] name name of tagset to open + \param[out] tagset open tagset + + \return H5_SUCCESS or error code + */ +static inline h5_err_t +H5FedOpenMTagset ( + h5t_mesh_t* const m, + const char name[], + h5t_tagset_t** tagset + ) { + H5_API_ENTER (h5_err_t, + "m=%p, name='%s', tagset=%p", + m, name, tagset); + H5_API_RETURN (h5t_open_mtagset (m, name, tagset)); +} + +/*! + Close tagset. + + \param[in] tagset open tagset + + \return H5_SUCCESS or error code + */ +static inline h5_err_t +H5FedCloseMTagset ( + h5t_tagset_t* tagset + ) { + H5_API_ENTER (h5_err_t, "tagset=%p", tagset); + H5_API_RETURN (h5t_close_mtagset(tagset)); +} + +/*! + Remove tagset from mesh + + \param[in] tagset tagset \param[in] name name of tagset to remove \return H5_SUCCESS or error code */ static inline h5_err_t H5FedRemoveMTagset ( - h5_file_t* const f, - char name[] + h5t_mesh_t* m, + const char name[] ) { - H5_API_ENTER2 (h5_err_t, "f=0x%p, name=\"%s\"", f, name); - H5_API_RETURN (h5t_remove_mtagset (f, name)); -} - -/*! - Get available tagsets in current mesh. - - \param[in] f file handle - \param[out] names names of available tagsets - - \return Number of tagsets or error code - */ -static inline h5_ssize_t -H5FedGetMTagsets ( - h5_file_t* const f, - char** names[] - ) { - H5_API_ENTER2 (h5_ssize_t, "f=0x%p, names=0x%p", f, names); - H5_API_RETURN (h5t_get_mtagsets (f, names)); -} - -/*! - Get type of tagset in current mesh. - - \param[in] f file handle - \param[in] name name of tagset - - \return H5_SUCCESS or error code - */ -static inline h5_id_t -H5FedGetTypeOfMTagset ( - h5_file_t* const f, - char name[] - ) { - H5_API_ENTER2 (h5_err_t, "f=0x%p, name=\"%s\"", f, name); - H5_API_RETURN (h5t_get_mtagset_type_by_name (f, name)); + H5_API_ENTER (h5_err_t, "m=%p, name='%s'", m, name); + H5_API_RETURN (h5t_remove_mtagset (m, name)); } /*! Set tag for entity in current mesh. - \param[in] f file handle - \param[in] name names of tagset - \param[in] id id of entity - \param[in] dim dimension of value - \param[in] val tag value + \param[in] tagset ptr tagset + \param[in] entity_id id of entity + \param[in] size size of value + \param[in] val tag value \return H5_SUCCESS or error code */ static inline h5_err_t -H5FedSetMTag ( - h5_file_t* const f, - char name[], - h5_loc_id_t id, - const size_t dim, - void* buffer +H5FedSetTag ( + h5t_tagset_t* const tagset, + h5_loc_id_t entity_id, + const h5_size_t size, + void* val ) { - H5_API_ENTER5 (h5_err_t, - "f=0x%p, name=\"%s\", id=%lld, dim=%lld, val=0x%p", - f, name, (long long)id, (long long)dim, buffer); - H5_API_RETURN (h5t_set_mtag_by_name (f, name, id, dim, buffer)); + H5_API_ENTER (h5_err_t, + "tagset=%p, entity_id=%lld, size=%lld, val=%p", + tagset, (long long)entity_id, (long long)size, val); + H5_API_RETURN (h5t_set_tag (tagset, entity_id, size, val)); } /*! - Set tag for entity in current mesh. + Get tag for entity in current mesh. If entity is not tagged, return tag of + the next coarser tagged entity. The corresponding entity ID is returned. - \param[in] f file handle - \param[in] name names of tagset - \param[in] id id of entity - \param[out] dim dimension of value - \param[out] val tag value + \param[in] tagset ptr to tagset + \param[in] entity_id id of entity to tag + \param[out] size size of value + \param[out] val tag value - \return H5_SUCCESS or error code + \return entity id + \return H5_ERR on error */ -static inline h5_err_t -H5FedGetMTag ( - h5_file_t* const f, - const char name[], - const h5_loc_id_t id, - size_t* dim, - void* buffer +static inline h5_loc_id_t +H5FedGetTag ( + h5t_tagset_t* const tagset, + const h5_loc_id_t entity_id, + h5_size_t* size, + void* val ) { - H5_API_ENTER5 (h5_err_t, - "f=0x%p, name=\"%s\", id=%lld, dim=0x%p, val=0x%p", - f, name, (long long)id, dim, buffer); - H5_API_RETURN (h5t_get_mtag_by_name (f, name, id, dim, buffer)); + H5_API_ENTER (h5_err_t, + "tagset=%p, entity_id=%lld, size=%p, val=%p", + tagset, (long long)entity_id, size, val); + H5_API_RETURN (h5t_get_tag (tagset, entity_id, size, val)); } /*! Remove tag for entity in current mesh. - \param[in] f file handle - \param[in] name names of tagset - \param[in] id id of entity + \param[in] tagset ptr to tagset tagset + \param[in] entity_id id of entity from which the tag must be removed. + + \return H5_SUCCESS or error code */ static inline h5_err_t H5FedRemoveMTag ( - h5_file_t* const f, - const char name[], - const h5_loc_id_t id + h5t_tagset_t* const tagset, + const h5_loc_id_t entity_id ) { - H5_API_ENTER3 (h5_err_t, "f=0x%p, name=\"%s\", id=%lld", - f, name, (long long)id); - H5_API_RETURN (h5t_remove_mtag_by_name (f, name, id)); + H5_API_ENTER (h5_err_t, + "tagset=%p, entity_id=%lld", + tagset, (long long)entity_id); + H5_API_RETURN (h5t_remove_tag (tagset, entity_id)); } #ifdef __cplusplus diff --git a/src/include/h5core/h5_core.h b/src/include/h5core/h5_core.h index e03ca15..5cce786 100644 --- a/src/include/h5core/h5_core.h +++ b/src/include/h5core/h5_core.h @@ -21,181 +21,103 @@ extern "C" { extern char* h5_rfmts[]; -#define __FUNC_ENTER(type) \ - h5_call_stack_push (__func__,e_##type); \ +////////////////////////////////////////////////////////////////////////////// +// function enter macro +#if defined(NDEBUG) + +#define __API_ENTER(type, mask, fmt, ...) \ + h5_call_stack_init (__func__,e_##type); \ type ret_value = (type)H5_ERR; -#if defined(NDEBUG) - -#define __FUNC_ARGS0(mask) -#define __FUNC_ARGS1(fmt, a1, mask) -#define __FUNC_ARGS2(fmt, a1, a2, mask) -#define __FUNC_ARGS3(fmt, a1, a2, a3, mask) -#define __FUNC_ARGS4(fmt, a1, a2, a3, a4, mask) -#define __FUNC_ARGS5(fmt, a1, a2, a3, a4, a5, mask) -#define __FUNC_ARGS6(fmt, a1, a2, a3, a4, a5, a6, mask) -#define __FUNC_ARGS7(fmt, a1, a2, a3, a4, a5, a6, a7, mask) -#define __FUNC_ARGS8(fmt, a1, a2, a3, a4, a5, a6, a7, a8, mask) +#define __FUNC_ENTER(type, mask, fmt, ...) \ + type ret_value = (type)H5_ERR; #else -#define __FUNC_ARGS0(mask) \ - if (h5_debug_level & mask ) { \ - h5_debug ("(void)"); \ +#define __API_ENTER(type, mask, fmt, ...) \ + h5_call_stack_push (__func__,e_##type); \ + type ret_value = (type)H5_ERR; \ + if (h5_debug_level & mask ) { \ + h5_debug ("(" fmt ")", __VA_ARGS__); \ } -#define __FUNC_ARGS1(fmt, a1, mask) \ - if (h5_debug_level & mask ) { \ - h5_debug ("(" fmt ")", a1); \ - } +#define __FUNC_ENTER(type, mask, fmt, ...) \ + type ret_value = (type)H5_ERR; \ + if (h5_debug_level & mask ) { \ + h5_call_stack_push (__func__,e_##type); \ + h5_debug ("(" fmt ")", __VA_ARGS__); \ + } \ -#define __FUNC_ARGS2(fmt, a1, a2, mask) \ - if (h5_debug_level & mask ) { \ - h5_debug ("(" fmt ")", a1, a2); \ - } - -#define __FUNC_ARGS3(fmt, a1, a2, a3, mask) \ - if (h5_debug_level & mask ) { \ - h5_debug ("(" fmt ")", a1, a2, a3); \ - } - -#define __FUNC_ARGS4(fmt, a1, a2, a3, a4, mask) \ - if (h5_debug_level & mask ) { \ - h5_debug ("(" fmt ")", a1, a2, a3, a4); \ - } - -#define __FUNC_ARGS5(fmt, a1, a2, a3, a4, a5, mask) \ - if (h5_debug_level & mask ) { \ - h5_debug ("(" fmt ")", a1, a2, a3, a4, a5); \ - } - -#define __FUNC_ARGS6(fmt, a1, a2, a3, a4, a5, a6, mask) \ - if (h5_debug_level & mask ) { \ - h5_debug ("(" fmt ")", a1, a2, a3, a4, a5, a6); \ - } - -#define __FUNC_ARGS7(fmt, a1, a2, a3, a4, a5, a6, a7, mask) \ - if (h5_debug_level & mask ) { \ - h5_debug ("(" fmt ")", a1, a2, a3, a4, a5, a6, a7); \ - } - -#define __FUNC_ARGS8(fmt, a1, a2, a3, a4, a5, a6, a7, a8, mask) \ - if (h5_debug_level & mask ) { \ - h5_debug ("(" fmt ")", a1, a2, a3, a4, a5, a6, a7, a8); \ - } #endif +// +////////////////////////////////////////////////////////////////////////////// -#define __FUNC_ENTER0(type, mask) \ - __FUNC_ENTER(type); \ - __FUNC_ARGS0(mask); +#define __API_LEAVE(expr) { \ + ret_value = expr; \ + goto done; \ + } -#define __FUNC_ENTER1(type, fmt, a1, mask) \ - __FUNC_ENTER(type); \ - __FUNC_ARGS1(fmt, a1, mask); - -#define __FUNC_ENTER2(type, fmt, a1, a2, mask) \ - __FUNC_ENTER(type); \ - __FUNC_ARGS2(fmt, a1, a2, mask); - -#define __FUNC_ENTER3(type, fmt, a1, a2, a3, mask) \ - __FUNC_ENTER(type); \ - __FUNC_ARGS3(fmt, a1, a2, a3, mask); - -#define __FUNC_ENTER4(type, fmt, a1, a2, a3, a4, mask) \ - __FUNC_ENTER(type); \ - __FUNC_ARGS4(fmt, a1, a2, a3, a4, mask); - -#define __FUNC_ENTER5(type, fmt, a1, a2, a3, a4, a5, mask) \ - __FUNC_ENTER(type); \ - __FUNC_ARGS5(fmt, a1, a2, a3, a4, a5, mask); - -#define __FUNC_ENTER6(type, fmt, a1, a2, a3, a4, a5, a6, mask) \ - __FUNC_ENTER(type); \ - __FUNC_ARGS6(fmt, a1, a2, a3, a4, a5, a6, mask); - -#define __FUNC_ENTER7(type, fmt, a1, a2, a3, a4, a5, a6, a7, mask) \ - __FUNC_ENTER(type); \ - __FUNC_ARGS7(fmt, a1, a2, a3, a4, a5, a6, a7, mask); - -#define __FUNC_ENTER8(type, fmt, a1, a2, a3, a4, a5, a6, a7, a8, mask) \ - __FUNC_ENTER(type); \ - __FUNC_ARGS8(fmt, a1, a2, a3, a4, a5, a6, a7, a8, mask); - -#define __FUNC_LEAVE(expr) { \ - ret_value = expr; \ - goto done; \ +#define __FUNC_LEAVE(expr) { \ + ret_value = expr; \ + goto done; \ } +////////////////////////////////////////////////////////////////////////////// +// function return macro #if defined(NDEBUG) -#define __FUNC_RETURN(expr, mask) \ - ret_value = expr; \ - goto done; \ -done: \ - h5_call_stack_pop(); \ +#define __API_RETURN(expr, mask) \ + ret_value = expr; \ + goto done; \ +done: \ + h5_call_stack_reset (); \ + return ret_value; + +#define __FUNC_RETURN(expr, mask) \ + ret_value = expr; \ + goto done; \ +done: \ return ret_value; #else -#define __FUNC_RETURN(expr, mask) \ - ret_value = expr; \ - goto done; \ -done: \ - if (h5_debug_level & mask ) { \ - char fmt[256]; \ - snprintf (fmt, sizeof(fmt), "return: %s", \ - h5_rfmts[h5_call_stack_get_type()]); \ - h5_debug (fmt, ret_value); \ - } \ - h5_call_stack_pop(); \ +#define __API_RETURN(expr, mask) \ + ret_value = expr; \ + goto done; \ +done: \ + if (h5_debug_level & mask ) { \ + char fmt[256]; \ + snprintf (fmt, sizeof(fmt), "return: %s", \ + h5_rfmts[h5_call_stack_get_type()]); \ + h5_debug (fmt, ret_value); \ + } \ + h5_call_stack_reset (); \ + return ret_value; + +#define __FUNC_RETURN(expr, mask) \ + ret_value = expr; \ + goto done; \ +done: \ + if (h5_debug_level & mask ) { \ + char fmt[256]; \ + snprintf (fmt, sizeof(fmt), "return: %s", \ + h5_rfmts[h5_call_stack_get_type()]); \ + h5_debug (fmt, ret_value); \ + h5_call_stack_pop(); \ + } \ return ret_value; #endif +// +////////////////////////////////////////////////////////////////////////////// -#define H5_API_ENTER_(type) \ - if (!h5_initialized) { \ - h5_initialize(); \ - } \ - __FUNC_ENTER(type); - -#define H5_API_ENTER0(type) \ - H5_API_ENTER_(type); \ - __FUNC_ARGS0(H5_DEBUG_API) - -#define H5_API_ENTER1(type, fmt, a1) \ - H5_API_ENTER_(type); \ - __FUNC_ARGS1(fmt, a1, H5_DEBUG_API) - -#define H5_API_ENTER2(type, fmt, a1, a2) \ - H5_API_ENTER_(type); \ - __FUNC_ARGS2(fmt, a1,a2, H5_DEBUG_API) - -#define H5_API_ENTER3(type, fmt, a1, a2, a3) \ - H5_API_ENTER_(type); \ - __FUNC_ARGS3(fmt, a1,a2,a3, H5_DEBUG_API) - -#define H5_API_ENTER4(type, fmt, a1, a2, a3, a4) \ - H5_API_ENTER_(type); \ - __FUNC_ARGS4(fmt, a1,a2,a3, a4, H5_DEBUG_API) - -#define H5_API_ENTER5(type, fmt, a1, a2, a3, a4, a5) \ - H5_API_ENTER_(type); \ - __FUNC_ARGS5(fmt, a1,a2,a3, a4, a5, H5_DEBUG_API) - -#define H5_API_ENTER6(type, fmt, a1, a2, a3, a4, a5, a6) \ - H5_API_ENTER_(type); \ - __FUNC_ARGS6(fmt, a1,a2,a3, a4, a5, a6, H5_DEBUG_API) - -#define H5_API_ENTER7(type, fmt, a1, a2, a3, a4, a5, a6, a7) \ - H5_API_ENTER_(type); \ - __FUNC_ARGS7(fmt, a1,a2,a3, a4, a5, a6, a7, H5_DEBUG_API) - -#define H5_API_ENTER8(type, fmt, a1, a2, a3, a4, a5, a6, a7, a8) \ - H5_API_ENTER_(type); \ - __FUNC_ARGS8(fmt, a1,a2,a3, a4, a5, a6, a7, a8, H5_DEBUG_API) - -#define H5_API_LEAVE(expr) __FUNC_LEAVE(expr) -#define H5_API_RETURN(expr) __FUNC_RETURN(expr, H5_DEBUG_API); +#define H5_API_ENTER(type, fmt, ...) \ + if (!h5_initialized) { \ + h5_initialize(); \ + } \ + __API_ENTER(type, H5_DEBUG_API, fmt, __VA_ARGS__) +#define H5_API_LEAVE(expr) __API_LEAVE(expr) +#define H5_API_RETURN(expr) __API_RETURN(expr, H5_DEBUG_API); #define TRY( func ) \ diff --git a/src/include/h5core/h5_errorhandling.h b/src/include/h5core/h5_errorhandling.h index e3fdced..a8b5a36 100644 --- a/src/include/h5core/h5_errorhandling.h +++ b/src/include/h5core/h5_errorhandling.h @@ -58,6 +58,9 @@ h5_initialize ( H5_ERR_INVAL, \ "Attempting to write to read-only file" ); +#define is_writable(f) (f->mode != H5_O_RDONLY) + + #define CHECK_READONLY_MODE( f ) \ if ( ! f->mode==H5_O_RDONLY ) \ return h5_error ( \ @@ -73,7 +76,7 @@ h5_initialize ( #define h5_error_not_implemented() \ h5_error( \ H5_ERR_NOT_IMPLEMENTED, \ - "%s: Function \"%s\", line %d not yet implemented!", \ + "%s: Function '%s', line %d not yet implemented!", \ __FILE__, __func__, __LINE__); #define h5_error_internal() \ diff --git a/src/include/h5core/h5_openclose.h b/src/include/h5core/h5_openclose.h index 8bf7885..d6736d0 100644 --- a/src/include/h5core/h5_openclose.h +++ b/src/include/h5core/h5_openclose.h @@ -9,7 +9,8 @@ h5_file_t * h5_open_file ( const char *filename, h5_int32_t flags, - MPI_Comm comm + MPI_Comm comm, + h5_size_t alignment ); h5_err_t diff --git a/src/include/h5core/h5_syscall.h b/src/include/h5core/h5_syscall.h index 634f853..2842dc3 100644 --- a/src/include/h5core/h5_syscall.h +++ b/src/include/h5core/h5_syscall.h @@ -1,26 +1,71 @@ #ifndef __H5_SYSCALL_H #define __H5_SYSCALL_H +#include +#include +#include "h5_errorhandling.h" + +#define MALLOC_WRAPPER_ENTER(type, fmt, ...) \ + __FUNC_ENTER(type, H5_DEBUG_MALLOC, fmt, __VA_ARGS__) +#define MALLOC_WRAPPER_LEAVE(value) __FUNC_LEAVE(value) +#define MALLOC_WRAPPER_RETURN(value) __FUNC_RETURN(value, H5_DEBUG_MALLOC) + #ifdef __cplusplus extern "C" { #endif -void* +static inline void_p h5_alloc ( void* ptr, const size_t size - ); + ) { + MALLOC_WRAPPER_ENTER (void_p, "ptr=%p, size=%lu", ptr, size); + ptr = realloc (ptr, size); + if (ptr == NULL) { + MALLOC_WRAPPER_LEAVE ( + (void_p)h5_error (H5_ERR_NOMEM, "Out of memory.")); + } + MALLOC_WRAPPER_RETURN (ptr); +} -void* +static inline void_p h5_calloc ( const size_t count, const size_t size - ); + ) { + MALLOC_WRAPPER_ENTER (void_p, "count=%zu , size=%zu", count, size); + void* ptr = calloc (count, size); + if (ptr == NULL) { + MALLOC_WRAPPER_LEAVE ( + (void_p)h5_error (H5_ERR_NOMEM, "Out of memory.")); + } + MALLOC_WRAPPER_RETURN (ptr); +} -h5_err_t +static inline h5_err_t h5_free ( void* ptr - ); + ) { + MALLOC_WRAPPER_ENTER (h5_err_t, "ptr=%p", ptr); + if (ptr) { + free (ptr); + } + MALLOC_WRAPPER_RETURN (H5_SUCCESS); +} + +static inline char_p +h5_strdup ( + const char* s1 + ) { + MALLOC_WRAPPER_ENTER (char_p, "s='%s'", s1); + + char_p s2 = h5_calloc (1, strlen (s1)+1 ); + if (s2 == NULL) { + MALLOC_WRAPPER_LEAVE ( + (char_p)h5_error (H5_ERR_NOMEM, "Out of memory.")); + } + MALLOC_WRAPPER_RETURN (strcpy (s2, s1)); +} #ifdef __cplusplus } diff --git a/src/include/h5core/h5_types.h b/src/include/h5core/h5_types.h index 00e73ed..4a88309 100644 --- a/src/include/h5core/h5_types.h +++ b/src/include/h5core/h5_types.h @@ -16,21 +16,26 @@ extern "C" { H5_O_RDWR: dataset may exist */ -#define H5_O_RDWR 0x01 -#define H5_O_RDONLY 0x02 -#define H5_O_WRONLY 0x04 -#define H5_O_APPEND 0x08 +#define H5_O_RDWR 0x001 +#define H5_O_RDONLY 0x002 +#define H5_O_WRONLY 0x004 +#define H5_O_APPEND 0x008 -#define H5_VFD_MPIPOSIX 0x10 -#define H5_VFD_INDEPENDENT 0x20 +#define H5_VFD_MPIPOSIX 0x010 +#define H5_VFD_INDEPENDENT 0x020 -#define H5_O_FLUSHSTEP 0x40 +#define H5_FLUSH_FILE 0x040 +#define H5_FLUSH_STEP 0x080 +#define H5_FLUSH_DATASET 0x100 + +#define H5_FS_LUSTRE 0x200 #define H5_ID_T H5T_NATIVE_INT64 #define H5_FLOAT64_T H5T_NATIVE_DOUBLE #define H5_FLOAT32_T H5T_NATIVE_FLOAT #define H5_INT64_T H5T_NATIVE_INT64 #define H5_INT32_T H5T_NATIVE_INT32 +#define H5_INT16_T H5T_NATIVE_INT16 #define H5_STRING_T H5T_NATIVE_CHAR #define H5_COMPOUND_T H5T_COMPOUND @@ -72,6 +77,10 @@ struct h5_file; typedef struct h5_file h5_file_t; typedef h5_file_t* h5_file_p; +struct h5t_mesh; +typedef struct h5t_mesh h5t_mesh_t; +typedef h5t_mesh_t* h5t_mesh_p; + typedef h5_err_t (*h5_errorhandler_t)( const char*, va_list ap ); diff --git a/src/include/h5core/h5t_adjacencies.h b/src/include/h5core/h5t_adjacencies.h index 3892e6f..111abde 100644 --- a/src/include/h5core/h5t_adjacencies.h +++ b/src/include/h5core/h5t_adjacencies.h @@ -7,7 +7,7 @@ extern "C" { h5_err_t h5t_get_adjacencies ( - h5_file_t * const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, const h5_int32_t dim, h5_loc_idlist_t **list @@ -15,13 +15,13 @@ h5t_get_adjacencies ( h5_err_t h5t_release_list_of_adjacencies ( - h5_file_t * const f, + h5t_mesh_t* const m, h5_loc_idlist_t **list ); h5_err_t h5t_find_te2 ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_idx_t face_idx, h5_loc_idx_t elem_idx, h5_loc_idlist_t** retval diff --git a/src/include/h5core/h5t_inquiry.h b/src/include/h5core/h5t_inquiry.h index 85c31d0..f8dd609 100644 --- a/src/include/h5core/h5t_inquiry.h +++ b/src/include/h5core/h5t_inquiry.h @@ -17,24 +17,24 @@ h5t_get_num_trimeshes ( h5_ssize_t h5t_get_num_leaf_levels ( - h5_file_t * const f + h5t_mesh_t* const m ); h5_ssize_t h5t_get_num_elems ( - h5_file_t * const f, + h5t_mesh_t* const m, const h5_id_t cnode ); h5_ssize_t h5t_get_num_vertices ( - h5_file_t * const f, + h5t_mesh_t* const m, const h5_id_t cnode ); h5t_lvl_idx_t h5t_get_level ( - h5_file_t * const f + h5t_mesh_t* const m ); #ifdef __cplusplus diff --git a/src/include/h5core/h5t_map.h b/src/include/h5core/h5t_map.h index de063eb..2cf56d6 100644 --- a/src/include/h5core/h5t_map.h +++ b/src/include/h5core/h5t_map.h @@ -7,13 +7,13 @@ extern "C" { h5_loc_idx_t h5t_map_global_vertex_idx2local ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_glb_idx_t glb_idx ); h5_err_t h5t_map_global_vertex_indices2local ( - h5_file_t* f, + h5t_mesh_t* f, const h5_glb_id_t* const glb_indices, const h5_size_t size, h5_loc_idx_t* const loc_indices @@ -21,13 +21,13 @@ h5t_map_global_vertex_indices2local ( h5_loc_idx_t h5t_map_glb_elem_idx2loc ( - h5_file_t * const f, + h5t_mesh_t* const m, const h5_glb_idx_t glb_idx ); h5_err_t h5t_map_glb_elem_indices2loc ( - h5_file_t * const f, + h5t_mesh_t* const m, const h5_glb_idx_t* glb_indices, const h5_size_t size, h5_loc_idx_t* loc_indices @@ -35,14 +35,14 @@ h5t_map_glb_elem_indices2loc ( h5_err_t h5t_get_vertex_index_of_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idx_t* vertex_index ); h5_err_t h5t_get_vertex_index_of_vertex2 ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t face_idx, const h5_loc_idx_t elem_idx, h5_loc_idx_t* vertex_indices @@ -50,14 +50,14 @@ h5t_get_vertex_index_of_vertex2 ( h5_err_t h5t_get_vertex_indices_of_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idx_t *vertex_indices ); h5_err_t h5t_get_vertex_indices_of_edge2 ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t face_idx, const h5_loc_idx_t elem_id, h5_loc_idx_t* vertex_indices @@ -65,14 +65,14 @@ h5t_get_vertex_indices_of_edge2 ( h5_err_t h5t_get_vertex_indices_of_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idx_t* vertex_indices ); h5_err_t h5t_get_vertex_indices_of_triangle2 ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_idx_t face_idx, const h5_loc_idx_t elem_idx, h5_loc_idx_t* vertex_indices @@ -80,21 +80,21 @@ h5t_get_vertex_indices_of_triangle2 ( h5_err_t h5t_get_vertex_indices_of_tet ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idx_t *vertex_indices ); h5_err_t h5t_get_vertex_indices_of_entity ( - h5_file_t * const f, + h5t_mesh_t* const m, const h5_loc_id_t entity_id, h5_loc_idx_t *vertex_indices ); h5_err_t h5t_get_vertex_indices_of_entity2 ( - h5_file_t* const f, + h5t_mesh_t* const m, const int dim, const h5_loc_idx_t face_idx, const h5_loc_idx_t elem_idx, diff --git a/src/include/h5core/h5t_model.h b/src/include/h5core/h5t_model.h index dec47de..77764af 100644 --- a/src/include/h5core/h5t_model.h +++ b/src/include/h5core/h5t_model.h @@ -5,33 +5,20 @@ extern "C" { #endif -h5_err_t h5t_open_tetrahedral_mesh ( - h5_file_t * const f, - const h5_id_t id - ); +h5_err_t h5t_open_tetrahedral_mesh (h5_file_t* const, const char*, h5t_mesh_t**); +h5_err_t h5t_open_tetrahedral_mesh_by_idx (h5_file_t* const, const h5_id_t, h5t_mesh_t**); -h5_err_t h5t_open_triangle_mesh ( - h5_file_t * const f, - const h5_id_t id - ); +h5_err_t h5t_open_triangle_mesh (h5_file_t* const, const char*, h5t_mesh_t**); +h5_err_t h5t_open_triangle_mesh_by_idx (h5_file_t* const, const h5_id_t, h5t_mesh_t**); -h5_id_t -h5t_add_tetrahedral_mesh ( - h5_file_t * const f - ); -h5_id_t -h5t_add_triangle_mesh ( - h5_file_t * const f - ); +h5_id_t h5t_add_tetrahedral_mesh (h5_file_t* const, const char* name, h5t_mesh_t**); -h5_err_t h5t_set_level ( - h5_file_t * const f, - const h5t_lvl_idx_t id - ); -h5_err_t h5t_close_mesh ( - h5_file_t * const f - ); +h5_id_t h5t_add_triangle_mesh (h5_file_t* const, const char*, h5t_mesh_t**); + +h5_err_t h5t_set_level (h5t_mesh_t* const, const h5t_lvl_idx_t); + +h5_err_t h5t_close_mesh (h5t_mesh_t* const); #ifdef __cplusplus } diff --git a/src/include/h5core/h5t_retrieve.h b/src/include/h5core/h5t_retrieve.h index e134aba..1d6e88d 100644 --- a/src/include/h5core/h5t_retrieve.h +++ b/src/include/h5core/h5t_retrieve.h @@ -9,29 +9,31 @@ struct h5t_tagset; union h5t_iterator; typedef struct { - h5_loc_id_t (*iter)(h5_file_t *const f, union h5t_iterator* iter); + h5t_mesh_t* mesh; + h5_loc_id_t (*iter)(union h5t_iterator*); h5t_lvl_idx_t leaf_level; const h5t_ref_elem_t* ref_elem; h5_loc_idx_t elem_idx; h5_loc_idx_t face_idx; // face according reference element int codim; // dimension of entities to traverse - h5_err_t (*find)(h5_file_t *const f, h5_loc_id_t face_idx, - h5_loc_id_t elem_idx, h5_loc_idlist_t **retval); + h5_err_t (*find)(h5t_mesh_t *const, h5_loc_id_t, h5_loc_id_t, h5_loc_idlist_t**); } h5t_leaf_iterator_t; typedef struct { - h5_loc_id_t (*iter)(h5_file_t *const f, union h5t_iterator* iter); + h5t_mesh_t* mesh; + h5_loc_id_t (*iter)(union h5t_iterator* iter); h5t_lvl_idx_t refinement_level; const h5t_ref_elem_t* ref_elem; h5_loc_idx_t elem_idx; h5_loc_idx_t face_idx; // face according reference element int codim; // dimension of entities to traverse - h5_err_t (*find)(h5_file_t *const f, h5_loc_id_t face_idx, + h5_err_t (*find)(h5t_mesh_t *const f, h5_loc_id_t face_idx, h5_loc_id_t elem_idx, h5_loc_idlist_t **retval); } h5t_level_iterator_t; typedef struct { - h5_loc_id_t (*iter)(h5_file_t *const f, union h5t_iterator* iter); + h5t_mesh_t* mesh; + h5_loc_id_t (*iter)(union h5t_iterator* iter); h5t_lvl_idx_t level_idx; struct h5t_tagset* tagset; h5_loc_idx_t elem_idx; @@ -39,7 +41,8 @@ typedef struct { } h5t_tag_iterator_t; typedef struct h5t_generic_iterator { - h5_loc_id_t (*iter)(h5_file_t *const f, union h5t_iterator* iter); + h5t_mesh_t* mesh; + h5_loc_id_t (*iter)(union h5t_iterator* iter); } h5t_generic_iterator_t; typedef union h5t_iterator { @@ -52,58 +55,28 @@ typedef union h5t_iterator { typedef h5t_iterator_t* h5t_iterator_p; h5_err_t -h5t_init_leaf_iterator ( - h5_file_t* f, - h5t_iterator_t* iter, - const int codim - ); +h5t_init_leaf_iterator (h5t_iterator_t*, h5t_mesh_t*, const int); h5_err_t -h5t_init_boundary_face_iterator ( - h5_file_t* f, - h5t_iterator_t* iter, - const int codim - ); +h5t_init_boundary_face_iterator (h5t_iterator_t*, h5t_mesh_t*, const int); h5_err_t -h5t_init_mtag_iterator ( - h5_file_t* f, - h5t_iterator_t* iter, - const char* name - ); +h5t_init_mtag_iterator (h5t_iterator_t*, h5t_mesh_t*, const char*); h5_err_t -h5t_release_entity_iterator ( - h5_file_t* const f, - h5t_iterator_t* iter - ); +h5t_release_entity_iterator (h5t_iterator_t*); h5_loc_id_t -h5t_iterate_entities ( - h5_file_t * const f, - h5t_iterator_t *iter - ); +h5t_iterate_entities (h5t_iterator_t*); h5_err_t -h5t_end_iterate_entities ( - h5_file_t * const f, - h5t_iterator_t *iter - ); - +h5t_end_iterate_entities (h5t_iterator_t*); h5_err_t -h5t_get_vertex_coords_by_index ( - h5_file_t* const f, - h5_loc_idx_t vertex_idx, - h5_float64_t P[3] - ); +h5t_get_vertex_coords_by_index (h5t_mesh_t* const, h5_loc_idx_t, h5_float64_t[3]); h5_err_t -h5t_get_vertex_coords_by_id ( - h5_file_t* const f, - h5_loc_id_t vertex_id, - h5_float64_t P[3] - ); +h5t_get_vertex_coords_by_id (h5t_mesh_t* const, h5_loc_id_t, h5_float64_t[3]); #ifdef __cplusplus } diff --git a/src/include/h5core/h5t_storemesh.h b/src/include/h5core/h5t_storemesh.h index 4e081ce..9de5eb7 100644 --- a/src/include/h5core/h5t_storemesh.h +++ b/src/include/h5core/h5t_storemesh.h @@ -6,81 +6,46 @@ extern "C" { #endif h5t_lvl_idx_t -h5t_add_level ( - h5_file_t * const f - ); +h5t_add_level (h5t_mesh_t* const); h5_err_t -h5t_begin_store_vertices ( - h5_file_t * const f, - const h5_size_t num - ); +h5t_begin_store_vertices (h5t_mesh_t* const, const h5_size_t); h5_loc_id_t -h5t_store_vertex ( - h5_file_t * const f, - const h5_glb_id_t glb_id, - const h5_float64_t P[3] - ); +h5t_store_vertex (h5t_mesh_t* const, const h5_glb_id_t, const h5_float64_t[3]); h5_err_t -h5t_end_store_vertices ( - h5_file_t * const f - ); +h5t_end_store_vertices (h5t_mesh_t* const); h5_err_t -h5t_begin_store_elems ( - h5_file_t * const f, - const h5_size_t num - ); +h5t_begin_store_elems (h5t_mesh_t* const, const h5_size_t); h5_loc_idx_t -h5t_store_elem ( - h5_file_t * const f, - const h5_loc_idx_t parent_idx, - const h5_loc_idx_t* vertex_indices - ); +h5t_store_elem (h5t_mesh_t* const, const h5_loc_idx_t, const h5_loc_idx_t*); h5_err_t -h5t_end_store_elems ( - h5_file_t * const f - ); +h5t_end_store_elems (h5t_mesh_t* const); h5_err_t -h5t_begin_refine_elems ( - h5_file_t * const f - ); +h5t_begin_refine_elems (h5t_mesh_t* const); h5_err_t -h5t_refine_marked_elems ( - h5_file_t * const f - ); +h5t_refine_marked_elems (h5t_mesh_t* const); h5_err_t -h5t_end_refine_elems ( - h5_file_t * const f - ); +h5t_end_refine_elems (h5t_mesh_t* const); h5_err_t -h5t_mark_entity ( - h5_file_t* const f, - const h5_loc_id_t entity_id - ); +h5t_mark_entity (h5t_mesh_t* const, const h5_loc_id_t); h5_err_t -h5t_pre_refine ( - h5_file_t* const f - ); +h5t_pre_refine (h5t_mesh_t* const); h5_err_t -h5t_refine ( - h5_file_t* const f - ); +h5t_refine (h5t_mesh_t* const); h5_err_t -h5t_post_refine ( - h5_file_t* const f - ); +h5t_post_refine (h5t_mesh_t* const); #ifdef __cplusplus } diff --git a/src/include/h5core/h5t_tags.h b/src/include/h5core/h5t_tags.h index e2fd12c..6bcb40e 100644 --- a/src/include/h5core/h5t_tags.h +++ b/src/include/h5core/h5t_tags.h @@ -8,98 +8,36 @@ extern "C" { typedef struct h5t_tagset h5t_tagset_t; typedef struct h5t_tagcontainer h5t_tagcontainer_t; -h5_err_t -h5t_mtagset_exists ( - h5_file_t* const f, - h5t_tagcontainer_t* ctn, - char* name - ); -h5_err_t -h5t_add_mtagset ( - h5_file_t* const f, - char name[], - h5_id_t type - ); -h5_err_t -h5t_remove_mtagset ( - h5_file_t* const f, - const char name[] - ); -h5_err_t -h5t_open_mtagset ( - h5_file_t* const f, - const char *name, - h5t_tagset_t** retval - ); h5_ssize_t -h5t_get_num_mtagsets ( - h5_file_t* const f - ); -h5_ssize_t -h5t_get_mtagsets ( - h5_file_t* const f, - char** names[] - ); -h5_err_t -h5t_get_mtagset_info ( - h5_file_t* const f, - const h5_id_t idx, - char** names, - h5_id_t* type - ); -h5_id_t -h5t_get_mtagset_type_by_name ( - h5_file_t* const f, - char name[] - ); +h5t_get_num_mtagsets (h5t_mesh_t* const); h5_err_t -h5t_set_mtag_by_name ( - h5_file_t* const f, - char name[], - const h5_loc_id_t entity_id, - const size_t dim, - void* value - ); +h5t_get_mtagset_info (h5t_mesh_t* const, const h5_size_t, char[], + const h5_size_t, h5_int64_t* const); h5_err_t -h5t_get_mtag_by_name ( - h5_file_t* const f, - const char name[], - const h5_loc_id_t entity_id, - size_t* dim, - void* vals ); +h5t_mtagset_exists (h5t_mesh_t* const, const char* const); h5_err_t -h5t_remove_mtag_by_name ( - h5_file_t* const f, - const char name[], - const h5_loc_id_t entity_id - ); - -h5_ssize_t -h5t_get_tag ( - h5_file_t *const f, - const h5t_tagset_t *tagset, - const h5_loc_id_t entity_id, - size_t* const dim, - void* const vals - ); +h5t_create_mtagset (h5t_mesh_t* const, const char[], const h5_id_t, h5t_tagset_t**); h5_err_t -h5t_remove_mtag ( - h5_file_t* const f, - h5t_tagset_t* tagset, - const h5_loc_id_t entity_id - ); +h5t_open_mtagset (h5t_mesh_t* const, const char* const, h5t_tagset_t**); -h5_ssize_t -h5t_get_mtagset_names_of_entity ( - h5_file_t* const f, - const h5_loc_id_t entity_id, - char *names[], - const h5_size_t dim - ); +h5_err_t +h5t_close_mtagset (h5t_tagset_t*); + +h5_err_t +h5t_remove_mtagset (h5t_mesh_t* const, const char[]); + +h5_err_t +h5t_set_tag (h5t_tagset_t* const, const h5_loc_id_t, const h5_size_t, void*); + +h5_loc_id_t +h5t_get_tag (const h5t_tagset_t*, const h5_loc_id_t, h5_size_t* const, void* const); + +h5_err_t +h5t_remove_tag (h5t_tagset_t*, const h5_loc_id_t); #ifdef __cplusplus } diff --git a/test/H5Fed/Makefile.am b/test/H5Fed/Makefile.am index bddded1..6f40374 100644 --- a/test/H5Fed/Makefile.am +++ b/test/H5Fed/Makefile.am @@ -8,6 +8,7 @@ INCLUDES = -I../../src/include @INCLUDES@ noinst_PROGRAMS = \ tetmesh_write \ + tetmesh_write1 \ tetmesh_write2 \ tetmesh_read \ tetmesh_adjacencies \ @@ -27,6 +28,7 @@ EXTRA_DIST = \ tetmesh_read.c \ tetmesh_read_tags.c \ tetmesh_write.c \ + tetmesh_write1.c \ tetmesh_write2.c \ tetmesh_write_tags.c \ trimesh_adjacencies.c \ diff --git a/test/H5Fed/tetmesh_adjacencies.c b/test/H5Fed/tetmesh_adjacencies.c index 2beafc6..8515110 100644 --- a/test/H5Fed/tetmesh_adjacencies.c +++ b/test/H5Fed/tetmesh_adjacencies.c @@ -10,302 +10,379 @@ const h5_oid_t MESH_TYPE = H5_TETRAHEDRAL_MESH; const char* FNAME = "simple_tet.h5"; +typedef struct timer { + clock_t _start; + clock_t _end; + clock_t _elapsed; + struct timer* (*new)(void); + void (*delete)(struct timer*); + void (*start)(struct timer*); + void (*stop)(struct timer*); + void (*reset)(struct timer*); + double (*elapsed)(struct timer*); +} Timer; + +extern Timer Timer_; +static Timer* +new ( + void + ) { + Timer* this = malloc (sizeof (Timer)); + *this = Timer_; + return this; +} + +static void +delete (Timer* this) { + free (this); +} + +static void +start (Timer* this) { + this->_start = clock(); +} + +static void +stop (Timer* this) { + this->_end = clock(); + this->_elapsed += this->_end - this->_start; + this->_start = this->_end; +} + +static void +reset (Timer* this) { + this->_start = this->_end = this->_elapsed = 0; +} + +static double +elapsed (Timer* this) { + return (double)(this->_elapsed)/CLOCKS_PER_SEC; +} + +Timer Timer_ = { + 0, + 0, + 0, + new, + delete, + start, + stop, + reset, + elapsed +}; + static h5_err_t print_adjacencies_of_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t local_id, - clock_t* time_used + int dumpit, + Timer* timer ) { h5_loc_idlist_t* uadj_edges; h5_loc_idlist_t* uadj_triangles; h5_loc_idlist_t* uadj_tets; - clock_t time_used_before = clock(); - H5FedGetAdjacencies (f, local_id, 1, &uadj_edges); - H5FedGetAdjacencies (f, local_id, 2, &uadj_triangles); - H5FedGetAdjacencies (f, local_id, 3, &uadj_tets); - *time_used = clock() - time_used_before; + timer->reset(timer); + timer->start(timer); + H5FedGetAdjacencies (m, local_id, 1, &uadj_edges); + H5FedGetAdjacencies (m, local_id, 2, &uadj_triangles); + H5FedGetAdjacencies (m, local_id, 3, &uadj_tets); + timer->stop(timer); int n = uadj_tets->num_items; if (uadj_triangles->num_items > n) n = uadj_triangles->num_items; if (uadj_edges->num_items > n) n = uadj_edges->num_items; - int i; - for (i = 0; i < n; i++) { - char v[256]; - char k[256]; - char d[256]; - char t[256]; - h5_loc_id_t local_vids[4]; - if (i == 0) { - H5FedGetVertexIndicesOfEntity ( - f, local_id, local_vids); - snprintf (v, sizeof(v), "=[%lld]=", - (long long)local_vids[0]); - } else { - *v = '\0'; + if (dumpit) { + for (int i = 0; i < n; i++) { + char v[256]; + char k[256]; + char d[256]; + char t[256]; + h5_loc_id_t local_vids[4]; + if (i == 0) { + H5FedGetVertexIndicesOfEntity ( + m, local_id, local_vids); + snprintf (v, sizeof(v), "=[%lld]=", + (long long)local_vids[0]); + } else { + *v = '\0'; + } + if (i < uadj_edges->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, uadj_edges->items[i], local_vids); + snprintf (k, sizeof(k), "=[%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1]); + } else { + *k = '\0'; + } + if (i < uadj_triangles->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, uadj_triangles->items[i], local_vids); + snprintf (d, sizeof(d), "=[%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2]); + } else { + *d = '\0'; + } + if (i < uadj_tets->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, uadj_tets->items[i], local_vids); + snprintf (t, sizeof(t), "=[%lld,%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2], + (long long)local_vids[3]); + } else { + *t = '\0'; + } + printf ("| %-18s | %-18s | %-18s | %-18s |\n", v, k, d, t); } - if (i < uadj_edges->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, uadj_edges->items[i], local_vids); - snprintf (k, sizeof(k), "=[%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1]); - } else { - *k = '\0'; - } - if (i < uadj_triangles->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, uadj_triangles->items[i], local_vids); - snprintf (d, sizeof(d), "=[%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2]); - } else { - *d = '\0'; - } - if (i < uadj_tets->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, uadj_tets->items[i], local_vids); - snprintf (t, sizeof(t), "=[%lld,%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2], - (long long)local_vids[3]); - } else { - *t = '\0'; - } - printf ("| %-18s | %-18s | %-18s | %-18s |\n", v, k, d, t); } - H5FedReleaseListOfAdjacencies (f, &uadj_edges); - H5FedReleaseListOfAdjacencies (f, &uadj_triangles); - H5FedReleaseListOfAdjacencies (f, &uadj_tets); + H5FedReleaseListOfAdjacencies (m, &uadj_edges); + H5FedReleaseListOfAdjacencies (m, &uadj_triangles); + H5FedReleaseListOfAdjacencies (m, &uadj_tets); return H5_SUCCESS; } static h5_err_t print_adjacencies_of_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t local_id, - clock_t* time_used + int dumpit, + Timer* timer ) { h5_loc_idlist_t* dadj_vertices; h5_loc_idlist_t* uadj_triangles; h5_loc_idlist_t* uadj_tets; - clock_t time_used_before = clock(); - H5FedGetAdjacencies (f, local_id, 0, &dadj_vertices); - H5FedGetAdjacencies (f, local_id, 2, &uadj_triangles); - H5FedGetAdjacencies (f, local_id, 3, &uadj_tets); - *time_used = clock() - time_used_before; + timer->reset(timer); + timer->start(timer); + H5FedGetAdjacencies (m, local_id, 0, &dadj_vertices); + H5FedGetAdjacencies (m, local_id, 2, &uadj_triangles); + H5FedGetAdjacencies (m, local_id, 3, &uadj_tets); + timer->stop(timer); int n = dadj_vertices->num_items; if (uadj_triangles->num_items > n) n = uadj_triangles->num_items; if (uadj_tets->num_items > n) n = uadj_tets->num_items; - int i; - for (i = 0; i < n; i++) { - char v[256]; - char k[256]; - char d[256]; - char t[256]; - h5_loc_id_t local_vids[4]; - if (i < dadj_vertices->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, dadj_vertices->items[i], local_vids); - snprintf (v, sizeof(v), "=[%lld]=", - (long long)local_vids[0]); - } else { - *v = '\0'; + if (dumpit) { + for (int i = 0; i < n; i++) { + char v[256]; + char k[256]; + char d[256]; + char t[256]; + h5_loc_id_t local_vids[4]; + if (i < dadj_vertices->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, dadj_vertices->items[i], local_vids); + snprintf (v, sizeof(v), "=[%lld]=", + (long long)local_vids[0]); + } else { + *v = '\0'; + } + if (i == 0) { + H5FedGetVertexIndicesOfEntity ( + m, local_id, local_vids); + snprintf (k, sizeof(k), "=[%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1]); + } else { + *k = '\0'; + } + if (i < uadj_triangles->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, uadj_triangles->items[i], local_vids); + snprintf (d, sizeof(d), "=[%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2]); + } else { + *d = '\0'; + } + if (i < uadj_tets->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, uadj_tets->items[i], local_vids); + snprintf (t, sizeof(t), "=[%lld,%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2], + (long long)local_vids[3]); + } else { + *t = '\0'; + } + printf ("| %-18s | %-18s | %-18s | %-18s |\n", v, k, d, t); } - if (i == 0) { - H5FedGetVertexIndicesOfEntity ( - f, local_id, local_vids); - snprintf (k, sizeof(k), "=[%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1]); - } else { - *k = '\0'; - } - if (i < uadj_triangles->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, uadj_triangles->items[i], local_vids); - snprintf (d, sizeof(d), "=[%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2]); - } else { - *d = '\0'; - } - if (i < uadj_tets->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, uadj_tets->items[i], local_vids); - snprintf (t, sizeof(t), "=[%lld,%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2], - (long long)local_vids[3]); - } else { - *t = '\0'; - } - printf ("| %-18s | %-18s | %-18s | %-18s |\n", v, k, d, t); } - H5FedReleaseListOfAdjacencies (f, &dadj_vertices); - H5FedReleaseListOfAdjacencies (f, &uadj_triangles); - H5FedReleaseListOfAdjacencies (f, &uadj_tets); + H5FedReleaseListOfAdjacencies (m, &dadj_vertices); + H5FedReleaseListOfAdjacencies (m, &uadj_triangles); + H5FedReleaseListOfAdjacencies (m, &uadj_tets); return H5_SUCCESS; } static h5_err_t print_adjacencies_of_triangle ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t local_id, - clock_t* time_used + int dumpit, + Timer* timer ) { h5_loc_idlist_t* dadj_vertices; h5_loc_idlist_t* dadj_edges; h5_loc_idlist_t* uadj_tets; - clock_t time_used_before = clock(); - H5FedGetAdjacencies (f, local_id, 0, &dadj_vertices); - H5FedGetAdjacencies (f, local_id, 1, &dadj_edges); - H5FedGetAdjacencies (f, local_id, 3, &uadj_tets); - *time_used = clock() - time_used_before; + timer->reset(timer); + timer->start(timer); + H5FedGetAdjacencies (m, local_id, 0, &dadj_vertices); + H5FedGetAdjacencies (m, local_id, 1, &dadj_edges); + H5FedGetAdjacencies (m, local_id, 3, &uadj_tets); + timer->stop(timer); int n = dadj_vertices->num_items; if (dadj_edges->num_items > n) n = dadj_edges->num_items; if (uadj_tets->num_items > n) n = uadj_tets->num_items; - int i; - for (i = 0; i < n; i++) { - char v[256]; - char k[256]; - char d[256]; - char t[256]; - h5_loc_id_t local_vids[4]; - if (i < dadj_vertices->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, dadj_vertices->items[i], local_vids); - snprintf (v, sizeof(v), "=[%lld]=", - (long long)local_vids[0]); - } else { - *v = '\0'; + if (dumpit) { + for (int i = 0; i < n; i++) { + char v[256]; + char k[256]; + char d[256]; + char t[256]; + h5_loc_id_t local_vids[4]; + if (i < dadj_vertices->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, dadj_vertices->items[i], local_vids); + snprintf (v, sizeof(v), "=[%lld]=", + (long long)local_vids[0]); + } else { + *v = '\0'; + } + if (i < dadj_edges->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, dadj_edges->items[i], local_vids); + snprintf (k, sizeof(k), "=[%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1]); + } else { + *k = '\0'; + } + if (i == 0) { + H5FedGetVertexIndicesOfEntity ( + m, local_id, local_vids); + snprintf (d, sizeof(k), "=[%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2]); + } else { + *d = '\0'; + } + if (i < uadj_tets->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, uadj_tets->items[i], local_vids); + snprintf (t, sizeof(t), "=[%lld,%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2], + (long long)local_vids[3]); + } else { + *t = '\0'; + } + printf ( "| %-18s | %-18s | %-18s | %-18s |\n", v, k, d, t ); } - if (i < dadj_edges->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, dadj_edges->items[i], local_vids); - snprintf (k, sizeof(k), "=[%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1]); - } else { - *k = '\0'; - } - if (i == 0) { - H5FedGetVertexIndicesOfEntity ( - f, local_id, local_vids); - snprintf (d, sizeof(k), "=[%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2]); - } else { - *d = '\0'; - } - if (i < uadj_tets->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, uadj_tets->items[i], local_vids); - snprintf (t, sizeof(t), "=[%lld,%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2], - (long long)local_vids[3]); - } else { - *t = '\0'; - } - printf ( "| %-18s | %-18s | %-18s | %-18s |\n", v, k, d, t ); } - H5FedReleaseListOfAdjacencies (f, &dadj_vertices); - H5FedReleaseListOfAdjacencies (f, &dadj_edges); - H5FedReleaseListOfAdjacencies (f, &uadj_tets); + H5FedReleaseListOfAdjacencies (m, &dadj_vertices); + H5FedReleaseListOfAdjacencies (m, &dadj_edges); + H5FedReleaseListOfAdjacencies (m, &uadj_tets); return H5_SUCCESS; } static h5_err_t print_adjacencies_of_tet ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t local_id, - clock_t* time_used + int dumpit, + Timer* timer ) { h5_loc_idlist_t* dadj_vertices; h5_loc_idlist_t* dadj_edges; h5_loc_idlist_t* dadj_triangles; - clock_t time_used_before = clock(); - H5FedGetAdjacencies (f, local_id, 0, &dadj_vertices); - H5FedGetAdjacencies (f, local_id, 1, &dadj_edges); - H5FedGetAdjacencies (f, local_id, 2, &dadj_triangles); - *time_used = clock() - time_used_before; + timer->reset(timer); + timer->start(timer); + H5FedGetAdjacencies (m, local_id, 0, &dadj_vertices); + H5FedGetAdjacencies (m, local_id, 1, &dadj_edges); + H5FedGetAdjacencies (m, local_id, 2, &dadj_triangles); + timer->stop(timer); int n = dadj_vertices->num_items; if (dadj_edges->num_items > n) n = dadj_edges->num_items; if (dadj_triangles->num_items > n) n = dadj_triangles->num_items; - int i; - for (i = 0; i < n; i++) { - char v[256]; - char k[256]; - char d[256]; - char t[256]; - h5_loc_id_t local_vids[4]; - if (i < dadj_vertices->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, dadj_vertices->items[i], local_vids); - snprintf (v, sizeof(v), "=[%lld]=", - (long long)local_vids[0]); - } else { - *v = '\0'; + if (dumpit) { + for (int i = 0; i < n; i++) { + char v[256]; + char k[256]; + char d[256]; + char t[256]; + h5_loc_id_t local_vids[4]; + if (i < dadj_vertices->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, dadj_vertices->items[i], local_vids); + snprintf (v, sizeof(v), "=[%lld]=", + (long long)local_vids[0]); + } else { + *v = '\0'; + } + if (i < dadj_edges->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, dadj_edges->items[i], local_vids); + snprintf (k, sizeof(k), "=[%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1]); + } else { + *k = '\0'; + } + if (i < dadj_triangles->num_items) { + H5FedGetVertexIndicesOfEntity ( + m, dadj_triangles->items[i], local_vids); + snprintf (d, sizeof(d), "=[%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2]); + } else { + *d = '\0'; + } + if (i == 0) { + H5FedGetVertexIndicesOfEntity ( + m, local_id, local_vids); + snprintf (d, sizeof(k), "=[%lld,%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2], + (long long)local_vids[2]); + } else { + *t = '\0'; + } + printf ("| %-18s | %-18s | %-18s | %-18s |\n", v, k, d, t); } - if (i < dadj_edges->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, dadj_edges->items[i], local_vids); - snprintf (k, sizeof(k), "=[%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1]); - } else { - *k = '\0'; - } - if (i < dadj_triangles->num_items) { - H5FedGetVertexIndicesOfEntity ( - f, dadj_triangles->items[i], local_vids); - snprintf (d, sizeof(d), "=[%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2]); - } else { - *d = '\0'; - } - if (i == 0) { - H5FedGetVertexIndicesOfEntity ( - f, local_id, local_vids); - snprintf (d, sizeof(k), "=[%lld,%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2], - (long long)local_vids[2]); - } else { - *t = '\0'; - } - printf ("| %-18s | %-18s | %-18s | %-18s |\n", v, k, d, t); } - H5FedReleaseListOfAdjacencies (f, &dadj_vertices); - H5FedReleaseListOfAdjacencies (f, &dadj_edges); - H5FedReleaseListOfAdjacencies (f, &dadj_triangles); + H5FedReleaseListOfAdjacencies (m, &dadj_vertices); + H5FedReleaseListOfAdjacencies (m, &dadj_edges); + H5FedReleaseListOfAdjacencies (m, &dadj_triangles); return H5_SUCCESS; } static h5_err_t traverse_vertices ( - h5_file_t* const f + h5t_mesh_t* const m, + int dumpit, + Timer* timer ) { h5_loc_id_t local_id; h5_loc_idx_t num = 0; - clock_t t_total = 0; - clock_t t_min = CLOCKS_PER_SEC; - clock_t t_max = 0; - clock_t t = 0; + double t_total = 0.0; + double t_min = CLOCKS_PER_SEC; + double t_max = 0.0; + double t = 0.0; + printf ("\nAdjacencies to vertices\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 3); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - print_adjacencies_of_vertex (f, local_id, &t); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 3); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + print_adjacencies_of_vertex (m, local_id, dumpit, timer); num++; + t = timer->elapsed(timer); t_total += t; if (t < t_min) t_min = t; if (t > t_max) t_max = t; @@ -314,28 +391,31 @@ traverse_vertices ( stderr, "%lld\ttotal: %f\tmin: %f\tavg: %f\tmax: %f\n", (long long)num, - (double)t_total / (double)CLOCKS_PER_SEC, - (double)t_min / (double)CLOCKS_PER_SEC, - (double)t_total / (double)CLOCKS_PER_SEC / (double)num, - (double)t_max / (double)CLOCKS_PER_SEC ); - return H5FedEndTraverseEntities (f, iter); + t_total, + t_min, + t_total / (double)num, + t_max); + return H5FedEndTraverseEntities (iter); } static h5_err_t traverse_edges ( - h5_file_t* const f + h5t_mesh_t* const m, + int dumpit, + Timer* timer ) { h5_loc_id_t local_id; h5_loc_idx_t num = 0; - clock_t t_total = 0; - clock_t t_min = CLOCKS_PER_SEC; - clock_t t_max = 0; - clock_t t = 0; + double t_total = 0.0; + double t_min = CLOCKS_PER_SEC; + double t_max = 0.0; + double t = 0.0; printf ("\nAdjacencies to edges\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 2); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - print_adjacencies_of_edge (f, local_id, &t); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 2); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + print_adjacencies_of_edge (m, local_id, dumpit, timer); num++; + t = timer->elapsed(timer); t_total += t; if (t < t_min) t_min = t; if (t > t_max) t_max = t; @@ -344,28 +424,31 @@ traverse_edges ( stderr, "%lld\ttotal: %f\tmin: %f\tavg: %f\tmax: %f\n", (long long)num, - (double)t_total / (double)CLOCKS_PER_SEC, - (double)t_min / (double)CLOCKS_PER_SEC, - (double)t_total / (double)CLOCKS_PER_SEC / (double)num, - (double)t_max / (double)CLOCKS_PER_SEC ); - return H5FedEndTraverseEntities (f, iter); + t_total, + t_min, + t_total / (double)num, + t_max); + return H5FedEndTraverseEntities (iter); } static h5_err_t traverse_triangles ( - h5_file_t* const f + h5t_mesh_t* const m, + int dumpit, + Timer* timer ) { h5_loc_id_t local_id; h5_loc_idx_t num = 0; - clock_t t_min = CLOCKS_PER_SEC; - clock_t t_max = 0; - clock_t t_total = 0; - clock_t t = 0; + double t_min = CLOCKS_PER_SEC; + double t_max = 0.0; + double t_total = 0.0; + double t = 0.0; printf ("\nAdjacencies to triangle\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 1); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - print_adjacencies_of_triangle (f, local_id, &t); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 1); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + print_adjacencies_of_triangle (m, local_id, dumpit, timer); num++; + t = timer->elapsed(timer); t_total += t; if (t < t_min) t_min = t; if (t > t_max) t_max = t; @@ -374,28 +457,31 @@ traverse_triangles ( stderr, "%lld\ttotal: %f\tmin: %f\tavg: %f\tmax: %f\n", (long long)num, - (double)t_total / (double)CLOCKS_PER_SEC, - (double)t_min / (double)CLOCKS_PER_SEC, - (double)t_total / (double)CLOCKS_PER_SEC / (double)num, - (double)t_max / (double)CLOCKS_PER_SEC ); - return H5FedEndTraverseEntities (f, iter); + t_total, + t_min, + t_total / (double)num, + t_max); + return H5FedEndTraverseEntities (iter); } static h5_err_t traverse_elems ( - h5_file_t* const f + h5t_mesh_t* const m, + int dumpit, + Timer* timer ) { h5_loc_id_t local_id; h5_loc_idx_t num = 0; - clock_t t_total = 0; - clock_t t_min = CLOCKS_PER_SEC; - clock_t t_max = 0; - clock_t t = 0; + double t_total = 0.0; + double t_min = CLOCKS_PER_SEC; + double t_max = 0.0; + double t = 0.0; printf ("\nAdjacencies to tetrahedra\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 0); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - print_adjacencies_of_tet (f, local_id, &t); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 0); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + print_adjacencies_of_tet (m, local_id, dumpit, timer); num++; + t = timer->elapsed(timer); t_total += t; if (t < t_min) t_min = t; if (t > t_max) t_max = t; @@ -404,46 +490,52 @@ traverse_elems ( stderr, "%lld\ttotal: %f\tmin: %f\tavg: %f\tmax: %f\n", (long long)num, - (double)t_total / (double)CLOCKS_PER_SEC, - (double)t_min / (double)CLOCKS_PER_SEC, - (double)t_total / (double)CLOCKS_PER_SEC / (double)num, - (double)t_max / (double)CLOCKS_PER_SEC); - return H5FedEndTraverseEntities (f, iter); + t_total, + t_min, + t_total / (double)num, + t_max); + return H5FedEndTraverseEntities (iter); } static h5_err_t traverse_level ( - h5_file_t* const f, - const h5t_lvl_idx_t level_id + h5t_mesh_t* const m, + const h5t_lvl_idx_t level_id, + int dumpit, + Timer* timer ) { printf (" Setting level to %d\n", level_id); - H5FedSetLevel (f, level_id); - traverse_vertices (f); - traverse_edges (f); - traverse_triangles (f); - traverse_elems (f); + H5FedSetLevel (m, level_id); + traverse_vertices (m, dumpit, timer); + traverse_edges (m, dumpit, timer); + traverse_triangles (m, dumpit, timer); + traverse_elems (m, dumpit, timer); return H5_SUCCESS; } static h5_err_t traverse_mesh ( h5_file_t* const f, - const h5_id_t mesh_id, - const h5_oid_t mesh_type + const h5_id_t mesh_id ) { + h5t_mesh_t* mesh; + int dumpit = 0; + Timer* timer = Timer_.new(); + /* open mesh and get number of levels */ printf (" Opening mesh with id %lld\n", mesh_id); - H5FedOpenTetrahedralMesh (f, mesh_id); - h5_size_t num_levels = H5FedGetNumLevels (f); + H5FedOpenTetrahedralMeshByIndex (f, mesh_id, &mesh); + h5_size_t num_levels = H5FedGetNumLevels (mesh); printf (" Number of levels in mesh: %lld\n", (long long)num_levels); /* loop over all levels */ h5t_lvl_idx_t level_id; for (level_id = 0; level_id < num_levels; level_id++) { - traverse_level (f, level_id); + traverse_level (mesh, level_id, dumpit, timer); } /* done */ - H5FedCloseMesh (f); + H5FedCloseMesh (mesh); + timer->delete(timer); return H5_SUCCESS; } @@ -465,7 +557,7 @@ main ( /* loop over all meshes */ h5_id_t mesh_id; for (mesh_id = 0; mesh_id < num_meshes; mesh_id++) { - traverse_mesh (f, mesh_id, MESH_TYPE); + traverse_mesh (f, mesh_id); } /* done */ diff --git a/test/H5Fed/tetmesh_read.c b/test/H5Fed/tetmesh_read.c index c99fa63..02648dd 100644 --- a/test/H5Fed/tetmesh_read.c +++ b/test/H5Fed/tetmesh_read.c @@ -2,37 +2,97 @@ #include #include +#include + #include "H5hut.h" const char* FNAME = "simple_tet.h5"; + +typedef struct timer { + clock_t _start; + clock_t _end; + struct timer* (*new)(void); + void (*delete)(struct timer*); + void (*start)(struct timer*); + void (*stop)(struct timer*); + double (*elapsed)(struct timer*); +} Timer; + +extern Timer Timer_; +static Timer* +new ( + void + ) { + Timer* this = malloc (sizeof (Timer)); + *this = Timer_; + return this; +} + +static void +delete (Timer* this) { + free (this); +} + +static void +start (Timer* this) { + this->_start = clock(); +} + +static void +stop (Timer* this) { + this->_end = clock(); +} + +static double +elapsed (Timer* this) { + return (double)(this->_end - this->_start)/CLOCKS_PER_SEC; +} + +Timer Timer_ = { + 0, + 0, + new, + delete, + start, + stop, + elapsed +}; + static h5_err_t traverse_vertices ( - h5_file_t* const f + h5t_mesh_t* const m, + int dumpit, + Timer* timer ) { - printf ( "Traversing vertices on level %lld:\n", (long long)H5FedGetLevel(f) ); + printf ( " %-32s", "Traversing vertices: "); /* get number of vertices we have to expect */ - h5_size_t num_vertices_expect = H5FedGetNumVerticesTotal (f); + h5_size_t num_vertices_expect = H5FedGetNumVerticesTotal (m); /* get iterator for co-dim 3 entities, i.e vertices */ - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 3); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 3); /* iterate */ h5_loc_id_t local_id; h5_size_t num_vertices = 0; - while ((local_id = H5FedTraverseEntities ( f, iter )) >= 0) { - h5_float64_t P[3]; - H5FedGetVertexCoordsByID (f, local_id, P); - char v[256]; - snprintf (v, sizeof(v), "=%llx=", (long long)local_id); - printf ("| %-18s | (%f, %f, %f) |\n", - v, P[0], P[1], P[2]); + timer->start(timer); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + if (dumpit) { + printf ("\n"); + h5_float64_t P[3]; + H5FedGetVertexCoordsByID (m, local_id, P); + char v[256]; + snprintf (v, sizeof(v), "=%llx=", (long long)local_id); + printf ("| %-18s | (%f, %f, %f) |\n", + v, P[0], P[1], P[2]); + } num_vertices++; } /* done */ - H5FedEndTraverseEntities (f, iter); + H5FedEndTraverseEntities (iter); + timer->stop(timer); /* report error if we got a different number then expected */ if (num_vertices != num_vertices_expect) { @@ -41,139 +101,168 @@ traverse_vertices ( (unsigned long)num_vertices_expect); } - printf (" Number of vertices on level: %lud\n", + printf (" %fsec, number of vertices: %lu\n", + timer->elapsed(timer), (unsigned long)num_vertices); return H5_SUCCESS; } static h5_err_t traverse_edges ( - h5_file_t* const f + h5t_mesh_t* const m, + int dumpit, + Timer* timer ) { - printf ( "Travering edges on level %lld:\n", (long long)H5FedGetLevel(f) ); - + printf ( " %-32s", "Traversing edges: "); + timer->start(timer); /* get iterator for co-dim 2 entities, i.e. edges */ - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 2); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 2); /* iterate */ h5_loc_id_t local_id; h5_size_t num_edges = 0; - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - char v[256]; - char k[256]; - h5_loc_id_t local_vids[4]; - snprintf ( k, sizeof(k), "=%llx=", (long long)local_id ); - H5FedGetVertexIndicesOfEntity ( f, local_id, local_vids ); - snprintf ( v, sizeof(v), "=[%lld,%lld]=", - (long long)local_vids[0], (long long)local_vids[1] ); - printf ( "| %-18s | %-18s |\n", k, v ); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + if (dumpit) { + printf ("\n"); + char v[256]; + char k[256]; + h5_loc_id_t local_vids[4]; + snprintf ( k, sizeof(k), "=%llx=", (long long)local_id ); + H5FedGetVertexIndicesOfEntity ( m, local_id, local_vids ); + snprintf ( v, sizeof(v), "=[%lld,%lld]=", + (long long)local_vids[0], (long long)local_vids[1] ); + printf ( "| %-18s | %-18s |\n", k, v ); + } num_edges++; } /* done */ - H5FedEndTraverseEntities ( f, iter ); - - printf (" Number of edges: %lu\n", (unsigned long)num_edges); + H5FedEndTraverseEntities (iter); + timer->stop(timer); + printf (" %fsec, number of edges: %lu\n", + timer->elapsed(timer), + (unsigned long)num_edges); return H5_SUCCESS; } static h5_err_t traverse_triangles ( - h5_file_t* const f + h5t_mesh_t* const m, + int dumpit, + Timer* timer ) { - printf ( "Travering triangles on level %lld:\n", (long long)H5FedGetLevel(f) ); + printf ( " %-32s", "Traversing triangles: "); + timer->start (timer); /* get iterator for co-dim 1 entities, i.e. triangles */ - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 1); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 1); /* iterate */ h5_loc_id_t local_id; h5_size_t num_triangles = 0; - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - char v[256]; - char d[256]; - h5_loc_id_t local_vids[4]; - snprintf ( d, sizeof(d), "=%llx=", (long long)local_id ); - H5FedGetVertexIndicesOfEntity ( f, local_id, local_vids ); - snprintf ( v, sizeof(v), "=[%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2] ); - printf ( "| %-18s | %-18s |\n", d, v ); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + if (dumpit) { + printf ("\n"); + char v[256]; + char d[256]; + h5_loc_id_t local_vids[4]; + snprintf ( d, sizeof(d), "=%llx=", (long long)local_id ); + H5FedGetVertexIndicesOfEntity ( m, local_id, local_vids ); + snprintf ( v, sizeof(v), "=[%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2] ); + printf ( "| %-18s | %-18s |\n", d, v ); + } num_triangles++; } /* done */ - H5FedEndTraverseEntities ( f, iter ); - - printf (" Number of triangles: %lu\n", + H5FedEndTraverseEntities (iter); + timer->stop(timer); + printf (" %fsec, number of triangles: %lu\n", + timer->elapsed(timer), (unsigned long)num_triangles); return H5_SUCCESS; } static h5_err_t traverse_boundary_triangles ( - h5_file_t* const f + h5t_mesh_t* const m, + int dumpit, + Timer* timer ) { - printf ( "Travering boundary triangles on level %lld:\n", (long long)H5FedGetLevel(f) ); + printf ( " %-32s", "Traversing boundary triangles: "); + timer->start(timer); /* get iterator for co-dim 1 entities, i.e. triangles */ - h5t_iterator_t* iter = H5FedBeginTraverseBoundaryFaces (f, 1); + h5t_iterator_t* iter = H5FedBeginTraverseBoundaryFaces (m, 1); /* iterate */ h5_loc_id_t local_id; h5_size_t num_triangles = 0; - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - char v[256]; - char d[256]; - h5_loc_id_t local_vids[4]; - snprintf ( d, sizeof(d), "=%llx=", (long long)local_id ); - H5FedGetVertexIndicesOfEntity ( f, local_id, local_vids ); - snprintf ( v, sizeof(v), "=[%lld,%lld,%lld]=", - (long long)local_vids[0], - (long long)local_vids[1], - (long long)local_vids[2] ); - printf ( "| %-18s | %-18s |\n", d, v ); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + if (dumpit) { + printf ("\n"); + char v[256]; + char d[256]; + h5_loc_id_t local_vids[4]; + snprintf ( d, sizeof(d), "=%llx=", (long long)local_id ); + H5FedGetVertexIndicesOfEntity ( m, local_id, local_vids ); + snprintf ( v, sizeof(v), "=[%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2] ); + printf ( "| %-18s | %-18s |\n", d, v ); + } num_triangles++; } /* done */ - H5FedEndTraverseEntities ( f, iter ); - - printf (" Number of boundary triangles: %lu\n", + H5FedEndTraverseEntities (iter); + timer->stop(timer); + printf (" %fsec, number of boundary triangles: %lu\n", + timer->elapsed(timer), (unsigned long)num_triangles); return H5_SUCCESS; } static h5_err_t traverse_elems ( - h5_file_t* const f + h5t_mesh_t* const m, + int dumpit, + Timer* timer ) { + printf ( " %-32s", "Traversing elements: "); + timer->start(timer); /* get number of elements we have to expect */ - h5_size_t num_elems_expect = H5FedGetNumElementsTotal (f); + h5_size_t num_elems_expect = H5FedGetNumElementsTotal (m); /* get iterator for co-dim 0 */ - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 0); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 0); /* iterate over all co-dim 0 entities, i.e. elements */ h5_loc_id_t local_id; h5_size_t num_elems = 0; - while ((local_id = H5FedTraverseEntities ( f, iter )) >= 0) { - char v[256]; - char t[256]; - h5_loc_id_t local_vids[4]; - snprintf ( t, sizeof(t), "=%llx=", (long long)local_id ); - H5FedGetVertexIndicesOfEntity ( f, local_id, local_vids ); - snprintf ( v, sizeof(v), "=[%lld,%lld,%lld,%lld]=", - (long long)local_vids[0], (long long)local_vids[1], - (long long)local_vids[2], (long long)local_vids[3] ); - printf ( "| %-18s | %-18s |\n", t, v ); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + if (dumpit) { + printf ("\n"); + char v[256]; + char t[256]; + h5_loc_id_t local_vids[4]; + snprintf ( t, sizeof(t), "=%llx=", (long long)local_id ); + H5FedGetVertexIndicesOfEntity (m, local_id, local_vids); + snprintf ( v, sizeof(v), "=[%lld,%lld,%lld,%lld]=", + (long long)local_vids[0], (long long)local_vids[1], + (long long)local_vids[2], (long long)local_vids[3] ); + printf ( "| %-18s | %-18s |\n", t, v ); + } num_elems++; } /* done */ - H5FedEndTraverseEntities (f, iter); - + H5FedEndTraverseEntities (iter); + timer->stop(timer); /* report error if we got a different number then expected */ if (num_elems != num_elems_expect) { fprintf (stderr, "!!! Got %lld elements, but expected %lld.\n", @@ -181,44 +270,56 @@ traverse_elems ( exit(1); } - printf (" Number of elements on level: %lld\n", (long long)num_elems); + printf (" %fsec, number of elements: %lld\n", + timer->elapsed(timer), + (long long)num_elems); return H5_SUCCESS; } static h5_err_t traverse_level ( - h5_file_t* const f, - const h5t_lvl_idx_t level_id + h5t_mesh_t* const m, + const h5t_lvl_idx_t level_id, + int dumpit, + Timer* timer ) { - printf (" Setting level to %d\n", level_id); - H5FedSetLevel (f, level_id); - traverse_vertices (f); - traverse_edges (f); - traverse_triangles (f); - traverse_boundary_triangles (f); - traverse_elems (f); + printf ("Setting level to %d\n", level_id); + H5FedSetLevel (m, level_id); + traverse_vertices (m, dumpit, timer); + traverse_edges (m, dumpit, timer); + traverse_triangles (m, dumpit, timer); + traverse_boundary_triangles (m, dumpit, timer); + traverse_elems (m, dumpit, timer); return H5_SUCCESS; } static h5_err_t traverse_mesh ( h5_file_t* const f, - const h5_id_t mesh_id + const h5_id_t mesh_id, + int dumpit ) { + h5t_mesh_t* mesh; + Timer* timer = Timer_.new(); + + timer->start(timer); /* open mesh and get number of levels */ printf (" Opening mesh with id %lld\n", mesh_id); - H5FedOpenTetrahedralMesh (f, mesh_id); - h5_size_t num_levels = H5FedGetNumLevels (f); + H5FedOpenTetrahedralMeshByIndex (f, mesh_id, &mesh); + timer->stop(timer); + printf (" %fsec\n", timer->elapsed(timer)); + h5_size_t num_levels = H5FedGetNumLevels (mesh); printf (" Number of levels in mesh: %lld\n", (long long)num_levels); /* loop over all levels */ h5t_lvl_idx_t level_id; for (level_id = 0; level_id < num_levels; level_id++) { - traverse_level (f, level_id); + traverse_level (mesh, level_id, dumpit, timer); } /* done */ - H5FedCloseMesh (f); + H5FedCloseMesh (mesh); + timer->delete(timer); return H5_SUCCESS; } @@ -238,8 +339,9 @@ main ( /* loop over all meshes */ h5_id_t mesh_id; + int dumpit = 0; for (mesh_id = 0; mesh_id < num_meshes; mesh_id++) { - traverse_mesh (f, mesh_id); + traverse_mesh (f, mesh_id, dumpit); } /* done */ diff --git a/test/H5Fed/tetmesh_read_tags.c b/test/H5Fed/tetmesh_read_tags.c index f69e236..07fd588 100644 --- a/test/H5Fed/tetmesh_read_tags.c +++ b/test/H5Fed/tetmesh_read_tags.c @@ -4,12 +4,64 @@ #include "H5hut.h" +const char* FNAME = "simple_tet.h5"; + #ifndef PARALLEL_IO #ifndef MPI_COMM_WORLD #define MPI_COMM_WORLD 0 #endif #endif +typedef struct timer { + clock_t _start; + clock_t _end; + struct timer* (*new)(void); + void (*delete)(struct timer*); + void (*start)(struct timer*); + void (*stop)(struct timer*); + double (*elapsed)(struct timer*); +} Timer; + +extern Timer Timer_; +static Timer* +new ( + void + ) { + Timer* self = malloc (sizeof (Timer)); + *self = Timer_; + return self; +} + +static void +delete (Timer* self) { + free (self); +} + +static void +start (Timer* self) { + self->_start = clock(); +} + +static void +stop (Timer* self) { + self->_end = clock(); +} + +static double +elapsed (Timer* self) { + return (double)(self->_end - self->_start)/CLOCKS_PER_SEC; +} + +Timer Timer_ = { + 0, + 0, + new, + delete, + start, + stop, + elapsed +}; + struct vertex { h5_float64_t P[3]; }; @@ -25,181 +77,324 @@ typedef struct tet tet_t; static h5_err_t traverse_vertices ( - h5_file_t * f + h5t_mesh_t* const m, + h5t_tagset_t* tagset, + int dumpit, + Timer* timer ) { + printf ( " %-32s", "Traversing vertices: "); + + /* get iterator for co-dim 3 entities, i.e vertices */ + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 3); + + /* iterate */ h5_loc_id_t local_id; - h5_size_t real_num = 0; - - h5_size_t num = H5FedGetNumVerticesTotal ( f ); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 3 ); - while ( (real_num < num) && - ((local_id = H5FedTraverseEntities (f, iter)) >= 0) ) { - size_t size = 3; - h5_int64_t retval[3]; - H5FedGetMTag ( f, "testtag", local_id, &size, retval ); - if ( (retval[0] != local_id) || - (retval[1] != local_id+1) || - (retval[2] != local_id+2) ) { - fprintf ( stderr, "!!! Wrong tag values for vertex %lld\n", - (long long)local_id ); - exit ( 1 ); + h5_size_t num_entities = 0; + h5_size_t num_entities_tagged = 0; + timer->start(timer); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + num_entities++; + if (dumpit) { + printf ("\n"); + h5_float64_t P[3]; + H5FedGetVertexCoordsByID (m, local_id, P); + char v[256]; + snprintf (v, sizeof(v), "=%llx=", (long long)local_id); + printf ("| %-18s | (%f, %f, %f) |", + v, P[0], P[1], P[2]); } - real_num++; - } - H5FedEndTraverseEntities (f, iter); - if ( real_num != num ) { - fprintf ( stderr, "!!! Got %lld vertices, but expected %lld.\n", - (long long)real_num, (long long)num ); - exit ( 1 ); + h5_size_t size = 3; + h5_int64_t tval[3]; + if ((local_id = H5FedGetTag (tagset, local_id, &size, tval)) < 0) { + continue; // not tagged + } + if (dumpit) { + printf (" (%llx, %llx, %llx) |", + tval[0], tval[1], tval[2]); + } + num_entities_tagged++; + if (tval[0] != local_id || + tval[1] != local_id+1 || + tval[2] != local_id+2) { + fprintf (stderr, + "!!! Wrong tag values for entity %lld\n", + (long long)local_id); + exit (1); + } } + /* done */ + H5FedEndTraverseEntities (iter); + timer->stop(timer); + + if (dumpit) { + printf ("\n\nTime elapsed:"); + } + printf (" %fsec, total number of entities: %lu; tagged: %lu\n", + timer->elapsed(timer), + (unsigned long)num_entities, (unsigned long)num_entities_tagged); return H5_SUCCESS; } static h5_err_t traverse_edges ( - h5_file_t * f + h5t_mesh_t* const m, + h5t_tagset_t* tagset, + int dumpit, + Timer* timer ) { - h5_loc_id_t local_id; + printf ( " %-32s", "Traversing edges: "); + timer->start(timer); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 1); - while ( (local_id = H5FedTraverseEntities (f, iter)) >= 0 ) { - h5_loc_id_t local_vids[4]; - H5FedGetVertexIndicesOfEntity( f, local_id, local_vids ); - size_t size; - h5_int64_t retval[3]; - H5FedGetMTag ( f, "testtag", local_id, &size, retval ); - if ( (retval[0] != local_id) || - (retval[1] != local_id+1) || - (retval[1] != local_id+1) ) { - fprintf ( stderr, "!!! Wrong tag values for edge %lld\n", - (long long)local_id ); - exit ( 1 ); + /* get iterator for co-dim 2 entities, i.e. edges */ + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 2); + + /* iterate */ + h5_loc_id_t local_id; + h5_size_t num_entities = 0; + h5_size_t num_entities_tagged = 0; + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + num_entities++; + if (dumpit) { + printf ("\n"); + char v[256]; + char k[256]; + h5_loc_id_t local_vids[4]; + snprintf ( k, sizeof(k), "=%llx=", (long long)local_id ); + H5FedGetVertexIndicesOfEntity ( m, local_id, local_vids ); + snprintf ( v, sizeof(v), "=[%lld,%lld]=", + (long long)local_vids[0], (long long)local_vids[1] ); + printf ( "| %-18s | %-18s |", k, v ); + } + h5_size_t size = 3; + h5_int64_t tval[3]; + if ((local_id = H5FedGetTag (tagset, local_id, &size, tval)) < 0) + continue; // not tagged + if (dumpit) { + printf (" (%llx, %llx, %llx) |", + tval[0], tval[1], tval[2]); + } + num_entities_tagged++; + + if (tval[0] != local_id || + tval[1] != local_id+1 || + tval[2] != local_id+2) { + fprintf (stderr, + "!!! Wrong tag values for entity %lld\n", + (long long)local_id); + exit (1); } } - H5FedEndTraverseEntities (f, iter); + + /* done */ + H5FedEndTraverseEntities (iter); + timer->stop(timer); + + if (dumpit) { + printf ("\n\nTime elapsed:"); + } + printf (" %fsec, total number of entities: %lu; tagged: %lu\n", + timer->elapsed(timer), + (unsigned long)num_entities, (unsigned long)num_entities_tagged); return H5_SUCCESS; } static h5_err_t traverse_triangles ( - h5_file_t * f + h5t_mesh_t* const m, + h5t_tagset_t* tagset, + int dumpit, + Timer* timer ) { - h5_loc_id_t local_id; + printf ( " %-32s", "Traversing triangles: "); + timer->start(timer); + /* get iterator for co-dim 1 entities, i.e. triangles */ + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 1); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 2); - while ( (local_id = H5FedTraverseEntities (f, iter)) >= 0 ) { - size_t size; - h5_int64_t retval[3]; - H5FedGetMTag ( f, "testtag", local_id, &size, retval ); - if ( (retval[0] != local_id) || - (retval[1] != local_id+1) || - (retval[1] != local_id+1) ) { - fprintf ( stderr, "!!! Wrong tag values for edge %lld\n", - (long long)local_id ); - exit ( 1 ); + /* iterate */ + h5_loc_id_t local_id; + h5_size_t num_entities = 0; + h5_size_t num_entities_tagged = 0; + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + num_entities++; + if (dumpit) { + printf ("\n"); + char v[256]; + char k[256]; + h5_loc_id_t local_vids[4]; + snprintf ( k, sizeof(k), "=%llx=", (long long)local_id ); + H5FedGetVertexIndicesOfEntity ( m, local_id, local_vids ); + snprintf ( v, sizeof(v), "=[%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2] ); + printf ( "| %-18s | %-18s |", k, v ); + } + h5_size_t size = 3; + h5_int64_t tval[3]; + if ((local_id = H5FedGetTag (tagset, local_id, &size, tval)) < 0) + continue; // not tagged + if (dumpit) { + printf (" (%llx, %llx, %llx) |", + tval[0], tval[1], tval[2]); + } + num_entities_tagged++; + + if (tval[0] != local_id || tval[1] != local_id+1 || tval[2] != local_id+2) { + fprintf (stderr, + "!!! Wrong tag values for entity %lld\n", + (long long)local_id); + exit (1); } } - H5FedEndTraverseEntities (f, iter); + + /* done */ + H5FedEndTraverseEntities (iter); + timer->stop(timer); + + if (dumpit) { + printf ("\n\nTime elapsed:"); + } + printf (" %fsec, total number of entities: %lu; tagged: %lu\n", + timer->elapsed(timer), + (unsigned long)num_entities, (unsigned long)num_entities_tagged); return H5_SUCCESS; } static h5_err_t traverse_tets ( - h5_file_t * f + h5t_mesh_t* const m, + h5t_tagset_t* tagset, + int dumpit, + Timer* timer ) { + printf ( " %-32s", "Traversing tetrahedra: "); + timer->start(timer); + /* get iterator for co-dim 0 entities, i.e. tetrahedra */ + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 0); + /* iterate */ h5_loc_id_t local_id; - h5_size_t real_num = 0; - - h5_size_t num = H5FedGetNumElementsTotal ( f ); - - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 0); - while ( (real_num < num) && - ((local_id = H5FedTraverseEntities (f, iter)) >= 0) ) { - size_t size; - h5_int64_t retval[3]; - H5FedGetMTag ( f, "testtag", local_id, &size, retval ); - if ( (retval[0] != local_id) || - (retval[1] != local_id+1) || - (retval[1] != local_id+1) ) { - fprintf ( stderr, "!!! Wrong tag values for edge %lld\n", - (long long)local_id ); - exit ( 1 ); + h5_size_t num_entities = 0; + h5_size_t num_entities_tagged = 0; + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + num_entities++; + if (dumpit) { + printf ("\n"); + char v[256]; + char k[256]; + h5_loc_id_t local_vids[4]; + snprintf ( k, sizeof(k), "=%llx=", (long long)local_id ); + H5FedGetVertexIndicesOfEntity ( m, local_id, local_vids ); + snprintf ( v, sizeof(v), "=[%lld,%lld,%lld,%lld]=", + (long long)local_vids[0], + (long long)local_vids[1], + (long long)local_vids[2], + (long long)local_vids[3] ); + printf ( "| %-18s | %-18s |", k, v ); + } + h5_size_t size = 3; + h5_int64_t tval[3]; + if ((local_id = H5FedGetTag (tagset, local_id, &size, tval)) < 0) + continue; // not tagged + if (dumpit) { + printf (" (%llx, %llx, %llx) |", + tval[0], tval[1], tval[2]); + } + num_entities_tagged++; + + if (tval[0] != local_id || tval[1] != local_id+1 || tval[2] != local_id+2) { + fprintf (stderr, + "!!! Wrong tag values for entity %lld\n", + (long long)local_id); + exit (1); } - real_num++; - } - H5FedEndTraverseEntities (f, iter); - if ( real_num != num ) { - fprintf ( stderr, "!!! Got %lld tets, but expected %lld.\n", - (long long)real_num, (long long)num ); - exit(1); } + /* done */ + H5FedEndTraverseEntities (iter); + timer->stop(timer); + + if (dumpit) { + printf ("\n\nTime elapsed:"); + } + printf (" %fsec, total number of entities: %lu; tagged: %lu\n", + timer->elapsed(timer), + (unsigned long)num_entities, (unsigned long)num_entities_tagged); return H5_SUCCESS; } static h5_err_t -read_level ( - h5_file_t * f +traverse_level ( + h5t_mesh_t* const m, + h5t_tagset_t* tagset, + const h5t_lvl_idx_t level_id, + int dumpit, + Timer* timer ) { - traverse_vertices ( f ); - traverse_edges ( f ); - traverse_triangles ( f ); - traverse_tets ( f ); + printf ("Setting level to %d\n", level_id); + H5FedSetLevel (m, level_id); + traverse_vertices (m, tagset, dumpit, timer); + traverse_edges (m, tagset, dumpit, timer); + traverse_triangles (m, tagset, dumpit, timer); + traverse_tets (m, tagset, dumpit, timer); return H5_SUCCESS; } static h5_err_t traverse_mesh ( - h5_file_t * f + h5_file_t* const f, + const h5_id_t mesh_id, + int dumpit ) { + h5t_mesh_t* mesh; + Timer* timer = Timer_.new(); + timer->start(timer); + /* open mesh and get number of levels */ + printf (" Opening mesh with id %lld\n", mesh_id); + H5FedOpenTetrahedralMeshByIndex (f, mesh_id, &mesh); + timer->stop(timer); + printf (" %fsec\n", timer->elapsed(timer)); - h5_loc_id_t level_id; - h5_size_t num_levels = H5FedGetNumLevels ( f ); - printf ( " Number of levels in mesh: %lld\n", (long long)num_levels ); - for ( level_id = 2; level_id < num_levels; level_id++ ) { - h5_err_t h5err = H5FedSetLevel ( f, level_id ); - if ( h5err < 0 ) { - fprintf ( stderr, "!!! Can't set level %d.\n", - level_id ); - return -1; - } - h5err = read_level ( f ); - if ( h5err < 0 ) { - fprintf ( stderr, "!!! Oops ...\n" ); - return -1; - } + h5t_tagset_t* tagset; + H5FedOpenMTagset (mesh, "testtag", &tagset); + + h5_size_t num_levels = H5FedGetNumLevels (mesh); + printf (" Number of levels in mesh: %lld\n", (long long)num_levels); + + /* loop over all levels */ + h5t_lvl_idx_t level_id; + for (level_id = 0; level_id < num_levels; level_id++) { + traverse_level (mesh, tagset, level_id, dumpit, timer); } - + /* done */ + H5FedCloseMTagset (tagset); + H5FedCloseMesh (mesh); + timer->delete(timer); return H5_SUCCESS; } int main ( int argc, - char *argv[] + char* argv[] ) { - H5SetVerbosityLevel ( 2 ); - H5SetErrorHandler ( H5AbortErrorhandler ); + /* abort program on error, so we don't have to handle them */ + H5SetErrorHandler (H5AbortErrorhandler); + H5SetVerbosityLevel (2); - h5_file_t *f = H5OpenFile ( "simple_tet.h5", H5_O_RDONLY, 0 ); + /* open file and get number of meshes */ + h5_file_t* f = H5OpenFile (FNAME, H5_O_RDONLY, 0); h5_size_t num_meshes = H5FedGetNumTetrahedralMeshes (f); - printf ( " Number of meshes: %lld\n", (long long)num_meshes ); + printf (" Number of meshes: %lld\n", (long long)num_meshes); + /* loop over all meshes */ h5_id_t mesh_id; - for ( mesh_id = 0; mesh_id < num_meshes; mesh_id++ ) { - fprintf ( - stderr, - "Time used: %f\n", - (float)clock()/(float)CLOCKS_PER_SEC ); - H5FedOpenTetrahedralMesh (f, mesh_id); - fprintf ( - stderr, - "Time used: %f\n", - (float)clock()/(float)CLOCKS_PER_SEC ); - traverse_mesh ( f ); + int dumpit = 1; + for (mesh_id = 0; mesh_id < num_meshes; mesh_id++) { + traverse_mesh (f, mesh_id, dumpit); } - H5CloseFile ( f ); + /* done */ + H5CloseFile (f); return 0; } diff --git a/test/H5Fed/tetmesh_write.c b/test/H5Fed/tetmesh_write.c index 0e86087..a9ccef6 100644 --- a/test/H5Fed/tetmesh_write.c +++ b/test/H5Fed/tetmesh_write.c @@ -47,36 +47,37 @@ main ( /* open file and add mesh */ h5_file_t* const f = H5OpenFile (FNAME, H5_O_WRONLY, 0); - H5FedAddTetrahedralMesh (f); + h5t_mesh_t* mesh; + H5FedAddTetrahedralMesh (f, "0", &mesh); /* store vertices */ - H5FedBeginStoreVertices (f, num_vertices); + H5FedBeginStoreVertices (mesh, num_vertices); int i; for (i = 0; i < num_vertices; i++) { - H5FedStoreVertex (f, -1, Vertices[i].P); + H5FedStoreVertex (mesh, -1, Vertices[i].P); } - H5FedEndStoreVertices (f); + H5FedEndStoreVertices (mesh); /* store elements */ - H5FedBeginStoreElements (f, num_elems); + H5FedBeginStoreElements (mesh, num_elems); for (i = 0; i < num_elems; i++) { - H5FedStoreElement (f, Elems[i].vids); + H5FedStoreElement (mesh, Elems[i].vids); } - H5FedEndStoreElements (f); + H5FedEndStoreElements (mesh); /* add 1. Level */ - H5FedAddLevel(f); - H5FedBeginRefineElements (f); - H5FedRefineElement (f, 0); - H5FedEndRefineElements (f); + H5FedAddLevel(mesh); + H5FedBeginRefineElements (mesh); + H5FedRefineElement (mesh, 0); + H5FedEndRefineElements (mesh); /* add 2. Level */ - H5FedAddLevel(f); - H5FedBeginRefineElements (f); - H5FedRefineElement (f, 2); - H5FedEndRefineElements (f); + H5FedAddLevel(mesh); + H5FedBeginRefineElements (mesh); + H5FedRefineElement (mesh, 2); + H5FedEndRefineElements (mesh); - H5FedCloseMesh (f); + H5FedCloseMesh (mesh); H5CloseFile (f); return 0; } diff --git a/test/H5Fed/tetmesh_write1.c b/test/H5Fed/tetmesh_write1.c new file mode 100644 index 0000000..1154bc7 --- /dev/null +++ b/test/H5Fed/tetmesh_write1.c @@ -0,0 +1,75 @@ +#include +#include +#include + +#include "H5hut.h" + +#ifndef PARALLEL_IO +#ifndef MPI_COMM_WORLD +#define MPI_COMM_WORLD 0 +#endif +#endif + +const char* FNAME = "simple_tet1.h5"; + +typedef struct vertex { + h5_float64_t P[3]; +} vertex_t; + +typedef struct elem { + h5_loc_idx_t vids[4]; +} elem_t; + +vertex_t Vertices[] = { + {{-1.0, 0.0, 0.0}}, + {{ 0.0, 0.0, 1.0}}, + {{ 0.0, 1.0, 0.0}}, + {{ 1.0, 0.0, 0.0}}, +}; + +elem_t Elems[] = { + {{ 0, 1, 2, 3 }}, +}; + +const int num_vertices = sizeof (Vertices) / sizeof (Vertices[0]); +const int num_elems = sizeof (Elems) / sizeof (Elems[0]); + +int +main ( + int argc, + char* argv[] + ) { + /* abort program on errors in library */ + H5SetErrorHandler (H5AbortErrorhandler); + H5SetVerbosityLevel (H5_DEBUG_ALL); + + /* open file and add mesh */ + h5_file_t* const f = H5OpenFile (FNAME, H5_O_WRONLY, 0); + h5t_mesh_t* mesh; + H5FedAddTetrahedralMesh (f, "0", &mesh); + + /* store vertices */ + H5FedBeginStoreVertices (mesh, num_vertices); + int i; + for (i = 0; i < num_vertices; i++) { + H5FedStoreVertex (mesh, -1, Vertices[i].P); + } + H5FedEndStoreVertices (mesh); + + /* store elements */ + H5FedBeginStoreElements (mesh, num_elems); + for (i = 0; i < num_elems; i++) { + H5FedStoreElement (mesh, Elems[i].vids); + } + H5FedEndStoreElements (mesh); + + /* add 1. Level */ + H5FedAddLevel(mesh); + H5FedBeginRefineElements (mesh); + H5FedRefineElement (mesh, 0); + H5FedEndRefineElements (mesh); + + H5FedCloseMesh (mesh); + H5CloseFile (f); + return 0; +} diff --git a/test/H5Fed/tetmesh_write2.c b/test/H5Fed/tetmesh_write2.c index e692653..624d90e 100644 --- a/test/H5Fed/tetmesh_write2.c +++ b/test/H5Fed/tetmesh_write2.c @@ -58,31 +58,33 @@ main ( /* abort program on errors in library */ H5SetErrorHandler (H5AbortErrorhandler); H5SetVerbosityLevel (2); + // H5SetVerbosityLevel (H5_DEBUG_ALL); /* open file and add mesh */ h5_file_t* const f = H5OpenFile (FNAME, H5_O_WRONLY, 0); - H5FedAddTetrahedralMesh (f); + h5t_mesh_t* mesh; + H5FedAddTetrahedralMesh (f, "0", &mesh); /* store vertices */ - H5FedBeginStoreVertices (f, num_vertices); + H5FedBeginStoreVertices (mesh, num_vertices); int i; for (i = 0; i < num_vertices; i++) { - H5FedStoreVertex (f, -1, Vertices[i].P); + H5FedStoreVertex (mesh, -1, Vertices[i].P); } - H5FedEndStoreVertices (f); + H5FedEndStoreVertices (mesh); /* store elements */ - H5FedBeginStoreElements (f, num_elems); + H5FedBeginStoreElements (mesh, num_elems); for (i = 0; i < num_elems; i++) { - H5FedStoreElement (f, Elems[i].vids); + H5FedStoreElement (mesh, Elems[i].vids); } - H5FedEndStoreElements (f); + H5FedEndStoreElements (mesh); /* add 1. Level */ - H5FedAddLevel(f); - H5FedBeginRefineElements (f); - H5FedRefineElement (f, 0); - H5FedEndRefineElements (f); + H5FedAddLevel(mesh); + H5FedBeginRefineElements (mesh); + H5FedRefineElement (mesh, 0); + H5FedEndRefineElements (mesh); /* add levels 2 to num_levels-1 */ h5_int32_t num_elems_last_level = 1; @@ -90,18 +92,18 @@ main ( for (level_id = 2; level_id < num_levels; level_id++) { /* refine 4 to the power of level_id-1 elems */ - H5FedAddLevel(f); + H5FedAddLevel(mesh); h5_int32_t num_elems2refine = power (4, level_id-1); - H5FedBeginRefineElements (f); + H5FedBeginRefineElements (mesh); for (i = num_elems_last_level; i < num_elems_last_level+num_elems2refine; i++) { - H5FedRefineElement (f, i); + H5FedRefineElement (mesh, i); } - H5FedEndRefineElements (f); + H5FedEndRefineElements (mesh); num_elems_last_level += 2 * num_elems2refine; } - H5FedCloseMesh (f); + H5FedCloseMesh (mesh); H5CloseFile (f); return 0; } diff --git a/test/H5Fed/tetmesh_write_tags.c b/test/H5Fed/tetmesh_write_tags.c index 4620625..9069a48 100644 --- a/test/H5Fed/tetmesh_write_tags.c +++ b/test/H5Fed/tetmesh_write_tags.c @@ -8,98 +8,173 @@ const h5_oid_t MESH_TYPE = H5_TETRAHEDRAL_MESH; const char* FNAME = "simple_tet.h5"; +typedef struct timer { + clock_t _start; + clock_t _end; + struct timer* (*new)(void); + void (*delete)(struct timer*); + void (*start)(struct timer*); + void (*stop)(struct timer*); + double (*elapsed)(struct timer*); +} Timer; + +extern Timer Timer_; +static Timer* +new ( + void + ) { + Timer* this = malloc (sizeof (Timer)); + *this = Timer_; + return this; +} + +static void +delete (Timer* this) { + free (this); +} + +static void +start (Timer* this) { + this->_start = clock(); +} + +static void +stop (Timer* this) { + this->_end = clock(); +} + +static double +elapsed (Timer* this) { + return (double)(this->_end - this->_start)/CLOCKS_PER_SEC; +} + +Timer Timer_ = { + 0, + 0, + new, + delete, + start, + stop, + elapsed +}; + static h5_err_t set_vertex_tags ( - h5_file_t* const f + h5t_mesh_t* m, + h5t_tagset_t* const tagset, + int verify, + Timer* timer ) { h5_loc_id_t local_id; h5_int64_t val[3]; - - printf ("\nSet tags to vertices\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 3); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { + h5_info ("Tagging all vertices ..."); + timer->start(timer); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 3); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { val[0] = local_id; val[1] = local_id+1; val[2] = local_id+2; - H5FedSetMTag (f, "testtag", local_id, 3, val); - h5_int64_t retval[3]; - size_t dim = 3; - H5FedGetMTag (f, "testtag", local_id, &dim, retval); - if (memcmp (val, retval, sizeof(val))) { - fprintf ( stderr, "Oops!\n"); + H5FedSetTag (tagset, local_id, 3, val); + if (verify) { + h5_int64_t retval[3]; + h5_size_t dim = 3; + H5FedGetTag (tagset, local_id, &dim, retval); + if (memcmp (val, retval, sizeof(val))) { + h5_warn ("Oops on entity %llx!", (long long)local_id); + } } - printf ("Set tag for entity %llx\n", (long long)local_id); + h5_debug ("Tagging %llx", (long long)local_id); } - return H5FedEndTraverseEntities (f, iter); + timer->stop(timer); + h5_info (" Time to tag to all vertices: %fsec", timer->elapsed(timer)); + return H5FedEndTraverseEntities (iter); } static h5_err_t set_edge_tags ( - h5_file_t* const f + h5t_mesh_t* const m, + h5t_tagset_t* tagset, + int dumpit, + Timer* timer ) { h5_loc_id_t local_id; h5_int64_t val[3]; - printf ("\nSet tags to edges\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 2); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { + h5_info ("Tagging all edges ..."); + timer->start(timer); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 2); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { val[0] = local_id; val[1] = local_id+1; val[2] = local_id+2; - H5FedSetMTag (f, "testtag", local_id, 3, val); + H5FedSetTag (tagset, local_id, 3, val); h5_int64_t retval[3]; - size_t dims; - H5FedGetMTag (f, "testtag", local_id, &dims, retval); + h5_size_t dims; + H5FedGetTag (tagset, local_id, &dims, retval); if (memcmp ( val, retval, sizeof(val))) { - fprintf ( stderr, "Oops!\n"); + h5_warn ("Oops on entity %llx!", (long long)local_id); } } - return H5FedEndTraverseEntities (f, iter); + timer->stop(timer); + h5_info (" Time to tag all edges: %fsec", timer->elapsed(timer)); + return H5FedEndTraverseEntities (iter); } static h5_err_t set_tri_tags ( - h5_file_t* const f + h5t_mesh_t* const m, + h5t_tagset_t* tagset, + int dumpit, + Timer* timer ) { h5_loc_id_t local_id; h5_int64_t val[3]; - printf ("\nSet tags to triangle\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 1); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { + h5_info ("Tagging all triangles ..."); + timer->start(timer); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 1); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { val[0] = local_id; val[1] = local_id+1; val[2] = local_id+2; - H5FedSetMTag (f, "testtag", local_id, 3, val); + H5FedSetTag (tagset, local_id, 3, val); h5_int64_t retval[3]; - size_t dims; - H5FedGetMTag (f, "testtag", local_id, &dims, retval); + h5_size_t dims; + H5FedGetTag (tagset, local_id, &dims, retval); if (memcmp (val, retval, sizeof(val))) { - fprintf (stderr, "Oops!\n"); + h5_warn ("Oops on entity %llx!", (long long)local_id); } } - return H5FedEndTraverseEntities (f, iter); + timer->stop(timer); + h5_info (" Time to tag all triangles: %fsec", timer->elapsed(timer)); + return H5FedEndTraverseEntities (iter); } static h5_err_t set_tet_tags ( - h5_file_t* const f + h5t_mesh_t* const m, + h5t_tagset_t* tagset, + int dumpit, + Timer* timer ) { h5_loc_id_t local_id; h5_int64_t val[3]; - printf ("\nSet tags to tetrahedra\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 0); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { + h5_info ("Tagging all tetrahedra ..."); + timer->start(timer); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 0); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { val[0] = local_id; val[1] = local_id+1; val[2] = local_id+2; - H5FedSetMTag (f, "testtag", local_id, 3, val); + H5FedSetTag (tagset, local_id, 3, val); h5_int64_t retval[3]; - size_t dims; - H5FedGetMTag (f, "testtag", local_id, &dims, retval); + h5_size_t dims; + H5FedGetTag (tagset, local_id, &dims, retval); if (memcmp (val, retval, sizeof(val))) { - fprintf (stderr, "Oops!\n"); + h5_warn ("Oops on entity %llx!", (long long)local_id); } } - return H5FedEndTraverseEntities (f, iter); + timer->stop(timer); + h5_info (" Time to tag to all tetrahedra: %fsec", timer->elapsed(timer)); + return H5FedEndTraverseEntities (iter); } int @@ -107,28 +182,49 @@ main ( int argc, char* argv[] ) { - + int verify = 1; /* abort program on error, so we don't have to handle them */ H5SetErrorHandler (H5AbortErrorhandler); - H5SetVerbosityLevel (4); + H5SetVerbosityLevel (3); /* open file and get number of meshes */ h5_file_t* f = H5OpenFile (FNAME, H5_O_RDWR, 0); - H5FedOpenTetrahedralMesh (f, 0); + h5t_mesh_t* mesh; + Timer* timer = Timer_.new(); + timer->start(timer); + H5FedOpenTetrahedralMesh (f, "0", &mesh); + timer->stop(timer); + h5_info (" Time to open mesh %fsec", timer->elapsed(timer)); /* open last level */ - h5_size_t num_levels = H5FedGetNumLevels (f); - H5FedSetLevel (f, num_levels-1); + h5_size_t num_levels = H5FedGetNumLevels (mesh); + //H5FedSetLevel (mesh, num_levels-1); + H5FedSetLevel (mesh, 0); /* add new tagset and write some data to it */ - H5FedAddMTagset (f, "testtag", H5_INT64_T); - set_vertex_tags (f); - set_edge_tags (f); - set_tri_tags (f); - set_tet_tags (f); + h5t_tagset_t* tagset = NULL; + H5FedAddMTagset (mesh, "testtag", H5_INT64_T, &tagset); + set_vertex_tags (mesh, tagset, verify, timer); + set_edge_tags (mesh, tagset, verify, timer); + set_tri_tags (mesh, tagset, verify, timer); + set_tet_tags (mesh, tagset, verify, timer); - /* done */ - H5FedCloseMesh (f); + // close tagset + timer->start(timer); + H5FedCloseMTagset (tagset); + timer->stop(timer); + h5_info (" Time to write tagset to disk %fsec", timer->elapsed(timer)); + + // close mesh + timer->start(timer); + H5FedCloseMesh (mesh); + timer->stop(timer); + h5_info (" Time to close mesh %fsec", timer->elapsed(timer)); + + // close file + timer->start(timer); H5CloseFile (f); + timer->stop(timer); + h5_info (" Time to close file %fsec", timer->elapsed(timer)); return 0; } diff --git a/test/H5Fed/trimesh_adjacencies.c b/test/H5Fed/trimesh_adjacencies.c index b80ccad..9ec1d18 100644 --- a/test/H5Fed/trimesh_adjacencies.c +++ b/test/H5Fed/trimesh_adjacencies.c @@ -12,15 +12,15 @@ const char* FNAME = "simple_triangle.h5"; static h5_err_t print_adjacencies_of_vertex ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t local_id, clock_t* time_used ) { h5_loc_idlist_t* uadj_edges; h5_loc_idlist_t* uadj_triangles; clock_t time_used_before = clock(); - H5FedGetAdjacencies (f, local_id, 1, &uadj_edges); - H5FedGetAdjacencies (f, local_id, 2, &uadj_triangles); + H5FedGetAdjacencies (m, local_id, 1, &uadj_edges); + H5FedGetAdjacencies (m, local_id, 2, &uadj_triangles); *time_used = clock() - time_used_before; int n = 0; if (uadj_triangles->num_items > n) n = uadj_triangles->num_items; @@ -33,7 +33,7 @@ print_adjacencies_of_vertex ( h5_loc_id_t local_vids[4]; if (i == 0) { H5FedGetVertexIndicesOfEntity ( - f, local_id, local_vids); + m, local_id, local_vids); snprintf (v, sizeof(v), "=[%lld]=", (long long)local_vids[0]); } else { @@ -41,7 +41,7 @@ print_adjacencies_of_vertex ( } if (i < uadj_edges->num_items) { H5FedGetVertexIndicesOfEntity ( - f, uadj_edges->items[i], local_vids); + m, uadj_edges->items[i], local_vids); snprintf (k, sizeof(k), "=[%lld,%lld]=", (long long)local_vids[0], (long long)local_vids[1]); @@ -50,7 +50,7 @@ print_adjacencies_of_vertex ( } if (i < uadj_triangles->num_items) { H5FedGetVertexIndicesOfEntity ( - f, uadj_triangles->items[i], local_vids); + m, uadj_triangles->items[i], local_vids); snprintf (d, sizeof(d), "=[%lld,%lld,%lld]=", (long long)local_vids[0], (long long)local_vids[1], @@ -60,22 +60,22 @@ print_adjacencies_of_vertex ( } printf ("| %-18s | %-18s | %-18s |\n", v, k, d); } - H5FedReleaseListOfAdjacencies (f, &uadj_edges); - H5FedReleaseListOfAdjacencies (f, &uadj_triangles); + H5FedReleaseListOfAdjacencies (m, &uadj_edges); + H5FedReleaseListOfAdjacencies (m, &uadj_triangles); return H5_SUCCESS; } static h5_err_t print_adjacencies_of_edge ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t local_id, clock_t* time_used ) { h5_loc_idlist_t* dadj_vertices; h5_loc_idlist_t* uadj_triangles; clock_t time_used_before = clock(); - H5FedGetAdjacencies (f, local_id, 0, &dadj_vertices); - H5FedGetAdjacencies (f, local_id, 2, &uadj_triangles); + H5FedGetAdjacencies (m, local_id, 0, &dadj_vertices); + H5FedGetAdjacencies (m, local_id, 2, &uadj_triangles); *time_used = clock() - time_used_before; int n = dadj_vertices->num_items; if (uadj_triangles->num_items > n) n = uadj_triangles->num_items; @@ -88,7 +88,7 @@ print_adjacencies_of_edge ( h5_loc_id_t local_vids[4]; if (i < dadj_vertices->num_items) { H5FedGetVertexIndicesOfEntity ( - f, dadj_vertices->items[i], local_vids); + m, dadj_vertices->items[i], local_vids); snprintf (v, sizeof(v), "=[%lld]=", (long long)local_vids[0]); } else { @@ -96,7 +96,7 @@ print_adjacencies_of_edge ( } if (i == 0) { H5FedGetVertexIndicesOfEntity ( - f, local_id, local_vids); + m, local_id, local_vids); snprintf (k, sizeof(k), "=[%lld,%lld]=", (long long)local_vids[0], (long long)local_vids[1]); @@ -105,7 +105,7 @@ print_adjacencies_of_edge ( } if (i < uadj_triangles->num_items) { H5FedGetVertexIndicesOfEntity ( - f, uadj_triangles->items[i], local_vids); + m, uadj_triangles->items[i], local_vids); snprintf (d, sizeof(d), "=[%lld,%lld,%lld]=", (long long)local_vids[0], (long long)local_vids[1], @@ -115,22 +115,22 @@ print_adjacencies_of_edge ( } printf ("| %-18s | %-18s | %-18s |\n", v, k, d); } - H5FedReleaseListOfAdjacencies (f, &dadj_vertices); - H5FedReleaseListOfAdjacencies (f, &uadj_triangles); + H5FedReleaseListOfAdjacencies (m, &dadj_vertices); + H5FedReleaseListOfAdjacencies (m, &uadj_triangles); return H5_SUCCESS; } static h5_err_t print_adjacencies_of_elem ( - h5_file_t* const f, + h5t_mesh_t* const m, h5_loc_id_t local_id, clock_t* time_used ) { h5_loc_idlist_t* dadj_vertices; h5_loc_idlist_t* dadj_edges; clock_t time_used_before = clock(); - H5FedGetAdjacencies (f, local_id, 0, &dadj_vertices); - H5FedGetAdjacencies (f, local_id, 1, &dadj_edges); + H5FedGetAdjacencies (m, local_id, 0, &dadj_vertices); + H5FedGetAdjacencies (m, local_id, 1, &dadj_edges); *time_used = clock() - time_used_before; int n = dadj_vertices->num_items; if (dadj_edges->num_items > n) n = dadj_edges->num_items; @@ -142,7 +142,7 @@ print_adjacencies_of_elem ( h5_loc_id_t local_vids[4]; if (i < dadj_vertices->num_items) { H5FedGetVertexIndicesOfEntity ( - f, dadj_vertices->items[i], local_vids); + m, dadj_vertices->items[i], local_vids); snprintf (v, sizeof(v), "=[%lld]=", (long long)local_vids[0]); } else { @@ -150,7 +150,7 @@ print_adjacencies_of_elem ( } if (i < dadj_edges->num_items) { H5FedGetVertexIndicesOfEntity ( - f, dadj_edges->items[i], local_vids); + m, dadj_edges->items[i], local_vids); snprintf (k, sizeof(k), "=[%lld,%lld]=", (long long)local_vids[0], (long long)local_vids[1]); @@ -159,7 +159,7 @@ print_adjacencies_of_elem ( } if (i == 0) { H5FedGetVertexIndicesOfEntity ( - f, local_id, local_vids); + m, local_id, local_vids); snprintf (d, sizeof(k), "=[%lld,%lld,%lld]=", (long long)local_vids[0], (long long)local_vids[1], @@ -169,14 +169,14 @@ print_adjacencies_of_elem ( } printf ( "| %-18s | %-18s | %-18s |\n", v, k, d ); } - H5FedReleaseListOfAdjacencies (f, &dadj_vertices); - H5FedReleaseListOfAdjacencies (f, &dadj_edges); + H5FedReleaseListOfAdjacencies (m, &dadj_vertices); + H5FedReleaseListOfAdjacencies (m, &dadj_edges); return H5_SUCCESS; } static h5_err_t traverse_vertices ( - h5_file_t* const f + h5t_mesh_t* const m ) { h5_loc_id_t local_id; h5_loc_idx_t num = 0; @@ -185,9 +185,9 @@ traverse_vertices ( clock_t t_max = 0; clock_t t = 0; printf ("\nAdjacencies to vertices\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 2); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - print_adjacencies_of_vertex (f, local_id, &t); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 2); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + print_adjacencies_of_vertex (m, local_id, &t); num++; t_total += t; if (t < t_min) t_min = t; @@ -201,12 +201,12 @@ traverse_vertices ( (double)t_min / (double)CLOCKS_PER_SEC, (double)t_total / (double)CLOCKS_PER_SEC / (double)num, (double)t_max / (double)CLOCKS_PER_SEC ); - return H5FedEndTraverseEntities (f, iter); + return H5FedEndTraverseEntities (iter); } static h5_err_t traverse_edges ( - h5_file_t* const f + h5t_mesh_t* const m ) { h5_loc_id_t local_id; h5_loc_idx_t num = 0; @@ -215,9 +215,9 @@ traverse_edges ( clock_t t_max = 0; clock_t t = 0; printf ("\nAdjacencies to edges\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 1); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - print_adjacencies_of_edge (f, local_id, &t); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 1); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + print_adjacencies_of_edge (m, local_id, &t); num++; t_total += t; if (t < t_min) t_min = t; @@ -231,12 +231,12 @@ traverse_edges ( (double)t_min / (double)CLOCKS_PER_SEC, (double)t_total / (double)CLOCKS_PER_SEC / (double)num, (double)t_max / (double)CLOCKS_PER_SEC ); - return H5FedEndTraverseEntities (f, iter); + return H5FedEndTraverseEntities (iter); } static h5_err_t traverse_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { h5_loc_id_t local_id; h5_loc_idx_t num = 0; @@ -245,9 +245,9 @@ traverse_elems ( clock_t t_max = 0; clock_t t = 0; printf ("\nAdjacencies to tetrahedra\n"); - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 0); - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { - print_adjacencies_of_elem (f, local_id, &t); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 0); + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { + print_adjacencies_of_elem (m, local_id, &t); num++; t_total += t; if (t < t_min) t_min = t; @@ -261,41 +261,41 @@ traverse_elems ( (double)t_min / (double)CLOCKS_PER_SEC, (double)t_total / (double)CLOCKS_PER_SEC / (double)num, (double)t_max / (double)CLOCKS_PER_SEC); - return H5FedEndTraverseEntities (f, iter); + return H5FedEndTraverseEntities (iter); } static h5_err_t traverse_level ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5t_lvl_idx_t level_id ) { printf (" Setting level to %d\n", level_id); - H5FedSetLevel (f, level_id); - traverse_vertices (f); - traverse_edges (f); - traverse_elems (f); + H5FedSetLevel (m, level_id); + traverse_vertices (m); + traverse_edges (m); + traverse_elems (m); return H5_SUCCESS; } static h5_err_t traverse_mesh ( h5_file_t* const f, - const h5_id_t mesh_id, - const h5_oid_t mesh_type + const h5_id_t mesh_id ) { + h5t_mesh_t* m; /* open mesh and get number of levels */ printf (" Opening mesh with id %lld\n", mesh_id); - H5FedOpenTriangleMesh (f, mesh_id); - h5_size_t num_levels = H5FedGetNumLevels (f); + H5FedOpenTriangleMeshByIndex (f, mesh_id, &m); + h5_size_t num_levels = H5FedGetNumLevels (m); printf (" Number of levels in mesh: %lld\n", (long long)num_levels); /* loop over all levels */ h5t_lvl_idx_t level_id; for (level_id = 0; level_id < num_levels; level_id++) { - traverse_level (f, level_id); + traverse_level (m, level_id); } /* done */ - H5FedCloseMesh (f); + H5FedCloseMesh (m); return H5_SUCCESS; } @@ -317,7 +317,7 @@ main ( /* loop over all meshes */ h5_id_t mesh_id; for (mesh_id = 0; mesh_id < num_meshes; mesh_id++) { - traverse_mesh (f, mesh_id, MESH_TYPE); + traverse_mesh (f, mesh_id); } /* done */ diff --git a/test/H5Fed/trimesh_read.c b/test/H5Fed/trimesh_read.c index 943d1ca..46f16be 100644 --- a/test/H5Fed/trimesh_read.c +++ b/test/H5Fed/trimesh_read.c @@ -10,20 +10,20 @@ const char* FNAME = "simple_triangle.h5"; static h5_err_t traverse_vertices ( - h5_file_t* const f + h5t_mesh_t* const m ) { /* get number of vertices we have to expect */ - h5_size_t num_vertices_expect = H5FedGetNumVerticesTotal (f); + h5_size_t num_vertices_expect = H5FedGetNumVerticesTotal (m); /* get iterator for co-dim 2 entities, i.e. vertices */ - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 2); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 2); /* iterate */ h5_loc_id_t local_id; h5_size_t num_vertices = 0; - while ((local_id = H5FedTraverseEntities ( f, iter )) >= 0) { + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { h5_float64_t P[3]; - H5FedGetVertexCoordsByID (f, local_id, P); + H5FedGetVertexCoordsByID (m, local_id, P); char v[256]; snprintf (v, sizeof(v), "=%llx=", (long long)local_id); printf ("| %-18s | (%f, %f, %f) |\n", @@ -32,7 +32,7 @@ traverse_vertices ( } /* done */ - H5FedEndTraverseEntities (f, iter); + H5FedEndTraverseEntities (iter); /* report error if we got a different number then expected */ if (num_vertices != num_vertices_expect) { @@ -47,22 +47,22 @@ traverse_vertices ( static h5_err_t traverse_edges ( - h5_file_t* const f + h5t_mesh_t* const m ) { - printf ( "Travering edges on level %lld:\n", (long long)H5FedGetLevel(f) ); + printf ( "Travering edges on level %lld:\n", (long long)H5FedGetLevel(m) ); /* get iterator for co-dim 1 entities, i.e. edges */ - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 1); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 1); /* iterate */ h5_loc_id_t local_id; h5_size_t num_edges = 0; - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { char v[256]; char k[256]; h5_loc_id_t local_vids[4]; snprintf ( k, sizeof(k), "=%llx=", (long long)local_id ); - H5FedGetVertexIndicesOfEntity ( f, local_id, local_vids ); + H5FedGetVertexIndicesOfEntity ( m, local_id, local_vids ); snprintf ( v, sizeof(v), "=[%lld,%lld]=", (long long)local_vids[0], (long long)local_vids[1] ); printf ( "| %-18s | %-18s |\n", k, v ); @@ -70,7 +70,7 @@ traverse_edges ( } /* done */ - H5FedEndTraverseEntities ( f, iter ); + H5FedEndTraverseEntities (iter); printf (" Number of edges: %lld\n", (long long)num_edges); return H5_SUCCESS; @@ -78,22 +78,22 @@ traverse_edges ( static h5_err_t traverse_boundary_edges ( - h5_file_t* const f + h5t_mesh_t* const m ) { - printf ( "Travering boundary edges on level %lld:\n", (long long)H5FedGetLevel(f) ); + printf ("Travering boundary edges on level %lld:\n", (long long)H5FedGetLevel(m)); /* get iterator for co-dim 1 entities, i.e. edges */ - h5t_iterator_t* iter = H5FedBeginTraverseBoundaryFaces (f, 1); + h5t_iterator_t* iter = H5FedBeginTraverseBoundaryFaces (m, 1); /* iterate */ h5_loc_id_t local_id; h5_size_t num_edges = 0; - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { char v[256]; char k[256]; h5_loc_id_t local_vids[4]; - snprintf ( k, sizeof(k), "=%llx=", (long long)local_id ); - H5FedGetVertexIndicesOfEntity ( f, local_id, local_vids ); + snprintf ( k, sizeof(k), "=%llx=", (long long)local_id); + H5FedGetVertexIndicesOfEntity (m, local_id, local_vids); snprintf ( v, sizeof(v), "=[%lld,%lld]=", (long long)local_vids[0], (long long)local_vids[1] ); printf ( "| %-18s | %-18s |\n", k, v ); @@ -101,7 +101,7 @@ traverse_boundary_edges ( } /* done */ - H5FedEndTraverseEntities ( f, iter ); + H5FedEndTraverseEntities (iter); printf (" Number of edges: %lld\n", (long long)num_edges); return H5_SUCCESS; @@ -109,23 +109,23 @@ traverse_boundary_edges ( static h5_err_t traverse_elems ( - h5_file_t* const f + h5t_mesh_t* const m ) { /* get number of elements we have to expect */ - h5_size_t num_elems_expect = H5FedGetNumElementsTotal (f); + h5_size_t num_elems_expect = H5FedGetNumElementsTotal (m); /* get iterator for co-dim 0 */ - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 0); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 0); /* iterate over all co-dim 0 entities, i.e. elements */ h5_loc_id_t local_id; h5_size_t num_elems = 0; - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { char v[256]; char t[256]; h5_loc_id_t local_vids[4]; snprintf (t, sizeof(t), "=%llx=", (long long)local_id); - H5FedGetVertexIndicesOfEntity (f, local_id, local_vids); + H5FedGetVertexIndicesOfEntity (m, local_id, local_vids); snprintf (v, sizeof(v), "=[%lld,%lld,%lld]=", (long long)local_vids[0], (long long)local_vids[1], @@ -135,7 +135,7 @@ traverse_elems ( } /* done */ - H5FedEndTraverseEntities (f, iter); + H5FedEndTraverseEntities (iter); /* report error if we got a different number then expected */ if (num_elems != num_elems_expect) { @@ -155,25 +155,25 @@ traverse_elems ( */ static h5_err_t traverse_elems2 ( - h5_file_t* const f + h5t_mesh_t* const m ) { /* get number of elements we have to expect */ - h5_size_t num_elems_expect = H5FedGetNumElementsTotal (f); + h5_size_t num_elems_expect = H5FedGetNumElementsTotal (m); /* get iterator for co-dim 0 */ - h5t_iterator_t* iter = H5FedBeginTraverseEntities (f, 0); + h5t_iterator_t* iter = H5FedBeginTraverseEntities (m, 0); /* iterate over all co-dim 0 entities, i.e. elements */ h5_loc_id_t local_id; h5_size_t num_elems = 0; - while ((local_id = H5FedTraverseEntities (f, iter)) >= 0) { + while ((local_id = H5FedTraverseEntities (iter)) >= 0) { printf ("%05llu", (unsigned long long)num_elems); h5_loc_id_t local_vids[4]; - H5FedGetVertexIndicesOfEntity (f, local_id, local_vids); + H5FedGetVertexIndicesOfEntity (m, local_id, local_vids); int i; for (i = 0; i < 3; i++) { h5_float64_t P[3]; - H5FedGetVertexCoordsByIndex (f, local_vids[i], P); + H5FedGetVertexCoordsByIndex (m, local_vids[i], P); printf (" %8.6f %8.6f %8.6f", P[0], P[1], P[2]); } printf ("\n"); @@ -181,31 +181,29 @@ traverse_elems2 ( } /* done */ - H5FedEndTraverseEntities (f, iter); + H5FedEndTraverseEntities (iter); /* report error if we got a different number then expected */ if (num_elems != num_elems_expect) { fprintf (stderr, "!!! Got %lld elements, but expected %lld.\n", (long long)num_elems, (long long)num_elems_expect); exit(1); - - } return H5_SUCCESS; } static h5_err_t traverse_level ( - h5_file_t* const f, + h5t_mesh_t* const m, const h5_loc_id_t level_id ) { printf (" Setting level to %d\n", level_id); - H5FedSetLevel (f, level_id); - traverse_vertices (f); - traverse_edges (f); - traverse_boundary_edges (f); - traverse_elems (f); - traverse_elems2 (f); + H5FedSetLevel (m, level_id); + traverse_vertices (m); + traverse_edges (m); + traverse_boundary_edges (m); + traverse_elems (m); + traverse_elems2 (m); return H5_SUCCESS; } @@ -214,19 +212,20 @@ traverse_mesh ( h5_file_t* const f, const h5_id_t mesh_id ) { + h5t_mesh_t* m; /* open mesh and get number of levels */ printf (" Opening mesh with id %lld\n", mesh_id); - H5FedOpenTriangleMesh (f, mesh_id); - h5_size_t num_levels = H5FedGetNumLevels (f); + H5FedOpenTriangleMeshByIndex (f, mesh_id, &m); + h5_size_t num_levels = H5FedGetNumLevels (m); printf (" Number of levels in mesh: %lld\n", (long long)num_levels); /* loop over all levels */ h5t_lvl_idx_t level_id; for (level_id = 0; level_id < num_levels; level_id++) { - traverse_level (f, level_id); + traverse_level (m, level_id); } /* done */ - H5FedCloseMesh (f); + H5FedCloseMesh (m); return H5_SUCCESS; } diff --git a/test/H5Fed/trimesh_write.c b/test/H5Fed/trimesh_write.c index 00514f4..13f7ca0 100644 --- a/test/H5Fed/trimesh_write.c +++ b/test/H5Fed/trimesh_write.c @@ -39,30 +39,31 @@ main ( /* open file and add mesh */ h5_file_t* const f = H5OpenFile (FNAME, H5_O_WRONLY, 0); - H5FedAddTriangleMesh (f); + h5t_mesh_t* m; + H5FedAddTriangleMesh (f, "0", &m); /* store vertices */ - H5FedBeginStoreVertices (f, num_vertices); + H5FedBeginStoreVertices (m, num_vertices); int i; for (i = 0; i < num_vertices; i++) { - H5FedStoreVertex (f, -1, Vertices[i].P); + H5FedStoreVertex (m, -1, Vertices[i].P); } - H5FedEndStoreVertices (f); + H5FedEndStoreVertices (m); /* store elements */ - H5FedBeginStoreElements (f, num_elems); + H5FedBeginStoreElements (m, num_elems); for (i = 0; i < num_elems; i++) { - H5FedStoreElement (f, Elems[i].vids); + H5FedStoreElement (m, Elems[i].vids); } - H5FedEndStoreElements (f); + H5FedEndStoreElements (m); /* add 1. Level */ - H5FedAddLevel(f); - H5FedBeginRefineElements (f); - H5FedRefineElement (f, 0); - H5FedEndRefineElements (f); + H5FedAddLevel(m); + H5FedBeginRefineElements (m); + H5FedRefineElement (m, 0); + H5FedEndRefineElements (m); - H5FedCloseMesh (f); + H5FedCloseMesh (m); H5CloseFile (f); return 0; } diff --git a/test/H5Fed/trimesh_write_dunetest.c b/test/H5Fed/trimesh_write_dunetest.c index c148532..b1da92d 100644 --- a/test/H5Fed/trimesh_write_dunetest.c +++ b/test/H5Fed/trimesh_write_dunetest.c @@ -46,24 +46,25 @@ main ( /* open file and add mesh */ h5_file_t* const f = H5OpenFile (FNAME, H5_O_WRONLY, 0); - H5FedAddTriangleMesh (f); + h5t_mesh_t* m; + H5FedAddTriangleMesh (f, "0", &m); /* store vertices */ - H5FedBeginStoreVertices (f, num_vertices); + H5FedBeginStoreVertices (m, num_vertices); int i; for (i = 0; i < num_vertices; i++) { - H5FedStoreVertex (f, -1, Vertices[i].P); + H5FedStoreVertex (m, -1, Vertices[i].P); } - H5FedEndStoreVertices (f); + H5FedEndStoreVertices (m); /* store elements */ - H5FedBeginStoreElements (f, num_elems); + H5FedBeginStoreElements (m, num_elems); for (i = 0; i < num_elems; i++) { - H5FedStoreElement (f, Elems[i].vids); + H5FedStoreElement (m, Elems[i].vids); } - H5FedEndStoreElements (f); + H5FedEndStoreElements (m); - H5FedCloseMesh (f); + H5FedCloseMesh (m); H5CloseFile (f); return 0; } diff --git a/test/Makefile.am b/test/Makefile.am index 682c670..e2831a1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -45,6 +45,6 @@ h5_attach_test_LDADD = \ ../src/h5core/libH5hut.la \ ../src/C/libH5hutC.la -clean: clean-am - rm -f *.h5 +clean-local: + ${RM} -f *.h5