[MOAB-dev] r1928 - in MOAB/trunk: . test/h5file

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Wed Jun 25 18:50:02 CDT 2008


Author: kraftche
Date: 2008-06-25 18:50:02 -0500 (Wed, 25 Jun 2008)
New Revision: 1928

Added:
   MOAB/trunk/test/h5file/h5sets_test.cpp
Modified:
   MOAB/trunk/ReadHDF5.cpp
   MOAB/trunk/ReadHDF5.hpp
   MOAB/trunk/WriteHDF5.cpp
   MOAB/trunk/test/h5file/Makefile.am
Log:
Fix .h5m file I/O bugs:
 o Fix bug writing ranged sets containing invalid handles
 o Don't create two sets for the contents of the file.
 o Add regression tests for above bugs.


Modified: MOAB/trunk/ReadHDF5.cpp
===================================================================
--- MOAB/trunk/ReadHDF5.cpp	2008-06-25 18:34:20 UTC (rev 1927)
+++ MOAB/trunk/ReadHDF5.cpp	2008-06-25 23:50:02 UTC (rev 1928)
@@ -125,7 +125,6 @@
   std::list<ElemSet>::iterator el_itor;
   std::list<ElemSet>::reverse_iterator rel_itor;
   unsigned int i, num_groups;
-  MBEntityHandle all;  // meshset of everything in file.
   bool have_nodes = true;
   file_set = 0;
 
@@ -216,10 +215,6 @@
   }
   free( tag_names );
   tag_names = 0;
-  
-DEBUGOUT("Finishing read.\n");
-  if (MB_SUCCESS != read_qa( all ))
-    goto read_fail;
     
 DEBUGOUT("Creating entity set for file contents\n")
   if (MB_SUCCESS != iFace->create_meshset( MESHSET_SET, file_set ))
@@ -232,6 +227,10 @@
   if (MB_SUCCESS != iFace->add_entities( file_set, nodeSet.range ))
     goto read_fail;
   
+DEBUGOUT("Finishing read.\n");
+  if (MB_SUCCESS != read_qa( file_set ))
+    goto read_fail;
+  
 
     // Clean up and exit.
   free( dataBuffer );
@@ -1986,7 +1985,7 @@
 }
   
 
-MBErrorCode ReadHDF5::read_qa( MBEntityHandle& import_set )
+MBErrorCode ReadHDF5::read_qa( MBEntityHandle import_set )
 {
   MBErrorCode rval;
   mhdf_Status status;
@@ -2007,35 +2006,6 @@
   }
   free( qa );
   
-  rval = iFace->create_meshset( MESHSET_SET, import_set );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  rval = MB_SUCCESS;
-  if (!setSet.range.empty())
-    rval = iFace->add_entities( import_set, setSet.range );
-  setSet.range.insert( import_set );
-  if (MB_SUCCESS != rval)
-    return rval;
-  
-  if (!nodeSet.range.empty())
-  {
-    rval = iFace->add_entities( import_set, nodeSet.range );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
-  std::list<ElemSet>::iterator iter = elemList.begin();
-  for ( ; iter != elemList.end(); ++iter )
-  {
-    if (iter->range.empty())
-      continue;
-    
-    rval = iFace->add_entities( import_set, iter->range );
-    if (MB_SUCCESS != rval)
-      return rval;
-  }
-  
   /** FIX ME - how to put QA list on set?? */
 
   return MB_SUCCESS;

Modified: MOAB/trunk/ReadHDF5.hpp
===================================================================
--- MOAB/trunk/ReadHDF5.hpp	2008-06-25 18:34:20 UTC (rev 1927)
+++ MOAB/trunk/ReadHDF5.hpp	2008-06-25 23:50:02 UTC (rev 1928)
@@ -145,7 +145,7 @@
                                 hid_t hdf_read_type,
                                 bool is_handle_type );
                                
