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 | Copyright (C) 2011-2013 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 "seriesProfile.H"
28 #include "IFstream.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(seriesProfile, 0);
35  addToRunTimeSelectionTable(profileModel, seriesProfile, dictionary);
36 }
37 
38 
39 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
40 
42 (
43  const scalar& xIn,
44  const List<scalar>& values
45 ) const
46 {
47  scalar result = 0.0;
48 
49  forAll(values, i)
50  {
51  result += values[i]*cos(i*xIn);
52  }
53 
54  return result;
55 }
56 
57 
59 (
60  const scalar& xIn,
61  const List<scalar>& values
62 ) const
63 {
64  scalar result = 0.0;
65 
66  forAll(values, i)
67  {
68  // note: first contribution always zero since sin(0) = 0, but
69  // keep zero base to be consitent with drag coeffs
70  result += values[i]*sin(i*xIn);
71  }
72 
73  return result;
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
80 (
81  const dictionary& dict,
82  const word& modelName
83 )
84 :
85  profileModel(dict, modelName),
86  CdCoeffs_(),
87  ClCoeffs_()
88 {
89  if (readFromFile())
90  {
91  IFstream is(fName_);
92  is >> CdCoeffs_ >> ClCoeffs_;
93  }
94  else
95  {
96  dict.lookup("CdCoeffs") >> CdCoeffs_;
97  dict.lookup("ClCoeffs") >> ClCoeffs_;
98  }
99 
100 
101  if (CdCoeffs_.empty())
102  {
104  (
105  "Foam::seriesProfile::seriesProfile"
106  "("
107  "const dictionary&, "
108  "const word&"
109  ")"
110  ) << "CdCoeffs must be specified" << exit(FatalError);
111  }
112  if (ClCoeffs_.empty())
113  {
115  (
116  "Foam::seriesProfile::seriesProfile"
117  "("
118  "const dictionary&, "
119  "const word&"
120  ")"
121  ) << "ClCoeffs must be specified" << exit(FatalError);
122  }
123 }
124 
125 
126 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127 
128 void Foam::seriesProfile::Cdl(const scalar alpha, scalar& Cd, scalar& Cl) const
129 {
130  Cd = evaluateDrag(alpha, CdCoeffs_);
131  Cl = evaluateLift(alpha, ClCoeffs_);
132 }
133 
134 
135 // ************************************************************************* //
A class for handling words, derived from string.
Definition: word.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
scalar evaluateLift(const scalar &xIn, const List< scalar > &values) const
Lift.
Definition: seriesProfile.C:59
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.
virtual void Cdl(const scalar alpha, scalar &Cd, scalar &Cl) const
Return the Cd and Cl for a given angle-of-attack.
seriesProfile(const dictionary &dict, const word &modelName)
Constructor.
Definition: seriesProfile.C:80
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
#define forAll(list, i)
Definition: UList.H:421
dimensionedScalar cos(const dimensionedScalar &ds)
Base class for profile models.
Definition: profileModel.H:50
Macros for easy insertion into run-time selection tables.
scalar evaluateDrag(const scalar &xIn, const List< scalar > &values) const
Drag.
Definition: seriesProfile.C:42
#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
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
dimensionedScalar sin(const dimensionedScalar &ds)