tabulated6DoFMotion.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) 2011-2015 OpenFOAM Foundation
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 "tabulated6DoFMotion.H"
28 #include "Tuple2.H"
29 #include "IFstream.H"
30 #include "interpolateSplineXY.H"
31 #include "mathematicalConstants.H"
32 
33 using namespace Foam::constant::mathematical;
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace solidBodyMotionFunctions
40 {
41  defineTypeNameAndDebug(tabulated6DoFMotion, 0);
43  (
44  solidBodyMotionFunction,
45  tabulated6DoFMotion,
46  dictionary
47  );
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
54 Foam::solidBodyMotionFunctions::tabulated6DoFMotion::tabulated6DoFMotion
55 (
56  const dictionary& SBMFCoeffs,
57  const Time& runTime
58 )
59 :
60  solidBodyMotionFunction(SBMFCoeffs, runTime)
61 {
62  read(SBMFCoeffs);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
69 {}
70 
71 
72 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
73 
76 {
77  scalar t = time_.value();
78 
79  if (t < times_[0])
80  {
82  (
83  "solidBodyMotionFunctions::tabulated6DoFMotion::transformation()"
84  ) << "current time (" << t
85  << ") is less than the minimum in the data table ("
86  << times_[0] << ')'
87  << exit(FatalError);
88  }
89 
90  if (t > times_.last())
91  {
93  (
94  "solidBodyMotionFunctions::tabulated6DoFMotion::transformation()"
95  ) << "current time (" << t
96  << ") is greater than the maximum in the data table ("
97  << times_.last() << ')'
98  << exit(FatalError);
99  }
100 
102  (
103  t,
104  times_,
105  values_
106  );
107 
108  // Convert the rotational motion from deg to rad
109  TRV[1] *= pi/180.0;
110 
111  quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
112  septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
113 
114  Info<< "solidBodyMotionFunctions::tabulated6DoFMotion::transformation(): "
115  << "Time = " << t << " transformation: " << TR << endl;
116 
117  return TR;
118 }
119 
120 
122 (
123  const dictionary& SBMFCoeffs
124 )
125 {
126  solidBodyMotionFunction::read(SBMFCoeffs);
127 
128  // If the timeDataFileName has changed read the file
129 
130  fileName newTimeDataFileName
131  (
132  fileName(SBMFCoeffs_.lookup("timeDataFileName")).expand()
133  );
134 
135  if (newTimeDataFileName != timeDataFileName_)
136  {
137  timeDataFileName_ = newTimeDataFileName;
138 
139  IFstream dataStream(timeDataFileName_);
140 
141  if (dataStream.good())
142  {
144  (
145  dataStream
146  );
147 
148  times_.setSize(timeValues.size());
149  values_.setSize(timeValues.size());
150 
151  forAll(timeValues, i)
152  {
153  times_[i] = timeValues[i].first();
154  values_[i] = timeValues[i].second();
155  }
156  }
157  else
158  {
160  (
161  "solidBodyMotionFunctions::tabulated6DoFMotion::read"
162  "(const dictionary&)"
163  ) << "Cannot open time data file " << timeDataFileName_
164  << exit(FatalError);
165  }
166  }
167 
168  SBMFCoeffs_.lookup("CofG") >> CofG_;
169 
170  return true;
171 }
172 
173 
174 // ************************************************************************* //
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
Base class for defining solid-body motions.
#define R(A, B, C, D, E, F, K, M)
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
messageStream Info
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Input from file stream.
Definition: IFstream.H:81
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
T & first()
Return the first element of the list.
Definition: UListI.H:117
Namespace for OpenFOAM.
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:64
string expand(const string &, const HashTable< string, word, string::hash > &mapping, const char sigil= '$')
Expand occurences of variables according to the mapping.
Definition: stringOps.C:74
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Interpolates y values from one curve to another with a different x distribution.
#define forAll(list, i)
Definition: UList.H:421
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
Macros for easy insertion into run-time selection tables.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
scalar y
A class for handling file names.
Definition: fileName.H:69
bool read(const char *, int32_t &)
Definition: int32IO.C:87
mathematical constants.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Templated 2D Vector derived from VectorSpace adding construction from 2 components, element access using x() and y() member functions and the inner-product (dot-product).
Definition: Vector2D.H:51