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-2026 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().poly().boundaryMesh().findIndices<wallPolyPatch>()
42  );
43 
44  const patchPatchDist pwd(patch().poly(), 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
79  *flowRate_->value(time().value())
80  /gSum(alpha*rho*profile*patch().magSf());
81 
82  operator==(- avgU*profile*patch().nf());
83 }
84 
85 
86 template<class AlphaType>
87 void Foam::flowRateInletVelocityFvPatchVectorField::updateValues
88 (
89  const AlphaType& alpha
90 )
91 {
92  if (meanVelocity_)
93  {
94  updateValues(area_, alpha, one());
95  }
96  else if (volumetric_ || rhoName_ == "none")
97  {
98  updateValues(one(), alpha, one());
99  }
100  else
101  {
102  // Mass flow-rate
103  if (db().foundObject<volScalarField>(rhoName_))
104  {
105  const fvPatchField<scalar>& rhop =
106  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
107 
108  updateValues(one(), alpha, rhop);
109  }
110  else
111  {
112  // Use constant density
113  if (rhoInlet_ < 0)
114  {
116  << "Did not find registered density field " << rhoName_
117  << " and no constant density 'rhoInlet' specified"
118  << exit(FatalError);
119  }
120 
121  updateValues(one(), alpha, rhoInlet_);
122  }
123  }
124 }
125 
126 
127 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128 
131 (
132  const fvPatch& p,
134  const dictionary& dict
135 )
136 :
137  fixedValueFvPatchField<vector>(p, iF, dict, false),
138  flowRate_(),
139  meanVelocity_(),
140  volumetric_(),
141  profile_(),
142  rhoName_("rho"),
143  rhoInlet_(dict.lookupOrDefault<scalar>("rhoInlet", dimDensity, -vGreat)),
144  alphaName_(dict.lookupOrDefault<word>("alpha", word::null)),
145  y_(),
146  area_(-vGreat)
147 {
148  if (dict.found("meanVelocity"))
149  {
150  meanVelocity_ = true;
151  volumetric_ = false;
152  flowRate_ =
154  (
155  "meanVelocity",
156  time().userUnits(),
157  dimVelocity,
158  dict
159  );
160  }
161  else if (dict.found("volumetricFlowRate"))
162  {
163  meanVelocity_ = false;
164  volumetric_ = true;
165  flowRate_ =
167  (
168  "volumetricFlowRate",
169  time().userUnits(),
171  dict
172  );
173  }
174  else if (dict.found("massFlowRate"))
175  {
176  meanVelocity_ = false;
177  volumetric_ = false;
178  flowRate_ =
180  (
181  "massFlowRate",
182  time().userUnits(),
183  dimMassFlux,
184  dict
185  );
186  rhoName_ = word(dict.lookupOrDefault<word>("rho", "rho"));
187  }
188  else
189  {
191  << "Please supply 'meanVelocity', 'volumetricFlowRate' or"
192  << " 'massFlowRate' and 'rho'" << exit(FatalIOError);
193  }
194 
195  if (dict.found("profile"))
196  {
197  profile_ = Function1<scalar>::New("profile", dimless, dimless, dict);
198  }
199 
200  if (!p.time().completeCase() || dict.found("value"))
201  {
203  (
204  vectorField("value", iF.dimensions(), dict, p.size())
205  );
206  }
207  else
208  {
210  }
211 }
212 
213 
216 (
218  const fvPatch& p,
220  const fieldMapper& mapper
221 )
222 :
223  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
224  flowRate_(ptf.flowRate_, false),
225  meanVelocity_(ptf.meanVelocity_),
226  volumetric_(ptf.volumetric_),
227  profile_(ptf.profile_, false),
228  rhoName_(ptf.rhoName_),
229  rhoInlet_(ptf.rhoInlet_),
230  alphaName_(ptf.alphaName_),
231  y_(),
232  area_(-vGreat)
233 {}
234 
235 
238 (
241 )
242 :
243  fixedValueFvPatchField<vector>(ptf, iF),
244  flowRate_(ptf.flowRate_, false),
245  meanVelocity_(ptf.meanVelocity_),
246  volumetric_(ptf.volumetric_),
247  profile_(ptf.profile_, false),
248  rhoName_(ptf.rhoName_),
249  rhoInlet_(ptf.rhoInlet_),
250  alphaName_(ptf.alphaName_),
251  y_(ptf.y_),
252  area_(ptf.area_)
253 {}
254 
255 
256 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
257 
259 (
260  const fvPatchVectorField& ptf,
261  const fieldMapper& mapper
262 )
263 {
264  fixedValueFvPatchVectorField::map(ptf, mapper);
265 
266  y_.clear();
267  area_ = -vGreat;
268 }
269 
270 
272 (
273  const fvPatchVectorField& ptf
274 )
275 {
276  fixedValueFvPatchVectorField::reset(ptf);
277 
278  y_.clear();
279  area_ = -vGreat;
280 }
281 
282 
284 {
285  if (updated())
286  {
287  return;
288  }
289 
290  if (!patch().time().completeCase())
291  {
293  << "Cannot evaluate flow rate on a non-parallel processor case"
294  << exit(FatalError);
295  }
296 
297  if (area_ < 0)
298  {
299  setWallDist();
300  }
301 
302  if (alphaName_ != word::null)
303  {
304  const fvPatchField<scalar>& alphap =
305  patch().lookupPatchField<volScalarField, scalar>(alphaName_);
306 
307  updateValues(alphap);
308  }
309  else
310  {
311  updateValues(one());
312  }
313 
314  fixedValueFvPatchVectorField::updateCoeffs();
315 }
316 
317 
319 {
321  writeEntry(os, time().userUnits(), units::any, flowRate_());
322  if (profile_.valid())
323  {
324  writeEntry(os, profile_());
325  }
326  if (!volumetric_)
327  {
328  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
329  writeEntryIfDifferent<scalar>(os, "rhoInlet", -vGreat, rhoInlet_);
330  }
331  writeEntryIfDifferent<word>(os, "alpha", word::null, alphaName_);
332  writeEntry(os, "value", *this);
333 }
334 
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
338 namespace Foam
339 {
341  (
344  );
345 }
346 
347 
348 // ************************************************************************* //
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::unitSets &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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...
Velocity inlet boundary condition creating a velocity field with optionally specified profile normal ...
flowRateInletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, fvMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void reset(const fvPatchVectorField &)
Reset the fvPatchField to the given fvPatchField.
virtual void map(const fvPatchVectorField &, const fieldMapper &)
Map the given fvPatchField onto this fvPatchField.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:90
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:235
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:58
A class representing the concept of 1 (scalar(1)) used to avoid unnecessary manipulations for objects...
Definition: one.H:51
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
#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
rho
Definition: pEqn.H:1
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
const dimensionSet time
const unitSet any
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const dimensionSet & dimless
Definition: dimensions.C:138
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
const dimensionSet & dimMassFlux
Definition: dimensions.C:179
makePatchTypeField(fvPatchScalarField, atmosphericBoundaryLayerTurbulentEpsilonFvPatchScalarField)
Type gSum(const UList< Type > &f, const label comm)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const dimensionSet & dimVelocity
Definition: dimensions.C:154
void evaluate(GeometricField< Type, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, GeoMesh > &x)
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:62
const dimensionSet & dimDensity
Definition: dimensions.C:158
Field< vector > vectorField
Specialisation of Field<T> for vector.
IOerror FatalIOError
Type gMax(const UList< Type > &f, const label comm)
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:213
error FatalError
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
const dimensionSet & dimVolumetricFlux
Definition: dimensions.C:178
dictionary dict
volScalarField & p