Forward compatibility: flex
[foam-extend-3.2.git] / src / dynamicMesh / meshMotion / solidBodyMotion / graphVelocity / graphVelocity.C
blob1c6b1e1c60b5bdda2677f64bca05176281d03362
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 \*---------------------------------------------------------------------------*/
27 #include "graphVelocity.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "mathematicalConstants.H"
30 #include "interpolateXY.H"
31 #include "IFstream.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
37 namespace solidBodyMotionFunctions
40 defineTypeNameAndDebug(graphVelocity, 0);
41 addToRunTimeSelectionTable(solidBodyMotionFunction, graphVelocity, dictionary);
46 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
48 Foam::vector
49 Foam::solidBodyMotionFunctions::graphVelocity::translationalVelocity() const
51     const scalar t = time_.value() - time_.deltaT().value()/2;
53     return vector
54            (
55                interpolateXY(t, surge_.x(), surge_.y()),
56                interpolateXY(t, sway_.x(), sway_.y()),
57                interpolateXY(t, heave_.x(), heave_.y())
58            );
62 Foam::vector
63 Foam::solidBodyMotionFunctions::graphVelocity::rotationalVelocity() const
65     const scalar t = time_.value() - time_.deltaT().value()/2;
67     scalar rollVelocity = interpolateXY(t, roll_.x(), roll_.y());
68     scalar pitchVelocity = interpolateXY(t, pitch_.x(), pitch_.y());
69     scalar yawVelocity = interpolateXY(t, yaw_.x(), yaw_.y());
71     if (inDegrees_)
72     {
73         const scalar piBy180 = mathematicalConstant::pi/180.0;
75         rollVelocity *= piBy180;
76         pitchVelocity *= piBy180;
77         yawVelocity *= piBy180;
78     }
80     return vector(rollVelocity, pitchVelocity, yawVelocity);
84 Foam::septernion
85 Foam::solidBodyMotionFunctions::graphVelocity::calcTransformation() const
87     // Integrate velocity to get position
88     if(localTimeIndex_ != time_.timeIndex())
89     {
90         // Set old translation and rotation to the previous state
91         translationOld_ = translation_;
92         rotationOld_ = rotation_;
94         const scalar dt = time_.deltaT().value();
96         translation_ += translationalVelocity()*dt;
97         rotation_ += rotationalVelocity()*dt;
99         localTimeIndex_ = time_.timeIndex();
100     }
102     const quaternion R(rotation_.x(), rotation_.y(), rotation_.z());
103     const septernion TR
104         (
105             septernion(origin_ + translation_)*R*septernion(-origin_)
106         );
108     return TR;
111 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
113 Foam::solidBodyMotionFunctions::graphVelocity::graphVelocity
115     const dictionary& SBMFCoeffs,
116     const Time& runTime
119     solidBodyMotionFunction(SBMFCoeffs, runTime),
120     translation_(vector::zero),
121     rotation_(vector::zero),
122     translationOld_(vector::zero),
123     rotationOld_(vector::zero),
124     localTimeIndex_(-1),
125     surge_
126     (
127         "surge",
128         "t",
129         "eta1Dot",
130         IFstream
131         (
132             time_.path()/time_.caseConstant()/
133             word(SBMFCoeffs_.lookup("surge"))
134         )()
135     ),
136     sway_
137     (
138         "sway",
139         "t",
140         "eta2Dot",
141         IFstream
142         (
143             time_.path()/time_.caseConstant()/
144             word(SBMFCoeffs_.lookup("sway"))
145         )()
146     ),
147     heave_
148     (
149         "heave",
150         "t",
151         "eta3Dot",
152         IFstream
153         (
154             time_.path()/time_.caseConstant()/
155             word(SBMFCoeffs_.lookup("heave"))
156         )()
157     ),
158     roll_
159     (
160         "roll",
161         "t",
162         "eta4Dot",
163         IFstream
164         (
165             time_.path()/time_.caseConstant()/
166             word(SBMFCoeffs_.lookup("roll"))
167         )()
168     ),
169     pitch_
170     (
171         "pitch",
172         "t",
173         "eta5Dot",
174         IFstream
175         (
176             time_.path()/time_.caseConstant()/
177             word(SBMFCoeffs_.lookup("pitch"))
178         )()
179     ),
180     yaw_
181     (
182         "yaw",
183         "t",
184         "eta6Dot",
185         IFstream
186         (
187             time_.path()/time_.caseConstant()/
188             word(SBMFCoeffs_.lookup("yaw"))
189         )()
190     )
192     read(SBMFCoeffs);
195 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
197 Foam::septernion
198 Foam::solidBodyMotionFunctions::graphVelocity::transformation() const
200    const septernion TR = calcTransformation();
202    Info<< "solidBodyMotionFunctions::graphVelocity::transformation(): "
203    << "Time = " << time_.value() << " transformation: " << TR << endl;
205    return TR;
209 Foam::septernion
210 Foam::solidBodyMotionFunctions::graphVelocity::velocity() const
212     const scalar dt = time_.deltaT().value();
214     const septernion TR = calcTransformation();
216     const quaternion ROld(rotationOld_.x(), rotationOld_.y(), rotationOld_.z());
217     const septernion TROld
218         (
219             septernion(origin_ + translationOld_)*ROld*septernion(-origin_)
220         );
222     return septernion
223     (
224         (TR.t() - TROld.t())/dt,
225         (TR.r()/TROld.r())/dt
226     );
230 bool Foam::solidBodyMotionFunctions::graphVelocity::read
232     const dictionary& SBMFCoeffs
235     solidBodyMotionFunction::read(SBMFCoeffs);
237     SBMFCoeffs_.lookup("origin") >> origin_;
238     SBMFCoeffs_.lookup("inDegrees") >> inDegrees_;
240     word surge = SBMFCoeffs_.lookup("surge");
241     word sway = SBMFCoeffs_.lookup("sway");
242     word heave = SBMFCoeffs_.lookup("heave");
243     word roll = SBMFCoeffs_.lookup("roll");
244     word pitch = SBMFCoeffs_.lookup("pitch");
245     word yaw = SBMFCoeffs_.lookup("yaw");
247     surge_ = graph
248     (
249         "surge",
250         "t",
251         "eta1Dot",
252         IFstream
253         (
254             time_.path()/time_.caseConstant()/
255             surge
256         )()
257     );
258     sway_ = graph
259     (
260         "sway",
261         "t",
262         "eta2Dot",
263         IFstream
264         (
265             time_.path()/time_.caseConstant()/
266             sway
267         )()
268     );
269     heave_ = graph
270     (
271         "heave",
272         "t",
273         "eta3Dot",
274         IFstream
275         (
276             time_.path()/time_.caseConstant()/
277             heave
278         )()
279     );
280     roll_ = graph
281     (
282         "roll",
283         "t",
284         "eta4Dot",
285         IFstream
286         (
287             time_.path()/time_.caseConstant()/
288             roll
289         )()
290     );
291     pitch_ = graph
292     (
293         "pitch",
294         "t",
295         "eta5Dot",
296         IFstream
297         (
298             time_.path()/time_.caseConstant()/
299             pitch
300         )()
301     );
302     yaw_ = graph
303     (
304         "yaw",
305         "t",
306         "eta6Dot",
307         IFstream
308         (
309             time_.path()/time_.caseConstant()/
310             yaw
311         )()
312     );
314     return true;
317 // ************************************************************************* //