1 |
tim |
147 |
/* |
2 |
|
|
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
|
|
* |
4 |
|
|
* Contact: oopse@oopse.org |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public License |
8 |
|
|
* as published by the Free Software Foundation; either version 2.1 |
9 |
|
|
* of the License, or (at your option) any later version. |
10 |
|
|
* All we ask is that proper credit is given for our work, which includes |
11 |
|
|
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
|
|
* of your source code files, and to any copyright notice that you may distribute |
13 |
|
|
* with programs based on this work. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU Lesser General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
21 |
|
|
* along with this program; if not, write to the Free Software |
22 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
|
|
* |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
#include "primitives/DirectionalAtom.hpp" |
27 |
|
|
|
28 |
|
|
namespace oopse { |
29 |
|
|
|
30 |
|
|
DirectionalAtom::DirectionalAtom() : objType_(otDAtom), storage_(&Snapshot::atomData){ |
31 |
|
|
|
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
Mat3x3d DirectionalAtom::getI() { |
35 |
|
|
return inertiaTensor_; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
void DirectionalAtom::setI(Mat3x3d& I) { |
39 |
|
|
inertiaTensor_ = I; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
std::vector<double> DirectionalAtom::getGrad() { |
43 |
|
|
vector<double> grad(6, 0.0); |
44 |
|
|
Vector3d force; |
45 |
|
|
Vector3d torque; |
46 |
|
|
Vector3d myEuler; |
47 |
|
|
double phi, theta, psi; |
48 |
|
|
double cphi, sphi, ctheta, stheta; |
49 |
|
|
Vector3d ephi; |
50 |
|
|
Vector3d etheta; |
51 |
|
|
Vector3d epsi; |
52 |
|
|
|
53 |
|
|
force = getFrc(); |
54 |
|
|
torque =getTrq(); |
55 |
|
|
myEuler = getA().toEulerAngles(); |
56 |
|
|
|
57 |
|
|
phi = myEuler[0]; |
58 |
|
|
theta = myEuler[1]; |
59 |
|
|
psi = myEuler[2]; |
60 |
|
|
|
61 |
|
|
cphi = cos(phi); |
62 |
|
|
sphi = sin(phi); |
63 |
|
|
ctheta = cos(theta); |
64 |
|
|
stheta = sin(theta); |
65 |
|
|
|
66 |
|
|
// get unit vectors along the phi, theta and psi rotation axes |
67 |
|
|
|
68 |
|
|
ephi[0] = 0.0; |
69 |
|
|
ephi[1] = 0.0; |
70 |
|
|
ephi[2] = 1.0; |
71 |
|
|
|
72 |
|
|
etheta[0] = cphi; |
73 |
|
|
etheta[1] = sphi; |
74 |
|
|
etheta[2] = 0.0; |
75 |
|
|
|
76 |
|
|
epsi[0] = stheta * cphi; |
77 |
|
|
epsi[1] = stheta * sphi; |
78 |
|
|
epsi[2] = ctheta; |
79 |
|
|
|
80 |
|
|
//gradient is equal to -force |
81 |
|
|
for (int j = 0 ; j<3; j++) |
82 |
|
|
grad[j] = -force[j]; |
83 |
|
|
|
84 |
|
|
for (int j = 0; j < 3; j++ ) { |
85 |
|
|
|
86 |
|
|
grad[3] += torque[j]*ephi[j]; |
87 |
|
|
grad[4] += torque[j]*etheta[j]; |
88 |
|
|
grad[5] += torque[j]*epsi[j]; |
89 |
|
|
|
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
return grad; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
void DirectionalAtom::accept(BaseVisitor* v) { |
96 |
|
|
v->visit(this); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
} |
100 |
|
|
|