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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "volFields.H"
30 #include "one.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
37 (
38  const fvPatch& p,
40 )
41 :
43  flowRate_(),
44  volumetric_(false),
45  rhoName_("rho"),
46  rhoOutlet_(0.0)
47 {}
48 
49 
52 (
53  const fvPatch& p,
55  const dictionary& dict
56 )
57 :
59  rhoOutlet_(dict.lookupOrDefault<scalar>("rhoOutlet", -VGREAT))
60 {
61  if (dict.found("volumetricFlowRate"))
62  {
63  volumetric_ = true;
64  flowRate_ = Function1<scalar>::New("volumetricFlowRate", dict);
65  rhoName_ = "rho";
66  }
67  else if (dict.found("massFlowRate"))
68  {
69  volumetric_ = false;
70  flowRate_ = Function1<scalar>::New("massFlowRate", dict);
71  rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
72  }
73  else
74  {
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_.clone()),
106  volumetric_(ptf.volumetric_),
107  rhoName_(ptf.rhoName_),
108  rhoOutlet_(ptf.rhoOutlet_)
109 {}
110 
111 
114 (
116 )
117 :
119  flowRate_(ptf.flowRate_.clone()),
120  volumetric_(ptf.volumetric_),
121  rhoName_(ptf.rhoName_),
122  rhoOutlet_(ptf.rhoOutlet_)
123 {}
124 
125 
128 (
131 )
132 :
134  flowRate_(ptf.flowRate_.clone()),
135  volumetric_(ptf.volumetric_),
136  rhoName_(ptf.rhoName_),
137  rhoOutlet_(ptf.rhoOutlet_)
138 {}
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
143 template<class RhoType>
144 void Foam::flowRateOutletVelocityFvPatchVectorField::updateValues
145 (
146  const RhoType& rho
147 )
148 {
149  const scalar t = db().time().timeOutputValue();
150 
151  const vectorField n(patch().nf());
152 
153  // Extrapolate patch velocity
154  vectorField Up(this->patchInternalField());
155 
156  // Patch normal extrapolated velocity
157  scalarField nUp(n & Up);
158 
159  // Remove the normal component of the extrapolate patch velocity
160  Up -= nUp*n;
161 
162  // Remove any reverse flow
163  nUp = max(nUp, scalar(0));
164 
165  const scalar flowRate = flowRate_->value(t);
166  const scalar estimatedFlowRate = gSum(rho*(this->patch().magSf()*nUp));
167 
168  if (estimatedFlowRate/flowRate > 0.5)
169  {
170  nUp *= (mag(flowRate)/mag(estimatedFlowRate));
171  }
172  else
173  {
174  nUp += ((flowRate - estimatedFlowRate)/gSum(rho*patch().magSf()));
175  }
176 
177  // Add the corrected normal component of velocity to the patch velocity
178  Up += nUp*n;
179 
180  // Correct the patch velocity
181  this->operator==(Up);
182 }
183 
184 
186 {
187  if (updated())
188  {
189  return;
190  }
191 
192  if (volumetric_ || rhoName_ == "none")
193  {
194  updateValues(one());
195  }
196  else
197  {
198  // Mass flow-rate
199  if (db().foundObject<volScalarField>(rhoName_))
200  {
201  const fvPatchField<scalar>& rhop =
202  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
203 
204  updateValues(rhop);
205  }
206  else
207  {
208  // Use constant density
209  if (rhoOutlet_ < 0)
210  {
212  << "Did not find registered density field " << rhoName_
213  << " and no constant density 'rhoOutlet' specified"
214  << exit(FatalError);
215  }
216 
217  updateValues(rhoOutlet_);
218  }
219  }
220 
221  fixedValueFvPatchVectorField::updateCoeffs();
222 }
223 
224 
226 {
228  flowRate_->writeData(os);
229  if (!volumetric_)
230  {
231  os.writeEntryIfDifferent<word>("rho", "rho", rhoName_);
232  os.writeEntryIfDifferent<scalar>("rhoOutlet", -VGREAT, rhoOutlet_);
233  }
234  writeEntry("value", os);
235 }
236 
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 namespace Foam
241 {
243  (
246  );
247 }
248 
249 
250 // ************************************************************************* //
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:231
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), which can be used to avoid manipulating objects that are...
Definition: one.H:60
Foam::FatalIOError
IOerror FatalIOError
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
rho
rho
Definition: readInitialConditions.H:96
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:63
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:37
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:355
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:375
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:185
Foam::flowRateOutletVelocityFvPatchVectorField::write
virtual void write(Ostream &) const
Write.
Definition: flowRateOutletVelocityFvPatchVectorField.C:225
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