From: ageay Date: Tue, 8 Mar 2011 10:23:31 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: FirstStepOK1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1aabec58785279929a8e10727b805e0cdf008c86;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 19fe8fdae..bb21c4a40 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -18,6 +18,7 @@ // #include "MEDFileField.hxx" +#include "MEDFileMesh.hxx" #include "MEDLoaderBase.hxx" #include "MEDFileUtilities.hxx" @@ -25,10 +26,10 @@ #include -extern med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2]; -extern INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2]; -extern med_geometrie_element typmainoeud[1]; -extern med_geometrie_element typmai3[32]; +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]; +extern med_geometry_type typmai3[32]; using namespace ParaMEDMEM; @@ -40,8 +41,8 @@ MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFil MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception) try:_father(fath) { - INTERP_KERNEL::AutoPtr locname=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - INTERP_KERNEL::AutoPtr pflname=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + INTERP_KERNEL::AutoPtr locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr pflname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); std::string fieldName=getName(); std::string meshName=getMeshName(); int iteration=getIteration(); @@ -49,16 +50,15 @@ try:_father(fath) const std::vector& infos=getInfos(); TypeOfField type=getType(); INTERP_KERNEL::NormalizedCellType geoType=getGeoType(); - int nval=MEDnVal(fid,(char *)fieldName.c_str(),type==ON_CELLS?MED_MAILLE:MED_NOEUD,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE, - iteration,order,(char *)meshName.c_str(),MED_COMPACT); + int profilesize,nbi; + int nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,type==ON_CELLS?MED_CELL:MED_NODE,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,1,MED_COMPACT_PFLMODE, + pflname,&profilesize,locname,&nbi);//to generalize _arr=DataArrayDouble::New(); _arr->alloc(nval,infos.size()); - MEDchampLire(fid,(char *)getMeshName().c_str(),(char *)fieldName.c_str(),(unsigned char*)_arr->getPointer(),MED_FULL_INTERLACE,MED_ALL,locname, - pflname,MED_COMPACT,type==ON_CELLS?MED_MAILLE:MED_NOEUD, - type==ON_CELLS?typmai3[(int)geoType]:MED_NONE, - iteration,order); - _profile=pflname; - _localization=locname; + MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,type==ON_CELLS?MED_CELL:MED_NODE,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,MED_COMPACT_PFLMODE, + pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast(_arr->getPointer())); + _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE); + _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE); } catch(INTERP_KERNEL::Exception& e) { @@ -105,6 +105,11 @@ int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const return _father->getNumberOfComponents(); } +int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const +{ + return _arr->getNumberOfTuples(); +} + const std::vector& MEDFileFieldPerMeshPerTypePerDisc::getInfos() const { return _father->getInfos(); @@ -195,6 +200,28 @@ std::vector MEDFileFieldPerMeshPerType::getLocsReallyUsed() const return ret; } +bool MEDFileFieldPerMeshPerType::isOnNode(int& type, int& number, const DataArrayInt* &arrs) const throw(INTERP_KERNEL::Exception) +{ + if(_type!=ON_NODES) + return false; + type=INTERP_KERNEL::NORM_ERROR; + number=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++) + number+=(*it)->getNumberOfTuples(); + return true; +} + +bool MEDFileFieldPerMeshPerType::isOnCell(int dimDimReq, int& type, int& number, const DataArrayInt* &arrs) const throw(INTERP_KERNEL::Exception) +{ + if(_type!=ON_CELLS) + return false; + type=(int)_geo_type; + number=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++) + number+=(*it)->getNumberOfTuples(); + return true; +} + MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_type(type),_geo_type(geoType) { } @@ -206,9 +233,9 @@ void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid) throw(INTERP_KERNEL: _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,fid); } -MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time) +MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileField1TSWithoutDAS *fath, double time) { - return new MEDFileFieldPerMesh(fath,meshName,time); + return new MEDFileFieldPerMesh(fath,time); } void MEDFileFieldPerMesh::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) @@ -250,7 +277,7 @@ std::string MEDFileFieldPerMesh::getName() const std::string MEDFileFieldPerMesh::getMeshName() const { - return _mesh_name; + return _father->getMeshName(); } int MEDFileFieldPerMesh::getNumberOfComponents() const @@ -297,7 +324,55 @@ std::vector MEDFileFieldPerMesh::getLocsReallyUsed() const return ret; } -MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time):_father(fath),_mesh_name(meshName),_time(time) +MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) +{ + std::vector arrs; + std::vector distrib=getDistributionOfTypes(meshDimRelToMaxExt,mesh->getMeshDimension(),arrs); + MEDCouplingAutoRefCountObjectPtr da=mesh->checkTypeConsistencyAndContig(distrib,arrs); + return 0; +} + +std::vector MEDFileFieldPerMesh::getDistributionOfTypes(int meshDimRelToMaxExt, int mdim, std::vector& arrs) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt>1) + throw INTERP_KERNEL::Exception("Invalid meshDimRelToMaxExt parameter passed ! must be 1 for node and 0,-1,-2,-3 for cells !"); + std::vector ret; + int tmp2,tmp3; + arrs.clear(); + const DataArrayInt *arrTmp=0; + if(meshDimRelToMaxExt==1) + {//On node + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + if((*it)->isOnNode(tmp2,tmp3,arrTmp)) + { + ret.push_back(-1); + ret.push_back(tmp2); + ret.push_back(tmp3); + if(arrTmp) + arrs.push_back(arrTmp); + } + if(ret.size()>2) + throw INTERP_KERNEL::Exception("Detected on same time step two different discretization ... Should never happen !"); + } + else + { + int dimTarget=mdim+meshDimRelToMaxExt; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + if((*it)->isOnCell(dimTarget,tmp2,tmp3,arrTmp)) + { + ret.push_back((int)(*it)->getGeoType()); + ret.push_back(tmp2); + ret.push_back(tmp3); + if(arrTmp) + arrs.push_back(arrTmp); + } + } + if(ret.empty()) + throw INTERP_KERNEL::Exception("No field part correspond to requested meshdimRel !"); + return ret; +} + +MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, double time):_father(fath),_time(time) { } @@ -305,17 +380,27 @@ void MEDFieldFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflN { _pfls[id]=DataArrayInt::New(); _pfls[id]->alloc(lgth,1); - MEDprofilLire(fid,_pfls[id]->getPointer(),(char *)pflName); + MEDprofileRd(fid,pflName,_pfls[id]->getPointer()); + _pfls[id]->applyLin(1,-1,0);//Converting into C format } void MEDFieldFieldGlobs::loadProfileInFile(med_idt fid, int i) { - INTERP_KERNEL::AutoPtr pflName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + INTERP_KERNEL::AutoPtr pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); int sz; - MEDprofilInfo(fid,i,pflName,&sz); + MEDprofileInfo(fid,i,pflName,&sz); _pfls[i]=DataArrayInt::New(); _pfls[i]->alloc(sz,1); - MEDprofilLire(fid,_pfls[i]->getPointer(),(char *)pflName); + MEDprofileRd(fid,pflName,_pfls[i]->getPointer()); +} + +MEDFieldFieldGlobs::MEDFieldFieldGlobs(const char *fname):_file_name(fname) +{ +} + +void MEDFieldFieldGlobs::setFileName(const char *fileName) +{ + _file_name=fileName; } std::vector MEDFieldFieldGlobs::getPfls() const @@ -336,41 +421,34 @@ std::vector MEDFieldFieldGlobs::getLocs() const return ret; } -MEDFileField1TSWithoutDAS *MEDFileField1TSWithoutDAS::New(const char *fieldName, int iteration, int order, const std::vector& infos) +MEDFileField1TSWithoutDAS *MEDFileField1TSWithoutDAS::New(const char *fieldName, const char *meshName, int iteration, int order, int meshIt, int meshOrder, const std::vector& infos) { - return new MEDFileField1TSWithoutDAS(fieldName,iteration,order,infos); + return new MEDFileField1TSWithoutDAS(fieldName,meshName,iteration,order,meshIt,meshOrder,infos); } -void MEDFileField1TSWithoutDAS::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time, const char *meshName) const +void MEDFileField1TSWithoutDAS::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time) const { _types.push_back(type); _geo_types.push_back(geoType); _times.push_back(time); - _meshes.push_back(meshName); } void MEDFileField1TSWithoutDAS::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception) { - std::vector meshesOnlyOnce; - int nbOfTurn=_meshes.size(); - for(int i=0;i::iterator it=std::find(meshesOnlyOnce.begin(),meshesOnlyOnce.end(),_meshes[i]); - if(it==meshesOnlyOnce.end()) - { - _field_per_mesh.push_back(MEDFileFieldPerMesh::New(this,_meshes[i].c_str(),_times[i])); - meshesOnlyOnce.push_back(_meshes[i]); - _field_per_mesh.back()->pushBack(_types[i],_geo_types[i]); - } - else - { - int w=std::distance(meshesOnlyOnce.begin(),it); - _field_per_mesh[w]->pushBack(_types[i],_geo_types[i]); - } - } - int nbOfMeshes=_field_per_mesh.size(); - for(int i=0;ifinishLoading(fid); + _field_per_mesh.push_back(MEDFileFieldPerMesh::New(this,_times[0])); + _field_per_mesh[0]->finishLoading(fid); +} + +MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr mm=MEDFileMesh::New(glob->getFileName(),_mesh_name.c_str(),_mesh_iteration,_mesh_order); + MEDCouplingAutoRefCountObjectPtr m=mm->getGenMeshAtLevel(meshDimRelToMaxExt); + return _field_per_mesh[0]->getFieldOnMeshAtLevel(meshDimRelToMaxExt,glob,m); +} + +MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) +{ + return _field_per_mesh[0]->getFieldOnMeshAtLevel(meshDimRelToMaxExt,glob,mesh); } std::vector MEDFileField1TSWithoutDAS::getPflsReallyUsed() const @@ -407,7 +485,9 @@ std::vector MEDFileField1TSWithoutDAS::getLocsReallyUsed() const return ret; } -MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, int iteration, int order, const std::vector& infos):_name(fieldName),_infos(infos),_iteration(iteration),_order(order) +MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, const char *meshName, int iteration, int order, int meshIt, int meshOrder, + const std::vector& infos):_name(fieldName),_mesh_name(meshName),_infos(infos),_iteration(iteration),_order(order), + _mesh_iteration(meshIt),_mesh_order(meshOrder) { } @@ -417,29 +497,35 @@ MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldNam } MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) -try:MEDFileField1TSWithoutDAS(fieldName,iteration,order,std::vector()) +try:MEDFileField1TSWithoutDAS(fieldName,"",iteration,order,-1,-1,std::vector()),MEDFieldFieldGlobs(fileName) { MEDFileUtilities::CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - int nbFields=MEDnChamp(fid,0); - med_type_champ typcha; + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbFields=MEDnField(fid); + med_field_type typcha; bool found=false; std::vector fns(nbFields); for(int i=0;i comp=new char[ncomp*MED_TAILLE_PNOM+1]; - INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_TAILLE_PNOM+1]; - INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp); + int ncomp=MEDfieldnComponent(fid,i+1); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localMesh; + int nbOfStep; + MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep); std::string tmp(nomcha); fns[i]=tmp; found=(tmp==fieldName); if(found) { + std::string mname=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE); + _mesh_name=mname; _infos.resize(ncomp); for(int j=0;j _pfls.resize(sz); for(int i=0;i& infos) throw(INTERP_KERNEL::Exception) +MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + return MEDFileField1TSWithoutDAS::getFieldAtLevel(meshDimRelToMaxExt,this); +} + +MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) +{ + return MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(meshDimRelToMaxExt,this,mesh); +} + +MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception) { - return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos); + return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos,nbOfStep); } MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(const char *fieldName):_name(fieldName) { } -MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector& infos) throw(INTERP_KERNEL::Exception) +MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception) try:_name(fieldName),_infos(infos) { - finishLoading(fid); + finishLoading(fid,nbOfStep); } catch(INTERP_KERNEL::Exception& e) { throw e; } -void MEDFileFieldMultiTSWithoutDAS::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception) +void MEDFileFieldMultiTSWithoutDAS::finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception) { - for(int i=0;ifinishLoading(fid); } -void MEDFileFieldMultiTSWithoutDAS::appendTimeStepEntry(med_idt fid, med_entite_maillage entity, int i, int j) throw(INTERP_KERNEL::Exception) +void MEDFileFieldMultiTSWithoutDAS::appendTimeStepEntry(med_idt fid, med_entity_type entity, int i, int j) throw(INTERP_KERNEL::Exception) { std::vector< std::pair > ts; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; + med_int numdt=0,numo=0; + med_int meshIt=0,meshOrder=0; med_float dt=0.0; - med_booleen local; - INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - MEDpasdetempsInfo(fid,(char *)_name.c_str(),MED_MAILLE,typmai[i],j+1,&ngauss,&numdt,&numo,dt_unit,&dt,maa_ass,&local,&nbrefmaa); + MEDfieldComputingStepMeshInfo(fid,_name.c_str(),j+1,&numdt,&numo,&dt,&meshIt,&meshOrder); std::pair p(numdt,numo); std::vector< std::pair >::iterator where=std::find(ts.begin(),ts.end(),p); if(where==ts.end()) { ts.push_back(p); - _time_steps.push_back(MEDFileField1TSWithoutDAS::New(_name.c_str(),numdt,numo,_infos)); - _time_steps.back()->pushBack(entity==MED_MAILLE?ON_CELLS:ON_NODES,entity==MED_MAILLE?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt,maa_ass); + _time_steps.push_back(MEDFileField1TSWithoutDAS::New(_name.c_str(),_mesh_name.c_str(),numdt,numo,meshIt,meshOrder,_infos)); + _time_steps.back()->pushBack(entity==MED_CELL?ON_CELLS:ON_NODES,entity==MED_CELL?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt); } else { int w=std::distance(ts.begin(),where); - _time_steps[w]->pushBack(entity==MED_MAILLE?ON_CELLS:ON_NODES,entity==MED_MAILLE?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt,maa_ass); + _time_steps[w]->pushBack(entity==MED_CELL?ON_CELLS:ON_NODES,entity==MED_CELL?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt); } } @@ -556,35 +644,46 @@ std::vector MEDFileFieldMultiTSWithoutDAS::getLocsReallyUsed() cons return ret; } +int MEDFileFieldMultiTSWithoutDAS::getNumberOfTS() const +{ + return _time_steps.size(); +} + MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception) { return new MEDFileFieldMultiTS(fileName,fieldName); } MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception) -try:MEDFileFieldMultiTSWithoutDAS(fieldName) +try:MEDFileFieldMultiTSWithoutDAS(fieldName),MEDFieldFieldGlobs(fileName) { MEDFileUtilities::CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - int nbFields=MEDnChamp(fid,0); - med_type_champ typcha; + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbFields=MEDnField(fid); + med_field_type typcha; bool found=false; std::vector fns(nbFields); + int nbstep2=-1; for(int i=0;i comp=new char[ncomp*MED_TAILLE_PNOM+1]; - INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_TAILLE_PNOM+1]; - INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp); + int ncomp=MEDfieldnComponent(fid,i+1); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localMesh; + int nbOfStep; + MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep); std::string tmp(nomcha); fns[i]=tmp; found=(tmp==fieldName); if(found) { + nbstep2=nbOfStep; _infos.resize(ncomp); for(int j=0;j(oss," ")); throw INTERP_KERNEL::Exception(oss.str().c_str()); } - finishLoading(fid); - MEDfermer(fid); + finishLoading(fid,nbstep2); } catch(INTERP_KERNEL::Exception& e) { @@ -612,30 +710,33 @@ int MEDFileFields::getNumberOfFields() const } MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception) -try +try:MEDFieldFieldGlobs(fileName) { MEDFileUtilities::CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - int nbFields=MEDnChamp(fid,0); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbFields=MEDnField(fid); _fields.resize(nbFields); - med_type_champ typcha; + med_field_type typcha; for(int i=0;i comp=new char[ncomp*MED_TAILLE_PNOM+1]; - INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_TAILLE_PNOM+1]; - INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp); + int ncomp=MEDfieldnComponent(fid,i+1); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localMesh; + int nbOfStep; + MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep); std::vector infos(ncomp); for(int j=0;j& getInfos() const; std::string getProfile() const; std::string getLocalization() const; private: MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception); + private: MEDFileFieldPerMeshPerType *_father; MEDCouplingAutoRefCountObjectPtr< DataArrayDouble > _arr; @@ -97,6 +103,8 @@ namespace ParaMEDMEM const std::vector& getInfos() const; std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; + bool isOnNode(int& type, int& number, const DataArrayInt* &arrs) const throw(INTERP_KERNEL::Exception); + bool isOnCell(int dimDimReq, int& type, int& number, const DataArrayInt* &arrs) const throw(INTERP_KERNEL::Exception); private: MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception); private: @@ -109,7 +117,7 @@ namespace ParaMEDMEM class MEDFileFieldPerMesh : public RefCountObject { public: - static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time); + static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, double time); void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType); void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); double getTime() const; @@ -121,12 +129,13 @@ namespace ParaMEDMEM const std::vector& getInfos() const; std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; + std::vector getDistributionOfTypes(int meshDimRelToMaxExt, int mdim, std::vector& arrs) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception); private: - MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time); + MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, double time); private: MEDFileField1TSWithoutDAS *_father; std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > _field_pm_pt; - std::string _mesh_name; double _time; private: mutable std::vector _types; @@ -136,41 +145,53 @@ namespace ParaMEDMEM class MEDFieldFieldGlobs { public: + MEDFieldFieldGlobs(const char *fname); void loadProfileInFile(med_idt fid, int id, const char *pflName, int lgth) throw(INTERP_KERNEL::Exception); void loadProfileInFile(med_idt fid, int id); std::vector getPfls() const; std::vector getLocs() const; + void setFileName(const char *fileName); + const char *getFileName() const { return _file_name.c_str(); } protected: std::vector< MEDCouplingAutoRefCountObjectPtr > _pfls; std::vector< MEDCouplingAutoRefCountObjectPtr > _locs; + std::string _file_name; }; class MEDFileField1TSWithoutDAS : public RefCountObject { public: - static MEDFileField1TSWithoutDAS *New(const char *fieldName, int iteration, int order, const std::vector& infos); - void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time, const char *meshName) const; - void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); int getIteration() const { return _iteration; } int getOrder() const { return _order; } std::string getName() const { return _name; } + std::string getMeshName() const { return _mesh_name; } int getNumberOfComponents() const { return _infos.size(); } const std::vector& getInfos() const { return _infos; } std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; + // + static MEDFileField1TSWithoutDAS *New(const char *fieldName, const char *meshName, int iteration, int order, int meshIt, int meshOrder, const std::vector& infos); + void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time) const; + void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); + protected: + MEDCouplingFieldDouble *getFieldAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception); protected: - MEDFileField1TSWithoutDAS(const char *fieldName, int iteration, int order, const std::vector& infos); + MEDFileField1TSWithoutDAS(const char *fieldName, const char *meshName, int iteration, int order, int meshIt, int meshOrder, + const std::vector& infos); protected: std::string _name; + std::string _mesh_name; std::vector _infos; std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > > _field_per_mesh; int _iteration; int _order; + int _mesh_iteration; + int _mesh_order; private: mutable std::vector _types; mutable std::vector _geo_types; mutable std::vector _times; - mutable std::vector _meshes; }; /*! @@ -180,6 +201,9 @@ namespace ParaMEDMEM { public: static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + void setFileName(const char *fileName); + MEDCouplingFieldDouble *getFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception); private: MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); }; @@ -187,16 +211,18 @@ namespace ParaMEDMEM class MEDFileFieldMultiTSWithoutDAS : public RefCountObject { public: - static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, const std::vector& infos) throw(INTERP_KERNEL::Exception); + static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); + int getNumberOfTS() const; protected: MEDFileFieldMultiTSWithoutDAS(const char *fieldName); - MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector& infos) throw(INTERP_KERNEL::Exception); - void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); - void appendTimeStepEntry(med_idt fid, med_entite_maillage entity, int i, int j) throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); + void finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception); + void appendTimeStepEntry(med_idt fid, med_entity_type entity, int i, int j) throw(INTERP_KERNEL::Exception); std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; protected: std::string _name; + std::string _mesh_name; std::vector _infos; std::vector< MEDCouplingAutoRefCountObjectPtr > _time_steps; }; @@ -220,8 +246,6 @@ namespace ParaMEDMEM public: static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception); int getNumberOfFields() const; - std::vector getPfls() const; - std::vector getLocs() const; private: MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception); private: diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 66f27e2e5..49221aea0 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -27,233 +27,142 @@ #include "InterpKernelAutoPtr.hxx" #include +#include using namespace ParaMEDMEM; -MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) -{ - throw INTERP_KERNEL::Exception("Not implemented yet !"); -} +const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO"; -MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) +MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.),_too_long_str(0),_zipconn_pol(2) { - return new MEDFileUMesh(fileName,mName); } -MEDFileUMesh *MEDFileUMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception) +MEDFileMesh *MEDFileMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception) { std::vector ms=MEDLoader::GetMeshNames(fileName); if(ms.empty()) { - std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !"; + std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << fileName << "\" !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - return new MEDFileUMesh(fileName,ms.front().c_str()); -} - -MEDFileUMesh *MEDFileUMesh::New() -{ - return new MEDFileUMesh; -} - -MEDFileUMesh::MEDFileUMesh():_too_long_str(0),_zipconn_pol(2) -{ -} - -MEDFileUMesh::MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) - try:_too_long_str(0) - { - MEDFileUtilities::CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - MEDFileUMeshL2 loaderl2; - loaderl2.loadAll(fid,MEDFileUMeshL2::getMeshIdFromName(fid,mName),mName); - int lev=loaderl2.getNumberOfLevels(); - _ms.resize(lev); - for(int i=0;i(this))->addFamily(0,"FAMILLE_ZERO"); - med_mode_acces medmod=MEDFileUtilities::TraduceWriteMode(mode); - med_idt fid=MEDouvrir((char *)fileName,medmod); - std::ostringstream oss; oss << "MEDFileUMesh : error on attempt to write in file : \"" << fileName << "\""; - MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str()); - const DataArrayDouble *coo=_coords; - INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_TAILLE_DESC); - MEDLoaderBase::safeStrCpy(_name.c_str(),MED_TAILLE_NOM,maa,_too_long_str); - MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_TAILLE_DESC,desc,_too_long_str); - int spaceDim=coo?coo->getNumberOfComponents():0; - int mdim=getMeshDimension(); - MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc);//spaceDim is false but to make reader happy for 3DSurf and 2DCurve meshes ! - MEDdimEspaceCr(fid,maa,spaceDim); - MEDFileUMeshL2::writeCoords(fid,maa,_coords,_fam_coords,_num_coords); - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) - if((const MEDFileUMeshSplitL1 *)(*it)!=0) - (*it)->write(fid,maa,mdim); - MEDFileUMeshL2::writeFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str); - MEDfermer(fid); -} - -std::vector MEDFileUMesh::getNonEmptyLevels() const -{ - std::vector ret; - int lev=0; - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--) - if((const MEDFileUMeshSplitL1 *)(*it)!=0) - if(!(*it)->empty()) - ret.push_back(lev); - return ret; -} - -std::vector MEDFileUMesh::getNonEmptyLevelsExt() const -{ - std::vector ret0=getNonEmptyLevels(); - if((const DataArrayDouble *) _coords) + MEDFileUtilities::CheckFileForRead(fileName); + ParaMEDMEM::MEDCouplingMeshType meshType; + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int dt,it; + std::string dummy2; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2); + switch(meshType) { - std::vector ret(ret0.size()+1); - ret[0]=1; - std::copy(ret0.begin(),ret0.end(),ret.begin()+1); - return ret; + case UNSTRUCTURED: + { + MEDCouplingAutoRefCountObjectPtr ret=MEDFileUMesh::New(); + ret->loadUMeshFromFile(fid,ms.front().c_str(),dt,it); + ret->incrRef(); + return (MEDFileUMesh *)ret; + } + case CARTESIAN: + { + MEDCouplingAutoRefCountObjectPtr ret=MEDFileCMesh::New(); + ret->loadCMeshFromFile(fid,ms.front().c_str(),dt,it); + ret->incrRef(); + return (MEDFileCMesh *)ret; + } + default: + { + std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << ms.front() << "' exists but unsupported type yet !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } - return ret0; } -int MEDFileUMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception) +MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) { - std::string oname(name); - std::map::const_iterator it=_families.find(oname); - std::vector fams=getFamiliesNames(); - if(it==_families.end()) + MEDFileUtilities::CheckFileForRead(fileName); + ParaMEDMEM::MEDCouplingMeshType meshType; + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int dummy0,dummy1; + std::string dummy2; + MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2); + switch(meshType) { - std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :"; - std::copy(fams.begin(),fams.end(),std::ostream_iterator(oss," ")); - throw INTERP_KERNEL::Exception(oss.str().c_str()); + case UNSTRUCTURED: + { + MEDCouplingAutoRefCountObjectPtr ret=MEDFileUMesh::New(); + ret->loadUMeshFromFile(fid,mName,dt,it); + ret->incrRef(); + return (MEDFileUMesh *)ret; + } + case CARTESIAN: + { + MEDCouplingAutoRefCountObjectPtr ret=MEDFileCMesh::New(); + ret->loadCMeshFromFile(fid,mName,dt,it); + ret->incrRef(); + return (MEDFileCMesh *)ret; + } + default: + { + std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << mName << "' exists but unsupported type yet !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } - return (*it).second; } -int MEDFileUMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception) +bool MEDFileMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const { - if(_families.empty()) - throw INTERP_KERNEL::Exception("MEDFileUMesh::getMaxFamilyId : no families set !"); - int ret=-std::numeric_limits::max(); - for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) + if(_order!=other->_order) { - ret=std::max((*it).second,ret); + what="Orders differ !"; + return false; } - return ret; -} - -std::vector MEDFileUMesh::getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception) -{ - std::vector famIds; - for(std::vector::const_iterator it=famNames.begin();it!=famNames.end();it++) + if(_iteration!=other->_iteration) { - std::map::const_iterator it2=_families.find(*it); - if(it2==_families.end()) - { - std::ostringstream oss; oss << "No such family in mesh \"" << _name << "\" : " << *it; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - famIds.push_back((*it2).second); + what="Iterations differ !"; + return false; } - return famIds; -} - -std::string MEDFileUMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception) -{ - for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) - if((*it).second==id) - return (*it).first; - std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id; - throw INTERP_KERNEL::Exception(oss.str().c_str()); -} - -int MEDFileUMesh::getMeshDimension() const -{ - int lev=0; - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++) - if((const MEDFileUMeshSplitL1 *)(*it)!=0) - return (*it)->getMeshDimension()+lev; - throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !"); -} - -int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) -{ - if(meshDimRelToMaxExt==1) + if(fabs(_time-other->_time)>eps) { - if(!((const DataArrayDouble *)_coords)) - throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !"); - return _coords->getNumberOfTuples(); + what="Time values differ !"; + return false; } - return getMeshAtLevSafe(meshDimRelToMaxExt)->getSize(); -} - -const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) -{ - if(meshDimRelToMaxExt==1) + if(_dt_unit!=other->_dt_unit) { - if(!((const DataArrayInt *)_fam_coords)) - throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamilyFieldAtLevel : no coordinates specified !"); - return _fam_coords; + what="Time units differ !"; + return false; } - const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); - return l1->getFamilyField(); + if(_name!=other->_name) + { + what="Names differ !"; + return false; + } + if(_univ_name!=other->_univ_name) + { + what="Univ names differ !"; + return false; + } + if(_desc_name!=other->_desc_name) + { + what="Description names differ !"; + return false; + } + if(!areGrpsEqual(other,what)) + return false; + if(!areFamsEqual(other,what)) + return false; + return true; } -const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +void MEDFileMesh::clearNonDiscrAttributes() const { - if(meshDimRelToMaxExt==1) - { - if(!((const DataArrayInt *)_num_coords)) - throw INTERP_KERNEL::Exception("MEDFileUMesh::getNumberFieldAtLevel : no coordinates renum specified !"); - return _num_coords; - } - const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); - return l1->getNumberField(); + } -const DataArrayInt *MEDFileUMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +void MEDFileMesh::copyFamGrpMapsFrom(const MEDFileMesh& other) { - if(meshDimRelToMaxExt==1) - { - if(!((const DataArrayInt *)_num_coords)) - throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !"); - return _rev_num_coords; - } - const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); - return l1->getRevNumberField(); + _groups=other._groups; + _families=other._families; } -std::vector MEDFileUMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception) +std::vector MEDFileMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception) { std::string oname(name); std::map >::const_iterator it=_groups.find(oname); @@ -267,7 +176,7 @@ std::vector MEDFileUMesh::getFamiliesOnGroup(const char *name) cons return (*it).second; } -std::vector MEDFileUMesh::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception) +std::vector MEDFileMesh::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception) { std::vector ret; for(std::map >::const_iterator it1=_groups.begin();it1!=_groups.end();it1++) @@ -282,7 +191,7 @@ std::vector MEDFileUMesh::getGroupsOnFamily(const char *name) const return ret; } -std::vector MEDFileUMesh::getGroupsNames() const +std::vector MEDFileMesh::getGroupsNames() const { std::vector ret(_groups.size()); int i=0; @@ -291,7 +200,7 @@ std::vector MEDFileUMesh::getGroupsNames() const return ret; } -std::vector MEDFileUMesh::getFamiliesNames() const +std::vector MEDFileMesh::getFamiliesNames() const { std::vector ret(_families.size()); int i=0; @@ -300,7 +209,7 @@ std::vector MEDFileUMesh::getFamiliesNames() const return ret; } -void MEDFileUMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception) +void MEDFileMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception) { std::string oname(name); std::map >::iterator it=_groups.find(oname); @@ -314,7 +223,7 @@ void MEDFileUMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception) _groups.erase(it); } -void MEDFileUMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception) +void MEDFileMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception) { std::string oname(name); std::map::iterator it=_families.find(oname); @@ -328,7 +237,7 @@ void MEDFileUMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception _families.erase(it); } -void MEDFileUMesh::changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception) +void MEDFileMesh::changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception) { std::string oname(oldName); std::map >::iterator it=_groups.find(oname); @@ -343,7 +252,7 @@ void MEDFileUMesh::changeGroupName(const char *oldName, const char *newName) thr it=_groups.find(nname); if(it!=_groups.end()) { - std::ostringstream oss; oss << "Such groupname \"" << newName << " already exists ! Kill it before !"; + std::ostringstream oss; oss << "Such groupname \"" << newName << "\" already exists ! Kill it before !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } std::vector cpy=(*it).second; @@ -351,7 +260,7 @@ void MEDFileUMesh::changeGroupName(const char *oldName, const char *newName) thr _groups[newName]=cpy; } -void MEDFileUMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception) +void MEDFileMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception) { std::string oname(oldName); std::map::iterator it=_families.find(oname); @@ -374,145 +283,738 @@ void MEDFileUMesh::changeFamilyName(const char *oldName, const char *newName) th _families[newName]=cpy; } -DataArrayDouble *MEDFileUMesh::getCoords() const +bool MEDFileMesh::areFamsEqual(const MEDFileMesh *other, std::string& what) const { - MEDCouplingAutoRefCountObjectPtr tmp(_coords); - if((DataArrayDouble *)tmp) + if(_families==other->_families) + return true; + std::map fam0; + std::map fam1; + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) + if((*it).second!=0) + fam0[(*it).first]=(*it).second; + for(std::map::const_iterator it=other->_families.begin();it!=other->_families.end();it++) + if((*it).second!=0) + fam1[(*it).first]=(*it).second; + return fam0==fam1; +} + +bool MEDFileMesh::areGrpsEqual(const MEDFileMesh *other, std::string& what) const +{ + if(_groups==other->_groups) + return true; + bool ret=true; + std::size_t sz=_groups.size(); + if(sz!=other->_groups.size()) { - tmp->incrRef(); - return tmp; + what="Groups differ because not same number !\n"; + ret=false; } - return 0; + if(ret) + { + std::map >::const_iterator it1=_groups.begin(); + for(std::size_t i=0;i >::const_iterator it2=other->_groups.find((*it1).first); + if(it2!=other->_groups.end()) + { + std::set s1((*it1).second.begin(),(*it1).second.end()); + std::set s2((*it2).second.begin(),(*it2).second.end()); + ret=(s1==s2); + } + else + { + ret=false; + what="A group in first mesh exists not in other !\n"; + } + } + } + if(!ret) + { + std::ostringstream oss; oss << "Groups description differs :\n"; + oss << "First group description :\n"; + for(std::map >::const_iterator it=_groups.begin();it!=_groups.end();it++) + { + oss << " Group \"" << (*it).first << "\" on following families :\n"; + for(std::vector::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++) + oss << " \"" << *it2 << "\n"; + } + oss << "Second group description :\n"; + for(std::map >::const_iterator it=other->_groups.begin();it!=other->_groups.end();it++) + { + oss << " Group \"" << (*it).first << "\" on following families :\n"; + for(std::vector::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++) + oss << " \"" << *it2 << "\n"; + } + what+=oss.str(); + } + return ret; } -MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception) +bool MEDFileMesh::existsFamily(int famId) const { - std::vector tmp(1); - tmp[0]=grp; - MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum); - ret->setName(grp); - return ret; + for(std::map::const_iterator it2=_families.begin();it2!=_families.end();it2++) + if((*it2).second==famId) + return true; + return false; } -DataArrayInt *MEDFileUMesh::getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception) +bool MEDFileMesh::existsFamily(const char *familyName) const { - std::vector tmp(1); - tmp[0]=grp; - DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum); - ret->setName(grp); - return ret; + std::string fname(familyName); + return _families.find(fname)!=_families.end(); } -MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) +void MEDFileMesh::setFamilyId(const char *familyName, int id) { - std::set fams; - for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + std::string fname(familyName); + _families[fname]=id; +} + +/*! + * This method appends a new entry in _families attribute. An exception is thrown if either the famId is already + * kept by an another familyName. An exception is thrown if name 'familyName' is alreadyset with a different 'famId'. + */ +void MEDFileMesh::addFamily(const char *familyName, int famId) throw(INTERP_KERNEL::Exception) +{ + std::string fname(familyName); + std::map::const_iterator it=_families.find(fname); + if(it==_families.end()) { - std::map >::const_iterator it2=_groups.find(*it); - if(it2==_groups.end()) + for(std::map::const_iterator it2=_families.begin();it2!=_families.end();it2++) + if((*it2).second==famId) + { + std::ostringstream oss; + oss << "MEDFileMesh::addFamily : Family \"" << (*it2).first << "\" already exists with specified id : " << famId << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _families[fname]=famId; + } + else + { + if((*it).second!=famId) { - std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; + std::ostringstream oss; + oss << "MEDFileMesh::addFamily : Family \"" << fname << "\" already exists but has id set to " << (*it).second << " different from asked famId " << famId << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - fams.insert((*it2).second.begin(),(*it2).second.end()); } - std::vector fams2(fams.begin(),fams.end()); - return getFamilies(meshDimRelToMaxExt,fams2,renum); } -DataArrayInt *MEDFileUMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) +void MEDFileMesh::addGrpOnFamily(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception) { - std::set fams; - for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + std::string grpn(grpName); + std::string famn(famName); + if(grpn.empty() || famn.empty()) + throw INTERP_KERNEL::Exception("MEDFileMesh::addGrpOnFamily : input strings must be non null !"); + std::map >::iterator it=_groups.find(grpn); + if(it==_groups.end()) { - std::map >::const_iterator it2=_groups.find(*it); - if(it2==_groups.end()) - { - std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - fams.insert((*it2).second.begin(),(*it2).second.end()); + _groups[grpn].push_back(famn); + } + else + { + std::vector::iterator it2=std::find((*it).second.begin(),(*it).second.end(),famn); + if(it2==(*it).second.end()) + (*it).second.push_back(famn); } - std::vector fams2(fams.begin(),fams.end()); - return getFamiliesArr(meshDimRelToMaxExt,fams2,renum); } -MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) +void MEDFileMesh::setFamilyInfo(const std::map& info) { - std::vector tmp(1); - tmp[0]=fam; - MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum); - ret->setName(fam); - return ret; + _families=info; } -DataArrayInt *MEDFileUMesh::getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) +void MEDFileMesh::setGroupInfo(const std::map >&info) { - std::vector tmp(1); - tmp[0]=fam; - DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum); - ret->setName(fam); - return ret; + _groups=info; } -MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +int MEDFileMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception) { - if(meshDimRelToMaxExt==1) + std::string oname(name); + std::map::const_iterator it=_families.find(oname); + std::vector fams=getFamiliesNames(); + if(it==_families.end()) { - MEDCouplingAutoRefCountObjectPtr arr=getFamiliesArr(1,fams,renum); - MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New(); - MEDCouplingAutoRefCountObjectPtr c=_coords->selectByTupleId(arr->getConstPointer(),arr->getConstPointer()+arr->getNbOfElems()); - ret->setCoords(c); - ret->incrRef(); + std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :"; + std::copy(fams.begin(),fams.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return (*it).second; +} + +int MEDFileMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception) +{ + if(_families.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::getMaxFamilyId : no families set !"); + int ret=-std::numeric_limits::max(); + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) + { + ret=std::max((*it).second,ret); + } + return ret; +} + +std::vector MEDFileMesh::getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception) +{ + std::vector famIds; + for(std::vector::const_iterator it=famNames.begin();it!=famNames.end();it++) + { + std::map::const_iterator it2=_families.find(*it); + if(it2==_families.end()) + { + std::ostringstream oss; oss << "No such family in mesh \"" << _name << "\" : " << *it; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + famIds.push_back((*it2).second); + } + return famIds; +} + +std::string MEDFileMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception) +{ + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) + if((*it).second==id) + return (*it).first; + std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id; + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +DataArrayInt *MEDFileMesh::getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=grp; + DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum); + ret->setName(grp); + return ret; +} + +DataArrayInt *MEDFileMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::set fams; + for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + { + std::map >::const_iterator it2=_groups.find(*it); + if(it2==_groups.end()) + { + std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + fams.insert((*it2).second.begin(),(*it2).second.end()); + } + std::vector fams2(fams.begin(),fams.end()); + return getFamiliesArr(meshDimRelToMaxExt,fams2,renum); +} + +DataArrayInt *MEDFileMesh::getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=fam; + DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum); + ret->setName(fam); + return ret; +} + +DataArrayInt *MEDFileMesh::getNodeGroupArr(const char *grp, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=grp; + DataArrayInt *ret=getNodeGroupsArr(tmp,renum); + ret->setName(grp); + return ret; +} + +DataArrayInt *MEDFileMesh::getNodeGroupsArr(const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getGroupsArr(1,grps,renum); +} + +DataArrayInt *MEDFileMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=fam; + DataArrayInt *ret=getNodeFamiliesArr(tmp,renum); + ret->setName(fam); + return ret; +} + +DataArrayInt *MEDFileMesh::getNodeFamiliesArr(const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getFamiliesArr(1,fams,renum); +} + +void MEDFileMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps, bool renum) throw(INTERP_KERNEL::Exception) +{ + if(grps.empty()) + return ; + std::set grpsName; + std::vector grpsName2(grps.size()); + int i=0; + + for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++,i++) + { + grpsName.insert((*it)->getName()); + grpsName2[i]=(*it)->getName(); + } + if(grpsName.size()!=grps.size()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !"); + if(grpsName.find(std::string(""))!=grpsName.end()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !"); + int sz=getSizeAtLevel(meshDimRelToMaxExt); + MEDCouplingAutoRefCountObjectPtr fam; + std::vector< std::vector > fidsOfGroups; + if(!renum) + { + fam=DataArrayInt::MakePartition(grps,sz,fidsOfGroups); + } + else + { + std::vector< MEDCouplingAutoRefCountObjectPtr > grps2(grps.size()); + for(unsigned int i=0;isetName(grps[i]->getName().c_str()); + } + std::vector grps3(grps2.begin(),grps2.end()); + fam=DataArrayInt::MakePartition(grps3,sz,fidsOfGroups); + } + int offset=1; + if(!_families.empty()) + offset=getMaxFamilyId()+1; + TranslateFamilyIds(offset,fam,fidsOfGroups); + std::set ids=fam->getDifferentValues(); + appendFamilyEntries(ids,fidsOfGroups,grpsName2); + setFamilyFieldArr(meshDimRelToMaxExt,fam); +} + +/*! + * This method append into '_families' attribute the families whose ids are in 'famIds'. Warning 'famIds' are expected to be ids + * not in '_families'. Groups information are given in parameters in order to give to families representative names. + * For the moment, the two last input parameters are not taken into account. + */ +void MEDFileMesh::appendFamilyEntries(const std::set& famIds, const std::vector< std::vector >& fidsOfGrps, const std::vector& grpNames) +{ + std::map famInv; + for(std::set::const_iterator it=famIds.begin();it!=famIds.end();it++) + { + std::ostringstream oss; + oss << "Family_" << (*it); + _families[oss.str()]=(*it); + famInv[*it]=oss.str(); + } + int i=0; + for(std::vector< std::vector >::const_iterator it1=fidsOfGrps.begin();it1!=fidsOfGrps.end();it1++,i++) + { + for(std::vector::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++) + { + _groups[grpNames[i]].push_back(famInv[*it2]); + } + } +} + +void MEDFileMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector >& famIdsPerGrp) +{ + famArr->applyLin(1,offset,0); + for(std::vector< std::vector >::iterator it1=famIdsPerGrp.begin();it1!=famIdsPerGrp.end();it1++) + std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus(),offset)); +} + +MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + return new MEDFileUMesh(fid,mName,dt,it); +} + +MEDFileUMesh *MEDFileUMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + std::vector ms=MEDLoader::GetMeshNames(fileName); + if(ms.empty()) + { + std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int dt,it; + ParaMEDMEM::MEDCouplingMeshType meshType; + std::string dummy2; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2); + return new MEDFileUMesh(fid,ms.front().c_str(),dt,it); +} + +MEDFileUMesh *MEDFileUMesh::New() +{ + return new MEDFileUMesh; +} + +bool MEDFileUMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const +{ + if(!MEDFileMesh::isEqual(other,eps,what)) + return false; + const MEDFileUMesh *otherC=dynamic_cast(other); + if(!otherC) + { + what="Mesh types differ ! This is unstructured and other is NOT !"; + return false; + } + clearNonDiscrAttributes(); + otherC->clearNonDiscrAttributes(); + const DataArrayDouble *coo1=_coords; + const DataArrayDouble *coo2=otherC->_coords; + if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0)) + { + what="Mismatch of coordinates ! One is defined and not other !"; + return false; + } + if(coo1) + { + bool ret=coo1->isEqual(*coo2,eps); + if(!ret) + { + what="Coords differ !"; + return false; + } + } + const DataArrayInt *famc1=_fam_coords; + const DataArrayInt *famc2=otherC->_fam_coords; + if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0)) + { + what="Mismatch of families arr on nodes ! One is defined and not other !"; + return false; + } + if(famc1) + { + bool ret=famc1->isEqual(*famc2); + if(!ret) + { + what="Families arr on node differ !"; + return false; + } + } + const DataArrayInt *numc1=_num_coords; + const DataArrayInt *numc2=otherC->_num_coords; + if((numc1==0 && numc2!=0) || (numc1!=0 && numc2==0)) + { + what="Mismatch of numbering arr on nodes ! One is defined and not other !"; + return false; + } + if(numc1) + { + bool ret=numc1->isEqual(*numc2); + if(!ret) + { + what="Numbering arr on node differ !"; + return false; + } + } + if(_ms.size()!=otherC->_ms.size()) + { + what="Number of levels differs !"; + return false; + } + std::size_t sz=_ms.size(); + for(std::size_t i=0;i_ms[i]; + if((s1==0 && s2!=0) || (s1!=0 && s2==0)) + { + what="Mismatch of presence of sub levels !"; + return false; + } + if(s1) + { + bool ret=s1->isEqual(s2,eps,what); + if(!ret) + return false; + } + } + std::vector< MEDCouplingAutoRefCountObjectPtr > _ms; + return true; +} + +void MEDFileUMesh::clearNonDiscrAttributes() const +{ + MEDFileMesh::clearNonDiscrAttributes(); + const DataArrayDouble *coo1=_coords; + if(coo1) + ((DataArrayDouble *)coo1)->setName("");//This parameter is not discriminant for comparison + const DataArrayInt *famc1=_fam_coords; + if(famc1) + ((DataArrayInt *)famc1)->setName("");//This parameter is not discriminant for comparison + const DataArrayInt *numc1=_num_coords; + if(numc1) + ((DataArrayInt *)numc1)->setName("");//This parameter is not discriminant for comparison + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) + { + const MEDFileUMeshSplitL1 *tmp=(*it); + if(tmp) + tmp->clearNonDiscrAttributes(); + } +} + +MEDFileUMesh::MEDFileUMesh() +{ +} + +MEDFileUMesh::MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +try + { + loadUMeshFromFile(fid,mName,dt,it); + } +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + MEDFileUMeshL2 loaderl2; + ParaMEDMEM::MEDCouplingMeshType meshType; + int dummy0,dummy1; + std::string dummy2; + int mid=MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2); + if(meshType!=UNSTRUCTURED) + { + std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + loaderl2.loadAll(fid,mid,mName,dt,it); + int lev=loaderl2.getNumberOfLevels(); + _ms.resize(lev); + for(int i=0;i(this))->addFamily(DFT_FAM_NAME,0); + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + std::ostringstream oss; oss << "MEDFileUMesh : error on attempt to write in file : \"" << fileName << "\""; + MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str()); + const DataArrayDouble *coo=_coords; + INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str); + MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str); + int spaceDim=coo?coo->getNumberOfComponents():0; + int mdim=getMeshDimension(); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + for(int i=0;igetInfoOnComponent(i); + std::string c,u; + MEDLoaderBase::splitIntoNameAndUnit(info,c,u); + MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + } + MEDmeshCr(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit); + MEDFileUMeshL2::WriteCoords(fid,maa,_iteration,_order,_time,_coords,_fam_coords,_num_coords); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) + if((const MEDFileUMeshSplitL1 *)(*it)!=0) + (*it)->write(fid,maa,mdim); + MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str); +} + +std::vector MEDFileUMesh::getNonEmptyLevels() const +{ + std::vector ret; + int lev=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--) + if((const MEDFileUMeshSplitL1 *)(*it)!=0) + if(!(*it)->empty()) + ret.push_back(lev); + return ret; +} + +std::vector MEDFileUMesh::getNonEmptyLevelsExt() const +{ + std::vector ret0=getNonEmptyLevels(); + if((const DataArrayDouble *) _coords) + { + std::vector ret(ret0.size()+1); + ret[0]=1; + std::copy(ret0.begin(),ret0.end(),ret.begin()+1); return ret; } - std::vector famIds=getFamiliesIds(fams); + return ret0; +} + +int MEDFileUMesh::getMeshDimension() const +{ + int lev=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++) + if((const MEDFileUMeshSplitL1 *)(*it)!=0) + return (*it)->getMeshDimension()+lev; + throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !"); +} + +int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + { + if(!((const DataArrayDouble *)_coords)) + throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !"); + return _coords->getNumberOfTuples(); + } + return getMeshAtLevSafe(meshDimRelToMaxExt)->getSize(); +} + +const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + { + if(!((const DataArrayInt *)_fam_coords)) + throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamilyFieldAtLevel : no coordinates specified !"); + return _fam_coords; + } const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); - return l1->getFamilyPart(famIds,renum); + return l1->getFamilyField(); } -DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { - std::vector famIds=getFamiliesIds(fams); if(meshDimRelToMaxExt==1) { - MEDCouplingAutoRefCountObjectPtr da=_fam_coords->getIdsEqualList(famIds); - return MEDFileUMeshSplitL1::Renumber(_num_coords,da); + if(!((const DataArrayInt *)_num_coords)) + throw INTERP_KERNEL::Exception("MEDFileUMesh::getNumberFieldAtLevel : no coordinates renum specified !"); + return _num_coords; } const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); - return l1->getFamilyPartArr(famIds,renum); + return l1->getNumberField(); +} + +const DataArrayInt *MEDFileUMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + { + if(!((const DataArrayInt *)_num_coords)) + throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !"); + return _rev_num_coords; + } + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + return l1->getRevNumberField(); } -DataArrayInt *MEDFileUMesh::getNodeGroupArr(const char *grp, bool renum) const throw(INTERP_KERNEL::Exception) +DataArrayDouble *MEDFileUMesh::getCoords() const +{ + MEDCouplingAutoRefCountObjectPtr tmp(_coords); + if((DataArrayDouble *)tmp) + { + tmp->incrRef(); + return tmp; + } + return 0; +} + +MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception) { + synchronizeTinyInfoOnLeaves(); std::vector tmp(1); tmp[0]=grp; - DataArrayInt *ret=getNodeGroupsArr(tmp,renum); + MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum); ret->setName(grp); return ret; } -DataArrayInt *MEDFileUMesh::getNodeGroupsArr(const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) +MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) { - return getGroupsArr(1,grps,renum); + synchronizeTinyInfoOnLeaves(); + std::set fams; + for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + { + std::map >::const_iterator it2=_groups.find(*it); + if(it2==_groups.end()) + { + std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + fams.insert((*it2).second.begin(),(*it2).second.end()); + } + std::vector fams2(fams.begin(),fams.end()); + return getFamilies(meshDimRelToMaxExt,fams2,renum); } -DataArrayInt *MEDFileUMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) +MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) { + synchronizeTinyInfoOnLeaves(); std::vector tmp(1); tmp[0]=fam; - DataArrayInt *ret=getNodeFamiliesArr(tmp,renum); + MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum); ret->setName(fam); return ret; } -DataArrayInt *MEDFileUMesh::getNodeFamiliesArr(const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +{ + synchronizeTinyInfoOnLeaves(); + if(meshDimRelToMaxExt==1) + { + MEDCouplingAutoRefCountObjectPtr arr=getFamiliesArr(1,fams,renum); + MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr c=_coords->selectByTupleId(arr->getConstPointer(),arr->getConstPointer()+arr->getNbOfElems()); + ret->setCoords(c); + ret->incrRef(); + return ret; + } + std::vector famIds=getFamiliesIds(fams); + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + return l1->getFamilyPart(famIds,renum); +} + +DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) { - return getFamiliesArr(1,fams,renum); + std::vector famIds=getFamiliesIds(fams); + if(meshDimRelToMaxExt==1) + { + if((const DataArrayInt *)_fam_coords) + { + MEDCouplingAutoRefCountObjectPtr da=_fam_coords->getIdsEqualList(famIds); + if(renum) + return MEDFileUMeshSplitL1::Renumber(_num_coords,da); + else + { + da->incrRef(); + return da; + } + } + else + throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamiliesArr : no family array specified on nodes !"); + } + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + return l1->getFamilyPartArr(famIds,renum); } MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception) { + synchronizeTinyInfoOnLeaves(); if(meshDimRelToMaxExt==1) { if(!renum) @@ -520,6 +1022,7 @@ MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renu MEDCouplingUMesh *umesh=MEDCouplingUMesh::New(); MEDCouplingAutoRefCountObjectPtr cc=_coords->deepCpy(); umesh->setCoords(cc); + MEDFileUMeshSplitL1::ClearNonDiscrAttributes(umesh); return umesh; } } @@ -527,6 +1030,11 @@ MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renu return l1->getWholeMesh(renum); } +MEDCouplingMesh *MEDFileUMesh::getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtLevel(meshDimRelToMax,false); +} + MEDCouplingUMesh *MEDFileUMesh::getLevel0Mesh(bool renum) const throw(INTERP_KERNEL::Exception) { return getMeshAtLevel(0,renum); @@ -547,20 +1055,6 @@ MEDCouplingUMesh *MEDFileUMesh::getLevelM3Mesh(bool renum) const throw(INTERP_KE return getMeshAtLevel(-3,renum); } -bool MEDFileUMesh::existsFamily(int famId) const -{ - for(std::map::const_iterator it2=_families.begin();it2!=_families.end();it2++) - if((*it2).second==famId) - return true; - return false; -} - -bool MEDFileUMesh::existsFamily(const char *familyName) const -{ - std::string fname(familyName); - return _families.find(fname)!=_families.end(); -} - const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { if(meshDimRelToMaxExt==1) @@ -616,50 +1110,6 @@ void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Excep _fam_coords->fillWithZero(); } -void MEDFileUMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps, bool renum) throw(INTERP_KERNEL::Exception) -{ - if(grps.empty()) - return ; - std::set grpsName; - std::vector grpsName2(grps.size()); - int i=0; - - for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++,i++) - { - grpsName.insert((*it)->getName()); - grpsName2[i]=(*it)->getName(); - } - if(grpsName.size()!=grps.size()) - throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !"); - if(grpsName.find(std::string(""))!=grpsName.end()) - throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !"); - int sz=getSizeAtLevel(meshDimRelToMaxExt); - MEDCouplingAutoRefCountObjectPtr fam; - std::vector< std::vector > fidsOfGroups; - if(!renum) - { - fam=DataArrayInt::MakePartition(grps,sz,fidsOfGroups); - } - else - { - std::vector< MEDCouplingAutoRefCountObjectPtr > grps2(grps.size()); - for(unsigned int i=0;isetName(grps[i]->getName().c_str()); - } - std::vector grps3(grps2.begin(),grps2.end()); - fam=DataArrayInt::MakePartition(grps3,sz,fidsOfGroups); - } - int offset=1; - if(!_families.empty()) - offset=getMaxFamilyId()+1; - TranslateFamilyIds(offset,fam,fidsOfGroups); - std::set ids=fam->getDifferentValues(); - appendFamilyEntries(ids,fidsOfGroups,grpsName2); - setFamilyArr(meshDimRelToMaxExt,fam); -} - void MEDFileUMesh::eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception) { if(meshDimRelToMaxExt==1) @@ -726,22 +1176,6 @@ void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector& } -void MEDFileUMesh::copyFamGrpMapsFrom(const MEDFileUMesh& other) -{ - _groups=other._groups; - _families=other._families; -} - -void MEDFileUMesh::setFamilyInfo(const std::map& info) -{ - _families=info; -} - -void MEDFileUMesh::setGroupInfo(const std::map >&info) -{ - _groups=info; -} - void MEDFileUMesh::setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception) { std::string oldName=getFamilyNameGivenId(id); @@ -859,7 +1293,7 @@ DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector1) - throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyArr : Dimension request is invalid (>1) !"); + throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : Dimension request is invalid (>1) !"); int traducedRk=-meshDimRelToMaxExt; if(traducedRk>=(int)_ms.size()) throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !"); @@ -877,7 +1311,7 @@ void MEDFileUMesh::setFamilyArr(int meshDimRelToMaxExt, DataArrayInt *famArr) return _ms[traducedRk]->setFamilyArr(famArr); } -void MEDFileUMesh::setRenumArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) +void MEDFileUMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) { if(meshDimRelToMaxExt==1) { @@ -897,74 +1331,447 @@ void MEDFileUMesh::setRenumArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) return _ms[traducedRk]->setRenumArr(renumArr); } -void MEDFileUMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector >& famIdsPerGrp) +void MEDFileUMesh::synchronizeTinyInfoOnLeaves() const { - famArr->applyLin(1,offset,0); - for(std::vector< std::vector >::iterator it1=famIdsPerGrp.begin();it1!=famIdsPerGrp.end();it1++) - std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus(),offset)); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) + if((const MEDFileUMeshSplitL1 *)(*it)) + (*it)->synchronizeTinyInfo(*this); } -/*! - * This method append into '_families' attribute the families whose ids are in 'famIds'. Warning 'famIds' are expected to be ids - * not in '_families'. Groups information are given in parameters in order to give to families representative names. - * For the moment, the two last input parameters are not taken into account. - */ -void MEDFileUMesh::appendFamilyEntries(const std::set& famIds, const std::vector< std::vector >& fidsOfGrps, const std::vector& grpNames) +void MEDFileUMesh::computeRevNum() const { - std::map famInv; - for(std::set::const_iterator it=famIds.begin();it!=famIds.end();it++) + if((const DataArrayInt *)_num_coords) { - std::ostringstream oss; - oss << "Family_" << (*it); - _families[oss.str()]=(*it); - famInv[*it]=oss.str(); + int pos; + int maxValue=_num_coords->getMaxValue(pos); + _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1); } - int i=0; - for(std::vector< std::vector >::const_iterator it1=fidsOfGrps.begin();it1!=fidsOfGrps.end();it1++,i++) +} + +MEDFileCMesh *MEDFileCMesh::New() +{ + return new MEDFileCMesh; +} + +MEDFileCMesh *MEDFileCMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + std::vector ms=MEDLoader::GetMeshNames(fileName); + if(ms.empty()) { - for(std::vector::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++) + std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int dt,it; + ParaMEDMEM::MEDCouplingMeshType meshType; + std::string dummy2; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2); + return new MEDFileCMesh(fid,ms.front().c_str(),dt,it); +} + +MEDFileCMesh *MEDFileCMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + return new MEDFileCMesh(fid,mName,dt,it); +} + +bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const +{ + if(!MEDFileMesh::isEqual(other,eps,what)) + return false; + const MEDFileCMesh *otherC=dynamic_cast(other); + if(!otherC) + { + what="Mesh types differ ! This is cartesian and other is NOT !"; + return false; + } + clearNonDiscrAttributes(); + otherC->clearNonDiscrAttributes(); + const MEDCouplingCMesh *coo1=_cmesh; + const MEDCouplingCMesh *coo2=otherC->_cmesh; + if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0)) + { + what="Mismatch of cartesian meshes ! One is defined and not other !"; + return false; + } + if(coo1) + { + bool ret=coo1->isEqual(coo2,eps); + if(!ret) { - _groups[grpNames[i]].push_back(famInv[*it2]); + what="cartesian meshes differ !"; + return false; + } + } + const DataArrayInt *famc1=_fam_nodes; + const DataArrayInt *famc2=otherC->_fam_nodes; + if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0)) + { + what="Mismatch of families arr on nodes ! One is defined and not other !"; + return false; + } + if(famc1) + { + bool ret=famc1->isEqual(*famc2); + if(!ret) + { + what="Families arr on nodes differ !"; + return false; + } + } + famc1=_fam_cells; + famc2=otherC->_fam_cells; + if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0)) + { + what="Mismatch of families arr on cells ! One is defined and not other !"; + return false; + } + if(famc1) + { + bool ret=famc1->isEqual(*famc2); + if(!ret) + { + what="Families arr on cells differ !"; + return false; + } + } + famc1=_num_nodes; + famc2=otherC->_num_nodes; + if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0)) + { + what="Mismatch of numbering arr on nodes ! One is defined and not other !"; + return false; + } + if(famc1) + { + bool ret=famc1->isEqual(*famc2); + if(!ret) + { + what="Numbering arr on nodes differ !"; + return false; + } + } + famc1=_num_cells; + famc2=otherC->_num_cells; + if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0)) + { + what="Mismatch of numbering arr on cells ! One is defined and not other !"; + return false; + } + if(famc1) + { + bool ret=famc1->isEqual(*famc2); + if(!ret) + { + what="Numbering arr on cells differ !"; + return false; } } + return true; } -/*! - * This method appends a new entry in _families attribute. An exception is thrown if either the famId is already - * kept by an another familyName. An exception is thrown if name 'familyName' is alreadyset with a different 'famId'. - */ -void MEDFileUMesh::addFamily(int famId, const char *familyName) throw(INTERP_KERNEL::Exception) +void MEDFileCMesh::clearNonDiscrAttributes() const { - std::string fname(familyName); - std::map::const_iterator it=_families.find(fname); - if(it==_families.end()) + MEDFileMesh::clearNonDiscrAttributes(); + MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_cmesh); + const DataArrayInt *tmp=_fam_nodes; + if(tmp) + (const_cast(tmp))->setName(""); + tmp=_num_nodes; + if(tmp) + (const_cast(tmp))->setName(""); + tmp=_fam_cells; + if(tmp) + (const_cast(tmp))->setName(""); + tmp=_num_cells; + if(tmp) + (const_cast(tmp))->setName(""); +} + +MEDFileCMesh::MEDFileCMesh() +{ +} + +MEDFileCMesh::MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +try + { + loadCMeshFromFile(fid,mName,dt,it); + } +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + MEDFileCMeshL2 loaderl2; + ParaMEDMEM::MEDCouplingMeshType meshType; + int dummy0,dummy1; + std::string dtunit; + int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit); + if(meshType!=CARTESIAN) { - for(std::map::const_iterator it2=_families.begin();it2!=_families.end();it2++) - if((*it2).second==famId) - { - std::ostringstream oss; - oss << "MEDFileUMesh::addFamily : Family \"" << (*it2).first << "\" already exists with specified id : " << famId << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - _families[fname]=famId; + std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + loaderl2.loadAll(fid,mid,mName,dt,it); + MEDCouplingCMesh *mesh=loaderl2.getMesh(); + mesh->incrRef(); + _cmesh=mesh; + setName(loaderl2.getName()); + setDescription(loaderl2.getDescription()); + setIteration(loaderl2.getIteration()); + setOrder(loaderl2.getOrder()); + setTimeValue(loaderl2.getTime()); + setTimeUnit(loaderl2.getTimeUnit()); + MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups); + med_bool chgt=MED_FALSE,trsf=MED_FALSE; + int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _fam_nodes=DataArrayInt::New(); + _fam_nodes->alloc(nbOfElt,1); + MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer()); + } + nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _num_nodes=DataArrayInt::New(); + _num_nodes->alloc(nbOfElt,1); + MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer()); + } + int spaceDim=mesh->getSpaceDimension(); + med_geometry_type geoTypeReq=MED_NONE; + switch(spaceDim) + { + case 3: + geoTypeReq=MED_HEXA8; + break; + case 2: + geoTypeReq=MED_QUAD4; + break; + case 1: + geoTypeReq=MED_SEG2; + break; + case 0: + geoTypeReq=MED_POINT1; + break; + default: + throw INTERP_KERNEL::Exception("Invalid spacedim detected for cartesian mesh ! Must be in (1,2,3) !"); + } + nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _fam_cells=DataArrayInt::New(); + _fam_cells->alloc(nbOfElt,1); + MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_fam_cells->getPointer()); + } + nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _num_cells=DataArrayInt::New(); + _num_cells->alloc(nbOfElt,1); + MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer()); + } +} + +const MEDCouplingCMesh *MEDFileCMesh::getMesh() const +{ + synchronizeTinyInfoOnLeaves(); + return _cmesh; +} + +MEDCouplingMesh *MEDFileCMesh::getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMax!=0) + throw INTERP_KERNEL::Exception("MEDFileCMesh does not support multi level for mesh 0 expected as input !"); + const MEDCouplingCMesh *m=getMesh(); + if(m) + m->incrRef(); + return const_cast(m); +} + +void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) +{ + if(m) + m->incrRef(); + _cmesh=m; +} + +void MEDFileCMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + if(_name.empty()) + throw INTERP_KERNEL::Exception("MEDFileCMesh : name is empty. MED file ask for a NON EMPTY name !"); + if(!existsFamily(0)) + (const_cast(this))->addFamily(DFT_FAM_NAME,0); + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + std::ostringstream oss; oss << "MEDFileCMesh : error on attempt to write in file : \"" << fileName << "\""; + MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str()); + INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str); + MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str); + MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str); + int spaceDim=_cmesh->getSpaceDimension(); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + for(int i=0;igetCoordsAt(i)->getInfoOnComponent(0)); + std::string c,u; + MEDLoaderBase::splitIntoNameAndUnit(info,c,u); + MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + } + MEDmeshCr(fid,maa,spaceDim,spaceDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit); + MEDmeshGridTypeWr(fid,maa,MED_CARTESIAN_GRID); + for(int i=0;igetCoordsAt(i); + MEDmeshGridIndexCoordinateWr(fid,maa,_iteration,_order,_time,i+1,da->getNumberOfTuples(),da->getConstPointer()); } + if((const DataArrayInt *)_fam_cells) + MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_CELL,MED_GEO_ALL,_fam_cells->getNumberOfTuples(),_fam_cells->getConstPointer()); + if((const DataArrayInt *)_fam_nodes) + MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_fam_nodes->getNumberOfTuples(),_fam_nodes->getConstPointer()); + // + MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str); +} + +int MEDFileCMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : Only available for levels 0 or 1 !"); + if(!((const MEDCouplingCMesh *)_cmesh)) + throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : No cartesian mesh set !"); + if(meshDimRelToMaxExt==0) + return _cmesh->getNumberOfCells(); else + return _cmesh->getNumberOfNodes(); +} + +void MEDFileCMesh::synchronizeTinyInfoOnLeaves() const +{ + const MEDCouplingCMesh *cmesh=_cmesh; + (const_cast(cmesh))->setName(_name.c_str()); + (const_cast(cmesh))->setDescription(_desc_name.c_str()); + (const_cast(cmesh))->setTime(_time,_iteration,_order); + (const_cast(cmesh))->setTimeUnit(_dt_unit.c_str()); +} + +DataArrayInt *MEDFileCMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : Only available for levels 0 or 1 !"); + std::vector famIds=getFamiliesIds(fams); + if(meshDimRelToMaxExt==1) { - if((*it).second!=famId) + if((const DataArrayInt *)_fam_nodes) { - std::ostringstream oss; - oss << "MEDFileUMesh::addFamily : Family \"" << fname << "\" already exists but has id set to " << (*it).second << " different from asked famId " << famId << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + MEDCouplingAutoRefCountObjectPtr da=_fam_nodes->getIdsEqualList(famIds); + if(renum) + return MEDFileUMeshSplitL1::Renumber(_num_nodes,da); + else + { + da->incrRef(); + return da; + } + } + else + throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on nodes !"); + } + else + { + if((const DataArrayInt *)_fam_cells) + { + MEDCouplingAutoRefCountObjectPtr da=_fam_cells->getIdsEqualList(famIds); + if(renum) + return MEDFileUMeshSplitL1::Renumber(_num_cells,da); + else + { + da->incrRef(); + return da; + } } + else + throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on cells !"); } } -void MEDFileUMesh::computeRevNum() const +void MEDFileCMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception) { - if((const DataArrayInt *)_num_coords) + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !"); + if(famArr) + famArr->incrRef(); + if(meshDimRelToMaxExt==0) + _fam_cells=famArr; + else + _fam_nodes=famArr; +} + +void MEDFileCMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !"); + if(renumArr) + renumArr->incrRef(); + if(meshDimRelToMaxExt==0) + _num_cells=renumArr; + else + _num_nodes=renumArr; +} + +const DataArrayInt *MEDFileCMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamilyFieldAtLevel : Only available for levels 0 or 1 !"); + if(meshDimRelToMaxExt==0) + return _fam_cells; + else + return _fam_nodes; +} + +const DataArrayInt *MEDFileCMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileCMesh::getNumberFieldAtLevel : Only available for levels 0 or 1 !"); + if(meshDimRelToMaxExt==0) + return _num_cells; + else + return _num_nodes; +} + +const DataArrayInt *MEDFileCMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : Only available for levels 0 or 1 !"); + if(meshDimRelToMaxExt==0) { - int pos; - int maxValue=_num_coords->getMaxValue(pos); - _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1); + if((const DataArrayInt *)_num_cells) + { + int pos; + int maxValue=_num_cells->getMaxValue(pos); + _rev_num_cells=_num_cells->invertArrayN2O2O2N(maxValue+1); + return _rev_num_cells; + } + else + throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no cell renumbering for a request on reverse numbering !"); + } + else + { + if((const DataArrayInt *)_num_nodes) + { + int pos; + int maxValue=_num_nodes->getMaxValue(pos); + _rev_num_nodes=_num_nodes->invertArrayN2O2O2N(maxValue+1); + return _rev_num_nodes; + } + else + throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no node renumbering for a request on reverse numbering !"); } } diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 64b05dfa6..98b42f6de 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -29,81 +29,130 @@ namespace ParaMEDMEM class MEDFileMesh : public RefCountObject { public: - static MEDFileMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + static MEDFileMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); + virtual bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; + virtual void clearNonDiscrAttributes() const; void setName(const char *name) { _name=name; } const char *getName() const { return _name.c_str(); } void setUnivName(const char *name) { _univ_name=name; } const char *getUnivName() const { return _univ_name.c_str(); } void setDescription(const char *name) { _desc_name=name; } const char *getDescription() const { return _desc_name.c_str(); } + void setOrder(int order) { _order=order; } + int getOrder() const { return _order; } + void setIteration(int it) { _iteration=it; } + int getIteration() const { return _iteration; } + void setTimeValue(double time) { _time=time; } + void setTime(double time, int dt, int it) { _time=time; _iteration=dt; _order=it; } + double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; } + double getTimeValue() const { return _time; } + void setTimeUnit(const char *unit) { _dt_unit=unit; } + const char *getTimeUnit() const { return _dt_unit.c_str(); } + virtual void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) = 0; + virtual int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0; + virtual MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) = 0; + // + bool areFamsEqual(const MEDFileMesh *other, std::string& what) const; + bool areGrpsEqual(const MEDFileMesh *other, std::string& what) const; + bool existsFamily(int famId) const; + bool existsFamily(const char *familyName) const; + void setFamilyId(const char *familyName, int id); + void addFamily(const char *familyName, int id) throw(INTERP_KERNEL::Exception); + void addGrpOnFamily(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception); + void setFamilyInfo(const std::map& info); + void setGroupInfo(const std::map >&info); + void copyFamGrpMapsFrom(const MEDFileMesh& other); + const std::map& getFamilyInfo() const { return _families; } + const std::map >& getGroupInfo() const { return _groups; } + std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getGroupsNames() const; + std::vector getFamiliesNames() const; + void removeGroup(const char *name) throw(INTERP_KERNEL::Exception); + void removeFamily(const char *name) throw(INTERP_KERNEL::Exception); + void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception); + int getMaxFamilyId() const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception); + std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception); + // + virtual void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) throw(INTERP_KERNEL::Exception); + virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception) = 0; + virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) = 0; + virtual const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0; + virtual const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0; + virtual const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0; + virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception) = 0; + virtual DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getNodeGroupsArr(const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getNodeFamiliesArr(const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); protected: + MEDFileMesh(); + virtual void synchronizeTinyInfoOnLeaves() const = 0; + virtual void appendFamilyEntries(const std::set& famIds, const std::vector< std::vector >& fidsOfGrps, const std::vector& grpNames); + static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector >& famIdsPerGrp); + protected: + int _order; + int _iteration; + double _time; + std::string _dt_unit; std::string _name; std::string _univ_name; std::string _desc_name; + protected: + std::map > _groups; + std::map _families; + protected://policies on write + int _too_long_str; + int _zipconn_pol; + public: + static const char DFT_FAM_NAME[]; }; class MEDFileUMesh : public MEDFileMesh { + friend class MEDFileMesh; public: - static MEDFileUMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + static MEDFileUMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); static MEDFileUMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileUMesh *New(); + bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; + void clearNonDiscrAttributes() const; ~MEDFileUMesh(); // - void removeGroup(const char *name) throw(INTERP_KERNEL::Exception); - void removeFamily(const char *name) throw(INTERP_KERNEL::Exception); - void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); - void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); - // void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); - int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception); - int getMaxFamilyId() const throw(INTERP_KERNEL::Exception); - std::vector getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception); - std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception); int getMeshDimension() const; int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); - std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); - std::vector getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception); - std::vector getGroupsNames() const; - std::vector getFamiliesNames() const; std::vector getNonEmptyLevels() const; std::vector getNonEmptyLevelsExt() const; DataArrayDouble *getCoords() const; MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); - DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); - DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getFamily(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); - DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getFamilies(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); - DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); - DataArrayInt *getNodeGroupsArr(const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); - DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); - DataArrayInt *getNodeFamiliesArr(const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getMeshAtLevel(int meshDimRelToMaxExt, bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getLevel0Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getLevelM2Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); - const std::map& getFamilyInfo() const { return _families; } - const std::map >& getGroupInfo() const { return _groups; } - bool existsFamily(int famId) const; - bool existsFamily(const char *familyName) const; // - void copyFamGrpMapsFrom(const MEDFileUMesh& other); - void setFamilyInfo(const std::map& info); - void setGroupInfo(const std::map >&info); void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception); void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); - void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) throw(INTERP_KERNEL::Exception); void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception); void setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector& grpNames, bool renum=false) throw(INTERP_KERNEL::Exception); - void setFamilyArr(int meshDimRelToMaxExt, DataArrayInt *famArr); - void setRenumArr(int meshDimRelToMaxExt, DataArrayInt *renumArr); + void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception); + void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception); void addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception); void setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); void setMeshAtLevelOld(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); @@ -111,32 +160,58 @@ namespace ParaMEDMEM void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception); void optimizeFamilies() throw(INTERP_KERNEL::Exception); - void addFamily(int famId, const char *familyName) throw(INTERP_KERNEL::Exception); private: MEDFileUMesh(); - MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); + void loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); const MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception); void checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); DataArrayDouble *checkMultiMesh(const std::vector& ms) const throw(INTERP_KERNEL::Exception); - void appendFamilyEntries(const std::set& famIds, const std::vector< std::vector >& fidsOfGrps, const std::vector& grpNames); void computeRevNum() const; - static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector >& famIdsPerGrp); + void synchronizeTinyInfoOnLeaves() const; private: - std::map > _groups; - std::map _families; std::vector< MEDCouplingAutoRefCountObjectPtr > _ms; MEDCouplingAutoRefCountObjectPtr _coords; MEDCouplingAutoRefCountObjectPtr _fam_coords; MEDCouplingAutoRefCountObjectPtr _num_coords; mutable MEDCouplingAutoRefCountObjectPtr _rev_num_coords; - int _too_long_str; - int _zipconn_pol; }; class MEDFileCMesh : public MEDFileMesh { + friend class MEDFileMesh; + public: + static MEDFileCMesh *New(); + static MEDFileCMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); + bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; + void clearNonDiscrAttributes() const; + const MEDCouplingCMesh *getMesh() const; + MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + void setMesh(MEDCouplingCMesh *m); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); + void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception); + void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception); + const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + private: + MEDFileCMesh(); + void synchronizeTinyInfoOnLeaves() const; + MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); + void loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); + private: + MEDCouplingAutoRefCountObjectPtr _cmesh; + MEDCouplingAutoRefCountObjectPtr _fam_nodes; + MEDCouplingAutoRefCountObjectPtr _num_nodes; + MEDCouplingAutoRefCountObjectPtr _fam_cells; + MEDCouplingAutoRefCountObjectPtr _num_cells; + mutable MEDCouplingAutoRefCountObjectPtr _rev_num_nodes; + mutable MEDCouplingAutoRefCountObjectPtr _rev_num_cells; }; } diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index 9fa3dfbe0..2e512a448 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -24,25 +24,27 @@ #include "InterpKernelAutoPtr.hxx" #include "CellModel.hxx" -extern med_geometrie_element typmai3[32]; +extern med_geometry_type typmai3[32]; using namespace ParaMEDMEM; -MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2) +MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType geoElt2) { - med_entite_maillage whichEntity; - if(!isExisting(fid,mName,geoElt,whichEntity)) + med_entity_type whichEntity; + if(!isExisting(fid,mName,dt,it,geoElt,whichEntity)) return 0; - return new MEDFileUMeshPerType(fid,mName,mdim,geoElt,geoElt2,whichEntity); + return new MEDFileUMeshPerType(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity); } -bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity) +bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, int dt, int it, med_geometry_type geoElt, med_entity_type& whichEntity) { - static const med_entite_maillage entities[3]={MED_MAILLE,MED_FACE,MED_ARETE}; + static const med_entity_type entities[1]={MED_CELL}; int nbOfElt=0; - for(int i=0;i<3;i++) + for(int i=0;i<1;i++) { - int tmp=MEDnEntMaa(fid,(char *)mName,MED_CONN,entities[i],geoElt,MED_NOD); + med_bool changement,transformation; + int tmp=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoElt,MED_CONNECTIVITY,MED_NODAL, + &changement,&transformation); if(tmp>nbOfElt) { nbOfElt=tmp; @@ -58,41 +60,42 @@ int MEDFileUMeshPerType::getDim() const return cm.getDimension(); } -MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, - med_entite_maillage entity):_type(type),_entity(entity) +MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entity_type entity):_type(type),_entity(entity) { - int curNbOfElem=MEDnEntMaa(fid,(char *)mName,MED_CONN,entity,geoElt,MED_NOD); + med_bool changement,transformation; + int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL, + &changement,&transformation); if(type!=INTERP_KERNEL::NORM_POLYGON && type!=INTERP_KERNEL::NORM_POLYHED) { - loadFromStaticType(fid,mName,mdim,curNbOfElem,geoElt,type,entity); + loadFromStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity); return; } if(type==INTERP_KERNEL::NORM_POLYGON) { - loadPolyg(fid,mName,mdim,curNbOfElem,geoElt,entity); + loadPolyg(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity); return; } //if(type==INTERP_KERNEL::NORM_POLYHED) - loadPolyh(fid,mName,mdim,curNbOfElem,geoElt,entity); + loadPolyh(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity); } -void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, - med_entite_maillage entity) +void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entity_type entity) { _conn=DataArrayInt::New(); int nbOfNodesPerCell=(geoElt%100); _conn->alloc((nbOfNodesPerCell+1)*curNbOfElem,1); _conn_index=DataArrayInt::New(); _conn_index->alloc(curNbOfElem+1,1); - int *connTab=new int[(nbOfNodesPerCell)*curNbOfElem]; + INTERP_KERNEL::AutoPtr connTab=new int[(nbOfNodesPerCell)*curNbOfElem]; _num=DataArrayInt::New(); _num->alloc(curNbOfElem,1); - char *noms=new char[MED_TAILLE_PNOM*curNbOfElem+1]; - med_booleen inoele, inuele; _fam=DataArrayInt::New(); _fam->alloc(curNbOfElem,1); - MEDelementsLire(fid,(char *)mName,mdim,connTab,MED_FULL_INTERLACE,noms,&inoele,_num->getPointer(),&inuele,_fam->getPointer(),curNbOfElem,entity,geoElt,MED_NOD); - delete [] noms; + med_bool withname=MED_FALSE,withnumber=MED_FALSE,withfam=MED_FALSE; + INTERP_KERNEL::AutoPtr noms=new char[MED_SNAME_SIZE*curNbOfElem+1]; + MEDmeshElementRd(fid,mName,dt,it,entity,geoElt,MED_NODAL,MED_FULL_INTERLACE,connTab,&withname,noms,&withnumber,_num->getPointer(),&withfam,_fam->getPointer()); int *w1=_conn->getPointer(); int *w2=_conn_index->getPointer(); *w2++=0; @@ -103,16 +106,15 @@ void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int w1=std::transform(wi,wi+nbOfNodesPerCell,w1,std::bind2nd(std::plus(),-1)); *w2=w2[-1]+nbOfNodesPerCell+1; } - delete [] connTab; - if(!inuele) + if(!withnumber) _num=0; } -void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, - med_entite_maillage entity) +void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, int arraySize, med_geometry_type geoElt, + med_entity_type entity) { - med_int arraySize; - MEDpolygoneInfo(fid,(char *)mName,entity,MED_NOD,&arraySize); + med_bool changement,transformation; + med_int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1; _conn_index=DataArrayInt::New(); _conn_index->alloc(curNbOfElem+1,1); _conn=DataArrayInt::New(); @@ -121,8 +123,8 @@ void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int mdim, in _num->alloc(curNbOfElem,1); _fam=DataArrayInt::New(); _fam->alloc(curNbOfElem,1); - int *locConn=new int[arraySize]; - MEDpolygoneConnLire(fid,(char *)mName,_conn_index->getPointer(),curNbOfElem+1,locConn,entity,MED_NOD); + INTERP_KERNEL::AutoPtr locConn=new int[arraySize]; + MEDmeshPolygonRd(fid,mName,dt,it,MED_CELL,MED_NODAL,_conn_index->getPointer(),locConn); int *w1=_conn->getPointer(); int *w2=_conn_index->getPointer(); const int *wi=locConn; @@ -133,24 +135,41 @@ void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int mdim, in *w2=*w2-1+i; } *w2=*w2-1+curNbOfElem; - delete [] locConn; - MEDfamLire(fid,(char *)mName,_fam->getPointer(),curNbOfElem,entity,MED_POLYGONE); - if(MEDnumLire(fid,(char *)mName,_num->getPointer(),curNbOfElem,entity,MED_POLYGONE)!=0) + if(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYGON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,MED_POLYGON,_fam->getPointer())!=0) + std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); + } + else + std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); + if(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYGON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,MED_POLYGON,_num->getPointer())!=0) + _num=0; + } + else _num=0; } -void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, - med_entite_maillage entity) +void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt, + med_entity_type entity) { - med_int indexFaceLgth,connFaceLgth; - MEDpolyedreInfo(fid,(char*)mName,MED_NOD,&indexFaceLgth,&connFaceLgth); - int *index=new int[curNbOfElem+1]; - int *indexFace=new int[indexFaceLgth]; - int *locConn=new int[connFaceLgth]; + med_bool changement,transformation; + med_int indexFaceLgth=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation); + int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1; + INTERP_KERNEL::AutoPtr index=new int[curNbOfElem+1]; + INTERP_KERNEL::AutoPtr indexFace=new int[indexFaceLgth]; + INTERP_KERNEL::AutoPtr locConn=new int[connFaceLgth]; _fam=DataArrayInt::New(); _fam->alloc(curNbOfElem,1); - MEDpolyedreConnLire(fid,(char *)mName,index,curNbOfElem+1,indexFace,indexFaceLgth,locConn,MED_NOD); - MEDfamLire(fid,(char *)mName,_fam->getPointer(),curNbOfElem,MED_MAILLE,MED_POLYEDRE); + MEDmeshPolyhedronRd(fid,mName,dt,it,MED_CELL,MED_NODAL,index,indexFace,locConn); + if(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,_fam->getPointer())!=0) + std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); + } + else + std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); int arraySize=connFaceLgth; for(int i=0;i(),-1)); } } - delete [] index; - delete [] locConn; - delete [] indexFace; _num=DataArrayInt::New(); _num->alloc(curNbOfElem,1); - if(MEDnumLire(fid,(char *)mName,_num->getPointer(),curNbOfElem,MED_MAILLE,MED_POLYEDRE)!=0) + if(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,MED_POLYHEDRON,_num->getPointer())!=0) + _num=0; + } + else _num=0; } @@ -186,9 +207,11 @@ void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const int nbOfCells=m->getNumberOfCells(); if(nbOfCells<1) return ; + int dt,it; + double timm=m->getTime(dt,it); INTERP_KERNEL::NormalizedCellType ikt=m->getTypeOfCell(0); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(ikt); - med_geometrie_element curMedType=typmai3[(int)ikt]; + med_geometry_type curMedType=typmai3[(int)ikt]; const int *conn=m->getNodalConnectivity()->getConstPointer(); const int *connI=m->getNodalConnectivityIndex()->getConstPointer(); if(ikt!=INTERP_KERNEL::NORM_POLYGON && ikt!=INTERP_KERNEL::NORM_POLYHED) @@ -198,7 +221,7 @@ void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const int *w=tab; for(int i=0;i(),1)); - MEDconnEcr(fid,(char *)mname,mdim,tab,MED_FULL_INTERLACE,nbOfCells,MED_MAILLE,curMedType,MED_NOD); + MEDmeshElementConnectivityWr(fid,mname,dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfCells,tab); } else { @@ -213,7 +236,7 @@ void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const wI[1]=wI[0]+connI[i+1]-connI[i]-1; w=std::transform(conn+connI[i]+1,conn+connI[i+1],w,std::bind2nd(std::plus(),1)); } - MEDpolygoneConnEcr(fid,(char *)mname,tab1,nbOfCells,tab2,MED_MAILLE,MED_NOD); + MEDmeshPolygonWr(fid,mname,dt,it,timm,MED_CELL,MED_NODAL,nbOfCells+1,tab1,tab2); } else { @@ -242,12 +265,11 @@ void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const } w1[1]=w1[0]+nbOfFaces; } - MEDpolyedreConnEcr(fid,(char *)mname,tab1,nbOfCells+1,tab2,nbOfFaces+1, - bigtab,MED_NOD); + MEDmeshPolyhedronWr(fid,mname,dt,it,timm,MED_CELL,MED_NODAL,nbOfCells+1,tab1,nbOfFaces+1,tab2,bigtab); } } if(fam) - MEDfamEcr(fid,(char *)mname,(int *)fam->getConstPointer(),nbOfCells,MED_MAILLE,curMedType); + MEDmeshEntityFamilyNumberWr(fid,mname,dt,it,MED_CELL,curMedType,nbOfCells,fam->getConstPointer()); if(num) - MEDnumEcr(fid,(char *)mname,(int *)num->getConstPointer(),nbOfCells,MED_MAILLE,curMedType); + MEDmeshEntityNumberWr(fid,mname,dt,it,MED_CELL,curMedType,nbOfCells,num->getConstPointer()); } diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx index 732ca2b43..ff79d1bbc 100644 --- a/src/MEDLoader/MEDFileMeshElt.hxx +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -37,8 +37,8 @@ namespace ParaMEDMEM class MEDFileUMeshPerType : public RefCountObject { public: - static MEDFileUMeshPerType *New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2); - static bool isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity); + static MEDFileUMeshPerType *New(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType geoElt2); + static bool isExisting(med_idt fid, const char *mName, int dt, int it, med_geometry_type geoElt, med_entity_type& whichEntity); int getDim() const; const DataArrayInt *getNodal() const { return _conn; } const DataArrayInt *getNodalIndex() const { return _conn_index; } @@ -46,21 +46,21 @@ namespace ParaMEDMEM const DataArrayInt *getNum() const { return _num; } static void write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num); private: - MEDFileUMeshPerType(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, - med_entite_maillage entity); - void loadFromStaticType(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, - med_entite_maillage entity); - void loadPolyg(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, - med_entite_maillage entity); - void loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, - med_entite_maillage entity); + MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entity_type entity); + void loadFromStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entity_type entity); + void loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, int arraySize, med_geometry_type geoElt, + med_entity_type entity); + void loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt, + med_entity_type entity); private: MEDCouplingAutoRefCountObjectPtr _conn; MEDCouplingAutoRefCountObjectPtr _conn_index; MEDCouplingAutoRefCountObjectPtr _num; MEDCouplingAutoRefCountObjectPtr _fam; INTERP_KERNEL::NormalizedCellType _type; - med_entite_maillage _entity; + med_entity_type _entity; }; } diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index e0e7840f4..83caf3aa2 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -18,6 +18,7 @@ // #include "MEDFileMeshLL.hxx" +#include "MEDFileMesh.hxx" #include "MEDLoaderBase.hxx" #include "MEDCouplingUMesh.hxx" @@ -26,108 +27,37 @@ #include -extern med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2]; -extern INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2]; -extern med_geometrie_element typmainoeud[1]; +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; -MEDFileMeshL2::MEDFileMeshL2():_name(MED_TAILLE_NOM),_description(MED_TAILLE_DESC) +MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_dt_unit(MED_LNAME_SIZE) { } -MEDFileUMeshL2::MEDFileUMeshL2() -{ -} - -void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName) -{ - _name.set(mName); - med_maillage type_maillage; - med_int Mdim; - if(MEDmaaInfo(fid,mId,(char *)mName,&Mdim,&type_maillage,_description.getPointer())!=0) - throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !"); - if(type_maillage!=MED_NON_STRUCTURE) - throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !"); - loadConnectivity(fid,Mdim,mName); - loadCoords(fid,mId,Mdim,mName); -} - -void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const char *mName) -{ - _per_type_mesh.resize(1); - _per_type_mesh[0].clear(); - for(int j=0;jalloc(nCoords,spaceDim); - double *coordsPtr=_coords->getPointer(); - med_repere repere; - char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); - char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); - MEDcoordLire(fid,(char *)mName,spaceDim,coordsPtr,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit); - _fam_coords=DataArrayInt::New(); - _fam_coords->alloc(nCoords,1); - _num_coords=DataArrayInt::New(); - _num_coords->alloc(nCoords,1); - MEDfamLire(fid,(char *)mName,_fam_coords->getPointer(),nCoords,MED_NOEUD,MED_NONE); - if(MEDnumLire(fid,(char *)mName,_num_coords->getPointer(),nCoords,MED_NOEUD,MED_NONE)!=0) - _num_coords=0; - for(int i=0;isetInfoOnComponent(i,info.c_str()); - } - delete [] comp; - delete [] unit; -} - -void MEDFileUMeshL2::sortTypes() +int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const char *mname, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception) { - std::set mdims; - std::vector< MEDCouplingAutoRefCountObjectPtr > tmp(_per_type_mesh[0]); - _per_type_mesh.clear(); - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=tmp.begin();it!=tmp.end();it++) - mdims.insert((*it)->getDim()); - if(mdims.empty()) - return; - int mdim=*mdims.rbegin(); - _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++) - if((*it)->getDim()==dim-1) - elt.push_back(*it); - } -} - -int MEDFileUMeshL2::getMeshIdFromName(med_idt fid, const char *mname) throw(INTERP_KERNEL::Exception) -{ - med_maillage type_maillage; - char maillage_description[MED_TAILLE_DESC+1]; - med_int dim; - char nommaa[MED_TAILLE_NOM+1]; - med_int n=MEDnMaa(fid); + 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_sorting_type stype; std::vector ms; - for(int i=0;i axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE); + 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) @@ -143,38 +73,106 @@ int MEDFileUMeshL2::getMeshIdFromName(med_idt fid, const char *mname) throw(INTE std::copy(ms.begin(),ms.end(),std::ostream_iterator(oss,", ")); throw INTERP_KERNEL::Exception(oss.str().c_str()); } + switch(type_maillage) + { + case MED_UNSTRUCTURED_MESH: + meshType=UNSTRUCTURED; + break; + case MED_STRUCTURED_MESH: + meshType=CARTESIAN; + break; + default: + throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !"); + } + med_int numdt,numit; + med_float dtt; + MEDmeshComputationStepInfo(fid,mname,1,&numdt,&numit,&dtt); + dt=numdt; it=numit; return ret; } -void MEDFileUMeshL2::readFamiliesAndGrps(med_idt fid, const char *meshName, std::map& fams, std::map >& grps) +double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const char *mName, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception) { - char nomfam[MED_TAILLE_NOM+1]; + bool found=false; + med_int numdt,numit; + med_float dtt; + std::vector< std::pair > p(nstep); + for(int i=0;i(numdt,numit); + found=(numdt==dt) && (numit==numit); + } + if(!found) + { + std::ostringstream oss; oss << "No such iteration=" << dt << ",order=" << it << " numbers found for mesh '" << mName << "' ! "; + oss << "Possibilities are : "; + for(int i=0;i MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception) +{ + med_mesh_type type_maillage; + med_int spaceDim; + 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); + 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 !"); + switch(type_maillage) + { + case MED_UNSTRUCTURED_MESH: + meshType=UNSTRUCTURED; + break; + case MED_STRUCTURED_MESH: + meshType=CARTESIAN; + break; + default: + throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !"); + } + // + std::vector infosOnComp(naxis); + for(int i=0;i& fams, std::map >& grps) +{ + char nomfam[MED_NAME_SIZE+1]; med_int numfam; - int nfam=MEDnFam(fid,(char *)meshName); + int nfam=MEDnFamily(fid,meshName); 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,i+1,nomfam,attide,attval,attdes,&numfam,gro); + std::string famName=MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE); fams[famName]=numfam; for(int j=0;j& fams, const std::map >& grps, int tooLongStrPol) +void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const char *mname, const std::map& fams, const std::map >& grps, int tooLongStrPol) { for(std::map::const_iterator it=fams.begin();it!=fams.end();it++) { @@ -185,35 +183,104 @@ void MEDFileUMeshL2::writeFamiliesAndGrps(med_idt fid, const char *mname, const grpsOfFam.push_back((*it1).first); } int ngro=grpsOfFam.size(); - INTERP_KERNEL::AutoPtr groName=MEDLoaderBase::buildEmptyString(MED_TAILLE_LNOM*ngro); + 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::safeStrCpy((*it2).c_str(),MED_TAILLE_LNOM-1,groName+i*MED_TAILLE_LNOM,tooLongStrPol); - INTERP_KERNEL::AutoPtr famName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_TAILLE_NOM,famName,tooLongStrPol); - MEDfamCr(fid,(char *)mname,famName,(*it).second,0,0,0,0,groName,ngro); + MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,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,famName,(*it).second,ngro,groName); + ret++; } } -void MEDFileUMeshL2::writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords) +MEDFileUMeshL2::MEDFileUMeshL2() { - if(!coords) - return ; - int spaceDim=coords->getNumberOfComponents(); - INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); - INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); +} + +void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, int it) +{ + _name.set(mName); + int nstep; + int Mdim; + ParaMEDMEM::MEDCouplingMeshType meshType; + std::vector infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim); + 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); + _iteration=dt; + _order=it; + loadConnectivity(fid,Mdim,mName,dt,it);//to improve check (dt,it) coherency + loadCoords(fid,mId,infosOnComp,mName,dt,it); +} + +void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it) +{ + _per_type_mesh.resize(1); + _per_type_mesh[0].clear(); + for(int j=0;j& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + int spaceDim=infosOnComp.size(); + med_bool changement,transformation; + int nCoords=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation); + _coords=DataArrayDouble::New(); + _coords->alloc(nCoords,spaceDim); + double *coordsPtr=_coords->getPointer(); + MEDmeshNodeCoordinateRd(fid,mName,dt,it,MED_FULL_INTERLACE,coordsPtr); + _fam_coords=DataArrayInt::New(); + _fam_coords->alloc(nCoords,1); + _num_coords=DataArrayInt::New(); + _num_coords->alloc(nCoords,1); + if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) + MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()); + else + _fam_coords=0; + if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) + MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()); + else + _num_coords=0; for(int i=0;isetInfoOnComponent(i,infosOnComp[i].c_str()); +} + +void MEDFileUMeshL2::sortTypes() +{ + std::set mdims; + std::vector< MEDCouplingAutoRefCountObjectPtr > tmp(_per_type_mesh[0]); + _per_type_mesh.clear(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=tmp.begin();it!=tmp.end();it++) + mdims.insert((*it)->getDim()); + if(mdims.empty()) + return; + int mdim=*mdims.rbegin(); + _per_type_mesh.resize(mdim+1); + for(int dim=mdim+1;dim!=0;dim--) { - std::string info=coords->getInfoOnComponent(i); - std::string c,u; - MEDLoaderBase::splitIntoNameAndUnit(info,c,u); - MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo - MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + std::vector< MEDCouplingAutoRefCountObjectPtr >& elt=_per_type_mesh[mdim+1-dim]; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=tmp.begin();it!=tmp.end();it++) + if((*it)->getDim()==dim-1) + elt.push_back(*it); } - MEDcoordEcr(fid,(char *)mname,spaceDim,coords->getPointer(),MED_FULL_INTERLACE,coords->getNumberOfTuples(),MED_CART,comp,unit); - MEDfamEcr(fid,(char *)mname,famCoords->getPointer(),famCoords->getNumberOfTuples(),MED_NOEUD,MED_NONE); +} + +void MEDFileUMeshL2::WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords) +{ + if(!coords) + return ; + MEDmeshNodeCoordinateWr(fid,mname,dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getPointer()); + if(famCoords) + MEDmeshEntityFamilyNumberWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getPointer()); if(numCoords) - MEDnumEcr(fid,(char *)mname,numCoords->getPointer(),numCoords->getNumberOfTuples(),MED_NOEUD,MED_NONE); + MEDmeshEntityNumberWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getPointer()); } bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const @@ -232,6 +299,56 @@ bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const return true; } +MEDFileCMeshL2::MEDFileCMeshL2() +{ +} + +void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + _name.set(mName); + int nstep; + int Mdim; + ParaMEDMEM::MEDCouplingMeshType meshType; + std::vector infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,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); + _iteration=dt; + _order=it; + // + med_grid_type gridtype; + MEDmeshGridTypeRd(fid,mName,&gridtype); + if(gridtype!=MED_CARTESIAN_GRID) + throw INTERP_KERNEL::Exception("Invalid cartesion mesh type ! Only Cartesian Grid supported ! Curvilinear grid will come soon !"); + _cmesh=MEDCouplingCMesh::New(); + for(int i=0;i da=DataArrayDouble::New(); + da->alloc(nbOfElt,1); + da->setInfoOnComponent(0,infosOnComp[i].c_str()); + MEDmeshGridIndexCoordinateRd(fid,mName,dt,it,i+1,da->getPointer()); + _cmesh->setCoordsAt(i,da); + } +} + +med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception) +{ + switch(id) + { + case 0: + return MED_COORDINATE_AXIS1; + case 1: + return MED_COORDINATE_AXIS2; + case 2: + return MED_COORDINATE_AXIS3; + default: + throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !"); + } +} + MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0) { } @@ -332,6 +449,76 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m( assignMesh(m,newOrOld); } +bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const +{ + const MEDCouplingUMesh *m1=_m_by_types; + const MEDCouplingUMesh *m2=other->_m_by_types; + if((m1==0 && m2!=0) || (m1!=0 && m2==0)) + { + what="Presence of mesh in one sublevel and not in other!"; + return false; + } + if(m1) + if(!m1->isEqual(m2,eps)) + { + what="meshes at a sublevel are not deeply equal !"; + return false; + } + const DataArrayInt *d1=_fam; + const DataArrayInt *d2=other->_fam; + if((d1==0 && d2!=0) || (d1!=0 && d2==0)) + { + what="Presence of family arr in one sublevel and not in other!"; + return false; + } + if(d1) + if(!d1->isEqual(*d2)) + { + what="family arr at a sublevel are not deeply equal !"; + return false; + } + d1=_num; + d2=other->_num; + if((d1==0 && d2!=0) || (d1!=0 && d2==0)) + { + what="Presence of cell numbering arr in one sublevel and not in other!"; + return false; + } + if(d1) + if(!d1->isEqual(*d2)) + { + what="Numbering cell arr at a sublevel are not deeply equal !"; + return false; + } + return true; +} + +void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const +{ + const MEDCouplingUMesh *tmp=_m_by_types; + if(!tmp) + return ; + (const_cast(tmp))->setName(master.getName()); + (const_cast(tmp))->setDescription(master.getDescription()); + (const_cast(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder()); + (const_cast(tmp))->setTimeUnit(master.getTimeUnit()); +} + +void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const +{ + ClearNonDiscrAttributes(_m_by_types); +} + +void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp) +{ + if(!tmp) + return ; + (const_cast(tmp))->setName(""); + (const_cast(tmp))->setDescription(""); + (const_cast(tmp))->setTime(0.,-1,-1); + (const_cast(tmp))->setTimeUnit(""); +} + void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception) { if(newOrOld) @@ -339,7 +526,7 @@ void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(I m->incrRef(); _m=m; _m_by_types=(MEDCouplingUMesh *)m->deepCpy(); - MEDCouplingAutoRefCountObjectPtr da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + MEDCouplingAutoRefCountObjectPtr da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO); if(!da->isIdentity()) { _num=da->invertArrayO2N2N2O(m->getNumberOfCells()); @@ -350,7 +537,7 @@ void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(I } else { - if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2)) + 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 !"); m->incrRef(); _m_by_types=m; @@ -441,7 +628,7 @@ void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vectorgetNumberOfCells(); std::map newfams; std::map famIdTrad; - traduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams); + TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams); for(int i=0;idecrRef(); int *w=_fam->getPointer(); @@ -519,7 +706,7 @@ DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) cons return Renumber(_num,da); } -std::vector MEDFileUMeshSplitL1::getNewFamiliesNumber(int nb, const std::map& families) +std::vector MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map& families) { int id=-1; for(std::map::const_iterator it=families.begin();it!=families.end();it++) @@ -532,7 +719,7 @@ std::vector MEDFileUMeshSplitL1::getNewFamiliesNumber(int nb, const std::ma return ret; } -void MEDFileUMeshSplitL1::traduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, +void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, std::map& famIdTrad, std::map& newfams) { std::set allfids; diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index bf8bf89d9..c6b4a5fd5 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -23,6 +23,8 @@ #include "MEDFileBasis.hxx" #include "MEDFileMeshElt.hxx" +#include "MEDCouplingUMesh.hxx" +#include "MEDCouplingCMesh.hxx" #include "MEDCouplingAutoRefCountObjectPtr.hxx" extern "C" @@ -34,26 +36,37 @@ extern "C" namespace ParaMEDMEM { - class MEDCouplingUMesh; - class MEDFileMeshL2 : public RefCountObject { public: MEDFileMeshL2(); const char *getName() const { return _name.getReprForWrite(); } - const char *getDescription() const { return _description.getReprForWrite(); } + const char *getDescription() const { return _description.getReprForWrite(); } + const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); } + int getIteration() const { return _iteration; } + int getOrder() const { return _order; } + double getTime() { return _time; } + std::vector getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception); + static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception); + static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception); + static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map& fams, std::map >& grps); + static void WriteFamiliesAndGrps(med_idt fid, const char *mname, const std::map& fams, const std::map >& grps, int tooLongStrPol); protected: MEDFileString _name; MEDFileString _description; + MEDFileString _dt_unit; + int _iteration; + int _order; + double _time; }; class MEDFileUMeshL2 : public MEDFileMeshL2 { public: MEDFileUMeshL2(); - void loadAll(med_idt fid, int mId, const char *mName); - void loadConnectivity(med_idt fid, int mdim, const char *mName); - void loadCoords(med_idt fid, int mId, int mdim, const char *mName) throw(INTERP_KERNEL::Exception); + void loadAll(med_idt fid, int mId, const char *mName, int dt, int it); + void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it); + void loadCoords(med_idt fid, int mId, const std::vector& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); int getNumberOfLevels() const { return _per_type_mesh.size(); } bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); } const std::vector< MEDCouplingAutoRefCountObjectPtr >& getLev(int levId) const { return _per_type_mesh[levId]; } @@ -62,10 +75,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr getCoords() const { return _coords; } MEDCouplingAutoRefCountObjectPtr getCoordsFamily() const { return _fam_coords; } MEDCouplingAutoRefCountObjectPtr getCoordsNum() const { return _num_coords; } - static int getMeshIdFromName(med_idt fid, const char *mname) throw(INTERP_KERNEL::Exception); - static void readFamiliesAndGrps(med_idt fid, const char *mname, std::map& fams, std::map >& grps); - static void writeFamiliesAndGrps(med_idt fid, const char *mname, const std::map& fams, const std::map >& grps, int tooLongStrPol); - static void writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords); + static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords); private: void sortTypes(); private: @@ -75,10 +85,19 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _num_coords; }; - class MEDFileUMeshL2CMesh : public MEDFileMeshL2 + class MEDFileCMeshL2 : public MEDFileMeshL2 { + public: + MEDFileCMeshL2(); + void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); + MEDCouplingCMesh *getMesh() { return _cmesh; } + private: + static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception); + private: + MEDCouplingAutoRefCountObjectPtr _cmesh; }; + class MEDFileMesh; class MEDFileUMeshSplitL1; class MEDFileUMeshPermCompute @@ -102,6 +121,9 @@ namespace ParaMEDMEM MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id); MEDFileUMeshSplitL1(MEDCouplingUMesh *m); MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld); + bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const; + void clearNonDiscrAttributes() const; + void synchronizeTinyInfo(const MEDFileMesh& master) const; void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception); bool empty() const; int getMeshDimension() const; @@ -120,8 +142,9 @@ namespace ParaMEDMEM void setFamilyArr(DataArrayInt *famArr); void setRenumArr(DataArrayInt *renumArr); // - static std::vector getNewFamiliesNumber(int nb, const std::map& families); - static void traduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, + static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp); + static std::vector GetNewFamiliesNumber(int nb, const std::map& families); + static void TraduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, std::map& famIdTrad, std::map& newfams); static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da); static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds); diff --git a/src/MEDLoader/MEDFileUtilities.cxx b/src/MEDLoader/MEDFileUtilities.cxx index 222d8a860..8d019d953 100644 --- a/src/MEDLoader/MEDFileUtilities.cxx +++ b/src/MEDLoader/MEDFileUtilities.cxx @@ -22,16 +22,16 @@ #include -med_mode_acces MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception) +med_access_mode MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception) { switch(medloaderwritemode) { case 2: - return MED_CREATION; + return MED_ACC_CREAT; case 1: - return MED_LECTURE_AJOUT; + return MED_ACC_RDEXT; case 0: - return MED_LECTURE_ECRITURE; + return MED_ACC_RDWR; default: throw INTERP_KERNEL::Exception("Invalid write mode specified ! must be 0(write with no question), 1(append) or 2(creation)"); } @@ -43,7 +43,6 @@ void MEDFileUtilities::CheckMEDCode(int code, med_idt fid, const char *msg) thro { std::ostringstream oss; oss << "MEDFile has returned an error code (" << code <<") : " << msg; - MEDfermer(fid); throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -71,7 +70,7 @@ void MEDFileUtilities::CheckFileForRead(const char *fileName) throw(INTERP_KERNE throw INTERP_KERNEL::Exception(oss.str().c_str()); } } - int fid=MEDouvrir((char *)fileName,MED_LECTURE); + AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); if(fid<0) { oss << " has been detected as unreadable by MED file : impossible to read anything !"; @@ -79,12 +78,24 @@ void MEDFileUtilities::CheckFileForRead(const char *fileName) throw(INTERP_KERNE } oss << " has been detected readable but "; int major,minor,release; - MEDversionLire(fid,&major,&minor,&release); + MEDfileNumVersionRd(fid,&major,&minor,&release); if(major<2 || (major==2 && minor<2)) { oss << "version of MED file is < 2.2 : impossible to read anything !"; - MEDfermer(fid); throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MEDfermer(fid); +} + +MEDFileUtilities::AutoFid::AutoFid(med_idt fid):_fid(fid) +{ +} + +MEDFileUtilities::AutoFid::operator med_idt() const +{ + return _fid; +} + +MEDFileUtilities::AutoFid::~AutoFid() +{ + MEDfileClose(_fid); } diff --git a/src/MEDLoader/MEDFileUtilities.hxx b/src/MEDLoader/MEDFileUtilities.hxx index 05f3f4e1c..194bc69b7 100644 --- a/src/MEDLoader/MEDFileUtilities.hxx +++ b/src/MEDLoader/MEDFileUtilities.hxx @@ -29,9 +29,19 @@ extern "C" namespace MEDFileUtilities { - med_mode_acces TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception); + med_access_mode TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception); void CheckMEDCode(int code, med_idt fid, const char *msg) throw(INTERP_KERNEL::Exception); void CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception); + + class AutoFid + { + public: + AutoFid(med_idt fid); + operator med_idt() const; + ~AutoFid(); + private: + med_idt _fid; + }; } #endif diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 19bbc158a..1c92710b8 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -34,84 +34,94 @@ extern "C" } #include +#include #include #include #include +#include #include #include -#include -#include -med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2] = { MED_POINT1, - MED_SEG2, - MED_SEG3, - MED_TRIA3, - MED_QUAD4, - MED_TRIA6, - MED_QUAD8, - MED_TETRA4, - MED_PYRA5, - MED_PENTA6, - MED_HEXA8, - MED_TETRA10, - MED_PYRA13, - MED_PENTA15, - MED_HEXA20, - MED_POLYGONE, - MED_POLYEDRE }; - -med_geometrie_element typmainoeud[1] = { MED_NONE }; - -INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP_KERNEL::NORM_POINT1, - INTERP_KERNEL::NORM_SEG2, - INTERP_KERNEL::NORM_SEG3, - INTERP_KERNEL::NORM_TRI3, - INTERP_KERNEL::NORM_QUAD4, - INTERP_KERNEL::NORM_TRI6, - INTERP_KERNEL::NORM_QUAD8, - INTERP_KERNEL::NORM_TETRA4, - INTERP_KERNEL::NORM_PYRA5, - INTERP_KERNEL::NORM_PENTA6, - INTERP_KERNEL::NORM_HEXA8, - INTERP_KERNEL::NORM_TETRA10, - INTERP_KERNEL::NORM_PYRA13, - INTERP_KERNEL::NORM_PENTA15, - INTERP_KERNEL::NORM_HEXA20, - INTERP_KERNEL::NORM_POLYGON, - INTERP_KERNEL::NORM_POLYHED }; - -med_geometrie_element typmai3[32] = { MED_POINT1,//0 - MED_SEG2,//1 - MED_SEG3,//2 - MED_TRIA3,//3 - MED_QUAD4,//4 - MED_POLYGONE,//5 - MED_TRIA6,//6 - MED_NONE,//7 - MED_QUAD8,//8 - MED_NONE,//9 - MED_NONE,//10 - MED_NONE,//11 - MED_NONE,//12 - MED_NONE,//13 - MED_TETRA4,//14 - MED_PYRA5,//15 - MED_PENTA6,//16 - MED_NONE,//17 - MED_HEXA8,//18 - MED_NONE,//19 - MED_TETRA10,//20 - MED_NONE,//21 - MED_NONE,//22 - MED_PYRA13,//23 - MED_NONE,//24 - MED_PENTA15,//25 - MED_NONE,//26 - MED_NONE,//27 - MED_NONE,//28 - MED_NONE,//29 - MED_HEXA20,//30 - MED_POLYEDRE//31 +med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1, + MED_SEG2, + MED_SEG3, + MED_SEG4, + MED_TRIA3, + MED_QUAD4, + MED_TRIA6, + MED_TRIA7, + MED_QUAD8, + MED_QUAD9, + MED_TETRA4, + MED_PYRA5, + MED_PENTA6, + MED_HEXA8, + MED_OCTA12, + MED_TETRA10, + MED_PYRA13, + MED_PENTA15, + MED_HEXA20, + MED_HEXA27, + MED_POLYGON, + MED_POLYHEDRON }; + +med_geometry_type typmainoeud[1] = { MED_NONE }; + +INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1, + INTERP_KERNEL::NORM_SEG2, + INTERP_KERNEL::NORM_SEG3, + INTERP_KERNEL::NORM_ERROR,//SEG4 + INTERP_KERNEL::NORM_TRI3, + INTERP_KERNEL::NORM_QUAD4, + INTERP_KERNEL::NORM_TRI6, + INTERP_KERNEL::NORM_ERROR,//TRI7 + INTERP_KERNEL::NORM_QUAD8, + INTERP_KERNEL::NORM_ERROR,//QUAD9 + INTERP_KERNEL::NORM_TETRA4, + INTERP_KERNEL::NORM_PYRA5, + INTERP_KERNEL::NORM_PENTA6, + INTERP_KERNEL::NORM_HEXA8, + INTERP_KERNEL::NORM_HEXGP12, + INTERP_KERNEL::NORM_TETRA10, + INTERP_KERNEL::NORM_PYRA13, + INTERP_KERNEL::NORM_PENTA15, + INTERP_KERNEL::NORM_HEXA20, + INTERP_KERNEL::NORM_ERROR,//HEXA27 + INTERP_KERNEL::NORM_POLYGON, + INTERP_KERNEL::NORM_POLYHED }; + +med_geometry_type typmai3[32] = { MED_POINT1,//0 + MED_SEG2,//1 + MED_SEG3,//2 + MED_TRIA3,//3 + MED_QUAD4,//4 + MED_POLYGON,//5 + MED_TRIA6,//6 + MED_NONE,//7 + MED_QUAD8,//8 + MED_NONE,//9 + MED_NONE,//10 + MED_NONE,//11 + MED_NONE,//12 + MED_NONE,//13 + MED_TETRA4,//14 + MED_PYRA5,//15 + MED_PENTA6,//16 + MED_NONE,//17 + MED_HEXA8,//18 + MED_NONE,//19 + MED_TETRA10,//20 + MED_NONE,//21 + MED_OCTA12,//22 + MED_PYRA13,//23 + MED_NONE,//24 + MED_PENTA15,//25 + MED_NONE,//26 + MED_NONE,//27 + MED_NONE,//28 + MED_NONE,//29 + MED_HEXA20,//30 + MED_POLYHEDRON//31 }; double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12; @@ -151,9 +161,9 @@ namespace MEDLoaderNS std::vector getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector& fams); std::vector getIdsFromGroups(const char *fileName, const char *meshName, const std::vector& grps); med_int getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception); - void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entite_maillage& whichEntity); + void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity); int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector& possibilities); - void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list& conn); + void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list& conn, std::string& desc); int buildMEDSubConnectivityOfOneType(const std::vector& conn, const std::vector& connIndex, const std::vector& families, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile, std::vector& fam4MEDFile, std::vector& renumber); @@ -261,15 +271,23 @@ void MEDLoader::MEDFieldDoublePerCellType::releaseArray() std::vector MEDLoaderNS::getMeshNamesFid(med_idt fid) { - med_maillage type_maillage; - char maillage_description[MED_TAILLE_DESC+1]; - med_int dim; - char nommaa[MED_TAILLE_NOM+1]; - med_int n=MEDnMaa(fid); + med_mesh_type type_maillage; + char maillage_description[MED_COMMENT_SIZE+1]; + char dtunit[MED_COMMENT_SIZE+1]; + med_int space_dim; + med_int mesh_dim; + char nommaa[MED_NAME_SIZE+1]; + med_axis_type axistype; + med_sorting_type stype; + med_int n=MEDnMesh(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; + 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; } @@ -278,28 +296,34 @@ std::vector MEDLoaderNS::getMeshNamesFid(med_idt fid) void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list& data, MEDCouplingFieldDouble *f) { - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - char locName[MED_TAILLE_NOM+1]; - int nloc=MEDnGauss(fid); - med_geometrie_element typeGeo; + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + char locName[MED_NAME_SIZE+1]; + int nloc=MEDnLocalization(fid); + med_geometry_type typeGeo; for(std::list::const_iterator iter=data.begin();iter!=data.end();iter++) { const std::string& loc=(*iter).getLocName(); int idLoc=1; int nbOfGaussPt=-1; + med_int spaceDim; for(;idLoc<=nloc;idLoc++) { - MEDgaussInfo(fid,idLoc,locName,&typeGeo,&nbOfGaussPt); + char geointerpname[MED_NAME_SIZE+1]=""; + char ipointstructmeshname[MED_NAME_SIZE+1]=""; + med_int nsectionmeshcell; + med_geometry_type sectiongeotype; + MEDlocalizationInfo(fid,idLoc,locName,&typeGeo,&spaceDim,&nbOfGaussPt, geointerpname, ipointstructmeshname, &nsectionmeshcell, + §iongeotype); if(loc==locName) break; } int dim=(int)INTERP_KERNEL::CellModel::getCellModel((*iter).getType()).getDimension(); int nbPtPerCell=(int)INTERP_KERNEL::CellModel::getCellModel((*iter).getType()).getNumberOfNodes(); std::vector refcoo(nbPtPerCell*dim),gscoo(nbOfGaussPt*dim),w(nbOfGaussPt); - MEDgaussLire(fid,(med_float *)&refcoo[0],(med_float *)&gscoo[0],(med_float *)&w[0],MED_FULL_INTERLACE,(char *)(*iter).getLocName().c_str()); + MEDlocalizationRd(fid,(*iter).getLocName().c_str(),MED_FULL_INTERLACE,&refcoo[0],&gscoo[0],&w[0]); f->setGaussLocalizationOnType((*iter).getType(),refcoo,gscoo,w); } - MEDfermer(fid); + MEDfileClose(fid); } void MEDLoader::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception) @@ -310,9 +334,9 @@ void MEDLoader::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exce std::vector MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); std::vector ret=MEDLoaderNS::getMeshNamesFid(fid); - MEDfermer(fid); + MEDfileClose(fid); return ret; } @@ -320,146 +344,114 @@ std::vector MEDLoader::GetMeshNamesOnField(const char *fileName, co { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); // - med_type_champ typcha; - //med_int nbpdtnor=0,pflsize,*pflval,lnsize; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; - med_float dt=0.0; - med_booleen local; - //char pflname[MED_TAILLE_NOM+1]=""; - //char locname[MED_TAILLE_NOM+1]=""; - char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); + // + med_field_type typcha; + INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localmesh; // for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + med_int nbPdt; + INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt); + std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE); + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1); if(curFieldName==fieldName) - { - bool found=false; - for(int j=0;j MEDLoader::GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nfam=MEDnFam(fid,(char *)meshName); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nfam=MEDnFamily(fid,meshName); std::vector ret(nfam); - char nomfam[MED_TAILLE_NOM+1]; + char nomfam[MED_NAME_SIZE+1]; med_int numfam; 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,i+1,nomfam,attide,attval,attdes,&numfam,gro); std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); ret[i]=cur; - delete [] attdes; - delete [] gro; - delete [] attide; - delete [] attval; } - MEDfermer(fid); + MEDfileClose(fid); return ret; } + std::vector MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nfam=MEDnFam(fid,(char *)meshName); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nfam=MEDnFamily(fid,meshName); std::vector ret; - char nomfam[MED_TAILLE_NOM+1]; + char nomfam[MED_NAME_SIZE+1]; med_int numfam; for(int i=0;i attide=new int[natt]; - INTERP_KERNEL::AutoPtr attval=new int[natt]; - INTERP_KERNEL::AutoPtr attdes=new char[MED_TAILLE_DESC*natt+1]; - INTERP_KERNEL::AutoPtr gro=new char[MED_TAILLE_LNOM*ngro+1]; - MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro); + int ngro=MEDnFamilyGroup(fid,meshName,i+1); + med_int natt=MEDnFamily23Attribute(fid,meshName,i+1); + INTERP_KERNEL::AutoPtr 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,i+1,nomfam,attide,attval,attdes,&numfam,gro); std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); for(int j=0;j MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nfam=MEDnFam(fid,(char *)meshName); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nfam=MEDnFamily(fid,meshName); std::vector ret; - char nomfam[MED_TAILLE_NOM+1]; + char nomfam[MED_NAME_SIZE+1]; med_int numfam; bool found=false; for(int i=0;i attide=new int[natt]; - INTERP_KERNEL::AutoPtr attval=new int[natt]; - INTERP_KERNEL::AutoPtr attdes=new char[MED_TAILLE_DESC*natt+1]; - INTERP_KERNEL::AutoPtr gro=new char[MED_TAILLE_LNOM*ngro+1]; - MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro); + int ngro=MEDnFamilyGroup(fid,meshName,i+1); + med_int natt=MEDnFamily23Attribute(fid,meshName,i+1); + INTERP_KERNEL::AutoPtr 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,i+1,nomfam,attide,attval,attdes,&numfam,gro); std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); found=(cur==famName); if(found) for(int j=0;j MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileN } return ret; } + std::vector MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nfam=MEDnFam(fid,(char *)meshName); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nfam=MEDnFamily(fid,meshName); std::vector ret; - char nomfam[MED_TAILLE_NOM+1]; + char nomfam[MED_NAME_SIZE+1]; med_int numfam; 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,i+1,nomfam,attide,attval,attdes,&numfam,gro); for(int j=0;j MEDLoader::GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); // - med_type_champ typcha; + med_field_type typcha; //med_int nbpdtnor=0,pflsize,*pflval,lnsize; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; + med_int numdt=0,numo=0; med_float dt=0.0; - med_booleen local; - //char pflname[MED_TAILLE_NOM+1]=""; - //char locname[MED_TAILLE_NOM+1]=""; - char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + //char pflname[MED_NAME_SIZE+1]=""; + //char locname[MED_NAME_SIZE+1]=""; + char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localmesh; // for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr dt_unit=new char[MED_LNAME_SIZE+1]; + med_int nbPdt; + 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); + if(curMeshName==meshName) { - med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE); - if(nbPdt>0) + if(curFieldName==fieldName) { - bool found=false; - for(int i=0;i0) { - MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa); - std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); - if(curMeshName==meshName) + bool found=false; + for(int i=0;i0) + { + ret.push_back(ON_NODES); + found=true; + } } } - } - bool found=false; - for(int j=0;j0) + bool found=false; + for(int j=0;j0) { - found=true; - ret.push_back(ON_CELLS); + MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt); + med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_CELL,typmai[j]); + if(nbOfVal>0) + { + found=true; + ret.push_back(ON_CELLS); + } } } } } } delete [] maa_ass; - delete [] dt_unit; delete [] nomcha; - MEDfermer(fid); + MEDfileClose(fid); return ret; } @@ -573,22 +561,23 @@ std::vector MEDLoader::GetAllFieldNames(const char *fileName) throw { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); - med_type_champ typcha; + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); + med_field_type typcha; for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr dt_unit=new char[MED_LNAME_SIZE+1]; + med_int nbPdt; + med_bool localmesh; + MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt); ret.push_back(std::string(nomcha)); - delete [] nomcha; - delete [] comp; - delete [] unit; } - MEDfermer(fid); + MEDfileClose(fid); return ret; } @@ -596,66 +585,31 @@ std::vector MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); // - med_type_champ typcha; - //med_int nbpdtnor=0,pflsize,*pflval,lnsize; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; - med_float dt=0.0; - med_booleen local; - //char pflname[MED_TAILLE_NOM+1]=""; - //char locname[MED_TAILLE_NOM+1]=""; - char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + med_field_type typcha; + char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); // for(int i=0;i0) - { - for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr dt_unit=new char[MED_LNAME_SIZE+1]; + med_int nbPdt; + med_bool localmesh; + 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); // - for(int j=0;j0) - { - MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa); - std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); - if(curMeshName==meshName) - { - found=true; - ret.push_back(curFieldName); - } - } - } + if(curMeshName==meshName) + ret.push_back(curFieldName); } delete [] maa_ass; - delete [] dt_unit; delete [] nomcha; - MEDfermer(fid); + MEDfileClose(fid); return ret; } @@ -677,50 +631,48 @@ std::vector MEDLoader::GetCellFieldNamesOnMesh(const char *fileName { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); // - med_type_champ typcha; + med_field_type typcha; //med_int nbpdtnor=0,pflsize,*pflval,lnsize; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; + med_int numdt=0,numo=0; med_float dt=0.0; - med_booleen local; - //char pflname[MED_TAILLE_NOM+1]=""; - //char locname[MED_TAILLE_NOM+1]=""; - char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + //char pflname[MED_NAME_SIZE+1]=""; + //char locname[MED_NAME_SIZE+1]=""; + INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localmesh; + med_int nbPdt; // for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + 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); + if(curMeshName==meshName) { - med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]); - if(nbPdt>0) + bool found=false; + for(int j=0;j0) { - found=true; - ret.push_back(curFieldName); + MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt); + med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_CELL,typmai[j]); + if(nbOfVal>0) + { + found=true; + ret.push_back(curFieldName); + } } } } } - delete [] maa_ass; - delete [] dt_unit; - delete [] nomcha; - MEDfermer(fid); + MEDfileClose(fid); return ret; } @@ -728,44 +680,39 @@ std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); // - med_type_champ typcha; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; + med_field_type typcha; + med_int numdt=0,numo=0; med_float dt=0.0; - med_booleen local; - char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localmesh; // for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + med_int nbPdt; + 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); bool found=false; - med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE); if(nbPdt>0) { - MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa); - std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); - if(curMeshName==meshName) + MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt); + med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_NODE,MED_NONE); + if(curMeshName==meshName && nbOfVal>0) { found=true; ret.push_back(curFieldName); } } } - delete [] maa_ass; - delete [] dt_unit; - delete [] nomcha; - MEDfermer(fid); + MEDfileClose(fid); return ret; } @@ -773,111 +720,93 @@ std::vector< std::pair< std::pair, double> > MEDLoader::GetAllFieldIter { CheckFileForRead(fileName); std::string meshNameCpp(meshName); - std::vector< std::pair< std::pair, double> > ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); + std::vector< std::pair< std::pair, double > > ret; + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); // - med_type_champ typcha; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; + med_field_type typcha; + med_int numdt=0,numo=0; med_float dt=0.0; - med_booleen local; - char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localmesh; // for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + med_int nbPdt; + MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt); + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1); if(curFieldName==fieldName) { bool found=false; - for(int j=0;j0) { found=true; ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt)); } } } - med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE); for(int k=0;k0) + { + found=true; + ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt)); + } } } } - delete [] maa_ass; - delete [] dt_unit; - delete [] nomcha; - MEDfermer(fid); + MEDfileClose(fid); return ret; } double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); // - med_type_champ typcha; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; + med_field_type typcha; + med_int numdt=0,numo=0; med_float dt=0.0; - med_booleen local; - char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + med_bool local; + INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); // bool found=false; bool found2=false; double ret=std::numeric_limits::max(); for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + med_int nbPdt; + MEDfieldInfo(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt); + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1); if(curFieldName==fieldName) { found=true; - for(int j=0;j > MEDLoader::GetCellFieldIterations(const char * CheckFileForRead(fileName); std::string meshNameCpp(meshName); std::vector< std::pair > ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); // - med_type_champ typcha; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; + med_field_type typcha; + med_int numdt=0,numo=0; med_float dt=0.0; - med_booleen local; - char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localmesh; // for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + med_int nbPdt; + MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt); + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1); if(curFieldName==fieldName) { bool found=false; - for(int j=0;j0) { found=true; ret.push_back(std::make_pair(numdt,numo)); @@ -959,10 +883,7 @@ std::vector< std::pair > MEDLoader::GetCellFieldIterations(const char * } } } - delete [] maa_ass; - delete [] dt_unit; - delete [] nomcha; - MEDfermer(fid); + MEDfileClose(fid); return ret; } @@ -971,45 +892,40 @@ std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char * CheckFileForRead(fileName); std::string meshNameCpp(meshName); std::vector< std::pair > ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); // - med_type_champ typcha; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; + med_field_type typcha; + med_int numdt=0,numo=0; med_float dt=0.0; - med_booleen local; - char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); - char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_bool localmesh; // for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + med_int nbPdt; + MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt); + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1); if(curFieldName==fieldName) { - med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE); for(int k=0;k0) { ret.push_back(std::make_pair(numdt,numo)); } } } } - delete [] maa_ass; - delete [] dt_unit; - delete [] nomcha; - MEDfermer(fid); + MEDfileClose(fid); return ret; } @@ -1024,170 +940,154 @@ void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char double& time, std::vector& infos) { time=0.; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + med_int nbFields=MEDnField(fid); // - med_type_champ typcha; - char nomcha[MED_TAILLE_NOM+1]=""; - char pflname [MED_TAILLE_NOM+1]=""; - char locname [MED_TAILLE_NOM+1]=""; - std::map tabEnt; - std::map tabType; + med_field_type typcha; + char nomcha[MED_NAME_SIZE+1]=""; + char pflname [MED_NAME_SIZE+1]=""; + char locname [MED_NAME_SIZE+1]=""; + std::map tabEnt; + std::map tabType; std::map tabTypeLgth; - tabEnt[ON_CELLS]=MED_MAILLE; + med_bool localmesh; + tabEnt[ON_CELLS]=MED_CELL; tabType[ON_CELLS]=typmai; - tabTypeLgth[ON_CELLS]=MED_NBR_GEOMETRIE_MAILLE+2; - tabEnt[ON_NODES]=MED_NOEUD; + tabTypeLgth[ON_CELLS]=MED_N_CELL_FIXED_GEO; + tabEnt[ON_NODES]=MED_NODE; tabType[ON_NODES]=typmainoeud; tabTypeLgth[ON_NODES]=1; - tabEnt[ON_GAUSS_PT]=MED_MAILLE; + tabEnt[ON_GAUSS_PT]=MED_CELL; tabType[ON_GAUSS_PT]=typmai; - tabTypeLgth[ON_GAUSS_PT]=MED_NBR_GEOMETRIE_MAILLE+2; - tabEnt[ON_GAUSS_NE]=MED_MAILLE; + tabTypeLgth[ON_GAUSS_PT]=MED_N_CELL_FIXED_GEO; + tabEnt[ON_GAUSS_NE]=MED_NODE_ELEMENT; tabType[ON_GAUSS_NE]=typmai; - tabTypeLgth[ON_GAUSS_NE]=MED_NBR_GEOMETRIE_MAILLE+2; + tabTypeLgth[ON_GAUSS_NE]=MED_N_CELL_FIXED_GEO; // for(int i=0;i comp=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr unit=new char[ncomp*MED_SNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr dt_unit=new char[MED_LNAME_SIZE+1]; + INTERP_KERNEL::AutoPtr maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + med_int nbPdt; + MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt); + std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1); + if(curMeshName!=meshName) + { + MEDfileClose(fid); + throw INTERP_KERNEL::Exception("Invalid meshname on field !"); + } + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1); if(curFieldName==fieldName) { infos.resize(ncomp); for(int i=0;i0) { @@ -1267,7 +1184,7 @@ int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName poss.insert(curDim); } } - MEDfermer(fid); + MEDfileClose(fid); if(!poss.empty()) { ret=*poss.rbegin(); @@ -1279,38 +1196,49 @@ int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName return ret; } -void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list& conn) +void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list& conn, std::string& description) { - char nommaa[MED_TAILLE_NOM+1]; - char maillage_description[MED_TAILLE_DESC+1]; - med_maillage type_maillage; + char nommaa[MED_NAME_SIZE+1]; + char maillage_description[MED_COMMENT_SIZE+1]; + med_mesh_type type_maillage; med_int Mdim; - MEDmaaInfo(fid,meshId,nommaa,&Mdim,&type_maillage,maillage_description); - med_int edim=MEDdimEspaceLire(fid,nommaa); - int spaceDim=std::max((int)Mdim,(int)edim); - int nCoords=MEDnEntMaa(fid,nommaa,MED_COOR,MED_NOEUD,(med_geometrie_element)0,(med_connectivite)0); + med_int Sdim; + INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + med_sorting_type sortingType; + med_int nstep; + med_axis_type axisType; + med_int numdt,numit; + med_float dt; + med_bool changement,transformation; + // endlimitation + Sdim=MEDmeshnAxis(fid,1); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE); + MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,comp,unit); + description=MEDLoaderBase::buildStringFromFortran(maillage_description,sizeof(maillage_description)); + MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt); + int spaceDim=std::max((int)Mdim,(int)Sdim); + int nCoords=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation); + // limitation + if(nstep!=1) + { + throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !"); + } coords=DataArrayDouble::New(); coords->alloc(nCoords,spaceDim); double *coordsPtr=coords->getPointer(); - med_repere repere; - char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); - char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); - MEDcoordLire(fid,nommaa,spaceDim,coordsPtr,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit); + MEDmeshNodeCoordinateRd(fid,nommaa,numdt,numit,MED_FULL_INTERLACE,coordsPtr); for(int i=0;isetInfoOnComponent(i,info.c_str()); } - delete [] comp; - delete [] unit; - med_booleen inoele, inuele; - for(int i=0;i0) @@ -1318,54 +1246,73 @@ void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayD int *connTab=new int[(curMedType%100)*curNbOfElem]; int *fam=new int[curNbOfElem]; MEDLoader::MEDConnOfOneElemType elem(typmai2[i],connTab,0,fam,curNbOfElem,-1); - int *tmp=new int[curNbOfElem]; - char *noms=new char[MED_TAILLE_PNOM*curNbOfElem+1]; - MEDelementsLire(fid,nommaa,Mdim,connTab,MED_FULL_INTERLACE,noms,&inoele,tmp,&inuele,fam,curNbOfElem,whichEntity,curMedType,MED_NOD); - delete [] tmp; + char *noms=new char[MED_SNAME_SIZE*curNbOfElem+1]; + med_bool withname=MED_FALSE,withnumber=MED_FALSE,withfam=MED_FALSE; + int *globArr=new int[curNbOfElem]; + MEDmeshElementRd(fid,nommaa,numdt,numit,whichEntity,curMedType,MED_NODAL,MED_FULL_INTERLACE,connTab,&withname,noms,&withnumber,globArr,&withfam,fam); + if(!withfam) + std::fill(fam,fam+curNbOfElem,0); delete [] noms; //trying to read global numbering - int *globArr=new int[curNbOfElem]; - if(MEDnumLire(fid,nommaa,globArr,curNbOfElem,whichEntity,curMedType)==0) + if(withnumber) elem.setGlobal(globArr); else delete [] globArr; + //limitation manage withfam==false conn.push_back(elem); } } int curNbOfPolyElem; - int curNbOfPolyElemM=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYGONE,MED_NOD); - int curNbOfPolyElemF=MEDnEntMaa(fid,nommaa,MED_CONN,MED_FACE,MED_POLYGONE,MED_NOD); - med_entite_maillage whichPolyEntity; + int curNbOfPolyElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1; + int curNbOfPolyElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;//limitation + med_entity_type whichPolyEntity; MEDLoaderNS::dispatchElems(curNbOfPolyElemM,curNbOfPolyElemF,curNbOfPolyElem,whichPolyEntity); if(curNbOfPolyElem>0) { - med_int arraySize; - MEDpolygoneInfo(fid,nommaa,whichPolyEntity,MED_NOD,&arraySize); + med_int arraySize=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation); int *index=new int[curNbOfPolyElem+1]; int *locConn=new int[arraySize]; int *fam=new int[curNbOfPolyElem]; int *globArr=new int[curNbOfPolyElem]; MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYGON,locConn,index,fam,curNbOfPolyElem,arraySize); - MEDpolygoneConnLire(fid,nommaa,index,curNbOfPolyElem+1,locConn,whichPolyEntity,MED_NOD); - MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,whichPolyEntity,MED_POLYGONE); - if(MEDnumLire(fid,nommaa,globArr,curNbOfPolyElem,whichPolyEntity,MED_POLYGONE)==0) - elem.setGlobal(globArr); + MEDmeshPolygonRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,locConn); + if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,fam)!=0) + std::fill(fam,fam+curNbOfPolyElem,0); + } + else + std::fill(fam,fam+curNbOfPolyElem,0); + if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYGON,globArr)==0) + elem.setGlobal(globArr); + else + delete [] globArr; + } else delete [] globArr; conn.push_back(elem); } - curNbOfPolyElem=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYEDRE,MED_NOD); + curNbOfPolyElem=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1; if(curNbOfPolyElem>0) { med_int indexFaceLgth,connFaceLgth; - MEDpolyedreInfo(fid,nommaa,MED_NOD,&indexFaceLgth,&connFaceLgth); - int *index=new int[curNbOfPolyElem+1]; - int *indexFace=new int[indexFaceLgth]; - int *locConn=new int[connFaceLgth]; + indexFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation); + connFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation); + INTERP_KERNEL::AutoPtr index=new int[curNbOfPolyElem+1]; + INTERP_KERNEL::AutoPtr indexFace=new int[indexFaceLgth]; + INTERP_KERNEL::AutoPtr locConn=new int[connFaceLgth]; int *fam=new int[curNbOfPolyElem]; int *globArr=new int[curNbOfPolyElem]; - MEDpolyedreConnLire(fid,nommaa,index,curNbOfPolyElem+1,indexFace,indexFaceLgth,locConn,MED_NOD); - MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,MED_MAILLE,MED_POLYEDRE); + MEDmeshPolyhedronRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,indexFace,locConn); + if(MEDmeshnEntity(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,fam)!=0) + std::fill(fam,fam+curNbOfPolyElem,0); + } + else + std::fill(fam,fam+curNbOfPolyElem,0); int arraySize=connFaceLgth; for(int i=0;i0) + { + if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,globArr)==0) + elem.setGlobal(globArr); + else + delete [] globArr; + } else delete [] globArr; conn.push_back(elem); @@ -1780,20 +1729,22 @@ MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const if(meshDimRelToMax>0) throw INTERP_KERNEL::Exception("meshDimRelToMax must be <=0 !"); //Extraction data from MED file. - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); std::string trueMeshName; med_int mid=getIdFromMeshName(fid,meshName,trueMeshName); DataArrayDouble *coords=0; std::list conn; - readUMeshDataInMedFile(fid,mid,coords,conn); + std::string descr; + readUMeshDataInMedFile(fid,mid,coords,conn,descr); meshDimExtract=MEDLoaderNS::calculateHighestMeshDim(conn); meshDimExtract=meshDimExtract+meshDimRelToMax; MEDLoaderNS::keepSpecifiedMeshDim(conn,meshDimExtract); MEDLoaderNS::keepTypes(conn,typesToKeep); - MEDfermer(fid); + MEDfileClose(fid); //Put data in returned data structure. MEDCouplingUMesh *ret=MEDCouplingUMesh::New(); ret->setName(trueMeshName.c_str()); + ret->setDescription(descr.c_str()); ret->setMeshDimension(meshDimExtract); // ret->setCoords(coords); @@ -1831,9 +1782,9 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char if(typeOfOutField==ON_CELLS) { if(newMesh) - mesh2=newMesh->keepSpecifiedCells((*iter).getType(),ci); + mesh2=newMesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size()); else - mesh2=mesh->keepSpecifiedCells((*iter).getType(),ci); + mesh2=mesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size()); } else if(typeOfOutField==ON_NODES) { @@ -2125,11 +2076,11 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const char *file */ void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vector& mesh, const std::vector& families, bool forceFromScratch, bool &isRenumbering) { - med_idt fid=MEDouvrir((char *)fileName,forceFromScratch?MED_CREATION:MED_LECTURE_ECRITURE); + med_idt fid=MEDfileOpen(fileName,forceFromScratch?MED_ACC_CREAT:MED_ACC_RDWR); std::string meshName(mesh[0]->getName()); if(meshName=="") { - MEDfermer(fid); + MEDfileClose(fid); throw INTERP_KERNEL::Exception("MEDCouplingMesh must have a not null name !"); } isRenumbering=false; @@ -2139,25 +2090,36 @@ void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vector allTypes; for(std::vector::const_iterator iter=mesh.begin();iter!=mesh.end();iter++) { - isRenumbering|=!(*iter)->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + isRenumbering|=!(*iter)->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO); isFamilies&=(families[std::distance(mesh.begin(),iter)]!=0); conn.push_back((*iter)->getNodalConnectivity()); connIndex.push_back((*iter)->getNodalConnectivityIndex()); const std::set& curTypes=(*iter)->getAllTypes(); allTypes.insert(curTypes.begin(),curTypes.end()); } - char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - char *desc=MEDLoaderBase::buildEmptyString(MED_TAILLE_DESC); - MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_TAILLE_NOM,maa,MEDLoader::_TOO_LONG_STR); - MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_TAILLE_DESC,desc,MEDLoader::_TOO_LONG_STR); + INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR); + MEDLoaderBase::safeStrCpy(mesh[0]->getDescription(),MED_COMMENT_SIZE,desc,MEDLoader::_TOO_LONG_STR); const int spaceDim=mesh[0]->getSpaceDimension(); - MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc); - MEDdimEspaceCr(fid,maa,spaceDim); + const int meshDim=mesh[0]->getMeshDimension(); + DataArrayDouble *arr=mesh[0]->getCoords(); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + for(int i=0;igetInfoOnComponent(i); + std::string c,u; + MEDLoaderBase::splitIntoNameAndUnit(info,c,u); + MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + } + MEDmeshCr(fid,maa,spaceDim,meshDim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit); for(std::vector::const_iterator iter=mesh.begin();iter!=mesh.end();iter++) { - for(int i=0;i fam; std::vector renumber; int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,families,curType,medConn,medConnIndex,medConnIndex2,fam,renumber); - if(curMedType!=MED_POLYGONE && curMedType!=MED_POLYEDRE) - MEDconnEcr(fid,maa,(*iter)->getMeshDimension(),&medConn[0],MED_FULL_INTERLACE,nbOfElt,MED_MAILLE,curMedType,MED_NOD); + if(curMedType!=MED_POLYGON && curMedType!=MED_POLYHEDRON) + MEDmeshElementConnectivityWr(fid,maa,-1,-1,0.,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfElt,&medConn[0]); else { - if(curMedType==MED_POLYGONE) - MEDpolygoneConnEcr(fid,maa,&medConnIndex[0],medConnIndex.size(),&medConn[0],MED_MAILLE,MED_NOD); - if(curMedType==MED_POLYEDRE) + if(curMedType==MED_POLYGON) + MEDmeshPolygonWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex.size(),&medConnIndex[0],&medConn[0]); + if(curMedType==MED_POLYHEDRON) { - MEDpolyedreConnEcr(fid,maa,&medConnIndex2[0],medConnIndex2.size(),&medConnIndex[0],medConnIndex.size(), - &medConn[0],MED_NOD); + MEDmeshPolyhedronWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex2.size(),&medConnIndex2[0],medConnIndex.size(),&medConnIndex[0], + &medConn[0]); } } if(isFamilies) - MEDfamEcr(fid,maa,&fam[0],nbOfElt,MED_MAILLE,curMedType); + MEDmeshEntityFamilyNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&fam[0]); if(isRenumbering) - MEDnumEcr(fid,maa,&renumber[0],nbOfElt,MED_MAILLE,curMedType); + MEDmeshEntityNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&renumber[0]); } } } - char familyName[MED_TAILLE_NOM+1]; - std::fill(familyName,familyName+MED_TAILLE_NOM+1,'\0'); + char familyName[MED_NAME_SIZE+1]; + std::fill(familyName,familyName+MED_NAME_SIZE+1,'\0'); const char DftFamilyName[]="DftFamily"; std::copy(DftFamilyName,DftFamilyName+sizeof(DftFamilyName),familyName); - MEDfamCr(fid,maa,familyName,0,0,0,0,0,0,0); - DataArrayDouble *arr=mesh[0]->getCoords(); - char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); - char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); - for(int i=0;igetInfoOnComponent(i); - std::string c,u; - MEDLoaderBase::splitIntoNameAndUnit(info,c,u); - MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo - MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo - } - MEDcoordEcr(fid,maa,spaceDim,arr->getPointer(),MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),MED_CART,comp,unit); - delete [] comp; - delete [] unit; - delete [] maa; - delete [] desc; - MEDfermer(fid); + MEDfamilyCr(fid,maa,familyName,0,0,0); + + MEDmeshNodeCoordinateWr(fid,maa,-1,-1,0.,MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),arr->getPointer()); + MEDfileClose(fid); } /*! @@ -2217,8 +2165,8 @@ void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vector& meshes, bool forceFromScratch) { std::string meshNameCpp(meshName); - char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDLoaderBase::safeStrCpy(meshName,MED_TAILLE_NOM,maa,MEDLoader::_TOO_LONG_STR); + char *maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDLoaderBase::safeStrCpy(meshName,MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR); if(meshNameCpp=="") throw INTERP_KERNEL::Exception("writeUMeshesPartitionDirectly : Invalid meshName : Must be different from \"\" !"); std::vector< DataArrayInt * > corr; @@ -2249,21 +2197,21 @@ void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char gidsOfFamilies[fid].push_back(gid); } fid=0; - med_idt fid2=MEDouvrir((char *)fileName,MED_LECTURE_ECRITURE); + med_idt fid2=MEDfileOpen(fileName,MED_ACC_RDWR); for(std::set::const_iterator it=familyIds.begin();it!=familyIds.end();it++,fid++) { int ngro=gidsOfFamilies[fid].size(); - char *groName=MEDLoaderBase::buildEmptyString(MED_TAILLE_LNOM*ngro); + char *groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro); for(int i=0;igetName(),MED_TAILLE_LNOM-1,groName+i*MED_TAILLE_LNOM,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_LNOM-1 to avoid to write '\0' on next compo + MEDLoaderBase::safeStrCpy2(meshes[gidsOfFamilies[fid][i]]->getName(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_LNAME_SIZE-1 to avoid to write '\0' on next compo std::ostringstream oss; oss << "Family_" << *it; - char *famName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,famName,MEDLoader::_TOO_LONG_STR); - MEDfamCr(fid2,maa,famName,*it,0,0,0,0,groName,ngro); + char *famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,famName,MEDLoader::_TOO_LONG_STR); + MEDfamilyCr(fid2,maa,famName,*it,ngro,groName); delete [] famName; delete [] groName; } - MEDfermer(fid2); + MEDfileClose(fid2); // end families creation delete [] maa; arr2->decrRef(); @@ -2278,24 +2226,19 @@ void MEDLoaderNS::appendNodeProfileField(const char *fileName, const ParaMEDMEM: { med_int numdt,numo; med_float dt; - char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_TAILLE_NOM,nommaa,MEDLoader::_TOO_LONG_STR); + INTERP_KERNEL::AutoPtr nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR); med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); int nbOfNodes=f->getMesh()->getNumberOfNodes(); const double *pt=f->getArray()->getConstPointer(); - int *profile=new int[nbOfNodes]; + INTERP_KERNEL::AutoPtr profile=new int[nbOfNodes]; std::ostringstream oss; oss << "Pfln" << f->getName(); - char *profileName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,profileName,MEDLoader::_TOO_LONG_STR); - std::transform(thisMeshNodeIds,thisMeshNodeIds+nbOfNodes,profile,std::bind2nd(std::plus(),1)); - MEDprofilEcr(fid,profile,nbOfNodes,profileName); - delete [] profile; - MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfNodes, - (char *)MED_NOGAUSS,MED_ALL,profileName,MED_COMPACT,MED_NOEUD, - MED_NONE,numdt,(char *)"",dt,numo); - delete [] profileName; - delete [] nommaa; - MEDfermer(fid); + INTERP_KERNEL::AutoPtr profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR); + std::transform(thisMeshNodeIds,thisMeshNodeIds+nbOfNodes,(int *)profile,std::bind2nd(std::plus(),1)); + MEDprofileWr(fid,profileName,nbOfNodes,profile); + MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE,profileName,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfNodes,(const unsigned char*)pt); + MEDfileClose(fid); } /*! @@ -2314,24 +2257,21 @@ void MEDLoaderNS::appendCellProfileField(const char *fileName, const ParaMEDMEM: int number=0; for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) { - char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_TAILLE_NOM,nommaa,MEDLoader::_TOO_LONG_STR); - char *profileName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + INTERP_KERNEL::AutoPtr nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR); + INTERP_KERNEL::AutoPtr profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++; - MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,profileName,MEDLoader::_TOO_LONG_STR); + MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR); const std::vector& ids=(*iter).getCellIdPerType(); int *profile=new int [ids.size()]; std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus(),1)); - MEDprofilEcr(fid,profile,ids.size(),profileName); + MEDprofileWr(fid,profileName,ids.size(),profile); delete [] profile; - MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,(*iter).getNbOfTuple(), - (char *)MED_NOGAUSS,MED_ALL,profileName,MED_COMPACT,MED_MAILLE, - typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo); - delete [] profileName; - delete [] nommaa; + MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,profileName, + MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt); pt+=(*iter).getNbOfTuple()*nbComp; } - MEDfermer(fid); + MEDfileClose(fid); } /*! @@ -2339,23 +2279,28 @@ void MEDLoaderNS::appendCellProfileField(const char *fileName, const ParaMEDMEM: */ med_idt MEDLoaderNS::appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt) { - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE_ECRITURE); + med_idt fid=MEDfileOpen(fileName,MED_ACC_RDWR); int nbComp=f->getNumberOfComponents(); - char *comp=MEDLoaderBase::buildEmptyString(nbComp*MED_TAILLE_PNOM); - char *unit=MEDLoaderBase::buildEmptyString(nbComp*MED_TAILLE_PNOM); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE); for(int i=0;igetArray()->getInfoOnComponent(i); std::string c,u; MEDLoaderBase::splitIntoNameAndUnit(info,c,u); - MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR); - MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR); - } - MEDchampCr(fid,(char *)f->getName(),MED_FLOAT64,comp,unit,nbComp); + MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR); + MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR); + } + INTERP_KERNEL::AutoPtr dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + INTERP_KERNEL::AutoPtr maaname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr fname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fname,MEDLoader::_TOO_LONG_STR); + MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,maaname,MEDLoader::_TOO_LONG_STR); + MEDfieldCr(fid,fname,MED_FLOAT64,nbComp,comp,unit,dt_unit,maaname); ParaMEDMEM::TypeOfTimeDiscretization td=f->getTimeDiscretization(); if(td==ParaMEDMEM::NO_TIME) { - numdt=MED_NOPDT; numo=MED_NONOR; dt=0.0; + numdt=MED_NO_DT; numo=MED_NO_IT; dt=0.0; } else if(td==ParaMEDMEM::ONE_TIME) { @@ -2364,8 +2309,6 @@ med_idt MEDLoaderNS::appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM numdt=(med_int)tmp1; numo=(med_int)tmp2; dt=(med_float)tmp0; } - delete [] comp; - delete [] unit; return fid; } @@ -2379,11 +2322,11 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME const MEDCouplingUMesh *meshC=dynamic_cast(mesh); if(!meshC) throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !"); - bool renum=!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + bool renum=!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO); if(renum) { ParaMEDMEM::MEDCouplingFieldDouble *f3=f2->clone(true); - DataArrayInt *da=meshC->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + DataArrayInt *da=meshC->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO); f3->renumberCells(da->getConstPointer(),false); da->decrRef(); f=f3; @@ -2392,8 +2335,8 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME int nbComp=f->getNumberOfComponents(); med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); const double *pt=f->getArray()->getConstPointer(); - char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_TAILLE_NOM,nommaa,MEDLoader::_TOO_LONG_STR); + INTERP_KERNEL::AutoPtr nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR); switch(f->getTypeOfField()) { case ParaMEDMEM::ON_CELLS: @@ -2402,9 +2345,8 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME prepareCellFieldDoubleForWriting(f,0,split); for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) { - MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,(*iter).getNbOfTuple(), - (char *)MED_NOGAUSS,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE, - typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo); + MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE, + MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt); pt+=(*iter).getNbOfTuple()*nbComp; } break; @@ -2412,8 +2354,8 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME case ParaMEDMEM::ON_NODES: { int nbOfTuples=f->getArray()->getNumberOfTuples(); - MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfTuples,(char *)MED_NOGAUSS, - MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_NOEUD,MED_NONE,numdt,(char *)"",dt,numo); + MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE, + MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfTuples,(const unsigned char*)pt); break; } case ParaMEDMEM::ON_GAUSS_PT: @@ -2423,20 +2365,20 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME int idGp=0; for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) { - char *nomGauss=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + INTERP_KERNEL::AutoPtr nomGauss=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); std::ostringstream oss; oss << "GP_" << f->getName() << idGp++; - MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,nomGauss,MEDLoader::_TOO_LONG_STR); + MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,nomGauss,MEDLoader::_TOO_LONG_STR); int id=f->getGaussLocalizationIdOfOneType((*iter).getType()); const MEDCouplingGaussLocalization& gl=f->getGaussLocalization(id); - MEDgaussEcr(fid,typmai3[(int)(*iter).getType()],(med_float*)&gl.getRefCoords()[0],MED_FULL_INTERLACE,gl.getNumberOfGaussPt(), - (med_float*)&gl.getGaussCoords()[0], - (med_float*)&gl.getWeights()[0],nomGauss); - int nbOfValues=gl.getNumberOfGaussPt()*f->getMesh()->getNumberOfCellsWithType((*iter).getType()); - MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfValues, - nomGauss,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE, - typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo); + MEDlocalizationWr(fid,nomGauss,typmai3[(int)(*iter).getType()],mesh->getMeshDimension(),&gl.getRefCoords()[0],MED_FULL_INTERLACE, + gl.getNumberOfGaussPt(),&gl.getGaussCoords()[0],&gl.getWeights()[0],MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT); + int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType()); + int nbOfValues=gl.getNumberOfGaussPt()*nbOfEntity; + INTERP_KERNEL::AutoPtr fieldname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fieldname,MEDLoader::_TOO_LONG_STR); + MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE, + MED_ALLENTITIES_PROFILE,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt); pt+=nbOfValues*nbComp; - delete [] nomGauss; } break; } @@ -2447,10 +2389,10 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) { int nbPtPerCell=(int)INTERP_KERNEL::CellModel::getCellModel((*iter).getType()).getNumberOfNodes(); - int nbOfValues=nbPtPerCell*f->getMesh()->getNumberOfCellsWithType((*iter).getType()); - MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfValues, - (char *)MED_GAUSS_ELNO,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE, - typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo); + int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType()); + int nbOfValues=nbPtPerCell*nbOfEntity; + MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE_ELEMENT,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE, + MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt); pt+=nbOfValues*nbComp; } break; @@ -2458,8 +2400,7 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME default: throw INTERP_KERNEL::Exception("Not managed this type of FIELD !"); } - delete [] nommaa; - MEDfermer(fid); + MEDfileClose(fid); if(renum) ((ParaMEDMEM::MEDCouplingFieldDouble *)f)->decrRef(); } @@ -2475,7 +2416,7 @@ void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCoupling const MEDCouplingUMesh *meshC=dynamic_cast(mesh); if(!meshC) throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !"); - if(!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2)) + if(!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO)) throw INTERP_KERNEL::Exception("Unstructuded mesh has not consecutive cell types !"); const int *connI=meshC->getNodalConnectivityIndex()->getConstPointer(); const int *conn=meshC->getNodalConnectivity()->getConstPointer(); @@ -2516,7 +2457,7 @@ void MEDLoaderNS::writeFieldAndMeshDirectly(const char *fileName, const ParaMEDM if(isRenumbering) { ParaMEDMEM::MEDCouplingFieldDouble *f2=f->clone(true); - DataArrayInt *da=mesh->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + DataArrayInt *da=mesh->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO); f2->renumberCells(da->getConstPointer(),false); da->decrRef(); appendFieldDirectly(fileName,f2); @@ -2864,8 +2805,5 @@ void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const Pa std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - std::string fieldName(f->getName()); - if(fieldName.empty()) - throw INTERP_KERNEL::Exception("Trying to write a field with no name ! MED file format needs a not empty field name !"); MEDLoaderNS::appendFieldDirectly(fileName,f); } diff --git a/src/MEDLoader/MEDLoaderBase.cxx b/src/MEDLoader/MEDLoaderBase.cxx index 3dc6aad58..afe59a542 100644 --- a/src/MEDLoader/MEDLoaderBase.cxx +++ b/src/MEDLoader/MEDLoaderBase.cxx @@ -117,6 +117,32 @@ void MEDLoaderBase::safeStrCpy(const char *src, int maxLgth, char *dest, int beh strcpy(dest,src); } +/*! + * This method is equivalent to MEDLoaderBase::safeStrCpy except that here no '\0' car is put. + * This method should be used for multi string in one string. + */ +void MEDLoaderBase::safeStrCpy2(const char *src, int maxLgth, char *dest, int behaviour) throw(INTERP_KERNEL::Exception) +{ + if((int)strlen(src)>maxLgth) + { + if(behaviour==0 || behaviour>1) + { + std::ostringstream oss; oss << "A string : \"" << src << "\" has been detected to be too long for MED File ( > " << maxLgth << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + else if(behaviour==1) + { + std::string s=zipString(src,maxLgth); + std::cerr << "A string : \"" << src << "\" has been detected to be too long for MED File ( > " << maxLgth << ") : "; + std::cerr << "zipping to : " << s << "\n"; + strcpy(dest,s.c_str()); + return ; + } + } + int n=strlen(src); + strncpy(dest,src,n); +} + std::string MEDLoaderBase::buildStringFromFortran(const char *expr, int lgth) { std::string ret(expr,lgth); diff --git a/src/MEDLoader/MEDLoaderBase.hxx b/src/MEDLoader/MEDLoaderBase.hxx index 09e0c5850..0ab2a6ea7 100644 --- a/src/MEDLoader/MEDLoaderBase.hxx +++ b/src/MEDLoader/MEDLoaderBase.hxx @@ -34,6 +34,7 @@ public: static void splitIntoNameAndUnit(const std::string& s, std::string& name, std::string& unit); static void strip(std::string& s); static void safeStrCpy(const char *src, int maxLgth, char *dest, int behaviour) throw(INTERP_KERNEL::Exception); + static void safeStrCpy2(const char *src, int maxLgth, char *dest, int behaviour) throw(INTERP_KERNEL::Exception); static std::string buildStringFromFortran(const char *expr, int lgth); static void zipEqualConsChar(std::string& s, int minConsSmChar); static std::string zipString(const char *src, int sizeToRespect); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 40e445af8..ca1af3b97 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -27,6 +27,7 @@ %{ #include "MEDLoader.hxx" #include "MEDFileMesh.hxx" +#include "MEDFileField.hxx" #include "MEDLoaderTypemaps.i" using namespace ParaMEDMEM; @@ -49,25 +50,32 @@ using namespace ParaMEDMEM; %newobject MEDLoader::ReadFieldNode; %newobject MEDLoader::ReadFieldGauss; %newobject MEDLoader::ReadFieldGaussNE; +%newobject ParaMEDMEM::MEDFileMesh::New; +%newobject ParaMEDMEM::MEDFileMesh::getGenMeshAtLevel; +%newobject ParaMEDMEM::MEDFileMesh::getGroupArr; +%newobject ParaMEDMEM::MEDFileMesh::getGroupsArr; +%newobject ParaMEDMEM::MEDFileMesh::getFamilyArr; +%newobject ParaMEDMEM::MEDFileMesh::getFamiliesArr; +%newobject ParaMEDMEM::MEDFileMesh::getNodeGroupArr; +%newobject ParaMEDMEM::MEDFileMesh::getNodeGroupsArr; +%newobject ParaMEDMEM::MEDFileMesh::getNodeFamilyArr; +%newobject ParaMEDMEM::MEDFileMesh::getNodeFamiliesArr; %newobject ParaMEDMEM::MEDFileUMesh::New; %newobject ParaMEDMEM::MEDFileUMesh::getCoords; %newobject ParaMEDMEM::MEDFileUMesh::getGroup; %newobject ParaMEDMEM::MEDFileUMesh::getGroups; %newobject ParaMEDMEM::MEDFileUMesh::getFamily; %newobject ParaMEDMEM::MEDFileUMesh::getFamilies; -%newobject ParaMEDMEM::MEDFileUMesh::getGroupArr; -%newobject ParaMEDMEM::MEDFileUMesh::getGroupsArr; -%newobject ParaMEDMEM::MEDFileUMesh::getFamilyArr; -%newobject ParaMEDMEM::MEDFileUMesh::getFamiliesArr; -%newobject ParaMEDMEM::MEDFileUMesh::getNodeGroupArr; -%newobject ParaMEDMEM::MEDFileUMesh::getNodeGroupsArr; -%newobject ParaMEDMEM::MEDFileUMesh::getNodeFamilyArr; -%newobject ParaMEDMEM::MEDFileUMesh::getNodeFamiliesArr; %newobject ParaMEDMEM::MEDFileUMesh::getMeshAtLevel; %newobject ParaMEDMEM::MEDFileUMesh::getLevel0Mesh; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM1Mesh; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM2Mesh; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM3Mesh; +%newobject ParaMEDMEM::MEDFileCMesh::New; + +%newobject ParaMEDMEM::MEDFileFields::New; +%newobject ParaMEDMEM::MEDFileFieldMultiTS::New; +%newobject ParaMEDMEM::MEDFileField1TS::New; class MEDLoader { @@ -207,14 +215,256 @@ public: static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception); }; -%include "MEDFileMesh.hxx" - -%extend ParaMEDMEM::MEDFileUMesh +namespace ParaMEDMEM { - void setGroupsAtLevel(int meshDimRelToMaxExt, PyObject *li, bool renum=false) throw(INTERP_KERNEL::Exception) + class MEDFileMesh : public RefCountObject + { + public: + static MEDFileMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1); + virtual void clearNonDiscrAttributes() const; + void setName(const char *name); + const char *getName(); + void setUnivName(const char *name); + const char *getUnivName() const; + void setDescription(const char *name); + const char *getDescription() const; + void setOrder(int order); + int getOrder() const; + void setIteration(int it); + int getIteration(); + void setTimeValue(double time); + void setTime(double time, int dt, int it); + double getTimeValue() const; + void setTimeUnit(const char *unit); + const char *getTimeUnit() const; + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + // + bool existsFamily(int famId) const; + bool existsFamily(const char *familyName) const; + void setFamilyId(const char *familyName, int id); + void addFamily(const char *familyName, int id) throw(INTERP_KERNEL::Exception); + void addGrpOnFamily(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception); + void copyFamGrpMapsFrom(const MEDFileMesh& other); + const std::map& getFamilyInfo() const; + const std::map >& getGroupInfo() const; + std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getGroupsNames() const; + std::vector getFamiliesNames() const; + void removeGroup(const char *name) throw(INTERP_KERNEL::Exception); + void removeFamily(const char *name) throw(INTERP_KERNEL::Exception); + void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + void setFamilyInfo(const std::map& info); + void setGroupInfo(const std::map >&info); + int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception); + int getMaxFamilyId() const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception); + std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception); + // + virtual MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception); + virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getNodeGroupsArr(const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getNodeFamiliesArr(const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); + %extend + { + PyObject *getTime() + { + int tmp1,tmp2; + double tmp0=self->getTime(tmp1,tmp2); + PyObject *res = PyList_New(3); + PyList_SetItem(res,0,SWIG_From_double(tmp0)); + PyList_SetItem(res,1,SWIG_From_int(tmp1)); + PyList_SetItem(res,2,SWIG_From_int(tmp2)); + return res; + } + + virtual PyObject *isEqual(const MEDFileMesh *other, double eps) const + { + std::string what; + bool ret0=self->isEqual(other,eps,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + + PyObject *areFamsEqual(const MEDFileMesh *other) const + { + std::string what; + bool ret0=self->areFamsEqual(other,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + + PyObject *areGrpsEqual(const MEDFileMesh *other) const + { + std::string what; + bool ret0=self->areGrpsEqual(other,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + + PyObject *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) + { + const DataArrayInt *tmp=self->getFamilyFieldAtLevel(meshDimRelToMaxExt); + if(tmp) + tmp->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + + PyObject *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) + { + const DataArrayInt *tmp=self->getNumberFieldAtLevel(meshDimRelToMaxExt); + if(tmp) + tmp->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + } + }; + + class MEDFileUMesh : public MEDFileMesh + { + public: + static MEDFileUMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); + static MEDFileUMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileUMesh *New(); + ~MEDFileUMesh(); + // + int getMeshDimension() const; + std::vector getNonEmptyLevels() const; + std::vector getNonEmptyLevelsExt() const; + DataArrayDouble *getCoords() const; + MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getFamily(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getFamilies(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getNodeGroupsArr(const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getNodeFamiliesArr(const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getMeshAtLevel(int meshDimRelToMaxExt, bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getLevel0Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getLevelM2Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); + // + void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception); + void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); + void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception); + void setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector& grpNames, bool renum=false) throw(INTERP_KERNEL::Exception); + void addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception); + void setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); + void setMeshAtLevelOld(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); + void setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception); + void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); + void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception); + void optimizeFamilies() throw(INTERP_KERNEL::Exception); + %extend + { + PyObject *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) + { + const DataArrayInt *tmp=self->getRevNumberFieldAtLevel(meshDimRelToMaxExt); + if(tmp) + tmp->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + + void setGroupsAtLevel(int meshDimRelToMaxExt, PyObject *li, bool renum=false) throw(INTERP_KERNEL::Exception) + { + std::vector grps; + convertPyObjToVecDataArrayIntCst(li,grps); + self->setGroupsAtLevel(meshDimRelToMaxExt,grps,renum); + } + } + }; + + class MEDFileCMesh : public MEDFileMesh + { + public: + static MEDFileCMesh *New(); + static MEDFileCMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); + void setMesh(MEDCouplingCMesh *m); + %extend + { + PyObject *getMesh() const + { + const MEDCouplingCMesh *tmp=self->getMesh(); + if(tmp) + tmp->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh, SWIG_POINTER_OWN | 0 ); + } + } + }; + + class MEDFieldFieldGlobs + { + public: + std::vector getPfls() const; + std::vector getLocs() const; + }; + + class MEDFileField1TSWithoutDAS : public RefCountObject + { + public: + int getIteration() const; + int getOrder() const; + std::string getName(); + std::string getMeshName(); + int getNumberOfComponents() const; + const std::vector& getInfos() const; + std::vector getPflsReallyUsed() const; + std::vector getLocsReallyUsed() const; + }; + + class MEDFileField1TS : public MEDFileField1TSWithoutDAS, public MEDFieldFieldGlobs + { + public: + static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + }; + + class MEDFileFieldMultiTSWithoutDAS + { + public: + int getNumberOfTS() const; + }; + + class MEDFileFieldMultiTS : public MEDFileFieldMultiTSWithoutDAS, public MEDFieldFieldGlobs + { + public: + static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); + }; + + class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobs { - std::vector grps; - convertPyObjToVecDataArrayIntCst(li,grps); - self->setGroupsAtLevel(meshDimRelToMaxExt,grps,renum); - } + public: + static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception); + int getNumberOfFields() const; + std::vector getPfls() const; + std::vector getLocs() const; + }; } diff --git a/src/MEDLoader/Swig/MEDLoaderTest.py b/src/MEDLoader/Swig/MEDLoaderTest.py index 4aa95056b..c8ca52755 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest.py +++ b/src/MEDLoader/Swig/MEDLoaderTest.py @@ -135,7 +135,6 @@ class MEDLoaderTest(unittest.TestCase): VAL2=-1111111111111.; name1="AField"; name3="AMesh1"; - name2="AMesh2"; f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); f1.getMesh().setName(name3); f1.setName(name1); @@ -146,14 +145,11 @@ class MEDLoaderTest(unittest.TestCase): f1.setTime(10.14,18,19); f1.getArray().setIJ(0,0,VAL2); MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); - f1.getMesh().setName(name2); + f1.getMesh().setName(name3); f1.setTime(10.55,28,29); f1.getArray().setIJ(0,0,3*VAL1); - MEDLoader.MEDLoader.WriteField(fileName,f1,False); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); vec=MEDLoader.MEDLoader.GetMeshNamesOnField(fileName,name1); - self.assertEqual(2,len(vec)); - self.assertTrue(vec[0]==name3); - self.assertTrue(vec[1]==name2); f1.setTime(10.66,38,39); f1.getArray().setIJ(0,0,3*VAL2); MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); @@ -163,7 +159,7 @@ class MEDLoaderTest(unittest.TestCase): #ON NODES f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1(); f1.setName(name1); - f1.getMesh().setName(name2); + f1.getMesh().setName(name3); f1.setTime(110.,8,9); MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.setTime(110.,108,109); @@ -175,39 +171,35 @@ class MEDLoaderTest(unittest.TestCase): MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); # it1=MEDLoader.MEDLoader.GetCellFieldIterations(fileName,name3,name1); - self.assertEqual(2,len(it1)); + self.assertEqual(5,len(it1)); self.assertEqual(8,it1[0][0]); self.assertEqual(9,it1[0][1]); self.assertEqual(18,it1[1][0]); self.assertEqual(19,it1[1][1]); - it2=MEDLoader.MEDLoader.GetCellFieldIterations(fileName,name2,name1); - self.assertEqual(3,len(it2)); - self.assertEqual(28,it2[0][0]); self.assertEqual(29,it2[0][1]); - self.assertEqual(38,it2[1][0]); self.assertEqual(39,it2[1][1]); - self.assertEqual(48,it2[2][0]); self.assertEqual(49,it2[2][1]); - it3=MEDLoader.MEDLoader.GetNodeFieldIterations(fileName,name2,name1); + self.assertEqual(28,it1[2][0]); self.assertEqual(29,it1[2][1]); + self.assertEqual(38,it1[3][0]); self.assertEqual(39,it1[3][1]); + self.assertEqual(48,it1[4][0]); self.assertEqual(49,it1[4][1]); + it3=MEDLoader.MEDLoader.GetNodeFieldIterations(fileName,name3,name1); self.assertEqual(3,len(it3)); self.assertEqual(8,it3[0][0]); self.assertEqual(9,it3[0][1]); self.assertEqual(108,it3[1][0]); self.assertEqual(109,it3[1][1]); self.assertEqual(208,it3[2][0]); self.assertEqual(209,it3[2][1]); - it4=MEDLoader.MEDLoader.GetNodeFieldIterations(fileName,name3,name1); - self.assertTrue(len(it4)==0); # # f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,8,9); self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,0),13); f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,18,19); self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name2,0,name1,28,29); + f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,28,29); self.assertAlmostEqual(3*VAL1,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name2,0,name1,38,39); + f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,38,39); self.assertAlmostEqual(3*VAL2,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name2,0,name1,48,49); + f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,48,49); self.assertAlmostEqual(4*VAL2,f1.getArray().getIJ(0,0),13); # - f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name2,0,name1,8,9); + f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name3,0,name1,8,9); self.assertAlmostEqual(71.,f1.getArray().getIJ(0,3),13); - f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name2,0,name1,108,109); + f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name3,0,name1,108,109); self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,3),13); - f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name2,0,name1,208,209); + f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name3,0,name1,208,209); self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,3),13); pass @@ -492,7 +484,7 @@ class MEDLoaderTest(unittest.TestCase): array.setValues(arr2,12,2) array.setInfoOnComponent(0,"plkj [mm]"); array.setInfoOnComponent(1,"pqqqss [mm]"); - f2.setTime(3.17,2,7); + f2.setTime(3.14,2,7); f2.checkCoherency(); # MEDLoader.MEDLoader.WriteField(fileName,f1,True); diff --git a/src/MEDLoader/Swig/MEDLoaderTest2.py b/src/MEDLoader/Swig/MEDLoaderTest2.py index b0ca6b1d4..c3cf5dfc1 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest2.py +++ b/src/MEDLoader/Swig/MEDLoaderTest2.py @@ -133,7 +133,6 @@ class MEDLoaderTest(unittest.TestCase): VAL2=-1111111111111.; name1="AField"; name3="AMesh1"; - name2="AMesh2"; f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); f1.getMesh().setName(name3); f1.setName(name1); @@ -144,10 +143,10 @@ class MEDLoaderTest(unittest.TestCase): f1.setTime(10.14,18,19); f1.getArray().setIJ(0,0,VAL2); MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); - f1.getMesh().setName(name2); + f1.getMesh().setName(name3); f1.setTime(10.55,28,29); f1.getArray().setIJ(0,0,3*VAL1); - MEDLoader.WriteFieldDep(fileName,f1,False); + MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.setTime(10.66,38,39); f1.getArray().setIJ(0,0,3*VAL2); MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); @@ -157,7 +156,7 @@ class MEDLoaderTest(unittest.TestCase): #ON NODES f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1(); f1.setName(name1); - f1.getMesh().setName(name2); + f1.getMesh().setName(name3); f1.setTime(110.,8,9); MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.setTime(110.,108,109); @@ -169,39 +168,35 @@ class MEDLoaderTest(unittest.TestCase): MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); # it1=MEDLoader.GetCellFieldIterations(fileName,name3,name1); - self.assertEqual(2,len(it1)); + self.assertEqual(5,len(it1)); self.assertEqual(8,it1[0][0]); self.assertEqual(9,it1[0][1]); self.assertEqual(18,it1[1][0]); self.assertEqual(19,it1[1][1]); - it2=MEDLoader.GetCellFieldIterations(fileName,name2,name1); - self.assertEqual(3,len(it2)); - self.assertEqual(28,it2[0][0]); self.assertEqual(29,it2[0][1]); - self.assertEqual(38,it2[1][0]); self.assertEqual(39,it2[1][1]); - self.assertEqual(48,it2[2][0]); self.assertEqual(49,it2[2][1]); - it3=MEDLoader.GetNodeFieldIterations(fileName,name2,name1); + self.assertEqual(28,it1[2][0]); self.assertEqual(29,it1[2][1]); + self.assertEqual(38,it1[3][0]); self.assertEqual(39,it1[3][1]); + self.assertEqual(48,it1[4][0]); self.assertEqual(49,it1[4][1]); + it3=MEDLoader.GetNodeFieldIterations(fileName,name3,name1); self.assertEqual(3,len(it3)); self.assertEqual(8,it3[0][0]); self.assertEqual(9,it3[0][1]); self.assertEqual(108,it3[1][0]); self.assertEqual(109,it3[1][1]); self.assertEqual(208,it3[2][0]); self.assertEqual(209,it3[2][1]); - it4=MEDLoader.GetNodeFieldIterations(fileName,name3,name1); - self.assertTrue(len(it4)==0); # # f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,8,9); self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,0),13); f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,18,19); self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.ReadFieldCell(fileName,name2,0,name1,28,29); + f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,28,29); self.assertAlmostEqual(3*VAL1,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.ReadFieldCell(fileName,name2,0,name1,38,39); + f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,38,39); self.assertAlmostEqual(3*VAL2,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.ReadFieldCell(fileName,name2,0,name1,48,49); + f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,48,49); self.assertAlmostEqual(4*VAL2,f1.getArray().getIJ(0,0),13); # - f1=MEDLoader.ReadFieldNode(fileName,name2,0,name1,8,9); + f1=MEDLoader.ReadFieldNode(fileName,name3,0,name1,8,9); self.assertAlmostEqual(71.,f1.getArray().getIJ(0,3),13); - f1=MEDLoader.ReadFieldNode(fileName,name2,0,name1,108,109); + f1=MEDLoader.ReadFieldNode(fileName,name3,0,name1,108,109); self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,3),13); - f1=MEDLoader.ReadFieldNode(fileName,name2,0,name1,208,209); + f1=MEDLoader.ReadFieldNode(fileName,name3,0,name1,208,209); self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,3),13); pass diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index a78a56263..355de88e9 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -27,7 +27,7 @@ class MEDLoaderTest(unittest.TestCase): def testMEDMesh1(self): fileName="Pyfile18.med" mname="ExampleOfMultiDimW" - medmesh=MEDFileUMesh.New(fileName,mname) + medmesh=MEDFileMesh.New(fileName,mname) self.assertEqual((0,-1),medmesh.getNonEmptyLevels()) m1_0=medmesh.getLevel0Mesh(True) m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0) @@ -69,13 +69,13 @@ class MEDLoaderTest(unittest.TestCase): self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],True).getValues()); self.assertEqual([19,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues()); famn=medmesh.getFamilyNameGivenId(0) - self.assertEqual(range(60),medmesh.getNodeFamilyArr(famn,True).getValues()); + self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True); #without renum self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2",False).getValues()); self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2",False).getValues()); self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],False).getValues()); self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues()); - self.assertEqual(range(60),medmesh.getNodeFamilyArr(famn,False).getValues()); + self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False); pass # this tests emulates MEDMEM ( Except that it works ! ) The permutation are NOT taken into account @@ -169,6 +169,8 @@ class MEDLoaderTest(unittest.TestCase): coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4] c.setValues(coords,9,2) + c.setInfoOnComponent(0,"abcdef [km]") + c.setInfoOnComponent(1,"ghij [MW]") m=MEDCouplingUMesh.New(); m.setMeshDimension(2); m.allocateCells(5); @@ -206,7 +208,7 @@ class MEDLoaderTest(unittest.TestCase): mm.setCoords(c) renumNode=DataArrayInt.New() renumNode.setValues([10,11,12,13,14,15,16,17,18],9,1) - mm.setRenumArr(1,renumNode) + mm.setRenumFieldArr(1,renumNode) mm.setMeshAtLevel(-1,m1); mm.setMeshAtLevel(0,m); mm.setMeshAtLevel(-2,m2); @@ -243,6 +245,63 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(g2_1.isEqual(t)); # mm.write(outFileName,2); + mm2=MEDFileMesh.New(outFileName) + res=mm.isEqual(mm2,1e-12) + self.assertTrue(res[0]) + pass + + #testing persistence of retrieved arrays + def testMEDMesh5(self): + fileName="Pyfile18.med" + mname="ExampleOfMultiDimW" + medmesh=MEDFileUMesh.New(fileName,mname) + m1_0=medmesh.getLevel0Mesh(True) + da1=medmesh.getFamilyFieldAtLevel(0) + del medmesh + self.assertEqual(20,m1_0.getNumberOfCells()) + self.assertEqual(20,da1.getNumberOfTuples()) + pass + + def testMEDMesh6(self): + outFileName="MEDFileMesh5.med" + m=MEDFileCMesh.New() + m.setTime(2.3,-1,-1) + m1=MEDCouplingCMesh.New(); + da=DataArrayDouble.New() + da.setValues([0.,1.,2.],3,1) + da.setInfoOnComponent(0,"XX [mm]") + m1.setCoordsAt(0,da) + da=DataArrayDouble.New() + da.setValues([0.,1.2],2,1) + da.setInfoOnComponent(0,"YY [km]") + m1.setCoordsAt(1,da) + da=DataArrayDouble.New() + da.setValues([0.,1.3],2,1) + da.setInfoOnComponent(0,"ZZ [um]") + m1.setCoordsAt(2,da) + m.setMesh(m1) + m.setName("myFirstCartMesh") + m.setDescription("mmmmpppppppp") + m.setTimeValue(2.3) + m.setTimeUnit("ms") + da=DataArrayInt.New() + da.setValues([0,0,1,0,1,2,4,3,0,1,2,2],12,1) + m.setFamilyFieldArr(1,da) + m.setFamilyId("family1",1) + da=m.getFamilyArr(1,"family1") + expected1=[2,4,9] + self.assertEqual(expected1,da.getValues()) + m.write(outFileName,2); + mm=MEDFileMesh.New(outFileName) + self.assertTrue(m.isEqual(mm,1e-12)[0]) + self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues()) + m2=mm.getMesh() + tt=m.getTime() + m1.setTime(tt[0],tt[1],tt[2]) + m1.setName(m.getName()) + m1.setTimeUnit(m.getTimeUnit()) + m1.setDescription(m.getDescription()) + self.assertTrue(m2.isEqual(m1,1e-12)); pass pass diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index 341fa6bfe..c2423d469 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -178,7 +178,6 @@ void MEDLoaderTest::testFieldRW3() static const double VAL2=-1111111111111.; const char name1[]="AField"; const char name3[]="AMesh1"; - const char name2[]="AMesh2"; MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1(); ((MEDCouplingMesh *)f1->getMesh())->setName(name3); f1->setName(name1); @@ -189,14 +188,9 @@ void MEDLoaderTest::testFieldRW3() f1->setTime(10.14,18,19); tmp[0]=VAL2; MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1); - ((MEDCouplingMesh *)f1->getMesh())->setName(name2); f1->setTime(10.55,28,29); tmp[0]=3*VAL1; - MEDLoader::WriteField(fileName,f1,false); - std::vector vec=MEDLoader::GetMeshNamesOnField(fileName,name1); - CPPUNIT_ASSERT_EQUAL(2,(int)vec.size()); - CPPUNIT_ASSERT(vec[0]==name3); - CPPUNIT_ASSERT(vec[1]==name2); + MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1->setTime(10.66,38,39); tmp[0]=3*VAL2; MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1); @@ -207,7 +201,7 @@ void MEDLoaderTest::testFieldRW3() f1->decrRef(); f1=buildVecFieldOnNodes_1(); f1->setName(name1); - ((MEDCouplingMesh *)f1->getMesh())->setName(name2); + ((MEDCouplingMesh *)f1->getMesh())->setName(name3); f1->setTime(110.,8,9); MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1->setTime(110.,108,109); @@ -219,21 +213,17 @@ void MEDLoaderTest::testFieldRW3() MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1); // std::vector< std::pair > it1=MEDLoader::GetCellFieldIterations(fileName,name3,name1); - CPPUNIT_ASSERT_EQUAL(2,(int)it1.size()); + CPPUNIT_ASSERT_EQUAL(5,(int)it1.size()); CPPUNIT_ASSERT_EQUAL(8,it1[0].first); CPPUNIT_ASSERT_EQUAL(9,it1[0].second); CPPUNIT_ASSERT_EQUAL(18,it1[1].first); CPPUNIT_ASSERT_EQUAL(19,it1[1].second); - std::vector< std::pair > it2=MEDLoader::GetCellFieldIterations(fileName,name2,name1); - CPPUNIT_ASSERT_EQUAL(3,(int)it2.size()); - CPPUNIT_ASSERT_EQUAL(28,it2[0].first); CPPUNIT_ASSERT_EQUAL(29,it2[0].second); - CPPUNIT_ASSERT_EQUAL(38,it2[1].first); CPPUNIT_ASSERT_EQUAL(39,it2[1].second); - CPPUNIT_ASSERT_EQUAL(48,it2[2].first); CPPUNIT_ASSERT_EQUAL(49,it2[2].second); - std::vector< std::pair > it3=MEDLoader::GetNodeFieldIterations(fileName,name2,name1); + CPPUNIT_ASSERT_EQUAL(28,it1[2].first); CPPUNIT_ASSERT_EQUAL(29,it1[2].second); + CPPUNIT_ASSERT_EQUAL(38,it1[3].first); CPPUNIT_ASSERT_EQUAL(39,it1[3].second); + CPPUNIT_ASSERT_EQUAL(48,it1[4].first); CPPUNIT_ASSERT_EQUAL(49,it1[4].second); + std::vector< std::pair > it3=MEDLoader::GetNodeFieldIterations(fileName,name3,name1); CPPUNIT_ASSERT_EQUAL(3,(int)it3.size()); CPPUNIT_ASSERT_EQUAL(8,it3[0].first); CPPUNIT_ASSERT_EQUAL(9,it3[0].second); CPPUNIT_ASSERT_EQUAL(108,it3[1].first); CPPUNIT_ASSERT_EQUAL(109,it3[1].second); CPPUNIT_ASSERT_EQUAL(208,it3[2].first); CPPUNIT_ASSERT_EQUAL(209,it3[2].second); - std::vector< std::pair > it4=MEDLoader::GetNodeFieldIterations(fileName,name3,name1); - CPPUNIT_ASSERT(it4.empty()); // f1->decrRef(); // @@ -243,23 +233,23 @@ void MEDLoaderTest::testFieldRW3() f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,18,19); CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[0],1e-13); f1->decrRef(); - f1=MEDLoader::ReadFieldCell(fileName,name2,0,name1,28,29); + f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,28,29); CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL1,f1->getArray()->getConstPointer()[0],1e-13); f1->decrRef(); - f1=MEDLoader::ReadFieldCell(fileName,name2,0,name1,38,39); + f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,38,39); CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL2,f1->getArray()->getConstPointer()[0],1e-13); f1->decrRef(); - f1=MEDLoader::ReadFieldCell(fileName,name2,0,name1,48,49); + f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,48,49); CPPUNIT_ASSERT_DOUBLES_EQUAL(4*VAL2,f1->getArray()->getConstPointer()[0],1e-13); f1->decrRef(); // - f1=MEDLoader::ReadFieldNode(fileName,name2,0,name1,8,9); + f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,8,9); CPPUNIT_ASSERT_DOUBLES_EQUAL(71.,f1->getArray()->getConstPointer()[3],1e-13); f1->decrRef(); - f1=MEDLoader::ReadFieldNode(fileName,name2,0,name1,108,109); + f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,108,109); CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[3],1e-13); f1->decrRef(); - f1=MEDLoader::ReadFieldNode(fileName,name2,0,name1,208,209); + f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,208,209); CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[3],1e-13); f1->decrRef(); } @@ -673,7 +663,7 @@ void MEDLoaderTest::testMixCellAndNodesFieldRW1() 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192. }; std::copy(arr2,arr2+24,tmp); - f2->setTime(3.17,2,7); + f2->setTime(3.14,2,7); f2->checkCoherency(); // MEDLoader::WriteField(fileName,f1,true);