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 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 "unitConversion.H"
35 
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 namespace solidBodyMotionFunctions
42 {
43  defineTypeNameAndDebug(tabulated6DoFMotion, 0);
45  (
46  solidBodyMotionFunction,
47  tabulated6DoFMotion,
48  dictionary
49  );
50 }
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
56 Foam::solidBodyMotionFunctions::tabulated6DoFMotion::tabulated6DoFMotion
57 (
58  const dictionary& SBMFCoeffs,
59  const Time& runTime
60 )
61 :
62  solidBodyMotionFunction(SBMFCoeffs, runTime)
63 {
64  read(SBMFCoeffs);
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 
71 {}
72 
73 
74 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
75 
78 {
79  scalar t = time_.value();
80 
81  if (t < times_[0])
82  {
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  << "current time (" << t
94  << ") is greater than the maximum in the data table ("
95  << times_.last() << ')'
96  << exit(FatalError);
97  }
98 
100  (
101  t,
102  times_,
103  values_
104  );
105 
106  // Convert the rotational motion from deg to rad
107  TRV[1] *= degToRad();
108 
109  quaternion R(quaternion::XYZ, TRV[1]);
110  septernion TR(septernion(-CofG_ + -TRV[0])*R*septernion(CofG_));
111 
112  DebugInFunction << "Time = " << t << " transformation: " << TR << endl;
113 
114  return TR;
115 }
116 
117 
119 (
120  const dictionary& SBMFCoeffs
121 )
122 {
123  solidBodyMotionFunction::read(SBMFCoeffs);
124 
125  // If the timeDataFileName has changed read the file
126 
127  fileName newTimeDataFileName
128  (
129  fileName(SBMFCoeffs_.lookup("timeDataFileName")).expand()
130  );
131 
132  if (newTimeDataFileName != timeDataFileName_)
133  {
134  timeDataFileName_ = newTimeDataFileName;
135 
136  IFstream dataStream(timeDataFileName_);
137 
138  if (dataStream.good())
139  {
141  (
142  dataStream
143  );
144 
145  times_.setSize(timeValues.size());
146  values_.setSize(timeValues.size());
147 
148  forAll(timeValues, i)
149  {
150  times_[i] = timeValues[i].first();
151  values_[i] = timeValues[i].second();
152  }
153  }
154  else
155  {
157  << "Cannot open time data file " << timeDataFileName_
158  << exit(FatalError);
159  }
160  }
161 
162  SBMFCoeffs_.readEntry("CofG", CofG_);
163 
164  return true;
165 }
166 
167 
168 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::septernion
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:66
tabulated6DoFMotion.H
Tuple2.H
Foam::solidBodyMotionFunctions::addToRunTimeSelectionTable
addToRunTimeSelectionTable(solidBodyMotionFunction, axisRotationMotion, dictionary)
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:97
Foam::solidBodyMotionFunctions::tabulated6DoFMotion::read
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Definition: tabulated6DoFMotion.C:119
unitConversion.H
Unit conversion functions.
Foam::solidBodyMotionFunctions::tabulated6DoFMotion::~tabulated6DoFMotion
virtual ~tabulated6DoFMotion()
Destructor.
Definition: tabulated6DoFMotion.C:70
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::Vector2D
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:55
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::quaternion
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:56
R
#define R(A, B, C, D, E, F, K, M)
Foam::solidBodyMotionFunctions::tabulated6DoFMotion::transformation
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
Definition: tabulated6DoFMotion.C:77
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:356
Foam::solidBodyMotionFunction
Base class for defining solid-body motions.
Definition: solidBodyMotionFunction.H:62
Foam::solidBodyMotionFunctions::defineTypeNameAndDebug
defineTypeNameAndDebug(axisRotationMotion, 0)
IFstream.H
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
Foam::quaternion::XYZ
Definition: quaternion.H:108
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::degToRad
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
Definition: unitConversion.H:48
Foam::solidBodyMotionFunction::read
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
Definition: solidBodyMotionFunction.C:66
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::stringOps::expand
string expand(const std::string &str, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Definition: stringOps.C:739
interpolateSplineXY.H
Interpolates y values from one curve to another with a different x distribution.
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:216
Foam::interpolateSplineXY
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)