[MOAB-dev] r1277 - in MOAB/trunk: . tools/converter tools/size

tautges at mcs.anl.gov tautges at mcs.anl.gov
Fri Sep 14 13:12:09 CDT 2007


Author: tautges
Date: 2007-09-14 13:12:09 -0500 (Fri, 14 Sep 2007)
New Revision: 1277

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MBCore.hpp
   MOAB/trunk/MBRange.cpp
   MOAB/trunk/MBRange.hpp
   MOAB/trunk/ReadParallel.cpp
   MOAB/trunk/tools/converter/convert.cpp
   MOAB/trunk/tools/size/size.cpp
Log:
Misc changes, mostly to help debug ReadParallel but also generally
useful.

MBCore: changed is_valid to a const function; also, in list_entities,
print set contents using MBRange::print instead of printing individual
entities; also print any non-opaque-typed sparse tags on sets

convert.cpp, size.cpp: when getting entities in sets, make
it a recursive call

ReadParallel.cpp: fixed bugs when deleting entities not in local
partition 

MBRange: in print function, added a prefix

Passes make check.



Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2007-09-14 17:33:37 UTC (rev 1276)
+++ MOAB/trunk/MBCore.cpp	2007-09-14 18:12:09 UTC (rev 1277)
@@ -1884,6 +1884,11 @@
   MBErrorCode result;
   MBHandleVec adj_vec;
 
+  if (!is_valid(entity)) {
+    std::cout << "(invalid)" << std::endl;
+    return MB_SUCCESS;
+  }
+
   if (0 != globalIdTag) {
     int dum;
     result = tag_get_data(globalIdTag, &entity, 1, &dum);
@@ -2498,17 +2503,7 @@
     
   std::string indent_prefix = prefix;
   indent_prefix += "  ";
-  for (MBRange::iterator it = entities.begin(); 
-       it != entities.end(); it++) 
-  {
-    if (TYPE_FROM_HANDLE(*it) == MBENTITYSET) {
-      print(*it, indent_prefix.c_str(), false);
-    }
-    else if (first_call) {
-      std::cout << prefix << MBCN::EntityTypeName(TYPE_FROM_HANDLE(*it)) << " " 
-                << ID_FROM_HANDLE(*it) << std::endl;
-    }
-  }
+  entities.print(indent_prefix.c_str());
 
   if (!first_call || !ms_handle) return;
   
@@ -2536,7 +2531,48 @@
     }
     std::cout << std::endl;
   }
+
+    // print all sparse tags
+  std::vector<MBTag> set_tags;
+  MBErrorCode result = this->tag_get_tags_on_entity(ms_handle, set_tags);
+  std::cout << indent_prefix << "Sparse tags:" << std::endl;
+  indent_prefix += "  ";
   
+  for (std::vector<MBTag>::iterator vit = set_tags.begin(); 
+       vit != set_tags.end(); vit++) {
+    MBTagType this_type;
+    result = this->tag_get_type(*vit, this_type);
+    if (MB_SUCCESS != result || MB_TAG_SPARSE != this_type) continue;
+    MBDataType this_data_type;
+    result = this->tag_get_data_type(*vit, this_data_type);
+    int this_size;
+    result = this->tag_get_size(*vit, this_size);
+    if (MB_SUCCESS != result || (int) sizeof(double) < this_size) continue;
+      // use double since this is largest single-valued tag
+    double this_val;
+    result = this->tag_get_data(*vit, &ms_handle, 1, &this_val);
+    if (MB_SUCCESS != result) continue;
+    std::string tag_name;
+    result = this->tag_get_name(*vit, tag_name);
+    if (MB_SUCCESS != result) continue;
+    switch (this_data_type) {
+      case MB_TYPE_INTEGER:
+        std::cout << indent_prefix << tag_name << " = " 
+                  << *((int*)&this_val) << std::endl;
+        break;
+      case MB_TYPE_DOUBLE:
+        std::cout << indent_prefix << tag_name << " = " 
+                  << this_val << std::endl;
+        break;
+      case MB_TYPE_HANDLE:
+        std::cout << indent_prefix << tag_name << " = " 
+                  << *((MBEntityID*)&this_val) << std::endl;
+        break;
+      case MB_TYPE_BIT:
+      case MB_TYPE_OPAQUE:
+        break;
+    }
+  }
 }
 
 MBErrorCode MBCore::check_adjacencies() 
@@ -2635,7 +2671,7 @@
   return MB_SUCCESS;
 }
 
