1 |
|
#include <math.h> |
2 |
|
|
3 |
|
#include "Atom.hpp" |
4 |
+ |
#include "DirectionalAtom.hpp" |
5 |
|
#include "simError.h" |
6 |
+ |
#include "MatVec3.h" |
7 |
|
|
6 |
– |
|
7 |
– |
|
8 |
|
void DirectionalAtom::zeroForces() { |
9 |
|
if( hasCoords ){ |
10 |
< |
frc[offsetX] = 0.0; |
11 |
< |
frc[offsetY] = 0.0; |
12 |
< |
frc[offsetZ] = 0.0; |
10 |
> |
|
11 |
> |
Atom::zeroForces(); |
12 |
|
|
13 |
|
trq[offsetX] = 0.0; |
14 |
|
trq[offsetY] = 0.0; |
35 |
|
&trq, |
36 |
|
&Amat, |
37 |
|
&mu, |
38 |
< |
&ul ); |
38 |
> |
&ul, |
39 |
> |
&quat); |
40 |
|
} |
41 |
|
else{ |
42 |
|
sprintf( painCave.errMsg, |
48 |
|
|
49 |
|
hasCoords = true; |
50 |
|
|
51 |
– |
*mu = myMu; |
52 |
– |
|
51 |
|
} |
52 |
|
|
55 |
– |
double DirectionalAtom::getMu( void ) { |
56 |
– |
|
57 |
– |
if( hasCoords ){ |
58 |
– |
return *mu; |
59 |
– |
} |
60 |
– |
else{ |
61 |
– |
return myMu; |
62 |
– |
} |
63 |
– |
} |
64 |
– |
|
65 |
– |
void DirectionalAtom::setMu( double the_mu ) { |
66 |
– |
|
67 |
– |
if( hasCoords ){ |
68 |
– |
*mu = the_mu; |
69 |
– |
myMu = the_mu; |
70 |
– |
} |
71 |
– |
else{ |
72 |
– |
myMu = the_mu; |
73 |
– |
} |
74 |
– |
} |
75 |
– |
|
53 |
|
void DirectionalAtom::setA( double the_A[3][3] ){ |
54 |
|
|
55 |
|
if( hasCoords ){ |
69 |
|
} |
70 |
|
} |
71 |
|
|
72 |
< |
void DirectionalAtom::setI( double the_I[3][3] ){ |
72 |
> |
void DirectionalAtom::setI( double the_I[3][3] ){ |
73 |
|
|
74 |
|
Ixx = the_I[0][0]; Ixy = the_I[0][1]; Ixz = the_I[0][2]; |
75 |
|
Iyx = the_I[1][0]; Iyy = the_I[1][1]; Iyz = the_I[1][2]; |
159 |
|
|
160 |
|
void DirectionalAtom::getU( double the_u[3] ){ |
161 |
|
|
162 |
< |
the_u[0] = sux; |
163 |
< |
the_u[1] = suy; |
164 |
< |
the_u[2] = suz; |
165 |
< |
|
162 |
> |
the_u[0] = sU[2][0]; |
163 |
> |
the_u[1] = sU[2][1]; |
164 |
> |
the_u[2] = sU[2][2]; |
165 |
> |
|
166 |
|
this->body2Lab( the_u ); |
167 |
|
} |
168 |
|
|
224 |
|
} |
225 |
|
} |
226 |
|
|
227 |
+ |
void DirectionalAtom::setUnitFrameFromEuler(double phi, |
228 |
+ |
double theta, |
229 |
+ |
double psi) { |
230 |
|
|
231 |
+ |
double myA[3][3]; |
232 |
+ |
double uFrame[3][3]; |
233 |
+ |
double len; |
234 |
+ |
int i, j; |
235 |
+ |
|
236 |
+ |
myA[0][0] = (cos(phi) * cos(psi)) - (sin(phi) * cos(theta) * sin(psi)); |
237 |
+ |
myA[0][1] = (sin(phi) * cos(psi)) + (cos(phi) * cos(theta) * sin(psi)); |
238 |
+ |
myA[0][2] = sin(theta) * sin(psi); |
239 |
+ |
|
240 |
+ |
myA[1][0] = -(cos(phi) * sin(psi)) - (sin(phi) * cos(theta) * cos(psi)); |
241 |
+ |
myA[1][1] = -(sin(phi) * sin(psi)) + (cos(phi) * cos(theta) * cos(psi)); |
242 |
+ |
myA[1][2] = sin(theta) * cos(psi); |
243 |
+ |
|
244 |
+ |
myA[2][0] = sin(phi) * sin(theta); |
245 |
+ |
myA[2][1] = -cos(phi) * sin(theta); |
246 |
+ |
myA[2][2] = cos(theta); |
247 |
+ |
|
248 |
+ |
// Make the unit Frame: |
249 |
+ |
|
250 |
+ |
for (i=0; i < 3; i++) |
251 |
+ |
for (j=0; j < 3; j++) |
252 |
+ |
uFrame[i][j] = 0.0; |
253 |
+ |
|
254 |
+ |
for (i=0; i < 3; i++) |
255 |
+ |
uFrame[i][i] = 1.0; |
256 |
+ |
|
257 |
+ |
// rotate by the given rotation matrix: |
258 |
+ |
|
259 |
+ |
matMul3(myA, uFrame, sU); |
260 |
+ |
|
261 |
+ |
// renormalize column vectors: |
262 |
+ |
|
263 |
+ |
for (i=0; i < 3; i++) { |
264 |
+ |
len = 0.0; |
265 |
+ |
for (j = 0; j < 3; j++) { |
266 |
+ |
len += sU[i][j]*sU[i][j]; |
267 |
+ |
} |
268 |
+ |
len = sqrt(len); |
269 |
+ |
for (j = 0; j < 3; j++) { |
270 |
+ |
sU[i][j] /= len; |
271 |
+ |
} |
272 |
+ |
} |
273 |
+ |
|
274 |
+ |
// sU now contains the coordinates of the 'special' frame; |
275 |
+ |
|
276 |
+ |
} |
277 |
+ |
|
278 |
|
void DirectionalAtom::setEuler( double phi, double theta, double psi ){ |
279 |
|
|
280 |
|
if( hasCoords ){ |
320 |
|
|
321 |
|
sprintf( painCave.errMsg, |
322 |
|
"Attempt to convert lab2body for atom %d before coords set.\n", |
323 |
+ |
index ); |
324 |
+ |
painCave.isFatal = 1; |
325 |
+ |
simError(); |
326 |
+ |
} |
327 |
+ |
|
328 |
+ |
} |
329 |
+ |
|
330 |
+ |
void DirectionalAtom::rotateBy( double by_A[3][3]) { |
331 |
+ |
|
332 |
+ |
// Check this |
333 |
+ |
|
334 |
+ |
double r00, r01, r02, r10, r11, r12, r20, r21, r22; |
335 |
+ |
|
336 |
+ |
if( hasCoords ){ |
337 |
+ |
|
338 |
+ |
r00 = by_A[0][0]*Amat[Axx] + by_A[0][1]*Amat[Ayx] + by_A[0][2]*Amat[Azx]; |
339 |
+ |
r01 = by_A[0][0]*Amat[Axy] + by_A[0][1]*Amat[Ayy] + by_A[0][2]*Amat[Azy]; |
340 |
+ |
r02 = by_A[0][0]*Amat[Axz] + by_A[0][1]*Amat[Ayz] + by_A[0][2]*Amat[Azz]; |
341 |
+ |
|
342 |
+ |
r10 = by_A[1][0]*Amat[Axx] + by_A[1][1]*Amat[Ayx] + by_A[1][2]*Amat[Azx]; |
343 |
+ |
r11 = by_A[1][0]*Amat[Axy] + by_A[1][1]*Amat[Ayy] + by_A[1][2]*Amat[Azy]; |
344 |
+ |
r12 = by_A[1][0]*Amat[Axz] + by_A[1][1]*Amat[Ayz] + by_A[1][2]*Amat[Azz]; |
345 |
+ |
|
346 |
+ |
r20 = by_A[2][0]*Amat[Axx] + by_A[2][1]*Amat[Ayx] + by_A[2][2]*Amat[Azx]; |
347 |
+ |
r21 = by_A[2][0]*Amat[Axy] + by_A[2][1]*Amat[Ayy] + by_A[2][2]*Amat[Azy]; |
348 |
+ |
r22 = by_A[2][0]*Amat[Axz] + by_A[2][1]*Amat[Ayz] + by_A[2][2]*Amat[Azz]; |
349 |
+ |
|
350 |
+ |
Amat[Axx] = r00; Amat[Axy] = r01; Amat[Axz] = r02; |
351 |
+ |
Amat[Ayx] = r10; Amat[Ayy] = r11; Amat[Ayz] = r12; |
352 |
+ |
Amat[Azx] = r20; Amat[Azy] = r21; Amat[Azz] = r22; |
353 |
+ |
|
354 |
+ |
} |
355 |
+ |
else{ |
356 |
+ |
|
357 |
+ |
sprintf( painCave.errMsg, |
358 |
+ |
"Attempt to rotate frame for atom %d before coords set.\n", |
359 |
|
index ); |
360 |
|
painCave.isFatal = 1; |
361 |
|
simError(); |
363 |
|
|
364 |
|
} |
365 |
|
|
366 |
+ |
|
367 |
|
void DirectionalAtom::body2Lab( double r[3] ){ |
368 |
|
|
369 |
|
double rb[3]; // the body frame vector |
390 |
|
void DirectionalAtom::updateU( void ){ |
391 |
|
|
392 |
|
if( hasCoords ){ |
393 |
< |
ul[offsetX] = (Amat[Axx] * sux) + (Amat[Ayx] * suy) + (Amat[Azx] * suz); |
394 |
< |
ul[offsetY] = (Amat[Axy] * sux) + (Amat[Ayy] * suy) + (Amat[Azy] * suz); |
395 |
< |
ul[offsetZ] = (Amat[Axz] * sux) + (Amat[Ayz] * suy) + (Amat[Azz] * suz); |
393 |
> |
ul[offsetX] = (Amat[Axx] * sU[2][0]) + |
394 |
> |
(Amat[Ayx] * sU[2][1]) + (Amat[Azx] * sU[2][2]); |
395 |
> |
ul[offsetY] = (Amat[Axy] * sU[2][0]) + |
396 |
> |
(Amat[Ayy] * sU[2][1]) + (Amat[Azy] * sU[2][2]); |
397 |
> |
ul[offsetZ] = (Amat[Axz] * sU[2][0]) + |
398 |
> |
(Amat[Ayz] * sU[2][1]) + (Amat[Azz] * sU[2][2]); |
399 |
|
} |
400 |
|
else{ |
401 |
|
|
432 |
|
|
433 |
|
sprintf( painCave.errMsg, |
434 |
|
"Attempt to get Trq for atom %d before coords set.\n", |
435 |
+ |
index ); |
436 |
+ |
painCave.isFatal = 1; |
437 |
+ |
simError(); |
438 |
+ |
} |
439 |
+ |
} |
440 |
+ |
|
441 |
+ |
void DirectionalAtom::setTrq( double theT[3] ){ |
442 |
+ |
|
443 |
+ |
if( hasCoords ){ |
444 |
+ |
trq[offsetX] = theT[0]; |
445 |
+ |
trq[offsetY] = theT[1]; |
446 |
+ |
trq[offsetZ] = theT[2]; |
447 |
+ |
} |
448 |
+ |
else{ |
449 |
+ |
|
450 |
+ |
sprintf( painCave.errMsg, |
451 |
+ |
"Attempt to add Trq for atom %d before coords set.\n", |
452 |
|
index ); |
453 |
|
painCave.isFatal = 1; |
454 |
|
simError(); |
557 |
|
|
558 |
|
|
559 |
|
double phi,theta,psi,eps; |
560 |
< |
double pi; |
477 |
< |
double cphi,ctheta,cpsi; |
478 |
< |
double sphi,stheta,spsi; |
479 |
< |
double b[3]; |
480 |
< |
int flip[3]; |
560 |
> |
double ctheta,stheta; |
561 |
|
|
562 |
|
// set the tolerance for Euler angles and rotation elements |
563 |
|
|
599 |
|
return; |
600 |
|
} |
601 |
|
|
602 |
+ |
double DirectionalAtom::getZangle( ){ |
603 |
+ |
|
604 |
+ |
if( hasCoords ){ |
605 |
+ |
return zAngle; |
606 |
+ |
} |
607 |
+ |
else{ |
608 |
+ |
|
609 |
+ |
sprintf( painCave.errMsg, |
610 |
+ |
"Attempt to get zAngle for atom %d before coords set.\n", |
611 |
+ |
index ); |
612 |
+ |
painCave.isFatal = 1; |
613 |
+ |
simError(); |
614 |
+ |
return 0; |
615 |
+ |
} |
616 |
+ |
} |
617 |
+ |
|
618 |
+ |
void DirectionalAtom::setZangle( double zAng ){ |
619 |
+ |
|
620 |
+ |
if( hasCoords ){ |
621 |
+ |
zAngle = zAng; |
622 |
+ |
} |
623 |
+ |
else{ |
624 |
+ |
|
625 |
+ |
sprintf( painCave.errMsg, |
626 |
+ |
"Attempt to set zAngle for atom %d before coords set.\n", |
627 |
+ |
index ); |
628 |
+ |
painCave.isFatal = 1; |
629 |
+ |
simError(); |
630 |
+ |
} |
631 |
+ |
} |
632 |
+ |
|
633 |
+ |
void DirectionalAtom::addZangle( double zAng ){ |
634 |
+ |
|
635 |
+ |
if( hasCoords ){ |
636 |
+ |
zAngle += zAng; |
637 |
+ |
} |
638 |
+ |
else{ |
639 |
+ |
|
640 |
+ |
sprintf( painCave.errMsg, |
641 |
+ |
"Attempt to add zAngle to atom %d before coords set.\n", |
642 |
+ |
index ); |
643 |
+ |
painCave.isFatal = 1; |
644 |
+ |
simError(); |
645 |
+ |
} |
646 |
+ |
} |
647 |
+ |
|
648 |
|
double DirectionalAtom::max(double x, double y) { |
649 |
|
return (x > y) ? x : y; |
650 |
|
} |