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 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 :
60  rhoOutlet_(dict.getOrDefault<scalar>("rhoOutlet", -VGREAT))
61 {
62  if (dict.found("volumetricFlowRate"))
63  {
64  volumetric_ = true;
65  flowRate_ = Function1<scalar>::New("volumetricFlowRate", dict);
66  rhoName_ = "rho";
67  }
68  else if (dict.found("massFlowRate"))
69  {
70  volumetric_ = false;
71  flowRate_ = Function1<scalar>::New("massFlowRate", dict);
72  rhoName_ = dict.getOrDefault<word>("rho", "rho");
73  }
74  else
75  {
77  << "Please supply either 'volumetricFlowRate' or"
78  << " 'massFlowRate' and 'rho'" << exit(FatalIOError);
79  }
80 
81  // Value field require if mass based
82  if (dict.found("value"))
83  {
85  (
86  vectorField("value", dict, p.size())
87  );
88  }
89  else
90  {
91  evaluate(Pstream::commsTypes::blocking);
92  }
93 }
94 
95 
98 (
100  const fvPatch& p,
102  const fvPatchFieldMapper& mapper
103 )
104 :
105  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
106  flowRate_(ptf.flowRate_.clone()),
107  volumetric_(ptf.volumetric_),
108  rhoName_(ptf.rhoName_),
109  rhoOutlet_(ptf.rhoOutlet_)
110 {}
111 
112 
115 (
117 )
118 :
120  flowRate_(ptf.flowRate_.clone()),
121  volumetric_(ptf.volumetric_),
122  rhoName_(ptf.rhoName_),
123  rhoOutlet_(ptf.rhoOutlet_)
124 {}
125 
126 
129 (
132 )
133 :
135  flowRate_(ptf.flowRate_.clone()),
136  volumetric_(ptf.volumetric_),
137  rhoName_(ptf.rhoName_),
138  rhoOutlet_(ptf.rhoOutlet_)
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
144 template<class RhoType>
145 void Foam::flowRateOutletVelocityFvPatchVectorField::updateValues
146 (
147  const RhoType& rho
148 )
149 {
150  const scalar t = db().time().timeOutputValue();
151 
152  const vectorField n(patch().nf());
153 
154  // Extrapolate patch velocity
155  vectorField Up(this->patchInternalField());
156 
157  // Patch normal extrapolated velocity
158  scalarField nUp(n & Up);
159 
160  // Remove the normal component of the extrapolate patch velocity
161  Up -= nUp*n;
162 
163  // Remove any reverse flow
164  nUp = max(nUp, scalar(0));
165 
166  const scalar flowRate = flowRate_->value(t);
167  const scalar estimatedFlowRate = gSum(rho*(this->patch().magSf()*nUp));
168 
169  if (estimatedFlowRate/flowRate > 0.5)
170  {
171  nUp *= (mag(flowRate)/mag(estimatedFlowRate));
172  }
173  else
174  {
175  nUp += ((flowRate - estimatedFlowRate)/gSum(rho*patch().magSf()));
176  }
177 
178  // Add the corrected normal component of velocity to the patch velocity
179  Up += nUp*n;
180 
181  // Correct the patch velocity
182  this->operator==(Up);
183 }
184 
185 
187 {
188  if (updated())
189  {
190  return;
191  }
192 
193  if (volumetric_ || rhoName_ == "none")
194  {
195  updateValues(one{});
196  }
197  else
198  {
199  // Mass flow-rate
200  if (db().foundObject<volScalarField>(rhoName_))
201  {
202  const fvPatchField<scalar>& rhop =
203  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
204 
205  updateValues(rhop);
206  }
207  else
208  {
209  // Use constant density
210  if (rhoOutlet_ < 0)
211  {
213  << "Did not find registered density field " << rhoName_
214  << " and no constant density 'rhoOutlet' specified"
215  << exit(FatalError);
216  }
217 
218  updateValues(rhoOutlet_);
219  }
220  }
221 
222  fixedValueFvPatchVectorField::updateCoeffs();
223 }
224 
225 
227 {
229  flowRate_->writeData(os);
230  if (!volumetric_)
231  {
232  os.writeEntryIfDifferent<word>("rho", "rho", rhoName_);
233  os.writeEntryIfDifferent<scalar>("rhoOutlet", -VGREAT, rhoOutlet_);
234  }
235  writeEntry("value", os);
236 }
237 
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 namespace Foam
242 {
244  (
247  );
248 }
249 
250 
251 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
volFields.H
Foam::fvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:364
Foam::Ostream::writeEntryIfDifferent
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:244
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::flowRateOutletVelocityFvPatchVectorField
Velocity outlet boundary condition which corrects the extrapolated velocity to match the specified fl...
Definition: flowRateOutletVelocityFvPatchVectorField.H:134
Foam::one
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:61
Foam::FatalIOError
IOerror FatalIOError
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
rho
rho
Definition: readInitialConditions.H:88
Foam::fixedValueFvPatchField
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
Definition: fixedValueFvPatchField.H:80
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
n
label n
Definition: TABSMDCalcMethod2.H:31
one.H
Foam::Field< vector >
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
flowRateOutletVelocityFvPatchVectorField.H
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::flowRateOutletVelocityFvPatchVectorField::flowRateOutletVelocityFvPatchVectorField
flowRateOutletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
Definition: flowRateOutletVelocityFvPatchVectorField.C:38
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::makePatchTypeField
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Foam::flowRateOutletVelocityFvPatchVectorField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: flowRateOutletVelocityFvPatchVectorField.C:186
Foam::flowRateOutletVelocityFvPatchVectorField::write
virtual void write(Ostream &) const
Write.
Definition: flowRateOutletVelocityFvPatchVectorField.C:226
Foam::stringOps::evaluate
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)
Definition: stringOpsEvaluate.C:37
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54