-bool MBCore::is_valid(const MBEntityHandle this_ent) 
+bool MBCore::is_valid(const MBEntityHandle this_ent) const
 {
   MBEntitySequence* seq = 0;
   MBErrorCode result = sequence_manager()->find(this_ent, seq);

Modified: MOAB/trunk/MBCore.hpp
===================================================================
--- MOAB/trunk/MBCore.hpp	2007-09-14 17:33:37 UTC (rev 1276)
+++ MOAB/trunk/MBCore.hpp	2007-09-14 18:12:09 UTC (rev 1277)
@@ -858,7 +858,7 @@
   MBErrorCode check_adjacencies(const MBEntityHandle *ents, int num_ents);
   
     //! return whether the input handle is valid or not
-  bool is_valid(const MBEntityHandle this_ent);
+  bool is_valid(const MBEntityHandle this_ent) const;
   
 //-----------------Memory Functions------------------//
 

Modified: MOAB/trunk/MBRange.cpp
===================================================================
--- MOAB/trunk/MBRange.cpp	2007-09-14 17:33:37 UTC (rev 1276)
+++ MOAB/trunk/MBRange.cpp	2007-09-14 18:12:09 UTC (rev 1277)
@@ -537,15 +537,18 @@
 }
 
 // for debugging
-void MBRange::print() const
+void MBRange::print(const char *indent_prefix) const
 {
-  print( std::cout );
+  print(std::cout, indent_prefix);
 }
 
