From: ageay Date: Mon, 25 Jul 2011 16:08:20 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~996 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d88db1c00a52bedc873e21b2e310464f2062391;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 217586abe..5f59890de 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -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. diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 54aa819d5..db1b332a0 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -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); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 4bab1b036..d720be782 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -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;iret) + ret=val; + } + return ret; +} + void DataArrayDouble::accumulate(double *res) const throw(INTERP_KERNEL::Exception) { checkAllocated(); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index a0c95f4ee..6206bcce2 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -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); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 6173a5410..9dc4d6dfc 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -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(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 0537e0358..23d972676 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -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(); +} diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index d86cd5c3d..f8f523cd1 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -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); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 62905e395..f8045e3f3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -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