1 package JSci.physics.relativity; 2 3 import JSci.GlobalSettings; 4 import JSci.maths.*; 5 6 11 public class Rank4Tensor extends Tensor { 12 protected double rank4[][][][]; 13 14 17 public Rank4Tensor() { 18 rank4=new double[4][4][4][4]; 19 } 20 24 public boolean equals(Object a) { 25 if(a instanceof Rank4Tensor) { 26 Rank4Tensor v=(Rank4Tensor)a; 27 for(int k,j,i=0;i<4;i++) { 28 for(j=0;j<4;j++) { 29 for(k=0;k<4;k++) { 30 if(Math.abs(rank4[i][j][k][0]-v.rank4[i][j][k][0])>GlobalSettings.ZERO_TOL || 31 Math.abs(rank4[i][j][k][1]-v.rank4[i][j][k][1])>GlobalSettings.ZERO_TOL || 32 Math.abs(rank4[i][j][k][2]-v.rank4[i][j][k][2])>GlobalSettings.ZERO_TOL || 33 Math.abs(rank4[i][j][k][3]-v.rank4[i][j][k][3])>GlobalSettings.ZERO_TOL) 34 return false; 35 } 36 } 37 } 38 return true; 39 } 40 return false; 41 } 42 50 public double getComponent(int i,int j,int k,int l) { 51 if(i>=0 && i<4 && j>=0 && j<4 && k>=0 && k<4 && l>=0 && l<4) 52 return rank4[i][j][k][l]; 53 else 54 throw new DimensionException("Invalid component."); 55 } 56 65 public void setComponent(int i,int j,int k,int l,double x) { 66 if(i>=0 && i<4 && j>=0 && j<4 && k>=0 && k<4 && l>=0 && l<4) 67 rank4[i][j][k][l]=x; 68 else 69 throw new DimensionException("Invalid component."); 70 } 71 72 76 78 82 public Rank4Tensor add(Rank4Tensor t) { 83 Rank4Tensor ans=new Rank4Tensor(); 84 for(int k,j,i=0;i<4;i++) { 85 for(j=0;j<4;j++) { 86 for(k=0;k<4;k++) { 87 ans.setComponent(i,j,k,0,rank4[i][j][k][0]+t.rank4[i][j][k][0]); 88 ans.setComponent(i,j,k,1,rank4[i][j][k][1]+t.rank4[i][j][k][1]); 89 ans.setComponent(i,j,k,2,rank4[i][j][k][2]+t.rank4[i][j][k][2]); 90 ans.setComponent(i,j,k,3,rank4[i][j][k][3]+t.rank4[i][j][k][3]); 91 } 92 } 93 } 94 return ans; 95 } 96 97 99 103 public Rank4Tensor subtract(Rank4Tensor t) { 104 Rank4Tensor ans=new Rank4Tensor(); 105 for(int k,j,i=0;i<4;i++) { 106 for(j=0;j<4;j++) { 107 for(k=0;k<4;k++) { 108 ans.setComponent(i,j,k,0,rank4[i][j][k][0]-t.rank4[i][j][k][0]); 109 ans.setComponent(i,j,k,1,rank4[i][j][k][1]-t.rank4[i][j][k][1]); 110 ans.setComponent(i,j,k,2,rank4[i][j][k][2]-t.rank4[i][j][k][2]); 111 ans.setComponent(i,j,k,3,rank4[i][j][k][3]-t.rank4[i][j][k][3]); 112 } 113 } 114 } 115 return ans; 116 } 117 } 118 119 | Popular Tags |