1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 Foam::sixDoFRigidBodyMotion
28 Six degree of freedom motion for a rigid body. Angular momentum
29 stored in body fixed reference frame. Reference orientation of
30 the body (where Q = I) must align with the cartesian axes such
31 that the Inertia tensor is in principle component form.
33 Symplectic motion as per:
35 title = {Symplectic splitting methods for rigid body molecular dynamics},
38 journal = {The Journal of Chemical Physics},
42 url = {http://link.aip.org/link/?JCP/107/5840/1},
43 doi = {10.1063/1.474310}
45 Can add restraints (i.e. a spring) and constraints (i.e. motion
46 may only be on a plane).
49 sixDoFRigidBodyMotionI.H
50 sixDoFRigidBodyMotion.C
51 sixDoFRigidBodyMotionIO.C
53 \*---------------------------------------------------------------------------*/
55 #ifndef sixDoFRigidBodyMotion_H
56 #define sixDoFRigidBodyMotion_H
58 #include "sixDoFRigidBodyMotionState.H"
59 #include "pointField.H"
60 #include "sixDoFRigidBodyMotionRestraint.H"
61 #include "sixDoFRigidBodyMotionConstraint.H"
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 // Forward declaration of classes
73 // Forward declaration of friend functions and operators
74 class sixDoFRigidBodyMotion;
75 Istream& operator>>(Istream&, sixDoFRigidBodyMotion&);
76 Ostream& operator<<(Ostream&, const sixDoFRigidBodyMotion&);
79 /*---------------------------------------------------------------------------*\
80 Class sixDoFRigidBodyMotion Declaration
81 \*---------------------------------------------------------------------------*/
83 class sixDoFRigidBodyMotion
87 //- Motion state data object
88 sixDoFRigidBodyMotionState motionState_;
90 //- Restraints on the motion
91 PtrList<sixDoFRigidBodyMotionRestraint> restraints_;
93 //- Names of the restraints
94 wordList restraintNames_;
96 //- Constaints on the motion
97 PtrList<sixDoFRigidBodyMotionConstraint> constraints_;
99 //- Names of the constraints
100 wordList constraintNames_;
102 //- Maximum number of iterations allowed to attempt to obey
104 label maxConstraintIterations_;
106 //- Centre of mass of initial state
107 point initialCentreOfMass_;
109 //- Orientation of initial state
112 //- Moment of inertia of the body in reference configuration
114 diagTensor momentOfInertia_;
119 //- Switch to turn reporting of motion data on and off
123 // Private Member Functions
125 //- Calculate the rotation tensor around the body reference
126 // frame x-axis by the given angle
127 inline tensor rotationTensorX(scalar deltaT) const;
129 //- Calculate the rotation tensor around the body reference
130 // frame y-axis by the given angle
131 inline tensor rotationTensorY(scalar deltaT) const;
133 //- Calculate the rotation tensor around the body reference
134 // frame z-axis by the given angle
135 inline tensor rotationTensorZ(scalar deltaT) const;
137 //- Apply rotation tensors to Q for the given torque (pi) and deltaT
138 inline void rotate(tensor& Q, vector& pi, scalar deltaT) const;
140 //- Apply the restraints to the object
141 void applyRestraints();
143 //- Apply the constraints to the object
144 void applyConstraints(scalar deltaT);
146 // Access functions retained as private because of the risk of
147 // confusion over what is a body local frame vector and what is global
151 //- Return access to the motion state
152 inline const sixDoFRigidBodyMotionState& motionState() const;
154 //- Return access to the restraints
155 inline const PtrList<sixDoFRigidBodyMotionRestraint>&
158 //- Return access to the restraintNames
159 inline const wordList& restraintNames() const;
161 //- Return access to the constraints
162 inline const PtrList<sixDoFRigidBodyMotionConstraint>&
165 //- Return access to the constraintNames
166 inline const wordList& constraintNames() const;
168 //- Return access to the maximum allowed number of
169 // constraint iterations
170 inline label maxConstraintIterations() const;
172 //- Return access to the initial centre of mass
173 inline const point& initialCentreOfMass() const;
175 //- Return access to the initial orientation
176 inline const tensor& initialQ() const;
178 //- Return access to the orientation
179 inline const tensor& Q() const;
181 //- Return access to velocity
182 inline const vector& v() const;
184 //- Return access to acceleration
185 inline const vector& a() const;
187 //- Return access to angular momentum
188 inline const vector& pi() const;
190 //- Return access to torque
191 inline const vector& tau() const;
196 //- Return access to the centre of mass
197 inline point& initialCentreOfMass();
199 //- Return access to the centre of mass
200 inline tensor& initialQ();
202 //- Return non-const access to the orientation
205 //- Return non-const access to vector
208 //- Return non-const access to acceleration
211 //- Return non-const access to angular momentum
214 //- Return non-const access to torque
215 inline vector& tau();
223 sixDoFRigidBodyMotion();
225 //- Construct from components
226 sixDoFRigidBodyMotion
228 const point& centreOfMass,
235 const point& initialCentreOfMass,
236 const tensor& initialQ,
237 const diagTensor& momentOfInertia,
241 //- Construct from dictionary
242 sixDoFRigidBodyMotion(const dictionary& dict);
244 //- Construct as copy
245 sixDoFRigidBodyMotion(const sixDoFRigidBodyMotion&);
249 ~sixDoFRigidBodyMotion();
254 //- Add restraints to the motion, public to allow external
255 // addition of restraints after construction
256 void addRestraints(const dictionary& dict);
258 //- Add restraints to the motion, public to allow external
259 // addition of restraints after construction
260 void addConstraints(const dictionary& dict);
262 //- First leapfrog velocity adjust and motion part, required
263 // before force calculation
269 //- Second leapfrog velocity adjust part, required after motion and
273 const vector& fGlobal,
274 const vector& tauGlobal,
278 //- Global forces supplied at locations, calculating net force
282 const pointField& positions,
283 const vectorField& forces,
287 //- Transform the given initial state pointField by the current
289 inline tmp<pointField> currentPosition
291 const pointField& pInitial
294 //- Transform the given initial state point by the current motion
296 inline point currentPosition(const point& pInitial) const;
298 //- Transform the given initial state direction by the current
300 inline vector currentOrientation(const vector& vInitial) const;
302 //- Access the orientation tensor, Q.
303 // globalVector = Q & bodyLocalVector
304 // bodyLocalVector = Q.T() & globalVector
305 inline const tensor& orientation() const;
307 //- Predict the position of the supplied initial state point
308 // after deltaT given the current motion state and the
309 // additional supplied force and moment
310 point predictedPosition
312 const point& pInitial,
313 const vector& deltaForce,
314 const vector& deltaMoment,
318 //- Predict the orientation of the supplied initial state
319 // vector after deltaT given the current motion state and the
320 // additional supplied moment
321 vector predictedOrientation
323 const vector& vInitial,
324 const vector& deltaMoment,
328 //- Return the angular velocity in the global frame
329 inline vector omega() const;
331 //- Return the velocity of a position given by the current
333 inline point currentVelocity(const point& pt) const;
335 //- Report the status of the motion
341 //- Return const access to the centre of mass
342 inline const point& centreOfMass() const;
344 //- Return access to the inertia tensor
345 inline const diagTensor& momentOfInertia() const;
347 //- Return const access to the mass
348 inline scalar mass() const;
350 //- Return the report Switch
351 inline bool report() const;
356 //- Return non-const access to the centre of mass
357 inline point& centreOfMass();
359 //- Return non-const access to the inertia tensor
360 inline diagTensor& momentOfInertia();
362 //- Return non-const access to the mass
363 inline scalar& mass();
367 void write(Ostream&) const;
370 // IOstream Operators
372 friend Istream& operator>>(Istream&, sixDoFRigidBodyMotion&);
373 friend Ostream& operator<<(Ostream&, const sixDoFRigidBodyMotion&);
377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
379 } // End namespace Foam
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 #include "sixDoFRigidBodyMotionI.H"
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
389 // ************************************************************************* //