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_;
87 //- Translational relaxation factor
90 //- Rotational relaxation factor
93 //- Old translational relaxation factor
94 scalar oldRelaxFactorT_;
96 //- Old rotational relaxation factor
97 scalar oldRelaxFactorR_;
100 // Initial body state variables
102 //- Displacement relative to spring equilibrium
103 dimensionedVector Xrel_;
105 //- Velocity of mass centroid
106 dimensionedVector U_;
108 //- Average velocity of mass centroid at previous time-step
109 dimensionedVector Uaverage_;
112 finiteRotation rotation_;
114 //- Rotational velocity about mass centroid
115 dimensionedVector omega_;
118 // Average variables that need to be stored
120 //- Average rotational velocity in relative coordinate system
121 dimensionedVector omegaAverage_;
123 //- Average rotational velocity in absolute coordinate system
124 dimensionedVector omegaAverageAbsolute_;
129 //- Accelerations from previous iterations
130 // A_[2] is the old value, A_[1] old old, A_[0] old old old
132 List<vector> OmegaDot_;
134 //- Previos iteration non relaxed accelerations
136 List<vector> OmegaDotn_;
138 //- Force driving the motion in inertial coord. sys.
139 dimensionedVector force_;
141 //- Moment driving the motion in inertial coord. sys.
142 dimensionedVector moment_;
144 //- Force driving the motion in relative coord. sys.
145 dimensionedVector forceRelative_;
147 //- Moment driving the motion in relative coord. sys.
148 dimensionedVector momentRelative_;
155 //- Motion constraints (given as fixed motion components)
157 //- Fixed surge (x-translation)
160 //- Fixed sway (y-translation)
163 //- Fixed heave (z-translation)
166 //- Fixed roll (rotation around x)
169 //- Fixed pitch (rotation around y)
172 //- Fixed yaw (rotation around z)
175 //- Restraints in referent coordinate system
176 Switch referentMotionConstraints_;
178 //- Rotation of referent coordinate system
179 HamiltonRodriguezRot referentRotation_;
182 // Private Member Functions
184 //- Disallow default bitwise copy construct
185 sixDOFqODE(const sixDOFqODE&);
187 //- Disallow default bitwise assignment
188 void operator=(const sixDOFqODE&);
191 //- Set ODE coefficients from position and rotation
195 // Variables in relative coordinate system (solved for)
197 //- Return acceleration in relative coordinate system
198 // given current values of relative displacement and velocity
201 const dimensionedVector& xR,
202 const dimensionedVector& uR,
203 const HamiltonRodriguezRot& rotation
207 //- Return rotational acceleration in relative coordinate system
208 // given current values for relative rotational velocity
209 dimensionedVector OmegaDot
211 const HamiltonRodriguezRot& rotation,
212 const dimensionedVector& omega
215 //- Return the Euler part of moment equation
218 const dimensionedVector& omega
221 //- Constrain rotation vector in referent or global coordinate
223 void constrainRotation(vector& vec) const;
225 //- Constrain translation vector in referent or global coordinate
227 void constrainTranslation(vector& vec) const;
229 //- Update Aitkens relaxation parameters
230 void aitkensRelaxation(const scalar min, const scalar max);
237 //- Construct from dictionary
238 sixDOFqODE(const IOobject& io);
240 //- Construct sixDOFqODE, changing name
250 virtual ~sixDOFqODE();
256 inline const dimensionedScalar& mass() const;
258 //- Return access to mass
259 inline dimensionedScalar& mass();
261 //- Return moment of inertia
262 inline const dimensionedDiagTensor& momentOfInertia() const;
264 //- Return access to moment of inertia
265 inline dimensionedDiagTensor& momentOfInertia();
267 //- Return equilibrium position of origin
268 inline const dimensionedVector& Xequilibrium() const;
270 //- Return access to equilibrium position of origin
271 inline dimensionedVector& Xequilibrium();
274 // Variables in relative coordinate system (solved for)
276 //- Return displacement in translated coordinate system
277 // relative to spring equilibrium
278 inline const dimensionedVector& Xrel() const;
280 //- Return rotational velocity in relative coordinate system
281 inline const dimensionedVector& omega() const;
283 //- Return rotational acceleration in relative coordinate system
284 inline dimensionedVector omegaDot() const;
287 // Displacement and rotation in the absolute coordinate system
289 //- Return position of origin in absolute coordinate system
290 inline dimensionedVector X() const;
292 //- Return velocity of origin
293 inline const dimensionedVector& U() const;
295 //- Return average velocity of origin for the previous time-step
296 inline const dimensionedVector& Uaverage() const;
298 //- Return finite rotation
299 inline const finiteRotation& rotation() const;
301 //- Return acceleration of origin
302 inline dimensionedVector A() const;
304 //- Return rotational vector of body
305 inline vector rotVector() const;
307 //- Return rotation angle of body
308 inline dimensionedScalar rotAngle() const;
311 // Non-constant access
313 //- Set position of origin
314 inline void setXrel(const vector& x);
316 //- Set velocity of origin
317 inline void setU(const vector& u);
319 //- Set rotational angle in relative
321 inline void setRotation(const HamiltonRodriguezRot& rot);
323 //- Set rotational velocity in relative
325 inline void setOmega(const vector& omega);
327 //- Set referent coordinate system to apply constraints
328 inline void setReferentRotation(const HamiltonRodriguezRot& rot);
331 // Average motion per time-step
333 //- Return average rotational vector of body
334 inline vector rotVectorAverage() const;
336 //- Return average rotational velocity in
337 // relative coordinate system
338 inline const dimensionedVector& omegaAverage() const;
340 //- Return average rotational velocity in
341 // absolute coordinate system
342 inline const dimensionedVector& omegaAverageAbsolute() const;
347 //- Return force in inertial coord. sys.
348 inline const dimensionedVector& force() const;
350 //- Return access to force in inertial coord. sys.
351 inline dimensionedVector& force();
353 //- Return moment in inertial coord. sys.
354 inline const dimensionedVector& moment() const;
356 //- Return access to moment in inertial coord. sys.
357 inline dimensionedVector& moment();
359 //- Return force in relative coord. sys.
360 inline const dimensionedVector& forceRelative() const;
362 //- Return access to force in relative coord. sys.
363 inline dimensionedVector& forceRelative();
365 //- Return moment in relative coord. sys.
366 inline const dimensionedVector& momentRelative() const;
368 //- Return access to moment in relative coord. sys.
369 inline dimensionedVector& momentRelative();
371 //- Return total force in inertial coord. sys.
372 inline dimensionedVector forceTotal() const;
374 //- Return total moment in inertial coord. sys.
375 inline dimensionedVector momentTotal() const;
377 //- Relax the force(acceleration) using Aitkens or fixed relaxation
378 void relaxAcceleration
380 const scalar minRelFactor,
381 const scalar maxRelFactor
387 //- Return rotation tensor to relative coordinate system
388 inline tensor toRelative() const;
390 //- Return rotation tensor to absolute coordinate system
391 inline tensor toAbsolute() const;
393 //- Return transformation tensor between new and previous rotation
394 inline const tensor& rotIncrementTensor() const;
396 //- Set ODE parameters from another ODE
397 void setState(const sixDOFqODE&);
402 //- Return number of equations
403 virtual label nEqns() const
408 //- Return access to coefficients
409 virtual scalarField& coeffs()
414 //- Return reference to coefficients
415 virtual const scalarField& coeffs() const
420 //- Return derivatives
421 virtual void derivatives
424 const scalarField& y,
429 virtual void jacobian
432 const scalarField& y,
434 scalarSquareMatrix& dfdy
437 //- Update ODE after the solution, advancing by delta
438 virtual void update(const scalar delta);
441 //- WriteData member function required by regIOobject
442 bool writeData(Ostream&) const;
447 friend Ostream& operator<<(Ostream&, const sixDOFqODE&);
451 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
453 } // End namespace Foam
455 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
457 #include "sixDOFqODEI.H"
459 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
463 // ************************************************************************* //