From: ageay Date: Mon, 25 Jul 2011 14:14:17 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~997 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5ed956b69b2f4c68a593f1a8f78f01fe803c9913;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 8f0b96749..217586abe 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -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. diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 024cf7847..54aa819d5 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -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); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index b2abe3b3f..4bab1b036 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -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;idecrRef(); } + +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(); +} diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 4b615f786..d86cd5c3d 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -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); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index d55b08b73..62905e395 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -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