1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH DriverMED : driver to read and write 'med' files
24 // File : DriverMED_R_SMESHDS_Mesh.cxx
27 #include "DriverMED_R_SMESHDS_Mesh.h"
28 #include "SMESHDS_Mesh.hxx"
29 #include "utilities.h"
31 #include "DriverMED_Family.h"
33 #include "SMESHDS_Group.hxx"
35 #include "MED_Factory.hxx"
36 #include "MED_CoordUtils.hxx"
37 #include "MED_Utilities.hxx"
42 static int MYDEBUG = 1;
45 static int MYDEBUG = 0;
48 #define _EDF_NODE_IDS_
54 DriverMED_R_SMESHDS_Mesh
55 ::SetMeshName(string theMeshName)
57 myMeshName = theMeshName;
60 static const SMDS_MeshNode*
61 FindNode(const SMDS_Mesh* theMesh, TInt theId)
63 const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
64 if(aNode) return aNode;
65 EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
70 DriverMED_R_SMESHDS_Mesh
73 Status aResult = DRS_FAIL;
78 if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
79 PWrapper aMed = CrWrapper(myFile,true);
82 if(TInt aNbMeshes = aMed->GetNbMeshes()){
83 for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
84 // Reading the MED mesh
85 //---------------------
86 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
90 ostringstream aMeshNameStr;
91 aMeshNameStr<<myMeshId;
92 aMeshName = aMeshNameStr.str();
94 aMeshName = myMeshName;
96 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
97 if(aMeshName != aMeshInfo->GetName()) continue;
100 // Reading MED families to the temporary structure
101 //------------------------------------------------
103 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
104 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
105 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
106 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
108 TInt aFamId = aFamilyInfo->GetId();
109 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
111 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
113 TInt aNbGrp = aFamilyInfo->GetNbGroup();
114 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
115 bool isAttrOk = false;
116 if(aFamilyInfo->GetNbAttr() == aNbGrp)
118 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
119 string aGroupName = aFamilyInfo->GetGroupName(iGr);
121 TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
122 aFamily->SetGroupAttributVal(anAttrVal);
125 if(MYDEBUG) MESSAGE(aGroupName);
126 aFamily->AddGroupName(aGroupName);
129 aFamily->SetId( aFamId );
130 myFamilies[aFamId] = aFamily;
134 if (aMeshInfo->GetType() == MED::eSTRUCTURE){
135 /*bool aRes = */buildMeshGrille(aMed,aMeshInfo);
139 // Reading MED nodes to the corresponding SMDS structure
140 //------------------------------------------------------
141 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
146 aMeshInfo->myDim=aMeshInfo->mySpaceDim;// ignore meshdim in MEDFile because it can be false
147 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
149 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
150 TInt aNbElems = aNodeInfo->GetNbElem();
151 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
152 DriverMED_FamilyPtr aFamily;
153 for(TInt iElem = 0; iElem < aNbElems; iElem++){
154 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
155 double aCoords[3] = {0.0, 0.0, 0.0};
156 for(TInt iDim = 0; iDim < 3; iDim++)
157 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
158 const SMDS_MeshNode* aNode;
160 aNode = myMesh->AddNodeWithID
161 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
163 aNode = myMesh->AddNodeWithID
164 (aCoords[0],aCoords[1],aCoords[2], iElem+1);
167 // Save reference to this node from its family
168 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
169 if ( checkFamilyID ( aFamily, aFamNum ))
171 aFamily->AddElement(aNode);
172 aFamily->SetType(SMDSAbs_Node);
176 // Reading pre information about all MED cells
177 //--------------------------------------------
178 typedef MED::TVector<int> TNodeIds;
179 bool takeNumbers = true; // initially we trust the numbers from file
180 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
181 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
182 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
183 const EEntiteMaillage& anEntity = anEntityIter->first;
184 if(anEntity == eNOEUD) continue;
185 // Reading MED cells to the corresponding SMDS structure
186 //------------------------------------------------------
187 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
188 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
189 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
190 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
193 // case ePOINT1: ## PAL16410
196 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
197 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
199 TInt aNbElem = aPolygoneInfo->GetNbElem();
200 for(TInt iElem = 0; iElem < aNbElem; iElem++){
201 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
202 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
203 TNodeIds aNodeIds(aNbConn);
204 #ifdef _EDF_NODE_IDS_
206 for(TInt iConn = 0; iConn < aNbConn; iConn++)
207 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
209 for(TInt iConn = 0; iConn < aNbConn; iConn++)
210 aNodeIds[iConn] = aConnSlice[iConn];
212 for(TInt iConn = 0; iConn < aNbConn; iConn++)
213 aNodeIds[iConn] = aConnSlice[iConn];
215 bool isRenum = false;
216 SMDS_MeshElement* anElement = NULL;
217 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
223 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
224 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
227 vector<const SMDS_MeshNode*> aNodes(aNbConn);
228 for(TInt iConn = 0; iConn < aNbConn; iConn++)
229 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
230 anElement = myMesh->AddPolygonalFace(aNodes);
231 isRenum = anIsElemNum;
234 }catch(const std::exception& exc){
241 aResult = DRS_WARN_SKIP_ELEM;
246 if(aResult < DRS_WARN_RENUMBER)
247 aResult = DRS_WARN_RENUMBER;
249 if ( checkFamilyID ( aFamily, aFamNum ))
251 // Save reference to this element from its family
252 aFamily->AddElement(anElement);
253 aFamily->SetType(anElement->GetType());
260 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
261 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
263 TInt aNbElem = aPolyedreInfo->GetNbElem();
264 for(TInt iElem = 0; iElem < aNbElem; iElem++){
265 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
266 TInt aNbFaces = aConnSliceArr.size();
267 typedef MED::TVector<int> TQuantities;
268 TQuantities aQuantities(aNbFaces);
269 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
270 TNodeIds aNodeIds(aNbNodes);
271 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
272 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
273 TInt aNbConn = aConnSlice.size();
274 aQuantities[iFace] = aNbConn;
275 #ifdef _EDF_NODE_IDS_
277 for(TInt iConn = 0; iConn < aNbConn; iConn++)
279 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
283 for(TInt iConn = 0; iConn < aNbConn; iConn++)
285 aNodeIds[iNode++] = aConnSlice[iConn];
288 for(TInt iConn = 0; iConn < aNbConn; iConn++)
290 aNodeIds[iNode++] = aConnSlice[iConn];
295 bool isRenum = false;
296 SMDS_MeshElement* anElement = NULL;
297 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
303 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
304 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
307 vector<const SMDS_MeshNode*> aNodes(aNbNodes);
308 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
309 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
310 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
311 isRenum = anIsElemNum;
314 }catch(const std::exception& exc){
321 aResult = DRS_WARN_SKIP_ELEM;
326 if (aResult < DRS_WARN_RENUMBER)
327 aResult = DRS_WARN_RENUMBER;
329 if ( checkFamilyID ( aFamily, aFamNum )) {
330 // Save reference to this element from its family
331 aFamily->AddElement(anElement);
332 aFamily->SetType(anElement->GetType());
339 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
340 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
341 TInt aNbElems = aCellInfo->GetNbElem();
342 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
343 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
347 case eSEG2: aNbNodes = 2; break;
348 case eSEG3: aNbNodes = 3; break;
349 case eTRIA3: aNbNodes = 3; break;
350 case eTRIA6: aNbNodes = 6; break;
351 case eQUAD4: aNbNodes = 4; break;
352 case eQUAD8: aNbNodes = 8; break;
353 case eQUAD9: aNbNodes = 9; break;
354 case eTETRA4: aNbNodes = 4; break;
355 case eTETRA10: aNbNodes = 10; break;
356 case ePYRA5: aNbNodes = 5; break;
357 case ePYRA13: aNbNodes = 13; break;
358 case ePENTA6: aNbNodes = 6; break;
359 case ePENTA15: aNbNodes = 15; break;
360 case eHEXA8: aNbNodes = 8; break;
361 case eHEXA20: aNbNodes = 20; break;
362 case eHEXA27: aNbNodes = 27; break;
363 case eOCTA12: aNbNodes = 12; break;
364 case ePOINT1: aNbNodes = 1; break;
367 vector<TInt> aNodeIds(aNbNodes);
368 for(int iElem = 0; iElem < aNbElems; iElem++){
369 bool anIsValidConnect = false;
370 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
374 #ifdef _EDF_NODE_IDS_
376 for(int iNode = 0; iNode < aNbNodes; iNode++)
377 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
379 for(int iNode = 0; iNode < aNbNodes; iNode++)
380 aNodeIds[iNode] = aConnSlice[iNode];
382 for(int iNode = 0; iNode < aNbNodes; iNode++)
383 aNodeIds[iNode] = aConnSlice[iNode];
385 anIsValidConnect = true;
387 }catch(const std::exception& exc){
388 INFOS("Following exception was caught:\n\t"<<exc.what());
391 INFOS("Unknown exception was cought !!!");
395 if(!anIsValidConnect)
398 bool isRenum = false;
399 const SMDS_MeshElement* anElement = NULL;
400 TInt aFamNum = aCellInfo->GetFamNum(iElem);
404 //MESSAGE("Try to create element # " << iElem << " with id = "
405 // << aCellInfo->GetElemNum(iElem));
408 //anElement = FindNode(myMesh,aNodeIds[0]);
410 anElement = myMesh->Add0DElementWithID
411 (aNodeIds[0], aCellInfo->GetElemNum(iElem));
413 anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
414 isRenum = anIsElemNum;
419 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
421 aCellInfo->GetElemNum(iElem));
423 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
424 FindNode(myMesh,aNodeIds[1]));
425 isRenum = anIsElemNum;
430 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
433 aCellInfo->GetElemNum(iElem));
435 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
436 FindNode(myMesh,aNodeIds[1]),
437 FindNode(myMesh,aNodeIds[2]));
438 isRenum = anIsElemNum;
444 anElement = myMesh->AddFaceWithID(aNodeIds[0],
447 aCellInfo->GetElemNum(iElem));
449 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
450 FindNode(myMesh,aNodeIds[1]),
451 FindNode(myMesh,aNodeIds[2]));
452 isRenum = anIsElemNum;
458 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
459 aNodeIds[2], aNodeIds[3],
460 aNodeIds[4], aNodeIds[5],
461 aCellInfo->GetElemNum(iElem));
463 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
464 FindNode(myMesh,aNodeIds[1]),
465 FindNode(myMesh,aNodeIds[2]),
466 FindNode(myMesh,aNodeIds[3]),
467 FindNode(myMesh,aNodeIds[4]),
468 FindNode(myMesh,aNodeIds[5]));
469 isRenum = anIsElemNum;
475 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
476 aNodeIds[2], aNodeIds[3],
477 aCellInfo->GetElemNum(iElem));
479 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
480 FindNode(myMesh,aNodeIds[1]),
481 FindNode(myMesh,aNodeIds[2]),
482 FindNode(myMesh,aNodeIds[3]));
483 isRenum = anIsElemNum;
489 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
490 aNodeIds[2], aNodeIds[3],
491 aNodeIds[4], aNodeIds[5],
492 aNodeIds[6], aNodeIds[7],
493 aCellInfo->GetElemNum(iElem));
495 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
496 FindNode(myMesh,aNodeIds[1]),
497 FindNode(myMesh,aNodeIds[2]),
498 FindNode(myMesh,aNodeIds[3]),
499 FindNode(myMesh,aNodeIds[4]),
500 FindNode(myMesh,aNodeIds[5]),
501 FindNode(myMesh,aNodeIds[6]),
502 FindNode(myMesh,aNodeIds[7]));
503 isRenum = anIsElemNum;
509 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
510 aNodeIds[2], aNodeIds[3],
511 aNodeIds[4], aNodeIds[5],
512 aNodeIds[6], aNodeIds[7], aNodeIds[8],
513 aCellInfo->GetElemNum(iElem));
515 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
516 FindNode(myMesh,aNodeIds[1]),
517 FindNode(myMesh,aNodeIds[2]),
518 FindNode(myMesh,aNodeIds[3]),
519 FindNode(myMesh,aNodeIds[4]),
520 FindNode(myMesh,aNodeIds[5]),
521 FindNode(myMesh,aNodeIds[6]),
522 FindNode(myMesh,aNodeIds[7]),
523 FindNode(myMesh,aNodeIds[8]));
524 isRenum = anIsElemNum;
530 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
531 aNodeIds[2], aNodeIds[3],
532 aCellInfo->GetElemNum(iElem));
534 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
535 FindNode(myMesh,aNodeIds[1]),
536 FindNode(myMesh,aNodeIds[2]),
537 FindNode(myMesh,aNodeIds[3]));
538 isRenum = anIsElemNum;
544 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
545 aNodeIds[2], aNodeIds[3],
546 aNodeIds[4], aNodeIds[5],
547 aNodeIds[6], aNodeIds[7],
548 aNodeIds[8], aNodeIds[9],
549 aCellInfo->GetElemNum(iElem));
551 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
552 FindNode(myMesh,aNodeIds[1]),
553 FindNode(myMesh,aNodeIds[2]),
554 FindNode(myMesh,aNodeIds[3]),
555 FindNode(myMesh,aNodeIds[4]),
556 FindNode(myMesh,aNodeIds[5]),
557 FindNode(myMesh,aNodeIds[6]),
558 FindNode(myMesh,aNodeIds[7]),
559 FindNode(myMesh,aNodeIds[8]),
560 FindNode(myMesh,aNodeIds[9]));
561 isRenum = anIsElemNum;
567 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
568 aNodeIds[2], aNodeIds[3],
570 aCellInfo->GetElemNum(iElem));
572 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
573 FindNode(myMesh,aNodeIds[1]),
574 FindNode(myMesh,aNodeIds[2]),
575 FindNode(myMesh,aNodeIds[3]),
576 FindNode(myMesh,aNodeIds[4]));
577 isRenum = anIsElemNum;
583 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
584 aNodeIds[2], aNodeIds[3],
585 aNodeIds[4], aNodeIds[5],
586 aNodeIds[6], aNodeIds[7],
587 aNodeIds[8], aNodeIds[9],
588 aNodeIds[10], aNodeIds[11],
590 aCellInfo->GetElemNum(iElem));
592 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
593 FindNode(myMesh,aNodeIds[1]),
594 FindNode(myMesh,aNodeIds[2]),
595 FindNode(myMesh,aNodeIds[3]),
596 FindNode(myMesh,aNodeIds[4]),
597 FindNode(myMesh,aNodeIds[5]),
598 FindNode(myMesh,aNodeIds[6]),
599 FindNode(myMesh,aNodeIds[7]),
600 FindNode(myMesh,aNodeIds[8]),
601 FindNode(myMesh,aNodeIds[9]),
602 FindNode(myMesh,aNodeIds[10]),
603 FindNode(myMesh,aNodeIds[11]),
604 FindNode(myMesh,aNodeIds[12]));
605 isRenum = anIsElemNum;
611 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
617 aCellInfo->GetElemNum(iElem));
619 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
620 FindNode(myMesh,aNodeIds[1]),
621 FindNode(myMesh,aNodeIds[2]),
622 FindNode(myMesh,aNodeIds[3]),
623 FindNode(myMesh,aNodeIds[4]),
624 FindNode(myMesh,aNodeIds[5]));
625 isRenum = anIsElemNum;
631 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
632 aNodeIds[2], aNodeIds[3],
633 aNodeIds[4], aNodeIds[5],
634 aNodeIds[6], aNodeIds[7],
635 aNodeIds[8], aNodeIds[9],
636 aNodeIds[10], aNodeIds[11],
637 aNodeIds[12], aNodeIds[13],
639 aCellInfo->GetElemNum(iElem));
641 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
642 FindNode(myMesh,aNodeIds[1]),
643 FindNode(myMesh,aNodeIds[2]),
644 FindNode(myMesh,aNodeIds[3]),
645 FindNode(myMesh,aNodeIds[4]),
646 FindNode(myMesh,aNodeIds[5]),
647 FindNode(myMesh,aNodeIds[6]),
648 FindNode(myMesh,aNodeIds[7]),
649 FindNode(myMesh,aNodeIds[8]),
650 FindNode(myMesh,aNodeIds[9]),
651 FindNode(myMesh,aNodeIds[10]),
652 FindNode(myMesh,aNodeIds[11]),
653 FindNode(myMesh,aNodeIds[12]),
654 FindNode(myMesh,aNodeIds[13]),
655 FindNode(myMesh,aNodeIds[14]));
656 isRenum = anIsElemNum;
662 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
670 aCellInfo->GetElemNum(iElem));
672 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
673 FindNode(myMesh,aNodeIds[1]),
674 FindNode(myMesh,aNodeIds[2]),
675 FindNode(myMesh,aNodeIds[3]),
676 FindNode(myMesh,aNodeIds[4]),
677 FindNode(myMesh,aNodeIds[5]),
678 FindNode(myMesh,aNodeIds[6]),
679 FindNode(myMesh,aNodeIds[7]));
680 isRenum = anIsElemNum;
687 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
688 aNodeIds[2], aNodeIds[3],
689 aNodeIds[4], aNodeIds[5],
690 aNodeIds[6], aNodeIds[7],
691 aNodeIds[8], aNodeIds[9],
692 aNodeIds[10], aNodeIds[11],
693 aNodeIds[12], aNodeIds[13],
694 aNodeIds[14], aNodeIds[15],
695 aNodeIds[16], aNodeIds[17],
696 aNodeIds[18], aNodeIds[19],
697 aCellInfo->GetElemNum(iElem));
699 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
700 FindNode(myMesh,aNodeIds[1]),
701 FindNode(myMesh,aNodeIds[2]),
702 FindNode(myMesh,aNodeIds[3]),
703 FindNode(myMesh,aNodeIds[4]),
704 FindNode(myMesh,aNodeIds[5]),
705 FindNode(myMesh,aNodeIds[6]),
706 FindNode(myMesh,aNodeIds[7]),
707 FindNode(myMesh,aNodeIds[8]),
708 FindNode(myMesh,aNodeIds[9]),
709 FindNode(myMesh,aNodeIds[10]),
710 FindNode(myMesh,aNodeIds[11]),
711 FindNode(myMesh,aNodeIds[12]),
712 FindNode(myMesh,aNodeIds[13]),
713 FindNode(myMesh,aNodeIds[14]),
714 FindNode(myMesh,aNodeIds[15]),
715 FindNode(myMesh,aNodeIds[16]),
716 FindNode(myMesh,aNodeIds[17]),
717 FindNode(myMesh,aNodeIds[18]),
718 FindNode(myMesh,aNodeIds[19]));
719 isRenum = anIsElemNum;
726 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
727 aNodeIds[2], aNodeIds[3],
728 aNodeIds[4], aNodeIds[5],
729 aNodeIds[6], aNodeIds[7],
730 aNodeIds[8], aNodeIds[9],
731 aNodeIds[10], aNodeIds[11],
732 aNodeIds[12], aNodeIds[13],
733 aNodeIds[14], aNodeIds[15],
734 aNodeIds[16], aNodeIds[17],
735 aNodeIds[18], aNodeIds[19],
736 aNodeIds[20], aNodeIds[21],
737 aNodeIds[22], aNodeIds[23],
738 aNodeIds[24], aNodeIds[25],
740 aCellInfo->GetElemNum(iElem));
742 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
743 FindNode(myMesh,aNodeIds[1]),
744 FindNode(myMesh,aNodeIds[2]),
745 FindNode(myMesh,aNodeIds[3]),
746 FindNode(myMesh,aNodeIds[4]),
747 FindNode(myMesh,aNodeIds[5]),
748 FindNode(myMesh,aNodeIds[6]),
749 FindNode(myMesh,aNodeIds[7]),
750 FindNode(myMesh,aNodeIds[8]),
751 FindNode(myMesh,aNodeIds[9]),
752 FindNode(myMesh,aNodeIds[10]),
753 FindNode(myMesh,aNodeIds[11]),
754 FindNode(myMesh,aNodeIds[12]),
755 FindNode(myMesh,aNodeIds[13]),
756 FindNode(myMesh,aNodeIds[14]),
757 FindNode(myMesh,aNodeIds[15]),
758 FindNode(myMesh,aNodeIds[16]),
759 FindNode(myMesh,aNodeIds[17]),
760 FindNode(myMesh,aNodeIds[18]),
761 FindNode(myMesh,aNodeIds[19]),
762 FindNode(myMesh,aNodeIds[20]),
763 FindNode(myMesh,aNodeIds[21]),
764 FindNode(myMesh,aNodeIds[22]),
765 FindNode(myMesh,aNodeIds[23]),
766 FindNode(myMesh,aNodeIds[24]),
767 FindNode(myMesh,aNodeIds[25]),
768 FindNode(myMesh,aNodeIds[26]));
769 isRenum = anIsElemNum;
776 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
777 aNodeIds[2], aNodeIds[3],
778 aNodeIds[4], aNodeIds[5],
779 aNodeIds[6], aNodeIds[7],
780 aNodeIds[8], aNodeIds[9],
781 aNodeIds[10], aNodeIds[11],
782 aCellInfo->GetElemNum(iElem));
784 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
785 FindNode(myMesh,aNodeIds[1]),
786 FindNode(myMesh,aNodeIds[2]),
787 FindNode(myMesh,aNodeIds[3]),
788 FindNode(myMesh,aNodeIds[4]),
789 FindNode(myMesh,aNodeIds[5]),
790 FindNode(myMesh,aNodeIds[6]),
791 FindNode(myMesh,aNodeIds[7]),
792 FindNode(myMesh,aNodeIds[8]),
793 FindNode(myMesh,aNodeIds[9]),
794 FindNode(myMesh,aNodeIds[10]),
795 FindNode(myMesh,aNodeIds[11]));
796 isRenum = anIsElemNum;
803 }catch(const std::exception& exc){
804 INFOS("The following exception was caught:\n\t"<<exc.what());
807 INFOS("Unknown exception was caught !!!");
812 aResult = DRS_WARN_SKIP_ELEM;
818 if (aResult < DRS_WARN_RENUMBER)
819 aResult = DRS_WARN_RENUMBER;
821 if ( checkFamilyID ( aFamily, aFamNum )) {
822 // Save reference to this element from its family
823 myFamilies[aFamNum]->AddElement(anElement);
824 myFamilies[aFamNum]->SetType(anElement->GetType());
834 }catch(const std::exception& exc){
835 INFOS("The following exception was caught:\n\t"<<exc.what());
838 INFOS("Unknown exception was caught !!!");
843 myMesh->compactMesh();
844 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
848 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
850 list<string> aMeshNames;
853 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
855 PWrapper aMed = CrWrapper(myFile);
857 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
858 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
859 // Reading the MED mesh
860 //---------------------
861 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
862 aMeshNames.push_back(aMeshInfo->GetName());
865 }catch(const std::exception& exc){
866 INFOS("Following exception was caught:\n\t"<<exc.what());
867 theStatus = DRS_FAIL;
869 INFOS("Unknown exception was caught !!!");
870 theStatus = DRS_FAIL;
876 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
878 list<TNameAndType> aResult;
879 set<TNameAndType> aResGroupNames;
881 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
882 for (; aFamsIter != myFamilies.end(); aFamsIter++)
884 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
885 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
886 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
887 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
889 const set< SMDSAbs_ElementType >& types = aFamily->GetTypes();
890 set< SMDSAbs_ElementType >::const_iterator type = types.begin();
891 for ( ; type != types.end(); ++type )
893 TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
894 if ( aResGroupNames.insert( aNameAndType ).second ) {
895 aResult.push_back( aNameAndType );
904 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
906 string aGroupName (theGroup->GetStoreName());
907 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
909 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
910 for (; aFamsIter != myFamilies.end(); aFamsIter++)
912 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
913 if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName))
915 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
916 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
917 for (; anElemsIter != anElements.end(); anElemsIter++)
919 const SMDS_MeshElement * element = *anElemsIter;
920 if ( element->GetType() == theGroup->GetType() ) // Issue 0020576
921 theGroup->SMDSGroup().Add(element);
923 int aGroupAttrVal = aFamily->GetGroupAttributVal();
924 if( aGroupAttrVal != 0)
925 theGroup->SetColorGroup(aGroupAttrVal);
926 // if ( element ) -- Issue 0020576
927 // theGroup->SetType( theGroup->SMDSGroup().GetType() );
932 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
935 char submeshGrpName[ 30 ];
936 sprintf( submeshGrpName, "SubMesh %d", theId );
937 string aName (submeshGrpName);
938 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
939 for (; aFamsIter != myFamilies.end(); aFamsIter++)
941 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
942 if (aFamily->MemberOf(aName))
944 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
945 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
946 if (aFamily->GetType() == SMDSAbs_Node)
948 for (; anElemsIter != anElements.end(); anElemsIter++)
950 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
951 theSubMesh->AddNode(node);
956 for (; anElemsIter != anElements.end(); anElemsIter++)
958 theSubMesh->AddElement(*anElemsIter);
965 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
967 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
968 for (; aFamsIter != myFamilies.end(); aFamsIter++)
970 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
971 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
972 set<string>::iterator aGrNamesIter = aGroupNames.begin();
973 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
975 string aName = *aGrNamesIter;
976 // Check, if this is a Group or SubMesh name
977 if (aName.substr(0, 7) == string("SubMesh"))
979 int Id = atoi(string(aName).substr(7).c_str());
980 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
981 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
982 if (aFamily->GetType() == SMDSAbs_Node)
984 for (; anElemsIter != anElements.end(); anElemsIter++)
986 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
987 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
988 // find out a shape type
989 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
990 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
991 switch ( aShapeType ) {
993 myMesh->SetNodeOnFace(node, Id); break;
995 myMesh->SetNodeOnEdge(node, Id); break;
997 myMesh->SetNodeOnVertex(node, Id); break;
999 myMesh->SetNodeInVolume(node, Id);
1005 for (; anElemsIter != anElements.end(); anElemsIter++)
1007 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
1015 * \brief Ensure aFamily to have required ID
1016 * \param aFamily - a family to check and update
1017 * \param anID - an ID aFamily should have
1018 * \retval bool - true if successful
1020 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
1022 if ( !aFamily || aFamily->GetId() != anID ) {
1023 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
1024 if ( i_fam == myFamilies.end() )
1026 aFamily = i_fam->second;
1028 return ( aFamily->GetId() == anID );
1032 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
1033 * \param theWrapper - PWrapper const pointer
1034 * \param theMeshInfo - PMeshInfo const pointer
1035 * \return TRUE, if successfully. Else FALSE
1037 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
1038 const MED::PMeshInfo& theMeshInfo)
1042 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
1043 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
1044 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
1045 MED::TInt aMeshDim = theMeshInfo->GetDim();
1046 DriverMED_FamilyPtr aFamily;
1047 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
1048 double aCoords[3] = {0.0, 0.0, 0.0};
1049 const SMDS_MeshNode* aNode;
1050 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
1051 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
1052 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
1053 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],iNode+1);
1055 EXCEPTION(runtime_error,"buildMeshGrille Error. Node not created! "<<(int)iNode);
1058 if((aGrilleInfo->myFamNumNode).size() > 0){
1059 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
1060 if ( checkFamilyID ( aFamily, aFamNum ))
1062 aFamily->AddElement(aNode);
1063 aFamily->SetType(SMDSAbs_Node);
1069 SMDS_MeshElement* anElement = NULL;
1070 MED::TIntVector aNodeIds;
1071 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
1072 aNodeIds = aGrilleInfo->GetConn(iCell);
1073 switch(aGrilleInfo->GetGeom()){
1075 if(aNodeIds.size() != 2){
1077 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
1079 anElement = myMesh->AddEdgeWithID(aNodeIds[0]+1,
1084 if(aNodeIds.size() != 4){
1086 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
1088 anElement = myMesh->AddFaceWithID(aNodeIds[0]+1,
1095 if(aNodeIds.size() != 8){
1097 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
1099 anElement = myMesh->AddVolumeWithID(aNodeIds[0]+1,
1113 EXCEPTION(runtime_error,"buildMeshGrille Error. Element not created! "<<iCell);
1115 if((aGrilleInfo->myFamNum).size() > 0){
1116 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
1117 if ( checkFamilyID ( aFamily, aFamNum )){
1118 aFamily->AddElement(anElement);
1119 aFamily->SetType(anElement->GetType());