[MOAB-dev] r1263 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Mon Aug 27 17:29:30 CDT 2007


Author: kraftche
Date: 2007-08-27 17:29:30 -0500 (Mon, 27 Aug 2007)
New Revision: 1263

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MBCore.hpp
   MOAB/trunk/TagServer.cpp
   MOAB/trunk/TagServer.hpp
   MOAB/trunk/WriteHDF5.cpp
Log:
o Remove special entity set from MBCore for storing "mesh" values of tag
o Make MBCore::get_root_set() return 0.
o Store global/mesh value of tags in TagInfo structure of TagServer
o Add special methods to get/set global/mesh value of tag
o Remove code in WriteHDF5 that checks for and removes the old "root set"
  from the results of calls to get all the mesh sets (and similar calls.)
  


Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2007-08-27 21:12:01 UTC (rev 1262)
+++ MOAB/trunk/MBCore.cpp	2007-08-27 22:29:30 UTC (rev 1263)
@@ -158,9 +158,6 @@
   readerWriterSet = new MBReaderWriterSet( this, mError );
   if (!readerWriterSet)
     return MB_MEMORY_ALLOCATION_FAILED;
-
-  MBErrorCode result = create_meshset(0, myMeshSet);
-  if (MB_SUCCESS != result) return result;
   
   material_tag();
   neumannBC_tag();
@@ -173,7 +170,7 @@
 
 MBEntityHandle MBCore::get_root_set() 
 {
-  return myMeshSet;
+  return 0;
 }
 
 void MBCore::deinitialize()
@@ -552,8 +549,6 @@
     delete sequenceManager;
   sequenceManager = new EntitySequenceManager( procInfo );
 
-  result = create_meshset(0, myMeshSet);
-
   return result;
 }
 
@@ -1430,11 +1425,8 @@
                                     const int num_entities,
                                     void *tag_data) const
 {
-  MBTagType tag_type;
-  
-  if (NULL == entity_handles && 0 == num_entities && 
-      MB_SUCCESS == tag_get_type(tag_handle, tag_type))
-    return tagServer->get_data(tag_handle, &myMeshSet, 1, tag_data);
+  if (NULL == entity_handles && 0 == num_entities)
+    return tagServer->get_mesh_data(tag_handle, tag_data);
 
   else return tagServer->get_data(tag_handle, entity_handles, num_entities, tag_data);
 }
@@ -1453,11 +1445,8 @@
                                     const int num_entities,
                                     const void *tag_data)
 {
-  MBTagType tag_type;
-  
-  if (NULL == entity_handles && 0 == num_entities && 
-      MB_SUCCESS == tag_get_type(tag_handle, tag_type))
-    return tagServer->set_data(tag_handle, &myMeshSet, 1, tag_data);
+  if (NULL == entity_handles && 0 == num_entities)
+    return tagServer->set_mesh_data(tag_handle, tag_data);
 
   //verify handles
   MBEntitySequence* seq;
@@ -1555,7 +1544,7 @@
   MBErrorCode status = MB_SUCCESS, temp_status;
   for (int i = 0; i < num_handles; i++) {
     if (0 == entity_handles[i])
-      temp_status = tagServer->remove_data(tag_handle, myMeshSet);
+      temp_status = tagServer->remove_mesh_data(tag_handle);
     else
       temp_status = tagServer->remove_data(tag_handle, entity_handles[i]);
     if (temp_status != MB_SUCCESS) status = temp_status;
@@ -1673,7 +1662,7 @@
                                             std::vector<MBTag> &tag_handles) const 
 {
   if (0 == entity)
-    return tagServer->get_tags(myMeshSet, tag_handles);
+    return tagServer->get_mesh_tags(tag_handles);
   else return tagServer->get_tags(entity, tag_handles);
 }
 

Modified: MOAB/trunk/MBCore.hpp
===================================================================
--- MOAB/trunk/MBCore.hpp	2007-08-27 21:12:01 UTC (rev 1262)
+++ MOAB/trunk/MBCore.hpp	2007-08-27 22:29:30 UTC (rev 1263)
@@ -1001,9 +1001,6 @@
   
   MBReaderWriterSet* readerWriterSet;
 
-    //! a meshset for the overall mesh; used primarily to set tags on entire mesh
-  MBEntityHandle myMeshSet;
-
   MBError* mError;
 
   static const char *errorStrings[];

Modified: MOAB/trunk/TagServer.cpp
===================================================================
--- MOAB/trunk/TagServer.cpp	2007-08-27 21:12:01 UTC (rev 1262)
+++ MOAB/trunk/TagServer.cpp	2007-08-27 22:29:30 UTC (rev 1263)
@@ -170,7 +170,6 @@
   if(iterator == mTagTable.end())
     return MB_TAG_NOT_FOUND;
 
-  mTagTable.erase(iterator);
   MBErrorCode status = MB_TAG_NOT_FOUND;
   
   MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
@@ -189,6 +188,10 @@
       status = MB_FAILURE;
   }
 
