ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/test/brains/DirectioanlAtom.cpp
Revision: 1682
Committed: Thu Oct 28 22:34:01 2004 UTC (19 years, 8 months ago) by tim
File size: 3467 byte(s)
Log Message:
More work on StuntDouble, Atom, DirectionalAtom and RigidBody

File Contents

# Content
1 /*
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 void DirectionalAtom::setPrevA(const RotMat3x3d& a) {
43 (snapshotMan_->getPrevSnapshot())->storage_->aMat[localIndex_] = a;
44 (snapshotMan_->getPrevSnapshot())->storage_->unitVector[localIndex_] = a.inverse() * sU_.getColum(2);
45 }
46
47
48 void DirectionalAtom::setA(const RotMat3x3d& a) {
49 (snapshotMan_->getCurrentSnapshot())->storage_->aMat[localIndex_] = a;
50 (snapshotMan_->getCurrentSnapshot())->storage_->unitVector[localIndex_] = a.inverse() * sU_.getColum(2);
51 }
52
53 void DirectionalAtom::setA(const RotMat3x3d& a, int snapshotNo) {
54 (snapshotMan_->getSnapshot(snapshotNo))->storage_->aMat[localIndex_] = a;
55 (snapshotMan_->getSnapshot(snapshotNo))->storage_->unitVector[localIndex_] = a.inverse() * sU_.getColum(2);
56 }
57
58
59
60 void DirectionalAtom::setUnitFrameFromEuler(double phi, double theta, double psi) {
61 sU_.setupRotMat(phi,theta,psi);
62
63 }
64
65 std::vector<double> DirectionalAtom::getGrad() {
66 vector<double> grad(6, 0.0);
67 Vector3d force;
68 Vector3d torque;
69 Vector3d myEuler;
70 double phi, theta, psi;
71 double cphi, sphi, ctheta, stheta;
72 Vector3d ephi;
73 Vector3d etheta;
74 Vector3d epsi;
75
76 force = getFrc();
77 torque =getTrq();
78 myEuler = getA().toEulerAngles();
79
80 phi = myEuler[0];
81 theta = myEuler[1];
82 psi = myEuler[2];
83
84 cphi = cos(phi);
85 sphi = sin(phi);
86 ctheta = cos(theta);
87 stheta = sin(theta);
88
89 // get unit vectors along the phi, theta and psi rotation axes
90
91 ephi[0] = 0.0;
92 ephi[1] = 0.0;
93 ephi[2] = 1.0;
94
95 etheta[0] = cphi;
96 etheta[1] = sphi;
97 etheta[2] = 0.0;
98
99 epsi[0] = stheta * cphi;
100 epsi[1] = stheta * sphi;
101 epsi[2] = ctheta;
102
103 //gradient is equal to -force
104 for (int j = 0 ; j<3; j++)
105 grad[j] = -force[j];
106
107 for (int j = 0; j < 3; j++ ) {
108
109 grad[3] += torque[j]*ephi[j];
110 grad[4] += torque[j]*etheta[j];
111 grad[5] += torque[j]*epsi[j];
112
113 }
114
115 return grad;
116 }
117
118 void DirectionalAtom::accept(BaseVisitor* v) {
119 v->visit(this);
120 }
121
122 }
123