From: Anthony Geay Date: Tue, 24 Jan 2017 14:36:10 +0000 (+0100) Subject: Finished. But maybe we have to manage profile. Only sky is the limit X-Git-Tag: V8_3_0a2~38^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ac09eb5d30ca4f7f01420b4b48ba0f0af35c50c8;p=tools%2Fmedcoupling.git Finished. But maybe we have to manage profile. Only sky is the limit --- diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.cxx b/src/MEDLoader/MEDFileBlowStrEltUp.cxx index 0ee8ec16f..fd4dd281f 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.cxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.cxx @@ -117,16 +117,10 @@ MCAuto MEDFileBlowStrEltUp::dealWithMEDBALLInMesh(const M MCAuto md(zeStr->getMeshDef()); const DataArrayInt *ff0(md->getFam()); if(ff0) - { - MCAuto ff0o(ff0->duplicateEachTupleNTimes(nbCells)); - mOut->setFamilyFieldArr(0,ff0o); - } + mOut->setFamilyFieldArr(0,const_cast(ff0)); const DataArrayInt *nf0(md->getNum()); if(nf0) - { - MCAuto nf0o(ff0->duplicateEachTupleNTimes(nbCells)); - mOut->setRenumFieldArr(0,nf0o); - } + mOut->setRenumFieldArr(0,const_cast(nf0)); mOut->copyFamGrpMapsFrom(*mesh); const std::vector< MCAuto >& vars(zeStr->getVars()); for(std::vector< MCAuto >::const_iterator it=vars.begin();it!=vars.end();it++) @@ -159,7 +153,7 @@ MCAuto MEDFileBlowStrEltUp::dealWithMEDBALLInMesh(const M * \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 * \param [out] zeOutputs - ze fields that are the concatenation of fields in \a fs transformed and those in \a varAtt normalized in time space */ -void MEDFileBlowStrEltUp::dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MCAuto& zeOutputs) const +void MEDFileBlowStrEltUp::dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const { if(!fs) throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInFields : null pointer !"); @@ -171,15 +165,61 @@ void MEDFileBlowStrEltUp::dealWithSEInFields(const std::string& seName, const ME 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 !"); } -void MEDFileBlowStrEltUp::dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MCAuto& zeOutputs) const +void MEDFileBlowStrEltUp::dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const { + int nbf(fs->getNumberOfFields()); + std::vector< MCAuto > elts0; + std::vector< MEDFileAnyTypeFieldMultiTS * > elts1; + for(int i=0;i elt(fs->getFieldAtPos(i)); + MCAuto eltOut(elt->buildNewEmpty()); + int nbTS(elt->getNumberOfTS()); + for(int j=0;j eltt(elt->getTimeStepAtPos(j)); + MCAuto elttOut(eltt->deepCopy()); + std::string meshName(eltt->getMeshName()); + elttOut->setMeshName(BuildNewMeshName(meshName,MED_BALL_STR)); + elttOut->convertMedBallIntoClassic(); + eltOut->pushBackTimeStep(elttOut); + } + elts0.push_back(eltOut); elts1.push_back(eltOut); + } + // + 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 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(),elt3->getName())); + elt4->pushBackTimeStep(elt3); + } + zeOutputs->pushField(elt4); + } + } } -void MEDFileBlowStrEltUp::generate(MCAuto& msOut, MCAuto& allZeOutFields) +void MEDFileBlowStrEltUp::generate(MEDFileMeshes *msOut, MEDFileFields *allZeOutFields) { - msOut=MEDFileMeshes::New(); - allZeOutFields=MEDFileFields::New(); for(std::vector< MCAuto >::iterator elt=_elts.begin();elt!=_elts.end();elt++) { std::vector< std::pair > ps; @@ -195,10 +235,8 @@ void MEDFileBlowStrEltUp::generate(MCAuto& msOut, MCAuto mOut; MCAuto fsOut1; MCAuto zeStr(dealWithSEInMesh(ps[0].second,umesh,mOut,fsOut1)); - msOut->pushMesh(umesh); - MCAuto fsOut2; - dealWithSEInFields(ps[0].second,*elt,zeStr,fsOut1,fsOut2); - allZeOutFields->aggregate(*fsOut2); + msOut->pushMesh(mOut); + dealWithSEInFields(ps[0].second,*elt,zeStr,fsOut1,allZeOutFields); } } @@ -209,13 +247,19 @@ std::string MEDFileBlowStrEltUp::BuildNewMeshName(const std::string& meshName, c return mNameOut.str(); } -void MEDFileBlowStrEltUp::DealWithSE(MEDFileFields *fs, const MEDFileMeshes *ms, const MEDFileStructureElements *ses, MCAuto& fsOut, MCAuto& msOut) +std::string MEDFileBlowStrEltUp::BuildVarAttName(std::size_t iPart, std::size_t totNbParts, const std::string& name) +{ + if(totNbParts==1) + return name; + std::ostringstream oss; + oss << name << "@" << iPart; + return oss.str(); +} + +void MEDFileBlowStrEltUp::DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const MEDFileStructureElements *ses) { MCAuto fsSEOnly(fs->partOfThisOnStructureElements()); fs->killStructureElements(); MEDFileBlowStrEltUp bu(fsSEOnly,ms,ses); - MCAuto msOut1; - MCAuto allZeOutFields1; - bu.generate(msOut1,allZeOutFields1); - + bu.generate(ms,fs); } diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.hxx b/src/MEDLoader/MEDFileBlowStrEltUp.hxx index 49743a1d7..29245e9cb 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.hxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.hxx @@ -35,14 +35,15 @@ namespace MEDCoupling { public: MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MEDFileMeshes *ms, const MEDFileStructureElements *ses); - static void DealWithSE(MEDFileFields *fs, const MEDFileMeshes *ms, const MEDFileStructureElements *ses, MCAuto& fsOut, MCAuto& msOut); + static void DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const MEDFileStructureElements *ses); private: - void generate(MCAuto& msOut, MCAuto& allZeOutFields); + void generate(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, MCAuto& zeOutputs) const; - void dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MCAuto& zeOutputs) const; + 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); public: static const char MED_BALL_STR[]; private: diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index 945708556..af66dda5b 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -21,6 +21,7 @@ #include "MEDFileData.hxx" #include "MEDLoaderBase.hxx" #include "MEDFileSafeCaller.txx" +#include "MEDFileBlowStrEltUp.hxx" #include "InterpKernelAutoPtr.hxx" @@ -231,6 +232,15 @@ bool MEDFileData::unPolyzeMeshes() return !meshesImpacted.empty(); } +void MEDFileData::dealWithStructureElements() +{ + if(_struct_elems.isNull()) + throw INTERP_KERNEL::Exception("MEDFileData::dealWithStructureElements : no structure elements in this !"); + if(_meshes.isNull() || _fields.isNull()) + throw INTERP_KERNEL::Exception("MEDFileData::dealWithStructureElements : meshes and fields must be not null !"); + MEDFileBlowStrEltUp::DealWithSE(_fields,_meshes,_struct_elems); +} + /*! * Precondition : all instances in \a mfds should have a single mesh with fields on it. If there is an instance with not exactly one mesh an exception will be thrown. * You can invoke MEDFileFields::partOfThisLyingOnSpecifiedMeshName method to make it work. diff --git a/src/MEDLoader/MEDFileData.hxx b/src/MEDLoader/MEDFileData.hxx index f9713a86b..2c9703d65 100644 --- a/src/MEDLoader/MEDFileData.hxx +++ b/src/MEDLoader/MEDFileData.hxx @@ -60,6 +60,7 @@ namespace MEDCoupling MEDLOADER_EXPORT bool changeMeshNames(const std::vector< std::pair >& modifTab); MEDLOADER_EXPORT bool changeMeshName(const std::string& oldMeshName, const std::string& newMeshName); MEDLOADER_EXPORT bool unPolyzeMeshes(); + MEDLOADER_EXPORT void dealWithStructureElements(); MEDLOADER_EXPORT static MCAuto Aggregate(const std::vector& mfds); // MEDLOADER_EXPORT void writeLL(med_idt fid) const; diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index ded7e99dd..9eda80613 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -1347,6 +1347,13 @@ bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const return nb>1; } +void MEDFileFieldPerMeshPerTypeCommon::pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc) +{ + MCAuto elt; + elt.takeRef(disc); + _field_pm_pt_pd.push_back(elt); +} + DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() { return _father->getOrCreateAndGetArray(); @@ -2241,6 +2248,29 @@ bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair((MEDFileFieldPerMeshPerTypeCommon *)_field_pm_pt[0])); + if(!pt) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : this is expected to be marked as structure element !"); + if(pt->getNumberOfLoc()!=1) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : only one loc managed !"); + const MEDFileFieldPerMeshPerTypePerDisc *disc(pt->getLeafGivenLocId(0)); + if(!disc) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : internal error !"); + MCAuto disc2(MEDFileFieldPerMeshPerTypePerDisc::New(*disc)); + disc2->setType(ON_NODES); + MCAuto pt2(MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR)); + disc2->setFather(pt2); + pt2->setFather(this); + pt2->pushDiscretization(disc2); + _field_pm_pt[0]=DynamicCast(pt2); +} + bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector& oldCode, const std::vector& newCode, const DataArrayInt *renumO2N, MEDFileFieldGlobsReal& glob) { @@ -4550,6 +4580,13 @@ int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname return ret; } +void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic() +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it<_field_per_mesh.end();it++) + if((*it).isNotNull()) + (*it)->convertMedBallIntoClassic(); +} + /*! * \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. @@ -6367,6 +6404,11 @@ int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vec return contentNotNullBase()->getNonEmptyLevels(mname,levs); } +void MEDFileAnyTypeField1TS::convertMedBallIntoClassic() +{ + return contentNotNullBase()->convertMedBallIntoClassic(); +} + std::vector MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const { return contentNotNullBase()->getTypesOfFieldAvailable(); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 8b49d1dac..cb501d21f 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -206,6 +206,7 @@ namespace MEDCoupling void getSizes(int& globalSz, int& nbOfEntries) const; int getNumberOfComponents() const; bool presenceOfMultiDiscPerGeoType() const; + void pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc); DataArray *getOrCreateAndGetArray(); const DataArray *getOrCreateAndGetArray() const; const std::vector& getInfo() const; @@ -224,6 +225,7 @@ namespace MEDCoupling bool keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair >& its); static med_entity_type ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType); MEDFileFieldPerMeshPerTypeCommon(MEDFileFieldPerMesh *father):_father(father) { } + void setFather(MEDFileFieldPerMesh *father); public: virtual ~MEDFileFieldPerMeshPerTypeCommon(); virtual void getDimension(int& dim) const = 0; @@ -234,7 +236,6 @@ namespace MEDCoupling virtual MEDFileFieldPerMeshPerTypeCommon *deepCopy(MEDFileFieldPerMesh *father) const = 0; virtual void getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair >& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const = 0; protected: - void setFather(MEDFileFieldPerMesh *father); void deepCopyElements(); std::vector addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells); std::vector addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells); @@ -331,6 +332,7 @@ namespace MEDCoupling std::vector getLocsReallyUsed() const; std::vector getPflsReallyUsedMulti() const; std::vector getLocsReallyUsedMulti() const; + void convertMedBallIntoClassic(); bool changeMeshNames(const std::vector< std::pair >& modifTab); bool renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector& oldCode, const std::vector& newCode, const DataArrayInt *renumO2N, MEDFileFieldGlobsReal& glob); void keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair >& its); @@ -552,6 +554,7 @@ namespace MEDCoupling MEDLOADER_EXPORT void changeLocsRefsNamesGen2(const std::vector< std::pair, std::string > >& mapOfModif); // MEDLOADER_EXPORT int getNonEmptyLevels(const std::string& mname, std::vector& levs) const; + MEDLOADER_EXPORT void convertMedBallIntoClassic(); 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); @@ -747,6 +750,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId); 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(); public: MEDLOADER_EXPORT void loadArrays(); MEDLOADER_EXPORT void loadArraysIfNecessary(); diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index d3e93c441..337ea7d17 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -2107,5 +2107,6 @@ MEDFileEltStruct4Mesh::MEDFileEltStruct4Mesh(med_idt fid, const std::string& mNa arr->alloc(nCells,var->getNbOfComponents()); arr->setName(vns[i]); MEDFILESAFECALLERRD0(MEDmeshStructElementVarAttRd,(fid,mName.c_str(),dt,it,_geo_type,vns[i].c_str(),arr->getVoidStarPointer())); + _vars[i]=arr; } } diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 63061304c..40ebad0fb 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -3624,6 +3624,7 @@ namespace MEDCoupling // bool changeMeshName(const std::string& oldMeshName, const std::string& newMeshName) throw(INTERP_KERNEL::Exception); bool unPolyzeMeshes() throw(INTERP_KERNEL::Exception); + void dealWithStructureElements() throw(INTERP_KERNEL::Exception); std::string getHeader() const throw(INTERP_KERNEL::Exception); void setHeader(const std::string& header) throw(INTERP_KERNEL::Exception); //