From 3a82b21de1abe1f79c52d6240557331815ba8a86 Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 15 Dec 2010 18:05:23 +0000 Subject: [PATCH] *** empty log message *** --- src/MEDCoupling/MEDCouplingMemArray.cxx | 11 +++ src/MEDCoupling/MEDCouplingMemArray.hxx | 2 + src/MEDCoupling_Swig/MEDCoupling.i | 6 ++ src/MEDCoupling_Swig/MEDCouplingTypemaps.i | 10 +++ src/MEDLoader/MEDFileMesh.cxx | 99 +++++++++++++++++++++- src/MEDLoader/MEDFileMesh.hxx | 10 ++- src/MEDLoader/MEDFileMeshLL.cxx | 10 +++ src/MEDLoader/MEDFileMeshLL.hxx | 2 + 8 files changed, 148 insertions(+), 2 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index bfa00a713..d0596e339 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -2264,6 +2264,17 @@ DataArrayInt *DataArrayInt::deltaShiftIndex() const throw(INTERP_KERNEL::Excepti return ret; } +/*! + * This method returns all different values found in 'this'. + */ +std::set DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + std::set ret; + ret.insert(getConstPointer(),getConstPointer()+getNbOfElems()); + return ret; +} + int *DataArrayInt::checkAndPreparePermutation(const int *start, const int *end) { int sz=std::distance(start,end); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index fe0f3d8fc..c3259e03b 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -25,6 +25,7 @@ #include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" +#include #include #include #include @@ -275,6 +276,7 @@ namespace ParaMEDMEM 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 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. diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index bd30c4516..32dd28f1a 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -1160,6 +1160,12 @@ namespace ParaMEDMEM return self->repr(); } + PyObject *getDifferentValues(bool val) const throw(INTERP_KERNEL::Exception) + { + std::set ret=self->getDifferentValues(); + return convertIntArrToPyList3(ret); + } + void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple) throw(INTERP_KERNEL::Exception) { int size; diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index 04254c96d..9e884c118 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -70,6 +70,16 @@ static PyObject *convertIntArrToPyList2(const std::vector& v) throw(INTERP_ #endif } +static PyObject *convertIntArrToPyList3(const std::set& v) throw(INTERP_KERNEL::Exception) +{ + int size=v.size(); + PyObject *ret=PyList_New(size); + std::set::const_iterator it=v.begin(); + for(int i=0;i MEDFileUMesh::getNonEmptyLevels() const return ret; } +std::vector MEDFileUMesh::getNonEmptyLevelsExt() const +{ + std::vector ret0=getNonEmptyLevels(); + if((const DataArrayDouble *) _coords) + { + std::vector 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); @@ -186,6 +199,30 @@ int MEDFileUMesh::getMeshDimension() const 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 MEDFileUMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception) { std::string oname(name); @@ -467,6 +504,16 @@ const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMax) c 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()) @@ -494,7 +541,57 @@ void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Excep _fam_coords->fillWithZero(); } -void MEDFileUMesh::addNodeGroup(const std::vector& ids) throw(INTERP_KERNEL::Exception) +void MEDFileUMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps, bool renum) throw(INTERP_KERNEL::Exception) +{ + if(grps.empty()) + return ; + std::set grpsName; + for(std::vector::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 levs=getNonEmptyLevelsExt(); + std::set allFamsIds; + for(std::vector::const_iterator it=levs.begin();it!=levs.end();it++) + { + const DataArrayInt *ffield=getFamilyFieldAtLevel(*it); + std::set ids=ffield->getDifferentValues(); + std::set 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& grpNames) throw(INTERP_KERNEL::Exception) +{ + +} + +void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception) { const DataArrayDouble *coords=_coords; if(!coords) diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index add1d30a2..d5378c57f 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -62,10 +62,13 @@ namespace ParaMEDMEM std::vector getFamiliesIds(const std::vector& 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 getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); std::vector getGroupsNames() const; std::vector getFamiliesNames() const; std::vector getNonEmptyLevels() const; + std::vector 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); @@ -87,14 +90,19 @@ namespace ParaMEDMEM // 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& ids) throw(INTERP_KERNEL::Exception); + void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& 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& grpNames) throw(INTERP_KERNEL::Exception); + void addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception); void setMeshAtRank(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); + 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& ms) const throw(INTERP_KERNEL::Exception); private: diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 23060b3dc..15992005f 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -326,6 +326,16 @@ MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const return tmp; } +const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const +{ + return _fam; +} + +void MEDFileUMeshSplitL1::eraseFamilyField() +{ + _fam->fillWithZero(); +} + /*! * This method ignores _m and _m_by_types. */ diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 5211468eb..57ecb634a 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -89,6 +89,8 @@ namespace ParaMEDMEM MEDCouplingUMesh *getFamilyPart(const std::vector& ids, bool renum) const; DataArrayInt *getFamilyPartArr(const std::vector& ids, bool renum) const; MEDCouplingUMesh *getWholeMesh(bool renum) const; + const DataArrayInt *getFamilyField() const; + void eraseFamilyField(); void setGroupsFromScratch(const std::vector& ms, std::map& familyIds, std::map >& groups) throw(INTERP_KERNEL::Exception); void write(med_idt fid, const char *mName, int mdim) const; -- 2.39.2