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;
337 // delete (*aFamsIter);
340 // Storing SMDS nodes to the MED file for the MED mesh
341 //----------------------------------------------------
342 #ifdef _EDF_NODE_IDS_
343 typedef map<TInt,TInt> TNodeIdMap;
344 TNodeIdMap aNodeIdMap;
346 TInt aNbElems = myMesh->NbNodes();
347 MED::TIntVector anElemNums(aNbElems);
348 MED::TIntVector aFamilyNums(aNbElems);
349 MED::TFloatVector aCoordinates(aNbElems*aMeshDimension);
350 for(TInt iNode = 0, aStartId = 0; aCoordHelperPtr->Next(); iNode++, aStartId += aMeshDimension){
351 for(TInt iCoord = 0; iCoord < aMeshDimension; iCoord++){
352 aCoordinates[aStartId+iCoord] = aCoordHelperPtr->GetCoord(iCoord);
354 int aNodeID = aCoordHelperPtr->GetID();
355 anElemNums[iNode] = aNodeID;
356 #ifdef _EDF_NODE_IDS_
357 aNodeIdMap[aNodeID] = iNode+1;
359 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
360 if (anElemFamMap.find(aNode) != anElemFamMap.end())
361 aFamilyNums[iNode] = anElemFamMap[aNode];
363 aFamilyNums[iNode] = myNodesDefaultFamilyId;
366 MED::TStringVector aCoordNames(aMeshDimension);
367 MED::TStringVector aCoordUnits(aMeshDimension);
368 for(TInt iCoord = 0; iCoord < aMeshDimension; iCoord++){
369 aCoordNames[iCoord] = aCoordHelperPtr->GetName(iCoord);
370 aCoordUnits[iCoord] = aCoordHelperPtr->GetUnit(iCoord);
373 const ERepere SMDS_COORDINATE_SYSTEM = eCART;
375 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo,
376 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 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
398 // TInt aNbConnectivity = MED::GetNbNodes(eSEG2);
399 // MED::TIntVector anElemNums(aNbElems);
400 // MED::TIntVector aFamilyNums(aNbElems);
401 // MED::TIntVector aConnectivity(aNbElems*aNbConnectivity);
403 TInt aNbSeg2Conn = MED::GetNbNodes(eSEG2);
404 MED::TIntVector aSeg2ElemNums(aNbElems);
405 MED::TIntVector aSeg2FamilyNums(aNbElems);
406 MED::TIntVector aSeg2Conn(aNbElems*aNbSeg2Conn);
408 TInt aNbSeg3Conn = MED::GetNbNodes(eSEG3);
409 MED::TIntVector aSeg3ElemNums(aNbElems);
410 MED::TIntVector aSeg3FamilyNums(aNbElems);
411 MED::TIntVector aSeg3Conn(aNbElems*aNbSeg3Conn);
413 //for(TInt iElem = 0, Conn = 0; anIter->more(); iElem++, iConn+=aNbConnectivity){
414 for(TInt iElem = 0; anIter->more(); iElem++) {
415 const SMDS_MeshEdge* anElem = anIter->next();
416 TInt aNbNodes = anElem->NbNodes();
417 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
419 TInt aNbConnectivity;
420 MED::TIntVector* anElemNums;
421 MED::TIntVector* aFamilyNums;
422 MED::TIntVector* aConnectivity;
425 aNbConnectivity = aNbSeg2Conn;
426 anElemNums = &aSeg2ElemNums;
427 aFamilyNums = &aSeg2FamilyNums;
428 aConnectivity = &aSeg2Conn;
431 aNbConnectivity = aNbSeg3Conn;
432 anElemNums = &aSeg3ElemNums;
433 aFamilyNums = &aSeg3FamilyNums;
434 aConnectivity = &aSeg3Conn;
440 MED::TIntVector aVector(aNbNodes);
441 for(TInt iNode = 0; aNodesIter->more(); iNode++){
442 const SMDS_MeshElement* aNode = aNodesIter->next();
443 #ifdef _EDF_NODE_IDS_
444 aVector[iNode] = aNodeIdMap[aNode->GetID()];
446 aVector[iNode] = aNode->GetID();
450 TInt aSize = aConnectivity->size();
451 aConnectivity->resize(aSize+aNbConnectivity);
452 // There is some differences between SMDS and MED in cells mapping
453 for(TInt iNode = 0; iNode < aNbNodes; iNode++)
454 (*aConnectivity)[aSize+iNode] = aVector[iNode];
456 anElemNums->push_back(anElem->GetID());
458 if (anElemFamMap.find(anElem) != anElemFamMap.end())
459 aFamilyNums->push_back(anElemFamMap[anElem]);
461 aFamilyNums->push_back(myFacesDefaultFamilyId);
465 if(TInt aNbElems = aSeg2ElemNums.size()){
466 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
469 SMDS_MED_CONNECTIVITY,
473 myMed->SetCellInfo(aCellInfo);
475 if(TInt aNbElems = aSeg3ElemNums.size()){
476 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
479 SMDS_MED_CONNECTIVITY,
483 myMed->SetCellInfo(aCellInfo);
487 // Storing SMDS Faces
488 if(TInt aNbElems = myMesh->NbFaces()){
489 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
490 #ifdef _ELEMENTS_BY_DIM_
491 SMDS_MED_ENTITY = eFACE;
493 TInt aNbTriaConn = MED::GetNbNodes(eTRIA3);
494 MED::TIntVector anTriaElemNums;
495 anTriaElemNums.reserve(aNbElems);
496 MED::TIntVector aTriaFamilyNums;
497 aTriaFamilyNums.reserve(aNbElems);
498 MED::TIntVector aTriaConn;
499 aTriaConn.reserve(aNbElems*aNbTriaConn);
501 TInt aNbTria6Conn = MED::GetNbNodes(eTRIA6);
502 MED::TIntVector anTria6ElemNums;
503 anTria6ElemNums.reserve(aNbElems);
504 MED::TIntVector aTria6FamilyNums;
505 aTria6FamilyNums.reserve(aNbElems);
506 MED::TIntVector aTria6Conn;
507 aTria6Conn.reserve(aNbElems*aNbTria6Conn);
509 TInt aNbQuadConn = MED::GetNbNodes(eQUAD4);
510 MED::TIntVector aQuadElemNums;
511 aQuadElemNums.reserve(aNbElems);
512 MED::TIntVector aQuadFamilyNums;
513 aQuadFamilyNums.reserve(aNbElems);
514 MED::TIntVector aQuadConn;
515 aQuadConn.reserve(aNbElems*aNbQuadConn);
517 TInt aNbQuad8Conn = MED::GetNbNodes(eQUAD8);
518 MED::TIntVector aQuad8ElemNums;
519 aQuad8ElemNums.reserve(aNbElems);
520 MED::TIntVector aQuad8FamilyNums;
521 aQuad8FamilyNums.reserve(aNbElems);
522 MED::TIntVector aQuad8Conn;
523 aQuad8Conn.reserve(aNbElems*aNbQuad8Conn);
525 MED::TIntVector aPolygoneElemNums;
526 aPolygoneElemNums.reserve(aNbElems);
527 MED::TIntVector aPolygoneInds;
528 aPolygoneInds.reserve(aNbElems + 1);
529 aPolygoneInds.push_back(1); // reference on the first element in the connectivities
530 MED::TIntVector aPolygoneFamilyNums;
531 aPolygoneFamilyNums.reserve(aNbElems);
532 MED::TIntVector aPolygoneConn;
533 aPolygoneConn.reserve(aNbElems*aNbQuadConn);
535 for(TInt iElem = 0; iElem < aNbElems && anIter->more(); iElem++){
536 const SMDS_MeshFace* anElem = anIter->next();
537 TInt aNbNodes = anElem->NbNodes();
538 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
539 TInt aNbConnectivity;
540 MED::TIntVector* anElemNums;
541 MED::TIntVector* aFamilyNums;
542 MED::TIntVector* aConnectivity;
543 if (anElem->IsPoly()) {
544 aNbConnectivity = aNbNodes;
545 anElemNums = &aPolygoneElemNums;
546 aFamilyNums = &aPolygoneFamilyNums;
547 aConnectivity = &aPolygoneConn;
552 aNbConnectivity = aNbTriaConn;
553 anElemNums = &anTriaElemNums;
554 aFamilyNums = &aTriaFamilyNums;
555 aConnectivity = &aTriaConn;
558 aNbConnectivity = aNbQuadConn;
559 anElemNums = &aQuadElemNums;
560 aFamilyNums = &aQuadFamilyNums;
561 aConnectivity = &aQuadConn;
564 aNbConnectivity = aNbTria6Conn;
565 anElemNums = &anTria6ElemNums;
566 aFamilyNums = &aTria6FamilyNums;
567 aConnectivity = &aTria6Conn;
570 aNbConnectivity = aNbQuad8Conn;
571 anElemNums = &aQuad8ElemNums;
572 aFamilyNums = &aQuad8FamilyNums;
573 aConnectivity = &aQuad8Conn;
579 MED::TIntVector aVector(aNbNodes);
580 for(TInt iNode = 0; aNodesIter->more(); iNode++){
581 const SMDS_MeshElement* aNode = aNodesIter->next();
582 #ifdef _EDF_NODE_IDS_
583 aVector[iNode] = aNodeIdMap[aNode->GetID()];
585 aVector[iNode] = aNode->GetID();
589 TInt aSize = aConnectivity->size();
590 aConnectivity->resize(aSize+aNbConnectivity);
591 // There is some differences between SMDS and MED in cells mapping
594 (*aConnectivity)[aSize+0] = aVector[0];
595 (*aConnectivity)[aSize+1] = aVector[1];
596 (*aConnectivity)[aSize+2] = aVector[3];
597 (*aConnectivity)[aSize+3] = aVector[2];
599 for(TInt iNode = 0; iNode < aNbNodes; iNode++)
600 (*aConnectivity)[aSize+iNode] = aVector[iNode];
603 if (anElem->IsPoly()) {
604 // fill indices for polygonal element
605 TInt aPrevPos = aPolygoneInds.back();
606 aPolygoneInds.push_back(aPrevPos + aNbNodes);
609 anElemNums->push_back(anElem->GetID());
611 if (anElemFamMap.find(anElem) != anElemFamMap.end())
612 aFamilyNums->push_back(anElemFamMap[anElem]);
614 aFamilyNums->push_back(myFacesDefaultFamilyId);
616 if(TInt aNbElems = anTriaElemNums.size()){
617 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
620 SMDS_MED_CONNECTIVITY,
624 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eTRIA3<<"; aNbElems = "<<aNbElems);
625 myMed->SetCellInfo(aCellInfo);
627 if(TInt aNbElems = aQuadElemNums.size()){
628 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
631 SMDS_MED_CONNECTIVITY,
635 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eQUAD4<<"; aNbElems = "<<aNbElems);
636 myMed->SetCellInfo(aCellInfo);
638 if(TInt aNbElems = anTria6ElemNums.size()){
639 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
642 SMDS_MED_CONNECTIVITY,
646 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eTRIA6<<"; aNbElems = "<<aNbElems);
647 myMed->SetCellInfo(aCellInfo);
649 if(TInt aNbElems = aQuad8ElemNums.size()){
650 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
653 SMDS_MED_CONNECTIVITY,
657 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eQUAD8<<"; aNbElems = "<<aNbElems);
658 myMed->SetCellInfo(aCellInfo);
660 if(TInt aNbElems = aPolygoneElemNums.size()){
661 // add one element in connectivities,
662 // referenced by the last element in indices
663 aPolygoneConn.push_back(0);
665 PPolygoneInfo aCellInfo = myMed->CrPolygoneInfo(aMeshInfo,
668 SMDS_MED_CONNECTIVITY,
673 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePOLYGONE<<"; aNbElems = "<<aNbElems);
674 myMed->SetPolygoneInfo(aCellInfo);
678 // Storing SMDS Volumes
679 if(TInt aNbElems = myMesh->NbVolumes()){
680 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
681 #ifdef _ELEMENTS_BY_DIM_
682 SMDS_MED_ENTITY = eMAILLE;
684 TInt aNbTetraConn = MED::GetNbNodes(eTETRA4);
685 MED::TIntVector anTetraElemNums;
686 anTetraElemNums.reserve(aNbElems);
687 MED::TIntVector aTetraFamilyNums;
688 aTetraFamilyNums.reserve(aNbElems);
689 MED::TIntVector aTetraConn;
690 aTetraConn.reserve(aNbElems*aNbTetraConn);
692 TInt aNbPyraConn = MED::GetNbNodes(ePYRA5);
693 MED::TIntVector anPyraElemNums;
694 anPyraElemNums.reserve(aNbElems);
695 MED::TIntVector aPyraFamilyNums;
696 aPyraFamilyNums.reserve(aNbElems);
697 MED::TIntVector aPyraConn;
698 aPyraConn.reserve(aNbElems*aNbPyraConn);
700 TInt aNbPentaConn = MED::GetNbNodes(ePENTA6);
701 MED::TIntVector anPentaElemNums;
702 anPentaElemNums.reserve(aNbElems);
703 MED::TIntVector aPentaFamilyNums;
704 aPentaFamilyNums.reserve(aNbElems);
705 MED::TIntVector aPentaConn;
706 aPentaConn.reserve(aNbElems*aNbPentaConn);
708 TInt aNbHexaConn = MED::GetNbNodes(eHEXA8);
709 MED::TIntVector aHexaElemNums;
710 aHexaElemNums.reserve(aNbElems);
711 MED::TIntVector aHexaFamilyNums;
712 aHexaFamilyNums.reserve(aNbElems);
713 MED::TIntVector aHexaConn;
714 aHexaConn.reserve(aNbElems*aNbHexaConn);
716 TInt aNbTetra10Conn = MED::GetNbNodes(eTETRA10);
717 MED::TIntVector anTetra10ElemNums;
718 anTetra10ElemNums.reserve(aNbElems);
719 MED::TIntVector aTetra10FamilyNums;
720 aTetra10FamilyNums.reserve(aNbElems);
721 MED::TIntVector aTetra10Conn;
722 aTetra10Conn.reserve(aNbElems*aNbTetra10Conn);
724 TInt aNbPyra13Conn = MED::GetNbNodes(ePYRA13);
725 MED::TIntVector anPyra13ElemNums;
726 anPyra13ElemNums.reserve(aNbElems);
727 MED::TIntVector aPyra13FamilyNums;
728 aPyra13FamilyNums.reserve(aNbElems);
729 MED::TIntVector aPyra13Conn;
730 aPyra13Conn.reserve(aNbElems*aNbPyra13Conn);
732 TInt aNbPenta15Conn = MED::GetNbNodes(ePENTA15);
733 MED::TIntVector anPenta15ElemNums;
734 anPenta15ElemNums.reserve(aNbElems);
735 MED::TIntVector aPenta15FamilyNums;
736 aPenta15FamilyNums.reserve(aNbElems);
737 MED::TIntVector aPenta15Conn;
738 aPenta15Conn.reserve(aNbElems*aNbPenta15Conn);
740 TInt aNbHexa20Conn = MED::GetNbNodes(eHEXA20);
741 MED::TIntVector aHexa20ElemNums;
742 aHexa20ElemNums.reserve(aNbElems);
743 MED::TIntVector aHexa20FamilyNums;
744 aHexa20FamilyNums.reserve(aNbElems);
745 MED::TIntVector aHexa20Conn;
746 aHexa20Conn.reserve(aNbElems*aNbHexa20Conn);
748 MED::TIntVector aPolyedreElemNums;
749 aPolyedreElemNums.reserve(aNbElems);
750 MED::TIntVector aPolyedreInds;
751 aPolyedreInds.reserve(aNbElems + 1);
752 aPolyedreInds.push_back(1); // reference on the first element in the faces
753 MED::TIntVector aPolyedreFaces;
754 aPolyedreFaces.reserve(aNbElems + 1);
755 aPolyedreFaces.push_back(1); // reference on the first element in the connectivities
756 MED::TIntVector aPolyedreFamilyNums;
757 aPolyedreFamilyNums.reserve(aNbElems);
758 MED::TIntVector aPolyedreConn;
759 aPolyedreConn.reserve(aNbElems*aNbHexaConn);
761 for(TInt iElem = 0; iElem < aNbElems && anIter->more(); iElem++){
762 const SMDS_MeshVolume* anElem = anIter->next();
764 MED::TIntVector* anElemNums;
765 MED::TIntVector* aFamilyNums;
767 if (anElem->IsPoly()) {
768 const SMDS_PolyhedralVolumeOfNodes* aPolyedre =
769 (const SMDS_PolyhedralVolumeOfNodes*) anElem;
771 MESSAGE("Warning: bad volumic element");
775 anElemNums = &aPolyedreElemNums;
776 aFamilyNums = &aPolyedreFamilyNums;
778 TInt aNodeId, aNbFaces = aPolyedre->NbFaces();
779 for (int iface = 1; iface <= aNbFaces; iface++) {
780 int aNbFaceNodes = aPolyedre->NbFaceNodes(iface);
781 for (int inode = 1; inode <= aNbFaceNodes; inode++) {
782 aNodeId = aPolyedre->GetFaceNode(iface, inode)->GetID();
783 #ifdef _EDF_NODE_IDS_
784 aPolyedreConn.push_back(aNodeIdMap[aNodeId]);
786 aPolyedreConn.push_back(aNodeId);
789 TInt aPrevPos = aPolyedreFaces.back();
790 aPolyedreFaces.push_back(aPrevPos + aNbFaceNodes);
792 TInt aPrevPos = aPolyedreInds.back();
793 aPolyedreInds.push_back(aPrevPos + aNbFaces);
797 TInt aNbNodes = anElem->NbNodes();
798 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
799 TInt aNbConnectivity;
800 MED::TIntVector* aConnectivity;
803 aNbConnectivity = aNbTetraConn;
804 anElemNums = &anTetraElemNums;
805 aFamilyNums = &aTetraFamilyNums;
806 aConnectivity = &aTetraConn;
809 aNbConnectivity = aNbPyraConn;
810 anElemNums = &anPyraElemNums;
811 aFamilyNums = &aPyraFamilyNums;
812 aConnectivity = &aPyraConn;
815 aNbConnectivity = aNbPentaConn;
816 anElemNums = &anPentaElemNums;
817 aFamilyNums = &aPentaFamilyNums;
818 aConnectivity = &aPentaConn;
821 aNbConnectivity = aNbHexaConn;
822 anElemNums = &aHexaElemNums;
823 aFamilyNums = &aHexaFamilyNums;
824 aConnectivity = &aHexaConn;
826 aNbConnectivity = aNbTetra10Conn;
827 anElemNums = &anTetra10ElemNums;
828 aFamilyNums = &aTetra10FamilyNums;
829 aConnectivity = &aTetra10Conn;
832 aNbConnectivity = aNbPyra13Conn;
833 anElemNums = &anPyra13ElemNums;
834 aFamilyNums = &aPyra13FamilyNums;
835 aConnectivity = &aPyra13Conn;
838 aNbConnectivity = aNbPenta15Conn;
839 anElemNums = &anPenta15ElemNums;
840 aFamilyNums = &aPenta15FamilyNums;
841 aConnectivity = &aPenta15Conn;
844 aNbConnectivity = aNbHexa20Conn;
845 anElemNums = &aHexa20ElemNums;
846 aFamilyNums = &aHexa20FamilyNums;
847 aConnectivity = &aHexa20Conn;
850 TInt aSize = aConnectivity->size();
851 aConnectivity->resize(aSize + aNbConnectivity);
853 MED::TIntVector aVector(aNbNodes);
854 for(TInt iNode = 0; aNodesIter->more(); iNode++){
855 const SMDS_MeshElement* aNode = aNodesIter->next();
856 #ifdef _EDF_NODE_IDS_
857 aVector[iNode] = aNodeIdMap[aNode->GetID()];
859 aVector[iNode] = aNode->GetID();
862 // There is some difference between SMDS and MED in cells mapping
865 (*aConnectivity)[aSize+0] = aVector[0];
866 (*aConnectivity)[aSize+1] = aVector[3];
867 (*aConnectivity)[aSize+2] = aVector[2];
868 (*aConnectivity)[aSize+3] = aVector[1];
869 (*aConnectivity)[aSize+4] = aVector[4];
871 for(TInt iNode = 0; iNode < aNbNodes; iNode++)
872 (*aConnectivity)[aSize+iNode] = aVector[iNode];
876 anElemNums->push_back(anElem->GetID());
878 if (anElemFamMap.find(anElem) != anElemFamMap.end())
879 aFamilyNums->push_back(anElemFamMap[anElem]);
881 aFamilyNums->push_back(myVolumesDefaultFamilyId);
884 if(TInt aNbElems = anTetraElemNums.size()){
885 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
888 SMDS_MED_CONNECTIVITY,
892 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eTETRA4<<"; aNbElems = "<<aNbElems);
893 myMed->SetCellInfo(aCellInfo);
895 if(TInt aNbElems = anPyraElemNums.size()){
896 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
899 SMDS_MED_CONNECTIVITY,
903 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePYRA5<<"; aNbElems = "<<aNbElems);
904 myMed->SetCellInfo(aCellInfo);
906 if(TInt aNbElems = anPentaElemNums.size()){
907 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
910 SMDS_MED_CONNECTIVITY,
914 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePENTA6<<"; aNbElems = "<<aNbElems);
915 myMed->SetCellInfo(aCellInfo);
917 if(TInt aNbElems = aHexaElemNums.size()){
918 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
921 SMDS_MED_CONNECTIVITY,
925 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eHEXA8<<"; aNbElems = "<<aNbElems);
926 myMed->SetCellInfo(aCellInfo);
928 if(TInt aNbElems = anTetra10ElemNums.size()){
929 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
932 SMDS_MED_CONNECTIVITY,
936 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eTETRA10<<"; aNbElems = "<<aNbElems);
937 myMed->SetCellInfo(aCellInfo);
939 if(TInt aNbElems = anPyra13ElemNums.size()){
940 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
943 SMDS_MED_CONNECTIVITY,
947 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePYRA13<<"; aNbElems = "<<aNbElems);
948 myMed->SetCellInfo(aCellInfo);
950 if(TInt aNbElems = anPenta15ElemNums.size()){
951 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
954 SMDS_MED_CONNECTIVITY,
958 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePENTA15<<"; aNbElems = "<<aNbElems);
959 myMed->SetCellInfo(aCellInfo);
961 if(TInt aNbElems = aHexa20ElemNums.size()){
962 PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo,
965 SMDS_MED_CONNECTIVITY,
969 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<eHEXA20<<"; aNbElems = "<<aNbElems);
970 myMed->SetCellInfo(aCellInfo);
973 if(TInt aNbElems = aPolyedreElemNums.size()){
974 // add one element in connectivities,
975 // referenced by the last element in faces
976 aPolyedreConn.push_back(0);
978 PPolyedreInfo aCellInfo = myMed->CrPolyedreInfo(aMeshInfo,
981 SMDS_MED_CONNECTIVITY,
987 MESSAGE("Perform - anEntity = "<<SMDS_MED_ENTITY<<"; aGeom = "<<ePOLYEDRE<<"; aNbElems = "<<aNbElems);
988 myMed->SetPolyedreInfo(aCellInfo);
992 catch(const std::exception& exc) {
993 INFOS("Follow exception was cought:\n\t"<<exc.what());
996 INFOS("Unknown exception was cought !!!");
1001 mySubMeshes.clear();