From: ageay Date: Fri, 30 Nov 2012 11:55:24 +0000 (+0000) Subject: Debug on MEDLoader.WriteFieldGauss on multi disc per cell type. X-Git-Tag: V6_6_0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6f16e810259b306d47a38043c64811eff08d62af;p=tools%2Fmedcoupling.git Debug on MEDLoader.WriteFieldGauss on multi disc per cell type. --- diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 842695a46..8fd883859 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -2402,10 +2402,9 @@ void MEDLoaderNS::appendCellProfileField(const char *fileName, const ParaMEDMEM: std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++; MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR); const std::vector& ids=(*iter).getCellIdPerType(); - int *profile=new int [ids.size()]; - std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus(),1)); + INTERP_KERNEL::AutoPtr profile=new int [ids.size()]; + std::transform(ids.begin(),ids.end(),(int *)profile,std::bind2nd(std::plus(),1)); MEDprofileWr(fid,profileName,ids.size(),profile); - delete [] profile; MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,profileName, MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt); pt+=(*iter).getNbOfTuple()*nbComp; @@ -2431,10 +2430,9 @@ void MEDLoaderNS::appendNodeElementProfileField(const char *fileName, const Para std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++; MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR); const std::vector& ids=(*iter).getCellIdPerType(); - int *profile=new int [ids.size()]; - std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus(),1)); + INTERP_KERNEL::AutoPtr profile=new int [ids.size()]; + std::transform(ids.begin(),ids.end(),(int *)profile,std::bind2nd(std::plus(),1)); MEDprofileWr(fid,profileName,ids.size(),profile); - delete [] profile; int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes(); int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType()); int nbOfValues=nbPtPerCell*nbOfEntity; @@ -2536,25 +2534,75 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME } case ParaMEDMEM::ON_GAUSS_PT: { + INTERP_KERNEL::AutoPtr profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); std::list split; prepareCellFieldDoubleForWriting(f,0,split); - int idGp=0; + int idGp=0,offset=0,offset2=0; + const double *pt2=0; + INTERP_KERNEL::NormalizedCellType prevType=INTERP_KERNEL::NORM_ERROR; for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) { + if((*iter).getType()!=prevType) + { + offset=offset2; + prevType=(*iter).getType(); + } INTERP_KERNEL::AutoPtr nomGauss=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); std::ostringstream oss; oss << "GP_" << f->getName() << idGp++; MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,nomGauss,MEDLoader::_TOO_LONG_STR); - int id=f->getGaussLocalizationIdOfOneType((*iter).getType()); + std::ostringstream ossPfl; + int id=-1,nbOfEntity=-1; + MEDCouplingAutoRefCountObjectPtr arrTmp; + if((*iter).getCellIdPerType().empty()) + { + id=f->getGaussLocalizationIdOfOneType((*iter).getType()); + nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType()); + } + else + { + id=f->getGaussLocalizationIdOfOneCell((*iter).getCellIdPerType()[0]+offset); + nbOfEntity=(int)(*iter).getCellIdPerType().size(); + ossPfl << "Pfl" << f->getName() << "_" << id; + MEDLoaderBase::safeStrCpy(ossPfl.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR); + INTERP_KERNEL::AutoPtr profile=new int[(*iter).getCellIdPerType().size()]; + std::transform((*iter).getCellIdPerType().begin(),(*iter).getCellIdPerType().end(),(int *)profile,std::bind2nd(std::plus(),1)); + MEDprofileWr(fid,profileName,(*iter).getCellIdPerType().size(),profile); + // + MEDCouplingAutoRefCountObjectPtr da3=DataArrayInt::New(); + da3->useArray(const_cast(&((*iter).getCellIdPerType()[0])),false,CPP_DEALLOC,(int)(*iter).getCellIdPerType().size(),1); + MEDCouplingAutoRefCountObjectPtr da4=da3->deepCpy(); + da4->applyLin(1,offset); + // + const MEDCouplingFieldDiscretizationGauss *disc2=static_cast(f->getDiscretization()); + MEDCouplingAutoRefCountObjectPtr arr=disc2->getOffsetArr(f->getMesh()); + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayInt::New(); + int trueNval=0; + for(const int *pt3=da4->begin();pt3!=da4->end();pt3++) + trueNval+=arr->getIJ(*pt3+1,0)-arr->getIJ(*pt3,0); + tmp->alloc(trueNval,1); + int *tmpPtr=tmp->getPointer(); + for(const int *pt3=da4->begin();pt3!=da4->end();pt3++) + for(int j=arr->getIJ(*pt3,0);jgetIJ(*pt3+1,0);j++) + *tmpPtr++=j; + arrTmp=f->getArray()->selectByTupleId(tmp->begin(),tmp->end()); + pt2=arrTmp->getConstPointer(); + } const MEDCouplingGaussLocalization& gl=f->getGaussLocalization(id); MEDlocalizationWr(fid,nomGauss,typmai3[(int)(*iter).getType()],mesh->getMeshDimension(),&gl.getRefCoords()[0],MED_FULL_INTERLACE, gl.getNumberOfGaussPt(),&gl.getGaussCoords()[0],&gl.getWeights()[0],MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT); - int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType()); int nbOfValues=gl.getNumberOfGaussPt()*nbOfEntity; INTERP_KERNEL::AutoPtr fieldname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fieldname,MEDLoader::_TOO_LONG_STR); - MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE, - MED_ALLENTITIES_PROFILE,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt); + if((*iter).getCellIdPerType().empty()) + { + MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE, + MED_ALLENTITIES_PROFILE,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt); + } + else + MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE, + profileName,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt2); pt+=nbOfValues*nbComp; + offset2+=(*iter).getNbOfGeoElt(); } break; } @@ -2603,12 +2651,56 @@ void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCoupling { curType=(INTERP_KERNEL::NormalizedCellType)conn[*pt]; const int *pt2=std::find_if(pt+1,connI+nbOfCells,ConnReaderML(conn,(int)curType)); - if(!cellIdsPerType) - split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,1,0,0)); + int szOfChunk=std::distance(pt,pt2); + if(f->getTypeOfField()!=ON_GAUSS_PT) + { + if(!cellIdsPerType) + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,szOfChunk,1,0,0)); + else + { + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,szOfChunk,1,wCellIdsPT,0)); + wCellIdsPT+=szOfChunk; + } + } else { - split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,1,wCellIdsPT,0)); - wCellIdsPT+=std::distance(pt,pt2); + const MEDCouplingFieldDiscretizationGauss *disc=static_cast(f->getDiscretization()); + const DataArrayInt *arr=disc->getArrayOfDiscIds(); + MEDCouplingAutoRefCountObjectPtr da,daTmp1; + if(!cellIdsPerType) + da=arr->selectByTupleId2(std::distance(connI,pt),std::distance(connI,pt2),1); + else + { + daTmp1=DataArrayInt::New(); + daTmp1->useArray(const_cast(cellIdsPerType),false,CPP_DEALLOC,szOfChunk,1); + MEDCouplingAutoRefCountObjectPtr daTmp2=daTmp1->deepCpy(); + daTmp2->applyLin(1,std::distance(connI,pt)); + da=arr->selectByTupleId(daTmp2->begin(),daTmp2->end()); + } + std::vector differentIds; + std::vector parts=da->partitionByDifferentValues(differentIds); + std::vector< MEDCouplingAutoRefCountObjectPtr > partsAuto(parts.size()); + int jj=0; + for(std::vector::const_iterator it=parts.begin();it!=parts.end();it++,jj++) + partsAuto[jj]=parts[jj]; + jj=0; + for(std::vector::const_iterator it=parts.begin();it!=parts.end();it++,jj++) + { + if(!cellIdsPerType) + { + if(parts[jj]->getNumberOfTuples()==szOfChunk && parts[jj]->isIdentity()) + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,szOfChunk,1,0,0)); + else + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,parts[jj]->getNumberOfTuples(),1,parts[jj]->getConstPointer(),0)); + } + else + { + MEDCouplingAutoRefCountObjectPtr tmp=daTmp1->selectByTupleId(parts[jj]->begin(),parts[jj]->end()); + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,tmp->getNumberOfTuples(),1,tmp->getConstPointer(),0)); + } + } + if(!cellIdsPerType) + wCellIdsPT+=szOfChunk; } pt=pt2; } diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 1c7276bec..194def721 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -1435,6 +1435,7 @@ class MEDLoaderTest(unittest.TestCase): def testGaussWriteOnPfl1(self): fname="Pyfile49.med" + fname2="Pyfile50.med" coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2) mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords) mQ8.allocateCells(1) @@ -1498,6 +1499,10 @@ class MEDLoaderTest(unittest.TestCase): f2_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) f2_bis.checkCoherency() self.assertTrue(f.isEqual(f2_bis,1e-12,1e-12)) + # + MEDLoader.WriteField(fname2,f,True) + f2_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) + self.assertTrue(f.isEqual(f2_ter,1e-12,1e-12)) ## Use case 2 : Pfl on part tri3 with 2 disc and on part quad8 with 1 disc f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME) pfl=DataArrayInt([1,2,5,6,8,9,15,16,17,18]) ; pfl.setName("pfl2") @@ -1532,6 +1537,11 @@ class MEDLoaderTest(unittest.TestCase): f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) f3_bis.renumberCells([0,1,3,2,4,5,6,7,8,9]) self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12)) + # + MEDLoader.WriteField(fname2,f,True) + f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) + f3_ter.renumberCells([0,1,3,2,4,5,6,7,8,9]) + self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12)) ## Use case 3 : no pfl but creation of pfls due to gauss pts f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME) f.setMesh(m) @@ -1566,6 +1576,11 @@ class MEDLoaderTest(unittest.TestCase): f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) f3_bis.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19]) self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12)) + # + MEDLoader.WriteField(fname2,f,True) + f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) + f3_ter.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19]) + self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12)) pass pass