initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / dynamicFvMesh / solidBodyMotionFvMesh / solidBodyMotionFunctions / SKA / SKA.C
blobe2e59d478811992689fe390690c62d1ccf16ae82
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
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 "SKA.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "Tuple2.H"
30 #include "IFstream.H"
31 #include "interpolateXY.H"
32 #include "mathematicalConstants.H"
34 using namespace Foam::mathematicalConstant;
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 namespace Foam
40 namespace solidBodyMotionFunctions
42     defineTypeNameAndDebug(SKA, 0);
43     addToRunTimeSelectionTable(solidBodyMotionFunction, SKA, dictionary);
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::solidBodyMotionFunctions::SKA::SKA
52     const dictionary& SBMFCoeffs,
53     const Time& runTime
56     solidBodyMotionFunction(SBMFCoeffs, runTime)
58     read(SBMFCoeffs);
62 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
64 Foam::solidBodyMotionFunctions::SKA::~SKA()
68 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
70 Foam::septernion Foam::solidBodyMotionFunctions::SKA::transformation() const
72     scalar t = time_.value();
74     if (t < times_[0])
75     {
76         FatalErrorIn
77         (
78             "solidBodyMotionFunctions::SKA::transformation()"
79         )   << "current time (" << t
80             << ") is less than the minimum in the data table ("
81             << times_[0] << ')'
82             << exit(FatalError);
83     }
85     if (t > times_[times_.size()-1])
86     {
87         FatalErrorIn
88         (
89             "solidBodyMotionFunctions::SKA::transformation()"
90         )   << "current time (" << t
91             << ") is greater than the maximum in the data table ("
92             << times_[times_.size()-1] << ')'
93             << exit(FatalError);
94     }
96     translationRotationVectors TRV = interpolateXY
97     (
98         t,
99         times_,
100         values_
101     );
103     // Convert the rotational motion from deg to rad
104     TRV[1] *= pi/180.0;
106     quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
107     septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
109     Info<< "solidBodyMotionFunctions::SKA::transformation(): "
110         << "Time = " << t << " transformation: " << TR << endl;
112     return TR;
116 bool Foam::solidBodyMotionFunctions::SKA::read(const dictionary& SBMFCoeffs)
118     solidBodyMotionFunction::read(SBMFCoeffs);
120     // If the timeDataFileName has changed read the file
122     fileName newTimeDataFileName(SBMFCoeffs_.lookup("timeDataFileName"));
124     if (newTimeDataFileName != timeDataFileName_)
125     {
126         timeDataFileName_ = newTimeDataFileName;
128         IFstream dataStream(timeDataFileName_);
130         if (dataStream.good())
131         {
132             List<Tuple2<scalar, translationRotationVectors> > timeValues
133             (
134                 dataStream
135             );
137             times_.setSize(timeValues.size());
138             values_.setSize(timeValues.size());
140             forAll(timeValues, i)
141             {
142                 times_[i] = timeValues[i].first();
143                 values_[i] = timeValues[i].second();
144             }
145         }
146         else
147         {
148             FatalErrorIn
149             (
150                 "solidBodyMotionFunctions::SKA::read(const dictionary&)"
151             )   << "Cannot open time data file " << timeDataFileName_
152                 << exit(FatalError);
153         }
154     }
156     SBMFCoeffs_.lookup("CofG") >> CofG_;
158     return true;
162 // ************************************************************************* //