[MOAB-dev] r1292 - MOAB/trunk/tools/dagmc

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Tue Sep 25 18:48:35 CDT 2007


Author: kraftche
Date: 2007-09-25 18:48:35 -0500 (Tue, 25 Sep 2007)
New Revision: 1292

Modified:
   MOAB/trunk/tools/dagmc/DagMC.cpp
   MOAB/trunk/tools/dagmc/DagMC.hpp
Log:
o Remove unnecessary 'static' qualifier.
o Move some static function variables to class member variables
o Provide single-surface version of DagMC::surface_sense so that
  we don't do unnecessary array allocations when we only need the
  value for one surface (all but one of the callers of the function.)
  


Modified: MOAB/trunk/tools/dagmc/DagMC.cpp
===================================================================
--- MOAB/trunk/tools/dagmc/DagMC.cpp	2007-09-25 23:32:39 UTC (rev 1291)
+++ MOAB/trunk/tools/dagmc/DagMC.cpp	2007-09-25 23:48:35 UTC (rev 1292)
@@ -55,6 +55,10 @@
   geomTag = get_tag( GEOM_DIMENSION_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER );
 
   obbTag = get_tag( MB_OBB_TREE_TAG_NAME, sizeof(MBEntityHandle), MB_TAG_DENSE, MB_TYPE_HANDLE );
+  
+    // get sense of surfaces wrt volumes
+  senseTag = get_tag( "GEOM_SENSE_2", 2*sizeof(MBEntityHandle), MB_TAG_DENSE, MB_TYPE_HANDLE );
+
 }
 
 MBErrorCode DagMC::ray_fire(const MBEntityHandle vol, const MBEntityHandle last_surf_hit, 
@@ -77,8 +81,8 @@
   MBErrorCode rval;
     // delcare some stuff static so we don't need to re-created
     // it for every call
-  static std::vector<double> distances;
-  static std::vector<MBEntityHandle> surfaces;
+  std::vector<double> &distances = distList;
+  std::vector<MBEntityHandle> &surfaces = surfList;
   
   
     // do ray fire
@@ -263,8 +267,8 @@
     return rval;
   
     // Allocate space to store vertices
-  static MBCartVect coords_static[4];
-  static std::vector<MBCartVect> coords_dynamic;
+  MBCartVect coords_static[4];
+  std::vector<MBCartVect> coords_dynamic;
   MBCartVect* coords = coords_static;
   if ((unsigned)len > (sizeof(coords_static)/sizeof(coords_static[0]))) {
     coords_dynamic.resize(len);
@@ -393,7 +397,7 @@
   }
   
     // Get triangles at closest point
-  static std::vector<MBEntityHandle> tris, surfs;
+  std::vector<MBEntityHandle> &tris = triList, &surfs = surfList;
   tris.clear();
   surfs.clear();
   rval = obbTree.sphere_intersect_triangles( closest.array(), epsilon, root, tris, &surfs );
@@ -410,7 +414,7 @@
     rval = moab_instance()->get_coords( conn, len, coords[0].array() );
     if (MB_SUCCESS != rval) return rval;
     
-    rval = surface_sense( volume, 1, &surfs.front(), &sense );
+    rval = surface_sense( volume, surfs.front(), sense );
     if (MB_SUCCESS != rval) return rval;
 
       // get triangle normal
@@ -441,7 +445,7 @@
     rval = moab_instance()->get_coords( conn, len, coords[0].array() );
     if (MB_SUCCESS != rval) return rval;
     
-    rval = surface_sense( volume, 1, &surfs.front(), &sense );
+    rval = surface_sense( volume, surfs.front(), sense );
     if (MB_SUCCESS != rval) return rval;
 
       // get triangle normal
@@ -621,12 +625,8 @@
                            const MBEntityHandle* surfaces,
                            int* senses_out )
 {
-  
-    // get sense of surfaces wrt volumes
-  static const MBTag tag = get_tag( "GEOM_SENSE_2", 2*sizeof(MBEntityHandle), MB_TAG_DENSE, MB_TYPE_HANDLE );
-
   std::vector<MBEntityHandle> surf_volumes( 2*num_surfaces );
-  MBErrorCode rval = moab_instance()->tag_get_data( tag, surfaces, num_surfaces, &surf_volumes[0] );
+  MBErrorCode rval = moab_instance()->tag_get_data( sense_tag(), surfaces, num_surfaces, &surf_volumes[0] );
   if (MB_SUCCESS != rval)  return rval;
   
   const MBEntityHandle* end = surfaces + num_surfaces;
@@ -648,6 +648,26 @@
   return MB_SUCCESS;
 }
 
