[MOAB-dev] r2650 - in MOAB/trunk: . tools/dagmc

janehu at mcs.anl.gov janehu at mcs.anl.gov
Mon Feb 23 11:10:54 CST 2009


Author: janehu
Date: 2009-02-23 11:10:54 -0600 (Mon, 23 Feb 2009)
New Revision: 2650

Added:
   MOAB/trunk/tools/dagmc/4Paul_pin_only05m_idmaps.cub
   MOAB/trunk/tools/dagmc/cub2h5m.cc
   MOAB/trunk/tools/dagmc/pin_only05m_idmps-out.e
Modified:
   MOAB/trunk/ReadNCDF.cpp
   MOAB/trunk/ReadNCDF.hpp
   MOAB/trunk/tools/dagmc/Makefile.am
Log:
Added test file cub2h5m.cc file as an interface to read in original data from a cub file, then use an exodus file to update the nodes' coordinates, and finally export a h5m file.

Modified: MOAB/trunk/ReadNCDF.cpp
===================================================================
--- MOAB/trunk/ReadNCDF.cpp	2009-02-19 19:39:22 UTC (rev 2649)
+++ MOAB/trunk/ReadNCDF.cpp	2009-02-23 17:10:54 UTC (rev 2650)
@@ -1976,7 +1976,7 @@
       return MB_TYPE_OUT_OF_RANGE;
   }
 
-  //2. check for the operations, currently support sum.
+  //2. check for the operations, currently support set.
   const char* op;
   if(tokens.size() > 2 && !tokens[2].empty())
     op = tokens[2].c_str();

Modified: MOAB/trunk/ReadNCDF.hpp
===================================================================
--- MOAB/trunk/ReadNCDF.hpp	2009-02-19 19:39:22 UTC (rev 2649)
+++ MOAB/trunk/ReadNCDF.hpp	2009-02-23 17:10:54 UTC (rev 2650)
@@ -31,7 +31,7 @@
 #define READNCDF_HPP
 
 #ifndef IS_BUILDING_MB
-#error "ReadNCDF.hpp isn't supposed to be included into an application"
+//#error "ReadNCDF.hpp isn't supposed to be included into an application"
 #endif
 
 #include <vector>

Added: MOAB/trunk/tools/dagmc/4Paul_pin_only05m_idmaps.cub
===================================================================
(Binary files differ)


Property changes on: MOAB/trunk/tools/dagmc/4Paul_pin_only05m_idmaps.cub
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: MOAB/trunk/tools/dagmc/Makefile.am
===================================================================
--- MOAB/trunk/tools/dagmc/Makefile.am	2009-02-19 19:39:22 UTC (rev 2649)
+++ MOAB/trunk/tools/dagmc/Makefile.am	2009-02-23 17:10:54 UTC (rev 2650)
@@ -33,11 +33,14 @@
 cfgdir = $(libdir)
 cfg_DATA = dagmc.make
 
-TESTS = test_geom
+TESTS = test_geom cub2h5m
 check_PROGRAMS = $(TESTS) pt_vol_test
 test_geom_SOURCES = test_geom.cc
+cub2h5m_SOURCES = cub2h5m.cc
 test_geom_LDADD = libdagmc.la $(top_builddir)/libMOAB.la $(CGM_LTFLAGS)  $(CGM_LIBS_LINK)
+cub2h5m_LDADD = libdagmc.la $(top_builddir)/libMOAB.la $(CGM_LTFLAGS) $(CGM_LIBS_LINK)
 
 pt_vol_test_SOURCES = pt_vol_test.cc
 pt_vol_test_LDADD = libdagmc.la $(top_builddir)/libMOAB.la $(CGM_LTFLAGS)  $(CGM_LIBS_LINK)
 
+

