1 package JSci.physics.relativity; 2 3 import JSci.GlobalSettings; 4 import JSci.maths.*; 5 import JSci.maths.vectors.Double3Vector; 6 7 12 public class Rank1Tensor extends Tensor { 13 protected double rank1[]; 14 15 18 public Rank1Tensor() { 19 rank1=new double[4]; 20 } 21 26 public Rank1Tensor(double s,Double3Vector v) { 27 this(); 28 rank1[0]=s; 29 rank1[1]=v.getComponent(0); 30 rank1[2]=v.getComponent(1); 31 rank1[3]=v.getComponent(2); 32 } 33 40 public Rank1Tensor(double s, double v1, double v2, double v3) { 41 this(); 42 rank1[0]=s; 43 rank1[1]=v1; 44 rank1[2]=v2; 45 rank1[3]=v3; 46 } 47 51 public boolean equals(Object a) { 52 if(a instanceof Rank1Tensor) { 53 Rank1Tensor v=(Rank1Tensor)a; 54 return Math.abs(rank1[0]-v.rank1[0])<=GlobalSettings.ZERO_TOL && 55 Math.abs(rank1[1]-v.rank1[1])<=GlobalSettings.ZERO_TOL && 56 Math.abs(rank1[2]-v.rank1[2])<=GlobalSettings.ZERO_TOL && 57 Math.abs(rank1[3]-v.rank1[3])<=GlobalSettings.ZERO_TOL; 58 } 59 return false; 60 } 61 64 public String toString() { 65 return new String (rank1[0]+","+rank1[1]+","+rank1[2]+","+rank1[3]); 66 } 67 70 public int hashCode() { 71 return (int)Math.exp(norm()); 72 } 73 78 public double getComponent(int i) { 79 if(i>=0 && i<4) 80 return rank1[i]; 81 else 82 throw new DimensionException("Invalid component."); 83 } 84 90 public void setComponent(int i,double x) { 91 if(i>=0 && i<4) 92 rank1[i]=x; 93 else 94 throw new DimensionException("Invalid component."); 95 } 96 99 public double norm() { 100 return Math.sqrt(rank1[0]*rank1[0]-rank1[1]*rank1[1] 101 -rank1[2]*rank1[2]-rank1[3]*rank1[3]); 102 } 103 104 108 110 114 public Rank1Tensor add(Rank1Tensor t) { 115 Rank1Tensor ans=new Rank1Tensor(); 116 ans.rank1[0]=rank1[0]+t.rank1[0]; 117 ans.rank1[1]=rank1[1]+t.rank1[1]; 118 ans.rank1[2]=rank1[2]+t.rank1[2]; 119 ans.rank1[3]=rank1[3]+t.rank1[3]; 120 return ans; 121 } 122 123 125 129 public Rank1Tensor subtract(Rank1Tensor t) { 130 Rank1Tensor ans=new Rank1Tensor(); 131 ans.rank1[0]=rank1[0]-t.rank1[0]; 132 ans.rank1[1]=rank1[1]-t.rank1[1]; 133 ans.rank1[2]=rank1[2]-t.rank1[2]; 134 ans.rank1[3]=rank1[3]-t.rank1[3]; 135 return ans; 136 } 137 138 140 144 public Rank2Tensor tensorProduct(Rank1Tensor t) { 145 Rank2Tensor ans=new Rank2Tensor(); 146 for(int i=0;i<4;i++) { 147 ans.setComponent(i,0,rank1[i]*t.rank1[0]); 148 ans.setComponent(i,1,rank1[i]*t.rank1[1]); 149 ans.setComponent(i,2,rank1[i]*t.rank1[2]); 150 ans.setComponent(i,3,rank1[i]*t.rank1[3]); 151 } 152 return ans; 153 } 154 158 public Rank3Tensor tensorProduct(Rank2Tensor t) { 159 Rank3Tensor ans=new Rank3Tensor(); 160 for(int j,i=0;i<4;i++) { 161 for(j=0;j<4;j++) { 162 ans.setComponent(i,j,0,rank1[i]*t.getComponent(j,0)); 163 ans.setComponent(i,j,1,rank1[i]*t.getComponent(j,1)); 164 ans.setComponent(i,j,2,rank1[i]*t.getComponent(j,2)); 165 ans.setComponent(i,j,3,rank1[i]*t.getComponent(j,3)); 166 } 167 } 168 return ans; 169 } 170 174 public Rank4Tensor tensorProduct(Rank3Tensor t) { 175 Rank4Tensor ans=new Rank4Tensor(); 176 for(int k,j,i=0;i<4;i++) { 177 for(j=0;j<4;j++) { 178 for(k=0;k<4;k++) { 179 ans.setComponent(i,j,k,0,rank1[i]*t.getComponent(j,k,0)); 180 ans.setComponent(i,j,k,1,rank1[i]*t.getComponent(j,k,1)); 181 ans.setComponent(i,j,k,2,rank1[i]*t.getComponent(j,k,2)); 182 ans.setComponent(i,j,k,3,rank1[i]*t.getComponent(j,k,3)); 183 } 184 } 185 } 186 return ans; 187 } 188 } 189 190 | Popular Tags |