[MOAB-dev] r2607 - MOAB/trunk/tools/iMesh

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Fri Jan 30 12:39:09 CST 2009


Author: kraftche
Date: 2009-01-30 12:39:09 -0600 (Fri, 30 Jan 2009)
New Revision: 2607

Modified:
   MOAB/trunk/tools/iMesh/iMeshP.h
   MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp
Log:
update iMeshP.h with changes analogous to iMesh.h, and some other minor changes

Modified: MOAB/trunk/tools/iMesh/iMeshP.h
===================================================================
--- MOAB/trunk/tools/iMesh/iMeshP.h	2009-01-30 18:38:37 UTC (rev 2606)
+++ MOAB/trunk/tools/iMesh/iMeshP.h	2009-01-30 18:39:09 UTC (rev 2607)
@@ -1016,128 +1016,73 @@
             int *num_topo, 
             int *err);
 
-
-
-
-/** \brief Return coordinate data for vertices that are in both a given part and a given entity set.
+/**\brief Get indexed representation of mesh or subset of mesh
  *
- *  Given a part handle and an entity set handle, 
- *  return the coordinate data for all vertices that are in BOTH 
- *  the given part AND the given entity set.  
- *  This function is similar to iMesh_getAllVtxCoords, but it also restricts
- *  the returned data with respect to its existence in the given part.
- *  If the input entity set is 
- *  not the root set, coordinates are returned for vertices either in the set 
- *  or contained by entities in the set. If storage order is
- *  a value other than iBase_UNDETERMINED, coordinates are returned with
- *  that storage order; otherwise the storage order is the implementation's
- *  native order.  On return, storage order contains
- *  order of the returned coordinates.
+ * Given part handle and an entity set and optionally a type or topology, 
+ * for all entities that are in BOTH the part and the entity set, return:
+ * - The entities in the part and set of the specified type or topology
+ * - The entities adjacent to those entities with a specified
+ *    type, as a list of unique handles.
+ * - For each entity in the first list, the adjacent entities,
+ *    specified as indices into the second list.
  *
  *  COMMUNICATION:  None.
  *
- *  \param  instance                (In)     Mesh instance containing the 
- *                                           partition.
- *  \param  partition               (In)     The partition being queried.
- *  \param  part                    (In)     The part being queried.
- *  \param  entity_set              (In)     Entity set handle for the 
- *                                           entity set being queried; 
- *                                           may be the root set.
- *  \param  coordinates             (In/Out) Array of coordinates for 
- *                                           vertices in both the part
- *                                           and entity set.
- *  \param  coordinates_allocated   (In/Out) Allocated size of coordinates 
- *                                           array.
- *  \param  coordinates_size        (Out)    Occupied size of coordinates 
- *                                           array.
- *  \param  in_entity_set           (In/Out) Array of flags returned if 
- *                                           non-root entity set was input; 
- *                                           (*in_entity_set)[i]=1 indicates 
- *                                           vertex i was in the entity set.
- *  \param  in_entity_set_allocated (In/Out) Allocated size of in_entity_set.
- *  \param  in_entity_set_size      (Out)    Occupied size of in_entity_set.
- *  \param  storage_order           (In/Out) Storage order requested/returned.
- *  \param  err                     (Out)    Error code.
+ *\param  instance                (In)     Mesh instance containing the 
+ *                                         partition.
+ *\param  partition               (In)     The partition being queried.
+ *\param  part                    (In)     The part being queried.
+ *\param entity_set_handle        (In)     The set being queried
+ *\param entity_type_requestor    (In)     If not iBase_ALL_TYPES, act only 
+ *                                         on the subset of entities with
+ *                                         the specified type.
+ *\param entity_topology_requestor (In)    If not iMesh_ALL_TOPOLOGIES, act 
+ *                                         only on the subset of entities with
+ *                                         the specified topology.
+ *\param entity_type_requested    (In)     The type of the adjacent entities
+ *                                         to return.
+ *\param entity_handles           (In/Out) The handles of the (non-strict) 
+ *                                         subset of the union of the part
+ *                                         and entity set, and the optional 
+ *                                         type and topology filtering 
+ *                                         arguments.
+ *\param adj_entity_handles       (In/Out) The union of the entities of type 
+ *                                         'requested_entity_type' adjacent 
+ *                                         to each entity in 'entity_handles'.
+ *\param adj_entity_indices       (In/Out) For each entity in 'entity_handles', 
+ *                                         the adjacent entities of type
+ *                                         'entity_type_requested', specified as 
+ *                                         indices into 'adj_entity_handles'.  
+ *                                         The indices are concatenated into a 
+ *                                         single array in the order of the 
+ *                                         entity handles in 'entity_handles'.
+ *\param offset                   (In/Out) For each entity in the 
+ *                                         corresponding position in 
+ *                                         'entity_handles', the position
+ *                                         in 'adj_entity_indices' at which
+ *                                         values for that entity are stored.
  */