-void MBRange::print( std::ostream& stream ) const
+void MBRange::print(std::ostream& stream, const char *indent_prefix) const
 {
+  std::string indent_prefix_str;
+  if (NULL != indent_prefix) indent_prefix_str += indent_prefix;
+  
   if (empty()) {
-    stream << "\tempty" << std::endl;
+    stream << indent_prefix_str << "\tempty" << std::endl;
     return;
   }
   
@@ -553,7 +556,8 @@
     MBEntityType t1 = TYPE_FROM_HANDLE( i->first );
     MBEntityType t2 = TYPE_FROM_HANDLE( i->second );
   
-    stream << "\t" << MBCN::EntityTypeName( t1 ) << " " << ID_FROM_HANDLE( i->first );
+    stream << indent_prefix_str << "\t" << MBCN::EntityTypeName( t1 ) << " " 
+           << ID_FROM_HANDLE( i->first );
     if(i->first != i->second) {
       stream << " - ";
       if (t1 != t2) 

Modified: MOAB/trunk/MBRange.hpp
===================================================================
--- MOAB/trunk/MBRange.hpp	2007-09-14 17:33:37 UTC (rev 1276)
+++ MOAB/trunk/MBRange.hpp	2007-09-14 18:12:09 UTC (rev 1277)
@@ -295,8 +295,8 @@
   void clear();
   
   //! for debugging
-  void print() const;
-  void print( std::ostream& s ) const;
+  void print(const char *indent_prefix = NULL) const;
+  void print(std::ostream& s, const char *indent_prefix = NULL) const;
   
   unsigned long get_memory_use() const;
 

Modified: MOAB/trunk/ReadParallel.cpp
===================================================================
--- MOAB/trunk/ReadParallel.cpp	2007-09-14 17:33:37 UTC (rev 1276)
+++ MOAB/trunk/ReadParallel.cpp	2007-09-14 18:12:09 UTC (rev 1277)
@@ -179,13 +179,13 @@
     // gather adjacent ents of lower dimension and add to existing ents
   MBRange tmp_ents;
   for (int dim = 2; dim >= 0; dim--) {
-    MBEntityType lower_type = MBVERTEX, upper_type = MBENTITYSET;
-    while (MBMAXTYPE != lower_type && MBCN::Dimension(lower_type) < dim+1) lower_type++;
+    MBEntityType lower_type = MBCN::TypeDimensionMap[dim+1].first,
+      upper_type = MBCN::TypeDimensionMap[3].second;
     
-    MBRange::iterator bit = exist_ents.lower_bound(lower_type),
+    MBRange::const_iterator bit = exist_ents.lower_bound(lower_type),
       eit = exist_ents.upper_bound(upper_type);
-    MBRange from_ents(*bit, *eit);
-    from_ents = from_ents.intersect(exist_ents);
+    MBRange from_ents;
+    from_ents.merge(bit, eit);
     tmp_ents.clear();
     result = mbImpl->get_adjacencies(from_ents, dim, false, tmp_ents, 
                                      MBInterface::UNION); RR;
@@ -195,43 +195,42 @@
     // subtract from all ents to get deletable ents
   all_ents = all_ents.subtract(exist_ents);
   
-    // now go through the sets to see if we should keep any
+    // go through the sets to which ones we should keep
   MBRange all_sets, deletable_sets;
   result = mbImpl->get_entities_by_type(0, MBENTITYSET, all_sets);
   for (MBRange::iterator rit = all_sets.begin(); rit != all_sets.end(); rit++) {
     tmp_ents.clear();
     result = mbImpl->get_entities_by_handle(*rit, tmp_ents, true); RR;
-    tmp_ents = tmp_ents.intersect(exist_ents);
+    MBRange tmp_ents2 = tmp_ents.intersect(exist_ents);
     
       // if the intersection is empty, set is deletable
-    if (tmp_ents.empty()) deletable_sets.insert(*rit);
+    if (tmp_ents2.empty()) deletable_sets.insert(*rit);
+    
+    else if (tmp_ents.size() > tmp_ents2.size()) {
+        // more elements in set or contained sets than we're keeping; delete 
+        // the difference from just this set, to remove entities to be deleted below
+        // it's ok if entity isn't contained, doesn't generate an error
+      tmp_ents = tmp_ents.subtract(tmp_ents2);
+      result = mbImpl->remove_entities(*rit, tmp_ents); RR;
+    }
   }
+
+    // take the deletable sets out of other sets so we don't end up
+    // with stale set handles
+  for (MBRange::iterator rit = all_sets.begin(); rit != all_sets.end(); rit++) {
+    if (deletable_sets.find(*rit) == deletable_sets.end()) {
+      result = mbImpl->remove_entities(*rit, deletable_sets); RR;
+    }
+  }
+
+    // remove sets from all_ents, since they're dealt with separately
+  all_ents = all_ents.subtract(all_sets);
   
     // now delete sets first, then ents
   result = mbImpl->delete_entities(deletable_sets); RR;
   result = mbImpl->delete_entities(all_ents); RR;
   
-    // finally, look for sparse tags which have no entities, and delete
-    // those too
-  std::vector<MBTag> all_tags;
-  result = mbImpl->tag_get_tags(all_tags);
-  MBTag *tag_vec = &all_tags[0];
-  for (unsigned int i = 0; i < all_tags.size(); i++) {
-      // get type first, and continue if not sparse
-    MBTagType this_type;
-    result = mbImpl->tag_get_type(tag_vec[i], this_type); RR;
-    if (MB_TAG_SPARSE != this_type) continue;
-    
-      // get ents with this tag; should be efficient for sparse tags
-    tmp_ents.clear();
-    result = mbImpl->get_entities_by_type_and_tag(0, MBMAXTYPE, 
-                                                  tag_vec+i, NULL,
-                                                  1, tmp_ents); RR;
-    if (tmp_ents.empty()) {
-        // no entities with this tag - delete the tag
-      result = mbImpl->tag_delete(tag_vec[i]); RR;
-    }
-  }
+  result = ((MBCore*)mbImpl)->check_adjacencies();
   
-  return MB_SUCCESS;
+  return result;
 }

Modified: MOAB/trunk/tools/converter/convert.cpp
===================================================================
--- MOAB/trunk/tools/converter/convert.cpp	2007-09-14 17:33:37 UTC (rev 1276)
+++ MOAB/trunk/tools/converter/convert.cpp	2007-09-14 18:12:09 UTC (rev 1277)
@@ -431,9 +431,9 @@
     }
     for (i = 0; i < num_sets; ++i) {
       MBRange dim3, dim2, adj;
-      gMB->get_entities_by_dimension( sets[i], 3, dim3 );
+      gMB->get_entities_by_dimension( sets[i], 3, dim3, true );
       if (generate[1]) {
-        gMB->get_entities_by_dimension( sets[i], 2, dim2 );
+        gMB->get_entities_by_dimension( sets[i], 2, dim2, true );
         gMB->get_adjacencies( dim3, 1, true, adj, MBInterface::UNION );
         gMB->get_adjacencies( dim2, 1, true, adj, MBInterface::UNION );
       }

Modified: MOAB/trunk/tools/size/size.cpp
===================================================================
--- MOAB/trunk/tools/size/size.cpp	2007-09-14 17:33:37 UTC (rev 1276)
+++ MOAB/trunk/tools/size/size.cpp	2007-09-14 18:12:09 UTC (rev 1277)
@@ -126,7 +126,7 @@
     int num_edges = MBCN::NumSubEntities( type, 1 );
     
     MBRange range;
-    rval = moab.get_entities_by_type( set, type, range, false );
+    rval = moab.get_entities_by_type( set, type, range, true );
     if (MB_SUCCESS != rval) return rval;
     for (MBRange::iterator i = range.begin(); i != range.end(); ++i)
     {




More information about the moab-dev mailing list