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 \*---------------------------------------------------------------------------*/
28 #include "addToRunTimeSelectionTable.H"
31 #include "interpolateXY.H"
32 #include "mathematicalConstants.H"
34 using namespace Foam::mathematicalConstant;
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 namespace solidBodyMotionFunctions
42 defineTypeNameAndDebug(SKA, 0);
43 addToRunTimeSelectionTable(solidBodyMotionFunction, SKA, dictionary);
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 Foam::solidBodyMotionFunctions::SKA::calcTransformation(const scalar t) const
57 "solidBodyMotionFunctions::SKA::transformation()"
58 ) << "current time (" << t
59 << ") is less than the minimum in the data table ("
64 if (t > times_[times_.size()-1])
68 "solidBodyMotionFunctions::SKA::transformation()"
69 ) << "current time (" << t
70 << ") is greater than the maximum in the data table ("
71 << times_[times_.size()-1] << ')'
75 translationRotationVectors TRV = interpolateXY
82 // Convert the rotational motion from deg to rad
85 quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
86 septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
92 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
94 Foam::solidBodyMotionFunctions::SKA::SKA
96 const dictionary& SBMFCoeffs,
100 solidBodyMotionFunction(SBMFCoeffs, runTime)
106 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
108 Foam::solidBodyMotionFunctions::SKA::~SKA()
112 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
114 Foam::septernion Foam::solidBodyMotionFunctions::SKA::transformation() const
116 scalar t = time_.value();
118 septernion TR = calcTransformation(t);
120 Info<< "solidBodyMotionFunctions::SKA::transformation(): "
121 << "Time = " << t << " transformation: " << TR << endl;
127 Foam::septernion Foam::solidBodyMotionFunctions::SKA::velocity() const
129 // Velocity is calculated as a difference
130 scalar t = time_.value();
131 scalar dt = time_.deltaT().value();
133 return (calcTransformation(t + dt) - calcTransformation(t))/dt;
137 bool Foam::solidBodyMotionFunctions::SKA::read(const dictionary& SBMFCoeffs)
139 solidBodyMotionFunction::read(SBMFCoeffs);
141 // If the timeDataFileName has changed read the file
143 fileName newTimeDataFileName(SBMFCoeffs_.lookup("timeDataFileName"));
145 if (newTimeDataFileName != timeDataFileName_)
147 timeDataFileName_ = newTimeDataFileName;
149 IFstream dataStream(timeDataFileName_);
151 if (dataStream.good())
153 List<Tuple2<scalar, translationRotationVectors> > timeValues
158 times_.setSize(timeValues.size());
159 values_.setSize(timeValues.size());
161 forAll(timeValues, i)
163 times_[i] = timeValues[i].first();
164 values_[i] = timeValues[i].second();
171 "solidBodyMotionFunctions::SKA::read(const dictionary&)"
172 ) << "Cannot open time data file " << timeDataFileName_
177 SBMFCoeffs_.lookup("CofG") >> CofG_;
183 // ************************************************************************* //