1 // Copyright (C) 2007-2023 CEA, EDF, 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 #include "MED_Structures.hxx"
24 #include "MED_Utilities.hxx"
33 const TString& theString)
35 const char* aPos = &theString[theId*theStep];
36 TInt aSize = std::min(TInt(strlen(aPos)),theStep);
37 return std::string(aPos,aSize);
44 const std::string& theValue)
46 TInt aSize = std::min(TInt(theValue.size()+1),theStep);
47 char* aPos = &theString[theId*theStep];
48 strncpy(aPos,theValue.c_str(),aSize);
55 const TString& theValue)
57 TInt aSize = std::min(TInt(theValue.size()+1),theStep);
58 char* aPos = &theString[theId*theStep];
59 const char* aValue = &theValue[0];
60 strncpy(aPos,aValue,aSize);
64 GetDimGaussCoord(EGeometrieElement theGeom)
70 GetNbRefCoord(EGeometrieElement theGeom)
75 //---------------------------------------------------------------
77 CastToFloatTimeStampValue(const PTimeStampValueBase& theTimeStampValue)
79 return theTimeStampValue;
83 CastToIntTimeStampValue(const PTimeStampValueBase& theTimeStampValue)
85 return theTimeStampValue;
88 //---------------------------------------------------------------
91 ::GetAttrId(TInt theId) const
93 return myAttrId[theId];
98 ::GetAttrVal(TInt theId) const
100 return myAttrVal[theId];
105 ::SetAttrId(TInt theId,TInt theVal)
107 myAttrId[theId] = theVal;
112 ::SetAttrVal(TInt theId,TInt theVal)
114 myAttrVal[theId] = theVal;
117 //---------------------------------------------------------------
120 ::GetFamNum(TInt theId) const
122 return (*myFamNum)[theId];
127 ::SetFamNum(TInt theId, TInt theVal)
129 (*myFamNum)[theId] = theVal;
135 ::GetElemNum(TInt theId) const
137 return (*myElemNum)[theId];
142 ::SetElemNum(TInt theId, TInt theVal)
145 (*myElemNum)[theId] = theVal;
148 //---------------------------------------------------------------
151 ::GetCoordSlice(TInt theId) const
153 TInt aDim = myMeshInfo->GetSpaceDim();
154 if(GetModeSwitch() == eFULL_INTERLACE)
155 return TCCoordSlice(*myCoord, std::slice(theId*aDim, aDim, 1));
157 return TCCoordSlice(*myCoord, std::slice(theId, aDim, aDim));
162 ::GetCoordSlice(TInt theId)
164 TInt aDim = myMeshInfo->GetSpaceDim();
165 if(GetModeSwitch() == eFULL_INTERLACE)
166 return TCoordSlice(*myCoord, std::slice(theId*aDim,aDim,1));
168 return TCoordSlice(*myCoord, std::slice(theId,aDim,aDim));
171 //---------------------------------------------------------------
174 ::GetConnSlice(TInt theElemId) const
176 if(GetModeSwitch() == eFULL_INTERLACE)
177 return TCConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1));
179 return TCConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim()));
184 ::GetConnSlice(TInt theElemId)
186 if(GetModeSwitch() == eFULL_INTERLACE)
187 return TConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1));
189 return TConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim()));
192 //---------------------------------------------------------------
195 ::GetNbConn(TInt theElemId) const
197 return (*myIndex)[theElemId + 1] - (*myIndex)[theElemId];
202 ::GetConnSlice(TInt theElemId) const
204 return TCConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1));
209 ::GetConnSlice(TInt theElemId)
211 return TConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1));
214 //---------------------------------------------------------------
217 ::GetNbFaces(TInt theElemId) const
219 return (*myIndex)[theElemId+1] - (*myIndex)[theElemId];
224 ::GetNbNodes(TInt theElemId) const
227 TInt aNbFaces = GetNbFaces(theElemId);
228 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
229 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
230 TInt aCurrentId = (*myFaces)[aStartFaceId];
231 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
239 ::GetConnSliceArr(TInt theElemId) const
241 TInt aNbFaces = GetNbFaces(theElemId);
242 TCConnSliceArr aConnSliceArr(aNbFaces);
243 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
244 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
245 TInt aCurrentId = (*myFaces)[aStartFaceId];
246 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
247 aConnSliceArr[aFaceId] =
248 TCConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1));
250 return aConnSliceArr;
255 ::GetConnSliceArr(TInt theElemId)
257 TInt aNbFaces = GetNbFaces(theElemId);
258 TConnSliceArr aConnSliceArr(aNbFaces);
259 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
260 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
261 TInt aCurrentId = (*myFaces)[aStartFaceId];
262 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
263 aConnSliceArr[aFaceId] =
264 TConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1));
266 return aConnSliceArr;
269 //---------------------------------------------------------------
280 ::Allocate(TInt theNbElem,
285 myModeSwitch = theMode;
287 myNbElem = theNbElem;
288 myNbGauss = theNbGauss;
289 myNbComp = theNbComp;
291 myStep = theNbComp*theNbGauss;
298 return myNbElem * myStep;
305 return myNbElem * myNbGauss;
322 //---------------------------------------------------------------
325 ::GetElemNum(TInt theId) const
327 return (*myElemNum)[theId];
332 ::SetElemNum(TInt theId,TInt theVal)
334 (*myElemNum)[theId] = theVal;
337 //---------------------------------------------------------------
340 ::operator()(const TKey& theLeft, const TKey& theRight) const
342 EGeometrieElement aLGeom = boost::get<0>(theLeft);
343 EGeometrieElement aRGeom = boost::get<0>(theRight);
345 return aLGeom < aRGeom;
347 const std::string& aLStr = boost::get<1>(theLeft);
348 const std::string& aRStr = boost::get<1>(theRight);
349 return aLStr < aRStr;
354 ::operator()(const TGaussInfo& theLeft, const TGaussInfo& theRight) const
356 if(!&theLeft) // address of reference can be assumed always non-null by compiler - OK
359 if(!&theRight) //address of reference can be assumed always non-null by compiler - OK
362 if(theLeft.myGeom != theRight.myGeom)
363 return theLeft.myGeom < theRight.myGeom;
365 if(theLeft.myRefCoord != theRight.myRefCoord)
366 return theLeft.myRefCoord < theRight.myRefCoord;
368 return theLeft.myGaussCoord < theRight.myGaussCoord;
373 ::GetRefCoordSlice(TInt theId) const
375 if(GetModeSwitch() == eFULL_INTERLACE)
376 return TCCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
378 return TCCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
383 ::GetRefCoordSlice(TInt theId)
385 if(GetModeSwitch() == eFULL_INTERLACE)
386 return TCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
388 return TCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
393 ::GetGaussCoordSlice(TInt theId) const
395 if(GetModeSwitch() == eFULL_INTERLACE)
396 return TCCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetDim(),1));
398 return TCCoordSlice(myGaussCoord,std::slice(theId,GetDim(),GetDim()));
403 ::GetGaussCoordSlice(TInt theId)
405 if(GetModeSwitch() == eFULL_INTERLACE)
406 return TCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetNbGauss(),1));
408 return TCoordSlice(myGaussCoord,std::slice(theId,GetNbGauss(),GetDim()));
411 //---------------------------------------------------------------
414 ::GetNbGauss(EGeometrieElement theGeom) const
416 TGeom2NbGauss::const_iterator anIter = myGeom2NbGauss.find(theGeom);
417 if(anIter == myGeom2NbGauss.end())
418 return 1;//EXCEPTION(runtime_error,"TTimeStampInfo::GetNbGauss - myGeom2NbGauss.find(theGeom) fails");
420 return anIter->second;
423 //---------------------------------------------------------------
424 // TGrilleInfo structure methods
425 //---------------------------------------------------------------
428 ::GetGrilleType() const
442 ::SetGrilleType(EGrilleType theGrilleType)
444 myGrilleType = theGrilleType;
450 ::GetMapOfIndexes() const
465 ::GetIndexes(TInt theAxisNumber) const
467 TIndexes::const_iterator aIter=myIndixes.find(theAxisNumber);
468 if(aIter==myIndixes.end())
469 EXCEPTION(std::runtime_error, "const TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber); fails");
470 return aIter->second;
475 ::GetIndexes(TInt theAxisNumber)
477 TIndexes::iterator aIter=myIndixes.find(theAxisNumber);
478 if(aIter==myIndixes.end())
479 EXCEPTION(std::runtime_error, "TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber="<<theAxisNumber<<"); fails");
480 return aIter->second;
485 ::GetNbIndexes(TInt theAxisNumber)
487 const TFloatVector& aVector=GetIndexes(theAxisNumber);
488 return aVector.size();
496 TInt aDim = myMeshInfo->GetDim();
497 for(int i=0;i<aDim;i++)
499 nbNodes = this->GetGrilleStructure()[i];
501 nbNodes = nbNodes*this->GetGrilleStructure()[i];
511 TInt aDim = myMeshInfo->GetDim();
512 for(int i=0;i<aDim;i++)
514 nbCells = this->GetGrilleStructure()[i]-1;
516 nbCells = nbCells*(this->GetGrilleStructure()[i]-1);
525 TInt aDim = myMeshInfo->GetDim();
529 (myGrilleStructure[0] ) * (myGrilleStructure[1]-1) * (myGrilleStructure[2]-1) +
530 (myGrilleStructure[0]-1) * (myGrilleStructure[1] ) * (myGrilleStructure[2]-1) +
531 (myGrilleStructure[0]-1) * (myGrilleStructure[1]-1) * (myGrilleStructure[2] );
535 (myGrilleStructure[0] ) * (myGrilleStructure[1]-1) +
536 (myGrilleStructure[0]-1) * (myGrilleStructure[1] );
546 TInt aDim = myMeshInfo->GetDim();
563 TInt aDim = myMeshInfo->GetDim();
584 TInt aDim = myMeshInfo->GetDim();
591 return EEntiteMaillage(-1);
597 ::GetGrilleStructure() const
599 return myGrilleStructure;
604 ::GetGrilleStructure()
606 return myGrilleStructure;
611 ::SetGrilleStructure(TInt theAxis,TInt theNb)
613 if(theAxis >= 0 && theAxis <=2 && theNb >= 0)
614 myGrilleStructure[theAxis]=theNb;
620 ::GetNodeCoord() const
634 ::GetCoord(TInt theId)
637 TInt aDim = myMeshInfo->GetDim();
638 TInt aNbNodes = this->GetNbNodes();
641 if(theId >= aNbNodes)
642 EXCEPTION(std::runtime_error, "TGrilleInfo::GetCoord - theId out of range");
644 if(myGrilleType == eGRILLE_STANDARD){
647 aCoord[2] = myCoord[aDim*theId+2];
650 aCoord[1] = myCoord[aDim*theId+1];
653 aCoord[0] = myCoord[aDim*theId];
658 TFloatVector aVecX = this->GetIndexes(0);
659 TInt nbIndxX = this->GetNbIndexes(0);
663 aCoord[0] = aVecX[theId];
667 TFloatVector aVecY = this->GetIndexes(1);
672 if(myGrilleType == eGRILLE_CARTESIENNE){
673 aCoord[0] = aVecX[i];
674 aCoord[1] = aVecY[j];
675 } else { // eGRILLE_POLAIRE (cylindrical)
676 aCoord[0] = aVecX[i] * cos(aVecY[j]);
677 aCoord[1] = aVecX[i] * sin(aVecY[j]);
682 TFloatVector aVecY = this->GetIndexes(1);
683 TInt nbIndxY = this->GetNbIndexes(1);
684 TFloatVector aVecZ = this->GetIndexes(2);
689 j = (theId / nbIndxX) % nbIndxY;
690 k = theId / (nbIndxX*nbIndxY);
692 if(myGrilleType == eGRILLE_CARTESIENNE){
693 aCoord[0] = aVecX[i];
694 aCoord[1] = aVecY[j];
695 aCoord[2] = aVecZ[k];
696 } else { // eGRILLE_POLAIRE (cylindrical)
697 aCoord[0] = aVecX[i] * cos(aVecY[j]);
698 aCoord[1] = aVecX[i] * sin(aVecY[j]);
699 aCoord[2] = aVecZ[k];
712 ::GetConn(TInt theId, const bool isSub)
714 TIntVector anIndexes;
715 TInt aDim = myMeshInfo->GetDim();
718 TInt iMin, jMin, kMin, iMax, jMax, kMax;
721 loc[0] = loc[1] = loc[2] = 0;
722 iMin = iMax = jMin = jMax = kMin = kMax = 0;
727 TInt nbX = this->GetGrilleStructure()[0];
728 TInt nbY = this->GetGrilleStructure()[1];
729 TInt nbZ = this->GetGrilleStructure()[2];
730 TInt d01 = nbX*nbY, dX = 1, dY = 1, dZ = 1;
733 if ( theId < nbX * (nbY-1) * (nbZ-1))
734 { // face is normal to X axis
737 else if ( theId < nbX * (nbY-1) * (nbZ-1) + (nbX-1) * nbY * (nbZ-1))
738 { // face is normal to Y axis
739 theId -= nbX * (nbY-1) * (nbZ-1);
744 theId -= nbX * (nbY-1) * (nbZ-1) + (nbX-1) * nbY * (nbZ-1);
750 iMin = theId % (nbX - dX);
751 jMin = (theId / (nbX - dX)) % (nbY - dY);
752 kMin = theId / ((nbX - dX) * (nbY - dY));
757 for (loc[2]=kMin; loc[2]<=kMax; loc[2]++)
758 for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
759 for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
761 idx = loc[0] + loc[1]*nbX + loc[2]*d01;
762 anIndexes.push_back(idx);
768 TInt nbX = this->GetGrilleStructure()[0];
769 TInt nbY = this->GetGrilleStructure()[1];
773 if ( theId < nbX * (nbY-1))
774 { // edge is normal to X axis
779 theId -= nbX * (nbY-1);
783 iMin = theId % (nbX-dX);
784 jMin = theId / (nbX-dX);
787 for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
788 for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
790 idx = loc[0] + loc[1]*nbX;
791 anIndexes.push_back(idx);
798 for (loc[0]=iMin; loc[0]<=iMin+1; loc[0]++)
801 anIndexes.push_back(idx);
812 ::GetFamNumNode(TInt theId) const
814 return myFamNumNode[theId];
819 ::SetFamNumNode(TInt theId,TInt theVal)
821 myFamNumNode[theId] = theVal;
826 ::GetFamNum(TInt theId) const
828 return myFamNum[theId];
833 ::SetFamNum(TInt theId,TInt theVal)
835 myFamNum[theId] = theVal;
840 ::GetFamSubNum(TInt theId) const
842 return myFamSubNum[theId];
847 ::SetFamSubNum(TInt theId,TInt theVal)
849 myFamSubNum[theId] = theVal;