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 "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 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
69 
72 {
73  scalar t = time_.value();
74 
75  if (t < times_[0])
76  {
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_.last())
85  {
87  << "current time (" << t
88  << ") is greater than the maximum in the data table ("
89  << times_.last() << ')'
90  << exit(FatalError);
91  }
92 
94  (
95  t,
96  times_,
97  values_
98  );
99 
100  // Convert the rotational motion from deg to rad
101  TRV[1] *= degToRad();
102 
103  quaternion R(quaternion::XYZ, TRV[1]);
104  septernion TR(septernion(-CofG_ + -TRV[0])*R*septernion(CofG_));
105 
106  DebugInFunction << "Time = " << t << " transformation: " << TR << endl;
107 
108  return TR;
109 }
110 
111 
113 (
114  const dictionary& SBMFCoeffs
115 )
116 {
117  solidBodyMotionFunction::read(SBMFCoeffs);
118 
119  // If the timeDataFileName has changed read the file
120 
121  fileName newTimeDataFileName
122  (
123  SBMFCoeffs_.get<fileName>("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  << "Cannot open time data file " << timeDataFileName_
152  << exit(FatalError);
153  }
154  }
155 
156  SBMFCoeffs_.readEntry("CofG", CofG_);
157 
158  return true;
159 }
160 
161 
162 // ************************************************************************* //
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:73
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:53
Foam::solidBodyMotionFunctions::tabulated6DoFMotion::read
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Definition: tabulated6DoFMotion.C:113
unitConversion.H
Unit conversion functions.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
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:296
Foam::IOstream::good
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
Foam::quaternion
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:56
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
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:71
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
Foam::solidBodyMotionFunction
Base class for defining solid-body motions.
Definition: solidBodyMotionFunction.H:63
Foam::solidBodyMotionFunctions::defineTypeNameAndDebug
defineTypeNameAndDebug(axisRotationMotion, 0)
IFstream.H
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:123
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:60
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:453
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::string::expand
string & expand(const bool allowEmpty=false)
Definition: string.C:173
interpolateSplineXY.H
Interpolates y values from one curve to another with a different x distribution.
Foam::solidBodyMotionFunction::time_
const Time & time_
Definition: solidBodyMotionFunction.H:71
Foam::interpolateSplineXY
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)