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 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  (
71  "tabulated6DoFAcceleration::acceleration()"
72  ) << "current time (" << t
73  << ") is less than the minimum in the data table ("
74  << times_[0] << ')'
75  << exit(FatalError);
76  }
77 
78  if (t > times_.last())
79  {
81  (
82  "tabulated6DoFAcceleration::acceleration()"
83  ) << "current time (" << t
84  << ") is greater than the maximum in the data table ("
85  << times_.last() << ')'
86  << exit(FatalError);
87  }
88 
90  (
91  t,
92  times_,
93  values_
94  );
95 
96  Info<< "tabulated6DoFAcceleration::acceleration(): "
97  << "Time = " << t << " accelerations: " << avs << endl;
98 
99  return avs;
100 }
101 
102 
104 (
105  const dictionary& accelerationCoeffs
106 )
107 {
108  accelerationCoeffs_ = accelerationCoeffs;
109 
110  // If the timeDataFileName has changed read the file
111 
112  fileName newTimeDataFileName
113  (
114  fileName(accelerationCoeffs_.lookup("timeDataFileName")).expand()
115  );
116 
117  if (newTimeDataFileName != timeDataFileName_)
118  {
119  timeDataFileName_ = newTimeDataFileName;
120 
121  IFstream dataStream(timeDataFileName_);
122 
123  if (dataStream.good())
124  {
126  (
127  dataStream
128  );
129 
130  times_.setSize(timeValues.size());
131  values_.setSize(timeValues.size());
132 
133  forAll(timeValues, i)
134  {
135  times_[i] = timeValues[i].first();
136  values_[i] = timeValues[i].second();
137  }
138  }
139  else
140  {
142  (
143  "tabulated6DoFAcceleration::read(const dictionary&)"
144  ) << "Cannot open time data file " << timeDataFileName_
145  << exit(FatalError);
146  }
147  }
148 
149  return true;
150 }
151 
152 
153 // ************************************************************************* //
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
messageStream Info
virtual ~tabulated6DoFAcceleration()
Destructor.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Input from file stream.
Definition: IFstream.H:81
T & first()
Return the first element of the list.
Definition: UListI.H:117
Namespace for OpenFOAM.
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:74
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
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
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual bool read(const dictionary &accelerationCoeffs)
Update properties from given dictionary.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Interpolates y values from one curve to another with a different x distribution.
#define forAll(list, i)
Definition: UList.H:421
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
A class for handling file names.
Definition: fileName.H:69
bool read(const char *, int32_t &)
Definition: int32IO.C:87
virtual Vector< vector > acceleration() const
Return the solid-body accelerations.
defineTypeNameAndDebug(combustionModel, 0)