From: ageay Date: Wed, 15 Jun 2011 07:54:16 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V5_1_6rc1~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3422cb7ec18e86ab14680172785ea7edd480722f;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDLoader/MEDFileBasis.cxx b/src/MEDLoader/MEDFileBasis.cxx new file mode 100644 index 000000000..0fedbd2c0 --- /dev/null +++ b/src/MEDLoader/MEDFileBasis.cxx @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileBasis.hxx" + +#include + +using namespace ParaMEDMEM; + +MEDFileString::MEDFileString(int maxLgth):_max_lgth(maxLgth),_content(new char[maxLgth+1]) +{ + std::fill(_content,_content+maxLgth+1,'\0'); +} + +MEDFileString::~MEDFileString() +{ + delete [] _content; +} + +void MEDFileString::set(const char *s) throw(INTERP_KERNEL::Exception) +{ + if((int)strlen(s)>_max_lgth) + throw INTERP_KERNEL::Exception("Name is too long to be stored in MEDfile !"); + std::fill(_content,_content+_max_lgth+1,'\0'); + strcpy(_content,s); +} + +std::string MEDFileString::getRepr() const +{ + return std::string(_content); +} + diff --git a/src/MEDLoader/MEDFileBasis.hxx b/src/MEDLoader/MEDFileBasis.hxx new file mode 100644 index 000000000..6e5394691 --- /dev/null +++ b/src/MEDLoader/MEDFileBasis.hxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEBASIS_HXX__ +#define __MEDFILEBASIS_HXX__ + +#include "InterpKernelException.hxx" + +#include +#include + +namespace ParaMEDMEM +{ + class MEDFileString + { + public: + MEDFileString(int maxLgth); + ~MEDFileString(); + void set(const char *s) throw(INTERP_KERNEL::Exception); + char *getPointer() { return _content; } + const char *getReprForWrite() const { return _content; } + std::string getRepr() const; + private: + int _max_lgth; + char *_content; + }; + + + class MEDFileMultiString + { + public: + MEDFileMultiString(int nbOfCompo, int maxLgthPerCompo); + ~MEDFileMultiString(); + void set(int compoId, const char *s); + const char *getReprForWrite() const; + std::vector getRepr() const; + std::string getReprPerComp(int compId) const; + private: + int _nb_of_comp; + int _max_lgth_per_comp; + char *_content; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx new file mode 100644 index 000000000..19fe8fdae --- /dev/null +++ b/src/MEDLoader/MEDFileField.cxx @@ -0,0 +1,643 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileField.hxx" +#include "MEDLoaderBase.hxx" +#include "MEDFileUtilities.hxx" + +#include "InterpKernelAutoPtr.hxx" + +#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]; + +using namespace ParaMEDMEM; + +MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileFieldPerMeshPerTypePerDisc(fath,fid); +} + +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); + std::string fieldName=getName(); + std::string meshName=getMeshName(); + int iteration=getIteration(); + int order=getOrder(); + 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); + _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; +} +catch(INTERP_KERNEL::Exception& e) +{ + throw e; +} + +const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const +{ + return _father; +} + +int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const +{ + return _father->getIteration(); +} + +int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const +{ + return _father->getOrder(); +} + +std::string MEDFileFieldPerMeshPerTypePerDisc::getName() const +{ + return _father->getName(); +} + +TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const +{ + return _father->getType(); +} + +INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const +{ + return _father->getGeoType(); +} + +std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const +{ + return _father->getMeshName(); +} + +int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const +{ + return _father->getNumberOfComponents(); +} + +const std::vector& MEDFileFieldPerMeshPerTypePerDisc::getInfos() const +{ + return _father->getInfos(); +} + +std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const +{ + return _profile; +} + +std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const +{ + return _localization; +} + +MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileFieldPerMeshPerType(fath,type,geoType); +} + +const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const +{ + return _father; +} + +int MEDFileFieldPerMeshPerType::getIteration() const +{ + return _father->getIteration(); +} + +int MEDFileFieldPerMeshPerType::getOrder() const +{ + return _father->getOrder(); +} + +std::string MEDFileFieldPerMeshPerType::getName() const +{ + return _father->getName(); +} + +std::string MEDFileFieldPerMeshPerType::getMeshName() const +{ + return _father->getMeshName(); +} + +TypeOfField MEDFileFieldPerMeshPerType::getType() const +{ + return _type; +} + +INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const +{ + return _geo_type; +} + + +int MEDFileFieldPerMeshPerType::getNumberOfComponents() const +{ + return _father->getNumberOfComponents(); +} + +const std::vector& MEDFileFieldPerMeshPerType::getInfos() const +{ + return _father->getInfos(); +} + +std::vector MEDFileFieldPerMeshPerType::getPflsReallyUsed() const +{ + std::vector ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++) + { + std::string tmp=(*it1)->getProfile(); + if(!tmp.empty()) + ret.push_back(tmp); + } + return ret; +} + +std::vector MEDFileFieldPerMeshPerType::getLocsReallyUsed() const +{ + std::vector ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++) + { + std::string tmp=(*it1)->getLocalization(); + if(!tmp.empty()) + ret.push_back(tmp); + } + return ret; +} + +MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_type(type),_geo_type(geoType) +{ +} + +void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception) +{ + //for MED3 porting this limitation will be killed ! + _field_pm_pt_pd.resize(1); + _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,fid); +} + +MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time) +{ + return new MEDFileFieldPerMesh(fath,meshName,time); +} + +void MEDFileFieldPerMesh::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) +{ + _types.push_back(type); + _geo_types.push_back(geoType); +} + +void MEDFileFieldPerMesh::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception) +{ + int sz=_types.size(); + _field_pm_pt.resize(sz); + for(int i=0;ifinishLoading(fid); + } +} + +double MEDFileFieldPerMesh::getTime() const +{ + return _time; +} + +int MEDFileFieldPerMesh::getIteration() const +{ + return _father->getIteration(); +} + +int MEDFileFieldPerMesh::getOrder() const +{ + return _father->getOrder(); +} + +std::string MEDFileFieldPerMesh::getName() const +{ + return _father->getName(); +} + +std::string MEDFileFieldPerMesh::getMeshName() const +{ + return _mesh_name; +} + +int MEDFileFieldPerMesh::getNumberOfComponents() const +{ + return _father->getNumberOfComponents(); +} + +const std::vector& MEDFileFieldPerMesh::getInfos() const +{ + return _father->getInfos(); +} + +std::vector MEDFileFieldPerMesh::getPflsReallyUsed() const +{ + std::vector ret; + std::set ret2; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + { + std::vector tmp=(*it)->getPflsReallyUsed(); + for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) + if(ret2.find(*it2)==ret2.end()) + { + ret.push_back(*it2); + ret2.insert(*it2); + } + } + return ret; +} + +std::vector MEDFileFieldPerMesh::getLocsReallyUsed() const +{ + std::vector ret; + std::set ret2; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + { + std::vector tmp=(*it)->getLocsReallyUsed(); + for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) + if(ret2.find(*it2)==ret2.end()) + { + ret.push_back(*it2); + ret2.insert(*it2); + } + } + return ret; +} + +MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time):_father(fath),_mesh_name(meshName),_time(time) +{ +} + +void MEDFieldFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName, int lgth) throw(INTERP_KERNEL::Exception) +{ + _pfls[id]=DataArrayInt::New(); + _pfls[id]->alloc(lgth,1); + MEDprofilLire(fid,_pfls[id]->getPointer(),(char *)pflName); +} + +void MEDFieldFieldGlobs::loadProfileInFile(med_idt fid, int i) +{ + INTERP_KERNEL::AutoPtr pflName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + int sz; + MEDprofilInfo(fid,i,pflName,&sz); + _pfls[i]=DataArrayInt::New(); + _pfls[i]->alloc(sz,1); + MEDprofilLire(fid,_pfls[i]->getPointer(),(char *)pflName); +} + +std::vector MEDFieldFieldGlobs::getPfls() const +{ + int sz=_pfls.size(); + std::vector ret(sz); + for(int i=0;igetName(); + return ret; +} + +std::vector MEDFieldFieldGlobs::getLocs() const +{ + int sz=_locs.size(); + std::vector ret(sz); + for(int i=0;igetName(); + return ret; +} + +MEDFileField1TSWithoutDAS *MEDFileField1TSWithoutDAS::New(const char *fieldName, int iteration, int order, const std::vector& infos) +{ + return new MEDFileField1TSWithoutDAS(fieldName,iteration,order,infos); +} + +void MEDFileField1TSWithoutDAS::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time, const char *meshName) 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); +} + +std::vector MEDFileField1TSWithoutDAS::getPflsReallyUsed() const +{ + std::vector ret; + std::set ret2; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + { + std::vector tmp=(*it)->getPflsReallyUsed(); + for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) + if(ret2.find(*it2)==ret2.end()) + { + ret.push_back(*it2); + ret2.insert(*it2); + } + } + return ret; +} + +std::vector MEDFileField1TSWithoutDAS::getLocsReallyUsed() const +{ + std::vector ret; + std::set ret2; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + { + std::vector tmp=(*it)->getLocsReallyUsed(); + for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) + if(ret2.find(*it2)==ret2.end()) + { + ret.push_back(*it2); + ret2.insert(*it2); + } + } + return ret; +} + +MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, int iteration, int order, const std::vector& infos):_name(fieldName),_infos(infos),_iteration(iteration),_order(order) +{ +} + +MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileField1TS(fileName,fieldName,iteration,order); +} + +MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) +try:MEDFileField1TSWithoutDAS(fieldName,iteration,order,std::vector()) +{ + MEDFileUtilities::CheckFileForRead(fileName); + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + int nbFields=MEDnChamp(fid,0); + med_type_champ 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); + std::string tmp(nomcha); + fns[i]=tmp; + found=(tmp==fieldName); + if(found) + { + _infos.resize(ncomp); + for(int j=0;j(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + finishLoading(fid); + // + std::vector profiles=getPflsReallyUsed(); + int sz=profiles.size(); + _pfls.resize(sz); + for(int i=0;i& infos) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos); +} + +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) +try:_name(fieldName),_infos(infos) +{ + finishLoading(fid); +} +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +void MEDFileFieldMultiTSWithoutDAS::finishLoading(med_idt fid) 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) +{ + std::vector< std::pair > ts; + med_int ngauss=0; + med_int numdt=0,numo=0,nbrefmaa; + 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); + 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); + } + 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); + } +} + +std::vector MEDFileFieldMultiTSWithoutDAS::getPflsReallyUsed() const +{ + std::vector ret; + std::set ret2; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutDAS > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + { + std::vector tmp=(*it)->getPflsReallyUsed(); + for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) + if(ret2.find(*it2)==ret2.end()) + { + ret.push_back(*it2); + ret2.insert(*it2); + } + } + return ret; +} + +std::vector MEDFileFieldMultiTSWithoutDAS::getLocsReallyUsed() const +{ + std::vector ret; + std::set ret2; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutDAS > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + { + std::vector tmp=(*it)->getLocsReallyUsed(); + for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) + if(ret2.find(*it2)==ret2.end()) + { + ret.push_back(*it2); + ret2.insert(*it2); + } + } + return ret; +} + +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) +{ + MEDFileUtilities::CheckFileForRead(fileName); + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + int nbFields=MEDnChamp(fid,0); + med_type_champ 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); + std::string tmp(nomcha); + fns[i]=tmp; + found=(tmp==fieldName); + if(found) + { + _infos.resize(ncomp); + for(int j=0;j(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + finishLoading(fid); + MEDfermer(fid); +} +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileFields(fileName); +} + +int MEDFileFields::getNumberOfFields() const +{ + return _fields.size(); +} + +MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception) +try + { + MEDFileUtilities::CheckFileForRead(fileName); + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + int nbFields=MEDnChamp(fid,0); + _fields.resize(nbFields); + med_type_champ 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); + std::vector infos(ncomp); + for(int j=0;j +#include + +extern "C" +{ +#include "med.h" +} + +namespace ParaMEDMEM +{ + class MEDFileFieldLoc : public RefCountObject + { + public: + const std::string& getName() const { return _name; } + private: + int _dim; + int _nb_gauss_pt; + int _nb_node_per_cell; + std::string _name; + INTERP_KERNEL::NormalizedCellType _geo_type; + std::vector _ref_coo; + std::vector _gs_coo; + std::vector _w; + }; + + class MEDFileFieldPerMeshPerType; + class MEDFileField1TSWithoutDAS; + class MEDFileFieldPerMesh; + + class MEDFileFieldPerMeshPerTypePerDisc : public RefCountObject + { + public: + static MEDFileFieldPerMeshPerTypePerDisc *New(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception); + const MEDFileFieldPerMeshPerType *getFather() const; + int getIteration() const; + int getOrder() const; + std::string getName() const; + std::string getMeshName() const; + TypeOfField getType() const; + INTERP_KERNEL::NormalizedCellType getGeoType() const; + int getNumberOfComponents() const; + const std::vector& 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; + std::string _profile; + std::string _localization; + std::string _mesh_name; + }; + + class MEDFileFieldPerMeshPerType : public RefCountObject + { + public: + static MEDFileFieldPerMeshPerType *New(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception); + const MEDFileFieldPerMesh *getFather() const; + void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); + int getIteration() const; + int getOrder() const; + std::string getName() const; + std::string getMeshName() const; + TypeOfField getType() const; + INTERP_KERNEL::NormalizedCellType getGeoType() const; + int getNumberOfComponents() const; + const std::vector& getInfos() const; + std::vector getPflsReallyUsed() const; + std::vector getLocsReallyUsed() const; + private: + MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception); + private: + MEDFileFieldPerMesh *_father; + std::vector< MEDCouplingAutoRefCountObjectPtr > _field_pm_pt_pd; + TypeOfField _type; + INTERP_KERNEL::NormalizedCellType _geo_type; + }; + + class MEDFileFieldPerMesh : public RefCountObject + { + public: + static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time); + void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType); + void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); + double getTime() const; + int getIteration() const; + int getOrder() const; + std::string getName() const; + std::string getMeshName() const; + int getNumberOfComponents() const; + const std::vector& getInfos() const; + std::vector getPflsReallyUsed() const; + std::vector getLocsReallyUsed() const; + private: + MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time); + private: + MEDFileField1TSWithoutDAS *_father; + std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > _field_pm_pt; + std::string _mesh_name; + double _time; + private: + mutable std::vector _types; + mutable std::vector _geo_types; + }; + + class MEDFieldFieldGlobs + { + public: + 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; + protected: + std::vector< MEDCouplingAutoRefCountObjectPtr > _pfls; + std::vector< MEDCouplingAutoRefCountObjectPtr > _locs; + }; + + 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; } + int getNumberOfComponents() const { return _infos.size(); } + const std::vector& getInfos() const { return _infos; } + std::vector getPflsReallyUsed() const; + std::vector getLocsReallyUsed() const; + protected: + MEDFileField1TSWithoutDAS(const char *fieldName, int iteration, int order, const std::vector& infos); + protected: + std::string _name; + std::vector _infos; + std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > > _field_per_mesh; + int _iteration; + int _order; + private: + mutable std::vector _types; + mutable std::vector _geo_types; + mutable std::vector _times; + mutable std::vector _meshes; + }; + + /*! + * User class. + */ + class MEDFileField1TS : public MEDFileField1TSWithoutDAS, public MEDFieldFieldGlobs + { + public: + static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + private: + MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + }; + + class MEDFileFieldMultiTSWithoutDAS : public RefCountObject + { + public: + static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, const std::vector& infos) throw(INTERP_KERNEL::Exception); + 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); + std::vector getPflsReallyUsed() const; + std::vector getLocsReallyUsed() const; + protected: + std::string _name; + std::vector _infos; + std::vector< MEDCouplingAutoRefCountObjectPtr > _time_steps; + }; + + /*! + * User class. + */ + class MEDFileFieldMultiTS : public MEDFileFieldMultiTSWithoutDAS, public MEDFieldFieldGlobs + { + public: + static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); + private: + MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); + }; + + /*! + * Use class. + */ + class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobs + { + 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: + std::vector< MEDCouplingAutoRefCountObjectPtr > _fields; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx new file mode 100644 index 000000000..7540e4f89 --- /dev/null +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -0,0 +1,970 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileMesh.hxx" +#include "MEDFileUtilities.hxx" +#include "MEDLoader.hxx" +#include "MEDLoaderBase.hxx" + +#include "MEDCouplingUMesh.hxx" + +#include "InterpKernelAutoPtr.hxx" + +#include + +using namespace ParaMEDMEM; + +MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileUMesh(fileName,mName); +} + +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()); + } + 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) + { + std::vector ret(ret0.size()+1); + ret[0]=1; + std::copy(ret0.begin(),ret0.end(),ret.begin()+1); + return ret; + } + return ret0; +} + +int MEDFileUMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map::const_iterator it=_families.find(oname); + std::vector fams=getFamiliesNames(); + if(it==_families.end()) + { + 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 MEDFileUMesh::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 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++) + { + 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 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(!((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->getFamilyField(); +} + +const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + 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) +{ + 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(); +} + +std::vector MEDFileUMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map >::const_iterator it=_groups.find(oname); + std::vector grps=getGroupsNames(); + if(it==_groups.end()) + { + std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :"; + std::copy(grps.begin(),grps.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return (*it).second; +} + +std::vector MEDFileUMesh::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception) +{ + std::vector ret; + for(std::map >::const_iterator it1=_groups.begin();it1!=_groups.end();it1++) + { + for(std::vector::const_iterator it2=(*it1).second.begin();it2!=(*it1).second.end();it2++) + if((*it2)==name) + { + ret.push_back((*it1).first); + break; + } + } + return ret; +} + +std::vector MEDFileUMesh::getGroupsNames() const +{ + std::vector ret(_groups.size()); + int i=0; + for(std::map >::const_iterator it=_groups.begin();it!=_groups.end();it++,i++) + ret[i]=(*it).first; + return ret; +} + +std::vector MEDFileUMesh::getFamiliesNames() const +{ + std::vector ret(_families.size()); + int i=0; + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++,i++) + ret[i]=(*it).first; + return ret; +} + +void MEDFileUMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map >::iterator it=_groups.find(oname); + std::vector grps=getGroupsNames(); + if(it==_groups.end()) + { + std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :"; + std::copy(grps.begin(),grps.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _groups.erase(it); +} + +void MEDFileUMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map::iterator it=_families.find(oname); + std::vector fams=getFamiliesNames(); + if(it==_families.end()) + { + 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()); + } + _families.erase(it); +} + +void MEDFileUMesh::changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception) +{ + std::string oname(oldName); + std::map >::iterator it=_groups.find(oname); + std::vector grps=getGroupsNames(); + if(it==_groups.end()) + { + std::ostringstream oss; oss << "No such groupname \"" << oldName << "\" !\nAvailable groups are :"; + std::copy(grps.begin(),grps.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::string nname(newName); + it=_groups.find(nname); + if(it!=_groups.end()) + { + 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; + _groups.erase(it); + _groups[newName]=cpy; +} + +void MEDFileUMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception) +{ + std::string oname(oldName); + std::map::iterator it=_families.find(oname); + std::vector fams=getFamiliesNames(); + if(it==_families.end()) + { + std::ostringstream oss; oss << "No such familyname \"" << oldName << "\" !\nAvailable families are :"; + std::copy(fams.begin(),fams.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::string nname(newName); + it=_families.find(nname); + if(it!=_families.end()) + { + std::ostringstream oss; oss << "Such familyname \"" << newName << " already exists ! Kill it before !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + int cpy=(*it).second; + _families.erase(it); + _families[newName]=cpy; +} + +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) +{ + std::vector tmp(1); + tmp[0]=grp; + MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum); + ret->setName(grp); + return ret; +} + +DataArrayInt *MEDFileUMesh::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; +} + +MEDCouplingUMesh *MEDFileUMesh::getGroups(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 getFamilies(meshDimRelToMaxExt,fams2,renum); +} + +DataArrayInt *MEDFileUMesh::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); +} + +MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=fam; + MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum); + ret->setName(fam); + return ret; +} + +DataArrayInt *MEDFileUMesh::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; +} + +MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +{ + 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) +{ + std::vector famIds=getFamiliesIds(fams); + if(meshDimRelToMaxExt==1) + { + MEDCouplingAutoRefCountObjectPtr da=_fam_coords->getIdsEqualList(famIds); + return MEDFileUMeshSplitL1::Renumber(_num_coords,da); + } + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + return l1->getFamilyPartArr(famIds,renum); +} + +DataArrayInt *MEDFileUMesh::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 *MEDFileUMesh::getNodeGroupsArr(const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getGroupsArr(1,grps,renum); +} + +DataArrayInt *MEDFileUMesh::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 *MEDFileUMesh::getNodeFamiliesArr(const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getFamiliesArr(1,fams,renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + { + if(!renum) + { + MEDCouplingUMesh *umesh=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr cc=_coords->deepCpy(); + umesh->setCoords(cc); + return umesh; + } + } + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + return l1->getWholeMesh(renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getLevel0Mesh(bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtLevel(0,renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getLevelM1Mesh(bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtLevel(-1,renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getLevelM2Mesh(bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtLevel(-2,renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getLevelM3Mesh(bool renum) const throw(INTERP_KERNEL::Exception) +{ + 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) + throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !"); + if(meshDimRelToMaxExt>1) + throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !"); + int tracucedRk=-meshDimRelToMaxExt; + if(tracucedRk>=(int)_ms.size()) + throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !"); + if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0) + throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !"); + return _ms[tracucedRk]; +} + +MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !"); + if(meshDimRelToMaxExt>1) + throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !"); + int tracucedRk=-meshDimRelToMaxExt; + if(tracucedRk>=(int)_ms.size()) + throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !"); + if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0) + throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !"); + return _ms[tracucedRk]; +} + +void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) +{ + if(-meshDimRelToMax>=(int)_ms.size()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : The meshdim of mesh is not managed by 'this' !"); + int i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++) + { + if(((const MEDFileUMeshSplitL1*) (*it))!=0) + { + int ref=(*it)->getMeshDimension(); + if(ref+i!=meshDim-meshDimRelToMax) + throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : no coherency between levels !"); + } + } +} + +void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception) +{ + coords->checkAllocated(); + int nbOfTuples=coords->getNumberOfTuples(); + _coords=coords; + coords->incrRef(); + _fam_coords=DataArrayInt::New(); + _fam_coords->alloc(nbOfTuples,1); + _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) + { + if((DataArrayInt *)_fam_coords) + _fam_coords->fillWithZero(); + return ; + } + MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + l1->eraseFamilyField(); + optimizeFamilies(); +} + +void MEDFileUMesh::optimizeFamilies() throw(INTERP_KERNEL::Exception) +{ + std::vector levs=getNonEmptyLevelsExt(); + std::set allFamsIds; + for(std::vector::const_iterator it=levs.begin();it!=levs.end();it++) + { + const DataArrayInt *ffield=getFamilyFieldAtLevel(*it); + std::set ids=ffield->getDifferentValues(); + std::set res; + std::set_union(ids.begin(),ids.end(),allFamsIds.begin(),allFamsIds.end(),std::inserter(res,res.begin())); + allFamsIds=res; + } + std::set famNamesToKill; + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) + { + if(allFamsIds.find((*it).second)!=allFamsIds.end()) + famNamesToKill.insert((*it).first); + } + for(std::set::const_iterator it=famNamesToKill.begin();it!=famNamesToKill.end();it++) + _families.erase(*it); + std::vector grpNamesToKill; + for(std::map >::iterator it=_groups.begin();it!=_groups.end();it++) + { + std::vector tmp; + for(std::vector::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++) + { + if(famNamesToKill.find(*it2)==famNamesToKill.end()) + tmp.push_back(*it2); + } + if(!tmp.empty()) + (*it).second=tmp; + else + tmp.push_back((*it).first); + } + for(std::vector::const_iterator it=grpNamesToKill.begin();it!=grpNamesToKill.end();it++) + _groups.erase(*it); +} + +void MEDFileUMesh::setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector& grpNames, bool renum) throw(INTERP_KERNEL::Exception) +{ + +} + +void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception) +{ + const DataArrayDouble *coords=_coords; + if(!coords) + throw INTERP_KERNEL::Exception("addNodeGroup : no coords set !"); + DataArrayInt *sub=_fam_coords->selectByTupleIdSafe(&ids[0],&ids[0]+ids.size()); + std::set ssub(sub->getConstPointer(),sub->getConstPointer()+sub->getNumberOfTuples()); + +} + +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); + _families.erase(oldName); + _families[newFamName]=id; +} + +void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception) +{ + setMeshAtLevelGen(meshDimRelToMax,m,true); +} + +void MEDFileUMesh::setMeshAtLevelOld(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception) +{ + setMeshAtLevelGen(meshDimRelToMax,m,false); +} + +void MEDFileUMesh::setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception) +{ + std::vector levSet=getNonEmptyLevels(); + if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end()) + { + if((DataArrayDouble *)_coords==0) + { + DataArrayDouble *c=m->getCoords(); + if(c) + c->incrRef(); + _coords=c; + } + else + { + if(m->getCoords()!=_coords) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtLevel : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !"); + int sz=(-meshDimRelToMax)+1; + if(sz>=(int)_ms.size()) + _ms.resize(sz); + checkMeshDimCoherency(m->getMeshDimension(),meshDimRelToMax); + _ms[sz-1]=new MEDFileUMeshSplitL1(m,newOrOld); + } + } +} + +void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception) +{ + if(ms.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : expecting a non empty vector !"); + int sz=(-meshDimRelToMax)+1; + if(sz>=(int)_ms.size()) + _ms.resize(sz); + checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax); + DataArrayDouble *coo=checkMultiMesh(ms); + if((DataArrayDouble *)_coords==0) + { + coo->incrRef(); + _coords=coo; + } + else + if((DataArrayDouble *)_coords!=coo) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : coordinates mismatches !"); + std::vector corr; + MEDCouplingAutoRefCountObjectPtr m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,_zipconn_pol,corr); + std::vector< MEDCouplingAutoRefCountObjectPtr > corr3(corr.begin(),corr.end()); + setMeshAtLevel(meshDimRelToMax,m); + std::vector corr2(corr.begin(),corr.end()); + setGroupsAtLevel(meshDimRelToMax,corr2,true); +} + +void MEDFileUMesh::setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception) +{ + if(ms.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : expecting a non empty vector !"); + int sz=(-meshDimRelToMax)+1; + if(sz>=(int)_ms.size()) + _ms.resize(sz); + checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax); + DataArrayDouble *coo=checkMultiMesh(ms); + if((DataArrayDouble *)_coords==0) + { + coo->incrRef(); + _coords=coo; + } + else + if((DataArrayDouble *)_coords!=coo) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : coordinates mismatches !"); + MEDCouplingUMesh *m=getMeshAtLevel(meshDimRelToMax,renum); + std::vector< MEDCouplingAutoRefCountObjectPtr > corr(ms.size()); + int i=0; + for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++,i++) + { + DataArrayInt *arr=0; + bool test=m->areCellsIncludedIn(*it,_zipconn_pol,arr); + corr[i]=arr; + if(!test) + { + std::ostringstream oss; oss << "MEDFileUMesh::setGroupsOnSetMesh : mesh #" << i << " is not part of whole mesh !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + std::vector corr2(corr.begin(),corr.end()); + setGroupsAtLevel(meshDimRelToMax,corr2,renum); +} + +DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector& ms) const throw(INTERP_KERNEL::Exception) +{ + const DataArrayDouble *ret=ms[0]->getCoords(); + int mdim=ms[0]->getMeshDimension(); + for(unsigned int i=1;icheckCoherency(); + if(ms[i]->getCoords()!=ret) + throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes must share the same coords !"); + if(ms[i]->getMeshDimension()!=mdim) + throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes have not same mesh dimension !"); + } + return const_cast(ret); +} + +void MEDFileUMesh::setFamilyArr(int meshDimRelToMaxExt, DataArrayInt *famArr) +{ + if(meshDimRelToMaxExt==1) + { + famArr->incrRef(); + _fam_coords=famArr; + return ; + } + if(meshDimRelToMaxExt>1) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyArr : 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 !"); + if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0) + throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !"); + return _ms[traducedRk]->setFamilyArr(famArr); +} + +void MEDFileUMesh::setRenumArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) +{ + if(meshDimRelToMaxExt==1) + { + if(renumArr) + renumArr->incrRef(); + _num_coords=renumArr; + computeRevNum(); + return ; + } + if(meshDimRelToMaxExt>1) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumArr : 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 !"); + if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0) + throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !"); + return _ms[traducedRk]->setRenumArr(renumArr); +} + +void MEDFileUMesh::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)); +} + +/*! + * 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) +{ + 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]); + } + } +} + +/*! + * 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) +{ + std::string fname(familyName); + std::map::const_iterator it=_families.find(fname); + if(it==_families.end()) + { + 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; + } + else + { + if((*it).second!=famId) + { + 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()); + } + } +} + +void MEDFileUMesh::computeRevNum() const +{ + if((const DataArrayInt *)_num_coords) + { + int pos; + int maxValue=_num_coords->getMaxValue(pos); + _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1); + } +} diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx new file mode 100644 index 000000000..64b05dfa6 --- /dev/null +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -0,0 +1,143 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEMESH_HXX__ +#define __MEDFILEMESH_HXX__ + +#include "MEDFileMeshLL.hxx" + +#include + +namespace ParaMEDMEM +{ + class MEDFileMesh : public RefCountObject + { + public: + static MEDFileMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + 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(); } + protected: + std::string _name; + std::string _univ_name; + std::string _desc_name; + }; + + class MEDFileUMesh : public MEDFileMesh + { + public: + static MEDFileUMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + static MEDFileUMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileUMesh *New(); + ~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); + 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 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); + void addFamily(int famId, const char *familyName) throw(INTERP_KERNEL::Exception); + private: + MEDFileUMesh(); + MEDFileUMesh(const char *fileName, const char *mName) 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); + 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 + { + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx new file mode 100644 index 000000000..9fa3dfbe0 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -0,0 +1,253 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileMeshElt.hxx" + +#include "MEDCouplingUMesh.hxx" + +#include "InterpKernelAutoPtr.hxx" +#include "CellModel.hxx" + +extern med_geometrie_element typmai3[32]; + +using namespace ParaMEDMEM; + +MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2) +{ + med_entite_maillage whichEntity; + if(!isExisting(fid,mName,geoElt,whichEntity)) + return 0; + return new MEDFileUMeshPerType(fid,mName,mdim,geoElt,geoElt2,whichEntity); +} + +bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity) +{ + static const med_entite_maillage entities[3]={MED_MAILLE,MED_FACE,MED_ARETE}; + int nbOfElt=0; + for(int i=0;i<3;i++) + { + int tmp=MEDnEntMaa(fid,(char *)mName,MED_CONN,entities[i],geoElt,MED_NOD); + if(tmp>nbOfElt) + { + nbOfElt=tmp; + whichEntity=entities[i]; + } + } + return nbOfElt>0; +} + +int MEDFileUMeshPerType::getDim() const +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_type); + 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) +{ + int curNbOfElem=MEDnEntMaa(fid,(char *)mName,MED_CONN,entity,geoElt,MED_NOD); + if(type!=INTERP_KERNEL::NORM_POLYGON && type!=INTERP_KERNEL::NORM_POLYHED) + { + loadFromStaticType(fid,mName,mdim,curNbOfElem,geoElt,type,entity); + return; + } + if(type==INTERP_KERNEL::NORM_POLYGON) + { + loadPolyg(fid,mName,mdim,curNbOfElem,geoElt,entity); + return; + } + //if(type==INTERP_KERNEL::NORM_POLYHED) + loadPolyh(fid,mName,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) +{ + _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]; + _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; + int *w1=_conn->getPointer(); + int *w2=_conn_index->getPointer(); + *w2++=0; + const int *wi=connTab; + for(int i=0;i(),-1)); + *w2=w2[-1]+nbOfNodesPerCell+1; + } + delete [] connTab; + if(!inuele) + _num=0; +} + +void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, + med_entite_maillage entity) +{ + med_int arraySize; + MEDpolygoneInfo(fid,(char *)mName,entity,MED_NOD,&arraySize); + _conn_index=DataArrayInt::New(); + _conn_index->alloc(curNbOfElem+1,1); + _conn=DataArrayInt::New(); + _conn->alloc(arraySize+curNbOfElem,1); + _num=DataArrayInt::New(); + _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); + int *w1=_conn->getPointer(); + int *w2=_conn_index->getPointer(); + const int *wi=locConn; + for(int i=0;i(),-1)); + *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) + _num=0; +} + +void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, + med_entite_maillage 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]; + _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); + int arraySize=connFaceLgth; + for(int i=0;ialloc(arraySize+curNbOfElem,1); + int *wFinalConn=_conn->getPointer(); + _conn_index=DataArrayInt::New(); + _conn_index->alloc(curNbOfElem+1,1); + int *finalIndex=_conn_index->getPointer(); + finalIndex[0]=0; + for(int i=0;i(),-1)); + for(int j=index[i];j(),-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) + _num=0; +} + +void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num) +{ + int nbOfCells=m->getNumberOfCells(); + if(nbOfCells<1) + return ; + INTERP_KERNEL::NormalizedCellType ikt=m->getTypeOfCell(0); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(ikt); + med_geometrie_element 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) + { + int nbNodesPerCell=cm.getNumberOfNodes(); + INTERP_KERNEL::AutoPtr tab=new int[nbNodesPerCell*nbOfCells]; + int *w=tab; + for(int i=0;i(),1)); + MEDconnEcr(fid,(char *)mname,mdim,tab,MED_FULL_INTERLACE,nbOfCells,MED_MAILLE,curMedType,MED_NOD); + } + else + { + if(ikt==INTERP_KERNEL::NORM_POLYGON) + { + INTERP_KERNEL::AutoPtr tab1=new int[nbOfCells+1]; + INTERP_KERNEL::AutoPtr tab2=new int[m->getMeshLength()]; + int *wI=tab1; *wI=1; + int *w=tab2; + for(int i=0;i(),1)); + } + MEDpolygoneConnEcr(fid,(char *)mname,tab1,nbOfCells,tab2,MED_MAILLE,MED_NOD); + } + else + { + int meshLgth=m->getMeshLength(); + int nbOfFaces=std::count(conn,conn+meshLgth,-1)+nbOfCells; + INTERP_KERNEL::AutoPtr tab1=new int[nbOfCells+1]; + int *w1=tab1; *w1=1; + INTERP_KERNEL::AutoPtr tab2=new int[nbOfFaces+1]; + int *w2=tab2; *w2=1; + INTERP_KERNEL::AutoPtr bigtab=new int[meshLgth-nbOfCells]; + int *bt=bigtab; + for(int i=0;i(),1)); + int nbOfNode=std::distance(w,wend); + w2[1]=w2[0]+nbOfNode; + if(wend!=conn+connI[i+1]) + w=wend+1; + else + w=wend; + nbOfFaces++; + } + w1[1]=w1[0]+nbOfFaces; + } + MEDpolyedreConnEcr(fid,(char *)mname,tab1,nbOfCells+1,tab2,nbOfFaces+1, + bigtab,MED_NOD); + } + } + if(fam) + MEDfamEcr(fid,(char *)mname,(int *)fam->getConstPointer(),nbOfCells,MED_MAILLE,curMedType); + if(num) + MEDnumEcr(fid,(char *)mname,(int *)num->getConstPointer(),nbOfCells,MED_MAILLE,curMedType); +} diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx new file mode 100644 index 000000000..732ca2b43 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -0,0 +1,67 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEMESHELT_HXX__ +#define __MEDFILEMESHELT_HXX__ + +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +#include "NormalizedUnstructuredMesh.hxx" + +extern "C" +{ +#include "med.h" +} + +namespace ParaMEDMEM +{ + class MEDCouplingUMesh; + + 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); + int getDim() const; + const DataArrayInt *getNodal() const { return _conn; } + const DataArrayInt *getNodalIndex() const { return _conn_index; } + const DataArrayInt *getFam() const { return _fam; } + 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); + private: + MEDCouplingAutoRefCountObjectPtr _conn; + MEDCouplingAutoRefCountObjectPtr _conn_index; + MEDCouplingAutoRefCountObjectPtr _num; + MEDCouplingAutoRefCountObjectPtr _fam; + INTERP_KERNEL::NormalizedCellType _type; + med_entite_maillage _entity; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx new file mode 100644 index 000000000..e0e7840f4 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -0,0 +1,547 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileMeshLL.hxx" +#include "MEDLoaderBase.hxx" + +#include "MEDCouplingUMesh.hxx" + +#include "InterpKernelAutoPtr.hxx" + +#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]; + +using namespace ParaMEDMEM; + +MEDFileMeshL2::MEDFileMeshL2():_name(MED_TAILLE_NOM),_description(MED_TAILLE_DESC) +{ +} + +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() +{ + 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); + bool found=false; + int ret=-1; + std::vector ms; + for(int i=0;i(oss,", ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return ret; +} + +void MEDFileUMeshL2::readFamiliesAndGrps(med_idt fid, const char *meshName, std::map& fams, std::map >& grps) +{ + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + int nfam=MEDnFam(fid,(char *)meshName); + for(int i=0;i& fams, const std::map >& grps, int tooLongStrPol) +{ + for(std::map::const_iterator it=fams.begin();it!=fams.end();it++) + { + std::vector grpsOfFam; + for(std::map >::const_iterator it1=grps.begin();it1!=grps.end();it1++) + { + if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end()) + grpsOfFam.push_back((*it1).first); + } + int ngro=grpsOfFam.size(); + INTERP_KERNEL::AutoPtr groName=MEDLoaderBase::buildEmptyString(MED_TAILLE_LNOM*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); + } +} + +void MEDFileUMeshL2::writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords) +{ + 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); + 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,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 + } + 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); + if(numCoords) + MEDnumEcr(fid,(char *)mname,numCoords->getPointer(),numCoords->getNumberOfTuples(),MED_NOEUD,MED_NONE); +} + +bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) + if((*it)->getFam()==0) + return false; + return true; +} + +bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) + if((*it)->getNum()==0) + return false; + return true; +} + +MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0) +{ +} + +/*! + * Warning it returns an instance to deallocate !!!! + */ +MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const +{ + _st->_m_by_types->updateTime(); + _st->_num->updateTime(); + if((MEDCouplingUMesh *)_m==0) + { + updateTime(); + MEDCouplingUMesh *ret=(MEDCouplingUMesh *)_st->_m_by_types->deepCpy(); + _m=ret; + _m->renumberCells(_st->_num->getConstPointer(),true); + ret->incrRef(); + return ret; + } + else + { + if(_mpt_time==_st->_m_by_types->getTimeOfThis() && _num_time==_st->_num->getTimeOfThis()) + { + _m->incrRef(); + return _m; + } + else + { + updateTime(); + MEDCouplingUMesh *ret=(MEDCouplingUMesh *)_st->_m_by_types->deepCpy(); + _m=ret; + _m->renumberCells(_st->_num->getConstPointer(),true); + ret->incrRef(); + return ret; + } + } +} + +void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m) +{ + _m=m; +} + +void MEDFileUMeshPermCompute::updateTime() const +{ + _mpt_time=_st->_m_by_types->getTimeOfThis(); + _num_time=_st->_num->getTimeOfThis(); +} + +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id):_m(this) +{ + const std::vector< MEDCouplingAutoRefCountObjectPtr >& v=l2.getLev(id); + if(v.empty()) + return; + int sz=v.size(); + std::vector ms(sz); + for(int i=0;igetDim()); + MEDCouplingAutoRefCountObjectPtr tmp2=l2.getCoords(); + tmp->setCoords(tmp2); + tmp->setConnectivity(const_cast(v[i]->getNodal()),const_cast(v[i]->getNodalIndex())); + ms[i]=tmp; + } + _m_by_types=MEDCouplingUMesh::MergeUMeshesOnSameCoords(ms); + _m_by_types->setName(mName); + if(l2.isFamDefinedOnLev(id)) + { + int nbOfCells=_m_by_types->getNumberOfCells(); + _fam=DataArrayInt::New(); + _fam->alloc(nbOfCells,1); + int *w=_fam->getPointer(); + for(int i=0;igetFam()->getConstPointer(),v[i]->getFam()->getConstPointer()+v[i]->getFam()->getNumberOfTuples(),w); + } + if(l2.isNumDefinedOnLev(id)) + { + int nbOfCells=_m_by_types->getNumberOfCells(); + _num=DataArrayInt::New(); + _num->alloc(nbOfCells,1); + int *w=_num->getPointer(); + for(int i=0;igetNum()->getConstPointer(),v[i]->getNum()->getConstPointer()+v[i]->getNum()->getNumberOfTuples(),w); + computeRevNum(); + } + for(int i=0;i(ms[i]))->decrRef();//const cast under control to avoid a copy of array +} + +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this) +{ + assignMesh(m,true); +} + +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this) +{ + assignMesh(m,newOrOld); +} + +void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception) +{ + if(newOrOld) + { + m->incrRef(); + _m=m; + _m_by_types=(MEDCouplingUMesh *)m->deepCpy(); + MEDCouplingAutoRefCountObjectPtr da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + if(!da->isIdentity()) + { + _num=da->invertArrayO2N2N2O(m->getNumberOfCells()); + _m.updateTime(); + computeRevNum(); + _m_by_types->renumberCells(da->getConstPointer(),false); + } + } + else + { + if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2)) + 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; + } + _fam=DataArrayInt::New(); + _fam->alloc(m->getNumberOfCells(),1); + _fam->fillWithValue(0); +} + +bool MEDFileUMeshSplitL1::empty() const +{ + return ((const MEDCouplingUMesh *)_m_by_types)==0; +} + +int MEDFileUMeshSplitL1::getMeshDimension() const +{ + return _m_by_types->getMeshDimension(); +} + +int MEDFileUMeshSplitL1::getSize() const throw(INTERP_KERNEL::Exception) +{ + if((const MEDCouplingUMesh *)_m_by_types==0) + throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::getSize : no mesh specified at level !"); + return _m_by_types->getNumberOfCells(); +} + +MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const std::vector& ids, bool renum) const +{ + MEDCouplingAutoRefCountObjectPtr eltsToKeep=_fam->getIdsEqualList(ids); + MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true); + if(renum) + return renumIfNeeded(m,eltsToKeep->getConstPointer()); + return m; +} + +DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const std::vector& ids, bool renum) const +{ + MEDCouplingAutoRefCountObjectPtr da=_fam->getIdsEqualList(ids); + if(renum) + return renumIfNeededArr(da); + da->incrRef(); + return da; +} + +MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const +{ + MEDCouplingAutoRefCountObjectPtr tmp; + if(renum) + tmp=_m; + else + tmp=_m_by_types; + tmp->incrRef(); + return tmp; +} + +const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const +{ + return _fam; +} + +const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const +{ + return _num; +} + +const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const +{ + return _rev_num; +} + +void MEDFileUMeshSplitL1::eraseFamilyField() +{ + _fam->fillWithZero(); +} + +/*! + * This method ignores _m and _m_by_types. + */ +void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector& ms, std::map& familyIds, + std::map >& groups) throw(INTERP_KERNEL::Exception) +{ + int sz=ms.size(); + std::vector< DataArrayInt * > corr; + _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr); + std::vector< std::vector > fidsOfGroups; + std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end()); + _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups); + int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells(); + std::map newfams; + std::map famIdTrad; + traduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams); + for(int i=0;idecrRef(); + int *w=_fam->getPointer(); + for(int i=0;i ms=_m_by_types->splitByType(); + int start=0; + for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++) + { + int nbCells=(*it)->getNumberOfCells(); + int end=start+nbCells; + DataArrayInt *fam=0,*num=0; + if((const DataArrayInt *)_fam) + fam=_fam->substr(start,end); + if((const DataArrayInt *)_num) + num=_num->substr(start,end); + MEDFileUMeshPerType::write(fid,mName,mdim,(*it),fam,num); + if(fam) + fam->decrRef(); + if(num) + num->decrRef(); + (*it)->decrRef(); + start=end; + } +} + +void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr) +{ + famArr->incrRef(); + _fam=famArr; +} + +void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr) +{ + renumArr->incrRef(); + _num=renumArr; + computeRevNum(); +} + +MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds) +{ + if(renum==0) + return m; + if(cellIds==0) + m->renumberCells(renum->getConstPointer(),true); + else + { + MEDCouplingAutoRefCountObjectPtr locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells()); + m->renumberCells(locnum->getConstPointer(),true); + } + return m; +} + +MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const +{ + return Renumber2(_num,m,cellIds); +} + +DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da) +{ + if((const DataArrayInt *)renum==0) + { + da->incrRef(); + return const_cast(da); + } + return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples()); +} + +DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const +{ + return Renumber(_num,da); +} + +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++) + id=std::max(id,(*it).second); + if(id==-1) + id=0; + std::vector ret(nb); + for(int i=1;i<=nb;i++) + ret[i]=id+i; + return ret; +} + +void MEDFileUMeshSplitL1::traduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, + std::map& famIdTrad, std::map& newfams) +{ + std::set allfids; + +} + +void MEDFileUMeshSplitL1::computeRevNum() const +{ + int pos; + int maxValue=_num->getMaxValue(pos); + _rev_num=_num->invertArrayN2O2O2N(maxValue+1); +} diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx new file mode 100644 index 000000000..bf8bf89d9 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -0,0 +1,141 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEMESHLL_HXX__ +#define __MEDFILEMESHLL_HXX__ + +#include "MEDFileBasis.hxx" +#include "MEDFileMeshElt.hxx" + +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +extern "C" +{ +#include "med.h" +} + +#include + +namespace ParaMEDMEM +{ + class MEDCouplingUMesh; + + class MEDFileMeshL2 : public RefCountObject + { + public: + MEDFileMeshL2(); + const char *getName() const { return _name.getReprForWrite(); } + const char *getDescription() const { return _description.getReprForWrite(); } + protected: + MEDFileString _name; + MEDFileString _description; + }; + + 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); + 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]; } + bool isFamDefinedOnLev(int levId) const; + bool isNumDefinedOnLev(int levId) const; + 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); + private: + void sortTypes(); + private: + std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > > _per_type_mesh; + MEDCouplingAutoRefCountObjectPtr _coords; + MEDCouplingAutoRefCountObjectPtr _fam_coords; + MEDCouplingAutoRefCountObjectPtr _num_coords; + }; + + class MEDFileUMeshL2CMesh : public MEDFileMeshL2 + { + }; + + class MEDFileUMeshSplitL1; + + class MEDFileUMeshPermCompute + { + public: + MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st); + operator MEDCouplingUMesh *() const; + void operator=(MEDCouplingUMesh *m); + void updateTime() const; + private: + const MEDFileUMeshSplitL1 *_st; + mutable unsigned int _mpt_time; + mutable unsigned int _num_time; + mutable MEDCouplingAutoRefCountObjectPtr _m; + }; + + class MEDFileUMeshSplitL1 : public RefCountObject + { + friend class MEDFileUMeshPermCompute; + public: + MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id); + MEDFileUMeshSplitL1(MEDCouplingUMesh *m); + MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld); + void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception); + bool empty() const; + int getMeshDimension() const; + int getSize() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getFamilyPart(const std::vector& ids, bool renum) const; + DataArrayInt *getFamilyPartArr(const std::vector& ids, bool renum) const; + MEDCouplingUMesh *getWholeMesh(bool renum) const; + const DataArrayInt *getFamilyField() const; + const DataArrayInt *getNumberField() const; + const DataArrayInt *getRevNumberField() const; + void eraseFamilyField(); + void setGroupsFromScratch(const std::vector& ms, std::map& familyIds, + std::map >& groups) throw(INTERP_KERNEL::Exception); + void write(med_idt fid, const char *mName, int mdim) const; + // + 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, + 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); + private: + MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const; + DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const; + void computeRevNum() const; + private: + MEDCouplingAutoRefCountObjectPtr _m_by_types; + MEDCouplingAutoRefCountObjectPtr _fam; + MEDCouplingAutoRefCountObjectPtr _num; + mutable MEDCouplingAutoRefCountObjectPtr _rev_num; + MEDFileUMeshPermCompute _m; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileUtilities.cxx b/src/MEDLoader/MEDFileUtilities.cxx new file mode 100644 index 000000000..222d8a860 --- /dev/null +++ b/src/MEDLoader/MEDFileUtilities.cxx @@ -0,0 +1,90 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileUtilities.hxx" +#include "MEDLoaderBase.hxx" + +#include + +med_mode_acces MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception) +{ + switch(medloaderwritemode) + { + case 2: + return MED_CREATION; + case 1: + return MED_LECTURE_AJOUT; + case 0: + return MED_LECTURE_ECRITURE; + default: + throw INTERP_KERNEL::Exception("Invalid write mode specified ! must be 0(write with no question), 1(append) or 2(creation)"); + } +} + +void MEDFileUtilities::CheckMEDCode(int code, med_idt fid, const char *msg) throw(INTERP_KERNEL::Exception) +{ + if(code==-1) + { + std::ostringstream oss; + oss << "MEDFile has returned an error code (" << code <<") : " << msg; + MEDfermer(fid); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + +void MEDFileUtilities::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + int status=MEDLoaderBase::getStatusOfFile(fileName); + std::ostringstream oss; + oss << " File : \"" << fileName << "\""; + switch(status) + { + case MEDLoaderBase::DIR_LOCKED: + { + oss << " has been detected as unreadable : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + case MEDLoaderBase::NOT_EXIST: + { + oss << " has been detected as NOT EXISTING : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + case MEDLoaderBase::EXIST_WRONLY: + { + oss << " has been detected as WRITE ONLY : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + int fid=MEDouvrir((char *)fileName,MED_LECTURE); + if(fid<0) + { + oss << " has been detected as unreadable by MED file : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + oss << " has been detected readable but "; + int major,minor,release; + MEDversionLire(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); +} diff --git a/src/MEDLoader/MEDFileUtilities.hxx b/src/MEDLoader/MEDFileUtilities.hxx new file mode 100644 index 000000000..05f3f4e1c --- /dev/null +++ b/src/MEDLoader/MEDFileUtilities.hxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEUTILITIES_HXX__ +#define __MEDFILEUTILITIES_HXX__ + +#include "InterpKernelException.hxx" + +extern "C" +{ +#include "med.h" +} + +namespace MEDFileUtilities +{ + med_mode_acces 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); +} + +#endif diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index cde077cee..abef88c99 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -19,12 +19,15 @@ #include "MEDLoader.hxx" #include "MEDLoaderBase.hxx" +#include "MEDFileUtilities.hxx" #include "CellModel.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingGaussLocalization.hxx" +#include "InterpKernelAutoPtr.hxx" + extern "C" { #include "med.h" @@ -37,42 +40,43 @@ extern "C" #include #include #include +#include med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2] = { MED_POINT1, MED_SEG2, MED_SEG3, MED_TRIA3, - MED_TRIA6, MED_QUAD4, + MED_TRIA6, MED_QUAD8, MED_TETRA4, - MED_TETRA10, - MED_HEXA8, - MED_HEXA20, - MED_PENTA6, - MED_PENTA15, 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_POINT0, +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_TRI6, INTERP_KERNEL::NORM_QUAD4, + INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_QUAD8, INTERP_KERNEL::NORM_TETRA4, - INTERP_KERNEL::NORM_TETRA10, - INTERP_KERNEL::NORM_HEXA8, - INTERP_KERNEL::NORM_HEXA20, - INTERP_KERNEL::NORM_PENTA6, - INTERP_KERNEL::NORM_PENTA15, 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 }; @@ -181,7 +185,7 @@ namespace MEDLoaderNS void prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIds, std::list& split); void fillGaussDataOnField(const char *fileName, const std::list& data, MEDCouplingFieldDouble *f); void writeUMeshesDirectly(const char *fileName, const std::vector& mesh, const std::vector& families, bool forceFromScratch, bool &isRenumbering); - void writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector& meshes, bool forceFromScratch); + void writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector& meshes, bool forceFromScratch); void writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch); void writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f); } @@ -300,43 +304,7 @@ void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception) @@ -434,6 +402,72 @@ std::vector MEDLoader::GetMeshFamiliesNames(const char *fileName, c MEDfermer(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); + std::vector ret; + char nomfam[MED_TAILLE_NOM+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); + 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); + std::vector ret; + char nomfam[MED_TAILLE_NOM+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); + std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); + found=(cur==famName); + if(found) + for(int j=0;j MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { @@ -466,7 +500,7 @@ std::vector MEDLoader::GetMeshGroupsNames(const char *fileName, con MEDfermer(fid); return ret; } -std::vector MEDLoader::GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception) +std::vector MEDLoader::GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); std::vector ret; @@ -812,7 +846,7 @@ double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const ch // bool found=false; bool found2=false; - double ret; + double ret=std::numeric_limits::max(); for(int i=0;i& ids, const std::vector& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception) { + if(meshDimRelToMax>0) + throw INTERP_KERNEL::Exception("meshDimRelToMax must be <=0 !"); //Extraction data from MED file. med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); std::string trueMeshName; @@ -1791,13 +1827,13 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char { std::vector ci(cellIds.size()); std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus(),-1)); - ParaMEDMEM::MEDCouplingUMesh *mesh2; + ParaMEDMEM::MEDCouplingUMesh *mesh2=0; 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) { @@ -2155,7 +2191,7 @@ void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vectorgetCoords(); + const 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;i& meshes, bool forceFromScratch) +void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector& meshes, bool forceFromScratch) { std::string meshNameCpp(meshName); char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); @@ -2186,10 +2222,11 @@ void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char if(meshNameCpp=="") throw INTERP_KERNEL::Exception("writeUMeshesPartitionDirectly : Invalid meshName : Must be different from \"\" !"); std::vector< DataArrayInt * > corr; - MEDCouplingUMesh *m=ParaMEDMEM::MEDCouplingUMesh::fuseUMeshesOnSameCoords(meshes,0,corr); + MEDCouplingUMesh *m=ParaMEDMEM::MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); m->setName(meshName); std::vector< std::vector > fidsOfGroups; - DataArrayInt *arr2=DataArrayInt::makePartition(corr,m->getNumberOfCells(),fidsOfGroups); + std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end()); + DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m->getNumberOfCells(),fidsOfGroups); for(std::vector< DataArrayInt * >::iterator it=corr.begin();it!=corr.end();it++) (*it)->decrRef(); bool isRenumbering; @@ -2511,7 +2548,7 @@ void MEDLoaderNS::writeFieldTryingToFitExistingMesh(const char *fileName, const throw INTERP_KERNEL::Exception(oss.str().c_str()); } MEDCouplingUMesh *m=MEDLoader::ReadUMeshFromFile(fileName,f->getMesh()->getName(),f2); - MEDCouplingUMesh *m2=MEDCouplingUMesh::mergeUMeshes(m,(MEDCouplingUMesh *)f->getMesh()); + MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshes(m,(MEDCouplingUMesh *)f->getMesh()); bool areNodesMerged; int newNbOfNodes; DataArrayInt *da=m2->mergeNodes(MEDLoader::_EPS_FOR_NODE_COMP,areNodesMerged,newNbOfNodes); @@ -2630,7 +2667,7 @@ void MEDLoader::WriteUMeshDep(const char *fileName, const ParaMEDMEM::MEDCouplin MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering); } -void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception) +void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception) { std::string meshName(meshNameC); if(meshName.empty()) @@ -2643,12 +2680,12 @@ void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshName } if(meshes.empty()) throw INTERP_KERNEL::Exception("List of meshes must be not empty !"); - DataArrayDouble *coords=meshes.front()->getCoords(); - for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) + const DataArrayDouble *coords=meshes.front()->getCoords(); + for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) if(coords!=(*iter)->getCoords()) throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !"); std::set tmp; - for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) + for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) { if(tmp.find((*iter)->getName())==tmp.end()) tmp.insert((*iter)->getName()); @@ -2680,7 +2717,7 @@ void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshName } } -void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception) +void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception) { std::string meshName(meshNameC); if(meshName.empty()) @@ -2693,12 +2730,12 @@ void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshN } if(meshes.empty()) throw INTERP_KERNEL::Exception("List of meshes must be not empty !"); - DataArrayDouble *coords=meshes.front()->getCoords(); - for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) + const DataArrayDouble *coords=meshes.front()->getCoords(); + for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) if(coords!=(*iter)->getCoords()) throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !"); std::set tmp; - for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) + for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) { if(tmp.find((*iter)->getName())==tmp.end()) tmp.insert((*iter)->getName()); @@ -2735,7 +2772,7 @@ void MEDLoader::WriteUMeshes(const char *fileName, const std::vectorgetName()); if(meshName.empty()) throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name : change name of first element of 2nd parameter !"); - DataArrayDouble *coords=meshes.front()->getCoords(); + const DataArrayDouble *coords=meshes.front()->getCoords(); for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) if(coords!=(*iter)->getCoords()) throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !"); diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index b90cad0f7..bac6eaced 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -90,9 +90,11 @@ class MEDLOADER_EXPORT MEDLoader static std::vector GetMeshNamesOnField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception); static std::vector GetAllFieldNames(const char *fileName) throw(INTERP_KERNEL::Exception); static std::vector GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); - static std::vector GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); static std::vector GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); @@ -123,8 +125,8 @@ class MEDLOADER_EXPORT MEDLoader static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); static void WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception); static void WriteUMeshDep(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception); - static void WriteUMeshesPartition(const char *fileName, const char *meshName, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception); - static void WriteUMeshesPartitionDep(const char *fileName, const char *meshName, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception); + static void WriteUMeshesPartition(const char *fileName, const char *meshName, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception); + static void WriteUMeshesPartitionDep(const char *fileName, const char *meshName, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception); static void WriteUMeshes(const char *fileName, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception); static void WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception); static void WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Makefile.am b/src/MEDLoader/Makefile.am index 3a2fbb760..500d698e4 100755 --- a/src/MEDLoader/Makefile.am +++ b/src/MEDLoader/Makefile.am @@ -36,10 +36,13 @@ lib_LTLIBRARIES = libmedloader.la salomeinclude_HEADERS= \ MEDLoaderDefines.hxx \ -MEDLoader.hxx MEDLoaderBase.hxx +MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx MEDFileMeshLL.hxx \ +MEDFileMeshElt.hxx MEDFileBasis.hxx MEDFileField.hxx dist_libmedloader_la_SOURCES= \ -MEDLoader.cxx MEDLoaderBase.cxx +MEDLoader.cxx MEDLoaderBase.cxx MEDFileUtilities.cxx \ +MEDFileMesh.cxx MEDFileMeshElt.cxx MEDFileBasis.cxx \ +MEDFileMeshLL.cxx MEDFileField.cxx libmedloader_la_CPPFLAGS= $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../INTERP_KERNEL \