1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Foam::sixDoFRigidBodyMotion
29 Six degree of freedom motion for a rigid body. Angular momentum
30 stored in body fixed reference frame. Reference orientation of
31 the body (where Q = I) must align with the cartesian axes such
32 that the Inertia tensor is in principle component form.
34 Symplectic motion as per:
36 title = {Symplectic splitting methods for rigid body molecular dynamics},
39 journal = {The Journal of Chemical Physics},
43 url = {http://link.aip.org/link/?JCP/107/5840/1},
44 doi = {10.1063/1.474310}
46 Can add restraints (i.e. a spring) and constraints (i.e. motion
47 may only be on a plane).
50 sixDoFRigidBodyMotionI.H
51 sixDoFRigidBodyMotion.C
52 sixDoFRigidBodyMotionIO.C
54 \*---------------------------------------------------------------------------*/
56 #ifndef sixDoFRigidBodyMotion_H
57 #define sixDoFRigidBodyMotion_H
59 #include "sixDoFRigidBodyMotionState.H"
60 #include "pointField.H"
61 #include "sixDoFRigidBodyMotionRestraint.H"
62 #include "sixDoFRigidBodyMotionConstraint.H"
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 // Forward declaration of classes
74 // Forward declaration of friend functions and operators
75 class sixDoFRigidBodyMotion;
76 Istream& operator>>(Istream&, sixDoFRigidBodyMotion&);
77 Ostream& operator<<(Ostream&, const sixDoFRigidBodyMotion&);
80 /*---------------------------------------------------------------------------*\
81 Class sixDoFRigidBodyMotion Declaration
82 \*---------------------------------------------------------------------------*/
84 class sixDoFRigidBodyMotion
88 //- Motion state data object
89 sixDoFRigidBodyMotionState motionState_;
91 //- Restraints on the motion
92 PtrList<sixDoFRigidBodyMotionRestraint> restraints_;
94 //- Names of the restraints
95 wordList restraintNames_;
97 //- Constaints on the motion
98 PtrList<sixDoFRigidBodyMotionConstraint> constraints_;
100 //- Names of the constraints
101 wordList constraintNames_;
103 //- Maximum number of iterations allowed to attempt to obey
105 label maxConstraintIterations_;
107 //- Centre of mass of initial state
108 point initialCentreOfMass_;
110 //- Orientation of initial state
113 //- Moment of inertia of the body in reference configuration
115 diagTensor momentOfInertia_;
120 //- Switch to turn reporting of motion data on and off
124 // Private Member Functions
126 //- Calculate the rotation tensor around the body reference
127 // frame x-axis by the given angle
128 inline tensor rotationTensorX(scalar deltaT) const;
130 //- Calculate the rotation tensor around the body reference
131 // frame y-axis by the given angle
132 inline tensor rotationTensorY(scalar deltaT) const;
134 //- Calculate the rotation tensor around the body reference
135 // frame z-axis by the given angle
136 inline tensor rotationTensorZ(scalar deltaT) const;
138 //- Apply rotation tensors to Q for the given torque (pi) and deltaT
139 inline void rotate(tensor& Q, vector& pi, scalar deltaT) const;
141 //- Apply the restraints to the object
142 void applyRestraints();
144 //- Apply the constraints to the object
145 void applyConstraints(scalar deltaT);
147 // Access functions retained as private because of the risk of
148 // confusion over what is a body local frame vector and what is global
152 //- Return access to the motion state
153 inline const sixDoFRigidBodyMotionState& motionState() const;
155 //- Return access to the restraints
156 inline const PtrList<sixDoFRigidBodyMotionRestraint>&
159 //- Return access to the restraintNames
160 inline const wordList& restraintNames() const;
162 //- Return access to the constraints
163 inline const PtrList<sixDoFRigidBodyMotionConstraint>&
166 //- Return access to the constraintNames
167 inline const wordList& constraintNames() const;
169 //- Return access to the maximum allowed number of
170 // constraint iterations
171 inline label maxConstraintIterations() const;
173 //- Return access to the initial centre of mass
174 inline const point& initialCentreOfMass() const;
176 //- Return access to the initial orientation
177 inline const tensor& initialQ() const;
179 //- Return access to the orientation
180 inline const tensor& Q() const;
182 //- Return access to velocity
183 inline const vector& v() const;
185 //- Return access to acceleration
186 inline const vector& a() const;
188 //- Return access to angular momentum
189 inline const vector& pi() const;
191 //- Return access to torque
192 inline const vector& tau() const;
197 //- Return access to the centre of mass
198 inline point& initialCentreOfMass();
200 //- Return access to the centre of mass
201 inline tensor& initialQ();
203 //- Return non-const access to the orientation
206 //- Return non-const access to vector
209 //- Return non-const access to acceleration
212 //- Return non-const access to angular momentum
215 //- Return non-const access to torque
216 inline vector& tau();
224 sixDoFRigidBodyMotion();
226 //- Construct from components
227 sixDoFRigidBodyMotion
229 const point& centreOfMass,
236 const point& initialCentreOfMass,
237 const tensor& initialQ,
238 const diagTensor& momentOfInertia,
242 //- Construct from dictionary
243 sixDoFRigidBodyMotion(const dictionary& dict);
245 //- Construct as copy
246 sixDoFRigidBodyMotion(const sixDoFRigidBodyMotion&);
250 ~sixDoFRigidBodyMotion();
255 //- Add restraints to the motion, public to allow external
256 // addition of restraints after construction
257 void addRestraints(const dictionary& dict);
259 //- Add restraints to the motion, public to allow external
260 // addition of restraints after construction
261 void addConstraints(const dictionary& dict);
263 //- First leapfrog velocity adjust and motion part, required
264 // before force calculation
270 //- Second leapfrog velocity adjust part, required after motion and
274 const vector& fGlobal,
275 const vector& tauGlobal,
279 //- Global forces supplied at locations, calculating net force
283 const pointField& positions,
284 const vectorField& forces,
288 //- Transform the given initial state pointField by the current
290 inline tmp<pointField> currentPosition
292 const pointField& pInitial
295 //- Transform the given initial state point by the current motion
297 inline point currentPosition(const point& pInitial) const;
299 //- Transform the given initial state direction by the current
301 inline vector currentOrientation(const vector& vInitial) const;
303 //- Access the orientation tensor, Q.
304 // globalVector = Q & bodyLocalVector
305 // bodyLocalVector = Q.T() & globalVector
306 inline const tensor& orientation() const;
308 //- Predict the position of the supplied initial state point
309 // after deltaT given the current motion state and the
310 // additional supplied force and moment
311 point predictedPosition
313 const point& pInitial,
314 const vector& deltaForce,
315 const vector& deltaMoment,
319 //- Predict the orientation of the supplied initial state
320 // vector after deltaT given the current motion state and the
321 // additional supplied moment
322 vector predictedOrientation
324 const vector& vInitial,
325 const vector& deltaMoment,
329 //- Return the angular velocity in the global frame
330 inline vector omega() const;
332 //- Return the velocity of a position given by the current
334 inline point currentVelocity(const point& pt) const;
336 //- Report the status of the motion
342 //- Return const access to the centre of mass
343 inline const point& centreOfMass() const;
345 //- Return access to the inertia tensor
346 inline const diagTensor& momentOfInertia() const;
348 //- Return const access to the mass
349 inline scalar mass() const;
351 //- Return the report Switch
352 inline bool report() const;
357 //- Return non-const access to the centre of mass
358 inline point& centreOfMass();
360 //- Return non-const access to the inertia tensor
361 inline diagTensor& momentOfInertia();
363 //- Return non-const access to the mass
364 inline scalar& mass();
368 void write(Ostream&) const;
371 // IOstream Operators
373 friend Istream& operator>>(Istream&, sixDoFRigidBodyMotion&);
374 friend Ostream& operator<<(Ostream&, const sixDoFRigidBodyMotion&);
378 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 } // End namespace Foam
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 #include "sixDoFRigidBodyMotionI.H"
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 // ************************************************************************* //