Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
38// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39
40namespace Foam
41{
43{
46 (
50 );
51}
52}
53
54
55const Foam::Enum
56<
57 Foam::solidBodyMotionFunctions::tabulated6DoFMotion::interpolationType
58>
59Foam::solidBodyMotionFunctions::tabulated6DoFMotion::interpolationTypeNames
60({
61 { interpolationType::SPLINE, "spline" },
62 { interpolationType::LINEAR, "linear" }
63});
64
65
66// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67
68Foam::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_));
134 DebugInFunction << "Time = " << t << " transformation: " << TR << endl;
135
136 return TR;
137}
138
139
141(
142 const dictionary& SBMFCoeffs
143)
144{
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// ************************************************************************* //
#define R(A, B, C, D, E, F, K, M)
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
Definition IFstream.H:55
bool good() const noexcept
True if next operation might succeed.
Definition IOstream.H:281
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
T & first()
Access first element of the list, position [0].
Definition UList.H:957
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A class for handling file names.
Definition fileName.H:75
Quaternion class used to perform rotations in 3D space.
Definition quaternion.H:54
Septernion class used to perform translations and rotations in 3D space.
Definition septernion.H:63
Base class for defining solid-body motions.
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
solidBodyMotionFunction(const solidBodyMotionFunction &)=delete
No copy construct.
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
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
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Interpolates y values from one curve to another with a different x distribution.
Interpolates y values from one curve to another with a different x distribution.
#define DebugInFunction
Report an information message using Foam::Info.
Namespace for solid-body motions.
Namespace for OpenFOAM.
Field< Type > interpolateXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
constexpr scalar degToRad() noexcept
Multiplication factor for degrees to radians conversion.
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
Unit conversion functions.