1 // Copyright (C) 2007-2013 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.
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 // File : MED_Structure.cxx
24 // Author : Eugeny NIKOLAEV
27 #include "MED_Structures.hxx"
28 #include "MED_Utilities.hxx"
37 GetNbNodes(EGeometrieElement typmai)
45 const TString& theString)
47 const char* aPos = &theString[theId*theStep];
48 TInt aSize = std::min(TInt(strlen(aPos)),theStep);
49 return std::string(aPos,aSize);
56 const std::string& theValue)
58 TInt aSize = std::min(TInt(theValue.size()+1),theStep);
59 char* aPos = &theString[theId*theStep];
60 strncpy(aPos,theValue.c_str(),aSize);
67 const TString& theValue)
69 TInt aSize = std::min(TInt(theValue.size()+1),theStep);
70 char* aPos = &theString[theId*theStep];
71 const char* aValue = &theValue[0];
72 strncpy(aPos,aValue,aSize);
76 GetDimGaussCoord(EGeometrieElement theGeom)
82 GetNbRefCoord(EGeometrieElement theGeom)
87 //---------------------------------------------------------------
89 CastToFloatTimeStampValue(const PTimeStampValueBase& theTimeStampValue)
91 return theTimeStampValue;
95 CastToIntTimeStampValue(const PTimeStampValueBase& theTimeStampValue)
97 return theTimeStampValue;
101 //---------------------------------------------------------------
104 ::GetAttrId(TInt theId) const
106 return myAttrId[theId];
111 ::GetAttrVal(TInt theId) const
113 return myAttrVal[theId];
118 ::SetAttrId(TInt theId,TInt theVal)
120 myAttrId[theId] = theVal;
125 ::SetAttrVal(TInt theId,TInt theVal)
127 myAttrVal[theId] = theVal;
130 //---------------------------------------------------------------
133 ::GetFamNum(TInt theId) const
135 return (*myFamNum)[theId];
140 ::SetFamNum(TInt theId, TInt theVal)
142 (*myFamNum)[theId] = theVal;
148 ::GetElemNum(TInt theId) const
150 return (*myElemNum)[theId];
155 ::SetElemNum(TInt theId, TInt theVal)
157 (*myElemNum)[theId] = theVal;
160 //---------------------------------------------------------------
163 ::GetCoordSlice(TInt theId) const
165 TInt aDim = myMeshInfo->GetSpaceDim();
166 if(GetModeSwitch() == eFULL_INTERLACE)
167 return TCCoordSlice(*myCoord, std::slice(theId*aDim, aDim, 1));
169 return TCCoordSlice(*myCoord, std::slice(theId, aDim, aDim));
174 ::GetCoordSlice(TInt theId)
176 TInt aDim = myMeshInfo->GetSpaceDim();
177 if(GetModeSwitch() == eFULL_INTERLACE)
178 return TCoordSlice(*myCoord, std::slice(theId*aDim,aDim,1));
180 return TCoordSlice(*myCoord, std::slice(theId,aDim,aDim));
183 //---------------------------------------------------------------
186 ::GetConnSlice(TInt theElemId) const
188 if(GetModeSwitch() == eFULL_INTERLACE)
189 return TCConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1));
191 return TCConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim()));
196 ::GetConnSlice(TInt theElemId)
198 if(GetModeSwitch() == eFULL_INTERLACE)
199 return TConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1));
201 return TConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim()));
205 //---------------------------------------------------------------
208 ::GetNbConn(TInt theElemId) const
210 return (*myIndex)[theElemId + 1] - (*myIndex)[theElemId];
215 ::GetConnSlice(TInt theElemId) const
217 return TCConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1));
222 ::GetConnSlice(TInt theElemId)
224 return TConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1));
228 //---------------------------------------------------------------
231 ::GetNbFaces(TInt theElemId) const
233 return (*myIndex)[theElemId+1] - (*myIndex)[theElemId];
238 ::GetNbNodes(TInt theElemId) const
241 TInt aNbFaces = GetNbFaces(theElemId);
242 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
243 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
244 TInt aCurrentId = (*myFaces)[aStartFaceId];
245 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
253 ::GetConnSliceArr(TInt theElemId) const
255 TInt aNbFaces = GetNbFaces(theElemId);
256 TCConnSliceArr aConnSliceArr(aNbFaces);
257 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
258 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
259 TInt aCurrentId = (*myFaces)[aStartFaceId];
260 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
261 aConnSliceArr[aFaceId] =
262 TCConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1));
264 return aConnSliceArr;
269 ::GetConnSliceArr(TInt theElemId)
271 TInt aNbFaces = GetNbFaces(theElemId);
272 TConnSliceArr aConnSliceArr(aNbFaces);
273 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
274 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
275 TInt aCurrentId = (*myFaces)[aStartFaceId];
276 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
277 aConnSliceArr[aFaceId] =
278 TConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1));
280 return aConnSliceArr;
284 //---------------------------------------------------------------
295 ::Allocate(TInt theNbElem,
300 myModeSwitch = theMode;
302 myNbElem = theNbElem;
303 myNbGauss = theNbGauss;
304 myNbComp = theNbComp;
306 myStep = theNbComp*theNbGauss;
313 return myNbElem * myStep;
320 return myNbElem * myNbGauss;
338 //---------------------------------------------------------------
341 ::GetElemNum(TInt theId) const
343 return (*myElemNum)[theId];
348 ::SetElemNum(TInt theId,TInt theVal)
350 (*myElemNum)[theId] = theVal;
353 //---------------------------------------------------------------
356 ::operator()(const TKey& theLeft, const TKey& theRight) const
358 EGeometrieElement aLGeom = boost::get<0>(theLeft);
359 EGeometrieElement aRGeom = boost::get<0>(theRight);
361 return aLGeom < aRGeom;
363 const std::string& aLStr = boost::get<1>(theLeft);
364 const std::string& aRStr = boost::get<1>(theRight);
365 return aLStr < aRStr;
370 ::operator()(const TGaussInfo& theLeft, const TGaussInfo& theRight) const
378 if(theLeft.myGeom != theRight.myGeom)
379 return theLeft.myGeom < theRight.myGeom;
381 if(theLeft.myRefCoord != theRight.myRefCoord)
382 return theLeft.myRefCoord < theRight.myRefCoord;
384 return theLeft.myGaussCoord < theRight.myGaussCoord;
389 ::GetRefCoordSlice(TInt theId) const
391 if(GetModeSwitch() == eFULL_INTERLACE)
392 return TCCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
394 return TCCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
399 ::GetRefCoordSlice(TInt theId)
401 if(GetModeSwitch() == eFULL_INTERLACE)
402 return TCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
404 return TCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
409 ::GetGaussCoordSlice(TInt theId) const
411 if(GetModeSwitch() == eFULL_INTERLACE)
412 return TCCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetDim(),1));
414 return TCCoordSlice(myGaussCoord,std::slice(theId,GetDim(),GetDim()));
419 ::GetGaussCoordSlice(TInt theId)
421 if(GetModeSwitch() == eFULL_INTERLACE)
422 return TCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetNbGauss(),1));
424 return TCoordSlice(myGaussCoord,std::slice(theId,GetNbGauss(),GetDim()));
428 //---------------------------------------------------------------
431 ::GetNbGauss(EGeometrieElement theGeom) const
433 TGeom2NbGauss::const_iterator anIter = myGeom2NbGauss.find(theGeom);
434 if(anIter == myGeom2NbGauss.end())
435 return 1;//EXCEPTION(runtime_error,"TTimeStampInfo::GetNbGauss - myGeom2NbGauss.find(theGeom) fails");
437 return anIter->second;
441 //---------------------------------------------------------------
442 // TGrilleInfo structure methods
443 //---------------------------------------------------------------
446 ::GetGrilleType() const
460 ::SetGrilleType(EGrilleType theGrilleType)
462 myGrilleType = theGrilleType;
468 ::GetMapOfIndexes() const
483 ::GetIndexes(TInt theAxisNumber) const
485 TIndexes::const_iterator aIter=myIndixes.find(theAxisNumber);
486 if(aIter==myIndixes.end())
487 EXCEPTION(std::runtime_error, "const TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber); fails");
488 return aIter->second;
493 ::GetIndexes(TInt theAxisNumber)
495 TIndexes::iterator aIter=myIndixes.find(theAxisNumber);
496 if(aIter==myIndixes.end())
497 EXCEPTION(std::runtime_error, "TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber="<<theAxisNumber<<"); fails");
498 return aIter->second;
503 ::GetNbIndexes(TInt theAxisNumber)
505 const TFloatVector& aVector=GetIndexes(theAxisNumber);
506 return aVector.size();
514 TInt aDim = myMeshInfo->GetDim();
515 for(int i=0;i<aDim;i++)
517 nbNodes = this->GetGrilleStructure()[i];
519 nbNodes = nbNodes*this->GetGrilleStructure()[i];
529 TInt aDim = myMeshInfo->GetDim();
530 for(int i=0;i<aDim;i++)
532 nbCells = this->GetGrilleStructure()[i]-1;
534 nbCells = nbCells*(this->GetGrilleStructure()[i]-1);
543 TInt aDim = myMeshInfo->GetDim();
547 (myGrilleStructure[0] ) * (myGrilleStructure[1]-1) * (myGrilleStructure[2]-1) +
548 (myGrilleStructure[0]-1) * (myGrilleStructure[1] ) * (myGrilleStructure[2]-1) +
549 (myGrilleStructure[0]-1) * (myGrilleStructure[1]-1) * (myGrilleStructure[2] );
553 (myGrilleStructure[0] ) * (myGrilleStructure[1]-1) +
554 (myGrilleStructure[0]-1) * (myGrilleStructure[1] );
564 TInt aDim = myMeshInfo->GetDim();
581 TInt aDim = myMeshInfo->GetDim();
602 TInt aDim = myMeshInfo->GetDim();
609 return EEntiteMaillage(-1);
615 ::GetGrilleStructure() const
617 return myGrilleStructure;
622 ::GetGrilleStructure()
624 return myGrilleStructure;
629 ::SetGrilleStructure(TInt theAxis,TInt theNb)
631 if(theAxis >= 0 && theAxis <=2 && theNb >= 0)
632 myGrilleStructure[theAxis]=theNb;
638 ::GetNodeCoord() const
652 ::GetCoord(TInt theId)
655 TInt aDim = myMeshInfo->GetDim();
656 TInt aNbNodes = this->GetNbNodes();
659 if(theId >= aNbNodes)
660 EXCEPTION(std::runtime_error, "TGrilleInfo::GetCoord - theId out of range");
662 if(myGrilleType == eGRILLE_STANDARD){
665 aCoord[2] = myCoord[aDim*theId+2];
667 aCoord[1] = myCoord[aDim*theId+1];
669 aCoord[0] = myCoord[aDim*theId];
675 TFloatVector aVecX = this->GetIndexes(0);
676 TInt nbIndxX = this->GetNbIndexes(0);
680 aCoord[0] = aVecX[theId];
684 TFloatVector aVecY = this->GetIndexes(1);
689 if(myGrilleType == eGRILLE_CARTESIENNE){
690 aCoord[0] = aVecX[i];
691 aCoord[1] = aVecY[j];
692 } else { // eGRILLE_POLAIRE (cylindrical)
693 aCoord[0] = aVecX[i] * cos(aVecY[j]);
694 aCoord[1] = aVecX[i] * sin(aVecY[j]);
699 TFloatVector aVecY = this->GetIndexes(1);
700 TInt nbIndxY = this->GetNbIndexes(1);
701 TFloatVector aVecZ = this->GetIndexes(2);
706 j = (theId / nbIndxX) % nbIndxY;
707 k = theId / (nbIndxX*nbIndxY);
709 if(myGrilleType == eGRILLE_CARTESIENNE){
710 aCoord[0] = aVecX[i];
711 aCoord[1] = aVecY[j];
712 aCoord[2] = aVecZ[k];
713 } else { // eGRILLE_POLAIRE (cylindrical)
714 aCoord[0] = aVecX[i] * cos(aVecY[j]);
715 aCoord[1] = aVecX[i] * sin(aVecY[j]);
716 aCoord[2] = aVecZ[k];
729 ::GetConn(TInt theId, const bool isSub)
731 TIntVector anIndexes;
732 TInt aDim = myMeshInfo->GetDim();
735 TInt iMin, jMin, kMin, iMax, jMax, kMax;
738 loc[0] = loc[1] = loc[2] = 0;
739 iMin = iMax = jMin = jMax = kMin = kMax = 0;
744 TInt nbX = this->GetGrilleStructure()[0];
745 TInt nbY = this->GetGrilleStructure()[1];
746 TInt nbZ = this->GetGrilleStructure()[2];
747 TInt d01 = nbX*nbY, dX = 1, dY = 1, dZ = 1;
750 if ( theId < nbX * (nbY-1) * (nbZ-1))
751 { // face is normal to X axis
754 else if ( theId < nbX * (nbY-1) * (nbZ-1) + (nbX-1) * nbY * (nbZ-1))
755 { // face is normal to Y axis
756 theId -= nbX * (nbY-1) * (nbZ-1);
761 theId -= nbX * (nbY-1) * (nbZ-1) + (nbX-1) * nbY * (nbZ-1);
767 iMin = theId % (nbX - dX);
768 jMin = (theId / (nbX - dX)) % (nbY - dY);
769 kMin = theId / ((nbX - dX) * (nbY - dY));
774 for (loc[2]=kMin; loc[2]<=kMax; loc[2]++)
775 for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
776 for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
778 idx = loc[0] + loc[1]*nbX + loc[2]*d01;
779 anIndexes.push_back(idx);
785 TInt nbX = this->GetGrilleStructure()[0];
786 TInt nbY = this->GetGrilleStructure()[1];
790 if ( theId < nbX * (nbY-1))
791 { // edge is normal to X axis
796 theId -= nbX * (nbY-1);
800 iMin = theId % (nbX-dX);
801 jMin = theId / (nbX-dX);
804 for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
805 for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
807 idx = loc[0] + loc[1]*nbX;
808 anIndexes.push_back(idx);
815 for (loc[0]=iMin; loc[0]<=iMin+1; loc[0]++)
818 anIndexes.push_back(idx);
829 ::GetFamNumNode(TInt theId) const
831 return myFamNumNode[theId];
836 ::SetFamNumNode(TInt theId,TInt theVal)
838 myFamNumNode[theId] = theVal;
843 ::GetFamNum(TInt theId) const
845 return myFamNum[theId];
850 ::SetFamNum(TInt theId,TInt theVal)
852 myFamNum[theId] = theVal;
857 ::GetFamSubNum(TInt theId) const
859 return myFamSubNum[theId];
864 ::SetFamSubNum(TInt theId,TInt theVal)
866 myFamSubNum[theId] = theVal;