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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "tabulated6DoFMotion.H"
31 #include "Tuple2.H"
32 #include "IFstream.H"
33 #include "interpolateSplineXY.H"
34 #include "interpolateXY.H"
35 #include "unitConversion.H"
36 
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 namespace solidBodyMotionFunctions
43 {
44  defineTypeNameAndDebug(tabulated6DoFMotion, 0);
46  (
47  solidBodyMotionFunction,
48  tabulated6DoFMotion,
49  dictionary
50  );
51 }
52 }
53 
54 
55 const Foam::Enum
56 <
57  Foam::solidBodyMotionFunctions::tabulated6DoFMotion::interpolationType
58 >
59 Foam::solidBodyMotionFunctions::tabulated6DoFMotion::interpolationTypeNames
60 ({
61  { interpolationType::SPLINE, "spline" },
62  { interpolationType::LINEAR, "linear" }
63 });
64 
65 
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 
68 Foam::solidBodyMotionFunctions::tabulated6DoFMotion::tabulated6DoFMotion
69 (
70  const dictionary& SBMFCoeffs,
71  const Time& runTime
72 )
73 :
74  solidBodyMotionFunction(SBMFCoeffs, runTime)
75 {
76  read(SBMFCoeffs);
77 }
78 
79 
80 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
81 
84 {
85  scalar t = time_.value();
86 
87  if (t < times_[0])
88  {
90  << "current time (" << t
91  << ") is less than the minimum in the data table ("
92  << times_[0] << ')'
93  << exit(FatalError);
94  }
95 
96  if (t > times_.last())
97  {
99  << "current time (" << t
100  << ") is greater than the maximum in the data table ("
101  << times_.last() << ')'
102  << exit(FatalError);
103  }
104 
105  translationRotationVectors TRV(Zero, Zero);
106  switch (interpolator_)
107  {
108  case interpolationType::SPLINE:
109  {
110  TRV = interpolateSplineXY(t, times_, values_);
111  break;
112  }
113  case interpolationType::LINEAR:
114  {
115  TRV = interpolateXY(t, times_, values_);
116  break;
117  }
118  default:
119  {
121  << "Unrecognised 'interpolationScheme' option: "
122  << interpolationTypeNames[interpolator_]
123  << exit(FatalError);
124  break;
125  }
126  }
127 
128  // Convert the rotational motion from deg to rad
129  TRV[1] *= degToRad();
130 
131  quaternion R(quaternion::XYZ, TRV[1]);
132  septernion TR(septernion(-CofG_ + -TRV[0])*R*septernion(CofG_));
133 
134  DebugInFunction << "Time = " << t << " transformation: " << TR << endl;
135 
136  return TR;
137 }
138 
139 
141 (
142  const dictionary& SBMFCoeffs
143 )
144 {
145  solidBodyMotionFunction::read(SBMFCoeffs);
146 
147  // If the timeDataFileName has changed read the file
148 
149  fileName newTimeDataFileName
150  (
151  SBMFCoeffs_.get<fileName>("timeDataFileName").expand()
152  );
153 
154  if (newTimeDataFileName != timeDataFileName_)
155  {
156  timeDataFileName_ = newTimeDataFileName;
157 
158  IFstream dataStream(timeDataFileName_);
159 
160  if (dataStream.good())
161  {
163  (
164  dataStream
165  );
166 
167  times_.setSize(timeValues.size());
168  values_.setSize(timeValues.size());
169 
170  forAll(timeValues, i)
171  {
172  times_[i] = timeValues[i].first();
173  values_[i] = timeValues[i].second();
174  }
175  }
176  else
177  {
179  << "Cannot open time data file " << timeDataFileName_
180  << exit(FatalError);
181  }
182  }
183 
184  SBMFCoeffs_.readEntry("CofG", CofG_);
185 
186  interpolator_ =
187  interpolationTypeNames.getOrDefault
188  (
189  "interpolationScheme",
190  SBMFCoeffs_,
191  interpolationType::SPLINE
192  );
193 
194  return true;
195 }
196 
197 
198 // ************************************************************************* //
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A class for handling file names.
Definition: fileName.H:72
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:600
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
Unit conversion functions.
Interpolates y values from one curve to another with a different x distribution.
T & first()
Access first element of the list, position [0].
Definition: UList.H:886
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:529
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:62
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
defineTypeNameAndDebug(axisRotationMotion, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
Base class for defining solid-body motions.
#define DebugInFunction
Report an information message using Foam::Info.
Interpolates y values from one curve to another with a different x distribution.
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
Field< Type > interpolateXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
Definition: interpolateXY.C:34
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Input from file stream as an ISstream, normally using std::ifstream for the actual input...
Definition: IFstream.H:51
#define R(A, B, C, D, E, F, K, M)
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
string & expand(const bool allowEmpty=false)
Inplace expand initial tags, tildes, and all occurrences of environment variables as per stringOps::e...
Definition: string.C:166
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:281
addToRunTimeSelectionTable(solidBodyMotionFunction, axisRotationMotion, dictionary)
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127