FreeFOAM The Cross-Platform CFD Toolkit
SKA.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "SKA.H"
28 #include <OpenFOAM/Tuple2.H>
29 #include <OpenFOAM/IFstream.H>
30 #include <OpenFOAM/interpolateXY.H>
32 
33 using namespace Foam::mathematicalConstant;
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace solidBodyMotionFunctions
40 {
41  defineTypeNameAndDebug(SKA, 0);
42  addToRunTimeSelectionTable(solidBodyMotionFunction, SKA, dictionary);
43 };
44 };
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 Foam::solidBodyMotionFunctions::SKA::SKA
50 (
51  const dictionary& SBMFCoeffs,
52  const Time& runTime
53 )
54 :
55  solidBodyMotionFunction(SBMFCoeffs, runTime)
56 {
57  read(SBMFCoeffs);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
62 
64 {}
65 
66 
67 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
68 
70 {
71  scalar t = time_.value();
72 
73  if (t < times_[0])
74  {
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  }
83 
84  if (t > times_[times_.size()-1])
85  {
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  }
94 
96  (
97  t,
98  times_,
99  values_
100  );
101 
102  // Convert the rotational motion from deg to rad
103  TRV[1] *= pi/180.0;
104 
105  quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
106  septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
107 
108  Info<< "solidBodyMotionFunctions::SKA::transformation(): "
109  << "Time = " << t << " transformation: " << TR << endl;
110 
111  return TR;
112 }
113 
114 
116 {
117  solidBodyMotionFunction::read(SBMFCoeffs);
118 
119  // If the timeDataFileName has changed read the file
120 
121  fileName newTimeDataFileName
122  (
123  fileName(SBMFCoeffs_.lookup("timeDataFileName")).expand()
124  );
125 
126  if (newTimeDataFileName != timeDataFileName_)
127  {
128  timeDataFileName_ = newTimeDataFileName;
129 
130  IFstream dataStream(timeDataFileName_);
131 
132  if (dataStream.good())
133  {
135  (
136  dataStream
137  );
138 
139  times_.setSize(timeValues.size());
140  values_.setSize(timeValues.size());
141 
142  forAll(timeValues, i)
143  {
144  times_[i] = timeValues[i].first();
145  values_[i] = timeValues[i].second();
146  }
147  }
148  else
149  {
151  (
152  "solidBodyMotionFunctions::SKA::read(const dictionary&)"
153  ) << "Cannot open time data file " << timeDataFileName_
154  << exit(FatalError);
155  }
156  }
157 
158  SBMFCoeffs_.lookup("CofG") >> CofG_;
159 
160  return true;
161 }
162 
163 
164 // ************************ vim: set sw=4 sts=4 et: ************************ //