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 -------------------------------------------------------------------------------
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 "lookupProfile.H"
31 #include "vector.H"
32 #include "unitConversion.H"
33 #include "IFstream.H"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(lookupProfile, 0);
40  addToRunTimeSelectionTable(profileModel, lookupProfile, dictionary);
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 
141 void 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 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::lookupProfile::interpolateWeights
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
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::lookupProfile::lookupProfile
lookupProfile(const dictionary &dict, const word &modelName)
Constructor from dictionary and model name.
Definition: lookupProfile.C:96
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::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:212
lookupProfile.H
unitConversion.H
Unit conversion functions.
Foam::FatalIOError
IOerror FatalIOError
Foam::lookupProfile::Cd_
List< scalar > Cd_
List of drag coefficient values.
Definition: lookupProfile.H:141
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
IFstream.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::lookupProfile::AOA_
List< scalar > AOA_
List of angle-of-attack values [deg] on input, converted to [rad].
Definition: lookupProfile.H:138
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
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::List< scalar >
Foam::lookupProfile::Cdl
virtual void Cdl(const scalar alpha, scalar &Cd, scalar &Cl) const
Return the Cd and Cl for a given angle-of-attack.
Definition: lookupProfile.C:141
vector.H
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55
Foam::profileModel
Base class for profile models for handling aerofoil lift and drag polar diagrams.
Definition: profileModel.H:120
Foam::lookupProfile::Cl_
List< scalar > Cl_
List of lift coefficient values.
Definition: lookupProfile.H:144