1 // Copyright (C) 2007-2016 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 = 0;
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 if ( strncmp( aGroupName.c_str(), NIG_GROUP_PREFIX, strlen(NIG_GROUP_PREFIX) ) != 0 )
159 aFamily->AddGroupName(aGroupName);
161 aFamily->SetId( aFamId );
162 myFamilies[aFamId] = aFamily;
166 if (aMeshInfo->GetType() == MED::eSTRUCTURE)
168 /*bool aRes = */DriverMED::buildMeshGrille(aMed,aMeshInfo,myMesh,myFamilies);
172 // Reading MED nodes to the corresponding SMDS structure
173 //------------------------------------------------------
174 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
176 aResult = addMessage("No nodes", /*isFatal=*/true );
179 aMeshInfo->myDim=aMeshInfo->mySpaceDim;// ignore meshdim in MEDFile because it can be false
180 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
182 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
183 TInt aNbElems = aNodeInfo->GetNbElem();
184 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
185 DriverMED_FamilyPtr aFamily;
186 for ( TInt iElem = 0; iElem < aNbElems; iElem++ )
188 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
189 double aCoords[3] = {0.0, 0.0, 0.0};
190 for(TInt iDim = 0; iDim < 3; iDim++)
191 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
192 const SMDS_MeshNode* aNode;
194 aNode = myMesh->AddNodeWithID
195 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
198 aNode = myMesh->AddNodeWithID
199 (aCoords[0],aCoords[1],aCoords[2], iElem+1);
202 // Save reference to this node from its family
203 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
204 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
206 aFamily->AddElement(aNode);
207 aFamily->SetType(SMDSAbs_Node);
211 // Are there any MED cells in descending connectivity
212 // Mantis issue 0020483
213 //---------------------------------------------------
214 NCollection_Map<EEntiteMaillage> aDescendingEntitiesMap;
216 MED::TEntityInfo aEntityInfoDesc = aMed->GetEntityInfo(aMeshInfo, eDESC);
217 MED::TEntityInfo::iterator anEntityIterDesc = aEntityInfoDesc.begin();
218 //for (; anEntityIterDesc != aEntityInfoDesc.end() && !isDescConn; anEntityIterDesc++) {
219 for (; anEntityIterDesc != aEntityInfoDesc.end(); anEntityIterDesc++) {
220 const EEntiteMaillage& anEntity = anEntityIterDesc->first;
221 aDescendingEntitiesMap.Add(anEntity);
222 //if (anEntity != eNOEUD) isDescConn = true;
226 // Reading pre information about all MED cells
227 //--------------------------------------------
228 typedef MED::TVector<int> TNodeIds;
229 bool takeNumbers = true; // initially we trust the numbers from file
230 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo, eNOD);
231 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
233 for (; anEntityIter != aEntityInfo.end(); anEntityIter++)
235 const EEntiteMaillage& anEntity = anEntityIter->first;
236 aDescendingEntitiesMap.Remove(anEntity); // Mantis issue 0020483
237 if (anEntity == eNOEUD) continue;
239 // Reading MED cells to the corresponding SMDS structure
240 //------------------------------------------------------
241 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
242 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
243 for ( ; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++)
245 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
247 if ( anEntity == eSTRUCT_ELEMENT ) // MED_BALL (issue 0021459)
249 PBallInfo aBallInfo = aMed->GetPBallInfo(aMeshInfo);
250 TInt aNbBalls = aBallInfo->GetNbElem();
252 EBooleen anIsElemNum = takeNumbers ? aBallInfo->IsElemNum() : eFAUX;
253 if ( anIsElemNum && aBallInfo->myElemNum->empty() )
256 // get supporting nodes
258 #ifdef _EDF_NODE_IDS_
260 aNodeIds.resize( aNbBalls );
261 for(TInt iBall = 0; iBall < aNbBalls && anIsNodeNum; iBall++)
263 aNodeIds[iBall] = aNodeInfo->GetElemNum( (*aBallInfo->myConn)[ iBall ]-1 );
264 anIsNodeNum = myMesh->FindNode( aNodeIds[iBall] ) ? eVRAI : eFAUX;
269 aNodeIds.swap( *(aBallInfo->myConn ));
271 // allocate array of diameters
272 vtkIdType maxID = myMesh->MaxElementID() + aNbBalls;
273 if ( anIsElemNum && !aBallInfo->myElemNum->empty() )
274 maxID = *std::max_element( aBallInfo->myElemNum->begin(),
275 aBallInfo->myElemNum->end() );
276 myMesh->getGrid()->AllocateDiameters( maxID ); // performance optimization
279 SMDS_MeshElement* anElement;
280 DriverMED_FamilyPtr aFamily;
281 for ( TInt iBall = 0; iBall < aNbBalls; iBall++)
285 if (!(anElement = myMesh->AddBallWithID( aNodeIds[iBall],
286 aBallInfo->myDiameters[iBall],
287 aBallInfo->GetElemNum(iBall))))
291 myMesh->AddBall( myMesh->FindNode( aNodeIds[iBall]),
292 aBallInfo->myDiameters[iBall] );
294 // Save reference to this element from its family
295 TInt aFamNum = aBallInfo->GetFamNum(iBall);
296 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
298 aFamily->AddElement(anElement);
299 aFamily->SetType( SMDSAbs_Ball );
304 ( takeNumbers && aBallInfo->IsElemNum() && !aBallInfo->myElemNum->empty() ))
305 if ( aResult < DRS_WARN_RENUMBER )
306 aResult = DRS_WARN_RENUMBER;
312 // case ePOINT1: ## PAL16410
317 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
318 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
320 typedef SMDS_MeshFace* (SMESHDS_Mesh::* FAddPolyWithID)
321 (const std::vector<int> & nodes_ids, const int ID);
322 typedef SMDS_MeshFace* (SMESHDS_Mesh::* FAddPolygon)
323 (const std::vector<const SMDS_MeshNode*> & nodes);
325 FAddPolyWithID addPolyWithID = & SMESHDS_Mesh::AddPolygonalFaceWithID;
326 FAddPolygon addPolygon = & SMESHDS_Mesh::AddPolygonalFace;
327 if ( aGeom == ePOLYGON2 ) {
328 addPolyWithID = & SMESHDS_Mesh::AddQuadPolygonalFaceWithID;
329 addPolygon = & SMESHDS_Mesh::AddQuadPolygonalFace;
332 vector<const SMDS_MeshNode*> aNodes;
333 const TInt aNbElem = aPolygoneInfo->GetNbElem();
334 for ( TInt iElem = 0; iElem < aNbElem; iElem++ )
336 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
337 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
338 aNodeIds.resize( aNbConn );
339 #ifdef _EDF_NODE_IDS_
341 for(TInt iConn = 0; iConn < aNbConn; iConn++)
342 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
344 for(TInt iConn = 0; iConn < aNbConn; iConn++)
345 aNodeIds[iConn] = aConnSlice[iConn];
347 for(TInt iConn = 0; iConn < aNbConn; iConn++)
348 aNodeIds[iConn] = aConnSlice[iConn];
350 bool isRenum = false;
351 SMDS_MeshElement* anElement = NULL;
352 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
357 TInt anElemId = aPolygoneInfo->GetElemNum( iElem );
358 anElement = (myMesh->*addPolyWithID)( aNodeIds, anElemId );
361 aNodes.resize( aNbConn );
362 for ( TInt iConn = 0; iConn < aNbConn; iConn++ )
363 aNodes[iConn] = FindNode( myMesh, aNodeIds[iConn] );
364 anElement = (myMesh->*addPolygon)( aNodes );
365 isRenum = anIsElemNum;
368 } catch(const std::exception& exc) {
369 aResult = addMessage( exc.what(), /*isFatal=*/true );
371 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
375 aResult = DRS_WARN_SKIP_ELEM;
381 if(aResult < DRS_WARN_RENUMBER)
382 aResult = DRS_WARN_RENUMBER;
384 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
386 // Save reference to this element from its family
387 aFamily->AddElement(anElement);
388 aFamily->SetType(anElement->GetType());
395 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
396 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
398 TInt aNbElem = aPolyedreInfo->GetNbElem();
399 for(TInt iElem = 0; iElem < aNbElem; iElem++){
400 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
401 TInt aNbFaces = aConnSliceArr.size();
402 typedef MED::TVector<int> TQuantities;
403 TQuantities aQuantities(aNbFaces);
404 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
405 TNodeIds aNodeIds(aNbNodes);
406 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
407 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
408 TInt aNbConn = aConnSlice.size();
409 aQuantities[iFace] = aNbConn;
410 #ifdef _EDF_NODE_IDS_
412 for(TInt iConn = 0; iConn < aNbConn; iConn++)
414 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
418 for(TInt iConn = 0; iConn < aNbConn; iConn++)
420 aNodeIds[iNode++] = aConnSlice[iConn];
423 for(TInt iConn = 0; iConn < aNbConn; iConn++)
425 aNodeIds[iNode++] = aConnSlice[iConn];
430 bool isRenum = false;
431 SMDS_MeshElement* anElement = NULL;
432 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
438 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
439 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
442 vector<const SMDS_MeshNode*> aNodes(aNbNodes);
443 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
444 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
445 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
446 isRenum = anIsElemNum;
449 }catch(const std::exception& exc){
456 aResult = DRS_WARN_SKIP_ELEM;
461 if (aResult < DRS_WARN_RENUMBER)
462 aResult = DRS_WARN_RENUMBER;
464 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
465 // Save reference to this element from its family
466 aFamily->AddElement(anElement);
467 aFamily->SetType(anElement->GetType());
474 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
475 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
476 TInt aNbElems = aCellInfo->GetNbElem();
477 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
478 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
482 case eSEG2: aNbNodes = 2; break;
483 case eSEG3: aNbNodes = 3; break;
484 case eTRIA3: aNbNodes = 3; break;
485 case eTRIA6: aNbNodes = 6; break;
486 case eTRIA7: aNbNodes = 7; break;
487 case eQUAD4: aNbNodes = 4; break;
488 case eQUAD8: aNbNodes = 8; break;
489 case eQUAD9: aNbNodes = 9; break;
490 case eTETRA4: aNbNodes = 4; break;
491 case eTETRA10: aNbNodes = 10; break;
492 case ePYRA5: aNbNodes = 5; break;
493 case ePYRA13: aNbNodes = 13; break;
494 case ePENTA6: aNbNodes = 6; break;
495 case ePENTA15: aNbNodes = 15; break;
496 case eHEXA8: aNbNodes = 8; break;
497 case eHEXA20: aNbNodes = 20; break;
498 case eHEXA27: aNbNodes = 27; break;
499 case eOCTA12: aNbNodes = 12; break;
500 case ePOINT1: aNbNodes = 1; break;
503 vector<TInt> aNodeIds(aNbNodes);
504 for ( int iElem = 0; iElem < aNbElems; iElem++ )
506 bool anIsValidConnect = false;
507 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
511 #ifdef _EDF_NODE_IDS_
513 for(int iNode = 0; iNode < aNbNodes; iNode++)
514 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
516 for(int iNode = 0; iNode < aNbNodes; iNode++)
517 aNodeIds[iNode] = aConnSlice[iNode];
519 for(int iNode = 0; iNode < aNbNodes; iNode++)
520 aNodeIds[iNode] = aConnSlice[iNode];
522 anIsValidConnect = true;
524 }catch(const std::exception& exc){
525 INFOS("Following exception was caught:\n\t"<<exc.what());
526 aResult = addMessage( exc.what(), /*isFatal=*/true );
528 INFOS("Unknown exception was caught !!!");
529 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
532 if(!anIsValidConnect)
535 bool isRenum = false;
536 const SMDS_MeshElement* anElement = NULL;
537 TInt aFamNum = aCellInfo->GetFamNum(iElem);
541 //MESSAGE("Try to create element # " << iElem << " with id = "
542 // << aCellInfo->GetElemNum(iElem));
545 //anElement = FindNode(myMesh,aNodeIds[0]);
547 anElement = myMesh->Add0DElementWithID
548 (aNodeIds[0], aCellInfo->GetElemNum(iElem));
550 anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
551 isRenum = anIsElemNum;
556 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
558 aCellInfo->GetElemNum(iElem));
560 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
561 FindNode(myMesh,aNodeIds[1]));
562 isRenum = anIsElemNum;
567 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
570 aCellInfo->GetElemNum(iElem));
572 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
573 FindNode(myMesh,aNodeIds[1]),
574 FindNode(myMesh,aNodeIds[2]));
575 isRenum = anIsElemNum;
581 anElement = myMesh->AddFaceWithID(aNodeIds[0],
584 aCellInfo->GetElemNum(iElem));
586 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
587 FindNode(myMesh,aNodeIds[1]),
588 FindNode(myMesh,aNodeIds[2]));
589 isRenum = anIsElemNum;
595 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
596 aNodeIds[2], aNodeIds[3],
597 aNodeIds[4], aNodeIds[5],
598 aCellInfo->GetElemNum(iElem));
600 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
601 FindNode(myMesh,aNodeIds[1]),
602 FindNode(myMesh,aNodeIds[2]),
603 FindNode(myMesh,aNodeIds[3]),
604 FindNode(myMesh,aNodeIds[4]),
605 FindNode(myMesh,aNodeIds[5]));
606 isRenum = anIsElemNum;
612 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
613 aNodeIds[2], aNodeIds[3],
614 aNodeIds[4], aNodeIds[5], aNodeIds[6],
615 aCellInfo->GetElemNum(iElem));
617 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
618 FindNode(myMesh,aNodeIds[1]),
619 FindNode(myMesh,aNodeIds[2]),
620 FindNode(myMesh,aNodeIds[3]),
621 FindNode(myMesh,aNodeIds[4]),
622 FindNode(myMesh,aNodeIds[5]),
623 FindNode(myMesh,aNodeIds[6]));
624 isRenum = anIsElemNum;
630 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
631 aNodeIds[2], aNodeIds[3],
632 aCellInfo->GetElemNum(iElem));
634 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
635 FindNode(myMesh,aNodeIds[1]),
636 FindNode(myMesh,aNodeIds[2]),
637 FindNode(myMesh,aNodeIds[3]));
638 isRenum = anIsElemNum;
644 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
645 aNodeIds[2], aNodeIds[3],
646 aNodeIds[4], aNodeIds[5],
647 aNodeIds[6], aNodeIds[7],
648 aCellInfo->GetElemNum(iElem));
650 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
651 FindNode(myMesh,aNodeIds[1]),
652 FindNode(myMesh,aNodeIds[2]),
653 FindNode(myMesh,aNodeIds[3]),
654 FindNode(myMesh,aNodeIds[4]),
655 FindNode(myMesh,aNodeIds[5]),
656 FindNode(myMesh,aNodeIds[6]),
657 FindNode(myMesh,aNodeIds[7]));
658 isRenum = anIsElemNum;
664 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
665 aNodeIds[2], aNodeIds[3],
666 aNodeIds[4], aNodeIds[5],
667 aNodeIds[6], aNodeIds[7], aNodeIds[8],
668 aCellInfo->GetElemNum(iElem));
670 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
671 FindNode(myMesh,aNodeIds[1]),
672 FindNode(myMesh,aNodeIds[2]),
673 FindNode(myMesh,aNodeIds[3]),
674 FindNode(myMesh,aNodeIds[4]),
675 FindNode(myMesh,aNodeIds[5]),
676 FindNode(myMesh,aNodeIds[6]),
677 FindNode(myMesh,aNodeIds[7]),
678 FindNode(myMesh,aNodeIds[8]));
679 isRenum = anIsElemNum;
685 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
686 aNodeIds[2], aNodeIds[3],
687 aCellInfo->GetElemNum(iElem));
689 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
690 FindNode(myMesh,aNodeIds[1]),
691 FindNode(myMesh,aNodeIds[2]),
692 FindNode(myMesh,aNodeIds[3]));
693 isRenum = anIsElemNum;
699 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
700 aNodeIds[2], aNodeIds[3],
701 aNodeIds[4], aNodeIds[5],
702 aNodeIds[6], aNodeIds[7],
703 aNodeIds[8], aNodeIds[9],
704 aCellInfo->GetElemNum(iElem));
706 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
707 FindNode(myMesh,aNodeIds[1]),
708 FindNode(myMesh,aNodeIds[2]),
709 FindNode(myMesh,aNodeIds[3]),
710 FindNode(myMesh,aNodeIds[4]),
711 FindNode(myMesh,aNodeIds[5]),
712 FindNode(myMesh,aNodeIds[6]),
713 FindNode(myMesh,aNodeIds[7]),
714 FindNode(myMesh,aNodeIds[8]),
715 FindNode(myMesh,aNodeIds[9]));
716 isRenum = anIsElemNum;
722 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
723 aNodeIds[2], aNodeIds[3],
725 aCellInfo->GetElemNum(iElem));
727 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
728 FindNode(myMesh,aNodeIds[1]),
729 FindNode(myMesh,aNodeIds[2]),
730 FindNode(myMesh,aNodeIds[3]),
731 FindNode(myMesh,aNodeIds[4]));
732 isRenum = anIsElemNum;
738 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
739 aNodeIds[2], aNodeIds[3],
740 aNodeIds[4], aNodeIds[5],
741 aNodeIds[6], aNodeIds[7],
742 aNodeIds[8], aNodeIds[9],
743 aNodeIds[10], aNodeIds[11],
745 aCellInfo->GetElemNum(iElem));
747 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
748 FindNode(myMesh,aNodeIds[1]),
749 FindNode(myMesh,aNodeIds[2]),
750 FindNode(myMesh,aNodeIds[3]),
751 FindNode(myMesh,aNodeIds[4]),
752 FindNode(myMesh,aNodeIds[5]),
753 FindNode(myMesh,aNodeIds[6]),
754 FindNode(myMesh,aNodeIds[7]),
755 FindNode(myMesh,aNodeIds[8]),
756 FindNode(myMesh,aNodeIds[9]),
757 FindNode(myMesh,aNodeIds[10]),
758 FindNode(myMesh,aNodeIds[11]),
759 FindNode(myMesh,aNodeIds[12]));
760 isRenum = anIsElemNum;
766 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
772 aCellInfo->GetElemNum(iElem));
774 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
775 FindNode(myMesh,aNodeIds[1]),
776 FindNode(myMesh,aNodeIds[2]),
777 FindNode(myMesh,aNodeIds[3]),
778 FindNode(myMesh,aNodeIds[4]),
779 FindNode(myMesh,aNodeIds[5]));
780 isRenum = anIsElemNum;
786 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
787 aNodeIds[2], aNodeIds[3],
788 aNodeIds[4], aNodeIds[5],
789 aNodeIds[6], aNodeIds[7],
790 aNodeIds[8], aNodeIds[9],
791 aNodeIds[10], aNodeIds[11],
792 aNodeIds[12], aNodeIds[13],
794 aCellInfo->GetElemNum(iElem));
796 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
797 FindNode(myMesh,aNodeIds[1]),
798 FindNode(myMesh,aNodeIds[2]),
799 FindNode(myMesh,aNodeIds[3]),
800 FindNode(myMesh,aNodeIds[4]),
801 FindNode(myMesh,aNodeIds[5]),
802 FindNode(myMesh,aNodeIds[6]),
803 FindNode(myMesh,aNodeIds[7]),
804 FindNode(myMesh,aNodeIds[8]),
805 FindNode(myMesh,aNodeIds[9]),
806 FindNode(myMesh,aNodeIds[10]),
807 FindNode(myMesh,aNodeIds[11]),
808 FindNode(myMesh,aNodeIds[12]),
809 FindNode(myMesh,aNodeIds[13]),
810 FindNode(myMesh,aNodeIds[14]));
811 isRenum = anIsElemNum;
817 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
825 aCellInfo->GetElemNum(iElem));
827 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
828 FindNode(myMesh,aNodeIds[1]),
829 FindNode(myMesh,aNodeIds[2]),
830 FindNode(myMesh,aNodeIds[3]),
831 FindNode(myMesh,aNodeIds[4]),
832 FindNode(myMesh,aNodeIds[5]),
833 FindNode(myMesh,aNodeIds[6]),
834 FindNode(myMesh,aNodeIds[7]));
835 isRenum = anIsElemNum;
842 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
843 aNodeIds[2], aNodeIds[3],
844 aNodeIds[4], aNodeIds[5],
845 aNodeIds[6], aNodeIds[7],
846 aNodeIds[8], aNodeIds[9],
847 aNodeIds[10], aNodeIds[11],
848 aNodeIds[12], aNodeIds[13],
849 aNodeIds[14], aNodeIds[15],
850 aNodeIds[16], aNodeIds[17],
851 aNodeIds[18], aNodeIds[19],
852 aCellInfo->GetElemNum(iElem));
854 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
855 FindNode(myMesh,aNodeIds[1]),
856 FindNode(myMesh,aNodeIds[2]),
857 FindNode(myMesh,aNodeIds[3]),
858 FindNode(myMesh,aNodeIds[4]),
859 FindNode(myMesh,aNodeIds[5]),
860 FindNode(myMesh,aNodeIds[6]),
861 FindNode(myMesh,aNodeIds[7]),
862 FindNode(myMesh,aNodeIds[8]),
863 FindNode(myMesh,aNodeIds[9]),
864 FindNode(myMesh,aNodeIds[10]),
865 FindNode(myMesh,aNodeIds[11]),
866 FindNode(myMesh,aNodeIds[12]),
867 FindNode(myMesh,aNodeIds[13]),
868 FindNode(myMesh,aNodeIds[14]),
869 FindNode(myMesh,aNodeIds[15]),
870 FindNode(myMesh,aNodeIds[16]),
871 FindNode(myMesh,aNodeIds[17]),
872 FindNode(myMesh,aNodeIds[18]),
873 FindNode(myMesh,aNodeIds[19]));
874 isRenum = anIsElemNum;
881 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
882 aNodeIds[2], aNodeIds[3],
883 aNodeIds[4], aNodeIds[5],
884 aNodeIds[6], aNodeIds[7],
885 aNodeIds[8], aNodeIds[9],
886 aNodeIds[10], aNodeIds[11],
887 aNodeIds[12], aNodeIds[13],
888 aNodeIds[14], aNodeIds[15],
889 aNodeIds[16], aNodeIds[17],
890 aNodeIds[18], aNodeIds[19],
891 aNodeIds[20], aNodeIds[21],
892 aNodeIds[22], aNodeIds[23],
893 aNodeIds[24], aNodeIds[25],
895 aCellInfo->GetElemNum(iElem));
897 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
898 FindNode(myMesh,aNodeIds[1]),
899 FindNode(myMesh,aNodeIds[2]),
900 FindNode(myMesh,aNodeIds[3]),
901 FindNode(myMesh,aNodeIds[4]),
902 FindNode(myMesh,aNodeIds[5]),
903 FindNode(myMesh,aNodeIds[6]),
904 FindNode(myMesh,aNodeIds[7]),
905 FindNode(myMesh,aNodeIds[8]),
906 FindNode(myMesh,aNodeIds[9]),
907 FindNode(myMesh,aNodeIds[10]),
908 FindNode(myMesh,aNodeIds[11]),
909 FindNode(myMesh,aNodeIds[12]),
910 FindNode(myMesh,aNodeIds[13]),
911 FindNode(myMesh,aNodeIds[14]),
912 FindNode(myMesh,aNodeIds[15]),
913 FindNode(myMesh,aNodeIds[16]),
914 FindNode(myMesh,aNodeIds[17]),
915 FindNode(myMesh,aNodeIds[18]),
916 FindNode(myMesh,aNodeIds[19]),
917 FindNode(myMesh,aNodeIds[20]),
918 FindNode(myMesh,aNodeIds[21]),
919 FindNode(myMesh,aNodeIds[22]),
920 FindNode(myMesh,aNodeIds[23]),
921 FindNode(myMesh,aNodeIds[24]),
922 FindNode(myMesh,aNodeIds[25]),
923 FindNode(myMesh,aNodeIds[26]));
924 isRenum = anIsElemNum;
931 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
932 aNodeIds[2], aNodeIds[3],
933 aNodeIds[4], aNodeIds[5],
934 aNodeIds[6], aNodeIds[7],
935 aNodeIds[8], aNodeIds[9],
936 aNodeIds[10], aNodeIds[11],
937 aCellInfo->GetElemNum(iElem));
939 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
940 FindNode(myMesh,aNodeIds[1]),
941 FindNode(myMesh,aNodeIds[2]),
942 FindNode(myMesh,aNodeIds[3]),
943 FindNode(myMesh,aNodeIds[4]),
944 FindNode(myMesh,aNodeIds[5]),
945 FindNode(myMesh,aNodeIds[6]),
946 FindNode(myMesh,aNodeIds[7]),
947 FindNode(myMesh,aNodeIds[8]),
948 FindNode(myMesh,aNodeIds[9]),
949 FindNode(myMesh,aNodeIds[10]),
950 FindNode(myMesh,aNodeIds[11]));
951 isRenum = anIsElemNum;
960 } catch(const std::exception& exc) {
961 INFOS("The following exception was caught:\n\t"<<exc.what());
962 aResult = addMessage( exc.what(), /*isFatal=*/true );
964 INFOS("Unknown exception was caught !!!");
965 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
969 aResult = DRS_WARN_SKIP_ELEM;
975 if (aResult < DRS_WARN_RENUMBER)
976 aResult = DRS_WARN_RENUMBER;
978 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
979 // Save reference to this element from its family
980 aFamily->AddElement(anElement);
981 aFamily->SetType(anElement->GetType());
984 } // loop on aNbElems
986 } // loop on aGeom2Size
987 } // loop on aEntityInfo
989 if (aDescendingEntitiesMap.Extent()) isDescConn = true; // Mantis issue 0020483
991 } // for(int iMesh = 0; iMesh < aNbMeshes; iMesh++)
994 catch(const std::exception& exc)
996 INFOS("The following exception was caught:\n\t"<<exc.what());
997 aResult = addMessage( exc.what(), /*isFatal=*/true );
1001 INFOS("Unknown exception was caught !!!");
1002 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
1006 myMesh->compactMesh();
1008 // Mantis issue 0020483
1009 if (aResult == DRS_OK && isDescConn) {
1010 INFOS("There are some elements in descending connectivity in med file. They were not read !!!");
1011 aResult = DRS_WARN_DESCENDING;
1014 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
1018 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
1020 list<string> aMeshNames;
1023 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
1025 PWrapper aMed = CrWrapper(myFile);
1027 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
1028 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
1029 // Reading the MED mesh
1030 //---------------------
1031 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
1032 aMeshNames.push_back(aMeshInfo->GetName());
1035 } catch(const std::exception& exc) {
1036 INFOS("Following exception was caught:\n\t"<<exc.what());
1037 theStatus = DRS_FAIL;
1039 INFOS("Unknown exception was caught !!!");
1040 theStatus = DRS_FAIL;
1046 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
1048 list<TNameAndType> aResult;
1049 set<TNameAndType> aResGroupNames;
1051 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1052 for (; aFamsIter != myFamilies.end(); aFamsIter++)
1054 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1055 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
1056 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
1057 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1059 const set< SMDSAbs_ElementType >& types = aFamily->GetTypes();
1060 set< SMDSAbs_ElementType >::const_iterator type = types.begin();
1061 for ( ; type != types.end(); ++type )
1063 TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
1064 if ( aResGroupNames.insert( aNameAndType ).second ) {
1065 aResult.push_back( aNameAndType );
1074 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
1076 string aGroupName (theGroup->GetStoreName());
1077 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
1079 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1080 for (; aFamsIter != myFamilies.end(); aFamsIter++)
1082 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1083 if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName))
1085 const ElementsSet& anElements = aFamily->GetElements();
1086 ElementsSet::const_iterator anElemsIter = anElements.begin();
1087 for (; anElemsIter != anElements.end(); anElemsIter++)
1089 const SMDS_MeshElement * element = *anElemsIter;
1090 if ( element->GetType() == theGroup->GetType() ) // Issue 0020576
1091 theGroup->SMDSGroup().Add(element);
1093 int aGroupAttrVal = aFamily->GetGroupAttributVal();
1094 if( aGroupAttrVal != 0)
1095 theGroup->SetColorGroup(aGroupAttrVal);
1096 // if ( element ) -- Issue 0020576
1097 // theGroup->SetType( theGroup->SMDSGroup().GetType() );
1102 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
1105 char submeshGrpName[ 30 ];
1106 sprintf( submeshGrpName, "SubMesh %d", theId );
1107 string aName (submeshGrpName);
1108 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1109 for (; aFamsIter != myFamilies.end(); aFamsIter++)
1111 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1112 if (aFamily->MemberOf(aName))
1114 const ElementsSet& anElements = aFamily->GetElements();
1115 ElementsSet::const_iterator anElemsIter = anElements.begin();
1116 if (aFamily->GetType() == SMDSAbs_Node)
1118 for (; anElemsIter != anElements.end(); anElemsIter++)
1120 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
1121 theSubMesh->AddNode(node);
1126 for (; anElemsIter != anElements.end(); anElemsIter++)
1128 theSubMesh->AddElement(*anElemsIter);
1135 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
1137 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1138 for (; aFamsIter != myFamilies.end(); aFamsIter++)
1140 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1141 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
1142 set<string>::iterator aGrNamesIter = aGroupNames.begin();
1143 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1145 string aName = *aGrNamesIter;
1146 // Check, if this is a Group or SubMesh name
1147 if (aName.substr(0, 7) == string("SubMesh"))
1149 int Id = atoi(string(aName).substr(7).c_str());
1150 const ElementsSet& anElements = aFamily->GetElements();
1151 ElementsSet::const_iterator anElemsIter = anElements.begin();
1152 if (aFamily->GetType() == SMDSAbs_Node)
1154 for (; anElemsIter != anElements.end(); anElemsIter++)
1156 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( *anElemsIter );
1157 // find out a shape type
1158 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
1159 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
1160 switch ( aShapeType ) {
1162 myMesh->SetNodeOnFace(node, Id); break;
1164 myMesh->SetNodeOnEdge(node, Id); break;
1166 myMesh->SetNodeOnVertex(node, Id); break;
1168 myMesh->SetNodeInVolume(node, Id);
1174 for (; anElemsIter != anElements.end(); anElemsIter++)
1176 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
1184 * \brief Ensure aFamily to have required ID
1185 * \param aFamily - a family to check and update
1186 * \param anID - an ID aFamily should have
1187 * \retval bool - true if successful
1189 bool DriverMED::checkFamilyID(DriverMED_FamilyPtr & aFamily,
1191 const TID2FamilyMap& myFamilies)
1193 if ( !aFamily || aFamily->GetId() != anID ) {
1194 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
1195 if ( i_fam == myFamilies.end() )
1197 aFamily = i_fam->second;
1199 return ( aFamily->GetId() == anID );
1203 * \brief Reading the structured mesh and convert to non structured
1204 * (by filling of smesh structure for non structured mesh)
1205 * \param theWrapper - PWrapper const pointer
1206 * \param theMeshInfo - PMeshInfo const pointer
1207 * \param myFamilies - a map of the family ID to the Family
1208 * \return TRUE, if successfully. Else FALSE
1210 bool DriverMED::buildMeshGrille(const MED::PWrapper& theWrapper,
1211 const MED::PMeshInfo& theMeshInfo,
1212 SMESHDS_Mesh* myMesh,
1213 const TID2FamilyMap& myFamilies)
1217 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
1218 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
1219 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
1220 MED::TInt aMeshDim = theMeshInfo->GetDim();
1221 DriverMED_FamilyPtr aFamily;
1222 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
1223 double aCoords[3] = {0.0, 0.0, 0.0};
1224 const SMDS_MeshNode* aNode;
1225 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
1226 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
1227 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
1228 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],iNode+1);
1230 EXCEPTION(runtime_error,"buildMeshGrille Error. Node not created! "<<(int)iNode);
1233 if((aGrilleInfo->myFamNumNode).size() > 0){
1234 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
1235 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
1237 aFamily->AddElement(aNode);
1238 aFamily->SetType(SMDSAbs_Node);
1244 SMDS_MeshElement* anElement = NULL;
1245 MED::TIntVector aNodeIds;
1246 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
1247 aNodeIds = aGrilleInfo->GetConn(iCell);
1248 switch(aGrilleInfo->GetGeom()){
1250 if(aNodeIds.size() != 2){
1252 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
1254 anElement = myMesh->AddEdgeWithID(aNodeIds[0]+1,
1259 if(aNodeIds.size() != 4){
1261 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
1263 anElement = myMesh->AddFaceWithID(aNodeIds[0]+1,
1270 if(aNodeIds.size() != 8){
1272 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
1274 anElement = myMesh->AddVolumeWithID(aNodeIds[0]+1,
1288 EXCEPTION(runtime_error,"buildMeshGrille Error. Element not created! "<<iCell);
1290 if((aGrilleInfo->myFamNum).size() > 0){
1291 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
1292 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )){
1293 aFamily->AddElement(anElement);
1294 aFamily->SetType(anElement->GetType());