1 // SMESH DriverMED : driver to read and write 'med' files
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DriverMED_W_SMESHDS_Mesh.cxx
29 #include "DriverMED_W_SMESHDS_Mesh.h"
30 #include "DriverMED_W_SMDS_Mesh.h"
31 #include "DriverMED_Family.h"
33 #include "SMESHDS_Mesh.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
38 #include "utilities.h"
40 #include "MED_Utilities.hxx"
42 #define _EDF_NODE_IDS_
43 //#define _ELEMENTS_BY_DIM_
49 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
50 myAllSubMeshes (false),
51 myDoGroupOfNodes (false),
52 myDoGroupOfEdges (false),
53 myDoGroupOfFaces (false),
54 myDoGroupOfVolumes (false)
57 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
60 myMed = CrWrapper(theFileName,theId);
61 Driver_SMESHDS_Mesh::SetFile(theFileName);
64 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
66 return SetFile(theFileName,MED::eV2_2);
69 void DriverMED_W_SMESHDS_Mesh::SetMeshName(const std::string& theMeshName)
71 myMeshName = theMeshName;
74 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
76 myGroups.push_back(theGroup);
79 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
81 myAllSubMeshes = true;
84 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
86 mySubMeshes[theID] = theSubMesh;
89 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
91 myDoGroupOfNodes = true;
94 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
96 myDoGroupOfEdges = true;
99 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
101 myDoGroupOfFaces = true;
104 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
106 myDoGroupOfVolumes = true;
110 typedef double (SMDS_MeshNode::* TGetCoord)() const;
111 typedef const char* TName;
112 typedef const char* TUnit;
114 // name length in a mesh must be equal to 16 :
121 TUnit aUnit[3] = {M,M,M};
124 TGetCoord aXYZGetCoord[3] = {
129 TName aXYZName[3] = {X,Y,Z};
132 TGetCoord aXYGetCoord[2] = {
136 TName aXYName[2] = {X,Y};
138 TGetCoord aYZGetCoord[2] = {
142 TName aYZName[2] = {Y,Z};
144 TGetCoord aXZGetCoord[2] = {
148 TName aXZName[2] = {X,Z};
151 TGetCoord aXGetCoord[1] = {
154 TName aXName[1] = {X};
156 TGetCoord aYGetCoord[1] = {
159 TName aYName[1] = {Y};
161 TGetCoord aZGetCoord[1] = {
164 TName aZName[1] = {Z};
168 SMDS_NodeIteratorPtr myNodeIter;
169 const SMDS_MeshNode* myCurrentNode;
170 TGetCoord* myGetCoord;
174 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
175 TGetCoord* theGetCoord,
177 TUnit* theUnit = aUnit):
178 myNodeIter(theNodeIter),
179 myGetCoord(theGetCoord),
183 virtual ~TCoordHelper(){}
185 return myNodeIter->more() &&
186 (myCurrentNode = myNodeIter->next());
188 const SMDS_MeshNode* GetNode(){
189 return myCurrentNode;
191 MED::TIntVector::value_type GetID(){
192 return myCurrentNode->GetID();
194 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
195 return (myCurrentNode->*myGetCoord[theCoodId])();
197 MED::TStringVector::value_type GetName(TInt theDimId){
198 return myName[theDimId];
200 MED::TStringVector::value_type GetUnit(TInt theDimId){
201 return myUnit[theDimId];
204 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
209 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
211 Status aResult = DRS_OK;
212 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
213 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
217 MESSAGE("Perform - myFile : "<<myFile);
219 // Creating the MED mesh for corresponding SMDS structure
220 //-------------------------------------------------------
222 if (myMeshId != -1) {
223 ostringstream aMeshNameStr;
224 aMeshNameStr<<myMeshId;
225 aMeshName = aMeshNameStr.str();
227 aMeshName = myMeshName;
230 // Mesh dimension definition
232 TCoordHelperPtr aCoordHelperPtr;
234 bool anIsXDimension = false;
235 bool anIsYDimension = false;
236 bool anIsZDimension = false;
238 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
240 if(aNodesIter->more()){
241 const SMDS_MeshNode* aNode = aNodesIter->next();
242 aBounds[0] = aBounds[1] = aNode->X();
243 aBounds[2] = aBounds[3] = aNode->Y();
244 aBounds[4] = aBounds[5] = aNode->Z();
246 while(aNodesIter->more()){
247 const SMDS_MeshNode* aNode = aNodesIter->next();
248 aBounds[0] = min(aBounds[0],aNode->X());
249 aBounds[1] = max(aBounds[1],aNode->X());
251 aBounds[2] = min(aBounds[2],aNode->Y());
252 aBounds[3] = max(aBounds[3],aNode->Y());
254 aBounds[4] = min(aBounds[4],aNode->Z());
255 aBounds[5] = max(aBounds[5],aNode->Z());
259 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
260 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
261 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
262 aMeshDimension = anIsXDimension + anIsYDimension + anIsZDimension;
267 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
268 switch(aMeshDimension){
270 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
273 if(anIsXDimension && anIsYDimension)
274 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
275 if(anIsYDimension && anIsZDimension)
276 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
277 if(anIsXDimension && anIsZDimension)
278 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
282 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
284 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
286 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
292 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aMeshName);
293 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
294 myMed->SetMeshInfo(aMeshInfo);
296 // Storing SMDS groups and sub-meshes
297 //-----------------------------------
298 int myNodesDefaultFamilyId = 0;
299 int myEdgesDefaultFamilyId = 0;
300 int myFacesDefaultFamilyId = 0;
301 int myVolumesDefaultFamilyId = 0;
302 if (myDoGroupOfNodes)
303 myNodesDefaultFamilyId = REST_NODES_FAMILY;
304 if (myDoGroupOfEdges)
305 myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
306 if (myDoGroupOfFaces)
307 myFacesDefaultFamilyId = REST_FACES_FAMILY;
308 if (myDoGroupOfVolumes)
309 myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
311 MESSAGE("Perform - aFamilyInfo");
312 map<const SMDS_MeshElement *, int> anElemFamMap;
313 list<DriverMED_FamilyPtr> aFamilies;
314 if (myAllSubMeshes) {
315 aFamilies = DriverMED_Family::MakeFamilies
316 (myMesh->SubMeshes(), myGroups,
317 myDoGroupOfNodes, myDoGroupOfEdges, myDoGroupOfFaces, myDoGroupOfVolumes);
319 aFamilies = DriverMED_Family::MakeFamilies
320 (mySubMeshes, myGroups,
321 myDoGroupOfNodes, myDoGroupOfEdges, myDoGroupOfFaces, myDoGroupOfVolumes);
323 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
325 for (; aFamsIter != aFamilies.end(); aFamsIter++)
327 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
328 myMed->SetFamilyInfo(aFamilyInfo);
329 int aFamId = (*aFamsIter)->GetId();
331 const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
332 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElems.begin();
333 for (; anElemsIter != anElems.end(); anElemsIter++)
335 anElemFamMap[*anElemsIter] = aFamId;
339 // Storing SMDS nodes to the MED file for the MED mesh
340 //----------------------------------------------------
341 #ifdef _EDF_NODE_IDS_
342 typedef map<TInt,TInt> TNodeIdMap;
343 TNodeIdMap aNodeIdMap;
345 TInt aNbElems = myMesh->NbNodes();
346 MED::TIntVector anElemNums(aNbElems);
347 MED::TIntVector aFamilyNums(aNbElems);
348 MED::TFloatVector aCoordinates(aNbElems*aMeshDimension);
349 for(TInt iNode = 0, aStartId = 0; aCoordHelperPtr->Next(); iNode++, aStartId += aMeshDimension){
350 for(TInt iCoord = 0; iCoord < aMeshDimension; iCoord++){
351 aCoordinates[aStartId+iCoord] = aCoordHelperPtr->GetCoord(iCoord);
353 int aNodeID = aCoordHelperPtr->GetID();
354 anElemNums[iNode] = aNodeID;
355 #ifdef _EDF_NODE_IDS_
356 aNodeIdMap[aNodeID] = iNode+1;
358 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
359 if (anElemFamMap.find(aNode) != anElemFamMap.end())
360 aFamilyNums[iNode] = anElemFamMap[aNode];
362 aFamilyNums[iNode] = myNodesDefaultFamilyId;
365 MED::TStringVector aCoordNames(aMeshDimension);
366 MED::TStringVector aCoordUnits(aMeshDimension);
367 for(TInt iCoord = 0; iCoord < aMeshDimension; iCoord++){
368 aCoordNames[iCoord] = aCoordHelperPtr->GetName(iCoord);
369 aCoordUnits[iCoord] = aCoordHelperPtr->GetUnit(iCoord);
372 const ERepere SMDS_COORDINATE_SYSTEM = eCART;
374 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo,
377 SMDS_COORDINATE_SYSTEM,
382 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems);
383 myMed->SetNodeInfo(aNodeInfo);
386 // Storing others SMDS elements to the MED file for the MED mesh
387 //--------------------------------------------------------------
388 EEntiteMaillage SMDS_MED_ENTITY = eMAILLE;
389 const EConnectivite SMDS_MED_CONNECTIVITY = eNOD;
391 // Storing SMDS Edges
392 if(TInt aNbElems = myMesh->NbEdges()){
393 #ifdef _ELEMENTS_BY_DIM_
394 SMDS_MED_ENTITY = eARETE;
396 // count edges of diff types
397 int aNbSeg3 = 0, aNbSeg2 = 0;
398 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
399 while ( anIter->more() )
400 if ( anIter->next()->NbNodes() == 3 )
402 aNbSeg2 = aNbElems - aNbSeg3;
404 TInt aNbSeg2Conn = MED::GetNbNodes(eSEG2);
405 MED::TIntVector aSeg2ElemNums, aSeg2FamilyNums, aSeg2Conn;
406 aSeg2ElemNums .reserve( aNbSeg2 );
407 aSeg2FamilyNums.reserve( aNbSeg2 );
408 aSeg2Conn .reserve( aNbSeg2*aNbSeg2Conn );
410 TInt aNbSeg3Conn = MED::GetNbNodes(eSEG3);
411 MED::TIntVector aSeg3ElemNums, aSeg3FamilyNums, aSeg3Conn;
412 aSeg3ElemNums .reserve( aNbSeg3 );
413 aSeg3FamilyNums.reserve( aNbSeg3 );
414 aSeg3Conn .reserve( aNbSeg3*aNbSeg3Conn );
416 anIter = myMesh->edgesIterator();
417 while ( anIter->more() ) {
418 const SMDS_MeshEdge* anElem = anIter->next();
419 TInt aNbNodes = anElem->NbNodes();
421 TInt aNbConnectivity;
422 MED::TIntVector* anElemNums;
423 MED::TIntVector* aFamilyNums;
424 MED::TIntVector* aConnectivity;
427 aNbConnectivity = aNbSeg2Conn;
428 anElemNums = &aSeg2ElemNums;
429 aFamilyNums = &aSeg2FamilyNums;
430 aConnectivity = &aSeg2Conn;
433 aNbConnectivity = aNbSeg3Conn;
434 anElemNums = &aSeg3ElemNums;
435 aFamilyNums = &aSeg3FamilyNums;
436 aConnectivity = &aSeg3Conn;
442 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
443 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
444 #ifdef _EDF_NODE_IDS_
445 aConnectivity->push_back( aNodeIdMap[aNode->GetID()] );
447 aConnectivity->push_back( aNode->GetID() );
451 anElemNums->push_back(anElem->GetID());
453 map<const SMDS_MeshElement*,int>::iterator edge_fam = anElemFamMap.find( anElem );
454 if ( edge_fam != anElemFamMap.end() )
455 aFamilyNums->push_back( edge_fam->second );
457 aFamilyNums->push_back( myFacesDefaultFamilyId );
461 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
465 SMDS_MED_CONNECTIVITY,
468 myMed->SetCellInfo(aCellInfo);
471 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
475 SMDS_MED_CONNECTIVITY,
478 myMed->SetCellInfo(aCellInfo);
482 // Storing SMDS Faces
483 if(TInt aNbElems = myMesh->NbFaces()){
484 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
485 #ifdef _ELEMENTS_BY_DIM_
486 SMDS_MED_ENTITY = eFACE;
488 TInt aNbTriaConn = MED::GetNbNodes(eTRIA3);
489 MED::TIntVector anTriaElemNums;
490 anTriaElemNums.reserve(aNbElems);
491 MED::TIntVector aTriaFamilyNums;
492 aTriaFamilyNums.reserve(aNbElems);
493 MED::TIntVector aTriaConn;
494 aTriaConn.reserve(aNbElems*aNbTriaConn);
496 TInt aNbTria6Conn = MED::GetNbNodes(eTRIA6);
497 MED::TIntVector anTria6ElemNums;
498 anTria6ElemNums.reserve(aNbElems);
499 MED::TIntVector aTria6FamilyNums;
500 aTria6FamilyNums.reserve(aNbElems);
501 MED::TIntVector aTria6Conn;
502 aTria6Conn.reserve(aNbElems*aNbTria6Conn);
504 TInt aNbQuadConn = MED::GetNbNodes(eQUAD4);
505 MED::TIntVector aQuadElemNums;
506 aQuadElemNums.reserve(aNbElems);
507 MED::TIntVector aQuadFamilyNums;
508 aQuadFamilyNums.reserve(aNbElems);
509 MED::TIntVector aQuadConn;
510 aQuadConn.reserve(aNbElems*aNbQuadConn);
512 TInt aNbQuad8Conn = MED::GetNbNodes(eQUAD8);
513 MED::TIntVector aQuad8ElemNums;
514 aQuad8ElemNums.reserve(aNbElems);
515 MED::TIntVector aQuad8FamilyNums;
516 aQuad8FamilyNums.reserve(aNbElems);
517 MED::TIntVector aQuad8Conn;
518 aQuad8Conn.reserve(aNbElems*aNbQuad8Conn);
520 MED::TIntVector aPolygoneElemNums;
521 aPolygoneElemNums.reserve(aNbElems);
522 MED::TIntVector aPolygoneInds;
523 aPolygoneInds.reserve(aNbElems + 1);
524 aPolygoneInds.push_back(1); // reference on the first element in the connectivities
525 MED::TIntVector aPolygoneFamilyNums;
526 aPolygoneFamilyNums.reserve(aNbElems);
527 MED::TIntVector aPolygoneConn;
528 aPolygoneConn.reserve(aNbElems*aNbQuadConn);
530 for(TInt iElem = 0; iElem < aNbElems && anIter->more(); iElem++){
531 const SMDS_MeshFace* anElem = anIter->next();
532 TInt aNbNodes = anElem->NbNodes();
533 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
534 TInt aNbConnectivity;
535 MED::TIntVector* anElemNums;
536 MED::TIntVector* aFamilyNums;
537 MED::TIntVector* aConnectivity;
538 if (anElem->IsPoly()) {
539 aNbConnectivity = aNbNodes;
540 anElemNums = &aPolygoneElemNums;
541 aFamilyNums = &aPolygoneFamilyNums;
542 aConnectivity = &aPolygoneConn;
547 aNbConnectivity = aNbTriaConn;
548 anElemNums = &anTriaElemNums;
549 aFamilyNums = &aTriaFamilyNums;
550 aConnectivity = &aTriaConn;
553 aNbConnectivity = aNbQuadConn;
554 anElemNums = &aQuadElemNums;
555 aFamilyNums = &aQuadFamilyNums;
556 aConnectivity = &aQuadConn;
559 aNbConnectivity = aNbTria6Conn;
560 anElemNums = &anTria6ElemNums;
561 aFamilyNums = &aTria6FamilyNums;
562 aConnectivity = &aTria6Conn;
565 aNbConnectivity = aNbQuad8Conn;
566 anElemNums = &aQuad8ElemNums;
567 aFamilyNums = &aQuad8FamilyNums;
568 aConnectivity = &aQuad8Conn;
574 MED::TIntVector aVector(aNbNodes);
575 for(TInt iNode = 0; aNodesIter->more(); iNode++){
576 const SMDS_MeshElement* aNode = aNodesIter->next();
577 #ifdef _EDF_NODE_IDS_
578 aVector[iNode] = aNodeIdMap[aNode->GetID()];
580 aVector[iNode] = aNode->GetID();
584 TInt aSize = aConnectivity->size();
585 aConnectivity->resize(aSize+aNbConnectivity);
586 // There is some differences between SMDS and MED in cells mapping
589 (*aConnectivity)[aSize+0] = aVector[0];
590 (*aConnectivity)[aSize+1] = aVector[1];
591 (*aConnectivity)[aSize+2] = aVector[3];
592 (*aConnectivity)[aSize+3] = aVector[2];
594 for(TInt iNode = 0; iNode < aNbNodes; iNode++)
595 (*aConnectivity)[aSize+iNode] = aVector[iNode];
598 if (anElem->IsPoly()) {
599 // fill indices for polygonal element
600 TInt aPrevPos = aPolygoneInds.back();
601 aPolygoneInds.push_back(aPrevPos + aNbNodes);
604 anElemNums->push_back(anElem->GetID());
606 if (anElemFamMap.find(anElem) != anElemFamMap.end())
607 aFamilyNums->push_back(anElemFamMap[anElem]);
609 aFamilyNums->push_back(myFacesDefaultFamilyId);
611 if(TInt aNbElems = anTriaElemNums.size()){
612 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
616 SMDS_MED_CONNECTIVITY,
619 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eTRIA3<<"; aNbElems = "<<aNbElems);
620 myMed->SetCellInfo(aCellInfo);
622 if(TInt aNbElems = aQuadElemNums.size()){
623 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
627 SMDS_MED_CONNECTIVITY,
630 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eQUAD4<<"; aNbElems = "<<aNbElems);
631 myMed->SetCellInfo(aCellInfo);
633 if(TInt aNbElems = anTria6ElemNums.size()){
634 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
638 SMDS_MED_CONNECTIVITY,
641 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eTRIA6<<"; aNbElems = "<<aNbElems);
642 myMed->SetCellInfo(aCellInfo);
644 if(TInt aNbElems = aQuad8ElemNums.size()){
645 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
649 SMDS_MED_CONNECTIVITY,
652 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eQUAD8<<"; aNbElems = "<<aNbElems);
653 myMed->SetCellInfo(aCellInfo);
655 if(TInt aNbElems = aPolygoneElemNums.size()){
656 // add one element in connectivities,
657 // referenced by the last element in indices
658 aPolygoneConn.push_back(0);
660 PPolygoneInfo aCellInfo = myMed->CrPolygoneInfo(aMeshInfo,
665 SMDS_MED_CONNECTIVITY,
668 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePOLYGONE<<"; aNbElems = "<<aNbElems);
669 myMed->SetPolygoneInfo(aCellInfo);
673 // Storing SMDS Volumes
674 if(TInt aNbElems = myMesh->NbVolumes()){
675 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
676 #ifdef _ELEMENTS_BY_DIM_
677 SMDS_MED_ENTITY = eMAILLE;
679 TInt aNbTetraConn = MED::GetNbNodes(eTETRA4);
680 MED::TIntVector anTetraElemNums;
681 anTetraElemNums.reserve(aNbElems);
682 MED::TIntVector aTetraFamilyNums;
683 aTetraFamilyNums.reserve(aNbElems);
684 MED::TIntVector aTetraConn;
685 aTetraConn.reserve(aNbElems*aNbTetraConn);
687 TInt aNbPyraConn = MED::GetNbNodes(ePYRA5);
688 MED::TIntVector anPyraElemNums;
689 anPyraElemNums.reserve(aNbElems);
690 MED::TIntVector aPyraFamilyNums;
691 aPyraFamilyNums.reserve(aNbElems);
692 MED::TIntVector aPyraConn;
693 aPyraConn.reserve(aNbElems*aNbPyraConn);
695 TInt aNbPentaConn = MED::GetNbNodes(ePENTA6);
696 MED::TIntVector anPentaElemNums;
697 anPentaElemNums.reserve(aNbElems);
698 MED::TIntVector aPentaFamilyNums;
699 aPentaFamilyNums.reserve(aNbElems);
700 MED::TIntVector aPentaConn;
701 aPentaConn.reserve(aNbElems*aNbPentaConn);
703 TInt aNbHexaConn = MED::GetNbNodes(eHEXA8);
704 MED::TIntVector aHexaElemNums;
705 aHexaElemNums.reserve(aNbElems);
706 MED::TIntVector aHexaFamilyNums;
707 aHexaFamilyNums.reserve(aNbElems);
708 MED::TIntVector aHexaConn;
709 aHexaConn.reserve(aNbElems*aNbHexaConn);
711 TInt aNbTetra10Conn = MED::GetNbNodes(eTETRA10);
712 MED::TIntVector anTetra10ElemNums;
713 anTetra10ElemNums.reserve(aNbElems);
714 MED::TIntVector aTetra10FamilyNums;
715 aTetra10FamilyNums.reserve(aNbElems);
716 MED::TIntVector aTetra10Conn;
717 aTetra10Conn.reserve(aNbElems*aNbTetra10Conn);
719 TInt aNbPyra13Conn = MED::GetNbNodes(ePYRA13);
720 MED::TIntVector anPyra13ElemNums;
721 anPyra13ElemNums.reserve(aNbElems);
722 MED::TIntVector aPyra13FamilyNums;
723 aPyra13FamilyNums.reserve(aNbElems);
724 MED::TIntVector aPyra13Conn;
725 aPyra13Conn.reserve(aNbElems*aNbPyra13Conn);
727 TInt aNbPenta15Conn = MED::GetNbNodes(ePENTA15);
728 MED::TIntVector anPenta15ElemNums;
729 anPenta15ElemNums.reserve(aNbElems);
730 MED::TIntVector aPenta15FamilyNums;
731 aPenta15FamilyNums.reserve(aNbElems);
732 MED::TIntVector aPenta15Conn;
733 aPenta15Conn.reserve(aNbElems*aNbPenta15Conn);
735 TInt aNbHexa20Conn = MED::GetNbNodes(eHEXA20);
736 MED::TIntVector aHexa20ElemNums;
737 aHexa20ElemNums.reserve(aNbElems);
738 MED::TIntVector aHexa20FamilyNums;
739 aHexa20FamilyNums.reserve(aNbElems);
740 MED::TIntVector aHexa20Conn;
741 aHexa20Conn.reserve(aNbElems*aNbHexa20Conn);
743 MED::TIntVector aPolyedreElemNums;
744 aPolyedreElemNums.reserve(aNbElems);
745 MED::TIntVector aPolyedreInds;
746 aPolyedreInds.reserve(aNbElems + 1);
747 aPolyedreInds.push_back(1); // reference on the first element in the faces
748 MED::TIntVector aPolyedreFaces;
749 aPolyedreFaces.reserve(aNbElems + 1);
750 aPolyedreFaces.push_back(1); // reference on the first element in the connectivities
751 MED::TIntVector aPolyedreFamilyNums;
752 aPolyedreFamilyNums.reserve(aNbElems);
753 MED::TIntVector aPolyedreConn;
754 aPolyedreConn.reserve(aNbElems*aNbHexaConn);
756 for(TInt iElem = 0; iElem < aNbElems && anIter->more(); iElem++){
757 const SMDS_MeshVolume* anElem = anIter->next();
759 MED::TIntVector* anElemNums;
760 MED::TIntVector* aFamilyNums;
762 if (anElem->IsPoly()) {
763 const SMDS_PolyhedralVolumeOfNodes* aPolyedre =
764 (const SMDS_PolyhedralVolumeOfNodes*) anElem;
766 MESSAGE("Warning: bad volumic element");
770 anElemNums = &aPolyedreElemNums;
771 aFamilyNums = &aPolyedreFamilyNums;
773 TInt aNodeId, aNbFaces = aPolyedre->NbFaces();
774 for (int iface = 1; iface <= aNbFaces; iface++) {
775 int aNbFaceNodes = aPolyedre->NbFaceNodes(iface);
776 for (int inode = 1; inode <= aNbFaceNodes; inode++) {
777 aNodeId = aPolyedre->GetFaceNode(iface, inode)->GetID();
778 #ifdef _EDF_NODE_IDS_
779 aPolyedreConn.push_back(aNodeIdMap[aNodeId]);
781 aPolyedreConn.push_back(aNodeId);
784 TInt aPrevPos = aPolyedreFaces.back();
785 aPolyedreFaces.push_back(aPrevPos + aNbFaceNodes);
787 TInt aPrevPos = aPolyedreInds.back();
788 aPolyedreInds.push_back(aPrevPos + aNbFaces);
792 TInt aNbNodes = anElem->NbNodes();
793 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
794 TInt aNbConnectivity;
795 MED::TIntVector* aConnectivity;
798 aNbConnectivity = aNbTetraConn;
799 anElemNums = &anTetraElemNums;
800 aFamilyNums = &aTetraFamilyNums;
801 aConnectivity = &aTetraConn;
804 aNbConnectivity = aNbPyraConn;
805 anElemNums = &anPyraElemNums;
806 aFamilyNums = &aPyraFamilyNums;
807 aConnectivity = &aPyraConn;
810 aNbConnectivity = aNbPentaConn;
811 anElemNums = &anPentaElemNums;
812 aFamilyNums = &aPentaFamilyNums;
813 aConnectivity = &aPentaConn;
816 aNbConnectivity = aNbHexaConn;
817 anElemNums = &aHexaElemNums;
818 aFamilyNums = &aHexaFamilyNums;
819 aConnectivity = &aHexaConn;
822 aNbConnectivity = aNbTetra10Conn;
823 anElemNums = &anTetra10ElemNums;
824 aFamilyNums = &aTetra10FamilyNums;
825 aConnectivity = &aTetra10Conn;
828 aNbConnectivity = aNbPyra13Conn;
829 anElemNums = &anPyra13ElemNums;
830 aFamilyNums = &aPyra13FamilyNums;
831 aConnectivity = &aPyra13Conn;
834 aNbConnectivity = aNbPenta15Conn;
835 anElemNums = &anPenta15ElemNums;
836 aFamilyNums = &aPenta15FamilyNums;
837 aConnectivity = &aPenta15Conn;
840 aNbConnectivity = aNbHexa20Conn;
841 anElemNums = &aHexa20ElemNums;
842 aFamilyNums = &aHexa20FamilyNums;
843 aConnectivity = &aHexa20Conn;
846 TInt aSize = aConnectivity->size();
847 aConnectivity->resize(aSize + aNbConnectivity);
849 MED::TIntVector aVector(aNbNodes);
850 for(TInt iNode = 0; aNodesIter->more(); iNode++){
851 const SMDS_MeshElement* aNode = aNodesIter->next();
852 #ifdef _EDF_NODE_IDS_
853 aVector[iNode] = aNodeIdMap[aNode->GetID()];
855 aVector[iNode] = aNode->GetID();
858 // There is some difference between SMDS and MED in cells mapping
861 (*aConnectivity)[aSize+0] = aVector[0];
862 (*aConnectivity)[aSize+1] = aVector[3];
863 (*aConnectivity)[aSize+2] = aVector[2];
864 (*aConnectivity)[aSize+3] = aVector[1];
865 (*aConnectivity)[aSize+4] = aVector[4];
867 for(TInt iNode = 0; iNode < aNbNodes; iNode++)
868 (*aConnectivity)[aSize+iNode] = aVector[iNode];
872 anElemNums->push_back(anElem->GetID());
874 if (anElemFamMap.find(anElem) != anElemFamMap.end())
875 aFamilyNums->push_back(anElemFamMap[anElem]);
877 aFamilyNums->push_back(myVolumesDefaultFamilyId);
880 if(TInt aNbElems = anTetraElemNums.size()){
881 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
885 SMDS_MED_CONNECTIVITY,
888 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eTETRA4<<"; aNbElems = "<<aNbElems);
889 myMed->SetCellInfo(aCellInfo);
891 if(TInt aNbElems = anPyraElemNums.size()){
892 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
896 SMDS_MED_CONNECTIVITY,
899 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePYRA5<<"; aNbElems = "<<aNbElems);
900 myMed->SetCellInfo(aCellInfo);
902 if(TInt aNbElems = anPentaElemNums.size()){
903 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
907 SMDS_MED_CONNECTIVITY,
910 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePENTA6<<"; aNbElems = "<<aNbElems);
911 myMed->SetCellInfo(aCellInfo);
913 if(TInt aNbElems = aHexaElemNums.size()){
914 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
918 SMDS_MED_CONNECTIVITY,
921 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eHEXA8<<"; aNbElems = "<<aNbElems);
922 myMed->SetCellInfo(aCellInfo);
924 if(TInt aNbElems = anTetra10ElemNums.size()){
925 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
929 SMDS_MED_CONNECTIVITY,
932 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eTETRA10<<"; aNbElems = "<<aNbElems);
933 myMed->SetCellInfo(aCellInfo);
935 if(TInt aNbElems = anPyra13ElemNums.size()){
936 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
940 SMDS_MED_CONNECTIVITY,
943 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePYRA13<<"; aNbElems = "<<aNbElems);
944 myMed->SetCellInfo(aCellInfo);
946 if(TInt aNbElems = anPenta15ElemNums.size()){
947 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
951 SMDS_MED_CONNECTIVITY,
954 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePENTA15<<"; aNbElems = "<<aNbElems);
955 myMed->SetCellInfo(aCellInfo);
957 if(TInt aNbElems = aHexa20ElemNums.size()){
958 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
962 SMDS_MED_CONNECTIVITY,
965 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eHEXA20<<"; aNbElems = "<<aNbElems);
966 myMed->SetCellInfo(aCellInfo);
969 if(TInt aNbElems = aPolyedreElemNums.size()){
970 // add one element in connectivities,
971 // referenced by the last element in faces
972 aPolyedreConn.push_back(0);
974 PPolyedreInfo aCellInfo = myMed->CrPolyedreInfo(aMeshInfo,
980 SMDS_MED_CONNECTIVITY,
983 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePOLYEDRE<<"; aNbElems = "<<aNbElems);
984 myMed->SetPolyedreInfo(aCellInfo);
988 catch(const std::exception& exc) {
989 INFOS("Follow exception was cought:\n\t"<<exc.what());
992 INFOS("Unknown exception was cought !!!");