From b8341c02eb995d20644af4cdd7a2b1463d5f87a1 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 23 Feb 2012 16:00:18 +0000 Subject: [PATCH] More accurate advancedRepr method with fields on Gauss points. --- .../MEDCouplingFieldDiscretization.cxx | 34 ++++++++++++---- .../MEDCouplingFieldDiscretization.hxx | 10 ++--- .../MEDCouplingGaussLocalization.cxx | 11 ++++++ .../MEDCouplingGaussLocalization.hxx | 1 + .../Test/MEDCouplingBasicsTest5.cxx | 39 +++++++++++++++++++ .../Test/MEDCouplingBasicsTest5.hxx | 2 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 27 +++++++++++++ 7 files changed, 111 insertions(+), 13 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 91219d31c..f2c0ae09d 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -337,9 +337,9 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP0::clone() const return new MEDCouplingFieldDiscretizationP0; } -const char *MEDCouplingFieldDiscretizationP0::getStringRepr() const +std::string MEDCouplingFieldDiscretizationP0::getStringRepr() const { - return REPR; + return std::string(REPR); } bool MEDCouplingFieldDiscretizationP0::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const @@ -497,9 +497,9 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP1::clone() const return new MEDCouplingFieldDiscretizationP1; } -const char *MEDCouplingFieldDiscretizationP1::getStringRepr() const +std::string MEDCouplingFieldDiscretizationP1::getStringRepr() const { - return REPR; + return std::string(REPR); } bool MEDCouplingFieldDiscretizationP1::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const @@ -824,9 +824,27 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clone() con return new MEDCouplingFieldDiscretizationGauss(*this); } -const char *MEDCouplingFieldDiscretizationGauss::getStringRepr() const +std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const { - return REPR; + std::ostringstream oss; oss << REPR << "." << std::endl; + if(_discr_per_cell) + { + if(_discr_per_cell->isAllocated()) + { + oss << "Discretization per cell : "; + std::copy(_discr_per_cell->begin(),_discr_per_cell->end(),std::ostream_iterator(oss,", ")); + oss << std::endl; + } + } + oss << "Presence of " << _loc.size() << " localizations." << std::endl; + int i=0; + for(std::vector::const_iterator it=_loc.begin();it!=_loc.end();it++,i++) + { + oss << "+++++ Localization #" << i << " +++++" << std::endl; + oss << (*it).getStringRepr(); + oss << "++++++++++" << std::endl; + } + return oss.str(); } int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *) const @@ -1350,9 +1368,9 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGaussNE::clone() c return new MEDCouplingFieldDiscretizationGaussNE(*this); } -const char *MEDCouplingFieldDiscretizationGaussNE::getStringRepr() const +std::string MEDCouplingFieldDiscretizationGaussNE::getStringRepr() const { - return REPR; + return std::string(REPR); } bool MEDCouplingFieldDiscretizationGaussNE::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 240619acd..93ca1478b 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -48,7 +48,7 @@ namespace ParaMEDMEM virtual bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const = 0; virtual bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; virtual MEDCouplingFieldDiscretization *clone() const = 0; - virtual const char *getStringRepr() const = 0; + virtual std::string getStringRepr() const = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const = 0; virtual int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const = 0; virtual DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const = 0; @@ -103,7 +103,7 @@ namespace ParaMEDMEM public: TypeOfField getEnum() const; MEDCouplingFieldDiscretization *clone() const; - const char *getStringRepr() const; + std::string getStringRepr() const; bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; @@ -133,7 +133,7 @@ namespace ParaMEDMEM public: TypeOfField getEnum() const; MEDCouplingFieldDiscretization *clone() const; - const char *getStringRepr() const; + std::string getStringRepr() const; bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; @@ -193,7 +193,7 @@ namespace ParaMEDMEM bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; MEDCouplingFieldDiscretization *clone() const; - const char *getStringRepr() const; + std::string getStringRepr() const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const; @@ -252,7 +252,7 @@ namespace ParaMEDMEM MEDCouplingFieldDiscretizationGaussNE(); TypeOfField getEnum() const; MEDCouplingFieldDiscretization *clone() const; - const char *getStringRepr() const; + std::string getStringRepr() const; bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx index 4adfeb235..dfeb5f1f3 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include ParaMEDMEM::MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, @@ -75,6 +76,16 @@ int ParaMEDMEM::MEDCouplingGaussLocalization::getNumberOfPtsInRefCell() const return (int)_ref_coord.size()/dim; } +std::string ParaMEDMEM::MEDCouplingGaussLocalization::getStringRepr() const +{ + std::ostringstream oss; + oss << "CellType : " << INTERP_KERNEL::CellModel::GetCellModel(_type).getRepr() << std::endl; + oss << "Ref coords : "; std::copy(_ref_coord.begin(),_ref_coord.end(),std::ostream_iterator(oss,", ")); oss << std::endl; + oss << "Localization coords : "; std::copy(_gauss_coord.begin(),_gauss_coord.end(),std::ostream_iterator(oss,", ")); oss << std::endl; + oss << "Weight : "; std::copy(_weight.begin(),_weight.end(),std::ostream_iterator(oss,", ")); oss << std::endl; + return oss.str(); +} + bool ParaMEDMEM::MEDCouplingGaussLocalization::isEqual(const MEDCouplingGaussLocalization& other, double eps) const { if(_type!=other._type) diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.hxx b/src/MEDCoupling/MEDCouplingGaussLocalization.hxx index 570bd4d56..1e275d024 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.hxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.hxx @@ -39,6 +39,7 @@ namespace ParaMEDMEM int getNumberOfGaussPt() const { return (int)_weight.size(); } int getDimension() const; int getNumberOfPtsInRefCell() const; + std::string getStringRepr() const; void checkCoherency() const throw(INTERP_KERNEL::Exception); bool isEqual(const MEDCouplingGaussLocalization& other, double eps) const; void pushTinySerializationIntInfo(std::vector& tinyInfo) const; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx index 3ea07c2a2..a324e1f2f 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx @@ -492,3 +492,42 @@ void MEDCouplingBasicsTest5::testDataArrayIntAdvSetting1() da2->decrRef(); da->decrRef(); } + +void MEDCouplingBasicsTest5::testBuildDescendingConnec2Of3DMesh1() +{ + MEDCouplingUMesh *mesh=build3DSourceMesh_1(); + DataArrayInt *desc=DataArrayInt::New(); + DataArrayInt *descIndx=DataArrayInt::New(); + DataArrayInt *revDesc=DataArrayInt::New(); + DataArrayInt *revDescIndx=DataArrayInt::New(); + // + MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity2(desc,descIndx,revDesc,revDescIndx); + mesh2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension()); + CPPUNIT_ASSERT_EQUAL(30,mesh2->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(31,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(31,revDescIndx->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(13,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(13,descIndx->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples()); + const int expected1[48]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,-10,15,-5,-13,16,17,-14,18,-4,19,-2,20,21,22,23,24,25,-11,26,-1,-12,-25,-22,27,28,-7,-20,-24,29,-16,-18,30,-8,-28}; + CPPUNIT_ASSERT(std::equal(expected1,expected1+48,desc->getConstPointer())); + const int expected2[13]={0,4,8,12,16,20,24,28,32,36,40,44,48}; + CPPUNIT_ASSERT(std::equal(expected2,expected2+13,descIndx->getConstPointer())); + const int expected3[31]={0,2,4,5,7,9,10,12,14,15,17,19,21,23,25,26,28,29,31,32,34,35,37,38,40,42,43,44,46,47,48}; + CPPUNIT_ASSERT(std::equal(expected3,expected3+31,revDescIndx->getConstPointer())); + const int expected4[48]={0,8,0,6,0,0,5,1,4,1,1,9,1,11,2,2,3,2,7,2,8,3,4,3,5,3,4,10,4,5,11,5,6,10,6,6,9,7,7,10,7,8,8,9,9,11,10,11}; + CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer())); + DataArrayInt *conn=mesh2->getNodalConnectivity(); + DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex(); + const int expected5[31]={0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120}; + CPPUNIT_ASSERT(std::equal(expected5,expected5+31,connIndex->getConstPointer())); + const int expected6[120]={3,8,1,7,3,8,3,1,3,1,3,7,3,7,3,8,3,6,0,8,3,6,2,0,3,0,2,8,3,8,2,6,3,7,4,5,3,7,8,4,3,4,8,5,3,5,8,7,3,6,8,4,3,6,7,8,3,4,7,6,3,8,4,0,3,0,4,6,3,6,3,8,3,7,3,6,3,8,0,1,3,1,0,3,3,3,0,8,3,4,1,5,3,4,8,1,3,1,8,5,3,1,7,5,3,0,2,3,3,3,2,8,3,1,4,0,3,3,2,6}; + CPPUNIT_ASSERT(std::equal(expected6,expected6+120,conn->getConstPointer())); + // + desc->decrRef(); + descIndx->decrRef(); + revDesc->decrRef(); + revDescIndx->decrRef(); + mesh2->decrRef(); + mesh->decrRef(); +} diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx index a20c1da19..e7ec0077e 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx @@ -42,6 +42,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testBuildSlice3DSurf1 ); CPPUNIT_TEST( testDataArrayDoubleAdvSetting1 ); CPPUNIT_TEST( testDataArrayIntAdvSetting1 ); + CPPUNIT_TEST( testBuildDescendingConnec2Of3DMesh1 ); CPPUNIT_TEST_SUITE_END(); public: void testUMeshTessellate2D1(); @@ -51,6 +52,7 @@ namespace ParaMEDMEM void testBuildSlice3DSurf1(); void testDataArrayDoubleAdvSetting1(); void testDataArrayIntAdvSetting1(); + void testBuildDescendingConnec2Of3DMesh1(); }; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 77ffeed3a..539c57775 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -8881,6 +8881,33 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected6[i],dac.getIJ(0,i)); pass pass + + def testBuildDescendingConnec2Of3DMesh1(self): + mesh=MEDCouplingDataForTest.build3DSourceMesh_1(); + # + mesh2,desc,descIndx,revDesc,revDescIndx=mesh.buildDescendingConnectivity2(); + mesh2.checkCoherency(); + self.assertEqual(2,mesh2.getMeshDimension()); + self.assertEqual(30,mesh2.getNumberOfCells()); + self.assertEqual(31,revDescIndx.getNbOfElems()); self.assertEqual(31,revDescIndx.getNumberOfTuples()); + self.assertEqual(13,descIndx.getNbOfElems()); self.assertEqual(13,descIndx.getNumberOfTuples()); + self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples()); + self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples()); + expected1=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,-10,15,-5,-13,16,17,-14,18,-4,19,-2,20,21,22,23,24,25,-11,26,-1,-12,-25,-22,27,28,-7,-20,-24,29,-16,-18,30,-8,-28] + self.assertEqual(expected1,desc.getValues()); + expected2=[0,4,8,12,16,20,24,28,32,36,40,44,48] + self.assertEqual(expected2,descIndx.getValues()); + expected3=[0,2,4,5,7,9,10,12,14,15,17,19,21,23,25,26,28,29,31,32,34,35,37,38,40,42,43,44,46,47,48] + self.assertEqual(expected3,revDescIndx.getValues()); + expected4=[0,8,0,6,0,0,5,1,4,1,1,9,1,11,2,2,3,2,7,2,8,3,4,3,5,3,4,10,4,5,11,5,6,10,6,6,9,7,7,10,7,8,8,9,9,11,10,11] + self.assertEqual(expected4,revDesc.getValues()); + conn=mesh2.getNodalConnectivity(); + connIndex=mesh2.getNodalConnectivityIndex(); + expected5=[0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120] + self.assertEqual(expected5,connIndex.getValues()); + expected6=[3,8,1,7,3,8,3,1,3,1,3,7,3,7,3,8,3,6,0,8,3,6,2,0,3,0,2,8,3,8,2,6,3,7,4,5,3,7,8,4,3,4,8,5,3,5,8,7,3,6,8,4,3,6,7,8,3,4,7,6,3,8,4,0,3,0,4,6,3,6,3,8,3,7,3,6,3,8,0,1,3,1,0,3,3,3,0,8,3,4,1,5,3,4,8,1,3,1,8,5,3,1,7,5,3,0,2,3,3,3,2,8,3,1,4,0,3,3,2,6] + self.assertEqual(expected6,conn.getValues()); + pass def setUp(self): pass -- 2.39.2