[MOAB-dev] r1397 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Thu Nov 15 16:52:52 CST 2007


Author: kraftche
Date: 2007-11-15 16:52:52 -0600 (Thu, 15 Nov 2007)
New Revision: 1397

Added:
   MOAB/trunk/PolyElementSeq.cpp
   MOAB/trunk/PolyElementSeq.hpp
Modified:
   MOAB/trunk/AEntityFactory.cpp
   MOAB/trunk/AEntityFactory.hpp
   MOAB/trunk/MBTest.cpp
   MOAB/trunk/Makefile.am
   MOAB/trunk/SequenceManager.cpp
   MOAB/trunk/UnstructuredElemSeq.hpp
Log:
o Add new PolyElementSeq that is a subclass of UnstructuredElemSeq,
  overriding the get_connetivity methods with an alternate version that 
  disregards the "bool topological" argument.  It would have been simpler 
  to just check the MBEntityType in UnstructuredElemSeq::get_connectivity,
  however this way avoids two extra branches on the MBEntityType for no
  extra cost (get_connectivity methods are already virtual due to structured
  elements.)

o Fix query for edges adjacent to a polygon: don't return 
  MB_MULTIPLE_ENTITIES_FOUND when there are no adjacent edges.

o Add Tim's test code that demonstrated the above two issues to MBTest.cpp

o Add utility method AEntityFactory::get_vertices that calls either
  MBInterface::get_connectivity or MBInterface::get_adjacencies depending
  on whether or not the input entity is a MBPOLYHEDRON.  Change some code
  in AEntityFactory to use utility method.



Modified: MOAB/trunk/AEntityFactory.cpp
===================================================================
--- MOAB/trunk/AEntityFactory.cpp	2007-11-15 21:12:59 UTC (rev 1396)
+++ MOAB/trunk/AEntityFactory.cpp	2007-11-15 22:52:52 UTC (rev 1397)
@@ -31,8 +31,24 @@
 #include <algorithm>
 #include <set>
 
+MBErrorCode AEntityFactory::get_vertices( MBEntityHandle h,
+                                          const MBEntityHandle*& vect_out,
+                                          int& count_out,
+                                          std::vector<MBEntityHandle>& storage )
+{
+  MBErrorCode result;
+  if (MBPOLYHEDRON == TYPE_FROM_HANDLE(h)) {
+    storage.clear();
+    result = thisMB->get_adjacencies( &h, 1, 0, false, storage );
+    vect_out = &storage[0];
+    count_out = storage.size();
+  }
+  else {
+    result = thisMB->get_connectivity( h, vect_out, count_out, false, &storage );
+  }
+  return result;
+}
 
