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 "unitConversion.H"
35
36
37// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38
39namespace Foam
40{
41namespace solidBodyMotionFunctions
42{
45 (
49 );
50}
51}
52
53
54// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55
57(
58 const dictionary& SBMFCoeffs,
59 const Time& runTime
60)
61:
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
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{
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// ************************************************************************* //
#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.
Input from file stream, using an ISstream.
Definition: IFstream.H:57
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
T & first()
Return the first element of the list.
Definition: UListI.H:202
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:58
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:58
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:67
Base class for defining solid-body motions.
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)
Definition: string.C:173
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Interpolates y values from one curve to another with a different x distribution.
#define DebugInFunction
Report an information message using Foam::Info.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr scalar degToRad() noexcept
Multiplication factor for degrees to radians conversion.
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
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:333
Unit conversion functions.