1 // Copyright (C) 2007-2014 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
22 // File : MED_Structure.cxx
23 // Author : Eugeny NIKOLAEV
25 #include "MED_Structures.hxx"
26 #include "MED_Utilities.hxx"
35 GetNbNodes(EGeometrieElement typmai)
43 const TString& theString)
45 const char* aPos = &theString[theId*theStep];
46 TInt aSize = std::min(TInt(strlen(aPos)),theStep);
47 return std::string(aPos,aSize);
54 const std::string& theValue)
56 TInt aSize = std::min(TInt(theValue.size()+1),theStep);
57 char* aPos = &theString[theId*theStep];
58 strncpy(aPos,theValue.c_str(),aSize);
65 const TString& theValue)
67 TInt aSize = std::min(TInt(theValue.size()+1),theStep);
68 char* aPos = &theString[theId*theStep];
69 const char* aValue = &theValue[0];
70 strncpy(aPos,aValue,aSize);
74 GetDimGaussCoord(EGeometrieElement theGeom)
80 GetNbRefCoord(EGeometrieElement theGeom)
85 //---------------------------------------------------------------
87 CastToFloatTimeStampValue(const PTimeStampValueBase& theTimeStampValue)
89 return theTimeStampValue;
93 CastToIntTimeStampValue(const PTimeStampValueBase& theTimeStampValue)
95 return theTimeStampValue;
99 //---------------------------------------------------------------
102 ::GetAttrId(TInt theId) const
104 return myAttrId[theId];
109 ::GetAttrVal(TInt theId) const
111 return myAttrVal[theId];
116 ::SetAttrId(TInt theId,TInt theVal)
118 myAttrId[theId] = theVal;
123 ::SetAttrVal(TInt theId,TInt theVal)
125 myAttrVal[theId] = theVal;
128 //---------------------------------------------------------------
131 ::GetFamNum(TInt theId) const
133 return (*myFamNum)[theId];
138 ::SetFamNum(TInt theId, TInt theVal)
140 (*myFamNum)[theId] = theVal;
146 ::GetElemNum(TInt theId) const
148 return (*myElemNum)[theId];
153 ::SetElemNum(TInt theId, TInt theVal)
155 (*myElemNum)[theId] = theVal;
158 //---------------------------------------------------------------
161 ::GetCoordSlice(TInt theId) const
163 TInt aDim = myMeshInfo->GetSpaceDim();
164 if(GetModeSwitch() == eFULL_INTERLACE)
165 return TCCoordSlice(*myCoord, std::slice(theId*aDim, aDim, 1));
167 return TCCoordSlice(*myCoord, std::slice(theId, aDim, aDim));
172 ::GetCoordSlice(TInt theId)
174 TInt aDim = myMeshInfo->GetSpaceDim();
175 if(GetModeSwitch() == eFULL_INTERLACE)
176 return TCoordSlice(*myCoord, std::slice(theId*aDim,aDim,1));
178 return TCoordSlice(*myCoord, std::slice(theId,aDim,aDim));
181 //---------------------------------------------------------------
184 ::GetConnSlice(TInt theElemId) const
186 if(GetModeSwitch() == eFULL_INTERLACE)
187 return TCConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1));
189 return TCConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim()));
194 ::GetConnSlice(TInt theElemId)
196 if(GetModeSwitch() == eFULL_INTERLACE)
197 return TConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1));
199 return TConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim()));
203 //---------------------------------------------------------------
206 ::GetNbConn(TInt theElemId) const
208 return (*myIndex)[theElemId + 1] - (*myIndex)[theElemId];
213 ::GetConnSlice(TInt theElemId) const
215 return TCConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1));
220 ::GetConnSlice(TInt theElemId)
222 return TConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1));
226 //---------------------------------------------------------------
229 ::GetNbFaces(TInt theElemId) const
231 return (*myIndex)[theElemId+1] - (*myIndex)[theElemId];
236 ::GetNbNodes(TInt theElemId) const
239 TInt aNbFaces = GetNbFaces(theElemId);
240 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
241 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
242 TInt aCurrentId = (*myFaces)[aStartFaceId];
243 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
251 ::GetConnSliceArr(TInt theElemId) const
253 TInt aNbFaces = GetNbFaces(theElemId);
254 TCConnSliceArr aConnSliceArr(aNbFaces);
255 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
256 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
257 TInt aCurrentId = (*myFaces)[aStartFaceId];
258 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
259 aConnSliceArr[aFaceId] =
260 TCConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1));
262 return aConnSliceArr;
267 ::GetConnSliceArr(TInt theElemId)
269 TInt aNbFaces = GetNbFaces(theElemId);
270 TConnSliceArr aConnSliceArr(aNbFaces);
271 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
272 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
273 TInt aCurrentId = (*myFaces)[aStartFaceId];
274 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
275 aConnSliceArr[aFaceId] =
276 TConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1));
278 return aConnSliceArr;
282 //---------------------------------------------------------------
293 ::Allocate(TInt theNbElem,
298 myModeSwitch = theMode;
300 myNbElem = theNbElem;
301 myNbGauss = theNbGauss;
302 myNbComp = theNbComp;
304 myStep = theNbComp*theNbGauss;
311 return myNbElem * myStep;
318 return myNbElem * myNbGauss;
336 //---------------------------------------------------------------
339 ::GetElemNum(TInt theId) const
341 return (*myElemNum)[theId];
346 ::SetElemNum(TInt theId,TInt theVal)
348 (*myElemNum)[theId] = theVal;
351 //---------------------------------------------------------------
354 ::operator()(const TKey& theLeft, const TKey& theRight) const
356 EGeometrieElement aLGeom = boost::get<0>(theLeft);
357 EGeometrieElement aRGeom = boost::get<0>(theRight);
359 return aLGeom < aRGeom;
361 const std::string& aLStr = boost::get<1>(theLeft);
362 const std::string& aRStr = boost::get<1>(theRight);
363 return aLStr < aRStr;
368 ::operator()(const TGaussInfo& theLeft, const TGaussInfo& theRight) const
376 if(theLeft.myGeom != theRight.myGeom)
377 return theLeft.myGeom < theRight.myGeom;
379 if(theLeft.myRefCoord != theRight.myRefCoord)
380 return theLeft.myRefCoord < theRight.myRefCoord;
382 return theLeft.myGaussCoord < theRight.myGaussCoord;
387 ::GetRefCoordSlice(TInt theId) const
389 if(GetModeSwitch() == eFULL_INTERLACE)
390 return TCCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
392 return TCCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
397 ::GetRefCoordSlice(TInt theId)
399 if(GetModeSwitch() == eFULL_INTERLACE)
400 return TCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
402 return TCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
407 ::GetGaussCoordSlice(TInt theId) const
409 if(GetModeSwitch() == eFULL_INTERLACE)
410 return TCCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetDim(),1));
412 return TCCoordSlice(myGaussCoord,std::slice(theId,GetDim(),GetDim()));
417 ::GetGaussCoordSlice(TInt theId)
419 if(GetModeSwitch() == eFULL_INTERLACE)
420 return TCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetNbGauss(),1));
422 return TCoordSlice(myGaussCoord,std::slice(theId,GetNbGauss(),GetDim()));
426 //---------------------------------------------------------------
429 ::GetNbGauss(EGeometrieElement theGeom) const
431 TGeom2NbGauss::const_iterator anIter = myGeom2NbGauss.find(theGeom);
432 if(anIter == myGeom2NbGauss.end())
433 return 1;//EXCEPTION(runtime_error,"TTimeStampInfo::GetNbGauss - myGeom2NbGauss.find(theGeom) fails");
435 return anIter->second;
439 //---------------------------------------------------------------
440 // TGrilleInfo structure methods
441 //---------------------------------------------------------------
444 ::GetGrilleType() const
458 ::SetGrilleType(EGrilleType theGrilleType)
460 myGrilleType = theGrilleType;
466 ::GetMapOfIndexes() const
481 ::GetIndexes(TInt theAxisNumber) const
483 TIndexes::const_iterator aIter=myIndixes.find(theAxisNumber);
484 if(aIter==myIndixes.end())
485 EXCEPTION(std::runtime_error, "const TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber); fails");
486 return aIter->second;
491 ::GetIndexes(TInt theAxisNumber)
493 TIndexes::iterator aIter=myIndixes.find(theAxisNumber);
494 if(aIter==myIndixes.end())
495 EXCEPTION(std::runtime_error, "TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber="<<theAxisNumber<<"); fails");
496 return aIter->second;
501 ::GetNbIndexes(TInt theAxisNumber)
503 const TFloatVector& aVector=GetIndexes(theAxisNumber);
504 return aVector.size();
512 TInt aDim = myMeshInfo->GetDim();
513 for(int i=0;i<aDim;i++)
515 nbNodes = this->GetGrilleStructure()[i];
517 nbNodes = nbNodes*this->GetGrilleStructure()[i];
527 TInt aDim = myMeshInfo->GetDim();
528 for(int i=0;i<aDim;i++)
530 nbCells = this->GetGrilleStructure()[i]-1;
532 nbCells = nbCells*(this->GetGrilleStructure()[i]-1);
541 TInt aDim = myMeshInfo->GetDim();
545 (myGrilleStructure[0] ) * (myGrilleStructure[1]-1) * (myGrilleStructure[2]-1) +
546 (myGrilleStructure[0]-1) * (myGrilleStructure[1] ) * (myGrilleStructure[2]-1) +
547 (myGrilleStructure[0]-1) * (myGrilleStructure[1]-1) * (myGrilleStructure[2] );
551 (myGrilleStructure[0] ) * (myGrilleStructure[1]-1) +
552 (myGrilleStructure[0]-1) * (myGrilleStructure[1] );
562 TInt aDim = myMeshInfo->GetDim();
579 TInt aDim = myMeshInfo->GetDim();
600 TInt aDim = myMeshInfo->GetDim();
607 return EEntiteMaillage(-1);
613 ::GetGrilleStructure() const
615 return myGrilleStructure;
620 ::GetGrilleStructure()
622 return myGrilleStructure;
627 ::SetGrilleStructure(TInt theAxis,TInt theNb)
629 if(theAxis >= 0 && theAxis <=2 && theNb >= 0)
630 myGrilleStructure[theAxis]=theNb;
636 ::GetNodeCoord() const
650 ::GetCoord(TInt theId)
653 TInt aDim = myMeshInfo->GetDim();
654 TInt aNbNodes = this->GetNbNodes();
657 if(theId >= aNbNodes)
658 EXCEPTION(std::runtime_error, "TGrilleInfo::GetCoord - theId out of range");
660 if(myGrilleType == eGRILLE_STANDARD){
663 aCoord[2] = myCoord[aDim*theId+2];
665 aCoord[1] = myCoord[aDim*theId+1];
667 aCoord[0] = myCoord[aDim*theId];
673 TFloatVector aVecX = this->GetIndexes(0);
674 TInt nbIndxX = this->GetNbIndexes(0);
678 aCoord[0] = aVecX[theId];
682 TFloatVector aVecY = this->GetIndexes(1);
687 if(myGrilleType == eGRILLE_CARTESIENNE){
688 aCoord[0] = aVecX[i];
689 aCoord[1] = aVecY[j];
690 } else { // eGRILLE_POLAIRE (cylindrical)
691 aCoord[0] = aVecX[i] * cos(aVecY[j]);
692 aCoord[1] = aVecX[i] * sin(aVecY[j]);
697 TFloatVector aVecY = this->GetIndexes(1);
698 TInt nbIndxY = this->GetNbIndexes(1);
699 TFloatVector aVecZ = this->GetIndexes(2);
704 j = (theId / nbIndxX) % nbIndxY;
705 k = theId / (nbIndxX*nbIndxY);
707 if(myGrilleType == eGRILLE_CARTESIENNE){
708 aCoord[0] = aVecX[i];
709 aCoord[1] = aVecY[j];
710 aCoord[2] = aVecZ[k];
711 } else { // eGRILLE_POLAIRE (cylindrical)
712 aCoord[0] = aVecX[i] * cos(aVecY[j]);
713 aCoord[1] = aVecX[i] * sin(aVecY[j]);
714 aCoord[2] = aVecZ[k];
727 ::GetConn(TInt theId, const bool isSub)
729 TIntVector anIndexes;
730 TInt aDim = myMeshInfo->GetDim();
733 TInt iMin, jMin, kMin, iMax, jMax, kMax;
736 loc[0] = loc[1] = loc[2] = 0;
737 iMin = iMax = jMin = jMax = kMin = kMax = 0;
742 TInt nbX = this->GetGrilleStructure()[0];
743 TInt nbY = this->GetGrilleStructure()[1];
744 TInt nbZ = this->GetGrilleStructure()[2];
745 TInt d01 = nbX*nbY, dX = 1, dY = 1, dZ = 1;
748 if ( theId < nbX * (nbY-1) * (nbZ-1))
749 { // face is normal to X axis
752 else if ( theId < nbX * (nbY-1) * (nbZ-1) + (nbX-1) * nbY * (nbZ-1))
753 { // face is normal to Y axis
754 theId -= nbX * (nbY-1) * (nbZ-1);
759 theId -= nbX * (nbY-1) * (nbZ-1) + (nbX-1) * nbY * (nbZ-1);
765 iMin = theId % (nbX - dX);
766 jMin = (theId / (nbX - dX)) % (nbY - dY);
767 kMin = theId / ((nbX - dX) * (nbY - dY));
772 for (loc[2]=kMin; loc[2]<=kMax; loc[2]++)
773 for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
774 for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
776 idx = loc[0] + loc[1]*nbX + loc[2]*d01;
777 anIndexes.push_back(idx);
783 TInt nbX = this->GetGrilleStructure()[0];
784 TInt nbY = this->GetGrilleStructure()[1];
788 if ( theId < nbX * (nbY-1))
789 { // edge is normal to X axis
794 theId -= nbX * (nbY-1);
798 iMin = theId % (nbX-dX);
799 jMin = theId / (nbX-dX);
802 for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
803 for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
805 idx = loc[0] + loc[1]*nbX;
806 anIndexes.push_back(idx);
813 for (loc[0]=iMin; loc[0]<=iMin+1; loc[0]++)
816 anIndexes.push_back(idx);
827 ::GetFamNumNode(TInt theId) const
829 return myFamNumNode[theId];
834 ::SetFamNumNode(TInt theId,TInt theVal)
836 myFamNumNode[theId] = theVal;
841 ::GetFamNum(TInt theId) const
843 return myFamNum[theId];
848 ::SetFamNum(TInt theId,TInt theVal)
850 myFamNum[theId] = theVal;
855 ::GetFamSubNum(TInt theId) const
857 return myFamSubNum[theId];
862 ::SetFamSubNum(TInt theId,TInt theVal)
864 myFamSubNum[theId] = theVal;