1 // Copyright (C) 2003 CEA/DEN, EDF R&D
3 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
5 // File : MED_Structure.cxx
6 // Author : Eugeny NIKOLAEV
9 #include "MED_Structures.hxx"
10 #include "MED_Utilities.hxx"
17 GetNbNodes(EGeometrieElement typmai)
25 const TString& theString)
27 const char* aPos = &theString[theId*theStep];
28 TInt aSize = std::min(TInt(strlen(aPos)),theStep);
29 return std::string(aPos,aSize);
36 const std::string& theValue)
38 TInt aSize = std::min(TInt(theValue.size()+1),theStep);
39 char* aPos = &theString[theId*theStep];
40 strncpy(aPos,theValue.c_str(),aSize);
44 GetDimGaussCoord(EGeometrieElement theGeom)
50 GetNbRefCoord(EGeometrieElement theGeom)
57 //---------------------------------------------------------------
60 ::GetAttrId(TInt theId) const
62 return myAttrId[theId];
67 ::GetAttrVal(TInt theId) const
69 return myAttrVal[theId];
74 ::SetAttrId(TInt theId,TInt theVal)
76 myAttrId[theId] = theVal;
81 ::SetAttrVal(TInt theId,TInt theVal)
83 myAttrVal[theId] = theVal;
86 //---------------------------------------------------------------
89 ::GetFamNum(TInt theId) const
91 return myFamNum[theId];
96 ::GetElemNum(TInt theId) const
98 return myElemNum[theId];
103 ::SetFamNum(TInt theId,TInt theVal)
105 myFamNum[theId] = theVal;
108 //---------------------------------------------------------------
111 ::GetCoordSlice(TInt theId) const
113 TInt aDim = myMeshInfo->GetDim();
114 if(GetModeSwitch() == eFULL_INTERLACE)
115 return TCCoordSlice(myCoord,std::slice(theId*aDim,aDim,1));
117 return TCCoordSlice(myCoord,std::slice(theId,aDim,aDim));
122 ::GetCoordSlice(TInt theId)
124 TInt aDim = myMeshInfo->GetDim();
125 if(GetModeSwitch() == eFULL_INTERLACE)
126 return TCoordSlice(myCoord,std::slice(theId*aDim,aDim,1));
128 return TCoordSlice(myCoord,std::slice(theId,aDim,aDim));
131 //---------------------------------------------------------------
134 ::GetConnSlice(TInt theElemId) const
136 if(GetModeSwitch() == eFULL_INTERLACE)
137 return TCConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbNodes(myGeom),1));
139 return TCConnSlice(myConn,std::slice(theElemId,GetNbNodes(myGeom),GetConnDim()));
144 ::GetConnSlice(TInt theElemId)
146 if(GetModeSwitch() == eFULL_INTERLACE)
147 return TConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbNodes(myGeom),1));
149 return TConnSlice(myConn,std::slice(theElemId,GetNbNodes(myGeom),GetConnDim()));
153 //---------------------------------------------------------------
156 ::GetNbConn(TInt theElemId) const
158 return myIndex[theElemId + 1] - myIndex[theElemId];
163 ::GetConnSlice(TInt theElemId) const
165 return TCConnSlice(myConn,std::slice(myIndex[theElemId]-1,GetNbConn(theElemId),1));
170 ::GetConnSlice(TInt theElemId)
172 return TConnSlice(myConn,std::slice(myIndex[theElemId]-1,GetNbConn(theElemId),1));
176 //---------------------------------------------------------------
179 ::GetNbFaces(TInt theElemId) const
181 return myIndex[theElemId+1] - myIndex[theElemId];
186 ::GetNbNodes(TInt theElemId) const
189 TInt aNbFaces = GetNbFaces(theElemId);
190 TInt aStartFaceId = myIndex[theElemId] - 1;
191 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
192 TInt aCurrentId = myFaces[aStartFaceId];
193 TInt aDiff = myFaces[aStartFaceId + 1] - aCurrentId;
201 ::GetConnSliceArr(TInt theElemId) const
203 TInt aNbFaces = GetNbFaces(theElemId);
204 TCConnSliceArr aConnSliceArr(aNbFaces);
205 TInt aStartFaceId = myIndex[theElemId] - 1;
206 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
207 TInt aCurrentId = myFaces[aStartFaceId];
208 TInt aDiff = myFaces[aStartFaceId + 1] - aCurrentId;
209 aConnSliceArr[aFaceId] =
210 TCConnSlice(myConn,std::slice(aCurrentId - 1,aDiff,1));
212 return aConnSliceArr;
217 ::GetConnSliceArr(TInt theElemId)
219 TInt aNbFaces = GetNbFaces(theElemId);
220 TConnSliceArr aConnSliceArr(aNbFaces);
221 TInt aStartFaceId = myIndex[theElemId] - 1;
222 for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){
223 TInt aCurrentId = myFaces[aStartFaceId];
224 TInt aDiff = myFaces[aStartFaceId + 1] - aCurrentId;
225 aConnSliceArr[aFaceId] =
226 TConnSlice(myConn,std::slice(aCurrentId - 1,aDiff,1));
228 return aConnSliceArr;
232 //---------------------------------------------------------------
235 ::GetElemNum(TInt theId) const
237 return myElemNum[theId];
242 ::SetElemNum(TInt theId,TInt theVal)
244 myElemNum[theId] = theVal;
247 //---------------------------------------------------------------
250 ::operator()(const TKey& theLeft, const TKey& theRight) const
252 EGeometrieElement aLGeom = boost::get<0>(theLeft);
253 EGeometrieElement aRGeom = boost::get<0>(theRight);
255 return aLGeom < aRGeom;
257 const std::string& aLStr = boost::get<1>(theLeft);
258 const std::string& aRStr = boost::get<1>(theRight);
259 return aLStr < aRStr;
264 ::operator()(const TGaussInfo& theLeft, const TGaussInfo& theRight) const
266 if(theLeft.myGeom != theRight.myGeom)
267 return theLeft.myGeom < theRight.myGeom;
269 if(theLeft.myRefCoord != theRight.myRefCoord)
270 return theLeft.myRefCoord < theRight.myRefCoord;
272 return theLeft.myGaussCoord < theRight.myGaussCoord;
277 ::GetRefCoordSlice(TInt theId) const
279 if(GetModeSwitch() == eFULL_INTERLACE)
280 return TCCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
282 return TCCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
287 ::GetRefCoordSlice(TInt theId)
289 if(GetModeSwitch() == eFULL_INTERLACE)
290 return TCoordSlice(myRefCoord,std::slice(theId*GetDim(),GetDim(),1));
292 return TCoordSlice(myRefCoord,std::slice(theId,GetDim(),GetDim()));
297 ::GetGaussCoordSlice(TInt theId) const
299 if(GetModeSwitch() == eFULL_INTERLACE)
300 return TCCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetDim(),1));
302 return TCCoordSlice(myGaussCoord,std::slice(theId,GetDim(),GetDim()));
307 ::GetGaussCoordSlice(TInt theId)
309 if(GetModeSwitch() == eFULL_INTERLACE)
310 return TCoordSlice(myGaussCoord,std::slice(theId*GetDim(),GetNbGauss(),1));
312 return TCoordSlice(myGaussCoord,std::slice(theId,GetNbGauss(),GetDim()));
316 //---------------------------------------------------------------
319 ::GetNbGauss(EGeometrieElement theGeom) const
321 TGeom2NbGauss::const_iterator anIter = myGeom2NbGauss.find(theGeom);
322 if(anIter == myGeom2NbGauss.end())
323 EXCEPTION(runtime_error,"TTimeStampInfo::GetNbGauss - myGeom2NbGauss.find(theGeom) fails");
325 return anIter->second;
329 //---------------------------------------------------------------
332 ::Init(TInt theNbElem,
337 myModeSwitch = theMode;
339 myNbElem = theNbElem;
340 myNbGauss = theNbGauss;
341 myNbComp = theNbComp;
343 myStep = theNbComp*theNbGauss;
345 myValue.resize(theNbElem*myStep);
348 //---------------------------------------------------------------
351 ::GetGaussValueSliceArr(TInt theElemId) const
353 TCValueSliceArr aValueSliceArr(myNbGauss);
354 if(GetModeSwitch() == eFULL_INTERLACE){
355 TInt anId = theElemId*myStep;
356 for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
357 aValueSliceArr[aGaussId] =
358 TCValueSlice(myValue,std::slice(anId,myNbComp,1));
363 for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
364 aValueSliceArr[aGaussId] =
365 TCValueSlice(myValue,std::slice(theElemId,myNbComp,myStep));
368 return aValueSliceArr;
373 ::GetGaussValueSliceArr(TInt theElemId)
375 TValueSliceArr aValueSliceArr(myNbGauss);
376 if(GetModeSwitch() == eFULL_INTERLACE){
377 TInt anId = theElemId*myStep;
378 for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
379 aValueSliceArr[aGaussId] =
380 TValueSlice(myValue,std::slice(anId,myNbComp,1));
385 for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
386 aValueSliceArr[aGaussId] =
387 TValueSlice(myValue,std::slice(theElemId,myNbComp,myStep));
390 return aValueSliceArr;
393 //---------------------------------------------------------------
396 ::GetCompValueSliceArr(TInt theElemId) const
398 TCValueSliceArr aValueSliceArr(myNbComp);
399 if(GetModeSwitch() == eFULL_INTERLACE){
400 TInt anId = theElemId*myStep;
401 for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){
402 aValueSliceArr[aCompId] =
403 TCValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp));
408 for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){
409 aValueSliceArr[aCompId] =
410 TCValueSlice(myValue,std::slice(theElemId,myNbGauss,myStep));
413 return aValueSliceArr;
419 ::GetCompValueSliceArr(TInt theElemId)
421 TValueSliceArr aValueSliceArr(myNbGauss);
422 if(GetModeSwitch() == eFULL_INTERLACE){
423 TInt anId = theElemId*myStep;
424 for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){
425 aValueSliceArr[aCompId] =
426 TValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp));
431 for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
432 aValueSliceArr[aGaussId] =
433 TValueSlice(myValue,std::slice(theElemId,myNbComp,myStep));
436 return aValueSliceArr;
440 //---------------------------------------------------------------
443 ::GetMeshValue(EGeometrieElement theGeom) const
445 TGeom2Value::const_iterator anIter = myGeom2Value.find(theGeom);
446 if(anIter == myGeom2Value.end())
447 EXCEPTION(runtime_error,"TTimeStampVal::GetMeshValue - myGeom2Value.find(theGeom) fails");
448 return anIter->second;
453 ::GetMeshValue(EGeometrieElement theGeom)
455 return myGeom2Value[theGeom];
458 //---------------------------------------------------------------
459 // TGrilleInfo structure methods
460 //---------------------------------------------------------------
463 ::GetGrilleType() const
477 ::SetGrilleType(EGrilleType theGrilleType)
479 myGrilleType = theGrilleType;
485 ::GetMapOfIndexes() const
500 ::GetIndexes(TInt theAxisNumber) const
502 TIndexes::const_iterator aIter=myIndixes.find(theAxisNumber);
503 if(aIter==myIndixes.end())
504 EXCEPTION(runtime_error,"const TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber); fails");
505 return aIter->second;
510 ::GetIndexes(TInt theAxisNumber)
512 TIndexes::iterator aIter=myIndixes.find(theAxisNumber);
513 if(aIter==myIndixes.end())
514 EXCEPTION(runtime_error,"TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber); fails");
515 return aIter->second;
520 ::GetNbIndexes(TInt theAxisNumber)
522 const TFloatVector& aVector=GetIndexes(theAxisNumber);
523 return aVector.size();
531 TInt aDim = myMeshInfo->GetDim();
532 if(myGrilleType == eGRILLE_STANDARD)
533 for(int i=0;i<aDim;i++)
535 nbNodes = myGrilleStructure[i];
537 nbNodes = nbNodes*myGrilleStructure[i];
539 for(int i=0;i<aDim;i++)
541 nbNodes = GetNbIndexes(i);
543 nbNodes = nbNodes*GetNbIndexes(i);
553 TInt aDim = myMeshInfo->GetDim();
554 if(myGrilleType == eGRILLE_STANDARD)
555 for(int i=0;i<aDim;i++)
557 nbCells = myGrilleStructure[i]-1;
559 nbCells = nbCells*(myGrilleStructure[i]-1);
561 for(int i=0;i<aDim;i++)
563 nbCells = GetNbIndexes(i)-1;
565 nbCells = nbCells*(GetNbIndexes(i)-1);
573 TInt aDim = myMeshInfo->GetDim();
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(runtime_error,"TGrilleInfo::GetCoord - theId out of range");
643 if(myGrilleType == eGRILLE_STANDARD){
646 aCoord[2] = myCoord[aDim*theId+2];
648 aCoord[1] = myCoord[aDim*theId+1];
650 aCoord[0] = myCoord[aDim*theId];
656 TFloatVector aVecX = this->GetIndexes(0);
657 TInt nbIndxX = this->GetNbIndexes(0);
661 aCoord[0] = aVecX[theId];
665 TFloatVector aVecY = this->GetIndexes(1);
670 if(myGrilleType == eGRILLE_CARTESIENNE){
671 aCoord[0] = aVecX[i];
672 aCoord[1] = aVecY[j];
673 } else { // eGRILLE_POLAIRE (cylindrical)
674 aCoord[0] = aVecX[i] * cos(aVecY[j]);
675 aCoord[1] = aVecX[i] * sin(aVecY[j]);
680 TFloatVector aVecY = this->GetIndexes(1);
681 TInt nbIndxY = this->GetNbIndexes(1);
682 TFloatVector aVecZ = this->GetIndexes(2);
687 j = (theId / nbIndxX) % nbIndxY;
688 k = theId / (nbIndxX*nbIndxY);
690 if(myGrilleType == eGRILLE_CARTESIENNE){
691 aCoord[0] = aVecX[i];
692 aCoord[1] = aVecY[j];
693 aCoord[2] = aVecZ[k];
694 } else { // eGRILLE_POLAIRE (cylindrical)
695 aCoord[0] = aVecX[i] * cos(aVecY[j]);
696 aCoord[1] = aVecX[i] * sin(aVecY[j]);
697 aCoord[2] = aVecZ[k];
710 ::GetConn(TInt theId)
712 TIntVector anIndexes;
713 TInt aDim = myMeshInfo->GetDim();
715 for(int i=1;i<aDim;i++) aArrSize = aArrSize*2;
718 TInt iMin, iMax, jMin, jMax, kMin, kMax;
721 loc[0] = loc[1] = loc[2] = 0;
722 iMin = iMax = jMin = jMax = kMin = kMax = 0;
725 if (myGrilleType == eGRILLE_STANDARD)
727 nbX = this->GetGrilleStructure()[0];
728 nbY = this->GetGrilleStructure()[1];
732 nbX = this->GetNbIndexes(0);
733 nbY = this->GetNbIndexes(1);
740 iMin = theId % (nbX - 1);
742 jMin = (theId / (nbX - 1)) % (nbY - 1);
744 kMin = theId / ((nbX - 1) * (nbY - 1));
749 iMin = theId % (nbX-1);
751 jMin = theId / (nbX-1);
763 for (loc[2]=kMin; loc[2]<=kMax; loc[2]++)
765 for (loc[1]=jMin; loc[1]<=jMax; loc[1]++)
767 for (loc[0]=iMin; loc[0]<=iMax; loc[0]++)
769 idx = loc[0] + loc[1]*nbX + loc[2]*d01;
770 anIndexes.push_back(idx);