]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
More accurate advancedRepr method with fields on Gauss points.
authorageay <ageay>
Thu, 23 Feb 2012 16:00:18 +0000 (16:00 +0000)
committerageay <ageay>
Thu, 23 Feb 2012 16:00:18 +0000 (16:00 +0000)
src/MEDCoupling/MEDCouplingFieldDiscretization.cxx
src/MEDCoupling/MEDCouplingFieldDiscretization.hxx
src/MEDCoupling/MEDCouplingGaussLocalization.cxx
src/MEDCoupling/MEDCouplingGaussLocalization.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 91219d31c2cd806642c93cf93a84d7b7d2c560a2..f2c0ae09d1af130d7db4a4c84480581e3132c14f 100644 (file)
@@ -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<int>(oss,", "));
+          oss << std::endl;
+        }
+    }
+  oss << "Presence of " << _loc.size() << " localizations." << std::endl;
+  int i=0;
+  for(std::vector<MEDCouplingGaussLocalization>::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
index 240619acd375221d17e6ffbb34afaaf6835995f0..93ca1478b7dc3ba71ad9f935685e2d2951599ea1 100644 (file)
@@ -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;
index 4adfeb235e2c6a481f00946cb4e1cd47c1bd024f..dfeb5f1f3610f8e391995fe3f39b1cf0288ae02c 100644 (file)
@@ -23,6 +23,7 @@
 #include <cmath>
 #include <numeric>
 #include <sstream>
+#include <iterator>
 #include <algorithm>
 
 ParaMEDMEM::MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& 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<double>(oss,", ")); oss << std::endl;
+  oss << "Localization coords : "; std::copy(_gauss_coord.begin(),_gauss_coord.end(),std::ostream_iterator<double>(oss,", ")); oss << std::endl;
+  oss << "Weight : "; std::copy(_weight.begin(),_weight.end(),std::ostream_iterator<double>(oss,", ")); oss << std::endl;
+  return oss.str();
+}
+
 bool ParaMEDMEM::MEDCouplingGaussLocalization::isEqual(const MEDCouplingGaussLocalization& other, double eps) const
 {
   if(_type!=other._type)
index 570bd4d56b7ba0cdec258c842dc459bbd34e9f94..1e275d024722605f0d354ec8a1c05d1069c55657 100644 (file)
@@ -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<int>& tinyInfo) const;
index 3ea07c2a28cf1548e52251033cfbc89d6af06e7b..a324e1f2f5239c4b53fca0d92691306180c52e91 100644 (file)
@@ -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();
+}
index a20c1da191f1edfeb237cbc601eefb2995849ac9..e7ec0077eba1f2ac28524bcfcde142172feee7d1 100644 (file)
@@ -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();
   };
 }
 
index 77ffeed3a14aa3d7b3b2171ef8d2cba7e3c39907..539c57775321b970f6eb990a5f54d060ba602e84 100644 (file)
@@ -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