3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
29 #include "MED_Algorithm.hxx"
30 #include "MED_Wrapper.hxx"
32 #include "MED_Utilities.hxx"
35 static int MYDEBUG = 0;
36 static int MYVALUEDEBUG = 0;
38 static int MYDEBUG = 0;
39 static int MYVALUEDEBUG = 0;
44 //---------------------------------------------------------------
45 TEntity2TGeom2ElemInfo
46 GetEntity2TGeom2ElemInfo(const PWrapper& theWrapper,
47 const PMeshInfo& theMeshInfo,
48 const MED::TEntityInfo& theEntityInfo)
50 MSG(MYDEBUG,"GetElemsByEntity(...)");
51 TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo;
52 MED::TEntityInfo::const_iterator anIter = theEntityInfo.begin();
55 for(; anIter != theEntityInfo.end(); anIter++){
56 const EEntiteMaillage& anEntity = anIter->first;
57 const TGeom2Size& aGeom2Size = anIter->second;
58 TGeom2ElemInfo& aGeom2ElemInfo = anEntity2TGeom2ElemInfo[anEntity];
60 if(anEntity == eNOEUD){
61 aGeom2ElemInfo[ePOINT1] = theWrapper->GetPElemInfo(theMeshInfo);
65 TGeom2Size::const_iterator anIter2 = aGeom2Size.begin();
66 for(; anIter2 != aGeom2Size.end(); anIter2++){
67 const EGeometrieElement& aGeom = anIter2->first;
68 aGeom2ElemInfo[aGeom] = theWrapper->GetPElemInfo(theMeshInfo,anEntity,aGeom,MED::eNOD,&anErr);
72 return anEntity2TGeom2ElemInfo;
76 //---------------------------------------------------------------
78 GetFamilyInfoSet(const PWrapper& theWrapper,
79 const PMeshInfo& theMeshInfo)
81 MSG(MYDEBUG,"GetFamilies(...)");
83 TFamilyInfoSet aFamilyInfoSet;
84 TInt aNbFam = theWrapper->GetNbFamilies(*theMeshInfo);
85 INITMSG(MYDEBUG,"GetNbFamilies() = "<<aNbFam<<"\n");
86 for(TInt iFam = 1; iFam <= aNbFam; iFam++){
87 PFamilyInfo aFamilyInfo = theWrapper->GetPFamilyInfo(theMeshInfo,iFam,&anErr);
89 aFamilyInfoSet.insert(aFamilyInfo);
92 return aFamilyInfoSet;
96 //---------------------------------------------------------------
98 GetGroupInfo(const TFamilyInfoSet& theFamilyInfoSet)
100 MSG(MYDEBUG,"GetFamiliesByGroup(...)");
102 TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
103 for(; anIter != theFamilyInfoSet.end(); anIter++){
104 const PFamilyInfo& aFamilyInfo = *anIter;
105 TInt aNbGroup = aFamilyInfo->GetNbGroup();
106 for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
107 aGroup[aFamilyInfo->GetGroupName(iGroup)].insert(aFamilyInfo);
113 TGroupInfo::const_iterator anIter = aGroup.begin();
114 for(; anIter != aGroup.end(); anIter++){
115 const std::string& aName = anIter->first;
116 INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
117 const TFamilyInfoSet& aFamilyInfoSet = anIter->second;
118 TFamilyInfoSet::const_iterator anFamIter = aFamilyInfoSet.begin();
119 for(; anFamIter != aFamilyInfoSet.end(); anFamIter++){
120 const PFamilyInfo& aFamilyInfo = *anFamIter;
121 INITMSG(MYDEBUG,"aFamilyName = '"<<aFamilyInfo->GetName()<<"'\n");
124 ADDMSG(MYDEBUG,"\n");
132 //---------------------------------------------------------------
133 TFieldInfo2TimeStampInfoSet
134 GetFieldInfo2TimeStampInfoSet(const PWrapper& theWrapper,
135 const PMeshInfo& theMeshInfo,
136 const MED::TEntityInfo& theEntityInfo)
138 MSG(MYDEBUG,"GetFieldsByEntity(...)");
139 TFieldInfo2TimeStampInfoSet aFieldInfo2TimeStampInfoSet;
140 TInt aNbFields = theWrapper->GetNbFields();
141 INITMSG(MYDEBUG,"GetNbFields() = "<<aNbFields<<"\n");
142 for(TInt iField = 1; iField <= aNbFields; iField++){
143 PFieldInfo aFieldInfo = theWrapper->GetPFieldInfo(theMeshInfo,iField);
144 INITMSG(MYDEBUG,"aFieldName = '"<<aFieldInfo->GetName()<<
145 "'; aNbComp = "<<aFieldInfo->GetNbComp()<<"; ");
146 TGeom2Size aGeom2Size;
147 EEntiteMaillage anEntity = EEntiteMaillage(-1);
148 TInt aNbTimeStamps = theWrapper->GetNbTimeStamps(aFieldInfo,theEntityInfo,anEntity,aGeom2Size);
149 ADDMSG(MYDEBUG,"anEntity = "<<anEntity<<"; GetNbTimeStamps = "<<aNbTimeStamps<<"\n");
150 for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
151 PTimeStampInfo aTimeStamp =
152 theWrapper->GetPTimeStampInfo(aFieldInfo,anEntity,aGeom2Size,iTimeStamp);
153 aFieldInfo2TimeStampInfoSet[aFieldInfo].insert(aTimeStamp);
155 "aDt = "<<aTimeStamp->GetDt()<<
156 ", Unit = \'"<<aTimeStamp->GetUnitDt()<<"\n");
159 ADDMSG(MYDEBUG,"\n");
160 return aFieldInfo2TimeStampInfoSet;
164 //---------------------------------------------------------------
165 TEntite2TFieldInfo2TimeStampInfoSet
166 GetEntite2TFieldInfo2TimeStampInfoSet(const TFieldInfo2TimeStampInfoSet& theFieldInfo2TimeStampInfoSet)
168 TEntite2TFieldInfo2TimeStampInfoSet anEntite2TFieldInfo2TimeStampInfoSet;
169 TFieldInfo2TimeStampInfoSet::const_iterator anIter = theFieldInfo2TimeStampInfoSet.begin();
170 for(; anIter != theFieldInfo2TimeStampInfoSet.end(); anIter++){
171 const TTimeStampInfoSet& aTimeStampInfoSet = anIter->second;
172 //const PFieldInfo& aFieldInfo = anIter->first;
173 if(aTimeStampInfoSet.empty())
175 const PTimeStampInfo& aTimeStampInfo = *aTimeStampInfoSet.begin();
176 anEntite2TFieldInfo2TimeStampInfoSet[aTimeStampInfo->GetEntity()].insert(*anIter);
178 return anEntite2TFieldInfo2TimeStampInfoSet;
182 //---------------------------------------------------------------
184 operator<(const TFamilyTSize& theLeft, const TFamilyTSize& theRight)
186 const MED::PFamilyInfo& aLeftInfo = boost::get<0>(theLeft);
187 const MED::PFamilyInfo& aRightInfo = boost::get<0>(theRight);
188 return aLeftInfo->GetId() < aRightInfo->GetId();
192 //---------------------------------------------------------------
194 GetEntity2FamilySet(const PWrapper& theWrapper,
195 const TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
196 const TFamilyInfoSet& theFamilyInfoSet)
198 MSG(MYDEBUG,"GetFamiliesByEntity(...)");
199 TEntity2FamilySet anEntity2FamilySet;
201 typedef map<TInt,PFamilyInfo> TId2Family;
202 TId2Family anId2Family;
203 TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
204 for(; anIter != theFamilyInfoSet.end(); anIter++){
205 const PFamilyInfo& aFamilyInfo = *anIter;
206 anId2Family.insert(TId2Family::value_type(aFamilyInfo->GetId(),aFamilyInfo));
209 if(!anId2Family.empty()){
210 typedef std::map<TInt,TInt> TFamilyID2Size;
211 typedef map<EEntiteMaillage,TFamilyID2Size> TEntity2FamilyID;
212 TEntity2FamilyID anEntity2FamilyID;
214 if(!theEntity2TGeom2ElemInfo.empty()){
215 TEntity2TGeom2ElemInfo::const_iterator anIter = theEntity2TGeom2ElemInfo.begin();
216 for(; anIter != theEntity2TGeom2ElemInfo.end(); anIter++){
217 const EEntiteMaillage& anEntity = anIter->first;
218 TFamilyID2Size& aFamilyID2Size = anEntity2FamilyID[anEntity];
219 const TGeom2ElemInfo& aGeom2ElemInfo = anIter->second;
220 TGeom2ElemInfo::const_iterator aGeom2ElemInfoIter = aGeom2ElemInfo.begin();
221 for(; aGeom2ElemInfoIter != aGeom2ElemInfo.end(); aGeom2ElemInfoIter++){
222 const PElemInfo& aElemInfo = aGeom2ElemInfoIter->second;
223 if(TInt aNbElem = aElemInfo->GetNbElem()){
224 for(TInt i = 0; i < aNbElem; i++){
225 aFamilyID2Size[aElemInfo->GetFamNum(i)] += 1;
232 if(!anEntity2FamilyID.empty()){
233 TEntity2FamilyID::const_iterator anIter = anEntity2FamilyID.begin();
234 for(; anIter != anEntity2FamilyID.end(); anIter++){
235 const EEntiteMaillage& anEntity = anIter->first;
236 INITMSG(MYDEBUG,"anEntity = "<<anEntity<<":\n");
237 const TFamilyID2Size& aFamilyID2Size = anIter->second;
238 TFamilyID2Size::const_iterator anIter2 = aFamilyID2Size.begin();
239 for(; anIter2 != aFamilyID2Size.end(); anIter2++){
240 TInt anId = anIter2->first;
241 TInt aSize = anIter2->second;
242 TId2Family::const_iterator anIter3 = anId2Family.find(anId);
243 if(anIter3 != anId2Family.end()){
244 const PFamilyInfo& aFamilyInfo = anIter3->second;
245 anEntity2FamilySet[anEntity].insert(TFamilyTSize(aFamilyInfo,aSize));
247 "aFamilyName = '"<<aFamilyInfo->GetName()<<
248 "' anId = "<<aFamilyInfo->GetId()<<"\n");
254 ADDMSG(MYDEBUG,"\n");
255 return anEntity2FamilySet;
259 //---------------------------------------------------------------
261 GetKey2Gauss(const PWrapper& theWrapper,
265 INITMSG(MYDEBUG,"GetKey2Gauss - theMode = "<<theMode<<endl);
266 TKey2Gauss aKey2Gauss;
267 TInt aNbGauss = theWrapper->GetNbGauss(theErr);
268 for(TInt anId = 1; anId <= aNbGauss; anId++){
269 TGaussInfo::TInfo aPreInfo = theWrapper->GetGaussPreInfo(anId);
270 PGaussInfo anInfo = theWrapper->CrGaussInfo(aPreInfo,theMode);
271 theWrapper->GetGaussInfo(anId,anInfo,theErr);
272 TGaussInfo::TKey aKey = boost::get<0>(aPreInfo);
273 aKey2Gauss[aKey] = anInfo;
276 const EGeometrieElement& aGeom = boost::get<0>(aKey);
277 const std::string& aName = boost::get<1>(aKey);
279 "- aGeom = "<<aGeom<<
280 "; aName = '"<<aName<<"'"<<
289 //---------------------------------------------------------------
291 GetProfileInfo(const PWrapper& theWrapper,
292 const std::string& theProfileName,
297 TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
298 for(TInt anId = 1; anId <= aNbProfiles; anId++){
299 TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
300 const std::string& aName = boost::get<0>(aPreInfo);
301 if(aName == theProfileName)
302 return theWrapper->GetPProfileInfo(anId,theMode,theErr);
308 //---------------------------------------------------------------
310 GetMKey2Profile(const PWrapper& theWrapper,
314 INITMSG(MYDEBUG,"GetMKey2Profile - theMode = "<<theMode<<endl);
315 TKey2Profile aKey2Profile;
316 TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
317 for(TInt anId = 1; anId <= aNbProfiles; anId++){
318 TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
319 PProfileInfo anInfo = theWrapper->GetPProfileInfo(anId,theMode,theErr);
320 const std::string& aName = boost::get<0>(aPreInfo);
321 aKey2Profile[aName] = anInfo;
325 "- aName = '"<<aName<<"'"<<
328 TInt aNbElem = anInfo->myElemNum.size();
329 for(TInt iElem = 0; iElem < aNbElem; iElem++){
330 ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
332 ADDMSG(MYVALUEDEBUG,endl);
336 return TMKey2Profile(theMode,aKey2Profile);