tabulated6DoFAcceleration.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) 2015-2016 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 
27 #include "Tuple2.H"
28 #include "IFstream.H"
29 #include "interpolateSplineXY.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(tabulated6DoFAcceleration, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 Foam::tabulated6DoFAcceleration::tabulated6DoFAcceleration
42 (
43  const dictionary& accelerationCoeffs,
44  const Time& runTime
45 )
46 :
47  time_(runTime),
48  accelerationCoeffs_(accelerationCoeffs)
49 {
50  read(accelerationCoeffs);
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
55 
57 {}
58 
59 
60 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
61 
64 {
65  scalar t = time_.value();
66 
67  if (t < times_[0])
68  {
70  << "current time (" << t
71  << ") is less than the minimum in the data table ("
72  << times_[0] << ')'
73  << exit(FatalError);
74  }
75 
76  if (t > times_.last())
77  {
79  << "current time (" << t
80  << ") is greater than the maximum in the data table ("
81  << times_.last() << ')'
82  << exit(FatalError);
83  }
84 
86  (
87  t,
88  times_,
89  values_
90  );
91 
93  << "Time = " << t << " accelerations: " << avs << endl;
94 
95  return avs;
96 }
97 
98 
100 (
101  const dictionary& accelerationCoeffs
102 )
103 {
104  accelerationCoeffs_ = accelerationCoeffs;
105 
106  // If the timeDataFileName has changed read the file
107 
108  fileName newTimeDataFileName
109  (
110  fileName(accelerationCoeffs_.lookup("timeDataFileName")).expand()
111  );
112 
113  if (newTimeDataFileName != timeDataFileName_)
114  {
115  timeDataFileName_ = newTimeDataFileName;
116 
117  IFstream dataStream(timeDataFileName_);
118 
119  if (dataStream.good())
120  {
122  (
123  dataStream
124  );
125 
126  times_.setSize(timeValues.size());
127  values_.setSize(timeValues.size());
128 
129  forAll(timeValues, i)
130  {
131  times_[i] = timeValues[i].first();
132  values_[i] = timeValues[i].second();
133  }
134  }
135  else
136  {
138  << "Cannot open time data file " << timeDataFileName_
139  << exit(FatalError);
140  }
141  }
142 
143  return true;
144 }
145 
146 
147 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
string expand(const string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Expand occurences of variables according to the mapping.
Definition: stringOps.C:75
A class for handling file names.
Definition: fileName.H:69
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Interpolates y values from one curve to another with a different x distribution.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
T & first()
Return the first element of the list.
Definition: UListI.H:114
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
bool read(const char *, int32_t &)
Definition: int32IO.C:85
virtual Vector< vector > acceleration() const
Return the solid-body accelerations.
virtual ~tabulated6DoFAcceleration()
Destructor.
defineTypeNameAndDebug(combustionModel, 0)
Input from file stream.
Definition: IFstream.H:81
virtual bool read(const dictionary &accelerationCoeffs)
Update properties from given dictionary.
Namespace for OpenFOAM.
#define InfoInFunction
Report an information message using Foam::Info.