#include "InterpKernelAutoPtr.hxx"
+#include <limits>
+
using namespace ParaMEDMEM;
MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
return new MEDFileUMesh;
}
-MEDFileUMesh::MEDFileUMesh():_too_long_str(0)
+MEDFileUMesh::MEDFileUMesh():_too_long_str(0),_zipconn_pol(2)
{
}
_coords=loaderl2.getCoords();
_fam_coords=loaderl2.getCoordsFamily();
_num_coords=loaderl2.getCoordsNum();
+ computeRevNum();
}
catch(INTERP_KERNEL::Exception& e)
{
{
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 << "\"";
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);
+ MEDFileUMeshL2::writeFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
MEDfermer(fid);
}
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);
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;
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);
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());
return 0;
}
-MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMax, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+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(meshDimRelToMax,tmp,renum);
+ MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum);
ret->setName(grp);
return ret;
}
-DataArrayInt *MEDFileUMesh::getGroupArr(int meshDimRelToMax, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+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(meshDimRelToMax,tmp,renum);
+ DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum);
ret->setName(grp);
return ret;
}
-MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMax, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
+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++)
fams.insert((*it2).second.begin(),(*it2).second.end());
}
std::vector<std::string> fams2(fams.begin(),fams.end());
- return getFamilies(meshDimRelToMax,fams2,renum);
+ return getFamilies(meshDimRelToMaxExt,fams2,renum);
}
-DataArrayInt *MEDFileUMesh::getGroupsArr(int meshDimRelToMax, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
+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++)
fams.insert((*it2).second.begin(),(*it2).second.end());
}
std::vector<std::string> fams2(fams.begin(),fams.end());
- return getFamiliesArr(meshDimRelToMax,fams2,renum);
+ return getFamiliesArr(meshDimRelToMaxExt,fams2,renum);
}
-MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMax, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
{
std::vector<std::string> tmp(1);
tmp[0]=fam;
- MEDCouplingUMesh *ret=getFamilies(meshDimRelToMax,tmp,renum);
+ MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum);
ret->setName(fam);
return ret;
}
-DataArrayInt *MEDFileUMesh::getFamilyArr(int meshDimRelToMax, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+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(meshDimRelToMax,tmp,renum);
+ DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum);
ret->setName(fam);
return ret;
}
-MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMax, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+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(meshDimRelToMax);
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
return l1->getFamilyPart(famIds,renum);
}
-DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMax, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
{
std::vector<int> famIds=getFamiliesIds(fams);
- const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax);
+ 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::getNodeGroupsArr(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 getNodeFamiliesArr(fams2,renum);
+ return getGroupsArr(1,grps,renum);
}
DataArrayInt *MEDFileUMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
DataArrayInt *MEDFileUMesh::getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
{
- std::vector<int> famIds=getFamiliesIds(fams);
- DataArrayInt *da=_fam_coords->getIdsEqualList(famIds);
- if(renum)
- return MEDFileUMeshSplitL1::renumber(_num_coords,da);
- return da;
+ return getFamiliesArr(1,fams,renum);
}
-MEDCouplingUMesh *MEDFileUMesh::getMeshAtRank(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception)
+MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception)
{
- const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax);
+ 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::getRank0Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
+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 getMeshAtRank(0,renum);
+ return getMeshAtLevel(-3,renum);
}
-MEDCouplingUMesh *MEDFileUMesh::getRankM1Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
+bool MEDFileUMesh::existsFamily(int famId) const
{
- return getMeshAtRank(-1,renum);
+ for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
+ if((*it2).second==famId)
+ return true;
+ return false;
}
-MEDCouplingUMesh *MEDFileUMesh::getRankM2Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
+bool MEDFileUMesh::existsFamily(const char *familyName) const
{
- return getMeshAtRank(-2,renum);
+ std::string fname(familyName);
+ return _families.find(fname)!=_families.end();
}
-MEDCouplingUMesh *MEDFileUMesh::getRankM3Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
+const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
{
- return getMeshAtRank(-3,renum);
+ 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];
}
-const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
+MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
{
- int tracucedRk=-meshDimRelToMax;
+ 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)
if(((const MEDFileUMeshSplitL1*) (*it))!=0)
{
int ref=(*it)->getMeshDimension();
- if(ref+i!=meshDim+meshDimRelToMax)
+ if(ref+i!=meshDim-meshDimRelToMax)
throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : no coherency between levels !");
}
}
_fam_coords->fillWithZero();
}
-void MEDFileUMesh::addNodeGroup(const std::vector<int>& ids) throw(INTERP_KERNEL::Exception)
+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)
_families[newFamName]=id;
}
-void MEDFileUMesh::setMeshAtRank(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
+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())
else
{
if(m->getCoords()!=_coords)
- throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtRank : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !");
+ 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(),sz);
- _ms[sz]=new MEDFileUMeshSplitL1(m);
+ checkMeshDimCoherency(m->getMeshDimension(),meshDimRelToMax);
+ _ms[sz-1]=new MEDFileUMeshSplitL1(m,newOrOld);
}
}
}
-void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector<MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception)
+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 !");
else
if((DataArrayDouble *)_coords!=coo)
throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : coordinates mismatches !");
- _ms[-meshDimRelToMax]->setGroupsFromScratch(ms,_families,_groups);
+ 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<MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception)
+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<MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception)
+DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception)
{
- return 0;
+ 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 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);
+ }
}
int getNumberOfLevels() const { return _ms.size(); }
int getNumberOfNonEmptyLevels() const;
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 meshDimRelToMax, const char *grp, bool renum=true) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getGroupArr(int meshDimRelToMax, const char *grp, bool renum=true) const throw(INTERP_KERNEL::Exception);
- MEDCouplingUMesh *getGroups(int meshDimRelToMax, const std::vector<std::string>& grps, bool renum=true) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getGroupsArr(int meshDimRelToMax, const std::vector<std::string>& grps, bool renum=true) const throw(INTERP_KERNEL::Exception);
- MEDCouplingUMesh *getFamily(int meshDimRelToMax, const char *fam, bool renum=true) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getFamilyArr(int meshDimRelToMax, const char *fam, bool renum=true) const throw(INTERP_KERNEL::Exception);
- MEDCouplingUMesh *getFamilies(int meshDimRelToMax, const std::vector<std::string>& fams, bool renum=true) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getFamiliesArr(int meshDimRelToMax, const std::vector<std::string>& fams, bool renum=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=true) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=true) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getFamily(int meshDimRelToMaxExt, const char *fam, bool renum=true) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=true) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=true) const throw(INTERP_KERNEL::Exception);
DataArrayInt *getNodeGroupArr(const char *grp, bool renum=true) const throw(INTERP_KERNEL::Exception);
DataArrayInt *getNodeGroupsArr(const std::vector<std::string>& grps, bool renum=true) const throw(INTERP_KERNEL::Exception);
DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=true) const throw(INTERP_KERNEL::Exception);
DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum=true) const throw(INTERP_KERNEL::Exception);
- MEDCouplingUMesh *getMeshAtRank(int meshDimRelToMax, bool renum=true) const throw(INTERP_KERNEL::Exception);
- MEDCouplingUMesh *getRank0Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception);
- MEDCouplingUMesh *getRankM1Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception);
- MEDCouplingUMesh *getRankM2Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception);
- MEDCouplingUMesh *getRankM3Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getMeshAtLevel(int meshDimRelToMaxExt, bool renum=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevel0Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevelM1Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevelM2Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevelM3Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception);
+ bool existsFamily(int famId) const;
+ bool existsFamily(const char *familyName) const;
//
void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception);
void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
- void addNodeGroup(const std::vector<int>& ids) throw(INTERP_KERNEL::Exception);
- void setMeshAtRank(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception);
- void setGroupsFromScratch(int meshDimRelToMax, const std::vector<MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception);
- void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception);
+ void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum=true) 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=true) 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 meshDimRelToMax) const 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<MEDCouplingUMesh *>& ms) 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;
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
+ mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_coords;
int _too_long_str;
+ int _zipconn_pol;
};
}
}
-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)
+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++)
{
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,0);//tony too long
+ 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,0);//tony too long
+ MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_TAILLE_NOM,famName,tooLongStrPol);
MEDfamCr(fid,(char *)mname,famName,(*it).second,0,0,0,0,groName,ngro);
}
}
if(v.empty())
return;
int sz=v.size();
- std::vector<MEDCouplingUMesh *> ms(sz);
+ std::vector<const MEDCouplingUMesh *> ms(sz);
for(int i=0;i<sz;i++)
{
MEDCouplingUMesh *tmp=MEDCouplingUMesh::New("",v[i]->getDim());
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=MEDCouplingUMesh::MergeUMeshesOnSameCoords(ms);
_m_by_types->setName(mName);
if(l2.isFamDefinedOnLev(id))
{
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();
_m=(MEDCouplingUMesh *)_m_by_types->deepCpy();
_m->renumberCells(_num->getConstPointer(),true);
}
else
_m=_m_by_types;
for(int i=0;i<sz;i++)
- ms[i]->decrRef();
+ (const_cast<MEDCouplingUMesh *>(ms[i]))->decrRef();//const cast under control to avoid a copy of array
}
MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m)
{
- m->incrRef();
- _m=m;
- _m_by_types=(MEDCouplingUMesh *)_m->deepCpy();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
- _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
+ assignMesh(m,true);
+}
+
+MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld)
+{
+ 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());
+ 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);
- _m_by_types->renumberCells(da->getConstPointer(),false);
}
bool MEDFileUMeshSplitL1::empty() 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);
DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const std::vector<int>& ids, bool renum) const
{
- DataArrayInt *da=_fam->getIdsEqualList(ids);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam->getIdsEqualList(ids);
if(renum)
return renumIfNeededArr(da);
+ da->incrRef();
return da;
}
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<MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
+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);
+ _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
std::vector< std::vector<int> > fidsOfGroups;
- _fam=DataArrayInt::makePartition(corr,_m->getNumberOfCells(),fidsOfGroups);
+ std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
+ _fam=DataArrayInt::MakePartition(corr2,_m->getNumberOfCells(),fidsOfGroups);
int nbOfCells=_m->getNumberOfCells();
std::map<int,std::string> newfams;
std::map<int,int> famIdTrad;
}
}
-MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
+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((const DataArrayInt *)_num==0)
+ if(renum==0)
return m;
if(cellIds==0)
- m->renumberCells(_num->getConstPointer(),true);
+ m->renumberCells(renum->getConstPointer(),true);
else
{
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=_num->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
m->renumberCells(locnum->getConstPointer(),true);
}
return m;
}
-DataArrayInt *MEDFileUMeshSplitL1::renumber(const DataArrayInt *renum, DataArrayInt *da)
+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)
- return da;
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
- da->decrRef();
- locnum->incrRef();
- return locnum;
+ {
+ da->incrRef();
+ return const_cast<DataArrayInt *>(da);
+ }
+ return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
}
-DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(DataArrayInt *da) const
+DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
{
- return renumber(_num,da);
+ return Renumber(_num,da);
}
std::vector<int> MEDFileUMeshSplitL1::getNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
std::set<int> allfids;
}
+
+void MEDFileUMeshSplitL1::computeRevNum() const
+{
+ int pos;
+ int maxValue=_num->getMaxValue(pos);
+ _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
+}
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);
+ 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();
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;
- void setGroupsFromScratch(const std::vector<MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
+ 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, DataArrayInt *da);
+ 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(DataArrayInt *da) 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;
MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
};
}
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,
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);
}
* 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++)
+ 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++)
+ 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());
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);
vec=[0.,1.,0.]
pt=[0.,0.,0.]
m1d.rotate(pt,vec,-pi/2.);
- ret=m3dsurf.buildExtrudedMeshFromThis(m1d,0);
+ ret=m3dsurf.buildExtrudedMesh(m1d,0);
return ret;
def buildVecFieldOnCells_1(cls):
return ret;
}
-static std::vector<ParaMEDMEM::MEDCouplingUMesh *> convertFieldDoubleVecFromPy(PyObject *pyLi)
+static std::vector<const ParaMEDMEM::MEDCouplingUMesh *> convertUMeshVecFromPy(PyObject *pyLi)
{
- std::vector<ParaMEDMEM::MEDCouplingUMesh *> ret;
+ std::vector<const ParaMEDMEM::MEDCouplingUMesh *> ret;
if(PyList_Check(pyLi))
{
int size=PyList_Size(pyLi);
mesh4->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
mesh4->finishInsertingCells();
mesh4->setCoords(mesh1->getCoords());
- std::vector<MEDCouplingUMesh *> meshes;
+ std::vector<const MEDCouplingUMesh *> meshes;
meshes.push_back(mesh1);
meshes.push_back(mesh2);
meshes.push_back(mesh3);
const double vec[3]={0.,1.,0.};
const double pt[3]={0.,0.,0.};
m1d->rotate(pt,vec,-M_PI/2.);
- MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMeshFromThis(m1d,0);
+ MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMesh(m1d,0);
m1d->decrRef();
m3dsurf->decrRef();
return ret;