seriesProfile.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-2024 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 {
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 consistent 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  << "CdCoeffs must be specified" << exit(FatalError);
105  }
106  if (ClCoeffs_.empty())
107  {
109  << "ClCoeffs must be specified" << exit(FatalError);
110  }
111 }
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
116 void Foam::seriesProfile::Cdl(const scalar alpha, scalar& Cd, scalar& Cl) const
117 {
118  Cd = evaluateDrag(alpha, CdCoeffs_);
119  Cl = evaluateLift(alpha, ClCoeffs_);
120 }
121 
122 
123 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
Input from file stream.
Definition: IFstream.H:85
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Base class for profile models.
Definition: profileModel.H:51
bool readFromFile() const
Return true if file name is set.
Definition: profileModel.C:40
fileName fName_
File name (optional)
Definition: profileModel.H:64
Series-up based profile data - drag and lift coefficients computed as sum of cosine series.
Definition: seriesProfile.H:66
scalar evaluateDrag(const scalar &xIn, const List< scalar > &values) const
Drag.
Definition: seriesProfile.C:42
seriesProfile(const dictionary &dict, const word &modelName)
Constructor.
Definition: seriesProfile.C:80
List< scalar > ClCoeffs_
List of lift coefficient values.
Definition: seriesProfile.H:76
List< scalar > CdCoeffs_
List of drag coefficient values.
Definition: seriesProfile.H:73
virtual void Cdl(const scalar alpha, scalar &Cd, scalar &Cl) const
Return the Cd and Cl for a given angle-of-attack.
scalar evaluateLift(const scalar &xIn, const List< scalar > &values) const
Lift.
Definition: seriesProfile.C:59
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
dimensionedScalar sin(const dimensionedScalar &ds)
defineTypeNameAndDebug(combustionModel, 0)
error FatalError
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict