1 // Copyright (C) 2007-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #include "MEDFileBlowStrEltUp.hxx"
22 #include "MEDCouplingFieldDouble.hxx"
23 #include "MEDFileFieldVisitor.hxx"
24 #include "MEDCouplingPartDefinition.hxx"
27 using namespace MEDCoupling;
29 const char MEDFileBlowStrEltUp::MED_BALL_STR[]="MED_BALL";
31 MEDFileBlowStrEltUp::MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MEDFileMeshes *ms, const MEDFileStructureElements *ses)
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());
40 for(std::size_t i=0;i<sz;i++)
42 const std::pair<std::string,std::string>& p(ps[i]);
43 MCAuto<MEDFileFields> f(fsOnlyOnSE->partOfThisLyingOnSpecifiedMeshSEName(p.first,p.second));
46 for(std::size_t i=0;i<sz;i++)
48 const std::pair<std::string,std::string>& p(ps[i]);
49 MEDFileMesh *mesh(_ms->getMeshWithName(p.first));
51 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp : NULL mesh !");
52 MEDFileUMesh *umesh(dynamic_cast<MEDFileUMesh *>(mesh));
54 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp : Blow up of Stru Elt not managed yet for unstructured meshes !");
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
63 MCAuto<MEDFileEltStruct4Mesh> MEDFileBlowStrEltUp::dealWithSEInMesh(const std::string& seName, MEDFileUMesh *mesh, MCAuto<MEDFileUMesh>& mOut, MCAuto<MEDFileFields>& fsOut) const
66 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInMesh : null pointer !");
67 if(seName==MED_BALL_STR)
69 MCAuto<MEDFileEltStruct4Mesh> ret(dealWithMEDBALLInMesh(mesh,mOut,fsOut));
70 mesh->killStructureElements();
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 !");
76 MCAuto<MEDFileEltStruct4Mesh> MEDFileBlowStrEltUp::dealWithMEDBALLInMesh(const MEDFileUMesh *mesh, MCAuto<MEDFileUMesh>& mOut, MCAuto<MEDFileFields>& fsOut) const
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++)
83 if((*it)->getGeoTypeName()==MED_BALL_STR)
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());
94 const DataArrayDouble *coo(mesh->getCoords());
96 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : null coords !");
97 MCAuto<DataArrayInt> conn(zeStr->getConn());
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));
111 MCAuto<DataArrayInt> ff1o(ff1->selectByTupleIdSafe(conn->begin(),conn->end()));
112 mOut->setFamilyFieldArr(1,ff1o);
114 const DataArrayInt *nf1(mesh->getNumberFieldAtLevel(1));
117 MCAuto<DataArrayInt> nf1o(nf1->selectByTupleIdSafe(conn->begin(),conn->end()));
118 mOut->setRenumFieldArr(1,nf1o);
120 MCAuto<MEDFileUMeshPerTypeCommon> md(zeStr->getMeshDef());
121 const DataArrayInt *ff0(md->getFam());
123 mOut->setFamilyFieldArr(0,const_cast<DataArrayInt *>(ff0));
124 const DataArrayInt *nf0(md->getNum());
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++)
131 const DataArray *elt(*it);
135 const DataArrayDouble *eltC(dynamic_cast<const DataArrayDouble *>(elt));
138 MCAuto<MEDFileFieldMultiTS> fmts(MEDFileFieldMultiTS::New());
139 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
140 MCAuto<MEDCouplingFieldDouble> f(MEDCouplingFieldDouble::New(ON_NODES));
142 f->setArray(const_cast<DataArrayDouble *>(eltC));
143 f->setName(eltC->getName());
144 f1ts->setFieldNoProfileSBT(f);
145 fmts->pushBackTimeStep(f1ts);
146 fsOut->pushField(fmts);
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
159 void MEDFileBlowStrEltUp::dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const
162 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInFields : null pointer !");
163 if(seName==MED_BALL_STR)
165 dealWithMEDBALLSInFields(fs,zeStr,varAtt,zeOutputs);
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 !");
171 void MEDFileBlowStrEltUp::dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const
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++)
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++)
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);
192 elts0.push_back(eltOut); elts1.push_back(eltOut);
195 const MEDFileMesh *zeCurrentMesh(_ms->getMeshWithName(zeMeshName));
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++)
201 std::vector< MCAuto<MEDFileFastCellSupportComparator> > fsc;
202 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > sp2(MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(*it0,zeCurrentMesh,fsc));
204 for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it1=sp2.begin();it1!=sp2.end();it1++,jj++)
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.
210 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath !");
211 MCAuto<MEDFileAnyTypeField1TS> zeGuideForPfl;// This var is the reference for pfl management.
214 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath 2 !");
215 int pdm((*it1)[0]->getNumberOfTS());
217 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath 3 !");
218 zeGuideForPfl=(*it1)[0]->getTimeStepAtPos(0);
220 if(zeGuideForPfl.isNull())
221 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath 4 !");
222 std::vector<std::string> pfls(zeGuideForPfl->getPflsReallyUsed());
224 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : drink less coffee");
225 MCAuto<DataArrayInt> pflMyLove;
227 pflMyLove.takeRef(zeGuideForPfl->getProfile(pfls[0]));
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++)
235 MCAuto<MEDFileAnyTypeFieldMultiTS> elt(varAtt->getFieldAtPos(i));
236 int nbTS2(elt->getNumberOfTS());
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++)
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);
250 zeOutputs->pushField(elt4);
256 void MEDFileBlowStrEltUp::generate(MEDFileMeshes *msOut, MEDFileFields *allZeOutFields)
258 for(std::vector< MCAuto<MEDFileFields> >::iterator elt=_elts.begin();elt!=_elts.end();elt++)
260 std::vector< std::pair<std::string,std::string> > ps;
261 (*elt)->getMeshSENames(ps);
263 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : internal error !");
264 MEDFileMesh *mesh(_ms->getMeshWithName(ps[0].first));
266 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : NULL mesh !");
267 MEDFileUMesh *umesh(dynamic_cast<MEDFileUMesh *>(mesh));
269 throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : Blow up of Stru Elt not managed yet for unstructured meshes !");
271 MCAuto<MEDFileFields> classicalSEFields(splitFieldsPerLoc(*elt,umesh,msOut,allZeOutFields));
272 if(classicalSEFields.isNotNull())
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);
283 std::string MEDFileBlowStrEltUp::BuildNewMeshName(const std::string& meshName, const std::string& seName)
285 std::ostringstream mNameOut;
286 mNameOut << meshName << "_" << seName;
287 return mNameOut.str();
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)
292 if(totINbParts==1 && totJNbParts==1)
294 std::ostringstream oss;
295 oss << name << "@" << iPart << "@" << jPart;
299 void MEDFileBlowStrEltUp::DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const MEDFileStructureElements *ses)
301 MCAuto<MEDFileFields> fsSEOnly(fs->partOfThisOnStructureElements());
302 fs->killStructureElements();
303 MEDFileBlowStrEltUp bu(fsSEOnly,ms,ses);
305 fs->killStructureElementsInGlobs();
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; }
324 MCAuto<SlicePartDefinition> _pd;
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; }
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> BuildMeshFromStructure(INTERP_KERNEL::NormalizedCellType gt, const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs);
341 static const char ANGLE_DE_VRILLE[];
343 std::vector<std::string> _locs;
344 std::vector<std::string> _pfl;
345 MCAuto<PartDefinition> _pd;
348 const char LocInfo::ANGLE_DE_VRILLE[]="ANGLE DE VRILLE";
350 LocInfo::LocInfo(const std::vector<FieldWalker2>& fw)
352 std::size_t sz(fw.size());
353 _locs.resize(sz); _pfl.resize(sz);
355 _pd=fw[0].getPartDef()->deepCopy();
356 for(std::size_t i=0;i<sz;i++)
358 _locs[i]=fw[i].getLoc();
359 _pfl[i]=fw[i].getPfl();
361 _pd=(*_pd)+(*(fw[i].getPartDef()));
365 void LocInfo::checkUniqueLoc(const std::string& loc) const
367 if(std::find(_locs.begin(),_locs.end(),loc)!=_locs.end())
369 std::ostringstream oss; oss << "LocInfo::checkUniqueLoc : loc \"" << loc << "\" already exists !";
370 throw INTERP_KERNEL::Exception(oss.str());
374 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)
376 MCAuto<DataArrayInt> conn(zeStr->getConn());
377 conn=conn->deepCopy(); conn->rearrange(1);
378 MCAuto<MEDCouplingUMesh> geoMesh;
380 MCAuto<MEDCoupling1SGTUMesh> umesh(MEDCoupling1SGTUMesh::New("",gt));
381 umesh->setCoords(mesh->getCoords());
382 umesh->setNodalConnectivity(conn);
383 geoMesh=umesh->buildUnstructured();
386 MCConstAuto<DataArrayDouble> angleVrille;
389 const DataArrayInt *pflArr(globs->getProfile(pfl));
390 geoMesh=geoMesh->buildPartOfMySelf(pflArr->begin(),pflArr->end(),true);
391 angleVrille=angleDeVrille->selectByTupleIdSafe(pflArr->begin(),pflArr->end());
394 angleVrille.takeRef(angleDeVrille);
396 MCAuto<MEDCouplingFieldDouble> fakeF(MEDCouplingFieldDouble::New(ON_GAUSS_PT));
397 fakeF->setMesh(geoMesh);
398 int nbg(loc.getGaussWeights().size());
399 fakeF->setGaussLocalizationOnType(gt,loc.getRefCoords(),loc.getGaussCoords(),loc.getGaussWeights());
400 MCAuto<DataArrayDouble> ptsForLoc(fakeF->getLocalizationOfDiscr());
402 MCAuto<MEDCouplingFieldDouble> dir(geoMesh->buildDirectionVectorField());
403 MCAuto<DataArrayDouble> rot(dir->getArray()->fromCartToSpher());
404 int nbCells(geoMesh->getNumberOfCells()),nbCompo(ptsForLoc->getNumberOfComponents());
405 MCAuto<DataArrayDouble> secPts(section->getCoords()->changeNbOfComponents(nbCompo,0.));
406 int nbSecPts(secPts->getNumberOfTuples());
408 const int TAB[3]={2,0,1};
409 std::vector<int> v(TAB,TAB+3);
410 secPts=secPts->keepSelectedComponents(v);
412 const double CENTER[3]={0.,0.,0.},AX0[3]={0.,0.,1.};
413 double AX1[3]; AX1[2]=0.;
414 std::vector< MCAuto<DataArrayDouble> > arrs(nbCells*nbg);
415 for(int j=0;j<nbCells;j++)
417 MCAuto<DataArrayDouble> p(secPts->deepCopy());
418 double ang0(rot->getIJ(j,2));
419 DataArrayDouble::Rotate3DAlg(CENTER,AX0,ang0,nbSecPts,p->begin(),p->getPointer());
420 AX1[0]=-sin(ang0); AX1[1]=cos(ang0);// rot Oy around OZ
421 double ang1(M_PI/2.-rot->getIJ(j,1));
422 DataArrayDouble::Rotate3DAlg(CENTER,AX1,-ang1,nbSecPts,p->begin(),p->getPointer());
423 DataArrayDouble::Rotate3DAlg(CENTER,dir->getArray()->begin()+j*3,angleVrille->getIJ(j,0),nbSecPts,p->begin(),p->getPointer());
424 for(int l=0;l<nbg;l++)
426 MCAuto<DataArrayDouble> p2(p->deepCopy());
427 for(int k=0;k<nbCompo;k++)
428 p2->applyLin(1.,ptsForLoc->getIJ(j*nbg+l,k),k);
432 std::vector<const DataArrayDouble *> arrs2(VecAutoToVecOfCstPt(arrs));
433 MCAuto<DataArrayDouble> resu(DataArrayDouble::Aggregate(arrs2));
437 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)
439 static const char MSG1[]="BuildMeshFromStructure : not recognized pattern ! Send mail to anthony.geay@edf.fr with corresponding MED file !";
440 const std::vector< MCAuto<DataArray> >& vars(zeStr->getVars());
442 throw INTERP_KERNEL::Exception(MSG1);
443 MCAuto<DataArray> zeArr(vars[0]);
445 throw INTERP_KERNEL::Exception(MSG1);
446 MCAuto<DataArrayDouble> zeArr2(DynamicCast<DataArray,DataArrayDouble>(zeArr));
448 throw INTERP_KERNEL::Exception(MSG1);
449 if(zeArr2->getName()!=ANGLE_DE_VRILLE)
450 throw INTERP_KERNEL::Exception(MSG1);
451 return BuildMeshFromAngleVrille(gt,zeArr2,pfl,loc,zeStr,mesh,section,globs);
454 MCAuto<MEDFileUMesh> LocInfo::generateNonClassicalData(int zePos, const MEDFileUMesh *mesh, const MEDFileFieldGlobsReal *globs) const
456 static const char MSG1[]="LocInfo::generateNonClassicalData : no spec for GAUSS on StructureElement with more than one cell !";
457 std::size_t sz(_locs.size());
458 std::vector< MCAuto<DataArrayDouble> > arrs(sz);
459 for(std::size_t i=0;i<sz;i++)
461 const MEDFileFieldLoc& loc(globs->getLocalization(_locs[i]));
462 const MEDFileGTKeeper *gtk(loc.getUndergroundGTKeeper());
463 const MEDFileGTKeeperDyn *gtk2(dynamic_cast<const MEDFileGTKeeperDyn *>(gtk));
465 throw INTERP_KERNEL::Exception("LocInfo::generateNonClassicalData : internal error !");
466 const MEDFileUMesh *meshLoc(gtk2->getMesh()),*section(gtk2->getSection());
467 const MEDFileStructureElement *se(gtk2->getSE());
468 INTERP_KERNEL::NormalizedCellType gt;
470 std::vector<int> nel(meshLoc->getNonEmptyLevels());
472 throw INTERP_KERNEL::Exception(MSG1);
474 throw INTERP_KERNEL::Exception(MSG1);
475 MCAuto<MEDCouplingUMesh> um(meshLoc->getMeshAtLevel(0));
476 if(um->getNumberOfCells()!=1)
477 throw INTERP_KERNEL::Exception(MSG1);
478 gt=um->getTypeOfCell(0);
480 um->getNodeIdsOfCell(0,v);
481 std::size_t sz2(v.size());
482 for(std::size_t j=0;j<sz2;j++)
484 throw INTERP_KERNEL::Exception(MSG1);
486 const std::vector< MCAuto<MEDFileEltStruct4Mesh> >& strs(mesh->getAccessOfUndergroundEltStrs());
487 MCAuto<MEDFileEltStruct4Mesh> zeStr;
488 for(std::vector< MCAuto<MEDFileEltStruct4Mesh> >::const_iterator it=strs.begin();it!=strs.end();it++)
490 if((*it)->getGeoTypeName()==se->getName())
498 std::ostringstream oss; oss << "LocInfo::generateNonClassicalData : : no geo type with name " << se->getName() << " in " << mesh->getName() << " !";
499 throw INTERP_KERNEL::Exception(oss.str());
501 arrs[i]=BuildMeshFromStructure(gt,_pfl[i],loc,zeStr,mesh,section,globs);
503 std::vector<const DataArrayDouble *> arrs2(VecAutoToVecOfCstPt(arrs));
504 MCAuto<DataArrayDouble> resu(DataArrayDouble::Aggregate(arrs2));
505 MCAuto<MEDFileUMesh> ret(MEDFileUMesh::New());
506 ret->setCoords(resu);
507 std::ostringstream meshName; meshName << mesh->getName() << "_on_" << sz << "_sections" << "_" << zePos;
508 ret->setName(meshName.str());
512 FieldWalker2::FieldWalker2(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd)
514 _loc=pmptpd->getLocalization();
515 _pfl=pmptpd->getProfile();
516 _is_classic=pmptpd->getType()!=ON_GAUSS_PT;
517 _pd=SlicePartDefinition::New(pmptpd->getStart(),pmptpd->getEnd(),1);
520 bool FieldWalker2::operator!=(const FieldWalker2& other) const
522 return !((*this)==other);
525 bool FieldWalker2::operator==(const FieldWalker2& other) const
530 ret2=_pd->isEqual(other._pd,tmp);
532 bool ret(_loc==other._loc && _pfl==other._pfl && _is_classic==other._is_classic && ret2);
539 FieldWalker1(const MEDFileAnyTypeField1TSWithoutSDA *ts):_ts(ts),_pm_pt(0),_nb_mesh(0) { }
540 void newMeshEntry(const MEDFileFieldPerMesh *fpm);
541 void endMeshEntry(const MEDFileFieldPerMesh *fpm) { }
542 void newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
543 void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
544 void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd);
545 void checkOK(const FieldWalker1& other) const;
546 bool isClassical() const;
547 std::vector<FieldWalker2> getNonClassicalData() const { return _fw; }
549 const MEDFileAnyTypeField1TSWithoutSDA *_ts;
550 const MEDFileFieldPerMeshPerTypeDyn *_pm_pt;
551 std::vector<FieldWalker2> _fw;
555 void FieldWalker1::newMeshEntry(const MEDFileFieldPerMesh *fpm)
558 throw INTERP_KERNEL::Exception("FieldWalker1::newMeshEntry : multi mesh not supported !");
561 void FieldWalker1::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
564 throw INTERP_KERNEL::Exception("FieldWalker1::newPerMeshPerTypeEntry : multi SE loc not managed yet !");
565 const MEDFileFieldPerMeshPerTypeDyn *pmpt2(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>(pmpt));
567 throw INTERP_KERNEL::Exception("newPerMeshPerTypeEntry : internal error !");
571 void FieldWalker1::endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *)
576 void FieldWalker1::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd)
578 _fw.push_back(FieldWalker2(pmptpd));
581 void FieldWalker1::checkOK(const FieldWalker1& other) const
583 std::size_t sz(_fw.size());
584 if(other._fw.size()!=sz)
585 throw INTERP_KERNEL::Exception("checkOK : not OK because size are not the same !");
586 for(std::size_t i=0;i<sz;i++)
587 if(_fw[i]!=other._fw[i])
588 throw INTERP_KERNEL::Exception("checkOK : not OK because an element mismatches !");
591 bool FieldWalker1::isClassical() const
594 throw INTERP_KERNEL::Exception("FieldWalker1::endPerMeshPerTypeEntry : internal error !");
595 std::size_t ic(0),inc(0);
596 for(std::vector<FieldWalker2>::const_iterator it=_fw.begin();it!=_fw.end();it++)
598 if((*it).isClassic())
604 throw INTERP_KERNEL::Exception("FieldWalker1::endPerMeshPerTypeEntry : mix is not allowed yet !");
611 FieldWalker(const MEDFileAnyTypeFieldMultiTSWithoutSDA *f):_f(f) { }
612 void newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts);
613 void endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts);
614 void newMeshEntry(const MEDFileFieldPerMesh *fpm);
615 void endMeshEntry(const MEDFileFieldPerMesh *fpm);
616 void newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
617 void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
618 void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd);
620 bool isEmpty() const;
621 bool isClassical() const;
622 const MEDFileAnyTypeFieldMultiTSWithoutSDA *field() const { return _f; }
623 std::vector<FieldWalker2> getNonClassicalData() const { return _fw_prev->getNonClassicalData(); }
625 const MEDFileAnyTypeFieldMultiTSWithoutSDA *_f;
626 mutable INTERP_KERNEL::AutoCppPtr<FieldWalker1> _fw;
627 mutable INTERP_KERNEL::AutoCppPtr<FieldWalker1> _fw_prev;
630 bool FieldWalker::isEmpty() const
632 return _fw_prev.isNull();
635 bool FieldWalker::isClassical() const
637 return _fw_prev->isClassical();
640 void FieldWalker::newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts)
642 _fw=new FieldWalker1(ts);
645 void FieldWalker::endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts)
647 if(_fw_prev.isNull())
648 _fw_prev=new FieldWalker1(*_fw);
650 _fw_prev->checkOK(*_fw);
654 void FieldWalker::newMeshEntry(const MEDFileFieldPerMesh *fpm)
656 _fw->newMeshEntry(fpm);
659 void FieldWalker::endMeshEntry(const MEDFileFieldPerMesh *fpm)
661 _fw->endMeshEntry(fpm);
664 void FieldWalker::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
666 _fw->newPerMeshPerTypeEntry(pmpt);
669 void FieldWalker::endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
671 _fw->endPerMeshPerTypeEntry(pmpt);
674 void FieldWalker::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd)
676 _fw->newPerMeshPerTypePerDisc(pmptpd);
679 // this class splits fields into same
680 class LocSpliter : public MEDFileFieldVisitor
683 LocSpliter(const MEDFileFieldGlobsReal *globs):_globs(globs),_fw(0) { }
684 MCAuto<MEDFileFields> getClassical() const { return _classical; }
685 void generateNonClassicalData(const MEDFileUMesh *mesh, std::vector< MCAuto<MEDFileFields> >& outFields, std::vector< MCAuto<MEDFileUMesh> >& outMeshes) const;
687 void newFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field);
688 void endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field);
690 void newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts);
691 void endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts);
693 void newMeshEntry(const MEDFileFieldPerMesh *fpm);
694 void endMeshEntry(const MEDFileFieldPerMesh *fpm);
696 void newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
697 void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt);
699 void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd);
701 const MEDFileFieldGlobsReal *_globs;
702 std::vector< LocInfo > _locs;
703 std::vector< MCAuto<MEDFileFields> > _fields_on_locs;//size of _locs== size of _fields_on_locs
704 MCAuto<MEDFileFields> _classical;
706 mutable INTERP_KERNEL::AutoCppPtr<FieldWalker> _fw;
709 void LocSpliter::newFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field)
711 _fw=new FieldWalker(field);
714 void LocSpliter::endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field)
718 MCAuto<MEDFileAnyTypeFieldMultiTS> f(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(field)));
719 if(_fw->isClassical())
721 if(_classical.isNull())
723 _classical=MEDFileFields::New();
724 _classical->shallowCpyGlobs(*_globs);
726 _classical->pushField(f);
730 std::vector<FieldWalker2> fw2(_fw->getNonClassicalData());
732 std::vector< LocInfo >::iterator it(std::find(_locs.begin(),_locs.end(),elt));
735 _locs.push_back(elt);
736 MCAuto<MEDFileFields> zeF(MEDFileFields::New());
737 zeF->shallowCpyGlobs(*_globs);
739 _fields_on_locs.push_back(zeF);
743 MCAuto<MEDFileFields> zeF(_fields_on_locs[std::distance(_locs.begin(),it)]);
749 void LocSpliter::generateNonClassicalData(const MEDFileUMesh *mesh, std::vector< MCAuto<MEDFileFields> >& outFields, std::vector< MCAuto<MEDFileUMesh> >& outMeshes) const
752 for(std::vector<LocInfo>::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
754 MCAuto<MEDFileUMesh> m((*it).generateNonClassicalData(i,mesh,_globs));
755 outMeshes.push_back(m);
756 MCAuto<MEDCouplingUMesh> mcm(MEDCouplingUMesh::Build0DMeshFromCoords(m->getCoords()));
757 mcm->setName(m->getName());
758 MCAuto<MEDFileFields> fs(_fields_on_locs[i]);
759 MCAuto<MEDFileFields> outFs(MEDFileFields::New());
760 for(int j=0;j<fs->getNumberOfFields();j++)
762 MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsNC(fs->getFieldAtPos(j));
763 MCAuto<MEDFileFieldMultiTS> fmts(DynamicCastSafe<MEDFileAnyTypeFieldMultiTS,MEDFileFieldMultiTS>(fmtsNC));
764 MCAuto<MEDFileFieldMultiTS> outFmts(MEDFileFieldMultiTS::New());
765 for(int k=0;k<fmts->getNumberOfTS();k++)
767 MCAuto<MEDFileField1TS> outF1t(MEDFileField1TS::New());
768 MCAuto<MEDFileField1TS> f1ts(fmts->getTimeStepAtPos(k));
770 double t1(f1ts->getTime(t2,t3));
771 MCAuto<MEDCouplingFieldDouble> mcf(MEDCouplingFieldDouble::New(ON_NODES));
772 MCAuto<DataArrayDouble> arr,arr2;
773 arr.takeRef(f1ts->getUndergroundDataArray());
774 arr2=arr->selectPartDef((*it).getPartDef());
776 mcf->setTime(t1,t2,t3);
777 mcf->setName(f1ts->getName());
779 outF1t->setFieldNoProfileSBT(mcf);
780 outFmts->pushBackTimeStep(outF1t);
782 outFs->pushField(outFmts);
784 outFields.push_back(outFs);
788 void LocSpliter::newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts)
790 _fw->newTimeStepEntry(ts);
793 void LocSpliter::endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts)
795 _fw->endTimeStepEntry(ts);
798 void LocSpliter::newMeshEntry(const MEDFileFieldPerMesh *fpm)
800 _fw->newMeshEntry(fpm);
803 void LocSpliter::endMeshEntry(const MEDFileFieldPerMesh *fpm)
805 _fw->endMeshEntry(fpm);
808 void LocSpliter::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
810 _fw->newPerMeshPerTypeEntry(pmpt);
813 void LocSpliter::endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt)
815 _fw->endPerMeshPerTypeEntry(pmpt);
818 void LocSpliter::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd)
820 _fw->newPerMeshPerTypePerDisc(pmptpd);
823 void MEDFileBlowStrEltUp::DealWithConflictNames(MEDFileAnyTypeFieldMultiTS *fmtsToAdd, const MEDFileFields *fs)
825 std::vector<std::string> fnames(fs->getFieldsNames());
826 for(int i=0;i<1000;i++)
828 std::ostringstream oss; oss << fmtsToAdd->getName();
831 if(std::find(fnames.begin(),fnames.end(),oss.str())==fnames.end())
833 fmtsToAdd->setName(oss.str());
837 throw INTERP_KERNEL::Exception("DealWithConflictNames : Eh eh interesting !");
840 MCAuto<MEDFileFields> MEDFileBlowStrEltUp::splitFieldsPerLoc(const MEDFileFields *fields, const MEDFileUMesh *mesh, MEDFileMeshes *msOut, MEDFileFields *allZeOutFields)
842 LocSpliter ls(fields);
844 std::vector< MCAuto<MEDFileFields> > outFields;
845 std::vector< MCAuto<MEDFileUMesh> > outMeshes;
846 ls.generateNonClassicalData(mesh,outFields,outMeshes);
847 for(std::vector< MCAuto<MEDFileFields> >::iterator it=outFields.begin();it!=outFields.end();it++)
849 for(int j=0;j<(*it)->getNumberOfFields();j++)
851 MCAuto<MEDFileAnyTypeFieldMultiTS> fmts((*it)->getFieldAtPos(j));
852 //DealWithConflictNames(fmts,allZeOutFields);// uncomment to have a writable data structure
853 allZeOutFields->pushField(fmts);
856 for(std::vector< MCAuto<MEDFileUMesh> >::iterator it=outMeshes.begin();it!=outMeshes.end();it++)
857 msOut->pushMesh(*it);
858 return ls.getClassical();