From: Anthony Geay Date: Mon, 24 Nov 2014 09:06:47 +0000 (+0100) Subject: MEDFileUMesh::zipCoords updates correctly the part definition is any without computat... X-Git-Tag: V7_5_1b1~5^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5fda846d4e3b7e5803cbb2ed83e1d60594ba69db;p=modules%2Fmed.git MEDFileUMesh::zipCoords updates correctly the part definition is any without computation of merged umesh. --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index aa007f405..173bbcd52 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -475,13 +475,14 @@ void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const { if(!_profile.empty()) throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !"); + INTERP_KERNEL::AutoPtr pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + int profilesize,nbi; + int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi)); const SlicePartDefinition *spd(dynamic_cast(pd)); if(spd) { - int profilesize,nbi,start,stop,step; + int start,stop,step; spd->getSlice(start,stop,step); - INTERP_KERNEL::AutoPtr pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); - int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi)); int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile")); med_filter filter=MED_FILTER_INIT; MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo, @@ -492,6 +493,29 @@ void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const MEDfilterClose(&filter); return ; } + const DataArrayPartDefinition *dpd(dynamic_cast(pd)); + if(dpd) + { + dpd->checkCoherency(); + MEDCouplingAutoRefCountObjectPtr myIds(dpd->toDAI()); + int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray()); + myIds->applyLin(1,-a); + int nbOfEltsToLoad(b-a+1); + med_filter filter=MED_FILTER_INIT; + {//TODO : manage int32 ! + MEDCouplingAutoRefCountObjectPtr tmp(DataArrayDouble::New()); + tmp->alloc(nbOfEltsToLoad,nbOfCompo); + MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo, + MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE, + /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad, + /*lastblocksize=useless because count=1*/0,&filter); + MEDfieldValueAdvancedRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast(tmp->getPointer())); + MEDCouplingAutoRefCountObjectPtr feeder(DataArrayDouble::New()); + feeder->useExternalArrayWithRWAccess(reinterpret_cast(startFeedingPtr),_nval,nbOfCompo); + feeder->setContigPartOfSelectedValues(0,tmp,myIds); + } + MEDfilterClose(&filter); + } else throw INTERP_KERNEL::Exception("Not implemented yet for not slices!"); } @@ -523,14 +547,9 @@ void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_i } else { - const SlicePartDefinition *spd(dynamic_cast(pd)); - if(!spd) - throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : Part def only implemented for split one !"); if(!_profile.empty()) throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !"); - int start1,stop1,step1; - spd->getSlice(start1,stop1,step1); - _nval=DataArray::GetNumberOfItemGivenBES(start1,stop1,step1,"MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively"); + _nval=pd->getNumberOfElems(); } _start=start; _end=start+_nval*nbi; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index f9074f970..d286ef511 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -3499,24 +3499,34 @@ struct MEDLoaderAccVisit1 */ DataArrayInt *MEDFileUMesh::zipCoords() { - const DataArrayDouble *coo=getCoords(); + const DataArrayDouble *coo(getCoords()); if(!coo) throw INTERP_KERNEL::Exception("MEDFileUMesh::zipCoords : no coordinates set in this !"); - int nbOfNodes=coo->getNumberOfTuples(); + int nbOfNodes(coo->getNumberOfTuples()); std::vector nodeIdsInUse(nbOfNodes,false); - std::vector neLevs=getNonEmptyLevels(); + std::vector neLevs(getNonEmptyLevels()); for(std::vector::const_iterator lev=neLevs.begin();lev!=neLevs.end();lev++) { - MEDCouplingAutoRefCountObjectPtr m=getMeshAtLevel(*lev); - m->computeNodeIdsAlg(nodeIdsInUse); + const MEDFileUMeshSplitL1 *zeLev(getMeshAtLevSafe(*lev)); + if(zeLev->isMeshStoredSplitByType()) + { + std::vector ms(zeLev->getDirectUndergroundSingleGeoTypeMeshes()); + for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++) + if(*it) + (*it)->computeNodeIdsAlg(nodeIdsInUse); + } + else + { + zeLev->getWholeMesh(false)->computeNodeIdsAlg(nodeIdsInUse); + } } - int nbrOfNodesInUse=(int)std::count(nodeIdsInUse.begin(),nodeIdsInUse.end(),true); + int nbrOfNodesInUse((int)std::count(nodeIdsInUse.begin(),nodeIdsInUse.end(),true)); if(nbrOfNodesInUse==nbOfNodes) - return 0; - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfNodes,1); + return 0;//no need to update _part_coords + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(nbOfNodes,1); std::transform(nodeIdsInUse.begin(),nodeIdsInUse.end(),ret->getPointer(),MEDLoaderAccVisit1()); - MEDCouplingAutoRefCountObjectPtr ret2=ret->invertArrayO2N2N2OBis(nbrOfNodesInUse); - MEDCouplingAutoRefCountObjectPtr newCoords=coo->selectByTupleIdSafe(ret2->begin(),ret2->end()); + MEDCouplingAutoRefCountObjectPtr ret2(ret->invertArrayO2N2N2OBis(nbrOfNodesInUse)); + MEDCouplingAutoRefCountObjectPtr newCoords(coo->selectByTupleIdSafe(ret2->begin(),ret2->end())); MEDCouplingAutoRefCountObjectPtr newFamCoords; MEDCouplingAutoRefCountObjectPtr newNameCoords; if((const DataArrayInt *)_fam_coords) @@ -3532,6 +3542,13 @@ DataArrayInt *MEDFileUMesh::zipCoords() if((MEDFileUMeshSplitL1*)*it) (*it)->renumberNodesInConn(ret->begin()); } + // updates _part_coords + const PartDefinition *pc(_part_coords); + if(pc) + { + MEDCouplingAutoRefCountObjectPtr tmpPD(DataArrayPartDefinition::New(ret2)); + _part_coords=tmpPD->composeWith(pc); + } return ret.retn(); } diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 0be925c44..5139d9ca9 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -1018,10 +1018,7 @@ void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N) { - MEDCouplingUMesh *m(_m_by_types.getUmesh()); - if(!m) - return; - m->renumberNodesInConn(newNodeNumbersO2N); + _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N); } void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId) @@ -1280,6 +1277,26 @@ void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTER throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !"); } +void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N) +{ + if(_mp_time>_m_time) + { + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) + { + MEDCoupling1GTUMesh *m(*it); + if(m) + m->renumberNodesInConn(newNodeNumbersO2N); + } + } + else + { + MEDCouplingUMesh *m(getUmesh()); + if(!m) + return; + m->renumberNodesInConn(newNodeNumbersO2N); + } +} + void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const { const MEDCouplingUMesh *m(_m); @@ -1313,6 +1330,14 @@ const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputati throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !"); } +/*! + * This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh. + */ +bool MEDFileUMeshAggregateCompute::isStoredSplitByType() const +{ + return _mp_time>=_m_time; +} + std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const { if(_mp_time>_m_time) diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 4be19e047..d493a26a9 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -160,6 +160,8 @@ namespace ParaMEDMEM std::vector retrievePartsWithoutComputation() const; MEDCoupling1GTUMesh *retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const; void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const; + void renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N); + bool isStoredSplitByType() const; std::size_t getTimeOfThis() const; std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildrenWithNull() const; @@ -213,6 +215,7 @@ namespace ParaMEDMEM MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const; DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const; MEDCouplingUMesh *getWholeMesh(bool renum) const; + bool isMeshStoredSplitByType() const { return _m_by_types.isStoredSplitByType(); } std::vector getGeoTypes() const; std::vector getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.retrievePartsWithoutComputation(); } MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.retrievePartWithoutComputation(gt); } diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 55762ee81..f9b8c1d84 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -3796,6 +3796,61 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(mm.getCoords().isEqual(coo,1e-12)) pass + def testZipCoordsWithLoadPart1(self): + """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated. + """ + fileName="Pyfile84.med" + meshName="Mesh" + compos=["aa [kg]","bbb [m/s]"] + arr=DataArrayDouble(6) ; arr.iota() + m=MEDCouplingCMesh() ; m.setCoords(arr,arr) + m=m.buildUnstructured() + m.setName(meshName) + m.changeSpaceDimension(3,0.) + infos=["aa [b]","cc [de]","gg [klm]"] + m.getCoords().setInfoOnComponents(infos) + m.checkCoherency2() + f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m) + f.setName("Field") + arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos) + arr[:,0]=range(25) + arr[:,1]=range(100,125) + f.setArray(arr) + MEDLoader.WriteField(fileName,f,2) + f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m) + f.setName("FieldNode") + arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos) + arr[:,0]=range(200,236) + arr[:,1]=range(300,336) + f.setArray(arr) + f.checkCoherency() + MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f) + # + ms=MEDFileMeshes() + mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1]) + ms.pushMesh(mm) + spd=mm.getPartDefAtLevel(0,NORM_QUAD4) + self.assertEqual(spd.getSlice(),slice(4,6,1)) + spd=mm.getPartDefAtLevel(1) + self.assertEqual(spd.getSlice(),slice(4,14,1)) + self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes()) + mm.zipCoords() # <- The important line is here ! + spd=mm.getPartDefAtLevel(0,NORM_QUAD4) + self.assertEqual(spd.getSlice(),slice(4,6,1)) + spd=mm.getPartDefAtLevel(1) + self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes()) + self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13]))) + fs=MEDFileFields.LoadPartOf(fileName,False,ms) + fs[0][0].loadArrays() + arr=DataArrayDouble([(4,104),(5,105)]) + arr.setInfoOnComponents(compos) + self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12)) + fs[1][0].loadArrays() + arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)]) + arr.setInfoOnComponents(compos) + self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12)) + pass + pass unittest.main()