FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

SKA.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "SKA.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <OpenFOAM/Tuple2.H>
00029 #include <OpenFOAM/IFstream.H>
00030 #include <OpenFOAM/interpolateXY.H>
00031 #include <OpenFOAM/mathematicalConstants.H>
00032 
00033 using namespace Foam::mathematicalConstant;
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 namespace solidBodyMotionFunctions
00040 {
00041     defineTypeNameAndDebug(SKA, 0);
00042     addToRunTimeSelectionTable(solidBodyMotionFunction, SKA, dictionary);
00043 };
00044 };
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 Foam::solidBodyMotionFunctions::SKA::SKA
00050 (
00051     const dictionary& SBMFCoeffs,
00052     const Time& runTime
00053 )
00054 :
00055     solidBodyMotionFunction(SBMFCoeffs, runTime)
00056 {
00057     read(SBMFCoeffs);
00058 }
00059 
00060 
00061 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
00062 
00063 Foam::solidBodyMotionFunctions::SKA::~SKA()
00064 {}
00065 
00066 
00067 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00068 
00069 Foam::septernion Foam::solidBodyMotionFunctions::SKA::transformation() const
00070 {
00071     scalar t = time_.value();
00072 
00073     if (t < times_[0])
00074     {
00075         FatalErrorIn
00076         (
00077             "solidBodyMotionFunctions::SKA::transformation()"
00078         )   << "current time (" << t
00079             << ") is less than the minimum in the data table ("
00080             << times_[0] << ')'
00081             << exit(FatalError);
00082     }
00083 
00084     if (t > times_[times_.size()-1])
00085     {
00086         FatalErrorIn
00087         (
00088             "solidBodyMotionFunctions::SKA::transformation()"
00089         )   << "current time (" << t
00090             << ") is greater than the maximum in the data table ("
00091             << times_[times_.size()-1] << ')'
00092             << exit(FatalError);
00093     }
00094 
00095     translationRotationVectors TRV = interpolateXY
00096     (
00097         t,
00098         times_,
00099         values_
00100     );
00101 
00102     // Convert the rotational motion from deg to rad
00103     TRV[1] *= pi/180.0;
00104 
00105     quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
00106     septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
00107 
00108     Info<< "solidBodyMotionFunctions::SKA::transformation(): "
00109         << "Time = " << t << " transformation: " << TR << endl;
00110 
00111     return TR;
00112 }
00113 
00114 
00115 bool Foam::solidBodyMotionFunctions::SKA::read(const dictionary& SBMFCoeffs)
00116 {
00117     solidBodyMotionFunction::read(SBMFCoeffs);
00118 
00119     // If the timeDataFileName has changed read the file
00120 
00121     fileName newTimeDataFileName
00122     (
00123         fileName(SBMFCoeffs_.lookup("timeDataFileName")).expand()
00124     );
00125 
00126     if (newTimeDataFileName != timeDataFileName_)
00127     {
00128         timeDataFileName_ = newTimeDataFileName;
00129 
00130         IFstream dataStream(timeDataFileName_);
00131 
00132         if (dataStream.good())
00133         {
00134             List<Tuple2<scalar, translationRotationVectors> > timeValues
00135             (
00136                 dataStream
00137             );
00138 
00139             times_.setSize(timeValues.size());
00140             values_.setSize(timeValues.size());
00141 
00142             forAll(timeValues, i)
00143             {
00144                 times_[i] = timeValues[i].first();
00145                 values_[i] = timeValues[i].second();
00146             }
00147         }
00148         else
00149         {
00150             FatalErrorIn
00151             (
00152                 "solidBodyMotionFunctions::SKA::read(const dictionary&)"
00153             )   << "Cannot open time data file " << timeDataFileName_
00154                 << exit(FatalError);
00155         }
00156     }
00157 
00158     SBMFCoeffs_.lookup("CofG") >> CofG_;
00159 
00160     return true;
00161 }
00162 
00163 
00164 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines