From: ageay Date: Mon, 6 Dec 2010 17:02:46 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: MEDPartitioner_first_compilable_version~53 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3d2bb4309dda3fde43f9967036d3c56d9ab4e8ba;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/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx new file mode 100644 index 000000000..93f97ea48 --- /dev/null +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -0,0 +1,412 @@ +// 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 "MEDLoaderBase.hxx" + +#include "MEDCouplingUMesh.hxx" + +#include "InterpKernelAutoPtr.hxx" + +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() +{ + return new MEDFileUMesh; +} + +MEDFileUMesh::MEDFileUMesh():_too_long_str(0) +{ +} + +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 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; + MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc); + MEDdimEspaceCr(fid,maa,spaceDim); + MEDFileUMeshL2::writeCoords(fid,maa,_coords); + MEDfermer(fid); +} + +int MEDFileUMesh::getNumberOfNonEmptyLevels() const +{ + int ret=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) + if((const MEDFileUMeshSplitL1 *)(*it)!=0) + if(!(*it)->empty()) + ret++; + return ret; +} + +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; +} + +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; +} + +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::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 meshDimRelToMax, const char *grp) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=grp; + MEDCouplingUMesh *ret=getGroups(meshDimRelToMax,tmp); + ret->setName(grp); + return ret; +} + +MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMax, const std::vector& grps) 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(meshDimRelToMax,fams2); +} + +MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMax, const char *fam) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=fam; + MEDCouplingUMesh *ret=getFamilies(meshDimRelToMax,tmp); + ret->setName(fam); + return ret; +} + +MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMax, const std::vector& fams) const throw(INTERP_KERNEL::Exception) +{ + std::vector famIds; + for(std::vector::const_iterator it=fams.begin();it!=fams.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); + } + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax); + return l1->getFamilyPart(famIds); +} + +MEDCouplingUMesh *MEDFileUMesh::getMeshAtRank(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) +{ + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax); + return l1->getWholeMesh(); +} + +MEDCouplingUMesh *MEDFileUMesh::getRank0Mesh() const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(0); +} + +MEDCouplingUMesh *MEDFileUMesh::getRankM1Mesh() const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(-1); +} + +MEDCouplingUMesh *MEDFileUMesh::getRankM2Mesh() const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(-2); +} + +MEDCouplingUMesh *MEDFileUMesh::getRankM3Mesh() const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(-3); +} + +const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) +{ + int tracucedRk=-meshDimRelToMax; + 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::setMeshAtRank(int meshDimRelToMax, MEDCouplingUMesh *m) 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::setMeshAtRank : 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(),sz); + _ms[sz]=new MEDFileUMeshSplitL1(m); + } + } +} + +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 !"); + _ms[-meshDimRelToMax]->setGroupsFromScratch(ms,_families,_groups); +} + +void MEDFileUMesh::setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception) +{ + if(ms.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : expecting a non empty vector !"); + +} + +DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector& ms) const throw(INTERP_KERNEL::Exception) +{ + return 0; +} diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx new file mode 100644 index 000000000..012f65f8b --- /dev/null +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -0,0 +1,99 @@ +// 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(); + ~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 getNumberOfLevels() const { return _ms.size(); } + int getNumberOfNonEmptyLevels() const; + int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getGroupsNames() const; + std::vector getFamiliesNames() const; + std::vector getNonEmptyLevels() const; + DataArrayDouble *getCoords() const; + MEDCouplingUMesh *getGroup(int meshDimRelToMax, const char *grp) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getGroups(int meshDimRelToMax, const std::vector& grps) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getFamily(int meshDimRelToMax, const char *fam) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getFamilies(int meshDimRelToMax, const std::vector& fams) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getMeshAtRank(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRank0Mesh() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRankM1Mesh() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRankM2Mesh() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRankM3Mesh() const throw(INTERP_KERNEL::Exception); + // + void setMeshAtRank(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); + void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); + void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); + private: + MEDFileUMesh(); + MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + const MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMax) const 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); + private: + std::map > _groups; + std::map _families; + std::vector< MEDCouplingAutoRefCountObjectPtr > _ms; + MEDCouplingAutoRefCountObjectPtr _coords; + int _too_long_str; + }; + + + class MEDFileCMesh : public MEDFileMesh + { + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx new file mode 100644 index 000000000..0c2865fae --- /dev/null +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -0,0 +1,181 @@ +// 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 "CellModel.hxx" + +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(); +} + +void MEDFileUMeshPerType::write(med_idt fid) const +{ +} + +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; +} diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx new file mode 100644 index 000000000..cf178c7f6 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -0,0 +1,65 @@ +// 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 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; + void write(med_idt fid) 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; } + 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..fa879cd55 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -0,0 +1,325 @@ +// 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 + +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); + 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;igetPointer(),MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),MED_CART,comp,unit); +} + +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; +} + +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id) +{ + 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); + _m=(MEDCouplingUMesh *)_m_by_types->deepCpy(); + _m->renumberCells(_num->getConstPointer(),true); + } + else + _m=_m_by_types; + for(int i=0;idecrRef(); +} + +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m) +{ + m->incrRef(); + _m=m; + _m_by_types=(MEDCouplingUMesh *)_m->deepCpy(); + MEDCouplingAutoRefCountObjectPtr da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + _num=da->invertArrayO2N2N2O(m->getNumberOfCells()); + _fam=DataArrayInt::New(); + _fam->alloc(m->getNumberOfCells(),1); + _fam->fillWithValue(0); + _m_by_types->renumberCells(da->getConstPointer(),false); +} + +bool MEDFileUMeshSplitL1::empty() const +{ + return ((const MEDCouplingUMesh *)_m_by_types)==0; +} + +int MEDFileUMeshSplitL1::getMeshDimension() const +{ + return _m_by_types->getMeshDimension(); +} + +MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const std::vector& ids) const +{ + MEDCouplingAutoRefCountObjectPtr eltsToKeep=_fam->getIdsEqualList(ids); + MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true); + return renumIfNeeded(m,eltsToKeep->getConstPointer()); +} + +MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh() const +{ + MEDCouplingAutoRefCountObjectPtr tmp=_m; + tmp->incrRef(); + return tmp; +} + +/*! + * 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; + _fam=DataArrayInt::makePartition(corr,_m->getNumberOfCells(),fidsOfGroups); + int nbOfCells=_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;irenumberCells(_num->getConstPointer(),true); + else + { + MEDCouplingAutoRefCountObjectPtr locnum=_num->selectByTupleId(cellIds,cellIds+m->getNumberOfCells()); + m->renumberCells(locnum->getConstPointer(),true); + } + return m; +} + +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; + +} diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx new file mode 100644 index 000000000..faa7c9de3 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -0,0 +1,101 @@ +// 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; } + 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 writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords); + private: + void sortTypes(); + private: + std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > > _per_type_mesh; + MEDCouplingAutoRefCountObjectPtr _coords; + }; + + class MEDFileUMeshL2CMesh : public MEDFileMeshL2 + { + }; + + class MEDFileUMeshSplitL1 : public RefCountObject + { + public: + MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id); + MEDFileUMeshSplitL1(MEDCouplingUMesh *m); + bool empty() const; + int getMeshDimension() const; + MEDCouplingUMesh *getFamilyPart(const std::vector& ids) const; + MEDCouplingUMesh *getWholeMesh() const; + void setGroupsFromScratch(const std::vector& ms, std::map& familyIds, + std::map >& groups) throw(INTERP_KERNEL::Exception); + 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); + private: + MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const; + private: + MEDCouplingAutoRefCountObjectPtr _m_by_types; + MEDCouplingAutoRefCountObjectPtr _fam; + MEDCouplingAutoRefCountObjectPtr _num; + MEDCouplingAutoRefCountObjectPtr _m; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileUtilities.cxx b/src/MEDLoader/MEDFileUtilities.cxx new file mode 100644 index 000000000..9f98e4e45 --- /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!=0) + { + 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..000602cf6 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -19,6 +19,7 @@ #include "MEDLoader.hxx" #include "MEDLoaderBase.hxx" +#include "MEDFileUtilities.hxx" #include "CellModel.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" @@ -37,6 +38,7 @@ extern "C" #include #include #include +#include med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2] = { MED_POINT1, MED_SEG2, @@ -300,43 +302,7 @@ void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception) @@ -812,7 +778,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 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) diff --git a/src/MEDLoader/Makefile.am b/src/MEDLoader/Makefile.am index 3a2fbb760..075f19d77 100755 --- a/src/MEDLoader/Makefile.am +++ b/src/MEDLoader/Makefile.am @@ -36,10 +36,12 @@ lib_LTLIBRARIES = libmedloader.la salomeinclude_HEADERS= \ MEDLoaderDefines.hxx \ -MEDLoader.hxx MEDLoaderBase.hxx +MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx MEDFileMeshLL.hxx dist_libmedloader_la_SOURCES= \ -MEDLoader.cxx MEDLoaderBase.cxx +MEDLoader.cxx MEDLoaderBase.cxx MEDFileUtilities.cxx \ +MEDFileMesh.cxx MEDFileMeshElt.cxx MEDFileBasis.cxx \ +MEDFileMeshLL.cxx libmedloader_la_CPPFLAGS= $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../INTERP_KERNEL \