OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "SKA.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "Tuple2.H"
00030 #include "IFstream.H"
00031 #include "interpolateXY.H"
00032 #include "mathematicalConstants.H"
00033 
00034 using namespace Foam::mathematicalConstant;
00035 
00036 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 namespace solidBodyMotionFunctions
00041 {
00042     defineTypeNameAndDebug(SKA, 0);
00043     addToRunTimeSelectionTable(solidBodyMotionFunction, SKA, dictionary);
00044 };
00045 };
00046 
00047 
00048 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00049 
00050 Foam::solidBodyMotionFunctions::SKA::SKA
00051 (
00052     const dictionary& SBMFCoeffs,
00053     const Time& runTime
00054 )
00055 :
00056     solidBodyMotionFunction(SBMFCoeffs, runTime)
00057 {
00058     read(SBMFCoeffs);
00059 }
00060 
00061 
00062 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
00063 
00064 Foam::solidBodyMotionFunctions::SKA::~SKA()
00065 {}
00066 
00067 
00068 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00069 
00070 Foam::septernion Foam::solidBodyMotionFunctions::SKA::transformation() const
00071 {
00072     scalar t = time_.value();
00073 
00074     if (t < times_[0])
00075     {
00076         FatalErrorIn
00077         (
00078             "solidBodyMotionFunctions::SKA::transformation()"
00079         )   << "current time (" << t
00080             << ") is less than the minimum in the data table ("
00081             << times_[0] << ')'
00082             << exit(FatalError);
00083     }
00084 
00085     if (t > times_[times_.size()-1])
00086     {
00087         FatalErrorIn
00088         (
00089             "solidBodyMotionFunctions::SKA::transformation()"
00090         )   << "current time (" << t
00091             << ") is greater than the maximum in the data table ("
00092             << times_[times_.size()-1] << ')'
00093             << exit(FatalError);
00094     }
00095 
00096     translationRotationVectors TRV = interpolateXY
00097     (
00098         t,
00099         times_,
00100         values_
00101     );
00102 
00103     // Convert the rotational motion from deg to rad
00104     TRV[1] *= pi/180.0;
00105 
00106     quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
00107     septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
00108 
00109     Info<< "solidBodyMotionFunctions::SKA::transformation(): "
00110         << "Time = " << t << " transformation: " << TR << endl;
00111 
00112     return TR;
00113 }
00114 
00115 
00116 bool Foam::solidBodyMotionFunctions::SKA::read(const dictionary& SBMFCoeffs)
00117 {
00118     solidBodyMotionFunction::read(SBMFCoeffs);
00119 
00120     // If the timeDataFileName has changed read the file
00121 
00122     fileName newTimeDataFileName(SBMFCoeffs_.lookup("timeDataFileName"));
00123 
00124     if (newTimeDataFileName != timeDataFileName_)
00125     {
00126         timeDataFileName_ = newTimeDataFileName;
00127 
00128         IFstream dataStream(timeDataFileName_);
00129 
00130         if (dataStream.good())
00131         {
00132             List<Tuple2<scalar, translationRotationVectors> > timeValues
00133             (
00134                 dataStream
00135             );
00136 
00137             times_.setSize(timeValues.size());
00138             values_.setSize(timeValues.size());
00139 
00140             forAll(timeValues, i)
00141             {
00142                 times_[i] = timeValues[i].first();
00143                 values_[i] = timeValues[i].second();
00144             }
00145         }
00146         else
00147         {
00148             FatalErrorIn
00149             (
00150                 "solidBodyMotionFunctions::SKA::read(const dictionary&)"
00151             )   << "Cannot open time data file " << timeDataFileName_
00152                 << exit(FatalError);
00153         }
00154     }
00155 
00156     SBMFCoeffs_.lookup("CofG") >> CofG_;
00157 
00158     return true;
00159 }
00160 
00161 
00162 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd