1 package JSci.physics.relativity; 2 3 import JSci.GlobalSettings; 4 import JSci.maths.*; 5 6 11 public class Rank3Tensor extends Tensor { 12 protected double rank3[][][]; 13 14 17 public Rank3Tensor() { 18 rank3=new double[4][4][4]; 19 } 20 24 public boolean equals(Object a) { 25 if(a instanceof Rank3Tensor) { 26 Rank3Tensor v=(Rank3Tensor)a; 27 for(int j,i=0;i<4;i++) { 28 for(j=0;j<4;j++) { 29 if(Math.abs(rank3[i][j][0]-v.rank3[i][j][0])>GlobalSettings.ZERO_TOL || 30 Math.abs(rank3[i][j][1]-v.rank3[i][j][1])>GlobalSettings.ZERO_TOL || 31 Math.abs(rank3[i][j][2]-v.rank3[i][j][2])>GlobalSettings.ZERO_TOL || 32 Math.abs(rank3[i][j][3]-v.rank3[i][j][3])>GlobalSettings.ZERO_TOL) 33 return false; 34 } 35 } 36 return true; 37 } 38 return false; 39 } 40 47 public double getComponent(int i, int j,int k) { 48 if(i>=0 && i<4 && j>=0 && j<4 && k>=0 && k<4) 49 return rank3[i][j][k]; 50 else 51 throw new DimensionException("Invalid component."); 52 } 53 61 public void setComponent(int i,int j,int k,double x) { 62 if(i>=0 && i<4 && j>=0 && j<4 && k>=0 && k<4) 63 rank3[i][j][k]=x; 64 else 65 throw new DimensionException("Invalid component."); 66 } 67 68 72 74 78 public Rank3Tensor add(Rank3Tensor t) { 79 Rank3Tensor ans=new Rank3Tensor(); 80 for(int j,i=0;i<4;i++) { 81 for(j=0;j<4;j++) { 82 ans.setComponent(i,j,0,rank3[i][j][0]+t.rank3[i][j][0]); 83 ans.setComponent(i,j,1,rank3[i][j][1]+t.rank3[i][j][1]); 84 ans.setComponent(i,j,2,rank3[i][j][2]+t.rank3[i][j][2]); 85 ans.setComponent(i,j,3,rank3[i][j][3]+t.rank3[i][j][3]); 86 } 87 } 88 return ans; 89 } 90 91 93 97 public Rank3Tensor subtract(Rank3Tensor t) { 98 Rank3Tensor ans=new Rank3Tensor(); 99 for(int j,i=0;i<4;i++) { 100 for(j=0;j<4;j++) { 101 ans.setComponent(i,j,0,rank3[i][j][0]-t.rank3[i][j][0]); 102 ans.setComponent(i,j,1,rank3[i][j][1]-t.rank3[i][j][1]); 103 ans.setComponent(i,j,2,rank3[i][j][2]-t.rank3[i][j][2]); 104 ans.setComponent(i,j,3,rank3[i][j][3]-t.rank3[i][j][3]); 105 } 106 } 107 return ans; 108 } 109 110 112 116 public Rank4Tensor tensorProduct(Rank1Tensor t) { 117 Rank4Tensor ans=new Rank4Tensor(); 118 for(int k,j,i=0;i<4;i++) { 119 for(j=0;j<4;j++) { 120 for(k=0;k<4;k++) { 121 ans.setComponent(i,j,k,0,rank3[i][j][k]*t.getComponent(0)); 122 ans.setComponent(i,j,k,1,rank3[i][j][k]*t.getComponent(1)); 123 ans.setComponent(i,j,k,2,rank3[i][j][k]*t.getComponent(2)); 124 ans.setComponent(i,j,k,3,rank3[i][j][k]*t.getComponent(3)); 125 } 126 } 127 } 128 return ans; 129 } 130 } 131 132 | Popular Tags |