1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 6-DOF solver using quaternions
31 Dubravko Matijasevic, FSB Zagreb. All rights reserved.
32 Updated by Hrvoje Jasak.
38 \*---------------------------------------------------------------------------*/
44 #include "IOdictionary.H"
45 #include "dimensionedTypes.H"
46 #include "HamiltonRodriguezRot.H"
47 #include "finiteRotation.H"
48 #include "vectorField.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 /*---------------------------------------------------------------------------*\
56 Class sixDOFqODE Declaration
57 \*---------------------------------------------------------------------------*/
69 dimensionedScalar mass_;
71 //- Rotational moment of inertia around centre of mass
72 // in body (relative) coordinates - aligned with main axes
73 dimensionedDiagTensor momentOfInertia_;
78 //- Spring equilibrium position for translation
79 dimensionedVector Xequilibrium_;
81 //- Linear spring coeffs
82 dimensionedDiagTensor linSpringCoeffs_;
84 //- Linear damping coeffs
85 dimensionedDiagTensor linDampingCoeffs_;
88 // Initial body state variables
90 //- Displacement relative to spring equilibrium
91 dimensionedVector Xrel_;
93 //- Velocity of mass centroid
96 //- Average velocity of mass centroid at previous time-step
97 dimensionedVector Uaverage_;
100 finiteRotation rotation_;
102 //- Rotational velocity about mass centroid
103 dimensionedVector omega_;
106 // Average variables that need to be stored
108 //- Average rotational velocity in relative coordinate system
109 dimensionedVector omegaAverage_;
111 //- Average rotational velocity in absolute coordinate system
112 dimensionedVector omegaAverageAbsolute_;
117 //- Force driving the motion in inertial coord. sys.
118 dimensionedVector force_;
120 //- Moment driving the motion in inertial coord. sys.
121 dimensionedVector moment_;
123 //- Force driving the motion in relative coord. sys.
124 dimensionedVector forceRelative_;
126 //- Moment driving the motion in relative coord. sys.
127 dimensionedVector momentRelative_;
134 //- Motion constraints (given as fixed motion components)
136 //- Fixed surge (x-translation)
139 //- Fixed sway (y-translation)
142 //- Fixed heave (z-translation)
145 //- Fixed roll (rotation around x)
148 //- Fixed pitch (rotation around y)
151 //- Fixed yaw (rotation around z)
154 //- Restraints in referent coordinate system
155 Switch referentMotionConstraints_;
157 //- Rotation of referent coordinate system
158 HamiltonRodriguezRot referentRotation_;
161 // Private Member Functions
163 //- Disallow default bitwise copy construct
164 sixDOFqODE(const sixDOFqODE&);
166 //- Disallow default bitwise assignment
167 void operator=(const sixDOFqODE&);
170 //- Set ODE coefficients from position and rotation
174 // Variables in relative coordinate system (solved for)
176 //- Return acceleration in relative coordinate system
177 // given current values of relative displacement and velocity
180 const dimensionedVector& xR,
181 const dimensionedVector& uR,
182 const HamiltonRodriguezRot& rotation
186 //- Return rotational acceleration in relative coordinate system
187 // given current values for relative rotational velocity
188 dimensionedVector OmegaDot
190 const HamiltonRodriguezRot& rotation,
191 const dimensionedVector& omega
194 //- Return the Euler part of moment equation
197 const dimensionedVector& omega
200 //- Constrain rotation vector in referent or global coordinate
202 void constrainRotation(vector& vec) const;
204 //- Constrain translation vector in referent or global coordinate
206 void constrainTranslation(vector& vec) const;
213 //- Construct from dictionary
214 sixDOFqODE(const IOobject& io);
216 //- Construct sixDOFqODE, changing name
226 virtual ~sixDOFqODE();
232 inline const dimensionedScalar& mass() const;
234 //- Return access to mass
235 inline dimensionedScalar& mass();
237 //- Return moment of inertia
238 inline const dimensionedDiagTensor& momentOfInertia() const;
240 //- Return access to moment of inertia
241 inline dimensionedDiagTensor& momentOfInertia();
243 //- Return equilibrium position of origin
244 inline const dimensionedVector& Xequilibrium() const;
246 //- Return access to equilibrium position of origin
247 inline dimensionedVector& Xequilibrium();
250 // Variables in relative coordinate system (solved for)
252 //- Return displacement in translated coordinate system
253 // relative to spring equilibrium
254 inline const dimensionedVector& Xrel() const;
256 //- Return rotational velocity in relative coordinate system
257 inline const dimensionedVector& omega() const;
259 //- Return rotational acceleration in relative coordinate system
260 inline dimensionedVector omegaDot() const;
263 // Displacement and rotation in the absolute coordinate system
265 //- Return position of origin in absolute coordinate system
266 inline dimensionedVector X() const;
268 //- Return velocity of origin
269 inline const dimensionedVector& U() const;
271 //- Return average velocity of origin for the previous time-step
272 inline const dimensionedVector& Uaverage() const;
274 //- Return finite rotation
275 inline const finiteRotation& rotation() const;
277 //- Return acceleration of origin
278 inline dimensionedVector A() const;
280 //- Return rotational vector of body
281 inline vector rotVector() const;
283 //- Return rotation angle of body
284 inline dimensionedScalar rotAngle() const;
287 // Non-constant access
289 //- Set position of origin
290 inline void setXrel(const vector& x);
292 //- Set velocity of origin
293 inline void setU(const vector& u);
295 //- Set rotational angle in relative
297 inline void setRotation(const HamiltonRodriguezRot& rot);
299 //- Set rotational velocity in relative
301 inline void setOmega(const vector& omega);
303 //- Set referent coordinate system to apply constraints
304 inline void setReferentRotation(const HamiltonRodriguezRot& rot);
307 // Average motion per time-step
309 //- Return average rotational vector of body
310 inline vector rotVectorAverage() const;
312 //- Return average rotational velocity in
313 // relative coordinate system
314 inline const dimensionedVector& omegaAverage() const;
316 //- Return average rotational velocity in
317 // absolute coordinate system
318 inline const dimensionedVector& omegaAverageAbsolute() const;
323 //- Return force in inertial coord. sys.
324 inline const dimensionedVector& force() const;
326 //- Return access to force in inertial coord. sys.
327 inline dimensionedVector& force();
329 //- Return moment in inertial coord. sys.
330 inline const dimensionedVector& moment() const;
332 //- Return access to moment in inertial coord. sys.
333 inline dimensionedVector& moment();
335 //- Return force in relative coord. sys.
336 inline const dimensionedVector& forceRelative() const;
338 //- Return access to force in relative coord. sys.
339 inline dimensionedVector& forceRelative();
341 //- Return moment in relative coord. sys.
342 inline const dimensionedVector& momentRelative() const;
344 //- Return access to moment in relative coord. sys.
345 inline dimensionedVector& momentRelative();
348 //- Return total force in inertial coord. sys.
349 inline dimensionedVector forceTotal() const;
351 //- Return total moment in inertial coord. sys.
352 inline dimensionedVector momentTotal() const;
357 //- Return rotation tensor to relative coordinate system
358 inline tensor toRelative() const;
360 //- Return rotation tensor to absolute coordinate system
361 inline tensor toAbsolute() const;
363 //- Return transformation tensor between new and previous rotation
364 inline const tensor& rotIncrementTensor() const;
366 //- Set ODE parameters from another ODE
367 void setState(const sixDOFqODE&);
372 //- Return number of equations
373 virtual label nEqns() const
378 //- Return access to coefficients
379 virtual scalarField& coeffs()
384 //- Return reference to coefficients
385 virtual const scalarField& coeffs() const
390 //- Return derivatives
391 virtual void derivatives
394 const scalarField& y,
399 virtual void jacobian
402 const scalarField& y,
404 scalarSquareMatrix& dfdy
407 //- Update ODE after the solution, advancing by delta
408 virtual void update(const scalar delta);
411 //- WriteData member function required by regIOobject
412 bool writeData(Ostream&) const;
417 friend Ostream& operator<<(Ostream&, const sixDOFqODE&);
421 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
423 } // End namespace Foam
425 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
427 #include "sixDOFqODEI.H"
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
433 // ************************************************************************* //