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 :
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  {
92  evaluate(Pstream::commsTypes::blocking);
93  }
94 }
95 
96 
99 (
101  const fvPatch& p,
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 :
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  (
248  );
249 }
250 
251 
252 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
volFields.H
Foam::fvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:384
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:248
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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:123
os
OBJstream os(runTime.globalPath()/outputName)
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:453
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:473
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:187
Foam::flowRateOutletVelocityFvPatchVectorField::write
virtual void write(Ostream &) const
Write.
Definition: flowRateOutletVelocityFvPatchVectorField.C:227
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::stringOps::evaluate
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.
Definition: stringOpsEvaluate.C:37