-void iMeshP_getAllVtxCoords(
-            iMesh_Instance instance,
-            const iMeshP_PartitionHandle partition,
-            const iMeshP_PartHandle part,
-            const iBase_EntitySetHandle entity_set,
-            double **coordinates,
-            int *coordinates_allocated,
-            int *coordinates_size,
-            int **in_entity_set,
-            int *in_entity_set_allocated,
-            int *in_entity_set_size,
-            int *storage_order, 
-            int *err);
+void iMeshP_getAdjEntIndices(iMesh_Instance instance,
+                             iMeshP_PartitionHandle partition,
+                             iMeshP_PartHandle part,
+                             iBase_EntitySetHandle entity_set_handle,
+                             int entity_type_requestor,
+                             int entity_topology_requestor,
+                             int entity_type_requested,
+                             iBase_EntityHandle** entity_handles,
+                             int* entity_handles_allocated,
+                             int* entity_handles_size,
+                             iBase_EntityHandle** adj_entity_handles,
+                             int* adj_entity_handles_allocated,
+                             int* adj_entity_handles_size,
+                             int** adj_entity_indices,
+                             int* adj_entity_indices_allocated,
+                             int* adj_entity_indices_size,
+                             int** offset,
+                             int* offset_allocated,
+                             int* offset_size,
+                             int *err);
 
