00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::sixDoFRigidBodyMotion 00026 00027 Description 00028 Six degree of freedom motion for a rigid body. Angular momentum 00029 stored in body fixed reference frame. Reference orientation of 00030 the body (where Q = I) must align with the cartesian axes such 00031 that the Inertia tensor is in principle component form. 00032 00033 Symplectic motion as per: 00034 00035 title = {Symplectic splitting methods for rigid body molecular dynamics}, 00036 publisher = {AIP}, 00037 year = {1997}, 00038 journal = {The Journal of Chemical Physics}, 00039 volume = {107}, 00040 number = {15}, 00041 pages = {5840-5851}, 00042 url = {http://link.aip.org/link/?JCP/107/5840/1}, 00043 doi = {10.1063/1.474310} 00044 00045 Can add restraints (i.e. a spring) and constraints (i.e. motion 00046 may only be on a plane). 00047 00048 SourceFiles 00049 sixDoFRigidBodyMotionI.H 00050 sixDoFRigidBodyMotion.C 00051 sixDoFRigidBodyMotionIO.C 00052 00053 \*---------------------------------------------------------------------------*/ 00054 00055 #ifndef sixDoFRigidBodyMotion_H 00056 #define sixDoFRigidBodyMotion_H 00057 00058 #include "sixDoFRigidBodyMotionState.H" 00059 #include <OpenFOAM/pointField.H> 00060 #include <forces/sixDoFRigidBodyMotionRestraint.H> 00061 #include <forces/sixDoFRigidBodyMotionConstraint.H> 00062 00063 00064 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00065 00066 namespace Foam 00067 { 00068 00069 // Forward declaration of classes 00070 class Istream; 00071 class Ostream; 00072 00073 // Forward declaration of friend functions and operators 00074 class sixDoFRigidBodyMotion; 00075 Istream& operator>>(Istream&, sixDoFRigidBodyMotion&); 00076 Ostream& operator<<(Ostream&, const sixDoFRigidBodyMotion&); 00077 00078 00079 /*---------------------------------------------------------------------------*\ 00080 Class sixDoFRigidBodyMotion Declaration 00081 \*---------------------------------------------------------------------------*/ 00082 00083 class sixDoFRigidBodyMotion 00084 { 00085 // Private data 00086 00087 //- Motion state data object 00088 sixDoFRigidBodyMotionState motionState_; 00089 00090 //- Restraints on the motion 00091 PtrList<sixDoFRigidBodyMotionRestraint> restraints_; 00092 00093 //- Names of the restraints 00094 wordList restraintNames_; 00095 00096 //- Constaints on the motion 00097 PtrList<sixDoFRigidBodyMotionConstraint> constraints_; 00098 00099 //- Names of the constraints 00100 wordList constraintNames_; 00101 00102 //- Maximum number of iterations allowed to attempt to obey 00103 // constraints 00104 label maxConstraintIterations_; 00105 00106 //- Centre of mass of initial state 00107 point initialCentreOfMass_; 00108 00109 //- Orientation of initial state 00110 tensor initialQ_; 00111 00112 //- Moment of inertia of the body in reference configuration 00113 // (Q = I) 00114 diagTensor momentOfInertia_; 00115 00116 //- Mass of the body 00117 scalar mass_; 00118 00119 //- Acceleration damping coefficient. Modify applied acceleration: 00120 // v1 = v0 + a*dt - cDamp*a*dt 00121 // = v0 + dt*f*(1 - cDamp)/m 00122 // Increases effective mass by 1/(1 - cDamp). 00123 scalar cDamp_; 00124 00125 //- Acceleration magnitude limit - clips large accelerations 00126 scalar aLim_; 00127 00128 //- Switch to turn reporting of motion data on and off 00129 Switch report_; 00130 00131 00132 // Private Member Functions 00133 00134 //- Calculate the rotation tensor around the body reference 00135 // frame x-axis by the given angle 00136 inline tensor rotationTensorX(scalar deltaT) const; 00137 00138 //- Calculate the rotation tensor around the body reference 00139 // frame y-axis by the given angle 00140 inline tensor rotationTensorY(scalar deltaT) const; 00141 00142 //- Calculate the rotation tensor around the body reference 00143 // frame z-axis by the given angle 00144 inline tensor rotationTensorZ(scalar deltaT) const; 00145 00146 //- Apply rotation tensors to Q for the given torque (pi) and deltaT 00147 inline void rotate(tensor& Q, vector& pi, scalar deltaT) const; 00148 00149 //- Apply the restraints to the object 00150 void applyRestraints(); 00151 00152 //- Apply the constraints to the object 00153 void applyConstraints(scalar deltaT); 00154 00155 // Access functions retained as private because of the risk of 00156 // confusion over what is a body local frame vector and what is global 00157 00158 // Access 00159 00160 //- Return access to the motion state 00161 inline const sixDoFRigidBodyMotionState& motionState() const; 00162 00163 //- Return access to the restraints 00164 inline const PtrList<sixDoFRigidBodyMotionRestraint>& 00165 restraints() const; 00166 00167 //- Return access to the restraintNames 00168 inline const wordList& restraintNames() const; 00169 00170 //- Return access to the constraints 00171 inline const PtrList<sixDoFRigidBodyMotionConstraint>& 00172 constraints() const; 00173 00174 //- Return access to the constraintNames 00175 inline const wordList& constraintNames() const; 00176 00177 //- Return access to the maximum allowed number of 00178 // constraint iterations 00179 inline label maxConstraintIterations() const; 00180 00181 //- Return access to the initial centre of mass 00182 inline const point& initialCentreOfMass() const; 00183 00184 //- Return access to the initial orientation 00185 inline const tensor& initialQ() const; 00186 00187 //- Return access to the orientation 00188 inline const tensor& Q() const; 00189 00190 //- Return access to velocity 00191 inline const vector& v() const; 00192 00193 //- Return access to acceleration 00194 inline const vector& a() const; 00195 00196 //- Return access to angular momentum 00197 inline const vector& pi() const; 00198 00199 //- Return access to torque 00200 inline const vector& tau() const; 00201 00202 00203 // Edit 00204 00205 //- Return access to the centre of mass 00206 inline point& initialCentreOfMass(); 00207 00208 //- Return access to the centre of mass 00209 inline tensor& initialQ(); 00210 00211 //- Return non-const access to the orientation 00212 inline tensor& Q(); 00213 00214 //- Return non-const access to vector 00215 inline vector& v(); 00216 00217 //- Return non-const access to acceleration 00218 inline vector& a(); 00219 00220 //- Return non-const access to angular momentum 00221 inline vector& pi(); 00222 00223 //- Return non-const access to torque 00224 inline vector& tau(); 00225 00226 00227 public: 00228 00229 // Constructors 00230 00231 //- Construct null 00232 sixDoFRigidBodyMotion(); 00233 00234 //- Construct from components 00235 sixDoFRigidBodyMotion 00236 ( 00237 const point& centreOfMass, 00238 const tensor& Q, 00239 const vector& v, 00240 const vector& a, 00241 const vector& pi, 00242 const vector& tau, 00243 scalar mass, 00244 const point& initialCentreOfMass, 00245 const tensor& initialQ, 00246 const diagTensor& momentOfInertia, 00247 scalar cDamp = 0.0, 00248 scalar aLim = VGREAT, 00249 bool report = false 00250 ); 00251 00252 //- Construct from dictionary 00253 sixDoFRigidBodyMotion(const dictionary& dict); 00254 00255 //- Construct as copy 00256 sixDoFRigidBodyMotion(const sixDoFRigidBodyMotion&); 00257 00258 00259 //- Destructor 00260 ~sixDoFRigidBodyMotion(); 00261 00262 00263 // Member Functions 00264 00265 //- Add restraints to the motion, public to allow external 00266 // addition of restraints after construction 00267 void addRestraints(const dictionary& dict); 00268 00269 //- Add restraints to the motion, public to allow external 00270 // addition of restraints after construction 00271 void addConstraints(const dictionary& dict); 00272 00273 //- First leapfrog velocity adjust and motion part, required 00274 // before force calculation. Takes old timestep for variable 00275 // timestep cases. 00276 void updatePosition 00277 ( 00278 scalar deltaT, 00279 scalar deltaT0 00280 ); 00281 00282 //- Second leapfrog velocity adjust part, required after motion and 00283 // force calculation 00284 void updateForce 00285 ( 00286 const vector& fGlobal, 00287 const vector& tauGlobal, 00288 scalar deltaT 00289 ); 00290 00291 //- Global forces supplied at locations, calculating net force 00292 // and moment 00293 void updateForce 00294 ( 00295 const pointField& positions, 00296 const vectorField& forces, 00297 scalar deltaT 00298 ); 00299 00300 //- Transform the given initial state pointField by the current 00301 // motion state 00302 inline tmp<pointField> currentPosition 00303 ( 00304 const pointField& pInitial 00305 ) const; 00306 00307 //- Transform the given initial state point by the current motion 00308 // state 00309 inline point currentPosition(const point& pInitial) const; 00310 00311 //- Transform the given initial state direction by the current 00312 // motion state 00313 inline vector currentOrientation(const vector& vInitial) const; 00314 00315 //- Access the orientation tensor, Q. 00316 // globalVector = Q & bodyLocalVector 00317 // bodyLocalVector = Q.T() & globalVector 00318 inline const tensor& orientation() const; 00319 00320 //- Predict the position of the supplied initial state point 00321 // after deltaT given the current motion state and the 00322 // additional supplied force and moment 00323 point predictedPosition 00324 ( 00325 const point& pInitial, 00326 const vector& deltaForce, 00327 const vector& deltaMoment, 00328 scalar deltaT 00329 ) const; 00330 00331 //- Predict the orientation of the supplied initial state 00332 // vector after deltaT given the current motion state and the 00333 // additional supplied moment 00334 vector predictedOrientation 00335 ( 00336 const vector& vInitial, 00337 const vector& deltaMoment, 00338 scalar deltaT 00339 ) const; 00340 00341 //- Return the angular velocity in the global frame 00342 inline vector omega() const; 00343 00344 //- Return the velocity of a position given by the current 00345 // motion state 00346 inline point currentVelocity(const point& pt) const; 00347 00348 //- Report the status of the motion 00349 void status() const; 00350 00351 00352 // Access 00353 00354 //- Return const access to the centre of mass 00355 inline const point& centreOfMass() const; 00356 00357 //- Return access to the inertia tensor 00358 inline const diagTensor& momentOfInertia() const; 00359 00360 //- Return const access to the mass 00361 inline scalar mass() const; 00362 00363 //- Return the report Switch 00364 inline bool report() const; 00365 00366 00367 // Edit 00368 00369 //- Return non-const access to the centre of mass 00370 inline point& centreOfMass(); 00371 00372 //- Return non-const access to the inertia tensor 00373 inline diagTensor& momentOfInertia(); 00374 00375 //- Return non-const access to the mass 00376 inline scalar& mass(); 00377 00378 00379 //- Write 00380 void write(Ostream&) const; 00381 00382 00383 // IOstream Operators 00384 00385 friend Istream& operator>>(Istream&, sixDoFRigidBodyMotion&); 00386 friend Ostream& operator<<(Ostream&, const sixDoFRigidBodyMotion&); 00387 }; 00388 00389 00390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00391 00392 } // End namespace Foam 00393 00394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00395 00396 #include "sixDoFRigidBodyMotionI.H" 00397 00398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00399 00400 #endif 00401 00402 // ************************ vim: set sw=4 sts=4 et: ************************ //