bladeModel.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2021 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 
29 #include "bladeModel.H"
30 #include "unitConversion.H"
31 #include "Tuple2.H"
32 #include "vector.H"
33 #include "IFstream.H"
34 
35 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
36 
38 {
39  return !fName_.empty();
40 }
41 
42 
44 (
45  const scalar& xIn,
46  const List<scalar>& values,
47  label& i1,
48  label& i2,
49  scalar& ddx
50 ) const
51 {
52  i2 = 0;
53  label nElem = values.size();
54 
55  if (nElem == 1)
56  {
57  i1 = i2;
58  ddx = 0.0;
59  return;
60  }
61  else
62  {
63  while ((i2 < nElem) && (values[i2] < xIn))
64  {
65  i2++;
66  }
67 
68  if (i2 == 0)
69  {
70  i1 = i2;
71  ddx = 0.0;
72  return;
73  }
74  else if (i2 == nElem)
75  {
76  i2 = nElem - 1;
77  i1 = i2;
78  ddx = 0.0;
79  return;
80  }
81  else
82  {
83  i1 = i2 - 1;
84  ddx = (xIn - values[i1])/(values[i2] - values[i1]);
85  }
86  }
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 
93 :
94  profileName_(),
95  profileID_(),
96  radius_(),
97  twist_(),
98  chord_(),
99  fName_()
100 {
102  if (readFromFile())
103  {
104  IFstream is(fName_);
105  is >> data;
106  }
107  else
108  {
109  dict.readEntry("data", data);
110  }
111 
112  if (data.size())
113  {
114  profileName_.setSize(data.size());
115  profileID_.setSize(data.size());
116  radius_.setSize(data.size());
117  twist_.setSize(data.size());
118  chord_.setSize(data.size());
119 
120  forAll(data, i)
121  {
122  profileName_[i] = data[i].first();
123  profileID_[i] = -1;
124  radius_[i] = data[i].second()[0];
125  twist_[i] = degToRad(data[i].second()[1]);
126  chord_[i] = data[i].second()[2];
127  }
128  }
129  else
130  {
132  << "No blade data specified"
133  << exit(FatalIOError);
134  }
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
141 {
142  return profileName_;
143 }
144 
145 
147 {
148  return profileID_;
149 }
150 
151 
153 {
154  return radius_;
155 }
156 
157 
159 {
160  return twist_;
161 }
162 
163 
165 {
166  return chord_;
167 }
168 
169 
171 {
172  return profileID_;
173 }
174 
175 
177 (
178  const scalar radius,
179  scalar& twist,
180  scalar& chord,
181  label& i1,
182  label& i2,
183  scalar& invDr
184 ) const
185 {
186  interpolateWeights(radius, radius_, i1, i2, invDr);
187 
188  twist = invDr*(twist_[i2] - twist_[i1]) + twist_[i1];
189  chord = invDr*(chord_[i2] - chord_[i1]) + chord_[i1];
190 }
191 
192 
193 // ************************************************************************* //
Foam::bladeModel::profileName
const List< word > & profileName() const
Return const access to the profile name list.
Definition: bladeModel.C:140
Foam::bladeModel::radius
const List< scalar > & radius() const
Return const access to the radius list.
Definition: bladeModel.C:152
Tuple2.H
Foam::bladeModel::chord
const List< scalar > & chord() const
Return const access to the chord list.
Definition: bladeModel.C:164
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:53
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::bladeModel::interpolateWeights
void interpolateWeights(const scalar &xIn, const List< scalar > &values, label &i1, label &i2, scalar &ddx) const
Return the interpolation indices and gradient.
Definition: bladeModel.C:44
Foam::bladeModel::twist
const List< scalar > & twist() const
Return const access to the twist list.
Definition: bladeModel.C:158
unitConversion.H
Unit conversion functions.
Foam::bladeModel::profileID
const List< label > & profileID() const
Return const access to the profile ID list.
Definition: bladeModel.C:146
Foam::FatalIOError
IOerror FatalIOError
Foam::bladeModel::interpolate
virtual void interpolate(const scalar radius, scalar &twist, scalar &chord, label &i1, label &i2, scalar &invDr) const
Return the twist and chord for a given radius.
Definition: bladeModel.C:177
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::bladeModel::fName_
fileName fName_
File name (optional)
Definition: bladeModel.H:166
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
bladeModel.H
IFstream.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::degToRad
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
Definition: unitConversion.H:48
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::bladeModel::profileName_
List< word > profileName_
Corresponding profile name per section.
Definition: bladeModel.H:151
Foam::bladeModel::radius_
List< scalar > radius_
Radius [m].
Definition: bladeModel.H:157
Foam::List< scalar >
Foam::bladeModel::profileID_
List< label > profileID_
Corresponding profile ID per section.
Definition: bladeModel.H:154
vector.H
Foam::bladeModel::twist_
List< scalar > twist_
Twist [deg] on input, converted to [rad].
Definition: bladeModel.H:160
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55
Foam::bladeModel::readFromFile
bool readFromFile() const
Return true if file name is set.
Definition: bladeModel.C:37
Foam::bladeModel::bladeModel
bladeModel(const dictionary &dict)
Construct from dictionary.
Definition: bladeModel.C:92
Foam::bladeModel::chord_
List< scalar > chord_
Chord [m].
Definition: bladeModel.H:163