]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Bug correction : normL1 and normL2
authorageay <ageay>
Fri, 17 Feb 2012 08:49:48 +0000 (08:49 +0000)
committerageay <ageay>
Fri, 17 Feb 2012 08:49:48 +0000 (08:49 +0000)
src/MEDCoupling/MEDCouplingFieldDiscretization.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index a3bc2d072223a6463e3e194668f15798d80212ef..91219d31c2cd806642c93cf93a84d7b7d2c560a2 100644 (file)
@@ -117,11 +117,15 @@ void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const D
   std::fill(res,res+nbOfCompo,0.);
   const double *arrPtr=arr->getConstPointer();
   const double *volPtr=vol->getArray()->getConstPointer();
+  double deno=0.;
   for(int i=0;i<nbOfElems;i++)
     {
+      double v=fabs(volPtr[i]);
       for(int j=0;j<nbOfCompo;j++)
-        res[j]+=fabs(arrPtr[i*nbOfCompo+j])*volPtr[i];
+        res[j]+=fabs(arrPtr[i*nbOfCompo+j])*v;
+      deno+=v;
     }
+  std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
   vol->decrRef();
 }
 
@@ -138,11 +142,15 @@ void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const D
   std::fill(res,res+nbOfCompo,0.);
   const double *arrPtr=arr->getConstPointer();
   const double *volPtr=vol->getArray()->getConstPointer();
+  double deno=0.;
   for(int i=0;i<nbOfElems;i++)
     {
+      double v=fabs(volPtr[i]);
       for(int j=0;j<nbOfCompo;j++)
-        res[j]+=arrPtr[i*nbOfCompo+j]*arrPtr[i*nbOfCompo+j]*fabs(volPtr[i]);
+        res[j]+=arrPtr[i*nbOfCompo+j]*arrPtr[i*nbOfCompo+j]*v;
+      deno+=v;
     }
+  std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
   std::transform(res,res+nbOfCompo,res,std::ptr_fun<double,double>(std::sqrt));
   vol->decrRef();
 }
index 2c04b395904e8097b1a74d679abae772548e88a7..87ed986e5ac8e99dfec13a2102786137e919f35b 100644 (file)
@@ -375,7 +375,7 @@ void MEDCouplingBasicsTest2::testNormL12Integ1D()
     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],res[i],1e-12);
   //normL1
   f1->normL1(res);
-  double expected5[3]={11.3068,27.3621,43.7881};
+  double expected5[3]={6.979506172839505, 16.89018518518518, 27.02969135802469};
   for(int i=0;i<3;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[0],f1->normL1(0),1e-12);
@@ -383,7 +383,7 @@ void MEDCouplingBasicsTest2::testNormL12Integ1D()
   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[2],f1->normL1(2),1e-12);
   //normL2
   f1->normL2(res);
-  double expected7[3]={9.0252562290496776, 21.545259176904789, 34.433193070059595};
+  double expected7[3]={7.090910979452395, 16.9275542960123, 27.053271464160858};
   for(int i=0;i<3;i++)
     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-9);
   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[0],f1->normL2(0),1e-9);
@@ -440,10 +440,10 @@ void MEDCouplingBasicsTest2::testNormL12Integ1D()
     CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
   f1->normL1(res);
   for(int i=0;i<3;i++)
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected5[i],res[i],1e-12);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
   f1->normL2(res);
   for(int i=0;i<3;i++)
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(sqrt(2.))*expected7[i],res[i],1e-12);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-12);
   //
   f1->decrRef();
   m1->decrRef();
index 19c0e02c2c2cc49bf10d1ea601180e44fe8f0087..2eb7afc2a014d6d46d61d9e9d568ac778bc6cc3c 100644 (file)
@@ -2265,7 +2265,7 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         #normL1
         res=f1.normL1();
         self.assertTrue(3,len(res))
-        expected5=[11.3068,27.3621,43.7881]
+        expected5=[6.979506172839505, 16.89018518518518, 27.02969135802469]
         for i in xrange(3):
             self.assertTrue(abs(expected5[i]-res[i])<1e-12);
             pass
@@ -2275,7 +2275,7 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         #normL2
         res=f1.normL2();
         self.assertTrue(3,len(res))
-        expected7=[9.0252562290496776, 21.545259176904789, 34.433193070059595]
+        expected7=[7.090910979452395, 16.9275542960123, 27.053271464160858]
         for i in xrange(3):
             self.assertTrue(abs(expected7[i]-res[i])<1e-9);
             pass
@@ -2328,11 +2328,11 @@ class MEDCouplingBasicsTest(unittest.TestCase):
             pass
         res=f1.normL1();
         for i in xrange(3):
-            self.assertTrue(abs(sqrt(2.)*expected5[i]-res[i])<1e-12);
+            self.assertTrue(abs(expected5[i]-res[i])<1e-12);
             pass
         res=f1.normL2();
         for i in xrange(3):
-            self.assertTrue(abs(sqrt(sqrt(2.))*expected7[i]-res[i])<1e-12);
+            self.assertTrue(abs(expected7[i]-res[i])<1e-12);
             pass
         pass