[MOAB-dev] r2049 - MOAB/trunk/refiner

dcthomp at mcs.anl.gov dcthomp at mcs.anl.gov
Mon Aug 25 22:29:53 CDT 2008


Author: dcthomp
Date: 2008-08-25 22:29:52 -0500 (Mon, 25 Aug 2008)
New Revision: 2049

Modified:
   MOAB/trunk/refiner/MBMeshOutputFunctor.cpp
   MOAB/trunk/refiner/MBMeshRefiner.cpp
   MOAB/trunk/refiner/MBRefinerTagManager.cpp
   MOAB/trunk/refiner/MBRefinerTagManager.hpp
   MOAB/trunk/refiner/MBSplitVertices.hpp
Log:
ENH: Add some state to the tag manager to keep track of
     which processes share the element currently being refined.
BUG: Fix mismatch in number of interface entries (wasn't
     properly setting the sharing information on refined
     entities... the vertices were correct but elements
     were not).
ENH: Start of work to copy element tag data from the original
     element to the subdivided versions. Incomplete.


Modified: MOAB/trunk/refiner/MBMeshOutputFunctor.cpp
===================================================================
--- MOAB/trunk/refiner/MBMeshOutputFunctor.cpp	2008-08-25 23:02:57 UTC (rev 2048)
+++ MOAB/trunk/refiner/MBMeshOutputFunctor.cpp	2008-08-26 03:29:52 UTC (rev 2049)
@@ -255,7 +255,7 @@
     {
     std::cout << " *** ";
     // FIXME: Handle tag assignment for elements as well as vertices
-    //this->assign_tags( elem_handle, this->element_tag_data );
+    this->tag_manager->assign_element_tags( elem_handle );
     }
   std::cout << "---------> " << elem_handle << " ( " << etyp << " )\n\n";
   this->elem_vert.clear();

Modified: MOAB/trunk/refiner/MBMeshRefiner.cpp
===================================================================
--- MOAB/trunk/refiner/MBMeshRefiner.cpp	2008-08-25 23:02:57 UTC (rev 2048)
+++ MOAB/trunk/refiner/MBMeshRefiner.cpp	2008-08-26 03:29:52 UTC (rev 2049)
@@ -111,16 +111,24 @@
         MBRange set_ents;
         if ( this->mesh_in->get_entities_by_handle( *it, set_ents, false ) == MB_SUCCESS )
           {
+          // Create a matching set on the output mesh.
           MBMeshRefinerIterator set_work;
           unsigned int set_work_opts;
           this->mesh_in->get_meshset_options( *it, set_work_opts );
           this->mesh_out->create_meshset( set_work_opts, set_work.destination_set );
           set_work.subset = set_ents;
           work.push_back( set_work );
+          // Copy any per-element tag values the user has requested to the output set.
+          this->tag_manager->set_element_tags_from_ent( *it );
+          this->tag_manager->assign_element_tags( set_work.destination_set );
+          // Copy the global ID to the new set (assuming it exists).
+          this->tag_manager->copy_gid( *it, set_work.destination_set );
           }
         }
       else
         {
+        this->tag_manager->set_element_tags_from_ent( *it );
+        this->tag_manager->set_element_procs_from_ent( *it );
         this->entity_refiner->refine_entity( etyp, *it );
         }
       }

Modified: MOAB/trunk/refiner/MBRefinerTagManager.cpp
===================================================================
--- MOAB/trunk/refiner/MBRefinerTagManager.cpp	2008-08-25 23:02:57 UTC (rev 2048)
+++ MOAB/trunk/refiner/MBRefinerTagManager.cpp	2008-08-26 03:29:52 UTC (rev 2049)
@@ -20,6 +20,7 @@
   this->input_mesh = in_mesh;
   this->output_mesh = out_mesh;
   this->reset_vertex_tags();
+  this->reset_element_tags();
   MBParallelComm* ipcomm = MBParallelComm::get_pcomm( this->input_mesh, 0 );
   MBParallelComm* opcomm = 0;
   if ( this->output_mesh != this->input_mesh )
@@ -169,6 +170,55 @@
   *\brief Return the number of tags that will be output with each new vertex.
   */
 
