From: Anthony Geay Date: Tue, 14 Feb 2017 08:45:58 +0000 (+0100) Subject: Yeah man it works ! a rotation still missing X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4c7a7804a1a4fb399a424042fdfd47a95cb870b5;p=tools%2Fmedcoupling.git Yeah man it works ! a rotation still missing --- diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.cxx b/src/MEDLoader/MEDFileBlowStrEltUp.cxx index a0f0e507e..bc5ecae84 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.cxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.cxx @@ -267,9 +267,7 @@ void MEDFileBlowStrEltUp::generate(MEDFileMeshes *msOut, MEDFileFields *allZeOut if(!umesh) throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : Blow up of Stru Elt not managed yet for unstructured meshes !"); // - std::vector< MCAuto > elts2; - std::vector< MCAuto > elts3; - MCAuto classicalSEFields(splitFieldsPerLoc(*elt,umesh,elts2,elts3)); + MCAuto classicalSEFields(splitFieldsPerLoc(*elt,umesh,msOut,allZeOutFields)); if(classicalSEFields.isNotNull()) { MCAuto mOut; @@ -278,9 +276,6 @@ void MEDFileBlowStrEltUp::generate(MEDFileMeshes *msOut, MEDFileFields *allZeOut msOut->pushMesh(mOut); dealWithSEInFields(ps[0].second,classicalSEFields,zeStr,fsOut1,allZeOutFields); } - /*for(std::vector< MCAuto >::iterator elt2=elts2.begin();elt2!=elts2.end();elt2++) - { - }*/ } } @@ -306,6 +301,7 @@ void MEDFileBlowStrEltUp::DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const fs->killStructureElements(); MEDFileBlowStrEltUp bu(fsSEOnly,ms,ses); bu.generate(ms,fs); + fs->killStructureElementsInGlobs(); } // @@ -332,14 +328,20 @@ public: LocInfo(const std::vector& fw); bool operator==(const LocInfo& other) const { return _locs==other._locs && _pfl==other._pfl; } void push(const std::string& loc, const std::string& pfl) { checkUniqueLoc(loc); _locs.push_back(loc); _pfl.push_back(pfl); } - void generateNonClassicalData(const MEDFileUMesh *mesh, const MEDFileFieldGlobsReal *globs) const; + MCAuto generateNonClassicalData(int zePos, const MEDFileUMesh *mesh, const MEDFileFieldGlobsReal *globs) const; private: void checkUniqueLoc(const std::string& loc) const; + static MCAuto 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); + static MCAuto BuildMeshFromStructure(INTERP_KERNEL::NormalizedCellType gt, const std::string& pfl, const MEDFileFieldLoc& loc, const MEDFileEltStruct4Mesh *zeStr, const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileFieldGlobsReal *globs); +public: + static const char ANGLE_DE_VRILLE[]; private: std::vector _locs; std::vector _pfl; }; +const char LocInfo::ANGLE_DE_VRILLE[]="ANGLE DE VRILLE"; + LocInfo::LocInfo(const std::vector& fw) { std::size_t sz(fw.size()); @@ -360,10 +362,91 @@ void LocInfo::checkUniqueLoc(const std::string& loc) const } } -void LocInfo::generateNonClassicalData(const MEDFileUMesh *mesh, const MEDFileFieldGlobsReal *globs) const +MCAuto 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) +{ + MCAuto conn(zeStr->getConn()); + conn=conn->deepCopy(); conn->rearrange(1); + MCAuto geoMesh; + { + MCAuto umesh(MEDCoupling1SGTUMesh::New("",gt)); + umesh->setCoords(mesh->getCoords()); + umesh->setNodalConnectivity(conn); + geoMesh=umesh->buildUnstructured(); + } + // + MCAuto angleVrille(angleDeVrille->deepCopy()); + if(!pfl.empty()) + { + const DataArrayInt *pflArr(globs->getProfile(pfl)); + geoMesh=geoMesh->buildPartOfMySelf(pflArr->begin(),pflArr->end(),true); + angleVrille=angleVrille->selectByTupleIdSafe(pflArr->begin(),pflArr->end()); + } + // + MCAuto fakeF(MEDCouplingFieldDouble::New(ON_GAUSS_PT)); + fakeF->setMesh(geoMesh); + int nbg(loc.getGaussWeights().size()); + fakeF->setGaussLocalizationOnType(gt,loc.getRefCoords(),loc.getGaussCoords(),loc.getGaussWeights()); + MCAuto ptsForLoc(fakeF->getLocalizationOfDiscr()); + // + MCAuto rot; + { + MCAuto dir(geoMesh->buildDirectionVectorField()); + rot=dir->getArray()->fromCartToSpher(); + } + int nbCells(geoMesh->getNumberOfCells()),nbCompo(ptsForLoc->getNumberOfComponents()); + MCAuto secPts(section->getCoords()->changeNbOfComponents(nbCompo,0.)); + int nbSecPts(secPts->getNumberOfTuples()); + { + const int TAB[3]={2,0,1}; + std::vector v(TAB,TAB+3); + secPts=secPts->keepSelectedComponents(v); + } + const double CENTER[3]={0.,0.,0.},AX0[3]={0.,0.,1.}; + double AX1[3]; AX1[2]=0.; + std::vector< MCAuto > arrs(nbCells*nbg); + for(int j=0;j p(secPts->deepCopy()); + double ang0(rot->getIJ(j,2)); + DataArrayDouble::Rotate3DAlg(CENTER,AX0,ang0,nbSecPts,p->begin(),p->getPointer()); + AX1[0]=-sin(ang0); AX1[1]=cos(ang0);// rot Oy around OZ + double ang1(M_PI/2.-rot->getIJ(j,1)); + DataArrayDouble::Rotate3DAlg(CENTER,AX1,ang1,nbSecPts,p->begin(),p->getPointer()); + for(int l=0;l p2(p->deepCopy()); + for(int k=0;kapplyLin(1.,ptsForLoc->getIJ(j*nbg+l,k),k); + arrs[j*nbg+l]=p2; + } + } + std::vector arrs2(VecAutoToVecOfCstPt(arrs)); + MCAuto resu(DataArrayDouble::Aggregate(arrs2)); + return resu; +} + +MCAuto 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) +{ + static const char MSG1[]="BuildMeshFromStructure : not recognized pattern ! Send mail to anthony.geay@edf.fr with corresponding MED file !"; + const std::vector< MCAuto >& vars(zeStr->getVars()); + if(vars.size()!=1) + throw INTERP_KERNEL::Exception(MSG1); + MCAuto zeArr(vars[0]); + if(zeArr.isNull()) + throw INTERP_KERNEL::Exception(MSG1); + MCAuto zeArr2(DynamicCast(zeArr)); + if(zeArr2.isNull()) + throw INTERP_KERNEL::Exception(MSG1); + if(zeArr2->getName()!=ANGLE_DE_VRILLE) + throw INTERP_KERNEL::Exception(MSG1); + return BuildMeshFromAngleVrille(gt,zeArr2,pfl,loc,zeStr,mesh,section,globs); +} + +MCAuto LocInfo::generateNonClassicalData(int zePos, const MEDFileUMesh *mesh, const MEDFileFieldGlobsReal *globs) const { static const char MSG1[]="LocInfo::generateNonClassicalData : no spec for GAUSS on StructureElement with more than one cell !"; std::size_t sz(_locs.size()); + std::vector< MCAuto > arrs(sz); for(std::size_t i=0;igetLocalization(_locs[i])); @@ -406,77 +489,15 @@ void LocInfo::generateNonClassicalData(const MEDFileUMesh *mesh, const MEDFileFi std::ostringstream oss; oss << "LocInfo::generateNonClassicalData : : no geo type with name " << se->getName() << " in " << mesh->getName() << " !"; throw INTERP_KERNEL::Exception(oss.str()); } - MCAuto conn(zeStr->getConn()); - conn=conn->deepCopy(); conn->rearrange(1); - MCAuto geoMesh; - { - MCAuto umesh(MEDCoupling1SGTUMesh::New("",gt)); - umesh->setCoords(mesh->getCoords()); - umesh->setNodalConnectivity(conn); - geoMesh=umesh->buildUnstructured(); - } - // - std::string pfl(_pfl[i]); - if(!pfl.empty()) - { - const DataArrayInt *pflArr(globs->getProfile(pfl)); - geoMesh=geoMesh->buildPartOfMySelf(pflArr->begin(),pflArr->end(),true); - } - // - geoMesh->writeVTK("geo.vtu"); - // - MCAuto fakeF(MEDCouplingFieldDouble::New(ON_GAUSS_PT)); - fakeF->setMesh(geoMesh); - int nbg(loc.getGaussWeights().size()); - fakeF->setGaussLocalizationOnType(gt,loc.getRefCoords(),loc.getGaussCoords(),loc.getGaussWeights()); - MCAuto ptsForLoc(fakeF->getLocalizationOfDiscr()); - { - MCAuto ptsForLoc1(MEDCouplingUMesh::Build0DMeshFromCoords(ptsForLoc)); - ptsForLoc1->writeVTK("pts.vtu"); - } - // - MCAuto rot; - { - MCAuto dir(geoMesh->buildDirectionVectorField()); - rot=dir->getArray()->fromCartToSpher(); - } - int nbCells(geoMesh->getNumberOfCells()),nbCompo(ptsForLoc->getNumberOfComponents()); - MCAuto secPts(section->getCoords()->changeNbOfComponents(nbCompo,0.)); - int nbSecPts(secPts->getNumberOfTuples()); - { - const int TAB[3]={2,0,1}; - std::vector v(TAB,TAB+3); - secPts=secPts->keepSelectedComponents(v); - } - const double CENTER[3]={0.,0.,0.},AX0[3]={0.,0.,1.}; - double AX1[3]; AX1[2]=0.; - std::vector< MCAuto > arrs(nbCells*nbg); - for(int j=0;j p(secPts->deepCopy()); - double ang0(rot->getIJ(j,2)); - DataArrayDouble::Rotate3DAlg(CENTER,AX0,ang0,nbSecPts,p->begin(),p->getPointer()); - AX1[0]=-sin(ang0); AX1[1]=cos(ang0);// rot Oy around OZ - double ang1(M_PI/2.-rot->getIJ(j,1)); - DataArrayDouble::Rotate3DAlg(CENTER,AX1,ang1,nbSecPts,p->begin(),p->getPointer()); - for(int l=0;l p2(p->deepCopy()); - for(int k=0;kapplyLin(1.,ptsForLoc->getIJ(j*nbg+l,k),k); - arrs[j*nbg+l]=p2; - } - } - std::vector arrs2(VecAutoToVecOfCstPt(arrs)); - MCAuto resu(DataArrayDouble::Aggregate(arrs2)); - MCAuto mresu(MEDCouplingUMesh::Build0DMeshFromCoords(resu)); - { - mresu->setName("mesh"); - std::ostringstream oss; oss << "mresu_" << i << ".vtu"; - mresu->writeVTK(oss.str()); - } - std::cerr << "kkkk " << mesh << " " << meshLoc << std::endl; + arrs[i]=BuildMeshFromStructure(gt,_pfl[i],loc,zeStr,mesh,section,globs); } + std::vector arrs2(VecAutoToVecOfCstPt(arrs)); + MCAuto resu(DataArrayDouble::Aggregate(arrs2)); + MCAuto ret(MEDFileUMesh::New()); + ret->setCoords(resu); + std::ostringstream meshName; meshName << mesh->getName() << "_on_" << sz << "_sections" << "_" << zePos; + ret->setName(meshName.str()); + return ret; } FieldWalker2::FieldWalker2(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd) @@ -647,7 +668,7 @@ class LocSpliter : public MEDFileFieldVisitor public: LocSpliter(const MEDFileFieldGlobsReal *globs):_globs(globs),_fw(0) { } MCAuto getClassical() const { return _classical; } - void generateNonClassicalData(const MEDFileUMesh *mesh) const; + void generateNonClassicalData(const MEDFileUMesh *mesh, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes) const; private: void newFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field); void endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field); @@ -680,6 +701,7 @@ void LocSpliter::endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field { if(_fw->isEmpty()) return ; + MCAuto f(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(const_cast(field))); if(_fw->isClassical()) { if(_classical.isNull()) @@ -687,7 +709,6 @@ void LocSpliter::endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field _classical=MEDFileFields::New(); _classical->shallowCpyGlobs(*_globs); } - MCAuto f(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(const_cast(field))); _classical->pushField(f); } else @@ -698,19 +719,52 @@ void LocSpliter::endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field if(it==_locs.end()) { _locs.push_back(elt); + MCAuto zeF(MEDFileFields::New()); + zeF->shallowCpyGlobs(*_globs); + zeF->pushField(f); + _fields_on_locs.push_back(zeF); } else { + MCAuto zeF(_fields_on_locs[std::distance(_locs.begin(),it)]); + zeF->pushField(f); } - std::cerr << "lkk " << _locs.size() << std::endl; } } -void LocSpliter::generateNonClassicalData(const MEDFileUMesh *mesh) const +void LocSpliter::generateNonClassicalData(const MEDFileUMesh *mesh, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes) const { - for(std::vector::const_iterator it=_locs.begin();it!=_locs.end();it++) + int i(0); + for(std::vector::const_iterator it=_locs.begin();it!=_locs.end();it++,i++) { - (*it).generateNonClassicalData(mesh,_globs); + MCAuto m((*it).generateNonClassicalData(i,mesh,_globs)); + outMeshes.push_back(m); + MCAuto mcm(MEDCouplingUMesh::Build0DMeshFromCoords(m->getCoords())); + mcm->setName(m->getName()); + MCAuto fs(_fields_on_locs[i]); + MCAuto outFs(MEDFileFields::New()); + for(int j=0;jgetNumberOfFields();j++) + { + MCAuto fmtsNC(fs->getFieldAtPos(j)); + MCAuto fmts(DynamicCastSafe(fmtsNC)); + MCAuto outFmts(MEDFileFieldMultiTS::New()); + for(int k=0;kgetNumberOfTS();k++) + { + MCAuto outF1t(MEDFileField1TS::New()); + MCAuto f1ts(fmts->getTimeStepAtPos(k)); + int t2,t3; + double t1(f1ts->getTime(t2,t3)); + MCAuto mcf(MEDCouplingFieldDouble::New(ON_NODES)); + mcf->setArray(f1ts->getUndergroundDataArray()); + mcf->setTime(t1,t2,t3); + mcf->setName(f1ts->getName()); + mcf->setMesh(mcm); + outF1t->setFieldNoProfileSBT(mcf); + outFmts->pushBackTimeStep(outF1t); + } + outFs->pushField(outFmts); + } + outFields.push_back(outFs); } } @@ -749,10 +803,22 @@ void LocSpliter::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDis _fw->newPerMeshPerTypePerDisc(pmptpd); } -MCAuto MEDFileBlowStrEltUp::splitFieldsPerLoc(const MEDFileFields *fields, const MEDFileUMesh *mesh, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes) +MCAuto MEDFileBlowStrEltUp::splitFieldsPerLoc(const MEDFileFields *fields, const MEDFileUMesh *mesh, MEDFileMeshes *msOut, MEDFileFields *allZeOutFields) { LocSpliter ls(fields); fields->accept(ls); - ls.generateNonClassicalData(mesh); + std::vector< MCAuto > outFields; + std::vector< MCAuto > outMeshes; + ls.generateNonClassicalData(mesh,outFields,outMeshes); + for(std::vector< MCAuto >::iterator it=outFields.begin();it!=outFields.end();it++) + { + for(int j=0;j<(*it)->getNumberOfFields();j++) + { + MCAuto fmts((*it)->getFieldAtPos(j)); + allZeOutFields->pushField(fmts); + } + } + for(std::vector< MCAuto >::iterator it=outMeshes.begin();it!=outMeshes.end();it++) + msOut->pushMesh(*it); return ls.getClassical(); } diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.hxx b/src/MEDLoader/MEDFileBlowStrEltUp.hxx index 595518160..1363548de 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.hxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.hxx @@ -38,7 +38,7 @@ namespace MEDCoupling void generate(MEDFileMeshes *msOut, MEDFileFields *allZeOutFields); static void DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const MEDFileStructureElements *ses); private: - MCAuto splitFieldsPerLoc(const MEDFileFields *fields, const MEDFileUMesh *mesh, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes); + MCAuto splitFieldsPerLoc(const MEDFileFields *fields, const MEDFileUMesh *mesh, MEDFileMeshes *msOut, MEDFileFields *allZeOutFields); MCAuto dealWithSEInMesh(const std::string& seName, MEDFileUMesh *mesh, MCAuto& mOut, MCAuto& fsOut) const; MCAuto dealWithMEDBALLInMesh(const MEDFileUMesh *mesh, MCAuto& mOut, MCAuto& fsOut) const; void dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const; diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index eedfeeaf4..b0a9eb651 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -205,6 +205,15 @@ MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const return new MEDFileFieldLoc(*this); } +bool MEDFileFieldLoc::isOnStructureElement() const +{ + const MEDFileGTKeeper *gt(_gt); + if(!gt) + throw INTERP_KERNEL::Exception("MEDFileFieldLoc::isOnStructureElement : null pointer !"); + const MEDFileGTKeeperDyn *gt2(dynamic_cast(gt)); + return gt2!=NULL; +} + std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const { return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity(); @@ -3533,6 +3542,19 @@ void MEDFileFieldGlobs::killLocalizationIds(const std::vector& locIds) _locs=newLocs; } +void MEDFileFieldGlobs::killStructureElementsInGlobs() +{ + std::vector< MCAuto > newLocs; + for(std::vector< MCAuto >::iterator it=_locs.begin();it!=_locs.end();it++) + { + if((*it).isNull()) + continue; + if(!(*it)->isOnStructureElement()) + newLocs.push_back(*it); + } + _locs=newLocs; +} + std::vector MEDFileFieldGlobs::getPfls() const { int sz=_pfls.size(); @@ -3718,6 +3740,11 @@ void MEDFileFieldGlobsReal::resetContent() _globals=MEDFileFieldGlobs::New(); } +void MEDFileFieldGlobsReal::killStructureElementsInGlobs() +{ + contentNotNull()->killStructureElementsInGlobs(); +} + MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal() { } diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 435a9c154..c929c534e 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -104,6 +104,7 @@ namespace MEDCoupling std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildrenWithNull() const; MEDFileFieldLoc *deepCopy() const; + bool isOnStructureElement() const; const MEDFileGTKeeper *getUndergroundGTKeeper() const { return _gt; } MEDLOADER_EXPORT int getNbOfGaussPtPerCell() const { return _nb_gauss_pt; } MEDLOADER_EXPORT void writeLL(med_idt fid) const; @@ -464,6 +465,7 @@ namespace MEDCoupling DataArrayInt *getProfileFromId(int pflId); void killProfileIds(const std::vector& pflIds); void killLocalizationIds(const std::vector& locIds); + void killStructureElementsInGlobs(); // void appendProfile(DataArrayInt *pfl); void appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& w); @@ -490,6 +492,7 @@ namespace MEDCoupling MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; MEDLOADER_EXPORT void simpleReprGlobs(std::ostream& oss) const; MEDLOADER_EXPORT void resetContent(); + MEDLOADER_EXPORT void killStructureElementsInGlobs(); MEDLOADER_EXPORT void shallowCpyGlobs(const MEDFileFieldGlobsReal& other); MEDLOADER_EXPORT void deepCpyGlobs(const MEDFileFieldGlobsReal& other); MEDLOADER_EXPORT void shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 26863381a..0ce4682b2 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -1894,6 +1894,7 @@ namespace MEDCoupling void changeLocName(const std::string& oldName, const std::string& newName) throw(INTERP_KERNEL::Exception); int getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception); int getLocalizationId(const std::string& loc) const throw(INTERP_KERNEL::Exception); + void killStructureElementsInGlobs() throw(INTERP_KERNEL::Exception); %extend { PyObject *getProfile(const std::string& pflName) const throw(INTERP_KERNEL::Exception)