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-------------------------------------------------------------------------------
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
30#include "Tuple2.H"
31#include "IFstream.H"
32#include "interpolateSplineXY.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
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// ************************************************************************* //
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
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
string & expand(const bool allowEmpty=false)
Definition: string.C:173
virtual bool read(const dictionary &accelerationCoeffs)
Update properties from given dictionary.
virtual Vector< vector > acceleration() const
Return the solid-body accelerations.
#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.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
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