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

sjackson at cae.wisc.edu sjackson at cae.wisc.edu
Mon Dec 7 13:28:46 CST 2009


Author: sjackson
Date: 2009-12-07 13:28:46 -0600 (Mon, 07 Dec 2009)
New Revision: 3403

Modified:
   MOAB/trunk/tools/dagmc/DagMC.cpp
   MOAB/trunk/tools/dagmc/DagMC.hpp
Log:
Fix CAD-based ray tracing feature within DagMC.

* At runtime, check CGM for data to determine if this feature is 
  available.
* Clean up code that checks for presence of needed CGM functions.



Modified: MOAB/trunk/tools/dagmc/DagMC.cpp
===================================================================
--- MOAB/trunk/tools/dagmc/DagMC.cpp	2009-12-06 06:18:10 UTC (rev 3402)
+++ MOAB/trunk/tools/dagmc/DagMC.cpp	2009-12-07 19:28:46 UTC (rev 3403)
@@ -69,9 +69,27 @@
   instance_ = new DagMC(mb_impl);
 }
 
+void DagMC::set_useCAD( bool use_cad ){
+  useCAD = use_cad;
+  if( useCAD ){
+    if( !have_cgm_geom ){
+      std::cerr << "Warning: CAD-based ray tracing not avaiable, because CGM has no data." << std::endl;
+      std::cerr << "         your input file was probably not a CAD format." << std::endl;
+      useCAD = false;
+    }
 
+#ifndef HAVE_CGM_FIRE_RAY
+    {
+      std::cerr << "Warning: use_cad = 1 not supported with this build of CGM/DagMC." << std:: endl;
+      std::cerr << "         Required ray-fire query not available. (Cubit-based CGM?)" <<  std::endl;
+      useCAD = false;
+    }
+#endif
+  }
+}
+
 DagMC::DagMC(MBInterface *mb_impl) 
-  : mbImpl(mb_impl), obbTree(mb_impl), is_geom(false)
+  : mbImpl(mb_impl), obbTree(mb_impl), have_cgm_geom(false)
 {
     // This is the correct place to uniquely define default values for the dagmc settings
   options[0] = Option( "source_cell",        "source cell ID, or zero if unknown", "0" );
@@ -158,21 +176,14 @@
                                      &len);
   assert( MB_SUCCESS == rval );
 
-#ifdef CGM
+
+  // if useCAD is true at this point, then we know we can call CGM's ray casting function.
   if (useCAD) {
-#ifndef HAVE_CGM_FIRE_RAY
-    std::cout << "use_cad = 1 not supported with this build of CGM/DagMC."
-              << std::endl
-              << "Required ray-fire query not available. (Cubit-based CGM?)" 
-              << std::endl;
-    return MB_NOT_IMPLEMENTED;
-#else    
     rval = CAD_ray_intersect(point, dir, huge_val,
                              distances, surfaces, len);
     if (MB_SUCCESS != rval) return rval;
-#endif
   }
-#endif
+
   
     // Find smallest intersection
   if (distances.empty()) {
@@ -311,15 +322,7 @@
 
   useDistLimit = !!atoi( options[2].value.c_str() );
 
-  useCAD = !!atoi( options[3].value.c_str() );
-#ifndef HAVE_CGM_FIRE_RAY
-  if (useCAD) {
-    std::cout << "Warning: use_cad = 1 not supported with this build of "
-              << "CGM/DagMC;" << std:: endl
-              << "Required ray-fire query not available. (Cubit-based CGM?)" 
-              << std::endl;
-  }
-#endif  
+  set_useCAD( !!atoi( options[3].value.c_str() ) );
 
   facetingTolerance = strtod( options[4].value.c_str(), 0 );
   if (facetingTolerance <= 0) {
@@ -371,16 +374,9 @@
 
   std::cout << "Turned " << (useDistLimit?"ON":"OFF") << " distance limit." << std::endl;
 
-  useCAD = !!(use_cad);
+  set_useCAD( use_cad );
+
   std::cout << "Turned " << (useCAD?"ON":"OFF") << " ray firing on full CAD model." << std::endl;
-#ifndef HAVE_CGM_FIRE_RAY
-  if (useCAD) {
-    std::cout << "Warning: use_cad = 1 not supported with this build of "
-              << "CGM/DagMC;" << std:: endl
-              << "Required ray-fire query not available. (Cubit-based CGM?)" 
-              << std::endl;
-  }
-#endif  
 
 
 }
@@ -888,6 +884,11 @@
 {
   MBErrorCode rval;
   
+#ifdef CGM
+  // cgm must be initialized so we can check it for CAD data after the load
+  InitCGMA::initialize_cgma();
+#endif
+
     // override default value of facetingTolerance with passed value
   if (facet_tolerance > 0 )
     facetingTolerance = facet_tolerance;
@@ -899,7 +900,7 @@
   // what if we are using default faceting tolerance???
   char options[120] = "CGM_ATTRIBS=yes;FACET_DISTANCE_TOLERANCE=";
   strcat(options,facetTolStr);
-
+  
   rval = MBI->load_file(cfile, 0, options, NULL, 0, 0);
   
   if( MB_UNHANDLED_OPTION == rval ){
@@ -911,14 +912,17 @@
     }
   }
   else if (MB_SUCCESS != rval) {
-    std::cerr << "Couldn't read file " << cfile << std::endl;
+    std::cerr << "DagMC Couldn't read file " << cfile << std::endl;
     return rval;
   }
-  
-  // How do we know what type of file we read for downstream issues:
-  // * useCad
-  // * is_geom in build_indices
 
+#ifdef CGM  
+  // check to see if CGM has data; if so, assume it corresponds to the data we loaded in.
+  if( GeometryQueryTool::instance()->num_ref_volumes() > 0 ){
+    std::cerr << "Setting have_cgm_geom = true" << std::endl;
+    have_cgm_geom = true;
+  }
+#endif
 
   return MB_SUCCESS;
 
@@ -1564,7 +1568,10 @@
 
  
 #ifdef CGM
-  if (is_geom) {
+  if ( have_cgm_geom ) {
+    // TODO: this block should only execute if the user has explicitly requested useCAD for ray firing.
+    // however, this function curently executes before we know if useCAD will be specified, so do it every time.
+
     geomEntities.resize(rootSets.size());
       // get geometry entities by id and cache in this vector
     std::vector<int> ids;

Modified: MOAB/trunk/tools/dagmc/DagMC.hpp
===================================================================
--- MOAB/trunk/tools/dagmc/DagMC.hpp	2009-12-06 06:18:10 UTC (rev 3402)
+++ MOAB/trunk/tools/dagmc/DagMC.hpp	2009-12-07 19:28:46 UTC (rev 3403)
@@ -206,6 +206,9 @@
   MBErrorCode build_obbs(MBRange &surfs, MBRange &vols);
   MBErrorCode build_obb_impl_compl(MBRange &surfs);
   
+  // attempt to set useCAD, first checking for availability
+  void set_useCAD( bool use_cad ); 
+
   class Option {
   public:
     Option(){}
@@ -241,8 +244,8 @@
   double facetingTolerance;
   int sourceCell;
   bool useDistLimit;
-  bool useCAD;
-  bool is_geom;
+  bool useCAD;         /// true if user requested CAD-based ray firing
+  bool have_cgm_geom;  /// true if CGM contains problem geometry; required for CAD-based ray firing.
 
   double distanceLimit;
 



More information about the moab-dev mailing list