From d05c498c6ad6fb8215fff65c527c2ef57f4d1926 Mon Sep 17 00:00:00 2001 From: Anthony GEAY Date: Tue, 17 Nov 2020 08:33:27 +0100 Subject: [PATCH] [EDF22126] : eigen values with identity matrix --- src/INTERP_KERNEL/GenMathFormulae.hxx | 7 ++++++- src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/INTERP_KERNEL/GenMathFormulae.hxx b/src/INTERP_KERNEL/GenMathFormulae.hxx index 19bc41024..037f96cfe 100644 --- a/src/INTERP_KERNEL/GenMathFormulae.hxx +++ b/src/INTERP_KERNEL/GenMathFormulae.hxx @@ -32,6 +32,8 @@ namespace INTERP_KERNEL * matrix[0]=m_xx, matrix[1]=m_yy, matrix[2]=m_zz, * matrix[3]=m_xy, matrix[4]=m_yz, matrix[5]=m_xz * This method returns the 3 eigenvalues in 'eigenVals'. + * + * https://en.wikipedia.org/wiki/Eigenvalue_algorithm */ void computeEigenValues6(const double *matrix, double *eigenVals) { @@ -44,7 +46,10 @@ namespace INTERP_KERNEL double tmp=p*sqp; double phi; if(fabs(q)<=fabs(tmp)) - phi=1./3.*acos(q/tmp); + if(tmp !=0) + phi=1./3.*acos(q/tmp); + else // EDF22176 + phi=1./3.; else phi=0.; if(phi<0.) diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index 3e480e24b..d279d1b2c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -897,6 +897,19 @@ class MEDCouplingBasicsTest7(unittest.TestCase): f.setArray(DataArrayDouble(18*[0.])) self.assertTrue(f.getLocalizationOfDiscr().isEqual(coo[conn],1e-10)) + def testDADEigenValuesPb(self): + """EDF22126 : eigen values with Identity matrix returned nan. Now it returns correct eigen values 1.0 """ + valuesExp = DataArrayDouble([(1.,1.,1.),(2.,-1.,0.),(2.,0.,1.),(3.,0.,0.)]) + d = DataArrayDouble(4, 6) + for i,(v0, v1, v2, v3, v4, v5,) in enumerate([ + (1, 1, 1, 0, 0, 0), + (1, 0, 0, 1, 0, 1), + (1, 1, 1, 0, 1, 0), + (1, 1, 1, 1, 1, 1)]): + d[i] = [v0, v1, v2, v3, v4, v5] + self.assertTrue(d.eigenValues().isEqual(valuesExp,1e-12)) + pass + pass if __name__ == '__main__': -- 2.39.2