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/>.
24 \*---------------------------------------------------------------------------*/
27 #include "addToRunTimeSelectionTable.H"
30 #include "interpolateXY.H"
31 #include "mathematicalConstants.H"
33 using namespace Foam::mathematicalConstant;
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 namespace solidBodyMotionFunctions
41 defineTypeNameAndDebug(SKA, 0);
42 addToRunTimeSelectionTable(solidBodyMotionFunction, SKA, dictionary);
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 Foam::solidBodyMotionFunctions::SKA::calcTransformation(const scalar t) const
56 "solidBodyMotionFunctions::SKA::transformation()"
57 ) << "current time (" << t
58 << ") is less than the minimum in the data table ("
63 if (t > times_[times_.size()-1])
67 "solidBodyMotionFunctions::SKA::transformation()"
68 ) << "current time (" << t
69 << ") is greater than the maximum in the data table ("
70 << times_[times_.size()-1] << ')'
74 translationRotationVectors TRV = interpolateXY
81 // Convert the rotational motion from deg to rad
84 quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
85 septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
93 Foam::solidBodyMotionFunctions::SKA::SKA
95 const dictionary& SBMFCoeffs,
99 solidBodyMotionFunction(SBMFCoeffs, runTime)
105 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
107 Foam::solidBodyMotionFunctions::SKA::~SKA()
111 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
113 Foam::septernion Foam::solidBodyMotionFunctions::SKA::transformation() const
115 scalar t = time_.value();
117 septernion TR = calcTransformation(t);
119 Info<< "solidBodyMotionFunctions::SKA::transformation(): "
120 << "Time = " << t << " transformation: " << TR << endl;
126 Foam::septernion Foam::solidBodyMotionFunctions::SKA::velocity() const
128 // Velocity is calculated as a difference
129 scalar t = time_.value();
130 scalar dt = time_.deltaT().value();
132 const septernion velocity
134 (calcTransformation(t).t() - calcTransformation(t - dt).t())/dt,
135 (calcTransformation(t).r()/calcTransformation(t - dt).r())/dt
142 bool Foam::solidBodyMotionFunctions::SKA::read(const dictionary& SBMFCoeffs)
144 solidBodyMotionFunction::read(SBMFCoeffs);
146 // If the timeDataFileName has changed read the file
148 fileName newTimeDataFileName(SBMFCoeffs_.lookup("timeDataFileName"));
150 if (newTimeDataFileName != timeDataFileName_)
152 timeDataFileName_ = newTimeDataFileName;
154 IFstream dataStream(timeDataFileName_);
156 if (dataStream.good())
158 List<Tuple2<scalar, translationRotationVectors> > timeValues
163 times_.setSize(timeValues.size());
164 values_.setSize(timeValues.size());
166 forAll(timeValues, i)
168 times_[i] = timeValues[i].first();
169 values_[i] = timeValues[i].second();
176 "solidBodyMotionFunctions::SKA::read(const dictionary&)"
177 ) << "Cannot open time data file " << timeDataFileName_
182 SBMFCoeffs_.lookup("CofG") >> CofG_;
188 // ************************************************************************* //