rotorDiskSourceTemplates.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-2021 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 "rotorDiskSource.H"
27 #include "volFields.H"
28 #include "unitConversion.H"
29 
30 using namespace Foam::constant;
31 
32 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
33 
34 template<class RhoFieldType>
36 (
37  const RhoFieldType& rho,
38  const vectorField& U,
39  const scalarField& thetag,
40  vectorField& force,
41  const bool divideVolume,
42  const bool output
43 ) const
44 {
45  const scalarField& V = mesh().V();
46 
47  // Logging info
48  scalar dragEff = 0;
49  scalar liftEff = 0;
50  scalar AOAmin = great;
51  scalar AOAmax = -great;
52  scalar powerEff = 0;
53 
54  const labelList& cells = set_.cells();
55 
56  forAll(cells, i)
57  {
58  if (area_[i] > rootVSmall)
59  {
60  const label celli = cells[i];
61 
62  const scalar radius = x_[i].x();
63 
64  // Transform velocity into local cylindrical reference frame
65  vector Uc = cylindrical_->invTransform(U[celli], i);
66  // Uc.x(): radial direction.
67  // Uc.y(): drag direction.
68  // Uc.z(): lift / thrust direction.
69 
70  // Transform velocity into local coning system
71  Uc = R_[i] & Uc;
72 
73  // Set radial component of velocity to zero
74  Uc.x() = 0;
75 
76  // Set blade normal component of velocity
77  Uc.y() = radius*omega_ - Uc.y();
78 
79  // Determine blade data for this radius
80  // i2 = index of upper radius bound data point in blade list
81  scalar twist = 0;
82  scalar chord = 0;
83  label i1 = -1;
84  label i2 = -1;
85  scalar invDr = 0;
86  blade_.interpolate(radius, twist, chord, i1, i2, invDr);
87 
88  const scalar alphaGeom = thetag[i] + twist;
89 
90  // Effective angle of attack
91  const int rotationSign = sign(omega_);
92  const scalar alphaEff =
93  alphaGeom - atan2(-Uc.z(), rotationSign*Uc.y());
94 
95  AOAmin = min(AOAmin, alphaEff);
96  AOAmax = max(AOAmax, alphaEff);
97 
98  // Determine profile data for this radius and angle of attack
99  const label profile1 = blade_.profileID()[i1];
100  const label profile2 = blade_.profileID()[i2];
101 
102  scalar Cd1 = 0;
103  scalar Cl1 = 0;
104  profiles_[profile1].Cdl(alphaEff, Cd1, Cl1);
105 
106  scalar Cd2 = 0;
107  scalar Cl2 = 0;
108  profiles_[profile2].Cdl(alphaEff, Cd2, Cl2);
109 
110  const scalar Cd = invDr*(Cd2 - Cd1) + Cd1;
111  const scalar Cl = invDr*(Cl2 - Cl1) + Cl1;
112 
113  // Apply tip effect for blade lift
114  const scalar tipFactor = neg(radius/rMax_ - tipEffect_);
115 
116  // Calculate forces perpendicular to blade
117  const scalar pDyn = 0.5*rho[celli]*magSqr(Uc);
118 
119  const scalar f =
120  pDyn*chord*nBlades_*area_[i]/radius/mathematical::twoPi;
121 
122  vector localForce = vector(0, rotationSign*-f*Cd, tipFactor*f*Cl);
123 
124  // Accumulate forces
125  dragEff += rhoRef_*localForce.y();
126  liftEff += rhoRef_*localForce.z();
127  powerEff += rhoRef_*localForce.y()*radius*omega_;
128 
129  // Transform force from local coning system into rotor cylindrical
130  localForce = invR_[i] & localForce;
131 
132  // Transform force into global Cartesian co-ordinate system
133  force[celli] = cylindrical_->transform(localForce, i);
134 
135  if (divideVolume)
136  {
137  force[celli] /= V[celli];
138  }
139  }
140  }
141 
142  if (output)
143  {
144  reduce(AOAmin, minOp<scalar>());
145  reduce(AOAmax, maxOp<scalar>());
146  reduce(dragEff, sumOp<scalar>());
147  reduce(liftEff, sumOp<scalar>());
148 
149  Info<< type() << " output:" << nl
150  << " min/max(AOA) = " << radToDeg(AOAmin) << ", "
151  << radToDeg(AOAmax) << nl
152  << " Effective power = " << powerEff << nl
153  << " Effective drag = " << dragEff << nl
154  << " Effective lift = " << liftEff << endl;
155  }
156 }
157 
158 
159 template<class Type>
160 void Foam::fv::rotorDiskSource::writeField
161 (
162  const word& name,
163  const List<Type>& values,
164  const bool writeNow
165 ) const
166 {
168 
169  if (mesh().time().writeTime() || writeNow)
170  {
171  tmp<fieldType> tfield
172  (
173  new fieldType
174  (
175  IOobject
176  (
177  name,
178  mesh().time().timeName(),
179  mesh(),
182  ),
183  mesh(),
184  dimensioned<Type>("zero", dimless, Zero)
185  )
186  );
187 
188  Field<Type>& field = tfield.ref().primitiveFieldRef();
189 
190  const labelList& cells = set_.cells();
191 
192  if (cells.size() != values.size())
193  {
195  }
196 
197  forAll(cells, i)
198  {
199  field[cells[i]] = values[i];
200  }
201 
202  tfield().write();
203  }
204 }
205 
206 
207 // ************************************************************************* //
Collection of constants.
dimensionedScalar sign(const dimensionedScalar &ds)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Unit conversion functions.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const Cmpt & z() const
Definition: VectorI.H:87
Generic GeometricField class.
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
const dimensionSet dimless
Generic dimensioned Type class.
fvMesh & mesh
dimensionedScalar neg(const dimensionedScalar &ds)
const Cmpt & y() const
Definition: VectorI.H:81
const cellShapeList & cells
A class for handling words, derived from string.
Definition: word.H:59
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
word timeName
Definition: getTimeIndex.H:3
static const zero Zero
Definition: zero.H:97
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const Cmpt & x() const
Definition: VectorI.H:75
const scalar twoPi(2 *pi)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
static const char nl
Definition: Ostream.H:260
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
labelList f(nPoints)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
messageStream Info
void calculate(const RhoFieldType &rho, const vectorField &U, const scalarField &thetag, vectorField &force, const bool divideVolume=true, const bool output=true) const
Calculate forces.
rDeltaTY field()
A class for managing temporary objects.
Definition: PtrList.H:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98