/** * Sets eigenvalues for the tensor with specified indices. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @param a array {au,av} of eigenvalues. */ public void setEigenvalues(int i1, int i2, float[] a) { setEigenvalues(i1,i2,a[0],a[1]); }
private static void setEigenvalues(Direction2 d, EigenTensors2 t) { float au = 0.0f; float av = 0.0f; if (d==Direction2.U || d==Direction2.UV) au = 1.0f; if (d==Direction2.V || d==Direction2.UV) av = 1.0f; t.setEigenvalues(au,av); } private static void setEigenvalues(Direction3 d, EigenTensors3 t) {
/** * Constructs tensors for specified array dimensions and eigenvalues. * @param u1 array of 1st components of u. * @param u2 array of 2nd components of u. * @param au array of 1D eigenvalues. * @param av array of 2D eigenvalues. */ public EigenTensors2( float[][] u1, float[][] u2, float[][] au, float[][] av) { this(u1[0].length,u1.length); for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { float aui = au[i2][i1]; float avi = av[i2][i1]; float u1i = u1[i2][i1]; float u2i = u2[i2][i1]; setEigenvalues(i1,i2,aui,avi); setEigenvectorU(i1,i2,u1i,u2i); } } }
public void apply( Direction2 d, EigenTensors2 t, float[][] f, float[][] g) { if (_scale==0.0f) { copy(f,g); } else { int n1 = f[0].length; int n2 = f.length; float[][] au = new float[n2][n1]; float[][] av = new float[n2][n1]; float[][] sf = new float[n2][n1]; t.getEigenvalues(au,av); setEigenvalues(d,t); _lsf.applySmoothL(_kmax,f,sf); //_lsf.applySmoothS(f,sf); _lsf.apply(t,_scale,sf,g); t.setEigenvalues(au,av); } } public void apply(
/** * Sets tensor elements for specified indices. * This method first computes an eigen-decomposition of the specified * tensor, and then stores the computed eigenvectors and eigenvalues. * The eigenvalues are ordered such that au >= av >= 0. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @param a11 tensor element a11. * @param a12 tensor element a12. * @param a22 tensor element a22. */ public void setTensor(int i1, int i2, float a11, float a12, float a22) { float[][] aa = { {a11,a12}, {a12,a22} }; float[][] vv = new float[2][2]; float[] ev = new float[2]; Eigen.solveSymmetric22(aa,vv,ev); float[] u = vv[0]; float au = ev[0]; if (au<0.0f) au = 0.0f; float av = ev[1]; if (av<0.0f) av = 0.0f; setEigenvectorU(i1,i2,u); setEigenvalues(i1,i2,au,av); }
private static void testRandom(double errorAngle, double errorCoeff) { int n1 = 13, n2 = 14; EigenTensors2 et = new EigenTensors2(n1,n2); for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++i1) { float[] a = makeRandomEigenvalues(); float[] u = makeRandomEigenvector(); et.setEigenvalues(i1,i2,a); et.setEigenvectorU(i1,i2,u); float[] c; c = et.getEigenvectorU(i1,i2); checkEigenvectors(u,c,errorAngle); c = et.getEigenvalues(i1,i2); checkEigenvalues(c,a,errorCoeff); et.setTensor(i1,i2,et.getTensor(i1,i2)); c = et.getEigenvectorU(i1,i2); checkEigenvectors(u,c,errorAngle); c = et.getEigenvalues(i1,i2); checkEigenvalues(c,a,errorCoeff); } } }