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 -------------------------------------------------------------------------------
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  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 :
116  fixedValueFvPatchField<vector>(ptf, iF),
117  inletPatchName_(ptf.inletPatchName_),
118  rhoName_(ptf.rhoName_),
119  volumetric_(ptf.volumetric_)
120 {}
121 
122 
123 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
124 
125 template<class RhoType>
126 void 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);
228  }
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  }
248 }
249 
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 namespace Foam
254 {
256  (
258  matchedFlowRateOutletVelocityFvPatchVectorField
259  );
260 }
261 
262 
263 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
dictionary dict
fvPatchField< vector > fvPatchVectorField
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:600
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
matchedFlowRateOutletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
Velocity outlet boundary condition which corrects the extrapolated velocity to match the flow rate of...
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: fvPatchField.H:413
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:374
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:76
Macros for easy insertion into run-time selection tables.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:72
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Type gSum(const FieldField< Field, Type > &f)
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Vector< scalar > vector
Definition: vector.H:57
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:336
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
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.
U
Definition: pEqn.H:72
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const std::string patch
OpenFOAM patch number as a std::string.
label n
Field< vector > vectorField
Specialisation of Field<T> for vector.
volScalarField & p
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
"buffered" : (MPI_Bsend, MPI_Recv)
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Namespace for OpenFOAM.