From: Anthony Geay Date: Tue, 24 Jan 2017 16:19:44 +0000 (+0100) Subject: Management of pfls X-Git-Tag: V8_3_0a2~38^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fagy%2FEltStrInMC;p=tools%2Fmedcoupling.git Management of pfls --- diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.cxx b/src/MEDLoader/MEDFileBlowStrEltUp.cxx index fd4dd281f..fcd9e51fa 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.cxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.cxx @@ -170,6 +170,7 @@ void MEDFileBlowStrEltUp::dealWithMEDBALLSInFields(const MEDFileFields *fs, cons int nbf(fs->getNumberOfFields()); std::vector< MCAuto > elts0; std::vector< MEDFileAnyTypeFieldMultiTS * > elts1; + std::string zeMeshName; for(int i=0;i elt(fs->getFieldAtPos(i)); @@ -180,42 +181,73 @@ void MEDFileBlowStrEltUp::dealWithMEDBALLSInFields(const MEDFileFields *fs, cons MCAuto eltt(elt->getTimeStepAtPos(j)); MCAuto elttOut(eltt->deepCopy()); std::string meshName(eltt->getMeshName()); - elttOut->setMeshName(BuildNewMeshName(meshName,MED_BALL_STR)); + zeMeshName=BuildNewMeshName(meshName,MED_BALL_STR); + elttOut->setMeshName(zeMeshName); elttOut->convertMedBallIntoClassic(); eltOut->pushBackTimeStep(elttOut); } elts0.push_back(eltOut); elts1.push_back(eltOut); } // + const MEDFileMesh *zeCurrentMesh(_ms->getMeshWithName(zeMeshName)); + // std::size_t ii(0); std::vector< std::vector > sp(MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(elts1)); for(std::vector< std::vector >::const_iterator it0=sp.begin();it0!=sp.end();it0++,ii++) { - for(std::vector::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++) - zeOutputs->pushField(*it1); - std::vector t2s; - std::vector< std::pair > t1s((*it0)[0]->getTimeSteps(t2s)); - std::size_t nbTS3(t2s.size()); - int nbf2(varAtt->getNumberOfFields()); - for(int i=0;i > fsc; + std::vector< std::vector > sp2(MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(*it0,zeCurrentMesh,fsc)); + std::size_t jj(0); + for(std::vector< std::vector >::const_iterator it1=sp2.begin();it1!=sp2.end();it1++,jj++) { - MCAuto elt(varAtt->getFieldAtPos(i)); - int nbTS2(elt->getNumberOfTS()); - if(nbTS2!=1) - throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : internal error ! The dealWithMEDBALLInMesh is expected to return a single TS !"); - MCAuto elt2(elt->getTimeStepAtPos(0)); - MCAuto elt4(elt->buildNewEmpty()); - for(std::size_t j=0;j::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++) + zeOutputs->pushField(*it2); + // The most exciting part. Users that put profiles on struct elements part of fields. Reduce var att. + if((*it1).size()<1) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath !"); + MCAuto zeGuideForPfl;// This var is the reference for pfl management. + { + if(!(*it1)[0]) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath 2 !"); + int pdm((*it1)[0]->getNumberOfTS()); + if(pdm<1) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath 3 !"); + zeGuideForPfl=(*it1)[0]->getTimeStepAtPos(0); + } + if(zeGuideForPfl.isNull()) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : take a deep breath 4 !"); + std::vector pfls(zeGuideForPfl->getPflsReallyUsed()); + if(pfls.size()>=2) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : drink less coffee"); + MCAuto pflMyLove; + if(pfls.size()==1) + pflMyLove.takeRef(zeGuideForPfl->getProfile(pfls[0])); + // Yeah we have pfls + std::vector t2s; + std::vector< std::pair > t1s((*it1)[0]->getTimeSteps(t2s)); + std::size_t nbTS3(t2s.size()); + int nbf2(varAtt->getNumberOfFields()); + for(int i=0;i elt3(elt2->deepCopy()); - elt3->setTime(t1s[j].first,t1s[j].second,t2s[j]); - elt3->setName(BuildVarAttName(ii,sp.size(),elt3->getName())); - elt4->pushBackTimeStep(elt3); + MCAuto elt(varAtt->getFieldAtPos(i)); + int nbTS2(elt->getNumberOfTS()); + if(nbTS2!=1) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLSInFields : internal error ! The dealWithMEDBALLInMesh is expected to return a single TS !"); + MCAuto elt2(elt->getTimeStepAtPos(0)); + MCAuto elt4(elt->buildNewEmpty()); + for(std::size_t j=0;j elt3(elt2->deepCopy()); + elt3->setTime(t1s[j].first,t1s[j].second,t2s[j]); + elt3->setName(BuildVarAttName(ii,sp.size(),jj,sp2.size(),elt3->getName())); + if(pflMyLove.isNotNull()) + elt3->makeReduction(INTERP_KERNEL::NORM_ERROR,ON_NODES,pflMyLove); + elt4->pushBackTimeStep(elt3); + } + zeOutputs->pushField(elt4); } - zeOutputs->pushField(elt4); } } - } void MEDFileBlowStrEltUp::generate(MEDFileMeshes *msOut, MEDFileFields *allZeOutFields) @@ -247,12 +279,12 @@ std::string MEDFileBlowStrEltUp::BuildNewMeshName(const std::string& meshName, c return mNameOut.str(); } -std::string MEDFileBlowStrEltUp::BuildVarAttName(std::size_t iPart, std::size_t totNbParts, const std::string& name) +std::string MEDFileBlowStrEltUp::BuildVarAttName(std::size_t iPart, std::size_t totINbParts, std::size_t jPart, std::size_t totJNbParts, const std::string& name) { - if(totNbParts==1) + if(totINbParts==1 && totJNbParts==1) return name; std::ostringstream oss; - oss << name << "@" << iPart; + oss << name << "@" << iPart << "@" << jPart; return oss.str(); } diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.hxx b/src/MEDLoader/MEDFileBlowStrEltUp.hxx index 29245e9cb..b237e83d8 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.hxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.hxx @@ -43,7 +43,7 @@ namespace MEDCoupling void dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const; void dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const; static std::string BuildNewMeshName(const std::string& meshName, const std::string& seName); - static std::string BuildVarAttName(std::size_t iPart, std::size_t totNbParts, const std::string& name); + static std::string BuildVarAttName(std::size_t iPart, std::size_t totINbParts, std::size_t jPart, std::size_t totJNbParts, const std::string& name); public: static const char MED_BALL_STR[]; private: diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 9eda80613..70b65d123 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -4587,6 +4587,42 @@ void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic() (*it)->convertMedBallIntoClassic(); } +void MEDFileAnyTypeField1TSWithoutSDA::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl) +{ + if(!pfl) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : null pfl !"); + std::string name(pfl->getName()); + pfl->checkAllocated(); + if(pfl->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : non mono compo array !"); + if(name.empty()) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : empty pfl name !"); + if(_field_per_mesh.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single mesh supported !"); + MCAuto fpm(_field_per_mesh[0]); + if(fpm.isNull()) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single not null mesh supported !"); + MEDFileFieldPerMeshPerTypePerDisc *disc(fpm->getLeafGivenTypeAndLocId(ct,0)); + if(disc->getType()!=tof) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : error !"); + int s(disc->getStart()),e(disc->getEnd()),nt(pfl->getNumberOfTuples()); + DataArray *arr(getUndergroundDataArray()); + int nt2(arr->getNumberOfTuples()),delta((e-s)-nt); + if(delta<0) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : internal error !"); + MCAuto arr0(arr->selectByTupleIdSafeSlice(0,s,1)),arr1(arr->selectByTupleIdSafeSlice(s,e,1)),arr2(arr->selectByTupleIdSafeSlice(e,nt2,1)); + MCAuto arr11(arr1->selectByTupleIdSafe(pfl->begin(),pfl->end())); + MCAuto arrOut(arr->buildNewEmptyInstance()); + arrOut->alloc(nt2-delta,arr->getNumberOfComponents()); + arrOut->copyStringInfoFrom(*arr); + arrOut->setContigPartOfSelectedValuesSlice(0,arr0,0,s,1); + arrOut->setContigPartOfSelectedValuesSlice(s,arr11,0,nt,1); + arrOut->setContigPartOfSelectedValuesSlice(e-delta,arr2,0,nt2-e,1); + setArray(arrOut); + disc->setEnd(e-delta); + disc->setProfile(name); +} + /*! * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh. * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. @@ -6409,6 +6445,11 @@ void MEDFileAnyTypeField1TS::convertMedBallIntoClassic() return contentNotNullBase()->convertMedBallIntoClassic(); } +void MEDFileAnyTypeField1TS::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl) +{ + return contentNotNullBase()->makeReduction(ct,tof,pfl); +} + std::vector MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const { return contentNotNullBase()->getTypesOfFieldAvailable(); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index cb501d21f..51a04df7d 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -131,6 +131,7 @@ namespace MEDCoupling int getNumberOfTuples() const; int getStart() const { return _start; } int getEnd() const { return _end; } + void setEnd(int endd) { _end=endd; } int getNumberOfVals() const { return _nval; } DataArray *getOrCreateAndGetArray(); const DataArray *getOrCreateAndGetArray() const; @@ -555,6 +556,7 @@ namespace MEDCoupling // MEDLOADER_EXPORT int getNonEmptyLevels(const std::string& mname, std::vector& levs) const; MEDLOADER_EXPORT void convertMedBallIntoClassic(); + MEDLOADER_EXPORT void makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl); MEDLOADER_EXPORT std::vector< std::vector > > getFieldSplitedByType(const std::string& mname, std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const; // MEDLOADER_EXPORT MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId); @@ -751,6 +753,7 @@ namespace MEDCoupling MEDLOADER_EXPORT const MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const; MEDLOADER_EXPORT int getNonEmptyLevels(const std::string& mname, std::vector& levs) const; MEDLOADER_EXPORT void convertMedBallIntoClassic(); + MEDLOADER_EXPORT void makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl); public: MEDLOADER_EXPORT void loadArrays(); MEDLOADER_EXPORT void loadArraysIfNecessary();