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 -------------------------------------------------------------------------------
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  inletPatchName_(),
44  volumetric_(false),
45  rhoName_("rho")
46 {}
47 
48 
51 (
52  const fvPatch& p,
54  const dictionary& dict
55 )
56 :
58  inletPatchName_(dict.lookup("inletPatch")),
59  volumetric_(dict.lookupOrDefault("volumetric", true))
60 {
61  if (volumetric_)
62  {
63  rhoName_ = "none";
64  }
65  else
66  {
67  rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
68  }
69 
70  // Value field require if mass based
71  if (dict.found("value"))
72  {
74  (
75  vectorField("value", dict, p.size())
76  );
77  }
78  else
79  {
80  evaluate(Pstream::commsTypes::blocking);
81  }
82 }
83 
84 
87 (
89  const fvPatch& p,
91  const fvPatchFieldMapper& mapper
92 )
93 :
94  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
95  inletPatchName_(ptf.inletPatchName_),
96  volumetric_(ptf.volumetric_),
97  rhoName_(ptf.rhoName_)
98 {}
99 
100 
103 (
105 )
106 :
108  inletPatchName_(ptf.inletPatchName_),
109  volumetric_(ptf.volumetric_),
110  rhoName_(ptf.rhoName_)
111 {}
112 
113 
116 (
119 )
120 :
122  inletPatchName_(ptf.inletPatchName_),
123  volumetric_(ptf.volumetric_),
124  rhoName_(ptf.rhoName_)
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
130 template<class RhoType>
131 void Foam::matchedFlowRateOutletVelocityFvPatchVectorField::updateValues
132 (
133  const label inletPatchID,
134  const RhoType& rhoOutlet,
135  const RhoType& rhoInlet
136 )
137 {
138  const fvPatch& p = patch();
139  const fvPatch& inletPatch = p.boundaryMesh()[inletPatchID];
140 
141  const vectorField n(p.nf());
142 
143  // Extrapolate patch velocity
144  vectorField Up(patchInternalField());
145 
146  // Patch normal extrapolated velocity
147  scalarField nUp(n & Up);
148 
149  // Remove the normal component of the extrapolate patch velocity
150  Up -= nUp*n;
151 
152  // Remove any reverse flow
153  nUp = max(nUp, scalar(0));
154 
155  // Lookup non-const access to velocity field
157  (
158  const_cast<volVectorField&>
159  (
160  dynamic_cast<const volVectorField&>(internalField())
161  )
162  );
163 
164  // Get the corresponding inlet velocity patch field
165  fvPatchVectorField& inletPatchU = U.boundaryFieldRef()[inletPatchID];
166 
167  // Ensure that the corresponding inlet velocity patch field is up-to-date
168  inletPatchU.updateCoeffs();
169 
170  // Calculate the inlet patch flow rate
171  const scalar flowRate = -gSum(rhoInlet*(inletPatch.Sf() & inletPatchU));
172 
173  // Calculate the extrapolated outlet patch flow rate
174  const scalar estimatedFlowRate = gSum(rhoOutlet*(patch().magSf()*nUp));
175 
176  if (estimatedFlowRate/flowRate > 0.5)
177  {
178  nUp *= (mag(flowRate)/mag(estimatedFlowRate));
179  }
180  else
181  {
182  nUp += ((flowRate - estimatedFlowRate)/gSum(rhoOutlet*patch().magSf()));
183  }
184 
185  // Add the corrected normal component of velocity to the patch velocity
186  Up += nUp*n;
187 
188  // Correct the patch velocity
189  operator==(Up);
190 }
191 
192 
194 {
195  if (updated())
196  {
197  return;
198  }
199 
200  // Find corresponding inlet patch
201  const label inletPatchID =
202  patch().patch().boundaryMesh().findPatchID(inletPatchName_);
203 
204  if (inletPatchID < 0)
205  {
207  << "Unable to find inlet patch " << inletPatchName_
208  << exit(FatalError);
209  }
210 
211  if (volumetric_)
212  {
213  updateValues(inletPatchID, one(), one());
214  }
215  else
216  {
217  // Mass flow-rate
218  if (db().foundObject<volScalarField>(rhoName_))
219  {
220  const volScalarField& rho = db().lookupObject<volScalarField>
221  (
222  rhoName_
223  );
224 
225  updateValues
226  (
227  inletPatchID,
228  rho.boundaryField()[patch().index()],
229  rho.boundaryField()[inletPatchID]
230  );
231  }
232  else
233  {
235  << "Cannot find density field " << rhoName_ << exit(FatalError);
236  }
237  }
238 
239  fixedValueFvPatchVectorField::updateCoeffs();
240 }
241 
242 
244 (
245  Ostream& os
246 ) const
247 {
249  os.writeEntry("inletPatch", inletPatchName_);
250  if (!volumetric_)
251  {
252  os.writeEntry("volumetric", volumetric_);
253  os.writeEntryIfDifferent<word>("rho", "rho", rhoName_);
254  }
255  writeEntry("value", os);
256 }
257 
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 namespace Foam
262 {
264  (
267  );
268 }
269 
270 
271 // ************************************************************************* //
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::fvPatch::Sf
const vectorField & Sf() const
Return face area vectors.
Definition: fvPatch.C:126
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
matchedFlowRateOutletVelocityFvPatchVectorField.H
Foam::matchedFlowRateOutletVelocityFvPatchVectorField::write
virtual void write(Ostream &) const
Write.
Definition: matchedFlowRateOutletVelocityFvPatchVectorField.C:244
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::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::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field< vector >
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::matchedFlowRateOutletVelocityFvPatchVectorField::matchedFlowRateOutletVelocityFvPatchVectorField
matchedFlowRateOutletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
Definition: matchedFlowRateOutletVelocityFvPatchVectorField.C:37
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
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
Foam::matchedFlowRateOutletVelocityFvPatchVectorField
Velocity outlet boundary condition which corrects the extrapolated velocity to match the flow rate of...
Definition: matchedFlowRateOutletVelocityFvPatchVectorField.H:95
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::fvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:313
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
U
U
Definition: pEqn.H:72
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)
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:219
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::matchedFlowRateOutletVelocityFvPatchVectorField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: matchedFlowRateOutletVelocityFvPatchVectorField.C:193
Foam::GeometricField< vector, fvPatchField, volMesh >
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