X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDLoader.cxx;h=687d0bcbf35a6d6c4b3b25c6b29c96bf83af4a3b;hb=f2ab61e92f55ee52cf5196f7904f625d93c8c2d0;hp=8b1ffc7c63e135d9d86c4c8430190cd36070d1ce;hpb=4e3de127a60f9ffb63abae1d17ed01f3f6711fd2;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 8b1ffc7c6..687d0bcbf 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2019 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 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 @@ -30,7 +30,7 @@ #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldFloat.hxx" -#include "MEDCouplingFieldInt.hxx" +#include "MEDCouplingFieldInt32.hxx" #include "MEDCouplingGaussLocalization.hxx" #include "MEDCouplingTraits.hxx" #include "MCAuto.hxx" @@ -47,7 +47,7 @@ #include #include #include - +#include med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1, MED_SEG2, @@ -101,7 +101,7 @@ INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNE INTERP_KERNEL::NORM_QPOLYG, INTERP_KERNEL::NORM_POLYHED }; -med_geometry_type typmai3[34] = { MED_POINT1,//0 +med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE] = { MED_POINT1,//0 MED_SEG2,//1 MED_SEG3,//2 MED_TRIA3,//3 @@ -133,8 +133,7 @@ med_geometry_type typmai3[34] = { MED_POINT1,//0 MED_NONE,//29 MED_HEXA20,//30 MED_POLYHEDRON,//31 - MED_POLYGON2,//32 - MED_NONE//33 + MED_POLYGON2//32 }; double _EPS_FOR_NODE_COMP=1.e-12; @@ -147,6 +146,20 @@ using namespace MEDCoupling; /// @cond INTERNAL +INTERP_KERNEL::NormalizedCellType ConvertGeometryType(med_geometry_type geotype) +{ + INTERP_KERNEL::NormalizedCellType result=INTERP_KERNEL::NORM_ERROR; + for(int i=0; i(getIdFromMeshName(fid,meshName,trueMeshName)); INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); med_sorting_type sortingType; med_int nstep; med_axis_type axisType; - int naxis(MEDmeshnAxis(fid,meshId)); + med_int naxis(MEDmeshnAxis(fid,meshId)); INTERP_KERNEL::AutoPtr axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); INTERP_KERNEL::AutoPtr axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit)); @@ -185,9 +198,9 @@ int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::st { med_geometry_type curMedType=typmai[i]; med_bool changement,transformation; - int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); - int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation - int curNbOfElem; + med_int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); + med_int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation + med_int curNbOfElem; med_entity_type whichEntity; MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity); if(curNbOfElem>0) @@ -208,8 +221,8 @@ int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::st return ret; } -med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName) - { +int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName) +{ if(meshName.empty()) { std::vector meshes=getMeshNamesFid(fid); @@ -231,8 +244,8 @@ med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, throw INTERP_KERNEL::Exception(os2.str().c_str()); } trueMeshName=meshName; - return iter-meshes.begin()+1; - } + return (int)( iter-meshes.begin()+1 ); +} std::vector MEDLoaderNS::getMeshNamesFid(med_idt fid) { @@ -248,10 +261,10 @@ std::vector MEDLoaderNS::getMeshNamesFid(med_idt fid) std::vector ret(n); for(int i=0;i axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); INTERP_KERNEL::AutoPtr axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); - int nstep; + med_int nstep; MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit)); std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)); ret[i]=cur; @@ -262,7 +275,7 @@ std::vector MEDLoaderNS::getMeshNamesFid(med_idt fid) /*! * This methods allows to merger all entities and to considerate only cell types. */ -void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity) +void MEDLoaderNS::dispatchElems(med_int nbOfElemCell, med_int nbOfElemFace, med_int& nbOfElem, med_entity_type& whichEntity) { if(nbOfElemCell>=nbOfElemFace) { @@ -340,9 +353,9 @@ void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release) med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell)); if(ret!=0) throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !"); - major=majj; - minor=minn; - release=rell; + major=FromMedInt(majj); + minor=FromMedInt(minn); + release=FromMedInt(rell); } /*! @@ -378,7 +391,7 @@ void MEDCoupling::SetTooLongStrPolicy(int val) * - the space dimension * - the number of nodes */ -std::vector< std::vector< std::pair > > MEDCoupling::GetUMeshGlobalInfo(const std::string& fileName, const std::string& meshName, int &meshDim, int& spaceDim, int& numberOfNodes) +std::vector< std::vector< std::pair > > MEDCoupling::GetUMeshGlobalInfo(const std::string& fileName, const std::string& meshName, int &meshDim, int& spaceDim, mcIdType& numberOfNodes) { MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName)); std::set poss; @@ -386,15 +399,17 @@ std::vector< std::vector< std::pair > > M char maillage_description[MED_COMMENT_SIZE+1]; med_mesh_type type_maillage; std::string trueMeshName; - med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName); + int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName); INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); med_sorting_type sortingType; - med_int nstep; + med_int nstep, mDim, sDim; med_axis_type axisType; - int naxis(MEDmeshnAxis(fid,meshId)); + med_int naxis(MEDmeshnAxis(fid,meshId)); INTERP_KERNEL::AutoPtr axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); INTERP_KERNEL::AutoPtr axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); - MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit)); + MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&sDim,&mDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit)); + meshDim=FromMedInt(mDim); + spaceDim=FromMedInt(sDim); if(type_maillage!=MED_UNSTRUCTURED_MESH) { std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName; @@ -414,7 +429,7 @@ std::vector< std::vector< std::pair > > M for(int i=0;i0) { INTERP_KERNEL::NormalizedCellType typp=typmai2[i]; @@ -431,7 +446,7 @@ std::vector< std::vector< std::pair > > M { ret[maxLev-dims[i]].push_back(geoTypes[i]); } - numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation); + numberOfNodes=ToIdType(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation)); return ret; } @@ -481,6 +496,37 @@ std::vector< std::pair > MEDCoupling::GetComponentsName throw INTERP_KERNEL::Exception(oss.str().c_str()); } +// see reference : https://en.cppreference.com/w/cpp/iterator/iterator +class MEDVectorStringIterator : public std::iterator< std::input_iterator_tag, long, long, const std::string*, std::string > +{ + long _num = 0; + char *_data = nullptr; +public: + explicit MEDVectorStringIterator(long num , char *data) : _num(num),_data(data) {} + MEDVectorStringIterator& operator++() { ++_num; return *this;} + bool operator==(const MEDVectorStringIterator& other) const {return _num == other._num;} + bool operator!=(const MEDVectorStringIterator& other) const {return !(*this == other);} + reference operator*() const {return MEDLoaderBase::buildStringFromFortran(_data+_num*MED_LNAME_SIZE,MED_LNAME_SIZE);} +}; + +void MEDCoupling::GetFamiliesGroupsInfo(const std::string& fileName, const std::string& meshName, std::map& families, std::map>& groupsOnFam) +{ + MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName)); + med_int nbFams(MEDnFamily(fid,meshName.c_str())); + char nomfam[MED_NAME_SIZE+1]; + for(med_int i=0;i gro{new char[MED_LNAME_SIZE*nbGrps+1]}; + MEDFILESAFECALLERRD0(MEDfamilyInfo,(fid,meshName.c_str(),i+1,nomfam,&famId,gro.get())); + std::string fam(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE)); + families[fam] = FromMedInt(famId); + std::vector v(nbGrps); + std::copy(MEDVectorStringIterator(0,gro.get()),MEDVectorStringIterator(nbGrps,gro.get()),v.begin()); + groupsOnFam[fam] = v; + } +} + std::vector MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName) { std::vector ret; @@ -518,7 +564,7 @@ std::vector MEDCoupling::GetMeshFamiliesNames(const std::string& fi med_int numfam; for(int i=0;i attide=new med_int[natt]; INTERP_KERNEL::AutoPtr attval=new med_int[natt]; @@ -541,7 +587,7 @@ std::vector MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::str med_int numfam; for(int i=0;i attide=new med_int[natt]; INTERP_KERNEL::AutoPtr attval=new med_int[natt]; @@ -569,7 +615,7 @@ std::vector MEDCoupling::GetMeshGroupsNamesOnFamily(const std::stri bool found=false; for(int i=0;i attide=new med_int[natt]; INTERP_KERNEL::AutoPtr attval=new med_int[natt]; @@ -604,7 +650,7 @@ std::vector MEDCoupling::GetMeshGroupsNames(const std::string& file med_int numfam; for(int i=0;i attide=new med_int[natt]; INTERP_KERNEL::AutoPtr attval=new med_int[natt]; @@ -746,7 +792,7 @@ std::vector MEDCoupling::GetCellFieldNamesOnMesh(const std::string& MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt)); std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1); std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1); - int profilesize,nbi; + med_int profilesize,nbi; if(curMeshName==meshName) { bool found=false; @@ -796,7 +842,7 @@ std::vector MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1); if(nbPdt>0) { - int profilesize,nbi; + med_int profilesize,nbi; MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt)); med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE, pflname,&profilesize,locname,&nbi)); @@ -946,7 +992,7 @@ std::vector< std::pair > MEDCoupling::GetCellFieldIterations(const std: { for(int k=0;k > MEDCoupling::GetNodeFieldIterations(const std: { for(int k=0;k MEDCoupling::ReadField(const std::string& } } { - MCAuto f1(MEDCoupling::DynamicCast(f)); + MCAuto f1(MEDCoupling::DynamicCast(f)); if(f1.isNotNull()) { - MCAuto ret(f1->field(mesh)); - return MEDCoupling::DynamicCast(ret); + MCAuto ret(f1->field(mesh)); + return MEDCoupling::DynamicCast(ret); } } { @@ -1270,7 +1316,7 @@ std::vector MEDCoupling::ReadFieldsOnSame if(!mmuPtr) throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !"); MCAuto m=mmuPtr->getMeshAtLevel(meshDimRelToMax); - const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax); + const DataArrayIdType *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax); MCAuto m2(m->clone(true)); if(o2n) m2->renumberCells(o2n->begin(),true); @@ -1325,7 +1371,7 @@ namespace MEDCoupling MCAuto::FieldType> ret(ff->getFieldOnMeshAtLevel(type,m)); if(muPtr.isNotNull()) { - const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); + const DataArrayIdType *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); if(num) ret->renumberCells(num->begin()); } @@ -1344,10 +1390,10 @@ namespace MEDCoupling } } { - MCAuto f1(MEDCoupling::DynamicCast(f)); + MCAuto f1(MEDCoupling::DynamicCast(f)); if(f1.isNotNull()) { - MCAuto ret(ReadFieldCellLikeT(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + MCAuto ret(ReadFieldCellLikeT(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); return ret.retn(); } } @@ -1373,27 +1419,27 @@ namespace MEDCoupling { if(muPtr.isNotNull()) { - const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); + const DataArrayIdType *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); if(num) ret->renumberCells(num->begin()); } } else { - DataArrayInt *pfl(nullptr),*arr2(nullptr); + DataArrayIdType *pfl(nullptr),*arr2(nullptr); MCAuto::ArrayType> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl)); - MCAuto pflSafe(pfl); - MCAuto mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end())); + MCAuto pflSafe(pfl); + MCAuto mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end())); MCAuto mzip(static_cast(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2))); - MCAuto arr2Safe(arr2); - MCAuto arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes())); - MCAuto pflSorted(pflSafe->deepCopy()); pflSorted->sort(true); + MCAuto arr2Safe(arr2); + MCAuto arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes())); + MCAuto pflSorted(pflSafe->deepCopy()); pflSorted->sort(true); if(!arr3->isEqualWithoutConsideringStr(*pflSorted)) throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !"); if(!arr3->isEqualWithoutConsideringStr(*pflSafe)) { - MCAuto o2n2(pflSafe->checkAndPreparePermutation()); - MCAuto n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples())); + MCAuto o2n2(pflSafe->checkAndPreparePermutation()); + MCAuto n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples())); mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples()); arr->setName(""); ret->setArray(arr); @@ -1421,10 +1467,10 @@ MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldNode(const std::string& fil } } { - MCAuto f1(MEDCoupling::DynamicCast(f)); + MCAuto f1(MEDCoupling::DynamicCast(f)); if(f1.isNotNull()) { - MCAuto ret(ReadFieldNodeT(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + MCAuto ret(ReadFieldNodeT(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); return ret.retn(); } } @@ -1557,8 +1603,8 @@ void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::stri { MCAuto mmu(MEDFileUMesh::New()); AssignStaticWritePropertiesTo(*mmu); - MCAuto o2n(um->getRenumArrForMEDFileFrmt()); - MCAuto n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples())); + MCAuto o2n(um->getRenumArrForMEDFileFrmt()); + MCAuto n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples())); f2->renumberCells(o2n->begin(),false); mmu->setMeshAtLevel(0,const_cast(static_cast(f2->getMesh()))); mmu->setRenumFieldArr(0,n2o); @@ -1630,7 +1676,7 @@ void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits MEDCouplingUMesh *m(dynamic_cast(const_cast(f2->getMesh()))); if(!m) throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !"); - MCAuto o2n(m->getRenumArrForMEDFileFrmt()); + MCAuto o2n(m->getRenumArrForMEDFileFrmt()); f2->renumberCells(o2n->begin(),false); m=static_cast(const_cast(f2->getMesh())); MCAuto mread(mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension())); @@ -1640,9 +1686,9 @@ void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP); else mread->setCoords(m->getCoords()); - DataArrayInt *part(NULL); + DataArrayIdType *part(NULL); bool b(mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part)); - MCAuto partSafe(part); + MCAuto partSafe(part); if(!b) { std::ostringstream oss; oss << "WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart) with the mesh you intend to write ! This is maybe due to a too strict policy ! Try with to lease it by calling SetCompPolicyForCell !"; @@ -1662,9 +1708,9 @@ void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits } else { - DataArrayInt *part(NULL); + DataArrayIdType *part(NULL); bool b(mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part)); - MCAuto partSafe(part); + MCAuto partSafe(part); if(!b) { std::ostringstream oss; oss << "WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart regarding nodes) with the mesh you intend to write ! This is maybe due to a too strict epsilon ! Try with to lease it by calling SetEpsilonForNodeComp !"; @@ -1698,7 +1744,7 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED } } { - const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast(f)); + const MEDCoupling::MEDCouplingFieldInt32 *f1(dynamic_cast(f)); if(f1) { WriteFieldT(fileName,f1,writeFromScratch); @@ -1738,7 +1784,7 @@ void WriteFieldUsingAlreadyWrittenMeshT(const std::string& fileName, const typen MEDCouplingUMesh *m(dynamic_cast(const_cast(f->getMesh()))); if(m) { - MCAuto o2n(m->getRenumArrForMEDFileFrmt()); + MCAuto o2n(m->getRenumArrForMEDFileFrmt()); MCAuto< typename MEDCoupling::Traits::FieldType > f2(f->deepCopy()); f2->renumberCells(o2n->begin(),false); f1ts->setFieldNoProfileSBT(f2); @@ -1759,7 +1805,7 @@ void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, return ; } { - const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast(f)); + const MEDCoupling::MEDCouplingFieldInt32 *f1(dynamic_cast(f)); if(f1) WriteFieldUsingAlreadyWrittenMeshT(fileName,f1); return ;