]> SALOME platform Git repositories - modules/med.git/blob - src/MEDWrapper/Base/MED_Algorithm.cxx
Salome HOME
6f523efec17be51508123ab298f62d0da3407cf1
[modules/med.git] / src / MEDWrapper / Base / MED_Algorithm.cxx
1 //  
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : 
25 //  Author : 
26 //  Module : 
27 //  $Header$
28
29 #include "MED_Algorithm.hxx"
30 #include "MED_Wrapper.hxx"
31
32 #include "MED_Utilities.hxx"
33  
34 #ifdef _DEBUG_
35 static int MYDEBUG = 0;
36 static int MYVALUEDEBUG = 0;
37 #else
38 static int MYDEBUG = 0;
39 static int MYVALUEDEBUG = 0;
40 #endif
41
42 namespace MED
43 {
44   //---------------------------------------------------------------
45   TEntity2TGeom2ElemInfo 
46   GetEntity2TGeom2ElemInfo(const PWrapper& theWrapper, 
47                            const PMeshInfo& theMeshInfo,
48                            const MED::TEntityInfo& theEntityInfo)
49   {
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];
57
58       if(anEntity == eNOEUD){
59         aGeom2ElemInfo[ePOINT1] = theWrapper->GetPNodeInfo(theMeshInfo);
60         continue;
61       }
62
63       TGeom2Size::const_iterator anIter2 = aGeom2Size.begin();
64       for(; anIter2 != aGeom2Size.end(); anIter2++){
65         const EGeometrieElement& aGeom = anIter2->first;
66         switch(aGeom){
67         case ePOLYGONE: {
68           aGeom2ElemInfo[ePOLYGONE] = theWrapper->GetPPolygoneInfo(theMeshInfo,anEntity,aGeom);
69           break;
70         }
71         case ePOLYEDRE: {
72           aGeom2ElemInfo[ePOLYEDRE] = theWrapper->GetPPolyedreInfo(theMeshInfo,anEntity,aGeom);
73           break;
74         }
75         default: {
76           aGeom2ElemInfo[aGeom] = theWrapper->GetPCellInfo(theMeshInfo,anEntity,aGeom);
77         }}
78
79       }
80     }
81     ADDMSG(MYDEBUG,"\n");
82     return anEntity2TGeom2ElemInfo;
83   }
84   
85   
86   //---------------------------------------------------------------
87   TFamilyInfoSet
88   GetFamilyInfoSet(const PWrapper& theWrapper,
89                    const PMeshInfo& theMeshInfo)
90   {
91     MSG(MYDEBUG,"GetFamilies(...)");
92     TErr anErr;
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);
98       if(anErr >= 0)
99         aFamilyInfoSet.insert(aFamilyInfo);
100     }
101     ADDMSG(MYDEBUG,"\n");
102     return aFamilyInfoSet;
103   }
104
105
106   //---------------------------------------------------------------
107   TGroupInfo
108   GetGroupInfo(const TFamilyInfoSet& theFamilyInfoSet)
109   {
110     MSG(MYDEBUG,"GetFamiliesByGroup(...)");
111     TGroupInfo aGroup;
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);
118       } 
119     }
120
121 #ifdef _DEBUG_
122     if(MYDEBUG){
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");
132         }
133       }
134       ADDMSG(MYDEBUG,"\n");
135     }
136 #endif
137
138     return aGroup;
139   }
140
141
142   //---------------------------------------------------------------
143   TFieldInfo2TimeStampInfoSet 
144   GetFieldInfo2TimeStampInfoSet(const PWrapper& theWrapper, 
145                                 const PMeshInfo& theMeshInfo,
146                                 const MED::TEntityInfo& theEntityInfo)
147   {
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);
164         INITMSG(MYDEBUG,
165                 "aDt = "<<aTimeStamp->GetDt()<<
166                 ", Unit = \'"<<aTimeStamp->GetUnitDt()<<"\n");
167       }
168     }
169     ADDMSG(MYDEBUG,"\n");
170     return aFieldInfo2TimeStampInfoSet;
171   }
172   
173
174   //---------------------------------------------------------------
175   TEntite2TFieldInfo2TimeStampInfoSet 
176   GetEntite2TFieldInfo2TimeStampInfoSet(const TFieldInfo2TimeStampInfoSet& theFieldInfo2TimeStampInfoSet)
177   {
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()) 
184         continue;
185       const PTimeStampInfo& aTimeStampInfo = *aTimeStampInfoSet.begin();
186       anEntite2TFieldInfo2TimeStampInfoSet[aTimeStampInfo->GetEntity()].insert(*anIter);
187     }
188     return anEntite2TFieldInfo2TimeStampInfoSet;
189   }
190   
191
192   //---------------------------------------------------------------
193   bool
194   operator<(const TFamilyTSize& theLeft, const TFamilyTSize& theRight)
195   {
196     const MED::PFamilyInfo& aLeftInfo = boost::get<0>(theLeft);
197     const MED::PFamilyInfo& aRightInfo = boost::get<0>(theRight);
198     return aLeftInfo->GetId() < aRightInfo->GetId();
199   }
200
201
202   //---------------------------------------------------------------
203   TEntity2FamilySet 
204   GetEntity2FamilySet(const PWrapper& theWrapper, 
205                       const TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
206                       const TFamilyInfoSet& theFamilyInfoSet)
207   {
208     MSG(MYDEBUG,"GetFamiliesByEntity(...)");
209     TEntity2FamilySet anEntity2FamilySet;
210     
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));
217     }
218     
219     if(!anId2Family.empty()){
220       typedef std::map<TInt,TInt> TFamilyID2Size;
221       typedef map<EEntiteMaillage,TFamilyID2Size> TEntity2FamilyID;
222       TEntity2FamilyID anEntity2FamilyID;
223       
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;
236               }
237             }
238           }
239         }
240       }
241       
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));
256               INITMSG(MYDEBUG,
257                       "aFamilyName = '"<<aFamilyInfo->GetName()<<
258                       "' anId = "<<aFamilyInfo->GetId()<<"\n");
259             }
260           }
261         }
262       }
263     }    
264     ADDMSG(MYDEBUG,"\n");
265     return anEntity2FamilySet;
266   }
267   
268
269   //---------------------------------------------------------------
270   TKey2Gauss
271   GetKey2Gauss(const PWrapper& theWrapper, 
272                TErr* theErr,
273                EModeSwitch theMode)
274   {
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;
284
285 #ifdef _DEBUG_
286       const EGeometrieElement& aGeom = boost::get<0>(aKey);
287       const std::string& aName = boost::get<1>(aKey);
288       INITMSG(MYDEBUG,
289               "- aGeom = "<<aGeom<<
290               "; aName = '"<<aName<<"'"<<
291               endl);
292 #endif
293
294     }
295     return aKey2Gauss;
296   }
297
298
299   //---------------------------------------------------------------
300   PProfileInfo
301   GetProfileInfo(const PWrapper& theWrapper, 
302                  const std::string& theProfileName,
303                  TErr* theErr,
304                  EModeProfil theMode)
305   {
306     PProfileInfo anInfo;
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);
313     }
314     return anInfo;
315   }
316   
317
318   //---------------------------------------------------------------
319   TMKey2Profile
320   GetMKey2Profile(const PWrapper& theWrapper, 
321                   TErr* theErr,
322                   EModeProfil theMode)
323   {
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;
332       
333 #ifdef _DEBUG_
334       INITMSG(MYDEBUG,
335               "- aName = '"<<aName<<"'"<<
336               " : "<<
337               endl);
338       TInt aNbElem = anInfo->myElemNum.size();
339       for(TInt iElem = 0; iElem < aNbElem; iElem++){
340         ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
341       }
342       ADDMSG(MYVALUEDEBUG,endl);
343 #endif
344       
345     }
346     return TMKey2Profile(theMode,aKey2Profile);
347   }
348
349 }