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 -------------------------------------------------------------------------------
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 "lookupProfile.H"
30 #include "vector.H"
31 #include "unitConversion.H"
32 #include "IFstream.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(lookupProfile, 0);
39  addToRunTimeSelectionTable(profileModel, lookupProfile, dictionary);
40 }
41 
42 
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 
46 (
47  const scalar& xIn,
48  const List<scalar>& values,
49  label& i1,
50  label& i2,
51  scalar& ddx
52 ) const
53 {
54  i2 = 0;
55  const label nElem = values.size();
56 
57  if (nElem == 1)
58  {
59  i1 = i2;
60  ddx = 0.0;
61  return;
62  }
63  else
64  {
65  while ((i2 < nElem) && (values[i2] < xIn))
66  {
67  i2++;
68  }
69 
70  if (i2 == 0)
71  {
72  i1 = i2;
73  ddx = 0.0;
74  return;
75  }
76  else if (i2 == nElem)
77  {
78  i2 = nElem - 1;
79  i1 = i2;
80  ddx = 0.0;
81  return;
82  }
83  else
84  {
85  i1 = i2 - 1;
86  ddx = (xIn - values[i1])/(values[i2] - values[i1]);
87  }
88  }
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
93 
95 (
96  const dictionary& dict,
97  const word& modelName
98 )
99 :
100  profileModel(dict, modelName),
101  AOA_(),
102  Cd_(),
103  Cl_()
104 {
106  if (readFromFile())
107  {
108  IFstream is(fName_);
109  is >> data;
110  }
111  else
112  {
113  dict.readEntry("data", data);
114  }
115 
116  if (data.size())
117  {
118  AOA_.setSize(data.size());
119  Cd_.setSize(data.size());
120  Cl_.setSize(data.size());
121 
122  forAll(data, i)
123  {
124  AOA_[i] = degToRad(data[i][0]);
125  Cd_[i] = data[i][1];
126  Cl_[i] = data[i][2];
127  }
128  }
129  else
130  {
132  << "No profile data specified" << exit(FatalError);
133  }
134 }
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
139 void Foam::lookupProfile::Cdl(const scalar alpha, scalar& Cd, scalar& Cl) const
140 {
141  label i1 = -1;
142  label i2 = -1;
143  scalar invAlpha = -1.0;
144  interpolateWeights(alpha, AOA_, i1, i2, invAlpha);
145 
146  Cd = invAlpha*(Cd_[i2] - Cd_[i1]) + Cd_[i1];
147  Cl = invAlpha*(Cl_[i2] - Cl_[i1]) + Cl_[i1];
148 }
149 
150 
151 // ************************************************************************* //
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:46
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::lookupProfile::lookupProfile
lookupProfile(const dictionary &dict, const word &modelName)
Constructor.
Definition: lookupProfile.C:95
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::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:212
lookupProfile.H
unitConversion.H
Unit conversion functions.
Foam::lookupProfile::Cd_
List< scalar > Cd_
List of drag coefficient values.
Definition: lookupProfile.H:79
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
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
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:76
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
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
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
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:139
vector.H
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54
Foam::profileModel
Base class for profile models.
Definition: profileModel.H:52
Foam::lookupProfile::Cl_
List< scalar > Cl_
List of lift coefficient values.
Definition: lookupProfile.H:82