ENH: RASModel.C: clipping input to log
[OpenFOAM-1.7.x.git] / src / dynamicFvMesh / solidBodyMotionFvMesh / solidBodyMotionFunctions / SKA / SKA.C
blob9a7cc8e38eb1597fa592da12c0e3412f2651c5c3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "SKA.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "Tuple2.H"
29 #include "IFstream.H"
30 #include "interpolateXY.H"
31 #include "mathematicalConstants.H"
33 using namespace Foam::mathematicalConstant;
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
39 namespace solidBodyMotionFunctions
41     defineTypeNameAndDebug(SKA, 0);
42     addToRunTimeSelectionTable(solidBodyMotionFunction, SKA, dictionary);
47 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
49 Foam::solidBodyMotionFunctions::SKA::SKA
51     const dictionary& SBMFCoeffs,
52     const Time& runTime
55     solidBodyMotionFunction(SBMFCoeffs, runTime)
57     read(SBMFCoeffs);
61 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
63 Foam::solidBodyMotionFunctions::SKA::~SKA()
67 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
69 Foam::septernion Foam::solidBodyMotionFunctions::SKA::transformation() const
71     scalar t = time_.value();
73     if (t < times_[0])
74     {
75         FatalErrorIn
76         (
77             "solidBodyMotionFunctions::SKA::transformation()"
78         )   << "current time (" << t
79             << ") is less than the minimum in the data table ("
80             << times_[0] << ')'
81             << exit(FatalError);
82     }
84     if (t > times_[times_.size()-1])
85     {
86         FatalErrorIn
87         (
88             "solidBodyMotionFunctions::SKA::transformation()"
89         )   << "current time (" << t
90             << ") is greater than the maximum in the data table ("
91             << times_[times_.size()-1] << ')'
92             << exit(FatalError);
93     }
95     translationRotationVectors TRV = interpolateXY
96     (
97         t,
98         times_,
99         values_
100     );
102     // Convert the rotational motion from deg to rad
103     TRV[1] *= pi/180.0;
105     quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
106     septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
108     Info<< "solidBodyMotionFunctions::SKA::transformation(): "
109         << "Time = " << t << " transformation: " << TR << endl;
111     return TR;
115 bool Foam::solidBodyMotionFunctions::SKA::read(const dictionary& SBMFCoeffs)
117     solidBodyMotionFunction::read(SBMFCoeffs);
119     // If the timeDataFileName has changed read the file
121     fileName newTimeDataFileName
122     (
123         fileName(SBMFCoeffs_.lookup("timeDataFileName")).expand()
124     );
126     if (newTimeDataFileName != timeDataFileName_)
127     {
128         timeDataFileName_ = newTimeDataFileName;
130         IFstream dataStream(timeDataFileName_);
132         if (dataStream.good())
133         {
134             List<Tuple2<scalar, translationRotationVectors> > timeValues
135             (
136                 dataStream
137             );
139             times_.setSize(timeValues.size());
140             values_.setSize(timeValues.size());
142             forAll(timeValues, i)
143             {
144                 times_[i] = timeValues[i].first();
145                 values_[i] = timeValues[i].second();
146             }
147         }
148         else
149         {
150             FatalErrorIn
151             (
152                 "solidBodyMotionFunctions::SKA::read(const dictionary&)"
153             )   << "Cannot open time data file " << timeDataFileName_
154                 << exit(FatalError);
155         }
156     }
158     SBMFCoeffs_.lookup("CofG") >> CofG_;
160     return true;
164 // ************************************************************************* //