Salome HOME
[EDF7075] Struct elements on COQUE (EPAISSEUR)
[tools/medcoupling.git] / src / MEDLoader / MEDFileBlowStrEltUp.cxx
1 // Copyright (C) 2007-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (EDF R&D)
20
21 #include "MEDFileBlowStrEltUp.hxx"
22 #include "MEDCouplingFieldDouble.hxx"
23 #include "MEDFileFieldVisitor.hxx"
24 #include "MEDCouplingPartDefinition.hxx"
25 #include "MCAuto.txx"
26
27 using namespace MEDCoupling;
28
29 const char MEDFileBlowStrEltUp::MED_BALL_STR[]="MED_BALL";
30
31 MEDFileBlowStrEltUp::MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MEDFileMeshes *ms, const MEDFileStructureElements *ses)
32 {
33   if(!fsOnlyOnSE || !ms || !ses)
34     throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp constructor : NULL input pointer !");
35   _ms.takeRef(ms); _ses.takeRef(ses);
36   std::vector< std::pair<std::string,std::string> > ps;
37   fsOnlyOnSE->getMeshSENames(ps);
38   std::size_t sz(ps.size());
39   _elts.resize(sz);
40   for(std::size_t i=0;i<sz;i++)
41     {
42       const std::pair<std::string,std::string>& p(ps[i]);
43       MCAuto<MEDFileFields> f(fsOnlyOnSE->partOfThisLyingOnSpecifiedMeshSEName(p.first,p.second));
44       _elts[i]=f;
45     }
46   for(std::size_t i=0;i<sz;i++)
47     {
48       const std::pair<std::string,std::string>& p(ps[i]);
49       MEDFileMesh *mesh(_ms->getMeshWithName(p.first));
50       if(!mesh)
51         throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp : NULL mesh !");
52       MEDFileUMesh *umesh(dynamic_cast<MEDFileUMesh *>(mesh));
53       if(!umesh)
54         throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp : Blow up of Stru Elt not managed yet for unstructured meshes !");
55     }
56 }
57
58 /*!
59  * \param [in] mesh - The mesh containing structure element called \a seName. After the call of this method the Structure elements parts will be removed.
60  * \param [out] mOut - the physical mesh of the structure element \a seName in mesh \a mesh
61  * \param [out] fsOut - the list of var attribute of structure element \a seName - \b WARNING no time steps here
62  */
63 MCAuto<MEDFileEltStruct4Mesh> MEDFileBlowStrEltUp::dealWithSEInMesh(const std::string& seName, MEDFileUMesh *mesh, MCAuto<MEDFileUMesh>& mOut, MCAuto<MEDFileFields>& fsOut) const
64 {
65   if(!mesh)
66     throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInMesh : null pointer !");
67   if(seName==MED_BALL_STR)
68     {
69       MCAuto<MEDFileEltStruct4Mesh> ret(dealWithMEDBALLInMesh(mesh,mOut,fsOut));
70       mesh->killStructureElements();
71       return ret;
72     }
73   throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInMesh : only MED_BALL is managed for the moment, but if you are interested please send spec to anthony.geay@edf.fr !");
74 }
75
76 MCAuto<MEDFileEltStruct4Mesh> MEDFileBlowStrEltUp::dealWithMEDBALLInMesh(const MEDFileUMesh *mesh, MCAuto<MEDFileUMesh>& mOut, MCAuto<MEDFileFields>& fsOut) const
77 {
78   mOut=MEDFileUMesh::New(); fsOut=MEDFileFields::New();
79   const std::vector< MCAuto<MEDFileEltStruct4Mesh> >& strs(mesh->getAccessOfUndergroundEltStrs());
80   MCAuto<MEDFileEltStruct4Mesh> zeStr;
81   for(std::vector< MCAuto<MEDFileEltStruct4Mesh> >::const_iterator it=strs.begin();it!=strs.end();it++)
82     {
83       if((*it)->getGeoTypeName()==MED_BALL_STR)
84         {
85           zeStr=*it;
86           break;
87         }
88     }
89   if(zeStr.isNull())
90     {
91       std::ostringstream oss; oss << "MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : no geo type with name " <<  MED_BALL_STR << " in " << mesh->getName() << " !";
92       throw INTERP_KERNEL::Exception(oss.str());
93     }
94   const DataArrayDouble *coo(mesh->getCoords());
95   if(!coo)
96     throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : null coords !");
97   MCAuto<DataArrayInt> conn(zeStr->getConn());
98   if(conn.isNull())
99     throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : null connectivity !");
100   conn->checkAllocated();
101   if(conn->getNumberOfComponents()!=1)
102     throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : excepted to be single compo !");
103   int nbCells(conn->getNumberOfTuples());
104   MCAuto<DataArrayDouble> connOut(coo->selectByTupleIdSafe(conn->begin(),conn->end()));
105   MCAuto<MEDCouplingUMesh> mcOut(MEDCouplingUMesh::Build0DMeshFromCoords(connOut));
106   mcOut->setName(BuildNewMeshName(mesh->getName(),MED_BALL_STR));
107   mOut->setMeshAtLevel(0,mcOut);
108   const DataArrayInt *ff1(mesh->getFamilyFieldAtLevel(1));
109   if(ff1)
110     {
111       MCAuto<DataArrayInt> ff1o(ff1->selectByTupleIdSafe(conn->begin(),conn->end()));
112       mOut->setFamilyFieldArr(1,ff1o);
113     }
114   const DataArrayInt *nf1(mesh->getNumberFieldAtLevel(1));
115   if(nf1)
116     {
117       MCAuto<DataArrayInt> nf1o(nf1->selectByTupleIdSafe(conn->begin(),conn->end()));
118       mOut->setRenumFieldArr(1,nf1o);
119     }
120   MCAuto<MEDFileUMeshPerTypeCommon> md(zeStr->getMeshDef());
121   const DataArrayInt *ff0(md->getFam());
122   if(ff0)
123     mOut->setFamilyFieldArr(0,const_cast<DataArrayInt *>(ff0));
124   const DataArrayInt *nf0(md->getNum());
125   if(nf0)
126     mOut->setRenumFieldArr(0,const_cast<DataArrayInt *>(nf0));
127   mOut->copyFamGrpMapsFrom(*mesh);
128   const std::vector< MCAuto<DataArray> >& vars(zeStr->getVars());
129   for(std::vector< MCAuto<DataArray> >::const_iterator it=vars.begin();it!=vars.end();it++)
130     {
131       const DataArray *elt(*it);
132       if(!elt)
133         continue;
134       {
135         const DataArrayDouble *eltC(dynamic_cast<const DataArrayDouble *>(elt));
136         if(eltC)
137           {
138             MCAuto<MEDFileFieldMultiTS> fmts(MEDFileFieldMultiTS::New());
139             MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
140             MCAuto<MEDCouplingFieldDouble> f(MEDCouplingFieldDouble::New(ON_NODES));
141             f->setMesh(mcOut);
142             f->setArray(const_cast<DataArrayDouble *>(eltC));
143             f->setName(eltC->getName());
144             f1ts->setFieldNoProfileSBT(f);
145             fmts->pushBackTimeStep(f1ts);
146             fsOut->pushField(fmts);
147           }
148       }
149     }
150   return zeStr;
151 }
152
153 /*!
154  * \param [in] fs - fields lying all on same mesh and on same structure element
155  * \param [in] zeStr - ze structure of current structure element
156  * \param [in] varAtt - fields containing var att of current structure element. WARNING at this stage the number of iteration are equal to one for each field in \a varAtt
157  * \param [out] zeOutputs - ze fields that are the concatenation of fields in \a fs transformed and those in \a varAtt normalized in time space
158  */
159 void MEDFileBlowStrEltUp::dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const
160 {
161   if(!fs)
162     throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInFields : null pointer !");
163   if(seName==MED_BALL_STR)
164     {
165       dealWithMEDBALLSInFields(fs,zeStr,varAtt,zeOutputs);
166       return ;
167     }
168   throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInFields : only MED_BALL is managed for the moment, but if you are interested please send spec to anthony.geay@edf.fr !");
169 }
170
171 void MEDFileBlowStrEltUp::dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const
172 {
173   int nbf(fs->getNumberOfFields());
174   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTS> > elts0;
175   std::vector< MEDFileAnyTypeFieldMultiTS * > elts1;
176   std::string zeMeshName;
177   for(int i=0;i<nbf;i++)
178     {
179       MCAuto<MEDFileAnyTypeFieldMultiTS> elt(fs->getFieldAtPos(i));
180       MCAuto<MEDFileAnyTypeFieldMultiTS> eltOut(elt->buildNewEmpty());
181       int nbTS(elt->getNumberOfTS());
182       for(int j=0;j<nbTS;j++)
183         {
184           MCAuto<MEDFileAnyTypeField1TS> eltt(elt->getTimeStepAtPos(j));
185           MCAuto<MEDFileAnyTypeField1TS> elttOut(eltt->deepCopy());
186           std::string meshName(eltt->getMeshName());
187           zeMeshName=BuildNewMeshName(meshName,MED_BALL_STR);
188           elttOut->setMeshName(zeMeshName);
189           elttOut->convertMedBallIntoClassic();
190           eltOut->pushBackTimeStep(elttOut);
191         }
192       elts0.push_back(eltOut); elts1.push_back(eltOut);
193     }
194   //
195   const MEDFileMesh *zeCurrentMesh(_ms->getMeshWithName(zeMeshName));
196   //
197   std::size_t ii(0);
198   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > sp(MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(elts1));
199   for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=sp.begin();it0!=sp.end();it0++,ii++)
200     {
201       std::vector< MCAuto<MEDFileFastCellSupportComparator> > fsc;
202       std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > sp2(MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(*it0,zeCurrentMesh,fsc));
203       std::size_t jj(0);
204       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it1=sp2.begin();it1!=sp2.end();it1++,jj++)
205         {
206           for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
207             zeOutputs->pushField(*it2);
208           // The most exciting part. Users that put profiles on struct elements part of fields. Reduce var att.
209           if((*it1).size()<1)
210             throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath !");
211           MCAuto<MEDFileAnyTypeField1TS> zeGuideForPfl;// This var is the reference for pfl management.
212           {
213             if(!(*it1)[0])
214               throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath 2 !");
215             int pdm((*it1)[0]->getNumberOfTS());
216             if(pdm<1)
217               throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath 3 !");
218             zeGuideForPfl=(*it1)[0]->getTimeStepAtPos(0);
219           }
220           if(zeGuideForPfl.isNull())
221             throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath 4 !");
222           std::vector<std::string> pfls(zeGuideForPfl->getPflsReallyUsed());
223           if(pfls.size()>=2)
224             throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : drink less coffee");
225           MCAuto<DataArrayInt> pflMyLove;
226           if(pfls.size()==1)
227             pflMyLove.takeRef(zeGuideForPfl->getProfile(pfls[0]));
228           // Yeah we have pfls
229           std::vector<double> t2s;
230           std::vector< std::pair<int,int> > t1s((*it1)[0]->getTimeSteps(t2s));
231           std::size_t nbTS3(t2s.size());
232           int nbf2(varAtt->getNumberOfFields());
233           for(int i=0;i<nbf2;i++)
234             {
235               MCAuto<MEDFileAnyTypeFieldMultiTS> elt(varAtt->getFieldAtPos(i));
236               int nbTS2(elt->getNumberOfTS());
237               if(nbTS2!=1)
238                 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : internal error ! The dealWithMEDBALLInMesh is expected to return a single TS !");
239               MCAuto<MEDFileAnyTypeField1TS> elt2(elt->getTimeStepAtPos(0));
240               MCAuto<MEDFileAnyTypeFieldMultiTS> elt4(elt->buildNewEmpty());
241               for(std::size_t j=0;j<nbTS3;j++)
242                 {
243                   MCAuto<MEDFileAnyTypeField1TS> elt3(elt2->deepCopy());
244                   elt3->setTime(t1s[j].first,t1s[j].second,t2s[j]);
245                   elt3->setName(BuildVarAttName(ii,sp.size(),jj,sp2.size(),elt3->getName()));
246                   if(pflMyLove.isNotNull())
247                     elt3->makeReduction(INTERP_KERNEL::NORM_ERROR,ON_NODES,pflMyLove);
248                   elt4->pushBackTimeStep(elt3);
249                 }
250               zeOutputs->pushField(elt4);
251             }
252         }
253     }
254 }
255
256 void MEDFileBlowStrEltUp::generate(MEDFileMeshes *msOut, MEDFileFields *allZeOutFields)
257 {
258   for(std::vector< MCAuto<MEDFileFields> >::iterator elt=_elts.begin();elt!=_elts.end();elt++)
259     {
260       std::vector< std::pair<std::string,std::string> > ps;
261       (*elt)->getMeshSENames(ps);
262       if(ps.size()!=1)
263         throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : internal error !");
264       MEDFileMesh *mesh(_ms->getMeshWithName(ps[0].first));
265       if(!mesh)
266         throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : NULL mesh !");
267       MEDFileUMesh *umesh(dynamic_cast<MEDFileUMesh *>(mesh));
268       if(!umesh)
269         throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : Blow up of Stru Elt not managed yet for unstructured meshes !");
270       //
271       MCAuto<MEDFileFields> classicalSEFields(splitFieldsPerLoc(*elt,umesh,msOut,allZeOutFields));
272       if(classicalSEFields.isNotNull())
273         {
274           MCAuto<MEDFileUMesh> mOut;
275           MCAuto<MEDFileFields> fsOut1;
276           MCAuto<MEDFileEltStruct4Mesh> zeStr(dealWithSEInMesh(ps[0].second,umesh,mOut,fsOut1));
277           msOut->pushMesh(mOut);
278           dealWithSEInFields(ps[0].second,classicalSEFields,zeStr,fsOut1,allZeOutFields);
279         }
280     }
281 }
282
283 std::string MEDFileBlowStrEltUp::BuildNewMeshName(const std::string& meshName, const std::string& seName)
284 {
285   std::ostringstream mNameOut;
286   mNameOut << meshName << "_" << seName;
287   return mNameOut.str();
288 }
289
290 std::string MEDFileBlowStrEltUp::BuildVarAttName(std::size_t iPart, std::size_t totINbParts, std::size_t jPart, std::size_t totJNbParts, const std::string& name)
291 {
292   if(totINbParts==1 && totJNbParts==1)
293     return name;
294   std::ostringstream oss;
295   oss << name << "@" << iPart << "@" << jPart;
296   return oss.str();
297 }
298
299 void MEDFileBlowStrEltUp::DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const MEDFileStructureElements *ses)
300 {
301   MCAuto<MEDFileFields> fsSEOnly(fs->partOfThisOnStructureElements());
302   fs->killStructureElements();
303   MEDFileBlowStrEltUp bu(fsSEOnly,ms,ses);
304   bu.generate(ms,fs);
305   fs->killStructureElementsInGlobs();
306 }
307
308 //
309
310 class FieldWalker2
311 {
312 public:
313   FieldWalker2(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd);
314   std::string getLoc() const { return _loc; }
315   std::string getPfl() const { return _pfl; }
316   bool isClassic() const { return _is_classic; }
317   bool operator!=(const FieldWalker2& other) const;
318   bool operator==(const FieldWalker2& other) const;
319   const SlicePartDefinition *getPartDef() const { return _pd; }
320 private:
321   std::string _loc;
322   std::string _pfl;
323   bool _is_classic;
324   MCAuto<SlicePartDefinition> _pd;
325 };
326
327 class LocInfo
328 {
329 public:
330   LocInfo() { }
331   LocInfo(const std::vector<FieldWalker2>& fw);
332   bool operator==(const LocInfo& other) const { return _locs==other._locs && _pfl==other._pfl; }
333   void push(const std::string& loc, const std::string& pfl) { checkUniqueLoc(loc); _locs.push_back(loc); _pfl.push_back(pfl); }
334   MCAuto<MEDFileUMesh> generateNonClassicalData(int zePos, const MEDFileUMesh *mesh, const MEDFileFieldGlobsReal *globs) const;
335   const PartDefinition *getPartDef() const { return _pd; }
336 private:
337   void checkUniqueLoc(const std::string& loc) const;
338   static MCAuto<DataArrayDouble> BuildMeshFromAngleVrille(INTERP_KERNEL::NormalizedCellType gt, const DataArrayDouble *angleDeVrille, const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs);
339   static MCAuto<DataArrayDouble> BuildMeshFromEpaisseur(INTERP_KERNEL::NormalizedCellType gt, const DataArrayDouble *thikness, const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs);
340   static MCAuto<MEDCouplingUMesh> BuildMeshCommon(INTERP_KERNEL::NormalizedCellType gt, const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs, MCAuto<DataArrayDouble>& ptsForLoc);
341   static MCAuto<DataArrayDouble> BuildMeshFromStructure(INTERP_KERNEL::NormalizedCellType gt, const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs);
342 public:
343   static const char ANGLE_DE_VRILLE[];
344   static const char EPAISSEUR[];
345 private:
346   std::vector<std::string> _locs;
347   std::vector<std::string> _pfl;
348   MCAuto<PartDefinition> _pd;
349 };
350
351 const char LocInfo::ANGLE_DE_VRILLE[]="ANGLE DE VRILLE";
352
353 const char LocInfo::EPAISSEUR[]="EPAISSEUR";
354
355 LocInfo::LocInfo(const std::vector<FieldWalker2>& fw)
356 {
357   std::size_t sz(fw.size());
358   _locs.resize(sz); _pfl.resize(sz);
359   if(sz>0)
360     _pd=fw[0].getPartDef()->deepCopy();
361   for(std::size_t i=0;i<sz;i++)
362     {
363       _locs[i]=fw[i].getLoc();
364       _pfl[i]=fw[i].getPfl();
365       if(i>0)
366         _pd=(*_pd)+(*(fw[i].getPartDef()));
367     }
368 }
369
370 void LocInfo::checkUniqueLoc(const std::string& loc) const
371 {
372   if(std::find(_locs.begin(),_locs.end(),loc)!=_locs.end())
373     {
374       std::ostringstream oss; oss << "LocInfo::checkUniqueLoc : loc \"" << loc << "\" already exists !";
375       throw INTERP_KERNEL::Exception(oss.str());
376     }
377 }
378
379 MCAuto<MEDCouplingUMesh> LocInfo::BuildMeshCommon(INTERP_KERNEL::NormalizedCellType gt,const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs, MCAuto<DataArrayDouble>& ptsForLoc)
380 {
381   MCAuto<DataArrayInt> conn(zeStr->getConn());
382   conn=conn->deepCopy(); conn->rearrange(1);
383   MCAuto<MEDCouplingUMesh> geoMesh;
384   {
385     MCAuto<MEDCoupling1SGTUMesh> umesh(MEDCoupling1SGTUMesh::New("",gt));
386     umesh->setCoords(mesh->getCoords());
387     umesh->setNodalConnectivity(conn);
388     geoMesh=umesh->buildUnstructured();
389   }
390   //
391   MCAuto<MEDCouplingFieldDouble> fakeF(MEDCouplingFieldDouble::New(ON_GAUSS_PT));
392   fakeF->setMesh(geoMesh);
393   fakeF->setGaussLocalizationOnType(gt,loc.getRefCoords(),loc.getGaussCoords(),loc.getGaussWeights());
394   ptsForLoc=fakeF->getLocalizationOfDiscr();
395   //
396   return geoMesh;
397 }
398
399 MCAuto<DataArrayDouble> LocInfo::BuildMeshFromAngleVrille(INTERP_KERNEL::NormalizedCellType gt, const DataArrayDouble *angleDeVrille, const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs)
400 {
401   MCAuto<DataArrayDouble> ptsForLoc;
402   MCAuto<MEDCouplingUMesh> geoMesh(BuildMeshCommon(gt,pfl,loc,zeStr,mesh,section,globs,ptsForLoc));
403   //
404   MCConstAuto<DataArrayDouble> angleVrille;
405   if(!pfl.empty())
406     {
407       const DataArrayInt *pflArr(globs->getProfile(pfl));
408       geoMesh=geoMesh->buildPartOfMySelf(pflArr->begin(),pflArr->end(),true);
409       angleVrille=angleDeVrille->selectByTupleIdSafe(pflArr->begin(),pflArr->end());
410     }
411   else
412     angleVrille.takeRef(angleDeVrille);
413   //
414   int nbCompo(ptsForLoc->getNumberOfComponents());
415   MCAuto<DataArrayDouble> secPts(section->getCoords()->changeNbOfComponents(nbCompo,0.));
416   int nbSecPts(secPts->getNumberOfTuples()),nbCells(geoMesh->getNumberOfCells()),nbg(loc.getGaussWeights().size());
417   {
418     const int TAB[3]={2,0,1};
419     std::vector<int> v(TAB,TAB+3);
420     secPts=secPts->keepSelectedComponents(v);
421   }
422   MCAuto<MEDCouplingFieldDouble> dir(geoMesh->buildDirectionVectorField());
423   MCAuto<DataArrayDouble> rot(dir->getArray()->fromCartToSpher());
424   //
425   const double CENTER[3]={0.,0.,0.},AX0[3]={0.,0.,1.};
426   double AX1[3]; AX1[2]=0.;
427   std::vector< MCAuto<DataArrayDouble> > arrs(nbCells*nbg);
428   for(int j=0;j<nbCells;j++)
429     {
430       MCAuto<DataArrayDouble> p(secPts->deepCopy());
431       double ang0(rot->getIJ(j,2));
432       DataArrayDouble::Rotate3DAlg(CENTER,AX0,ang0,nbSecPts,p->begin(),p->getPointer());
433       AX1[0]=-sin(ang0); AX1[1]=cos(ang0);// rot Oy around OZ
434       double ang1(M_PI/2.-rot->getIJ(j,1));
435       DataArrayDouble::Rotate3DAlg(CENTER,AX1,-ang1,nbSecPts,p->begin(),p->getPointer());
436       DataArrayDouble::Rotate3DAlg(CENTER,dir->getArray()->begin()+j*3,angleVrille->getIJ(j,0),nbSecPts,p->begin(),p->getPointer());
437       for(int l=0;l<nbg;l++)
438         {
439           MCAuto<DataArrayDouble> p2(p->deepCopy());
440           for(int k=0;k<nbCompo;k++)
441             p2->applyLin(1.,ptsForLoc->getIJ(j*nbg+l,k),k);
442           arrs[j*nbg+l]=p2;
443         }
444     }
445   std::vector<const DataArrayDouble *> arrs2(VecAutoToVecOfCstPt(arrs));
446   MCAuto<DataArrayDouble> resu(DataArrayDouble::Aggregate(arrs2));
447   return resu;
448 }
449
450 MCAuto<DataArrayDouble> LocInfo::BuildMeshFromEpaisseur(INTERP_KERNEL::NormalizedCellType gt, const DataArrayDouble *thikness, const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs)
451 {
452   MCAuto<DataArrayDouble> ptsForLoc;
453   MCAuto<MEDCouplingUMesh> geoMesh(BuildMeshCommon(gt,pfl,loc,zeStr,mesh,section,globs,ptsForLoc));
454   int nbSecPts(section->getNumberOfNodes()),nbCells(geoMesh->getNumberOfCells()),nbg(loc.getGaussWeights().size());
455   MCConstAuto<DataArrayDouble> zeThikness;
456   if(!pfl.empty())
457     {
458       const DataArrayInt *pflArr(globs->getProfile(pfl));
459       geoMesh=geoMesh->buildPartOfMySelf(pflArr->begin(),pflArr->end(),true);
460       zeThikness=thikness->selectByTupleIdSafe(pflArr->begin(),pflArr->end());
461     }
462   else
463     zeThikness.takeRef(thikness);
464   MCAuto<DataArrayDouble> orthoArr;
465   {
466     MCAuto<MEDCouplingFieldDouble> ortho(geoMesh->buildOrthogonalField());
467     orthoArr.takeRef(ortho->getArray());
468   }
469   int nbCompo(orthoArr->getNumberOfComponents());
470   MCAuto<DataArrayDouble> secPts(section->getCoords()->duplicateEachTupleNTimes(nbCompo));
471   secPts->rearrange(nbCompo);
472   std::vector< MCAuto<DataArrayDouble> > arrs(nbCells*nbg);
473   for(int j=0;j<nbCells;j++)
474     {
475       double thck(zeThikness->getIJ(j,0));
476       MCAuto<DataArrayDouble> fact(DataArrayDouble::New()); fact->alloc(1,nbCompo);
477       std::copy(orthoArr->begin()+j*nbCompo,orthoArr->begin()+(j+1)*nbCompo,fact->getPointer());
478       std::transform(fact->begin(),fact->end(),fact->getPointer(),std::bind2nd(std::multiplies<double>(),thck/2.));
479       MCAuto<DataArrayDouble> p(DataArrayDouble::Multiply(secPts,fact));
480       for(int l=0;l<nbg;l++)
481         {
482           MCAuto<DataArrayDouble> p2(p->deepCopy());
483           for(int k=0;k<nbCompo;k++)
484             p2->applyLin(1.,ptsForLoc->getIJ(j*nbg+l,k),k);
485           arrs[j*nbg+l]=p2;
486         }
487     }
488   std::vector<const DataArrayDouble *> arrs2(VecAutoToVecOfCstPt(arrs));
489   MCAuto<DataArrayDouble> resu(DataArrayDouble::Aggregate(arrs2));
490   return resu;
491 }
492
493 MCAuto<DataArrayDouble> LocInfo::BuildMeshFromStructure(INTERP_KERNEL::NormalizedCellType gt, const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs)
494 {
495   static const char MSG1[]="BuildMeshFromStructure : not recognized pattern ! Send mail to anthony.geay@edf.fr with corresponding MED file !";
496   const std::vector< MCAuto<DataArray> >& vars(zeStr->getVars());
497   if(vars.size()!=1)
498     throw INTERP_KERNEL::Exception(MSG1);
499   MCAuto<DataArray> zeArr(vars[0]);
500   if(zeArr.isNull())
501     throw INTERP_KERNEL::Exception(MSG1);
502   MCAuto<DataArrayDouble> zeArr2(DynamicCast<DataArray,DataArrayDouble>(zeArr));
503   if(zeArr2.isNull())
504     throw INTERP_KERNEL::Exception(MSG1);
505   if(zeArr2->getName()==ANGLE_DE_VRILLE)
506     return BuildMeshFromAngleVrille(gt,zeArr2,pfl,loc,zeStr,mesh,section,globs);
507   if(zeArr2->getName()==EPAISSEUR)
508     return BuildMeshFromEpaisseur(gt,zeArr2,pfl,loc,zeStr,mesh,section,globs);
509   throw INTERP_KERNEL::Exception(MSG1);
510 }
511
512 MCAuto<MEDFileUMesh> LocInfo::generateNonClassicalData(int zePos, const MEDFileUMesh *mesh, const MEDFileFieldGlobsReal *globs) const
513 {
514   static const char MSG1[]="LocInfo::generateNonClassicalData : no spec for GAUSS on StructureElement with more than one cell !";
515   std::size_t sz(_locs.size());
516   std::vector< MCAuto<DataArrayDouble> > arrs(sz);
517   for(std::size_t i=0;i<sz;i++)
518     {
519       const MEDFileFieldLoc& loc(globs->getLocalization(_locs[i]));
520       const MEDFileGTKeeper *gtk(loc.getUndergroundGTKeeper());
521       const MEDFileGTKeeperDyn *gtk2(dynamic_cast<const MEDFileGTKeeperDyn *>(gtk));
522       if(!gtk2)
523         throw INTERP_KERNEL::Exception("LocInfo::generateNonClassicalData : internal error !");
524       const MEDFileUMesh *meshLoc(gtk2->getMesh()),*section(gtk2->getSection());
525       const MEDFileStructureElement *se(gtk2->getSE());
526       INTERP_KERNEL::NormalizedCellType gt;
527       {
528         std::vector<int> nel(meshLoc->getNonEmptyLevels());
529         if(nel.size()!=1)
530           throw INTERP_KERNEL::Exception(MSG1);
531         if(nel[0]!=0)
532           throw INTERP_KERNEL::Exception(MSG1);
533         MCAuto<MEDCouplingUMesh> um(meshLoc->getMeshAtLevel(0));
534         if(um->getNumberOfCells()!=1)
535           throw INTERP_KERNEL::Exception(MSG1);
536         gt=um->getTypeOfCell(0);
537         std::vector<int> v;
538         um->getNodeIdsOfCell(0,v);
539         std::size_t sz2(v.size());
540         for(std::size_t j=0;j<sz2;j++)
541           if(v[j]!=j)
542             throw INTERP_KERNEL::Exception(MSG1);
543       }
544       const std::vector< MCAuto<MEDFileEltStruct4Mesh> >& strs(mesh->getAccessOfUndergroundEltStrs());
545       MCAuto<MEDFileEltStruct4Mesh> zeStr;
546       for(std::vector< MCAuto<MEDFileEltStruct4Mesh> >::const_iterator it=strs.begin();it!=strs.end();it++)
547         {
548           if((*it)->getGeoTypeName()==se->getName())
549             {
550               zeStr=*it;
551               break;
552             }
553         }
554       if(zeStr.isNull())
555         {
556           std::ostringstream oss; oss << "LocInfo::generateNonClassicalData :  : no geo type with name " <<  se->getName() << " in " << mesh->getName() << " !";
557           throw INTERP_KERNEL::Exception(oss.str());
558         }
559       arrs[i]=BuildMeshFromStructure(gt,_pfl[i],loc,zeStr,mesh,section,globs);
560     }
561   std::vector<const DataArrayDouble *> arrs2(VecAutoToVecOfCstPt(arrs));
562   MCAuto<DataArrayDouble> resu(DataArrayDouble::Aggregate(arrs2));
563   MCAuto<MEDFileUMesh> ret(MEDFileUMesh::New());
564   ret->setCoords(resu);
565   std::ostringstream meshName; meshName << mesh->getName() << "_on_" << sz << "_sections" << "_" << zePos;
566   ret->setName(meshName.str());
567   return ret;
568 }
569
570 FieldWalker2::FieldWalker2(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd)
571 {
572   _loc=pmptpd->getLocalization();
573   _pfl=pmptpd->getProfile();
574   _is_classic=pmptpd->getType()!=ON_GAUSS_PT;
575   _pd=SlicePartDefinition::New(pmptpd->getStart(),pmptpd->getEnd(),1);
576 }
577
578 bool FieldWalker2::operator!=(const FieldWalker2& other) const
579 {
580   return !((*this)==other);
581 }
582
583 bool FieldWalker2::operator==(const FieldWalker2& other) const
584 {
585   bool ret2(false);
586   {
587     std::string tmp;
588     ret2=_pd->isEqual(other._pd,tmp);
589   }
590   bool ret(_loc==other._loc && _pfl==other._pfl && _is_classic==other._is_classic && ret2);
591   return ret;
592 }
593
594 class FieldWalker1
595 {
596 public:
597   FieldWalker1(const MEDFileAnyTypeField1TSWithoutSDA *ts):_ts(ts),_pm_pt(0),_nb_mesh(0) { }
598   void newMeshEntry(const MEDFileFieldPerMesh *fpm);
599   void endMeshEntry(const MEDFileFieldPerMesh *fpm) { }
600   void newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
601   void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
602   void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd);
603   void checkOK(const FieldWalker1& other) const;
604   bool isClassical() const;
605   std::vector<FieldWalker2> getNonClassicalData() const { return _fw; }
606 private:
607   const MEDFileAnyTypeField1TSWithoutSDA *_ts;
608   const MEDFileFieldPerMeshPerTypeDyn *_pm_pt;
609   std::vector<FieldWalker2> _fw;
610   int _nb_mesh;
611 };
612
613 void FieldWalker1::newMeshEntry(const MEDFileFieldPerMesh *fpm)
614 {
615   if(_nb_mesh++==1)
616     throw INTERP_KERNEL::Exception("FieldWalker1::newMeshEntry : multi mesh not supported !");
617 }
618
619 void FieldWalker1::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
620 {
621   if(_pm_pt)
622     throw INTERP_KERNEL::Exception("FieldWalker1::newPerMeshPerTypeEntry : multi SE loc not managed yet !");
623   const MEDFileFieldPerMeshPerTypeDyn *pmpt2(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>(pmpt));
624   if(!pmpt2)
625     throw INTERP_KERNEL::Exception("newPerMeshPerTypeEntry : internal error !");
626   _pm_pt=pmpt2;
627 }
628
629 void FieldWalker1::endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *)
630 {
631   isClassical();
632 }
633
634 void FieldWalker1::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd)
635 {
636   _fw.push_back(FieldWalker2(pmptpd));
637 }
638
639 void FieldWalker1::checkOK(const FieldWalker1& other) const
640 {
641   std::size_t sz(_fw.size());
642   if(other._fw.size()!=sz)
643     throw INTERP_KERNEL::Exception("checkOK : not OK because size are not the same !");
644   for(std::size_t i=0;i<sz;i++)
645     if(_fw[i]!=other._fw[i])
646       throw INTERP_KERNEL::Exception("checkOK : not OK because an element mismatches !");
647 }
648
649 bool FieldWalker1::isClassical() const
650 {
651   if(_fw.empty())
652     throw INTERP_KERNEL::Exception("FieldWalker1::endPerMeshPerTypeEntry : internal error !");
653   std::size_t ic(0),inc(0);
654   for(std::vector<FieldWalker2>::const_iterator it=_fw.begin();it!=_fw.end();it++)
655     {
656       if((*it).isClassic())
657         ic++;
658       else
659         inc++;
660     }
661   if(ic!=0 && inc!=0)
662     throw INTERP_KERNEL::Exception("FieldWalker1::endPerMeshPerTypeEntry : mix is not allowed yet !");
663   return inc==0;
664 }
665
666 class FieldWalker
667 {
668 public:
669   FieldWalker(const MEDFileAnyTypeFieldMultiTSWithoutSDA *f):_f(f) { }
670   void newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts);
671   void endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts);
672   void newMeshEntry(const MEDFileFieldPerMesh *fpm);
673   void endMeshEntry(const MEDFileFieldPerMesh *fpm);
674   void newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
675   void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
676   void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd);
677 public:
678   bool isEmpty() const;
679   bool isClassical() const;
680   const MEDFileAnyTypeFieldMultiTSWithoutSDA *field() const { return _f; }
681   std::vector<FieldWalker2> getNonClassicalData() const { return _fw_prev->getNonClassicalData(); }
682 private:
683   const MEDFileAnyTypeFieldMultiTSWithoutSDA *_f;
684   mutable INTERP_KERNEL::AutoCppPtr<FieldWalker1> _fw;
685   mutable INTERP_KERNEL::AutoCppPtr<FieldWalker1> _fw_prev;
686 };
687
688 bool FieldWalker::isEmpty() const
689 {
690   return _fw_prev.isNull();
691 }
692
693 bool FieldWalker::isClassical() const
694 {
695   return _fw_prev->isClassical();
696 }
697
698 void FieldWalker::newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts)
699 {
700   _fw=new FieldWalker1(ts);
701 }
702
703 void FieldWalker::endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts)
704 {
705   if(_fw_prev.isNull())
706     _fw_prev=new FieldWalker1(*_fw);
707   else
708     _fw_prev->checkOK(*_fw);
709   _fw=0;
710 }
711
712 void FieldWalker::newMeshEntry(const MEDFileFieldPerMesh *fpm)
713 {
714   _fw->newMeshEntry(fpm);
715 }
716
717 void FieldWalker::endMeshEntry(const MEDFileFieldPerMesh *fpm)
718 {
719   _fw->endMeshEntry(fpm);
720 }
721
722 void FieldWalker::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
723 {
724   _fw->newPerMeshPerTypeEntry(pmpt);
725 }
726
727 void FieldWalker::endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
728 {
729   _fw->endPerMeshPerTypeEntry(pmpt);
730 }
731
732 void FieldWalker::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd)
733 {
734   _fw->newPerMeshPerTypePerDisc(pmptpd);
735 }
736
737 // this class splits fields into same
738 class LocSpliter : public MEDFileFieldVisitor
739 {
740 public:
741   LocSpliter(const MEDFileFieldGlobsReal *globs):_globs(globs),_fw(0) { }
742   MCAuto<MEDFileFields> getClassical() const { return _classical; }
743   void generateNonClassicalData(const MEDFileUMesh *mesh, std::vector< MCAuto<MEDFileFields> >& outFields, std::vector< MCAuto<MEDFileUMesh> >& outMeshes) const;
744 private:
745   void newFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field);
746   void endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field);
747   //
748   void newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts);
749   void endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts);
750   //
751   void newMeshEntry(const MEDFileFieldPerMesh *fpm);
752   void endMeshEntry(const MEDFileFieldPerMesh *fpm);
753   //
754   void newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
755   void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
756   //
757   void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd);
758 private:
759   const MEDFileFieldGlobsReal *_globs;
760   std::vector< LocInfo > _locs;
761   std::vector< MCAuto<MEDFileFields> > _fields_on_locs;//size of _locs== size of _fields_on_locs
762   MCAuto<MEDFileFields> _classical;
763 private:
764   mutable INTERP_KERNEL::AutoCppPtr<FieldWalker> _fw;
765 };
766
767 void LocSpliter::newFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field)
768 {
769   _fw=new FieldWalker(field);
770 }
771
772 void LocSpliter::endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field)
773 {
774   if(_fw->isEmpty())
775     return ;
776   MCAuto<MEDFileAnyTypeFieldMultiTS> f(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(field)));
777   if(_fw->isClassical())
778     {
779       if(_classical.isNull())
780         {
781           _classical=MEDFileFields::New();
782           _classical->shallowCpyGlobs(*_globs);
783         }
784       _classical->pushField(f);
785     }
786   else
787     {
788       std::vector<FieldWalker2> fw2(_fw->getNonClassicalData());
789       LocInfo elt(fw2);
790       std::vector< LocInfo >::iterator it(std::find(_locs.begin(),_locs.end(),elt));
791       if(it==_locs.end())
792         {
793           _locs.push_back(elt);
794           MCAuto<MEDFileFields> zeF(MEDFileFields::New());
795           zeF->shallowCpyGlobs(*_globs);
796           zeF->pushField(f);
797           _fields_on_locs.push_back(zeF);
798         }
799       else
800         {
801           MCAuto<MEDFileFields> zeF(_fields_on_locs[std::distance(_locs.begin(),it)]);
802           zeF->pushField(f);
803         }
804     }
805 }
806
807 void LocSpliter::generateNonClassicalData(const MEDFileUMesh *mesh, std::vector< MCAuto<MEDFileFields> >& outFields, std::vector< MCAuto<MEDFileUMesh> >& outMeshes) const
808 {
809   int i(0);
810   for(std::vector<LocInfo>::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
811     {
812       MCAuto<MEDFileUMesh> m((*it).generateNonClassicalData(i,mesh,_globs));
813       outMeshes.push_back(m);
814       MCAuto<MEDCouplingUMesh> mcm(MEDCouplingUMesh::Build0DMeshFromCoords(m->getCoords()));
815       mcm->setName(m->getName());
816       MCAuto<MEDFileFields> fs(_fields_on_locs[i]);
817       MCAuto<MEDFileFields> outFs(MEDFileFields::New());
818       for(int j=0;j<fs->getNumberOfFields();j++)
819         {
820           MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsNC(fs->getFieldAtPos(j));
821           MCAuto<MEDFileFieldMultiTS> fmts(DynamicCastSafe<MEDFileAnyTypeFieldMultiTS,MEDFileFieldMultiTS>(fmtsNC));
822           MCAuto<MEDFileFieldMultiTS> outFmts(MEDFileFieldMultiTS::New());
823           for(int k=0;k<fmts->getNumberOfTS();k++)
824             {
825               MCAuto<MEDFileField1TS> outF1t(MEDFileField1TS::New());
826               MCAuto<MEDFileField1TS> f1ts(fmts->getTimeStepAtPos(k));
827               int t2,t3;
828               double t1(f1ts->getTime(t2,t3));
829               MCAuto<MEDCouplingFieldDouble> mcf(MEDCouplingFieldDouble::New(ON_NODES));
830               MCAuto<DataArrayDouble> arr,arr2;
831               arr.takeRef(f1ts->getUndergroundDataArray());
832               arr2=arr->selectPartDef((*it).getPartDef());
833               mcf->setArray(arr2);
834               mcf->setTime(t1,t2,t3);
835               mcf->setName(f1ts->getName());
836               mcf->setMesh(mcm);
837               outF1t->setFieldNoProfileSBT(mcf);
838               outFmts->pushBackTimeStep(outF1t);
839             }
840           outFs->pushField(outFmts);
841         }
842       outFields.push_back(outFs);
843     }
844 }
845
846 void LocSpliter::newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts)
847 {
848   _fw->newTimeStepEntry(ts);
849 }
850
851 void LocSpliter::endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts)
852 {
853   _fw->endTimeStepEntry(ts);
854 }
855
856 void LocSpliter::newMeshEntry(const MEDFileFieldPerMesh *fpm)
857 {
858   _fw->newMeshEntry(fpm);
859 }
860
861 void LocSpliter::endMeshEntry(const MEDFileFieldPerMesh *fpm)
862 {
863   _fw->endMeshEntry(fpm);
864 }
865
866 void LocSpliter::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
867 {
868   _fw->newPerMeshPerTypeEntry(pmpt);
869 }
870
871 void LocSpliter::endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
872 {
873   _fw->endPerMeshPerTypeEntry(pmpt);
874 }
875
876 void LocSpliter::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd)
877 {
878   _fw->newPerMeshPerTypePerDisc(pmptpd);
879 }
880
881 void MEDFileBlowStrEltUp::DealWithConflictNames(MEDFileAnyTypeFieldMultiTS *fmtsToAdd, const MEDFileFields *fs)
882 {
883   std::vector<std::string> fnames(fs->getFieldsNames());
884   for(int i=0;i<1000;i++)
885     {
886       std::ostringstream oss; oss << fmtsToAdd->getName();
887       if(i>=1)
888         oss << "_" << i-1;
889       if(std::find(fnames.begin(),fnames.end(),oss.str())==fnames.end())
890         {
891           fmtsToAdd->setName(oss.str());
892           return ;
893         }
894     }
895   throw INTERP_KERNEL::Exception("DealWithConflictNames : Eh eh interesting !");
896 }
897
898 MCAuto<MEDFileFields> MEDFileBlowStrEltUp::splitFieldsPerLoc(const MEDFileFields *fields, const MEDFileUMesh *mesh, MEDFileMeshes *msOut, MEDFileFields *allZeOutFields)
899 {
900   LocSpliter ls(fields);
901   fields->accept(ls);
902   std::vector< MCAuto<MEDFileFields> > outFields;
903   std::vector< MCAuto<MEDFileUMesh> > outMeshes;
904   ls.generateNonClassicalData(mesh,outFields,outMeshes);
905   for(std::vector< MCAuto<MEDFileFields> >::iterator it=outFields.begin();it!=outFields.end();it++)
906     {
907       for(int j=0;j<(*it)->getNumberOfFields();j++)
908         {
909           MCAuto<MEDFileAnyTypeFieldMultiTS> fmts((*it)->getFieldAtPos(j));
910           //DealWithConflictNames(fmts,allZeOutFields);// uncomment to have a writable data structure
911           allZeOutFields->pushField(fmts);
912         }
913     }
914   for(std::vector< MCAuto<MEDFileUMesh> >::iterator it=outMeshes.begin();it!=outMeshes.end();it++)
915     msOut->pushMesh(*it);
916   return ls.getClassical();
917 }