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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "bladeModel.H"
29 #include "unitConversion.H"
30 #include "Tuple2.H"
31 #include "vector.H"
32 #include "IFstream.H"
33 
34 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
35 
37 {
38  return fName_ != fileName::null;
39 }
40 
41 
43 (
44  const scalar& xIn,
45  const List<scalar>& values,
46  label& i1,
47  label& i2,
48  scalar& ddx
49 ) const
50 {
51  i2 = 0;
52  label nElem = values.size();
53 
54  if (nElem == 1)
55  {
56  i1 = i2;
57  ddx = 0.0;
58  return;
59  }
60  else
61  {
62  while ((i2 < nElem) && (values[i2] < xIn))
63  {
64  i2++;
65  }
66 
67  if (i2 == 0)
68  {
69  i1 = i2;
70  ddx = 0.0;
71  return;
72  }
73  else if (i2 == nElem)
74  {
75  i2 = nElem - 1;
76  i1 = i2;
77  ddx = 0.0;
78  return;
79  }
80  else
81  {
82  i1 = i2 - 1;
83  ddx = (xIn - values[i1])/(values[i2] - values[i1]);
84  }
85  }
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 :
93  profileName_(),
94  profileID_(),
95  radius_(),
96  twist_(),
97  chord_(),
98  fName_(fileName::null)
99 {
101  if (readFromFile())
102  {
103  IFstream is(fName_);
104  is >> data;
105  }
106  else
107  {
108  dict.readEntry("data", data);
109  }
110 
111  if (data.size())
112  {
113  profileName_.setSize(data.size());
114  profileID_.setSize(data.size());
115  radius_.setSize(data.size());
116  twist_.setSize(data.size());
117  chord_.setSize(data.size());
118 
119  forAll(data, i)
120  {
121  profileName_[i] = data[i].first();
122  profileID_[i] = -1;
123  radius_[i] = data[i].second()[0];
124  twist_[i] = degToRad(data[i].second()[1]);
125  chord_[i] = data[i].second()[2];
126  }
127  }
128  else
129  {
131  << "No blade data specified" << exit(FatalError);
132  }
133 }
134 
135 
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137 
139 {
140  return profileName_;
141 }
142 
143 
145 {
146  return profileID_;
147 }
148 
149 
151 {
152  return radius_;
153 }
154 
155 
157 {
158  return twist_;
159 }
160 
161 
163 {
164  return chord_;
165 }
166 
167 
169 {
170  return profileID_;
171 }
172 
173 
175 (
176  const scalar radius,
177  scalar& twist,
178  scalar& chord,
179  label& i1,
180  label& i2,
181  scalar& invDr
182 ) const
183 {
184  interpolateWeights(radius, radius_, i1, i2, invDr);
185 
186  twist = invDr*(twist_[i2] - twist_[i1]) + twist_[i1];
187  chord = invDr*(chord_[i2] - chord_[i1]) + chord_[i1];
188 }
189 
190 
191 // ************************************************************************* //
Foam::bladeModel::profileName
const List< word > & profileName() const
Return const access to the profile name list.
Definition: bladeModel.C:138
Foam::bladeModel::radius
const List< scalar > & radius() const
Return const access to the radius list.
Definition: bladeModel.C:150
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Tuple2.H
Foam::bladeModel::chord
const List< scalar > & chord() const
Return const access to the chord list.
Definition: bladeModel.C:162
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:97
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:43
Foam::bladeModel::twist
const List< scalar > & twist() const
Return const access to the twist list.
Definition: bladeModel.C:156
unitConversion.H
Unit conversion functions.
Foam::bladeModel::profileID
const List< label > & profileID() const
Return const access to the profile ID list.
Definition: bladeModel.C:144
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:175
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::bladeModel::fName_
fileName fName_
File name (optional)
Definition: bladeModel.H:88
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
bladeModel.H
IFstream.H
dict
dictionary dict
Definition: searchingEngine.H:14
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:121
Foam::degToRad
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
Definition: unitConversion.H:48
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
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:73
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::bladeModel::radius_
List< scalar > radius_
Radius [m].
Definition: bladeModel.H:79
Foam::List< scalar >
Foam::bladeModel::profileID_
List< label > profileID_
Corresponding profile ID per section.
Definition: bladeModel.H:76
vector.H
Foam::bladeModel::twist_
List< scalar > twist_
Twist [deg] on input, converted to [rad].
Definition: bladeModel.H:82
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54
Foam::bladeModel::readFromFile
bool readFromFile() const
Return ture if file name is set.
Definition: bladeModel.C:36
Foam::bladeModel::bladeModel
bladeModel(const dictionary &dict)
Constructor.
Definition: bladeModel.C:91
Foam::bladeModel::chord_
List< scalar > chord_
Chord [m].
Definition: bladeModel.H:85