flowRateOutletVelocityFvPatchVectorField.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017 OpenFOAM Foundation
9  Copyright (C) 2020-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "volFields.H"
31 #include "one.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
38 (
39  const fvPatch& p,
41 )
42 :
44  flowRate_(),
45  volumetric_(false),
46  rhoName_("rho"),
47  rhoOutlet_(0.0)
48 {}
49 
50 
53 (
54  const fvPatch& p,
56  const dictionary& dict
57 )
58 :
59  fixedValueFvPatchField<vector>(p, iF, dict, false),
60  rhoOutlet_(dict.getOrDefault<scalar>("rhoOutlet", -VGREAT))
61 {
62  if (dict.found("volumetricFlowRate"))
63  {
64  volumetric_ = true;
65  flowRate_ =
66  Function1<scalar>::New("volumetricFlowRate", dict, &db());
67  rhoName_ = "rho";
68  }
69  else if (dict.found("massFlowRate"))
70  {
71  volumetric_ = false;
72  flowRate_ = Function1<scalar>::New("massFlowRate", dict, &db());
73  rhoName_ = dict.getOrDefault<word>("rho", "rho");
74  }
75  else
76  {
78  << "Please supply either 'volumetricFlowRate' or"
79  << " 'massFlowRate' and 'rho'" << exit(FatalIOError);
80  }
81 
82  // Value field require if mass based
83  if (dict.found("value"))
84  {
86  (
87  vectorField("value", dict, p.size())
88  );
89  }
90  else
91  {
93  }
94 }
95 
96 
99 (
100  const flowRateOutletVelocityFvPatchVectorField& ptf,
101  const fvPatch& p,
102  const DimensionedField<vector, volMesh>& iF,
103  const fvPatchFieldMapper& mapper
104 )
105 :
106  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
107  flowRate_(ptf.flowRate_.clone()),
108  volumetric_(ptf.volumetric_),
109  rhoName_(ptf.rhoName_),
110  rhoOutlet_(ptf.rhoOutlet_)
111 {}
112 
113 
116 (
118 )
119 :
121  flowRate_(ptf.flowRate_.clone()),
122  volumetric_(ptf.volumetric_),
123  rhoName_(ptf.rhoName_),
124  rhoOutlet_(ptf.rhoOutlet_)
125 {}
126 
127 
130 (
133 )
134 :
135  fixedValueFvPatchField<vector>(ptf, iF),
136  flowRate_(ptf.flowRate_.clone()),
137  volumetric_(ptf.volumetric_),
138  rhoName_(ptf.rhoName_),
139  rhoOutlet_(ptf.rhoOutlet_)
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
145 template<class RhoType>
146 void Foam::flowRateOutletVelocityFvPatchVectorField::updateValues
147 (
148  const RhoType& rho
149 )
150 {
151  const scalar t = db().time().timeOutputValue();
152 
153  const vectorField n(patch().nf());
154 
155  // Extrapolate patch velocity
156  vectorField Up(this->patchInternalField());
157 
158  // Patch normal extrapolated velocity
159  scalarField nUp(n & Up);
160 
161  // Remove the normal component of the extrapolate patch velocity
162  Up -= nUp*n;
163 
164  // Remove any reverse flow
165  nUp = max(nUp, scalar(0));
166 
167  const scalar flowRate = flowRate_->value(t);
168  const scalar estimatedFlowRate = gSum(rho*(this->patch().magSf()*nUp));
169 
170  if (estimatedFlowRate > 0.5*flowRate)
171  {
172  nUp *= (mag(flowRate)/mag(estimatedFlowRate));
173  }
174  else
175  {
176  nUp += ((flowRate - estimatedFlowRate)/gSum(rho*patch().magSf()));
177  }
178 
179  // Add the corrected normal component of velocity to the patch velocity
180  Up += nUp*n;
181 
182  // Correct the patch velocity
183  this->operator==(Up);
184 }
185 
186 
188 {
189  if (updated())
190  {
191  return;
192  }
193 
194  if (volumetric_ || rhoName_ == "none")
195  {
196  updateValues(one{});
197  }
198  else
199  {
200  // Mass flow-rate
201  if (db().foundObject<volScalarField>(rhoName_))
202  {
203  const fvPatchField<scalar>& rhop =
204  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
205 
206  updateValues(rhop);
207  }
208  else
209  {
210  // Use constant density
211  if (rhoOutlet_ < 0)
212  {
214  << "Did not find registered density field " << rhoName_
215  << " and no constant density 'rhoOutlet' specified"
216  << exit(FatalError);
217  }
218 
219  updateValues(rhoOutlet_);
220  }
221  }
222 
223  fixedValueFvPatchVectorField::updateCoeffs();
224 }
225 
226 
228 {
230  flowRate_->writeData(os);
231  if (!volumetric_)
232  {
233  os.writeEntryIfDifferent<word>("rho", "rho", rhoName_);
234  os.writeEntryIfDifferent<scalar>("rhoOutlet", -VGREAT, rhoOutlet_);
235  }
236  writeEntry("value", os);
237 }
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 namespace Foam
243 {
245  (
247  flowRateOutletVelocityFvPatchVectorField
248  );
249 }
250 
251 
252 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
dictionary dict
"blocking" : (MPI_Bsend, MPI_Recv)
fvPatchField< vector > fvPatchVectorField
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
friend Ostream & operator(Ostream &, const fvPatchField< Type > &)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:68
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:333
Macros for easy insertion into run-time selection tables.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:84
Type gSum(const FieldField< Field, Type > &f)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
Vector< scalar > vector
Definition: vector.H:57
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
Definition: Ostream.H:327
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:607
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
label n
Velocity outlet boundary condition which corrects the extrapolated velocity to match the specified fl...
Field< vector > vectorField
Specialisation of Field<T> for vector.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
volScalarField & p
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
flowRateOutletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...