X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileMeshLL.cxx;h=ecef4f432b53bb2fb110e495607668ffb65cffed;hb=490dddcbdaa4272528887a2bbaaf345c11e28cad;hp=639e0f7fa224bfd15d503025c00bbab29bddd6dd;hpb=76184f4ee8ba59e4f9739ae8e89256106002eb03;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 639e0f7fa..ecef4f432 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -23,6 +23,8 @@ #include "MEDLoaderBase.hxx" #include "MEDFileSafeCaller.txx" #include "MEDFileMeshReadSelector.hxx" +#include "MEDFileStructureElement.hxx" +#include "MEDFileMeshSupport.hxx" #include "MEDCouplingUMesh.hxx" @@ -30,63 +32,37 @@ #include "CellModel.hxx" #include +#include +// From MEDLOader.cxx TU extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO]; extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO]; extern med_geometry_type typmainoeud[1]; -using namespace ParaMEDMEM; +using namespace MEDCoupling; -MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE) -{ -} +const char MEDFileMeshL2::ZE_SEP_FOR_FAMILY_KILLERS[]="!/__\\!";//important start by - because ord('!')==33 the smallest (!=' ') to preserve orders at most. -std::size_t MEDFileMeshL2::getHeapMemorySizeWithoutChildren() const -{ - return 0; -} +int MEDFileMeshL2::ZE_SEP2_FOR_FAMILY_KILLERS=4; -std::vector MEDFileMeshL2::getDirectChildrenWithNull() const -{ - return std::vector(); -} - -int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) +std::vector MeshCls::getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const { med_mesh_type type_maillage; - char maillage_description[MED_COMMENT_SIZE+1]; - char dtunit[MED_LNAME_SIZE+1]; - med_int spaceDim,dim; - char nommaa[MED_NAME_SIZE+1]; - med_int n=MEDnMesh(fid); - bool found=false; - int ret=-1; + med_int spaceDim, meshDim, nbSteps; med_sorting_type stype; - std::vector ms; - int nstep; med_axis_type axistype; - for(int i=0;i axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); - INTERP_KERNEL::AutoPtr axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); - MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit)); - dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit)); - std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)); - ms.push_back(cur); - if(cur==mname) - { - found=true; - ret=i+1; - } - } - if(!found) - { - std::ostringstream oss; - oss << "No such meshname (" << mname << ") in file ! Must be in : "; - std::copy(ms.begin(),ms.end(),std::ostream_iterator(oss,", ")); - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } + med_int naxis(MEDmeshnAxis(fid,getID())); + INTERP_KERNEL::AutoPtr nameTmp(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + INTERP_KERNEL::AutoPtr axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)); + INTERP_KERNEL::AutoPtr axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)); + INTERP_KERNEL::AutoPtr univTmp(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE)); + if(MEDmeshInfo(fid,getID(),nameTmp,&spaceDim,&meshDim,&type_maillage,description.getPointer(),dtunit.getPointer(), + &stype,&nbSteps,&axistype,axisname,axisunit)!=0) + throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !"); + Mdim=FromMedInt(meshDim); + nstep=FromMedInt(nbSteps); + MEDmeshUniversalNameRd(fid,nameTmp,univName.getPointer());// do not protect MEDFILESAFECALLERRD0 call : Thanks to fra.med. + axType=MEDFileMeshL2::TraduceAxisType(axistype); switch(type_maillage) { case MED_UNSTRUCTURED_MESH: @@ -95,7 +71,7 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, Para case MED_STRUCTURED_MESH: { med_grid_type gt; - MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mname.c_str(),>)); + MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),>)); switch(gt) { case MED_CARTESIAN_GRID: @@ -104,32 +80,39 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, Para case MED_CURVILINEAR_GRID: meshType=CURVE_LINEAR; break; + case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader + meshType=CARTESIAN; + break; default: - throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); + throw INTERP_KERNEL::Exception("MEDFileMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); } break; } default: - throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !"); + throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !"); } - med_int numdt,numit; - med_float dtt; - MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mname.c_str(),1,&numdt,&numit,&dtt)); - dt=numdt; it=numit; - return ret; + // + std::vector infosOnComp(naxis); + for(int i=0;i > p(nstep); for(int i=0;i(numdt,numit); - found=(numdt==dt) && (numit==numit); + p[i]=std::make_pair((int)numdt,(int)numit); + found=(numdt==dt) && (numit==it); + if (found) break; } if(!found) { @@ -142,85 +125,199 @@ double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, i return dtt; } -std::vector MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) +std::vector StructMeshCls::getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const +{ + INTERP_KERNEL::AutoPtr msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + INTERP_KERNEL::AutoPtr zeDescription(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE)); + med_axis_type medAxType; + med_int nAxis(MEDsupportMeshnAxis(fid,getID())); + INTERP_KERNEL::AutoPtr axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]); + med_int spaceDim(0),meshDim(0); + MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,getID(),msn,&spaceDim,&meshDim,zeDescription,&medAxType,axisName,axisUnit)); + std::string descriptionCpp(MEDLoaderBase::buildStringFromFortran(zeDescription,MED_COMMENT_SIZE)); + description.set(descriptionCpp.c_str()); + dtunit.clear(); univName.clear(); meshType=UNSTRUCTURED; nstep=1; + axType=MEDFileMeshL2::TraduceAxisType(medAxType); + //int nmodels(0); + //med_bool chgt=MED_FALSE,trsf=MED_FALSE; + //nmodels=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf); + std::vector ret; + for(int i=0;i MEDFileMeshL2::getDirectChildrenWithNull() const +{ + return std::vector(); +} + +INTERP_KERNEL::AutoCppPtr MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1) +{ + med_mesh_type type_maillage=MED_UNDEF_MESH_TYPE; + char maillage_description[MED_COMMENT_SIZE+1]; + char dtunit[MED_LNAME_SIZE+1]; + med_int spaceDim,dim; + char nommaa[MED_NAME_SIZE+1]; + med_int n=MEDnMesh(fid); + char found(0); + int ret=-1; med_sorting_type stype; - med_axis_type axistype; - int naxis(MEDmeshnAxis(fid,mId)); - INTERP_KERNEL::AutoPtr nameTmp=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); - INTERP_KERNEL::AutoPtr axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); - INTERP_KERNEL::AutoPtr axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); - INTERP_KERNEL::AutoPtr univTmp=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); - if(MEDmeshInfo(fid,mId,nameTmp,&spaceDim,&Mdim,&type_maillage,_description.getPointer(),_dt_unit.getPointer(), - &stype,&nstep,&axistype,axisname,axisunit)!=0) - throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !"); - MEDmeshUniversalNameRd(fid,nameTmp,_univ_name.getPointer());// do not protect MEDFILESAFECALLERRD0 call : Thanks to fra.med. - switch(type_maillage) - { - case MED_UNSTRUCTURED_MESH: - meshType=UNSTRUCTURED; - break; - case MED_STRUCTURED_MESH: - { - med_grid_type gt; - MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),>)); - switch(gt) + std::vector ms; + med_int nstep; + med_axis_type axistype=MED_UNDEF_AXIS_TYPE; + for(int i=0;i axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)); + MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit)); + dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit)); + std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa))); + ms.push_back(cur); + if(cur==mName) { - case MED_CARTESIAN_GRID: - meshType=CARTESIAN; - break; - case MED_CURVILINEAR_GRID: - meshType=CURVE_LINEAR; + found=1; + ret=i+1; + } + } + if(found==0) + {//last chance ! Is it a support mesh ? + med_int nbSM(MEDnSupportMesh(fid)); + for(int i=0;i axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)); + MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,maillage_description,&axistype,axisname,axisunit)); + std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa))); + ms.push_back(cur); + if(cur==mName) + { + found=2; + ret=i+1; + } + } + } + //////////////////////// + switch(found) + { + case 1: + { + axType=TraduceAxisType(axistype); + switch(type_maillage) + { + case MED_UNSTRUCTURED_MESH: + meshType=UNSTRUCTURED; break; + case MED_STRUCTURED_MESH: + { + med_grid_type gt; + MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),>)); + switch(gt) + { + case MED_CARTESIAN_GRID: + meshType=CARTESIAN; + break; + case MED_CURVILINEAR_GRID: + meshType=CURVE_LINEAR; + break; + case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader + meshType=CARTESIAN; + break; + default: + throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); + } + break; + } default: - throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); - } - break; + throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !"); + } + med_int numdt,numit; + med_float dtt; + MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),1,&numdt,&numit,&dtt)); + dt=FromMedInt(numdt); it=FromMedInt(numit); + return new MeshCls(ret); + } + case 2: + { + meshType=UNSTRUCTURED; + dt=MED_NO_DT; it=MED_NO_IT; dtunit1.clear(); + axType=TraduceAxisType(axistype); + return new StructMeshCls(ret); } default: - throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !"); - } - // - std::vector infosOnComp(naxis); - for(int i=0;i(oss,", ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } - return infosOnComp; + } -void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const std::string& meshName, std::map& fams, std::map >& grps, MEDFileMeshReadSelector *mrs) +/*! + * non static and non const method because _description, _dt_unit... are set in this method. + */ +std::vector MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim) +{ + return mId->getAxisInfoOnMesh(fid,mName,meshType,axType,nstep,Mdim,_description,_dt_unit,_univ_name); +} + +void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const std::string& meshName, std::map& fams, std::map >& grps, MEDFileMeshReadSelector *mrs) { if(mrs && !(mrs->isCellFamilyFieldReading() || mrs->isNodeFamilyFieldReading())) return ; char nomfam[MED_NAME_SIZE+1]; med_int numfam; - int nfam=MEDnFamily(fid,meshName.c_str()); + med_int nfam=MEDnFamily(fid,meshName.c_str()); + std::vector< std::pair > > > crudeFams(nfam); for(int i=0;i attide=new med_int[natt]; INTERP_KERNEL::AutoPtr attval=new med_int[natt]; INTERP_KERNEL::AutoPtr attdes=new char[MED_COMMENT_SIZE*natt+1]; INTERP_KERNEL::AutoPtr gro=new char[MED_LNAME_SIZE*ngro+1]; MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro); - std::string famName=MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE); - fams[famName]=numfam; + std::string famName(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE)); + std::vector grps2(ngro); for(int j=0;j > >(famName,std::pair >(numfam,grps2)); + } + RenameFamiliesFromFileToMemInternal(crudeFams); + for(std::vector< std::pair > > >::const_iterator it0=crudeFams.begin();it0!=crudeFams.end();it0++) + { + fams[(*it0).first]=(*it0).second.first; + for(std::vector::const_iterator it1=(*it0).second.second.begin();it1!=(*it0).second.second.end();it1++) + grps[*it1].push_back((*it0).first); } } -void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map& fams, const std::map >& grps, int tooLongStrPol) +void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map& fams, const std::map >& grps, int tooLongStrPol) { - for(std::map::const_iterator it=fams.begin();it!=fams.end();it++) + std::vector< std::pair > > > crudeFams(fams.size()); + std::size_t ii(0); + for(std::map::const_iterator it=fams.begin();it!=fams.end();it++,ii++) { std::vector grpsOfFam; for(std::map >::const_iterator it1=grps.begin();it1!=grps.end();it1++) @@ -228,29 +325,205 @@ void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const std::string& mname, if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end()) grpsOfFam.push_back((*it1).first); } - int ngro=grpsOfFam.size(); + crudeFams[ii]=std::pair > >((*it).first,std::pair >((*it).second,grpsOfFam)); + } + RenameFamiliesFromMemToFileInternal(crudeFams); + for(std::vector< std::pair > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++) + { + std::size_t ngro((*it).second.second.size()); INTERP_KERNEL::AutoPtr groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro); int i=0; - for(std::vector::const_iterator it2=grpsOfFam.begin();it2!=grpsOfFam.end();it2++,i++) - MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,tooLongStrPol); + for(std::vector::const_iterator it2=(*it).second.second.begin();it2!=(*it).second.second.end();it2++,i++) + MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE,groName+i*MED_LNAME_SIZE,tooLongStrPol); INTERP_KERNEL::AutoPtr famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol); - int ret=MEDfamilyCr(fid,mname.c_str(),famName,(*it).second,ngro,groName); + med_int ret=MEDfamilyCr(fid,mname.c_str(),famName,ToMedInt((*it).second.first),ToMedInt(ngro),groName); ret++; } } +void MEDFileMeshL2::RenameFamiliesPatternInternal(std::vector< std::pair > > >& crudeFams, RenameFamiliesPatternFunc func) +{ + std::size_t ii(0); + std::vector fams(crudeFams.size()); + for(std::vector< std::pair > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++) + fams[ii]=(*it).first; + if(!func(fams)) + return ; + ii=0; + for(std::vector< std::pair > > >::iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++) + (*it).first=fams[ii]; +} + +/*! + * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it. + * So this method renames families (if needed generally not !) in order to have a discriminant name for families. + */ +void MEDFileMeshL2::RenameFamiliesFromFileToMemInternal(std::vector< std::pair > > >& crudeFams) +{ + RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromFileToMem); +} + +bool MEDFileMeshL2::RenameFamiliesFromFileToMem(std::vector< std::string >& famNames) +{ + std::map m; + std::set s; + for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++) + { + if(s.find(*it)!=s.end()) + m[*it]=0; + s.insert(*it); + } + if(m.empty()) + return false;// the general case ! + for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++) + { + std::map::iterator it2(m.find(*it)); + if(it2!=m.end()) + { + std::ostringstream oss; oss << *it << ZE_SEP_FOR_FAMILY_KILLERS << std::setfill('0') << std::setw(ZE_SEP2_FOR_FAMILY_KILLERS) << (*it2).second++; + *it=oss.str(); + } + } + return true; +} + +/*! + * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it. + * So this method renames families (if needed generally not !) in order to have a discriminant name for families. + */ +void MEDFileMeshL2::RenameFamiliesFromMemToFileInternal(std::vector< std::pair > > >& crudeFams) +{ + RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromMemToFile); +} + +bool MEDFileMeshL2::RenameFamiliesFromMemToFile(std::vector< std::string >& famNames) +{ + bool isSmthingStrange(false); + for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++) + { + std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS)); + if(found!=std::string::npos) + isSmthingStrange=true; + } + if(!isSmthingStrange) + return false; + // pattern matching + std::map< std::string, std::vector > m; + for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++) + { + std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS)); + if(found!=std::string::npos && found>=1) + { + std::string s1((*it).substr(found+sizeof(ZE_SEP_FOR_FAMILY_KILLERS)-1)); + if((int)s1.size()!=ZE_SEP2_FOR_FAMILY_KILLERS) + continue; + int k(-1); + std::istringstream iss(s1); + iss >> k; + bool isOK((iss.rdstate() & ( std::istream::failbit | std::istream::eofbit)) == std::istream::eofbit); + if(isOK && k>=0) + { + std::string s0((*it).substr(0,found)); + m[s0].push_back(*it); + } + } + } + if(m.empty()) + return false; + // filtering + std::map zeMap; + for(std::map< std::string, std::vector >::const_iterator it=m.begin();it!=m.end();it++) + { + if((*it).second.size()==1) + continue; + for(std::vector::const_iterator it1=(*it).second.begin();it1!=(*it).second.end();it1++) + zeMap[*it1]=(*it).first; + } + if(zeMap.empty()) + return false; + // traduce + for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++) + { + std::map::iterator it1(zeMap.find(*it)); + if(it1!=zeMap.end()) + *it=(*it1).second; + } + return true; +} + +MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisType(med_axis_type at) +{ + switch(at) + { + case MED_CARTESIAN: + return AX_CART; + case MED_CYLINDRICAL: + return AX_CYL; + case MED_SPHERICAL: + return AX_SPHER; + case MED_UNDEF_AXIS_TYPE: + return AX_CART; + default: + throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisType : unrecognized axis type !"); + } +} + +MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisTypeStruct(med_grid_type gt) +{ + switch(gt) + { + case MED_CARTESIAN_GRID: + return AX_CART; + case MED_POLAR_GRID: + return AX_CYL; + default: + throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeStruct : only Cartesian and Cylindrical supported by MED file !"); + } +} + +med_axis_type MEDFileMeshL2::TraduceAxisTypeRev(MEDCoupling::MEDCouplingAxisType at) +{ + switch(at) + { + case AX_CART: + return MED_CARTESIAN; + case AX_CYL: + return MED_CYLINDRICAL; + case AX_SPHER: + return MED_SPHERICAL; + default: + throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRev : unrecognized axis type !"); + } +} + +med_grid_type MEDFileMeshL2::TraduceAxisTypeRevStruct(MEDCoupling::MEDCouplingAxisType at) +{ + switch(at) + { + case AX_CART: + return MED_CARTESIAN_GRID; + case AX_CYL: + return MED_POLAR_GRID; + case AX_SPHER: + return MED_POLAR_GRID; + default: + throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRevStruct : unrecognized axis type !"); + } +} + MEDFileUMeshL2::MEDFileUMeshL2() { } -std::vector MEDFileUMeshL2::loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim) +std::vector MEDFileUMeshL2::loadCommonPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, int& Mdim) { Mdim=-3; _name.set(mName.c_str()); int nstep; - ParaMEDMEM::MEDCouplingMeshType meshType; - std::vector ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim)); + MEDCoupling::MEDCouplingMeshType meshType; + MEDCoupling::MEDCouplingAxisType dummy3; + std::vector ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim)); if(nstep==0) { Mdim=-4; @@ -258,23 +531,23 @@ std::vector MEDFileUMeshL2::loadCommonPart(med_idt fid, int mId, co } if(meshType!=UNSTRUCTURED) throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !"); - _time=CheckMeshTimeStep(fid,mName,nstep,dt,it); + _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it); _iteration=dt; _order=it; return ret; } -void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs) +void MEDFileUMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs) { int Mdim; std::vector infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim)); if(Mdim==-4) return ; loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency - loadCoords(fid,mId,infosOnComp,mName,dt,it); + loadCoords(fid,infosOnComp,mName,dt,it); } -void MEDFileUMeshL2::loadPart(med_idt fid, int mId, const std::string& mName, const std::vector& types, const std::vector& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs) +void MEDFileUMeshL2::loadPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector& types, const std::vector& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs) { int Mdim; std::vector infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim)); @@ -282,18 +555,31 @@ void MEDFileUMeshL2::loadPart(med_idt fid, int mId, const std::string& mName, co return ; loadPartOfConnectivity(fid,Mdim,mName,types,slicPerTyp,dt,it,mrs); med_bool changement,transformation; - int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation)); + mcIdType nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation)); std::vector fetchedNodeIds(nCoords,false); - for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++) - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++) + for(std::vector< std::vector< MCAuto > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++) + for(std::vector< MCAuto >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++) (*it1)->getMesh()->computeNodeIdsAlg(fetchedNodeIds); - int nMin(std::distance(fetchedNodeIds.begin(),std::find(fetchedNodeIds.begin(),fetchedNodeIds.end(),true))); - int nMax(std::distance(fetchedNodeIds.rbegin(),std::find(fetchedNodeIds.rbegin(),fetchedNodeIds.rend(),true))); - nMax=nCoords-nMax; - for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++) - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++) - (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin); - loadPartCoords(fid,mId,infosOnComp,mName,dt,it,nMin,nMax); + if(!mrs || mrs->getNumberOfCoordsLoadSessions()==1) + { + mcIdType nMin(ToIdType(std::distance(fetchedNodeIds.begin(),std::find(fetchedNodeIds.begin(),fetchedNodeIds.end(),true)))); + mcIdType nMax(ToIdType(std::distance(fetchedNodeIds.rbegin(),std::find(fetchedNodeIds.rbegin(),fetchedNodeIds.rend(),true)))); + nMax=nCoords-nMax; + for(std::vector< std::vector< MCAuto > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++) + for(std::vector< MCAuto >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++) + (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin); + this->loadPartCoords(fid,infosOnComp,mName,dt,it,nMin,nMax); + } + else + { + mcIdType nbOfCooLS(mrs->getNumberOfCoordsLoadSessions()); + MCAuto fni(DataArrayIdType::BuildListOfSwitchedOn(fetchedNodeIds)); + MCAuto< MapKeyVal > o2n(fni->invertArrayN2O2O2NOptimized()); + for(std::vector< std::vector< MCAuto > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++) + for(std::vector< MCAuto >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++) + (*it1)->getMesh()->renumberNodesInConn(o2n->data()); + this->loadPartCoordsSlice(fid,infosOnComp,mName,dt,it,fni,nbOfCooLS); + } } void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs) @@ -309,7 +595,7 @@ void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const std::string& sortTypes(); } -void MEDFileUMeshL2::loadPartOfConnectivity(med_idt fid, int mdim, const std::string& mName, const std::vector& types, const std::vector& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs) +void MEDFileUMeshL2::loadPartOfConnectivity(med_idt fid, int mdim, const std::string& mName, const std::vector& types, const std::vector& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs) { std::size_t nbOfTypes(types.size()); if(slicPerTyp.size()!=3*nbOfTypes) @@ -321,18 +607,18 @@ void MEDFileUMeshL2::loadPartOfConnectivity(med_idt fid, int mdim, const std::st _per_type_mesh[0].clear(); for(std::size_t ii=0;ii tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs)); + mcIdType strt(slicPerTyp[3*ii+0]),stp(slicPerTyp[3*ii+1]),step(slicPerTyp[3*ii+2]); + MCAuto tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs)); _per_type_mesh[0].push_back(tmp); } sortTypes(); } -void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector& infosOnComp, const std::string& mName, int dt, int it) +void MEDFileUMeshL2::loadCoords(med_idt fid, const std::vector& infosOnComp, const std::string& mName, int dt, int it) { int spaceDim((int)infosOnComp.size()); med_bool changement,transformation; - int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation)); + med_int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation)); _coords=DataArrayDouble::New(); _coords->alloc(nCoords,spaceDim); double *coordsPtr(_coords->getPointer()); @@ -340,17 +626,19 @@ void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector0) { - _fam_coords=DataArrayInt::New(); - _fam_coords->alloc(nCoords,1); - MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer())); + MCAuto miFamCoord=DataArrayMedInt::New(); + miFamCoord->alloc(nCoords,1); + MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,miFamCoord->getPointer())); + _fam_coords=FromMedIntArray(miFamCoord); } else _fam_coords=0; if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) { - _num_coords=DataArrayInt::New(); - _num_coords->alloc(nCoords,1); - MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer())); + MCAuto miNumCoord=DataArrayMedInt::New(); + miNumCoord->alloc(nCoords,1); + MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,miNumCoord->getPointer())); + _num_coords=FromMedIntArray(miNumCoord); } else _num_coords=0; @@ -363,43 +651,53 @@ void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector0) + { + MCAuto miNumCoord=DataArrayMedInt::New(); + miNumCoord->alloc(nCoords,1); + MEDFILESAFECALLERRD0(MEDmeshGlobalNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,miNumCoord->getPointer())); + _global_num_coords=FromMedIntArray(miNumCoord); + } for(int i=0;isetInfoOnComponent(i,infosOnComp[i]); } -void MEDFileUMeshL2::loadPartCoords(med_idt fid, int mId, const std::vector& infosOnComp, const std::string& mName, int dt, int it, int nMin, int nMax) +void MEDFileUMeshL2::LoadPartCoords(med_idt fid, const std::vector& infosOnComp, const std::string& mName, int dt, int it, mcIdType nMin, mcIdType nMax, +MCAuto& _coords, MCAuto& _part_coords, MCAuto& _fam_coords, MCAuto& _num_coords, MCAuto& _name_coords) { med_bool changement,transformation; - int spaceDim((int)infosOnComp.size()),nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation)); + med_int spaceDim((int)infosOnComp.size()),nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation)); _coords=DataArrayDouble::New(); - int nbNodesToLoad(nMax-nMin); + mcIdType nbNodesToLoad(nMax-nMin); _coords->alloc(nbNodesToLoad,spaceDim); med_filter filter=MED_FILTER_INIT,filter2=MED_FILTER_INIT; MEDfilterBlockOfEntityCr(fid,/*nentity*/nCoords,/*nvaluesperentity*/1,/*nconstituentpervalue*/spaceDim, MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE, - /*start*/nMin+1,/*stride*/1,/*count*/1,/*blocksize*/nbNodesToLoad, + /*start*/ToMedInt(nMin+1),/*stride*/1,/*count*/1,/*blocksize*/ToMedInt(nbNodesToLoad), /*lastblocksize=useless because count=1*/0,&filter); MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateAdvancedRd,(fid,mName.c_str(),dt,it,&filter,_coords->getPointer())); _part_coords=PartDefinition::New(nMin,nMax,1); MEDfilterClose(&filter); MEDfilterBlockOfEntityCr(fid,nCoords,1,1,MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE, - MED_NO_PROFILE,nMin+1,1,1,nbNodesToLoad,0,&filter2); + MED_NO_PROFILE,ToMedInt(nMin+1),1,1,ToMedInt(nbNodesToLoad),0,&filter2); if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) { - _fam_coords=DataArrayInt::New(); - _fam_coords->alloc(nbNodesToLoad,1); - MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_FAMILY_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_fam_coords->getPointer())); + MCAuto miFamCoord=DataArrayMedInt::New(); + miFamCoord->alloc(nbNodesToLoad,1); + MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_FAMILY_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,miFamCoord->getPointer())); + _fam_coords=FromMedIntArray(miFamCoord); } else - _fam_coords=0; + _fam_coords=nullptr; if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) { - _num_coords=DataArrayInt::New(); - _num_coords->alloc(nbNodesToLoad,1); - MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_num_coords->getPointer())); + MCAuto miNumCoord=DataArrayMedInt::New(); + miNumCoord->alloc(nbNodesToLoad,1); + MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,miNumCoord->getPointer())); + _num_coords=FromMedIntArray(miNumCoord); } else - _num_coords=0; + _num_coords=nullptr; if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0) { _name_coords=DataArrayAsciiChar::New(); @@ -408,17 +706,87 @@ void MEDFileUMeshL2::loadPartCoords(med_idt fid, int mId, const std::vectorreAlloc(nbNodesToLoad);//not a bug to avoid the memory corruption due to last \0 at the end } else - _name_coords=0; + _name_coords=nullptr; MEDfilterClose(&filter2); _coords->setInfoOnComponents(infosOnComp); } +/*! + * For performance reasons LoadPartCoordsArray method calls LoadPartCoords + */ +void MEDFileUMeshL2::LoadPartCoordsArray(med_idt fid, const std::vector& infosOnComp, const std::string& mName, int dt, int it, const DataArrayIdType *nodeIds, +MCAuto& _coords, MCAuto& _fam_coords, MCAuto& _num_coords, MCAuto& _name_coords) +{ + MCAuto useless; + nodeIds->checkAllocated(); + nodeIds->checkNbOfComps(1,"loadPartCoordsSlice : Only one component expected !"); + mcIdType nMin(0),nMax(0); + if(!nodeIds->empty()) + { nMin = nodeIds->front(); nMax = nodeIds->back()+1; } + LoadPartCoords(fid,infosOnComp,mName,dt,it,nMin,nMax,_coords,useless,_fam_coords,_num_coords,_name_coords); + if(nodeIds->empty()) + return ; + MCAuto nodeIds2(nodeIds->deepCopy()); + nodeIds2->applyLin(1,-nMin); + _coords = _coords->selectByTupleIdSafe(nodeIds2->begin(),nodeIds2->end()); + if(_fam_coords.isNotNull()) + _fam_coords = _fam_coords->selectByTupleIdSafe(nodeIds2->begin(),nodeIds2->end()); + if(_num_coords.isNotNull()) + _num_coords = _num_coords->selectByTupleIdSafe(nodeIds2->begin(),nodeIds2->end()); + if(_name_coords.isNotNull()) + { + MCAuto tmp(_name_coords->selectByTupleIdSafe(nodeIds2->begin(),nodeIds2->end())); + _name_coords = DynamicCastSafe( tmp ); + } +} + +void MEDFileUMeshL2::loadPartCoords(med_idt fid, const std::vector& infosOnComp, const std::string& mName, int dt, int it, mcIdType nMin, mcIdType nMax) +{ + LoadPartCoords(fid,infosOnComp,mName,dt,it,nMin,nMax,_coords,_part_coords,_fam_coords,_num_coords,_name_coords); +} + +void MEDFileUMeshL2::loadPartCoordsSlice(med_idt fid, const std::vector& infosOnComp, const std::string& mName, int dt, int it, const DataArrayIdType *nodeIds, mcIdType nbOfCoordLS) +{ + nodeIds->checkAllocated(); + nodeIds->checkNbOfComps(1,"loadPartCoordsSlice : Only one component expected !"); + if(nodeIds->empty()) + return ; + if( nbOfCoordLS<1 ) + throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartCoordsSlice : nb of coords load session must be >=1 !"); + mcIdType nMin(nodeIds->front()),nMax(nodeIds->back()+1); + std::vector< MCAuto > coords(nbOfCoordLS); + std::vector< MCAuto > famCoords(nbOfCoordLS); + std::vector< MCAuto > numCoords(nbOfCoordLS); + std::vector< MCAuto > nameCoords(nbOfCoordLS); + for(mcIdType ipart = 0 ; ipart < nbOfCoordLS ; ++ipart) + { + mcIdType partStart,partStop; + DataArray::GetSlice(nMin,nMax,1,ipart,nbOfCoordLS,partStart,partStop); + MCAuto idsNodeIdsToKeep(nodeIds->findIdsInRange(partStart,partStop)); + MCAuto nodeIdsToKeep( nodeIds->selectByTupleIdSafe(idsNodeIdsToKeep->begin(),idsNodeIdsToKeep->end()) ); + LoadPartCoordsArray(fid,infosOnComp,mName,dt,it,nodeIdsToKeep,coords[ipart],famCoords[ipart],numCoords[ipart],nameCoords[ipart]); + } + _coords = DataArrayDouble::Aggregate(ToConstVect(coords)); + if(famCoords[0].isNotNull()) + _fam_coords = DataArrayIdType::Aggregate(ToConstVect(famCoords)); + if(numCoords[0].isNotNull()) + _num_coords = DataArrayIdType::Aggregate(ToConstVect(numCoords)); + if(nameCoords[0].isNotNull()) + { + std::vector< MCAuto > nameCoords2(nameCoords.begin(),nameCoords.end()); + std::for_each(nameCoords2.begin(),nameCoords2.end(),[](MCAuto& elt){ elt->incrRef(); }); + MCAuto tmp( DataArrayChar::Aggregate(ToConstVect(nameCoords2)) ); + _name_coords = DynamicCastSafe( tmp ); + } + _part_coords = DataArrayPartDefinition::New( const_cast(nodeIds) ); +} + void MEDFileUMeshL2::sortTypes() { std::set mdims; - std::vector< MEDCouplingAutoRefCountObjectPtr > tmp(_per_type_mesh[0]); + std::vector< MCAuto > tmp(_per_type_mesh[0]); _per_type_mesh.clear(); - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=tmp.begin();it!=tmp.end();it++) + for(std::vector< MCAuto >::const_iterator it=tmp.begin();it!=tmp.end();it++) mdims.insert((*it)->getDim()); if(mdims.empty()) return; @@ -426,15 +794,15 @@ void MEDFileUMeshL2::sortTypes() _per_type_mesh.resize(mdim+1); for(int dim=mdim+1;dim!=0;dim--) { - std::vector< MEDCouplingAutoRefCountObjectPtr >& elt=_per_type_mesh[mdim+1-dim]; - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=tmp.begin();it!=tmp.end();it++) + std::vector< MCAuto >& elt=_per_type_mesh[mdim+1-dim]; + for(std::vector< MCAuto >::const_iterator it=tmp.begin();it!=tmp.end();it++) if((*it)->getDim()==dim-1) elt.push_back(*it); } // suppression of contiguous empty levels at the end of _per_type_mesh. int nbOfUselessLev=0; bool isFirst=true; - for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++) + for(std::vector< std::vector< MCAuto > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++) { if((*it2).empty() && isFirst) { @@ -446,15 +814,15 @@ void MEDFileUMeshL2::sortTypes() _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev); } -void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords) +void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayIdType *famCoords, const DataArrayIdType *numCoords, const DataArrayAsciiChar *nameCoords, const DataArrayIdType *globalNumCoords) { if(!coords) return ; - MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getConstPointer())); + MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,ToMedInt(coords->getNumberOfTuples()),coords->begin())); if(famCoords) - MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer())); + MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,ToMedInt(famCoords->getNumberOfTuples()),ToMedIntArray(famCoords)->begin())); if(numCoords) - MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer())); + MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,ToMedInt(numCoords->getNumberOfTuples()),ToMedIntArray(numCoords)->begin())); if(nameCoords) { if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE) @@ -463,13 +831,15 @@ void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer())); + MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,ToMedInt(nameCoords->getNumberOfTuples()),nameCoords->begin())); } + if(globalNumCoords) + MEDFILESAFECALLERWR0(MEDmeshGlobalNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NONE,ToMedInt(globalNumCoords->getNumberOfTuples()),ToMedIntArray(globalNumCoords)->begin())); } bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const { - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) + for(std::vector< MCAuto >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) if((*it)->getFam()==0) return false; return true; @@ -477,7 +847,7 @@ bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const { - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) + for(std::vector< MCAuto >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) if((*it)->getNum()==0) return false; return true; @@ -485,40 +855,42 @@ bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const { - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) + for(std::vector< MCAuto >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) if((*it)->getNames()==0) return false; return true; } -MEDFileCMeshL2::MEDFileCMeshL2() +MEDFileCMeshL2::MEDFileCMeshL2():_ax_type(AX_CART) { } -void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it) +void MEDFileCMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it) { _name.set(mName.c_str()); int nstep; int Mdim; - ParaMEDMEM::MEDCouplingMeshType meshType; - std::vector infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim); + MEDCoupling::MEDCouplingMeshType meshType; + MEDCoupling::MEDCouplingAxisType dummy3; + std::vector infosOnComp(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim)); if(meshType!=CARTESIAN) throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !"); - _time=CheckMeshTimeStep(fid,mName,nstep,dt,it); + _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it); _iteration=dt; _order=it; // med_grid_type gridtype; MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gridtype)); - if(gridtype!=MED_CARTESIAN_GRID) - throw INTERP_KERNEL::Exception("Invalid structured mesh ! Expected cartesian mesh type !"); + if(gridtype!=MED_CARTESIAN_GRID && gridtype!=MED_POLAR_GRID) + throw INTERP_KERNEL::Exception("Invalid rectilinear mesh ! Only cartesian and polar are supported !"); + _ax_type=TraduceAxisTypeStruct(gridtype); _cmesh=MEDCouplingCMesh::New(); for(int i=0;i da=DataArrayDouble::New(); + med_int nbOfElt(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf)); + MCAuto da=DataArrayDouble::New(); da->alloc(nbOfElt,1); da->setInfoOnComponent(0,infosOnComp[i]); MEDFILESAFECALLERRD0(MEDmeshGridIndexCoordinateRd,(fid,mName.c_str(),dt,it,i+1,da->getPointer())); @@ -545,26 +917,29 @@ MEDFileCLMeshL2::MEDFileCLMeshL2() { } -void MEDFileCLMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it) +void MEDFileCLMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it) { _name.set(mName.c_str()); int nstep; int Mdim; - ParaMEDMEM::MEDCouplingMeshType meshType; - std::vector infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim); + MEDCoupling::MEDCouplingMeshType meshType; + MEDCoupling::MEDCouplingAxisType dummy3; + std::vector infosOnComp(getAxisInfoOnMesh(fid,mId,mName,meshType,dummy3,nstep,Mdim)); if(meshType!=CURVE_LINEAR) throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !"); - _time=CheckMeshTimeStep(fid,mName,nstep,dt,it); + _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it); _iteration=dt; _order=it; // _clmesh=MEDCouplingCurveLinearMesh::New(); - INTERP_KERNEL::AutoPtr stGrid=new int[Mdim]; - MEDFILESAFECALLERRD0(MEDmeshGridStructRd,(fid,mName.c_str(),dt,it,stGrid)); - _clmesh->setNodeGridStructure(stGrid,((int *)stGrid)+Mdim); + MCAuto miStGrid=DataArrayMedInt::New(); + miStGrid->alloc(Mdim,1); + MEDFILESAFECALLERRD0(MEDmeshGridStructRd,(fid,mName.c_str(),dt,it,miStGrid->getPointer())); + MCAuto stGrid=FromMedIntArray(miStGrid); + _clmesh->setNodeGridStructure(stGrid->begin(),stGrid->end()); med_bool chgt=MED_FALSE,trsf=MED_FALSE; - int nbNodes(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf)); - MEDCouplingAutoRefCountObjectPtr da=DataArrayDouble::New(); + med_int nbNodes(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf)); + MCAuto da=DataArrayDouble::New(); da->alloc(nbNodes,infosOnComp.size()); da->setInfoOnComponents(infosOnComp); MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,da->getPointer())); @@ -584,8 +959,8 @@ MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const if((MEDCouplingUMesh *)_m==0) { updateTime(); - _m=static_cast(_st->_m_by_types.getUmesh()->deepCpy()); - _m->renumberCells(_st->_num->getConstPointer(),true); + _m=static_cast(_st->_m_by_types.getUmesh()->deepCopy()); + _m->renumberCells(_st->_num->begin(),true); return _m.retn(); } else @@ -595,8 +970,8 @@ MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const else { updateTime(); - _m=static_cast(_st->_m_by_types.getUmesh()->deepCpy()); - _m->renumberCells(_st->_num->getConstPointer(),true); + _m=static_cast(_st->_m_by_types.getUmesh()->deepCopy()); + _m->renumberCells(_st->_num->begin(),true); return _m.retn(); } } @@ -631,18 +1006,18 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other):RefCo MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id):_m(this) { - const std::vector< MEDCouplingAutoRefCountObjectPtr >& v=l2.getLev(id); + const std::vector< MCAuto >& v=l2.getLev(id); if(v.empty()) return; - int sz=v.size(); + std::size_t sz=v.size(); std::vector ms(sz); - std::vector fams(sz),nums(sz); + std::vector fams(sz),nums(sz); std::vector names(sz); std::vector pds(sz); - for(int i=0;igetMesh()); - MEDCouplingAutoRefCountObjectPtr tmp2=l2.getCoords(); + MCAuto tmp2=l2.getCoords(); elt->setCoords(tmp2); ms[i]=elt; pds[i]=v[i]->getPartDef(); @@ -651,32 +1026,32 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::st _m_by_types.assignDefParts(pds); if(l2.isFamDefinedOnLev(id)) { - for(int i=0;igetFam(); if(sz!=1) - _fam=DataArrayInt::Aggregate(fams); + _fam=DataArrayIdType::Aggregate(fams); else { fams[0]->incrRef(); - _fam=const_cast(fams[0]); + _fam=const_cast(fams[0]); } } if(l2.isNumDefinedOnLev(id)) { - for(int i=0;igetNum(); if(sz!=1) - _num=DataArrayInt::Aggregate(nums); + _num=DataArrayIdType::Aggregate(nums); else { nums[0]->incrRef(); - _num=const_cast(nums[0]); + _num=const_cast(nums[0]); } computeRevNum(); } if(l2.isNamesDefinedOnLev(id)) { - for(int i=0;igetNames(); _names=dynamic_cast(DataArrayChar::Aggregate(names)); } @@ -714,34 +1089,65 @@ std::vector MEDFileUMeshSplitL1::getDirectChildrenWithN std::vector ret; ret.push_back(&_m_by_types); ret.push_back(&_m); - ret.push_back((const DataArrayInt*)_fam); - ret.push_back((const DataArrayInt*)_num); - ret.push_back((const DataArrayInt*)_rev_num); + ret.push_back((const DataArrayIdType*)_fam); + ret.push_back((const DataArrayIdType*)_num); + ret.push_back((const DataArrayIdType*)_rev_num); ret.push_back((const DataArrayAsciiChar*)_names); return ret; } -MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy(DataArrayDouble *coords) const +MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::shallowCpyUsingCoords(DataArrayDouble *coords) const +{ + MCAuto ret(new MEDFileUMeshSplitL1(*this)); + ret->_m_by_types.shallowCpyMeshes(); + ret->_m_by_types.setCoords(coords); + return ret.retn(); +} + +MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCopy(DataArrayDouble *coords) const { - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileUMeshSplitL1(*this); - ret->_m_by_types=_m_by_types.deepCpy(coords); - if((const DataArrayInt *)_fam) - ret->_fam=_fam->deepCpy(); - if((const DataArrayInt *)_num) - ret->_num=_num->deepCpy(); - if((const DataArrayInt *)_rev_num) - ret->_rev_num=_rev_num->deepCpy(); + MCAuto ret(new MEDFileUMeshSplitL1(*this)); + ret->_m_by_types=_m_by_types.deepCopy(coords); + if((const DataArrayIdType *)_fam) + ret->_fam=_fam->deepCopy(); + if((const DataArrayIdType *)_num) + ret->_num=_num->deepCopy(); + if((const DataArrayIdType *)_rev_num) + ret->_rev_num=_rev_num->deepCopy(); if((const DataArrayAsciiChar *)_names) - ret->_names=_names->deepCpy(); + ret->_names=_names->deepCopy(); return ret.retn(); } +void MEDFileUMeshSplitL1::checkConsistency() const +{ + if (!_fam || _fam->getNumberOfTuples() != getSize()) + throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): internal family array has an invalid size!"); + mcIdType nbCells = getSize(); + if (_num) + { + _num->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array!"); + mcIdType pos; + mcIdType maxValue=_num->getMaxValue(pos); + if (!_rev_num || _rev_num->getNumberOfTuples() != (maxValue+1)) + throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal revert node numbering array!"); + } + if ((_num && !_rev_num) || (!_num && _rev_num)) + throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal numbering arrays (one is null)!"); + if (_num && !_num->hasUniqueValues()) + throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array: duplicates found!"); + if (_names) + _names->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): internal cell naming array has an invalid size!"); + + _m_by_types.checkConsistency(); +} + bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const { if(!_m_by_types.isEqual(other->_m_by_types,eps,what)) return false; - const DataArrayInt *d1=_fam; - const DataArrayInt *d2=other->_fam; + const DataArrayIdType *d1=_fam; + const DataArrayIdType *d2=other->_fam; if((d1==0 && d2!=0) || (d1!=0 && d2==0)) { what="Presence of family arr in one sublevel and not in other!"; @@ -813,20 +1219,20 @@ void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) { m->incrRef(); _m=m; - _m_by_types.assignUMesh(dynamic_cast(m->deepCpy())); - MEDCouplingAutoRefCountObjectPtr da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO); - if(!da->isIdentity()) + _m_by_types.assignUMesh(dynamic_cast(m->deepCopy())); + MCAuto da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO); + if(!da->isIota(m->getNumberOfCells())) { _num=da->invertArrayO2N2N2O(m->getNumberOfCells()); _m.updateTime(); computeRevNum(); - _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false); + _m_by_types.getUmesh()->renumberCells(da->begin(),false); } } else { if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO)) - throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh : the mode of mesh setting expects to follow the MED file numbering convention ! it is not the case !"); + throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh(): the mesh does not follow the MED file numbering convention! Invoke sortCellsInMEDFileFrmt() first!"); m->incrRef(); _m_by_types.assignUMesh(m); } @@ -850,7 +1256,7 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1():_m(this) void MEDFileUMeshSplitL1::assignCommonPart() { - _fam=DataArrayInt::New(); + _fam=DataArrayIdType::New(); _fam->alloc(_m_by_types.getSize(),1); _fam->fillWithValue(0); } @@ -860,9 +1266,9 @@ bool MEDFileUMeshSplitL1::empty() const return _m_by_types.empty(); } -bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector& ids) const +bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector& ids) const { - const DataArrayInt *fam=_fam; + const DataArrayIdType *fam=_fam; if(!fam) return false; return fam->presenceOfValue(ids); @@ -875,32 +1281,32 @@ int MEDFileUMeshSplitL1::getMeshDimension() const void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const { - std::vector code=_m_by_types.getDistributionOfTypes(); - int nbOfTypes=code.size()/3; - for(int i=0;i code=_m_by_types.getDistributionOfTypes(); + std::size_t nbOfTypes=code.size()/3; + for(std::size_t i=0;i eltsToKeep=_fam->getIdsEqualList(idsBg,idsEnd); - MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true); + MCAuto eltsToKeep=_fam->findIdsEqualList(idsBg,idsEnd); + MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->begin(),eltsToKeep->end(),true); if(renum) - return renumIfNeeded(m,eltsToKeep->getConstPointer()); + return renumIfNeeded(m,eltsToKeep->begin()); return m; } -DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const +DataArrayIdType *MEDFileUMeshSplitL1::getFamilyPartArr(const mcIdType *idsBg, const mcIdType *idsEnd, bool renum) const { - MEDCouplingAutoRefCountObjectPtr da=_fam->getIdsEqualList(idsBg,idsEnd); + MCAuto da=_fam->findIdsEqualList(idsBg,idsEnd); if(renum) return renumIfNeededArr(da); return da.retn(); @@ -911,61 +1317,66 @@ std::vector MEDFileUMeshSplitL1::getGeoTypes( return _m_by_types.getGeoTypes(); } +mcIdType MEDFileUMeshSplitL1::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const +{ + return _m_by_types.getNumberOfCellsWithType(ct); +} + MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const { - MEDCouplingAutoRefCountObjectPtr tmp; - if(renum && ((const DataArrayInt *)_num)) + MCAuto tmp; + if(renum && ((const DataArrayIdType *)_num)) tmp=_m; else { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); } return tmp.retn(); } -int MEDFileUMeshSplitL1::getNumberOfCells() const +mcIdType MEDFileUMeshSplitL1::getNumberOfCells() const { return _m_by_types.getNumberOfCells(); } -DataArrayInt *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const +DataArrayIdType *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const { - const DataArrayInt *fam(_fam); + const DataArrayIdType *fam(_fam); if(!fam) return 0; - int start(0),stop(0); + mcIdType start(0),stop(0); _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop); - return fam->selectByTupleId2(start,stop,1); + return fam->selectByTupleIdSafeSlice(start,stop,1); } -DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const +DataArrayIdType *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const { - const DataArrayInt *num(_num); + const DataArrayIdType *num(_num); if(!num) return 0; - int start(0),stop(0); + mcIdType start(0),stop(0); _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop); - return num->selectByTupleId2(start,stop,1); + return num->selectByTupleIdSafeSlice(start,stop,1); } -DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField() +DataArrayIdType *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField() { - if((DataArrayInt *)_fam) + if((DataArrayIdType *)_fam) return _fam; - int nbOfTuples=_m_by_types.getSize(); - _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero(); + mcIdType nbOfTuples=_m_by_types.getSize(); + _fam=DataArrayIdType::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero(); return _fam; } -const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const +const DataArrayIdType *MEDFileUMeshSplitL1::getFamilyField() const { return _fam; } -const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const +const DataArrayIdType *MEDFileUMeshSplitL1::getNumberField() const { return _num; } -const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const +const DataArrayIdType *MEDFileUMeshSplitL1::getRevNumberField() const { return _rev_num; } @@ -988,90 +1399,90 @@ void MEDFileUMeshSplitL1::eraseFamilyField() /*! * This method ignores _m and _m_by_types. */ -void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector& ms, std::map& familyIds, +void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector& ms, std::map& familyIds, std::map >& groups) { - std::vector< DataArrayInt * > corr; + std::vector< DataArrayIdType * > corr; _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr); - std::vector< MEDCouplingAutoRefCountObjectPtr > corrMSafe(corr.begin(),corr.end()); - std::vector< std::vector > fidsOfGroups; - std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end()); - _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups); - int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells(); - std::map newfams; - std::map famIdTrad; + std::vector< MCAuto > corrMSafe(corr.begin(),corr.end()); + std::vector< std::vector > fidsOfGroups; + std::vector< const DataArrayIdType * > corr2(corr.begin(),corr.end()); + _fam=DataArrayIdType::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups); + mcIdType nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells(); + std::map newfams; + std::map famIdTrad; TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams); - int *w=_fam->getPointer(); - for(int i=0;igetPointer(); + for(mcIdType i=0;i ms(_m_by_types.getParts()); - int start=0; + mcIdType start=0; for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++) { - int nbCells=(*it)->getNumberOfCells(); - int end=start+nbCells; - MEDCouplingAutoRefCountObjectPtr fam,num; - MEDCouplingAutoRefCountObjectPtr names; - if((const DataArrayInt *)_fam) - fam=_fam->substr(start,end); - if((const DataArrayInt *)_num) - num=_num->substr(start,end); + mcIdType nbCells=(*it)->getNumberOfCells(); + mcIdType end=start+nbCells; + MCAuto fam,num; + MCAuto names; + if((const DataArrayIdType *)_fam) + fam=_fam->subArray(start,end); + if((const DataArrayIdType *)_num) + num=_num->subArray(start,end); if((const DataArrayAsciiChar *)_names) - names=static_cast(_names->substr(start,end)); + names=static_cast(_names->subArray(start,end)); MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names); start=end; } } -void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N) +void MEDFileUMeshSplitL1::renumberNodesInConn(const mcIdType *newNodeNumbersO2N) { _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N); } -void MEDFileUMeshSplitL1::serialize(std::vector& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr >& bigArraysI) const +void MEDFileUMeshSplitL1::serialize(std::vector& tinyInt, std::vector< MCAuto >& bigArraysI) const { bigArraysI.push_back(_fam); bigArraysI.push_back(_num); _m_by_types.serialize(tinyInt,bigArraysI); } -void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr >& bigArraysI) +void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector& tinyInt, std::vector< MCAuto >& bigArraysI) { _fam=bigArraysI.back(); bigArraysI.pop_back(); _num=bigArraysI.back(); bigArraysI.pop_back(); _m_by_types.unserialize(name,coo,tinyInt,bigArraysI); } -void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId) +void MEDFileUMeshSplitL1::changeFamilyIdArr(mcIdType oldId, mcIdType newId) { - DataArrayInt *arr=_fam; + DataArrayIdType *arr=_fam; if(arr) arr->changeValue(oldId,newId); } -void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr) +void MEDFileUMeshSplitL1::setFamilyArr(DataArrayIdType *famArr) { if(!famArr) { _fam=0; return ; } - int sz(_m_by_types.getSize()); + mcIdType sz(_m_by_types.getSize()); famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! "); famArr->incrRef(); _fam=famArr; } -DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() +DataArrayIdType *MEDFileUMeshSplitL1::getFamilyField() { return _fam; } -void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr) +void MEDFileUMeshSplitL1::setRenumArr(DataArrayIdType *renumArr) { if(!renumArr) { @@ -1079,7 +1490,7 @@ void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr) _rev_num=0; return ; } - int sz(_m_by_types.getSize()); + mcIdType sz(_m_by_types.getSize()); renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! "); renumArr->incrRef(); _num=renumArr; @@ -1093,78 +1504,87 @@ void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr) _names=0; return ; } - int sz(_m_by_types.getSize()); + mcIdType sz(_m_by_types.getSize()); nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! "); nameArr->incrRef(); _names=nameArr; } -MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds) +MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayIdType *renum, MEDCouplingUMesh *m, const mcIdType *cellIds) { if(renum==0) return m; if(cellIds==0) - m->renumberCells(renum->getConstPointer(),true); + m->renumberCells(renum->begin(),true); else { - MEDCouplingAutoRefCountObjectPtr locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells()); - m->renumberCells(locnum->getConstPointer(),true); + MCAuto locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells()); + m->renumberCells(locnum->begin(),true); } return m; } -MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr >& bigArraysI) +MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector& tinyInt, std::vector< MCAuto >& bigArraysI) { - MEDCouplingAutoRefCountObjectPtr ret(new MEDFileUMeshSplitL1); + MCAuto ret(new MEDFileUMeshSplitL1); ret->unserialize(name,coo,tinyInt,bigArraysI); return ret.retn(); } -MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const +MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const mcIdType *cellIds) const { return Renumber2(_num,m,cellIds); } -DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da) +DataArrayIdType *MEDFileUMeshSplitL1::Renumber(const DataArrayIdType *renum, const DataArrayIdType *da) { - if((const DataArrayInt *)renum==0) + if((const DataArrayIdType *)renum==0) { da->incrRef(); - return const_cast(da); + return const_cast(da); } - return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples()); + return renum->selectByTupleId(da->begin(),da->end()); } -DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const +DataArrayIdType *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayIdType *da) const { return Renumber(_num,da); } -std::vector MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map& families) +std::vector MEDFileUMeshSplitL1::GetNewFamiliesNumber(mcIdType nb, const std::map& families) { - int id=-1; - for(std::map::const_iterator it=families.begin();it!=families.end();it++) + mcIdType id=-1; + for(std::map::const_iterator it=families.begin();it!=families.end();it++) id=std::max(id,(*it).second); if(id==-1) id=0; - std::vector ret(nb); - for(int i=1;i<=nb;i++) + std::vector ret(nb); + for(mcIdType i=1;i<=nb;i++) ret[i]=id+i; return ret; } -void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, - std::map& famIdTrad, std::map& newfams) +void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, + std::map& famIdTrad, std::map& newfams) { - std::set allfids; + std::set allfids; //tony } void MEDFileUMeshSplitL1::computeRevNum() const { - int pos; - int maxValue=_num->getMaxValue(pos); - _rev_num=_num->invertArrayN2O2O2N(maxValue+1); + mcIdType pos; + if(!_num->empty()) + { + mcIdType maxValue=_num->getMaxValue(pos); + _rev_num=_num->invertArrayN2O2O2N(maxValue+1); + } + else + { + _rev_num = DataArrayIdType::New(); + _rev_num->alloc(0,1); + } + } //= @@ -1183,7 +1603,7 @@ void MEDFileUMeshAggregateCompute::setName(const std::string& name) } if(_mp_time>=_m_time) { - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) + for(std::vector< MCAuto >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) { MEDCoupling1GTUMesh *tmp(*it); if(tmp) @@ -1195,7 +1615,7 @@ void MEDFileUMeshAggregateCompute::setName(const std::string& name) void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts) { std::size_t sz(mParts.size()); - std::vector< MEDCouplingAutoRefCountObjectPtr > ret(sz); + std::vector< MCAuto > ret(sz); for(std::size_t i=0;igetNumberOfCells(); - int ret(0); - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + mcIdType ret(0); + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) ret+=(*it)->getNumberOfCells(); return ret; } @@ -1268,6 +1688,22 @@ std::vector MEDFileUMeshAggregateCompute::get return _m->getAllGeoTypesSorted(); } +mcIdType MEDFileUMeshAggregateCompute::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const +{ + if(_mp_time>=_m_time) + { + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + { + const MEDCoupling1GTUMesh *elt(*it); + if(elt && elt->getCellModelEnum()==ct) + return elt->getNumberOfCells(); + } + return 0; + } + else + return _m->getNumberOfCellsWithType(ct); +} + std::vector MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const { if(_mp_time<_m_time) @@ -1275,7 +1711,7 @@ std::vector MEDFileUMeshAggregateCompute::retrievePartsWi // std::vector ret(_m_parts.size()); std::size_t i(0); - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++) + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++) { const MEDCoupling1GTUMesh *elt(*it); ret[i]=const_cast(elt); @@ -1290,6 +1726,16 @@ std::vector MEDFileUMeshAggregateCompute::getParts() cons return retrievePartsWithoutComputation(); } +void MEDFileUMeshAggregateCompute::highlightUsedNodes(std::vector& nodesToBeHighlighted) const +{ + if(_mp_time<_m_time) + forceComputationOfPartsFromUMesh(); + for(auto part : this->_m_parts) + { + part->computeNodeIdsAlg(nodesToBeHighlighted); + } +} + MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const { std::vector v(retrievePartsWithoutComputation()); @@ -1303,7 +1749,7 @@ MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputatio throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !"); } -void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const +void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, mcIdType& start, mcIdType& stop) const { start=0; stop=0; std::vector v(retrievePartsWithoutComputation()); @@ -1324,11 +1770,11 @@ void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTER throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !"); } -void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N) +void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const mcIdType *newNodeNumbersO2N) { if(_mp_time>_m_time) { - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) + for(std::vector< MCAuto >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) { MEDCoupling1GTUMesh *m(*it); if(m) @@ -1341,6 +1787,9 @@ void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const i if(!m) return; m->renumberNodesInConn(newNodeNumbersO2N); + // if _mp_time == _m_time notify for future clients that _m_parts is obsolete + _m_parts.clear(); + _m_time = std::max(_m_time,_mp_time+1); } } @@ -1348,9 +1797,14 @@ void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const { const MEDCouplingUMesh *m(_m); if(!m) - throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !"); + { + if(_m_parts.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !"); + else + return ;// no needs to compte parts they are already here ! + } std::vector ms(m->splitByType()); - std::vector< MEDCouplingAutoRefCountObjectPtr > msMSafe(ms.begin(),ms.end()); + std::vector< MCAuto > msMSafe(ms.begin(),ms.end()); std::size_t sz(msMSafe.size()); _m_parts.resize(sz); for(std::size_t i=0;i& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr >& bigArraysI) const +void MEDFileUMeshAggregateCompute::serialize(std::vector& tinyInt, std::vector< MCAuto >& bigArraysI) const { if(_mp_time<_m_time) throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !"); std::size_t sz(_m_parts.size()); - tinyInt.push_back((int)sz); + tinyInt.push_back((mcIdType)sz); for(std::size_t i=0;i& tinyInt, std::vec const MEDCoupling1DGTUMesh *mesh2(dynamic_cast(mesh)); if(mesh1) { - DataArrayInt *elt(mesh1->getNodalConnectivity()); + DataArrayIdType *elt(mesh1->getNodalConnectivity()); if(elt) elt->incrRef(); - MEDCouplingAutoRefCountObjectPtr elt1(elt); + MCAuto elt1(elt); bigArraysI.push_back(elt1); } else if(mesh2) { - DataArrayInt *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex()); + DataArrayIdType *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex()); if(elt1) elt1->incrRef(); if(elt2) elt2->incrRef(); - MEDCouplingAutoRefCountObjectPtr elt11(elt1),elt22(elt2); + MCAuto elt11(elt1),elt22(elt2); bigArraysI.push_back(elt11); bigArraysI.push_back(elt22); } else @@ -1416,23 +1870,23 @@ void MEDFileUMeshAggregateCompute::serialize(std::vector& tinyInt, std::vec tinyInt.push_back(-1); else { - std::vector tinyTmp; + std::vector tinyTmp; pd->serialize(tinyTmp,bigArraysI); - tinyInt.push_back((int)tinyTmp.size()); + tinyInt.push_back((mcIdType)tinyTmp.size()); tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end()); } } } -void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr >& bigArraysI) +void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector& tinyInt, std::vector< MCAuto >& bigArraysI) { - int nbParts(tinyInt.back()); tinyInt.pop_back(); + mcIdType nbParts(tinyInt.back()); tinyInt.pop_back(); _part_def.clear(); _part_def.resize(nbParts); _m_parts.clear(); _m_parts.resize(nbParts); - for(int i=0;i mesh(MEDCoupling1GTUMesh::New(name,tp)); + MCAuto mesh(MEDCoupling1GTUMesh::New(name,tp)); mesh->setCoords(coo); MEDCoupling1SGTUMesh *mesh1(dynamic_cast((MEDCoupling1GTUMesh *) mesh)); MEDCoupling1DGTUMesh *mesh2(dynamic_cast((MEDCoupling1GTUMesh *) mesh)); @@ -1442,7 +1896,7 @@ void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArra } else if(mesh2) { - MEDCouplingAutoRefCountObjectPtr elt0,elt1; + MCAuto elt0,elt1; elt0=bigArraysI.back(); bigArraysI.pop_back(); elt1=bigArraysI.back(); bigArraysI.pop_back(); mesh2->setNodalConnectivity(elt0,elt1); @@ -1450,7 +1904,7 @@ void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArra else throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !"); _m_parts[i]=mesh; - int pdid(tinyInt.back()); tinyInt.pop_back(); + mcIdType pdid(tinyInt.back()); tinyInt.pop_back(); if(pdid!=-1) _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI); _mp_time=std::max(_mp_time,_m_time)+1; @@ -1477,7 +1931,7 @@ std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const { std::size_t ret(0); - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) { const MEDCoupling1GTUMesh *elt(*it); if(!elt) @@ -1499,20 +1953,20 @@ std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const { - std::size_t ret(_m_parts.size()*sizeof(MEDCouplingAutoRefCountObjectPtr)); + std::size_t ret(_m_parts.size()*sizeof(MCAuto)); return ret; } std::vector MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const { std::vector ret; - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) ret.push_back((const MEDCoupling1GTUMesh *)*it); ret.push_back((const MEDCouplingUMesh *)_m); return ret; } -MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDouble *coords) const +MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCopy(DataArrayDouble *coords) const { MEDFileUMeshAggregateCompute ret; ret._m_parts.resize(_m_parts.size()); @@ -1521,14 +1975,14 @@ MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDoub const MEDCoupling1GTUMesh *elt(_m_parts[i]); if(elt) { - ret._m_parts[i]=static_cast(elt->deepCpy()); + ret._m_parts[i]=static_cast(elt->deepCopy()); ret._m_parts[i]->setCoords(coords); } } ret._mp_time=_mp_time; ret._m_time=_m_time; if((const MEDCouplingUMesh *)_m) { - ret._m=static_cast(_m->deepCpy()); + ret._m=static_cast(_m->deepCopy()); ret._m->setCoords(coords); } std::size_t sz(_part_def.size()); @@ -1537,11 +1991,27 @@ MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDoub { const PartDefinition *elt(_part_def[i]); if(elt) - ret._part_def[i]=elt->deepCpy(); + ret._part_def[i]=elt->deepCopy(); } return ret; } +void MEDFileUMeshAggregateCompute::shallowCpyMeshes() +{ + for(std::vector< MCAuto >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) + { + const MEDCoupling1GTUMesh *elt(*it); + if(elt) + { + MCAuto elt2(elt->clone(false)); + *it=DynamicCastSafe(elt2); + } + } + const MEDCouplingUMesh *m(_m); + if(m) + _m=m->clone(false); +} + bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const { const MEDCouplingUMesh *m1(getUmesh()); @@ -1583,16 +2053,26 @@ bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& o return true; } +void MEDFileUMeshAggregateCompute::checkConsistency() const +{ + if(_mp_time >= _m_time) + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin(); + it!=_m_parts.end(); it++) + (*it)->checkConsistency(); + else + _m->checkConsistency(); +} + void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const { - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it); MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m); } void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const { - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) { const MEDCoupling1GTUMesh *tmp(*it); if(tmp) @@ -1641,7 +2121,7 @@ int MEDFileUMeshAggregateCompute::getMeshDimension() const } } -std::vector MEDFileUMeshAggregateCompute::getDistributionOfTypes() const +std::vector MEDFileUMeshAggregateCompute::getDistributionOfTypes() const { if(_mp_time<_m_time) { @@ -1652,20 +2132,20 @@ std::vector MEDFileUMeshAggregateCompute::getDistributionOfTypes() const } else { - std::vector ret; - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + std::vector ret; + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) { const MEDCoupling1GTUMesh *tmp(*it); if(!tmp) throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !"); - std::vector ret0(tmp->getDistributionOfTypes()); + std::vector ret0(tmp->getDistributionOfTypes()); ret.insert(ret.end(),ret0.begin(),ret0.end()); } return ret; } } -int MEDFileUMeshAggregateCompute::getSize() const +mcIdType MEDFileUMeshAggregateCompute::getSize() const { if(_mp_time<_m_time) { @@ -1676,8 +2156,8 @@ int MEDFileUMeshAggregateCompute::getSize() const } else { - int ret=0; - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + mcIdType ret=0; + for(std::vector< MCAuto >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) { const MEDCoupling1GTUMesh *m(*it); if(!m) @@ -1690,7 +2170,7 @@ int MEDFileUMeshAggregateCompute::getSize() const void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords) { - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) + for(std::vector< MCAuto >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) { MEDCoupling1GTUMesh *tmp(*it); if(tmp) @@ -1700,3 +2180,60 @@ void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords) if(m) m->setCoords(coords); } + +MEDFileEltStruct4Mesh *MEDFileEltStruct4Mesh::New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs) +{ + return new MEDFileEltStruct4Mesh(fid,mName,dt,it,iterOnStEltOfMesh,mrs); +} + +std::size_t MEDFileEltStruct4Mesh::getHeapMemorySizeWithoutChildren() const +{ + return _geo_type_name.capacity()+_vars.capacity()*sizeof(MCAuto); +} + +std::vector MEDFileEltStruct4Mesh::getDirectChildrenWithNull() const +{ + std::vector ret; + ret.push_back(_conn); + ret.push_back(_common); + for(std::vector< MCAuto >::const_iterator it=_vars.begin();it!=_vars.end();it++) + ret.push_back(*it); + return ret; +} + +MEDFileEltStruct4Mesh::MEDFileEltStruct4Mesh(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs) +{ + med_geometry_type geoType; + INTERP_KERNEL::AutoPtr geoTypeName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + MEDFILESAFECALLERRD0(MEDmeshEntityInfo,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,iterOnStEltOfMesh+1,geoTypeName,&geoType)); + _geo_type=geoType; + _geo_type_name=MEDLoaderBase::buildStringFromFortran(geoTypeName,MED_NAME_SIZE); + mcIdType nCells(0); + { + med_bool chgt=MED_FALSE,trsf=MED_FALSE; + nCells=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,geoType,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf); + } + MCAuto mss(MEDFileMeshSupports::New(fid)); + MCAuto mse(MEDFileStructureElements::New(fid,mss)); + mcIdType nbEntities(mse->getNumberOfNodesPerSE(_geo_type_name)); + MCAuto miConn=DataArrayMedInt::New(); miConn->alloc(nCells*nbEntities); + MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,_geo_type,MED_NODAL,MED_FULL_INTERLACE,miConn->getPointer())); + _conn=FromMedIntArray(miConn); + _conn->applyLin(1,-1); + _conn->rearrange(nbEntities); + _common=MEDFileUMeshPerTypeCommon::New(); + _common->loadCommonPart(fid,mName.c_str(),dt,it,nCells,geoType,MED_STRUCT_ELEMENT,mrs); + std::vector vns(mse->getVarAttsOf(_geo_type_name)); + std::size_t sz(vns.size()); + _vars.resize(sz); + for(std::size_t i=0;igetVarAttOf(_geo_type_name,vns[i])); + MCAuto gen(var->getGenerator()); + MCAuto arr(gen->buildNewEmptyInstance()); + 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; + } +}