--- branches/new_design/OOPSE-4/src/primitives/RigidBody.hpp 2004/10/28 22:34:02 1683 +++ branches/new_design/OOPSE-4/src/primitives/RigidBody.hpp 2004/11/01 20:15:58 1692 @@ -1,128 +1,170 @@ -#ifndef __RIGIDBODY_HPP__ -#define __RIGIDBODY_HPP__ +/* + * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project + * + * Contact: oopse@oopse.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * All we ask is that proper credit is given for our work, which includes + * - but is not limited to - adding the above copyright notice to the beginning + * of your source code files, and to any copyright notice that you may distribute + * with programs based on this work. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ -#include -//#include "primitives/Atom.hpp" -//#include "types/AtomStamp.hpp" -#include "types/RigidBodyStamp.hpp" -#include "primitives/StuntDouble.hpp" -using namespace std; +/** + * @file RigidBody.hpp + * @author tlin + * @date 10/23/2004 + * @version 1.0 + */ -class Atom; -class AtomStamp; +#ifndef PRIMITIVES_RIGIDBODY_HPP +#define PRIMITIVES_RIGIDBODY_HPP -typedef struct { - double vec[3]; - double& operator[](int index) {return vec[index];} -} vec3; +#include -typedef struct { - double mat[3][3]; - double* operator[](int index) {return mat[index];} -} mat3x3; +#include "primitives/StuntDouble.hpp" +#include "primitives/DirectionalAtom.hpp" +namespace oopse{ + class RigidBody : public StuntDouble { + public: + RigidBody(); -class RigidBody : public StuntDouble { + /** + * Sets the previous rotation matrix of this stuntdouble + * @param a new rotation matrix + */ + virtual void setPrevA(const RotMat3x3d& a); + + /** + * Sets the current rotation matrix of this stuntdouble + * @param a new rotation matrix + */ + virtual void setA(const RotMat3x3d& a); + /** + * Sets the rotation matrix of this stuntdouble in specified snapshot + * @param a rotation matrix to be set + * @param snapshotNo + * @see #getA + */ + virtual void setA(const RotMat3x3d& a, int snapshotNo); -public: - - RigidBody(); - //RigidBody(const RigidBody& rb); - - virtual ~RigidBody(); - - void addAtom(Atom* at, AtomStamp* ats); + /** + * Returns the inertia tensor of this stuntdouble + * @return the inertia tensor of this stuntdouble + */ + virtual Mat3x3d getI(); - void getPos( double theP[3] ); - void setPos( double theP[3] ); - void getVel( double theV[3] ); - void setVel( double theV[3] ); + /** Sets the internal unit frame of this stuntdouble by three euler angles */ + void setUnitFrameFromEuler(double phi, double theta, double psi); + + /** + * Returns the gradient of this stuntdouble + * @return the inertia tensor of this stuntdouble + * @see #setI + */ + virtual std::vector getGrad(); - void getFrc( double theF[3] ); - void addFrc( double theF[3] ); - void zeroForces(); - - virtual bool isLinear() {return is_linear;} - virtual int linearAxis() {return linear_axis;} + virtual void accept(BaseVisitor* v); - double getMass( void ) { return mass; } + void addAtom(Atom* atom); - void printAmatIndex( void ); - void setEuler( double phi, double theta, double psi ); - void getQ( double the_q[4] ); // get the quanternions - void setQ( double the_q[4] ); + /** calculate the reference coordinates */ + void calcRefCoords(); - void getA( double the_A[3][3] ); // get the full rotation matrix - void setA( double the_A[3][3] ); + /** Convert Atomic forces and torques to total forces and torques */ + void calcForcesAndTorques(); - void getJ( double theJ[3] ); - void setJ( double theJ[3] ); + /** update the positions of atoms belong to this rigidbody */ + void updateAtoms(); - virtual void setType(char* type) {strcpy(rbName, type);} - virtual char* getType() { return rbName;} + /** + * Returns the atoms of this rigid body + * @return the atoms of this rigid body in a vector + */ + std::vector getAtoms() { + return atoms_; + } - void getTrq( double theT[3] ); - void addTrq( double theT[3] ); + /** + * Returns the number of atoms in this rigid body + * @return the number of atoms in this rigid body + */ + int getNumAtoms() { + return atoms_.size(); + } - void getI( double the_I[3][3] ); - void lab2Body( double r[3] ); - void body2Lab( double r[3] ); + /** + * Return the position of atom which belongs to this rigid body. + * @return true if index is valid otherwise return false + * @param pos the position of atom which will be set on return if index is valid + * @param index the index of the atom in rigid body's private data member atoms_ + */ + bool getAtomPos(Vector3d& pos, unsigned int index); - double getZangle( ); - void setZangle( double zAng ); - void addZangle( double zAng ); + /** + * Return the position of atom which belongs to this rigid body. + * @return true if atom belongs to this rigid body,otherwise return false + * @param pos position of atom which will be set on return if atom belongs to this rigid body + * @param atom the pointer to an atom + */ + bool getAtomPos(Vector3d& pos, Atom* atom); - void calcRefCoords( void ); - void doEulerToRotMat(vec3 &euler, mat3x3 &myA ); - void calcForcesAndTorques( void ); - void updateAtoms( void ); + /** + * Return the velocity of atom which belongs to this rigid body. + * @return true if index is valid otherwise return false + * @param vel the velocity of atom which will be set on return if index is valid + * @param index the index of the atom in rigid body's private data member atoms_ + */ + bool getAtomVel(Vector3d& vel, unsigned int index); - //void yourAtomsHaveMoved( void ); + /** + * Return the velocity of atom which belongs to this rigid body. + * @return true if atom belongs to this rigid body,otherwise return false + * @param vel velocity of atom which will be set on return if atom belongs to this rigid body + * @param atom the pointer to an atom + */ + bool getAtomVel(Vector3d& vel, Atom*); - // Four functions added for derivatives with respect to Euler Angles: - // (Needed for minimization routines): + /** + * Return the reference coordinate of atom which belongs to this rigid body. + * @return true if index is valid otherwise return false + * @param coor the reference coordinate of atom which will be set on return if index is valid + * @param index the index of the atom in rigid body's private data member atoms_ + */ + bool getAtomRefCoor(Vector3d& coor, unsigned int index); - void getGrad(double gradient[6] ); - void getEulerAngles( double myEuler[3] ); - - double max(double x, double y); - double min(double x, double y); + /** + * Return the velocity of atom which belongs to this rigid body. + * @return true if atom belongs to this rigid body,otherwise return false + * @param coor velocity of atom which will be set on return if atom belongs to this rigid body + * @param atom the pointer to an atom + */ + bool getAtomRefCoor(Vector3d& coor, Atom* atom); + private: + + Mat3x3d inertiaTensor_; + RotMat3x3d sU_; /**< body fixed standard unit vector */ + + std::vector atoms_; + std::vector refCoords_; + }; - // utility routines +}//namepace oopse - void findCOM( void ); +#endif //PRIMITIVES_RIGIDBODY_HPP - virtual void accept(BaseVisitor* v); - - vector getAtoms() { return myAtoms;} - int getNumAtoms() {return myAtoms.size();} - - void getAtomPos(double theP[3], int index); - void getAtomVel(double theV[3], int index); - void getAtomRefCoor(double pos[3], int index); -protected: - - double mass; // the total mass - double pos[3]; // the position array (center of mass) - double vel[3]; // the velocity array (center of mass) - double frc[3]; // the force array (center of mass) - double trq[3]; // the torque vector ( space fixed ) - double ji[3]; // the angular momentum vector (body fixed) - double A[3][3]; // the rotation matrix - double I[3][3]; // the inertial tensor (body fixed) - double sU[3][3]; // the standard unit vectors (body fixed) - double zAngle; // the rotation about the z-axis (body fixed) - - bool is_linear; - int linear_axis; - double momIntTol; - - vector myAtoms; // the vector of atoms - vector refCoords; - vector refOrients; - - char rbName[100]; //it will eventually be converted into string -}; - -#endif