/** * Sets eigenvalues for the tensor with specified indices. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @param i3 index for 3rd dimension. * @param a array {au,av,aw} of eigenvalues. */ public void setEigenvalues(int i1, int i2, int i3, float[] a) { setEigenvalues(i1,i2,i3,a[0],a[1],a[2]); }
/** * Sets eigenvalues for all tensors. * @param au array of eigenvalues au. * @param av array of eigenvalues av. * @param aw array of eigenvalues aw. */ public void setEigenvalues(float[][][] au, float[][][] av, float[][][] aw) { for (int i3=0; i3<_n3; ++i3) { for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { float aui = au[i3][i2][i1]; float avi = av[i3][i2][i1]; float awi = aw[i3][i2][i1]; setEigenvalues(i1,i2,i3,aui,avi,awi); } } } }
private static void setEigenvalues(Direction3 d, EigenTensors3 t) { float au = 0.0f; float av = 0.0f; float aw = 0.0f; if (d==Direction3.U || d==Direction3.UV || d==Direction3.UW || d==Direction3.UVW) au = 1.0f; if (d==Direction3.V || d==Direction3.UV || d==Direction3.VW || d==Direction3.UVW) av = 1.0f; if (d==Direction3.W || d==Direction3.UW || d==Direction3.VW || d==Direction3.UVW) aw = 1.0f; t.setEigenvalues(au,av,aw); }
/** * Inverts these tensors by inverting their eigenvalues. * Takes no care to avoid division by zero eigenvalues. */ public void invert() { float[] a = new float[3]; for (int i3=0; i3<_n3; ++i3) { for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { getEigenvalues(i1,i2,i3,a); a[0] = 1.0f/a[0]; a[1] = 1.0f/a[1]; a[2] = 1.0f/a[2]; setEigenvalues(i1,i2,i3,a); } } } }
/** * Scales eigenvalues of these tensors by specified factors. * @param s array of scale factors. */ public void scale(float[][][] s) { float[] a = new float[3]; for (int i3=0; i3<_n3; ++i3) { for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { float si = s[i3][i2][i1]; getEigenvalues(i1,i2,i3,a); a[0] *= si; a[1] *= si; a[2] *= si; setEigenvalues(i1,i2,i3,a); } } } }
public void apply( Direction3 d, EigenTensors3 t, float[][][] f, float[][][] g) { if (_scale==0.0f) { copy(f,g); } else { int n1 = f[0][0].length; int n2 = f[0].length; int n3 = f.length; float[][][] au = new float[n3][n2][n1]; float[][][] av = new float[n3][n2][n1]; float[][][] aw = new float[n3][n2][n1]; float[][][] sf = new float[n3][n2][n1]; t.getEigenvalues(au,av,aw); setEigenvalues(d,t); _lsf.applySmoothL(_kmax,f,sf); //_lsf.applySmoothS(f,sf); _lsf.apply(t,_scale,sf,g); t.setEigenvalues(au,av,aw); } } private float _scale;
setEigenvectorU(i1,i2,i3,u1,u2,u3); setEigenvectorW(i1,i2,i3,w1,w2,w3); setEigenvalues(i1,i2,i3,au,av,aw);
if (awi<amin) amin = awi; if (aui>amax) amax = aui; setEigenvalues(i1,i2,i3,aui,avi,awi); avi = a0i*a1i; awi = a0i; setEigenvalues(i1,i2,i3,aui,avi,awi);
float w2i = w2[i3][i2][i1]; float w3i = c3(w1i,w2i); setEigenvalues(i1,i2,i3,aui,avi,awi); setEigenvectorU(i1,i2,i3,u1i,u2i,u3i); setEigenvectorW(i1,i2,i3,w1i,w2i,w3i);
/** * Constructs tensors from the specified tensors. * @param t the tensors from which to copy eigenvectors and eigenvalues. */ public EigenTensors3(EigenTensors3 t) { this(t._n1,t._n2,t._n3,t._compressed); float[] a = new float[3]; float[] u = new float[3]; float[] w = new float[3]; for (int i3=0; i3<_n3; ++i3) { for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { t.getEigenvalues(i1,i2,i3,a); t.getEigenvectorU(i1,i2,i3,u); t.getEigenvectorW(i1,i2,i3,w); setEigenvalues(i1,i2,i3,a); setEigenvectorU(i1,i2,i3,u); setEigenvectorW(i1,i2,i3,w); } } } }
float[] u = makeRandomEigenvector(); float[] w = makeOrthogonalVector(u); et1.setEigenvalues(i1,i2,i3,a); et1.setEigenvectorU(i1,i2,i3,u); et1.setEigenvectorW(i1,i2,i3,w);
public static void demo3() { int n1 = 111; int n2 = 111; int n3 = 1; EigenTensors3 et = new EigenTensors3(n1,n2,n3,false); float eu = 0.01f, ev = 1.00f, ew = 1.00f; float u1 = 1.00f, u2 = 0.00f, u3 = 0.00f; float w1 = 0.00f, w2 = 0.00f, w3 = 1.00f; int i3 = 0; for (int i2=0; i2<n2; ++i2) { float a = i2*FLT_PI/2.0f/(n2-1); u1 = cos(a); u2 = sin(a); for (int i1=0; i1<n1; ++i1) { et.setEigenvalues(i1,i2,i3,eu,ev,ew); et.setEigenvectorU(i1,i2,i3,u1,u2,u3); et.setEigenvectorW(i1,i2,i3,w1,w2,w3); } } TensorsPanel tp = new TensorsPanel(et); AxisAlignedQuad aaq = new AxisAlignedQuad(Axis.X, new Point3(i3, 0, 0), new Point3(i3,n2-1,n1-1)); aaq.getFrame().addChild(tp); show(aaq); }
public static void demo1() { int n1 = 1; int n2 = 111; int n3 = 111; EigenTensors3 et = new EigenTensors3(n1,n2,n3,false); float eu = 1.00f, ev = 1.00f, ew = 0.01f; float u1 = 1.00f, u2 = 0.00f, u3 = 0.00f; float w1 = 0.00f, w2 = 0.00f, w3 = 1.00f; int i1 = 0; for (int i3=0; i3<n3; ++i3) { float a = i3*FLT_PI/2.0f/(n3-1); w2 = sin(a); w3 = cos(a); for (int i2=0; i2<n2; ++i2) { et.setEigenvalues(i1,i2,i3,eu,ev,ew); et.setEigenvectorU(i1,i2,i3,u1,u2,u3); et.setEigenvectorW(i1,i2,i3,w1,w2,w3); } } TensorsPanel tp = new TensorsPanel(et); AxisAlignedQuad aaq = new AxisAlignedQuad(Axis.Z, new Point3( 0, 0,i1), new Point3(n3-1,n2-1,i1)); aaq.getFrame().addChild(tp); show(aaq); }
public static void demo2() { int n1 = 111; int n2 = 1; int n3 = 111; EigenTensors3 et = new EigenTensors3(n1,n2,n3,false); float eu = 0.01f, ev = 1.00f, ew = 1.00f; float u1 = 1.00f, u2 = 0.00f, u3 = 0.00f; float w1 = 0.00f, w2 = 1.00f, w3 = 0.00f; int i2 = 0; for (int i3=0; i3<n3; ++i3) { float a = i3*FLT_PI/2.0f/(n3-1); u1 = cos(a); u3 = sin(a); for (int i1=0; i1<n1; ++i1) { et.setEigenvalues(i1,i2,i3,eu,ev,ew); et.setEigenvectorU(i1,i2,i3,u1,u2,u3); et.setEigenvectorW(i1,i2,i3,w1,w2,w3); } } TensorsPanel tp = new TensorsPanel(et); AxisAlignedQuad aaq = new AxisAlignedQuad(Axis.Y, new Point3( 0,i2, 0), new Point3(n3-1,i2,n1-1)); aaq.getFrame().addChild(tp); show(aaq); }
private static void testRandom( boolean compressed, double errorAngle, double errorValue, double errorTensor) { int n1 = 19, n2 = 20, n3 = 21; EigenTensors3 et = new EigenTensors3(n1,n2,n3,compressed); for (int i3=0; i3<n3; ++i3) { for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++i1) { float[] a = makeRandomEigenvalues(); float[] u = makeRandomEigenvector(); float[] w = makeOrthogonalVector(u); et.setEigenvalues(i1,i2,i3,a); et.setEigenvectorU(i1,i2,i3,u); et.setEigenvectorW(i1,i2,i3,w); float[] c; c = et.getEigenvectorU(i1,i2,i3); checkEigenvectors(u,c,errorAngle); c = et.getEigenvectorW(i1,i2,i3); checkEigenvectors(w,c,errorAngle); c = et.getEigenvalues(i1,i2,i3); checkEigenvalues(a,c,errorValue); float[] t1 = et.getTensor(i1,i2,i3); et.setTensor(i1,i2,i3,t1); float[] t2 = et.getTensor(i1,i2,i3); checkTensors(t1,t2,errorTensor); } } } }