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_MeshNode.hxx"
35 #include "SMDS_SetIterator.hxx"
36 #include "SMESHDS_Mesh.hxx"
38 #include <BRep_Tool.hxx>
39 #include <TopExp_Explorer.hxx>
42 #include <utilities.h>
45 #define _EDF_NODE_IDS_
46 //#define _ELEMENTS_BY_DIM_
52 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
53 myAllSubMeshes (false),
54 myDoGroupOfNodes (false),
55 myDoGroupOfEdges (false),
56 myDoGroupOfFaces (false),
57 myDoGroupOfVolumes (false),
58 myDoGroupOf0DElems(false),
59 myDoGroupOfBalls(false),
60 myAutoDimension(false),
61 myAddODOnVertices(false),
62 myDoAllInGroups(false)
65 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
67 Driver_SMESHDS_Mesh::SetFile(theFileName);
70 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
72 myGroups.push_back(theGroup);
75 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
77 myAllSubMeshes = true;
80 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
82 mySubMeshes.push_back( theSubMesh );
85 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
87 myDoGroupOfNodes = true;
90 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
92 myDoGroupOfEdges = true;
95 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
97 myDoGroupOfFaces = true;
100 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
102 myDoGroupOfVolumes = true;
105 void DriverMED_W_SMESHDS_Mesh::AddGroupOf0DElems()
107 myDoGroupOf0DElems = true;
110 void DriverMED_W_SMESHDS_Mesh::AddGroupOfBalls()
112 myDoGroupOfBalls = true;
115 //================================================================================
117 * \brief Set up a flag to add all elements not belonging to any group to
118 * some auxiliary group. This is needed for SMESH -> SAUVE -> SMESH conversion,
119 * which since PAL0023285 reads only SAUVE elements belonging to any group,
120 * and hence can lose some elements. That auxiliary group is ignored while
121 * reading a MED file.
123 //================================================================================
125 void DriverMED_W_SMESHDS_Mesh::AddAllToGroup()
127 myDoAllInGroups = true;
133 typedef double (SMDS_MeshNode::* TGetCoord)() const;
134 typedef const char* TName;
135 typedef const char* TUnit;
137 // name length in a mesh must be equal to 16 :
144 TUnit aUnit[3] = {M,M,M};
147 TGetCoord aXYZGetCoord[3] = {
152 TName aXYZName[3] = {X,Y,Z};
155 TGetCoord aXYGetCoord[2] = {
159 TName aXYName[2] = {X,Y};
161 TGetCoord aYZGetCoord[2] = {
165 TName aYZName[2] = {Y,Z};
167 TGetCoord aXZGetCoord[2] = {
171 TName aXZName[2] = {X,Z};
174 TGetCoord aXGetCoord[1] = {
177 TName aXName[1] = {X};
179 TGetCoord aYGetCoord[1] = {
182 TName aYName[1] = {Y};
184 TGetCoord aZGetCoord[1] = {
187 TName aZName[1] = {Z};
191 SMDS_NodeIteratorPtr myNodeIter;
192 const SMDS_MeshNode* myCurrentNode;
193 TGetCoord* myGetCoord;
197 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
198 TGetCoord* theGetCoord,
200 TUnit* theUnit = aUnit):
201 myNodeIter(theNodeIter),
202 myGetCoord(theGetCoord),
206 virtual ~TCoordHelper(){}
208 return myNodeIter->more() &&
209 (myCurrentNode = myNodeIter->next());
211 const SMDS_MeshNode* GetNode(){
212 return myCurrentNode;
214 MED::TIntVector::value_type GetID(){
215 return myCurrentNode->GetID();
217 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
218 return (myCurrentNode->*myGetCoord[theCoodId])();
220 MED::TStringVector::value_type GetName(TInt theDimId){
221 return myName[theDimId];
223 MED::TStringVector::value_type GetUnit(TInt theDimId){
224 return myUnit[theDimId];
227 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
229 //-------------------------------------------------------
231 * \brief Structure describing element type
233 //-------------------------------------------------------
236 EEntiteMaillage _entity;
237 EGeometrieElement _geomType;
239 SMDSAbs_ElementType _smdsType;
241 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
242 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
246 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
248 //================================================================================
250 * \brief Fills element to famaly ID map for element type.
251 * Removes all families of anElemType
253 //================================================================================
255 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
256 list<DriverMED_FamilyPtr> & aFamilies,
257 const SMDSAbs_ElementType anElemType)
259 anElemFamMap.Clear();
260 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
261 while ( aFamsIter != aFamilies.end() )
263 if ((*aFamsIter)->GetType() != anElemType) {
267 int aFamId = (*aFamsIter)->GetId();
268 const ElementsSet& anElems = (*aFamsIter)->GetElements();
269 ElementsSet::const_iterator anElemsIter = anElems.begin();
270 for (; anElemsIter != anElems.end(); anElemsIter++)
272 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
274 // remove a family from the list
275 aFamilies.erase( aFamsIter++ );
280 //================================================================================
282 * \brief For an element, return family ID found in the map or a default one
284 //================================================================================
286 int getFamilyId( const TElemFamilyMap & anElemFamMap,
287 const SMDS_MeshElement* anElement,
288 const int aDefaultFamilyId)
290 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
291 return anElemFamMap( (Standard_Address) anElement );
293 return aDefaultFamilyId;
296 //================================================================================
298 * \brief Returns iterator on sub-meshes
300 //================================================================================
302 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
304 return SMESHDS_SubMeshIteratorPtr
305 ( new SMDS_SetIterator
306 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
307 mySubMeshes.end() ));
311 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
313 Status aResult = DRS_OK;
315 //MESSAGE("Perform - myFile : "<<myFile);
317 // Creating the MED mesh for corresponding SMDS structure
318 //-------------------------------------------------------
320 if (myMeshId != -1) {
321 ostringstream aMeshNameStr;
322 aMeshNameStr<<myMeshId;
323 aMeshName = aMeshNameStr.str();
325 aMeshName = myMeshName;
328 // Mesh dimension definition
330 TInt aMeshDimension = 0;
331 if ( myMesh->NbEdges() > 0 )
333 if ( myMesh->NbFaces() > 0 )
335 if ( myMesh->NbVolumes() > 0 )
338 TInt aSpaceDimension = 3;
339 TCoordHelperPtr aCoordHelperPtr;
341 bool anIsXDimension = false;
342 bool anIsYDimension = false;
343 bool anIsZDimension = false;
344 if ( myAutoDimension && aMeshDimension < 3 )
346 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
348 if(aNodesIter->more()){
349 const SMDS_MeshNode* aNode = aNodesIter->next();
350 aBounds[0] = aBounds[1] = aNode->X();
351 aBounds[2] = aBounds[3] = aNode->Y();
352 aBounds[4] = aBounds[5] = aNode->Z();
354 while(aNodesIter->more()){
355 const SMDS_MeshNode* aNode = aNodesIter->next();
356 aBounds[0] = min(aBounds[0],aNode->X());
357 aBounds[1] = max(aBounds[1],aNode->X());
359 aBounds[2] = min(aBounds[2],aNode->Y());
360 aBounds[3] = max(aBounds[3],aNode->Y());
362 aBounds[4] = min(aBounds[4],aNode->Z());
363 aBounds[5] = max(aBounds[5],aNode->Z());
367 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
368 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
369 if ( !mainShape.IsNull() && hasShapeToMesh )
371 // define EPS by max tolerance of the mainShape (IPAL53097)
372 TopExp_Explorer subShape;
373 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
374 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
376 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
377 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
379 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
380 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
384 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
385 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
386 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
387 aSpaceDimension = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
388 if ( !aSpaceDimension )
390 // PAL16857(SMESH not conform to the MED convention):
391 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
393 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
394 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
395 if ( anIsYDimension ) {
397 anIsXDimension = true;
404 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
405 switch ( aSpaceDimension ) {
407 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
410 if(anIsXDimension && anIsYDimension)
411 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
412 if(anIsYDimension && anIsZDimension)
413 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
414 if(anIsXDimension && anIsZDimension)
415 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
419 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
421 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
423 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
428 MED::PWrapper myMed = CrWrapperW(myFile);
429 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
430 //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
431 myMed->SetMeshInfo(aMeshInfo);
433 // Storing SMDS groups and sub-meshes as med families
434 //----------------------------------------------------
435 int myNodesDefaultFamilyId = 0;
436 int my0DElementsDefaultFamilyId = 0;
437 int myBallsDefaultFamilyId = 0;
438 int myEdgesDefaultFamilyId = 0;
439 int myFacesDefaultFamilyId = 0;
440 int myVolumesDefaultFamilyId = 0;
441 int nbNodes = myMesh->NbNodes();
442 int nb0DElements = myMesh->Nb0DElements();
443 int nbBalls = myMesh->NbBalls();
444 int nbEdges = myMesh->NbEdges();
445 int nbFaces = myMesh->NbFaces();
446 int nbVolumes = myMesh->NbVolumes();
447 if (myDoGroupOfNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
448 if (myDoGroupOfEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
449 if (myDoGroupOfFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
450 if (myDoGroupOfVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
451 if (myDoGroupOf0DElems) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
452 if (myDoGroupOfBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
453 if (myDoAllInGroups )
455 if (!myDoGroupOfEdges) myEdgesDefaultFamilyId = NIG_EDGES_FAMILY ;
456 if (!myDoGroupOfFaces) myFacesDefaultFamilyId = NIG_FACES_FAMILY ;
457 if (!myDoGroupOfVolumes) myVolumesDefaultFamilyId = NIG_VOLS_FAMILY ;
458 if (!myDoGroupOf0DElems) my0DElementsDefaultFamilyId = NIG_0DELEM_FAMILY ;
459 if (!myDoGroupOfBalls) myBallsDefaultFamilyId = NIG_BALL_FAMILY ;
462 //MESSAGE("Perform - aFamilyInfo");
463 list<DriverMED_FamilyPtr> aFamilies;
464 if (myAllSubMeshes) {
465 aFamilies = DriverMED_Family::MakeFamilies
466 (myMesh->SubMeshes(), myGroups,
467 myDoGroupOfNodes && nbNodes,
468 myDoGroupOfEdges && nbEdges,
469 myDoGroupOfFaces && nbFaces,
470 myDoGroupOfVolumes && nbVolumes,
471 myDoGroupOf0DElems && nb0DElements,
472 myDoGroupOfBalls && nbBalls,
476 aFamilies = DriverMED_Family::MakeFamilies
477 (getIterator( mySubMeshes ), myGroups,
478 myDoGroupOfNodes && nbNodes,
479 myDoGroupOfEdges && nbEdges,
480 myDoGroupOfFaces && nbFaces,
481 myDoGroupOfVolumes && nbVolumes,
482 myDoGroupOf0DElems && nb0DElements,
483 myDoGroupOfBalls && nbBalls,
486 list<DriverMED_FamilyPtr>::iterator aFamsIter;
487 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
489 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
490 myMed->SetFamilyInfo(aFamilyInfo);
493 // Storing SMDS nodes to the MED file for the MED mesh
494 //----------------------------------------------------
495 #ifdef _EDF_NODE_IDS_
496 typedef map<TInt,TInt> TNodeIdMap;
497 TNodeIdMap aNodeIdMap;
499 const EModeSwitch theMode = eFULL_INTERLACE;
500 const ERepere theSystem = eCART;
501 const EBooleen theIsElemNum = eVRAI;
502 const EBooleen theIsElemNames = eFAUX;
503 const EConnectivite theConnMode = eNOD;
505 TInt aNbNodes = myMesh->NbNodes();
506 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
507 theMode, theSystem, theIsElemNum, theIsElemNames);
509 // find family numbers for nodes
510 TElemFamilyMap anElemFamMap;
511 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
513 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
516 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
517 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
518 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
521 int aNodeID = aCoordHelperPtr->GetID();
522 aNodeInfo->SetElemNum( iNode, aNodeID );
523 #ifdef _EDF_NODE_IDS_
524 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
527 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
528 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
529 aNodeInfo->SetFamNum( iNode, famNum );
531 anElemFamMap.Clear();
533 // coordinate names and units
534 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
535 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
536 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
539 //MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
540 myMed->SetNodeInfo(aNodeInfo);
541 aNodeInfo.reset(); // free memory used for arrays
544 // Storing SMDS elements to the MED file for the MED mesh
545 //-------------------------------------------------------
546 // Write one element type at once in order to minimize memory usage (PAL19276)
548 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
550 // poly elements are not supported by med-2.1
551 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
552 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
554 // nodes on VERTEXes where 0D elements are absent
555 std::vector<const SMDS_MeshElement*> nodesOf0D;
556 std::vector< SMDS_ElemIteratorPtr > iterVec;
557 SMDS_ElemIteratorPtr iterVecIter;
558 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
561 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
562 iterVec[1] = SMDS_ElemIteratorPtr
563 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
565 typedef SMDS_IteratorOnIterators
566 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
567 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
570 // collect info on all geom types
572 list< TElemTypeData > aTElemTypeDatas;
574 EEntiteMaillage anEntity = eMAILLE;
575 #ifdef _ELEMENTS_BY_DIM_
576 anEntity = eNOEUD_ELEMENT;
578 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
580 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
582 #ifdef _ELEMENTS_BY_DIM_
583 anEntity = eSTRUCT_ELEMENT;
585 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
587 nbElemInfo.NbBalls(),
589 #ifdef _ELEMENTS_BY_DIM_
592 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
594 nbElemInfo.NbEdges( ORDER_LINEAR ),
596 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
598 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
600 #ifdef _ELEMENTS_BY_DIM_
603 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
605 nbElemInfo.NbTriangles( ORDER_LINEAR ),
607 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
609 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
610 nbElemInfo.NbBiQuadTriangles(),
612 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
614 nbElemInfo.NbBiQuadTriangles(),
616 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
618 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
620 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
622 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
623 nbElemInfo.NbBiQuadQuadrangles(),
625 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
627 nbElemInfo.NbBiQuadQuadrangles(),
629 if ( polyTypesSupported ) {
630 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
632 nbElemInfo.NbPolygons( ORDER_LINEAR ),
634 // we need one more loop on poly elements to count nb of their nodes
635 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
637 nbElemInfo.NbPolygons( ORDER_LINEAR ),
639 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
641 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
643 // we need one more loop on QUAD poly elements to count nb of their nodes
644 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
646 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
649 #ifdef _ELEMENTS_BY_DIM_
652 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
654 nbElemInfo.NbTetras( ORDER_LINEAR ),
656 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
658 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
660 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
662 nbElemInfo.NbPyramids( ORDER_LINEAR ),
664 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
666 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
668 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
670 nbElemInfo.NbPrisms( ORDER_LINEAR ),
672 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
674 nbElemInfo.NbQuadPrisms(),
676 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
678 nbElemInfo.NbBiQuadPrisms(),
680 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
682 nbElemInfo.NbHexas( ORDER_LINEAR ),
684 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
686 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
687 nbElemInfo.NbTriQuadHexas(),
689 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
691 nbElemInfo.NbTriQuadHexas(),
693 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
695 nbElemInfo.NbHexPrisms(),
697 if ( polyTypesSupported ) {
698 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
700 nbElemInfo.NbPolyhedrons(),
702 // we need one more loop on poly elements to count nb of their nodes
703 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
705 nbElemInfo.NbPolyhedrons(),
709 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
711 // loop on all geom types of elements
713 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
714 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
716 if ( aElemTypeData->_nbElems == 0 )
719 int defaultFamilyId = 0;
720 switch ( aElemTypeData->_smdsType ) {
721 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
722 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
723 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
724 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
725 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
730 // build map of family numbers for this type
731 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
733 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
734 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
737 // iterator on elements of a current type
738 SMDS_ElemIteratorPtr elemIterator;
743 if ( aElemTypeData->_geomType == ePOLYGONE ||
744 aElemTypeData->_geomType == ePOLYGON2 )
746 if ( aElemTypeData->_geomType == ePOLYGONE )
747 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
749 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
751 if ( nbPolygonNodes == 0 ) {
753 while ( elemIterator->more() ) {
754 const SMDS_MeshElement* anElem = elemIterator->next();
755 nbPolygonNodes += anElem->NbNodes();
756 if ( ++iElem == aElemTypeData->_nbElems )
762 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
763 aElemTypeData->_entity,
764 aElemTypeData->_geomType,
765 aElemTypeData->_nbElems,
767 theConnMode, theIsElemNum,
769 TElemNum & index = *(aPolygoneInfo->myIndex.get());
772 while ( elemIterator->more() )
774 const SMDS_MeshElement* anElem = elemIterator->next();
776 TInt aNbNodes = anElem->NbNodes();
777 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
780 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
781 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
782 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
783 #ifdef _EDF_NODE_IDS_
784 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
786 aTConnSlice[ iNode ] = aNode->GetID();
790 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
793 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
794 aPolygoneInfo->SetFamNum( iElem, famNum );
796 if ( ++iElem == aPolygoneInfo->GetNbElem() )
799 myMed->SetPolygoneInfo(aPolygoneInfo);
801 nbPolygonNodes = 0; // to treat next polygon type
807 else if ( aElemTypeData->_geomType == ePOLYEDRE )
809 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
811 if ( nbPolyhedronNodes == 0 ) {
813 while ( elemIterator->more() ) {
814 const SMDS_MeshElement* anElem = elemIterator->next();
815 nbPolyhedronNodes += anElem->NbNodes();
816 nbPolyhedronFaces += anElem->NbFaces();
817 if ( ++iElem == aElemTypeData->_nbElems )
823 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
824 aElemTypeData->_entity,
825 aElemTypeData->_geomType,
826 aElemTypeData->_nbElems,
832 TElemNum & index = *(aPolyhInfo->myIndex.get());
833 TElemNum & faces = *(aPolyhInfo->myFaces.get());
834 TElemNum & conn = *(aPolyhInfo->myConn.get());
838 TInt iFace = 0, iNode = 0;
839 while ( elemIterator->more() )
841 const SMDS_MeshElement* anElem = elemIterator->next();
842 const SMDS_MeshVolume *aPolyedre = myMesh->DownCast< SMDS_MeshVolume >( anElem );
843 if ( !aPolyedre ) continue;
845 TInt aNbFaces = aPolyedre->NbFaces();
846 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
849 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
850 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
851 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
854 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
855 while ( nodeIt->more() ) {
856 const SMDS_MeshElement* aNode = nodeIt->next();
857 #ifdef _EDF_NODE_IDS_
858 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
860 conn[ iNode ] = aNode->GetID();
865 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
868 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
869 aPolyhInfo->SetFamNum( iElem, famNum );
871 if ( ++iElem == aPolyhInfo->GetNbElem() )
874 myMed->SetPolyedreInfo(aPolyhInfo);
876 } // if (aElemTypeData->_geomType == ePOLYEDRE )
880 else if (aElemTypeData->_geomType == eBALL )
882 // allocate data arrays
883 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
885 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
886 while ( elemIterator->more() )
888 const SMDS_MeshElement* anElem = elemIterator->next();
890 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
891 #ifdef _EDF_NODE_IDS_
892 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
894 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
897 aBallInfo->SetElemNum( iElem, anElem->GetID() );
900 aBallInfo->myDiameters[ iElem ] =
901 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
904 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
905 aBallInfo->SetFamNum( iElem, famNum );
908 // store data in a file
909 myMed->SetBallInfo(aBallInfo);
914 // Treat standard types
915 // ---------------------
916 // allocate data arrays
917 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
918 aElemTypeData->_entity,
919 aElemTypeData->_geomType,
920 aElemTypeData->_nbElems,
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);
958 } // loop on geom types
960 catch(const std::exception& exc) {
961 INFOS("The following exception was caught:\n\t"<<exc.what());
965 INFOS("Unknown exception was caught !!!");
975 //================================================================================
977 * \brief Returns nodes on VERTEXes where 0D elements are absent
979 //================================================================================
981 bool DriverMED_W_SMESHDS_Mesh::
982 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
983 std::vector<const SMDS_MeshElement*>& nodes)
986 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
988 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
990 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
991 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
994 const SMDS_MeshNode* n = nIt->next();
995 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
996 nodes.push_back( n );
1000 return !nodes.empty();