Source Code Cross Referenced for Rank1Tensor.java in  » Science » JSci » JSci » physics » relativity » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » JSci » JSci.physics.relativity 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package JSci.physics.relativity;
002:
003:        import JSci.GlobalSettings;
004:        import JSci.maths.*;
005:        import JSci.maths.vectors.Double3Vector;
006:
007:        /**
008:         * The Rank1Tensor class encapsulates 1st rank tensors.
009:         * @version 1.0
010:         * @author Mark Hale
011:         */
012:        public class Rank1Tensor extends Tensor {
013:            protected double rank1[];
014:
015:            /**
016:             * Constructs a 1st rank tensor.
017:             */
018:            public Rank1Tensor() {
019:                rank1 = new double[4];
020:            }
021:
022:            /**
023:             * Constructs a 1st rank tensor.
024:             * @param s a scalar
025:             * @param v a 3-vector
026:             */
027:            public Rank1Tensor(double s, Double3Vector v) {
028:                this ();
029:                rank1[0] = s;
030:                rank1[1] = v.getComponent(0);
031:                rank1[2] = v.getComponent(1);
032:                rank1[3] = v.getComponent(2);
033:            }
034:
035:            /**
036:             * Constructs a 1st rank tensor.
037:             * @param s a scalar
038:             * @param v1 1st 3-vector component
039:             * @param v2 2nd 3-vector component
040:             * @param v3 3rd 3-vector component
041:             */
042:            public Rank1Tensor(double s, double v1, double v2, double v3) {
043:                this ();
044:                rank1[0] = s;
045:                rank1[1] = v1;
046:                rank1[2] = v2;
047:                rank1[3] = v3;
048:            }
049:
050:            /**
051:             * Compares two tensors for equality.
052:             * @param a a 1st rank tensor
053:             */
054:            public boolean equals(Object a) {
055:                if (a instanceof  Rank1Tensor) {
056:                    Rank1Tensor v = (Rank1Tensor) a;
057:                    return Math.abs(rank1[0] - v.rank1[0]) <= GlobalSettings.ZERO_TOL
058:                            && Math.abs(rank1[1] - v.rank1[1]) <= GlobalSettings.ZERO_TOL
059:                            && Math.abs(rank1[2] - v.rank1[2]) <= GlobalSettings.ZERO_TOL
060:                            && Math.abs(rank1[3] - v.rank1[3]) <= GlobalSettings.ZERO_TOL;
061:                }
062:                return false;
063:            }
064:
065:            /**
066:             * Returns a comma delimited string representing the value of this tensor.
067:             */
068:            public String toString() {
069:                return new String(rank1[0] + "," + rank1[1] + "," + rank1[2]
070:                        + "," + rank1[3]);
071:            }
072:
073:            /**
074:             * Returns a hashcode for this tensor.
075:             */
076:            public int hashCode() {
077:                return (int) Math.exp(norm());
078:            }
079:
080:            /**
081:             * Returns a component of this tensor.
082:             * @param i 1st index
083:             * @exception DimensionException If attempting to access an invalid component.
084:             */
085:            public double getComponent(int i) {
086:                if (i >= 0 && i < 4)
087:                    return rank1[i];
088:                else
089:                    throw new DimensionException("Invalid component.");
090:            }
091:
092:            /**
093:             * Sets the value of a component of this tensor.
094:             * @param i 1st index
095:             * @param x value
096:             * @exception DimensionException If attempting to access an invalid component.
097:             */
098:            public void setComponent(int i, double x) {
099:                if (i >= 0 && i < 4)
100:                    rank1[i] = x;
101:                else
102:                    throw new DimensionException("Invalid component.");
103:            }
104:
105:            /**
106:             * Returns the norm (invariant).
107:             */
108:            public double norm() {
109:                return Math.sqrt(rank1[0] * rank1[0] - rank1[1] * rank1[1]
110:                        - rank1[2] * rank1[2] - rank1[3] * rank1[3]);
111:            }
112:
113:            //============
114:            // OPERATIONS
115:            //============
116:
117:            // ADDITION
118:
119:            /**
120:             * Returns the addition of this tensor and another.
121:             * @param t a 1st rank tensor
122:             */
123:            public Rank1Tensor add(Rank1Tensor t) {
124:                Rank1Tensor ans = new Rank1Tensor();
125:                ans.rank1[0] = rank1[0] + t.rank1[0];
126:                ans.rank1[1] = rank1[1] + t.rank1[1];
127:                ans.rank1[2] = rank1[2] + t.rank1[2];
128:                ans.rank1[3] = rank1[3] + t.rank1[3];
129:                return ans;
130:            }
131:
132:            // SUBTRACTION
133:
134:            /**
135:             * Returns the subtraction of this tensor by another.
136:             * @param t a 1st rank tensor
137:             */
138:            public Rank1Tensor subtract(Rank1Tensor t) {
139:                Rank1Tensor ans = new Rank1Tensor();
140:                ans.rank1[0] = rank1[0] - t.rank1[0];
141:                ans.rank1[1] = rank1[1] - t.rank1[1];
142:                ans.rank1[2] = rank1[2] - t.rank1[2];
143:                ans.rank1[3] = rank1[3] - t.rank1[3];
144:                return ans;
145:            }
146:
147:            // TENSOR PRODUCT
148:
149:            /**
150:             * Returns the tensor product of this tensor and another.
151:             * @param t a 1st rank tensor
152:             */
153:            public Rank2Tensor tensorProduct(Rank1Tensor t) {
154:                Rank2Tensor ans = new Rank2Tensor();
155:                for (int i = 0; i < 4; i++) {
156:                    ans.setComponent(i, 0, rank1[i] * t.rank1[0]);
157:                    ans.setComponent(i, 1, rank1[i] * t.rank1[1]);
158:                    ans.setComponent(i, 2, rank1[i] * t.rank1[2]);
159:                    ans.setComponent(i, 3, rank1[i] * t.rank1[3]);
160:                }
161:                return ans;
162:            }
163:
164:            /**
165:             * Returns the tensor product of this tensor and another.
166:             * @param t a 2nd rank tensor
167:             */
168:            public Rank3Tensor tensorProduct(Rank2Tensor t) {
169:                Rank3Tensor ans = new Rank3Tensor();
170:                for (int j, i = 0; i < 4; i++) {
171:                    for (j = 0; j < 4; j++) {
172:                        ans.setComponent(i, j, 0, rank1[i]
173:                                * t.getComponent(j, 0));
174:                        ans.setComponent(i, j, 1, rank1[i]
175:                                * t.getComponent(j, 1));
176:                        ans.setComponent(i, j, 2, rank1[i]
177:                                * t.getComponent(j, 2));
178:                        ans.setComponent(i, j, 3, rank1[i]
179:                                * t.getComponent(j, 3));
180:                    }
181:                }
182:                return ans;
183:            }
184:
185:            /**
186:             * Returns the tensor product of this tensor and another.
187:             * @param t a 3rd rank tensor
188:             */
189:            public Rank4Tensor tensorProduct(Rank3Tensor t) {
190:                Rank4Tensor ans = new Rank4Tensor();
191:                for (int k, j, i = 0; i < 4; i++) {
192:                    for (j = 0; j < 4; j++) {
193:                        for (k = 0; k < 4; k++) {
194:                            ans.setComponent(i, j, k, 0, rank1[i]
195:                                    * t.getComponent(j, k, 0));
196:                            ans.setComponent(i, j, k, 1, rank1[i]
197:                                    * t.getComponent(j, k, 1));
198:                            ans.setComponent(i, j, k, 2, rank1[i]
199:                                    * t.getComponent(j, k, 2));
200:                            ans.setComponent(i, j, k, 3, rank1[i]
201:                                    * t.getComponent(j, k, 3));
202:                        }
203:                    }
204:                }
205:                return ans;
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.