Back to index

salome-med  6.5.0
MED_Algorithm.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : 
00024 //  Author : 
00025 //  Module : 
00026 //  $Header: /home/server/cvs/MED/MED_SRC/src/MEDWrapper/Base/MED_Algorithm.cxx,v 1.7.2.2.6.2.10.1 2012-04-13 08:48:42 vsr Exp $
00027 //
00028 #include "MED_Algorithm.hxx"
00029 #include "MED_Wrapper.hxx"
00030 
00031 #include "MED_Utilities.hxx"
00032  
00033 #ifdef _DEBUG_
00034 static int MYDEBUG = 0;
00035 static int MYVALUEDEBUG = 0;
00036 #else
00037 // static int MYDEBUG = 0;
00038 // static int MYVALUEDEBUG = 0;
00039 #endif
00040 
00041 namespace MED
00042 {
00043   //---------------------------------------------------------------
00044   TEntity2TGeom2ElemInfo 
00045   GetEntity2TGeom2ElemInfo(const PWrapper& theWrapper, 
00046                            const PMeshInfo& theMeshInfo,
00047                            const MED::TEntityInfo& theEntityInfo)
00048   {
00049     MSG(MYDEBUG,"GetElemsByEntity(...)");
00050     TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo;
00051     MED::TEntityInfo::const_iterator anIter = theEntityInfo.begin();
00052     PElemInfo anElemInfo;
00053     TErr anErr;
00054     for(; anIter != theEntityInfo.end(); anIter++){
00055       const EEntiteMaillage& anEntity = anIter->first;
00056       const TGeom2Size& aGeom2Size = anIter->second;
00057       TGeom2ElemInfo& aGeom2ElemInfo = anEntity2TGeom2ElemInfo[anEntity];
00058 
00059       if(anEntity == eNOEUD){
00060         aGeom2ElemInfo[ePOINT1] = theWrapper->GetPElemInfo(theMeshInfo);
00061         continue;
00062       }
00063 
00064       TGeom2Size::const_iterator anIter2 = aGeom2Size.begin();
00065       for(; anIter2 != aGeom2Size.end(); anIter2++){
00066         const EGeometrieElement& aGeom = anIter2->first;
00067         aGeom2ElemInfo[aGeom] = theWrapper->GetPElemInfo(theMeshInfo,anEntity,aGeom,MED::eNOD,&anErr);
00068       }
00069     }
00070     ADDMSG(MYDEBUG,"\n");
00071     return anEntity2TGeom2ElemInfo;
00072   }
00073   
00074   
00075   //---------------------------------------------------------------
00076   TFamilyInfoSet
00077   GetFamilyInfoSet(const PWrapper& theWrapper,
00078                    const PMeshInfo& theMeshInfo)
00079   {
00080     MSG(MYDEBUG,"GetFamilies(...)");
00081     TErr anErr;
00082     TFamilyInfoSet aFamilyInfoSet;
00083     TInt aNbFam = theWrapper->GetNbFamilies(*theMeshInfo);
00084     INITMSG(MYDEBUG,"GetNbFamilies() = "<<aNbFam<<"\n");
00085     for(TInt iFam = 1; iFam <= aNbFam; iFam++){
00086       PFamilyInfo aFamilyInfo = theWrapper->GetPFamilyInfo(theMeshInfo,iFam,&anErr);
00087       if(anErr >= 0)
00088         aFamilyInfoSet.insert(aFamilyInfo);
00089     }
00090     ADDMSG(MYDEBUG,"\n");
00091     return aFamilyInfoSet;
00092   }
00093 
00094 
00095   //---------------------------------------------------------------
00096   TGroupInfo
00097   GetGroupInfo(const TFamilyInfoSet& theFamilyInfoSet)
00098   {
00099     MSG(MYDEBUG,"GetFamiliesByGroup(...)");
00100     TGroupInfo aGroup;
00101     TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
00102     for(; anIter != theFamilyInfoSet.end(); anIter++){
00103       const PFamilyInfo& aFamilyInfo = *anIter;
00104       TInt aNbGroup = aFamilyInfo->GetNbGroup();
00105       for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
00106         aGroup[aFamilyInfo->GetGroupName(iGroup)].insert(aFamilyInfo);
00107       } 
00108     }
00109 
00110 #ifdef _DEBUG_
00111     if(MYDEBUG){
00112       TGroupInfo::const_iterator anIter = aGroup.begin();
00113       for(; anIter != aGroup.end(); anIter++){
00114         const std::string& aName = anIter->first;
00115         INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
00116         const TFamilyInfoSet& aFamilyInfoSet = anIter->second;
00117         TFamilyInfoSet::const_iterator anFamIter = aFamilyInfoSet.begin();
00118         for(; anFamIter != aFamilyInfoSet.end(); anFamIter++){
00119           const PFamilyInfo& aFamilyInfo = *anFamIter;
00120           INITMSG(MYDEBUG,"aFamilyName = '"<<aFamilyInfo->GetName()<<"'\n");
00121         }
00122       }
00123       ADDMSG(MYDEBUG,"\n");
00124     }
00125 #endif
00126 
00127     return aGroup;
00128   }
00129 
00130 
00131   //---------------------------------------------------------------
00132   TFieldInfo2TimeStampInfoSet 
00133   GetFieldInfo2TimeStampInfoSet(const PWrapper& theWrapper, 
00134                                 const PMeshInfo& theMeshInfo,
00135                                 const MED::TEntityInfo& theEntityInfo)
00136   {
00137     MSG(MYDEBUG,"GetFieldsByEntity(...)");
00138     TFieldInfo2TimeStampInfoSet aFieldInfo2TimeStampInfoSet;
00139     TInt aNbFields = theWrapper->GetNbFields();
00140     INITMSG(MYDEBUG,"GetNbFields() = "<<aNbFields<<"\n");
00141     for(TInt iField = 1; iField <= aNbFields; iField++){
00142       PFieldInfo aFieldInfo = theWrapper->GetPFieldInfo(theMeshInfo,iField);
00143       INITMSG(MYDEBUG,"aFieldName = '"<<aFieldInfo->GetName()<<
00144               "'; aNbComp = "<<aFieldInfo->GetNbComp()<<"; ");
00145       TGeom2Size aGeom2Size;
00146       EEntiteMaillage anEntity = EEntiteMaillage(-1);
00147       TInt aNbTimeStamps = theWrapper->GetNbTimeStamps(aFieldInfo,theEntityInfo,anEntity,aGeom2Size);
00148       ADDMSG(MYDEBUG,"anEntity = "<<anEntity<<"; GetNbTimeStamps = "<<aNbTimeStamps<<"\n");
00149       for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
00150         PTimeStampInfo aTimeStamp = 
00151           theWrapper->GetPTimeStampInfo(aFieldInfo,anEntity,aGeom2Size,iTimeStamp);
00152         aFieldInfo2TimeStampInfoSet[aFieldInfo].insert(aTimeStamp);
00153         INITMSG(MYDEBUG,
00154                 "aDt = "<<aTimeStamp->GetDt()<<
00155                 ", Unit = \'"<<aTimeStamp->GetUnitDt()<<"\n");
00156       }
00157     }
00158     ADDMSG(MYDEBUG,"\n");
00159     return aFieldInfo2TimeStampInfoSet;
00160   }
00161   
00162 
00163   //---------------------------------------------------------------
00164   TEntite2TFieldInfo2TimeStampInfoSet 
00165   GetEntite2TFieldInfo2TimeStampInfoSet(const TFieldInfo2TimeStampInfoSet& theFieldInfo2TimeStampInfoSet)
00166   {
00167     TEntite2TFieldInfo2TimeStampInfoSet anEntite2TFieldInfo2TimeStampInfoSet;
00168     TFieldInfo2TimeStampInfoSet::const_iterator anIter = theFieldInfo2TimeStampInfoSet.begin();
00169     for(; anIter != theFieldInfo2TimeStampInfoSet.end(); anIter++){
00170       const TTimeStampInfoSet& aTimeStampInfoSet = anIter->second;
00171       //const PFieldInfo& aFieldInfo = anIter->first;
00172       if(aTimeStampInfoSet.empty()) 
00173         continue;
00174       const PTimeStampInfo& aTimeStampInfo = *aTimeStampInfoSet.begin();
00175       anEntite2TFieldInfo2TimeStampInfoSet[ConvertEntity(aTimeStampInfo->GetEntity())].insert(*anIter);
00176     }
00177     return anEntite2TFieldInfo2TimeStampInfoSet;
00178   }
00179   
00180 
00181   //---------------------------------------------------------------
00182   bool
00183   operator<(const TFamilyTSize& theLeft, const TFamilyTSize& theRight)
00184   {
00185     const MED::PFamilyInfo& aLeftInfo = boost::get<0>(theLeft);
00186     const MED::PFamilyInfo& aRightInfo = boost::get<0>(theRight);
00187     return aLeftInfo->GetId() < aRightInfo->GetId();
00188   }
00189 
00190 
00191   //---------------------------------------------------------------
00192   TEntity2FamilySet 
00193   GetEntity2FamilySet(const PWrapper& theWrapper, 
00194                       const TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
00195                       const TFamilyInfoSet& theFamilyInfoSet)
00196   {
00197     MSG(MYDEBUG,"GetFamiliesByEntity(...)");
00198     TEntity2FamilySet anEntity2FamilySet;
00199     
00200     typedef std::map<TInt,PFamilyInfo> TId2Family;
00201     TId2Family anId2Family;
00202     TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
00203     for(; anIter != theFamilyInfoSet.end(); anIter++){
00204       const PFamilyInfo& aFamilyInfo = *anIter;
00205       anId2Family.insert(TId2Family::value_type(aFamilyInfo->GetId(),aFamilyInfo));
00206     }
00207     
00208     if(!anId2Family.empty()){
00209       typedef std::map<TInt,TInt> TFamilyID2Size;
00210       typedef std::map<EEntiteMaillage,TFamilyID2Size> TEntity2FamilyID;
00211       TEntity2FamilyID anEntity2FamilyID;
00212       
00213       if(!theEntity2TGeom2ElemInfo.empty()){
00214         TEntity2TGeom2ElemInfo::const_iterator anIter = theEntity2TGeom2ElemInfo.begin();
00215         for(; anIter != theEntity2TGeom2ElemInfo.end(); anIter++){
00216           const EEntiteMaillage& anEntity = anIter->first;
00217           TFamilyID2Size& aFamilyID2Size = anEntity2FamilyID[anEntity];
00218           const TGeom2ElemInfo& aGeom2ElemInfo = anIter->second;
00219           TGeom2ElemInfo::const_iterator aGeom2ElemInfoIter = aGeom2ElemInfo.begin();
00220           for(; aGeom2ElemInfoIter != aGeom2ElemInfo.end(); aGeom2ElemInfoIter++){
00221             const PElemInfo& aElemInfo = aGeom2ElemInfoIter->second;
00222             if(TInt aNbElem = aElemInfo->GetNbElem()){
00223               for(TInt i = 0; i < aNbElem; i++){
00224                 aFamilyID2Size[aElemInfo->GetFamNum(i)] += 1;
00225               }
00226             }
00227           }
00228         }
00229       }
00230       
00231       if(!anEntity2FamilyID.empty()){
00232         TEntity2FamilyID::const_iterator anIter = anEntity2FamilyID.begin();
00233         for(; anIter != anEntity2FamilyID.end(); anIter++){
00234           const EEntiteMaillage& anEntity = anIter->first;
00235           INITMSG(MYDEBUG,"anEntity = "<<anEntity<<":\n");
00236           const TFamilyID2Size& aFamilyID2Size = anIter->second;
00237           TFamilyID2Size::const_iterator anIter2 = aFamilyID2Size.begin();
00238           for(; anIter2 != aFamilyID2Size.end(); anIter2++){
00239             TInt anId = anIter2->first;
00240             TInt aSize = anIter2->second;
00241             TId2Family::const_iterator anIter3 = anId2Family.find(anId);
00242             if(anIter3 != anId2Family.end()){
00243               const PFamilyInfo& aFamilyInfo = anIter3->second;
00244               anEntity2FamilySet[anEntity].insert(TFamilyTSize(aFamilyInfo,aSize));
00245               INITMSG(MYDEBUG,
00246                       "aFamilyName = '"<<aFamilyInfo->GetName()<<
00247                       "' anId = "<<aFamilyInfo->GetId()<<"\n");
00248             }
00249           }
00250         }
00251       }
00252     }    
00253     ADDMSG(MYDEBUG,"\n");
00254     return anEntity2FamilySet;
00255   }
00256   
00257 
00258   //---------------------------------------------------------------
00259   TKey2Gauss
00260   GetKey2Gauss(const PWrapper& theWrapper, 
00261                TErr* theErr,
00262                EModeSwitch theMode)
00263   {
00264     INITMSG(MYDEBUG,"GetKey2Gauss - theMode = "<<theMode<<std::endl);
00265     TKey2Gauss aKey2Gauss;
00266     TInt aNbGauss = theWrapper->GetNbGauss(theErr);
00267     for(TInt anId = 1; anId <= aNbGauss; anId++){
00268       TGaussInfo::TInfo aPreInfo = theWrapper->GetGaussPreInfo(anId);
00269       PGaussInfo anInfo = theWrapper->CrGaussInfo(aPreInfo,theMode);
00270       theWrapper->GetGaussInfo(anId,anInfo,theErr);
00271       TGaussInfo::TKey aKey = boost::get<0>(aPreInfo);
00272       aKey2Gauss[aKey] = anInfo;
00273 
00274 #ifdef _DEBUG_
00275       const EGeometrieElement& aGeom = boost::get<0>(aKey);
00276       const std::string& aName = boost::get<1>(aKey);
00277       INITMSG(MYDEBUG,
00278               "- aGeom = "<<aGeom<<
00279               "; aName = '"<<aName<<"'"<<
00280               std::endl);
00281 #endif
00282 
00283     }
00284     return aKey2Gauss;
00285   }
00286 
00287 
00288   //---------------------------------------------------------------
00289   PProfileInfo
00290   GetProfileInfo(const PWrapper& theWrapper, 
00291                  const std::string& theProfileName,
00292                  TErr* theErr,
00293                  EModeProfil theMode)
00294   {
00295     PProfileInfo anInfo;
00296     TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
00297     for(TInt anId = 1; anId <= aNbProfiles; anId++){
00298       TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
00299       const std::string& aName = boost::get<0>(aPreInfo);
00300       if(aName == theProfileName)
00301         return theWrapper->GetPProfileInfo(anId,theMode,theErr);
00302     }
00303     return anInfo;
00304   }
00305   
00306 
00307   //---------------------------------------------------------------
00308   TMKey2Profile
00309   GetMKey2Profile(const PWrapper& theWrapper, 
00310                   TErr* theErr,
00311                   EModeProfil theMode)
00312   {
00313     INITMSG(MYDEBUG,"GetMKey2Profile - theMode = "<<theMode<<std::endl);
00314     TKey2Profile aKey2Profile;
00315     TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
00316     for(TInt anId = 1; anId <= aNbProfiles; anId++){
00317       TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
00318       PProfileInfo anInfo = theWrapper->GetPProfileInfo(anId,theMode,theErr);
00319       const std::string& aName = boost::get<0>(aPreInfo);
00320       aKey2Profile[aName] = anInfo;
00321       
00322 #ifdef _DEBUG_
00323       INITMSG(MYDEBUG,
00324               "- aName = '"<<aName<<"'"<<
00325               " : "<<
00326               std::endl);
00327       TInt aNbElem = anInfo->GetSize();
00328       for(TInt iElem = 0; iElem < aNbElem; iElem++){
00329         ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
00330       }
00331       ADDMSG(MYVALUEDEBUG, std::endl);
00332 #endif
00333       
00334     }
00335     return TMKey2Profile(theMode,aKey2Profile);
00336   }
00337 
00338   //---------------------------------------------------------------
00339   EEntiteMaillage
00340   GetEntityByFamilyId(PGrilleInfo& theInfo,TInt theId){
00341     TElemNum::iterator aNodeFamIter = (theInfo->myFamNumNode).begin();
00342     for(;aNodeFamIter != (theInfo->myFamNumNode).end(); aNodeFamIter++){
00343       if(theId == *aNodeFamIter)
00344         return eNOEUD;
00345     }
00346     TElemNum::iterator aCellFamIter = (theInfo->myFamNum).begin();
00347     for(;aCellFamIter != (theInfo->myFamNum).end(); aCellFamIter++){
00348       if(theId == *aCellFamIter)
00349         return eMAILLE;
00350     }
00351     EXCEPTION(std::runtime_error, "GetEntityByFamilyId - fails");
00352     return EEntiteMaillage(-1);
00353   }
00354 
00355   TFamilyID2NbCells
00356   GetFamilyID2NbCells(PGrilleInfo& theInfo){
00357     TFamilyID2NbCells aFamily2NbCells;
00358     TInt aNbNodes = theInfo->myFamNumNode.size();
00359     TInt aNbCells = theInfo->myFamNum.size();
00360     for(TInt i=0; i<aNbNodes; i++) aFamily2NbCells[theInfo->GetFamNumNode(i)] = 0;
00361     for(TInt i=0; i<aNbCells; i++) aFamily2NbCells[theInfo->GetFamNum(i)] = 0;
00362     for(TInt i=0; i<aNbNodes; i++) aFamily2NbCells[theInfo->GetFamNumNode(i)] += 1;
00363     for(TInt i=0; i<aNbCells; i++) aFamily2NbCells[theInfo->GetFamNum(i)] += 1;
00364     return aFamily2NbCells;
00365   }
00366 
00367   EEntiteMaillage ConvertEntity(const EEntiteMaillage& aEntity){
00368     switch( aEntity ){
00369       
00370     case eNOEUD_ELEMENT:
00371     case eMAILLE: return eMAILLE; //eNOEUD_ELEMENT it is eMAILLE
00372       
00373     case eFACE:
00374     case eARETE:
00375     case eNOEUD: return aEntity; break;
00376     default: return EEntiteMaillage(-1);
00377       
00378     }
00379   }
00380 }