1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace solidBodyMotionFunctions
40 defineTypeNameAndDebug(graphVelocity, 0);
41 addToRunTimeSelectionTable(solidBodyMotionFunction, graphVelocity, dictionary);
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 Foam::solidBodyMotionFunctions::graphVelocity::translationalVelocity() const
51 const scalar t = time_.value() - time_.deltaT().value()/2;
55 interpolateXY(t, surge_.x(), surge_.y()),
56 interpolateXY(t, sway_.x(), sway_.y()),
57 interpolateXY(t, heave_.x(), heave_.y())
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());
73 const scalar piBy180 = mathematicalConstant::pi/180.0;
75 rollVelocity *= piBy180;
76 pitchVelocity *= piBy180;
77 yawVelocity *= piBy180;
80 return vector(rollVelocity, pitchVelocity, yawVelocity);
85 Foam::solidBodyMotionFunctions::graphVelocity::calcTransformation() const
87 // Integrate velocity to get position
88 if(localTimeIndex_ != time_.timeIndex())
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();
102 const quaternion R(rotation_.x(), rotation_.y(), rotation_.z());
105 septernion(origin_ + translation_)*R*septernion(-origin_)
111 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113 Foam::solidBodyMotionFunctions::graphVelocity::graphVelocity
115 const dictionary& SBMFCoeffs,
119 solidBodyMotionFunction(SBMFCoeffs, runTime),
120 translation_(vector::zero),
121 rotation_(vector::zero),
122 translationOld_(vector::zero),
123 rotationOld_(vector::zero),
132 time_.path()/time_.caseConstant()/
133 word(SBMFCoeffs_.lookup("surge"))
143 time_.path()/time_.caseConstant()/
144 word(SBMFCoeffs_.lookup("sway"))
154 time_.path()/time_.caseConstant()/
155 word(SBMFCoeffs_.lookup("heave"))
165 time_.path()/time_.caseConstant()/
166 word(SBMFCoeffs_.lookup("roll"))
176 time_.path()/time_.caseConstant()/
177 word(SBMFCoeffs_.lookup("pitch"))
187 time_.path()/time_.caseConstant()/
188 word(SBMFCoeffs_.lookup("yaw"))
195 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
198 Foam::solidBodyMotionFunctions::graphVelocity::transformation() const
200 const septernion TR = calcTransformation();
202 Info<< "solidBodyMotionFunctions::graphVelocity::transformation(): "
203 << "Time = " << time_.value() << " transformation: " << TR << endl;
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
219 septernion(origin_ + translationOld_)*ROld*septernion(-origin_)
224 (TR.t() - TROld.t())/dt,
225 (TR.r()/TROld.r())/dt
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");
254 time_.path()/time_.caseConstant()/
265 time_.path()/time_.caseConstant()/
276 time_.path()/time_.caseConstant()/
287 time_.path()/time_.caseConstant()/
298 time_.path()/time_.caseConstant()/
309 time_.path()/time_.caseConstant()/
317 // ************************************************************************* //