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();
53 for(; anIter != theEntityInfo.end(); anIter++){
54 const EEntiteMaillage& anEntity = anIter->first;
55 const TGeom2Size& aGeom2Size = anIter->second;
56 TGeom2ElemInfo& aGeom2ElemInfo = anEntity2TGeom2ElemInfo[anEntity];
58 if(anEntity == eNOEUD){
59 aGeom2ElemInfo[ePOINT1] = theWrapper->GetPNodeInfo(theMeshInfo);
63 TGeom2Size::const_iterator anIter2 = aGeom2Size.begin();
64 for(; anIter2 != aGeom2Size.end(); anIter2++){
65 const EGeometrieElement& aGeom = anIter2->first;
68 aGeom2ElemInfo[ePOLYGONE] = theWrapper->GetPPolygoneInfo(theMeshInfo,anEntity,aGeom);
72 aGeom2ElemInfo[ePOLYEDRE] = theWrapper->GetPPolyedreInfo(theMeshInfo,anEntity,aGeom);
76 aGeom2ElemInfo[aGeom] = theWrapper->GetPCellInfo(theMeshInfo,anEntity,aGeom);
82 return anEntity2TGeom2ElemInfo;
86 //---------------------------------------------------------------
88 GetFamilyInfoSet(const PWrapper& theWrapper,
89 const PMeshInfo& theMeshInfo)
91 MSG(MYDEBUG,"GetFamilies(...)");
93 TFamilyInfoSet aFamilyInfoSet;
94 TInt aNbFam = theWrapper->GetNbFamilies(*theMeshInfo);
95 INITMSG(MYDEBUG,"GetNbFamilies() = "<<aNbFam<<"\n");
96 for(TInt iFam = 1; iFam <= aNbFam; iFam++){
97 PFamilyInfo aFamilyInfo = theWrapper->GetPFamilyInfo(theMeshInfo,iFam,&anErr);
99 aFamilyInfoSet.insert(aFamilyInfo);
101 ADDMSG(MYDEBUG,"\n");
102 return aFamilyInfoSet;
106 //---------------------------------------------------------------
108 GetGroupInfo(const TFamilyInfoSet& theFamilyInfoSet)
110 MSG(MYDEBUG,"GetFamiliesByGroup(...)");
112 TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
113 for(; anIter != theFamilyInfoSet.end(); anIter++){
114 const PFamilyInfo& aFamilyInfo = *anIter;
115 TInt aNbGroup = aFamilyInfo->GetNbGroup();
116 for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
117 aGroup[aFamilyInfo->GetGroupName(iGroup)].insert(aFamilyInfo);
123 TGroupInfo::const_iterator anIter = aGroup.begin();
124 for(; anIter != aGroup.end(); anIter++){
125 const std::string& aName = anIter->first;
126 INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
127 const TFamilyInfoSet& aFamilyInfoSet = anIter->second;
128 TFamilyInfoSet::const_iterator anFamIter = aFamilyInfoSet.begin();
129 for(; anFamIter != aFamilyInfoSet.end(); anFamIter++){
130 const PFamilyInfo& aFamilyInfo = *anFamIter;
131 INITMSG(MYDEBUG,"aFamilyName = '"<<aFamilyInfo->GetName()<<"'\n");
134 ADDMSG(MYDEBUG,"\n");
142 //---------------------------------------------------------------
143 TFieldInfo2TimeStampInfoSet
144 GetFieldInfo2TimeStampInfoSet(const PWrapper& theWrapper,
145 const PMeshInfo& theMeshInfo,
146 const MED::TEntityInfo& theEntityInfo)
148 MSG(MYDEBUG,"GetFieldsByEntity(...)");
149 TFieldInfo2TimeStampInfoSet aFieldInfo2TimeStampInfoSet;
150 TInt aNbFields = theWrapper->GetNbFields();
151 INITMSG(MYDEBUG,"GetNbFields() = "<<aNbFields<<"\n");
152 for(TInt iField = 1; iField <= aNbFields; iField++){
153 PFieldInfo aFieldInfo = theWrapper->GetPFieldInfo(theMeshInfo,iField);
154 INITMSG(MYDEBUG,"aFieldName = '"<<aFieldInfo->GetName()<<
155 "'; aNbComp = "<<aFieldInfo->GetNbComp()<<"; ");
156 TGeom2Size aGeom2Size;
157 EEntiteMaillage anEntity = EEntiteMaillage(-1);
158 TInt aNbTimeStamps = theWrapper->GetNbTimeStamps(aFieldInfo,theEntityInfo,anEntity,aGeom2Size);
159 ADDMSG(MYDEBUG,"anEntity = "<<anEntity<<"; GetNbTimeStamps = "<<aNbTimeStamps<<"\n");
160 for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
161 PTimeStampInfo aTimeStamp =
162 theWrapper->GetPTimeStampInfo(aFieldInfo,anEntity,aGeom2Size,iTimeStamp);
163 aFieldInfo2TimeStampInfoSet[aFieldInfo].insert(aTimeStamp);
165 "aDt = "<<aTimeStamp->GetDt()<<
166 ", Unit = \'"<<aTimeStamp->GetUnitDt()<<"\n");
169 ADDMSG(MYDEBUG,"\n");
170 return aFieldInfo2TimeStampInfoSet;
174 //---------------------------------------------------------------
175 TEntite2TFieldInfo2TimeStampInfoSet
176 GetEntite2TFieldInfo2TimeStampInfoSet(const TFieldInfo2TimeStampInfoSet& theFieldInfo2TimeStampInfoSet)
178 TEntite2TFieldInfo2TimeStampInfoSet anEntite2TFieldInfo2TimeStampInfoSet;
179 TFieldInfo2TimeStampInfoSet::const_iterator anIter = theFieldInfo2TimeStampInfoSet.begin();
180 for(; anIter != theFieldInfo2TimeStampInfoSet.end(); anIter++){
181 const TTimeStampInfoSet& aTimeStampInfoSet = anIter->second;
182 //const PFieldInfo& aFieldInfo = anIter->first;
183 if(aTimeStampInfoSet.empty())
185 const PTimeStampInfo& aTimeStampInfo = *aTimeStampInfoSet.begin();
186 anEntite2TFieldInfo2TimeStampInfoSet[aTimeStampInfo->GetEntity()].insert(*anIter);
188 return anEntite2TFieldInfo2TimeStampInfoSet;
192 //---------------------------------------------------------------
194 operator<(const TFamilyTSize& theLeft, const TFamilyTSize& theRight)
196 const MED::PFamilyInfo& aLeftInfo = boost::get<0>(theLeft);
197 const MED::PFamilyInfo& aRightInfo = boost::get<0>(theRight);
198 return aLeftInfo->GetId() < aRightInfo->GetId();
202 //---------------------------------------------------------------
204 GetEntity2FamilySet(const PWrapper& theWrapper,
205 const TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
206 const TFamilyInfoSet& theFamilyInfoSet)
208 MSG(MYDEBUG,"GetFamiliesByEntity(...)");
209 TEntity2FamilySet anEntity2FamilySet;
211 typedef map<TInt,PFamilyInfo> TId2Family;
212 TId2Family anId2Family;
213 TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
214 for(; anIter != theFamilyInfoSet.end(); anIter++){
215 const PFamilyInfo& aFamilyInfo = *anIter;
216 anId2Family.insert(TId2Family::value_type(aFamilyInfo->GetId(),aFamilyInfo));
219 if(!anId2Family.empty()){
220 typedef std::map<TInt,TInt> TFamilyID2Size;
221 typedef map<EEntiteMaillage,TFamilyID2Size> TEntity2FamilyID;
222 TEntity2FamilyID anEntity2FamilyID;
224 if(!theEntity2TGeom2ElemInfo.empty()){
225 TEntity2TGeom2ElemInfo::const_iterator anIter = theEntity2TGeom2ElemInfo.begin();
226 for(; anIter != theEntity2TGeom2ElemInfo.end(); anIter++){
227 const EEntiteMaillage& anEntity = anIter->first;
228 TFamilyID2Size& aFamilyID2Size = anEntity2FamilyID[anEntity];
229 const TGeom2ElemInfo& aGeom2ElemInfo = anIter->second;
230 TGeom2ElemInfo::const_iterator aGeom2ElemInfoIter = aGeom2ElemInfo.begin();
231 for(; aGeom2ElemInfoIter != aGeom2ElemInfo.end(); aGeom2ElemInfoIter++){
232 const PElemInfo& aElemInfo = aGeom2ElemInfoIter->second;
233 if(TInt aNbElem = aElemInfo->GetNbElem()){
234 for(TInt i = 0; i < aNbElem; i++){
235 aFamilyID2Size[aElemInfo->GetFamNum(i)] += 1;
242 if(!anEntity2FamilyID.empty()){
243 TEntity2FamilyID::const_iterator anIter = anEntity2FamilyID.begin();
244 for(; anIter != anEntity2FamilyID.end(); anIter++){
245 const EEntiteMaillage& anEntity = anIter->first;
246 INITMSG(MYDEBUG,"anEntity = "<<anEntity<<":\n");
247 const TFamilyID2Size& aFamilyID2Size = anIter->second;
248 TFamilyID2Size::const_iterator anIter2 = aFamilyID2Size.begin();
249 for(; anIter2 != aFamilyID2Size.end(); anIter2++){
250 TInt anId = anIter2->first;
251 TInt aSize = anIter2->second;
252 TId2Family::const_iterator anIter3 = anId2Family.find(anId);
253 if(anIter3 != anId2Family.end()){
254 const PFamilyInfo& aFamilyInfo = anIter3->second;
255 anEntity2FamilySet[anEntity].insert(TFamilyTSize(aFamilyInfo,aSize));
257 "aFamilyName = '"<<aFamilyInfo->GetName()<<
258 "' anId = "<<aFamilyInfo->GetId()<<"\n");
264 ADDMSG(MYDEBUG,"\n");
265 return anEntity2FamilySet;
269 //---------------------------------------------------------------
271 GetKey2Gauss(const PWrapper& theWrapper,
275 INITMSG(MYDEBUG,"GetKey2Gauss - theMode = "<<theMode<<endl);
276 TKey2Gauss aKey2Gauss;
277 TInt aNbGauss = theWrapper->GetNbGauss(theErr);
278 for(TInt anId = 1; anId <= aNbGauss; anId++){
279 TGaussInfo::TInfo aPreInfo = theWrapper->GetGaussPreInfo(anId);
280 PGaussInfo anInfo = theWrapper->CrGaussInfo(aPreInfo,theMode);
281 theWrapper->GetGaussInfo(anId,anInfo,theErr);
282 TGaussInfo::TKey aKey = boost::get<0>(aPreInfo);
283 aKey2Gauss[aKey] = anInfo;
286 const EGeometrieElement& aGeom = boost::get<0>(aKey);
287 const std::string& aName = boost::get<1>(aKey);
289 "- aGeom = "<<aGeom<<
290 "; aName = '"<<aName<<"'"<<
299 //---------------------------------------------------------------
301 GetProfileInfo(const PWrapper& theWrapper,
302 const std::string& theProfileName,
307 TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
308 for(TInt anId = 1; anId <= aNbProfiles; anId++){
309 TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
310 const std::string& aName = boost::get<0>(aPreInfo);
311 if(aName == theProfileName)
312 return theWrapper->GetPProfileInfo(anId,theMode,theErr);
318 //---------------------------------------------------------------
320 GetMKey2Profile(const PWrapper& theWrapper,
324 INITMSG(MYDEBUG,"GetMKey2Profile - theMode = "<<theMode<<endl);
325 TKey2Profile aKey2Profile;
326 TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
327 for(TInt anId = 1; anId <= aNbProfiles; anId++){
328 TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
329 PProfileInfo anInfo = theWrapper->GetPProfileInfo(anId,theMode,theErr);
330 const std::string& aName = boost::get<0>(aPreInfo);
331 aKey2Profile[aName] = anInfo;
335 "- aName = '"<<aName<<"'"<<
338 TInt aNbElem = anInfo->myElemNum.size();
339 for(TInt iElem = 0; iElem < aNbElem; iElem++){
340 ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
342 ADDMSG(MYVALUEDEBUG,endl);
346 return TMKey2Profile(theMode,aKey2Profile);