lookupProfile.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-2018 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  << "No profile data specified" << exit(FatalError);
131  }
132 }
133 
134 
135 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 
137 void Foam::lookupProfile::Cdl(const scalar alpha, scalar& Cd, scalar& Cl) const
138 {
139  label i1 = -1;
140  label i2 = -1;
141  scalar invAlpha = -1.0;
142  interpolateWeights(alpha, AOA_, i1, i2, invAlpha);
143 
144  Cd = invAlpha*(Cd_[i2] - Cd_[i1]) + Cd_[i1];
145  Cl = invAlpha*(Cl_[i2] - Cl_[i1]) + Cl_[i1];
146 }
147 
148 
149 // ************************************************************************* //
#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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Unit conversion functions.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Macros for easy insertion into run-time selection tables.
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
lookupProfile(const dictionary &dict, const word &modelName)
Constructor.
Definition: lookupProfile.C:93
A class for handling words, derived from string.
Definition: word.H:59
Base class for profile models.
Definition: profileModel.H:50
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Database for solution and other reduced data.
Definition: data.H:51
virtual void Cdl(const scalar alpha, scalar &Cd, scalar &Cl) const
Return the Cd and Cl for a given angle-of-attack.
Input from file stream.
Definition: IFstream.H:81
void setSize(const label)
Reset size of List.
Definition: List.C:281
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
volScalarField alpha(IOobject("alpha", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583