-
-
-
-/**\brief  Get adjacent entities as connectivity lists
- *
- *  For a specified part handle, entity set handle, and entity type 
- *  and/or entity topology,
- *  return the connectivity of adjacent entities of specified dimension.  
- *  This function is similar to iMesh_getVtxCoordIndex, but it also restricts
- *  the returned data with respect to its existence in the given part.
- *  Connectivity is expressed as an index into an array of vertices returned
- *  by iMeshP_getEntities.  Entry offset[i] is the index of the first
- *  vertex of the first entity adjacent to entity i in the entity set
- *  or the mesh.  The topology of entities whose connectivity is returned
- *  is given in the entity_topologies array.
- *
- *  COMMUNICATION:  None.
- *
- *  \param  instance                    (In)     Mesh instance containing the 
- *                                               partition.
- *  \param  partition                   (In)     The partition being queried.
- *  \param  part                        (In)     The part being queried.
- *  \param  entity_set                  (In)     Entity set handle for the 
- *                                               entity set being queried; 
- *                                               may be the root set.
- *  \param  entity_type                 (In)     Entity type of the 
- *                                               entities;
- *                                               may be iBase_ALL_TYPES.
- *  \param  entity_topology             (In)     Entity topology of the 
- *                                               entities;
- *                                               may be iMesh_ALL_TOPOLOGIES.
- *  \param  entity_adjacency_type       (In)     Adjacency type
- *  \param  offset                      (In/Out) Array of offsets returned.
- *  \param  offset_allocated            (In/Out) Allocated size of offset.
- *  \param  offset_size                 (Out)    Occupied size of offset.
- *  \param  index                       (In/Out) Array of indices returned.
- *  \param  index_allocated             (In/Out) Allocated size of index.
- *  \param  index_size                  (Out)    Occupied size of index.
- *  \param  entity_topologies           (In/Out) Array of entity topologies 
- *                                               returned.
- *  \param  entity_topologies_allocated (In/Out) Allocated size of 
- *                                               entity_topologies.
- *  \param  entity_topologies_size      (Out)    Occupied size of 
- *                                               entity_topologies.
- *  \param  err                         (Out)    Error code.
- */
-void iMeshP_getVtxCoordIndex(
-            iMesh_Instance instance,
-            const iMeshP_PartitionHandle partition,
-            const iMeshP_PartHandle part,
-            const iBase_EntitySetHandle entity_set,
-            int entity_type,
-            int entity_topology,
-            int entity_adjacency_type,
-            int **offset,
-            int *offset_allocated,
-            int *offset_size,
-            int **index,
-            int *index_allocated,
-            int *index_size,
-            int **entity_topologies,
-            int *entity_topologies_allocated,
-            int *entity_topologies_size, 
-            int *err);
-
 /** \brief Return entities in a both given part and entity set.
  *
  *  Given an entity set handle 
@@ -1224,16 +1169,6 @@
  *  \param  offset                       (In/Out) Array of offsets returned.
  *  \param  offset_allocated             (In/Out) Allocated size of offset.
  *  \param  offset_size                  (Out)    Occupied size of offset.
- *  \param  in_entity_set                (In/Out) Array of flags returned if 
- *                                                non-root entity set was input;
- *                                                (*in_entity_set)[i]=1 
- *                                                indicates
- *                                                (*adj_entities)[i] 
- *                                                is in the entity set.
- *  \param  in_entity_set_allocated      (In/Out) Allocated size of 
- *                                                in_entity_set.
- *  \param  in_entity_set_size           (Out)    Occupied size of 
- *                                                in_entity_set.
  *  \param  err                          (Out)    Error code.
  */
 void iMeshP_getAdjEntities(
@@ -1250,9 +1185,6 @@
             int **offset,
             int *offset_allocated,
             int *offset_size,
-            int **in_entity_set,
-            int *in_entity_set_allocated,
-            int *in_entity_set_size, 
             int *err);
 
 /** \brief Create an entity iterator for a given part and entity set.  

Modified: MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp
===================================================================
--- MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp	2009-01-30 18:38:37 UTC (rev 2606)
+++ MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp	2009-01-30 18:39:09 UTC (rev 2607)
@@ -831,142 +831,150 @@
   *num_topo = r.size();
 }
 
-void iMeshP_getAllVtxCoords( iMesh_Instance instance,
-                             const iMeshP_PartitionHandle ,
-                             const iMeshP_PartHandle part_handle,
-                             const iBase_EntitySetHandle entity_set_handle,
-                             double** coordinates,
-                             int* coordinates_allocated,
-                             int* coordinates_size,
-                             int** in_entity_set,
-                             int* in_entity_set_allocated,
-                             int* in_entity_set_size,
-                             int* storage_order,
-                             int *err )
+void iMeshP_getAdjEntIndices(iMesh_Instance instance,
+                             iMeshP_PartitionHandle partition,
+                             iMeshP_PartHandle part,
+                             iBase_EntitySetHandle entity_set_handle,
+                             int entity_type_requestor,
+                             int entity_topology_requestor,
+                             int entity_type_requested,
+                             iBase_EntityHandle** entity_handles,
+                             int* entity_handles_allocated,
+                             int* entity_handles_size,
+                             iBase_EntityHandle** adj_entity_handles,
+                             int* adj_entity_handles_allocated,
+                             int* adj_entity_handles_size,
+                             int** adj_entity_indices,
+                             int* adj_entity_indices_allocated,
+                             int* adj_entity_indices_size,
+                             int** offset,
+                             int* offset_allocated,
+                             int* offset_size,
+                             int *err)
 {
-  int dim;
-  MBErrorCode rval = MBI->get_dimension( dim ); CHKERR(rval);
+  const int allocated_entity_handles = (*entity_handles_allocated == 0);
+  const int allocated_indices = (*adj_entity_indices_allocated == 0);
+  const int allocated_offset = (*offset_allocated == 0);
 
-  MBRange r;
-  set_intersection_query( instance, part_handle, entity_set_handle, 
-                          iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, r, err );
-  if (*err != iBase_SUCCESS)
+  // get source entities
+  iMeshP_getEntities( instance, 
+                      partition, part,
+                      entity_set_handle,
+                      entity_type_requestor, 
+                      entity_topology_requestor,
+                      entity_handles,
+                      entity_handles_allocated,
+                      entity_handles_size,
+                      err );
+  if (iBase_SUCCESS != *err)
     return;
-    
-  MBRange v;
-  rval = MBI->get_adjacencies( r, 0, false, v, MBInterface::UNION );
-  CHKERR(rval);
-    
-  const size_t n = v.size();
-  ALLOCATE_ARRAY( coordinates, dim*n );
-  ALLOCATE_ARRAY( in_entity_set, n );
-  std::fill( *in_entity_set, (*in_entity_set)+n, 1 );
 
-  switch (*storage_order) {
-    case iBase_UNDETERMINED:
-      *storage_order = iBase_INTERLEAVED;
-      // NO BREAK -- fall through
-    case iBase_INTERLEAVED:
-      rval = MBI->get_coords( v, *coordinates );
-      break;
-    case iBase_BLOCKED:
-      rval = MBI->get_coords( v,
-                               *coordinates,
-                              (*coordinates)+n,
-                              (*coordinates)+2*n );
-      break;
-    default:
-      RETURN (iBase_INVALID_ARGUMENT);
+  // get adjacencies
+  iBase_EntityHandle* all_adj_handles = 0;
+  int size = 0, alloc = 0;
+  iMesh_getEntArrAdj( instance,
+                      *entity_handles, *entity_handles_size,
+                      entity_type_requested,
+                      &all_adj_handles, &alloc, &size,
+                      offset, offset_allocated, offset_size,
+                      err );
+  if (*err != iBase_SUCCESS) {
+    if (allocated_entity_handles) {
+      free( *entity_handles );
+      *entity_handles = 0;
+      *entity_handles_allocated = 0;
+    }
+    return;
   }
-  
-  CHKERR(rval);
-  RETURN (iBase_SUCCESS);
-}
 
-void iMeshP_getVtxCoordIndex( iMesh_Instance instance,
-                              const iMeshP_PartitionHandle ,
-                              const iMeshP_PartHandle part_handle,
-                              const iBase_EntitySetHandle entity_set_handle,
-                              const int requested_entity_type,
-                              const int requested_entity_topology,
-                              const int entity_adjacency_type,
-                              int** offset,
-                              int* offset_allocated,
-                              int* offset_size,
-                              int** index,
-                              int* index_allocated,
-                              int* index_size,
-                              int** entity_topologies,
-                              int* entity_topologies_allocated,
-                              int* entity_topologies_size,
-                              int *err )
-{
-  MBRange::iterator i;
-  MBRange r;
-  set_intersection_query( instance, part_handle, entity_set_handle, 
-                          iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, r, err );
-  if (*err != iBase_SUCCESS)
+  // allocate or check size of adj_entity_indices
+  *adj_entity_indices_size = size;
+  if (allocated_indices) {
+    *adj_entity_indices = (int*)malloc(sizeof(iBase_EntityHandle)*size);
+    if (!*adj_entity_indices) 
+      *err = iBase_MEMORY_ALLOCATION_FAILED;
+    else
+      *adj_entity_indices_allocated = size;
+  }
+  else if (*adj_entity_indices_allocated < size) {
+    *err = iBase_BAD_ARRAY_DIMENSION;
+  }
+  if (iBase_SUCCESS != *err) {
+    free( all_adj_handles );
+    if (allocated_entity_handles) {
+      free( *entity_handles );
+      *entity_handles = 0;
+      *entity_handles_allocated = 0;
+    }
+    if (allocated_offset) {
+      free( *offset );
+      *offset = 0;
+      *offset_allocated = 0;
+    }
     return;
-    
-  MBRange v;
-  MBErrorCode rval = MBI->get_adjacencies( r, 0, false, v, MBInterface::UNION );
-  CHKERR(rval);
+  }
 
-  r.clear();
-  set_intersection_query( instance, part_handle, entity_set_handle, 
-                          requested_entity_type, requested_entity_topology, 
-                          r, err );
-  if (*err != iBase_SUCCESS)
-    return;
-    
-  std::vector<MBEntityHandle> sorted(v.size());
-  std::copy( v.begin(), v.end(), sorted.begin() );
-  
-  if (!r.all_of_dimension(entity_adjacency_type)) {
-    MBRange r2;
-    rval =  MBI->get_adjacencies( r, entity_adjacency_type, false, r2, MBInterface::UNION );
-    CHKERR(rval);
-    r.swap(r2);
+  // Now create an array of unique sorted handles from all_adj_handles.
+  // We need to create a copy because we still need all_adj_handles.  We
+  // will eventually need to copy the resulting unique list into 
+  // adj_entity_handles, so if adj_entity_handles is already allocated and
+  // of sufficient size, use it rather than allocating another temporary.
+  iBase_EntityHandle* unique_adj = 0;
+  if (*adj_entity_handles_allocated >= size) {
+    unique_adj = *adj_entity_handles;
   }
-  
-    // count size of connectivity data
-  size_t cn = 0;
-  int num;
-  const MBEntityHandle* conn;
-  std::vector<MBEntityHandle>::iterator s;
-  std::vector<MBEntityHandle> store;
-  for (i = r.begin(); i != r.end(); ++i) {
-    rval = MBI->get_connectivity( *i, conn, num, true, &store );
-    CHKERR(rval);
-    cn += num;
+  else {
+    unique_adj = (iBase_EntityHandle*)malloc(sizeof(iBase_EntityHandle) * size);
   }
+  std::copy( all_adj_handles, all_adj_handles+size, unique_adj );
+  std::sort( unique_adj, unique_adj + size );
+  *adj_entity_handles_size = std::unique( unique_adj, unique_adj + size ) - unique_adj;
 
-  const size_t n = r.size();
-  ALLOCATE_ARRAY( offset, n );
-  ALLOCATE_ARRAY( index, cn );
-  ALLOCATE_ARRAY( entity_topologies, n );
-    
-    // populate output arrays
-  int* offset_iterator = *offset;
-  int* index_iterator = *index;
-  int* topo_iterator = *entity_topologies;
-  for (i = r.begin(); i != r.end(); ++i) {
-    *offset_iterator = index_iterator - *index;
-    ++offset_iterator;
-    
-    rval = MBI->get_connectivity( *i, conn, num, true, &store );
-    CHKERR(rval);
-    for (int j = 0; j < num; ++j) {
-      s = std::lower_bound( sorted.begin(), sorted.end(), conn[j] );
-      if (s == sorted.end() || *s != conn[j]) 
-        RETURN(iBase_FAILURE);
-      *index_iterator = s - sorted.begin();
-      ++index_iterator;
+  // If we created a temporary array for unique_adj rather than using
+  // already allocated space in adj_entity_handles, allocate adj_entity_handles
+  // and copy the unique handle list into it
+  if (*adj_entity_handles != unique_adj) {
+    if (!*adj_entity_handles_allocated) {
+      *adj_entity_handles = (iBase_EntityHandle*)malloc(
+                            sizeof(iBase_EntityHandle) * *adj_entity_handles_size);
+      if (!*adj_entity_handles)
+        *err = iBase_MEMORY_ALLOCATION_FAILED;
+      else
+        *adj_entity_handles_allocated = *adj_entity_handles_size;
     }
-    
-    *topo_iterator = tstt_topology_table[ TYPE_FROM_HANDLE(*i) ];
-    ++topo_iterator;
+    else if (*adj_entity_handles_allocated < *adj_entity_handles_size) 
+      *err = iBase_BAD_ARRAY_DIMENSION;
+    if (iBase_SUCCESS != *err) {
+      free( unique_adj );
+      free( all_adj_handles );
+      if (allocated_entity_handles) {
+        free( *entity_handles );
+        *entity_handles = 0;
+        *entity_handles_allocated = 0;
+      }
+      if (allocated_offset) {
+        free( *offset );
+        *offset = 0;
+        *offset_allocated = 0;
+      }
+      if (allocated_indices) {
+        free( *adj_entity_indices );
+        *adj_entity_indices = 0;
+        *adj_entity_indices_allocated = 0;
+      }
+      return;
+    }
+
+    std::copy( unique_adj, unique_adj + *adj_entity_handles_size, *adj_entity_handles );
+    free( unique_adj );
+    unique_adj = *adj_entity_handles;
   }
+
+  // convert from adjacency list to indices into unique_adj
+  for (int i = 0; i < *adj_entity_indices_size; ++i)
+    (*adj_entity_indices)[i] = std::lower_bound( unique_adj, 
+      unique_adj + *adj_entity_handles_size, all_adj_handles[i] ) - unique_adj;
+  free( all_adj_handles );
 }
 
 void iMeshP_getEntities( iMesh_Instance instance,
@@ -1003,9 +1011,6 @@
                             int** offset,
                             int* offset_allocated,
                             int* offset_size,
-                            int** in_entity_set,
-                            int* in_entity_set_allocated,
-                            int* in_entity_set_size,
                             int *err )
 {
   MBErrorCode rval;
@@ -1052,16 +1057,6 @@
       ++arr_pos;
     }
   }
-
-    // get in_entity_set
-  iMesh_isEntArrContained( instance, 
-                           entity_set_handle, 
-                           *adj_entity_handles,
-                           *adj_entity_handles_size,
-                           in_entity_set,
-                           in_entity_set_allocated,
-                           in_entity_set_size,
-                           err );
 }
 
 void iMeshP_initEntIter( iMesh_Instance instance,



More information about the moab-dev mailing list