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.
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);
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();
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);
CPPUNIT_TEST( testDAIComputeOffsets2 );
CPPUNIT_TEST( testMergeField3 );
CPPUNIT_TEST( testGetDistributionOfTypes1 );
+ CPPUNIT_TEST( testNorm2_1 );
//MEDCouplingBasicsTestInterp.cxx
CPPUNIT_TEST( test2DInterpP0P0_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_1 );
void testDAIComputeOffsets2();
void testMergeField3();
void testGetDistributionOfTypes1();
+ void testNorm2_1();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
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();
+}
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);
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