Loading...
Searching...
No Matches
matchedFlowRateOutletVelocityFvPatchVectorField.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
38(
39 const fvPatch& p,
41)
42:
44 inletPatchName_(),
45 rhoName_("rho"),
46 volumetric_(false)
47{}
48
49
52(
53 const fvPatch& p,
55 const dictionary& dict
56)
57:
59 inletPatchName_(dict.get<word>("inletPatch")),
60 rhoName_(),
61 volumetric_(dict.getOrDefault("volumetric", true))
62{
63 if (volumetric_)
64 {
65 rhoName_ = "none";
66 }
67 else
68 {
69 rhoName_ = dict.getOrDefault<word>("rho", "rho");
70 }
71
72 // Value field required if mass based
73 if (!this->readValueEntry(dict))
74 {
76 }
77}
78
79
82(
83 const matchedFlowRateOutletVelocityFvPatchVectorField& ptf,
84 const fvPatch& p,
85 const DimensionedField<vector, volMesh>& iF,
86 const fvPatchFieldMapper& mapper
87)
88:
89 fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
90 inletPatchName_(ptf.inletPatchName_),
91 rhoName_(ptf.rhoName_),
92 volumetric_(ptf.volumetric_)
93{}
94
95
98(
100)
101:
103 inletPatchName_(ptf.inletPatchName_),
104 rhoName_(ptf.rhoName_),
105 volumetric_(ptf.volumetric_)
106{}
107
108
111(
114)
115:
117 inletPatchName_(ptf.inletPatchName_),
118 rhoName_(ptf.rhoName_),
119 volumetric_(ptf.volumetric_)
120{}
121
122
123// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
124
125template<class RhoType>
126void Foam::matchedFlowRateOutletVelocityFvPatchVectorField::updateValues
127(
128 const label inletPatchID,
129 const RhoType& rhoOutlet,
130 const RhoType& rhoInlet
131)
132{
133 const fvPatch& p = patch();
134 const fvPatch& inletPatch = p.boundaryMesh()[inletPatchID];
135
136 const vectorField n(p.nf());
137
138 // Extrapolate patch velocity
139 vectorField Up(patchInternalField());
140
141 // Patch normal extrapolated velocity
142 scalarField nUp(n & Up);
143
144 // Remove the normal component of the extrapolate patch velocity
145 Up -= nUp*n;
146
147 // Remove any reverse flow
148 nUp = max(nUp, scalar(0));
149
150 // Lookup non-const access to velocity field
152 (
153 dynamic_cast<const volVectorField&>(internalField()).constCast()
154 );
155
156 // Get the corresponding inlet velocity patch field
157 fvPatchVectorField& inletPatchU = U.boundaryFieldRef()[inletPatchID];
158
159 // Ensure that the corresponding inlet velocity patch field is up-to-date
160 inletPatchU.updateCoeffs();
161
162 // Calculate the inlet patch flow rate
163 const scalar flowRate = -gSum(rhoInlet*(inletPatch.Sf() & inletPatchU));
164
165 // Calculate the extrapolated outlet patch flow rate
166 const scalar estimatedFlowRate = gSum(rhoOutlet*(patch().magSf()*nUp));
167
168 if (estimatedFlowRate > 0.5*flowRate)
169 {
170 nUp *= (mag(flowRate)/mag(estimatedFlowRate));
171 }
172 else
173 {
174 nUp += ((flowRate - estimatedFlowRate)/gSum(rhoOutlet*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 operator==(Up);
182}
183
184
186{
187 if (updated())
188 {
189 return;
190 }
191
192 // Find corresponding inlet patch
193 const label inletPatchID =
194 patch().patch().boundaryMesh().findPatchID(inletPatchName_);
195
196 if (inletPatchID < 0)
197 {
199 << "Unable to find inlet patch " << inletPatchName_
200 << exit(FatalError);
201 }
202
203 if (volumetric_)
204 {
205 updateValues(inletPatchID, one{}, one{});
206 }
207 else
208 {
209 // Mass flow-rate
210 if (db().foundObject<volScalarField>(rhoName_))
211 {
212 const volScalarField& rho = db().lookupObject<volScalarField>
213 (
214 rhoName_
215 );
216
217 updateValues
218 (
219 inletPatchID,
220 rho.boundaryField()[patch().index()],
221 rho.boundaryField()[inletPatchID]
222 );
223 }
224 else
225 {
227 << "Cannot find density field " << rhoName_ << exit(FatalError);
229 }
230
231 fixedValueFvPatchVectorField::updateCoeffs();
232}
233
234
236(
237 Ostream& os
238) const
239{
241 os.writeEntry("inletPatch", inletPatchName_);
242 if (!volumetric_)
243 {
244 os.writeEntry("volumetric", volumetric_);
245 os.writeEntryIfDifferent<word>("rho", "rho", rhoName_);
246 }
249
250
251// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252
253namespace Foam
254{
256 (
258 matchedFlowRateOutletVelocityFvPatchVectorField
259 );
260}
261
262
263// ************************************************************************* //
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...
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition Ostream.H:331
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:346
@ buffered
"buffered" : (MPI_Bsend, MPI_Recv)
Definition UPstream.H:82
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
A FieldMapper for finite-volume patch fields.
virtual void write(Ostream &) const
Write.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition fvPatch.H:71
const vectorField & Sf() const
Return face area vectors, like the fvMesh::Sf() method.
Definition fvPatch.C:125
Velocity outlet boundary condition which corrects the extrapolated velocity to match the flow rate of...
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
matchedFlowRateOutletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition one.H:57
A class for handling words, derived from Foam::string.
Definition word.H:66
U
Definition pEqn.H:72
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
#define makePatchTypeField(PatchTypeField, typePatchTypeField)
Define a concrete fvPatchField type and add to run-time tables Example, (fvPatchScalarField,...
const std::string patch
OpenFOAM patch number as a std::string.
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:40
Type gSum(const FieldField< Field, Type > &f)
GeometricField< vector, fvPatchField, volMesh > volVectorField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
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.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
Vector< scalar > vector
Definition vector.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
fvPatchField< vector > fvPatchVectorField
dictionary dict