cgma
cgmpartitioner.cpp
Go to the documentation of this file.
00001 #include "MergeTool.hpp"
00002 #include "InitCGMA.hpp"
00003 #include "GeometryModifyTool.hpp"
00004 #include "GeometryQueryTool.hpp"
00005 #include "Body.hpp"
00006 #include "CGMApp.hpp"
00007 #include "CubitAttribManager.hpp"
00008 #include "CubitCompat.hpp"
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <iostream>
00013 #include <vector>
00014 
00015 #ifndef ENGINE
00016 # define ENGINE 0
00017 #endif
00018 
00019 #define gti GeometryQueryTool::instance()
00020 #define gmti GeometryModifyTool::instance()
00021 
00022 #define ASSERT(A) if (!(A)) failed(#A,__FILE__,__LINE__)
00023 void failed( const char* A, const char* FILE, int LINE )
00024 {
00025   printf( "Condition failed at %s:%d : %s\n", FILE, LINE, A );
00026   abort();
00027 }
00028 
00029 
00030 static void print_usage( const char* name, std::ostream& stream )
00031 {
00032   std::cout << "Usage: " << name << " <input geometry file name> #x-parts #y-parts #z-parts <output geometry file name>" << std::endl;
00033 }
00034 
00035 
00036 std::string type_from_file_name( const std::string& filename )
00037 {
00038   size_t dot_pos = filename.find_last_of( '.' );
00039   if (dot_pos == std::string::npos)
00040     return std::string();
00041 
00042   std::string extension = filename.substr( dot_pos + 1 );
00043   std::transform( extension.begin(), extension.end(), extension.begin(), ::tolower );
00044   if (extension == "occ" || extension == "brep")
00045     return "OCC";
00046   else if (extension == "step" || extension == "stp")
00047     return "STEP";
00048   else if (extension == "iges" || extension == "igs")
00049     return "IGES";
00050   else if (extension == "sat")
00051     return "ACIS_SAT";
00052   else
00053     return std::string();
00054 }
00055 
00056 
00057 int main(int argc, char* argv[])
00058 {
00059   if (argc !=6){
00060     print_usage(argv[0], std::cerr);
00061     exit(0);
00062   }
00063   // parse command line options for partitioning geometry for parallel mesh generation
00064   CubitStatus rsl = CUBIT_SUCCESS;
00065 
00066   rsl = InitCGMA::initialize_cgma( ENGINE );
00067   ASSERT(rsl);
00068 
00069   CGMApp::instance()->attrib_manager()->auto_flag( CUBIT_TRUE );
00070 
00071   std::string type = type_from_file_name( argv[1] );
00072   if (type.empty()) // just guess OCC
00073     type = "OCC";
00074   rsl = CubitCompat_import_solid_model(argv[1], type.c_str());
00075   if (rsl != CUBIT_SUCCESS) {
00076     PRINT_ERROR("Problems reading geometry file %s.\n", argv[1]);
00077     abort();
00078   }
00079 
00080   int npartsx = atoi(argv[2]), npartsy = atoi(argv[3]), npartsz = atoi(argv[4]);
00081 
00082   // Get the bounding box for this geometry
00083   DLIList<Body*> old_bodies, new_bodies, junk;
00084   gti->bodies(old_bodies);
00085   old_bodies.reset();
00086 
00087   std::vector<CubitBox> box;
00088   box.resize(old_bodies.size());
00089   CubitBox box1;
00090 
00091   for(int i=0; i< old_bodies.size (); i++){
00092       box[i] =old_bodies[i]->bounding_box();
00093       if (i>0)
00094         box1 = box[i-1].operator |= (box[i]);
00095       else
00096         box1 = box[i];
00097     }
00098 
00099   double bxmax =box1.max_x ();
00100   double bymax =box1.max_y ();
00101   double bzmax =box1.max_z ();
00102 
00103   double bxmin =box1.min_x ();
00104   double bymin =box1.min_y ();
00105   double bzmin =box1.min_z ();
00106   std::cout << "Bounding box of the geometry file:" << std::endl;
00107   std::cout << bxmin << " < X < " << bxmax << std::endl;
00108   std::cout << bymin << " < X < " << bymax << std::endl;
00109   std::cout << bzmin << " < X < " << bzmax << std::endl;
00110   double dx = box1.x_range ();
00111   double dy = box1.y_range ();
00112   double dz = box1.z_range ();
00113 
00114   for (int i=0; i< npartsx-1;  i++){
00115       double xcenter = bxmin + (i+1)*dx/npartsx;
00116 
00117       CubitVector center(xcenter,0.0, 0.0);
00118       CubitVector axes[2];
00119       axes[0].set(0.,0.,1.);
00120       axes[1].set(0.,1.,0.);
00121 
00122       new_bodies.clean_out ();
00123       rsl = gmti->webcut_with_planar_sheet(old_bodies,center,axes,2*dy,2*dz,new_bodies,junk);
00124       if (rsl== CUBIT_FAILURE)
00125         return rsl;
00126       old_bodies.clean_out ();
00127       old_bodies.copy_from (&new_bodies[0],new_bodies.size ());
00128     }
00129 
00130   old_bodies.clean_out ();
00131   gti->bodies(old_bodies);
00132   old_bodies.reset();
00133   for (int j=0; j< npartsy-1; j++){
00134 
00135       double ycenter = bymin + (j+1)*dy/npartsy;
00136 
00137       CubitVector center(0.0,ycenter, 0.0);
00138       CubitVector axes[2];
00139       axes[0].set(0.,0.,1.);
00140       axes[1].set(1.,0.,0.);
00141 
00142       new_bodies.clean_out ();
00143       rsl = gmti->webcut_with_planar_sheet(old_bodies,center,axes,2*dz,2*dx,new_bodies,junk);
00144       if (rsl== CUBIT_FAILURE)
00145         return rsl;
00146       old_bodies.clean_out ();
00147       old_bodies.copy_from (&new_bodies[0],new_bodies.size ());
00148     }
00149 
00150   old_bodies.clean_out ();
00151   gti->bodies(old_bodies);
00152   old_bodies.reset();
00153   for (int k=0; k< npartsz-1; k++){
00154 
00155       double zcenter = bzmin + (k+1)*dz/npartsz;
00156 
00157       CubitVector center(0.0,0.0, zcenter);
00158       CubitVector axes[2];
00159       axes[0].set(0.,1.,0.);
00160       axes[1].set(1.,0.,0.);
00161 
00162       new_bodies.clean_out ();
00163       rsl = gmti->webcut_with_planar_sheet(old_bodies,center,axes,2*dx,2*dy,new_bodies,junk);
00164       if (rsl== CUBIT_FAILURE)
00165         return rsl;
00166       old_bodies.clean_out ();
00167       old_bodies.copy_from (&new_bodies[0],new_bodies.size ());
00168     }
00169 
00170 // merge entities 
00171   rsl = MergeTool::instance()->merge_bodies( new_bodies );
00172   ASSERT(rsl);
00173 
00174   int num_ents_exported=0;
00175   DLIList<RefEntity*> ref_entities;
00176   const CubitString cubit_version="10.2";
00177   const char * filename = argv[5];
00178 
00179   ref_entities.clean_out();
00180   rsl = CubitCompat_export_solid_model(ref_entities, filename, type.c_str(),
00181                                        num_ents_exported, cubit_version);
00182   if (rsl== CUBIT_FAILURE)
00183     return rsl;
00184 
00185   return 0;
00186 }
00187 
00188 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines