Bugfix: New way of handling constraints in 6-DOF
[foam-extend-3.2.git] / src / ODE / sixDOF / sixDOFqODE / sixDOFqODE.H
blobe61f54f878a57f7ee350b26dcd34bce72aec3cd5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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/>.
24 Class
25     sixDOFqODE
27 Description
28     6-DOF solver using quaternions
30 Author
31     Dubravko Matijasevic, FSB Zagreb.  All rights reserved.
32     Updated by Hrvoje Jasak.
34 SourceFiles
35     sixDOFqODEI.H
36     sixDOFqODE.C
38 \*---------------------------------------------------------------------------*/
40 #ifndef sixDOFqODE_H
41 #define sixDOFqODE_H
43 #include "ODE.H"
44 #include "IOdictionary.H"
45 #include "dimensionedTypes.H"
46 #include "HamiltonRodriguezRot.H"
47 #include "finiteRotation.H"
48 #include "vectorField.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 namespace Foam
55 /*---------------------------------------------------------------------------*\
56                          Class sixDOFqODE Declaration
57 \*---------------------------------------------------------------------------*/
59 class sixDOFqODE
61     public IOdictionary,
62     public ODE
64     // Private data
66         // Body data
68             //- Mass
69             dimensionedScalar mass_;
71             //- Rotational moment of inertia around centre of mass
72             //  in body (relative) coordinates - aligned with main axes
73             dimensionedDiagTensor momentOfInertia_;
76         // Platform variables
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
94             dimensionedVector U_;
96             //- Average velocity of mass centroid at previous time-step
97             dimensionedVector Uaverage_;
99             //- Finite rotation
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_;
115         // External forces
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_;
130         //- ODE coefficients
131         scalarField coeffs_;
134         //- Motion constraints (given as fixed motion components)
136             //- Fixed surge (x-translation)
137             Switch fixedSurge_;
139             //- Fixed sway (y-translation)
140             Switch fixedSway_;
142             //- Fixed heave (z-translation)
143             Switch fixedHeave_;
145             //- Fixed roll (rotation around x)
146             Switch fixedRoll_;
148             //- Fixed pitch (rotation around y)
149             Switch fixedPitch_;
151             //- Fixed yaw (rotation around z)
152             Switch fixedYaw_;
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
171         void setCoeffs();
174         // Variables in relative coordinate system (solved for)
176             //- Return acceleration in relative coordinate system
177             //  given current values of relative displacement and velocity
178             dimensionedVector A
179             (
180                 const dimensionedVector& xR,
181                 const dimensionedVector& uR,
182                 const HamiltonRodriguezRot& rotation
183             ) const;
186             //- Return rotational acceleration in relative coordinate system
187             //  given current values for relative rotational velocity
188             dimensionedVector OmegaDot
189             (
190                 const HamiltonRodriguezRot& rotation,
191                 const dimensionedVector& omega
192             ) const;
194             //- Return the Euler part of moment equation
195             dimensionedVector E
196             (
197                 const dimensionedVector& omega
198             ) const;
200             //- Constrain rotation vector in referent or global coordinate
201             //  system
202             void constrainRotation(vector& vec) const;
204             //- Constrain translation vector in referent or global coordinate
205             //  system
206             void constrainTranslation(vector& vec) const;
209 public:
211     // Constructors
213         //- Construct from dictionary
214         sixDOFqODE(const IOobject& io);
216         //- Construct sixDOFqODE, changing name
217         sixDOFqODE
218         (
219             const word& name,
220             const sixDOFqODE& sd
221         );
224     // Destructor
226         virtual ~sixDOFqODE();
229     // Member Functions
231         //- Return mass
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
296             //  coordinate system
297             inline void setRotation(const HamiltonRodriguezRot& rot);
299             //- Set rotational velocity in relative
300             //  coordinate system
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;
321         // Force and moment
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;
355         // Rotations
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&);
370         // ODE parameters
372             //- Return number of equations
373             virtual label nEqns() const
374             {
375                 return 13;
376             }
378             //- Return access to coefficients
379             virtual scalarField& coeffs()
380             {
381                 return coeffs_;
382             }
384             //- Return reference to coefficients
385             virtual const scalarField& coeffs() const
386             {
387                 return coeffs_;
388             }
390             //- Return derivatives
391             virtual void derivatives
392             (
393                 const scalar x,
394                 const scalarField& y,
395                 scalarField& dydx
396             ) const;
398             //- Return Jacobian
399             virtual void jacobian
400             (
401                 const scalar x,
402                 const scalarField& y,
403                 scalarField& dfdx,
404                 scalarSquareMatrix& dfdy
405             ) const;
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;
415     // Ostream operator
417         friend Ostream& operator<<(Ostream&, const sixDOFqODE&);
421 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
423 } // End namespace Foam
425 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
427 #include "sixDOFqODEI.H"
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
431 #endif
433 // ************************************************************************* //