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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "tabulated6DoFMotion.H"
28 #include "Tuple2.H"
29 #include "IFstream.H"
30 #include "interpolateSplineXY.H"
31 #include "mathematicalConstants.H"
32 
33 using namespace Foam::constant::mathematical;
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace solidBodyMotionFunctions
40 {
41  defineTypeNameAndDebug(tabulated6DoFMotion, 0);
43  (
44  solidBodyMotionFunction,
45  tabulated6DoFMotion,
46  dictionary
47  );
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const dictionary& SBMFCoeffs,
57  const Time& runTime
58 )
59 :
60  solidBodyMotionFunction(SBMFCoeffs, runTime)
61 {
62  read(SBMFCoeffs);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
69 {}
70 
71 
72 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
73 
76 {
77  scalar t = time_.value();
78 
79  if (t < times_[0])
80  {
82  << "current time (" << t
83  << ") is less than the minimum in the data table ("
84  << times_[0] << ')'
85  << exit(FatalError);
86  }
87 
88  if (t > times_.last())
89  {
91  << "current time (" << t
92  << ") is greater than the maximum in the data table ("
93  << times_.last() << ')'
94  << exit(FatalError);
95  }
96 
98  (
99  t,
100  times_,
101  values_
102  );
103 
104  // Convert the rotational motion from deg to rad
105  TRV[1] *= pi/180.0;
106 
107  quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
108  septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
109 
110  Info<< "solidBodyMotionFunctions::tabulated6DoFMotion::transformation(): "
111  << "Time = " << t << " transformation: " << TR << endl;
112 
113  return TR;
114 }
115 
116 
118 (
119  const dictionary& SBMFCoeffs
120 )
121 {
122  solidBodyMotionFunction::read(SBMFCoeffs);
123 
124  // If the timeDataFileName has changed read the file
125 
126  fileName newTimeDataFileName
127  (
128  fileName(SBMFCoeffs_.lookup("timeDataFileName")).expand()
129  );
130 
131  if (newTimeDataFileName != timeDataFileName_)
132  {
133  timeDataFileName_ = newTimeDataFileName;
134 
135  IFstream dataStream(timeDataFileName_);
136 
137  if (dataStream.good())
138  {
140  (
141  dataStream
142  );
143 
144  times_.setSize(timeValues.size());
145  values_.setSize(timeValues.size());
146 
147  forAll(timeValues, i)
148  {
149  times_[i] = timeValues[i].first();
150  values_[i] = timeValues[i].second();
151  }
152  }
153  else
154  {
156  << "Cannot open time data file " << timeDataFileName_
157  << exit(FatalError);
158  }
159  }
160 
161  SBMFCoeffs_.lookup("CofG") >> CofG_;
162 
163  return true;
164 }
165 
166 
167 // ************************************************************************* //
mathematicalConstants.H
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
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:64
tabulated6DoFMotion.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Tuple2.H
Foam::IFstream
Input from file stream.
Definition: IFstream.H:81
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::solidBodyMotionFunctions::tabulated6DoFMotion::read
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Definition: tabulated6DoFMotion.C:118
Foam::solidBodyMotionFunctions::tabulated6DoFMotion::~tabulated6DoFMotion
virtual ~tabulated6DoFMotion()
Destructor.
Definition: tabulated6DoFMotion.C:68
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::Vector2D
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:51
Foam::quaternion
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
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:75
Foam::Info
messageStream Info
Foam::solidBodyMotionFunction
Base class for defining solid-body motions.
Definition: solidBodyMotionFunction.H:60
IFstream.H
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::solidBodyMotionFunction::read
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
Definition: solidBodyMotionFunction.C:65
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::solidBodyMotionFunctions::tabulated6DoFMotion::tabulated6DoFMotion
tabulated6DoFMotion(const tabulated6DoFMotion &)
Disallow copy construct.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::constant::mathematical
mathematical constants.
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:59
Foam::string::expand
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurences of environment variables.
Definition: string.C:98
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::constant::mathematical::pi
const scalar pi(M_PI)
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
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:333
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
y
scalar y
Definition: LISASMDCalcMethod1.H:14
Foam::interpolateSplineXY
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)