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 | Copyright (C) 2011-2015 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 "lookupProfile.H"
28 #include "vector.H"
29 #include "unitConversion.H"
30 #include "IFstream.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(lookupProfile, 0);
37  addToRunTimeSelectionTable(profileModel, lookupProfile, dictionary);
38 }
39 
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
44 (
45  const scalar& xIn,
46  const List<scalar>& values,
47  label& i1,
48  label& i2,
49  scalar& ddx
50 ) const
51 {
52  i2 = 0;
53  label nElem = values.size();
54 
55  if (nElem == 1)
56  {
57  i1 = i2;
58  ddx = 0.0;
59  return;
60  }
61  else
62  {
63  while ((i2 < nElem) && (values[i2] < xIn))
64  {
65  i2++;
66  }
67 
68  if (i2 == 0)
69  {
70  i1 = i2;
71  ddx = 0.0;
72  return;
73  }
74  else if (i2 == nElem)
75  {
76  i2 = nElem - 1;
77  i1 = i2;
78  ddx = 0.0;
79  return;
80  }
81  else
82  {
83  i1 = i2 - 1;
84  ddx = (xIn - values[i1])/(values[i2] - values[i1]);
85  }
86  }
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 
93 (
94  const dictionary& dict,
95  const word& modelName
96 )
97 :
98  profileModel(dict, modelName),
99  AOA_(),
100  Cd_(),
101  Cl_()
102 {
104  if (readFromFile())
105  {
106  IFstream is(fName_);
107  is >> data;
108  }
109  else
110  {
111  dict.lookup("data") >> data;
112  }
113 
114  if (data.size() > 0)
115  {
116  AOA_.setSize(data.size());
117  Cd_.setSize(data.size());
118  Cl_.setSize(data.size());
119 
120  forAll(data, i)
121  {
122  AOA_[i] = degToRad(data[i][0]);
123  Cd_[i] = data[i][1];
124  Cl_[i] = data[i][2];
125  }
126  }
127  else
128  {
130  (
131  "Foam::lookupProfile::lookupProfile"
132  "("
133  "const dictionary&, "
134  "const word&"
135  ")"
136  ) << "No profile data specified" << exit(FatalError);
137  }
138 }
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
143 void Foam::lookupProfile::Cdl(const scalar alpha, scalar& Cd, scalar& Cl) const
144 {
145  label i1 = -1;
146  label i2 = -1;
147  scalar invAlpha = -1.0;
148  interpolateWeights(alpha, AOA_, i1, i2, invAlpha);
149 
150  Cd = invAlpha*(Cd_[i2] - Cd_[i1]) + Cd_[i1];
151  Cl = invAlpha*(Cl_[i2] - Cl_[i1]) + Cl_[i1];
152 }
153 
154 
155 // ************************************************************************* //
lookupProfile(const dictionary &dict, const word &modelName)
Constructor.
Definition: lookupProfile.C:93
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:44
virtual void Cdl(const scalar alpha, scalar &Cd, scalar &Cl) const
Return the Cd and Cl for a given angle-of-attack.
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Input from file stream.
Definition: IFstream.H:81
Namespace for OpenFOAM.
void setSize(const label)
Reset size of List.
Definition: List.C:318
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
#define forAll(list, i)
Definition: UList.H:421
Base class for profile models.
Definition: profileModel.H:50
Macros for easy insertion into run-time selection tables.
Unit conversion functions.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)