From: Anthony Geay Date: Tue, 15 Jan 2019 08:48:28 +0000 (+0100) Subject: Bug correction into MEDCouplingUMesh::getMeasureFieldOnNode on non simplex cells... X-Git-Tag: V9_3_0a1~25^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a576269fefd44bfc3fcced449a8b1bd2c1da17d9;p=tools%2Fmedcoupling.git Bug correction into MEDCouplingUMesh::getMeasureFieldOnNode on non simplex cells. Consequence : FieldDouble::integral on P1 field may change in case of non simplex use. --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 0e1258aa7..cce5fe0bf 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -3306,8 +3306,14 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureFieldOnNode(bool isAbs) cons std::string name="MeasureOnNodeOfMesh_"; name+=getName(); int nbNodes=getNumberOfNodes(); + MCAuto nnpc; + { + MCAuto tmp(computeNbOfNodesPerCell()); + nnpc=tmp->convertToDblArr(); + } + std::for_each(nnpc->rwBegin(),nnpc->rwEnd(),[](double& v) { v=1./v; }); + const double *nnpcPtr(nnpc->begin()); MCAuto ret=MEDCouplingFieldDouble::New(ON_NODES); - double cst=1./((double)getMeshDimension()+1.); MCAuto 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;isetMesh(this); ret->setArray(array); return ret.retn(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx index 4e859d322..e09ca0e77 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx @@ -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); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index e7d48150c..564c0b52a 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -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); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py index ae07b6d34..92298fe33 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py @@ -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): diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py index bb74613ad..437da7926 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py @@ -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);