]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Bug correction into MEDCouplingUMesh::getMeasureFieldOnNode on non simplex cells...
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 15 Jan 2019 08:48:28 +0000 (09:48 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 15 Jan 2019 08:48:28 +0000 (09:48 +0100)
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py
src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py

index 0e1258aa705e26fb07fc97b83a8b73d6ff0ceaf0..cce5fe0bfb82e3ab1a51592340d9efbb023aea4e 100644 (file)
@@ -3306,8 +3306,14 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureFieldOnNode(bool isAbs) cons
   std::string name="MeasureOnNodeOfMesh_";
   name+=getName();
   int nbNodes=getNumberOfNodes();
+  MCAuto<DataArrayDouble> nnpc;
+  {
+    MCAuto<DataArrayInt> tmp(computeNbOfNodesPerCell());
+    nnpc=tmp->convertToDblArr();
+  }
+  std::for_each(nnpc->rwBegin(),nnpc->rwEnd(),[](double& v) { v=1./v; });
+  const double *nnpcPtr(nnpc->begin());
   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(ON_NODES);
-  double cst=1./((double)getMeshDimension()+1.);
   MCAuto<DataArrayDouble> array=DataArrayDouble::New();
   array->alloc(nbNodes,1);
   double *valsToFill=array->getPointer();
@@ -3320,7 +3326,7 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureFieldOnNode(bool isAbs) cons
   const int *daIPtr=daInd->getConstPointer();
   for(int i=0;i<nbNodes;i++)
     for(const int *cell=daPtr+daIPtr[i];cell!=daPtr+daIPtr[i+1];cell++)
-      valsToFill[i]+=cst*values[*cell];
+      valsToFill[i]+=nnpcPtr[*cell]*values[*cell];
   ret->setMesh(this);
   ret->setArray(array);
   return ret.retn();
index 4e859d3225f69168f53e482843643b9e08640f58..e09ca0e77925fd3290da093261810cb759a7106d 100644 (file)
@@ -1474,8 +1474,9 @@ void MEDCouplingBasicsTest1::testFillFromAnalytic()
   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
   f1->integral(true,values4);
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
+  //0.4 == 0.25/4*-0.6+(0.25/4+0.125/3)*-0.1+0.4*(0.125/3.+0.125/3)+(-0.1)*(0.25/4+0.25/4)+0.4*(0.25/4+0.125/3+0.125/3+0.25/4+0.25/4)+0.9*(0.25/4+0.125/3)+0.4*0.25/4+0.9*(0.25/4+0.25/4)+1.4*0.25/4
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.4,values4[0],1.e-12);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8,values4[1],1.e-12);
   f1->decrRef();
   //
   CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
@@ -1544,8 +1545,8 @@ void MEDCouplingBasicsTest1::testFillFromAnalytic2()
   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
   f1->integral(true,values4);
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.4,values4[0],1.e-12);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8,values4[1],1.e-12);
   f1->decrRef();
   //
   CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
index e7d48150ce1b6eb1f43d3156e1676a7dc3fca66b..564c0b52acddb8af7a66067c3d97a4e5f80d2d13 100644 (file)
@@ -2141,8 +2141,8 @@ void MEDCouplingBasicsTest2::testFillFromAnalytic3()
   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
   f1->integral(true,values4);
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.4,values4[0],1.e-12);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8,values4[1],1.e-12);
   f1->decrRef();
   //
   f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
index ae07b6d34464c5997133b83b26d69f62b672d2dc..92298fe33c7f5a6d344b0d3e328d59cf685e8259 100644 (file)
@@ -1094,9 +1094,10 @@ class MEDCouplingBasicsTest1(unittest.TestCase):
         self.assertTrue(abs(3.6-values4[0])<1.e-12);
         self.assertTrue(abs(7.2-values4[1])<1.e-12);
         values4=f1.integral(True);
+        #0.4 == 0.25/4*-0.6+(0.25/4+0.125/3)*-0.1+0.4*(0.125/3.+0.125/3)+(-0.1)*(0.25/4+0.25/4)+0.4*(0.25/4+0.125/3+0.125/3+0.25/4+0.25/4)+0.9*(0.25/4+0.125/3)+0.4*0.25/4+0.9*(0.25/4+0.25/4)+1.4*0.25/4
         self.assertEqual(2,len(values4))
-        self.assertTrue(abs(0.5-values4[0])<1.e-12);
-        self.assertTrue(abs(1.-values4[1])<1.e-12);
+        self.assertTrue(abs(0.4-values4[0])<1.e-12);
+        self.assertTrue(abs(0.8-values4[1])<1.e-12);
         #
         self.assertRaises(InterpKernelException,m.fillFromAnalytic,ON_NODES,1,"1./(x-0.2)");
         pass
@@ -1157,8 +1158,8 @@ class MEDCouplingBasicsTest1(unittest.TestCase):
         self.assertTrue(abs(3.6-values4[0])<1.e-12);
         self.assertTrue(abs(7.2-values4[1])<1.e-12);
         values4=f1.integral(True);
-        self.assertTrue(abs(0.5-values4[0])<1.e-12);
-        self.assertTrue(abs(1.-values4[1])<1.e-12);
+        self.assertTrue(abs(0.4-values4[0])<1.e-12);
+        self.assertTrue(abs(0.8-values4[1])<1.e-12);
         pass
 
     def testApplyFunc(self):
index bb74613adda4a5e53586566b7003d3c4acfe9666..437da792659af4bf7d9f0441d6400c02d5f65cff 100644 (file)
@@ -820,8 +820,8 @@ class MEDCouplingBasicsTest2(unittest.TestCase):
         self.assertTrue(abs(3.6-values4[0])<1.e-12);
         self.assertTrue(abs(7.2-values4[1])<1.e-12);
         values4=f1.integral(True);
-        self.assertTrue(abs(0.5-values4[0])<1.e-12);
-        self.assertTrue(abs(1.-values4[1])<1.e-12);
+        self.assertTrue(abs(0.4-values4[0])<1.e-12);
+        self.assertTrue(abs(0.8-values4[1])<1.e-12);
         #
         f1=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
         f1.setMesh(m);