+// get sense of surface(s) wrt volume
+MBErrorCode DagMC::surface_sense( MBEntityHandle volume, 
+                                  MBEntityHandle surface,
+                                  int& sense_out )
+{
+    // get sense of surfaces wrt volumes
+  MBEntityHandle surf_volumes[2];
+  MBErrorCode rval = moab_instance()->tag_get_data( sense_tag(), &surface, 1, surf_volumes );
+  if (MB_SUCCESS != rval)  return rval;
+  
+  if (surf_volumes[0] == volume)
+    sense_out = (surf_volumes[1] != volume); // zero if both, otherwise 1
+  else if (surf_volumes[1] == volume) 
+    sense_out = -1;
+  else
+    return MB_ENTITY_NOT_FOUND;
+  
+  return MB_SUCCESS;
+}
+
 MBErrorCode DagMC::load_file_and_init(const char* cfile,
                                        const int clen,
                                        const char* ffile,
@@ -1193,7 +1213,7 @@
   MBEntityHandle root = rootSets[surf - setOffset];
   
   const double in_pt[] = { xxx, yyy, zzz };
-  static std::vector<MBEntityHandle> facets;
+  std::vector<MBEntityHandle> &facets = triList;
   facets.clear();
   MBErrorCode rval = obbTree.closest_to_location( in_pt, root, tolerance(), facets );
   assert(MB_SUCCESS == rval);
@@ -1411,7 +1431,7 @@
         // skip any surfaces that are non-manifold in the volume
         // because point containment code will get confused by them
       int sense;
-      rval = surface_sense( *i, 1, &*j, &sense );
+      rval = surface_sense( *i, *j, sense );
       if (MB_SUCCESS != rval) {
         std::cerr << "Surface/Volume sense data missing." << std::endl;
         return rval;

Modified: MOAB/trunk/tools/dagmc/DagMC.hpp
===================================================================
--- MOAB/trunk/tools/dagmc/DagMC.hpp	2007-09-25 23:32:39 UTC (rev 1291)
+++ MOAB/trunk/tools/dagmc/DagMC.hpp	2007-09-25 23:48:35 UTC (rev 1292)
@@ -62,6 +62,10 @@
                              const MBEntityHandle* surfaces,
                              int* senses_out );
 
+    // Get the sense of surfaces wrt a volume.  Sense values are:
+    // {-1 -> reversed, 0 -> both, 1 -> forward}
+  MBErrorCode surface_sense( MBEntityHandle volume, MBEntityHandle surface, int& sense_out );
+
     // load mesh and initialize
   MBErrorCode load_file_and_init(const char* cfile,
                                  const int clen,
@@ -97,6 +101,8 @@
   MBTag id_tag() {return idTag;}
 
   MBTag name_tag() {return nameTag;}
+  
+  MBTag sense_tag() { return senseTag; }
 
   double distance_limit() {return distanceLimit;}
   void distance_limit(double this_limit) {distanceLimit = this_limit;}
@@ -164,7 +170,7 @@
   MBInterface *mbImpl;
 
   MBOrientedBoxTreeTool obbTree;
-  MBTag obbTag, geomTag, idTag, nameTag;
+  MBTag obbTag, geomTag, idTag, nameTag, senseTag;
   
   Option options[4];
 
@@ -201,6 +207,10 @@
   DagMC(MBInterface *mb_impl);
   
   static DagMC *instance_;
+  
+    // temporary storage so functions don't have to reallocate vectors
+  std::vector<MBEntityHandle> triList, surfList;
+  std::vector<double> distList;
 };
 
 inline char *DagMC::get_spec_reflect() 




More information about the moab-dev mailing list