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_W_SMESHDS_Mesh.cxx
28 #include "DriverMED_W_SMESHDS_Mesh.h"
30 #include "DriverMED_Family.h"
31 #include "MED_Factory.hxx"
32 #include "MED_Utilities.hxx"
33 #include "SMDS_IteratorOnIterators.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
37 #include "SMDS_SetIterator.hxx"
38 #include "SMESHDS_Mesh.hxx"
40 #include <BRep_Tool.hxx>
41 #include <TopExp_Explorer.hxx>
44 #include <utilities.h>
47 #define _EDF_NODE_IDS_
48 //#define _ELEMENTS_BY_DIM_
54 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
55 myMedVersion(MED::eV2_2),
56 myAllSubMeshes (false),
57 myDoGroupOfNodes (false),
58 myDoGroupOfEdges (false),
59 myDoGroupOfFaces (false),
60 myDoGroupOfVolumes (false),
61 myDoGroupOf0DElems(false),
62 myDoGroupOfBalls(false),
63 myAutoDimension(true),
64 myAddODOnVertices(false)
67 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
70 Driver_SMESHDS_Mesh::SetFile(theFileName);
74 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
76 Driver_SMESHDS_Mesh::SetFile(theFileName);
79 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
81 TInt majeur, mineur, release;
82 majeur = mineur = release = 0;
83 // if ( theVersion == eV2_1 )
84 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
86 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
88 if ( theNbDigits > 0 )
90 if ( theNbDigits > 1 )
91 name << "." << mineur;
92 if ( theNbDigits > 2 )
93 name << "." << release;
97 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
99 myGroups.push_back(theGroup);
102 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
104 myAllSubMeshes = true;
107 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
109 mySubMeshes.push_back( theSubMesh );
112 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
114 myDoGroupOfNodes = true;
117 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
119 myDoGroupOfEdges = true;
122 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
124 myDoGroupOfFaces = true;
127 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
129 myDoGroupOfVolumes = true;
134 typedef double (SMDS_MeshNode::* TGetCoord)() const;
135 typedef const char* TName;
136 typedef const char* TUnit;
138 // name length in a mesh must be equal to 16 :
145 TUnit aUnit[3] = {M,M,M};
148 TGetCoord aXYZGetCoord[3] = {
153 TName aXYZName[3] = {X,Y,Z};
156 TGetCoord aXYGetCoord[2] = {
160 TName aXYName[2] = {X,Y};
162 TGetCoord aYZGetCoord[2] = {
166 TName aYZName[2] = {Y,Z};
168 TGetCoord aXZGetCoord[2] = {
172 TName aXZName[2] = {X,Z};
175 TGetCoord aXGetCoord[1] = {
178 TName aXName[1] = {X};
180 TGetCoord aYGetCoord[1] = {
183 TName aYName[1] = {Y};
185 TGetCoord aZGetCoord[1] = {
188 TName aZName[1] = {Z};
192 SMDS_NodeIteratorPtr myNodeIter;
193 const SMDS_MeshNode* myCurrentNode;
194 TGetCoord* myGetCoord;
198 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
199 TGetCoord* theGetCoord,
201 TUnit* theUnit = aUnit):
202 myNodeIter(theNodeIter),
203 myGetCoord(theGetCoord),
207 virtual ~TCoordHelper(){}
209 return myNodeIter->more() &&
210 (myCurrentNode = myNodeIter->next());
212 const SMDS_MeshNode* GetNode(){
213 return myCurrentNode;
215 MED::TIntVector::value_type GetID(){
216 return myCurrentNode->GetID();
218 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
219 return (myCurrentNode->*myGetCoord[theCoodId])();
221 MED::TStringVector::value_type GetName(TInt theDimId){
222 return myName[theDimId];
224 MED::TStringVector::value_type GetUnit(TInt theDimId){
225 return myUnit[theDimId];
228 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
230 //-------------------------------------------------------
232 * \brief Structure describing element type
234 //-------------------------------------------------------
237 EEntiteMaillage _entity;
238 EGeometrieElement _geomType;
240 SMDSAbs_ElementType _smdsType;
242 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
243 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
247 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
249 //================================================================================
251 * \brief Fills element to famaly ID map for element type.
252 * Removes all families of anElemType
254 //================================================================================
256 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
257 list<DriverMED_FamilyPtr> & aFamilies,
258 const SMDSAbs_ElementType anElemType)
260 anElemFamMap.Clear();
261 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
262 while ( aFamsIter != aFamilies.end() )
264 if ((*aFamsIter)->GetType() != anElemType) {
268 int aFamId = (*aFamsIter)->GetId();
269 const ElementsSet& anElems = (*aFamsIter)->GetElements();
270 ElementsSet::const_iterator anElemsIter = anElems.begin();
271 for (; anElemsIter != anElems.end(); anElemsIter++)
273 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
275 // remove a family from the list
276 aFamilies.erase( aFamsIter++ );
281 //================================================================================
283 * \brief For an element, return family ID found in the map or a default one
285 //================================================================================
287 int getFamilyId( const TElemFamilyMap & anElemFamMap,
288 const SMDS_MeshElement* anElement,
289 const int aDefaultFamilyId)
291 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
292 return anElemFamMap( (Standard_Address) anElement );
294 return aDefaultFamilyId;
297 //================================================================================
299 * \brief Returns iterator on sub-meshes
301 //================================================================================
303 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
305 return SMESHDS_SubMeshIteratorPtr
306 ( new SMDS_SetIterator
307 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
308 mySubMeshes.end() ));
312 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
314 Status aResult = DRS_OK;
315 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
316 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
320 MESSAGE("Perform - myFile : "<<myFile);
322 // Creating the MED mesh for corresponding SMDS structure
323 //-------------------------------------------------------
325 if (myMeshId != -1) {
326 ostringstream aMeshNameStr;
327 aMeshNameStr<<myMeshId;
328 aMeshName = aMeshNameStr.str();
330 aMeshName = myMeshName;
333 // Mesh dimension definition
334 TInt aSpaceDimension = 3;
335 TCoordHelperPtr aCoordHelperPtr;
337 bool anIsXDimension = false;
338 bool anIsYDimension = false;
339 bool anIsZDimension = false;
340 if ( myAutoDimension )
342 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
344 if(aNodesIter->more()){
345 const SMDS_MeshNode* aNode = aNodesIter->next();
346 aBounds[0] = aBounds[1] = aNode->X();
347 aBounds[2] = aBounds[3] = aNode->Y();
348 aBounds[4] = aBounds[5] = aNode->Z();
350 while(aNodesIter->more()){
351 const SMDS_MeshNode* aNode = aNodesIter->next();
352 aBounds[0] = min(aBounds[0],aNode->X());
353 aBounds[1] = max(aBounds[1],aNode->X());
355 aBounds[2] = min(aBounds[2],aNode->Y());
356 aBounds[3] = max(aBounds[3],aNode->Y());
358 aBounds[4] = min(aBounds[4],aNode->Z());
359 aBounds[5] = max(aBounds[5],aNode->Z());
363 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
364 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
365 if ( !mainShape.IsNull() && hasShapeToMesh )
367 // define EPS by max tolerance of the mainShape (IPAL53097)
368 TopExp_Explorer subShape;
369 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
370 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
372 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
373 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
375 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
376 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
380 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
381 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
382 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
383 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
384 if ( !aSpaceDimension )
386 // PAL16857(SMESH not conform to the MED convention):
387 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
389 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
390 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
391 if ( anIsYDimension ) {
393 anIsXDimension = true;
400 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
401 switch ( aSpaceDimension ) {
403 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
406 if(anIsXDimension && anIsYDimension)
407 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
408 if(anIsYDimension && anIsZDimension)
409 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
410 if(anIsXDimension && anIsZDimension)
411 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
415 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
417 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
419 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
423 TInt aMeshDimension = 0;
424 if ( myMesh->NbEdges() > 0 )
426 if ( myMesh->NbFaces() > 0 )
428 if ( myMesh->NbVolumes() > 0 )
431 MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
432 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
433 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
434 myMed->SetMeshInfo(aMeshInfo);
436 // Storing SMDS groups and sub-meshes as med families
437 //----------------------------------------------------
438 int myNodesDefaultFamilyId = 0;
439 int my0DElementsDefaultFamilyId = 0;
440 int myBallsDefaultFamilyId = 0;
441 int myEdgesDefaultFamilyId = 0;
442 int myFacesDefaultFamilyId = 0;
443 int myVolumesDefaultFamilyId = 0;
444 int nbNodes = myMesh->NbNodes();
445 int nb0DElements = myMesh->Nb0DElements();
446 int nbBalls = myMesh->NbBalls();
447 int nbEdges = myMesh->NbEdges();
448 int nbFaces = myMesh->NbFaces();
449 int nbVolumes = myMesh->NbVolumes();
450 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
451 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
452 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
453 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
454 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
455 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
457 MESSAGE("Perform - aFamilyInfo");
458 list<DriverMED_FamilyPtr> aFamilies;
459 if (myAllSubMeshes) {
460 aFamilies = DriverMED_Family::MakeFamilies
461 (myMesh->SubMeshes(), myGroups,
462 myDoGroupOfNodes && nbNodes,
463 myDoGroupOfEdges && nbEdges,
464 myDoGroupOfFaces && nbFaces,
465 myDoGroupOfVolumes && nbVolumes,
466 myDoGroupOf0DElems && nb0DElements,
467 myDoGroupOfBalls && nbBalls);
470 aFamilies = DriverMED_Family::MakeFamilies
471 (getIterator( mySubMeshes ), myGroups,
472 myDoGroupOfNodes && nbNodes,
473 myDoGroupOfEdges && nbEdges,
474 myDoGroupOfFaces && nbFaces,
475 myDoGroupOfVolumes && nbVolumes,
476 myDoGroupOf0DElems && nb0DElements,
477 myDoGroupOfBalls && nbBalls);
479 list<DriverMED_FamilyPtr>::iterator aFamsIter;
480 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
482 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
483 myMed->SetFamilyInfo(aFamilyInfo);
486 // Storing SMDS nodes to the MED file for the MED mesh
487 //----------------------------------------------------
488 #ifdef _EDF_NODE_IDS_
489 typedef map<TInt,TInt> TNodeIdMap;
490 TNodeIdMap aNodeIdMap;
492 const EModeSwitch theMode = eFULL_INTERLACE;
493 const ERepere theSystem = eCART;
494 const EBooleen theIsElemNum = eVRAI;
495 const EBooleen theIsElemNames = eFAUX;
496 const EConnectivite theConnMode = eNOD;
498 TInt aNbNodes = myMesh->NbNodes();
499 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
500 theMode, theSystem, theIsElemNum, theIsElemNames);
502 // find family numbers for nodes
503 TElemFamilyMap anElemFamMap;
504 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
506 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
509 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
510 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
511 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
514 int aNodeID = aCoordHelperPtr->GetID();
515 aNodeInfo->SetElemNum( iNode, aNodeID );
516 #ifdef _EDF_NODE_IDS_
517 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
520 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
521 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
522 aNodeInfo->SetFamNum( iNode, famNum );
524 anElemFamMap.Clear();
526 // coordinate names and units
527 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
528 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
529 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
532 //cout << " SetNodeInfo(aNodeInfo)" << endl;
533 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
534 myMed->SetNodeInfo(aNodeInfo);
535 aNodeInfo.reset(); // free memory used for arrays
538 // Storing SMDS elements to the MED file for the MED mesh
539 //-------------------------------------------------------
540 // Write one element type at once in order to minimize memory usage (PAL19276)
542 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
544 // poly elements are not supported by med-2.1
545 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
546 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
548 // nodes on VERTEXes where 0D elements are absent
549 std::vector<const SMDS_MeshElement*> nodesOf0D;
550 std::vector< SMDS_ElemIteratorPtr > iterVec;
551 SMDS_ElemIteratorPtr iterVecIter;
552 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
555 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
556 iterVec[1] = SMDS_ElemIteratorPtr
557 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
559 typedef SMDS_IteratorOnIterators
560 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
561 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
564 // collect info on all geom types
566 list< TElemTypeData > aTElemTypeDatas;
568 EEntiteMaillage anEntity = eMAILLE;
569 #ifdef _ELEMENTS_BY_DIM_
570 anEntity = eNOEUD_ELEMENT;
572 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
574 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
576 #ifdef _ELEMENTS_BY_DIM_
577 anEntity = eSTRUCT_ELEMENT;
579 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
581 nbElemInfo.NbBalls(),
583 #ifdef _ELEMENTS_BY_DIM_
586 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
588 nbElemInfo.NbEdges( ORDER_LINEAR ),
590 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
592 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
594 #ifdef _ELEMENTS_BY_DIM_
597 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
599 nbElemInfo.NbTriangles( ORDER_LINEAR ),
601 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
603 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
604 nbElemInfo.NbBiQuadTriangles(),
606 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
608 nbElemInfo.NbBiQuadTriangles(),
610 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
612 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
614 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
616 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
617 nbElemInfo.NbBiQuadQuadrangles(),
619 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
621 nbElemInfo.NbBiQuadQuadrangles(),
623 if ( polyTypesSupported ) {
624 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
626 nbElemInfo.NbPolygons( ORDER_LINEAR ),
628 // we need one more loop on poly elements to count nb of their nodes
629 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
631 nbElemInfo.NbPolygons( ORDER_LINEAR ),
633 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
635 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
637 // we need one more loop on QUAD poly elements to count nb of their nodes
638 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
640 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
643 #ifdef _ELEMENTS_BY_DIM_
646 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
648 nbElemInfo.NbTetras( ORDER_LINEAR ),
650 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
652 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
654 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
656 nbElemInfo.NbPyramids( ORDER_LINEAR ),
658 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
660 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
662 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
664 nbElemInfo.NbPrisms( ORDER_LINEAR ),
666 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
668 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
670 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
672 nbElemInfo.NbHexas( ORDER_LINEAR ),
674 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
676 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
677 nbElemInfo.NbTriQuadHexas(),
679 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
681 nbElemInfo.NbTriQuadHexas(),
683 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
685 nbElemInfo.NbHexPrisms(),
687 if ( polyTypesSupported ) {
688 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
690 nbElemInfo.NbPolyhedrons(),
692 // we need one more loop on poly elements to count nb of their nodes
693 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
695 nbElemInfo.NbPolyhedrons(),
699 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
701 // loop on all geom types of elements
703 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
704 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
706 if ( aElemTypeData->_nbElems == 0 )
709 int defaultFamilyId = 0;
710 switch ( aElemTypeData->_smdsType ) {
711 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
712 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
713 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
714 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
715 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
720 // iterator on elements of a current type
721 SMDS_ElemIteratorPtr elemIterator;
726 if ( aElemTypeData->_geomType == ePOLYGONE ||
727 aElemTypeData->_geomType == ePOLYGON2 )
729 if ( aElemTypeData->_geomType == ePOLYGONE )
730 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
732 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
734 if ( nbPolygonNodes == 0 ) {
736 while ( elemIterator->more() ) {
737 const SMDS_MeshElement* anElem = elemIterator->next();
738 nbPolygonNodes += anElem->NbNodes();
739 if ( ++iElem == aElemTypeData->_nbElems )
745 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
746 aElemTypeData->_entity,
747 aElemTypeData->_geomType,
748 aElemTypeData->_nbElems,
750 theConnMode, theIsElemNum,
752 TElemNum & index = *(aPolygoneInfo->myIndex.get());
755 while ( elemIterator->more() )
757 const SMDS_MeshElement* anElem = elemIterator->next();
759 TInt aNbNodes = anElem->NbNodes();
760 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
763 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
764 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
765 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
766 #ifdef _EDF_NODE_IDS_
767 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
769 aTConnSlice[ iNode ] = aNode->GetID();
773 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
776 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
777 aPolygoneInfo->SetFamNum( iElem, famNum );
779 if ( ++iElem == aPolygoneInfo->GetNbElem() )
782 myMed->SetPolygoneInfo(aPolygoneInfo);
784 nbPolygonNodes = 0; // to treat next polygon type
790 else if (aElemTypeData->_geomType == ePOLYEDRE )
792 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
794 if ( nbPolyhedronNodes == 0 ) {
796 while ( elemIterator->more() ) {
797 const SMDS_MeshElement* anElem = elemIterator->next();
798 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
799 if ( !aPolyedre ) continue;
800 nbPolyhedronNodes += aPolyedre->NbNodes();
801 nbPolyhedronFaces += aPolyedre->NbFaces();
802 if ( ++iElem == aElemTypeData->_nbElems )
808 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
809 aElemTypeData->_entity,
810 aElemTypeData->_geomType,
811 aElemTypeData->_nbElems,
817 TElemNum & index = *(aPolyhInfo->myIndex.get());
818 TElemNum & faces = *(aPolyhInfo->myFaces.get());
819 TElemNum & conn = *(aPolyhInfo->myConn.get());
823 TInt iFace = 0, iNode = 0;
824 while ( elemIterator->more() )
826 const SMDS_MeshElement* anElem = elemIterator->next();
827 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
828 if ( !aPolyedre ) continue;
830 TInt aNbFaces = aPolyedre->NbFaces();
831 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
834 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
835 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
836 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
839 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
840 while ( nodeIt->more() ) {
841 const SMDS_MeshElement* aNode = nodeIt->next();
842 #ifdef _EDF_NODE_IDS_
843 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
845 conn[ iNode ] = aNode->GetID();
850 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
853 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
854 aPolyhInfo->SetFamNum( iElem, famNum );
856 if ( ++iElem == aPolyhInfo->GetNbElem() )
859 myMed->SetPolyedreInfo(aPolyhInfo);
861 } // if (aElemTypeData->_geomType == ePOLYEDRE )
865 else if (aElemTypeData->_geomType == eBALL )
867 // allocate data arrays
868 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
870 // build map of family numbers for this type
871 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
873 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
874 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
877 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
878 while ( elemIterator->more() )
880 const SMDS_MeshElement* anElem = elemIterator->next();
882 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
883 #ifdef _EDF_NODE_IDS_
884 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
886 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
889 aBallInfo->SetElemNum( iElem, anElem->GetID() );
892 aBallInfo->myDiameters[ iElem ] =
893 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
896 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
897 aBallInfo->SetFamNum( iElem, famNum );
900 // store data in a file
901 myMed->SetBallInfo(aBallInfo);
906 // Treat standard types
907 // ---------------------
909 // allocate data arrays
910 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
911 aElemTypeData->_entity,
912 aElemTypeData->_geomType,
913 aElemTypeData->_nbElems,
917 // build map of family numbers for this type
918 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
920 //cout << " fillElemFamilyMap()" << endl;
921 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
922 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
925 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
926 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
927 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
928 elemIterator = iterVecIter;
929 while ( elemIterator->more() )
931 const SMDS_MeshElement* anElem = elemIterator->next();
932 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
933 continue; // other geometry
936 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
937 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
938 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
939 #ifdef _EDF_NODE_IDS_
940 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
942 aTConnSlice[ iNode ] = aNode->GetID();
946 aCellInfo->SetElemNum( iElem, anElem->GetID() );
949 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
950 aCellInfo->SetFamNum( iElem, famNum );
952 if ( ++iElem == aCellInfo->GetNbElem() )
955 // store data in a file
956 myMed->SetCellInfo(aCellInfo);
959 } // loop on geom types
963 catch(const std::exception& exc) {
964 INFOS("The following exception was caught:\n\t"<<exc.what());
968 INFOS("Unknown exception was caught !!!");
978 //================================================================================
980 * \brief Returns nodes on VERTEXes where 0D elements are absent
982 //================================================================================
984 bool DriverMED_W_SMESHDS_Mesh::
985 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
986 std::vector<const SMDS_MeshElement*>& nodes)
989 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
991 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
993 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
994 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
997 const SMDS_MeshNode* n = nIt->next();
998 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
999 nodes.push_back( n );
1003 return !nodes.empty();