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-2019 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  forAll(cells_, i)
55  {
56  if (area_[i] > rootVSmall)
57  {
58  const label celli = cells_[i];
59 
60  const scalar radius = x_[i].x();
61 
62  // Transform velocity into local cylindrical reference frame
63  vector Uc = cylindrical_->invTransform(U[celli], i);
64  // Uc.x(): radial direction.
65  // Uc.y(): drag direction.
66  // Uc.z(): lift / thrust direction.
67 
68  // Transform velocity into local coning system
69  Uc = R_[i] & Uc;
70 
71  // Set radial component of velocity to zero
72  Uc.x() = 0;
73 
74  // Set blade normal component of velocity
75  Uc.y() = radius*omega_ - Uc.y();
76 
77  // Determine blade data for this radius
78  // i2 = index of upper radius bound data point in blade list
79  scalar twist = 0;
80  scalar chord = 0;
81  label i1 = -1;
82  label i2 = -1;
83  scalar invDr = 0;
84  blade_.interpolate(radius, twist, chord, i1, i2, invDr);
85 
86  const scalar alphaGeom = thetag[i] + twist;
87 
88  // Effective angle of attack
89  const int rotationSign = sign(omega_);
90  const scalar alphaEff =
91  alphaGeom - atan2(-Uc.z(), rotationSign*Uc.y());
92 
93  AOAmin = min(AOAmin, alphaEff);
94  AOAmax = max(AOAmax, alphaEff);
95 
96  // Determine profile data for this radius and angle of attack
97  const label profile1 = blade_.profileID()[i1];
98  const label profile2 = blade_.profileID()[i2];
99 
100  scalar Cd1 = 0;
101  scalar Cl1 = 0;
102  profiles_[profile1].Cdl(alphaEff, Cd1, Cl1);
103 
104  scalar Cd2 = 0;
105  scalar Cl2 = 0;
106  profiles_[profile2].Cdl(alphaEff, Cd2, Cl2);
107 
108  const scalar Cd = invDr*(Cd2 - Cd1) + Cd1;
109  const scalar Cl = invDr*(Cl2 - Cl1) + Cl1;
110 
111  // Apply tip effect for blade lift
112  const scalar tipFactor = neg(radius/rMax_ - tipEffect_);
113 
114  // Calculate forces perpendicular to blade
115  const scalar pDyn = 0.5*rho[celli]*magSqr(Uc);
116 
117  const scalar f =
118  pDyn*chord*nBlades_*area_[i]/radius/mathematical::twoPi;
119 
120  vector localForce = vector(0, rotationSign*-f*Cd, tipFactor*f*Cl);
121 
122  // Accumulate forces
123  dragEff += rhoRef_*localForce.y();
124  liftEff += rhoRef_*localForce.z();
125  powerEff += rhoRef_*localForce.y()*radius*omega_;
126 
127  // Transform force from local coning system into rotor cylindrical
128  localForce = invR_[i] & localForce;
129 
130  // Transform force into global Cartesian co-ordinate system
131  force[celli] = cylindrical_->transform(localForce, i);
132 
133  if (divideVolume)
134  {
135  force[celli] /= V[celli];
136  }
137  }
138  }
139 
140  if (output)
141  {
142  reduce(AOAmin, minOp<scalar>());
143  reduce(AOAmax, maxOp<scalar>());
144  reduce(dragEff, sumOp<scalar>());
145  reduce(liftEff, sumOp<scalar>());
146 
147  Info<< type() << " output:" << nl
148  << " min/max(AOA) = " << radToDeg(AOAmin) << ", "
149  << radToDeg(AOAmax) << nl
150  << " Effective power = " << powerEff << nl
151  << " Effective drag = " << dragEff << nl
152  << " Effective lift = " << liftEff << endl;
153  }
154 }
155 
156 
157 template<class Type>
159 (
160  const word& name,
161  const List<Type>& values,
162  const bool writeNow
163 ) const
164 {
166 
167  if (mesh_.time().writeTime() || writeNow)
168  {
169  tmp<fieldType> tfield
170  (
171  new fieldType
172  (
173  IOobject
174  (
175  name,
176  mesh_.time().timeName(),
177  mesh_,
180  ),
181  mesh_,
182  dimensioned<Type>("zero", dimless, Zero)
183  )
184  );
185 
186  Field<Type>& field = tfield.ref().primitiveFieldRef();
187 
188  if (cells_.size() != values.size())
189  {
191  }
192 
193  forAll(cells_, i)
194  {
195  const label celli = cells_[i];
196  field[celli] = values[i];
197  }
198 
199  tfield().write();
200  }
201 }
202 
203 
204 // ************************************************************************* //
Collection of constants.
dimensionedScalar sign(const dimensionedScalar &ds)
#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
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
error FatalError
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
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
Generic dimensioned Type class.
dimensionedScalar neg(const dimensionedScalar &ds)
const Cmpt & y() const
Definition: VectorI.H:81
A class for handling words, derived from string.
Definition: word.H:59
volScalarField pDyn(IOobject("pDyn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimPressure, 0))
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)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
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 writeField(const word &name, const List< Type > &values, const bool writeNow=false) const
Helper function to write rotor values.
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:92