From 0b5edc7fb6133cc5955b4dc5bc3351c0c7bd6709 Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 3 Dec 2010 17:24:10 +0000 Subject: [PATCH] *** empty log message *** --- .../Test/MEDCouplingBasicsTest.hxx | 4 + src/MEDLoader/MEDFileMesh.cxx | 177 +++++++++++++++++- src/MEDLoader/MEDFileMesh.hxx | 17 +- src/MEDLoader/MEDFileMeshLL.cxx | 60 ++++++ src/MEDLoader/MEDFileMeshLL.hxx | 7 + 5 files changed, 263 insertions(+), 2 deletions(-) diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 112c2a335..4982c2e7a 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -158,6 +158,8 @@ namespace ParaMEDMEM CPPUNIT_TEST( testExtrudedMesh5 ); CPPUNIT_TEST( testExtrudedMesh6 ); CPPUNIT_TEST( testExtrudedMesh7 ); + CPPUNIT_TEST( testSimplexize1 ); + CPPUNIT_TEST( testSimplexize2 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -344,6 +346,8 @@ namespace ParaMEDMEM void testExtrudedMesh5(); void testExtrudedMesh6(); void testExtrudedMesh7(); + void testSimplexize1(); + void testSimplexize2(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 2ec445339..196f350a4 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -67,7 +67,7 @@ MEDFileUMesh::~MEDFileUMesh() { } -void MEDFileUMesh::write(const char *fileName, int mode) const +void MEDFileUMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) { } @@ -92,6 +92,34 @@ std::vector MEDFileUMesh::getNonEmptyLevels() const return ret; } +int MEDFileUMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map::const_iterator it=_families.find(oname); + std::vector 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(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return (*it).second; +} + +std::vector MEDFileUMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map >::const_iterator it=_groups.find(oname); + std::vector 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(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return (*it).second; +} + std::vector MEDFileUMesh::getGroupsNames() const { std::vector ret(_groups.size()); @@ -110,6 +138,80 @@ std::vector MEDFileUMesh::getFamiliesNames() const return ret; } +void MEDFileUMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map >::iterator it=_groups.find(oname); + std::vector 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(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::iterator it=_families.find(oname); + std::vector 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(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 >::iterator it=_groups.find(oname); + std::vector 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(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 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::iterator it=_families.find(oname); + std::vector 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(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 tmp(_coords); @@ -208,3 +310,76 @@ const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMax) c 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 >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++) + { + if(((const MEDFileUMeshSplitL1*) (*it))!=0) + { + int ref=(*it)->getMeshDimension(); + if(ref+i!=meshDim+meshDimRelToMax) + throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : no coherency between levels !"); + } + } +} + +void MEDFileUMesh::setMeshAtRank(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception) +{ + std::vector levSet=getNonEmptyLevels(); + if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end()) + { + if((DataArrayDouble *)_coords==0) + { + DataArrayDouble *c=m->getCoords(); + if(c) + c->incrRef(); + _coords=c; + } + else + { + if(m->getCoords()!=_coords) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtRank : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !"); + int sz=(-meshDimRelToMax)+1; + if(sz>=(int)_ms.size()) + _ms.resize(sz); + checkMeshDimCoherency(m->getMeshDimension(),sz); + _ms[sz]=new MEDFileUMeshSplitL1(m); + } + } +} + +void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception) +{ + if(ms.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : expecting a non empty vector !"); + int sz=(-meshDimRelToMax)+1; + if(sz>=(int)_ms.size()) + _ms.resize(sz); + checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax); + DataArrayDouble *coo=checkMultiMesh(ms); + if((DataArrayDouble *)_coords==0) + { + coo->incrRef(); + _coords=coo; + } + else + if((DataArrayDouble *)_coords!=coo) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : coordinates mismatches !"); + _ms[-meshDimRelToMax]->setGroupsFromScratch(ms,_families,_groups); +} + +void MEDFileUMesh::setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception) +{ + if(ms.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : expecting a non empty vector !"); + +} + +DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector& ms) const throw(INTERP_KERNEL::Exception) +{ + return 0; +} diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index ecdd4a201..330240e7a 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -46,10 +46,19 @@ namespace ParaMEDMEM { public: static MEDFileUMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + static MEDFileUMesh *New(); ~MEDFileUMesh(); - void write(const char *fileName, int mode) const; + // + void removeGroup(const char *name) throw(INTERP_KERNEL::Exception); + void removeFamily(const char *name) throw(INTERP_KERNEL::Exception); + void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + // + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); int getNumberOfLevels() const { return _ms.size(); } int getNumberOfNonEmptyLevels() const; + int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); std::vector getGroupsNames() const; std::vector getFamiliesNames() const; std::vector getNonEmptyLevels() const; @@ -63,9 +72,15 @@ namespace ParaMEDMEM MEDCouplingUMesh *getRankM1Mesh() const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getRankM2Mesh() const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getRankM3Mesh() const throw(INTERP_KERNEL::Exception); + // + void setMeshAtRank(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); + void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); + void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); private: MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); const MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + void checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *checkMultiMesh(const std::vector& ms) const throw(INTERP_KERNEL::Exception); private: std::map > _groups; std::map _families; diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index ba819948c..52aad20e7 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -224,11 +224,29 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *m ms[i]->decrRef(); } +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m) +{ + m->incrRef(); + _m=m; + _m_by_types=(MEDCouplingUMesh *)_m->deepCpy(); + MEDCouplingAutoRefCountObjectPtr da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + _num=da->invertArrayO2N2N2O(m->getNumberOfCells()); + _fam=DataArrayInt::New(); + _fam->alloc(m->getNumberOfCells(),1); + _fam->fillWithValue(0); + _m_by_types->renumberCells(da->getConstPointer(),false); +} + bool MEDFileUMeshSplitL1::empty() const { return ((const MEDCouplingUMesh *)_m_by_types)==0; } +int MEDFileUMeshSplitL1::getMeshDimension() const +{ + return _m_by_types->getMeshDimension(); +} + MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const std::vector& ids) const { MEDCouplingAutoRefCountObjectPtr eltsToKeep=_fam->getIdsEqualList(ids); @@ -243,6 +261,28 @@ MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh() const return tmp; } +/*! + * This method ignores _m and _m_by_types. + */ +void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector& ms, std::map& familyIds, + std::map >& groups) throw(INTERP_KERNEL::Exception) +{ + int sz=ms.size(); + std::vector< DataArrayInt * > corr; + _m=MEDCouplingUMesh::fuseUMeshesOnSameCoords(ms,0,corr); + std::vector< std::vector > fidsOfGroups; + _fam=DataArrayInt::makePartition(corr,_m->getNumberOfCells(),fidsOfGroups); + int nbOfCells=_m->getNumberOfCells(); + std::map newfams; + std::map famIdTrad; + traduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams); + for(int i=0;idecrRef(); + int *w=_fam->getPointer(); + for(int i=0;i MEDFileUMeshSplitL1::getNewFamiliesNumber(int nb, const std::map& families) +{ + int id=-1; + for(std::map::const_iterator it=families.begin();it!=families.end();it++) + id=std::max(id,(*it).second); + if(id==-1) + id=0; + std::vector ret(nb); + for(int i=1;i<=nb;i++) + ret[i]=id+i; + return ret; +} + +void MEDFileUMeshSplitL1::traduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, + std::map& famIdTrad, std::map& newfams) +{ + std::set allfids; + +} diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 720a962ae..5988a03d4 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -77,9 +77,16 @@ namespace ParaMEDMEM { public: MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id); + MEDFileUMeshSplitL1(MEDCouplingUMesh *m); bool empty() const; + int getMeshDimension() const; MEDCouplingUMesh *getFamilyPart(const std::vector& ids) const; MEDCouplingUMesh *getWholeMesh() const; + void setGroupsFromScratch(const std::vector& ms, std::map& familyIds, + std::map >& groups) throw(INTERP_KERNEL::Exception); + static std::vector getNewFamiliesNumber(int nb, const std::map& families); + static void traduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, + std::map& famIdTrad, std::map& newfams); private: MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const; private: -- 2.39.2