+  if (MB_SUCCESS == status) {
+    mTagTable.erase(iterator);
+  }
+  
   return status;
 
 }
@@ -249,6 +252,17 @@
   return mBitServer->get_bits(ID_FROM_TAG_HANDLE(tag_handle), entity_handle, data);
 }
 
+MBErrorCode TagServer::set_mesh_data( const MBTag tag_handle,
+                                      const void* data )
+{
+  TagInfo* info = get_tag_info( tag_handle );
+  if (!info)
+    return MB_TAG_NOT_FOUND;
+  
+  info->set_mesh_value( data );
+  return MB_SUCCESS;
+}
+
 MBErrorCode TagServer::set_data(const MBTag tag_handle, 
                                  const MBEntityHandle entity_handle, 
                                  const void* data)
@@ -391,6 +405,17 @@
 }
 
 
+MBErrorCode TagServer::get_mesh_data( const MBTag tag_handle,
+                                      void* data ) const
+{
+  const TagInfo* info = get_tag_info( tag_handle );
+  if (!info || !info->get_mesh_value())
+    return MB_TAG_NOT_FOUND;
+  
+  memcpy( data, info->get_mesh_value(), info->get_size() );
+  return MB_SUCCESS;
+}
+
 MBErrorCode TagServer::get_data(const MBTag tag_handle,
                        const MBEntityHandle entity_handle,
                        void* data)
@@ -603,6 +628,15 @@
   return result;
 }
 
+MBErrorCode TagServer::get_mesh_tags( std::vector<MBTag>& all_tags ) const
+{
+  std::map<MBTag,TagInfo>::const_iterator i;
+  for (i = mTagTable.begin(); i != mTagTable.end(); ++i)
+    if (i->second.get_mesh_value())
+      all_tags.push_back( i->first );
+  return MB_SUCCESS;
+}
+
 MBErrorCode TagServer::get_default_data_ref(const MBTag tag_handle, const void *& data) 
 {
 
@@ -644,6 +678,16 @@
 }
 
 
