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