From ea284ee6918dbd0a0691e1f48a301179c38516c6 Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 3 Dec 2010 11:11:16 +0000 Subject: [PATCH] *** empty log message *** --- .../MEDCouplingFieldDiscretization.cxx | 37 +++++++++++++++++++ .../MEDCouplingFieldDiscretization.hxx | 6 +++ src/MEDCoupling/MEDCouplingFieldDouble.cxx | 21 +++++++++++ src/MEDCoupling/MEDCouplingFieldDouble.hxx | 1 + src/MEDCoupling/MEDCouplingUMesh.cxx | 2 + .../Test/MEDCouplingBasicsTest2.cxx | 29 +++++++++++++++ src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 24 ++++++++++++ src/MEDCoupling_Swig/libMEDCoupling_Swig.i | 1 + 8 files changed, 121 insertions(+) diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index dfa7049cc..e5ad06173 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -288,6 +288,21 @@ void MEDCouplingFieldDiscretization::renumberEntitiesFromO2NArr(const int *old2N arrCpy->decrRef(); } +void MEDCouplingFieldDiscretization::renumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg) +{ + int nbOfComp=arr->getNumberOfComponents(); + DataArrayDouble *arrCpy=arr->deepCopy(); + const double *ptSrc=arrCpy->getConstPointer(); + arr->reAlloc(new2OldSz); + double *ptToFill=arr->getPointer(); + for(int i=0;idecrRef(); +} + MEDCouplingFieldDiscretization::~MEDCouplingFieldDiscretization() { } @@ -395,6 +410,11 @@ void MEDCouplingFieldDiscretizationP0::renumberValuesOnCells(const MEDCouplingMe renumberEntitiesFromO2NArr(old2New,arr,"Cell"); } +void MEDCouplingFieldDiscretizationP0::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const +{ + renumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell"); +} + /*! * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end). * @param di is an array returned that specifies entity ids (here cells ids) in mesh 'mesh' of entity in returned submesh. @@ -531,6 +551,13 @@ void MEDCouplingFieldDiscretizationP1::renumberValuesOnCells(const MEDCouplingMe { } +/*! + * Nothing to do it's not a bug. + */ +void MEDCouplingFieldDiscretizationP1::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const +{ +} + /*! * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end). * @param di is an array returned that specifies entity ids (here nodes ids) in mesh 'mesh' of entity in returned submesh. @@ -881,6 +908,11 @@ void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCells(const MEDCouplin throw INTERP_KERNEL::Exception("Not implemented yet !"); } +void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const +{ + throw INTERP_KERNEL::Exception("Number of cells has changed and becomes higher with some cells that have been split ! Unable to conserve the Gauss field !"); +} + void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) { @@ -1180,6 +1212,11 @@ void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCells(const MEDCoupl throw INTERP_KERNEL::Exception("Not implemented yet !"); } +void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other):MEDCouplingFieldDiscretization(other) { } diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 316fa753d..ad629d3ed 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -68,6 +68,7 @@ namespace ParaMEDMEM virtual MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const = 0; virtual void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const = 0; virtual void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const = 0; + virtual void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const = 0; virtual void getSerializationIntArray(DataArrayInt *& arr) const; virtual void getTinySerializationIntInformation(std::vector& tinyInfo) const; virtual void getTinySerializationDbleInformation(std::vector& tinyInfo) const; @@ -88,6 +89,7 @@ namespace ParaMEDMEM protected: MEDCouplingFieldDiscretization(); static void renumberEntitiesFromO2NArr(const int *old2NewPtr, DataArrayDouble *arr, const char *msg); + static void renumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg); protected: double _precision; static const double DFLT_PRECISION; @@ -113,6 +115,7 @@ namespace ParaMEDMEM void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const; void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; + void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; public: static const char REPR[]; @@ -140,6 +143,7 @@ namespace ParaMEDMEM MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; + void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; public: static const char REPR[]; static const TypeOfField TYPE; @@ -195,6 +199,7 @@ namespace ParaMEDMEM MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; + void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; void setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); void setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, @@ -244,6 +249,7 @@ namespace ParaMEDMEM MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; + void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; protected: MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other); public: diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 8246d9569..60b5caab8 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -1083,6 +1083,27 @@ bool MEDCouplingFieldDouble::zipConnectivity(int compType) throw(INTERP_KERNEL:: return false; } +/*! + * This method applyies ParaMEDMEM::MEDCouplingUMesh::simplexize on 'this->_mesh'. + * The semantic of 'policy' is given in ParaMEDMEM::MEDCouplingUMesh::simplexize method. + */ +bool MEDCouplingFieldDouble::simplexize(int policy) throw(INTERP_KERNEL::Exception) +{ + int oldNbOfCells=_mesh->getNumberOfCells(); + MEDCouplingAutoRefCountObjectPtr meshC2(_mesh->deepCpy()); + MEDCouplingAutoRefCountObjectPtr arr=meshC2->simplexize(policy); + int newNbOfCells=meshC2->getNumberOfCells(); + if(oldNbOfCells==newNbOfCells) + return false; + std::vector arrays; + _time_discr->getArrays(arrays); + for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) + if(*iter) + _type->renumberValuesOnCellsR(_mesh,arr->getConstPointer(),arr->getNbOfElems(),*iter); + setMesh(meshC2); + return true; +} + MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception) { MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct(); diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index bcbc385de..19f804c31 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -114,6 +114,7 @@ namespace ParaMEDMEM bool mergeNodes(double eps) throw(INTERP_KERNEL::Exception); bool zipCoords() throw(INTERP_KERNEL::Exception); bool zipConnectivity(int compType) throw(INTERP_KERNEL::Exception); + bool simplexize(int policy) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *determinant() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *eigenValues() const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index abba9dd6e..2fb724a8d 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -2470,6 +2470,7 @@ DataArrayInt *MEDCouplingUMesh::simplexizePol0() throw(INTERP_KERNEL::Exception) _nodal_connec_index->decrRef(); _nodal_connec_index=newConnI; computeTypes(); + updateTime(); return ret; } @@ -2525,6 +2526,7 @@ DataArrayInt *MEDCouplingUMesh::simplexizePol1() throw(INTERP_KERNEL::Exception) _nodal_connec_index->decrRef(); _nodal_connec_index=newConnI; computeTypes(); + updateTime(); return ret; } diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index 271ba57a8..2b2f4de2a 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -3589,3 +3589,32 @@ void MEDCouplingBasicsTest::testSimplexize1() da->decrRef(); m->decrRef(); } + +void MEDCouplingBasicsTest::testSimplexize2() +{ + MEDCouplingUMesh *m=build3DSurfTargetMesh_1(); + std::vector v(1); + v[0]=3; + m->convertToPolyTypes(v); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setMesh(m); + DataArrayDouble *arr=DataArrayDouble::New(); + const double arr1[10]={10.,110.,20.,120.,30.,130.,40.,140.,50.,150.}; + arr->alloc(5,2); + std::copy(arr1,arr1+10,arr->getPointer()); + f1->setArray(arr); + arr->decrRef(); + // + f1->checkCoherency(); + CPPUNIT_ASSERT(f1->simplexize(0)); + f1->checkCoherency(); + const double expected1[14]={10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.}; + for(int i=0;i<14;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10); + CPPUNIT_ASSERT(!f1->simplexize(0)); + for(int i=0;i<14;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10); + // + f1->decrRef(); + m->decrRef(); +} diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index eac14333e..25119adda 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -5141,6 +5141,30 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertAlmostEqual(expected1[i]*sqrt(2.),f.getIJ(i,0),10); pass pass + + def testSimplexize2(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + m.convertToPolyTypes([3]); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setMesh(m); + arr=DataArrayDouble.New(); + arr1=[10.,110.,20.,120.,30.,130.,40.,140.,50.,150.] + arr.setValues(arr1,5,2); + f1.setArray(arr); + # + f1.checkCoherency(); + self.assertTrue(f1.simplexize(0)); + f1.checkCoherency(); + expected1=[10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.] + for i in xrange(14): + self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10); + pass + self.assertTrue(not f1.simplexize(0)); + for i in xrange(14): + self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10); + pass + # + pass def setUp(self): pass diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i index 179563ff6..65112f642 100644 --- a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i +++ b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i @@ -1289,6 +1289,7 @@ namespace ParaMEDMEM bool mergeNodes(double eps) throw(INTERP_KERNEL::Exception); bool zipCoords() throw(INTERP_KERNEL::Exception); bool zipConnectivity(int compType) throw(INTERP_KERNEL::Exception); + bool simplexize(int policy) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *determinant() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *eigenValues() const throw(INTERP_KERNEL::Exception); -- 2.39.2