X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileField.cxx;h=dc81062983ab4c36394b02db050c007211927003;hb=662a2a2393a25baef77e42f74204b11b70a9646c;hp=aca9b0c2fca26eca2fd14b4ad113d3d2aa06014d;hpb=e4063d87dbb8dad309dc1880af096d521934cf24;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index aca9b0c2f..dc8106298 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2020 CEA/DEN, EDF R&D +// Copyright (C) 2007-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -1077,6 +1077,125 @@ 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 !"); + // + std::vector msNames(ms->getMeshesNames()); + std::set msNamesSet(msNames.begin(),msNames.end()); + if(msNames.size() == msNamesSet.size()) + return ; + // + 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)); + } + // until this point nothing has changed in \a this nor in \a ms as if a const method. + ms->resize(0); + for(auto mesh : otherMeshes) + ms->pushMesh(mesh); + _fields = otherFields; } MCAuto MEDFileFields::partOfThisOnStructureElements() const