bladeModel.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 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 
26 #include "bladeModel.H"
27 #include "unitConversion.H"
28 #include "Tuple2.H"
29 #include "vector.H"
30 #include "IFstream.H"
31 
32 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
33 
35 {
36  return fName_ != fileName::null;
37 }
38 
39 
41 (
42  const scalar& xIn,
43  const List<scalar>& values,
44  label& i1,
45  label& i2,
46  scalar& ddx
47 ) const
48 {
49  i2 = 0;
50  label nElem = values.size();
51 
52  if (nElem == 1)
53  {
54  i1 = i2;
55  ddx = 0.0;
56  return;
57  }
58  else
59  {
60  while ((i2 < nElem) && (values[i2] < xIn))
61  {
62  i2++;
63  }
64 
65  if (i2 == 0)
66  {
67  i1 = i2;
68  ddx = 0.0;
69  return;
70  }
71  else if (i2 == nElem)
72  {
73  i2 = nElem - 1;
74  i1 = i2;
75  ddx = 0.0;
76  return;
77  }
78  else
79  {
80  i1 = i2 - 1;
81  ddx = (xIn - values[i1])/(values[i2] - values[i1]);
82  }
83  }
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 :
91  profileName_(),
92  profileID_(),
93  radius_(),
94  twist_(),
95  chord_(),
96  fName_(fileName::null)
97 {
99  if (readFromFile())
100  {
101  IFstream is(fName_);
102  is >> data;
103  }
104  else
105  {
106  dict.lookup("data") >> data;
107  }
108 
109  if (data.size() > 0)
110  {
111  profileName_.setSize(data.size());
112  profileID_.setSize(data.size());
113  radius_.setSize(data.size());
114  twist_.setSize(data.size());
115  chord_.setSize(data.size());
116 
117  forAll(data, i)
118  {
119  profileName_[i] = data[i].first();
120  profileID_[i] = -1;
121  radius_[i] = data[i].second()[0];
122  twist_[i] = degToRad(data[i].second()[1]);
123  chord_[i] = data[i].second()[2];
124  }
125  }
126  else
127  {
129  << "No blade data specified" << exit(FatalError);
130  }
131 }
132 
133 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
134 
136 {}
137 
138 
139 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140 
142 {
143  return profileName_;
144 }
145 
146 
148 {
149  return profileID_;
150 }
151 
152 
154 {
155  return radius_;
156 }
157 
158 
160 {
161  return twist_;
162 }
163 
164 
166 {
167  return chord_;
168 }
169 
170 
172 {
173  return profileID_;
174 }
175 
176 
178 (
179  const scalar radius,
180  scalar& twist,
181  scalar& chord,
182  label& i1,
183  label& i2,
184  scalar& invDr
185 ) const
186 {
187  interpolateWeights(radius, radius_, i1, i2, invDr);
188 
189  twist = invDr*(twist_[i2] - twist_[i1]) + twist_[i1];
190  chord = invDr*(chord_[i2] - chord_[i1]) + chord_[i1];
191 }
192 
193 
194 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:59
A class for handling file names.
Definition: fileName.H:79
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< scalar > radius_
Radius [m].
Definition: bladeModel.H:78
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
const List< scalar > & radius() const
Return const access to the radius list.
Definition: bladeModel.C:153
Unit conversion functions.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
static const fileName null
An empty fileName.
Definition: fileName.H:97
List< scalar > chord_
Chord [m].
Definition: bladeModel.H:84
List< scalar > twist_
Twist [deg] on input, converted to [rad].
Definition: bladeModel.H:81
T & first()
Return the first element of the list.
Definition: UListI.H:114
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
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:178
virtual ~bladeModel()
Destructor.
Definition: bladeModel.C:135
bladeModel(const dictionary &dict)
Constructor.
Definition: bladeModel.C:89
const List< scalar > & twist() const
Return const access to the twist list.
Definition: bladeModel.C:159
List< word > profileName_
Corresponding profile name per section.
Definition: bladeModel.H:72
const List< label > & profileID() const
Return const access to the profile ID list.
Definition: bladeModel.C:147
bool readFromFile() const
Return true if file name is set.
Definition: bladeModel.C:34
Database for solution and other reduced data.
Definition: data.H:51
Input from file stream.
Definition: IFstream.H:81
const List< scalar > & chord() const
Return const access to the chord list.
Definition: bladeModel.C:165
List< label > profileID_
Corresponding profile ID per section.
Definition: bladeModel.H:75
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:41
void setSize(const label)
Reset size of List.
Definition: List.C:281
fileName fName_
File name (optional)
Definition: bladeModel.H:87
const List< word > & profileName() const
Return const access to the profile name list.
Definition: bladeModel.C:141
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844