]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Mon, 25 Jul 2011 14:14:17 +0000 (14:14 +0000)
committerageay <ageay>
Mon, 25 Jul 2011 14:14:17 +0000 (14:14 +0000)
src/MEDCoupling/MEDCouplingFieldDouble.cxx
src/MEDCoupling/MEDCouplingFieldDouble.hxx
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 8f0b96749b176eb920ac48ef051ebb18c63f9942..217586abef8d74307a028cc3f0b5b35458eaf9cf 100644 (file)
@@ -570,6 +570,20 @@ double MEDCouplingFieldDouble::getAverageValue() const throw(INTERP_KERNEL::Exce
   return getArray()->getAverageValue();
 }
 
+/*!
+ * This method returns the euclidean norm of 'this'.
+ * \f[
+ * \sqrt{\sum_{0 \leq i < nbOfEntity}val[i]*val[i]}
+ * \f]
+ * If default array does not exist, an exception will be thrown.
+ */
+double MEDCouplingFieldDouble::norm2() const throw(INTERP_KERNEL::Exception)
+{
+  if(getArray()==0)
+    throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::norm2 : no default array defined !");
+  return getArray()->norm2();
+}
+
 /*!
  * This method returns the average value in 'this' weighted by ParaMEDMEM::MEDCouplingField::buildMeasureField.
  * 'This' is expected to be a field with exactly \b one component. If not an exception will be thrown.
index 024cf784720443a3adeab1ca1411094a0c176826..54aa819d53b6aeb958ca5172893ce2f527bd96a3 100644 (file)
@@ -92,6 +92,7 @@ namespace ParaMEDMEM
     double getMinValue() const throw(INTERP_KERNEL::Exception);
     double getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception);
     double getAverageValue() const throw(INTERP_KERNEL::Exception);
+    double norm2() const throw(INTERP_KERNEL::Exception);
     double getWeightedAverageValue() const throw(INTERP_KERNEL::Exception);
     double normL1(int compId) const throw(INTERP_KERNEL::Exception);
     void normL1(double *res) const throw(INTERP_KERNEL::Exception);
index b2abe3b3f27ca88033bb12510c377b79299dbb70..4bab1b036735c43543dbcd9a718203021c51e1f0 100644 (file)
@@ -1022,6 +1022,17 @@ double DataArrayDouble::getAverageValue() const throw(INTERP_KERNEL::Exception)
   return ret/nbOfTuples;
 }
 
+double DataArrayDouble::norm2() const throw(INTERP_KERNEL::Exception)
+{
+  checkAllocated();
+  double ret=0.;
+  int nbOfElems=getNbOfElems();
+  const double *pt=getConstPointer();
+  for(int i=0;i<nbOfElems;i++,pt++)
+    ret+=(*pt)*(*pt);
+  return sqrt(ret);
+}
+
 void DataArrayDouble::accumulate(double *res) const throw(INTERP_KERNEL::Exception)
 {
   checkAllocated();
index 9dc9b89eb2a0d4af38c104087652151654c6e00a..a0c95f4ee0940c2fe9bba56c8376e8df78bd5845 100644 (file)
@@ -191,6 +191,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT double getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT double getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT double getAverageValue() const throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT double norm2() const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void accumulate(double *res) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT double accumulate(int compId) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT DataArrayDouble *fromPolarToCart() const throw(INTERP_KERNEL::Exception);
index 0274806742a30cc40e9394fdcfdc0eaa76c837d3..6173a5410afc5f26710ec39f0cabf11823a4046e 100644 (file)
@@ -229,6 +229,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testDAIComputeOffsets2 );
     CPPUNIT_TEST( testMergeField3 );
     CPPUNIT_TEST( testGetDistributionOfTypes1 );
+    CPPUNIT_TEST( testNorm2_1 );
     //MEDCouplingBasicsTestInterp.cxx
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
@@ -484,6 +485,7 @@ namespace ParaMEDMEM
     void testDAIComputeOffsets2();
     void testMergeField3();
     void testGetDistributionOfTypes1();
+    void testNorm2_1();
     //MEDCouplingBasicsTestInterp.cxx
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
index 6353f0ec5e50decc1b22ff78a065fc9990df4779..0537e03583e7a9a5dcb9957384428d68f7fcc428 100644 (file)
@@ -1514,3 +1514,23 @@ void MEDCouplingBasicsTest::testGetDistributionOfTypes1()
   CPPUNIT_ASSERT_EQUAL(0,code[5]);
   m->decrRef();
 }
+
+void MEDCouplingBasicsTest::testNorm2_1()
+{
+  MEDCouplingUMesh *m=build2DTargetMesh_1();
+  MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+  f->setMesh(m);
+  m->decrRef();
+  //
+  DataArrayDouble *d=DataArrayDouble::New();
+  const double tab[10]={1.2,1.3,2.2,2.3,3.2,3.3,4.2,4.3,5.2,5.3};
+  d->alloc(5,2);
+  std::copy(tab,tab+10,d->getPointer());
+  f->setArray(d);
+  d->decrRef();
+  f->checkCoherency();
+  //
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(11.209371079592289,f->norm2(),1e-14);
+  //
+  f->decrRef();
+}
index 4b615f78695429a40dd089caebf1a764b910b1c0..d86cd5c3dd31c1804fc6bef1ed6a0a468253a734 100644 (file)
@@ -3759,6 +3759,7 @@ namespace ParaMEDMEM
     double getMaxValue() const throw(INTERP_KERNEL::Exception);
     double getMinValue() const throw(INTERP_KERNEL::Exception);
     double getAverageValue() const throw(INTERP_KERNEL::Exception);
+    double norm2() const throw(INTERP_KERNEL::Exception);
     double getWeightedAverageValue() const throw(INTERP_KERNEL::Exception);
     double integral(int compId, bool isWAbs) const throw(INTERP_KERNEL::Exception);
     double normL1(int compId) const throw(INTERP_KERNEL::Exception);
index d55b08b73995452c5757209f8b73d864aac304d2..62905e395e0b9a1bffbef09efb5a59416df13f41 100644 (file)
@@ -7592,6 +7592,21 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertEqual(3,code[4]);
         self.assertEqual(0,code[5]);
         pass
+
+    def testNorm2_1(self):
+        m=MEDCouplingDataForTest.build2DTargetMesh_1();
+        f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+        f.setMesh(m);
+        #
+        d=DataArrayDouble.New();
+        tab=[1.2,1.3,2.2,2.3,3.2,3.3,4.2,4.3,5.2,5.3]
+        d.setValues(tab,5,2);
+        f.setArray(d);
+        f.checkCoherency();
+        #
+        self.assertAlmostEqual(11.209371079592289,f.norm2(),1e-14);
+        #
+        pass
     
     def setUp(self):
         pass