-
 AEntityFactory::AEntityFactory(MBCore *mdb) 
 {
   assert(NULL != mdb);
@@ -437,18 +453,9 @@
     MBEntityHandle const *connvect = 0, *adjvect = 0;
     int numconn = 0, numadj = 0;
     std::vector<MBEntityHandle> connstorage;
-    if (base_type != MBPOLYGON) {
-      result = thisMB->get_connectivity( base_entity, connvect, numconn, false, &connstorage );
-      if (MB_SUCCESS != result) 
-        return result;
-    }
-    else {
-      result = thisMB->get_adjacencies(&base_entity, 1, 0, false, connstorage);
-      if (MB_SUCCESS != result) 
-        return result;
-      connvect = &connstorage[0];
-      numconn = connstorage.size();
-    }
+    result = get_vertices( base_entity, connvect, numconn, connstorage );
+    if (MB_SUCCESS != result) 
+      return result;
     
     for (int i = 0; i < numconn; ++i) {
       result = get_adjacencies( connvect[i], adjvect, numadj );
@@ -498,13 +505,11 @@
   MBEntityType ent_type;
   MBRange::iterator i_range;
   const MBEntityHandle *connectivity;
-  std::vector<MBEntityHandle> polyh_connect;
+  std::vector<MBEntityHandle> aux_connect;
   int number_nodes;
   MBErrorCode result;
   MBRange handle_range;
-  static std::vector<MBEntityHandle> aux_connect;
   
-  
   // 1. over all element types, for each element, create vertex-element adjacencies
   for (ent_type = MBEDGE; ent_type != MBENTITYSET; ent_type++) 
   {
@@ -517,27 +522,9 @@
 
     for (i_range = handle_range.begin(); i_range != handle_range.end(); ++i_range) 
     {
-        // get the min-id vertex
-      if (MBPOLYHEDRON != ent_type) {
-        result = this->thisMB->get_connectivity(*i_range, connectivity, number_nodes);
-        if (MB_NOT_IMPLEMENTED == result) {
-            // probably a structured sequence - get the connectivity as a vector and
-            // set connectivity to point to that
-          result = this->thisMB->get_connectivity(&(*i_range), 1, aux_connect);
-          if (MB_SUCCESS != result) return result;
-          connectivity = &aux_connect[0];
-          number_nodes = aux_connect.size();
-        }
-          
-        if (MB_SUCCESS != result) return result;
-      }
-      else {
-        polyh_connect.clear();
-        result = get_adjacencies(*i_range, 0, false, polyh_connect);
-        if (MB_SUCCESS != result) return result;
-        connectivity = &polyh_connect[0];
-        number_nodes = polyh_connect.size();
-      }
+      result = get_vertices( *i_range, connectivity, number_nodes, aux_connect );
+      if (MB_SUCCESS != result)
+        return result;
       
         // add the adjacency
       for( int k=0; k<number_nodes; k++)
@@ -905,7 +892,7 @@
           // single edge - don't check adjacencies
         target_entities.push_back(*adj_edges.begin());
       }
-      else {
+      else if (adj_edges.size() != 0) {
           // multiple ones - need to check for explicit adjacencies
         unsigned int start_sz = target_entities.size();
         const MBEntityHandle *explicit_adjs;

Modified: MOAB/trunk/AEntityFactory.hpp
===================================================================
--- MOAB/trunk/AEntityFactory.hpp	2007-11-15 21:12:59 UTC (rev 1396)
+++ MOAB/trunk/AEntityFactory.hpp	2007-11-15 22:52:52 UTC (rev 1397)
@@ -150,6 +150,10 @@
   MBErrorCode get_adjacency_ptr( MBEntityHandle, const std::vector<MBEntityHandle>*& ) const;
   MBErrorCode set_adjacency_ptr( MBEntityHandle, std::vector<MBEntityHandle>* );
   
+  MBErrorCode get_vertices( MBEntityHandle h,
+                            const MBEntityHandle*& vect_out,
+                            int& count_out,
+                            std::vector<MBEntityHandle>& storage );
 
   //! private constructor to prevent the construction of a default one
   AEntityFactory();

Modified: MOAB/trunk/MBTest.cpp
===================================================================
--- MOAB/trunk/MBTest.cpp	2007-11-15 21:12:59 UTC (rev 1396)
+++ MOAB/trunk/MBTest.cpp	2007-11-15 22:52:52 UTC (rev 1397)
@@ -5599,6 +5599,49 @@
   return MB_SUCCESS;
 }
 
+MBErrorCode mb_poly_adjacency_test( MBInterface* )
+{
+  MBErrorCode rval;
+  MBCore moab(0,1);
+  MBInterface *mbImpl = &moab;
+  
+    // make a couple polygons and a polyhedron
+  double coords[3] = {0,1,2};
+  MBEntityHandle verts[10], polygons[2], polyhedron;
+  
+  for (int i = 0; i < 10; i++) {
+    rval = mbImpl->create_vertex(coords, verts[i]);
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+
+  for (int i = 0; i < 2; i++) {
+    rval = mbImpl->create_element(MBPOLYGON, verts, 5, polygons[i]);
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  rval = mbImpl->create_element(MBPOLYHEDRON, polygons, 2, polyhedron);
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // create the aentities
+  MBRange dum_range;
+  for (int dim = 0; dim < 3; dim++) {
+    dum_range.clear();
+    rval = mbImpl->get_adjacencies(&polyhedron, 1, dim, true, dum_range);
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+    // delete the polyhedron
+  rval = mbImpl->delete_entities(&polyhedron, 1);
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+    // check adjacencies
+  return moab.check_adjacencies();
+}
+
 MBErrorCode mb_memory_use_test( MBInterface* ) 
 {
   MBCore mb;
@@ -5781,8 +5824,9 @@
   RUN_TEST( mb_split_test );
   RUN_TEST( mb_range_seq_intersect_test );
   RUN_TEST( mb_proc_subset_test );
+  RUN_TEST( mb_poly_adjacency_test );
+  RUN_TEST( mb_memory_use_test );
   RUN_TEST( mb_merge_test );
-  RUN_TEST( mb_memory_use_test );
   if (stress_test) RUN_TEST( mb_stress_test );
 
     // summary

Modified: MOAB/trunk/Makefile.am
===================================================================
--- MOAB/trunk/Makefile.am	2007-11-15 21:12:59 UTC (rev 1396)
+++ MOAB/trunk/Makefile.am	2007-11-15 22:52:52 UTC (rev 1397)
@@ -143,6 +143,8 @@
   MeshSetSequence.cpp \
   MeshSetSequence.hpp \
   MeshTopoUtil.cpp \
+  PolyElementSeq.cpp \
+  PolyElementSeq.hpp \
   ReadGmsh.cpp \
   ReadGmsh.hpp \
   ReadSTL.cpp \

Added: MOAB/trunk/PolyElementSeq.cpp
===================================================================
--- MOAB/trunk/PolyElementSeq.cpp	                        (rev 0)
+++ MOAB/trunk/PolyElementSeq.cpp	2007-11-15 22:52:52 UTC (rev 1397)
@@ -0,0 +1,32 @@
+#include "PolyElementSeq.hpp"
+
+PolyElementSeq::~PolyElementSeq() {}
+  
+EntitySequence* PolyElementSeq::split( MBEntityHandle here )
+  { return new PolyElementSeq( *this, here ); }
+                       
+
+MBErrorCode
+PolyElementSeq::get_connectivity( MBEntityHandle handle,
+                                  std::vector<MBEntityHandle>& connect,
+                                  bool ) const
+{
+  MBEntityHandle const* conn = get_array() + nodes_per_element() * (handle - start_handle());
+  int len = nodes_per_element();
+  connect.reserve( connect.size() + len );
+  std::copy( conn, conn+len, std::back_inserter( connect ) );
+  return MB_SUCCESS;
+}
+
+
+MBErrorCode
+PolyElementSeq::get_connectivity( MBEntityHandle handle,
+                                  MBEntityHandle const*& conn_ptr,
+                                  int& len,
+                                  bool,
+                                  std::vector<MBEntityHandle>* ) const
+{
+  conn_ptr = get_array() + nodes_per_element() * (handle - start_handle());
+  len = nodes_per_element();
+  return MB_SUCCESS;
+}

Added: MOAB/trunk/PolyElementSeq.hpp
===================================================================
--- MOAB/trunk/PolyElementSeq.hpp	                        (rev 0)
+++ MOAB/trunk/PolyElementSeq.hpp	2007-11-15 22:52:52 UTC (rev 1397)
@@ -0,0 +1,46 @@
+#ifndef POLY_ELEMENT_SEQ_HPP
+#define POLY_ELEMENT_SEQ_HPP
+
+#include "UnstructuredElemSeq.hpp"
+
+
+class PolyElementSeq : public UnstructuredElemSeq
+{
+public:
+  PolyElementSeq( MBEntityHandle start_handle, 
+                  MBEntityID entity_count, 
+                  unsigned nodes_per_entity,
+                  SequenceData* data )
+    : UnstructuredElemSeq( start_handle, entity_count, nodes_per_entity, data )
+    {}
+
+  PolyElementSeq( MBEntityHandle start_handle, 
+                  MBEntityID entity_count, 
+                  unsigned nodes_per_entity,
+                  MBEntityID sequence_data_size)
+    : UnstructuredElemSeq( start_handle, entity_count, nodes_per_entity, sequence_data_size )
+    {}
+
+  virtual ~PolyElementSeq();
+  
+  virtual EntitySequence* split( MBEntityHandle here );
+                       
+  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
+                                        std::vector<MBEntityHandle>& connect,
+                                        bool topological = false ) const;
+  
+  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
+                                        MBEntityHandle const*& connect,
+                                        int &connect_length,
+                                        bool topological = false,
+                                        std::vector<MBEntityHandle>* storage = 0
+                                       ) const;
+
+protected:
+
+  PolyElementSeq( PolyElementSeq& split_from, MBEntityHandle here )
+    : UnstructuredElemSeq( split_from, here )
+   {}
+};
+
+#endif

Modified: MOAB/trunk/SequenceManager.cpp
===================================================================
--- MOAB/trunk/SequenceManager.cpp	2007-11-15 21:12:59 UTC (rev 1396)
+++ MOAB/trunk/SequenceManager.cpp	2007-11-15 22:52:52 UTC (rev 1397)
@@ -5,6 +5,7 @@
 #include "MeshSetSequence.hpp"
 #include "StructuredElementSeq.hpp"
 #include "HomXform.hpp"
+#include "PolyElementSeq.hpp"
 
 #include <assert.h>
 
@@ -157,11 +158,19 @@
     if (!handle) 
       return MB_FAILURE;
     
-    if (seq_data) 
-      eseq = new UnstructuredElemSeq( handle, 1, conn_len, seq_data );
-    else
-      eseq = new UnstructuredElemSeq( handle, 1, conn_len, size );
-      
+    if (MBPOLYGON == type || MBPOLYHEDRON == type) {
+      if (seq_data) 
+        eseq = new PolyElementSeq( handle, 1, conn_len, seq_data );
+      else
+        eseq = new PolyElementSeq( handle, 1, conn_len, size );
+    }
+    else {
+      if (seq_data) 
+        eseq = new UnstructuredElemSeq( handle, 1, conn_len, seq_data );
+      else
+        eseq = new UnstructuredElemSeq( handle, 1, conn_len, size );
+    }
+    
     MBErrorCode rval = typeData[type].insert_sequence( eseq );
     if (MB_SUCCESS != rval) {
       SequenceData* vdata = eseq->data();
@@ -372,6 +381,18 @@
     
     break;
   
+  case MBPOLYGON:
+  case MBPOLYHEDRON:
+    if (size == 0)
+      return MB_INDEX_OUT_OF_RANGE;
+
+    if (data)
+      sequence = new PolyElementSeq( handle, count, size, data );
+    else 
+      sequence = new PolyElementSeq( handle, count, size, count );
+
+    break;
+  
   default:
     if (size == 0)
       return MB_INDEX_OUT_OF_RANGE;

Modified: MOAB/trunk/UnstructuredElemSeq.hpp
===================================================================
--- MOAB/trunk/UnstructuredElemSeq.hpp	2007-11-15 21:12:59 UTC (rev 1396)
+++ MOAB/trunk/UnstructuredElemSeq.hpp	2007-11-15 22:52:52 UTC (rev 1397)
@@ -19,24 +19,24 @@
                        unsigned nodes_per_entity,
                        MBEntityID sequence_data_size);
 
-  ~UnstructuredElemSeq();
+  virtual ~UnstructuredElemSeq();
 
   int values_per_entity() const;
   
-  EntitySequence* split( MBEntityHandle here );
+  virtual EntitySequence* split( MBEntityHandle here );
   
   SequenceData* create_data_subset( MBEntityHandle start, MBEntityHandle end ) const;
                        
-  MBErrorCode get_connectivity( MBEntityHandle handle,
-                                std::vector<MBEntityHandle>& connect,
-                                bool topological = false ) const;
+  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
+                                        std::vector<MBEntityHandle>& connect,
+                                        bool topological = false ) const;
   
-  MBErrorCode get_connectivity( MBEntityHandle handle,
-                                MBEntityHandle const*& connect,
-                                int &connect_length,
-                                bool topological = false,
-                                std::vector<MBEntityHandle>* storage = 0
-                               ) const;
+  virtual MBErrorCode get_connectivity( MBEntityHandle handle,
+                                        MBEntityHandle const*& connect,
+                                        int &connect_length,
+                                        bool topological = false,
+                                        std::vector<MBEntityHandle>* storage = 0
+                                       ) const;
 
   MBErrorCode set_connectivity( MBEntityHandle handle,
                                 MBEntityHandle const* connect,




More information about the moab-dev mailing list