-  MBErrorCode read_qa( MBEntityHandle& import_set_out );
+  MBErrorCode read_qa( MBEntityHandle file_set );
                                
   MBErrorCode convert_id_to_handle( const ElemSet& elems_in_this_set,
                                     MBEntityHandle* in_out_array,

Modified: MOAB/trunk/WriteHDF5.cpp
===================================================================
--- MOAB/trunk/WriteHDF5.cpp	2008-06-25 18:34:20 UTC (rev 1927)
+++ MOAB/trunk/WriteHDF5.cpp	2008-06-25 23:50:02 UTC (rev 1928)
@@ -1079,8 +1079,10 @@
     MBEntityHandle h = pi->first;
     while (h <= pi->second) {
       ri = idMap.lower_bound( ri, idMap.end(), h );
-      if (ri == idMap.end()) 
+      if (ri == idMap.end() || ri->begin > h) {
+        ++h;
         continue;
+      }
 
       id_t n = pi->second - pi->first + 1;
       if (n > ri->count)
@@ -1138,7 +1140,7 @@
     MBEntityHandle h = pi->first;
     while (h <= pi->second) {
       ri = idMap.lower_bound( ri, idMap.end(), h );
-      if (ri == idMap.end()) {
+      if (ri == idMap.end() || ri->begin > h) {
         rval = MB_ENTITY_NOT_FOUND;
         *i = 0; 
         ++i;

Modified: MOAB/trunk/test/h5file/Makefile.am
===================================================================
--- MOAB/trunk/test/h5file/Makefile.am	2008-06-25 18:34:20 UTC (rev 1927)
+++ MOAB/trunk/test/h5file/Makefile.am	2008-06-25 23:50:02 UTC (rev 1928)
@@ -1,6 +1,6 @@
 DEFS = $(DEFINES)
 INCLUDES += -I$(top_srcdir) -I$(top_srcdir)/mhdf/include -I$(top_builddir)
-check_PROGRAMS = h5test h5legacy h5varlen
+check_PROGRAMS = h5test h5legacy h5varlen h5sets_test
 parallel_programs = parallel varlen_ll mhdf_parallel
 
 if PARALLEL_HDF5
@@ -18,3 +18,4 @@
 varlen_ll_SOURCES = varlen_ll.cpp
 mhdf_parallel_SOURCES = mhdf_parallel.c
 mhdf_parallel_LDADD = ../../mhdf/libmhdf.la
+h5sets_test_SOURCES = h5sets_test.cpp

Added: MOAB/trunk/test/h5file/h5sets_test.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5sets_test.cpp	                        (rev 0)
+++ MOAB/trunk/test/h5file/h5sets_test.cpp	2008-06-25 23:50:02 UTC (rev 1928)
@@ -0,0 +1,136 @@
+#include "MBCore.hpp"
+#include "testdir.h"
+#include "TestUtil.hpp"
+
+#include <algorithm>
+#include <iostream>
+#include <stdlib.h>
+#include <math.h>
+
+const char filename[] = "sets.h5m";
+bool keep_file = false;
+
+void read_write_file( MBInterface& output, MBInterface& input, MBEntityHandle* input_set = 0 )
+{
+  MBEntityHandle file;
+  MBErrorCode rval;
+  rval = output.write_file( filename );
+  CHECK_ERR(rval);
+  rval = input.load_file( filename, file );
+  if (!keep_file)
+    remove(filename);
+  CHECK_ERR(rval);
+  if (input_set)
+    *input_set = file;
+}
+
+void test_ranged_set_with_holes()
+{
+  MBCore moab;
+  MBInterface& mb = moab;
+  MBErrorCode rval;
+  MBRange verts;
+  
+  const int num_vtx = 40;
+  std::vector<double> coords( 3*num_vtx, 0.0 );
+  rval = mb.create_vertices( &coords[0], num_vtx, verts );
+  CHECK_ERR(rval);
+  CHECK_EQUAL(num_vtx, (int)verts.size());
+  
+  MBEntityHandle set;
+  rval = mb.create_meshset( MESHSET_SET, set );
+  CHECK_ERR(rval);
+  rval = mb.add_entities( set, verts );
+  
+  std::vector<MBEntityHandle> dead_verts;
+  for (int i = num_vtx/4; i < num_vtx; i += num_vtx/4 ) {
+    MBRange::iterator j = verts.begin();
+    j += i;
+    dead_verts.push_back( *j );
+  }
+  rval = mb.delete_entities( &dead_verts[0], dead_verts.size() );
+  CHECK_ERR(rval);
+  
+  MBCore moab2;
+  MBInterface& mb2 = moab2;
+  MBEntityHandle file_set;
+  read_write_file( mb, mb2, &file_set );
+  MBRange sets;
+  mb2.get_entities_by_type( 0, MBENTITYSET, sets );
+  CHECK_EQUAL( 2, (int)sets.size() );
+  MBEntityHandle other_set = sets.front() == file_set ? sets.back() : sets.front();
+  
+  int num_vtx2 = -5;
+  rval = mb2.get_number_entities_by_type( other_set, MBVERTEX, num_vtx2 );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( (int)(num_vtx - dead_verts.size()), num_vtx2 );
+}
+
+void test_file_set()
+{
+  MBErrorCode rval;
+  MBCore moab;
+  double vtxcoords[] = { 0.0, 0.0, 0.0, 
+                         1.0, 0.0, 0.0, 
+                         0.0, 1.0, 0.0 };
+  MBRange verts;
+  rval = moab.create_vertices( vtxcoords, 3, verts );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 3, (int)verts.size() );
+  
+  MBEntityHandle tri;
+  MBEntityHandle conn[3];
+  std::copy( verts.begin(), verts.end(), conn );
+  rval = moab.create_element( MBTRI, conn, 3, tri );
+  CHECK_ERR(rval);
+  
+  MBEntityHandle set;
+  rval = moab.create_meshset( MESHSET_ORDERED, set );
+  CHECK_ERR(rval);
+  rval = moab.add_entities( set, &tri, 1 );
+  CHECK_ERR(rval);
+  
+  MBEntityHandle file;
+  read_write_file( moab, moab, &file );
+  
+  int count;
+  rval = moab.get_number_entities_by_type( 0, MBVERTEX, count );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 6, count );
+  rval = moab.get_number_entities_by_type( file, MBVERTEX, count );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 3, count );
+  
+  rval = moab.get_number_entities_by_type( 0, MBTRI, count );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 2, count );
+  rval = moab.get_number_entities_by_type( file, MBTRI, count );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 1, count );
+  
+  rval = moab.get_number_entities_by_type( 0, MBENTITYSET, count );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 3, count );
+  rval = moab.get_number_entities_by_type( file, MBENTITYSET, count );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 1, count );
+}
+  
+
+int main(int argc, char* argv[])
+{
+  if (argc == 2 &&  std::string(argv[1]) == "-k")
+    keep_file = true;
+  else if (argc != 1) {
+    std::cerr << "Usage: " << argv[0] << " [-k]" << std::endl;
+    return 1;
+  }
+
+  // only one test so far... should probably add second test
+  // for really-old-format  entityset parent/child links
+  int exitval = 0;
+  exitval += RUN_TEST( test_ranged_set_with_holes );
+  exitval += RUN_TEST( test_file_set );
+}
+
+  




More information about the moab-dev mailing list