flowRateInletVelocityFvPatchVectorField.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-2022 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 
28 #include "volFields.H"
29 #include "one.H"
30 #include "patchPatchDist.H"
31 #include "wallPolyPatch.H"
32 
33 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
34 
35 void Foam::flowRateInletVelocityFvPatchVectorField::setWallDist()
36 {
37  if (profile_.valid())
38  {
39  const labelHashSet otherPatchIDs
40  (
41  patch().patch().boundaryMesh().findPatchIDs<wallPolyPatch>()
42  );
43 
44  const patchPatchDist pwd(patch().patch(), otherPatchIDs);
45 
46  y_ = pwd/gMax(pwd);
47  }
48 
49  area_ = gSum(patch().magSf());
50 }
51 
52 
54 Foam::flowRateInletVelocityFvPatchVectorField::profile()
55 {
56  if (profile_.valid())
57  {
58  return profile_->value(y_);
59  }
60  else
61  {
62  return tmp<scalarField>(new scalarField(size(), scalar(1)));
63  }
64 }
65 
66 
67 template<class ScaleType, class AlphaType, class RhoType>
68 void Foam::flowRateInletVelocityFvPatchVectorField::updateValues
69 (
70  const ScaleType& scale,
71  const AlphaType& alpha,
72  const RhoType& rho
73 )
74 {
75  const scalarField profile(this->profile());
76 
77  const scalar avgU =
78  -(scale*flowRate_->value(db().time().userTimeValue()))
79  /gSum(alpha*rho*profile*patch().magSf());
80 
81  operator==(avgU*profile*patch().nf());
82 }
83 
84 
85 template<class AlphaType>
86 void Foam::flowRateInletVelocityFvPatchVectorField::updateValues
87 (
88  const AlphaType& alpha
89 )
90 {
91  if (meanVelocity_)
92  {
93  updateValues(area_, alpha, one());
94  }
95  else if (volumetric_ || rhoName_ == "none")
96  {
97  updateValues(one(), alpha, one());
98  }
99  else
100  {
101  // Mass flow-rate
102  if (db().foundObject<volScalarField>(rhoName_))
103  {
104  const fvPatchField<scalar>& rhop =
105  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
106 
107  updateValues(one(), alpha, rhop);
108  }
109  else
110  {
111  // Use constant density
112  if (rhoInlet_ < 0)
113  {
115  << "Did not find registered density field " << rhoName_
116  << " and no constant density 'rhoInlet' specified"
117  << exit(FatalError);
118  }
119 
120  updateValues(one(), alpha, rhoInlet_);
121  }
122  }
123 }
124 
125 
126 bool Foam::flowRateInletVelocityFvPatchVectorField::canEvaluate()
127 {
128  return
130  || !patch().boundaryMesh().mesh().time().processorCase();
131 }
132 
133 
134 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
135 
138 (
139  const fvPatch& p,
141 )
142 :
144  flowRate_(),
145  profile_(),
146  meanVelocity_(false),
147  volumetric_(false),
148  rhoName_("rho"),
149  rhoInlet_(0),
150  alphaName_(word::null),
151  y_(),
152  area_(NaN)
153 {}
154 
155 
158 (
159  const fvPatch& p,
161  const dictionary& dict
162 )
163 :
165  rhoInlet_(dict.lookupOrDefault<scalar>("rhoInlet", -vGreat)),
166  alphaName_(dict.lookupOrDefault<word>("alpha", word::null))
167 {
168  if (dict.found("meanVelocity"))
169  {
170  meanVelocity_ = true;
171  volumetric_ = false;
172  flowRate_ = Function1<scalar>::New("meanVelocity", dict);
173  }
174  else if (dict.found("volumetricFlowRate"))
175  {
176  meanVelocity_ = false;
177  volumetric_ = true;
178  flowRate_ = Function1<scalar>::New("volumetricFlowRate", dict);
179  }
180  else if (dict.found("massFlowRate"))
181  {
182  meanVelocity_ = false;
183  volumetric_ = false;
184  flowRate_ = Function1<scalar>::New("massFlowRate", dict);
185  rhoName_ = word(dict.lookupOrDefault<word>("rho", "rho"));
186  }
187  else
188  {
190  (
191  dict
192  ) << "Please supply 'meanVelocity', 'volumetricFlowRate' or"
193  << " 'massFlowRate' and 'rho'" << exit(FatalIOError);
194  }
195 
196  if (dict.found("profile"))
197  {
198  profile_ = Function1<scalar>::New("profile", dict);
199  }
200 
201  if (canEvaluate())
202  {
203  setWallDist();
204  }
205 
206  if (!canEvaluate() || dict.found("value"))
207  {
209  (
210  vectorField("value", dict, p.size())
211  );
212  }
213  else
214  {
216  }
217 }
218 
219 
222 (
224  const fvPatch& p,
226  const fvPatchFieldMapper& mapper
227 )
228 :
229  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
230  flowRate_(ptf.flowRate_, false),
231  profile_(ptf.profile_, false),
232  meanVelocity_(ptf.meanVelocity_),
233  volumetric_(ptf.volumetric_),
234  rhoName_(ptf.rhoName_),
235  rhoInlet_(ptf.rhoInlet_),
236  alphaName_(ptf.alphaName_),
237  y_(),
238  area_(NaN)
239 {}
240 
241 
244 (
247 )
248 :
250  flowRate_(ptf.flowRate_, false),
251  profile_(ptf.profile_, false),
252  meanVelocity_(ptf.meanVelocity_),
253  volumetric_(ptf.volumetric_),
254  rhoName_(ptf.rhoName_),
255  rhoInlet_(ptf.rhoInlet_),
256  alphaName_(ptf.alphaName_),
257  y_(ptf.y_),
258  area_(ptf.area_)
259 {}
260 
261 
262 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
263 
265 (
266  const fvPatchFieldMapper& m
267 )
268 {
269  fixedValueFvPatchVectorField::autoMap(m);
270 
271  if (canEvaluate())
272  {
273  setWallDist();
274  }
275 }
276 
277 
279 (
280  const fvPatchVectorField& ptf,
281  const labelList& addr
282 )
283 {
284  fixedValueFvPatchVectorField::rmap(ptf, addr);
285 
287  refCast<const flowRateInletVelocityFvPatchVectorField>(ptf);
288 
289  if (profile_.valid() && canEvaluate())
290  {
291  y_.rmap(tiptf.y_, addr);
292  }
293 }
294 
295 
297 (
298  const fvPatchVectorField& ptf
299 )
300 {
301  fixedValueFvPatchVectorField::reset(ptf);
302 
304  refCast<const flowRateInletVelocityFvPatchVectorField>(ptf);
305 
306  if (profile_.valid() && canEvaluate())
307  {
308  y_.reset(tiptf.y_);
309  }
310 }
311 
312 
314 {
315  if (updated())
316  {
317  return;
318  }
319 
320  if (!canEvaluate())
321  {
323  << "Cannot evaluate flow rate on a non-parallel processor case"
324  << exit(FatalError);
325  }
326 
327  if (alphaName_ != word::null)
328  {
329  const fvPatchField<scalar>& alphap =
330  patch().lookupPatchField<volScalarField, scalar>(alphaName_);
331 
332  updateValues(alphap);
333  }
334  else
335  {
336  updateValues(one());
337  }
338 
339  fixedValueFvPatchVectorField::updateCoeffs();
340 }
341 
342 
344 {
346  writeEntry(os, flowRate_());
347  if (profile_.valid())
348  {
349  writeEntry(os, profile_());
350  }
351  if (!volumetric_)
352  {
353  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
354  writeEntryIfDifferent<scalar>(os, "rhoInlet", -vGreat, rhoInlet_);
355  }
356  writeEntryIfDifferent<word>(os, "alpha", word::null, alphaName_);
357  writeEntry(os, "value", *this);
358 }
359 
360 
361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
362 
363 namespace Foam
364 {
366  (
369  );
370 }
371 
372 
373 // ************************************************************************* //
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void evaluate(GeometricField< Type, PatchField, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, PatchField, GeoMesh > &x)
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:243
Macros for easy insertion into run-time selection tables.
virtual void rmap(const fvPatchVectorField &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:58
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:211
Type gSum(const FieldField< Field, Type > &f)
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
A class for handling words, derived from string.
Definition: word.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
flowRateInletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
Foam::fvPatchFieldMapper.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
static const word null
An empty word.
Definition: word.H:77
Velocity inlet boundary condition creating a velocity field with optionally specified profile normal ...
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
Type gMax(const FieldField< Field, Type > &f)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition: Field.C:362
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Field< vector > vectorField
Specialisation of Field<T> for vector.
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
void reset(const Field< Type > &)
Reset the field values to the given field.
Definition: Field.C:432
virtual void reset(const fvPatchVectorField &)
Reset the fvPatchField to the given fvPatchField.
Namespace for OpenFOAM.
static autoPtr< Function1< Type > > New(const word &name, const dictionary &dict)
Selector.
Definition: Function1New.C:32
A class representing the concept of 1 (scalar(1)) used to avoid unnecessary manipulations for objects...
Definition: one.H:50
IOerror FatalIOError