From: Anthony Geay Date: Mon, 2 Aug 2021 09:01:54 +0000 (+0200) Subject: Premiere implementation avec 2 Elements de structure dont la description repose sur... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ef613eda295785dc8bf685c209b0d15b92ada50e;p=tools%2Fmedcoupling.git Premiere implementation avec 2 Elements de structure dont la description repose sur un meme maillage --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 6dacb50b9..17b42cf44 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -1077,6 +1077,120 @@ void MEDFileFields::getMeshSENames(std::vector< std::pairaggregateFieldsOnSameMeshes(ms); +} + +/*! + * This method is dedicated to explosed Structured Elements that can lead to exotic situation. + * Especially when there are several structured elements for a same field. + * + * This method looks into meshes into \a ms if there is presence of multiple mesh having same name. + * If so, these meshes are aggregated in the same order than \a ms. + * The fields in \a this lying on the same meshName are also aggregated in the same order than \a this. + */ +void MEDFileFields::aggregateFieldsOnSameMeshes(MEDFileMeshes *ms) +{ + if(!ms) + THROW_IK_EXCEPTION("MEDFileFields::aggregateFieldsOnSameMeshes : ms is nullptr !"); + MCAuto mfs(MEDFileFields::New()); + std::map> > fsByName; + for(auto fmts : _fields) + { + fsByName[fmts->getMeshName()].push_back(fmts); + } + std::vector fieldsNamesToBeAggregated; + std::vector< MCAuto > otherFields; + std::set expectedMeshNamesToMerge; + for(auto fieldsWithSame : fsByName) + { + if(fieldsWithSame.second.size() > 1) + { + fieldsNamesToBeAggregated.push_back(fieldsWithSame.first); + std::set< std::string > zeMeshNames; + for(auto fmtsWithSameName : fieldsWithSame.second) + zeMeshNames.insert(fmtsWithSameName->getMeshName()); + if(zeMeshNames.size()!=1) + THROW_IK_EXCEPTION("MEDFileFields::aggregateFieldsOnSameMeshes : Presence of multiple MultiTS instances with same name but lying on same meshName. Looks bad !"); + std::string meshNameToMerge = *zeMeshNames.begin(); + if(expectedMeshNamesToMerge.find(meshNameToMerge) != expectedMeshNamesToMerge.end()) + THROW_IK_EXCEPTION("MEDFileFields::aggregateFieldsOnSameMeshes : unexpected situation ! Error in implementation !"); + expectedMeshNamesToMerge.insert(*zeMeshNames.begin()); + } + else + { + otherFields.push_back(fieldsWithSame.second.front()); + } + } + for(auto fieldNameToBeAggregated : fieldsNamesToBeAggregated) + { + auto base_fs = fsByName[fieldNameToBeAggregated].front(); + auto fieldsToBeAggregated = fsByName[fieldNameToBeAggregated]; + std::vector< std::vector< std::pair > > dtsToAggregate; + std::vector< MCAuto > eltsToAggregate; + for(auto fieldToBeAggregated : fieldsToBeAggregated) + { + std::vector< std::pair,std::pair > > entries; + int iteration,order; + { + auto dtits = fieldToBeAggregated->getIterations(); + iteration = dtits.front().first; + order = dtits.front().second; + } + fieldToBeAggregated->getUndergroundDataArrayExt(iteration,order,entries); + std::vector< std::pair > dtsToPush; + for(auto entry : entries) + dtsToPush.push_back({entry.first.first,entry.second.second-entry.second.first}); + dtsToAggregate.push_back(dtsToPush); + MCAuto eltToAggregate = MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(fieldToBeAggregated); + eltsToAggregate.push_back(eltToAggregate); + } + MCAuto gg = MEDFileAnyTypeFieldMultiTS::Aggregate(FromVecAutoToVecOfConst(eltsToAggregate),dtsToAggregate); + gg->setMeshName(base_fs->getMeshName()); + otherFields.push_back(gg->getContent()); + } + // now deal with meshes + std::map > msByName; + for(auto iMesh = 0 ; iMesh < ms->getNumberOfMeshes() ; ++iMesh) + { + auto curMesh = ms->getMeshAtPos(iMesh); + msByName[curMesh->getName()].push_back(curMesh); + } + std::set meshesNamesToBeAggregated; + std::vector< MCAuto > otherMeshes; + for(auto msWithSameName : msByName) + { + if(msWithSameName.second.size()>1) + meshesNamesToBeAggregated.insert(msWithSameName.first); + else + { + otherMeshes.push_back( MCAuto::TakeRef(msWithSameName.second.front()) ); + } + } + if(meshesNamesToBeAggregated != expectedMeshNamesToMerge) + THROW_IK_EXCEPTION("MEDFileFields::aggregateFieldsOnSameMeshes : mismatch between meshes to be aggregated and meshnames into fields to be aggregated"); + std::vector coos; + for(auto meshNameToBeAggregated : meshesNamesToBeAggregated) + { + for(auto curMesh : msByName[meshNameToBeAggregated]) + { + if(!curMesh->getNonEmptyLevels().empty()) + THROW_IK_EXCEPTION("MEDFileFields::aggregateFieldsOnSameMeshes : only meshes without cells supported."); + MEDFileUMesh *curMeshU(dynamic_cast(curMesh)); + if(!curMeshU) + THROW_IK_EXCEPTION("MEDFileFields::aggregateFieldsOnSameMeshes : only unstructured mesh supported."); + coos.push_back(curMeshU->getCoords()); + } + MCAuto coo=DataArrayDouble::Aggregate(coos); + MCAuto gg = MEDFileUMesh::New(); + gg->setName(meshNameToBeAggregated); + gg->setCoords(coo); + otherMeshes.push_back(DynamicCast(gg)); + } + // + ms->resize(0); + for(auto mesh : otherMeshes) + ms->pushMesh(mesh); + _fields = otherFields; } MCAuto MEDFileFields::partOfThisOnStructureElements() const diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 3eb3c32bb..c06875e10 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -112,6 +112,7 @@ namespace MEDCoupling MEDLOADER_EXPORT void keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName); MEDLOADER_EXPORT void getMeshSENames(std::vector< std::pair >& ps) const; MEDLOADER_EXPORT void blowUpSE(MEDFileMeshes *ms, const MEDFileStructureElements *ses); + MEDLOADER_EXPORT void aggregateFieldsOnSameMeshes(MEDFileMeshes *ms); MEDLOADER_EXPORT MCAuto partOfThisOnStructureElements() const; MEDLOADER_EXPORT MCAuto partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const; MEDLOADER_EXPORT void aggregate(const MEDFileFields& other); diff --git a/src/MEDLoader/MEDFileFieldMultiTS.cxx b/src/MEDLoader/MEDFileFieldMultiTS.cxx index 8376767e7..74bc171d6 100644 --- a/src/MEDLoader/MEDFileFieldMultiTS.cxx +++ b/src/MEDLoader/MEDFileFieldMultiTS.cxx @@ -1157,6 +1157,36 @@ MEDFileInt32FieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt( return ret.retn(); } +MCAuto MEDFileFieldMultiTSWithoutSDA::createNewWithSDA() const +{ + MCAuto ret(MEDFileFieldMultiTS::New()); + return DynamicCast(ret); +} + +//= + +MCAuto MEDFileInt32FieldMultiTSWithoutSDA::createNewWithSDA() const +{ + MCAuto ret(MEDFileInt32FieldMultiTS::New()); + return DynamicCast(ret); +} + +//= + +MCAuto MEDFileInt64FieldMultiTSWithoutSDA::createNewWithSDA() const +{ + MCAuto ret(MEDFileInt64FieldMultiTS::New()); + return DynamicCast(ret); +} + +//= + +MCAuto MEDFileFloatFieldMultiTSWithoutSDA::createNewWithSDA() const +{ + MCAuto ret(MEDFileFloatFieldMultiTS::New()); + return DynamicCast(ret); +} + //= MEDFileAnyTypeFieldMultiTS MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS() @@ -2059,6 +2089,7 @@ MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< type /*! * \a dts and \a ftmss are expected to have same size. + * see MEDFileFieldPerMeshPerTypePerDisc::Aggregate for description of \a dts. */ MCAuto MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector& fmtss, const std::vector< std::vector< std::pair > >& dts) { diff --git a/src/MEDLoader/MEDFileFieldMultiTS.hxx b/src/MEDLoader/MEDFileFieldMultiTS.hxx index aa4b2330e..05f7d2b58 100644 --- a/src/MEDLoader/MEDFileFieldMultiTS.hxx +++ b/src/MEDLoader/MEDFileFieldMultiTS.hxx @@ -34,7 +34,8 @@ namespace MEDCoupling class MEDFileFieldVisitor; class MEDFileAnyTypeField1TS; class MEDFileAnyTypeField1TSWithoutSDA; - + class MEDFileAnyTypeFieldMultiTS; + class MEDFileAnyTypeFieldMultiTSWithoutSDA : public RefCountObject, public MEDFileFieldNameScope { protected: @@ -53,6 +54,7 @@ namespace MEDCoupling MEDLOADER_EXPORT virtual const char *getTypeStr() const = 0; MEDLOADER_EXPORT virtual MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const = 0; MEDLOADER_EXPORT virtual MEDFileAnyTypeFieldMultiTSWithoutSDA *createNew() const = 0; + MEDLOADER_EXPORT virtual MCAuto createNewWithSDA() const = 0; MEDLOADER_EXPORT virtual MEDFileAnyTypeField1TSWithoutSDA *createNew1TSWithoutSDAEmptyInstance() const = 0; MEDLOADER_EXPORT virtual void checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const = 0; MEDLOADER_EXPORT const std::vector& getInfo() const; @@ -147,6 +149,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileInt32FieldMultiTSWithoutSDA *convertToInt() const; MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const { return new MEDFileFieldMultiTSWithoutSDA(*this); } MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileFieldMultiTSWithoutSDA"); } + MEDLOADER_EXPORT MCAuto createNewWithSDA() const override; protected: MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileTemplateFieldMultiTSWithoutSDA(fieldName,meshName) { } MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileTemplateFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { } @@ -174,6 +177,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileInt32FieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities) { } MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const { return new MEDFileInt32FieldMultiTSWithoutSDA(*this); } MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileInt32FieldMultiTSWithoutSDA"); } + MEDLOADER_EXPORT MCAuto createNewWithSDA() const override; protected: MEDFileInt32FieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileNDTemplateFieldMultiTSWithoutSDA(fieldName,meshName) { } MEDFileInt32FieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { } @@ -189,6 +193,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileInt64FieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities) { } MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const { return new MEDFileInt64FieldMultiTSWithoutSDA(*this); } MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileInt64FieldMultiTSWithoutSDA"); } + MEDLOADER_EXPORT MCAuto createNewWithSDA() const override; protected: MEDFileInt64FieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileNDTemplateFieldMultiTSWithoutSDA(fieldName,meshName) { } MEDFileInt64FieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { } @@ -204,6 +209,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileFloatFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities) { } MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const { return new MEDFileFloatFieldMultiTSWithoutSDA(*this); } MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileFloatFieldMultiTSWithoutSDA"); } + MEDLOADER_EXPORT MCAuto createNewWithSDA() const override; protected: MEDFileFloatFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileNDTemplateFieldMultiTSWithoutSDA(fieldName,meshName) { } MEDFileFloatFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { }