swirlFlowRateInletVelocityFvPatchVectorField.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 
27 #include "volFields.H"
29 
30 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
31 
32 template<class RhoType>
33 void Foam::swirlFlowRateInletVelocityFvPatchVectorField::updateValues
34 (
35  const RhoType& rho
36 )
37 {
38  const scalar t = db().time().value();
39  const scalarField ts(size(), t);
40 
41  // Compute geometry
42  const vector axisHat = normalised(axis_);
43  const vectorField d(patch().Cf() - origin_);
44  const vectorField r(d - (axisHat & d)*axisHat);
45  const scalarField magR(mag(r));
46  const vectorField rHat(normalised(r));
47 
48  // Evaluate individual velocity components
49  const scalar axialVelocity = flowRate_->value(t)/gSum(rho*patch().magSf());
50  const scalarField radialVelocity(radialVelocity_->value(ts, magR));
51  tmp<scalarField> tangentialVelocity;
52  if (omega_.valid())
53  {
54  tangentialVelocity = omega_->value(t)*magR;
55  }
56  else
57  {
58  tangentialVelocity = tangentialVelocity_->value(ts, magR);
59  }
60 
61  // Combine components the complete vector velocity
62  operator==
63  (
64  axialVelocity*axisHat
65  + radialVelocity*rHat
66  + tangentialVelocity*(axisHat ^ rHat)
67  );
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
72 
75 (
76  const fvPatch& p,
78  const dictionary& dict
79 )
80 :
81  fixedValueFvPatchField<vector>(p, iF, dict, false),
82  origin_
83  (
84  dict.lookupOrDefault
85  (
86  "origin",
87  dimLength,
88  returnReduce(patch().size(), sumOp<label>())
89  ? gSum(patch().Cf()*patch().magSf())/gSum(patch().magSf())
90  : Zero
91  )
92  ),
93  axis_
94  (
95  dict.lookupOrDefault
96  (
97  "axis",
98  dimless,
99  returnReduce(patch().size(), sumOp<label>())
100  ? -gSum(patch().Sf())/gSum(patch().magSf())
101  : Zero
102  )
103  ),
104  flowRate_(),
105  volumetric_(),
106  rhoName_("rho"),
107  rhoInlet_(dict.lookupOrDefault<scalar>("rhoInlet", dimDensity, -vGreat)),
108  radialVelocity_
109  (
110  Function2<scalar>::New
111  (
112  "radialVelocity",
113  db().time().userUnits(),
114  dimLength,
115  dimVelocity,
116  dict
117  )
118  ),
119  omega_(nullptr),
120  tangentialVelocity_(nullptr)
121 {
122  if (dict.found("volumetricFlowRate"))
123  {
124  flowRate_ =
126  (
127  "volumetricFlowRate",
128  db().time().userUnits(),
130  dict
131  );
132  volumetric_ = true;
133  }
134  else if (dict.found("massFlowRate"))
135  {
136  flowRate_ =
138  (
139  "massFlowRate",
140  db().time().userUnits(),
141  dimMassFlux,
142  dict
143  );
144  volumetric_ = false;
145  rhoName_ = word(dict.lookupOrDefault<word>("rho", "rho"));
146  }
147  else
148  {
150  << "Please supply either 'volumetricFlowRate' or"
151  << " 'massFlowRate' and 'rho'" << exit(FatalIOError);
152  }
153 
154  if (dict.found("omega") || dict.found("rpm"))
155  {
156  omega_ = new Function1s::omega(db().time(), dict);
157  }
158  else if (dict.found("tangentialVelocity"))
159  {
160  tangentialVelocity_ =
162  (
163  "tangentialVelocity",
164  db().time().userUnits(),
165  dimLength,
166  dimVelocity,
167  dict
168  );
169  }
170  else
171  {
173  << "Please supply either 'omega' or 'rpm' or"
174  << " 'tangentialVelocity'" << exit(FatalIOError);
175  }
176 
177  if (dict.found("value"))
178  {
180  (
181  vectorField("value", iF.dimensions(), dict, p.size())
182  );
183  }
184  else
185  {
187  }
188 }
189 
190 
193 (
195  const fvPatch& p,
197  const fieldMapper& mapper
198 )
199 :
200  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
201  origin_(ptf.origin_),
202  axis_(ptf.axis_),
203  flowRate_(ptf.flowRate_, false),
204  volumetric_(ptf.volumetric_),
205  rhoName_(ptf.rhoName_),
206  rhoInlet_(ptf.rhoInlet_),
207  radialVelocity_(ptf.radialVelocity_, false),
208  omega_(ptf.omega_, false),
209  tangentialVelocity_(ptf.tangentialVelocity_, false)
210 {}
211 
212 
215 (
218 )
219 :
220  fixedValueFvPatchField<vector>(ptf, iF),
221  origin_(ptf.origin_),
222  axis_(ptf.axis_),
223  flowRate_(ptf.flowRate_, false),
224  volumetric_(ptf.volumetric_),
225  rhoName_(ptf.rhoName_),
226  rhoInlet_(ptf.rhoInlet_),
227  radialVelocity_(ptf.radialVelocity_, false),
228  omega_(ptf.omega_, false),
229  tangentialVelocity_(ptf.tangentialVelocity_, false)
230 {}
231 
232 
233 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
234 
236 {
237  if (updated())
238  {
239  return;
240  }
241 
242  if (volumetric_ || rhoName_ == "none")
243  {
244  updateValues(one());
245  }
246  else
247  {
248  // Mass flow-rate
249  if (db().foundObject<volScalarField>(rhoName_))
250  {
251  const fvPatchField<scalar>& rhop =
252  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
253 
254  updateValues(rhop);
255  }
256  else
257  {
258  // Use constant density
259  if (rhoInlet_ < 0)
260  {
262  << "Did not find registered density field " << rhoName_
263  << " and no constant density 'rhoInlet' specified"
264  << exit(FatalError);
265  }
266 
267  updateValues(rhoInlet_);
268  }
269  }
270 
272 }
273 
274 
276 (
277  Ostream& os
278 ) const
279 {
281  writeEntry(os, "origin", origin_);
282  writeEntry(os, "axis", axis_);
283  writeEntry(os, db().time().userUnits(), unitAny, flowRate_());
284  if (!volumetric_)
285  {
286  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
287  writeEntryIfDifferent<scalar>(os, "rhoInlet", -vGreat, rhoInlet_);
288  }
289  writeEntry
290  (
291  os,
292  db().time().userUnits(),
293  dimLength,
294  dimVelocity,
295  radialVelocity_()
296  );
297  if (omega_.valid())
298  {
299  writeEntry(os, omega_());
300  }
301  else
302  {
303  writeEntry
304  (
305  os,
306  db().time().userUnits(),
307  dimLength,
308  dimVelocity,
309  tangentialVelocity_()
310  );
311  }
312  writeEntry(os, "value", *this);
313 }
314 
315 
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 
318 namespace Foam
319 {
321  (
324  );
325 }
326 
327 
328 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const dimensionSet & dimensions() const
Return dimensions.
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
Run-time selectable function of two variables.
Definition: Function2.H:98
static autoPtr< Function2< Type > > New(const word &name, const Function2s::unitConversions &units, const dictionary &dict)
Select from dictionary.
Definition: Function2New.C:32
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:88
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:229
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:202
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
A class representing the concept of 1 (scalar(1)) used to avoid unnecessary manipulations for objects...
Definition: one.H:51
Velocity inlet boundary condition creating a normal velocity field to match the specified mass or vol...
swirlFlowRateInletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const scalar omega
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
Type gSum(const FieldField< Field, Type > &f)
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
const unitConversion unitAny
const dimensionSet dimMassFlux
const dimensionSet dimVolumetricFlux
const dimensionSet dimless
const dimensionSet dimLength
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
const dimensionSet dimDensity
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:64
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:510
dimensioned< scalar > mag(const dimensioned< Type > &)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Field< vector > vectorField
Specialisation of Field<T> for vector.
IOerror FatalIOError
const dimensionSet dimVelocity
void evaluate(GeometricField< Type, PatchField, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, PatchField, GeoMesh > &x)
error FatalError
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
dictionary dict
volScalarField & p