tabulated6DoFMotion.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 
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  << "current time (" << t
83  << ") is less than the minimum in the data table ("
84  << times_[0] << ')'
85  << exit(FatalError);
86  }
87 
88  if (t > times_.last())
89  {
91  << "current time (" << t
92  << ") is greater than the maximum in the data table ("
93  << times_.last() << ')'
94  << exit(FatalError);
95  }
96 
98  (
99  t,
100  times_,
101  values_
102  );
103 
104  // Convert the rotational motion from deg to rad
105  TRV[1] *= pi/180.0;
106 
107  quaternion R(quaternion::XYZ, TRV[1]);
108  septernion TR(septernion(-CofG_ + -TRV[0])*R*septernion(CofG_));
109 
110  DebugInFunction << "Time = " << t << " transformation: " << TR << endl;
111 
112  return TR;
113 }
114 
115 
117 (
118  const dictionary& SBMFCoeffs
119 )
120 {
121  solidBodyMotionFunction::read(SBMFCoeffs);
122 
123  // If the timeDataFileName has changed read the file
124 
125  fileName newTimeDataFileName
126  (
127  fileName(SBMFCoeffs_.lookup("timeDataFileName")).expand()
128  );
129 
130  if (newTimeDataFileName != timeDataFileName_)
131  {
132  timeDataFileName_ = newTimeDataFileName;
133 
134  IFstream dataStream(timeDataFileName_);
135 
136  if (dataStream.good())
137  {
139  (
140  dataStream
141  );
142 
143  times_.setSize(timeValues.size());
144  values_.setSize(timeValues.size());
145 
146  forAll(timeValues, i)
147  {
148  times_[i] = timeValues[i].first();
149  values_[i] = timeValues[i].second();
150  }
151  }
152  else
153  {
155  << "Cannot open time data file " << timeDataFileName_
156  << exit(FatalError);
157  }
158  }
159 
160  SBMFCoeffs_.lookup("CofG") >> CofG_;
161 
162  return true;
163 }
164 
165 
166 // ************************************************************************* //
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
tabulated6DoFMotion(const dictionary &SBMFCoeffs, const Time &runTime)
Construct from components.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
string expand(const string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Expand occurrences of variables according to the mapping.
Definition: stringOps.C:75
A class for handling file names.
Definition: fileName.H:79
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Interpolates y values from one curve to another with a different x distribution.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:65
T & first()
Return the first element of the list.
Definition: UListI.H:114
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Macros for easy insertion into run-time selection tables.
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
bool read(const char *, int32_t &)
Definition: int32IO.C:85
Base class for defining solid-body motions.
mathematical constants.
#define DebugInFunction
Report an information message using Foam::Info.
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Input from file stream.
Definition: IFstream.H:81
#define R(A, B, C, D, E, F, K, M)
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
Namespace for OpenFOAM.