return ret;
}
+/*!
+ * This method returns all different values found in 'this'.
+ */
+std::set<int> DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exception)
+{
+ checkAllocated();
+ std::set<int> ret;
+ ret.insert(getConstPointer(),getConstPointer()+getNbOfElems());
+ return ret;
+}
+
int *DataArrayInt::checkAndPreparePermutation(const int *start, const int *end)
{
int sz=std::distance(start,end);
#include "MEDCouplingRefCountObject.hxx"
#include "InterpKernelException.hxx"
+#include <set>
#include <string>
#include <vector>
#include <iterator>
MEDCOUPLING_EXPORT DataArrayInt *buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT std::set<int> getDifferentValues() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
//! nothing to do here because this class does not aggregate any TimeLabel instance.
return self->repr();
}
+ PyObject *getDifferentValues(bool val) const throw(INTERP_KERNEL::Exception)
+ {
+ std::set<int> ret=self->getDifferentValues();
+ return convertIntArrToPyList3(ret);
+ }
+
void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple) throw(INTERP_KERNEL::Exception)
{
int size;
#endif
}
+static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
+{
+ int size=v.size();
+ PyObject *ret=PyList_New(size);
+ std::set<int>::const_iterator it=v.begin();
+ for(int i=0;i<size;i++,it++)
+ PyList_SetItem(ret,i,PyInt_FromLong(*it));
+ return ret;
+}
+
static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
{
PyObject *ret=PyList_New(nbOfTuples);
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);
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();
+ }
+ MEDCouplingUMesh *m=getMeshAtRank(meshDimRelToMaxExt,false);
+ return m->getNumberOfCells();
+}
+
+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();
+}
+
std::vector<std::string> MEDFileUMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
{
std::string oname(name);
return _ms[tracucedRk];
}
+MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
+{
+ int tracucedRk=-meshDimRelToMax;
+ if(tracucedRk>=(int)_ms.size())
+ throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
+ if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
+ throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
+ return _ms[tracucedRk];
+}
+
void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
{
if(-meshDimRelToMax>=(int)_ms.size())
_fam_coords->fillWithZero();
}
-void MEDFileUMesh::addNodeGroup(const std::vector<int>& ids) throw(INTERP_KERNEL::Exception)
+void MEDFileUMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<DataArrayInt *>& grps, bool renum) throw(INTERP_KERNEL::Exception)
+{
+ if(grps.empty())
+ return ;
+ std::set<std::string> grpsName;
+ for(std::vector<DataArrayInt *>::const_iterator it=grps.begin();it!=grps.end();it++)
+ grpsName.insert((*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);
+ if(!renum)
+ {
+
+ }*/
+}
+
+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;
+ }
+}
+
+void MEDFileUMesh::setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector<std::string>& grpNames) 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)
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);
std::vector<std::string> getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
std::vector<std::string> getGroupsNames() const;
std::vector<std::string> getFamiliesNames() const;
std::vector<int> getNonEmptyLevels() const;
+ 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);
//
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 setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<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) throw(INTERP_KERNEL::Exception);
+ void addNodeGroup(const std::string& name, 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 optimizeFamilies() 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);
+ MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMax) throw(INTERP_KERNEL::Exception);
void checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception);
DataArrayDouble *checkMultiMesh(const std::vector<MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception);
private:
return tmp;
}
+const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
+{
+ return _fam;
+}
+
+void MEDFileUMeshSplitL1::eraseFamilyField()
+{
+ _fam->fillWithZero();
+}
+
/*!
* This method ignores _m and _m_by_types.
*/
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;
+ void eraseFamilyField();
void setGroupsFromScratch(const std::vector<MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
void write(med_idt fid, const char *mName, int mdim) const;