]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Mon, 25 Jul 2011 16:08:20 +0000 (16:08 +0000)
committerageay <ageay>
Mon, 25 Jul 2011 16:08:20 +0000 (16:08 +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 217586abef8d74307a028cc3f0b5b35458eaf9cf..5f59890de8adad08d40f35d90b290b1277c99720 100644 (file)
@@ -584,6 +584,20 @@ double MEDCouplingFieldDouble::norm2() const throw(INTERP_KERNEL::Exception)
   return getArray()->norm2();
 }
 
+/*!
+ * This method returns the max norm of 'this'.
+ * \f[
+ * \max_{0 \leq i < nbOfEntity}{abs(val[i])}
+ * \f]
+ * If default array does not exist, an exception will be thrown.
+ */
+double MEDCouplingFieldDouble::normMax() const throw(INTERP_KERNEL::Exception)
+{
+  if(getArray()==0)
+    throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::normMax : no default array defined !");
+  return getArray()->normMax();
+}
+
 /*!
  * 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 54aa819d53b6aeb958ca5172893ce2f527bd96a3..db1b332a0272ca9d1765f265c3930e40068138f1 100644 (file)
@@ -93,6 +93,7 @@ namespace ParaMEDMEM
     double getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception);
     double getAverageValue() const throw(INTERP_KERNEL::Exception);
     double norm2() const throw(INTERP_KERNEL::Exception);
+    double normMax() 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 4bab1b036735c43543dbcd9a718203021c51e1f0..d720be782675737858ce38b83d41318277636dd9 100644 (file)
@@ -1033,6 +1033,21 @@ double DataArrayDouble::norm2() const throw(INTERP_KERNEL::Exception)
   return sqrt(ret);
 }
 
+double DataArrayDouble::normMax() const throw(INTERP_KERNEL::Exception)
+{
+  checkAllocated();
+  double ret=-1.;
+  int nbOfElems=getNbOfElems();
+  const double *pt=getConstPointer();
+  for(int i=0;i<nbOfElems;i++,pt++)
+    {
+      double val=std::abs(*pt);
+      if(val>ret)
+        ret=val;
+    }
+  return ret;
+}
+
 void DataArrayDouble::accumulate(double *res) const throw(INTERP_KERNEL::Exception)
 {
   checkAllocated();
index a0c95f4ee0940c2fe9bba56c8376e8df78bd5845..6206bcce2849854fcffb71340bdcff89c24d1fed 100644 (file)
@@ -192,6 +192,7 @@ namespace ParaMEDMEM
     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 double normMax() 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 6173a5410afc5f26710ec39f0cabf11823a4046e..9dc4d6dfc0ea4d33808f58d152dee52ccc7b8105 100644 (file)
@@ -230,6 +230,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testMergeField3 );
     CPPUNIT_TEST( testGetDistributionOfTypes1 );
     CPPUNIT_TEST( testNorm2_1 );
+    CPPUNIT_TEST( testNormMax1 );
     //MEDCouplingBasicsTestInterp.cxx
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
@@ -486,6 +487,7 @@ namespace ParaMEDMEM
     void testMergeField3();
     void testGetDistributionOfTypes1();
     void testNorm2_1();
+    void testNormMax1();
     //MEDCouplingBasicsTestInterp.cxx
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
index 0537e03583e7a9a5dcb9957384428d68f7fcc428..23d972676da4cfc519f60c7bf69035335c7efb7b 100644 (file)
@@ -1534,3 +1534,23 @@ void MEDCouplingBasicsTest::testNorm2_1()
   //
   f->decrRef();
 }
+
+void MEDCouplingBasicsTest::testNormMax1()
+{
+  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]={2.3,-1.2,6.3,-7.8,2.9,7.7,2.1,0.,3.6,-7.6};
+  d->alloc(5,2);
+  std::copy(tab,tab+10,d->getPointer());
+  f->setArray(d);
+  d->decrRef();
+  f->checkCoherency();
+  //
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(7.8,f->normMax(),1e-14);
+  //
+  f->decrRef();
+}
index d86cd5c3dd31c1804fc6bef1ed6a0a468253a734..f8f523cd10b60121062d82dfa1192e14e93fd6bd 100644 (file)
@@ -3760,6 +3760,7 @@ namespace ParaMEDMEM
     double getMinValue() const throw(INTERP_KERNEL::Exception);
     double getAverageValue() const throw(INTERP_KERNEL::Exception);
     double norm2() const throw(INTERP_KERNEL::Exception);
+    double normMax() 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 62905e395e0b9a1bffbef09efb5a59416df13f41..f8045e3f3ec50b194fbc7606f9105285a4e5f081 100644 (file)
@@ -7607,6 +7607,21 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertAlmostEqual(11.209371079592289,f.norm2(),1e-14);
         #
         pass
+
+    def testNormMax1(self):
+        m=MEDCouplingDataForTest.build2DTargetMesh_1();
+        f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+        f.setMesh(m);
+        #
+        d=DataArrayDouble.New();
+        tab=[2.3,-1.2,6.3,-7.8,2.9,7.7,2.1,0.,3.6,-7.6]
+        d.setValues(tab,5,2);
+        f.setArray(d);
+        f.checkCoherency();
+        #
+        self.assertAlmostEqual(7.8,f.normMax(),1e-14);
+        #
+        pass
     
     def setUp(self):
         pass