Added: MOAB/trunk/tools/dagmc/cub2h5m.cc
===================================================================
--- MOAB/trunk/tools/dagmc/cub2h5m.cc	                        (rev 0)
+++ MOAB/trunk/tools/dagmc/cub2h5m.cc	2009-02-23 17:10:54 UTC (rev 2650)
@@ -0,0 +1,257 @@
+#include "GeometryQueryTool.hpp"
+#include "InitCGMA.hpp"
+#include "CGMApp.hpp"
+#include "MBCore.hpp"
+#include "cgm2moab.hpp"
+#include "cubfile.h"
+#include "Tqdcfr.hpp"
+#include "FileOptions.hpp"
+#include "ReadNCDF.hpp"
+
+#define GF_CUBIT_FILE_TYPE    "CUBIT"
+#define GF_STEP_FILE_TYPE     "STEP"
+#define GF_IGES_FILE_TYPE     "IGES"
+#define GF_ACIS_TXT_FILE_TYPE "ACIS_SAT"
+#define GF_ACIS_BIN_FILE_TYPE "ACIS_SAB"
+#define GF_OCC_BREP_FILE_TYPE "OCC"
+
+/* Get the type of a file.
+   Return value is one of the above constants
+ */
+const char* get_geom_file_type( const char* filename );
+const char* get_geom_fptr_type( FILE* file );
+
+int is_cubit_file( FILE* file );
+int is_step_file( FILE* file );
+int is_iges_file( FILE* file );
+int is_acis_txt_file( FILE* file );
+int is_acis_bin_file( FILE* file );
+int is_occ_brep_file( FILE* file );
+
+void usage(char *name);
+void print_usage(char *name);
+void help(char *name);
+
+double DEFAULT_DISTANCE = 0.001;
+double DEFAULT_LEN = 0.0;
+int DEFAULT_NORM = 5;
+
+int main( int argc, char* argv[] )
+{
+  char *name = argv[0];
+  const char *file_type = NULL;
+  
+  const char* input_name = 0;
+  const char* output_name = 0;
+
+  double dist_tol = 0.001, len_tol = 0.0;
+  int norm_tol = 5;
+  bool actuate_attribs = true;
+  
+    // Process CL args
+  bool process_options = true;
+  for (int i = 1; i < argc; ++i) {
+    if (!process_options || argv[i][0] != '-') {
+      if (output_name) {
+        std::cerr << "Unexpected argument: " << argv[i] << std::endl;
+        usage(argv[0]);
+      }
+      else if (input_name)
+        output_name = argv[i];
+      else 
+        input_name = argv[i];
+      continue;
+    }
+  }   
+    // Initialize CGM
+  InitCGMA::initialize_cgma();
+  if (actuate_attribs) {
+    CGMApp::instance()->attrib_manager()->set_all_auto_read_flags( actuate_attribs );
+    CGMApp::instance()->attrib_manager()->set_all_auto_actuate_flags( actuate_attribs );
+  }
+  
+    // Get CGM file type
+  if (!file_type) {
+    file_type = get_geom_file_type( input_name );
+    if (!file_type) {
+      std::cerr << input_name << " : unknown file type, try '-t'" << std::endl;
+      exit(1);
+    }
+  }
+  
+    // If CUB file, extract ACIS geometry
+  CubitStatus s;
+  if (!strcmp( file_type, "CUBIT" )) {
+    char* temp_name = tempnam( 0, "cgm" );
+    if (!temp_name) {
+      perror(name);
+      exit(2);
+    }
+    
+    FILE* cub_file = fopen( input_name, "r" );
+    if (!cub_file) {
+      free(temp_name);
+      perror(input_name);
+      exit(2);
+    }
+    
+    FILE* tmp_file = fopen( temp_name, "w" );
+    if (!tmp_file) {
+      free(temp_name);
+      perror(temp_name);
+      exit(2);
+    }
+    
+    MBCore *my_impl = new MBCore();
+    Tqdcfr *my_tqd = new Tqdcfr(my_impl);
+    ReadNCDF my_ex_reader(my_impl);
+    MBEntityHandle file_set;
+    FileOptions opts(NULL);
+
+    MBErrorCode result = my_tqd->load_file(input_name, file_set, opts, 0, 0);
+
+    //opts = "tdata=coord, 100, sum, temp.exo";
+    opts = "tdata=coord, 100, set, temp.exo";
+    result =  my_ex_reader.load_file("pin_only05m_idmps-out.e", file_set, opts, 0 , 0);
+
+    result = my_impl->write_mesh( "tree.h5m" );
+    assert(!result);
+  }
+  return 0;
+}
+
+void print_usage(char *name)
+{
+  std::cout << "Usage: " << std::endl;
+  std::cout << name << 
+      " [-d <tol>|-D] [-n <tol>|-N] [-l <tol>|-L] [-A|-a] [-t <type>] <input_file> <outupt_file>" <<
+      std::endl;
+  std::cout << name << " -h" << std::endl;
+}
+
+void usage(char *name)
+{
+  print_usage(name);
+  exit(1);
+}
+
+void help(char *name)
+{
+  print_usage(name);
+  std::cout << "\t-d  max. distance deviation between facet and geometry" << std::endl
+            << "\t-D  no distance tolerance" << std::endl
+            << "\t    (default:" << DEFAULT_DISTANCE << ")" <<std::endl
+            << "\t-n  max. normal angle deviation (degrees) between facet and geometry" << std::endl
+            << "\t    (default:" << DEFAULT_NORM << ")" <<std::endl
+            << "\t-N  no normal tolerance" << std::endl
+            << "\t-l  max. facet edge length" << std::endl
+            << "\t-L  no facet edge length maximum" << std::endl
+            << "\t    (default:" << DEFAULT_LEN << ")" << std::endl
+            << "\t-a  force actuation of all CGM attributes" << std::endl
+            << "\t-A  disable all CGM attributes" << std::endl
+            << "\t-t  specify input file type (default is autodetect)" << std::endl
+            << std::endl;
+  exit(0);
+}
+
+const char* get_geom_file_type( const char* name )
+{
+  FILE* file;
+  const char* result = 0;
+  
+  file = fopen( name, "r" );
+  if (file) {
+    result = get_geom_fptr_type( file );
+    fclose( file );
+  }
+  
+  return result;
+}
+
+const char* get_geom_fptr_type( FILE* file )
+{
+  static const char* CUBIT_NAME = GF_CUBIT_FILE_TYPE;
+  static const char*  STEP_NAME = GF_STEP_FILE_TYPE;
+  static const char*  IGES_NAME = GF_IGES_FILE_TYPE;
+  static const char*   SAT_NAME = GF_ACIS_TXT_FILE_TYPE;
+  static const char*   SAB_NAME = GF_ACIS_BIN_FILE_TYPE;
+  static const char*  BREP_NAME = GF_OCC_BREP_FILE_TYPE;
+  
+  if (is_cubit_file(file))
+    return CUBIT_NAME;
+  else if (is_step_file(file))
+    return STEP_NAME;
+  else if (is_iges_file(file))
+    return IGES_NAME;
+  else if (is_acis_bin_file(file))
+    return SAB_NAME;
+  else if (is_acis_txt_file(file))
+    return SAT_NAME;
+  else if (is_occ_brep_file(file))
+    return BREP_NAME;
+  else
+    return 0;
+}
+
+int is_cubit_file( FILE* file )
+{
+  unsigned char buffer[4];
+  return !fseek(file, 0, SEEK_SET) &&
+         fread(buffer, 4, 1, file) &&
+         !memcmp(buffer, "CUBE", 4);
+}
+
+int is_step_file( FILE* file )
+{
+  unsigned char buffer[9];
+  return !fseek(file, 0, SEEK_SET) &&
+         fread(buffer, 9, 1, file) &&
+         !memcmp(buffer, "ISO-10303", 9);
+}
+
+int is_iges_file( FILE* file )
+{
+  unsigned char buffer[10];
+  return !fseek(file, 72, SEEK_SET) &&
+         fread(buffer, 10, 1, file) &&
+         !memcmp(buffer, "S      1\r\n", 10);
+}
+
+int is_acis_bin_file( FILE* file )
+{
+  char buffer[15];
+  return !fseek(file, 0, SEEK_SET) &&
+         fread(buffer, 15, 1, file) &&
+         !memcmp(buffer, "ACIS BinaryFile", 9);
+}
+
+int is_acis_txt_file( FILE* file )
+{
+  char buffer[5];
+  int version, length;
+  
+  if (fseek(file,0,SEEK_SET) || 
+      2 != fscanf( file, "%d %*d %*d %*d %d ", &version, &length ))
+    return 0;
+    
+  if (version < 1 || version >0xFFFF)
+    return 0;
+  
+    // Skip appliation name
+  if (fseek(file, length, SEEK_CUR))
+    return 0;
+    
+    // Read length of version string followed by first 5 characters
+  if (2 != fscanf(file, "%d %4s", &length, buffer))
+    return 0;
+    
+  return !strcmp( buffer, "ACIS" );
+}
+
+int is_occ_brep_file( FILE* file )
+{
+  unsigned char buffer[6];
+  return !fseek(file, 0, SEEK_SET) &&
+         fread(buffer, 6, 1, file) &&
+         !memcmp(buffer, "DBRep_", 6);
+}

Added: MOAB/trunk/tools/dagmc/pin_only05m_idmps-out.e
===================================================================
(Binary files differ)


Property changes on: MOAB/trunk/tools/dagmc/pin_only05m_idmps-out.e
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the moab-dev mailing list