1 // Copyright (C) 2007-2021 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
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)
144 (*myElemNum)[theId] = theVal;
147 //---------------------------------------------------------------
150 ::GetCoordSlice(TInt theId) const
152 TInt aDim = myMeshInfo->GetSpaceDim();
153 if(GetModeSwitch() == eFULL_INTERLACE)
154 return TCCoordSlice(*myCoord, std::slice(theId*aDim, aDim, 1));
156 return TCCoordSlice(*myCoord, std::slice(theId, aDim, aDim));
161 ::GetCoordSlice(TInt theId)
163 TInt aDim = myMeshInfo->GetSpaceDim();
164 if(GetModeSwitch() == eFULL_INTERLACE)
165 return TCoordSlice(*myCoord, std::slice(theId*aDim,aDim,1));
167 return TCoordSlice(*myCoord, std::slice(theId,aDim,aDim));
170 //---------------------------------------------------------------
173 ::GetConnSlice(TInt theElemId) const
175 if(GetModeSwitch() == eFULL_INTERLACE)
176 return TCConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1));
178 return TCConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim()));
183 ::GetConnSlice(TInt theElemId)
185 if(GetModeSwitch() == eFULL_INTERLACE)
186 return TConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1));
188 return TConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim()));
191 //---------------------------------------------------------------
194 ::GetNbConn(TInt theElemId) const
196 return (*myIndex)[theElemId + 1] - (*myIndex)[theElemId];
201 ::GetConnSlice(TInt theElemId) const
203 return TCConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1));
208 ::GetConnSlice(TInt theElemId)
210 return TConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1));
213 //---------------------------------------------------------------
216 ::GetNbFaces(TInt theElemId) const
218 return (*myIndex)[theElemId+1] - (*myIndex)[theElemId];
223 ::GetNbNodes(TInt theElemId) const
226 TInt aNbFaces = GetNbFaces(theElemId);
227 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
228 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
229 TInt aCurrentId = (*myFaces)[aStartFaceId];
230 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
238 ::GetConnSliceArr(TInt theElemId) const
240 TInt aNbFaces = GetNbFaces(theElemId);
241 TCConnSliceArr aConnSliceArr(aNbFaces);
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;
246 aConnSliceArr[aFaceId] =
247 TCConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1));
249 return aConnSliceArr;
254 ::GetConnSliceArr(TInt theElemId)
256 TInt aNbFaces = GetNbFaces(theElemId);
257 TConnSliceArr aConnSliceArr(aNbFaces);
258 TInt aStartFaceId = (*myIndex)[theElemId] - 1;
259 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
260 TInt aCurrentId = (*myFaces)[aStartFaceId];
261 TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId;
262 aConnSliceArr[aFaceId] =
263 TConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1));
265 return aConnSliceArr;
268 //---------------------------------------------------------------
279 ::Allocate(TInt theNbElem,
284 myModeSwitch = theMode;
286 myNbElem = theNbElem;
287 myNbGauss = theNbGauss;
288 myNbComp = theNbComp;
290 myStep = theNbComp*theNbGauss;
297 return myNbElem * myStep;
304 return myNbElem * myNbGauss;
321 //---------------------------------------------------------------
324 ::GetElemNum(TInt theId) const
326 return (*myElemNum)[theId];
331 ::SetElemNum(TInt theId,TInt theVal)
333 (*myElemNum)[theId] = theVal;
336 //---------------------------------------------------------------
339 ::operator()(const TKey& theLeft, const TKey& theRight) const
341 EGeometrieElement aLGeom = boost::get<0>(theLeft);
342 EGeometrieElement aRGeom = boost::get<0>(theRight);
344 return aLGeom < aRGeom;
346 const std::string& aLStr = boost::get<1>(theLeft);
347 const std::string& aRStr = boost::get<1>(theRight);
348 return aLStr < aRStr;
353 ::operator()(const TGaussInfo& theLeft, const TGaussInfo& theRight) const
355 if(!&theLeft) // address of reference can be assumed always non-null by compiler - OK
358 if(!&theRight) //address of reference can be assumed always non-null by compiler - OK
361 if(theLeft.myGeom != theRight.myGeom)
362 return theLeft.myGeom < theRight.myGeom;
364 if(theLeft.myRefCoord != theRight.myRefCoord)
365 return theLeft.myRefCoord < theRight.myRefCoord;
367 return theLeft.myGaussCoord < theRight.myGaussCoord;
372 ::GetRefCoordSlice(TInt theId) const
374 if(GetModeSwitch() == eFULL_INTERLACE)
375 return TCCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
377 return TCCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
382 ::GetRefCoordSlice(TInt theId)
384 if(GetModeSwitch() == eFULL_INTERLACE)
385 return TCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
387 return TCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
392 ::GetGaussCoordSlice(TInt theId) const
394 if(GetModeSwitch() == eFULL_INTERLACE)
395 return TCCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetDim(),1));
397 return TCCoordSlice(myGaussCoord,std::slice(theId,GetDim(),GetDim()));
402 ::GetGaussCoordSlice(TInt theId)
404 if(GetModeSwitch() == eFULL_INTERLACE)
405 return TCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetNbGauss(),1));
407 return TCoordSlice(myGaussCoord,std::slice(theId,GetNbGauss(),GetDim()));
410 //---------------------------------------------------------------
413 ::GetNbGauss(EGeometrieElement theGeom) const
415 TGeom2NbGauss::const_iterator anIter = myGeom2NbGauss.find(theGeom);
416 if(anIter == myGeom2NbGauss.end())
417 return 1;//EXCEPTION(runtime_error,"TTimeStampInfo::GetNbGauss - myGeom2NbGauss.find(theGeom) fails");
419 return anIter->second;
422 //---------------------------------------------------------------
423 // TGrilleInfo structure methods
424 //---------------------------------------------------------------
427 ::GetGrilleType() const
441 ::SetGrilleType(EGrilleType theGrilleType)
443 myGrilleType = theGrilleType;
449 ::GetMapOfIndexes() const
464 ::GetIndexes(TInt theAxisNumber) const
466 TIndexes::const_iterator aIter=myIndixes.find(theAxisNumber);
467 if(aIter==myIndixes.end())
468 EXCEPTION(std::runtime_error, "const TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber); fails");
469 return aIter->second;
474 ::GetIndexes(TInt theAxisNumber)
476 TIndexes::iterator aIter=myIndixes.find(theAxisNumber);
477 if(aIter==myIndixes.end())
478 EXCEPTION(std::runtime_error, "TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber="<<theAxisNumber<<"); fails");
479 return aIter->second;
484 ::GetNbIndexes(TInt theAxisNumber)
486 const TFloatVector& aVector=GetIndexes(theAxisNumber);
487 return aVector.size();
495 TInt aDim = myMeshInfo->GetDim();
496 for(int i=0;i<aDim;i++)
498 nbNodes = this->GetGrilleStructure()[i];
500 nbNodes = nbNodes*this->GetGrilleStructure()[i];
510 TInt aDim = myMeshInfo->GetDim();
511 for(int i=0;i<aDim;i++)
513 nbCells = this->GetGrilleStructure()[i]-1;
515 nbCells = nbCells*(this->GetGrilleStructure()[i]-1);
524 TInt aDim = myMeshInfo->GetDim();
528 (myGrilleStructure[0] ) * (myGrilleStructure[1]-1) * (myGrilleStructure[2]-1) +
529 (myGrilleStructure[0]-1) * (myGrilleStructure[1] ) * (myGrilleStructure[2]-1) +
530 (myGrilleStructure[0]-1) * (myGrilleStructure[1]-1) * (myGrilleStructure[2] );
534 (myGrilleStructure[0] ) * (myGrilleStructure[1]-1) +
535 (myGrilleStructure[0]-1) * (myGrilleStructure[1] );
545 TInt aDim = myMeshInfo->GetDim();
562 TInt aDim = myMeshInfo->GetDim();
583 TInt aDim = myMeshInfo->GetDim();
590 return EEntiteMaillage(-1);
596 ::GetGrilleStructure() const
598 return myGrilleStructure;
603 ::GetGrilleStructure()
605 return myGrilleStructure;
610 ::SetGrilleStructure(TInt theAxis,TInt theNb)
612 if(theAxis >= 0 && theAxis <=2 && theNb >= 0)
613 myGrilleStructure[theAxis]=theNb;
619 ::GetNodeCoord() const
633 ::GetCoord(TInt theId)
636 TInt aDim = myMeshInfo->GetDim();
637 TInt aNbNodes = this->GetNbNodes();
640 if(theId >= aNbNodes)
641 EXCEPTION(std::runtime_error, "TGrilleInfo::GetCoord - theId out of range");
643 if(myGrilleType == eGRILLE_STANDARD){
646 aCoord[2] = myCoord[aDim*theId+2];
649 aCoord[1] = myCoord[aDim*theId+1];
652 aCoord[0] = myCoord[aDim*theId];
657 TFloatVector aVecX = this->GetIndexes(0);
658 TInt nbIndxX = this->GetNbIndexes(0);
662 aCoord[0] = aVecX[theId];
666 TFloatVector aVecY = this->GetIndexes(1);
671 if(myGrilleType == eGRILLE_CARTESIENNE){
672 aCoord[0] = aVecX[i];
673 aCoord[1] = aVecY[j];
674 } else { // eGRILLE_POLAIRE (cylindrical)
675 aCoord[0] = aVecX[i] * cos(aVecY[j]);
676 aCoord[1] = aVecX[i] * sin(aVecY[j]);
681 TFloatVector aVecY = this->GetIndexes(1);
682 TInt nbIndxY = this->GetNbIndexes(1);
683 TFloatVector aVecZ = this->GetIndexes(2);
688 j = (theId / nbIndxX) % nbIndxY;
689 k = theId / (nbIndxX*nbIndxY);
691 if(myGrilleType == eGRILLE_CARTESIENNE){
692 aCoord[0] = aVecX[i];
693 aCoord[1] = aVecY[j];
694 aCoord[2] = aVecZ[k];
695 } else { // eGRILLE_POLAIRE (cylindrical)
696 aCoord[0] = aVecX[i] * cos(aVecY[j]);
697 aCoord[1] = aVecX[i] * sin(aVecY[j]);
698 aCoord[2] = aVecZ[k];
711 ::GetConn(TInt theId, const bool isSub)
713 TIntVector anIndexes;
714 TInt aDim = myMeshInfo->GetDim();
717 TInt iMin, jMin, kMin, iMax, jMax, kMax;
720 loc[0] = loc[1] = loc[2] = 0;
721 iMin = iMax = jMin = jMax = kMin = kMax = 0;
726 TInt nbX = this->GetGrilleStructure()[0];
727 TInt nbY = this->GetGrilleStructure()[1];
728 TInt nbZ = this->GetGrilleStructure()[2];
729 TInt d01 = nbX*nbY, dX = 1, dY = 1, dZ = 1;
732 if ( theId < nbX * (nbY-1) * (nbZ-1))
733 { // face is normal to X axis
736 else if ( theId < nbX * (nbY-1) * (nbZ-1) + (nbX-1) * nbY * (nbZ-1))
737 { // face is normal to Y axis
738 theId -= nbX * (nbY-1) * (nbZ-1);
743 theId -= nbX * (nbY-1) * (nbZ-1) + (nbX-1) * nbY * (nbZ-1);
749 iMin = theId % (nbX - dX);
750 jMin = (theId / (nbX - dX)) % (nbY - dY);
751 kMin = theId / ((nbX - dX) * (nbY - dY));
756 for (loc[2]=kMin; loc[2]<=kMax; loc[2]++)
757 for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
758 for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
760 idx = loc[0] + loc[1]*nbX + loc[2]*d01;
761 anIndexes.push_back(idx);
767 TInt nbX = this->GetGrilleStructure()[0];
768 TInt nbY = this->GetGrilleStructure()[1];
772 if ( theId < nbX * (nbY-1))
773 { // edge is normal to X axis
778 theId -= nbX * (nbY-1);
782 iMin = theId % (nbX-dX);
783 jMin = theId / (nbX-dX);
786 for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
787 for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
789 idx = loc[0] + loc[1]*nbX;
790 anIndexes.push_back(idx);
797 for (loc[0]=iMin; loc[0]<=iMin+1; loc[0]++)
800 anIndexes.push_back(idx);
811 ::GetFamNumNode(TInt theId) const
813 return myFamNumNode[theId];
818 ::SetFamNumNode(TInt theId,TInt theVal)
820 myFamNumNode[theId] = theVal;
825 ::GetFamNum(TInt theId) const
827 return myFamNum[theId];
832 ::SetFamNum(TInt theId,TInt theVal)
834 myFamNum[theId] = theVal;
839 ::GetFamSubNum(TInt theId) const
841 return myFamSubNum[theId];
846 ::SetFamSubNum(TInt theId,TInt theVal)
848 myFamSubNum[theId] = theVal;