--- /dev/null
+// 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 <cstring>
+
+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);
+}
+
--- /dev/null
+// 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 <string>
+#include <vector>
+
+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<std::string> getRepr() const;
+ std::string getReprPerComp(int compId) const;
+ private:
+ int _nb_of_comp;
+ int _max_lgth_per_comp;
+ char *_content;
+ };
+}
+
+#endif
--- /dev/null
+// 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<lev;i++)
+ {
+ if(!loaderl2.emptyLev(i))
+ _ms[i]=new MEDFileUMeshSplitL1(loaderl2,mName,i);
+ else
+ _ms[i]=0;
+ }
+ MEDFileUMeshL2::readFamiliesAndGrps(fid,mName,_families,_groups);
+ MEDfermer(fid);
+ //
+ setName(loaderl2.getName());
+ setDescription(loaderl2.getDescription());
+ _coords=loaderl2.getCoords();
+ }
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+MEDFileUMesh::~MEDFileUMesh()
+{
+}
+
+void MEDFileUMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
+{
+ if(_name.empty())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh : name is empty. MED file ask for a NON EMPTY name !");
+ 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<char> maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> 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<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
+ if((const MEDFileUMeshSplitL1 *)(*it)!=0)
+ if(!(*it)->empty())
+ ret++;
+ return ret;
+}
+
+std::vector<int> MEDFileUMesh::getNonEmptyLevels() const
+{
+ std::vector<int> ret;
+ int lev=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::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<std::string, int>::const_iterator it=_families.find(oname);
+ std::vector<std::string> 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<std::string>(oss," "));
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return (*it).second;
+}
+
+std::vector<std::string> MEDFileUMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
+{
+ std::string oname(name);
+ std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
+ std::vector<std::string> 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<std::string>(oss," "));
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return (*it).second;
+}
+
+std::vector<std::string> MEDFileUMesh::getGroupsNames() const
+{
+ std::vector<std::string> ret(_groups.size());
+ int i=0;
+ for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++,i++)
+ ret[i]=(*it).first;
+ return ret;
+}
+
+std::vector<std::string> MEDFileUMesh::getFamiliesNames() const
+{
+ std::vector<std::string> ret(_families.size());
+ int i=0;
+ for(std::map<std::string, int >::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<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
+ std::vector<std::string> 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<std::string>(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<std::string, int >::iterator it=_families.find(oname);
+ std::vector<std::string> 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<std::string>(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<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
+ std::vector<std::string> 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<std::string>(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<std::string> 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<std::string, int >::iterator it=_families.find(oname);
+ std::vector<std::string> 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<std::string>(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<DataArrayDouble> 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<std::string> tmp(1);
+ tmp[0]=grp;
+ MEDCouplingUMesh *ret=getGroups(meshDimRelToMax,tmp);
+ ret->setName(grp);
+ return ret;
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMax, const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
+{
+ std::set<std::string> fams;
+ for(std::vector<std::string>::const_iterator it=grps.begin();it!=grps.end();it++)
+ {
+ std::map<std::string, std::vector<std::string> >::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<std::string> fams2(fams.begin(),fams.end());
+ return getFamilies(meshDimRelToMax,fams2);
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMax, const char *fam) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=fam;
+ MEDCouplingUMesh *ret=getFamilies(meshDimRelToMax,tmp);
+ ret->setName(fam);
+ return ret;
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMax, const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> famIds;
+ for(std::vector<std::string>::const_iterator it=fams.begin();it!=fams.end();it++)
+ {
+ std::map<std::string,int>::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<MEDFileUMeshSplitL1> >::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<int> 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<MEDCouplingUMesh *>& 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<MEDCouplingUMesh *>& 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<MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception)
+{
+ return 0;
+}
--- /dev/null
+// 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 <map>
+
+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<std::string> getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
+ std::vector<std::string> getGroupsNames() const;
+ std::vector<std::string> getFamiliesNames() const;
+ std::vector<int> getNonEmptyLevels() const;
+ DataArrayDouble *getCoords() const;
+ MEDCouplingUMesh *getGroup(int meshDimRelToMax, const char *grp) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getGroups(int meshDimRelToMax, const std::vector<std::string>& 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<std::string>& 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<MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception);
+ void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<MEDCouplingUMesh *>& 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<MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception);
+ private:
+ std::map<std::string, std::vector<std::string> > _groups;
+ std::map<std::string,int> _families;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> > _ms;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
+ int _too_long_str;
+ };
+
+
+ class MEDFileCMesh : public MEDFileMesh
+ {
+ };
+}
+
+#endif
--- /dev/null
+// 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<curNbOfElem;i++,wi+=nbOfNodesPerCell,w2++)
+ {
+ *w1++=(int)type;
+ w1=std::transform(wi,wi+nbOfNodesPerCell,w1,std::bind2nd(std::plus<int>(),-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<curNbOfElem;i++,w2++)
+ {
+ *w1++=(int)INTERP_KERNEL::NORM_POLYGON;
+ w1=std::transform(wi,wi+(w2[1]-w2[0]),w1,std::bind2nd(std::plus<int>(),-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;i<curNbOfElem;i++)
+ arraySize+=index[i+1]-index[i]-1;
+ _conn=DataArrayInt::New();
+ _conn->alloc(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<curNbOfElem;i++)
+ {
+ *wFinalConn++=(int)INTERP_KERNEL::NORM_POLYHED;
+ finalIndex[i+1]=finalIndex[i]+index[i+1]-index[i]-1+indexFace[index[i+1]-1]-indexFace[index[i]-1]+1;
+ wFinalConn=std::transform(locConn+indexFace[index[i]-1]-1,locConn+indexFace[index[i]]-1,wFinalConn,std::bind2nd(std::plus<int>(),-1));
+ for(int j=index[i];j<index[i+1]-1;j++)
+ {
+ *wFinalConn++=-1;
+ wFinalConn=std::transform(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn,std::bind2nd(std::plus<int>(),-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;
+}
--- /dev/null
+// 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<DataArrayInt> _conn;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _conn_index;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
+ INTERP_KERNEL::NormalizedCellType _type;
+ med_entite_maillage _entity;
+ };
+}
+
+#endif
--- /dev/null
+// 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 <set>
+
+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;j<MED_NBR_GEOMETRIE_MAILLE+2;j++)
+ {
+ MEDFileUMeshPerType *tmp=MEDFileUMeshPerType::New(fid,mName,mdim,typmai[j],typmai2[j]);
+ if(tmp)
+ _per_type_mesh[0].push_back(tmp);
+ }
+ sortTypes();
+}
+
+void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, int mdim, const char *mName) throw(INTERP_KERNEL::Exception)
+{
+ med_int edim=MEDdimEspaceLire(fid,(char *)mName);
+ int spaceDim=std::max((int)mdim,(int)edim);
+ int nCoords=MEDnEntMaa(fid,(char *)mName,MED_COOR,MED_NOEUD,(med_geometrie_element)0,(med_connectivite)0);
+ _coords=DataArrayDouble::New();
+ _coords->alloc(nCoords,spaceDim);
+ double *coordsPtr=_coords->getPointer();
+ med_repere repere;
+ char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
+ char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
+ MEDcoordLire(fid,(char *)mName,spaceDim,coordsPtr,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit);
+ for(int i=0;i<spaceDim;i++)
+ {
+ std::string n,u;
+ std::string info=MEDLoaderBase::buildUnionUnit(comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
+ _coords->setInfoOnComponent(i,info.c_str());
+ }
+ delete [] comp;
+ delete [] unit;
+}
+
+void MEDFileUMeshL2::sortTypes()
+{
+ std::set<int> mdims;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
+ _per_type_mesh.clear();
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::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<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::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<std::string> ms;
+ for(int i=0;i<n;i++)
+ {
+ MEDmaaInfo(fid,i+1,nommaa,&dim,&type_maillage,maillage_description);
+ std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
+ ms.push_back(cur);
+ if(cur==mname)
+ {
+ found=true;
+ ret=i+1;
+ }
+ }
+ if(!found)
+ {
+ std::ostringstream oss;
+ oss << "No such meshname in file ! Must be in :";
+ std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return ret;
+}
+
+void MEDFileUMeshL2::readFamiliesAndGrps(med_idt fid, const char *meshName, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps)
+{
+ char nomfam[MED_TAILLE_NOM+1];
+ med_int numfam;
+ int nfam=MEDnFam(fid,(char *)meshName);
+ for(int i=0;i<nfam;i++)
+ {
+ int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
+ med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
+ med_int *attide=new int[natt];
+ med_int *attval=new int[natt];
+ char *attdes=new char[MED_TAILLE_DESC*natt+1];
+ char *gro=new char[MED_TAILLE_LNOM*ngro+1];
+ MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro);
+ std::string famName=MEDLoaderBase::buildStringFromFortran(nomfam,MED_TAILLE_LNOM);
+ fams[famName]=numfam;
+ for(int j=0;j<ngro;j++)
+ {
+ std::string groupname=MEDLoaderBase::buildStringFromFortran(gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
+ grps[groupname].push_back(famName);
+ }
+ delete [] attdes;
+ delete [] gro;
+ delete [] attide;
+ delete [] attval;
+ }
+}
+
+void MEDFileUMeshL2::writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords)
+{
+ if(!coords)
+ return ;
+ MEDcoordEcr(fid,maa,spaceDim,arr->getPointer(),MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),MED_CART,comp,unit);
+}
+
+bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::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<MEDFileUMeshPerType> >::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<MEDFileUMeshPerType> >& v=l2.getLev(id);
+ if(v.empty())
+ return;
+ int sz=v.size();
+ std::vector<MEDCouplingUMesh *> ms(sz);
+ for(int i=0;i<sz;i++)
+ {
+ MEDCouplingUMesh *tmp=MEDCouplingUMesh::New("",v[i]->getDim());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp2=l2.getCoords();
+ tmp->setCoords(tmp2);
+ tmp->setConnectivity(const_cast<DataArrayInt *>(v[i]->getNodal()),const_cast<DataArrayInt *>(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;i<sz;i++)
+ w=std::copy(v[i]->getFam()->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;i<sz;i++)
+ w=std::copy(v[i]->getNum()->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;i<sz;i++)
+ ms[i]->decrRef();
+}
+
+MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m)
+{
+ m->incrRef();
+ _m=m;
+ _m_by_types=(MEDCouplingUMesh *)_m->deepCpy();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> 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<int>& ids) const
+{
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> 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<MEDCouplingUMesh> tmp=_m;
+ tmp->incrRef();
+ return tmp;
+}
+
+/*!
+ * This method ignores _m and _m_by_types.
+ */
+void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
+ std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception)
+{
+ int sz=ms.size();
+ std::vector< DataArrayInt * > corr;
+ _m=MEDCouplingUMesh::fuseUMeshesOnSameCoords(ms,0,corr);
+ std::vector< std::vector<int> > fidsOfGroups;
+ _fam=DataArrayInt::makePartition(corr,_m->getNumberOfCells(),fidsOfGroups);
+ int nbOfCells=_m->getNumberOfCells();
+ std::map<int,std::string> newfams;
+ std::map<int,int> famIdTrad;
+ traduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
+ for(int i=0;i<sz;i++)
+ corr[i]->decrRef();
+ int *w=_fam->getPointer();
+ for(int i=0;i<nbOfCells;i++,w++)
+ *w=famIdTrad[*w];
+}
+
+MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
+{
+ if((const DataArrayInt *)_num==0)
+ return m;
+ if(cellIds==0)
+ m->renumberCells(_num->getConstPointer(),true);
+ else
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=_num->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
+ m->renumberCells(locnum->getConstPointer(),true);
+ }
+ return m;
+}
+
+std::vector<int> MEDFileUMeshSplitL1::getNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
+{
+ int id=-1;
+ for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++)
+ id=std::max(id,(*it).second);
+ if(id==-1)
+ id=0;
+ std::vector<int> ret(nb);
+ for(int i=1;i<=nb;i++)
+ ret[i]=id+i;
+ return ret;
+}
+
+void MEDFileUMeshSplitL1::traduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
+ std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams)
+{
+ std::set<int> allfids;
+
+}
--- /dev/null
+// 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 <map>
+
+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<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
+ bool isFamDefinedOnLev(int levId) const;
+ bool isNumDefinedOnLev(int levId) const;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> 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<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps);
+ static void writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords);
+ private:
+ void sortTypes();
+ private:
+ std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _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<int>& ids) const;
+ MEDCouplingUMesh *getWholeMesh() const;
+ void setGroupsFromScratch(const std::vector<MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
+ std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
+ static std::vector<int> getNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
+ static void traduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
+ std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
+ private:
+ MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
+ private:
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m_by_types;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
+ };
+}
+
+#endif
--- /dev/null
+// 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 <sstream>
+
+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);
+}
--- /dev/null
+// 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
#include "MEDLoader.hxx"
#include "MEDLoaderBase.hxx"
+#include "MEDFileUtilities.hxx"
#include "CellModel.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingMemArray.hxx"
#include <iterator>
#include <algorithm>
#include <numeric>
+#include <limits>
med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2] = { MED_POINT1,
MED_SEG2,
void MEDLoader::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);
+ MEDFileUtilities::CheckFileForRead(fileName);
}
std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception)
//
bool found=false;
bool found2=false;
- double ret;
+ double ret=std::numeric_limits<double>::max();
for(int i=0;i<nbFields && !found;i++)
{
med_int ncomp=MEDnChamp(fid,i+1);
{
std::vector<int> ci(cellIds.size());
std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus<int>(),-1));
- ParaMEDMEM::MEDCouplingUMesh *mesh2;
+ ParaMEDMEM::MEDCouplingUMesh *mesh2=0;
if(typeOfOutField==ON_CELLS)
{
if(newMesh)
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 \