1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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"
29 #include "DriverMED_Family.h"
30 #include "SMESHDS_Group.hxx"
31 #include "SMESHDS_Mesh.hxx"
32 #include "SMESH_Comment.hxx"
34 #include "MED_CoordUtils.hxx"
35 #include "MED_Factory.hxx"
36 #include "MED_Utilities.hxx"
38 #include <NCollection_Map.hxx>
40 #include "utilities.h"
45 static int MYDEBUG = 1;
48 static int MYDEBUG = 0;
51 #define _EDF_NODE_IDS_
56 typedef std::map<int, DriverMED_FamilyPtr> TID2FamilyMap;
60 bool buildMeshGrille(const MED::PWrapper& theWrapper,
61 const MED::PMeshInfo& theMeshInfo,
62 SMESHDS_Mesh* theMesh,
63 const TID2FamilyMap& myFamilies);
65 * \brief Ensure aFamily has a required ID
66 * \param aFamily - a family to check
67 * \param anID - an ID aFamily should have
68 * \param myFamilies - a map of the family ID to the Family
69 * \retval bool - true if successful
71 bool checkFamilyID(DriverMED_FamilyPtr & aFamily,
73 const TID2FamilyMap& myFamilies);
76 const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, TInt theId)
78 const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
79 if(aNode) return aNode;
80 EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
85 //================================================================================
87 * \brief Stores a mesh name
89 //================================================================================
91 void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName)
93 myMeshName = theMeshName;
96 //================================================================================
98 * \brief Reads a med file
100 //================================================================================
102 Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
104 using namespace DriverMED;
106 Status aResult = DRS_FAIL;
107 bool isDescConn = false; // Mantis issue 0020483
112 if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
113 PWrapper aMed = CrWrapper(myFile,true);
116 TInt aNbMeshes = aMed->GetNbMeshes();
117 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++)
119 // Reading the MED mesh
120 //---------------------
121 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
124 if (myMeshId != -1) aMeshName = SMESH_Comment( myMeshId );
125 else aMeshName = myMeshName;
127 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
128 if ( aMeshName != aMeshInfo->GetName() ) continue;
131 // Reading MED families to the temporary structure
132 //------------------------------------------------
134 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
135 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
136 for (TInt iFam = 0; iFam < aNbFams; iFam++)
138 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
140 TInt aFamId = aFamilyInfo->GetId();
141 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
143 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
145 TInt aNbGrp = aFamilyInfo->GetNbGroup();
146 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
147 bool isAttrOk = false;
148 if(aFamilyInfo->GetNbAttr() == aNbGrp)
150 for (TInt iGr = 0; iGr < aNbGrp; iGr++)
152 string aGroupName = aFamilyInfo->GetGroupName(iGr);
154 TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
155 aFamily->SetGroupAttributVal(anAttrVal);
157 if(MYDEBUG) MESSAGE(aGroupName);
158 aFamily->AddGroupName(aGroupName);
160 aFamily->SetId( aFamId );
161 myFamilies[aFamId] = aFamily;
165 if (aMeshInfo->GetType() == MED::eSTRUCTURE)
167 /*bool aRes = */DriverMED::buildMeshGrille(aMed,aMeshInfo,myMesh,myFamilies);
171 // Reading MED nodes to the corresponding SMDS structure
172 //------------------------------------------------------
173 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
178 aMeshInfo->myDim=aMeshInfo->mySpaceDim;// ignore meshdim in MEDFile because it can be false
179 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
181 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
182 TInt aNbElems = aNodeInfo->GetNbElem();
183 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
184 DriverMED_FamilyPtr aFamily;
185 for ( TInt iElem = 0; iElem < aNbElems; iElem++ )
187 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
188 double aCoords[3] = {0.0, 0.0, 0.0};
189 for(TInt iDim = 0; iDim < 3; iDim++)
190 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
191 const SMDS_MeshNode* aNode;
193 aNode = myMesh->AddNodeWithID
194 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
197 aNode = myMesh->AddNodeWithID
198 (aCoords[0],aCoords[1],aCoords[2], iElem+1);
201 // Save reference to this node from its family
202 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
203 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
205 aFamily->AddElement(aNode);
206 aFamily->SetType(SMDSAbs_Node);
210 // Are there any MED cells in descending connectivity
211 // Mantis issue 0020483
212 //---------------------------------------------------
213 NCollection_Map<EEntiteMaillage> aDescendingEntitiesMap;
215 MED::TEntityInfo aEntityInfoDesc = aMed->GetEntityInfo(aMeshInfo, eDESC);
216 MED::TEntityInfo::iterator anEntityIterDesc = aEntityInfoDesc.begin();
217 //for (; anEntityIterDesc != aEntityInfoDesc.end() && !isDescConn; anEntityIterDesc++) {
218 for (; anEntityIterDesc != aEntityInfoDesc.end(); anEntityIterDesc++) {
219 const EEntiteMaillage& anEntity = anEntityIterDesc->first;
220 aDescendingEntitiesMap.Add(anEntity);
221 //if (anEntity != eNOEUD) isDescConn = true;
225 // Reading pre information about all MED cells
226 //--------------------------------------------
227 typedef MED::TVector<int> TNodeIds;
228 bool takeNumbers = true; // initially we trust the numbers from file
229 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo, eNOD);
230 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
232 for (; anEntityIter != aEntityInfo.end(); anEntityIter++)
234 const EEntiteMaillage& anEntity = anEntityIter->first;
235 aDescendingEntitiesMap.Remove(anEntity); // Mantis issue 0020483
236 if (anEntity == eNOEUD) continue;
238 // Reading MED cells to the corresponding SMDS structure
239 //------------------------------------------------------
240 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
241 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
242 for ( ; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++)
244 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
246 if ( anEntity == eSTRUCT_ELEMENT ) // MED_BALL (issue 0021459)
248 PBallInfo aBallInfo = aMed->GetPBallInfo(aMeshInfo);
249 TInt aNbBalls = aBallInfo->GetNbElem();
251 EBooleen anIsElemNum = takeNumbers ? aBallInfo->IsElemNum() : eFAUX;
252 if ( anIsElemNum && aBallInfo->myElemNum->empty() )
255 // get supporting nodes
257 #ifdef _EDF_NODE_IDS_
259 aNodeIds.resize( aNbBalls );
260 for(TInt iBall = 0; iBall < aNbBalls && anIsNodeNum; iBall++)
262 aNodeIds[iBall] = aNodeInfo->GetElemNum( (*aBallInfo->myConn)[ iBall ]-1 );
263 anIsNodeNum = myMesh->FindNode( aNodeIds[iBall] ) ? eVRAI : eFAUX;
268 aNodeIds.swap( *(aBallInfo->myConn ));
270 // allocate array of diameters
271 vtkIdType maxID = myMesh->MaxElementID() + aNbBalls;
272 if ( anIsElemNum && !aBallInfo->myElemNum->empty() )
273 maxID = *std::max_element( aBallInfo->myElemNum->begin(),
274 aBallInfo->myElemNum->end() );
275 myMesh->getGrid()->AllocateDiameters( maxID ); // performance optimization
278 SMDS_MeshElement* anElement;
279 DriverMED_FamilyPtr aFamily;
280 for ( TInt iBall = 0; iBall < aNbBalls; iBall++)
284 if (!(anElement = myMesh->AddBallWithID( aNodeIds[iBall],
285 aBallInfo->myDiameters[iBall],
286 aBallInfo->GetElemNum(iBall))))
290 myMesh->AddBall( myMesh->FindNode( aNodeIds[iBall]),
291 aBallInfo->myDiameters[iBall] );
293 // Save reference to this element from its family
294 TInt aFamNum = aBallInfo->GetFamNum(iBall);
295 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
297 aFamily->AddElement(anElement);
298 aFamily->SetType( SMDSAbs_Ball );
303 ( takeNumbers && aBallInfo->IsElemNum() && !aBallInfo->myElemNum->empty() ))
304 if ( aResult < DRS_WARN_RENUMBER )
305 aResult = DRS_WARN_RENUMBER;
311 // case ePOINT1: ## PAL16410
316 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
317 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
319 typedef SMDS_MeshFace* (SMESHDS_Mesh::* FAddPolyWithID)
320 (const std::vector<int> & nodes_ids, const int ID);
321 typedef SMDS_MeshFace* (SMESHDS_Mesh::* FAddPolygon)
322 (const std::vector<const SMDS_MeshNode*> & nodes);
324 FAddPolyWithID addPolyWithID = & SMESHDS_Mesh::AddPolygonalFaceWithID;
325 FAddPolygon addPolygon = & SMESHDS_Mesh::AddPolygonalFace;
326 if ( aGeom == ePOLYGON2 ) {
327 addPolyWithID = & SMESHDS_Mesh::AddQuadPolygonalFaceWithID;
328 addPolygon = & SMESHDS_Mesh::AddQuadPolygonalFace;
331 vector<const SMDS_MeshNode*> aNodes;
332 const TInt aNbElem = aPolygoneInfo->GetNbElem();
333 for ( TInt iElem = 0; iElem < aNbElem; iElem++ )
335 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
336 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
337 aNodeIds.resize( aNbConn );
338 #ifdef _EDF_NODE_IDS_
340 for(TInt iConn = 0; iConn < aNbConn; iConn++)
341 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
343 for(TInt iConn = 0; iConn < aNbConn; iConn++)
344 aNodeIds[iConn] = aConnSlice[iConn];
346 for(TInt iConn = 0; iConn < aNbConn; iConn++)
347 aNodeIds[iConn] = aConnSlice[iConn];
349 bool isRenum = false;
350 SMDS_MeshElement* anElement = NULL;
351 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
356 TInt anElemId = aPolygoneInfo->GetElemNum( iElem );
357 anElement = (myMesh->*addPolyWithID)( aNodeIds, anElemId );
360 aNodes.resize( aNbConn );
361 for ( TInt iConn = 0; iConn < aNbConn; iConn++ )
362 aNodes[iConn] = FindNode( myMesh, aNodeIds[iConn] );
363 anElement = (myMesh->*addPolygon)( aNodes );
364 isRenum = anIsElemNum;
367 } catch(const std::exception& exc) {
374 aResult = DRS_WARN_SKIP_ELEM;
380 if(aResult < DRS_WARN_RENUMBER)
381 aResult = DRS_WARN_RENUMBER;
383 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
385 // Save reference to this element from its family
386 aFamily->AddElement(anElement);
387 aFamily->SetType(anElement->GetType());
394 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
395 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
397 TInt aNbElem = aPolyedreInfo->GetNbElem();
398 for(TInt iElem = 0; iElem < aNbElem; iElem++){
399 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
400 TInt aNbFaces = aConnSliceArr.size();
401 typedef MED::TVector<int> TQuantities;
402 TQuantities aQuantities(aNbFaces);
403 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
404 TNodeIds aNodeIds(aNbNodes);
405 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
406 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
407 TInt aNbConn = aConnSlice.size();
408 aQuantities[iFace] = aNbConn;
409 #ifdef _EDF_NODE_IDS_
411 for(TInt iConn = 0; iConn < aNbConn; iConn++)
413 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
417 for(TInt iConn = 0; iConn < aNbConn; iConn++)
419 aNodeIds[iNode++] = aConnSlice[iConn];
422 for(TInt iConn = 0; iConn < aNbConn; iConn++)
424 aNodeIds[iNode++] = aConnSlice[iConn];
429 bool isRenum = false;
430 SMDS_MeshElement* anElement = NULL;
431 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
437 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
438 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
441 vector<const SMDS_MeshNode*> aNodes(aNbNodes);
442 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
443 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
444 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
445 isRenum = anIsElemNum;
448 }catch(const std::exception& exc){
455 aResult = DRS_WARN_SKIP_ELEM;
460 if (aResult < DRS_WARN_RENUMBER)
461 aResult = DRS_WARN_RENUMBER;
463 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
464 // Save reference to this element from its family
465 aFamily->AddElement(anElement);
466 aFamily->SetType(anElement->GetType());
473 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
474 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
475 TInt aNbElems = aCellInfo->GetNbElem();
476 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
477 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
481 case eSEG2: aNbNodes = 2; break;
482 case eSEG3: aNbNodes = 3; break;
483 case eTRIA3: aNbNodes = 3; break;
484 case eTRIA6: aNbNodes = 6; break;
485 case eTRIA7: aNbNodes = 7; break;
486 case eQUAD4: aNbNodes = 4; break;
487 case eQUAD8: aNbNodes = 8; break;
488 case eQUAD9: aNbNodes = 9; break;
489 case eTETRA4: aNbNodes = 4; break;
490 case eTETRA10: aNbNodes = 10; break;
491 case ePYRA5: aNbNodes = 5; break;
492 case ePYRA13: aNbNodes = 13; break;
493 case ePENTA6: aNbNodes = 6; break;
494 case ePENTA15: aNbNodes = 15; break;
495 case eHEXA8: aNbNodes = 8; break;
496 case eHEXA20: aNbNodes = 20; break;
497 case eHEXA27: aNbNodes = 27; break;
498 case eOCTA12: aNbNodes = 12; break;
499 case ePOINT1: aNbNodes = 1; break;
502 vector<TInt> aNodeIds(aNbNodes);
503 for(int iElem = 0; iElem < aNbElems; iElem++){
504 bool anIsValidConnect = false;
505 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
509 #ifdef _EDF_NODE_IDS_
511 for(int iNode = 0; iNode < aNbNodes; iNode++)
512 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
514 for(int iNode = 0; iNode < aNbNodes; iNode++)
515 aNodeIds[iNode] = aConnSlice[iNode];
517 for(int iNode = 0; iNode < aNbNodes; iNode++)
518 aNodeIds[iNode] = aConnSlice[iNode];
520 anIsValidConnect = true;
522 }catch(const std::exception& exc){
523 INFOS("Following exception was caught:\n\t"<<exc.what());
526 INFOS("Unknown exception was caught !!!");
530 if(!anIsValidConnect)
533 bool isRenum = false;
534 const SMDS_MeshElement* anElement = NULL;
535 TInt aFamNum = aCellInfo->GetFamNum(iElem);
539 //MESSAGE("Try to create element # " << iElem << " with id = "
540 // << aCellInfo->GetElemNum(iElem));
543 //anElement = FindNode(myMesh,aNodeIds[0]);
545 anElement = myMesh->Add0DElementWithID
546 (aNodeIds[0], aCellInfo->GetElemNum(iElem));
548 anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
549 isRenum = anIsElemNum;
554 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
556 aCellInfo->GetElemNum(iElem));
558 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
559 FindNode(myMesh,aNodeIds[1]));
560 isRenum = anIsElemNum;
565 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
568 aCellInfo->GetElemNum(iElem));
570 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
571 FindNode(myMesh,aNodeIds[1]),
572 FindNode(myMesh,aNodeIds[2]));
573 isRenum = anIsElemNum;
579 anElement = myMesh->AddFaceWithID(aNodeIds[0],
582 aCellInfo->GetElemNum(iElem));
584 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
585 FindNode(myMesh,aNodeIds[1]),
586 FindNode(myMesh,aNodeIds[2]));
587 isRenum = anIsElemNum;
593 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
594 aNodeIds[2], aNodeIds[3],
595 aNodeIds[4], aNodeIds[5],
596 aCellInfo->GetElemNum(iElem));
598 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
599 FindNode(myMesh,aNodeIds[1]),
600 FindNode(myMesh,aNodeIds[2]),
601 FindNode(myMesh,aNodeIds[3]),
602 FindNode(myMesh,aNodeIds[4]),
603 FindNode(myMesh,aNodeIds[5]));
604 isRenum = anIsElemNum;
610 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
611 aNodeIds[2], aNodeIds[3],
612 aNodeIds[4], aNodeIds[5], aNodeIds[6],
613 aCellInfo->GetElemNum(iElem));
615 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
616 FindNode(myMesh,aNodeIds[1]),
617 FindNode(myMesh,aNodeIds[2]),
618 FindNode(myMesh,aNodeIds[3]),
619 FindNode(myMesh,aNodeIds[4]),
620 FindNode(myMesh,aNodeIds[5]),
621 FindNode(myMesh,aNodeIds[6]));
622 isRenum = anIsElemNum;
628 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
629 aNodeIds[2], aNodeIds[3],
630 aCellInfo->GetElemNum(iElem));
632 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
633 FindNode(myMesh,aNodeIds[1]),
634 FindNode(myMesh,aNodeIds[2]),
635 FindNode(myMesh,aNodeIds[3]));
636 isRenum = anIsElemNum;
642 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
643 aNodeIds[2], aNodeIds[3],
644 aNodeIds[4], aNodeIds[5],
645 aNodeIds[6], aNodeIds[7],
646 aCellInfo->GetElemNum(iElem));
648 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
649 FindNode(myMesh,aNodeIds[1]),
650 FindNode(myMesh,aNodeIds[2]),
651 FindNode(myMesh,aNodeIds[3]),
652 FindNode(myMesh,aNodeIds[4]),
653 FindNode(myMesh,aNodeIds[5]),
654 FindNode(myMesh,aNodeIds[6]),
655 FindNode(myMesh,aNodeIds[7]));
656 isRenum = anIsElemNum;
662 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
663 aNodeIds[2], aNodeIds[3],
664 aNodeIds[4], aNodeIds[5],
665 aNodeIds[6], aNodeIds[7], aNodeIds[8],
666 aCellInfo->GetElemNum(iElem));
668 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
669 FindNode(myMesh,aNodeIds[1]),
670 FindNode(myMesh,aNodeIds[2]),
671 FindNode(myMesh,aNodeIds[3]),
672 FindNode(myMesh,aNodeIds[4]),
673 FindNode(myMesh,aNodeIds[5]),
674 FindNode(myMesh,aNodeIds[6]),
675 FindNode(myMesh,aNodeIds[7]),
676 FindNode(myMesh,aNodeIds[8]));
677 isRenum = anIsElemNum;
683 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
684 aNodeIds[2], aNodeIds[3],
685 aCellInfo->GetElemNum(iElem));
687 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
688 FindNode(myMesh,aNodeIds[1]),
689 FindNode(myMesh,aNodeIds[2]),
690 FindNode(myMesh,aNodeIds[3]));
691 isRenum = anIsElemNum;
697 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
698 aNodeIds[2], aNodeIds[3],
699 aNodeIds[4], aNodeIds[5],
700 aNodeIds[6], aNodeIds[7],
701 aNodeIds[8], aNodeIds[9],
702 aCellInfo->GetElemNum(iElem));
704 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
705 FindNode(myMesh,aNodeIds[1]),
706 FindNode(myMesh,aNodeIds[2]),
707 FindNode(myMesh,aNodeIds[3]),
708 FindNode(myMesh,aNodeIds[4]),
709 FindNode(myMesh,aNodeIds[5]),
710 FindNode(myMesh,aNodeIds[6]),
711 FindNode(myMesh,aNodeIds[7]),
712 FindNode(myMesh,aNodeIds[8]),
713 FindNode(myMesh,aNodeIds[9]));
714 isRenum = anIsElemNum;
720 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
721 aNodeIds[2], aNodeIds[3],
723 aCellInfo->GetElemNum(iElem));
725 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
726 FindNode(myMesh,aNodeIds[1]),
727 FindNode(myMesh,aNodeIds[2]),
728 FindNode(myMesh,aNodeIds[3]),
729 FindNode(myMesh,aNodeIds[4]));
730 isRenum = anIsElemNum;
736 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
737 aNodeIds[2], aNodeIds[3],
738 aNodeIds[4], aNodeIds[5],
739 aNodeIds[6], aNodeIds[7],
740 aNodeIds[8], aNodeIds[9],
741 aNodeIds[10], aNodeIds[11],
743 aCellInfo->GetElemNum(iElem));
745 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
746 FindNode(myMesh,aNodeIds[1]),
747 FindNode(myMesh,aNodeIds[2]),
748 FindNode(myMesh,aNodeIds[3]),
749 FindNode(myMesh,aNodeIds[4]),
750 FindNode(myMesh,aNodeIds[5]),
751 FindNode(myMesh,aNodeIds[6]),
752 FindNode(myMesh,aNodeIds[7]),
753 FindNode(myMesh,aNodeIds[8]),
754 FindNode(myMesh,aNodeIds[9]),
755 FindNode(myMesh,aNodeIds[10]),
756 FindNode(myMesh,aNodeIds[11]),
757 FindNode(myMesh,aNodeIds[12]));
758 isRenum = anIsElemNum;
764 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
770 aCellInfo->GetElemNum(iElem));
772 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
773 FindNode(myMesh,aNodeIds[1]),
774 FindNode(myMesh,aNodeIds[2]),
775 FindNode(myMesh,aNodeIds[3]),
776 FindNode(myMesh,aNodeIds[4]),
777 FindNode(myMesh,aNodeIds[5]));
778 isRenum = anIsElemNum;
784 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
785 aNodeIds[2], aNodeIds[3],
786 aNodeIds[4], aNodeIds[5],
787 aNodeIds[6], aNodeIds[7],
788 aNodeIds[8], aNodeIds[9],
789 aNodeIds[10], aNodeIds[11],
790 aNodeIds[12], aNodeIds[13],
792 aCellInfo->GetElemNum(iElem));
794 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
795 FindNode(myMesh,aNodeIds[1]),
796 FindNode(myMesh,aNodeIds[2]),
797 FindNode(myMesh,aNodeIds[3]),
798 FindNode(myMesh,aNodeIds[4]),
799 FindNode(myMesh,aNodeIds[5]),
800 FindNode(myMesh,aNodeIds[6]),
801 FindNode(myMesh,aNodeIds[7]),
802 FindNode(myMesh,aNodeIds[8]),
803 FindNode(myMesh,aNodeIds[9]),
804 FindNode(myMesh,aNodeIds[10]),
805 FindNode(myMesh,aNodeIds[11]),
806 FindNode(myMesh,aNodeIds[12]),
807 FindNode(myMesh,aNodeIds[13]),
808 FindNode(myMesh,aNodeIds[14]));
809 isRenum = anIsElemNum;
815 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
823 aCellInfo->GetElemNum(iElem));
825 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
826 FindNode(myMesh,aNodeIds[1]),
827 FindNode(myMesh,aNodeIds[2]),
828 FindNode(myMesh,aNodeIds[3]),
829 FindNode(myMesh,aNodeIds[4]),
830 FindNode(myMesh,aNodeIds[5]),
831 FindNode(myMesh,aNodeIds[6]),
832 FindNode(myMesh,aNodeIds[7]));
833 isRenum = anIsElemNum;
840 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
841 aNodeIds[2], aNodeIds[3],
842 aNodeIds[4], aNodeIds[5],
843 aNodeIds[6], aNodeIds[7],
844 aNodeIds[8], aNodeIds[9],
845 aNodeIds[10], aNodeIds[11],
846 aNodeIds[12], aNodeIds[13],
847 aNodeIds[14], aNodeIds[15],
848 aNodeIds[16], aNodeIds[17],
849 aNodeIds[18], aNodeIds[19],
850 aCellInfo->GetElemNum(iElem));
852 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
853 FindNode(myMesh,aNodeIds[1]),
854 FindNode(myMesh,aNodeIds[2]),
855 FindNode(myMesh,aNodeIds[3]),
856 FindNode(myMesh,aNodeIds[4]),
857 FindNode(myMesh,aNodeIds[5]),
858 FindNode(myMesh,aNodeIds[6]),
859 FindNode(myMesh,aNodeIds[7]),
860 FindNode(myMesh,aNodeIds[8]),
861 FindNode(myMesh,aNodeIds[9]),
862 FindNode(myMesh,aNodeIds[10]),
863 FindNode(myMesh,aNodeIds[11]),
864 FindNode(myMesh,aNodeIds[12]),
865 FindNode(myMesh,aNodeIds[13]),
866 FindNode(myMesh,aNodeIds[14]),
867 FindNode(myMesh,aNodeIds[15]),
868 FindNode(myMesh,aNodeIds[16]),
869 FindNode(myMesh,aNodeIds[17]),
870 FindNode(myMesh,aNodeIds[18]),
871 FindNode(myMesh,aNodeIds[19]));
872 isRenum = anIsElemNum;
879 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
880 aNodeIds[2], aNodeIds[3],
881 aNodeIds[4], aNodeIds[5],
882 aNodeIds[6], aNodeIds[7],
883 aNodeIds[8], aNodeIds[9],
884 aNodeIds[10], aNodeIds[11],
885 aNodeIds[12], aNodeIds[13],
886 aNodeIds[14], aNodeIds[15],
887 aNodeIds[16], aNodeIds[17],
888 aNodeIds[18], aNodeIds[19],
889 aNodeIds[20], aNodeIds[21],
890 aNodeIds[22], aNodeIds[23],
891 aNodeIds[24], aNodeIds[25],
893 aCellInfo->GetElemNum(iElem));
895 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
896 FindNode(myMesh,aNodeIds[1]),
897 FindNode(myMesh,aNodeIds[2]),
898 FindNode(myMesh,aNodeIds[3]),
899 FindNode(myMesh,aNodeIds[4]),
900 FindNode(myMesh,aNodeIds[5]),
901 FindNode(myMesh,aNodeIds[6]),
902 FindNode(myMesh,aNodeIds[7]),
903 FindNode(myMesh,aNodeIds[8]),
904 FindNode(myMesh,aNodeIds[9]),
905 FindNode(myMesh,aNodeIds[10]),
906 FindNode(myMesh,aNodeIds[11]),
907 FindNode(myMesh,aNodeIds[12]),
908 FindNode(myMesh,aNodeIds[13]),
909 FindNode(myMesh,aNodeIds[14]),
910 FindNode(myMesh,aNodeIds[15]),
911 FindNode(myMesh,aNodeIds[16]),
912 FindNode(myMesh,aNodeIds[17]),
913 FindNode(myMesh,aNodeIds[18]),
914 FindNode(myMesh,aNodeIds[19]),
915 FindNode(myMesh,aNodeIds[20]),
916 FindNode(myMesh,aNodeIds[21]),
917 FindNode(myMesh,aNodeIds[22]),
918 FindNode(myMesh,aNodeIds[23]),
919 FindNode(myMesh,aNodeIds[24]),
920 FindNode(myMesh,aNodeIds[25]),
921 FindNode(myMesh,aNodeIds[26]));
922 isRenum = anIsElemNum;
929 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
930 aNodeIds[2], aNodeIds[3],
931 aNodeIds[4], aNodeIds[5],
932 aNodeIds[6], aNodeIds[7],
933 aNodeIds[8], aNodeIds[9],
934 aNodeIds[10], aNodeIds[11],
935 aCellInfo->GetElemNum(iElem));
937 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
938 FindNode(myMesh,aNodeIds[1]),
939 FindNode(myMesh,aNodeIds[2]),
940 FindNode(myMesh,aNodeIds[3]),
941 FindNode(myMesh,aNodeIds[4]),
942 FindNode(myMesh,aNodeIds[5]),
943 FindNode(myMesh,aNodeIds[6]),
944 FindNode(myMesh,aNodeIds[7]),
945 FindNode(myMesh,aNodeIds[8]),
946 FindNode(myMesh,aNodeIds[9]),
947 FindNode(myMesh,aNodeIds[10]),
948 FindNode(myMesh,aNodeIds[11]));
949 isRenum = anIsElemNum;
956 }catch(const std::exception& exc){
957 INFOS("The following exception was caught:\n\t"<<exc.what());
960 INFOS("Unknown exception was caught !!!");
965 aResult = DRS_WARN_SKIP_ELEM;
971 if (aResult < DRS_WARN_RENUMBER)
972 aResult = DRS_WARN_RENUMBER;
974 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
975 // Save reference to this element from its family
976 myFamilies[aFamNum]->AddElement(anElement);
977 myFamilies[aFamNum]->SetType(anElement->GetType());
984 if (aDescendingEntitiesMap.Extent()) isDescConn = true; // Mantis issue 0020483
985 } // for(int iMesh = 0; iMesh < aNbMeshes; iMesh++)
988 catch(const std::exception& exc)
990 INFOS("The following exception was caught:\n\t"<<exc.what());
995 INFOS("Unknown exception was caught !!!");
1000 myMesh->compactMesh();
1002 // Mantis issue 0020483
1003 if (aResult == DRS_OK && isDescConn) {
1004 INFOS("There are some elements in descending connectivity in med file. They were not read !!!");
1005 aResult = DRS_WARN_DESCENDING;
1008 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
1012 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
1014 list<string> aMeshNames;
1017 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
1019 PWrapper aMed = CrWrapper(myFile);
1021 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
1022 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
1023 // Reading the MED mesh
1024 //---------------------
1025 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
1026 aMeshNames.push_back(aMeshInfo->GetName());
1029 } catch(const std::exception& exc) {
1030 INFOS("Following exception was caught:\n\t"<<exc.what());
1031 theStatus = DRS_FAIL;
1033 INFOS("Unknown exception was caught !!!");
1034 theStatus = DRS_FAIL;
1040 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
1042 list<TNameAndType> aResult;
1043 set<TNameAndType> aResGroupNames;
1045 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1046 for (; aFamsIter != myFamilies.end(); aFamsIter++)
1048 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1049 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
1050 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
1051 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1053 const set< SMDSAbs_ElementType >& types = aFamily->GetTypes();
1054 set< SMDSAbs_ElementType >::const_iterator type = types.begin();
1055 for ( ; type != types.end(); ++type )
1057 TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
1058 if ( aResGroupNames.insert( aNameAndType ).second ) {
1059 aResult.push_back( aNameAndType );
1068 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
1070 string aGroupName (theGroup->GetStoreName());
1071 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
1073 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1074 for (; aFamsIter != myFamilies.end(); aFamsIter++)
1076 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1077 if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName))
1079 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
1080 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
1081 for (; anElemsIter != anElements.end(); anElemsIter++)
1083 const SMDS_MeshElement * element = *anElemsIter;
1084 if ( element->GetType() == theGroup->GetType() ) // Issue 0020576
1085 theGroup->SMDSGroup().Add(element);
1087 int aGroupAttrVal = aFamily->GetGroupAttributVal();
1088 if( aGroupAttrVal != 0)
1089 theGroup->SetColorGroup(aGroupAttrVal);
1090 // if ( element ) -- Issue 0020576
1091 // theGroup->SetType( theGroup->SMDSGroup().GetType() );
1096 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
1099 char submeshGrpName[ 30 ];
1100 sprintf( submeshGrpName, "SubMesh %d", theId );
1101 string aName (submeshGrpName);
1102 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1103 for (; aFamsIter != myFamilies.end(); aFamsIter++)
1105 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1106 if (aFamily->MemberOf(aName))
1108 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
1109 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
1110 if (aFamily->GetType() == SMDSAbs_Node)
1112 for (; anElemsIter != anElements.end(); anElemsIter++)
1114 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
1115 theSubMesh->AddNode(node);
1120 for (; anElemsIter != anElements.end(); anElemsIter++)
1122 theSubMesh->AddElement(*anElemsIter);
1129 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
1131 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1132 for (; aFamsIter != myFamilies.end(); aFamsIter++)
1134 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1135 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
1136 set<string>::iterator aGrNamesIter = aGroupNames.begin();
1137 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1139 string aName = *aGrNamesIter;
1140 // Check, if this is a Group or SubMesh name
1141 if (aName.substr(0, 7) == string("SubMesh"))
1143 int Id = atoi(string(aName).substr(7).c_str());
1144 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
1145 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
1146 if (aFamily->GetType() == SMDSAbs_Node)
1148 for (; anElemsIter != anElements.end(); anElemsIter++)
1150 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
1151 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
1152 // find out a shape type
1153 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
1154 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
1155 switch ( aShapeType ) {
1157 myMesh->SetNodeOnFace(node, Id); break;
1159 myMesh->SetNodeOnEdge(node, Id); break;
1161 myMesh->SetNodeOnVertex(node, Id); break;
1163 myMesh->SetNodeInVolume(node, Id);
1169 for (; anElemsIter != anElements.end(); anElemsIter++)
1171 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
1179 * \brief Ensure aFamily to have required ID
1180 * \param aFamily - a family to check and update
1181 * \param anID - an ID aFamily should have
1182 * \retval bool - true if successful
1184 bool DriverMED::checkFamilyID(DriverMED_FamilyPtr & aFamily,
1186 const TID2FamilyMap& myFamilies)
1188 if ( !aFamily || aFamily->GetId() != anID ) {
1189 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
1190 if ( i_fam == myFamilies.end() )
1192 aFamily = i_fam->second;
1194 return ( aFamily->GetId() == anID );
1198 * \brief Reading the structured mesh and convert to non structured
1199 * (by filling of smesh structure for non structured mesh)
1200 * \param theWrapper - PWrapper const pointer
1201 * \param theMeshInfo - PMeshInfo const pointer
1202 * \param myFamilies - a map of the family ID to the Family
1203 * \return TRUE, if successfully. Else FALSE
1205 bool DriverMED::buildMeshGrille(const MED::PWrapper& theWrapper,
1206 const MED::PMeshInfo& theMeshInfo,
1207 SMESHDS_Mesh* myMesh,
1208 const TID2FamilyMap& myFamilies)
1212 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
1213 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
1214 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
1215 MED::TInt aMeshDim = theMeshInfo->GetDim();
1216 DriverMED_FamilyPtr aFamily;
1217 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
1218 double aCoords[3] = {0.0, 0.0, 0.0};
1219 const SMDS_MeshNode* aNode;
1220 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
1221 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
1222 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
1223 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],iNode+1);
1225 EXCEPTION(runtime_error,"buildMeshGrille Error. Node not created! "<<(int)iNode);
1228 if((aGrilleInfo->myFamNumNode).size() > 0){
1229 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
1230 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
1232 aFamily->AddElement(aNode);
1233 aFamily->SetType(SMDSAbs_Node);
1239 SMDS_MeshElement* anElement = NULL;
1240 MED::TIntVector aNodeIds;
1241 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
1242 aNodeIds = aGrilleInfo->GetConn(iCell);
1243 switch(aGrilleInfo->GetGeom()){
1245 if(aNodeIds.size() != 2){
1247 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
1249 anElement = myMesh->AddEdgeWithID(aNodeIds[0]+1,
1254 if(aNodeIds.size() != 4){
1256 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
1258 anElement = myMesh->AddFaceWithID(aNodeIds[0]+1,
1265 if(aNodeIds.size() != 8){
1267 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
1269 anElement = myMesh->AddVolumeWithID(aNodeIds[0]+1,
1283 EXCEPTION(runtime_error,"buildMeshGrille Error. Element not created! "<<iCell);
1285 if((aGrilleInfo->myFamNum).size() > 0){
1286 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
1287 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )){
1288 aFamily->AddElement(anElement);
1289 aFamily->SetType(anElement->GetType());