sixDoFRigidBodyMotion.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2016-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::sixDoFRigidBodyMotion
29 
30 Description
31  Six degree of freedom motion for a rigid body.
32 
33  Angular momentum stored in body fixed reference frame. Reference
34  orientation of the body (where Q = I) must align with the cartesian axes
35  such that the Inertia tensor is in principle component form. Can add
36  restraints (e.g. a spring) and constraints (e.g. motion may only be on a
37  plane).
38 
39  The time-integrator for the motion is run-time selectable with options for
40  symplectic (explicit), Crank-Nicolson and Newmark schemes.
41 
42 SourceFiles
43  sixDoFRigidBodyMotionI.H
44  sixDoFRigidBodyMotion.C
45  sixDoFRigidBodyMotionIO.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef sixDoFRigidBodyMotion_H
50 #define sixDoFRigidBodyMotion_H
51 
53 #include "pointField.H"
56 #include "Tuple2.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 // Forward declarations
64 class sixDoFSolver;
65 
66 /*---------------------------------------------------------------------------*\
67  Class sixDoFRigidBodyMotion Declaration
68 \*---------------------------------------------------------------------------*/
69 
71 {
72  friend class sixDoFSolver;
73 
74  // Private data
75 
76  //- Reference to time database
77  const Time& time_;
78 
79  //- Motion state data object
80  sixDoFRigidBodyMotionState motionState_;
81 
82  //- Motion state data object for previous time-step
83  sixDoFRigidBodyMotionState motionState0_;
84 
85  //- Motion restraints
87 
88  //- Motion constraints
90 
91  //- Translational constraint tensor
92  tensor tConstraints_;
93 
94  //- Rotational constraint tensor
95  tensor rConstraints_;
96 
97  //- Centre of mass of initial state
98  point initialCentreOfMass_;
99 
100  //- Centre of rotation of initial state
101  point initialCentreOfRotation_;
102 
103  //- Orientation of initial state
104  tensor initialQ_;
105 
106  //- Mass of the body
107  scalar mass_;
108 
109  //- Moment of inertia of the body in reference configuration
110  // (Q = I)
111  diagTensor momentOfInertia_;
112 
113  //- Acceleration relaxation coefficient
114  scalar aRelax_;
115 
116  //- Acceleration damping coefficient (for steady-state simulations)
117  scalar aDamp_;
118 
119  //- Reporting of motion data (on or off)
120  bool report_;
121 
122  //- Flag to enable time-variant constraints
123  bool updateConstraints_;
124 
125  //- Motion solver
126  autoPtr<sixDoFSolver> solver_;
127 
128 
129  // Private Member Functions
130 
131  //- Calculate the rotation tensor around the body reference
132  // frame x-axis by the given angle
133  inline tensor rotationTensorX(scalar deltaT) const;
134 
135  //- Calculate the rotation tensor around the body reference
136  // frame y-axis by the given angle
137  inline tensor rotationTensorY(scalar deltaT) const;
138 
139  //- Calculate the rotation tensor around the body reference
140  // frame z-axis by the given angle
141  inline tensor rotationTensorZ(scalar deltaT) const;
142 
143  //- Apply rotation tensors to Q0 for the given torque (pi) and deltaT
144  // and return the rotated Q and pi as a tuple
145  inline Tuple2<tensor, vector> rotate
146  (
147  const tensor& Q0,
148  const vector& pi,
149  const scalar deltaT
150  ) const;
151 
152  //- Apply the restraints to the object
153  void applyRestraints();
154 
155  //- Update and relax accelerations from the force and torque
156  void updateAcceleration(const vector& fGlobal, const vector& tauGlobal);
157 
158  //- Update the constraints to the object
159  void updateConstraints();
160 
161 
162  // Access functions retained as private because of the risk of
163  // confusion over what is a body local frame vector and what is global
164 
165  // Access
166 
167  //- Return the restraints
169  restraints() const;
170 
171  //- Return the constraints
173  constraints() const;
174 
175  //- Return the initial centre of rotation
176  inline const point& initialCentreOfRotation() const;
177 
178  //- Return the initial orientation
179  inline const tensor& initialQ() const;
180 
181  //- Return the orientation
182  inline const tensor& Q() const;
183 
184  //- Return the current acceleration
185  inline const vector& a() const;
186 
187  //- Return the current angular momentum
188  inline const vector& pi() const;
189 
190  //- Return the current torque
191  inline const vector& tau() const;
192 
193 
194  // Edit
195 
196  //- Return the centre of rotation
197  inline point& initialCentreOfRotation();
198 
199  //- Return initial orientation
200  inline tensor& initialQ();
201 
202  //- Return non-const access to the orientation
203  inline tensor& Q();
204 
205  //- Return non-const access to acceleration
206  inline vector& a();
207 
208  //- Return non-const access to angular momentum
209  inline vector& pi();
210 
211  //- Return non-const access to torque
212  inline vector& tau();
213 
214 
215 public:
216 
217  // Constructors
218 
219  //- Construct null
220  sixDoFRigidBodyMotion(const Time&);
221 
222  //- Construct from constant and state dictionaries
224  (
225  const dictionary& dict,
226  const dictionary& stateDict,
227  const Time& time
228  );
229 
230  //- Construct as copy
232 
233 
234  //- Destructor
236 
237 
238  // Member Functions
239 
240  // Access
241 
242  //- Return the mass
243  inline scalar mass() const;
244 
245  //- Return the inertia tensor
246  inline const diagTensor& momentOfInertia() const;
247 
248  //- Return the motion state
249  inline const sixDoFRigidBodyMotionState& state() const;
250 
251  //- Return the current centre of rotation
252  inline const point& centreOfRotation() const;
253 
254  //- Return the initial centre of mass
255  inline const point& initialCentreOfMass() const;
256 
257  //- Return the current centre of mass
258  inline point centreOfMass() const;
259 
260  //- Return the orientation tensor, Q.
261  // globalVector = Q & bodyLocalVector
262  // bodyLocalVector = Q.T() & globalVector
263  inline const tensor& orientation() const;
264 
265  //- Return the angular velocity in the global frame
266  inline vector omega() const;
267 
268  //- Return the current velocity
269  inline const vector& v() const;
270 
271  //- Return non-const access to vector
272  inline vector& v();
273 
274  //- Return the current momentArm
275  inline vector momentArm() const;
276 
277  //- Return the report Switch
278  inline bool report() const;
279 
280  //- Return the update-constraints flag
281  inline bool updateConstraints() const;
282 
283  //- Return time
284  inline const Time& time() const;
285 
286 
287  // Edit
288 
289  //- Store the motion state at the beginning of the time-step
290  inline void newTime();
291 
292  //- Return non-const access to the centre of rotation
293  inline point& centreOfRotation();
294 
295 
296  // Constraints and Restraints
297 
298  //- Add restraints to the motion, public to allow external
299  // addition of restraints after construction
300  void addRestraints(const dictionary& dict);
301 
302  //- Add restraints to the motion, public to allow external
303  // addition of restraints after construction
304  void addConstraints(const dictionary& dict);
305 
306 
307  // Update state
308 
309  //- Symplectic integration of velocities, orientation and position.
310  // Changes to Crank-Nicolson integration for subsequent iterations.
311  void update
312  (
313  bool firstIter,
314  const vector& fGlobal,
315  const vector& tauGlobal,
316  scalar deltaT,
317  scalar deltaT0
318  );
319 
320  //- Report the status of the motion
321  void status() const;
322 
323 
324  // Transformations
325 
326  //- Return the velocity of a position
327  inline point velocity(const point& pt) const;
328 
329  //- Transform the given initial state point by the current motion
330  // state
331  inline point transform(const point& initialPoints) const;
332 
333  //- Transform the given initial state pointField by the current
334  // motion state
335  tmp<pointField> transform(const pointField& initialPoints) const;
336 
337  //- Transform the given initial state pointField by the current
338  // motion state scaled by the given scale
340  (
341  const pointField& initialPoints,
342  const scalarField& scale
343  ) const;
344 
345 
346  //- Write
347  void write(Ostream&) const;
348 
349  //- Read coefficients dictionary and update system parameters,
350  // constraints and restraints but not the current state
351  bool read(const dictionary& dict);
352 };
353 
354 
355 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 
357 } // End namespace Foam
358 
359 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360 
361 #include "sixDoFRigidBodyMotionI.H"
362 
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 
365 #endif
366 
367 // ************************************************************************* //
Six degree of freedom motion for a rigid body.
void addConstraints(const dictionary &dict)
Add restraints to the motion, public to allow external.
bool read(const dictionary &dict)
Read coefficients dictionary and update system parameters,.
dictionary dict
bool report() const
Return the report Switch.
void write(Ostream &) const
Write.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
point centreOfMass() const
Return the current centre of mass.
const point & centreOfRotation() const
Return the current centre of rotation.
point transform(const point &initialPoints) const
Transform the given initial state point by the current motion.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
const sixDoFRigidBodyMotionState & state() const
Return the motion state.
vector momentArm() const
Return the current momentArm.
const diagTensor & momentOfInertia() const
Return the inertia tensor.
vector omega() const
Return the angular velocity in the global frame.
Holds the motion state of sixDoF object. Wrapped up together to allow rapid scatter to other processo...
const tensor & orientation() const
Return the orientation tensor, Q.
constexpr scalar pi(M_PI)
void status() const
Report the status of the motion.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
void newTime()
Store the motion state at the beginning of the time-step.
point velocity(const point &pt) const
Return the velocity of a position.
const Time & time() const
Return time.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
scalar mass() const
Return the mass.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
sixDoFRigidBodyMotion(const Time &)
Construct null.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Tensor of scalars, i.e. Tensor<scalar>.
void update(bool firstIter, const vector &fGlobal, const vector &tauGlobal, scalar deltaT, scalar deltaT0)
Symplectic integration of velocities, orientation and position.
const point & initialCentreOfMass() const
Return the initial centre of mass.
const vector & v() const
Return the current velocity.
void addRestraints(const dictionary &dict)
Add restraints to the motion, public to allow external.
Namespace for OpenFOAM.