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 #include "MED_Algorithm.hxx"
24 #include "MED_Wrapper.hxx"
26 #include "MED_Utilities.hxx"
29 static int MYDEBUG = 0;
30 static int MYVALUEDEBUG = 0;
32 // static int MYDEBUG = 0;
33 // static int MYVALUEDEBUG = 0;
38 //---------------------------------------------------------------
39 TEntity2TGeom2ElemInfo
40 GetEntity2TGeom2ElemInfo(const PWrapper& theWrapper,
41 const PMeshInfo& theMeshInfo,
42 const MED::TEntityInfo& theEntityInfo)
44 MSG(MYDEBUG,"GetElemsByEntity(...)");
45 TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo;
46 MED::TEntityInfo::const_iterator anIter = theEntityInfo.begin();
49 for(; anIter != theEntityInfo.end(); anIter++){
50 const EEntiteMaillage& anEntity = anIter->first;
51 const TGeom2Size& aGeom2Size = anIter->second;
52 TGeom2ElemInfo& aGeom2ElemInfo = anEntity2TGeom2ElemInfo[anEntity];
54 if(anEntity == eNOEUD){
55 aGeom2ElemInfo[ePOINT1] = theWrapper->GetPElemInfo(theMeshInfo);
59 TGeom2Size::const_iterator anIter2 = aGeom2Size.begin();
60 for(; anIter2 != aGeom2Size.end(); anIter2++){
61 const EGeometrieElement& aGeom = anIter2->first;
62 aGeom2ElemInfo[aGeom] = theWrapper->GetPElemInfo(theMeshInfo,anEntity,aGeom,MED::eNOD,&anErr);
66 return anEntity2TGeom2ElemInfo;
70 //---------------------------------------------------------------
72 GetFamilyInfoSet(const PWrapper& theWrapper,
73 const PMeshInfo& theMeshInfo)
75 MSG(MYDEBUG,"GetFamilies(...)");
77 TFamilyInfoSet aFamilyInfoSet;
78 TInt aNbFam = theWrapper->GetNbFamilies(*theMeshInfo);
79 INITMSG(MYDEBUG,"GetNbFamilies() = "<<aNbFam<<"\n");
80 for(TInt iFam = 1; iFam <= aNbFam; iFam++){
81 PFamilyInfo aFamilyInfo = theWrapper->GetPFamilyInfo(theMeshInfo,iFam,&anErr);
83 aFamilyInfoSet.insert(aFamilyInfo);
86 return aFamilyInfoSet;
90 //---------------------------------------------------------------
92 GetGroupInfo(const TFamilyInfoSet& theFamilyInfoSet)
94 MSG(MYDEBUG,"GetFamiliesByGroup(...)");
96 TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
97 for(; anIter != theFamilyInfoSet.end(); anIter++){
98 const PFamilyInfo& aFamilyInfo = *anIter;
99 TInt aNbGroup = aFamilyInfo->GetNbGroup();
100 for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
101 aGroup[aFamilyInfo->GetGroupName(iGroup)].insert(aFamilyInfo);
107 TGroupInfo::const_iterator anIter = aGroup.begin();
108 for(; anIter != aGroup.end(); anIter++){
109 const std::string& aName = anIter->first;
110 INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
111 const TFamilyInfoSet& aFamilyInfoSet = anIter->second;
112 TFamilyInfoSet::const_iterator anFamIter = aFamilyInfoSet.begin();
113 for(; anFamIter != aFamilyInfoSet.end(); anFamIter++){
114 const PFamilyInfo& aFamilyInfo = *anFamIter;
115 INITMSG(MYDEBUG,"aFamilyName = '"<<aFamilyInfo->GetName()<<"'\n");
118 ADDMSG(MYDEBUG,"\n");
126 //---------------------------------------------------------------
127 TFieldInfo2TimeStampInfoSet
128 GetFieldInfo2TimeStampInfoSet(const PWrapper& theWrapper,
129 const PMeshInfo& theMeshInfo,
130 const MED::TEntityInfo& theEntityInfo)
132 MSG(MYDEBUG,"GetFieldsByEntity(...)");
133 TFieldInfo2TimeStampInfoSet aFieldInfo2TimeStampInfoSet;
134 TInt aNbFields = theWrapper->GetNbFields();
135 INITMSG(MYDEBUG,"GetNbFields() = "<<aNbFields<<"\n");
136 for(TInt iField = 1; iField <= aNbFields; iField++){
137 PFieldInfo aFieldInfo = theWrapper->GetPFieldInfo(theMeshInfo,iField);
138 INITMSG(MYDEBUG,"aFieldName = '"<<aFieldInfo->GetName()<<
139 "'; aNbComp = "<<aFieldInfo->GetNbComp()<<"; ");
140 TGeom2Size aGeom2Size;
141 EEntiteMaillage anEntity = EEntiteMaillage(-1);
142 TInt aNbTimeStamps = theWrapper->GetNbTimeStamps(aFieldInfo,theEntityInfo,anEntity,aGeom2Size);
143 ADDMSG(MYDEBUG,"anEntity = "<<anEntity<<"; GetNbTimeStamps = "<<aNbTimeStamps<<"\n");
144 for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
145 PTimeStampInfo aTimeStamp =
146 theWrapper->GetPTimeStampInfo(aFieldInfo,anEntity,aGeom2Size,iTimeStamp);
147 aFieldInfo2TimeStampInfoSet[aFieldInfo].insert(aTimeStamp);
149 "aDt = "<<aTimeStamp->GetDt()<<
150 ", Unit = \'"<<aTimeStamp->GetUnitDt()<<"\n");
153 ADDMSG(MYDEBUG,"\n");
154 return aFieldInfo2TimeStampInfoSet;
158 //---------------------------------------------------------------
159 TEntite2TFieldInfo2TimeStampInfoSet
160 GetEntite2TFieldInfo2TimeStampInfoSet(const TFieldInfo2TimeStampInfoSet& theFieldInfo2TimeStampInfoSet)
162 TEntite2TFieldInfo2TimeStampInfoSet anEntite2TFieldInfo2TimeStampInfoSet;
163 TFieldInfo2TimeStampInfoSet::const_iterator anIter = theFieldInfo2TimeStampInfoSet.begin();
164 for(; anIter != theFieldInfo2TimeStampInfoSet.end(); anIter++){
165 const TTimeStampInfoSet& aTimeStampInfoSet = anIter->second;
166 //const PFieldInfo& aFieldInfo = anIter->first;
167 if(aTimeStampInfoSet.empty())
169 const PTimeStampInfo& aTimeStampInfo = *aTimeStampInfoSet.begin();
170 anEntite2TFieldInfo2TimeStampInfoSet[ConvertEntity(aTimeStampInfo->GetEntity())].insert(*anIter);
172 return anEntite2TFieldInfo2TimeStampInfoSet;
176 //---------------------------------------------------------------
178 operator<(const TFamilyTSize& theLeft, const TFamilyTSize& theRight)
180 const MED::PFamilyInfo& aLeftInfo = boost::get<0>(theLeft);
181 const MED::PFamilyInfo& aRightInfo = boost::get<0>(theRight);
182 return aLeftInfo->GetId() < aRightInfo->GetId();
186 //---------------------------------------------------------------
188 GetEntity2FamilySet(const PWrapper& theWrapper,
189 const TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
190 const TFamilyInfoSet& theFamilyInfoSet)
192 MSG(MYDEBUG,"GetFamiliesByEntity(...)");
193 TEntity2FamilySet anEntity2FamilySet;
195 typedef std::map<TInt,PFamilyInfo> TId2Family;
196 TId2Family anId2Family;
197 TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
198 for(; anIter != theFamilyInfoSet.end(); anIter++){
199 const PFamilyInfo& aFamilyInfo = *anIter;
200 anId2Family.insert(TId2Family::value_type(aFamilyInfo->GetId(),aFamilyInfo));
203 if(!anId2Family.empty()){
204 typedef std::map<TInt,TInt> TFamilyID2Size;
205 typedef std::map<EEntiteMaillage,TFamilyID2Size> TEntity2FamilyID;
206 TEntity2FamilyID anEntity2FamilyID;
208 if(!theEntity2TGeom2ElemInfo.empty()){
209 TEntity2TGeom2ElemInfo::const_iterator anIter = theEntity2TGeom2ElemInfo.begin();
210 for(; anIter != theEntity2TGeom2ElemInfo.end(); anIter++){
211 const EEntiteMaillage& anEntity = anIter->first;
212 TFamilyID2Size& aFamilyID2Size = anEntity2FamilyID[anEntity];
213 const TGeom2ElemInfo& aGeom2ElemInfo = anIter->second;
214 TGeom2ElemInfo::const_iterator aGeom2ElemInfoIter = aGeom2ElemInfo.begin();
215 for(; aGeom2ElemInfoIter != aGeom2ElemInfo.end(); aGeom2ElemInfoIter++){
216 const PElemInfo& aElemInfo = aGeom2ElemInfoIter->second;
217 if(TInt aNbElem = aElemInfo->GetNbElem()){
218 for(TInt i = 0; i < aNbElem; i++){
219 aFamilyID2Size[aElemInfo->GetFamNum(i)] += 1;
226 if(!anEntity2FamilyID.empty()){
227 TEntity2FamilyID::const_iterator anIter = anEntity2FamilyID.begin();
228 for(; anIter != anEntity2FamilyID.end(); anIter++){
229 const EEntiteMaillage& anEntity = anIter->first;
230 INITMSG(MYDEBUG,"anEntity = "<<anEntity<<":\n");
231 const TFamilyID2Size& aFamilyID2Size = anIter->second;
232 TFamilyID2Size::const_iterator anIter2 = aFamilyID2Size.begin();
233 for(; anIter2 != aFamilyID2Size.end(); anIter2++){
234 TInt anId = anIter2->first;
235 TInt aSize = anIter2->second;
236 TId2Family::const_iterator anIter3 = anId2Family.find(anId);
237 if(anIter3 != anId2Family.end()){
238 const PFamilyInfo& aFamilyInfo = anIter3->second;
239 anEntity2FamilySet[anEntity].insert(TFamilyTSize(aFamilyInfo,aSize));
241 "aFamilyName = '"<<aFamilyInfo->GetName()<<
242 "' anId = "<<aFamilyInfo->GetId()<<"\n");
248 ADDMSG(MYDEBUG,"\n");
249 return anEntity2FamilySet;
253 //---------------------------------------------------------------
255 GetKey2Gauss(const PWrapper& theWrapper,
259 INITMSG(MYDEBUG,"GetKey2Gauss - theMode = "<<theMode<<std::endl);
260 TKey2Gauss aKey2Gauss;
261 TInt aNbGauss = theWrapper->GetNbGauss(theErr);
262 for(TInt anId = 1; anId <= aNbGauss; anId++){
263 TGaussInfo::TInfo aPreInfo = theWrapper->GetGaussPreInfo(anId);
264 PGaussInfo anInfo = theWrapper->CrGaussInfo(aPreInfo,theMode);
265 theWrapper->GetGaussInfo(anId,anInfo,theErr);
266 TGaussInfo::TKey aKey = boost::get<0>(aPreInfo);
267 aKey2Gauss[aKey] = anInfo;
270 const EGeometrieElement& aGeom = boost::get<0>(aKey);
271 const std::string& aName = boost::get<1>(aKey);
273 "- aGeom = "<<aGeom<<
274 "; aName = '"<<aName<<"'"<<
283 //---------------------------------------------------------------
285 GetProfileInfo(const PWrapper& theWrapper,
286 const std::string& theProfileName,
291 TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
292 for(TInt anId = 1; anId <= aNbProfiles; anId++){
293 TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
294 const std::string& aName = boost::get<0>(aPreInfo);
295 if(aName == theProfileName)
296 return theWrapper->GetPProfileInfo(anId,theMode,theErr);
302 //---------------------------------------------------------------
304 GetMKey2Profile(const PWrapper& theWrapper,
308 INITMSG(MYDEBUG,"GetMKey2Profile - theMode = "<<theMode<<std::endl);
309 TKey2Profile aKey2Profile;
310 TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
311 for(TInt anId = 1; anId <= aNbProfiles; anId++){
312 TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
313 PProfileInfo anInfo = theWrapper->GetPProfileInfo(anId,theMode,theErr);
314 const std::string& aName = boost::get<0>(aPreInfo);
315 aKey2Profile[aName] = anInfo;
319 "- aName = '"<<aName<<"'"<<
322 TInt aNbElem = anInfo->GetSize();
323 for(TInt iElem = 0; iElem < aNbElem; iElem++){
324 ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
326 ADDMSG(MYVALUEDEBUG, std::endl);
330 return TMKey2Profile(theMode,aKey2Profile);
333 //---------------------------------------------------------------
335 GetEntityByFamilyId(PGrilleInfo& theInfo,TInt theId){
336 TElemNum::iterator aNodeFamIter = (theInfo->myFamNumNode).begin();
337 for(;aNodeFamIter != (theInfo->myFamNumNode).end(); aNodeFamIter++){
338 if(theId == *aNodeFamIter)
341 TElemNum::iterator aCellFamIter = (theInfo->myFamNum).begin();
342 for(;aCellFamIter != (theInfo->myFamNum).end(); aCellFamIter++){
343 if(theId == *aCellFamIter)
346 EXCEPTION(std::runtime_error, "GetEntityByFamilyId - fails");
347 return EEntiteMaillage(-1);
351 GetFamilyID2NbCells(PGrilleInfo& theInfo){
352 TFamilyID2NbCells aFamily2NbCells;
353 TInt aNbNodes = theInfo->myFamNumNode.size();
354 TInt aNbCells = theInfo->myFamNum.size();
355 for(TInt i=0; i<aNbNodes; i++) aFamily2NbCells[theInfo->GetFamNumNode(i)] = 0;
356 for(TInt i=0; i<aNbCells; i++) aFamily2NbCells[theInfo->GetFamNum(i)] = 0;
357 for(TInt i=0; i<aNbNodes; i++) aFamily2NbCells[theInfo->GetFamNumNode(i)] += 1;
358 for(TInt i=0; i<aNbCells; i++) aFamily2NbCells[theInfo->GetFamNum(i)] += 1;
359 return aFamily2NbCells;
362 EEntiteMaillage ConvertEntity(const EEntiteMaillage& aEntity){
366 case eMAILLE: return eMAILLE; //eNOEUD_ELEMENT it is eMAILLE
370 case eNOEUD: return aEntity; break;
371 default: return EEntiteMaillage(-1);