1 |
< |
#ifndef __RIGIDBODY_HPP__ |
2 |
< |
#define __RIGIDBODY_HPP__ |
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 <vector> |
27 |
< |
//#include "primitives/Atom.hpp" |
28 |
< |
//#include "types/AtomStamp.hpp" |
29 |
< |
#include "types/RigidBodyStamp.hpp" |
30 |
< |
#include "primitives/StuntDouble.hpp" |
31 |
< |
using namespace std; |
26 |
> |
/** |
27 |
> |
* @file RigidBody.hpp |
28 |
> |
* @author tlin |
29 |
> |
* @date 10/23/2004 |
30 |
> |
* @version 1.0 |
31 |
> |
*/ |
32 |
|
|
33 |
< |
class Atom; |
34 |
< |
class AtomStamp; |
33 |
> |
#ifndef PRIMITIVES_RIGIDBODY_HPP |
34 |
> |
#define PRIMITIVES_RIGIDBODY_HPP |
35 |
|
|
36 |
< |
typedef struct { |
15 |
< |
double vec[3]; |
16 |
< |
double& operator[](int index) {return vec[index];} |
17 |
< |
} vec3; |
36 |
> |
#include <vector> |
37 |
|
|
38 |
< |
typedef struct { |
39 |
< |
double mat[3][3]; |
40 |
< |
double* operator[](int index) {return mat[index];} |
41 |
< |
} mat3x3; |
23 |
< |
|
38 |
> |
#include "primitives/StuntDouble.hpp" |
39 |
> |
#include "primitives/DirectionalAtom.hpp" |
40 |
> |
#include "types/AtomStamp.hpp" |
41 |
> |
namespace oopse{ |
42 |
|
class RigidBody : public StuntDouble { |
43 |
+ |
public: |
44 |
+ |
RigidBody(); |
45 |
|
|
46 |
< |
public: |
47 |
< |
|
48 |
< |
RigidBody(); |
49 |
< |
//RigidBody(const RigidBody& rb); |
50 |
< |
|
31 |
< |
virtual ~RigidBody(); |
32 |
< |
|
33 |
< |
void addAtom(Atom* at, AtomStamp* ats); |
46 |
> |
virtual std::string getType() { return name_;} |
47 |
> |
|
48 |
> |
/** Sets the name of this stuntdouble*/ |
49 |
> |
virtual void setType(const std::string& name) { name_ = name;} |
50 |
> |
|
51 |
|
|
52 |
< |
void getPos( double theP[3] ); |
53 |
< |
void setPos( double theP[3] ); |
52 |
> |
/** |
53 |
> |
* Sets the previous rotation matrix of this stuntdouble |
54 |
> |
* @param a new rotation matrix |
55 |
> |
*/ |
56 |
> |
virtual void setPrevA(const RotMat3x3d& a); |
57 |
> |
|
58 |
> |
/** |
59 |
> |
* Sets the current rotation matrix of this stuntdouble |
60 |
> |
* @param a new rotation matrix |
61 |
> |
* @note setA will not change the position and rotation matrix of Directional atoms belong to |
62 |
> |
* this rigidbody. If you want to do that, use #updateAtoms |
63 |
> |
*/ |
64 |
> |
virtual void setA(const RotMat3x3d& a); |
65 |
> |
/** |
66 |
> |
* Sets the rotation matrix of this stuntdouble in specified snapshot |
67 |
> |
* @param a rotation matrix to be set |
68 |
> |
* @param snapshotNo |
69 |
> |
* @see #getA |
70 |
> |
*/ |
71 |
> |
virtual void setA(const RotMat3x3d& a, int snapshotNo); |
72 |
|
|
73 |
< |
void getVel( double theV[3] ); |
74 |
< |
void setVel( double theV[3] ); |
73 |
> |
/** |
74 |
> |
* Returns the inertia tensor of this stuntdouble |
75 |
> |
* @return the inertia tensor of this stuntdouble |
76 |
> |
*/ |
77 |
> |
virtual Mat3x3d getI(); |
78 |
|
|
41 |
– |
void getFrc( double theF[3] ); |
42 |
– |
void addFrc( double theF[3] ); |
43 |
– |
void zeroForces(); |
44 |
– |
|
45 |
– |
virtual bool isLinear() {return is_linear;} |
46 |
– |
virtual int linearAxis() {return linear_axis;} |
79 |
|
|
80 |
< |
double getMass( void ) { return mass; } |
80 |
> |
/** Sets the internal unit frame of this stuntdouble by three euler angles */ |
81 |
> |
void setElectroFrameFromEuler(double phi, double theta, double psi); |
82 |
> |
|
83 |
> |
/** |
84 |
> |
* Returns the gradient of this stuntdouble |
85 |
> |
* @return the inertia tensor of this stuntdouble |
86 |
> |
* @see #setI |
87 |
> |
*/ |
88 |
> |
virtual std::vector<double> getGrad(); |
89 |
|
|
90 |
< |
void printAmatIndex( void ); |
51 |
< |
void setEuler( double phi, double theta, double psi ); |
52 |
< |
void getQ( double the_q[4] ); // get the quanternions |
53 |
< |
void setQ( double the_q[4] ); |
90 |
> |
virtual void accept(BaseVisitor* v); |
91 |
|
|
92 |
< |
void getA( double the_A[3][3] ); // get the full rotation matrix |
56 |
< |
void setA( double the_A[3][3] ); |
92 |
> |
void addAtom(Atom* at, AtomStamp* ats); |
93 |
|
|
94 |
< |
void getJ( double theJ[3] ); |
95 |
< |
void setJ( double theJ[3] ); |
94 |
> |
/** calculate the reference coordinates */ |
95 |
> |
void calcRefCoords(); |
96 |
|
|
97 |
< |
virtual void setType(char* type) {strcpy(rbName, type);} |
98 |
< |
virtual char* getType() { return rbName;} |
97 |
> |
/** Convert Atomic forces and torques to total forces and torques */ |
98 |
> |
void calcForcesAndTorques(); |
99 |
|
|
100 |
< |
void getTrq( double theT[3] ); |
101 |
< |
void addTrq( double theT[3] ); |
100 |
> |
/** update the positions of atoms belong to this rigidbody */ |
101 |
> |
void updateAtoms(); |
102 |
|
|
103 |
< |
void getI( double the_I[3][3] ); |
68 |
< |
void lab2Body( double r[3] ); |
69 |
< |
void body2Lab( double r[3] ); |
103 |
> |
Atom* beginAtom(std::vector<Atom*>::iterator& i); |
104 |
|
|
105 |
< |
double getZangle( ); |
72 |
< |
void setZangle( double zAng ); |
73 |
< |
void addZangle( double zAng ); |
105 |
> |
Atom* nextAtom(std::vector<Atom*>::iterator& i); |
106 |
|
|
107 |
< |
void calcRefCoords( void ); |
108 |
< |
void doEulerToRotMat(vec3 &euler, mat3x3 &myA ); |
109 |
< |
void calcForcesAndTorques( void ); |
110 |
< |
void updateAtoms( void ); |
107 |
> |
std::vector<Atom*>::iterator getBeginAtomIter() { |
108 |
> |
return atoms_.begin(); |
109 |
> |
} |
110 |
> |
|
111 |
> |
std::vector<Atom*>::iterator getEndAtomIter() { |
112 |
> |
return atoms_.end(); |
113 |
> |
} |
114 |
|
|
115 |
< |
//void yourAtomsHaveMoved( void ); |
115 |
> |
/** |
116 |
> |
* Returns the atoms of this rigid body |
117 |
> |
* @return the atoms of this rigid body in a vector |
118 |
> |
* @deprecate |
119 |
> |
*/ |
120 |
> |
std::vector<Atom*> getAtoms() { |
121 |
> |
return atoms_; |
122 |
> |
} |
123 |
|
|
124 |
< |
// Four functions added for derivatives with respect to Euler Angles: |
125 |
< |
// (Needed for minimization routines): |
124 |
> |
/** |
125 |
> |
* Returns the number of atoms in this rigid body |
126 |
> |
* @return the number of atoms in this rigid body |
127 |
> |
*/ |
128 |
> |
int getNumAtoms() { |
129 |
> |
return atoms_.size(); |
130 |
> |
} |
131 |
|
|
132 |
< |
void getGrad(double gradient[6] ); |
133 |
< |
void getEulerAngles( double myEuler[3] ); |
134 |
< |
|
135 |
< |
double max(double x, double y); |
136 |
< |
double min(double x, double y); |
132 |
> |
/** |
133 |
> |
* Return the position of atom which belongs to this rigid body. |
134 |
> |
* @return true if index is valid otherwise return false |
135 |
> |
* @param pos the position of atom which will be set on return if index is valid |
136 |
> |
* @param index the index of the atom in rigid body's private data member atoms_ |
137 |
> |
*/ |
138 |
> |
bool getAtomPos(Vector3d& pos, unsigned int index); |
139 |
|
|
140 |
+ |
/** |
141 |
+ |
* Return the position of atom which belongs to this rigid body. |
142 |
+ |
* @return true if atom belongs to this rigid body,otherwise return false |
143 |
+ |
* @param pos position of atom which will be set on return if atom belongs to this rigid body |
144 |
+ |
* @param atom the pointer to an atom |
145 |
+ |
*/ |
146 |
+ |
bool getAtomPos(Vector3d& pos, Atom* atom); |
147 |
|
|
148 |
< |
// utility routines |
148 |
> |
/** |
149 |
> |
* Return the velocity of atom which belongs to this rigid body. |
150 |
> |
* @return true if index is valid otherwise return false |
151 |
> |
* @param vel the velocity of atom which will be set on return if index is valid |
152 |
> |
* @param index the index of the atom in rigid body's private data member atoms_ |
153 |
> |
*/ |
154 |
> |
bool getAtomVel(Vector3d& vel, unsigned int index); |
155 |
|
|
156 |
< |
void findCOM( void ); |
156 |
> |
/** |
157 |
> |
* Return the velocity of atom which belongs to this rigid body. |
158 |
> |
* @return true if atom belongs to this rigid body,otherwise return false |
159 |
> |
* @param vel velocity of atom which will be set on return if atom belongs to this rigid body |
160 |
> |
* @param atom the pointer to an atom |
161 |
> |
*/ |
162 |
> |
bool getAtomVel(Vector3d& vel, Atom*); |
163 |
|
|
164 |
< |
virtual void accept(BaseVisitor* v); |
164 |
> |
/** |
165 |
> |
* Return the reference coordinate of atom which belongs to this rigid body. |
166 |
> |
* @return true if index is valid otherwise return false |
167 |
> |
* @param coor the reference coordinate of atom which will be set on return if index is valid |
168 |
> |
* @param index the index of the atom in rigid body's private data member atoms_ |
169 |
> |
*/ |
170 |
> |
bool getAtomRefCoor(Vector3d& coor, unsigned int index); |
171 |
|
|
172 |
< |
vector<Atom*> getAtoms() { return myAtoms;} |
173 |
< |
int getNumAtoms() {return myAtoms.size();} |
172 |
> |
/** |
173 |
> |
* Return the velocity of atom which belongs to this rigid body. |
174 |
> |
* @return true if atom belongs to this rigid body,otherwise return false |
175 |
> |
* @param coor velocity of atom which will be set on return if atom belongs to this rigid body |
176 |
> |
* @param atom the pointer to an atom |
177 |
> |
*/ |
178 |
> |
bool getAtomRefCoor(Vector3d& coor, Atom* atom); |
179 |
|
|
180 |
< |
void getAtomPos(double theP[3], int index); |
181 |
< |
void getAtomVel(double theV[3], int index); |
182 |
< |
void getAtomRefCoor(double pos[3], int index); |
183 |
< |
protected: |
180 |
> |
private: |
181 |
> |
std::string name_; |
182 |
> |
Mat3x3d inertiaTensor_; |
183 |
> |
RotMat3x3d sU_; /**< body fixed standard unit vector */ |
184 |
> |
|
185 |
> |
std::vector<Atom*> atoms_; |
186 |
> |
std::vector<Vector3d> refCoords_; |
187 |
> |
std::vector<RotMat3x3d> refOrients_; |
188 |
> |
}; |
189 |
|
|
190 |
< |
double mass; // the total mass |
107 |
< |
double pos[3]; // the position array (center of mass) |
108 |
< |
double vel[3]; // the velocity array (center of mass) |
109 |
< |
double frc[3]; // the force array (center of mass) |
110 |
< |
double trq[3]; // the torque vector ( space fixed ) |
111 |
< |
double ji[3]; // the angular momentum vector (body fixed) |
112 |
< |
double A[3][3]; // the rotation matrix |
113 |
< |
double I[3][3]; // the inertial tensor (body fixed) |
114 |
< |
double sU[3][3]; // the standard unit vectors (body fixed) |
115 |
< |
double zAngle; // the rotation about the z-axis (body fixed) |
190 |
> |
}//namepace oopse |
191 |
|
|
192 |
< |
bool is_linear; |
118 |
< |
int linear_axis; |
119 |
< |
double momIntTol; |
192 |
> |
#endif //PRIMITIVES_RIGIDBODY_HPP |
193 |
|
|
121 |
– |
vector<Atom*> myAtoms; // the vector of atoms |
122 |
– |
vector<vec3> refCoords; |
123 |
– |
vector<mat3x3> refOrients; |
124 |
– |
|
125 |
– |
char rbName[100]; //it will eventually be converted into string |
126 |
– |
}; |
127 |
– |
|
128 |
– |
#endif |