--- /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 "MEDFileField.hxx"
+#include "MEDLoaderBase.hxx"
+#include "MEDFileUtilities.hxx"
+
+#include "InterpKernelAutoPtr.hxx"
+
+#include <algorithm>
+
+extern med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2];
+extern INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2];
+extern med_geometrie_element typmainoeud[1];
+extern med_geometrie_element typmai3[32];
+
+using namespace ParaMEDMEM;
+
+MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileFieldPerMeshPerTypePerDisc(fath,fid);
+}
+
+MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception)
+try:_father(fath)
+{
+ INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ std::string fieldName=getName();
+ std::string meshName=getMeshName();
+ int iteration=getIteration();
+ int order=getOrder();
+ const std::vector<std::string>& infos=getInfos();
+ TypeOfField type=getType();
+ INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
+ int nval=MEDnVal(fid,(char *)fieldName.c_str(),type==ON_CELLS?MED_MAILLE:MED_NOEUD,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,
+ iteration,order,(char *)meshName.c_str(),MED_COMPACT);
+ _arr=DataArrayDouble::New();
+ _arr->alloc(nval,infos.size());
+ MEDchampLire(fid,(char *)getMeshName().c_str(),(char *)fieldName.c_str(),(unsigned char*)_arr->getPointer(),MED_FULL_INTERLACE,MED_ALL,locname,
+ pflname,MED_COMPACT,type==ON_CELLS?MED_MAILLE:MED_NOEUD,
+ type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,
+ iteration,order);
+ _profile=pflname;
+ _localization=locname;
+}
+catch(INTERP_KERNEL::Exception& e)
+{
+ throw e;
+}
+
+const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
+{
+ return _father;
+}
+
+int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
+{
+ return _father->getIteration();
+}
+
+int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
+{
+ return _father->getOrder();
+}
+
+std::string MEDFileFieldPerMeshPerTypePerDisc::getName() const
+{
+ return _father->getName();
+}
+
+TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
+{
+ return _father->getType();
+}
+
+INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
+{
+ return _father->getGeoType();
+}
+
+std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
+{
+ return _father->getMeshName();
+}
+
+int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
+{
+ return _father->getNumberOfComponents();
+}
+
+const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfos() const
+{
+ return _father->getInfos();
+}
+
+std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
+{
+ return _profile;
+}
+
+std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
+{
+ return _localization;
+}
+
+MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileFieldPerMeshPerType(fath,type,geoType);
+}
+
+const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
+{
+ return _father;
+}
+
+int MEDFileFieldPerMeshPerType::getIteration() const
+{
+ return _father->getIteration();
+}
+
+int MEDFileFieldPerMeshPerType::getOrder() const
+{
+ return _father->getOrder();
+}
+
+std::string MEDFileFieldPerMeshPerType::getName() const
+{
+ return _father->getName();
+}
+
+std::string MEDFileFieldPerMeshPerType::getMeshName() const
+{
+ return _father->getMeshName();
+}
+
+TypeOfField MEDFileFieldPerMeshPerType::getType() const
+{
+ return _type;
+}
+
+INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
+{
+ return _geo_type;
+}
+
+
+int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
+{
+ return _father->getNumberOfComponents();
+}
+
+const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfos() const
+{
+ return _father->getInfos();
+}
+
+std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
+{
+ std::vector<std::string> ret;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
+ {
+ std::string tmp=(*it1)->getProfile();
+ if(!tmp.empty())
+ ret.push_back(tmp);
+ }
+ return ret;
+}
+
+std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
+{
+ std::vector<std::string> ret;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
+ {
+ std::string tmp=(*it1)->getLocalization();
+ if(!tmp.empty())
+ ret.push_back(tmp);
+ }
+ return ret;
+}
+
+MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_type(type),_geo_type(geoType)
+{
+}
+
+void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
+{
+ //for MED3 porting this limitation will be killed !
+ _field_pm_pt_pd.resize(1);
+ _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,fid);
+}
+
+MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time)
+{
+ return new MEDFileFieldPerMesh(fath,meshName,time);
+}
+
+void MEDFileFieldPerMesh::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType)
+{
+ _types.push_back(type);
+ _geo_types.push_back(geoType);
+}
+
+void MEDFileFieldPerMesh::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
+{
+ int sz=_types.size();
+ _field_pm_pt.resize(sz);
+ for(int i=0;i<sz;i++)
+ {
+ _field_pm_pt[i]=MEDFileFieldPerMeshPerType::New(this,_types[i],_geo_types[i]);
+ _field_pm_pt[i]->finishLoading(fid);
+ }
+}
+
+double MEDFileFieldPerMesh::getTime() const
+{
+ return _time;
+}
+
+int MEDFileFieldPerMesh::getIteration() const
+{
+ return _father->getIteration();
+}
+
+int MEDFileFieldPerMesh::getOrder() const
+{
+ return _father->getOrder();
+}
+
+std::string MEDFileFieldPerMesh::getName() const
+{
+ return _father->getName();
+}
+
+std::string MEDFileFieldPerMesh::getMeshName() const
+{
+ return _mesh_name;
+}
+
+int MEDFileFieldPerMesh::getNumberOfComponents() const
+{
+ return _father->getNumberOfComponents();
+}
+
+const std::vector<std::string>& MEDFileFieldPerMesh::getInfos() const
+{
+ return _father->getInfos();
+}
+
+std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
+{
+ std::vector<std::string> ret;
+ std::set<std::string> ret2;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
+ {
+ std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
+ for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
+ if(ret2.find(*it2)==ret2.end())
+ {
+ ret.push_back(*it2);
+ ret2.insert(*it2);
+ }
+ }
+ return ret;
+}
+
+std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
+{
+ std::vector<std::string> ret;
+ std::set<std::string> ret2;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
+ {
+ std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
+ for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
+ if(ret2.find(*it2)==ret2.end())
+ {
+ ret.push_back(*it2);
+ ret2.insert(*it2);
+ }
+ }
+ return ret;
+}
+
+MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time):_father(fath),_mesh_name(meshName),_time(time)
+{
+}
+
+void MEDFieldFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName, int lgth) throw(INTERP_KERNEL::Exception)
+{
+ _pfls[id]=DataArrayInt::New();
+ _pfls[id]->alloc(lgth,1);
+ MEDprofilLire(fid,_pfls[id]->getPointer(),(char *)pflName);
+}
+
+void MEDFieldFieldGlobs::loadProfileInFile(med_idt fid, int i)
+{
+ INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ int sz;
+ MEDprofilInfo(fid,i,pflName,&sz);
+ _pfls[i]=DataArrayInt::New();
+ _pfls[i]->alloc(sz,1);
+ MEDprofilLire(fid,_pfls[i]->getPointer(),(char *)pflName);
+}
+
+std::vector<std::string> MEDFieldFieldGlobs::getPfls() const
+{
+ int sz=_pfls.size();
+ std::vector<std::string> ret(sz);
+ for(int i=0;i<sz;i++)
+ ret[i]=_pfls[i]->getName();
+ return ret;
+}
+
+std::vector<std::string> MEDFieldFieldGlobs::getLocs() const
+{
+ int sz=_locs.size();
+ std::vector<std::string> ret(sz);
+ for(int i=0;i<sz;i++)
+ ret[i]=_locs[i]->getName();
+ return ret;
+}
+
+MEDFileField1TSWithoutDAS *MEDFileField1TSWithoutDAS::New(const char *fieldName, int iteration, int order, const std::vector<std::string>& infos)
+{
+ return new MEDFileField1TSWithoutDAS(fieldName,iteration,order,infos);
+}
+
+void MEDFileField1TSWithoutDAS::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time, const char *meshName) const
+{
+ _types.push_back(type);
+ _geo_types.push_back(geoType);
+ _times.push_back(time);
+ _meshes.push_back(meshName);
+}
+
+void MEDFileField1TSWithoutDAS::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> meshesOnlyOnce;
+ int nbOfTurn=_meshes.size();
+ for(int i=0;i<nbOfTurn;i++)
+ {
+ std::vector<std::string>::iterator it=std::find(meshesOnlyOnce.begin(),meshesOnlyOnce.end(),_meshes[i]);
+ if(it==meshesOnlyOnce.end())
+ {
+ _field_per_mesh.push_back(MEDFileFieldPerMesh::New(this,_meshes[i].c_str(),_times[i]));
+ meshesOnlyOnce.push_back(_meshes[i]);
+ _field_per_mesh.back()->pushBack(_types[i],_geo_types[i]);
+ }
+ else
+ {
+ int w=std::distance(meshesOnlyOnce.begin(),it);
+ _field_per_mesh[w]->pushBack(_types[i],_geo_types[i]);
+ }
+ }
+ int nbOfMeshes=_field_per_mesh.size();
+ for(int i=0;i<nbOfMeshes;i++)
+ _field_per_mesh[i]->finishLoading(fid);
+}
+
+std::vector<std::string> MEDFileField1TSWithoutDAS::getPflsReallyUsed() const
+{
+ std::vector<std::string> ret;
+ std::set<std::string> ret2;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
+ {
+ std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
+ for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
+ if(ret2.find(*it2)==ret2.end())
+ {
+ ret.push_back(*it2);
+ ret2.insert(*it2);
+ }
+ }
+ return ret;
+}
+
+std::vector<std::string> MEDFileField1TSWithoutDAS::getLocsReallyUsed() const
+{
+ std::vector<std::string> ret;
+ std::set<std::string> ret2;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
+ {
+ std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
+ for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
+ if(ret2.find(*it2)==ret2.end())
+ {
+ ret.push_back(*it2);
+ ret2.insert(*it2);
+ }
+ }
+ return ret;
+}
+
+MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, int iteration, int order, const std::vector<std::string>& infos):_name(fieldName),_infos(infos),_iteration(iteration),_order(order)
+{
+}
+
+MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileField1TS(fileName,fieldName,iteration,order);
+}
+
+MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
+try:MEDFileField1TSWithoutDAS(fieldName,iteration,order,std::vector<std::string>())
+{
+ MEDFileUtilities::CheckFileForRead(fileName);
+ med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ int nbFields=MEDnChamp(fid,0);
+ med_type_champ typcha;
+ bool found=false;
+ std::vector<std::string> fns(nbFields);
+ for(int i=0;i<nbFields && !found;i++)
+ {
+ int ncomp=MEDnChamp(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_TAILLE_PNOM+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_TAILLE_PNOM+1];
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ std::string tmp(nomcha);
+ fns[i]=tmp;
+ found=(tmp==fieldName);
+ if(found)
+ {
+ _infos.resize(ncomp);
+ for(int j=0;j<ncomp;j++)
+ _infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,(char *)unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
+ }
+ }
+ if(!found)
+ {
+ std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
+ std::copy(fns.begin(),fns.end(),std::ostream_iterator<std::string>(oss," "));
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ finishLoading(fid);
+ //
+ std::vector<std::string> profiles=getPflsReallyUsed();
+ int sz=profiles.size();
+ _pfls.resize(sz);
+ for(int i=0;i<sz;i++)
+ loadProfileInFile(fid,i,profiles[i].c_str(),37);//tony
+ MEDfermer(fid);
+}
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos);
+}
+
+MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(const char *fieldName):_name(fieldName)
+{
+}
+
+MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
+try:_name(fieldName),_infos(infos)
+{
+ finishLoading(fid);
+}
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+void MEDFileFieldMultiTSWithoutDAS::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
+{
+ for(int i=0;i<MED_NBR_GEOMETRIE_MAILLE+2;i++)
+ {
+ int nbPdt=MEDnPasdetemps(fid,(char *)_name.c_str(),MED_MAILLE,typmai[i]);
+ for(int j=0;j<nbPdt;j++)
+ appendTimeStepEntry(fid,MED_MAILLE,i,j);
+ }
+ int nbPdt=MEDnPasdetemps(fid,(char *)_name.c_str(),MED_NOEUD,MED_NONE);
+ for(int j=0;j<nbPdt;j++)
+ appendTimeStepEntry(fid,MED_NOEUD,0,j);
+ int nbOfTimeSteps=_time_steps.size();
+ for(int i=0;i<nbOfTimeSteps;i++)
+ _time_steps[i]->finishLoading(fid);
+}
+
+void MEDFileFieldMultiTSWithoutDAS::appendTimeStepEntry(med_idt fid, med_entite_maillage entity, int i, int j) throw(INTERP_KERNEL::Exception)
+{
+ std::vector< std::pair<int,int> > ts;
+ med_int ngauss=0;
+ med_int numdt=0,numo=0,nbrefmaa;
+ med_float dt=0.0;
+ med_booleen local;
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
+ MEDpasdetempsInfo(fid,(char *)_name.c_str(),MED_MAILLE,typmai[i],j+1,&ngauss,&numdt,&numo,dt_unit,&dt,maa_ass,&local,&nbrefmaa);
+ std::pair<int,int> p(numdt,numo);
+ std::vector< std::pair<int,int> >::iterator where=std::find(ts.begin(),ts.end(),p);
+ if(where==ts.end())
+ {
+ ts.push_back(p);
+ _time_steps.push_back(MEDFileField1TSWithoutDAS::New(_name.c_str(),numdt,numo,_infos));
+ _time_steps.back()->pushBack(entity==MED_MAILLE?ON_CELLS:ON_NODES,entity==MED_MAILLE?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt,maa_ass);
+ }
+ else
+ {
+ int w=std::distance(ts.begin(),where);
+ _time_steps[w]->pushBack(entity==MED_MAILLE?ON_CELLS:ON_NODES,entity==MED_MAILLE?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt,maa_ass);
+ }
+}
+
+std::vector<std::string> MEDFileFieldMultiTSWithoutDAS::getPflsReallyUsed() const
+{
+ std::vector<std::string> ret;
+ std::set<std::string> ret2;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutDAS > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
+ for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
+ if(ret2.find(*it2)==ret2.end())
+ {
+ ret.push_back(*it2);
+ ret2.insert(*it2);
+ }
+ }
+ return ret;
+}
+
+std::vector<std::string> MEDFileFieldMultiTSWithoutDAS::getLocsReallyUsed() const
+{
+ std::vector<std::string> ret;
+ std::set<std::string> ret2;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutDAS > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
+ for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
+ if(ret2.find(*it2)==ret2.end())
+ {
+ ret.push_back(*it2);
+ ret2.insert(*it2);
+ }
+ }
+ return ret;
+}
+
+MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileFieldMultiTS(fileName,fieldName);
+}
+
+MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
+try:MEDFileFieldMultiTSWithoutDAS(fieldName)
+{
+ MEDFileUtilities::CheckFileForRead(fileName);
+ med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ int nbFields=MEDnChamp(fid,0);
+ med_type_champ typcha;
+ bool found=false;
+ std::vector<std::string> fns(nbFields);
+ for(int i=0;i<nbFields && !found;i++)
+ {
+ int ncomp=MEDnChamp(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_TAILLE_PNOM+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_TAILLE_PNOM+1];
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ std::string tmp(nomcha);
+ fns[i]=tmp;
+ found=(tmp==fieldName);
+ if(found)
+ {
+ _infos.resize(ncomp);
+ for(int j=0;j<ncomp;j++)
+ _infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,(char *)unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
+ }
+ }
+ if(!found)
+ {
+ std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
+ std::copy(fns.begin(),fns.end(),std::ostream_iterator<std::string>(oss," "));
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ finishLoading(fid);
+ MEDfermer(fid);
+}
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileFields(fileName);
+}
+
+int MEDFileFields::getNumberOfFields() const
+{
+ return _fields.size();
+}
+
+MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception)
+try
+ {
+ MEDFileUtilities::CheckFileForRead(fileName);
+ med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ int nbFields=MEDnChamp(fid,0);
+ _fields.resize(nbFields);
+ med_type_champ typcha;
+ for(int i=0;i<nbFields;i++)
+ {
+ int ncomp=MEDnChamp(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_TAILLE_PNOM+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_TAILLE_PNOM+1];
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ std::vector<std::string> infos(ncomp);
+ for(int j=0;j<ncomp;j++)
+ infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,(char *)unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
+ _fields[i]=MEDFileFieldMultiTSWithoutDAS::New(fid,nomcha,i,infos);
+ }
+ int nProfil=MEDnProfil(fid);
+ _pfls.resize(nProfil);
+ for(int i=0;i<nProfil;i++)
+ loadProfileInFile(fid,i);
+ MEDfermer(fid);
+ }
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
--- /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 __MEDFILEFIELD_HXX__
+#define __MEDFILEFIELD_HXX__
+
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+#include "MEDCouplingRefCountObject.hxx"
+#include "MEDCouplingMemArray.hxx"
+
+#include "NormalizedUnstructuredMesh.hxx"
+#include "InterpKernelException.hxx"
+
+#include <vector>
+#include <string>
+
+extern "C"
+{
+#include "med.h"
+}
+
+namespace ParaMEDMEM
+{
+ class MEDFileFieldLoc : public RefCountObject
+ {
+ public:
+ const std::string& getName() const { return _name; }
+ private:
+ int _dim;
+ int _nb_gauss_pt;
+ int _nb_node_per_cell;
+ std::string _name;
+ INTERP_KERNEL::NormalizedCellType _geo_type;
+ std::vector<double> _ref_coo;
+ std::vector<double> _gs_coo;
+ std::vector<double> _w;
+ };
+
+ class MEDFileFieldPerMeshPerType;
+ class MEDFileField1TSWithoutDAS;
+ class MEDFileFieldPerMesh;
+
+ class MEDFileFieldPerMeshPerTypePerDisc : public RefCountObject
+ {
+ public:
+ static MEDFileFieldPerMeshPerTypePerDisc *New(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception);
+ const MEDFileFieldPerMeshPerType *getFather() const;
+ int getIteration() const;
+ int getOrder() const;
+ std::string getName() const;
+ std::string getMeshName() const;
+ TypeOfField getType() const;
+ INTERP_KERNEL::NormalizedCellType getGeoType() const;
+ int getNumberOfComponents() const;
+ const std::vector<std::string>& getInfos() const;
+ std::string getProfile() const;
+ std::string getLocalization() const;
+ private:
+ MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception);
+ private:
+ MEDFileFieldPerMeshPerType *_father;
+ MEDCouplingAutoRefCountObjectPtr< DataArrayDouble > _arr;
+ std::string _profile;
+ std::string _localization;
+ std::string _mesh_name;
+ };
+
+ class MEDFileFieldPerMeshPerType : public RefCountObject
+ {
+ public:
+ static MEDFileFieldPerMeshPerType *New(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception);
+ const MEDFileFieldPerMesh *getFather() const;
+ void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception);
+ int getIteration() const;
+ int getOrder() const;
+ std::string getName() const;
+ std::string getMeshName() const;
+ TypeOfField getType() const;
+ INTERP_KERNEL::NormalizedCellType getGeoType() const;
+ int getNumberOfComponents() const;
+ const std::vector<std::string>& getInfos() const;
+ std::vector<std::string> getPflsReallyUsed() const;
+ std::vector<std::string> getLocsReallyUsed() const;
+ private:
+ MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception);
+ private:
+ MEDFileFieldPerMesh *_father;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > _field_pm_pt_pd;
+ TypeOfField _type;
+ INTERP_KERNEL::NormalizedCellType _geo_type;
+ };
+
+ class MEDFileFieldPerMesh : public RefCountObject
+ {
+ public:
+ static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time);
+ void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType);
+ void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception);
+ double getTime() const;
+ int getIteration() const;
+ int getOrder() const;
+ std::string getName() const;
+ std::string getMeshName() const;
+ int getNumberOfComponents() const;
+ const std::vector<std::string>& getInfos() const;
+ std::vector<std::string> getPflsReallyUsed() const;
+ std::vector<std::string> getLocsReallyUsed() const;
+ private:
+ MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time);
+ private:
+ MEDFileField1TSWithoutDAS *_father;
+ std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > _field_pm_pt;
+ std::string _mesh_name;
+ double _time;
+ private:
+ mutable std::vector<TypeOfField> _types;
+ mutable std::vector<INTERP_KERNEL::NormalizedCellType> _geo_types;
+ };
+
+ class MEDFieldFieldGlobs
+ {
+ public:
+ void loadProfileInFile(med_idt fid, int id, const char *pflName, int lgth) throw(INTERP_KERNEL::Exception);
+ void loadProfileInFile(med_idt fid, int id);
+ std::vector<std::string> getPfls() const;
+ std::vector<std::string> getLocs() const;
+ protected:
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _pfls;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > _locs;
+ };
+
+ class MEDFileField1TSWithoutDAS : public RefCountObject
+ {
+ public:
+ static MEDFileField1TSWithoutDAS *New(const char *fieldName, int iteration, int order, const std::vector<std::string>& infos);
+ void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time, const char *meshName) const;
+ void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception);
+ int getIteration() const { return _iteration; }
+ int getOrder() const { return _order; }
+ std::string getName() const { return _name; }
+ int getNumberOfComponents() const { return _infos.size(); }
+ const std::vector<std::string>& getInfos() const { return _infos; }
+ std::vector<std::string> getPflsReallyUsed() const;
+ std::vector<std::string> getLocsReallyUsed() const;
+ protected:
+ MEDFileField1TSWithoutDAS(const char *fieldName, int iteration, int order, const std::vector<std::string>& infos);
+ protected:
+ std::string _name;
+ std::vector<std::string> _infos;
+ std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > > _field_per_mesh;
+ int _iteration;
+ int _order;
+ private:
+ mutable std::vector<TypeOfField> _types;
+ mutable std::vector<INTERP_KERNEL::NormalizedCellType> _geo_types;
+ mutable std::vector<double> _times;
+ mutable std::vector<std::string> _meshes;
+ };
+
+ /*!
+ * User class.
+ */
+ class MEDFileField1TS : public MEDFileField1TSWithoutDAS, public MEDFieldFieldGlobs
+ {
+ public:
+ static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
+ private:
+ MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
+ };
+
+ class MEDFileFieldMultiTSWithoutDAS : public RefCountObject
+ {
+ public:
+ static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception);
+ protected:
+ MEDFileFieldMultiTSWithoutDAS(const char *fieldName);
+ MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception);
+ void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception);
+ void appendTimeStepEntry(med_idt fid, med_entite_maillage entity, int i, int j) throw(INTERP_KERNEL::Exception);
+ std::vector<std::string> getPflsReallyUsed() const;
+ std::vector<std::string> getLocsReallyUsed() const;
+ protected:
+ std::string _name;
+ std::vector<std::string> _infos;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutDAS> > _time_steps;
+ };
+
+ /*!
+ * User class.
+ */
+ class MEDFileFieldMultiTS : public MEDFileFieldMultiTSWithoutDAS, public MEDFieldFieldGlobs
+ {
+ public:
+ static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
+ private:
+ MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
+ };
+
+ /*!
+ * Use class.
+ */
+ class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobs
+ {
+ public:
+ static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ int getNumberOfFields() const;
+ std::vector<std::string> getPfls() const;
+ std::vector<std::string> getLocs() const;
+ private:
+ MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception);
+ private:
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutDAS> > _fields;
+ };
+}
+
+#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 "MEDLoader.hxx"
+#include "MEDLoaderBase.hxx"
+
+#include "MEDCouplingUMesh.hxx"
+
+#include "InterpKernelAutoPtr.hxx"
+
+#include <limits>
+
+using namespace ParaMEDMEM;
+
+MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
+{
+ throw INTERP_KERNEL::Exception("Not implemented yet !");
+}
+
+MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileUMesh(fileName,mName);
+}
+
+MEDFileUMesh *MEDFileUMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
+ if(ms.empty())
+ {
+ std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return new MEDFileUMesh(fileName,ms.front().c_str());
+}
+
+MEDFileUMesh *MEDFileUMesh::New()
+{
+ return new MEDFileUMesh;
+}
+
+MEDFileUMesh::MEDFileUMesh():_too_long_str(0),_zipconn_pol(2)
+{
+}
+
+MEDFileUMesh::MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
+ try:_too_long_str(0)
+ {
+ MEDFileUtilities::CheckFileForRead(fileName);
+ med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ MEDFileUMeshL2 loaderl2;
+ loaderl2.loadAll(fid,MEDFileUMeshL2::getMeshIdFromName(fid,mName),mName);
+ int lev=loaderl2.getNumberOfLevels();
+ _ms.resize(lev);
+ for(int i=0;i<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();
+ _fam_coords=loaderl2.getCoordsFamily();
+ _num_coords=loaderl2.getCoordsNum();
+ computeRevNum();
+ }
+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 !");
+ if(!existsFamily(0))
+ (const_cast<MEDFileUMesh *>(this))->addFamily(0,"FAMILLE_ZERO");
+ med_mode_acces medmod=MEDFileUtilities::TraduceWriteMode(mode);
+ med_idt fid=MEDouvrir((char *)fileName,medmod);
+ std::ostringstream oss; oss << "MEDFileUMesh : error on attempt to write in file : \"" << fileName << "\"";
+ MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
+ const DataArrayDouble *coo=_coords;
+ INTERP_KERNEL::AutoPtr<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;
+ int mdim=getMeshDimension();
+ MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc);//spaceDim is false but to make reader happy for 3DSurf and 2DCurve meshes !
+ MEDdimEspaceCr(fid,maa,spaceDim);
+ MEDFileUMeshL2::writeCoords(fid,maa,_coords,_fam_coords,_num_coords);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
+ if((const MEDFileUMeshSplitL1 *)(*it)!=0)
+ (*it)->write(fid,maa,mdim);
+ MEDFileUMeshL2::writeFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
+ MEDfermer(fid);
+}
+
+std::vector<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;
+}
+
+std::vector<int> MEDFileUMesh::getNonEmptyLevelsExt() const
+{
+ std::vector<int> ret0=getNonEmptyLevels();
+ if((const DataArrayDouble *) _coords)
+ {
+ std::vector<int> ret(ret0.size()+1);
+ ret[0]=1;
+ std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
+ return ret;
+ }
+ return ret0;
+}
+
+int MEDFileUMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception)
+{
+ std::string oname(name);
+ std::map<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;
+}
+
+int MEDFileUMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception)
+{
+ if(_families.empty())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getMaxFamilyId : no families set !");
+ int ret=-std::numeric_limits<int>::max();
+ for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+ {
+ ret=std::max((*it).second,ret);
+ }
+ return ret;
+}
+
+std::vector<int> MEDFileUMesh::getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> famIds;
+ for(std::vector<std::string>::const_iterator it=famNames.begin();it!=famNames.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);
+ }
+ return famIds;
+}
+
+std::string MEDFileUMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception)
+{
+ for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+ if((*it).second==id)
+ return (*it).first;
+ std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id;
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+}
+
+int MEDFileUMesh::getMeshDimension() const
+{
+ int lev=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++)
+ if((const MEDFileUMeshSplitL1 *)(*it)!=0)
+ return (*it)->getMeshDimension()+lev;
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !");
+}
+
+int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if(!((const DataArrayDouble *)_coords))
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !");
+ return _coords->getNumberOfTuples();
+ }
+ return getMeshAtLevSafe(meshDimRelToMaxExt)->getSize();
+}
+
+const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if(!((const DataArrayInt *)_fam_coords))
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamilyFieldAtLevel : no coordinates specified !");
+ return _fam_coords;
+ }
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ return l1->getFamilyField();
+}
+
+const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if(!((const DataArrayInt *)_num_coords))
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getNumberFieldAtLevel : no coordinates renum specified !");
+ return _num_coords;
+ }
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ return l1->getNumberField();
+}
+
+const DataArrayInt *MEDFileUMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if(!((const DataArrayInt *)_num_coords))
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !");
+ return _rev_num_coords;
+ }
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ return l1->getRevNumberField();
+}
+
+std::vector<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::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> ret;
+ for(std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();it1!=_groups.end();it1++)
+ {
+ for(std::vector<std::string>::const_iterator it2=(*it1).second.begin();it2!=(*it1).second.end();it2++)
+ if((*it2)==name)
+ {
+ ret.push_back((*it1).first);
+ break;
+ }
+ }
+ return ret;
+}
+
+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 meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=grp;
+ MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum);
+ ret->setName(grp);
+ return ret;
+}
+
+DataArrayInt *MEDFileUMesh::getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=grp;
+ DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum);
+ ret->setName(grp);
+ return ret;
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) 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(meshDimRelToMaxExt,fams2,renum);
+}
+
+DataArrayInt *MEDFileUMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) 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 getFamiliesArr(meshDimRelToMaxExt,fams2,renum);
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=fam;
+ MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum);
+ ret->setName(fam);
+ return ret;
+}
+
+DataArrayInt *MEDFileUMesh::getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=fam;
+ DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum);
+ ret->setName(fam);
+ return ret;
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=getFamiliesArr(1,fams,renum);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> c=_coords->selectByTupleId(arr->getConstPointer(),arr->getConstPointer()+arr->getNbOfElems());
+ ret->setCoords(c);
+ ret->incrRef();
+ return ret;
+ }
+ std::vector<int> famIds=getFamiliesIds(fams);
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ return l1->getFamilyPart(famIds,renum);
+}
+
+DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> famIds=getFamiliesIds(fams);
+ if(meshDimRelToMaxExt==1)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam_coords->getIdsEqualList(famIds);
+ return MEDFileUMeshSplitL1::Renumber(_num_coords,da);
+ }
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ return l1->getFamilyPartArr(famIds,renum);
+}
+
+DataArrayInt *MEDFileUMesh::getNodeGroupArr(const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=grp;
+ DataArrayInt *ret=getNodeGroupsArr(tmp,renum);
+ ret->setName(grp);
+ return ret;
+}
+
+DataArrayInt *MEDFileUMesh::getNodeGroupsArr(const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ return getGroupsArr(1,grps,renum);
+}
+
+DataArrayInt *MEDFileUMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=fam;
+ DataArrayInt *ret=getNodeFamiliesArr(tmp,renum);
+ ret->setName(fam);
+ return ret;
+}
+
+DataArrayInt *MEDFileUMesh::getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ return getFamiliesArr(1,fams,renum);
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if(!renum)
+ {
+ MEDCouplingUMesh *umesh=MEDCouplingUMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> cc=_coords->deepCpy();
+ umesh->setCoords(cc);
+ return umesh;
+ }
+ }
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ return l1->getWholeMesh(renum);
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getLevel0Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ return getMeshAtLevel(0,renum);
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getLevelM1Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ return getMeshAtLevel(-1,renum);
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getLevelM2Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ return getMeshAtLevel(-2,renum);
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getLevelM3Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ return getMeshAtLevel(-3,renum);
+}
+
+bool MEDFileUMesh::existsFamily(int famId) const
+{
+ for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
+ if((*it2).second==famId)
+ return true;
+ return false;
+}
+
+bool MEDFileUMesh::existsFamily(const char *familyName) const
+{
+ std::string fname(familyName);
+ return _families.find(fname)!=_families.end();
+}
+
+const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
+ if(meshDimRelToMaxExt>1)
+ throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
+ int tracucedRk=-meshDimRelToMaxExt;
+ if(tracucedRk>=(int)_ms.size())
+ throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
+ if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
+ throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
+ return _ms[tracucedRk];
+}
+
+MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
+ if(meshDimRelToMaxExt>1)
+ throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
+ int tracucedRk=-meshDimRelToMaxExt;
+ if(tracucedRk>=(int)_ms.size())
+ throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
+ if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
+ throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
+ return _ms[tracucedRk];
+}
+
+void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
+{
+ if(-meshDimRelToMax>=(int)_ms.size())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : The meshdim of mesh is not managed by 'this' !");
+ int i=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<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::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception)
+{
+ coords->checkAllocated();
+ int nbOfTuples=coords->getNumberOfTuples();
+ _coords=coords;
+ coords->incrRef();
+ _fam_coords=DataArrayInt::New();
+ _fam_coords->alloc(nbOfTuples,1);
+ _fam_coords->fillWithZero();
+}
+
+void MEDFileUMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum) throw(INTERP_KERNEL::Exception)
+{
+ if(grps.empty())
+ return ;
+ std::set<std::string> grpsName;
+ std::vector<std::string> grpsName2(grps.size());
+ int i=0;
+
+ for(std::vector<const DataArrayInt *>::const_iterator it=grps.begin();it!=grps.end();it++,i++)
+ {
+ grpsName.insert((*it)->getName());
+ grpsName2[i]=(*it)->getName();
+ }
+ if(grpsName.size()!=grps.size())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !");
+ if(grpsName.find(std::string(""))!=grpsName.end())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !");
+ int sz=getSizeAtLevel(meshDimRelToMaxExt);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam;
+ std::vector< std::vector<int> > fidsOfGroups;
+ if(!renum)
+ {
+ fam=DataArrayInt::MakePartition(grps,sz,fidsOfGroups);
+ }
+ else
+ {
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > grps2(grps.size());
+ for(unsigned int i=0;i<grps.size();i++)
+ {
+ grps2[i]=MEDFileUMeshSplitL1::Renumber(getRevNumberFieldAtLevel(meshDimRelToMaxExt),grps[i]);
+ grps2[i]->setName(grps[i]->getName().c_str());
+ }
+ std::vector<const DataArrayInt *> grps3(grps2.begin(),grps2.end());
+ fam=DataArrayInt::MakePartition(grps3,sz,fidsOfGroups);
+ }
+ int offset=1;
+ if(!_families.empty())
+ offset=getMaxFamilyId()+1;
+ TranslateFamilyIds(offset,fam,fidsOfGroups);
+ std::set<int> ids=fam->getDifferentValues();
+ appendFamilyEntries(ids,fidsOfGroups,grpsName2);
+ setFamilyArr(meshDimRelToMaxExt,fam);
+}
+
+void MEDFileUMesh::eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if((DataArrayInt *)_fam_coords)
+ _fam_coords->fillWithZero();
+ return ;
+ }
+ MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ l1->eraseFamilyField();
+ optimizeFamilies();
+}
+
+void MEDFileUMesh::optimizeFamilies() throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> levs=getNonEmptyLevelsExt();
+ std::set<int> allFamsIds;
+ for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
+ {
+ const DataArrayInt *ffield=getFamilyFieldAtLevel(*it);
+ std::set<int> ids=ffield->getDifferentValues();
+ std::set<int> res;
+ std::set_union(ids.begin(),ids.end(),allFamsIds.begin(),allFamsIds.end(),std::inserter(res,res.begin()));
+ allFamsIds=res;
+ }
+ std::set<std::string> famNamesToKill;
+ for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+ {
+ if(allFamsIds.find((*it).second)!=allFamsIds.end())
+ famNamesToKill.insert((*it).first);
+ }
+ for(std::set<std::string>::const_iterator it=famNamesToKill.begin();it!=famNamesToKill.end();it++)
+ _families.erase(*it);
+ std::vector<std::string> grpNamesToKill;
+ for(std::map<std::string, std::vector<std::string> >::iterator it=_groups.begin();it!=_groups.end();it++)
+ {
+ std::vector<std::string> tmp;
+ for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
+ {
+ if(famNamesToKill.find(*it2)==famNamesToKill.end())
+ tmp.push_back(*it2);
+ }
+ if(!tmp.empty())
+ (*it).second=tmp;
+ else
+ tmp.push_back((*it).first);
+ }
+ for(std::vector<std::string>::const_iterator it=grpNamesToKill.begin();it!=grpNamesToKill.end();it++)
+ _groups.erase(*it);
+}
+
+void MEDFileUMesh::setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector<std::string>& grpNames, bool renum) throw(INTERP_KERNEL::Exception)
+{
+
+}
+
+void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector<int>& ids) throw(INTERP_KERNEL::Exception)
+{
+ const DataArrayDouble *coords=_coords;
+ if(!coords)
+ throw INTERP_KERNEL::Exception("addNodeGroup : no coords set !");
+ DataArrayInt *sub=_fam_coords->selectByTupleIdSafe(&ids[0],&ids[0]+ids.size());
+ std::set<int> ssub(sub->getConstPointer(),sub->getConstPointer()+sub->getNumberOfTuples());
+
+}
+
+void MEDFileUMesh::copyFamGrpMapsFrom(const MEDFileUMesh& other)
+{
+ _groups=other._groups;
+ _families=other._families;
+}
+
+void MEDFileUMesh::setFamilyInfo(const std::map<std::string,int>& info)
+{
+ _families=info;
+}
+
+void MEDFileUMesh::setGroupInfo(const std::map<std::string, std::vector<std::string> >&info)
+{
+ _groups=info;
+}
+
+void MEDFileUMesh::setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception)
+{
+ std::string oldName=getFamilyNameGivenId(id);
+ _families.erase(oldName);
+ _families[newFamName]=id;
+}
+
+void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
+{
+ setMeshAtLevelGen(meshDimRelToMax,m,true);
+}
+
+void MEDFileUMesh::setMeshAtLevelOld(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
+{
+ setMeshAtLevelGen(meshDimRelToMax,m,false);
+}
+
+void MEDFileUMesh::setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<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::setMeshAtLevel : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !");
+ int sz=(-meshDimRelToMax)+1;
+ if(sz>=(int)_ms.size())
+ _ms.resize(sz);
+ checkMeshDimCoherency(m->getMeshDimension(),meshDimRelToMax);
+ _ms[sz-1]=new MEDFileUMeshSplitL1(m,newOrOld);
+ }
+ }
+}
+
+void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector<const 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 !");
+ std::vector<DataArrayInt *> corr;
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,_zipconn_pol,corr);
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr3(corr.begin(),corr.end());
+ setMeshAtLevel(meshDimRelToMax,m);
+ std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
+ setGroupsAtLevel(meshDimRelToMax,corr2,true);
+}
+
+void MEDFileUMesh::setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum) throw(INTERP_KERNEL::Exception)
+{
+ if(ms.empty())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : expecting a non empty vector !");
+ int sz=(-meshDimRelToMax)+1;
+ if(sz>=(int)_ms.size())
+ _ms.resize(sz);
+ checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax);
+ DataArrayDouble *coo=checkMultiMesh(ms);
+ if((DataArrayDouble *)_coords==0)
+ {
+ coo->incrRef();
+ _coords=coo;
+ }
+ else
+ if((DataArrayDouble *)_coords!=coo)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : coordinates mismatches !");
+ MEDCouplingUMesh *m=getMeshAtLevel(meshDimRelToMax,renum);
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr(ms.size());
+ int i=0;
+ for(std::vector<const MEDCouplingUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
+ {
+ DataArrayInt *arr=0;
+ bool test=m->areCellsIncludedIn(*it,_zipconn_pol,arr);
+ corr[i]=arr;
+ if(!test)
+ {
+ std::ostringstream oss; oss << "MEDFileUMesh::setGroupsOnSetMesh : mesh #" << i << " is not part of whole mesh !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
+ setGroupsAtLevel(meshDimRelToMax,corr2,renum);
+}
+
+DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception)
+{
+ const DataArrayDouble *ret=ms[0]->getCoords();
+ int mdim=ms[0]->getMeshDimension();
+ for(unsigned int i=1;i<ms.size();i++)
+ {
+ ms[i]->checkCoherency();
+ if(ms[i]->getCoords()!=ret)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes must share the same coords !");
+ if(ms[i]->getMeshDimension()!=mdim)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes have not same mesh dimension !");
+ }
+ return const_cast<DataArrayDouble *>(ret);
+}
+
+void MEDFileUMesh::setFamilyArr(int meshDimRelToMaxExt, DataArrayInt *famArr)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ famArr->incrRef();
+ _fam_coords=famArr;
+ return ;
+ }
+ if(meshDimRelToMaxExt>1)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyArr : Dimension request is invalid (>1) !");
+ int traducedRk=-meshDimRelToMaxExt;
+ if(traducedRk>=(int)_ms.size())
+ throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
+ if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
+ throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
+ return _ms[traducedRk]->setFamilyArr(famArr);
+}
+
+void MEDFileUMesh::setRenumArr(int meshDimRelToMaxExt, DataArrayInt *renumArr)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if(renumArr)
+ renumArr->incrRef();
+ _num_coords=renumArr;
+ computeRevNum();
+ return ;
+ }
+ if(meshDimRelToMaxExt>1)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumArr : Dimension request is invalid (>1) !");
+ int traducedRk=-meshDimRelToMaxExt;
+ if(traducedRk>=(int)_ms.size())
+ throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
+ if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
+ throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
+ return _ms[traducedRk]->setRenumArr(renumArr);
+}
+
+void MEDFileUMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp)
+{
+ famArr->applyLin(1,offset,0);
+ for(std::vector< std::vector<int> >::iterator it1=famIdsPerGrp.begin();it1!=famIdsPerGrp.end();it1++)
+ std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus<int>(),offset));
+}
+
+/*!
+ * This method append into '_families' attribute the families whose ids are in 'famIds'. Warning 'famIds' are expected to be ids
+ * not in '_families'. Groups information are given in parameters in order to give to families representative names.
+ * For the moment, the two last input parameters are not taken into account.
+ */
+void MEDFileUMesh::appendFamilyEntries(const std::set<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames)
+{
+ std::map<int,std::string> famInv;
+ for(std::set<int>::const_iterator it=famIds.begin();it!=famIds.end();it++)
+ {
+ std::ostringstream oss;
+ oss << "Family_" << (*it);
+ _families[oss.str()]=(*it);
+ famInv[*it]=oss.str();
+ }
+ int i=0;
+ for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGrps.begin();it1!=fidsOfGrps.end();it1++,i++)
+ {
+ for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
+ {
+ _groups[grpNames[i]].push_back(famInv[*it2]);
+ }
+ }
+}
+
+/*!
+ * This method appends a new entry in _families attribute. An exception is thrown if either the famId is already
+ * kept by an another familyName. An exception is thrown if name 'familyName' is alreadyset with a different 'famId'.
+ */
+void MEDFileUMesh::addFamily(int famId, const char *familyName) throw(INTERP_KERNEL::Exception)
+{
+ std::string fname(familyName);
+ std::map<std::string,int>::const_iterator it=_families.find(fname);
+ if(it==_families.end())
+ {
+ for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
+ if((*it2).second==famId)
+ {
+ std::ostringstream oss;
+ oss << "MEDFileUMesh::addFamily : Family \"" << (*it2).first << "\" already exists with specified id : " << famId << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ _families[fname]=famId;
+ }
+ else
+ {
+ if((*it).second!=famId)
+ {
+ std::ostringstream oss;
+ oss << "MEDFileUMesh::addFamily : Family \"" << fname << "\" already exists but has id set to " << (*it).second << " different from asked famId " << famId << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+}
+
+void MEDFileUMesh::computeRevNum() const
+{
+ if((const DataArrayInt *)_num_coords)
+ {
+ int pos;
+ int maxValue=_num_coords->getMaxValue(pos);
+ _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1);
+ }
+}
--- /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(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileUMesh *New();
+ ~MEDFileUMesh();
+ //
+ void removeGroup(const char *name) throw(INTERP_KERNEL::Exception);
+ void removeFamily(const char *name) throw(INTERP_KERNEL::Exception);
+ void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
+ void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
+ //
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception);
+ int getMaxFamilyId() const throw(INTERP_KERNEL::Exception);
+ std::vector<int> getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception);
+ std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception);
+ int getMeshDimension() const;
+ int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ std::vector<std::string> getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
+ std::vector<std::string> getGroupsOnFamily(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;
+ std::vector<int> getNonEmptyLevelsExt() const;
+ DataArrayDouble *getCoords() const;
+ MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getFamily(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getNodeGroupsArr(const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getMeshAtLevel(int meshDimRelToMaxExt, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevel0Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevelM2Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
+ const std::map<std::string,int>& getFamilyInfo() const { return _families; }
+ const std::map<std::string, std::vector<std::string> >& getGroupInfo() const { return _groups; }
+ bool existsFamily(int famId) const;
+ bool existsFamily(const char *familyName) const;
+ //
+ void copyFamGrpMapsFrom(const MEDFileUMesh& other);
+ void setFamilyInfo(const std::map<std::string,int>& info);
+ void setGroupInfo(const std::map<std::string, std::vector<std::string> >&info);
+ void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception);
+ void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
+ void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum=false) throw(INTERP_KERNEL::Exception);
+ void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
+ void setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector<std::string>& grpNames, bool renum=false) throw(INTERP_KERNEL::Exception);
+ void setFamilyArr(int meshDimRelToMaxExt, DataArrayInt *famArr);
+ void setRenumArr(int meshDimRelToMaxExt, DataArrayInt *renumArr);
+ void addNodeGroup(const std::string& name, const std::vector<int>& ids) throw(INTERP_KERNEL::Exception);
+ void setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception);
+ void setMeshAtLevelOld(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception);
+ void setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
+ void setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception);
+ void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum) throw(INTERP_KERNEL::Exception);
+ void optimizeFamilies() throw(INTERP_KERNEL::Exception);
+ void addFamily(int famId, const char *familyName) throw(INTERP_KERNEL::Exception);
+ private:
+ MEDFileUMesh();
+ MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
+ const MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
+ void checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception);
+ DataArrayDouble *checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception);
+ void appendFamilyEntries(const std::set<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames);
+ void computeRevNum() const;
+ static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp);
+ private:
+ std::map<std::string, std::vector<std::string> > _groups;
+ std::map<std::string,int> _families;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> > _ms;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
+ mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_coords;
+ int _too_long_str;
+ int _zipconn_pol;
+ };
+
+
+ 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 "MEDCouplingUMesh.hxx"
+
+#include "InterpKernelAutoPtr.hxx"
+#include "CellModel.hxx"
+
+extern med_geometrie_element typmai3[32];
+
+using namespace ParaMEDMEM;
+
+MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2)
+{
+ med_entite_maillage whichEntity;
+ if(!isExisting(fid,mName,geoElt,whichEntity))
+ return 0;
+ return new MEDFileUMeshPerType(fid,mName,mdim,geoElt,geoElt2,whichEntity);
+}
+
+bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity)
+{
+ static const med_entite_maillage entities[3]={MED_MAILLE,MED_FACE,MED_ARETE};
+ int nbOfElt=0;
+ for(int i=0;i<3;i++)
+ {
+ int tmp=MEDnEntMaa(fid,(char *)mName,MED_CONN,entities[i],geoElt,MED_NOD);
+ if(tmp>nbOfElt)
+ {
+ nbOfElt=tmp;
+ whichEntity=entities[i];
+ }
+ }
+ return nbOfElt>0;
+}
+
+int MEDFileUMeshPerType::getDim() const
+{
+ const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_type);
+ return cm.getDimension();
+}
+
+MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type,
+ med_entite_maillage entity):_type(type),_entity(entity)
+{
+ int curNbOfElem=MEDnEntMaa(fid,(char *)mName,MED_CONN,entity,geoElt,MED_NOD);
+ if(type!=INTERP_KERNEL::NORM_POLYGON && type!=INTERP_KERNEL::NORM_POLYHED)
+ {
+ loadFromStaticType(fid,mName,mdim,curNbOfElem,geoElt,type,entity);
+ return;
+ }
+ if(type==INTERP_KERNEL::NORM_POLYGON)
+ {
+ loadPolyg(fid,mName,mdim,curNbOfElem,geoElt,entity);
+ return;
+ }
+ //if(type==INTERP_KERNEL::NORM_POLYHED)
+ loadPolyh(fid,mName,mdim,curNbOfElem,geoElt,entity);
+}
+
+void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type,
+ med_entite_maillage entity)
+{
+ _conn=DataArrayInt::New();
+ int nbOfNodesPerCell=(geoElt%100);
+ _conn->alloc((nbOfNodesPerCell+1)*curNbOfElem,1);
+ _conn_index=DataArrayInt::New();
+ _conn_index->alloc(curNbOfElem+1,1);
+ int *connTab=new int[(nbOfNodesPerCell)*curNbOfElem];
+ _num=DataArrayInt::New();
+ _num->alloc(curNbOfElem,1);
+ char *noms=new char[MED_TAILLE_PNOM*curNbOfElem+1];
+ med_booleen inoele, inuele;
+ _fam=DataArrayInt::New();
+ _fam->alloc(curNbOfElem,1);
+ MEDelementsLire(fid,(char *)mName,mdim,connTab,MED_FULL_INTERLACE,noms,&inoele,_num->getPointer(),&inuele,_fam->getPointer(),curNbOfElem,entity,geoElt,MED_NOD);
+ delete [] noms;
+ int *w1=_conn->getPointer();
+ int *w2=_conn_index->getPointer();
+ *w2++=0;
+ const int *wi=connTab;
+ for(int i=0;i<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;
+}
+
+void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num)
+{
+ int nbOfCells=m->getNumberOfCells();
+ if(nbOfCells<1)
+ return ;
+ INTERP_KERNEL::NormalizedCellType ikt=m->getTypeOfCell(0);
+ const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(ikt);
+ med_geometrie_element curMedType=typmai3[(int)ikt];
+ const int *conn=m->getNodalConnectivity()->getConstPointer();
+ const int *connI=m->getNodalConnectivityIndex()->getConstPointer();
+ if(ikt!=INTERP_KERNEL::NORM_POLYGON && ikt!=INTERP_KERNEL::NORM_POLYHED)
+ {
+ int nbNodesPerCell=cm.getNumberOfNodes();
+ INTERP_KERNEL::AutoPtr<int> tab=new int[nbNodesPerCell*nbOfCells];
+ int *w=tab;
+ for(int i=0;i<nbOfCells;i++)
+ w=std::transform(conn+connI[i]+1,conn+connI[i+1],w,std::bind2nd(std::plus<int>(),1));
+ MEDconnEcr(fid,(char *)mname,mdim,tab,MED_FULL_INTERLACE,nbOfCells,MED_MAILLE,curMedType,MED_NOD);
+ }
+ else
+ {
+ if(ikt==INTERP_KERNEL::NORM_POLYGON)
+ {
+ INTERP_KERNEL::AutoPtr<int> tab1=new int[nbOfCells+1];
+ INTERP_KERNEL::AutoPtr<int> tab2=new int[m->getMeshLength()];
+ int *wI=tab1; *wI=1;
+ int *w=tab2;
+ for(int i=0;i<nbOfCells;i++,wI++)
+ {
+ wI[1]=wI[0]+connI[i+1]-connI[i]-1;
+ w=std::transform(conn+connI[i]+1,conn+connI[i+1],w,std::bind2nd(std::plus<int>(),1));
+ }
+ MEDpolygoneConnEcr(fid,(char *)mname,tab1,nbOfCells,tab2,MED_MAILLE,MED_NOD);
+ }
+ else
+ {
+ int meshLgth=m->getMeshLength();
+ int nbOfFaces=std::count(conn,conn+meshLgth,-1)+nbOfCells;
+ INTERP_KERNEL::AutoPtr<int> tab1=new int[nbOfCells+1];
+ int *w1=tab1; *w1=1;
+ INTERP_KERNEL::AutoPtr<int> tab2=new int[nbOfFaces+1];
+ int *w2=tab2; *w2=1;
+ INTERP_KERNEL::AutoPtr<int> bigtab=new int[meshLgth-nbOfCells];
+ int *bt=bigtab;
+ for(int i=0;i<nbOfCells;i++,w1++)
+ {
+ int nbOfFaces=0;
+ for(const int *w=conn+connI[i]+1;w!=conn+connI[i+1];w2++)
+ {
+ const int *wend=std::find(w,conn+connI[i+1],-1);
+ bt=std::transform(w,wend,bt,std::bind2nd(std::plus<int>(),1));
+ int nbOfNode=std::distance(w,wend);
+ w2[1]=w2[0]+nbOfNode;
+ if(wend!=conn+connI[i+1])
+ w=wend+1;
+ else
+ w=wend;
+ nbOfFaces++;
+ }
+ w1[1]=w1[0]+nbOfFaces;
+ }
+ MEDpolyedreConnEcr(fid,(char *)mname,tab1,nbOfCells+1,tab2,nbOfFaces+1,
+ bigtab,MED_NOD);
+ }
+ }
+ if(fam)
+ MEDfamEcr(fid,(char *)mname,(int *)fam->getConstPointer(),nbOfCells,MED_MAILLE,curMedType);
+ if(num)
+ MEDnumEcr(fid,(char *)mname,(int *)num->getConstPointer(),nbOfCells,MED_MAILLE,curMedType);
+}
--- /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 MEDCouplingUMesh;
+
+ class MEDFileUMeshPerType : public RefCountObject
+ {
+ public:
+ static MEDFileUMeshPerType *New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2);
+ static bool isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity);
+ int getDim() const;
+ const DataArrayInt *getNodal() const { return _conn; }
+ const DataArrayInt *getNodalIndex() const { return _conn_index; }
+ const DataArrayInt *getFam() const { return _fam; }
+ const DataArrayInt *getNum() const { return _num; }
+ static void write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num);
+ private:
+ MEDFileUMeshPerType(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type,
+ med_entite_maillage entity);
+ void loadFromStaticType(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type,
+ med_entite_maillage entity);
+ void loadPolyg(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt,
+ med_entite_maillage entity);
+ void loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt,
+ med_entite_maillage entity);
+ private:
+ MEDCouplingAutoRefCountObjectPtr<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 "InterpKernelAutoPtr.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);
+ _fam_coords=DataArrayInt::New();
+ _fam_coords->alloc(nCoords,1);
+ _num_coords=DataArrayInt::New();
+ _num_coords->alloc(nCoords,1);
+ MEDfamLire(fid,(char *)mName,_fam_coords->getPointer(),nCoords,MED_NOEUD,MED_NONE);
+ if(MEDnumLire(fid,(char *)mName,_num_coords->getPointer(),nCoords,MED_NOEUD,MED_NONE)!=0)
+ _num_coords=0;
+ for(int i=0;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 (" << mname << ") 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::writeFamiliesAndGrps(med_idt fid, const char *mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol)
+{
+ for(std::map<std::string,int>::const_iterator it=fams.begin();it!=fams.end();it++)
+ {
+ std::vector<std::string> grpsOfFam;
+ for(std::map<std::string, std::vector<std::string> >::const_iterator it1=grps.begin();it1!=grps.end();it1++)
+ {
+ if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end())
+ grpsOfFam.push_back((*it1).first);
+ }
+ int ngro=grpsOfFam.size();
+ INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_TAILLE_LNOM*ngro);
+ int i=0;
+ for(std::vector<std::string>::const_iterator it2=grpsOfFam.begin();it2!=grpsOfFam.end();it2++,i++)
+ MEDLoaderBase::safeStrCpy((*it2).c_str(),MED_TAILLE_LNOM-1,groName+i*MED_TAILLE_LNOM,tooLongStrPol);
+ INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_TAILLE_NOM,famName,tooLongStrPol);
+ MEDfamCr(fid,(char *)mname,famName,(*it).second,0,0,0,0,groName,ngro);
+ }
+}
+
+void MEDFileUMeshL2::writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords)
+{
+ if(!coords)
+ return ;
+ int spaceDim=coords->getNumberOfComponents();
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
+ for(int i=0;i<spaceDim;i++)
+ {
+ std::string info=coords->getInfoOnComponent(i);
+ std::string c,u;
+ MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
+ MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+ MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+ }
+ MEDcoordEcr(fid,(char *)mname,spaceDim,coords->getPointer(),MED_FULL_INTERLACE,coords->getNumberOfTuples(),MED_CART,comp,unit);
+ MEDfamEcr(fid,(char *)mname,famCoords->getPointer(),famCoords->getNumberOfTuples(),MED_NOEUD,MED_NONE);
+ if(numCoords)
+ MEDnumEcr(fid,(char *)mname,numCoords->getPointer(),numCoords->getNumberOfTuples(),MED_NOEUD,MED_NONE);
+}
+
+bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<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;
+}
+
+MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
+{
+}
+
+/*!
+ * Warning it returns an instance to deallocate !!!!
+ */
+MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
+{
+ _st->_m_by_types->updateTime();
+ _st->_num->updateTime();
+ if((MEDCouplingUMesh *)_m==0)
+ {
+ updateTime();
+ MEDCouplingUMesh *ret=(MEDCouplingUMesh *)_st->_m_by_types->deepCpy();
+ _m=ret;
+ _m->renumberCells(_st->_num->getConstPointer(),true);
+ ret->incrRef();
+ return ret;
+ }
+ else
+ {
+ if(_mpt_time==_st->_m_by_types->getTimeOfThis() && _num_time==_st->_num->getTimeOfThis())
+ {
+ _m->incrRef();
+ return _m;
+ }
+ else
+ {
+ updateTime();
+ MEDCouplingUMesh *ret=(MEDCouplingUMesh *)_st->_m_by_types->deepCpy();
+ _m=ret;
+ _m->renumberCells(_st->_num->getConstPointer(),true);
+ ret->incrRef();
+ return ret;
+ }
+ }
+}
+
+void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m)
+{
+ _m=m;
+}
+
+void MEDFileUMeshPermCompute::updateTime() const
+{
+ _mpt_time=_st->_m_by_types->getTimeOfThis();
+ _num_time=_st->_num->getTimeOfThis();
+}
+
+MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id):_m(this)
+{
+ const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& v=l2.getLev(id);
+ if(v.empty())
+ return;
+ int sz=v.size();
+ std::vector<const 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);
+ computeRevNum();
+ }
+ for(int i=0;i<sz;i++)
+ (const_cast<MEDCouplingUMesh *>(ms[i]))->decrRef();//const cast under control to avoid a copy of array
+}
+
+MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
+{
+ assignMesh(m,true);
+}
+
+MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this)
+{
+ assignMesh(m,newOrOld);
+}
+
+void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
+{
+ if(newOrOld)
+ {
+ m->incrRef();
+ _m=m;
+ _m_by_types=(MEDCouplingUMesh *)m->deepCpy();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
+ if(!da->isIdentity())
+ {
+ _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
+ _m.updateTime();
+ computeRevNum();
+ _m_by_types->renumberCells(da->getConstPointer(),false);
+ }
+ }
+ else
+ {
+ if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2))
+ throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh : the mode of mesh setting expects to follow the MED file numbering convention ! it is not the case !");
+ m->incrRef();
+ _m_by_types=m;
+ }
+ _fam=DataArrayInt::New();
+ _fam->alloc(m->getNumberOfCells(),1);
+ _fam->fillWithValue(0);
+}
+
+bool MEDFileUMeshSplitL1::empty() const
+{
+ return ((const MEDCouplingUMesh *)_m_by_types)==0;
+}
+
+int MEDFileUMeshSplitL1::getMeshDimension() const
+{
+ return _m_by_types->getMeshDimension();
+}
+
+int MEDFileUMeshSplitL1::getSize() const throw(INTERP_KERNEL::Exception)
+{
+ if((const MEDCouplingUMesh *)_m_by_types==0)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::getSize : no mesh specified at level !");
+ return _m_by_types->getNumberOfCells();
+}
+
+MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const std::vector<int>& ids, bool renum) const
+{
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> eltsToKeep=_fam->getIdsEqualList(ids);
+ MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
+ if(renum)
+ return renumIfNeeded(m,eltsToKeep->getConstPointer());
+ return m;
+}
+
+DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const std::vector<int>& ids, bool renum) const
+{
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam->getIdsEqualList(ids);
+ if(renum)
+ return renumIfNeededArr(da);
+ da->incrRef();
+ return da;
+}
+
+MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp;
+ if(renum)
+ tmp=_m;
+ else
+ tmp=_m_by_types;
+ tmp->incrRef();
+ return tmp;
+}
+
+const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
+{
+ return _fam;
+}
+
+const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const
+{
+ return _num;
+}
+
+const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const
+{
+ return _rev_num;
+}
+
+void MEDFileUMeshSplitL1::eraseFamilyField()
+{
+ _fam->fillWithZero();
+}
+
+/*!
+ * This method ignores _m and _m_by_types.
+ */
+void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const 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;
+ std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
+ _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
+ int nbOfCells=((MEDCouplingUMesh *)_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];
+}
+
+void MEDFileUMeshSplitL1::write(med_idt fid, const char *mName, int mdim) const
+{
+ std::vector<MEDCouplingUMesh *> ms=_m_by_types->splitByType();
+ int start=0;
+ for(std::vector<MEDCouplingUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
+ {
+ int nbCells=(*it)->getNumberOfCells();
+ int end=start+nbCells;
+ DataArrayInt *fam=0,*num=0;
+ if((const DataArrayInt *)_fam)
+ fam=_fam->substr(start,end);
+ if((const DataArrayInt *)_num)
+ num=_num->substr(start,end);
+ MEDFileUMeshPerType::write(fid,mName,mdim,(*it),fam,num);
+ if(fam)
+ fam->decrRef();
+ if(num)
+ num->decrRef();
+ (*it)->decrRef();
+ start=end;
+ }
+}
+
+void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr)
+{
+ famArr->incrRef();
+ _fam=famArr;
+}
+
+void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr)
+{
+ renumArr->incrRef();
+ _num=renumArr;
+ computeRevNum();
+}
+
+MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds)
+{
+ if(renum==0)
+ return m;
+ if(cellIds==0)
+ m->renumberCells(renum->getConstPointer(),true);
+ else
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
+ m->renumberCells(locnum->getConstPointer(),true);
+ }
+ return m;
+}
+
+MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
+{
+ return Renumber2(_num,m,cellIds);
+}
+
+DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da)
+{
+ if((const DataArrayInt *)renum==0)
+ {
+ da->incrRef();
+ return const_cast<DataArrayInt *>(da);
+ }
+ return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
+}
+
+DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
+{
+ return Renumber(_num,da);
+}
+
+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;
+
+}
+
+void MEDFileUMeshSplitL1::computeRevNum() const
+{
+ int pos;
+ int maxValue=_num->getMaxValue(pos);
+ _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
+}
--- /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; }
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
+ static int getMeshIdFromName(med_idt fid, const char *mname) throw(INTERP_KERNEL::Exception);
+ static void readFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps);
+ static void writeFamiliesAndGrps(med_idt fid, const char *mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol);
+ static void writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords);
+ private:
+ void sortTypes();
+ private:
+ std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
+ };
+
+ class MEDFileUMeshL2CMesh : public MEDFileMeshL2
+ {
+ };
+
+ class MEDFileUMeshSplitL1;
+
+ class MEDFileUMeshPermCompute
+ {
+ public:
+ MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
+ operator MEDCouplingUMesh *() const;
+ void operator=(MEDCouplingUMesh *m);
+ void updateTime() const;
+ private:
+ const MEDFileUMeshSplitL1 *_st;
+ mutable unsigned int _mpt_time;
+ mutable unsigned int _num_time;
+ mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
+ };
+
+ class MEDFileUMeshSplitL1 : public RefCountObject
+ {
+ friend class MEDFileUMeshPermCompute;
+ public:
+ MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
+ MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
+ MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
+ void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
+ bool empty() const;
+ int getMeshDimension() const;
+ int getSize() const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getFamilyPart(const std::vector<int>& ids, bool renum) const;
+ DataArrayInt *getFamilyPartArr(const std::vector<int>& ids, bool renum) const;
+ MEDCouplingUMesh *getWholeMesh(bool renum) const;
+ const DataArrayInt *getFamilyField() const;
+ const DataArrayInt *getNumberField() const;
+ const DataArrayInt *getRevNumberField() const;
+ void eraseFamilyField();
+ void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
+ std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
+ void write(med_idt fid, const char *mName, int mdim) const;
+ //
+ void setFamilyArr(DataArrayInt *famArr);
+ void setRenumArr(DataArrayInt *renumArr);
+ //
+ static std::vector<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);
+ static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
+ static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
+ private:
+ MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
+ DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
+ void computeRevNum() const;
+ private:
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m_by_types;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
+ mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
+ MEDFileUMeshPermCompute _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==-1)
+ {
+ std::ostringstream oss;
+ oss << "MEDFile has returned an error code (" << code <<") : " << msg;
+ MEDfermer(fid);
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+}
+
+void MEDFileUtilities::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ int status=MEDLoaderBase::getStatusOfFile(fileName);
+ std::ostringstream oss;
+ oss << " File : \"" << fileName << "\"";
+ switch(status)
+ {
+ case MEDLoaderBase::DIR_LOCKED:
+ {
+ oss << " has been detected as unreadable : impossible to read anything !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ case MEDLoaderBase::NOT_EXIST:
+ {
+ oss << " has been detected as NOT EXISTING : impossible to read anything !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ case MEDLoaderBase::EXIST_WRONLY:
+ {
+ oss << " has been detected as WRITE ONLY : impossible to read anything !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ int fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ if(fid<0)
+ {
+ oss << " has been detected as unreadable by MED file : impossible to read anything !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ oss << " has been detected readable but ";
+ int major,minor,release;
+ MEDversionLire(fid,&major,&minor,&release);
+ if(major<2 || (major==2 && minor<2))
+ {
+ oss << "version of MED file is < 2.2 : impossible to read anything !";
+ MEDfermer(fid);
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ MEDfermer(fid);
+}
--- /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 "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingGaussLocalization.hxx"
+#include "InterpKernelAutoPtr.hxx"
+
extern "C"
{
#include "med.h"
#include <iterator>
#include <algorithm>
#include <numeric>
+#include <limits>
med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2] = { MED_POINT1,
MED_SEG2,
MED_SEG3,
MED_TRIA3,
- MED_TRIA6,
MED_QUAD4,
+ MED_TRIA6,
MED_QUAD8,
MED_TETRA4,
- MED_TETRA10,
- MED_HEXA8,
- MED_HEXA20,
- MED_PENTA6,
- MED_PENTA15,
MED_PYRA5,
+ MED_PENTA6,
+ MED_HEXA8,
+ MED_TETRA10,
MED_PYRA13,
+ MED_PENTA15,
+ MED_HEXA20,
MED_POLYGONE,
MED_POLYEDRE };
med_geometrie_element typmainoeud[1] = { MED_NONE };
-INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP_KERNEL::NORM_POINT0,
+INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP_KERNEL::NORM_POINT1,
INTERP_KERNEL::NORM_SEG2,
INTERP_KERNEL::NORM_SEG3,
INTERP_KERNEL::NORM_TRI3,
- INTERP_KERNEL::NORM_TRI6,
INTERP_KERNEL::NORM_QUAD4,
+ INTERP_KERNEL::NORM_TRI6,
INTERP_KERNEL::NORM_QUAD8,
INTERP_KERNEL::NORM_TETRA4,
- INTERP_KERNEL::NORM_TETRA10,
- INTERP_KERNEL::NORM_HEXA8,
- INTERP_KERNEL::NORM_HEXA20,
- INTERP_KERNEL::NORM_PENTA6,
- INTERP_KERNEL::NORM_PENTA15,
INTERP_KERNEL::NORM_PYRA5,
+ INTERP_KERNEL::NORM_PENTA6,
+ INTERP_KERNEL::NORM_HEXA8,
+ INTERP_KERNEL::NORM_TETRA10,
INTERP_KERNEL::NORM_PYRA13,
+ INTERP_KERNEL::NORM_PENTA15,
+ INTERP_KERNEL::NORM_HEXA20,
INTERP_KERNEL::NORM_POLYGON,
INTERP_KERNEL::NORM_POLYHED };
void prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIds, std::list<MEDLoader::MEDFieldDoublePerCellType>& split);
void fillGaussDataOnField(const char *fileName, const std::list<MEDLoader::MEDFieldDoublePerCellType>& data, MEDCouplingFieldDouble *f);
void writeUMeshesDirectly(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& mesh, const std::vector<const DataArrayInt *>& families, bool forceFromScratch, bool &isRenumbering);
- void writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch);
+ void writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch);
void writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch);
void writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
}
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)
MEDfermer(fid);
return ret;
}
+
+std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception)
+{
+ CheckFileForRead(fileName);
+ med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ med_int nfam=MEDnFam(fid,(char *)meshName);
+ std::vector<std::string> ret;
+ char nomfam[MED_TAILLE_NOM+1];
+ med_int numfam;
+ for(int i=0;i<nfam;i++)
+ {
+ int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
+ med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
+ INTERP_KERNEL::AutoPtr<med_int> attide=new int[natt];
+ INTERP_KERNEL::AutoPtr<med_int> attval=new int[natt];
+ INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_TAILLE_DESC*natt+1];
+ INTERP_KERNEL::AutoPtr<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 cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
+ for(int j=0;j<ngro;j++)
+ {
+ std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
+ if(cur2==grpName)
+ ret.push_back(cur);
+ }
+ }
+ MEDfermer(fid);
+ return ret;
+}
+
+std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception)
+{
+ CheckFileForRead(fileName);
+ med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ med_int nfam=MEDnFam(fid,(char *)meshName);
+ std::vector<std::string> ret;
+ char nomfam[MED_TAILLE_NOM+1];
+ med_int numfam;
+ bool found=false;
+ for(int i=0;i<nfam && !found;i++)
+ {
+ int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
+ med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
+ INTERP_KERNEL::AutoPtr<med_int> attide=new int[natt];
+ INTERP_KERNEL::AutoPtr<med_int> attval=new int[natt];
+ INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_TAILLE_DESC*natt+1];
+ INTERP_KERNEL::AutoPtr<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 cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
+ found=(cur==famName);
+ if(found)
+ for(int j=0;j<ngro;j++)
+ {
+ std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
+ ret.push_back(cur);
+ }
+ }
+ MEDfermer(fid);
+ if(!found)
+ {
+ std::ostringstream oss;
+ oss << "MEDLoader::GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return ret;
+}
std::vector<std::string> MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
MEDfermer(fid);
return ret;
}
-std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception)
+std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
std::vector<ParaMEDMEM::TypeOfField> ret;
//
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);
MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<int>& ids,
const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception)
{
+ if(meshDimRelToMax>0)
+ throw INTERP_KERNEL::Exception("meshDimRelToMax must be <=0 !");
//Extraction data from MED file.
med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
std::string trueMeshName;
{
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)
- mesh2=newMesh->keepSpecifiedCells((*iter).getType(),ci);
+ mesh2=newMesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
else
- mesh2=mesh->keepSpecifiedCells((*iter).getType(),ci);
+ mesh2=mesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
}
else if(typeOfOutField==ON_NODES)
{
const char DftFamilyName[]="DftFamily";
std::copy(DftFamilyName,DftFamilyName+sizeof(DftFamilyName),familyName);
MEDfamCr(fid,maa,familyName,0,0,0,0,0,0,0);
- DataArrayDouble *arr=mesh[0]->getCoords();
+ const DataArrayDouble *arr=mesh[0]->getCoords();
char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
for(int i=0;i<spaceDim;i++)
* In this method meshes are assumed to shared the same coords.
* This method makes the assumption that 'meshes' is not empty, no check on that is done (responsability of the caller)
*/
-void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch)
+void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch)
{
std::string meshNameCpp(meshName);
char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
if(meshNameCpp=="")
throw INTERP_KERNEL::Exception("writeUMeshesPartitionDirectly : Invalid meshName : Must be different from \"\" !");
std::vector< DataArrayInt * > corr;
- MEDCouplingUMesh *m=ParaMEDMEM::MEDCouplingUMesh::fuseUMeshesOnSameCoords(meshes,0,corr);
+ MEDCouplingUMesh *m=ParaMEDMEM::MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
m->setName(meshName);
std::vector< std::vector<int> > fidsOfGroups;
- DataArrayInt *arr2=DataArrayInt::makePartition(corr,m->getNumberOfCells(),fidsOfGroups);
+ std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
+ DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m->getNumberOfCells(),fidsOfGroups);
for(std::vector< DataArrayInt * >::iterator it=corr.begin();it!=corr.end();it++)
(*it)->decrRef();
bool isRenumbering;
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
MEDCouplingUMesh *m=MEDLoader::ReadUMeshFromFile(fileName,f->getMesh()->getName(),f2);
- MEDCouplingUMesh *m2=MEDCouplingUMesh::mergeUMeshes(m,(MEDCouplingUMesh *)f->getMesh());
+ MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshes(m,(MEDCouplingUMesh *)f->getMesh());
bool areNodesMerged;
int newNbOfNodes;
DataArrayInt *da=m2->mergeNodes(MEDLoader::_EPS_FOR_NODE_COMP,areNodesMerged,newNbOfNodes);
MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering);
}
-void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector<ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
+void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
{
std::string meshName(meshNameC);
if(meshName.empty())
}
if(meshes.empty())
throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
- DataArrayDouble *coords=meshes.front()->getCoords();
- for(std::vector<ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
+ const DataArrayDouble *coords=meshes.front()->getCoords();
+ for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
if(coords!=(*iter)->getCoords())
throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
std::set<std::string> tmp;
- for(std::vector<ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
+ for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
{
if(tmp.find((*iter)->getName())==tmp.end())
tmp.insert((*iter)->getName());
}
}
-void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector<ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
+void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
{
std::string meshName(meshNameC);
if(meshName.empty())
}
if(meshes.empty())
throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
- DataArrayDouble *coords=meshes.front()->getCoords();
- for(std::vector<ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
+ const DataArrayDouble *coords=meshes.front()->getCoords();
+ for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
if(coords!=(*iter)->getCoords())
throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
std::set<std::string> tmp;
- for(std::vector<ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
+ for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
{
if(tmp.find((*iter)->getName())==tmp.end())
tmp.insert((*iter)->getName());
std::string meshName(meshes[0]->getName());
if(meshName.empty())
throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name : change name of first element of 2nd parameter !");
- DataArrayDouble *coords=meshes.front()->getCoords();
+ const DataArrayDouble *coords=meshes.front()->getCoords();
for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
if(coords!=(*iter)->getCoords())
throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
static std::vector<std::string> GetMeshNamesOnField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
+ static std::vector<std::string> GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception);
+ static std::vector<std::string> GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetAllFieldNames(const char *fileName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
- static std::vector<ParaMEDMEM::TypeOfField> GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception);
+ static std::vector<ParaMEDMEM::TypeOfField> GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
static void WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
static void WriteUMeshDep(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
- static void WriteUMeshesPartition(const char *fileName, const char *meshName, const std::vector<ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
- static void WriteUMeshesPartitionDep(const char *fileName, const char *meshName, const std::vector<ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
+ static void WriteUMeshesPartition(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
+ static void WriteUMeshesPartitionDep(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
static void WriteUMeshes(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
static void WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
static void WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
salomeinclude_HEADERS= \
MEDLoaderDefines.hxx \
-MEDLoader.hxx MEDLoaderBase.hxx
+MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx MEDFileMeshLL.hxx \
+MEDFileMeshElt.hxx MEDFileBasis.hxx MEDFileField.hxx
dist_libmedloader_la_SOURCES= \
-MEDLoader.cxx MEDLoaderBase.cxx
+MEDLoader.cxx MEDLoaderBase.cxx MEDFileUtilities.cxx \
+MEDFileMesh.cxx MEDFileMeshElt.cxx MEDFileBasis.cxx \
+MEDFileMeshLL.cxx MEDFileField.cxx
libmedloader_la_CPPFLAGS= $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \
-I$(srcdir)/../INTERP_KERNEL \