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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015-2016 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd
10 -------------------------------------------------------------------------------
11 License
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 
30 #include "Tuple2.H"
31 #include "IFstream.H"
32 #include "interpolateSplineXY.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(tabulated6DoFAcceleration, 0);
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 (
46  const dictionary& accelerationCoeffs,
47  const Time& runTime
48 )
49 :
50  time_(runTime),
51  accelerationCoeffs_(accelerationCoeffs)
52 {
53  read(accelerationCoeffs);
54 }
55 
56 
57 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
58 
61 {
62  scalar t = time_.value();
63 
64  if (t < times_[0])
65  {
67  << "current time (" << t
68  << ") is less than the minimum in the data table ("
69  << times_[0] << ')'
70  << exit(FatalError);
71  }
72 
73  if (t > times_.last())
74  {
76  << "current time (" << t
77  << ") is greater than the maximum in the data table ("
78  << times_.last() << ')'
79  << exit(FatalError);
80  }
81 
83  (
84  t,
85  times_,
86  values_
87  );
88 
89  Info << "Time = " << t << " accelerations: " << avs << endl;
90 
91  return avs;
92 }
93 
94 
96 (
97  const dictionary& accelerationCoeffs
98 )
99 {
100  accelerationCoeffs_ = accelerationCoeffs;
101 
102  // If the timeDataFileName has changed read the file
103 
104  fileName newTimeDataFileName
105  (
106  accelerationCoeffs_.get<fileName>("timeDataFileName").expand()
107  );
108 
109  if (newTimeDataFileName != timeDataFileName_)
110  {
111  timeDataFileName_ = newTimeDataFileName;
112 
113  IFstream dataStream(timeDataFileName_);
114 
115  if (dataStream.good())
116  {
118  (
119  dataStream
120  );
121 
122  times_.setSize(timeValues.size());
123  values_.setSize(timeValues.size());
124 
125  forAll(timeValues, i)
126  {
127  times_[i] = timeValues[i].first();
128  values_[i] = timeValues[i].second();
129  }
130  }
131  else
132  {
134  << "Cannot open time data file " << timeDataFileName_
135  << exit(FatalError);
136  }
137  }
138 
139  return true;
140 }
141 
142 
143 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::tabulated6DoFAcceleration::acceleration
virtual Vector< vector > acceleration() const
Return the solid-body accelerations.
Definition: tabulated6DoFAcceleration.C:60
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Tuple2.H
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:53
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::IOstream::good
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::tabulated6DoFAcceleration::read
virtual bool read(const dictionary &accelerationCoeffs)
Update properties from given dictionary.
Definition: tabulated6DoFAcceleration.C:96
IFstream.H
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::Vector< vector >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::string::expand
string & expand(const bool allowEmpty=false)
Definition: string.C:173
tabulated6DoFAcceleration.H
Foam::tabulated6DoFAcceleration::tabulated6DoFAcceleration
tabulated6DoFAcceleration(const dictionary &accelerationCoeffs, const Time &runTime)
Construct from components.
Definition: tabulated6DoFAcceleration.C:45
interpolateSplineXY.H
Interpolates y values from one curve to another with a different x distribution.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::interpolateSplineXY
Field< Type > interpolateSplineXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)