1 // Copyright (C) 2007-2023 CEA, EDF, 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, or (at your option) any later version.
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"
25 #include "MED_Utilities.hxx"
29 //---------------------------------------------------------------
30 TEntity2TGeom2ElemInfo
31 GetEntity2TGeom2ElemInfo(const PWrapper& theWrapper,
32 const PMeshInfo& theMeshInfo,
33 const MED::TEntityInfo& theEntityInfo)
35 MSG("GetElemsByEntity(...)");
36 TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo;
37 MED::TEntityInfo::const_iterator anIter = theEntityInfo.begin();
40 for(; anIter != theEntityInfo.end(); anIter++){
41 const EEntiteMaillage& anEntity = anIter->first;
42 const TGeom2Size& aGeom2Size = anIter->second;
43 TGeom2ElemInfo& aGeom2ElemInfo = anEntity2TGeom2ElemInfo[anEntity];
45 if(anEntity == eNOEUD){
46 aGeom2ElemInfo[ePOINT1] = theWrapper->GetPElemInfo(theMeshInfo);
50 TGeom2Size::const_iterator anIter2 = aGeom2Size.begin();
51 for(; anIter2 != aGeom2Size.end(); anIter2++){
52 const EGeometrieElement& aGeom = anIter2->first;
53 aGeom2ElemInfo[aGeom] = theWrapper->GetPElemInfo(theMeshInfo,anEntity,aGeom,MED::eNOD,&anErr);
57 return anEntity2TGeom2ElemInfo;
60 //---------------------------------------------------------------
62 GetFamilyInfoSet(const PWrapper& theWrapper,
63 const PMeshInfo& theMeshInfo)
65 MSG("GetFamilies(...)");
67 TFamilyInfoSet aFamilyInfoSet;
68 TInt aNbFam = theWrapper->GetNbFamilies(*theMeshInfo);
69 INITMSG("GetNbFamilies() = "<<aNbFam<<"\n");
70 for(TInt iFam = 1; iFam <= aNbFam; iFam++){
71 PFamilyInfo aFamilyInfo = theWrapper->GetPFamilyInfo(theMeshInfo,iFam,&anErr);
73 aFamilyInfoSet.insert(aFamilyInfo);
76 return aFamilyInfoSet;
79 //---------------------------------------------------------------
81 GetGroupInfo(const TFamilyInfoSet& theFamilyInfoSet)
83 MSG("GetFamiliesByGroup(...)");
85 TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
86 for(; anIter != theFamilyInfoSet.end(); anIter++){
87 const PFamilyInfo& aFamilyInfo = *anIter;
88 TInt aNbGroup = aFamilyInfo->GetNbGroup();
89 for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
90 aGroup[aFamilyInfo->GetGroupName(iGroup)].insert(aFamilyInfo);
94 if(SALOME::VerbosityActivated()){
95 TGroupInfo::const_iterator anIter = aGroup.begin();
96 for(; anIter != aGroup.end(); anIter++){
97 const std::string& aName = anIter->first;
98 INITMSG("aGroupName = '"<<aName<<"'\n");
99 const TFamilyInfoSet& aFamilyInfoSet = anIter->second;
100 TFamilyInfoSet::const_iterator anFamIter = aFamilyInfoSet.begin();
101 for(; anFamIter != aFamilyInfoSet.end(); anFamIter++){
102 const PFamilyInfo& aFamilyInfo = *anFamIter;
103 INITMSG("aFamilyName = '"<<aFamilyInfo->GetName()<<"'\n");
112 //---------------------------------------------------------------
113 TFieldInfo2TimeStampInfoSet
114 GetFieldInfo2TimeStampInfoSet(const PWrapper& theWrapper,
115 const PMeshInfo& theMeshInfo,
116 const MED::TEntityInfo& theEntityInfo)
118 MSG("GetFieldsByEntity(...)");
119 TFieldInfo2TimeStampInfoSet aFieldInfo2TimeStampInfoSet;
120 TInt aNbFields = theWrapper->GetNbFields();
121 INITMSG("GetNbFields() = "<<aNbFields<<"\n");
122 for(TInt iField = 1; iField <= aNbFields; iField++){
123 PFieldInfo aFieldInfo = theWrapper->GetPFieldInfo(theMeshInfo,iField);
124 INITMSG("aFieldName = '"<<aFieldInfo->GetName()<<
125 "'; aNbComp = "<<aFieldInfo->GetNbComp()<<"; ");
126 TGeom2Size aGeom2Size;
127 EEntiteMaillage anEntity = EEntiteMaillage(-1);
128 TInt aNbTimeStamps = theWrapper->GetNbTimeStamps(aFieldInfo,theEntityInfo,anEntity,aGeom2Size);
129 ADDMSG("anEntity = "<<anEntity<<"; GetNbTimeStamps = "<<aNbTimeStamps<<"\n");
130 for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
131 PTimeStampInfo aTimeStamp =
132 theWrapper->GetPTimeStampInfo(aFieldInfo,anEntity,aGeom2Size,iTimeStamp);
133 aFieldInfo2TimeStampInfoSet[aFieldInfo].insert(aTimeStamp);
134 INITMSG("aDt = "<<aTimeStamp->GetDt()<<", Unit = \'"<<aTimeStamp->GetUnitDt()<<"\n");
138 return aFieldInfo2TimeStampInfoSet;
141 //---------------------------------------------------------------
142 TEntite2TFieldInfo2TimeStampInfoSet
143 GetEntite2TFieldInfo2TimeStampInfoSet(const TFieldInfo2TimeStampInfoSet& theFieldInfo2TimeStampInfoSet)
145 TEntite2TFieldInfo2TimeStampInfoSet anEntite2TFieldInfo2TimeStampInfoSet;
146 TFieldInfo2TimeStampInfoSet::const_iterator anIter = theFieldInfo2TimeStampInfoSet.begin();
147 for(; anIter != theFieldInfo2TimeStampInfoSet.end(); anIter++){
148 const TTimeStampInfoSet& aTimeStampInfoSet = anIter->second;
149 //const PFieldInfo& aFieldInfo = anIter->first;
150 if(aTimeStampInfoSet.empty())
152 const PTimeStampInfo& aTimeStampInfo = *aTimeStampInfoSet.begin();
153 anEntite2TFieldInfo2TimeStampInfoSet[ConvertEntity(aTimeStampInfo->GetEntity())].insert(*anIter);
155 return anEntite2TFieldInfo2TimeStampInfoSet;
158 //---------------------------------------------------------------
160 operator<(const TFamilyTSize& theLeft, const TFamilyTSize& theRight)
162 const MED::PFamilyInfo& aLeftInfo = boost::get<0>(theLeft);
163 const MED::PFamilyInfo& aRightInfo = boost::get<0>(theRight);
164 return aLeftInfo->GetId() < aRightInfo->GetId();
167 //---------------------------------------------------------------
169 GetEntity2FamilySet(const PWrapper& /*theWrapper*/,
170 const TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
171 const TFamilyInfoSet& theFamilyInfoSet)
173 MSG("GetFamiliesByEntity(...)");
174 TEntity2FamilySet anEntity2FamilySet;
176 typedef std::map<TInt,PFamilyInfo> TId2Family;
177 TId2Family anId2Family;
178 TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin();
179 for(; anIter != theFamilyInfoSet.end(); anIter++){
180 const PFamilyInfo& aFamilyInfo = *anIter;
181 anId2Family.insert(TId2Family::value_type(aFamilyInfo->GetId(),aFamilyInfo));
184 if(!anId2Family.empty()){
185 typedef std::map<TInt,TInt> TFamilyID2Size;
186 typedef std::map<EEntiteMaillage,TFamilyID2Size> TEntity2FamilyID;
187 TEntity2FamilyID anEntity2FamilyID;
189 if(!theEntity2TGeom2ElemInfo.empty()){
190 TEntity2TGeom2ElemInfo::const_iterator anIter = theEntity2TGeom2ElemInfo.begin();
191 for(; anIter != theEntity2TGeom2ElemInfo.end(); anIter++){
192 const EEntiteMaillage& anEntity = anIter->first;
193 TFamilyID2Size& aFamilyID2Size = anEntity2FamilyID[anEntity];
194 const TGeom2ElemInfo& aGeom2ElemInfo = anIter->second;
195 TGeom2ElemInfo::const_iterator aGeom2ElemInfoIter = aGeom2ElemInfo.begin();
196 for(; aGeom2ElemInfoIter != aGeom2ElemInfo.end(); aGeom2ElemInfoIter++){
197 const PElemInfo& aElemInfo = aGeom2ElemInfoIter->second;
198 if(TInt aNbElem = aElemInfo->GetNbElem()){
199 for(TInt i = 0; i < aNbElem; i++){
200 aFamilyID2Size[aElemInfo->GetFamNum(i)] += 1;
207 if(!anEntity2FamilyID.empty()){
208 TEntity2FamilyID::const_iterator anIter = anEntity2FamilyID.begin();
209 for(; anIter != anEntity2FamilyID.end(); anIter++){
210 const EEntiteMaillage& anEntity = anIter->first;
211 INITMSG("anEntity = "<<anEntity<<":\n");
212 const TFamilyID2Size& aFamilyID2Size = anIter->second;
213 TFamilyID2Size::const_iterator anIter2 = aFamilyID2Size.begin();
214 for(; anIter2 != aFamilyID2Size.end(); anIter2++){
215 TInt anId = anIter2->first;
216 TInt aSize = anIter2->second;
217 TId2Family::const_iterator anIter3 = anId2Family.find(anId);
218 if(anIter3 != anId2Family.end()){
219 const PFamilyInfo& aFamilyInfo = anIter3->second;
220 anEntity2FamilySet[anEntity].insert(TFamilyTSize(aFamilyInfo,aSize));
221 INITMSG("aFamilyName = '"<<aFamilyInfo->GetName()<<
222 "' anId = "<<aFamilyInfo->GetId()<<"\n");
229 return anEntity2FamilySet;
232 //---------------------------------------------------------------
234 GetKey2Gauss(const PWrapper& theWrapper,
238 INITMSG("GetKey2Gauss - theMode = "<<theMode<<std::endl);
239 TKey2Gauss aKey2Gauss;
240 TInt aNbGauss = theWrapper->GetNbGauss(theErr);
241 for(TInt anId = 1; anId <= aNbGauss; anId++){
242 TGaussInfo::TInfo aPreInfo = theWrapper->GetGaussPreInfo(anId);
243 PGaussInfo anInfo = theWrapper->CrGaussInfo(aPreInfo,theMode);
244 theWrapper->GetGaussInfo(anId,anInfo,theErr);
245 TGaussInfo::TKey aKey = boost::get<0>(aPreInfo);
246 aKey2Gauss[aKey] = anInfo;
248 if (SALOME::VerbosityActivated())
250 const EGeometrieElement& aGeom = boost::get<0>(aKey);
251 const std::string& aName = boost::get<1>(aKey);
252 INITMSG("- aGeom = "<<aGeom<<"; aName = '"<<aName<<"'"<<std::endl);
259 //---------------------------------------------------------------
261 GetProfileInfo(const PWrapper& theWrapper,
262 const std::string& theProfileName,
267 TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
268 for(TInt anId = 1; anId <= aNbProfiles; anId++){
269 TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
270 const std::string& aName = boost::get<0>(aPreInfo);
271 if(aName == theProfileName)
272 return theWrapper->GetPProfileInfo(anId,theMode,theErr);
277 //---------------------------------------------------------------
279 GetMKey2Profile(const PWrapper& theWrapper,
283 INITMSG("GetMKey2Profile - theMode = "<<theMode<<std::endl);
284 TKey2Profile aKey2Profile;
285 TInt aNbProfiles = theWrapper->GetNbProfiles(theErr);
286 for(TInt anId = 1; anId <= aNbProfiles; anId++){
287 TProfileInfo::TInfo aPreInfo = theWrapper->GetProfilePreInfo(anId);
288 PProfileInfo anInfo = theWrapper->GetPProfileInfo(anId,theMode,theErr);
289 const std::string& aName = boost::get<0>(aPreInfo);
290 aKey2Profile[aName] = anInfo;
292 if(SALOME::VerbosityActivated()){
293 INITMSG("- aName = '"<<aName<<"'"<<" : "<<std::endl);
294 TInt aNbElem = anInfo->GetSize();
296 for(TInt iElem = 0; iElem < aNbElem; iElem++){
297 ADDMSG(anInfo->GetElemNum(iElem)<<", ");
303 return TMKey2Profile(theMode,aKey2Profile);
306 //---------------------------------------------------------------
308 GetEntityByFamilyId(PGrilleInfo& theInfo,
311 TElemNum::iterator aNodeFamIter = (theInfo->myFamNumNode).begin();
312 for(;aNodeFamIter != (theInfo->myFamNumNode).end(); aNodeFamIter++){
313 if(theId == *aNodeFamIter)
316 TElemNum::iterator aCellFamIter = (theInfo->myFamNum).begin();
317 for(;aCellFamIter != (theInfo->myFamNum).end(); aCellFamIter++){
318 if(theId == *aCellFamIter)
321 EXCEPTION(std::runtime_error, "GetEntityByFamilyId - fails");
322 return EEntiteMaillage(-1);
325 //---------------------------------------------------------------
327 GetFamilyID2NbCells(PGrilleInfo& theInfo)
329 TFamilyID2NbCells aFamily2NbCells;
330 TInt aNbNodes = theInfo->myFamNumNode.size();
331 TInt aNbCells = theInfo->myFamNum.size();
332 for(TInt i=0; i<aNbNodes; i++) aFamily2NbCells[theInfo->GetFamNumNode(i)] = 0;
333 for(TInt i=0; i<aNbCells; i++) aFamily2NbCells[theInfo->GetFamNum(i)] = 0;
334 for(TInt i=0; i<aNbNodes; i++) aFamily2NbCells[theInfo->GetFamNumNode(i)] += 1;
335 for(TInt i=0; i<aNbCells; i++) aFamily2NbCells[theInfo->GetFamNum(i)] += 1;
336 return aFamily2NbCells;
339 //---------------------------------------------------------------
341 ConvertEntity(const EEntiteMaillage& aEntity)
346 return eMAILLE; // eNOEUD_ELEMENT is eMAILLE
354 return EEntiteMaillage(-1);