| 1 | /* | 
| 2 | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 3 | * | 
| 4 | * The University of Notre Dame grants you ("Licensee") a | 
| 5 | * non-exclusive, royalty free, license to use, modify and | 
| 6 | * redistribute this software in source and binary code form, provided | 
| 7 | * that the following conditions are met: | 
| 8 | * | 
| 9 | * 1. Acknowledgement of the program authors must be made in any | 
| 10 | *    publication of scientific results based in part on use of the | 
| 11 | *    program.  An acceptable form of acknowledgement is citation of | 
| 12 | *    the article in which the program was described (Matthew | 
| 13 | *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 | *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 | *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 | *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 | * | 
| 18 | * 2. Redistributions of source code must retain the above copyright | 
| 19 | *    notice, this list of conditions and the following disclaimer. | 
| 20 | * | 
| 21 | * 3. Redistributions in binary form must reproduce the above copyright | 
| 22 | *    notice, this list of conditions and the following disclaimer in the | 
| 23 | *    documentation and/or other materials provided with the | 
| 24 | *    distribution. | 
| 25 | * | 
| 26 | * This software is provided "AS IS," without a warranty of any | 
| 27 | * kind. All express or implied conditions, representations and | 
| 28 | * warranties, including any implied warranty of merchantability, | 
| 29 | * fitness for a particular purpose or non-infringement, are hereby | 
| 30 | * excluded.  The University of Notre Dame and its licensors shall not | 
| 31 | * be liable for any damages suffered by licensee as a result of | 
| 32 | * using, modifying or distributing the software or its | 
| 33 | * derivatives. In no event will the University of Notre Dame or its | 
| 34 | * licensors be liable for any lost revenue, profit or data, or for | 
| 35 | * direct, indirect, special, consequential, incidental or punitive | 
| 36 | * damages, however caused and regardless of the theory of liability, | 
| 37 | * arising out of the use of or inability to use software, even if the | 
| 38 | * University of Notre Dame has been advised of the possibility of | 
| 39 | * such damages. | 
| 40 | */ | 
| 41 |  | 
| 42 | /** | 
| 43 | * @file RigidBody.hpp | 
| 44 | * @author    tlin | 
| 45 | * @date  10/23/2004 | 
| 46 | * @version 1.0 | 
| 47 | */ | 
| 48 |  | 
| 49 | #ifndef PRIMITIVES_RIGIDBODY_HPP | 
| 50 | #define PRIMITIVES_RIGIDBODY_HPP | 
| 51 |  | 
| 52 | #include <vector> | 
| 53 |  | 
| 54 | #include "primitives/StuntDouble.hpp" | 
| 55 | #include "primitives/DirectionalAtom.hpp" | 
| 56 | #include "types/AtomStamp.hpp" | 
| 57 | namespace oopse{ | 
| 58 | class RigidBody : public StuntDouble { | 
| 59 | public: | 
| 60 | RigidBody(); | 
| 61 |  | 
| 62 | virtual std::string getType() { return name_;} | 
| 63 |  | 
| 64 | /** Sets the name of this stuntdouble*/ | 
| 65 | virtual void setType(const std::string& name) { name_ = name;} | 
| 66 |  | 
| 67 |  | 
| 68 | /** | 
| 69 | * Sets  the previous rotation matrix of this stuntdouble | 
| 70 | * @param a  new rotation matrix | 
| 71 | */ | 
| 72 | virtual void setPrevA(const RotMat3x3d& a); | 
| 73 |  | 
| 74 | /** | 
| 75 | * Sets  the current rotation matrix of this stuntdouble | 
| 76 | * @param a  new rotation matrix | 
| 77 | * @note setA will not change the position and rotation matrix of Directional atoms belong to | 
| 78 | * this rigidbody. If you want to do that, use #updateAtoms | 
| 79 | */ | 
| 80 | virtual void setA(const RotMat3x3d& a); | 
| 81 | /** | 
| 82 | * Sets  the rotation matrix of this stuntdouble in specified snapshot | 
| 83 | * @param a rotation matrix to be set | 
| 84 | * @param snapshotNo | 
| 85 | * @see #getA | 
| 86 | */ | 
| 87 | virtual void setA(const RotMat3x3d& a, int snapshotNo); | 
| 88 |  | 
| 89 | /** | 
| 90 | * Returns the inertia tensor of this stuntdouble | 
| 91 | * @return the inertia tensor of this stuntdouble | 
| 92 | */ | 
| 93 | virtual Mat3x3d getI(); | 
| 94 |  | 
| 95 |  | 
| 96 | /** Sets the internal unit frame of this stuntdouble by three euler angles */ | 
| 97 | void setElectroFrameFromEuler(double phi, double theta, double psi); | 
| 98 |  | 
| 99 | /** | 
| 100 | * Returns the gradient of this stuntdouble | 
| 101 | * @return the inertia tensor of this stuntdouble | 
| 102 | * @see #setI | 
| 103 | */ | 
| 104 | virtual std::vector<double> getGrad(); | 
| 105 |  | 
| 106 | virtual void accept(BaseVisitor* v); | 
| 107 |  | 
| 108 | void addAtom(Atom* at, AtomStamp* ats); | 
| 109 |  | 
| 110 | /** calculate the reference coordinates */ | 
| 111 | void calcRefCoords(); | 
| 112 |  | 
| 113 | /** Convert Atomic forces and torques to total forces and torques */ | 
| 114 | void calcForcesAndTorques(); | 
| 115 |  | 
| 116 | /** update the positions of atoms belong to this rigidbody */ | 
| 117 | void updateAtoms(); | 
| 118 |  | 
| 119 | Atom* beginAtom(std::vector<Atom*>::iterator& i); | 
| 120 |  | 
| 121 | Atom* nextAtom(std::vector<Atom*>::iterator& i); | 
| 122 |  | 
| 123 | std::vector<Atom*>::iterator getBeginAtomIter() { | 
| 124 | return atoms_.begin(); | 
| 125 | } | 
| 126 |  | 
| 127 | std::vector<Atom*>::iterator getEndAtomIter() { | 
| 128 | return atoms_.end(); | 
| 129 | } | 
| 130 |  | 
| 131 | /** | 
| 132 | * Returns the atoms of this rigid body | 
| 133 | * @return the atoms of this rigid body in a vector | 
| 134 | * @deprecate | 
| 135 | */ | 
| 136 | std::vector<Atom*> getAtoms() { | 
| 137 | return atoms_; | 
| 138 | } | 
| 139 |  | 
| 140 | /** | 
| 141 | * Returns the number of atoms in this rigid body | 
| 142 | * @return the number of atoms in this rigid body | 
| 143 | */ | 
| 144 | int getNumAtoms() { | 
| 145 | return atoms_.size(); | 
| 146 | } | 
| 147 |  | 
| 148 | /** | 
| 149 | * Return the position of atom which belongs to this rigid body. | 
| 150 | * @return true if index is valid otherwise return false | 
| 151 | * @param pos the position 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 getAtomPos(Vector3d& pos, unsigned int index); | 
| 155 |  | 
| 156 | /** | 
| 157 | * Return the position of atom which belongs to this rigid body. | 
| 158 | * @return true if atom belongs to this rigid body,otherwise return false | 
| 159 | * @param pos position 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 getAtomPos(Vector3d& pos, Atom* atom); | 
| 163 |  | 
| 164 | /** | 
| 165 | * Return the velocity of atom which belongs to this rigid body. | 
| 166 | * @return true if index is valid otherwise return false | 
| 167 | * @param vel the velocity 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 getAtomVel(Vector3d& vel, unsigned int index); | 
| 171 |  | 
| 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 vel 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 getAtomVel(Vector3d& vel, Atom*); | 
| 179 |  | 
| 180 | /** | 
| 181 | * Return the reference coordinate of atom which belongs to this rigid body. | 
| 182 | * @return true if index is valid otherwise return false | 
| 183 | * @param coor the reference coordinate of atom which will be set on return if index is valid | 
| 184 | * @param index the index of the atom in rigid body's private data member atoms_ | 
| 185 | */ | 
| 186 | bool getAtomRefCoor(Vector3d& coor, unsigned int index); | 
| 187 |  | 
| 188 | /** | 
| 189 | * Return the velocity of atom which belongs to this rigid body. | 
| 190 | * @return true if atom belongs to this rigid body,otherwise return false | 
| 191 | * @param coor velocity of atom which will be set on return if atom belongs to this rigid body | 
| 192 | * @param atom the pointer to an atom | 
| 193 | */ | 
| 194 | bool getAtomRefCoor(Vector3d& coor, Atom* atom); | 
| 195 |  | 
| 196 | private: | 
| 197 | std::string name_; | 
| 198 | Mat3x3d inertiaTensor_; | 
| 199 | RotMat3x3d sU_;               /**< body fixed standard unit vector */ | 
| 200 |  | 
| 201 | std::vector<Atom*> atoms_; | 
| 202 | std::vector<Vector3d> refCoords_; | 
| 203 | std::vector<RotMat3x3d> refOrients_; | 
| 204 | }; | 
| 205 |  | 
| 206 | }//namepace oopse | 
| 207 |  | 
| 208 | #endif //PRIMITIVES_RIGIDBODY_HPP | 
| 209 |  |