]> SALOME platform Git repositories - modules/med.git/blob - src/MEDWrapper/Base/MED_Algorithm.cxx
Salome HOME
Join modifications from branch CEAFor_V3_2_0
[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     PElemInfo anElemInfo;
54     TErr anErr;
55     for(; anIter != theEntityInfo.end(); anIter++){
56       const EEntiteMaillage& anEntity = anIter->first;
57       const TGeom2Size& aGeom2Size = anIter->second;
58       TGeom2ElemInfo& aGeom2ElemInfo = anEntity2TGeom2ElemInfo[anEntity];
59
60       if(anEntity == eNOEUD){
61         aGeom2ElemInfo[ePOINT1] = theWrapper->GetPElemInfo(theMeshInfo);
62         continue;
63       }
64
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);
69       }
70     }
71     ADDMSG(MYDEBUG,"\n");
72     return anEntity2TGeom2ElemInfo;
73   }
74   
75   
76   //---------------------------------------------------------------
77   TFamilyInfoSet
78   GetFamilyInfoSet(const PWrapper& theWrapper,
79                    const PMeshInfo& theMeshInfo)
80   {
81     MSG(MYDEBUG,"GetFamilies(...)");
82     TErr anErr;
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);
88       if(anErr >= 0)
89         aFamilyInfoSet.insert(aFamilyInfo);
90     }
91     ADDMSG(MYDEBUG,"\n");
92     return aFamilyInfoSet;
93   }
94
95
96   //---------------------------------------------------------------
97   TGroupInfo
98   GetGroupInfo(const TFamilyInfoSet& theFamilyInfoSet)
99   {
100     MSG(MYDEBUG,"GetFamiliesByGroup(...)");
101     TGroupInfo aGroup;
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);
108       } 
109     }
110
111 #ifdef _DEBUG_
112     if(MYDEBUG){
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");
122         }
123       }
124       ADDMSG(MYDEBUG,"\n");
125     }
126 #endif
127
128     return aGroup;
129   }
130
131
132   //---------------------------------------------------------------
133   TFieldInfo2TimeStampInfoSet 
134   GetFieldInfo2TimeStampInfoSet(const PWrapper& theWrapper, 
135                                 const PMeshInfo& theMeshInfo,
136                                 const MED::TEntityInfo& theEntityInfo)
137   {
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);
154         INITMSG(MYDEBUG,
155                 "aDt = "<<aTimeStamp->GetDt()<<
156                 ", Unit = \'"<<aTimeStamp->GetUnitDt()<<"\n");
157       }
158     }
159     ADDMSG(MYDEBUG,"\n");
160     return aFieldInfo2TimeStampInfoSet;
161   }
162   
163
164   //---------------------------------------------------------------
165   TEntite2TFieldInfo2TimeStampInfoSet 
166   GetEntite2TFieldInfo2TimeStampInfoSet(const TFieldInfo2TimeStampInfoSet& theFieldInfo2TimeStampInfoSet)
167   {
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()) 
174         continue;
175       const PTimeStampInfo& aTimeStampInfo = *aTimeStampInfoSet.begin();
176       anEntite2TFieldInfo2TimeStampInfoSet[aTimeStampInfo->GetEntity()].insert(*anIter);
177     }
178     return anEntite2TFieldInfo2TimeStampInfoSet;
179   }
180   
181
182   //---------------------------------------------------------------
183   bool
184   operator<(const TFamilyTSize& theLeft, const TFamilyTSize& theRight)
185   {
186     const MED::PFamilyInfo& aLeftInfo = boost::get<0>(theLeft);
187     const MED::PFamilyInfo& aRightInfo = boost::get<0>(theRight);
188     return aLeftInfo->GetId() < aRightInfo->GetId();
189   }
190
191
192   //---------------------------------------------------------------
193   TEntity2FamilySet 
194   GetEntity2FamilySet(const PWrapper& theWrapper, 
195                       const TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
196                       const TFamilyInfoSet& theFamilyInfoSet)
197   {
198     MSG(MYDEBUG,"GetFamiliesByEntity(...)");
199     TEntity2FamilySet anEntity2FamilySet;
200     
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));
207     }
208     
209     if(!anId2Family.empty()){
210       typedef std::map<TInt,TInt> TFamilyID2Size;
211       typedef map<EEntiteMaillage,TFamilyID2Size> TEntity2FamilyID;
212       TEntity2FamilyID anEntity2FamilyID;
213       
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;
226               }
227             }
228           }
229         }
230       }
231       
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));
246               INITMSG(MYDEBUG,
247                       "aFamilyName = '"<<aFamilyInfo->GetName()<<
248                       "' anId = "<<aFamilyInfo->GetId()<<"\n");
249             }
250           }
251         }
252       }
253     }    
254     ADDMSG(MYDEBUG,"\n");
255     return anEntity2FamilySet;
256   }
257   
258
259   //---------------------------------------------------------------
260   TKey2Gauss
261   GetKey2Gauss(const PWrapper& theWrapper, 
262                TErr* theErr,
263                EModeSwitch theMode)
264   {
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;
274
275 #ifdef _DEBUG_
276       const EGeometrieElement& aGeom = boost::get<0>(aKey);
277       const std::string& aName = boost::get<1>(aKey);
278       INITMSG(MYDEBUG,
279               "- aGeom = "<<aGeom<<
280               "; aName = '"<<aName<<"'"<<
281               endl);
282 #endif
283
284     }
285     return aKey2Gauss;
286   }
287
288
289   //---------------------------------------------------------------
290   PProfileInfo
291   GetProfileInfo(const PWrapper& theWrapper, 
292                  const std::string& theProfileName,
293                  TErr* theErr,
294                  EModeProfil theMode)
295   {
296     PProfileInfo anInfo;
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);
303     }
304     return anInfo;
305   }
306   
307
308   //---------------------------------------------------------------
309   TMKey2Profile
310   GetMKey2Profile(const PWrapper& theWrapper, 
311                   TErr* theErr,
312                   EModeProfil theMode)
313   {
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;
322       
323 #ifdef _DEBUG_
324       INITMSG(MYDEBUG,
325               "- aName = '"<<aName<<"'"<<
326               " : "<<
327               endl);
328       TInt aNbElem = anInfo->myElemNum.size();
329       for(TInt iElem = 0; iElem < aNbElem; iElem++){
330         ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
331       }
332       ADDMSG(MYVALUEDEBUG,endl);
333 #endif
334       
335     }
336     return TMKey2Profile(theMode,aKey2Profile);
337   }
338
339 }