seriesProfile.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 "seriesProfile.H"
31 #include "IFstream.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(seriesProfile, 0);
39 }
40 
41 
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
43 
45 (
46  const scalar& xIn,
47  const List<scalar>& values
48 ) const
49 {
50  scalar result = 0.0;
51 
52  forAll(values, i)
53  {
54  result += values[i]*cos(i*xIn);
55  }
56 
57  return result;
58 }
59 
60 
62 (
63  const scalar& xIn,
64  const List<scalar>& values
65 ) const
66 {
67  scalar result = 0.0;
68 
69  forAll(values, i)
70  {
71  // note: first contribution always zero since sin(0) = 0, but
72  // keep zero base to be consistent with drag coeffs
73  result += values[i]*sin(i*xIn);
74  }
75 
76  return result;
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 
83 (
84  const dictionary& dict,
85  const word& modelName
86 )
87 :
88  profileModel(dict, modelName),
89  CdCoeffs_(),
90  ClCoeffs_()
91 {
92  if (readFromFile())
93  {
94  IFstream is(fName_);
95  is >> CdCoeffs_ >> ClCoeffs_;
96  }
97  else
98  {
99  dict.readEntry("CdCoeffs", CdCoeffs_);
100  dict.readEntry("ClCoeffs", ClCoeffs_);
101  }
102 
103 
104  if (CdCoeffs_.empty())
105  {
107  << "CdCoeffs must be specified"
108  << exit(FatalIOError);
109  }
110  if (ClCoeffs_.empty())
111  {
113  << "ClCoeffs must be specified"
115  }
116 }
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
121 void Foam::seriesProfile::Cdl(const scalar alpha, scalar& Cd, scalar& Cl) const
122 {
123  Cd = evaluateDrag(alpha, CdCoeffs_);
124  Cl = evaluateLift(alpha, ClCoeffs_);
125 }
126 
127 
128 // ************************************************************************* //
dictionary dict
virtual void Cdl(const scalar alpha, scalar &Cd, scalar &Cl) const
Return the Cd and Cl for a given angle-of-attack.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
List< scalar > ClCoeffs_
List of lift coefficient values.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
scalar evaluateLift(const scalar &xIn, const List< scalar > &values) const
Lift.
Definition: seriesProfile.C:55
seriesProfile(const dictionary &dict, const word &modelName)
Constructor from dictionary and model name.
Definition: seriesProfile.C:76
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
Profile model where polar lift and drag coefficients are computed as sum of trigonometric series by u...
dimensionedScalar cos(const dimensionedScalar &ds)
fileName fName_
File name (optional)
Definition: profileModel.H:135
A class for handling words, derived from Foam::string.
Definition: word.H:63
Base class for profile models for handling aerofoil lift and drag polar diagrams. ...
Definition: profileModel.H:116
dimensionedScalar sin(const dimensionedScalar &ds)
defineTypeNameAndDebug(combustionModel, 0)
Input from file stream, using an ISstream.
Definition: IFstream.H:49
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
List< scalar > CdCoeffs_
List of drag coefficient values.
bool readFromFile() const
Return true if file name is set.
Definition: profileModel.C:36
scalar evaluateDrag(const scalar &xIn, const List< scalar > &values) const
Drag.
Definition: seriesProfile.C:38
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...