flowRateOutletVelocityFvPatchVectorField.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) 2017-2020 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"
28 #include "one.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
35 (
36  const fvPatch& p,
38 )
39 :
41  flowRate_(),
42  volumetric_(false),
43  rhoName_("rho"),
44  rhoOutlet_(0.0)
45 {}
46 
47 
50 (
51  const fvPatch& p,
53  const dictionary& dict
54 )
55 :
57  rhoOutlet_(dict.lookupOrDefault<scalar>("rhoOutlet", -vGreat))
58 {
59  if (dict.found("volumetricFlowRate"))
60  {
61  volumetric_ = true;
62  flowRate_ = Function1<scalar>::New("volumetricFlowRate", dict);
63  rhoName_ = "rho";
64  }
65  else if (dict.found("massFlowRate"))
66  {
67  volumetric_ = false;
68  flowRate_ = Function1<scalar>::New("massFlowRate", dict);
69  rhoName_ = word(dict.lookupOrDefault<word>("rho", "rho"));
70  }
71  else
72  {
74  (
75  dict
76  ) << "Please supply either 'volumetricFlowRate' or"
77  << " 'massFlowRate' and 'rho'" << exit(FatalIOError);
78  }
79 
80  // Value field require if mass based
81  if (dict.found("value"))
82  {
84  (
85  vectorField("value", dict, p.size())
86  );
87  }
88  else
89  {
90  evaluate(Pstream::commsTypes::blocking);
91  }
92 }
93 
94 
97 (
99  const fvPatch& p,
101  const fvPatchFieldMapper& mapper
102 )
103 :
104  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
105  flowRate_(ptf.flowRate_, false),
106  volumetric_(ptf.volumetric_),
107  rhoName_(ptf.rhoName_),
108  rhoOutlet_(ptf.rhoOutlet_)
109 {}
110 
111 
114 (
117 )
118 :
120  flowRate_(ptf.flowRate_, false),
121  volumetric_(ptf.volumetric_),
122  rhoName_(ptf.rhoName_),
123  rhoOutlet_(ptf.rhoOutlet_)
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 
129 template<class RhoType>
130 void Foam::flowRateOutletVelocityFvPatchVectorField::updateValues
131 (
132  const RhoType& rho
133 )
134 {
135  const scalar t = db().time().timeOutputValue();
136 
137  const vectorField n(patch().nf());
138 
139  // Extrapolate patch velocity
140  vectorField Up(this->patchInternalField());
141 
142  // Patch normal extrapolated velocity
143  scalarField nUp(n & Up);
144 
145  // Remove the normal component of the extrapolate patch velocity
146  Up -= nUp*n;
147 
148  // Remove any reverse flow
149  nUp = max(nUp, scalar(0));
150 
151  const scalar flowRate = flowRate_->value(t);
152  const scalar estimatedFlowRate = gSum(rho*(this->patch().magSf()*nUp));
153 
154  if (estimatedFlowRate/flowRate > 0.5)
155  {
156  nUp *= (mag(flowRate)/mag(estimatedFlowRate));
157  }
158  else
159  {
160  nUp += ((flowRate - estimatedFlowRate)/gSum(rho*patch().magSf()));
161  }
162 
163  // Add the corrected normal component of velocity to the patch velocity
164  Up += nUp*n;
165 
166  // Correct the patch velocity
167  this->operator==(Up);
168 }
169 
170 
172 {
173  if (updated())
174  {
175  return;
176  }
177 
178  if (volumetric_ || rhoName_ == "none")
179  {
180  updateValues(one());
181  }
182  else
183  {
184  // Mass flow-rate
185  if (db().foundObject<volScalarField>(rhoName_))
186  {
187  const fvPatchField<scalar>& rhop =
188  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
189 
190  updateValues(rhop);
191  }
192  else
193  {
194  // Use constant density
195  if (rhoOutlet_ < 0)
196  {
198  << "Did not find registered density field " << rhoName_
199  << " and no constant density 'rhoOutlet' specified"
200  << exit(FatalError);
201  }
202 
203  updateValues(rhoOutlet_);
204  }
205  }
206 
207  fixedValueFvPatchVectorField::updateCoeffs();
208 }
209 
210 
212 {
214  writeEntry(os, flowRate_());
215  if (!volumetric_)
216  {
217  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
218  writeEntryIfDifferent<scalar>(os, "rhoOutlet", -vGreat, rhoOutlet_);
219  }
220  writeEntry(os, "value", *this);
221 }
222 
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 namespace Foam
227 {
229  (
232  );
233 }
234 
235 
236 // ************************************************************************* //
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
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
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:62
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
volVectorField vectorField(fieldObject, mesh)
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:260
Macros for easy insertion into run-time selection tables.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Type gSum(const FieldField< Field, Type > &f)
virtual Type value(const scalar x) const =0
Return value as a function of scalar x.
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
A class for handling words, derived from string.
Definition: word.H:59
Foam::fvPatchFieldMapper.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dimensioned< scalar > mag(const dimensioned< Type > &)
label n
Velocity outlet boundary condition which corrects the extrapolated velocity to match the specified fl...
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
volScalarField & p
flowRateOutletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Namespace for OpenFOAM.
A class representing the concept of 1 (scalar(1)) used to avoid unnecessary manipulations for objects...
Definition: one.H:50
IOerror FatalIOError