MeshKit
1.0
|
00001 /********************************************* 00002 AssyGen Tool: Reactor Geometry Generator 00003 Argonne National Laboratory 00004 *********************************************/ 00005 00006 #ifdef _WIN32 00007 #define _USE_MATH_DEFINES 00008 #endif 00009 00010 #include "meshkit/AssyGen.hpp" 00011 00012 namespace MeshKit 00013 { 00014 // static registration of this mesh scheme 00015 moab::EntityType AssyGen_tps[] = { moab::MBVERTEX, 00016 moab::MBEDGE, 00017 moab::MBTRI, 00018 moab::MBHEX, 00019 moab::MBMAXTYPE}; 00020 const moab::EntityType* AssyGen::output_types() 00021 { return AssyGen_tps; } 00022 00023 AssyGen::AssyGen( MKCore *mk, const MEntVector &me_vec) 00024 : MeshScheme( mk, me_vec), 00025 igeomImpl(mk->igeom_instance()) 00026 { 00027 err = 0; 00028 tmpSB = 1; 00029 m_nPlanar = 0; //default is 3D 00030 m_nLineNumber = 0; 00031 root_set= NULL; 00032 szComment = "!"; 00033 MAXCHARS = 10000; 00034 MAXLINES = 1000; 00035 pi = M_PI; 00036 m_nTotalPincells = 0; 00037 m_dRadialSize = -1.0; 00038 m_dTetMeshSize = -1.0; 00039 m_nDimensions = 0; 00040 m_nMaterialSetId = 1; 00041 m_nNeumannSetId = 1; 00042 m_szEngine = "acis"; 00043 m_szMeshType = "hex"; 00044 m_nDuct = 0; 00045 m_nDuctNum = 0; 00046 m_nJouFlag = 0; 00047 m_szSideset = "yes"; 00048 m_nAssyGenInputFiles = 0; 00049 m_dMergeTol = 1e-4; 00050 m_edgeInterval = 99; 00051 m_nStartpinid = 1; 00052 m_szInfo = "off"; 00053 m_szMeshScheme = "pave"; 00054 pin_name = ""; 00055 m_nHblock = -1; 00056 m_nPincells = 0; 00057 m_bCreateMatFiles = false; 00058 m_nSuperBlocks = 0; 00059 m_bmerge = true; 00060 m_bimprint = true; 00061 save_exodus = false; 00062 have_common = true; 00063 com_run_count = 0; 00064 m_nBLAssemblyMat = 0; 00065 m_szInnerDuct = ""; 00066 m_szSmooth = "off"; 00067 } 00068 00069 AssyGen::~AssyGen() 00070 { 00071 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 00072 iGeom_dtor(igeomImpl->instance(), &err); 00073 #endif 00074 //CHECK( "Interface destruction didn't work properly." ); 00075 // close the input and output files 00076 m_FileInput.close (); 00077 m_FileOutput.close (); 00078 m_SchemesFile.close (); 00079 if(strcmp(m_szInfo.c_str(),"on") == 0) 00080 m_AssmInfo.close (); 00081 } 00082 00083 00084 bool AssyGen::add_modelent(ModelEnt *model_ent) 00085 { 00086 return MeshOp::add_modelent(model_ent); 00087 } 00088 00089 void AssyGen::setup_this() 00090 { 00091 // start the timer 00092 CClock Timer; 00093 clock_t sTime = clock(); 00094 std::string szDateTime; 00095 Timer.GetDateTime (szDateTime); 00096 std::cout << "\nStarting out at : " << szDateTime << "\n"; 00097 00098 if (have_common == true) 00099 ReadCommonInp(); 00100 00101 //count pin cylinders and cell material, needed for setting array size before actual read 00102 ReadInputPhase1 (); 00103 00104 if (have_common == true) 00105 ReadCommonInp(); 00106 00107 // read the problem size and create pincell 00108 ReadAndCreate (); 00109 00110 // create the .jou file 00111 CreateCubitJournal(); 00112 00113 CreateAssyGenInputFiles(); 00114 00115 // get the current date and time 00116 Timer.GetDateTime (szDateTime); 00117 std::cout << "Ending at : " << szDateTime; 00118 00119 // compute the elapsed time 00120 std::cout << "Elapsed wall clock time: " << Timer.DiffTime () 00121 << " seconds or " << (Timer.DiffTime ())/60.0 << " mins\n"; 00122 00123 std::cout << "## Total CPU time used := " << (double) (clock() - sTime)/CLOCKS_PER_SEC \ 00124 << " seconds" << std::endl; 00125 } 00126 00127 void AssyGen::execute_this() 00128 { 00129 } 00130 00131 00132 void AssyGen::PrepareIO (int argc, char *argv[], std::string TestDir) 00133 // --------------------------------------------------------------------------- 00134 // Function: Obtains file names and opens input/output files 00135 // Input: command line arguments 00136 // Output: none 00137 // --------------------------------------------------------------------------- 00138 { 00139 std::cout << '\n'; 00140 std::cout << "\t\t---------------------------------------------------------" << '\n'; 00141 std::cout << "\t\tProgram to Generate Nuclear Reactor Assembly Geometries " << '\n'; 00142 std::cout << "\t\t\t\tArgonne National Laboratory" << '\n'; 00143 std::cout << "\t\t---------------------------------------------------------" << '\n'; 00144 std::cout << "\nsee http://press3.mcs.anl.gov/sigma/meshkit-library/rgg/ for details.\n"<< std::endl; 00145 // set and open input output files 00146 bool bDone = false; 00147 do{ 00148 if (2 == argc) { 00149 m_szFile = argv[1]; 00150 m_szInFile=m_szFile+".inp"; 00151 m_szJouFile = m_szFile+".jou"; 00152 m_szSchFile = m_szFile+".template.jou"; 00153 m_szAssmInfo = m_szFile + "_info.csv"; 00154 m_szLogFile = m_szFile + ".screenlog"; 00155 m_szPyCubGeom = m_szFile + ".py"; 00156 m_szCommonFile = "common.inp"; 00157 } 00158 else if (3 == argc) { 00159 int i=1;// will loop through arguments, and process them 00160 for (i=1; i<argc-1 ; i++) { 00161 if (argv[i][0]=='-') { 00162 switch (argv[i][1]) 00163 { 00164 case 'j': 00165 { 00166 m_nJouFlag = 1; 00167 std::cout << "Creating journal file only.\n Geometry file must exist in the same directory." << std::endl; 00168 m_szFile = argv[2]; 00169 m_szInFile=m_szFile+".inp"; 00170 m_szJouFile = m_szFile+".jou"; 00171 m_szSchFile = m_szFile+".template.jou"; 00172 m_szAssmInfo = m_szFile + "_info.csv"; 00173 m_szLogFile = m_szFile + ".screenlog"; 00174 m_szPyCubGeom = m_szFile + ".py"; 00175 m_szCommonFile = "common.inp"; 00176 break; 00177 } 00178 case 'h': 00179 { 00180 std::cout << "\nInstruction on writing assygen input file can also be found at: " << std::endl; 00181 std::cout << " http://press3.mcs.anl.gov/sigma/meshkit/rgg/assygen-input-file-keyword-definitions/" << std::endl; 00182 std::cout << "Usage: assygen [-j -h] <input file name without extension>"<< std::endl; 00183 std::cout << " -j create journal file only" << std::endl; 00184 std::cout << " -h print help" << std::endl; 00185 00186 exit(0); 00187 break; 00188 } 00189 } 00190 } 00191 } 00192 } 00193 else if (1 == argc){ 00194 std::cout << "\nInstruction on writing assygen input file can also be found at: " << std::endl; 00195 std::cout << " http://press3.mcs.anl.gov/sigma/meshkit/rgg/assygen-input-file-keyword-definitions/" << std::endl; 00196 std::cout << "Usage: assygen [-t -j -h] <input file name without extension>"<< std::endl; 00197 std::cout << " -t print timing and memory usage info in each step" << std::endl; 00198 std::cout << " -j create journal file only" << std::endl; 00199 std::cout << " -h print help" << std::endl; 00200 00201 m_szInFile = TestDir + "/" + (char *)DEFAULT_TEST_FILE; 00202 m_szGeomFile = (char *)TEST_FILE_NAME; 00203 m_szJouFile = (char *)TEST_FILE_NAME; 00204 m_szFile = (char *)TEST_FILE_NAME; 00205 m_szInFile+=".inp"; 00206 m_szJouFile+=".jou"; 00207 m_szSchFile = m_szFile+".template.jou"; 00208 m_szAssmInfo = m_szFile + "_info.csv"; 00209 m_szLogFile = m_szFile + ".screenlog"; 00210 m_szPyCubGeom = m_szFile + ".py"; 00211 m_szCommonFile = TestDir + "/" + "common.inp"; 00212 00213 std::cout <<"Default case input file is located here <MeshKit/data> "<< std::endl; 00214 } 00215 // open the file 00216 m_FileInput.open (m_szInFile.c_str(), std::ios::in); 00217 if (!m_FileInput){ 00218 std::cout << "Usage: assygen <input filename WITHOUT EXTENSION>"<< std::endl; 00219 m_FileInput.clear (); 00220 exit(1); 00221 } 00222 else 00223 bDone = true; // file opened successfully 00224 00225 // open common.inp file, if not found do nothing. 00226 m_FileCommon.open (m_szCommonFile.c_str(), std::ios::in); 00227 if (!m_FileCommon){ 00228 have_common = false; 00229 std::cout << "common.inp file not specified." << std::endl; 00230 m_FileCommon.clear (); 00231 } 00232 else { 00233 have_common = true; 00234 } 00235 std::cout << " opened file " << m_szCommonFile << " have common is " 00236 << have_common << std::endl; 00237 } while (!bDone); 00238 std::cout << "\nEntered input file name: " << m_szInFile <<std::endl; 00239 00240 // open the file 00241 do{ 00242 m_FileOutput.open (m_szJouFile.c_str(), std::ios::out); 00243 if (!m_FileOutput){ 00244 std::cout << "Unable to open o/p file: " << m_szJouFile << std::endl; 00245 m_FileOutput.clear (); 00246 exit(1); 00247 } 00248 else 00249 bDone = true; // file opened successfully 00250 } while (!bDone); 00251 00252 // open the template journal file for writing 00253 do{ 00254 m_SchemesFile.open (m_szSchFile.c_str(), std::ios::out); 00255 if (!m_SchemesFile){ 00256 std::cout << "Unable to open o/p file: " << m_szSchFile << std::endl; 00257 m_SchemesFile.clear (); 00258 exit(1); 00259 } 00260 else 00261 bDone = true; // file opened successfully 00262 } while (!bDone); 00263 00264 do{ 00265 m_PyCubGeomFile.open (m_szPyCubGeom.c_str(), std::ios::out); 00266 if (!m_PyCubGeomFile){ 00267 std::cout << "Unable to open o/p file: " << m_szPyCubGeom << std::endl; 00268 m_PyCubGeomFile.clear (); 00269 exit(1); 00270 } 00271 else 00272 bDone = true; // file opened successfully 00273 } while (!bDone); 00274 00275 std::cout<<"\no/p Cubit journal file name: "<< m_szJouFile 00276 << std::endl; 00277 00278 // filename to be saved with cubit journal file 00279 m_szGeomFile1 = m_szFile+".sat"; 00280 00281 //ACIS ENGINE 00282 #ifdef HAVE_ACIS 00283 // if(m_szEngine == "acis"){ 00284 m_szGeomFile = m_szFile+".sat"; 00285 // } 00286 #elif defined(HAVE_OCC) 00287 // OCC ENGINE 00288 // if (m_szEngine == "occ"){ 00289 m_szGeomFile = m_szFile+".brep"; 00290 // } 00291 #endif 00292 std::cout << "\no/p geometry file name: " << m_szGeomFile <<std::endl; 00293 00294 // writing schemes .jou file ends, now write the main journal file. 00295 // stuff common to both surface and volume 00296 m_FileOutput << "## This file is created by rgg program in MeshKit ##\n"; 00297 m_FileOutput << "#User needs to specify mesh interval and schemes in this file\n#" << std::endl; 00298 00299 m_PyCubGeomFile << "## This python script is created by the RGG AssyGen program in MeshKit ##\n"; 00300 m_PyCubGeomFile << "# Here the RGG AssyGen program creates the assembly geometry and mesh\n#" << std::endl; 00301 m_PyCubGeomFile << "\nimport cubit" << std::endl; 00302 00303 00304 // write the name faces python function here 00305 m_PyCubGeomFile << "def name_faces(name, body):\n" 00306 " vector_locs = cubit.get_bounding_box(\"volume\", body.id())\n" 00307 " topno = vector_locs[7] - 1e-2\n" 00308 " botno = vector_locs[6] + 1e-2\n" 00309 " cubit.cmd('group \"g1\" equals surf in vol {0} '.format(body.id()))\n" 00310 " cubit.cmd('group \"g2\" equals surf in g1 with z_coord < {0} and z_coord > {1}'.format(topno,botno))\n" 00311 " cubit.cmd('group \"g3\" subtract g2 from g1')\n" 00312 " cubit.cmd('group \"gtop\" equals surf in g3 with z_coord > {0}'.format(topno) )\n" 00313 " cubit.cmd('group \"gbot\" equals surf in g3 with z_coord < {0}'.format(botno) )\n" 00314 " g2id = cubit.get_id_from_name(\"g2\")\n" 00315 " ssurfs = cubit.get_group_surfaces(g2id)\n" 00316 " side_surfs = len(ssurfs)\n" 00317 " for i in range(0,side_surfs):\n" 00318 " sname = name + \"_side\" + str(i+1)\n" 00319 " cubit.cmd('surf {0} name \"{1}\"'.format( ssurfs[i] , sname ) )\n" 00320 " top_surf = name + \"_top\"\n" 00321 " bot_surf = name + \"_bot\"\n" 00322 " cubit.cmd('surf in gtop name \"{0}\"'.format(top_surf) )\n" 00323 " cubit.cmd('surf in gbot name \"{0}\"'.format(bot_surf) )\n" 00324 " cubit.cmd('delete group g1 g2 g3 gtop gbot')\n" << std::endl; 00325 00326 00327 // write the name faces python function here 00328 m_PyCubGeomFile << "\n\ndef section_assm(cDir, dOffset, szReverse):\n" 00329 " vol = cubit.get_entities(\"volume\")\n" 00330 " for i in range(len(vol)):\n" 00331 " vl = cubit.get_bounding_box(\"volume\", vol[i])\n" 00332 " xmin = vl[0]\n" 00333 " xmax = vl[1]\n" 00334 " ymin = vl[3]\n" 00335 " ymax = vl[4]\n" 00336 " print xmin, xmax, ymin, ymax\n" 00337 " if(xmin > dOffset and cDir == \"x\" and szReverse == \"reverse\"):\n" 00338 " cubit.cmd('delete vol {0}'.format(vol[i]) )\n" 00339 " continue\n" 00340 " if(ymin > dOffset and cDir == \"y\" and szReverse == \"reverse\"):\n" 00341 " cubit.cmd('delete vol {0}'.format(vol[i]) )\n" 00342 " continue\n" 00343 " if(xmax < dOffset and cDir == \"x\" and szReverse == \"\"):\n" 00344 " cubit.cmd('delete vol {0}'.format(vol[i]) )\n" 00345 " continue\n" 00346 " if(ymax < dOffset and cDir == \"y\" and szReverse == \"\"):\n" 00347 " cubit.cmd('delete vol {0}'.format(vol[i]) )\n" 00348 " continue\n" 00349 " else:\n" 00350 " if (ymax > dOffset and cDir == \"y\" and ymin < dOffset):\n" 00351 " cubit.cmd('section vol {0} with yplane offset {1} {2}'.format(vol[i], dOffset, szReverse))\n" 00352 " if (xmax > dOffset and cDir == \"x\" and xmin < dOffset):\n" 00353 " cubit.cmd('section vol {0} with xplane offset {1} {2}'.format(vol[i], dOffset, szReverse))\n" << std::endl; 00354 00355 m_PyCubGeomFile << "\ncubit.cmd('reset')" << std::endl; 00356 00357 00358 m_FileOutput << "#" << std::endl; 00359 m_FileOutput << "set logging on file '" << m_szLogFile << "'" <<std::endl; 00360 m_FileOutput << "Timer Start" << std::endl; 00361 // import the geometry file 00362 m_FileOutput << "# Import geometry file " << std::endl; 00363 // Use sat file always as step isn't supported 00364 m_FileOutput << "import '" << m_szGeomFile1 <<"'" << std::endl; 00365 m_FileOutput << "{include(\"" << m_szSchFile << "\")}" <<std::endl; 00366 m_FileOutput << "#" << std::endl; 00367 00368 } 00369 00370 00371 void AssyGen::ReadCommonInp () 00372 // ------------------------------------------------------------------------------------------- 00373 // Function: reads the input file to count the no. of cyl in a pincell, before the actual read 00374 // Input: none 00375 // Output: none 00376 // ------------------------------------------------------------------------------------------- 00377 { 00378 ++com_run_count; 00379 if(com_run_count > 1){ 00380 //Rewind the reader for common.inp file 00381 m_FileCommon.clear (std::ios_base::goodbit); 00382 m_FileCommon.seekg (0L, std::ios::beg); 00383 } 00384 CParser Parse1; 00385 bool found = false; 00386 std::string card; 00387 m_nLineNumber = 0; 00388 std::cout << "Reading from common.inp file." << std::endl; 00389 for(;;){ 00390 if (!Parse1.ReadNextLine (m_FileCommon, m_nLineNumber, szInputString, 00391 MAXCHARS, szComment)) 00392 IOErrorHandler (INVALIDINPUT); 00393 00394 if (szInputString.substr(0,10) == "geomengine"){ 00395 found = true; 00396 std::istringstream szFormatString (szInputString); 00397 szFormatString >> card >> m_szEngine; 00398 if( ((strcmp (m_szEngine.c_str(), "acis") != 0) && 00399 (strcmp (m_szEngine.c_str(), "occ") != 0)) || szFormatString.fail()) 00400 IOErrorHandler(EGEOMENGINE); 00401 } 00402 // start id for pin number 00403 if (szInputString.substr(0, 10) == "startpinid") { 00404 found = true; 00405 std::istringstream szFormatString(szInputString); 00406 szFormatString >> card >> m_nStartpinid; 00407 } 00408 if (szInputString.substr(0,8) == "meshtype"){ 00409 found = true; 00410 std::istringstream szFormatString (szInputString); 00411 szFormatString >> card >> m_szMeshType; 00412 if( ((strcmp (m_szMeshType.c_str(), "hex") != 0) && 00413 (strcmp (m_szMeshType.c_str(), "tet") != 0)) || szFormatString.fail()) 00414 IOErrorHandler(INVALIDINPUT); 00415 } 00416 // info flag 00417 if (szInputString.substr(0,4) == "info"){ 00418 found = true; 00419 std::istringstream szFormatString (szInputString); 00420 szFormatString >> card >> m_szInfo; 00421 std::cout <<"--------------------------------------------------"<<std::endl; 00422 } 00423 // hex block along z 00424 if (szInputString.substr(0,6) == "hblock"){ 00425 found = true; 00426 std::istringstream szFormatString (szInputString); 00427 szFormatString >> card >> m_nHblock >> m_dZstart >> m_dZend; 00428 std::cout <<"--------------------------------------------------"<<std::endl; 00429 } 00430 // Hex or Rect geometry type 00431 if (szInputString.substr(0,12) == "geometrytype"){ 00432 found = true; 00433 std::istringstream szFormatString (szInputString); 00434 szFormatString >> card >> m_szGeomType; 00435 if( ((strcmp (m_szGeomType.c_str(), "hexagonal") != 0) && 00436 (strcmp (m_szGeomType.c_str(), "rectangular") != 0)) || szFormatString.fail()) 00437 IOErrorHandler(EGEOMTYPE); 00438 00439 // set the number of sides in the geometry 00440 if(m_szGeomType == "hexagonal") 00441 m_nSides = 6; 00442 else if(m_szGeomType == "rectangular") 00443 m_nSides = 4; 00444 } 00445 // Default if volume, set geometry type to surface for 2D assemblies 00446 if (szInputString.substr(0,8) == "geometry"){ 00447 found = true; 00448 std::string outfile; 00449 std::istringstream szFormatString (szInputString); 00450 szFormatString >> card >> outfile; 00451 if(strcmp (outfile.c_str(), "surface") == 0 || szFormatString.fail()) 00452 m_nPlanar=1; 00453 } 00454 // 'yes' or 'no' for creating sidesets 00455 if (szInputString.substr(0,13) == "createsideset"){ 00456 found = true; 00457 std::istringstream szFormatString (szInputString); 00458 szFormatString >> card >> m_szSideset; 00459 std::cout <<"--------------------------------------------------"<<std::endl; 00460 } 00461 // Create specified number of files with varying material ids 00462 if (szInputString.substr(0,11) == "createfiles"){ 00463 found = true; 00464 std::istringstream szFormatString (szInputString); 00465 szFormatString >> card >> m_nAssyGenInputFiles; 00466 std::cout <<"--------------------------------------------------"<<std::endl; 00467 } 00468 // Create specified number of files with varying material ids 00469 if (szInputString.substr(0,11) == "save_exodus"){ 00470 found = true; 00471 save_exodus = true; 00472 std::cout <<"--------------------------------------------------"<<std::endl; 00473 } 00474 // specify a merge tolerance value for cubit journal file 00475 if (szInputString.substr(0,14) == "mergetolerance"){ 00476 found = true; 00477 std::istringstream szFormatString (szInputString); 00478 szFormatString >> card >> m_dMergeTol; 00479 std::cout <<"--------------------------------------------------"<<std::endl; 00480 } 00481 // Handle mesh size inputs 00482 if (szInputString.substr(0,14) == "radialmeshsize"){ 00483 found = true; 00484 std::istringstream szFormatString (szInputString); 00485 szFormatString >> card >> m_dRadialSize; 00486 if(m_dRadialSize < 0 || szFormatString.fail()) 00487 IOErrorHandler(ENEGATIVE); 00488 std::cout <<"--------------------------------------------------"<<std::endl; 00489 00490 } 00491 // Handle mesh size inputs 00492 if (szInputString.substr(0,11) == "tetmeshsize"){ 00493 found = true; 00494 std::istringstream szFormatString (szInputString); 00495 szFormatString >> card >> m_dTetMeshSize; 00496 if(m_dTetMeshSize < 0 || szFormatString.fail()) 00497 IOErrorHandler(ENEGATIVE); 00498 std::cout <<"--------------------------------------------------"<<std::endl; 00499 00500 } 00501 // Handle mesh size inputs 00502 if (szInputString.substr(0,13) == "axialmeshsize"){ 00503 found = true; 00504 if(com_run_count > 1){ 00505 std::istringstream szFormatString (szInputString); 00506 szFormatString >> card; 00507 m_dAxialSize.SetSize(m_nDuct); 00508 int num_ams_specified = std::distance(std::istream_iterator<std::string>(szFormatString), 00509 std::istream_iterator<std::string>()); 00510 std::istringstream szFormatStringAgain (szInputString); 00511 szFormatStringAgain >> card; 00512 for (int p = 1; p <= m_nDuct; p++){ 00513 if(p <= num_ams_specified) 00514 szFormatStringAgain >> m_dAxialSize(p); 00515 else 00516 m_dAxialSize(p) = m_dAxialSize(num_ams_specified); 00517 if(m_dAxialSize(p) < 0) 00518 IOErrorHandler(ENEGATIVE); 00519 } 00520 std::cout <<"--------------------------------------------------"<<std::endl; 00521 } 00522 } 00523 // edge interval 00524 if (szInputString.substr(0, 12) == "edgeinterval") { 00525 found = true; 00526 std::istringstream szFormatString(szInputString); 00527 szFormatString >> card >> m_edgeInterval; 00528 } 00529 // mesh scheme - hole or pave 00530 if (szInputString.substr(0, 10) == "meshscheme") { 00531 std::istringstream szFormatString(szInputString); 00532 szFormatString >> card >> m_szMeshScheme; 00533 } 00534 // breaking condition 00535 if(szInputString.substr(0,3) == "end" || m_nLineNumber == MAXLINES){ 00536 found = true; 00537 break; 00538 } 00539 if (found == false){ 00540 std::cout << "Cannot specify: " << szInputString << " in common.inp files" << std::endl; 00541 } 00542 } 00543 00544 } 00545 00546 void AssyGen::ReadInputPhase1 () 00547 // ------------------------------------------------------------------------------------------- 00548 // Function: reads the input file to count the no. of cyl in a pincell, before the actual read 00549 // Input: none 00550 // Output: none 00551 // ------------------------------------------------------------------------------------------- 00552 { 00553 std::cout << "Reading from AssyGen input file." << std::endl; 00554 CParser Parse; bool bDone = false; 00555 int nCyl =0, nCellMat=0, nInputLines=0; 00556 std::string card, szVolId, szVolAlias; 00557 m_nLineNumber = 0; 00558 // count the total number of cylinder commands in each pincell 00559 for(;;){ 00560 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 00561 MAXCHARS, szComment)) 00562 IOErrorHandler (INVALIDINPUT); 00563 00564 if (szInputString.substr(0,10) == "geomengine"){ 00565 std::istringstream szFormatString (szInputString); 00566 szFormatString >> card >> m_szEngine; 00567 if( ((strcmp (m_szEngine.c_str(), "acis") != 0) && 00568 (strcmp (m_szEngine.c_str(), "occ") != 0)) || szFormatString.fail()) 00569 IOErrorHandler(EGEOMENGINE); 00570 } 00571 // Read material data 00572 if ((szInputString.substr(0,9) == "materials") && (szInputString.substr(0,19) != "materialset_startid")){ 00573 00574 std::istringstream szFormatString (szInputString); 00575 szFormatString >> card >> m_nAssemblyMat; 00576 if(szFormatString.fail()) 00577 IOErrorHandler(INVALIDINPUT); 00578 m_szAssmMat.SetSize(m_nAssemblyMat); m_szAssmMatAlias.SetSize(m_nAssemblyMat); 00579 for (int j=1; j<=m_nAssemblyMat; j++){ 00580 szFormatString >> m_szAssmMat(j) >> m_szAssmMatAlias(j); 00581 if( (strcmp (m_szAssmMat(j).c_str(), "") == 0) || 00582 (strcmp (m_szAssmMatAlias(j).c_str(), "") == 0)){ 00583 IOErrorHandler(EMAT); 00584 } 00585 // checking if & inserted at the end of the material by mistake 00586 if (j == m_nAssemblyMat){ 00587 std::string dummy = ""; 00588 szFormatString >> dummy; 00589 if (strcmp (dummy.c_str(), "") != 0) 00590 IOErrorHandler(EMAT); 00591 } 00592 } 00593 } 00594 // Read material data 00595 if (szInputString.substr(0,11) == "blmaterials"){ 00596 00597 std::istringstream szFormatString (szInputString); 00598 szFormatString >> card >> m_nBLAssemblyMat; 00599 if(szFormatString.fail()) 00600 IOErrorHandler(INVALIDINPUT); 00601 m_szBLAssmMat.SetSize(m_nBLAssemblyMat); m_dBLMatBias.SetSize(m_nBLAssemblyMat); 00602 m_nBLMatIntervals.SetSize(m_nBLAssemblyMat); 00603 for (int j=1; j<=m_nBLAssemblyMat; j++){ 00604 szFormatString >> m_szBLAssmMat(j) >> m_dBLMatBias(j) >> m_nBLMatIntervals(j); 00605 if( (strcmp (m_szBLAssmMat(j).c_str(), "") == 0) || 00606 (m_nBLMatIntervals(j) < 0) ){ 00607 IOErrorHandler(EMAT); 00608 } 00609 // checking if & inserted at the end of the material by mistake 00610 if (j == m_nBLAssemblyMat){ 00611 std::string dummy = ""; 00612 szFormatString >> dummy; 00613 if (strcmp (dummy.c_str(), "") != 0) 00614 IOErrorHandler(EMAT); 00615 } 00616 } 00617 } 00618 00619 // start id for pin number 00620 if (szInputString.substr(0, 10) == "startpinid") { 00621 std::istringstream szFormatString(szInputString); 00622 szFormatString >> card >> m_nStartpinid; 00623 } 00624 if (szInputString.substr(0,8) == "meshtype"){ 00625 std::istringstream szFormatString (szInputString); 00626 szFormatString >> card >> m_szMeshType; 00627 if( ((strcmp (m_szMeshType.c_str(), "hex") != 0) && 00628 (strcmp (m_szMeshType.c_str(), "tet") != 0)) || szFormatString.fail()) 00629 IOErrorHandler(INVALIDINPUT); 00630 } 00631 if (szInputString.substr(0,4) == "duct" || szInputString.substr(0,10) == "dimensions"){ 00632 ++m_nDuct; 00633 } 00634 if (szInputString.substr(0,8) == "pincells"){ 00635 std::istringstream szFormatString (szInputString); 00636 szFormatString >> card >> m_nPincells; 00637 if(m_nPincells>0) 00638 m_Pincell.SetSize(m_nPincells); 00639 else if(m_nPincells ==0) 00640 m_Pincell.SetSize(1); // assume for using dummy pincell 00641 00642 // count the number of cylinder lines for each pincell 00643 for (int i=1; i<=m_nPincells; i++){ 00644 // read the no. of input lines first pincell 00645 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 00646 MAXCHARS, szComment)) 00647 IOErrorHandler (INVALIDINPUT); 00648 std::istringstream szFormatString1 (szInputString); 00649 szFormatString1 >> szVolId >> szVolAlias >> nInputLines; 00650 if(szFormatString1.fail()) 00651 IOErrorHandler(INVALIDINPUT); 00652 // loop thru the input lines of each pincell 00653 for(int l=1; l<=nInputLines; l++){ 00654 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 00655 MAXCHARS, szComment)) 00656 IOErrorHandler (INVALIDINPUT); 00657 if (szInputString.substr(0,8) == "cylinder" || szInputString.substr(0,7) == "frustum"){ 00658 ++nCyl; 00659 } 00660 if (szInputString.substr(0,12) == "cellmaterial"){ 00661 ++nCellMat; 00662 } 00663 } 00664 00665 // set the sizes 00666 if(nCyl>0){ 00667 if (nCellMat!=0){ 00668 m_Pincell(i).SetCellMatSize(nCyl); 00669 } 00670 m_Pincell(i).SetNumCyl(nCyl); 00671 } 00672 else if(nCyl ==0){ 00673 if(nInputLines >0) 00674 m_Pincell(i).SetCellMatSize(nCellMat); 00675 } 00676 nCyl = 0; 00677 nCellMat = 0; 00678 } 00679 } 00680 // info flag 00681 if (szInputString.substr(0,4) == "info"){ 00682 std::istringstream szFormatString (szInputString); 00683 szFormatString >> card >> m_szInfo; 00684 std::cout <<"--------------------------------------------------"<<std::endl; 00685 } 00686 // merge 00687 if (szInputString.substr(0,7) == "imprint"){ 00688 m_bimprint = true; 00689 std::cout <<"--------------------------------------------------"<<std::endl; 00690 } 00691 // imprint 00692 if (szInputString.substr(0,5) == "merge"){ 00693 m_bmerge = true; 00694 std::cout <<"--------------------------------------------------"<<std::endl; 00695 } 00696 // info flag 00697 if (szInputString.substr(0,6) == "smooth"){ 00698 std::istringstream szFormatString (szInputString); 00699 szFormatString >> card >> m_szSmooth; 00700 std::cout <<"--------------------------------------------------"<<std::endl; 00701 } 00702 // mesh scheme - hole or pave 00703 if (szInputString.substr(0, 10) == "meshscheme") { 00704 std::istringstream szFormatString(szInputString); 00705 szFormatString >> card >> m_szMeshScheme; 00706 } 00707 // hex block along z 00708 if (szInputString.substr(0,6) == "hblock"){ 00709 std::istringstream szFormatString (szInputString); 00710 szFormatString >> card >> m_nHblock >> m_dZstart >> m_dZend; 00711 std::cout <<"--------------------------------------------------"<<std::endl; 00712 } 00713 // breaking condition 00714 if(szInputString.substr(0,3) == "end" || m_nLineNumber == MAXLINES){ 00715 break; 00716 } 00717 } 00718 00719 if(strcmp(m_szInfo.c_str(),"on") == 0){ 00720 std::cout << m_szAssmInfo <<std::endl; 00721 do{ 00722 m_AssmInfo.open (m_szAssmInfo.c_str(), std::ios::out); 00723 if (!m_AssmInfo){ 00724 std::cout << "Unable to open o/p file: " << m_szAssmInfo << std::endl; 00725 m_AssmInfo.clear (); 00726 exit(1); 00727 } 00728 else 00729 bDone = true; // file opened successfully 00730 } while (!bDone); 00731 00732 // write header for info file 00733 m_AssmInfo <<"pincell"<< " \t" << 00734 "m" << " \t" << "n" << " \t" << "dX" << " \t" << 00735 "dY" << " \t" << "dZ" << std::endl; 00736 } 00737 // set the size of cp_inpins matrix 00738 // cp_inpins.resize(m_nDuct); 00739 for (int j=0; j<m_nDuct ; j++) 00740 cp_inpins.push_back(std::vector<iBase_EntityHandle>()); 00741 00742 } 00743 00744 void AssyGen::ReadPinCellData (int i) 00745 //--------------------------------------------------------------------------- 00746 //Function: reading pincell i from file and storing the data 00747 //Input: none 00748 //Output: none 00749 //--------------------------------------------------------------------------- 00750 { 00751 CParser Parse; 00752 std::string card, szVolId, szVolAlias, szIFlag; 00753 int nInputLines, nMaterials, nCyl = 0, nRadii=0, nCellMat=0; 00754 double dLZ=0.0, dFlatF=0.0, dPX=0.0, dPY=0.0, dPZ=0.0; 00755 CVector <std::string> szVMatName, szVMatAlias, szVCylMat, szVCellMat; 00756 CVector<double> dVCoor(2), dVCylRadii, dVCylZPos, dZVStart, dZVEnd; 00757 00758 //loop over input lines 00759 if (m_szGeomType == "rectangular"){ 00760 00761 std::cout << "\ngetting volume id"; 00762 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 00763 MAXCHARS, szComment)) 00764 IOErrorHandler (INVALIDINPUT); 00765 std::istringstream szFormatString (szInputString); 00766 szFormatString >> szVolId >> szVolAlias >> nInputLines >> szIFlag; 00767 00768 // error checking 00769 if( (strcmp (szVolAlias.c_str(), "") == 0) || 00770 (strcmp (szVolId.c_str(), "") == 0)) 00771 IOErrorHandler(EPIN); 00772 if( nInputLines < 0 ) 00773 IOErrorHandler(ENEGATIVE); 00774 00775 m_Pincell(i).SetLineOne (szVolId, szVolAlias, nInputLines); 00776 if(szIFlag == "intersect"){ 00777 m_Pincell(i).SetIntersectFlag(1); 00778 } 00779 else{ 00780 m_Pincell(i).SetIntersectFlag(0); 00781 } 00782 for(int l=1; l<=nInputLines; l++){ 00783 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 00784 MAXCHARS, szComment)) 00785 IOErrorHandler (INVALIDINPUT); 00786 if (szInputString.substr(0,5) == "pitch"){ 00787 00788 std::istringstream szFormatString (szInputString); 00789 std::cout << "\ngetting pitch data"; 00790 szFormatString >> card >> dPX >> dPY >> dPZ; 00791 00792 if( dPX < 0 || dPY < 0 || dPZ < 0 || szFormatString.fail()) 00793 IOErrorHandler(ENEGATIVE); 00794 m_Pincell(i).SetPitch (dPX, dPY, dPZ); 00795 } 00796 if (szInputString.substr(0,9) == "materials"){ 00797 00798 std::istringstream szFormatString (szInputString); 00799 szFormatString >> card >> nMaterials; 00800 if(szFormatString.fail()) 00801 IOErrorHandler(INVALIDINPUT); 00802 00803 //setting local arrays 00804 szVMatName.SetSize(nMaterials); 00805 szVMatAlias.SetSize(nMaterials); 00806 00807 //set class variable sizes 00808 m_Pincell(i).SetMatArray(nMaterials); 00809 std::cout << "\ngetting material data"; 00810 for(int j=1; j<= nMaterials; j++){ 00811 szFormatString >> szVMatName(j) >> szVMatAlias(j); 00812 if(szFormatString.fail()) 00813 IOErrorHandler(INVALIDINPUT); 00814 } 00815 m_Pincell(i).SetMat(szVMatName, szVMatAlias); 00816 } 00817 if (szInputString.substr(0,8) == "cylinder"){ 00818 00819 ++nCyl; 00820 std::cout << "\ngetting cylinder data"; 00821 std::istringstream szFormatString (szInputString); 00822 szFormatString >> card >> nRadii >> dVCoor(1) >> dVCoor(2); 00823 if(szFormatString.fail()) 00824 IOErrorHandler(INVALIDINPUT); 00825 m_Pincell(i).SetCylSizes(nCyl, nRadii); 00826 m_Pincell(i).SetCylPos(nCyl, dVCoor); 00827 m_Pincell(i).SetCellType(nCyl, 0); 00828 00829 //set local array 00830 dVCylRadii.SetSize(2*nRadii); 00831 szVCylMat.SetSize(nRadii); 00832 dVCylZPos.SetSize(2); 00833 m_Pincell(i).SetCylSizes(nCyl, nRadii); 00834 00835 // reading ZCoords 00836 for(int k=1; k<=2; k++){ 00837 szFormatString >> dVCylZPos(k); 00838 if(szFormatString.fail()) 00839 IOErrorHandler(INVALIDINPUT); 00840 } 00841 m_Pincell(i).SetCylZPos(nCyl, dVCylZPos); 00842 00843 // reading Radii 00844 for(int l=1; l<= nRadii; l++){ 00845 szFormatString >> dVCylRadii(l); 00846 if( dVCylRadii(l) < 0 || szFormatString.fail()) 00847 IOErrorHandler(ENEGATIVE); 00848 } 00849 m_Pincell(i).SetCylRadii(nCyl, dVCylRadii); 00850 00851 // reading Material alias 00852 for(int m=1; m<= nRadii; m++){ 00853 szFormatString >> szVCylMat(m); 00854 if(strcmp (szVCylMat(m).c_str(), "") == 0 || szFormatString.fail()) 00855 IOErrorHandler(EALIAS); 00856 // setting stuff for hole scheme determination for meshing 00857 if (m > 1 && m_szMeshScheme == "hole" && m_nBLAssemblyMat == 0){ 00858 // find material name for this alias 00859 for (int ll=1; ll<= m_nAssemblyMat; ll++){ 00860 if(szVCylMat(m) == m_szAssmMatAlias(ll)){ 00861 00862 #ifdef HAVE_RGG16 00863 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top*'" << std::endl; 00864 #else 00865 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top'" << std::endl; 00866 #endif 00867 } 00868 } 00869 } 00870 m_Pincell(i).SetCylMat(nCyl, szVCylMat); 00871 } 00872 } 00873 if (szInputString.substr(0,7) == "frustum"){ 00874 00875 ++nCyl; 00876 std::cout << "\ngetting frustum data"; 00877 std::istringstream szFormatString (szInputString); 00878 szFormatString >> card >> nRadii >> dVCoor(1) >> dVCoor(2); 00879 if(szFormatString.fail()) 00880 IOErrorHandler(INVALIDINPUT); 00881 m_Pincell(i).SetCylSizes(nCyl, nRadii); 00882 m_Pincell(i).SetCylPos(nCyl, dVCoor); 00883 m_Pincell(i).SetCellType(nCyl, 1); 00884 00885 //set local array 00886 dVCylRadii.SetSize(2*nRadii); 00887 szVCylMat.SetSize(nRadii); 00888 dVCylZPos.SetSize(2); 00889 m_Pincell(i).SetCylSizes(nCyl, nRadii); 00890 00891 // reading ZCoords 00892 for(int k=1; k<=2; k++){ 00893 szFormatString >> dVCylZPos(k); 00894 if(szFormatString.fail()) 00895 IOErrorHandler(INVALIDINPUT); 00896 } 00897 m_Pincell(i).SetCylZPos(nCyl, dVCylZPos); 00898 00899 // reading Radii 00900 for(int l=1; l<= 2*nRadii; l++){ 00901 szFormatString >> dVCylRadii(l); 00902 if( dVCylRadii(l) < 0 || szFormatString.fail()) 00903 IOErrorHandler(ENEGATIVE); 00904 } 00905 m_Pincell(i).SetCylRadii(nCyl, dVCylRadii); 00906 00907 // reading Material alias 00908 for(int m=1; m<= nRadii; m++){ 00909 szFormatString >> szVCylMat(m); 00910 if(strcmp (szVCylMat(m).c_str(), "") == 0 || szFormatString.fail()) 00911 IOErrorHandler(EALIAS); 00912 // setting stuff for hole scheme determination for meshing 00913 if (m > 2 && m_szMeshScheme == "hole"){ 00914 // find material name for this alias 00915 for (int ll=1; ll<= m_nAssemblyMat; ll++){ 00916 if(szVCylMat(m) == m_szAssmMatAlias(ll)){ 00917 #ifdef HAVE_RGG16 00918 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top*'" << std::endl; 00919 #else 00920 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top'" << std::endl; 00921 #endif 00922 } 00923 } 00924 } 00925 } 00926 m_Pincell(i).SetCylMat(nCyl, szVCylMat); 00927 } 00928 if (szInputString.substr(0,12) == "cellmaterial"){ 00929 00930 std::cout << "\ngetting cell material data\n"; 00931 std::istringstream szFormatString (szInputString); 00932 szFormatString >> card; 00933 00934 //set local arrays 00935 m_Pincell(i).GetCellMatSize(nCellMat); // since size of cell material already set equal to number of cylinders 00936 dZVStart.SetSize(nCellMat); 00937 dZVEnd.SetSize(nCellMat); 00938 szVCellMat.SetSize(nCellMat); 00939 00940 for(int k=1; k<=nCellMat; k++){ 00941 szFormatString >> dZVStart(k)>> dZVEnd(k) >> szVCellMat(k); 00942 if(strcmp (szVCellMat(k).c_str(), "") == 0 || szFormatString.fail()) 00943 IOErrorHandler(EALIAS); 00944 } 00945 m_Pincell(i).SetCellMat(dZVStart, dZVEnd, szVCellMat); 00946 } 00947 } 00948 }//if rectangular ends 00949 00950 if (m_szGeomType == "hexagonal"){ 00951 00952 std::cout << "\ngetting volume id"; 00953 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 00954 MAXCHARS, szComment)) 00955 IOErrorHandler (INVALIDINPUT); 00956 std::istringstream szFormatString (szInputString); 00957 szFormatString >> szVolId >> szVolAlias >> nInputLines >> szIFlag; 00958 00959 // error checking 00960 if( (strcmp (szVolAlias.c_str(), "") == 0) || 00961 (strcmp (szVolId.c_str(), "") == 0)) 00962 IOErrorHandler(EPIN); 00963 if( nInputLines < 0 ) 00964 IOErrorHandler(ENEGATIVE); 00965 00966 m_Pincell(i).SetLineOne (szVolId, szVolAlias, nInputLines); 00967 if(szIFlag == "intersect"){ 00968 m_Pincell(i).SetIntersectFlag(1); 00969 } 00970 else{ 00971 m_Pincell(i).SetIntersectFlag(0); 00972 } 00973 for(int l=1; l<=nInputLines; l++){ 00974 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 00975 MAXCHARS, szComment)) 00976 IOErrorHandler (INVALIDINPUT); 00977 if (szInputString.substr(0,5) == "pitch"){ 00978 00979 std::istringstream szFormatString (szInputString); 00980 std::cout << "\ngetting pitch data"; 00981 szFormatString >> card >> dFlatF >> dLZ; 00982 if( dFlatF < 0 || dLZ < 0 || szFormatString.fail()) 00983 IOErrorHandler(ENEGATIVE); 00984 m_Pincell(i).SetPitch (dFlatF, dLZ); 00985 } 00986 if (szInputString.substr(0,9) == "materials"){ 00987 00988 std::istringstream szFormatString (szInputString); 00989 szFormatString >> card >> nMaterials; 00990 if(szFormatString.fail()) 00991 IOErrorHandler(INVALIDINPUT); 00992 //setting local arrays 00993 szVMatName.SetSize(nMaterials); 00994 szVMatAlias.SetSize(nMaterials); 00995 00996 //set class variable sizes 00997 m_Pincell(i).SetMatArray(nMaterials); 00998 std::cout << "\ngetting material data"; 00999 for(int j=1; j<= nMaterials; j++){ 01000 szFormatString >> szVMatName(j) >> szVMatAlias(j); 01001 if(szFormatString.fail()) 01002 IOErrorHandler(INVALIDINPUT); 01003 } 01004 m_Pincell(i).SetMat(szVMatName, szVMatAlias); 01005 } 01006 if (szInputString.substr(0,8) == "cylinder"){ 01007 01008 ++nCyl; 01009 std::cout << "\ngetting cylinder data"; 01010 std::istringstream szFormatString (szInputString); 01011 szFormatString >> card >> nRadii >> dVCoor(1) >> dVCoor(2); 01012 if(szFormatString.fail()) 01013 IOErrorHandler(INVALIDINPUT); 01014 m_Pincell(i).SetCylSizes(nCyl, nRadii); 01015 m_Pincell(i).SetCylPos(nCyl, dVCoor); 01016 m_Pincell(i).SetCellType(nCyl, 0); 01017 01018 //set local array 01019 dVCylRadii.SetSize(2*nRadii); 01020 szVCylMat.SetSize(nRadii); 01021 dVCylZPos.SetSize(2); 01022 // 01023 m_Pincell(i).SetCylSizes(nCyl, nRadii); 01024 01025 // reading ZCoords - max and min 2 always 01026 for(int k=1; k<=2; k++) 01027 szFormatString >> dVCylZPos(k); 01028 m_Pincell(i).SetCylZPos(nCyl, dVCylZPos); 01029 01030 // reading Radii 01031 for(int l=1; l<= nRadii; l++){ 01032 szFormatString >> dVCylRadii(l); 01033 if( dVCylRadii(l) < 0 || szFormatString.fail()) 01034 IOErrorHandler(ENEGATIVE); 01035 } 01036 m_Pincell(i).SetCylRadii(nCyl, dVCylRadii); 01037 01038 // reading Material alias 01039 for(int m=1; m<= nRadii; m++){ 01040 szFormatString >> szVCylMat(m); 01041 if(strcmp (szVCylMat(m).c_str(), "") == 0 || szFormatString.fail()) 01042 IOErrorHandler(EALIAS); 01043 // setting stuff for hole scheme determination for meshing 01044 if (m > 1 && m_szMeshScheme == "hole" && m_nBLAssemblyMat == 0){ 01045 // find material name for this alias 01046 for (int ll=1; ll<= m_nAssemblyMat; ll++){ 01047 // if(szVCylMat(m) == m_szAssmMatAlias(ll)) 01048 if(strcmp (m_szAssmMatAlias(ll).c_str(), szVCylMat(m).c_str()) == 0){ 01049 #ifdef HAVE_RGG16 01050 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top*'" << std::endl; 01051 #else 01052 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top'" << std::endl; 01053 #endif 01054 } 01055 } 01056 } 01057 } 01058 01059 m_Pincell(i).SetCylMat(nCyl, szVCylMat); 01060 } 01061 if (szInputString.substr(0,7) == "frustum"){ 01062 01063 ++nCyl; 01064 std::cout << "\ngetting frustum data"; 01065 std::istringstream szFormatString (szInputString); 01066 szFormatString >> card >> nRadii >> dVCoor(1) >> dVCoor(2); 01067 if(szFormatString.fail()) 01068 IOErrorHandler(INVALIDINPUT); 01069 m_Pincell(i).SetCylSizes(nCyl, nRadii); 01070 m_Pincell(i).SetCylPos(nCyl, dVCoor); 01071 m_Pincell(i).SetCellType(nCyl, 1); 01072 01073 //set local array 01074 dVCylRadii.SetSize(2*nRadii); 01075 szVCylMat.SetSize(nRadii); 01076 dVCylZPos.SetSize(2); 01077 m_Pincell(i).SetCylSizes(nCyl, nRadii); 01078 01079 // reading ZCoords 01080 for(int k=1; k<=2; k++){ 01081 szFormatString >> dVCylZPos(k); 01082 if(szFormatString.fail()) 01083 IOErrorHandler(INVALIDINPUT); 01084 } 01085 m_Pincell(i).SetCylZPos(nCyl, dVCylZPos); 01086 01087 // reading Radii 01088 for(int l=1; l<= 2*nRadii; l++){ 01089 szFormatString >> dVCylRadii(l); 01090 if( dVCylRadii(l) < 0 || szFormatString.fail()) 01091 IOErrorHandler(ENEGATIVE); 01092 } 01093 m_Pincell(i).SetCylRadii(nCyl, dVCylRadii); 01094 01095 // reading Material alias 01096 for(int m=1; m<= nRadii; m++){ 01097 szFormatString >> szVCylMat(m); 01098 if(strcmp (szVCylMat(m).c_str(), "") == 0 || szFormatString.fail()) 01099 IOErrorHandler(EALIAS); 01100 // setting stuff for hole scheme determination for meshing 01101 if (m > 2 && m_szMeshScheme == "hole"){ 01102 // find material name for this alias 01103 for (int ll=1; ll<= m_nAssemblyMat; ll++){ 01104 if(szVCylMat(m) == m_szAssmMatAlias(ll)){ 01105 #ifdef HAVE_RGG16 01106 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top*'" << std::endl; 01107 #else 01108 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top'" << std::endl; 01109 #endif 01110 } 01111 } 01112 } 01113 } 01114 m_Pincell(i).SetCylMat(nCyl, szVCylMat); 01115 } 01116 if (szInputString.substr(0,12) == "cellmaterial"){ 01117 01118 std::cout << "\ngetting cell material data"; 01119 std::istringstream szFormatString (szInputString); 01120 szFormatString >> card; 01121 01122 //set local arrays 01123 m_Pincell(i).GetCellMatSize(nCellMat); // since size of cell material already set equal to number of cylinders 01124 dZVStart.SetSize(nCellMat); 01125 dZVEnd.SetSize(nCellMat); 01126 szVCellMat.SetSize(nCellMat); 01127 01128 for(int k=1; k<=nCellMat; k++){ 01129 szFormatString >> dZVStart(k)>> dZVEnd(k) >> szVCellMat(k); 01130 if(strcmp (szVCellMat(k).c_str(), "") == 0 || szFormatString.fail()) 01131 IOErrorHandler(EALIAS); 01132 } 01133 m_Pincell(i).SetCellMat(dZVStart, dZVEnd, szVCellMat); 01134 } 01135 } 01136 }// if hexagonal end 01137 01138 } 01139 01140 01141 void AssyGen::ReadAndCreate() 01142 //--------------------------------------------------------------------------- 01143 //Function: reads the input file and creates assembly 01144 //Input: none 01145 //Output: none 01146 //--------------------------------------------------------------------------- 01147 { 01148 //Rewind the input file 01149 m_FileInput.clear (std::ios_base::goodbit); 01150 m_FileInput.seekg (0L, std::ios::beg); 01151 m_nLineNumber = 0; 01152 CParser Parse; 01153 std::string card; 01154 01155 // start reading the input file break when encounter end 01156 for(;;){ 01157 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 01158 MAXCHARS, szComment)) 01159 IOErrorHandler (INVALIDINPUT); 01160 if (szInputString.substr(0,12) == "geometrytype"){ 01161 std::istringstream szFormatString (szInputString); 01162 szFormatString >> card >> m_szGeomType; 01163 if( ((strcmp (m_szGeomType.c_str(), "hexagonal") != 0) && 01164 (strcmp (m_szGeomType.c_str(), "rectangular") != 0)) || szFormatString.fail()) 01165 IOErrorHandler(EGEOMTYPE); 01166 01167 // set the number of sides in the geometry 01168 if(m_szGeomType == "hexagonal") 01169 m_nSides = 6; 01170 else if(m_szGeomType == "rectangular") 01171 m_nSides = 4; 01172 } 01173 01174 if (szInputString.substr(0,8) == "geometry"){ 01175 std::string outfile; 01176 std::istringstream szFormatString (szInputString); 01177 szFormatString >> card >> outfile; 01178 if(strcmp (outfile.c_str(), "surface") == 0 || szFormatString.fail()) 01179 m_nPlanar=1; 01180 } 01181 if( (szInputString.substr(0,10) == "dimensions") || 01182 (szInputString.substr(0,4) == "duct") ){ 01183 01184 ++m_nDuctNum; 01185 std::cout << "getting assembly dimensions " << m_nDuctNum << std::endl; 01186 01187 if(m_szGeomType =="hexagonal"){ 01188 std::istringstream szFormatString (szInputString); 01189 01190 if(m_nDuctNum == 1){ 01191 m_dMXYAssm.SetSize(m_nDuct, 2); m_dMZAssm.SetSize(m_nDuct, 2); 01192 } 01193 szFormatString >> card >> m_nDimensions 01194 >> m_dMXYAssm(m_nDuctNum, 1) >> m_dMXYAssm(m_nDuctNum, 2) 01195 >> m_dMZAssm(m_nDuctNum, 1) >> m_dMZAssm(m_nDuctNum, 2); 01196 if(m_nDuctNum == 1){ 01197 m_dMAssmPitch.SetSize(m_nDuct, m_nDimensions); m_szMMAlias.SetSize(m_nDuct, m_nDimensions); 01198 01199 assms.resize(m_nDimensions*m_nDuct); // setup while reading the problem size 01200 // Declaration for python script 01201 m_PyCubGeomFile << "assms = range(" << m_nDimensions*m_nDuct << ")\ncp_inpins = []\n" << std::endl; 01202 } 01203 01204 for (int i=1; i<=m_nDimensions; i++){ 01205 szFormatString >> m_dMAssmPitch(m_nDuctNum, i); 01206 if( m_dMAssmPitch(m_nDuctNum, i) < 0 ) 01207 IOErrorHandler(ENEGATIVE); 01208 } 01209 01210 for (int i=1; i<=m_nDimensions; i++){ 01211 szFormatString >> m_szMMAlias(m_nDuctNum, i); 01212 if(strcmp (m_szMMAlias(m_nDuctNum, i).c_str(), "") == 0) 01213 IOErrorHandler(EALIAS); 01214 m_szDuctMats.push_back(m_szMMAlias(m_nDuctNum, i)); 01215 // this is the innermost duct add to group for journaling later 01216 if (i==1){ 01217 // find material name for this alias 01218 for (int ll=1; ll<= m_nAssemblyMat; ll++){ 01219 // if(szVCylMat(m) == m_szAssmMatAlias(ll)) 01220 if(strcmp (m_szAssmMatAlias(ll).c_str(), m_szMMAlias(m_nDuctNum, i).c_str()) == 0){ 01221 #ifdef HAVE_RGG16 01222 m_FileOutput << "group 'innerduct' add surface with name '"<< m_szAssmMat(ll) << "_top*'" << std::endl; 01223 #else 01224 m_FileOutput << "group 'innerduct' add surface with name '"<< m_szAssmMat(ll) << "_top'" << std::endl; 01225 #endif 01226 } 01227 } 01228 } 01229 // setting stuff for hole scheme determination for meshing 01230 if (i > 1 && m_szMeshScheme == "hole"){ 01231 // find material name for this alias 01232 for (int ll=1; ll<= m_nAssemblyMat; ll++){ 01233 // if(szVCylMat(m) == m_szAssmMatAlias(ll)) 01234 if(strcmp (m_szAssmMatAlias(ll).c_str(), m_szMMAlias(m_nDuctNum, i).c_str()) == 0) 01235 #ifdef HAVE_RGG16 01236 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top*'" << std::endl; 01237 #else 01238 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top'" << std::endl; 01239 #endif 01240 } 01241 } 01242 } 01243 } 01244 if(m_szGeomType =="rectangular"){ 01245 std::istringstream szFormatString (szInputString); 01246 if(m_nDuctNum == 1){ 01247 m_dMXYAssm.SetSize(m_nDuct, 2); 01248 m_dMZAssm.SetSize(m_nDuct, 2); 01249 } 01250 szFormatString >> card >> m_nDimensions 01251 >> m_dMXYAssm(m_nDuctNum, 1) >> m_dMXYAssm(m_nDuctNum, 2) 01252 >> m_dMZAssm(m_nDuctNum, 1) >> m_dMZAssm(m_nDuctNum, 2); 01253 if (szFormatString.fail()) 01254 IOErrorHandler(INVALIDINPUT); 01255 if(m_nDuctNum == 1){ 01256 m_dMAssmPitchX.SetSize(m_nDuct, m_nDimensions); 01257 m_dMAssmPitchY.SetSize(m_nDuct, m_nDimensions); 01258 m_szMMAlias.SetSize(m_nDuct, m_nDimensions); 01259 assms.resize(m_nDimensions*m_nDuct); 01260 // Declaration for python script 01261 m_PyCubGeomFile << "assms = range(" << m_nDimensions*m_nDuct << ")\ncp_inpins = []\n" << std::endl; 01262 } 01263 for (int i=1; i<=m_nDimensions; i++){ 01264 szFormatString >> m_dMAssmPitchX(m_nDuctNum, i) >> m_dMAssmPitchY(m_nDuctNum, i); 01265 if( m_dMAssmPitchX(m_nDuctNum, i) < 0 || m_dMAssmPitchY(m_nDuctNum, i) < 0 || szFormatString.fail()) 01266 IOErrorHandler(ENEGATIVE); 01267 } 01268 01269 for (int i=1; i<=m_nDimensions; i++){ 01270 szFormatString >> m_szMMAlias(m_nDuctNum, i); 01271 if(strcmp (m_szMMAlias(m_nDuctNum, i).c_str(), "") == 0 || szFormatString.fail()) 01272 IOErrorHandler(EALIAS); 01273 m_szDuctMats.push_back(m_szMMAlias(m_nDuctNum, i)); 01274 // this is the innermost duct 01275 if (i==1){ 01276 // find material name for this alias 01277 for (int ll=1; ll<= m_nAssemblyMat; ll++){ 01278 // if(szVCylMat(m) == m_szAssmMatAlias(ll)) 01279 if(strcmp (m_szAssmMatAlias(ll).c_str(), m_szMMAlias(m_nDuctNum, i).c_str()) == 0){ 01280 #ifdef HAVE_RGG16 01281 m_FileOutput << "group 'innerduct' add surface with name '"<< m_szAssmMat(ll) << "_top*'" << std::endl; 01282 #else 01283 m_FileOutput << "group 'innerduct' add surface with name '"<< m_szAssmMat(ll) << "_top'" << std::endl; 01284 #endif 01285 } 01286 } 01287 } 01288 // setting stuff for hole scheme determination for meshing 01289 if (i > 1 && m_szMeshScheme == "hole"){ 01290 // find material name for this alias 01291 for (int ll=1; ll<= m_nAssemblyMat; ll++){ 01292 // if(szVCylMat(m) == m_szAssmMatAlias(ll)) 01293 if(strcmp (m_szAssmMatAlias(ll).c_str(), m_szMMAlias(m_nDuctNum, i).c_str()) == 0){ 01294 #ifdef HAVE_RGG16 01295 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top*'" << std::endl; 01296 #else 01297 m_FileOutput << "group 'hole_surfaces' add surface with name '"<< m_szAssmMat(ll) << "_top'" << std::endl; 01298 #endif 01299 } 01300 } 01301 } 01302 } 01303 } 01304 } 01305 if (szInputString.substr(0,8) == "pincells"){ 01306 std::istringstream szFormatString (szInputString); 01307 01308 szFormatString >> card >> m_nPincells >> m_dPitch; 01309 if(m_nPincells < 0) 01310 IOErrorHandler(ENEGATIVE); 01311 01312 // this is an option if a user wants to specify pitch here 01313 double dTotalHeight = 0.0; 01314 01315 //get the number of cylinder in each pincell 01316 int nTemp = 1; 01317 if(m_nDimensions > 0){ 01318 dTotalHeight = m_dMZAssm(nTemp, 2)-m_dMZAssm(nTemp, 1); 01319 } 01320 else{ 01321 dTotalHeight = 0; // nothing specified only pincells in the model 01322 } 01323 01324 // loop thro' the pincells and read/store pincell data 01325 for (int i=1; i<=m_nPincells; i++){ 01326 01327 // set pitch if specified in pincell card 01328 if(m_dPitch > 0.0) 01329 m_Pincell(i).SetPitch(m_dPitch, dTotalHeight); 01330 01331 ReadPinCellData(i); 01332 //ERRORR("Error in ReadPinCellData", err); 01333 std::cout << "\nread pincell " << i << std::endl; 01334 } 01335 } 01336 if (szInputString.substr(0,8) == "assembly"){ 01337 if(m_szGeomType =="hexagonal"){ 01338 Create_HexAssm(szInputString); 01339 //ERRORR("Error in Create_HexAssm", err); 01340 } 01341 if(m_szGeomType =="rectangular"){ 01342 Create_CartAssm(szInputString); 01343 //ERRORR("Error in Create_CartAssm", err); 01344 } 01345 if (m_nJouFlag == 0){ 01346 CreateOuterCovering(); 01347 //ERRORR("Error in CreateOuterCovering", err); 01348 01349 // subtract pins before save 01350 if(m_nDuct > 0){ 01351 Subtract_Pins(); 01352 clock_t s_subtract = clock(); 01353 std::cout << "## Subract Pins CPU time used := " << (double) (clock() - s_subtract)/CLOCKS_PER_SEC 01354 << " seconds" << std::endl; 01355 } 01356 } 01357 } 01358 01359 // section the assembly as described in section card 01360 if (szInputString.substr(0,7) == "section" && m_nJouFlag == 0){ 01361 std::cout << "Sectioning geometry .." << std::endl; 01362 char cDir; 01363 double dOffset; 01364 std::string szReverse = ""; 01365 std::istringstream szFormatString (szInputString); 01366 szFormatString >> card >> cDir >> dOffset >> szReverse; 01367 Section_Assm(cDir, dOffset, szReverse); 01368 m_PyCubGeomFile << "section_assm(\"" << cDir << "\", " << dOffset << ", \"" << szReverse << "\")" << std::endl; 01369 //ERRORR("Error in Section_Assm", err); 01370 std::cout <<"--------------------------------------------------"<<std::endl; 01371 01372 } 01373 if (szInputString.substr(0,4) == "move" && m_nJouFlag == 0){ 01374 std::cout << "Moving geometry .." << std::endl; 01375 double dX, dY, dZ; 01376 std::istringstream szFormatString (szInputString); 01377 szFormatString >> card >> dX >> dY >> dZ; 01378 if(szFormatString.fail()) 01379 IOErrorHandler(INVALIDINPUT); 01380 Move_Assm(dX, dY, dZ); 01381 //ERRORR("Error in Move_Assm", err); 01382 std::cout <<"--------------------------------------------------"<<std::endl; 01383 01384 } 01385 // center the assembly 01386 if (szInputString.substr(0,6) == "center" && m_nJouFlag == 0){ 01387 01388 char rDir = 'q'; 01389 std::istringstream szFormatString (szInputString); 01390 szFormatString >> card >> rDir; 01391 if (rDir != 'q') 01392 std::cout << "Positioning assembly to "<< rDir << " center" << std::endl; 01393 else 01394 std::cout << "Positioning assembly to xy center" << std::endl; 01395 Center_Assm(rDir); 01396 //ERRORR("Error in Center_Assm", err); 01397 std::cout <<"--------------------------------------------------"<<std::endl; 01398 } 01399 // rotate the assembly if rotate card is specified 01400 if (szInputString.substr(0,6) == "rotate" && m_nJouFlag == 0){ 01401 char cDir; 01402 double dAngle; 01403 std::cout << "Rotating geometry .." << std::endl; 01404 std::istringstream szFormatString (szInputString); 01405 szFormatString >> card >> cDir >> dAngle; 01406 if(szFormatString.fail()) 01407 IOErrorHandler(INVALIDINPUT); 01408 Rotate_Assm(cDir, dAngle); 01409 //ERRORR("Error in Rotate_Assm", err); 01410 std::cout <<"--------------------------------------------------"<<std::endl; 01411 01412 } 01413 // 'yes' or 'no' for creating sidesets 01414 if (szInputString.substr(0,13) == "createsideset"){ 01415 std::istringstream szFormatString (szInputString); 01416 szFormatString >> card >> m_szSideset; 01417 std::cout <<"--------------------------------------------------"<<std::endl; 01418 } 01419 // Create specified number of files with varying material ids 01420 if (szInputString.substr(0,11) == "createfiles"){ 01421 std::istringstream szFormatString (szInputString); 01422 szFormatString >> card >> m_nAssyGenInputFiles; 01423 std::cout <<"--------------------------------------------------"<<std::endl; 01424 } 01425 // Create specified number of files with varying material ids 01426 if (szInputString.substr(0,14) == "creatematfiles"){ 01427 m_bCreateMatFiles = true; 01428 std::istringstream szFormatString (szInputString); 01429 szFormatString >> card >> m_nAssyGenInputFiles; 01430 std::cout <<"--------------------------------------------------"<<std::endl; 01431 } 01432 // Create specified number of files with varying material ids 01433 if (szInputString.substr(0,11) == "save_exodus"){ 01434 save_exodus = true; 01435 std::cout <<"--------------------------------------------------"<<std::endl; 01436 } 01437 // specify a merge tolerance value for cubit journal file 01438 if (szInputString.substr(0,14) == "mergetolerance"){ 01439 std::istringstream szFormatString (szInputString); 01440 szFormatString >> card >> m_dMergeTol; 01441 std::cout <<"--------------------------------------------------"<<std::endl; 01442 } 01443 // Handle mesh size inputs 01444 if (szInputString.substr(0,14) == "radialmeshsize"){ 01445 std::istringstream szFormatString (szInputString); 01446 szFormatString >> card >> m_dRadialSize; 01447 if(m_dRadialSize < 0 || szFormatString.fail()) 01448 IOErrorHandler(ENEGATIVE); 01449 std::cout <<"--------------------------------------------------"<<std::endl; 01450 01451 } 01452 // Handle mesh size inputs 01453 if (szInputString.substr(0,11) == "tetmeshsize"){ 01454 std::istringstream szFormatString (szInputString); 01455 szFormatString >> card >> m_dTetMeshSize; 01456 if(m_dTetMeshSize < 0 || szFormatString.fail()) 01457 IOErrorHandler(ENEGATIVE); 01458 std::cout <<"--------------------------------------------------"<<std::endl; 01459 01460 } 01461 // Handle mesh size inputs 01462 if (szInputString.substr(0,13) == "axialmeshsize"){ 01463 std::istringstream szFormatString (szInputString); 01464 szFormatString >> card; 01465 if(m_nDuct > 0){ 01466 m_dAxialSize.SetSize(m_nDuct); 01467 int num_ams_specified = std::distance(std::istream_iterator<std::string>(szFormatString), 01468 std::istream_iterator<std::string>()); 01469 std::istringstream szFormatStringAgain (szInputString); 01470 szFormatStringAgain >> card; 01471 for (int p = 1; p <= m_nDuct; p++){ 01472 if(p <= num_ams_specified) 01473 szFormatStringAgain >> m_dAxialSize(p); 01474 else 01475 m_dAxialSize(p) = m_dAxialSize(num_ams_specified); 01476 if(m_dAxialSize(p) < 0) 01477 IOErrorHandler(ENEGATIVE); 01478 } 01479 } 01480 else{ 01481 m_dAxialSize.SetSize(1); 01482 szFormatString >> m_dAxialSize(1); 01483 } 01484 std::cout <<"--------------------------------------------------"<<std::endl; 01485 01486 } 01487 // edge interval 01488 if (szInputString.substr(0, 12) == "edgeinterval") { 01489 std::istringstream szFormatString(szInputString); 01490 szFormatString >> card >> m_edgeInterval; 01491 } 01492 // Handle mesh size inputs 01493 if (szInputString.substr(0,18) == "neumannset_startid"){ 01494 std::istringstream szFormatString (szInputString); 01495 szFormatString >> card >> m_nNeumannSetId; 01496 if(m_nNeumannSetId < 0 || szFormatString.fail()) 01497 IOErrorHandler(ENEGATIVE); 01498 std::cout <<"--------------------------------------------------"<<std::endl; 01499 01500 } 01501 // Handle mesh size inputs 01502 if (szInputString.substr(0,19) == "materialset_startid"){ 01503 std::istringstream szFormatString (szInputString); 01504 szFormatString >> card >> m_nMaterialSetId; 01505 if(m_nMaterialSetId < 0 || szFormatString.fail()) 01506 IOErrorHandler(ENEGATIVE); 01507 std::cout <<"--------------------------------------------------"<<std::endl; 01508 01509 } 01510 if ((szInputString.substr(0,23) == "list_neumannset_startid") ){ 01511 std::istringstream szFormatString (szInputString); 01512 int num_nset_ids = 0; 01513 szFormatString >> card >> num_nset_ids; 01514 m_nListNeuSet.SetSize(num_nset_ids); 01515 for (int p = 1; p <= num_nset_ids; p++){ 01516 szFormatString >> m_nListNeuSet(p); 01517 if(m_nListNeuSet(p) < 0 || szFormatString.fail()) 01518 IOErrorHandler(ENEGATIVE); 01519 } 01520 } 01521 if ((szInputString.substr(0,14) == "numsuperblocks") ){ 01522 std::istringstream szFormatString (szInputString); 01523 szFormatString >> card >> m_nSuperBlocks; 01524 sb.SetSize(m_nSuperBlocks); 01525 } 01526 if ((szInputString.substr(0,10) == "superblock") ){ 01527 std::istringstream szFormatString (szInputString); 01528 szFormatString >> card >> sb(tmpSB).m_nSuperBlockId >> sb(tmpSB).m_szSuperBlockAlias >> sb(tmpSB).m_nNumSBContents; 01529 sb(tmpSB).m_nSBContents.SetSize(sb(tmpSB).m_nNumSBContents); 01530 for (int p = 1; p <= sb(tmpSB).m_nNumSBContents; p++){ 01531 szFormatString >> sb(tmpSB).m_nSBContents(p); 01532 if(sb(tmpSB).m_nSBContents(p) < 0 || szFormatString.fail()) 01533 IOErrorHandler(ENEGATIVE); 01534 } 01535 ++tmpSB; 01536 } 01537 if ((szInputString.substr(0,24) == "list_materialset_startid") ){ 01538 std::istringstream szFormatString (szInputString); 01539 int num_mset_ids = 0; 01540 szFormatString >> card >> num_mset_ids; 01541 m_nListMatSet.SetSize(num_mset_ids); 01542 for (int p = 1; p <= num_mset_ids; p++){ 01543 szFormatString >> m_nListMatSet(p); 01544 if(m_nListMatSet(p) < 0 || szFormatString.fail()) 01545 IOErrorHandler(ENEGATIVE); 01546 } 01547 } 01548 if (szInputString.substr(0,3) == "end" || m_nLineNumber == MAXLINES){ 01549 // if this is a surface only case, delete all the volume entities create so far 01550 if(m_nPlanar ==1){ 01551 Create2DSurf(); 01552 } 01553 if ( m_nJouFlag == 0){ 01554 // impring merge before saving 01555 Imprint_Merge(m_bimprint, m_bmerge); 01556 01557 clock_t s_save= clock(); 01558 // save .sat file 01559 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 01560 iGeom_save(igeomImpl->instance(), m_szGeomFile.c_str(), NULL, &err, m_szGeomFile.length() , 0); 01561 #endif 01562 01563 std::cout << "## Saving CPU time used := " << (double) (clock() - s_save)/CLOCKS_PER_SEC 01564 << " seconds" << std::endl; 01565 01566 m_PyCubGeomFile << "cubit.cmd('export acis \"" <<m_szGeomFile1 << "\" over')\nexit()" << std::endl; 01567 01568 std::cout << "Normal Termination.\n"<< "Geometry file: " << m_szGeomFile << " saved." << std::endl; 01569 // // Now run the journal file from the python script 01570 // m_PyCubGeomFile << "infile = open(\""<< m_szJouFile << "\", \"r\")" << std::endl; 01571 // m_PyCubGeomFile << "for line in infile:\n cubit.cmd(line)" << std::endl; 01572 01573 // Reloading file to check load times 01574 bool if_loadagain = false; 01575 if (if_loadagain == true){ 01576 clock_t s_load= clock(); 01577 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 01578 iGeom_load(igeomImpl->instance(), m_szGeomFile.c_str(), NULL, &err, 01579 strlen(m_szGeomFile.c_str()), 0); 01580 #endif 01581 std::cout << "## Load again CPU time used := " << (double) (clock() - s_load)/CLOCKS_PER_SEC 01582 << " seconds" << std::endl; 01583 } 01584 } 01585 break; 01586 } 01587 } 01588 01589 } 01590 01591 void AssyGen::CreateAssyGenInputFiles() 01592 //--------------------------------------------------------------------------- 01593 //Function: Create Cubit Journal File for generating mesh 01594 //Input: none 01595 //Output: none 01596 //--------------------------------------------------------------------------- 01597 { 01598 // create file names 01599 std::ostringstream os; 01600 std::string file, temp, temp1; 01601 int counter_ms = 0; 01602 int counter_ns = 0; 01603 for(int i=1; i<=m_nAssyGenInputFiles; i++){ 01604 // form the name of the AssyGen input file 01605 if(m_bCreateMatFiles) 01606 os << m_nListMatSet(i) << ".inp"; 01607 else 01608 os << m_szFile << i << ".inp"; 01609 std::ofstream ofs; 01610 // open input file 01611 01612 std::cout << os.str() << std::endl; 01613 bool bDone = false; 01614 do{ 01615 file = os.str(); 01616 ofs.open (file.c_str(), std::ios::out); 01617 if(!ofs){ 01618 ofs.clear(); 01619 std::cout << "Unable to open AssyGen Input File(s) for writing" << std::endl; 01620 exit(1); 01621 } 01622 else { 01623 bDone = true; 01624 std::cout << "File Opened" << std::endl; 01625 } 01626 os.str(""); 01627 01628 // write the input deck 01629 ofs << "! ## This is an automatically created AssyGen Input File: "<< file << std::endl; 01630 ofs << "MeshType " << m_szMeshType << std::endl; 01631 ofs << "GeomEngine " << m_szEngine << std::endl; 01632 ofs << "GeometryType " << m_szGeomType << std::endl; 01633 ofs << "Materials " << m_nAssemblyMat; 01634 01635 // list all materials and alias with subscripts 01636 for (int j =1;j<=m_nAssemblyMat; j++){ 01637 if(!m_bCreateMatFiles){ 01638 os << m_szAssmMat(j) << "_" << (i-1)*m_nAssemblyMat + j; 01639 temp = os.str(); 01640 01641 ofs << " " << temp << " " << m_szAssmMatAlias(j); 01642 os.str(""); 01643 } 01644 else{ 01645 ofs << " " << m_szAssmMat(j) << " " << m_szAssmMatAlias(j); 01646 } 01647 } 01648 ofs << "\n"; 01649 01650 //Rewind the input file 01651 int nDumpAllLinesAfter = 0, nMid = 0; 01652 m_FileInput.clear (std::ios_base::goodbit); 01653 m_FileInput.seekg (0L, std::ios::beg); 01654 m_nLineNumber = 0; 01655 CParser Parse; 01656 std::string card; 01657 01658 // start reading the input file break when encounter end 01659 for(;;){ 01660 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 01661 MAXCHARS, szComment)) 01662 IOErrorHandler (INVALIDINPUT); 01663 // dump all the lines after duct command, limiting the format for writing AssyGen Files 01664 if( (szInputString.substr(0,10) == "dimensions") || 01665 (szInputString.substr(0,4) == "duct") ){ 01666 ofs << szInputString << std::endl; 01667 nDumpAllLinesAfter = m_nLineNumber; 01668 } 01669 else if ((szInputString.substr(0,19) == "materialset_startid") ){ 01670 nMid = (i-1)*m_nAssemblyMat + 1; 01671 ofs << "MaterialSet_StartId " << nMid << std::endl; 01672 } 01673 else if ((szInputString.substr(0,18) == "neumannset_startid") ){ 01674 nMid = (i-1)*m_nAssemblyMat + 1; 01675 ofs << "NeumannSet_StartId " << nMid << std::endl; 01676 } 01677 else if ((szInputString.substr(0,24) == "list_materialset_startid") ){ 01678 ++counter_ms; 01679 ofs << "MaterialSet_StartId " << m_nListMatSet(counter_ms) << std::endl; 01680 } 01681 else if ((szInputString.substr(0,23) == "list_neumannset_startid") ){ 01682 ++counter_ns; 01683 ofs << "NeumannSet_StartId " << m_nListNeuSet(counter_ns) << std::endl; 01684 } 01685 else if((szInputString.substr(0,11) == "createfiles")){ 01686 //skip this line 01687 } 01688 else if((szInputString.substr(0,14) == "creatematfiles")){ 01689 //skip this line 01690 } 01691 else if (nDumpAllLinesAfter > 0 && m_nLineNumber > nDumpAllLinesAfter){ 01692 ofs << szInputString << std::endl; 01693 } 01694 01695 if (szInputString.substr(0,3) == "end" || m_nLineNumber == MAXLINES){ 01696 break; 01697 } 01698 } 01699 ofs.close(); 01700 } while(!bDone); 01701 } 01702 01703 01704 01705 } 01706 01707 void AssyGen:: ComputePinCentroid(int nTempPin, CMatrix<std::string> MAssembly, 01708 int m, int n, double &dX, double &dY, double &dZ) 01709 // --------------------------------------------------------------------------- 01710 // Function: computes the centroid in the whole assembly of rectangular or hexagonal pincell 01711 // Input: number and location of the pincell 01712 // Output: coordinates of pin in assembly 01713 // --------------------------------------------------------------------------- 01714 { 01715 int nTempPin1 = -1, nTempPin2 = 0, nInputLines; 01716 std::string szVolId, szVolAlias; 01717 if(m_szGeomType == "hexagonal"){ 01718 double dP, dZ; 01719 m_Pincell(nTempPin).GetPitch(dP, dZ); 01720 01721 if (m < m_nPin){ 01722 dX = (m_nPin - n + 1)*dP/2.0 + n*dP/2.0 + (n-1)*dP - (m-1)*dP/2.0; 01723 dY = (m-1)*(0.5*dP/sin(pi/3.0) + 0.5*dP*sin(pi/6.0)/sin(pi/3.0)); 01724 } 01725 else{ 01726 dX = (m_nPin - n + 1)*dP/2.0 + n*dP/2.0 + (n-1)*dP - (2*m_nPin - m -1)*dP/2.0; 01727 dY = (m-1)*(0.5*dP/sin(pi/3.0) + 0.5*dP*sin(pi/6.0)/sin(pi/3.0)); 01728 } 01729 } 01730 if(m_szGeomType == "rectangular"){ 01731 double dPX, dPY, dPZ, dPX1, dPY1, dPZ1, dPX2, dPY2, dPZ2; 01732 if((m_Assembly(m,n)=="x")||(m_Assembly(m,n)=="xx")) 01733 m_Pincell(1).GetPitch(dPX, dPY, dPZ); 01734 else 01735 m_Pincell(nTempPin).GetPitch(dPX, dPY, dPZ); 01736 01737 if (n==1){ 01738 dX = 0; 01739 if(m==1) 01740 dY = 0; 01741 } 01742 else{ 01743 dX+= dPX/2.0; 01744 // find the previous pincell type 01745 // check if it's dummy 01746 if((m_Assembly(m,n-1)=="x")||(m_Assembly(m,n-1)=="xx")){ 01747 dX+=dPX/2.0; 01748 } 01749 else{ 01750 for(int b=1; b<=m_nPincells; b++){ 01751 m_Pincell(b).GetLineOne(szVolId, szVolAlias, nInputLines); 01752 if(m_Assembly(m,n-1) == szVolAlias) 01753 nTempPin1 = b; 01754 } 01755 if(nTempPin1 == -1){ 01756 std::cout << "Unknown pincell, pincell " << m_Assembly(m,n-1) << " not declared" << std::endl; 01757 exit(1); 01758 } 01759 m_Pincell(nTempPin1).GetPitch(dPX1, dPY1, dPZ1); 01760 // now add half of X pitch to the previous cells pitch 01761 dX+= dPX1/2.0; 01762 } 01763 } 01764 if (m > 1 && n==1){ 01765 dY+= dPY/2.0; 01766 // check if it's dummy 01767 if((m_Assembly(m-1,n)=="x")||(m_Assembly(m-1,n)=="xx")){ 01768 dY+= dPY/2.0; 01769 } 01770 else{ 01771 for(int c=1; c<=m_nPincells; c++){ 01772 m_Pincell(c).GetLineOne(szVolId, szVolAlias, nInputLines); 01773 if(m_Assembly(m-1,n) == szVolAlias) 01774 nTempPin2 = c; 01775 } 01776 m_Pincell(nTempPin2).GetPitch(dPX2, dPY2, dPZ2); 01777 dY+= dPY2/2.0; 01778 } 01779 } 01780 dZ = 0.0; // moving in XY plane only 01781 }//if rectangular ends 01782 01783 } 01784 01785 void AssyGen::IOErrorHandler (ErrorStates ECode) const 01786 // --------------------------------------------------------------------------- 01787 // Function: displays error messages related to input data 01788 // Input: error code 01789 // Output: none 01790 // --------------------------------------------------------------------------- 01791 { 01792 std::cerr << '\n'; 01793 01794 if (ECode == PINCELLS) // invalid number of pincells 01795 std::cerr << "Number of pincells must be >= 0."; 01796 else if (ECode == INVALIDINPUT) // invalid input 01797 std::cerr << "Invalid input."; 01798 else if (ECode == EMAT) // invalid input 01799 std::cerr << "Invalid Material Data."; 01800 else if (ECode == EGEOMTYPE) // invalid input 01801 std::cerr << "Invalid GeomType Data."; 01802 else if (ECode == EGEOMENGINE) // invalid input 01803 std::cerr << "Invalid Geometry Engine."; 01804 else if (ECode == EALIAS) // invalid input 01805 std::cerr << "Error Reading Aliases."; 01806 else if (ECode == ENEGATIVE) // invalid input 01807 std::cerr << "Unexpected negative value."; 01808 else if (ECode == EPIN) // invalid input 01809 std::cerr << "Invalid pinCell specs."; 01810 else if (ECode == EUNEQUAL) // invalid input 01811 std::cerr << "Number of cyliders and ducts in Z don't match, check .inp file."; 01812 else 01813 std::cerr << "Unknown error ...?"; 01814 01815 std::cerr << '\n' << "Error in input file line : " << m_nLineNumber; 01816 std::cerr << std::endl; 01817 exit (1); 01818 } 01819 01820 void AssyGen:: Name_Faces(const std::string sMatName, const iBase_EntityHandle body, iBase_TagHandle this_tag ) 01821 // --------------------------------------------------------------------------- 01822 // Function: names all the faces in the body 01823 // Input: none 01824 // Output: none 01825 // --------------------------------------------------------------------------- 01826 { 01827 double dTol = 1e-4, ttol = 1e-2; 01828 if(m_dMAssmPitch.GetRows()!=0 && m_dMAssmPitch.GetColumns()!=0){ 01829 if(m_szGeomType == "hexagonal") 01830 ttol = m_dMAssmPitch(1, 1); 01831 else if (m_szGeomType == "rectangular") 01832 ttol = m_dMAssmPitchX(1,1); 01833 } 01834 // set tolerance for surface identification 01835 if (ttol != 0){ 01836 dTol=ttol*1.0e-2; 01837 } 01838 double dZTemp = 0.0; 01839 int flag = 0, locTemp = 0; 01840 iBase_EntityHandle max_surf = NULL, min_surf = NULL, side_surf =NULL; 01841 SimpleArray<iBase_EntityHandle> surfs; 01842 int nSide = 0; 01843 std::ostringstream os; 01844 std::string sMatName0=sMatName+"_top"; 01845 std::string sMatName1=sMatName+"_bot"; 01846 std::string sSideName; 01847 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 01848 iGeom_getEntAdj( igeomImpl->instance(), body, iBase_FACE, ARRAY_INOUT(surfs), &err ); 01849 #endif 01850 01851 SimpleArray<double> max_corn, min_corn; 01852 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 01853 iGeom_getArrBoundBox( igeomImpl->instance(), ARRAY_IN(surfs), iBase_INTERLEAVED, 01854 ARRAY_INOUT( min_corn ), 01855 ARRAY_INOUT( max_corn ), 01856 &err ); 01857 #endif 01858 01859 for (int i = 0; i < surfs.size(); ++i){ 01860 // first find the max z-coordinate 01861 if( (fabs(min_corn[3*i+2]-max_corn[3*i+2])) < dTol ) { 01862 if(flag == 0){ 01863 dZTemp = min_corn[3*i+2]; 01864 locTemp = i; 01865 flag = 1; 01866 } 01867 else if(dZTemp > min_corn[3*i+2]){ 01868 // we have a bot surface 01869 min_surf = surfs[i]; 01870 // the top surface is dZTemp 01871 max_surf = surfs[locTemp]; 01872 } 01873 else{ 01874 //we have a top surface 01875 min_surf = surfs[locTemp]; 01876 // the top surface is dZTemp 01877 max_surf = surfs[i]; 01878 } 01879 } 01880 // see if max or min set name 01881 if(max_surf !=0){ 01882 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 01883 iGeom_setData(igeomImpl->instance(), max_surf, this_tag, 01884 sMatName0.c_str(), sMatName0.size(), &err); 01885 #endif 01886 01887 std::cout << sMatName0 << ", "; 01888 max_surf = NULL; 01889 01890 } 01891 if(min_surf !=0){ 01892 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 01893 iGeom_setData(igeomImpl->instance(), min_surf, this_tag, 01894 sMatName1.c_str(), sMatName1.size(), &err); 01895 #endif 01896 std::cout << sMatName1 << ", "; 01897 min_surf = NULL; 01898 01899 } 01900 } 01901 for (int i = 0; i < surfs.size(); ++i){ 01902 if( (fabs(min_corn[3*i+2]-max_corn[3*i+2])) < dTol ) { 01903 continue; // its a max of min surface 01904 } 01905 else{ // its a side surface 01906 side_surf = surfs[i]; 01907 } 01908 //set name for the sidesurf now 01909 if(side_surf !=0){ 01910 ++nSide; 01911 sSideName = sMatName + "_side"; 01912 if(m_szGeomType == "hexagonal") { 01913 if(nSide <= 6) 01914 os << sSideName << nSide; 01915 else 01916 os << sSideName << "_" << nSide; 01917 } 01918 01919 if(m_szGeomType == "rectangular"){ 01920 if(nSide <= 4) 01921 os << sSideName << nSide; 01922 else 01923 os << sSideName << "_" << nSide; 01924 } 01925 sSideName = os.str(); 01926 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 01927 iGeom_setData(igeomImpl->instance(), side_surf, this_tag, 01928 sSideName.c_str(), sMatName1.size(), &err); 01929 #endif 01930 std::cout << sSideName << ", " ; 01931 sSideName = ""; 01932 os.str(""); 01933 side_surf = NULL; 01934 } 01935 else { 01936 std::cerr << "Couldn't find surface for naming" << std::endl; 01937 } 01938 } 01939 std::cout <<"\n"; 01940 01941 } 01942 01943 01944 void AssyGen::Center_Assm (char &rDir) 01945 // --------------------------------------------------------------------------- 01946 // Function: centers all the entities along x and y axis 01947 // Input: none 01948 // Output: none 01949 // --------------------------------------------------------------------------- 01950 { 01951 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 01952 double xmin = 0.0, xmax = 0.0, ymin = 0.0, ymax = 0.0, zmin = 0.0, zmax = 0.0, xcenter = 0.0, ycenter = 0.0, zcenter = 0.0; 01953 // position the assembly such that origin is at the center before sa 01954 iGeom_getBoundBox(igeomImpl->instance(),&xmin,&ymin,&zmin, 01955 &xmax,&ymax,&zmax, &err); 01956 // moving all geom entities to center 01957 01958 01959 if( rDir =='x'){ 01960 xcenter = (xmin+xmax)/2.0; 01961 } 01962 else if( rDir =='y'){ 01963 ycenter = (ymin+ymax)/2.0; 01964 } 01965 else if ( rDir =='z'){ 01966 zcenter = (zmin+zmax)/2.0; 01967 } 01968 else{ 01969 // assume that it is centered along x and y and not z direction 01970 xcenter = (xmin+xmax)/2.0; 01971 ycenter = (ymin+ymax)/2.0; 01972 } 01973 01974 SimpleArray<iBase_EntityHandle> all; 01975 iGeom_getEntities( igeomImpl->instance(), root_set, iBase_REGION,ARRAY_INOUT(all),&err ); 01976 for(int i=0; i<all.size(); i++){ 01977 iGeom_moveEnt(igeomImpl->instance(),all[i],-xcenter,-ycenter,-zcenter,&err); 01978 } 01979 #endif 01980 01981 // OCC bounding box computation is buggy, better to compute bounding box in python and supply to the script. 01982 m_PyCubGeomFile << "vol = cubit.get_entities(\"volume\")" << std::endl; 01983 m_PyCubGeomFile << "vl = cubit.get_total_bounding_box(\"volume\", vol)\nzcenter = 0.0" << std::endl; 01984 01985 if( rDir =='x'){ 01986 m_PyCubGeomFile << "xcenter = (vl[0]+vl[1])/2.0" << std::endl; 01987 m_PyCubGeomFile << "ycenter = 0" << std::endl; 01988 m_PyCubGeomFile << "zcenter = 0" << std::endl; 01989 } 01990 else if( rDir =='y'){ 01991 m_PyCubGeomFile << "ycenter = (vl[3]+vl[4])/2.0" << std::endl; 01992 m_PyCubGeomFile << "xcenter = 0" << std::endl; 01993 m_PyCubGeomFile << "zcenter = 0" << std::endl; 01994 } 01995 else if ( rDir =='z'){ 01996 m_PyCubGeomFile << "zcenter = (vl[6]+vl[7])/2.0" << std::endl; 01997 m_PyCubGeomFile << "xcenter = 0" << std::endl; 01998 m_PyCubGeomFile << "ycenter = 0" << std::endl; 01999 } 02000 else{ 02001 // assume that it is centered along x and y and not z direction 02002 m_PyCubGeomFile << "xcenter = (vl[0]+vl[1])/2.0" << std::endl; 02003 m_PyCubGeomFile << "ycenter = (vl[3]+vl[4])/2.0" << std::endl; 02004 } 02005 02006 m_PyCubGeomFile << "cubit.cmd('move vol all x {0} y {1} z {2}'.format(-xcenter, -ycenter, -zcenter) )" << std::endl; 02007 } 02008 02009 void AssyGen::Section_Assm (char &cDir, double &dOffset, const std::string szReverse) 02010 // --------------------------------------------------------------------------- 02011 // Function: sections the assembly about the cutting plane 02012 // Input: none 02013 // Output: none 02014 // --------------------------------------------------------------------------- 02015 { 02016 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02017 double xmin = 0.0, xmax = 0.0, ymin = 0.0, ymax = 0.0, zmin = 0.0, zmax = 0.0, yzplane = 0.0, xzplane = 0.0; 02018 iBase_EntityHandle sec = NULL; 02019 int nReverse = 0; 02020 // check if reverse side is needed 02021 if(szReverse == "reverse"){ 02022 nReverse = 1; 02023 } 02024 if( cDir =='x'){ 02025 yzplane = 1.0; 02026 xzplane = 0.0; 02027 } 02028 if( cDir =='y'){ 02029 yzplane = 0.0; 02030 xzplane = 1.0; 02031 } 02032 SimpleArray<iBase_EntityHandle> all; 02033 iGeom_getEntities( igeomImpl->instance(), root_set, iBase_REGION,ARRAY_INOUT(all),&err ); 02034 // loop and section/delete entities 02035 for(int i=0; i < all.size(); i++){ 02036 //get the bounding box to decide 02037 iGeom_getEntBoundBox(igeomImpl->instance(),all[i],&xmin,&ymin,&zmin, 02038 &xmax,&ymax,&zmax, &err); 02039 02040 if(xmin > dOffset && yzplane ==1 && nReverse ==1){ 02041 iGeom_deleteEnt(igeomImpl->instance(),all[i],&err); 02042 continue; 02043 } 02044 if(ymin > dOffset && xzplane == 1 && nReverse ==1){ 02045 iGeom_deleteEnt(igeomImpl->instance(),all[i],&err); 02046 continue; 02047 } 02048 if(xmax < dOffset && yzplane ==1 && nReverse ==0){ 02049 iGeom_deleteEnt(igeomImpl->instance(),all[i],&err); 02050 continue; 02051 } 02052 if(ymax < dOffset && xzplane == 1 && nReverse ==0){ 02053 iGeom_deleteEnt(igeomImpl->instance(),all[i],&err); 02054 continue; 02055 } 02056 else{ 02057 if(xzplane ==1 && ymax >dOffset && ymin < dOffset){ 02058 iGeom_sectionEnt(igeomImpl->instance(), all[i],yzplane,xzplane,0, dOffset, nReverse,&sec,&err); 02059 } 02060 if(yzplane ==1 && xmax >dOffset && xmin < dOffset){ 02061 iGeom_sectionEnt(igeomImpl->instance(), all[i],yzplane,xzplane,0, dOffset,nReverse,&sec,&err); 02062 } 02063 } 02064 } 02065 #endif 02066 } 02067 02068 void AssyGen::Rotate_Assm (char &cDir, double &dAngle) 02069 // --------------------------------------------------------------------------- 02070 // Function: rotates the whole assembly 02071 // Input: none 02072 // Output: none 02073 // --------------------------------------------------------------------------- 02074 { 02075 m_PyCubGeomFile << "cDir = '" << cDir << "'" << "\ncubit.cmd('rotate vol all angle " << dAngle << " about {0}'.format(cDir))" << std::endl; 02076 02077 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02078 double dX = 0.0, dY=0.0, dZ=0.0; 02079 if( cDir =='x'){ 02080 dX = 1.0; 02081 } 02082 if( cDir =='y'){ 02083 dY = 1.0; 02084 } 02085 if( cDir =='z'){ 02086 dZ = 1.0; 02087 } 02088 SimpleArray<iBase_EntityHandle> all; 02089 iGeom_getEntities( igeomImpl->instance(), root_set, iBase_REGION,ARRAY_INOUT(all),&err ); 02090 02091 // loop and rotate all entities 02092 for(int i=0; i<all.size(); i++){ 02093 //get the bounding box to decide 02094 iGeom_rotateEnt(igeomImpl->instance(),all[i],dAngle, 02095 dX, dY, dZ, &err); 02096 } 02097 #endif 02098 } 02099 02100 void AssyGen::Move_Assm (double &dX,double &dY, double &dZ) 02101 // --------------------------------------------------------------------------- 02102 // Function: move's the model by dX, dY and dZ 02103 // Input: none 02104 // Output: none 02105 // --------------------------------------------------------------------------- 02106 { 02107 SimpleArray<iBase_EntityHandle> all; 02108 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02109 iGeom_getEntities( igeomImpl->instance(), root_set, iBase_REGION,ARRAY_INOUT(all),&err ); 02110 #endif 02111 m_PyCubGeomFile << "cubit.cmd('move vol all x " << dX << " y " << dY << " dZ " << dZ << "')" << std::endl; 02112 02113 // loop and rotate all entities 02114 for(int i=0; i<all.size(); i++){ 02115 //get the bounding box to decide 02116 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02117 iGeom_moveEnt(igeomImpl->instance(),all[i], 02118 dX, dY, dZ, &err); 02119 #endif 02120 } 02121 02122 } 02123 02124 void AssyGen::Create_HexAssm(std::string &szInputString) 02125 // --------------------------------------------------------------------------- 02126 // Function: read and create the assembly for hexagonal lattice 02127 // Input: error code 02128 // Output: none 02129 // --------------------------------------------------------------------------- 02130 { 02131 CParser Parse; 02132 std::string card, szVolId, szVolAlias; 02133 int nInputLines, nTempPin = 1, t, nIFlag = 0, total_pincells = 0; 02134 double dX = 0.0, dY =0.0, dZ=0.0; 02135 double dP, dH, dSide, dHeight; 02136 iBase_EntityHandle assm = NULL; 02137 std::cout << "\ngetting Assembly data and creating ..\n"<< std::endl; 02138 std::istringstream szFormatString (szInputString); 02139 02140 szFormatString >> card >> m_nPin; 02141 if(m_nPin <=0 ) 02142 IOErrorHandler (INVALIDINPUT); 02143 02144 // width of the hexagon is n*n+1/2 02145 int nWidth =2*m_nPin -1; 02146 02147 // creating a square array of size width 02148 m_Assembly.SetSize(nWidth, nWidth); 02149 if (m_nJouFlag == 1) 02150 return; 02151 02152 for(int m=1; m<=nWidth; m++){ 02153 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 02154 MAXCHARS, szComment)) 02155 IOErrorHandler (INVALIDINPUT); 02156 if(m>m_nPin) 02157 t = 2*m_nPin - m; 02158 else 02159 t = m; 02160 std::istringstream szFormatString1 (szInputString); 02161 02162 for(int n=1; n<=(m_nPin + t - 1); n++){ 02163 ++total_pincells; 02164 nTempPin = -1; 02165 szFormatString1 >> m_Assembly(m,n); 02166 if(szFormatString1.fail()) 02167 IOErrorHandler (INVALIDINPUT); 02168 // if dummy pincell skip and continue 02169 if((m_Assembly(m,n)=="x")||(m_Assembly(m,n)=="xx")){ 02170 continue; 02171 } 02172 // find that pincell 02173 ++m_nTotalPincells; 02174 for(int b=1; b<=m_nPincells; b++){ 02175 m_Pincell(b).GetLineOne(szVolId, szVolAlias, nInputLines); 02176 if(m_Assembly(m,n) == szVolAlias) 02177 nTempPin = b; 02178 } 02179 if(nTempPin == -1){ 02180 std::cout << "Unknown pincell, pincell " << m_Assembly(m,n) << " not declared" << std::endl; 02181 exit(1); 02182 } 02183 02184 // now compute the location and create it 02185 ComputePinCentroid(nTempPin, m_Assembly, m, n, dX, dY, dZ); 02186 //ERRORR("Error in function ComputePinCentroid", err); 02187 02188 // now create the pincell in the location found 02189 std::cout << "\n--------------------------------------------------"<<std::endl; 02190 std::cout << " m = " << m <<" n = " << n << std::endl; 02191 std::cout << "creating pin: " << nTempPin; 02192 std::cout << " at X Y Z " << dX << " " << dY << " " << dZ << std::endl; 02193 02194 if(strcmp(m_szInfo.c_str(),"on") == 0) 02195 m_AssmInfo << nTempPin << " \t" << m << " \t" << n << " \t" << dX << " \t" << dY << " \t" << dZ << std::endl; 02196 02197 m_Pincell(nTempPin).GetIntersectFlag(nIFlag); 02198 if(nIFlag){ 02199 CreatePinCell_Intersect(nTempPin, dX, -dY, dZ); 02200 //ERRORR("Error in function CreatePinCell_Intersect", err); 02201 } 02202 else{ 02203 CreatePinCell(nTempPin, dX, -dY, dZ); 02204 //ERRORR("Error in function CreatePinCell", err); 02205 } 02206 } 02207 } 02208 02209 // get all the entities (in pins)defined so far, in an entity set - for subtraction later 02210 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02211 iGeom_getEntities( igeomImpl->instance(), root_set, iBase_REGION, ARRAY_INOUT(in_pins),&err ); 02212 #endif 02213 std::cout << "Expected pin definitions: " << total_pincells << "\n\nCreating surrounding outer hexes .." << std::endl; 02214 02215 for (int nTemp = 1; nTemp <= m_nDuct; nTemp ++){ 02216 if(m_nDimensions >0){ 02217 02218 // create outermost hexes 02219 for(int n=1;n<=m_nDimensions; n++){ 02220 dSide = m_dMAssmPitch(nTemp, n)/(sqrt(3)); 02221 dHeight = m_dMZAssm(nTemp, 2) - m_dMZAssm(nTemp, 1); 02222 02223 // creating coverings 02224 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02225 iGeom_createPrism(igeomImpl->instance(), dHeight, 6, 02226 dSide, dSide, 02227 &assm, &err); 02228 #endif 02229 m_PyCubGeomFile << "##\nassm = cubit.prism(" << dHeight << ", 6, " << dSide << ", " << dSide << ")" << std::endl; 02230 02231 // rotate the prism to match the pins 02232 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02233 iGeom_rotateEnt (igeomImpl->instance(), assm, 30, 0, 0, 1, &err); 02234 #endif 02235 m_PyCubGeomFile << "cubit.cmd('rotate body {0} angle 30 about z'.format(assm.id()) )" << std::endl; 02236 02237 if(0 != m_Pincell.GetSize()){ 02238 m_Pincell(1).GetPitch(dP, dH); 02239 dX = m_nPin*dP; 02240 dY = -(m_nPin-1)*dP*sqrt(3.0)/2.0; 02241 } 02242 else{ 02243 dX = 0.0; 02244 dY = 0.0; 02245 } 02246 dZ = (m_dMZAssm(nTemp, 2) + m_dMZAssm(nTemp, 1))/2.0; 02247 02248 // position the prism 02249 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02250 iGeom_moveEnt(igeomImpl->instance(), assm, dX,dY,dZ, &err); 02251 #endif 02252 m_PyCubGeomFile << "vector = [" << dX << ", " << dY << ", " << dZ << "]" << std::endl; 02253 m_PyCubGeomFile << "cubit.move(assm, vector)" << std::endl; 02254 02255 // populate the coverings array 02256 int loc = (nTemp-1)*m_nDimensions + n -1; 02257 assms[(nTemp-1)*m_nDimensions + n -1]=assm; 02258 m_PyCubGeomFile << "assms.insert(" << loc << ", assm)" << std::endl; 02259 } 02260 } 02261 } 02262 02263 } 02264 02265 void AssyGen::Create_CartAssm(std::string &szInputString) 02266 // --------------------------------------------------------------------------- 02267 // Function: read and create the assembly for rectangular lattice 02268 // Input: error code 02269 // Output: none 02270 // --------------------------------------------------------------------------- 02271 { 02272 CParser Parse; 02273 std::string card, szVolId, szVolAlias; 02274 int nInputLines, nTempPin = 1, nIFlag = 0.0; 02275 double dX = 0.0, dY =0.0, dZ=0.0, dMoveX = 0.0, dMoveY = 0.0, dHeight = 0, dPX=0.0, dPY=0.0, dPZ=0.0; 02276 iBase_EntityHandle assm = NULL; 02277 02278 std::istringstream szFormatString (szInputString); 02279 szFormatString >> card >> m_nPinX >> m_nPinY; 02280 if(m_nPinX <=0 || m_nPinY <=0) 02281 IOErrorHandler (INVALIDINPUT); 02282 m_Assembly.SetSize(m_nPinY,m_nPinX); 02283 02284 if (m_nJouFlag == 1) 02285 return; 02286 02287 //read the next line to get assembly info &store assembly info 02288 if(0 != m_Pincell.GetSize()){ 02289 for(int m=1; m<=m_nPinY; m++){ 02290 if (!Parse.ReadNextLine (m_FileInput, m_nLineNumber, szInputString, 02291 MAXCHARS, szComment)) 02292 IOErrorHandler (INVALIDINPUT); 02293 std::istringstream szFormatString1 (szInputString); 02294 02295 //store the line read in Assembly array and create / position the pin in the core 02296 for(int n=1; n<=m_nPinX; n++){ 02297 szFormatString1 >> m_Assembly(m,n); 02298 if(szFormatString1.fail()) 02299 IOErrorHandler (INVALIDINPUT); 02300 02301 02302 // loop thro' all pins to get the type of pin 02303 for(int b=1; b<=m_nPincells; b++){ 02304 m_Pincell(b).GetLineOne(szVolId, szVolAlias, nInputLines); 02305 if(m_Assembly(m,n) == szVolAlias) 02306 nTempPin = b; 02307 } 02308 02309 //now compute the location where the pin needs to be placed 02310 ComputePinCentroid(nTempPin, m_Assembly, m, n, dX, dY, dZ); 02311 //ERRORR("Error in function ComputePinCentroid", err); 02312 02313 // if dummy pincell skip and continue 02314 if((m_Assembly(m,n)=="x")||(m_Assembly(m,n)=="xx")){ 02315 m_Pincell(1).GetPitch(dPX, dPY, dPZ); 02316 // dMoveX and dMoveY are stored for positioning the outer squares later 02317 if(m == m_nPinY && n ==m_nPinX){ 02318 dMoveX = dX/2.0; 02319 dMoveY = -dY/2.0; 02320 } 02321 continue; 02322 } 02323 ++m_nTotalPincells; 02324 // now create the pincell in the location found 02325 std::cout << "\n--------------------------------------------------"<<std::endl; 02326 std::cout << " m = " << m <<" n = " << n << std::endl; 02327 std::cout << "creating pin: " << nTempPin; 02328 std::cout << " at X Y Z " << dX << " " << -dY << " " << dZ << std::endl; 02329 02330 if(strcmp(m_szInfo.c_str(),"on") == 0) 02331 m_AssmInfo << nTempPin << " \t" << m << " \t" << n << " \t" << dX << " \t" << dY << " \t" << dZ << std::endl; 02332 02333 m_Pincell(nTempPin).GetIntersectFlag(nIFlag); 02334 if(nIFlag){ 02335 CreatePinCell_Intersect(nTempPin, dX, -dY, dZ); 02336 //ERRORR("Error in function CreatePinCell_Intersect", err); 02337 } 02338 else{ 02339 CreatePinCell(nTempPin, dX, -dY, dZ); 02340 //ERRORR("Error in function CreatePinCell", err); 02341 } 02342 // dMoveX and dMoveY are stored for positioning the outer squares later 02343 if(m == m_nPinY && n ==m_nPinX){ 02344 dMoveX = dX/2.0; 02345 dMoveY = -dY/2.0; 02346 } 02347 } 02348 } 02349 } 02350 std::cout << "\n--------------------------------------------------"<<std::endl; 02351 02352 // get all the entities (in pins)defined so far, in an entity set - for subtraction later 02353 // iGeom_getEntities( igeomImpl->instance(), root_set, iBase_REGION, ARRAY_INOUT(in_pins),&err ); 02354 // //CHECK( "ERROR : getRootSet failed!" ); 02355 02356 02357 if(m_nDimensions > 0){ 02358 02359 // create outermost rectangular blocks 02360 std::cout << "\nCreating surrounding outer blocks .." << std::endl; 02361 int nCount = -1; 02362 for(int nTemp = 1; nTemp <= m_nDuct; nTemp ++){ 02363 for(int n=1;n<=m_nDimensions; n++){ 02364 ++nCount; 02365 dHeight = m_dMZAssm(nTemp, 2) - m_dMZAssm(nTemp, 1); 02366 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02367 iGeom_createBrick(igeomImpl->instance(), m_dMAssmPitchX(nTemp, n), m_dMAssmPitchY(nTemp, n), dHeight, 02368 &assm, &err); 02369 #endif 02370 m_PyCubGeomFile << "assm = cubit.brick( " << m_dMAssmPitchX(nTemp, n) << ", " << m_dMAssmPitchY(nTemp, n) << ", " << dHeight << ")" << std::endl; 02371 02372 // position the outer block to match the pins 02373 dZ = (m_dMZAssm(nTemp, 2) + m_dMZAssm(nTemp, 1))/2.0; 02374 std::cout << "Move " << dMoveX << " " << dMoveY <<std::endl; 02375 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02376 iGeom_moveEnt(igeomImpl->instance(), assm, dMoveX,dMoveY,dZ, &err); 02377 #endif 02378 m_PyCubGeomFile << "vector = [" << dMoveX << ", " << dMoveY << ", " << dZ << "]" << std::endl; 02379 m_PyCubGeomFile << "cubit.move(assm, vector)" << std::endl; 02380 02381 // populate the outer covering array squares 02382 assms[nCount]=assm; 02383 m_PyCubGeomFile << "assms.insert(" << nCount << ", assm)" << std::endl; 02384 02385 } 02386 } 02387 } 02388 02389 } 02390 02391 void AssyGen::CreateOuterCovering () 02392 // --------------------------------------------------------------------------- 02393 // Function: this function sets the names of the coverings 02394 // Input: error code 02395 // Output: none 02396 // --------------------------------------------------------------------------- 02397 { 02398 double zmin = 0.0, zmax = 0.0; 02399 iBase_TagHandle this_tag = NULL; 02400 std::string sMatName = ""; 02401 std::string sMatName0 = ""; 02402 std::string sMatName1 = ""; 02403 m_PyCubGeomFile << "sub1 = []\nsub2=[]" << std::endl; 02404 02405 // get tag handle for 'NAME' tag, already created as iGeom instance is created 02406 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02407 char* tag_name =(char *)"NAME"; 02408 iGeom_getTagHandle(igeomImpl->instance(), tag_name, &this_tag, &err, 4); 02409 #endif 02410 iBase_EntityHandle tmp_vol= NULL, tmp_new= NULL; 02411 02412 // name the innermost outer covering common for both rectangular and hexagonal assembliees 02413 if(m_nDimensions >0){ 02414 // int tag_no = 0; 02415 for (int nTemp1 = 1; nTemp1 <=m_nDuct; nTemp1++){ 02416 for(int p=1;p<=m_szAssmMatAlias.GetSize();p++){ 02417 if(strcmp ( m_szMMAlias(nTemp1, 1).c_str(), m_szAssmMatAlias(p).c_str()) == 0){ 02418 sMatName = m_szAssmMat(p); 02419 // tag_no=p; 02420 } 02421 } 02422 02423 std::cout << "\ncreated innermost block: " << sMatName << std::endl; 02424 02425 tmp_vol = assms[(nTemp1 - 1)*m_nDimensions]; 02426 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02427 iGeom_setData(igeomImpl->instance(), tmp_vol, this_tag, 02428 sMatName.c_str(), sMatName.size(), &err); 02429 #endif 02430 Name_Faces(sMatName, tmp_vol, this_tag); 02431 m_PyCubGeomFile << "lid = assms[" << (nTemp1 - 1)*m_nDimensions << "].id()" << std::endl; 02432 if (sMatName == "") 02433 IOErrorHandler(EALIAS); 02434 m_PyCubGeomFile << "cubit.set_entity_name(\"body\", lid, \"" << sMatName << "\" )" << std::endl; 02435 m_PyCubGeomFile << "name_faces(\"" << sMatName << "\", assms[" << (nTemp1 - 1)*m_nDimensions << "])" << std::endl; 02436 } 02437 02438 int count =0;//index for edge names 02439 for (int nTemp = 1; nTemp <= m_nDuct; nTemp++){ 02440 // Naming outermost block edges - sidesets in cubit journal file 02441 std::cout << "Naming outermost block edges" << std::endl; 02442 SimpleArray<iBase_EntityHandle> edges; 02443 02444 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02445 iGeom_getEntAdj( igeomImpl->instance(), assms[nTemp*m_nDimensions-1] , iBase_EDGE,ARRAY_INOUT(edges), 02446 &err ); 02447 #endif 02448 // get the top corner edges of the outer most covering 02449 //m_PyCubGeomFile << "lid=assms<<["<< nTemp*m_nDimensions-1 << "].id()" << std::endl; 02450 m_PyCubGeomFile << "cubit.cmd('group \"g1\" equals curve in vol {0} '.format(assms[" << nTemp*m_nDimensions-1 << "].id()))" << std::endl; 02451 m_PyCubGeomFile << "cubit.cmd('group \"g2\" equals curve with z_max<> z_min in g1')\ncubit.cmd('group \"g3\" subtract g2 from g1')" << std::endl; 02452 m_PyCubGeomFile << "tmp_g3id = cubit.get_id_from_name(\"g3\")\n" 02453 "gs_curves = cubit.get_group_curves(tmp_g3id)\n" 02454 "side_curves = len(gs_curves)\n" 02455 "for i in range(0,side_curves):\n" 02456 " sname = \"side_edge\" + str(i+1)\n" 02457 " cubit.cmd('curve {0} name \"{1}\"'.format( gs_curves[i] , sname ) )\n" << std::endl; 02458 std::ostringstream os; 02459 for (int i = 0; i < edges.size(); ++i){ 02460 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02461 double xmin = 0.0, xmax = 0.0, ymin = 0.0, ymax = 0.0; 02462 iGeom_getEntBoundBox(igeomImpl->instance(), edges[i],&xmin,&ymin,&zmin, 02463 &xmax,&ymax,&zmax, &err); 02464 #endif 02465 double dTol = 1e-5; // tolerance for comparing coordinates 02466 02467 if(fabs(zmax - m_dMZAssm(nTemp, 2)) < dTol){ 02468 if(fabs(zmax-zmin) < dTol){ 02469 02470 //we have a corner edge - name it 02471 sMatName="side_edge"; 02472 ++count; 02473 os << sMatName << count; 02474 sMatName=os.str(); 02475 std::cout << sMatName << std::endl; 02476 tmp_vol=edges[i]; 02477 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02478 iGeom_setData(igeomImpl->instance(), tmp_vol, this_tag, 02479 sMatName.c_str(), sMatName.size(), &err); 02480 #endif 02481 std::cout << "created: " << sMatName << std::endl; 02482 os.str(""); 02483 sMatName=""; 02484 } 02485 } 02486 } 02487 } 02488 // now subtract the outermost hexes and name them 02489 std::cout << "Subtract outermost hexes and naming them" << std::endl; 02490 int nCount = 0; 02491 for(int nTemp=1; nTemp<=m_nDuct; nTemp++){ 02492 for(int n=m_nDimensions; n>1 ; n--){ 02493 if(n>1){ 02494 ++nCount; 02495 // copy cyl before subtract 02496 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02497 iGeom_copyEnt(igeomImpl->instance(), assms[(nTemp-1)*m_nDimensions + n-2], &tmp_vol, &err); 02498 #endif 02499 m_PyCubGeomFile << "tmp_vol = cubit.copy_body(assms[" << (nTemp-1)*m_nDimensions + n-2 << "])" << std::endl; 02500 02501 // subtract outer most cyl from brick 02502 m_PyCubGeomFile << "\nsub1.append(tmp_vol)" << std::endl; 02503 m_PyCubGeomFile << "\nsub2.append(assms[" << (nTemp-1)*m_nDimensions + n-1 <<"])" << std::endl; 02504 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02505 iGeom_subtractEnts(igeomImpl->instance(), assms[(nTemp-1)*m_nDimensions + n-1], tmp_vol, &tmp_new, &err); 02506 #endif 02507 m_PyCubGeomFile << "tmp_new = cubit.subtract(sub1, sub2)" << std::endl; 02508 m_PyCubGeomFile << "assms[" << (nTemp-1)*m_nDimensions + n-1 << "] = tmp_new[0]\n\nsub1[:]=[]\nsub2[:]=[]" << std::endl; 02509 02510 assms[(nTemp-1)*m_nDimensions + n-1]=tmp_new; 02511 02512 // name the vols by searching for the full name of the abbreviated Cell Mat 02513 for(int p=1;p<=m_szAssmMatAlias.GetSize();p++){ 02514 if(strcmp ( m_szMMAlias(nTemp, n).c_str(), m_szAssmMatAlias(p).c_str()) == 0){ 02515 sMatName = m_szAssmMat(p); 02516 } 02517 } 02518 std::cout << "created: " << sMatName << std::endl; 02519 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02520 iGeom_setData(igeomImpl->instance(), tmp_new, this_tag, 02521 sMatName.c_str(), sMatName.size(), &err); 02522 #endif 02523 m_PyCubGeomFile << "lid = tmp_new[0].id()" << std::endl; 02524 if (sMatName == "") 02525 IOErrorHandler(EALIAS); 02526 m_PyCubGeomFile << "cubit.set_entity_name(\"body\", lid, \"" << sMatName << "\" )" << std::endl; 02527 m_PyCubGeomFile << "name_faces(\"" << sMatName << "\", tmp_new[0]) " << std::endl; 02528 Name_Faces(sMatName, tmp_new, this_tag); 02529 } 02530 } 02531 } 02532 std::cout << "\n--------------------------------------------------"<<std::endl; 02533 } 02534 02535 } 02536 02537 void AssyGen::Subtract_Pins() 02538 // --------------------------------------------------------------------------- 02539 // Function: subtract the pins from the outer block 02540 // Input: none 02541 // Output: none 02542 // --------------------------------------------------------------------------- 02543 { 02544 if (m_nDimensions >0){ 02545 std::cout <<"Total number of pins in the model = " << m_nTotalPincells << std::endl; 02546 02547 for (int k=1; k<=m_nDuct; k++){ 02548 if(cp_inpins[k-1].size() ==0) 02549 continue; 02550 // put all the in pins in a matrix of size duct for subtraction with ducts 02551 std::vector <iBase_EntityHandle> pin_copy( cp_inpins[k-1].size(), NULL); 02552 m_PyCubGeomFile << "pin_copy=[]\n\nsub1=[]\nsub2=[]\n" << std::endl; 02553 for (int i=0; i< (int) cp_inpins[k-1].size();i++){ 02554 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02555 iGeom_copyEnt(igeomImpl->instance(), cp_inpins[k-1][i], &pin_copy[i], &err); 02556 #endif 02557 m_PyCubGeomFile << "tmp_vol = cubit.copy_body(cp_inpins[" << k-1 << "][" << i << "])" << std::endl; 02558 m_PyCubGeomFile << "pin_copy.append(tmp_vol)" << std::endl; 02559 m_PyCubGeomFile << "\nsub2.append(cp_inpins[" << k-1 << "]["<< i << "])" << std::endl; 02560 } 02561 02562 iBase_EntityHandle tmp_vol = NULL; 02563 (void) tmp_vol; 02564 tmp_vol = assms[(k-1)*m_nDimensions]; 02565 m_PyCubGeomFile << "tmp_vol = assms[" << k << "]" << std::endl; 02566 02567 // subtract the innermost hex from the pins 02568 std::cout << "Duct no.: " << k << " subtracting " << cp_inpins[k-1].size() << " pins from the duct .. " << std::endl; 02569 02570 //#if HAVE_ACIS 02571 iBase_EntityHandle unite= NULL, tmp_new1 = NULL; 02572 (void) unite; 02573 02574 // if there are more than one pins 02575 if( cp_inpins[k-1].size() > 1){ 02576 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02577 iGeom_uniteEnts(igeomImpl->instance(), &cp_inpins[k-1][0], cp_inpins[k-1].size(), &unite, &err); 02578 #endif 02579 m_PyCubGeomFile << "\nsub1.append(assms[" << (k-1)*m_nDimensions <<"])" << std::endl; 02580 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02581 iGeom_subtractEnts(igeomImpl->instance(), tmp_vol,unite, &tmp_new1, &err); 02582 #endif 02583 m_PyCubGeomFile << "tmp_new1 = cubit.subtract(sub2, sub1)" << std::endl; 02584 m_PyCubGeomFile << "tmp_vol = tmp_new1" << std::endl; 02585 02586 tmp_vol = tmp_new1; 02587 unite = NULL; 02588 tmp_new1=NULL; 02589 } 02590 else{ // only one pin in in_pins 02591 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02592 iGeom_subtractEnts(igeomImpl->instance(), tmp_vol, cp_inpins[k-1][0], &tmp_new1, &err); 02593 #endif 02594 m_PyCubGeomFile << "\nsub1.append(assms[" << (k-1)*m_nDimensions <<"])" << std::endl; 02595 m_PyCubGeomFile << "tmp_new1 = cubit.subtract(sub2, sub1)" << std::endl; 02596 } 02597 //#endif 02598 // This block was needed for OCE below 0.13 or OCC 6.6 02599 //#if HAVE_OCC 02600 // iBase_EntityHandle tmp_new1 = NULL; 02601 // // if there are more than one pins 02602 // if( cp_inpins[k-1].size() > 1){ 02603 // std::cout << "Subtraction is slower in OCC, since each pin is subtracted one by one" << std::endl; 02604 // for (int i=0; i< (int)cp_inpins[k-1].size(); i++){ 02605 // // iGeom_copyEnt(igeomImpl->instance(), cp_inpins[k-1][i], &unite, &err); 02606 // iGeom_subtractEnts(igeomImpl->instance(), tmp_vol,cp_inpins[k-1][i], &tmp_new1, &err); 02607 // ////CHECK("Couldn't subtract pins from block."); 02608 // tmp_vol = tmp_new1; 02609 // tmp_new1=NULL; 02610 // } 02611 02612 // } 02613 // else{ // only one pin in in_pins 02614 // iGeom_subtractEnts(igeomImpl->instance(), tmp_vol, cp_inpins[k-1][0], &tmp_new1, &err); 02615 // ////CHECK("Couldn't subtract pins from block."); 02616 // } 02617 //#endif 02618 02619 } 02620 std::cout << "\n--------------------------------------------------"<<std::endl; 02621 } 02622 else{ 02623 std::cout <<"Nothing to subtract" << std::endl; 02624 } 02625 02626 } 02627 02628 void AssyGen::Imprint_Merge(bool if_merge, bool if_imprint) 02629 // --------------------------------------------------------------------------- 02630 // Function: Imprint and Merge 02631 // Input: none 02632 // Output: none 02633 // --------------------------------------------------------------------------- 02634 { 02635 // getting all entities for merge and imprint 02636 SimpleArray<iBase_EntityHandle> entities; 02637 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02638 iGeom_getEntities( igeomImpl->instance(), root_set, iBase_REGION, ARRAY_INOUT(entities),&err ); 02639 #endif 02640 02641 if(if_imprint == true){ 02642 // now imprint 02643 std::cout << "\n\nImprinting...." << std::endl; 02644 clock_t s_imprint = clock(); 02645 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02646 iGeom_imprintEnts(igeomImpl->instance(), ARRAY_IN(entities),&err); 02647 #endif 02648 std::cout << "## Imprint CPU time used := " << (double) (clock() - s_imprint)/CLOCKS_PER_SEC 02649 << " seconds" << std::endl; 02650 std::cout << "\n--------------------------------------------------"<<std::endl; 02651 } 02652 02653 if(if_merge == true){ 02654 // merge tolerance 02655 // now merge 02656 std::cout << "\n\nMerging...." << std::endl; 02657 clock_t s_merge = clock(); 02658 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02659 double dTol = 1e-4; 02660 iGeom_mergeEnts(igeomImpl->instance(), ARRAY_IN(entities), dTol, &err); 02661 #endif 02662 std::cout << "## Merge CPU time used := " << (double) (clock() - s_merge)/CLOCKS_PER_SEC 02663 << " seconds" << std::endl; 02664 std::cout <<"merging finished."<< std::endl; 02665 std::cout << "\n--------------------------------------------------"<<std::endl; 02666 } 02667 } 02668 02669 void AssyGen::Create2DSurf () 02670 // --------------------------------------------------------------------------- 02671 // Function: creating planar top surface with zmax 02672 // Input: error code 02673 // Output: none 02674 // --------------------------------------------------------------------------- 02675 { 02676 m_PyCubGeomFile << "#keep top surface delete the rest" << std::endl; 02677 m_PyCubGeomFile << "cubit.cmd('surf with z_coord == {0} copy'.format(vl[7]) )" << std::endl; 02678 m_PyCubGeomFile << "cubit.cmd('delete vol with z_coord < {0}'.format(vl[7]) )" << std::endl; 02679 02680 #if defined (HAVE_ACIS) || defined (HAVE_OCC) 02681 std::cout << "Creating surface; 2D assembly specified..." << std::endl; 02682 SimpleArray<iBase_EntityHandle> all_geom; 02683 SimpleArray<iBase_EntityHandle> surfs; 02684 int t=0; 02685 SimpleArray<double> max_corn, min_corn; 02686 02687 // get all the entities in the model (delete after making a copy of top surface) 02688 int *offset = NULL, offset_alloc = 0, offset_size = -1; 02689 iGeom_getEntities( igeomImpl->instance(), root_set, iBase_REGION,ARRAY_INOUT(all_geom),&err ); 02690 02691 // get all the surfaces in the model 02692 iGeom_getArrAdj( igeomImpl->instance(), ARRAY_IN(all_geom) , iBase_FACE, ARRAY_INOUT(surfs), 02693 &offset, &offset_alloc, &offset_size, &err ); 02694 02695 iGeom_getArrBoundBox( igeomImpl->instance(), ARRAY_IN(surfs), iBase_INTERLEAVED, 02696 ARRAY_INOUT( min_corn ), 02697 ARRAY_INOUT( max_corn ), 02698 &err ); 02699 02700 // find the number of surfaces 't' for array allocation 02701 int nTemp = 1; 02702 double dTol = 1e-5; 02703 double dtop = m_dMZAssm(nTemp, 2); 02704 for (int i = 0; i < surfs.size(); ++i){ 02705 if((fabs(max_corn[3*i+2] - dtop) < dTol) && (fabs(min_corn[3*i+2] - dtop)<dTol)) 02706 t++; 02707 } 02708 02709 // allocate arrays 02710 SimpleArray<iBase_EntityHandle> max_surfs(t); 02711 SimpleArray<iBase_EntityHandle> new_surfs(t); 02712 t=0; 02713 02714 // store the max surfaces in max_surfs 02715 for (int i = 0; i < surfs.size(); ++i){ 02716 02717 // locate surfaces for which max and min zcoord is same as maxz coord 02718 if((fabs(max_corn[3*i+2] - dtop) < dTol) && (fabs(min_corn[3*i+2] - dtop) < dTol)){ 02719 max_surfs[t] = surfs[i]; 02720 t++; 02721 } 02722 } 02723 02724 // make a copy of max_surfs 02725 for(int i = 0; i < max_surfs.size(); ++i){ 02726 iGeom_copyEnt(igeomImpl->instance(), max_surfs[i], &new_surfs[i], &err); 02727 } 02728 02729 // delete all the old ents 02730 for(int i=0; i<all_geom.size(); i++){ 02731 iGeom_deleteEnt(igeomImpl->instance(), all_geom[i], &err); 02732 } 02733 // position the final assembly at the center 02734 // get the assembly on z=0 plane 02735 02736 double zcenter = m_dMZAssm(nTemp, 2)/2.0;//move up 02737 SimpleArray<iBase_EntityHandle> all; 02738 iGeom_getEntities( igeomImpl->instance(), root_set, iBase_REGION,ARRAY_INOUT(all),&err ); 02739 02740 for(int i=0; i<all.size(); i++){ 02741 iGeom_moveEnt(igeomImpl->instance(),all[i],0,0,-zcenter,&err); 02742 } 02743 free(offset); 02744 #endif 02745 std::cout << "-----Done creating 2D surface-----"<<std::endl; 02746 02747 } 02748 }