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-------------------------------------------------------------------------------
11License
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
36Foam::flowRateOutletVelocityFvPatchVectorField::
37flowRateOutletVelocityFvPatchVectorField
38(
39 const fvPatch& p,
41)
42:
44 flowRate_(),
45 volumetric_(false),
46 rhoName_("rho"),
47 rhoOutlet_(0.0)
48{}
49
50
51Foam::flowRateOutletVelocityFvPatchVectorField::
52flowRateOutletVelocityFvPatchVectorField
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
97Foam::flowRateOutletVelocityFvPatchVectorField::
98flowRateOutletVelocityFvPatchVectorField
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
114Foam::flowRateOutletVelocityFvPatchVectorField::
115flowRateOutletVelocityFvPatchVectorField
116(
118)
119:
121 flowRate_(ptf.flowRate_.clone()),
122 volumetric_(ptf.volumetric_),
123 rhoName_(ptf.rhoName_),
124 rhoOutlet_(ptf.rhoOutlet_)
125{}
126
127
128Foam::flowRateOutletVelocityFvPatchVectorField::
129flowRateOutletVelocityFvPatchVectorField
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
145template<class RhoType>
146void 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
242namespace Foam
243{
245 (
248 );
249}
250
251
252// ************************************************************************* //
label n
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
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:251
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
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.
virtual bool write()
Write the output fields.
A FieldMapper for finite-volume patch fields.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:82
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
#define makePatchTypeField(PatchTypeField, typePatchTypeField)
Definition: fvPatchField.H:676
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Type gSum(const FieldField< Field, Type > &f)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:82
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Field< vector > vectorField
Specialisation of Field<T> for vector.
IOerror FatalIOError
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dictionary dict