rotorDiskSourceTemplates.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-2016 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.0;
49  scalar liftEff = 0.0;
50  scalar AOAmin = GREAT;
51  scalar AOAmax = -GREAT;
52 
53  forAll(cells_, i)
54  {
55  if (area_[i] > ROOTVSMALL)
56  {
57  const label celli = cells_[i];
58 
59  const scalar radius = x_[i].x();
60 
61  // Transform velocity into local cylindrical reference frame
62  vector Uc = cylindrical_->invTransform(U[celli], i);
63 
64  // Transform velocity into local coning system
65  Uc = R_[i] & Uc;
66 
67  // Set radial component of velocity to zero
68  Uc.x() = 0.0;
69 
70  // Set blade normal component of velocity
71  Uc.y() = radius*omega_ - Uc.y();
72 
73  // Determine blade data for this radius
74  // i2 = index of upper radius bound data point in blade list
75  scalar twist = 0.0;
76  scalar chord = 0.0;
77  label i1 = -1;
78  label i2 = -1;
79  scalar invDr = 0.0;
80  blade_.interpolate(radius, twist, chord, i1, i2, invDr);
81 
82  // Flip geometric angle if blade is spinning in reverse (clockwise)
83  scalar alphaGeom = thetag[i] + twist;
84  if (omega_ < 0)
85  {
86  alphaGeom = mathematical::pi - alphaGeom;
87  }
88 
89  // Effective angle of attack
90  scalar alphaEff = alphaGeom - atan2(-Uc.z(), Uc.y());
91  if (alphaEff > mathematical::pi)
92  {
93  alphaEff -= mathematical::twoPi;
94  }
95  if (alphaEff < -mathematical::pi)
96  {
97  alphaEff += mathematical::twoPi;
98  }
99 
100  AOAmin = min(AOAmin, alphaEff);
101  AOAmax = max(AOAmax, alphaEff);
102 
103  // Determine profile data for this radius and angle of attack
104  const label profile1 = blade_.profileID()[i1];
105  const label profile2 = blade_.profileID()[i2];
106 
107  scalar Cd1 = 0.0;
108  scalar Cl1 = 0.0;
109  profiles_[profile1].Cdl(alphaEff, Cd1, Cl1);
110 
111  scalar Cd2 = 0.0;
112  scalar Cl2 = 0.0;
113  profiles_[profile2].Cdl(alphaEff, Cd2, Cl2);
114 
115  scalar Cd = invDr*(Cd2 - Cd1) + Cd1;
116  scalar Cl = invDr*(Cl2 - Cl1) + Cl1;
117 
118  // Apply tip effect for blade lift
119  scalar tipFactor = neg(radius/rMax_ - tipEffect_);
120 
121  // Calculate forces perpendicular to blade
122  scalar pDyn = 0.5*rho[celli]*magSqr(Uc);
123 
124  scalar f = pDyn*chord*nBlades_*area_[i]/radius/mathematical::twoPi;
125  vector localForce = vector(0.0, -f*Cd, tipFactor*f*Cl);
126 
127  // Accumulate forces
128  dragEff += rhoRef_*localForce.y();
129  liftEff += rhoRef_*localForce.z();
130 
131  // Transform force from local coning system into rotor cylindrical
132  localForce = invR_[i] & localForce;
133 
134  // Transform force into global Cartesian co-ordinate system
135  force[celli] = cylindrical_->transform(localForce, i);
136 
137  if (divideVolume)
138  {
139  force[celli] /= V[celli];
140  }
141  }
142  }
143 
144  if (output)
145  {
146  reduce(AOAmin, minOp<scalar>());
147  reduce(AOAmax, maxOp<scalar>());
148  reduce(dragEff, sumOp<scalar>());
149  reduce(liftEff, sumOp<scalar>());
150 
151  Info<< type() << " output:" << nl
152  << " min/max(AOA) = " << radToDeg(AOAmin) << ", "
153  << radToDeg(AOAmax) << nl
154  << " Effective drag = " << dragEff << nl
155  << " Effective lift = " << liftEff << endl;
156  }
157 }
158 
159 
160 template<class Type>
162 (
163  const word& name,
164  const List<Type>& values,
165  const bool writeNow
166 ) const
167 {
169 
170  if (mesh_.time().writeTime() || writeNow)
171  {
172  tmp<fieldType> tfield
173  (
174  new fieldType
175  (
176  IOobject
177  (
178  name,
179  mesh_.time().timeName(),
180  mesh_,
183  ),
184  mesh_,
185  dimensioned<Type>("zero", dimless, Zero)
186  )
187  );
188 
189  Field<Type>& field = tfield.ref().primitiveFieldRef();
190 
191  if (cells_.size() != values.size())
192  {
194  << abort(FatalError);
195  }
196 
197  forAll(cells_, i)
198  {
199  const label celli = cells_[i];
200  field[celli] = values[i];
201  }
202 
203  tfield().write();
204  }
205 }
206 
207 
208 // ************************************************************************* //
Collection of constants.
const Cmpt & z() const
Definition: VectorI.H:87
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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.
const Cmpt & x() const
Definition: VectorI.H:75
error FatalError
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Unit conversion functions.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
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)
A class for handling words, derived from string.
Definition: word.H:59
const Cmpt & y() const
Definition: VectorI.H:81
static const zero Zero
Definition: zero.H:91
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const scalar twoPi(2 *pi)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
static const char nl
Definition: Ostream.H:262
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)
void calculate(const RhoFieldType &rho, const vectorField &U, const scalarField &thetag, vectorField &force, const bool divideVolume=true, const bool output=true) const
Calculate forces.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
messageStream Info
volScalarField pDyn(IOobject("pDyn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar("zero", dimPressure, 0.0))
volScalarField alphaEff("alphaEff", turbulence->nu()/Pr+alphat)
A class for managing temporary objects.
Definition: PtrList.H:54
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
void writeField(const word &name, const List< Type > &values, const bool writeNow=false) const
Helper function to write rotor values.