FreeFOAM The Cross-Platform CFD Toolkit
swirlFlowRateInletVelocityFvPatchVectorField.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) 2010-2010 OpenCFD Ltd.
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 
27 #include <finiteVolume/volFields.H>
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 Foam::
38 (
39  const fvPatch& p,
41 )
42 :
44  flowRate_(0),
45  phiName_("phi"),
46  rhoName_("rho"),
47  rpm_(0)
48 {}
49 
50 
51 Foam::
54 (
56  const fvPatch& p,
58  const fvPatchFieldMapper& mapper
59 )
60 :
61  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
62  flowRate_(ptf.flowRate_),
63  phiName_(ptf.phiName_),
64  rhoName_(ptf.rhoName_),
65  rpm_(ptf.rpm_)
66 {}
67 
68 
69 Foam::
72 (
73  const fvPatch& p,
75  const dictionary& dict
76 )
77 :
79  flowRate_(readScalar(dict.lookup("flowRate"))),
80  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
81  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
82  rpm_(readScalar(dict.lookup("rpm")))
83 {}
84 
85 
86 Foam::
89 (
91 )
92 :
94  flowRate_(ptf.flowRate_),
95  phiName_(ptf.phiName_),
96  rhoName_(ptf.rhoName_),
97  rpm_(ptf.rpm_)
98 {}
99 
100 
101 Foam::
104 (
107 )
108 :
110  flowRate_(ptf.flowRate_),
111  phiName_(ptf.phiName_),
112  rhoName_(ptf.rhoName_),
113  rpm_(ptf.rpm_)
114 {}
115 
116 
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 
120 {
121  if (updated())
122  {
123  return;
124  }
125 
126  const scalar totArea = gSum(patch().magSf());
127  // a simpler way of doing this would be nice
128  const scalar avgU = -flowRate_/totArea;
129 
130  const vector avgCenter = gSum(patch().Cf()*patch().magSf())/totArea;
131  const vector avgNormal = gSum(patch().Sf())/totArea;
132 
133  // Update angular velocity - convert [rpm] to [rad/s]
134  vectorField tangentialVelocity =
135  (
136  (rpm_*mathematicalConstant::pi/30.0)
137  * (patch().Cf() - avgCenter) ^ avgNormal
138  );
139 
140  tmp<vectorField> n = patch().nf();
141 
142  const surfaceScalarField& phi =
143  db().lookupObject<surfaceScalarField>(phiName_);
144 
145  if (phi.dimensions() == dimVelocity*dimArea)
146  {
147  // volumetric flow-rate
148  operator==(tangentialVelocity + n*avgU);
149  }
150  else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
151  {
152  const fvPatchField<scalar>& rhop =
153  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
154 
155  // mass flow-rate
156  operator==(tangentialVelocity + n*avgU/rhop);
157  }
158  else
159  {
161  (
162  "swirlFlowRateInletVelocityFvPatchVectorField::updateCoeffs()"
163  ) << "dimensions of " << phiName_ << " are incorrect" << nl
164  << " on patch " << this->patch().name()
165  << " of field " << this->dimensionedInternalField().name()
166  << " in file " << this->dimensionedInternalField().objectPath()
167  << nl << exit(FatalError);
168  }
169 
171 }
172 
173 
175 (
176  Ostream& os
177 ) const
178 {
180  os.writeKeyword("flowRate") << flowRate_ << token::END_STATEMENT << nl;
181  writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
182  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
183  os.writeKeyword("rpm") << rpm_ << token::END_STATEMENT << nl;
184  writeEntry("value", os);
185 }
186 
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 namespace Foam
191 {
193  (
196  );
197 }
198 
199 
200 // ************************************************************************* //