+/// Clear the list of tag values that will appear past the element coordinates in \a p0, \a p1, and \a p2.
+void MBRefinerTagManager::reset_element_tags()
+{
+  this->element_size = 0;
+  this->input_element_tags.clear();
+  this->output_element_tags.clear();
+  this->element_tag_data.clear();
+}
+
+/** Add a tag to the list of tag values that will appear past the element coordinates.
+  * The return value is the offset into each element coordinate pointer (\a p0, \a p1, \a p2) where the
+  * tag value(s) will be stored.
+  */
+int MBRefinerTagManager::add_element_tag( MBTag tag_handle )
+{
+  int offset = this->element_size; // old size is offset of tag being added
+  int tag_size;
+  MBTagType tagType;
+  if ( this->input_mesh->tag_get_size( tag_handle, tag_size ) != MB_SUCCESS )
+    return -1;
+
+  if ( this->input_mesh->tag_get_type( tag_handle, tagType ) != MB_SUCCESS )
+    return -1;
+
+  if ( tagType == MB_TAG_BIT )
+    {
+    // Pad any bit tags to a size in full bytes.
+    tag_size = ( tag_size % 8 ? 1 : 0 ) + ( tag_size / 8 );
+    }
+
+  // Now pad so that the next tag will be word-aligned:
+  while ( tag_size % sizeof(int) )
+    ++tag_size;
+
+  this->element_size += tag_size;
+  this->element_tag_data.resize( this->element_size );
+
+  this->input_element_tags.push_back( std::pair< MBTag, int >( tag_handle, offset ) );
+  return offset;
+}
+
+/**\fn int MBRefinerTagManager::get_element_tag_size()
+  *\brief Return the number of bytes to allocate for tag data per point.
+  */
+
+/**\fn int MBRefinerTagManager::get_number_of_element_tags() const
+  *\brief Return the number of tags that will be output with each new element.
+  */
+
 /**\brief Populate the list of output tags to match the list of input tags.
   *
   * When the input mesh and output mesh pointers are identical, this simply copies the list of input tags.
@@ -179,41 +229,14 @@
   if ( this->input_mesh == this->output_mesh )
     {
     this->output_vertex_tags = this->input_vertex_tags;
+    this->output_element_tags = this->input_element_tags;
     return;
     }
 
-  std::pair< MBTag, int > tag_rec;
   std::vector< std::pair< MBTag, int > >::iterator it;
-  std::vector< char > tag_default;
-  std::string tag_name;
-  MBTagType tag_type;
-  MBDataType tag_data_type;
-  int tag_size;
   for ( it = this->input_vertex_tags.begin(); it != this->input_vertex_tags.end(); ++ it )
     {
-    MBTag tag_in = it->first;
-    tag_rec.second = it->second;
-    this->input_mesh->tag_get_name( tag_in, tag_name );
-    this->input_mesh->tag_get_size( tag_in, tag_size );
-    this->input_mesh->tag_get_type( tag_in, tag_type );
-    this->input_mesh->tag_get_data_type( tag_in, tag_data_type );
-    this->input_mesh->tag_get_default_value( tag_in, (void*) &tag_default[0] );
-    tag_default.resize( tag_size );
-    MBErrorCode res = this->output_mesh->tag_create(
-      tag_name.c_str(), tag_size, tag_type, tag_data_type, tag_rec.first, (void*) &tag_default[0], true );
-    std::cout
-      << "Creating output tag: \"" << tag_name.c_str() << "\" handle: " << tag_rec.first
-      << " input handle: " << tag_in << "\n";
-    if ( res == MB_FAILURE )
-      {
-      std::cerr
-        << "Could not create output tag name: \"" << tag_name.c_str() << "\" type: "
-        << tag_type << " data type: " << tag_data_type << "\n";
-      }
-    else
-      {
-      this->output_vertex_tags.push_back( tag_rec );
-      }
+    this->create_tag_internal( it->first, it->second );
     }
 }
 
@@ -306,6 +329,23 @@
   return this->output_mesh->tag_set_data( this->tag_ogid, &ent, 1, &gid );
 }
 
+/**\brief Copy a global ID from an entity of the input mesh to an entity of the output mesh.
+  *
+  * @param[in] ent_input An entity on the input mesh with a global ID.
+  * @param[in] ent_output An entity on the output mesh whose global ID should be set.
+  * @retval               Normally MB_SUCCESS, but returns other values if tag_get_data or tag_set_data fail.
+  */
+int MBRefinerTagManager::copy_gid( MBEntityHandle ent_input, MBEntityHandle ent_output )
+{
+  int gid = -1;
+  int status;
+  if ( ( status =  this->input_mesh->tag_get_data( this->tag_igid, &ent_input, 1, &gid ) ) == MB_SUCCESS )
+    {
+    status = this->output_mesh->tag_set_data( this->tag_ogid, &ent_output, 1, &gid );
+    }
+  return status;
+}
+
 /**\brief Set parallel status and sharing process list on an entity.
   *
   * This sets tag values for the PARALLEL_STATUS and one of PARALLEL_SHARED_PROC or PARALLEL_SHARED_PROCS tags
@@ -418,3 +458,54 @@
   std::cout << "\n";
 }
 
+void MBRefinerTagManager::create_tag_internal( MBTag tag_in, int offset )
+{
+  std::pair< MBTag, int > tag_rec;
+  std::vector< char > tag_default;
+  std::string tag_name;
+  MBTagType tag_type;
+  MBDataType tag_data_type;
+  int tag_size;
+
+  tag_rec.second = offset;
+  this->input_mesh->tag_get_name( tag_in, tag_name );
+  this->input_mesh->tag_get_size( tag_in, tag_size );
+  this->input_mesh->tag_get_type( tag_in, tag_type );
+  this->input_mesh->tag_get_data_type( tag_in, tag_data_type );
+  this->input_mesh->tag_get_default_value( tag_in, (void*) &tag_default[0] );
+  tag_default.resize( tag_size );
+  MBErrorCode res = this->output_mesh->tag_create(
+    tag_name.c_str(), tag_size, tag_type, tag_data_type, tag_rec.first, (void*) &tag_default[0], true );
+  std::cout
+    << "Creating output tag: \"" << tag_name.c_str() << "\" handle: " << tag_rec.first
+    << " input handle: " << tag_in << "\n";
+  if ( res == MB_FAILURE )
+    {
+    std::cerr
+      << "Could not create output tag name: \"" << tag_name.c_str() << "\" type: "
+      << tag_type << " data type: " << tag_data_type << "\n";
+    }
+  else
+    {
+    this->output_vertex_tags.push_back( tag_rec );
+    }
+}
+
+void MBRefinerTagManager::set_element_tags_from_ent( MBEntityHandle ent_input )
+{
+  std::vector< std::pair< MBTag, int > >::iterator it;
+  for ( it = this->input_element_tags.begin(); it != this->input_element_tags.end(); ++ it )
+    {
+    this->input_mesh->tag_get_data( it->first, &ent_input, 1, &this->element_tag_data[it->second] );
+    }
+}
+
+void MBRefinerTagManager::assign_element_tags( MBEntityHandle ent_output )
+{
+  std::vector< std::pair< MBTag, int > >::iterator it;
+  for ( it = this->output_element_tags.begin(); it != this->output_element_tags.end(); ++ it )
+    {
+    this->output_mesh->tag_set_data( it->first, &ent_output, 1, &this->element_tag_data[it->second] );
+    }
+}
+

Modified: MOAB/trunk/refiner/MBRefinerTagManager.hpp
===================================================================
--- MOAB/trunk/refiner/MBRefinerTagManager.hpp	2008-08-25 23:02:57 UTC (rev 2048)
+++ MOAB/trunk/refiner/MBRefinerTagManager.hpp	2008-08-26 03:29:52 UTC (rev 2049)
@@ -45,11 +45,19 @@
   int get_vertex_tag_size() const { return this->vertex_size; }
   int get_number_of_vertex_tags() const { return this->input_vertex_tags.size(); }
 
+  void reset_element_tags();
+  int add_element_tag( MBTag tag_handle );
+  int get_element_tag_size() const { return this->element_size; }
+  int get_number_of_element_tags() const { return this->input_element_tags.size(); }
+
   void create_output_tags();
 
   void get_input_vertex_tag( int i, MBTag& tag, int& byte_offset );
   void get_output_vertex_tag( int i, MBTag& tag, int& byte_offset );
 
+  void get_input_element_tag( int i, MBTag& tag, int& byte_offset );
+  void get_output_element_tag( int i, MBTag& tag, int& byte_offset );
+
   MBInterface* get_input_mesh() { return this->input_mesh; }
   MBInterface* get_output_mesh() { return this->output_mesh; }
 
@@ -60,14 +68,36 @@
   int get_input_gids( int n, const MBEntityHandle* ents, std::vector<int>& gids );
   int get_output_gids( int n, const MBEntityHandle* ents, std::vector<int>& gids );
   int set_gid( MBEntityHandle ent, int gid );
+  int copy_gid( MBEntityHandle ent_input, MBEntityHandle ent_output );
 
   void set_sharing( MBEntityHandle ent_handle, MBProcessSet& procs );
   void get_common_processes( int num, const MBEntityHandle* src, MBProcessSet& common_shared_procs, bool on_output_mesh = true );
 
+  void set_element_tags_from_ent( MBEntityHandle ent_input );
+  void assign_element_tags( MBEntityHandle ent_output );
+
+  void set_element_procs_from_ent( MBEntityHandle ent_input )
+    {
+    this->get_common_processes( 1, &ent_input, this->current_element_procs, false );
+    }
+  MBProcessSet& get_element_procs()
+    {
+    return this->current_element_procs;
+    }
+  void set_element_sharing( MBEntityHandle ent_output )
+    {
+    this->set_sharing( ent_output, this->current_element_procs );
+    }
+
 protected:
+  void create_tag_internal( MBTag, int );
+
   std::vector< std::pair< MBTag, int > > input_vertex_tags;
   std::vector< std::pair< MBTag, int > > output_vertex_tags;
+  std::vector< std::pair< MBTag, int > > input_element_tags;
+  std::vector< std::pair< MBTag, int > > output_element_tags;
   int vertex_size;
+  int element_size;
   MBInterface* input_mesh;
   MBInterface* output_mesh;
   MBTag tag_ipstatus; // Handle for PARALLEL_STATUS on mesh_in
@@ -86,6 +116,8 @@
   std::vector<int> shared_procs_in; // Used to hold procs sharing an input vert.
   std::vector<int> shared_procs_out; // Used to hold procs sharing an output entity.
   MBProcessSet current_shared_procs; // Holds process list as it is being accumulated
+  MBProcessSet current_element_procs; // The list of processes which should share an output element.
+  std::vector<char> element_tag_data; // Holds tag data for per-element tags
 };
 
 #endif // MB_REFINERTAGMANAGER_H

Modified: MOAB/trunk/refiner/MBSplitVertices.hpp
===================================================================
--- MOAB/trunk/refiner/MBSplitVertices.hpp	2008-08-25 23:02:57 UTC (rev 2048)
+++ MOAB/trunk/refiner/MBSplitVertices.hpp	2008-08-26 03:29:52 UTC (rev 2049)
@@ -186,15 +186,15 @@
   int stat;
   stat = this->tag_manager->get_input_gids( _n, elem_verts, this->split_gids );
   MBSplitVertexIndex<_n> key( &this->split_gids[0] );
-  this->tag_manager->get_common_processes( _n, elem_verts, this->common_shared_procs );
-  proc_partition_counts[this->common_shared_procs]++;
-  key.set_common_processes( this->common_shared_procs );
+  //this->tag_manager->get_common_processes( _n, elem_verts, this->common_shared_procs );
+  proc_partition_counts[this->tag_manager->get_element_procs()]++;
+  key.set_common_processes( this->tag_manager->get_element_procs() );
   if ( this->mesh_out->create_element( etyp, elem_verts, nconn, elem_handle ) != MB_SUCCESS )
     {
     return false;
     }
   (*this)[key] = elem_handle;
-  this->tag_manager->set_sharing( elem_handle, this->common_shared_procs );
+  this->tag_manager->set_sharing( elem_handle, this->tag_manager->get_element_procs() );
   return true;
 }
 




More information about the moab-dev mailing list