+MBErrorCode TagServer::remove_mesh_data( const MBTag tag_handle )
+{
+  TagInfo* info = get_tag_info( tag_handle );
+  if (!info || !info->get_mesh_value())
+    return MB_TAG_NOT_FOUND;
+  info->remove_mesh_value();
+  return MB_SUCCESS;
+}
+
+
 MBErrorCode TagServer::remove_data( const MBTag tag_handle, const MBEntityHandle entity_handle )
 {
 

Modified: MOAB/trunk/TagServer.hpp
===================================================================
--- MOAB/trunk/TagServer.hpp	2007-08-27 21:12:01 UTC (rev 1262)
+++ MOAB/trunk/TagServer.hpp	2007-08-27 22:29:30 UTC (rev 1263)
@@ -52,19 +52,24 @@
 public:
 
   //! constructor
-  TagInfo() : mTagName(""), mDataSize(0), mDefaultValue(NULL) {}
+  TagInfo() : mTagName(""), 
+              mDataSize(0), 
+              mDefaultValue(NULL), 
+              mMeshValue(NULL),
+              dataType(MB_TYPE_OPAQUE)
+              {}
   
   //! destructor
-  ~TagInfo();
+  inline ~TagInfo();
   
   //! copy constructor
-  TagInfo(const TagInfo&);
+  inline TagInfo(const TagInfo&);
 
   //! constructor that takes all parameters
-  TagInfo(const char *, int, MBDataType type, const void *);
+  inline TagInfo(const char *, int, MBDataType type, const void *);
 
   //! assignment operator
-  TagInfo &operator=(const TagInfo &rhs);
+  inline TagInfo &operator=(const TagInfo &rhs);
   
   //! set the name of the tag
   void set_name( const std::string& name) { mTagName = name; }
@@ -81,6 +86,15 @@
     //! get the default data
   const void *default_value() const  { return mDefaultValue;}
   
+    //! set mesh value
+  void set_mesh_value( const void* data );
+  
+    //! get mesh value
+  const void* get_mesh_value() const { return mMeshValue; }
+  
+    //! remove mesh value
+  void remove_mesh_value();
+  
   inline MBDataType get_data_type() const     { return dataType; }
   
   inline void set_data_type( MBDataType t )   { dataType = t; }
@@ -98,6 +112,9 @@
   //! stores the default data, if any
   unsigned char *mDefaultValue;
   
+  //! store the mesh value, if any
+  unsigned char *mMeshValue;
+  
   //! type of tag data
   MBDataType dataType;
 
@@ -138,6 +155,9 @@
   //! cleans out all data tagged on all entities
   MBErrorCode reset_all_data();
 
+  //! set global/mesh value of tag
+  MBErrorCode set_mesh_data( const MBTag tag_handle, const void* data );
+
   //! set the value of a tag
   MBErrorCode set_data(const MBTag tag_handle, const MBEntityHandle entity_handle, const void* data );
   
@@ -145,6 +165,9 @@
   
   MBErrorCode set_data(const MBTag tag_handle, const MBRange& entity_handles, const void* data );
 
+  //! get global/mesh value of tag
+  MBErrorCode get_mesh_data( const MBTag tag_handle, void* data ) const;
+
   //! get the value of a tag
   MBErrorCode get_data(const MBTag tag_handle, const MBEntityHandle entity_handle, void* data );
   
@@ -158,6 +181,9 @@
   //! get the value of a tag
   MBErrorCode get_bits(const MBTag tag_handle, const MBEntityHandle entity_handle, unsigned char& data );
 
+  //! remove global/mesh value of tag
+  MBErrorCode remove_mesh_data( const MBTag tag_handle );
+
   //! remove the tag data on an entity
   MBErrorCode remove_data( const MBTag tag_handle, const MBEntityHandle entity_handle );
 
@@ -220,7 +246,10 @@
 
   //! get all the tags which have been defined for this entity
   MBErrorCode get_tags(const MBEntityHandle entity, std::vector<MBTag> &all_tags);
-  
+ 
+  //! get all the tags which have a global/mesh value
+  MBErrorCode get_mesh_tags(std::vector<MBTag> &all_tags) const;
+ 
   //! get all the tags which have been defined
   MBErrorCode get_tags(std::vector<MBTag> &all_tags);
   
@@ -233,6 +262,7 @@
   //! get information about a tag
   const TagInfo* get_tag_info(const char *tag_name ) const;
   const TagInfo* get_tag_info( MBTag tag_handle ) const;
+  TagInfo* get_tag_info( MBTag tag_handle );
   
   unsigned long get_memory_use( MBTag tag_handle ) const;
   
@@ -268,15 +298,19 @@
 inline TagInfo::TagInfo(const TagInfo& copy)
   : mTagName( copy.mTagName ),
     mDataSize( copy.mDataSize ),
+    mDefaultValue( 0 ),
+    mMeshValue( 0 ),
     dataType( copy.dataType )
 {
-  if (NULL != copy.mDefaultValue)
-  {
+  if (copy.mDefaultValue) {
     mDefaultValue = new unsigned char[mDataSize];
     memcpy(mDefaultValue, copy.mDefaultValue, mDataSize);
   }
-  else 
-    mDefaultValue = NULL;
+  
+  if (copy.mMeshValue) {
+    mMeshValue = new unsigned char[mDataSize];
+    memcpy(mMeshValue, copy.mMeshValue, mDataSize);
+  }
 }
 
 inline TagInfo::TagInfo( const char* name, 
@@ -285,35 +319,34 @@
                          const void* default_value)
  : mTagName( name ),
    mDataSize( size ),
+   mDefaultValue( 0 ),
+   mMeshValue( 0 ),
    dataType( type )
 {
-  if (NULL != default_value) 
-  {
+  if (default_value) {
     mDefaultValue = new unsigned char[size];
     memcpy(mDefaultValue, default_value, size);
   }
-  else 
-    mDefaultValue = NULL;
 }
 
 inline TagInfo &TagInfo::operator=(const TagInfo &rhs)
 {
   mTagName = rhs.mTagName;
   mDataSize = rhs.mDataSize;
-  if (NULL != rhs.mDefaultValue) 
-  {
-    // delete the old data and make a new one (could be different size)
-    if(mDefaultValue != NULL)
-      delete [] mDefaultValue;
+  
+  delete [] mDefaultValue;
+  delete [] mMeshValue;
+  mDefaultValue = 0;
+  mMeshValue = 0;
+  
+  if (rhs.mDefaultValue) {
     mDefaultValue = new unsigned char[mDataSize];
-    memcpy(mDefaultValue, rhs.mDefaultValue, mDataSize);
+    memcpy( mDefaultValue, rhs.mDefaultValue, mDataSize );
   }
-  else
-  {
-    // delete old data
-    if(mDefaultValue != NULL)
-      delete [] mDefaultValue;
-    mDefaultValue = NULL;
+  
+  if (rhs.mMeshValue) {
+    mMeshValue = new unsigned char[mDataSize];
+    memcpy( mMeshValue, rhs.mMeshValue, mDataSize );
   }
   
   return *this;
@@ -322,11 +355,24 @@
 inline TagInfo::~TagInfo() 
 {
   // clean up default value
-  if (NULL != mDefaultValue)
-    delete [] mDefaultValue;
+  delete [] mDefaultValue;
+  delete [] mMeshValue;
 }
 
 
+inline void TagInfo::set_mesh_value( const void* data )
+{
+  if (!mMeshValue)
+    mMeshValue = new unsigned char[mDataSize];
+  memcpy( mMeshValue, data, mDataSize );
+}
+
+inline void TagInfo::remove_mesh_value()
+{ 
+  delete [] mMeshValue;
+  mMeshValue = 0;
+}
+
 inline const TagInfo* TagServer::get_tag_info( const char *tag_name ) const
 {
   if(NULL == tag_name || strcmp(tag_name, "") == 0)
@@ -357,6 +403,11 @@
   return NULL;
 }
 
+inline TagInfo* TagServer::get_tag_info( MBTag tag_handle )
+{
+  std::map<MBTag, TagInfo>::iterator i = mTagTable.find(tag_handle);
+  return (i == mTagTable.end()) ? (TagInfo*)0 : &(i->second);
+}
 
 #endif //TAG_SERVER_HPP
 

Modified: MOAB/trunk/WriteHDF5.cpp
===================================================================
--- MOAB/trunk/WriteHDF5.cpp	2007-08-27 21:12:01 UTC (rev 1262)
+++ MOAB/trunk/WriteHDF5.cpp	2007-08-27 22:29:30 UTC (rev 1263)
@@ -712,19 +712,6 @@
   CHK_MB_ERR_0(rval);
   setSet.type = MBENTITYSET;
   setSet.num_nodes = 0;
-  
-    // MOAB always returns the default set / global mesh
-    // Don't want it.
-  int size;
-  MBRange::iterator gs = setSet.range.begin();
-  assert( gs != setSet.range.end() &&
-          MB_SUCCESS == iFace->get_number_entities_by_handle( *gs, size ) && 
-          0 == size &&
-          MB_SUCCESS == iFace->num_child_meshsets( *gs, &size ) && 
-          0 == size &&
-          MB_SUCCESS == iFace->num_parent_meshsets( *gs, &size ) && 
-          0 == size );
-  setSet.range.erase( gs );
 
     // Get all elements, grouped by type and number of higher-order nodes
   exportList.clear();




More information about the moab-dev mailing list