lookupProfile.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-2015 OpenFOAM Foundation
9 Copyright (C) 2020 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
29#include "lookupProfile.H"
31#include "vector.H"
32#include "unitConversion.H"
33#include "IFstream.H"
34
35// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36
37namespace Foam
38{
41}
42
43
44// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
45
47(
48 const scalar& xIn,
49 const List<scalar>& values,
50 label& i1,
51 label& i2,
52 scalar& ddx
53) const
54{
55 i2 = 0;
56 const label nElem = values.size();
57
58 if (nElem == 1)
59 {
60 i1 = i2;
61 ddx = 0.0;
62 return;
63 }
64 else
65 {
66 while ((i2 < nElem) && (values[i2] < xIn))
67 {
68 i2++;
69 }
70
71 if (i2 == 0)
72 {
73 i1 = i2;
74 ddx = 0.0;
75 return;
76 }
77 else if (i2 == nElem)
78 {
79 i2 = nElem - 1;
80 i1 = i2;
81 ddx = 0.0;
82 return;
83 }
84 else
85 {
86 i1 = i2 - 1;
87 ddx = (xIn - values[i1])/(values[i2] - values[i1]);
88 }
89 }
90}
91
92
93// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
94
96(
97 const dictionary& dict,
98 const word& modelName
99)
100:
101 profileModel(dict, modelName),
102 AOA_(),
103 Cd_(),
104 Cl_()
105{
107 if (readFromFile())
108 {
109 IFstream is(fName_);
110 is >> data;
111 }
112 else
113 {
114 dict.readEntry("data", data);
115 }
116
117 if (data.size())
118 {
119 AOA_.setSize(data.size());
120 Cd_.setSize(data.size());
121 Cl_.setSize(data.size());
122
123 forAll(data, i)
124 {
125 AOA_[i] = degToRad(data[i][0]);
126 Cd_[i] = data[i][1];
127 Cl_[i] = data[i][2];
128 }
129 }
130 else
131 {
133 << "No profile data specified"
134 << exit(FatalIOError);
135 }
136}
137
138
139// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140
141void Foam::lookupProfile::Cdl(const scalar alpha, scalar& Cd, scalar& Cl) const
142{
143 label i1 = -1;
144 label i2 = -1;
145 scalar invAlpha = -1.0;
146 interpolateWeights(alpha, AOA_, i1, i2, invAlpha);
147
148 Cd = invAlpha*(Cd_[i2] - Cd_[i1]) + Cd_[i1];
149 Cl = invAlpha*(Cl_[i2] - Cl_[i1]) + Cl_[i1];
150}
151
152
153// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Input from file stream, using an ISstream.
Definition: IFstream.H:57
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
void setSize(const label n)
Alias for resize()
Definition: List.H:218
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Profile model where polar lift and drag coefficients are linearly interpolated from a polar table by ...
List< scalar > Cl_
List of lift coefficient values.
void interpolateWeights(const scalar &xIn, const List< scalar > &values, label &i1, label &i2, scalar &ddx) const
Return the interpolation indices and gradient.
Definition: lookupProfile.C:47
virtual void Cdl(const scalar alpha, scalar &Cd, scalar &Cl) const
Return the Cd and Cl for a given angle-of-attack.
List< scalar > Cd_
List of drag coefficient values.
List< scalar > AOA_
List of angle-of-attack values [deg] on input, converted to [rad].
Base class for profile models for handling aerofoil lift and drag polar diagrams.
Definition: profileModel.H:121
bool readFromFile() const
Return true if file name is set.
Definition: profileModel.C:43
fileName fName_
File name (optional)
Definition: profileModel.H:133
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Namespace for OpenFOAM.
constexpr scalar degToRad() noexcept
Multiplication factor for degrees to radians conversion.
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
volScalarField & alpha
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Unit conversion functions.