00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "DriverMED_R_SMESHDS_Mesh.h"
00028 #include "DriverMED_R_SMDS_Mesh.h"
00029 #include "SMESHDS_Mesh.hxx"
00030 #include "utilities.h"
00031
00032 #include "DriverMED_Family.h"
00033
00034 #include "SMESHDS_Group.hxx"
00035
00036 #include "MED_Factory.hxx"
00037 #include "MED_CoordUtils.hxx"
00038 #include "MED_Utilities.hxx"
00039
00040 #include <stdlib.h>
00041
00042 #ifdef _DEBUG_
00043 static int MYDEBUG = 1;
00044
00045 #else
00046 static int MYDEBUG = 0;
00047 #endif
00048
00049 #define _EDF_NODE_IDS_
00050
00051 using namespace MED;
00052 using namespace std;
00053
00054 void
00055 DriverMED_R_SMESHDS_Mesh
00056 ::SetMeshName(string theMeshName)
00057 {
00058 myMeshName = theMeshName;
00059 }
00060
00061 static const SMDS_MeshNode*
00062 FindNode(const SMDS_Mesh* theMesh, TInt theId){
00063 const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
00064 if(aNode) return aNode;
00065 EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
00066 }
00067
00068
00069 Driver_Mesh::Status
00070 DriverMED_R_SMESHDS_Mesh
00071 ::Perform()
00072 {
00073 Status aResult = DRS_FAIL;
00074 #ifndef _DEXCEPT_
00075 try{
00076 #endif
00077 myFamilies.clear();
00078 if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
00079 PWrapper aMed = CrWrapper(myFile,true);
00080
00081 aResult = DRS_EMPTY;
00082 if(TInt aNbMeshes = aMed->GetNbMeshes()){
00083 for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
00084
00085
00086 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
00087
00088 string aMeshName;
00089 if (myMeshId != -1) {
00090 ostringstream aMeshNameStr;
00091 aMeshNameStr<<myMeshId;
00092 aMeshName = aMeshNameStr.str();
00093 } else {
00094 aMeshName = myMeshName;
00095 }
00096 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
00097 if(aMeshName != aMeshInfo->GetName()) continue;
00098 aResult = DRS_OK;
00099
00100
00101
00102
00103
00104 TErr anErr;
00105 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
00106 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
00107 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
00108 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
00109 if(anErr >= 0){
00110 TInt aFamId = aFamilyInfo->GetId();
00111 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
00112
00113 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
00114
00115 TInt aNbGrp = aFamilyInfo->GetNbGroup();
00116 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
00117 bool isAttrOk = false;
00118 if(aFamilyInfo->GetNbAttr() == aNbGrp)
00119 isAttrOk = true;
00120 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
00121 string aGroupName = aFamilyInfo->GetGroupName(iGr);
00122 if(isAttrOk){
00123 TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
00124 aFamily->SetGroupAttributVal(anAttrVal);
00125 }
00126
00127 if(MYDEBUG) MESSAGE(aGroupName);
00128 aFamily->AddGroupName(aGroupName);
00129
00130 }
00131 aFamily->SetId( aFamId );
00132 myFamilies[aFamId] = aFamily;
00133 }
00134 }
00135
00136 if (aMeshInfo->GetType() == MED::eSTRUCTURE){
00137 buildMeshGrille(aMed,aMeshInfo);
00138 continue;
00139 }
00140
00141
00142
00143 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
00144 if (!aNodeInfo) {
00145 aResult = DRS_FAIL;
00146 continue;
00147 }
00148 aMeshInfo->myDim=aMeshInfo->mySpaceDim;
00149 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
00150
00151 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
00152 TInt aNbElems = aNodeInfo->GetNbElem();
00153 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
00154 DriverMED_FamilyPtr aFamily;
00155 for(TInt iElem = 0; iElem < aNbElems; iElem++){
00156 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
00157 double aCoords[3] = {0.0, 0.0, 0.0};
00158 for(TInt iDim = 0; iDim < 3; iDim++)
00159 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
00160 const SMDS_MeshNode* aNode;
00161 if(anIsNodeNum) {
00162 aNode = myMesh->AddNodeWithID
00163 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
00164
00165 } else {
00166 aNode = myMesh->AddNodeWithID
00167 (aCoords[0],aCoords[1],aCoords[2], iElem+1);
00168
00169 }
00170
00171
00172
00173 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
00174 if ( checkFamilyID ( aFamily, aFamNum ))
00175 {
00176 aFamily->AddElement(aNode);
00177 aFamily->SetType(SMDSAbs_Node);
00178 }
00179 }
00180
00181
00182
00183 typedef MED::TVector<int> TNodeIds;
00184 bool takeNumbers = true;
00185 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
00186 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
00187 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
00188 const EEntiteMaillage& anEntity = anEntityIter->first;
00189 if(anEntity == eNOEUD) continue;
00190
00191
00192 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
00193 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
00194 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
00195 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
00196
00197 switch(aGeom) {
00198
00199
00200 case ePOLYGONE: {
00201 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
00202 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
00203
00204 TInt aNbElem = aPolygoneInfo->GetNbElem();
00205 for(TInt iElem = 0; iElem < aNbElem; iElem++){
00206 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
00207 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
00208 TNodeIds aNodeIds(aNbConn);
00209 #ifdef _EDF_NODE_IDS_
00210 if(anIsNodeNum)
00211 for(TInt iConn = 0; iConn < aNbConn; iConn++)
00212 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
00213 else
00214 for(TInt iConn = 0; iConn < aNbConn; iConn++)
00215 aNodeIds[iConn] = aConnSlice[iConn];
00216 #else
00217 for(TInt iConn = 0; iConn < aNbConn; iConn++)
00218 aNodeIds[iConn] = aConnSlice[iConn];
00219 #endif
00220 bool isRenum = false;
00221 SMDS_MeshElement* anElement = NULL;
00222 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
00223
00224 #ifndef _DEXCEPT_
00225 try{
00226 #endif
00227 if(anIsElemNum){
00228 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
00229 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
00230
00231 }
00232 if(!anElement){
00233 vector<const SMDS_MeshNode*> aNodes(aNbConn);
00234 for(TInt iConn = 0; iConn < aNbConn; iConn++)
00235 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
00236 anElement = myMesh->AddPolygonalFace(aNodes);
00237
00238 isRenum = anIsElemNum;
00239 }
00240 #ifndef _DEXCEPT_
00241 }catch(const std::exception& exc){
00242 aResult = DRS_FAIL;
00243 }catch (...){
00244 aResult = DRS_FAIL;
00245 }
00246 #endif
00247 if(!anElement){
00248 aResult = DRS_WARN_SKIP_ELEM;
00249 }else{
00250 if(isRenum){
00251 anIsElemNum = eFAUX;
00252 takeNumbers = false;
00253 if(aResult < DRS_WARN_RENUMBER)
00254 aResult = DRS_WARN_RENUMBER;
00255 }
00256 if ( checkFamilyID ( aFamily, aFamNum ))
00257 {
00258
00259 aFamily->AddElement(anElement);
00260 aFamily->SetType(anElement->GetType());
00261 }
00262 }
00263 }
00264 break;
00265 }
00266 case ePOLYEDRE: {
00267 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
00268 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
00269
00270 TInt aNbElem = aPolyedreInfo->GetNbElem();
00271 for(TInt iElem = 0; iElem < aNbElem; iElem++){
00272 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
00273 TInt aNbFaces = aConnSliceArr.size();
00274 typedef MED::TVector<int> TQuantities;
00275 TQuantities aQuantities(aNbFaces);
00276 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
00277
00278 TNodeIds aNodeIds(aNbNodes);
00279 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
00280
00281 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
00282 TInt aNbConn = aConnSlice.size();
00283 aQuantities[iFace] = aNbConn;
00284 #ifdef _EDF_NODE_IDS_
00285
00286 if(anIsNodeNum)
00287 for(TInt iConn = 0; iConn < aNbConn; iConn++)
00288 {
00289
00290 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
00291
00292 iNode++;
00293 }
00294 else
00295 for(TInt iConn = 0; iConn < aNbConn; iConn++)
00296 {
00297
00298 aNodeIds[iNode++] = aConnSlice[iConn];
00299 }
00300 #else
00301 for(TInt iConn = 0; iConn < aNbConn; iConn++)
00302 {
00303
00304 aNodeIds[iNode++] = aConnSlice[iConn];
00305 }
00306 #endif
00307 }
00308
00309 bool isRenum = false;
00310 SMDS_MeshElement* anElement = NULL;
00311 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
00312
00313 #ifndef _DEXCEPT_
00314 try{
00315 #endif
00316 if(anIsElemNum){
00317 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
00318 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
00319
00320 }
00321 if(!anElement){
00322 vector<const SMDS_MeshNode*> aNodes(aNbNodes);
00323 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
00324 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
00325 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
00326
00327 isRenum = anIsElemNum;
00328 }
00329 #ifndef _DEXCEPT_
00330 }catch(const std::exception& exc){
00331 aResult = DRS_FAIL;
00332 }catch(...){
00333 aResult = DRS_FAIL;
00334 }
00335 #endif
00336 if(!anElement){
00337 aResult = DRS_WARN_SKIP_ELEM;
00338 }else{
00339 if(isRenum){
00340 anIsElemNum = eFAUX;
00341 takeNumbers = false;
00342 if (aResult < DRS_WARN_RENUMBER)
00343 aResult = DRS_WARN_RENUMBER;
00344 }
00345 if ( checkFamilyID ( aFamily, aFamNum )) {
00346
00347 aFamily->AddElement(anElement);
00348 aFamily->SetType(anElement->GetType());
00349 }
00350 }
00351 }
00352 break;
00353 }
00354 default: {
00355 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
00356 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
00357 TInt aNbElems = aCellInfo->GetNbElem();
00358 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
00359 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
00360
00361 TInt aNbNodes = -1;
00362 switch(aGeom){
00363 case eSEG2: aNbNodes = 2; break;
00364 case eSEG3: aNbNodes = 3; break;
00365 case eTRIA3: aNbNodes = 3; break;
00366 case eTRIA6: aNbNodes = 6; break;
00367 case eQUAD4: aNbNodes = 4; break;
00368 case eQUAD8: aNbNodes = 8; break;
00369 case eTETRA4: aNbNodes = 4; break;
00370 case eTETRA10: aNbNodes = 10; break;
00371 case ePYRA5: aNbNodes = 5; break;
00372 case ePYRA13: aNbNodes = 13; break;
00373 case ePENTA6: aNbNodes = 6; break;
00374 case ePENTA15: aNbNodes = 15; break;
00375 case eHEXA8: aNbNodes = 8; break;
00376 case eHEXA20: aNbNodes = 20; break;
00377 case ePOINT1: aNbNodes = 1; break;
00378 default:;
00379 }
00380 vector<TInt> aNodeIds(aNbNodes);
00381 for(int iElem = 0; iElem < aNbElems; iElem++){
00382 bool anIsValidConnect = false;
00383 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
00384 #ifndef _DEXCEPT_
00385 try{
00386 #endif
00387 #ifdef _EDF_NODE_IDS_
00388 if(anIsNodeNum)
00389 for(int iNode = 0; iNode < aNbNodes; iNode++)
00390 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
00391 else
00392 for(int iNode = 0; iNode < aNbNodes; iNode++)
00393 aNodeIds[iNode] = aConnSlice[iNode];
00394 #else
00395 for(int iNode = 0; iNode < aNbNodes; iNode++)
00396 aNodeIds[iNode] = aConnSlice[iNode];
00397 #endif
00398 anIsValidConnect = true;
00399 #ifndef _DEXCEPT_
00400 }catch(const std::exception& exc){
00401 INFOS("Following exception was caught:\n\t"<<exc.what());
00402 aResult = DRS_FAIL;
00403 }catch(...){
00404 INFOS("Unknown exception was cought !!!");
00405 aResult = DRS_FAIL;
00406 }
00407 #endif
00408 if(!anIsValidConnect)
00409 continue;
00410
00411 bool isRenum = false;
00412 const SMDS_MeshElement* anElement = NULL;
00413 TInt aFamNum = aCellInfo->GetFamNum(iElem);
00414 #ifndef _DEXCEPT_
00415 try{
00416 #endif
00417
00418
00419 switch(aGeom) {
00420 case ePOINT1:
00421
00422 if(anIsElemNum)
00423 anElement = myMesh->Add0DElementWithID
00424 (aNodeIds[0], aCellInfo->GetElemNum(iElem));
00425 if (!anElement) {
00426 anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
00427 isRenum = anIsElemNum;
00428 }
00429 break;
00430 case eSEG2:
00431 if(anIsElemNum)
00432 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
00433 aNodeIds[1],
00434 aCellInfo->GetElemNum(iElem));
00435 if (!anElement) {
00436 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
00437 FindNode(myMesh,aNodeIds[1]));
00438 isRenum = anIsElemNum;
00439 }
00440 break;
00441 case eSEG3:
00442 if(anIsElemNum)
00443 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
00444 aNodeIds[1],
00445 aNodeIds[2],
00446 aCellInfo->GetElemNum(iElem));
00447 if (!anElement) {
00448 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
00449 FindNode(myMesh,aNodeIds[1]),
00450 FindNode(myMesh,aNodeIds[2]));
00451 isRenum = anIsElemNum;
00452 }
00453 break;
00454 case eTRIA3:
00455 aNbNodes = 3;
00456 if(anIsElemNum)
00457 anElement = myMesh->AddFaceWithID(aNodeIds[0],
00458 aNodeIds[1],
00459 aNodeIds[2],
00460 aCellInfo->GetElemNum(iElem));
00461 if (!anElement) {
00462 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
00463 FindNode(myMesh,aNodeIds[1]),
00464 FindNode(myMesh,aNodeIds[2]));
00465 isRenum = anIsElemNum;
00466 }
00467 break;
00468 case eTRIA6:
00469 aNbNodes = 6;
00470 if(anIsElemNum)
00471 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
00472 aNodeIds[2], aNodeIds[3],
00473 aNodeIds[4], aNodeIds[5],
00474 aCellInfo->GetElemNum(iElem));
00475 if (!anElement) {
00476 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
00477 FindNode(myMesh,aNodeIds[1]),
00478 FindNode(myMesh,aNodeIds[2]),
00479 FindNode(myMesh,aNodeIds[3]),
00480 FindNode(myMesh,aNodeIds[4]),
00481 FindNode(myMesh,aNodeIds[5]));
00482 isRenum = anIsElemNum;
00483 }
00484 break;
00485 case eQUAD4:
00486 aNbNodes = 4;
00487 if(anIsElemNum)
00488 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
00489 aNodeIds[2], aNodeIds[3],
00490 aCellInfo->GetElemNum(iElem));
00491 if (!anElement) {
00492 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
00493 FindNode(myMesh,aNodeIds[1]),
00494 FindNode(myMesh,aNodeIds[2]),
00495 FindNode(myMesh,aNodeIds[3]));
00496 isRenum = anIsElemNum;
00497 }
00498 break;
00499 case eQUAD8:
00500 aNbNodes = 8;
00501 if(anIsElemNum)
00502 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
00503 aNodeIds[2], aNodeIds[3],
00504 aNodeIds[4], aNodeIds[5],
00505 aNodeIds[6], aNodeIds[7],
00506 aCellInfo->GetElemNum(iElem));
00507 if (!anElement) {
00508 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
00509 FindNode(myMesh,aNodeIds[1]),
00510 FindNode(myMesh,aNodeIds[2]),
00511 FindNode(myMesh,aNodeIds[3]),
00512 FindNode(myMesh,aNodeIds[4]),
00513 FindNode(myMesh,aNodeIds[5]),
00514 FindNode(myMesh,aNodeIds[6]),
00515 FindNode(myMesh,aNodeIds[7]));
00516 isRenum = anIsElemNum;
00517 }
00518 break;
00519 case eTETRA4:
00520 aNbNodes = 4;
00521 if(anIsElemNum)
00522 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00523 aNodeIds[2], aNodeIds[3],
00524 aCellInfo->GetElemNum(iElem));
00525 if (!anElement) {
00526 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00527 FindNode(myMesh,aNodeIds[1]),
00528 FindNode(myMesh,aNodeIds[2]),
00529 FindNode(myMesh,aNodeIds[3]));
00530 isRenum = anIsElemNum;
00531 }
00532 break;
00533 case eTETRA10:
00534 aNbNodes = 10;
00535 if(anIsElemNum)
00536 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00537 aNodeIds[2], aNodeIds[3],
00538 aNodeIds[4], aNodeIds[5],
00539 aNodeIds[6], aNodeIds[7],
00540 aNodeIds[8], aNodeIds[9],
00541 aCellInfo->GetElemNum(iElem));
00542 if (!anElement) {
00543 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00544 FindNode(myMesh,aNodeIds[1]),
00545 FindNode(myMesh,aNodeIds[2]),
00546 FindNode(myMesh,aNodeIds[3]),
00547 FindNode(myMesh,aNodeIds[4]),
00548 FindNode(myMesh,aNodeIds[5]),
00549 FindNode(myMesh,aNodeIds[6]),
00550 FindNode(myMesh,aNodeIds[7]),
00551 FindNode(myMesh,aNodeIds[8]),
00552 FindNode(myMesh,aNodeIds[9]));
00553 isRenum = anIsElemNum;
00554 }
00555 break;
00556 case ePYRA5:
00557 aNbNodes = 5;
00558
00559 if(anIsElemNum)
00560 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00561 aNodeIds[2], aNodeIds[3],
00562 aNodeIds[4],
00563 aCellInfo->GetElemNum(iElem));
00564 if (!anElement) {
00565 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00566 FindNode(myMesh,aNodeIds[1]),
00567 FindNode(myMesh,aNodeIds[2]),
00568 FindNode(myMesh,aNodeIds[3]),
00569 FindNode(myMesh,aNodeIds[4]));
00570 isRenum = anIsElemNum;
00571 }
00572 break;
00573 case ePYRA13:
00574 aNbNodes = 13;
00575
00576 if(anIsElemNum)
00577 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00578 aNodeIds[2], aNodeIds[3],
00579 aNodeIds[4], aNodeIds[5],
00580 aNodeIds[6], aNodeIds[7],
00581 aNodeIds[8], aNodeIds[9],
00582 aNodeIds[10], aNodeIds[11],
00583 aNodeIds[12],
00584 aCellInfo->GetElemNum(iElem));
00585 if (!anElement) {
00586 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00587 FindNode(myMesh,aNodeIds[1]),
00588 FindNode(myMesh,aNodeIds[2]),
00589 FindNode(myMesh,aNodeIds[3]),
00590 FindNode(myMesh,aNodeIds[4]),
00591 FindNode(myMesh,aNodeIds[5]),
00592 FindNode(myMesh,aNodeIds[6]),
00593 FindNode(myMesh,aNodeIds[7]),
00594 FindNode(myMesh,aNodeIds[8]),
00595 FindNode(myMesh,aNodeIds[9]),
00596 FindNode(myMesh,aNodeIds[10]),
00597 FindNode(myMesh,aNodeIds[11]),
00598 FindNode(myMesh,aNodeIds[12]));
00599 isRenum = anIsElemNum;
00600 }
00601 break;
00602 case ePENTA6:
00603 aNbNodes = 6;
00604 if(anIsElemNum)
00605 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
00606 aNodeIds[1],
00607 aNodeIds[2],
00608 aNodeIds[3],
00609 aNodeIds[4],
00610 aNodeIds[5],
00611 aCellInfo->GetElemNum(iElem));
00612 if (!anElement) {
00613 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00614 FindNode(myMesh,aNodeIds[1]),
00615 FindNode(myMesh,aNodeIds[2]),
00616 FindNode(myMesh,aNodeIds[3]),
00617 FindNode(myMesh,aNodeIds[4]),
00618 FindNode(myMesh,aNodeIds[5]));
00619 isRenum = anIsElemNum;
00620 }
00621 break;
00622 case ePENTA15:
00623 aNbNodes = 15;
00624 if(anIsElemNum)
00625 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00626 aNodeIds[2], aNodeIds[3],
00627 aNodeIds[4], aNodeIds[5],
00628 aNodeIds[6], aNodeIds[7],
00629 aNodeIds[8], aNodeIds[9],
00630 aNodeIds[10], aNodeIds[11],
00631 aNodeIds[12], aNodeIds[13],
00632 aNodeIds[14],
00633 aCellInfo->GetElemNum(iElem));
00634 if (!anElement) {
00635 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00636 FindNode(myMesh,aNodeIds[1]),
00637 FindNode(myMesh,aNodeIds[2]),
00638 FindNode(myMesh,aNodeIds[3]),
00639 FindNode(myMesh,aNodeIds[4]),
00640 FindNode(myMesh,aNodeIds[5]),
00641 FindNode(myMesh,aNodeIds[6]),
00642 FindNode(myMesh,aNodeIds[7]),
00643 FindNode(myMesh,aNodeIds[8]),
00644 FindNode(myMesh,aNodeIds[9]),
00645 FindNode(myMesh,aNodeIds[10]),
00646 FindNode(myMesh,aNodeIds[11]),
00647 FindNode(myMesh,aNodeIds[12]),
00648 FindNode(myMesh,aNodeIds[13]),
00649 FindNode(myMesh,aNodeIds[14]));
00650 isRenum = anIsElemNum;
00651 }
00652 break;
00653 case eHEXA8:
00654 aNbNodes = 8;
00655 if(anIsElemNum)
00656 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
00657 aNodeIds[1],
00658 aNodeIds[2],
00659 aNodeIds[3],
00660 aNodeIds[4],
00661 aNodeIds[5],
00662 aNodeIds[6],
00663 aNodeIds[7],
00664 aCellInfo->GetElemNum(iElem));
00665 if (!anElement) {
00666 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00667 FindNode(myMesh,aNodeIds[1]),
00668 FindNode(myMesh,aNodeIds[2]),
00669 FindNode(myMesh,aNodeIds[3]),
00670 FindNode(myMesh,aNodeIds[4]),
00671 FindNode(myMesh,aNodeIds[5]),
00672 FindNode(myMesh,aNodeIds[6]),
00673 FindNode(myMesh,aNodeIds[7]));
00674 isRenum = anIsElemNum;
00675 }
00676 break;
00677 case eHEXA20:
00678 aNbNodes = 20;
00679 if(anIsElemNum)
00680 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00681 aNodeIds[2], aNodeIds[3],
00682 aNodeIds[4], aNodeIds[5],
00683 aNodeIds[6], aNodeIds[7],
00684 aNodeIds[8], aNodeIds[9],
00685 aNodeIds[10], aNodeIds[11],
00686 aNodeIds[12], aNodeIds[13],
00687 aNodeIds[14], aNodeIds[15],
00688 aNodeIds[16], aNodeIds[17],
00689 aNodeIds[18], aNodeIds[19],
00690 aCellInfo->GetElemNum(iElem));
00691 if (!anElement) {
00692 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00693 FindNode(myMesh,aNodeIds[1]),
00694 FindNode(myMesh,aNodeIds[2]),
00695 FindNode(myMesh,aNodeIds[3]),
00696 FindNode(myMesh,aNodeIds[4]),
00697 FindNode(myMesh,aNodeIds[5]),
00698 FindNode(myMesh,aNodeIds[6]),
00699 FindNode(myMesh,aNodeIds[7]),
00700 FindNode(myMesh,aNodeIds[8]),
00701 FindNode(myMesh,aNodeIds[9]),
00702 FindNode(myMesh,aNodeIds[10]),
00703 FindNode(myMesh,aNodeIds[11]),
00704 FindNode(myMesh,aNodeIds[12]),
00705 FindNode(myMesh,aNodeIds[13]),
00706 FindNode(myMesh,aNodeIds[14]),
00707 FindNode(myMesh,aNodeIds[15]),
00708 FindNode(myMesh,aNodeIds[16]),
00709 FindNode(myMesh,aNodeIds[17]),
00710 FindNode(myMesh,aNodeIds[18]),
00711 FindNode(myMesh,aNodeIds[19]));
00712 isRenum = anIsElemNum;
00713 }
00714 break;
00715 }
00716
00717
00718
00719
00720
00721
00722 #ifndef _DEXCEPT_
00723 }catch(const std::exception& exc){
00724 INFOS("The following exception was caught:\n\t"<<exc.what());
00725 aResult = DRS_FAIL;
00726 }catch(...){
00727 INFOS("Unknown exception was caught !!!");
00728 aResult = DRS_FAIL;
00729 }
00730 #endif
00731 if (!anElement) {
00732 aResult = DRS_WARN_SKIP_ELEM;
00733 }
00734 else {
00735 if (isRenum) {
00736 anIsElemNum = eFAUX;
00737 takeNumbers = false;
00738 if (aResult < DRS_WARN_RENUMBER)
00739 aResult = DRS_WARN_RENUMBER;
00740 }
00741 if ( checkFamilyID ( aFamily, aFamNum )) {
00742
00743 myFamilies[aFamNum]->AddElement(anElement);
00744 myFamilies[aFamNum]->SetType(anElement->GetType());
00745 }
00746 }
00747 }
00748 }}
00749 }
00750 }
00751 }
00752 }
00753 #ifndef _DEXCEPT_
00754 }catch(const std::exception& exc){
00755 INFOS("The following exception was caught:\n\t"<<exc.what());
00756 aResult = DRS_FAIL;
00757 }catch(...){
00758 INFOS("Unknown exception was caught !!!");
00759 aResult = DRS_FAIL;
00760 }
00761 #endif
00762 if (myMesh)
00763 myMesh->compactMesh();
00764 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
00765 return aResult;
00766 }
00767
00768 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
00769 {
00770 list<string> aMeshNames;
00771
00772 try {
00773 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
00774 theStatus = DRS_OK;
00775 PWrapper aMed = CrWrapper(myFile);
00776
00777 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
00778 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
00779
00780
00781 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
00782 aMeshNames.push_back(aMeshInfo->GetName());
00783 }
00784 }
00785 }catch(const std::exception& exc){
00786 INFOS("Following exception was caught:\n\t"<<exc.what());
00787 theStatus = DRS_FAIL;
00788 }catch(...){
00789 INFOS("Unknown exception was caught !!!");
00790 theStatus = DRS_FAIL;
00791 }
00792
00793 return aMeshNames;
00794 }
00795
00796 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
00797 {
00798 list<TNameAndType> aResult;
00799 set<TNameAndType> aResGroupNames;
00800
00801 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
00802 for (; aFamsIter != myFamilies.end(); aFamsIter++)
00803 {
00804 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
00805 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
00806 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
00807 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
00808 {
00809 const set< SMDSAbs_ElementType >& types = aFamily->GetTypes();
00810 set< SMDSAbs_ElementType >::const_iterator type = types.begin();
00811 for ( ; type != types.end(); ++type )
00812 {
00813 TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
00814 if ( aResGroupNames.insert( aNameAndType ).second ) {
00815 aResult.push_back( aNameAndType );
00816 }
00817 }
00818 }
00819 }
00820
00821 return aResult;
00822 }
00823
00824 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
00825 {
00826 string aGroupName (theGroup->GetStoreName());
00827 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
00828
00829 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
00830 for (; aFamsIter != myFamilies.end(); aFamsIter++)
00831 {
00832 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
00833 if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName))
00834 {
00835 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
00836 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
00837 for (; anElemsIter != anElements.end(); anElemsIter++)
00838 {
00839 const SMDS_MeshElement * element = *anElemsIter;
00840 if ( element->GetType() == theGroup->GetType() )
00841 theGroup->SMDSGroup().Add(element);
00842 }
00843 int aGroupAttrVal = aFamily->GetGroupAttributVal();
00844 if( aGroupAttrVal != 0)
00845 theGroup->SetColorGroup(aGroupAttrVal);
00846
00847
00848 }
00849 }
00850 }
00851
00852 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
00853 const int theId)
00854 {
00855 char submeshGrpName[ 30 ];
00856 sprintf( submeshGrpName, "SubMesh %d", theId );
00857 string aName (submeshGrpName);
00858 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
00859 for (; aFamsIter != myFamilies.end(); aFamsIter++)
00860 {
00861 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
00862 if (aFamily->MemberOf(aName))
00863 {
00864 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
00865 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
00866 if (aFamily->GetType() == SMDSAbs_Node)
00867 {
00868 for (; anElemsIter != anElements.end(); anElemsIter++)
00869 {
00870 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
00871 theSubMesh->AddNode(node);
00872 }
00873 }
00874 else
00875 {
00876 for (; anElemsIter != anElements.end(); anElemsIter++)
00877 {
00878 theSubMesh->AddElement(*anElemsIter);
00879 }
00880 }
00881 }
00882 }
00883 }
00884
00885 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
00886 {
00887 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
00888 for (; aFamsIter != myFamilies.end(); aFamsIter++)
00889 {
00890 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
00891 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
00892 set<string>::iterator aGrNamesIter = aGroupNames.begin();
00893 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
00894 {
00895 string aName = *aGrNamesIter;
00896
00897 if (aName.substr(0, 7) == string("SubMesh"))
00898 {
00899 int Id = atoi(string(aName).substr(7).c_str());
00900 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
00901 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
00902 if (aFamily->GetType() == SMDSAbs_Node)
00903 {
00904 for (; anElemsIter != anElements.end(); anElemsIter++)
00905 {
00906 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
00907 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
00908
00909 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
00910 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
00911 switch ( aShapeType ) {
00912 case TopAbs_FACE:
00913 myMesh->SetNodeOnFace(node, Id); break;
00914 case TopAbs_EDGE:
00915 myMesh->SetNodeOnEdge(node, Id); break;
00916 case TopAbs_VERTEX:
00917 myMesh->SetNodeOnVertex(node, Id); break;
00918 default:
00919 myMesh->SetNodeInVolume(node, Id);
00920 }
00921 }
00922 }
00923 else
00924 {
00925 for (; anElemsIter != anElements.end(); anElemsIter++)
00926 {
00927 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
00928 }
00929 }
00930 }
00931 }
00932 }
00933 }
00940 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
00941 {
00942 if ( !aFamily || aFamily->GetId() != anID ) {
00943 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
00944 if ( i_fam == myFamilies.end() )
00945 return false;
00946 aFamily = i_fam->second;
00947 }
00948 return ( aFamily->GetId() == anID );
00949 }
00950
00951
00957 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
00958 const MED::PMeshInfo& theMeshInfo)
00959 {
00960 bool res = true;
00961
00962 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
00963 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
00964 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
00965 MED::TInt aMeshDim = theMeshInfo->GetDim();
00966 DriverMED_FamilyPtr aFamily;
00967 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
00968 double aCoords[3] = {0.0, 0.0, 0.0};
00969 const SMDS_MeshNode* aNode;
00970 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
00971 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
00972 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
00973 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],iNode+1);
00974 if (!aNode) {
00975 EXCEPTION(runtime_error,"buildMeshGrille Error. Node not created! "<<(int)iNode);
00976 }
00977
00978 if((aGrilleInfo->myFamNumNode).size() > 0){
00979 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
00980 if ( checkFamilyID ( aFamily, aFamNum ))
00981 {
00982 aFamily->AddElement(aNode);
00983 aFamily->SetType(SMDSAbs_Node);
00984 }
00985 }
00986
00987 }
00988
00989 SMDS_MeshElement* anElement = NULL;
00990 MED::TIntVector aNodeIds;
00991 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
00992 aNodeIds = aGrilleInfo->GetConn(iCell);
00993 switch(aGrilleInfo->GetGeom()){
00994 case MED::eSEG2:
00995 if(aNodeIds.size() != 2){
00996 res = false;
00997 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
00998 }
00999 anElement = myMesh->AddEdgeWithID(aNodeIds[0]+1,
01000 aNodeIds[1]+1,
01001 iCell+1);
01002 break;
01003 case MED::eQUAD4:
01004 if(aNodeIds.size() != 4){
01005 res = false;
01006 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
01007 }
01008 anElement = myMesh->AddFaceWithID(aNodeIds[0]+1,
01009 aNodeIds[2]+1,
01010 aNodeIds[3]+1,
01011 aNodeIds[1]+1,
01012 iCell+1);
01013 break;
01014 case MED::eHEXA8:
01015 if(aNodeIds.size() != 8){
01016 res = false;
01017 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
01018 }
01019 anElement = myMesh->AddVolumeWithID(aNodeIds[0]+1,
01020 aNodeIds[2]+1,
01021 aNodeIds[3]+1,
01022 aNodeIds[1]+1,
01023 aNodeIds[4]+1,
01024 aNodeIds[6]+1,
01025 aNodeIds[7]+1,
01026 aNodeIds[5]+1,
01027 iCell+1);
01028 break;
01029 default:
01030 break;
01031 }
01032 if (!anElement) {
01033 EXCEPTION(runtime_error,"buildMeshGrille Error. Element not created! "<<iCell);
01034 }
01035 if((aGrilleInfo->myFamNum).size() > 0){
01036 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
01037 if ( checkFamilyID ( aFamily, aFamNum )){
01038 aFamily->AddElement(anElement);
01039 aFamily->SetType(anElement->GetType());
01040 }
01041 }
01042 }
01043
01044 return res;
01045 }