00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef MECHSYS_TENSORS_JACOBIROT_H
00047 #define MECHSYS_TENSORS_JACOBIROT_H
00048
00049 #ifdef HAVE_CONFIG_H
00050 #include "config.h"
00051 #else
00052 #ifndef REAL
00053 #define REAL double
00054 #endif
00055 #endif
00056
00057 #include <cmath>
00058
00059 #include "tensors/tensors.h"
00060
00061 namespace Tensors
00062 {
00063
00068
00069
00078 int JacobiRot(Tensor2 const & T ,
00079 REAL V0[3],
00080 REAL V1[3],
00081 REAL V2[3],
00082 REAL L[3]);
00083
00085
00086 int JacobiRot(Tensor2 const & T ,
00087 REAL L[3]);
00088
00090
00091
00093
00094
00095 inline int JacobiRot(Tensor2 const & T, REAL V0[3], REAL V1[3], REAL V2[3], REAL L[3])
00096 {
00097 const REAL maxIt=30;
00098 const REAL errTol=1.0e-15;
00099 const REAL ZERO=1.0e-10;
00100
00101 REAL UT[3];
00102 REAL th;
00103 REAL c;
00104 REAL s;
00105 REAL cc;
00106 REAL ss;
00107 REAL t;
00108 REAL Temp;
00109 REAL TM[3];
00110 REAL sq2=sqrt(2.0);
00111 REAL sumUT;
00112 int it;
00113 REAL h;
00114
00115
00116 L[0]=T(0); L[1]=T(1); L[2]=T(2);
00117
00118
00119 UT[0]=T(3)/sq2; UT[1]=T(4)/sq2; UT[2]=T(5)/sq2;
00120
00121
00122 V0[0]=1.0; V1[0]=0.0; V2[0]=0.0;
00123 V0[1]=0.0; V1[1]=1.0; V2[1]=0.0;
00124 V0[2]=0.0; V1[2]=0.0; V2[2]=1.0;
00125
00126
00127 for (it=1; it<=maxIt; ++it)
00128 {
00129
00130 sumUT = fabs(UT[0])+fabs(UT[1])+fabs(UT[2]);
00131 if (sumUT<=errTol) return it;
00132
00133
00134 h=L[0]-L[1];
00135 if (fabs(h)<ZERO) t=1.0;
00136 else
00137 {
00138 th=0.5*h/UT[0];
00139 t=1.0/(fabs(th)+sqrt(th*th+1.0));
00140 if (th<0.0) t=-t;
00141 }
00142 c = 1.0/sqrt(1.0+t*t);
00143 s = c*t;
00144 cc = c*c;
00145 ss = s*s;
00146
00147 Temp = cc*L[0] + 2.0*c*s*UT[0] + ss*L[1];
00148 L[1] = ss*L[0] - 2.0*c*s*UT[0] + cc*L[1];
00149 L[0] = Temp;
00150 UT[0] = 0.0;
00151 Temp = c*UT[2] + s*UT[1];
00152 UT[1] = c*UT[1] - s*UT[2];
00153 UT[2] = Temp;
00154
00155 TM[0] = s*V1[0] + c*V0[0];
00156 TM[1] = s*V1[1] + c*V0[1];
00157 TM[2] = s*V1[2] + c*V0[2];
00158 V1[0] = c*V1[0] - s*V0[0];
00159 V1[1] = c*V1[1] - s*V0[1];
00160 V1[2] = c*V1[2] - s*V0[2];
00161 V0[0] = TM[0];
00162 V0[1] = TM[1];
00163 V0[2] = TM[2];
00164
00165
00166 h = L[1]-L[2];
00167 if (fabs(h)<ZERO) t=1.0;
00168 else
00169 {
00170 th=0.5*h/UT[1];
00171 t=1.0/(fabs(th)+sqrt(th*th+1.0));
00172 if (th<0.0) t=-t;
00173 }
00174 c = 1.0/sqrt(1.0+t*t);
00175 s = c*t;
00176 cc = c*c;
00177 ss = s*s;
00178
00179 Temp = cc*L[1] + 2.0*c*s*UT[1] + ss*L[2];
00180 L[2] = ss*L[1] - 2.0*c*s*UT[1] + cc*L[2];
00181 L[1] = Temp;
00182 UT[1] = 0.0;
00183 Temp = c*UT[0] + s*UT[2];
00184 UT[2] = c*UT[2] - s*UT[0];
00185 UT[0] = Temp;
00186
00187 TM[1] = s*V2[1] + c*V1[1];
00188 TM[2] = s*V2[2] + c*V1[2];
00189 TM[0] = s*V2[0] + c*V1[0];
00190 V2[1] = c*V2[1] - s*V1[1];
00191 V2[2] = c*V2[2] - s*V1[2];
00192 V2[0] = c*V2[0] - s*V1[0];
00193 V1[1] = TM[1];
00194 V1[2] = TM[2];
00195 V1[0] = TM[0];
00196
00197
00198 h = L[0]-L[2];
00199 if (fabs(h)<ZERO) t=1.0;
00200 else
00201 {
00202 th=0.5*h/UT[2];
00203 t=1.0/(fabs(th)+sqrt(th*th+1.0));
00204 if (th<0.0) t=-t;
00205 }
00206 c = 1.0/sqrt(1.0+t*t);
00207 s = c*t;
00208 cc = c*c;
00209 ss = s*s;
00210
00211 Temp = cc*L[0] + 2.0*c*s*UT[2] + ss*L[2];
00212 L[2] = ss*L[0] - 2.0*c*s*UT[2] + cc*L[2];
00213 L[0] = Temp;
00214 UT[2] = 0.0;
00215 Temp = c*UT[0] + s*UT[1];
00216 UT[1] = c*UT[1] - s*UT[0];
00217 UT[0] = Temp;
00218
00219 TM[0] = s*V2[0] + c*V0[0];
00220 TM[2] = s*V2[2] + c*V0[2];
00221 TM[1] = s*V2[1] + c*V0[1];
00222 V2[0] = c*V2[0] - s*V0[0];
00223 V2[2] = c*V2[2] - s*V0[2];
00224 V2[1] = c*V2[1] - s*V0[1];
00225 V0[0] = TM[0];
00226 V0[2] = TM[2];
00227 V0[1] = TM[1];
00228 }
00229
00230 return -1;
00231
00232 }
00233
00234 inline int JacobiRot(Tensor2 const & T, REAL L[3])
00235 {
00236 const REAL maxIt=30;
00237 const REAL errTol=1.0e-15;
00238 const REAL ZERO=1.0e-10;
00239
00240 REAL UT[3];
00241 REAL th;
00242 REAL c;
00243 REAL s;
00244 REAL cc;
00245 REAL ss;
00246 REAL t;
00247 REAL Temp;
00248 REAL sq2=sqrt(2.0);
00249 REAL sumUT;
00250 int it;
00251 REAL h;
00252
00253
00254 L[0]=T(0); L[1]=T(1); L[2]=T(2);
00255
00256
00257 UT[0]=T(3)/sq2; UT[1]=T(4)/sq2; UT[2]=T(5)/sq2;
00258
00259
00260 for (it=1; it<=maxIt; ++it)
00261 {
00262
00263 sumUT = fabs(UT[0])+fabs(UT[1])+fabs(UT[2]);
00264 if (sumUT<=errTol) return it;
00265
00266
00267 h=L[0]-L[1];
00268 if (fabs(h)<ZERO) t=1.0;
00269 else
00270 {
00271 th=0.5*h/UT[0];
00272 t=1.0/(fabs(th)+sqrt(th*th+1.0));
00273 if (th<0.0) t=-t;
00274 }
00275 c = 1.0/sqrt(1.0+t*t);
00276 s = c*t;
00277 cc = c*c;
00278 ss = s*s;
00279
00280 Temp = cc*L[0] + 2.0*c*s*UT[0] + ss*L[1];
00281 L[1] = ss*L[0] - 2.0*c*s*UT[0] + cc*L[1];
00282 L[0] = Temp;
00283 UT[0] = 0.0;
00284 Temp = c*UT[2] + s*UT[1];
00285 UT[1] = c*UT[1] - s*UT[2];
00286 UT[2] = Temp;
00287
00288
00289 h = L[1]-L[2];
00290 if (fabs(h)<ZERO) t=1.0;
00291 else
00292 {
00293 th=0.5*h/UT[1];
00294 t=1.0/(fabs(th)+sqrt(th*th+1.0));
00295 if (th<0.0) t=-t;
00296 }
00297 c = 1.0/sqrt(1.0+t*t);
00298 s = c*t;
00299 cc = c*c;
00300 ss = s*s;
00301
00302 Temp = cc*L[1] + 2.0*c*s*UT[1] + ss*L[2];
00303 L[2] = ss*L[1] - 2.0*c*s*UT[1] + cc*L[2];
00304 L[1] = Temp;
00305 UT[1] = 0.0;
00306 Temp = c*UT[0] + s*UT[2];
00307 UT[2] = c*UT[2] - s*UT[0];
00308 UT[0] = Temp;
00309
00310
00311 h = L[0]-L[2];
00312 if (fabs(h)<ZERO) t=1.0;
00313 else
00314 {
00315 th=0.5*h/UT[2];
00316 t=1.0/(fabs(th)+sqrt(th*th+1.0));
00317 if (th<0.0) t=-t;
00318 }
00319 c = 1.0/sqrt(1.0+t*t);
00320 s = c*t;
00321 cc = c*c;
00322 ss = s*s;
00323
00324 Temp = cc*L[0] + 2.0*c*s*UT[2] + ss*L[2];
00325 L[2] = ss*L[0] - 2.0*c*s*UT[2] + cc*L[2];
00326 L[0] = Temp;
00327 UT[2] = 0.0;
00328 Temp = c*UT[0] + s*UT[1];
00329 UT[1] = c*UT[1] - s*UT[0];
00330 UT[0] = Temp;
00331 }
00332
00333 return -1;
00334
00335 }
00336
00337 };
00338
00339 #endif // MECHSYS_TENSORS_JACOBIROT_H
00340
00341